@kubb/core 2.0.0-beta.2 → 2.0.0-beta.4
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.
- package/dist/index.cjs +188 -156
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -13
- package/dist/index.d.ts +9 -13
- package/dist/index.js +191 -158
- package/dist/index.js.map +1 -1
- package/dist/transformers.cjs +222 -0
- package/dist/transformers.cjs.map +1 -0
- package/dist/transformers.d.ts +55 -0
- package/dist/transformers.js +207 -0
- package/dist/transformers.js.map +1 -0
- package/dist/utils.cjs +226 -212
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +1 -49
- package/dist/utils.d.ts +1 -49
- package/dist/utils.js +227 -212
- package/dist/utils.js.map +1 -1
- package/package.json +9 -4
- package/src/FileManager.ts +33 -15
- package/src/PluginManager.ts +9 -9
- package/src/build.ts +1 -1
- package/src/index.ts +0 -1
- package/src/transformers/casing.ts +9 -0
- package/src/transformers/createJSDocBlockText.ts +9 -0
- package/src/transformers/index.ts +36 -0
- package/src/transformers/trim.ts +7 -0
- package/src/utils/FunctionParams.ts +3 -2
- package/src/utils/URLPath.ts +5 -5
- package/src/utils/index.ts +0 -1
- package/src/utils/write.ts +1 -1
- package/src/SchemaGenerator.ts +0 -8
- package/src/utils/transformers/createJSDocBlockText.ts +0 -15
- package/src/utils/transformers/index.ts +0 -22
- package/src/utils/transformers/trim.ts +0 -3
- /package/src/{utils/transformers → transformers}/combineCodes.ts +0 -0
- /package/src/{utils/transformers → transformers}/escape.ts +0 -0
- /package/src/{utils/transformers → transformers}/indent.ts +0 -0
- /package/src/{utils/transformers → transformers}/nameSorter.ts +0 -0
- /package/src/{utils/transformers → transformers}/searchAndReplace.ts +0 -0
- /package/src/{utils/transformers → transformers}/transformReservedWord.ts +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -473,7 +473,10 @@ declare namespace KubbFile {
|
|
|
473
473
|
* @example ["useState"]
|
|
474
474
|
* @example "React"
|
|
475
475
|
*/
|
|
476
|
-
name: string | Array<string
|
|
476
|
+
name: string | Array<string | {
|
|
477
|
+
propertyName: string;
|
|
478
|
+
name?: string;
|
|
479
|
+
}>;
|
|
477
480
|
/**
|
|
478
481
|
* Path for the import
|
|
479
482
|
* @xample '@kubb/core'
|
|
@@ -483,6 +486,10 @@ declare namespace KubbFile {
|
|
|
483
486
|
* Add `type` prefix to the import, this will result in: `import type { Type } from './path'`.
|
|
484
487
|
*/
|
|
485
488
|
isTypeOnly?: boolean;
|
|
489
|
+
/**
|
|
490
|
+
* When root is set it will get the path with relative getRelativePath(root, path).
|
|
491
|
+
*/
|
|
492
|
+
root?: string;
|
|
486
493
|
};
|
|
487
494
|
type Export = {
|
|
488
495
|
/**
|
|
@@ -561,10 +568,6 @@ declare namespace KubbFile {
|
|
|
561
568
|
* This will override `process.env[key]` inside the `source`, see `getFileSource`.
|
|
562
569
|
*/
|
|
563
570
|
env?: NodeJS.ProcessEnv;
|
|
564
|
-
/**
|
|
565
|
-
* @deprecated
|
|
566
|
-
*/
|
|
567
|
-
validate?: boolean;
|
|
568
571
|
};
|
|
569
572
|
type ResolvedFile<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = KubbFile.File<TMeta, TBaseName> & {
|
|
570
573
|
/**
|
|
@@ -706,13 +709,6 @@ declare class PromiseManager<TState = any> {
|
|
|
706
709
|
run<TInput extends Array<PromiseFunc<TValue, null>>, TValue, TStrategy extends Strategy, TOutput = StrategySwitch<TStrategy, TInput, TValue>>(strategy: TStrategy, promises: TInput): TOutput;
|
|
707
710
|
}
|
|
708
711
|
|
|
709
|
-
/**
|
|
710
|
-
* Abstract class that contains the building blocks for plugins to create their own SchemaGenerator
|
|
711
|
-
*/
|
|
712
|
-
declare abstract class SchemaGenerator<TOptions extends object, TInput, TOutput> extends Generator<TOptions> {
|
|
713
|
-
abstract build(schema: TInput, name: string, description?: string): TOutput;
|
|
714
|
-
}
|
|
715
|
-
|
|
716
712
|
interface _Register {
|
|
717
713
|
}
|
|
718
714
|
type Plugins = _Register;
|
|
@@ -723,4 +719,4 @@ type OptionsOfPlugin<K extends keyof Plugins> = Plugins[K]['options'];
|
|
|
723
719
|
type PluginUnion = TupleToUnion<ObjValueTuple<OptionsPlugins>>;
|
|
724
720
|
type Plugin = keyof Plugins;
|
|
725
721
|
|
|
726
|
-
export { type CLIOptions, FileManager, Generator, type GetPluginFactoryOptions, type InputData, type InputPath, type KubbConfig, KubbFile, type KubbObjectPlugin, type KubbPlugin, type KubbPluginWithLifeCycle, type KubbUnionPlugins, type KubbUserConfig, type KubbUserPlugin, type KubbUserPluginWithLifeCycle, type OptionsOfPlugin, type OptionsPlugins, PackageManager, type Plugin, type PluginCache, type PluginContext, type PluginFactoryOptions, type PluginLifecycle, type PluginLifecycleHooks, PluginManager, type PluginParameter, type PluginUnion, type Plugins, PromiseManager, type ResolveNameParams, type ResolvePathParams,
|
|
722
|
+
export { type CLIOptions, FileManager, Generator, type GetPluginFactoryOptions, type InputData, type InputPath, type KubbConfig, KubbFile, type KubbObjectPlugin, type KubbPlugin, type KubbPluginWithLifeCycle, type KubbUnionPlugins, type KubbUserConfig, type KubbUserPlugin, type KubbUserPluginWithLifeCycle, type OptionsOfPlugin, type OptionsPlugins, PackageManager, type Plugin, type PluginCache, type PluginContext, type PluginFactoryOptions, type PluginLifecycle, type PluginLifecycleHooks, PluginManager, type PluginParameter, type PluginUnion, type Plugins, PromiseManager, type ResolveNameParams, type ResolvePathParams, type TransformResult, ValidationPluginError, Warning, type _Register, build, combineExports, combineImports, createPlugin, build as default, defineConfig, isInputPath, pluginName as name, pluginName, safeBuild };
|
package/dist/index.d.ts
CHANGED
|
@@ -473,7 +473,10 @@ declare namespace KubbFile {
|
|
|
473
473
|
* @example ["useState"]
|
|
474
474
|
* @example "React"
|
|
475
475
|
*/
|
|
476
|
-
name: string | Array<string
|
|
476
|
+
name: string | Array<string | {
|
|
477
|
+
propertyName: string;
|
|
478
|
+
name?: string;
|
|
479
|
+
}>;
|
|
477
480
|
/**
|
|
478
481
|
* Path for the import
|
|
479
482
|
* @xample '@kubb/core'
|
|
@@ -483,6 +486,10 @@ declare namespace KubbFile {
|
|
|
483
486
|
* Add `type` prefix to the import, this will result in: `import type { Type } from './path'`.
|
|
484
487
|
*/
|
|
485
488
|
isTypeOnly?: boolean;
|
|
489
|
+
/**
|
|
490
|
+
* When root is set it will get the path with relative getRelativePath(root, path).
|
|
491
|
+
*/
|
|
492
|
+
root?: string;
|
|
486
493
|
};
|
|
487
494
|
type Export = {
|
|
488
495
|
/**
|
|
@@ -561,10 +568,6 @@ declare namespace KubbFile {
|
|
|
561
568
|
* This will override `process.env[key]` inside the `source`, see `getFileSource`.
|
|
562
569
|
*/
|
|
563
570
|
env?: NodeJS.ProcessEnv;
|
|
564
|
-
/**
|
|
565
|
-
* @deprecated
|
|
566
|
-
*/
|
|
567
|
-
validate?: boolean;
|
|
568
571
|
};
|
|
569
572
|
type ResolvedFile<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = KubbFile.File<TMeta, TBaseName> & {
|
|
570
573
|
/**
|
|
@@ -706,13 +709,6 @@ declare class PromiseManager<TState = any> {
|
|
|
706
709
|
run<TInput extends Array<PromiseFunc<TValue, null>>, TValue, TStrategy extends Strategy, TOutput = StrategySwitch<TStrategy, TInput, TValue>>(strategy: TStrategy, promises: TInput): TOutput;
|
|
707
710
|
}
|
|
708
711
|
|
|
709
|
-
/**
|
|
710
|
-
* Abstract class that contains the building blocks for plugins to create their own SchemaGenerator
|
|
711
|
-
*/
|
|
712
|
-
declare abstract class SchemaGenerator<TOptions extends object, TInput, TOutput> extends Generator<TOptions> {
|
|
713
|
-
abstract build(schema: TInput, name: string, description?: string): TOutput;
|
|
714
|
-
}
|
|
715
|
-
|
|
716
712
|
interface _Register {
|
|
717
713
|
}
|
|
718
714
|
type Plugins = _Register;
|
|
@@ -723,4 +719,4 @@ type OptionsOfPlugin<K extends keyof Plugins> = Plugins[K]['options'];
|
|
|
723
719
|
type PluginUnion = TupleToUnion<ObjValueTuple<OptionsPlugins>>;
|
|
724
720
|
type Plugin = keyof Plugins;
|
|
725
721
|
|
|
726
|
-
export { type CLIOptions, FileManager, Generator, type GetPluginFactoryOptions, type InputData, type InputPath, type KubbConfig, KubbFile, type KubbObjectPlugin, type KubbPlugin, type KubbPluginWithLifeCycle, type KubbUnionPlugins, type KubbUserConfig, type KubbUserPlugin, type KubbUserPluginWithLifeCycle, type OptionsOfPlugin, type OptionsPlugins, PackageManager, type Plugin, type PluginCache, type PluginContext, type PluginFactoryOptions, type PluginLifecycle, type PluginLifecycleHooks, PluginManager, type PluginParameter, type PluginUnion, type Plugins, PromiseManager, type ResolveNameParams, type ResolvePathParams,
|
|
722
|
+
export { type CLIOptions, FileManager, Generator, type GetPluginFactoryOptions, type InputData, type InputPath, type KubbConfig, KubbFile, type KubbObjectPlugin, type KubbPlugin, type KubbPluginWithLifeCycle, type KubbUnionPlugins, type KubbUserConfig, type KubbUserPlugin, type KubbUserPluginWithLifeCycle, type OptionsOfPlugin, type OptionsPlugins, PackageManager, type Plugin, type PluginCache, type PluginContext, type PluginFactoryOptions, type PluginLifecycle, type PluginLifecycleHooks, PluginManager, type PluginParameter, type PluginUnion, type Plugins, PromiseManager, type ResolveNameParams, type ResolvePathParams, type TransformResult, ValidationPluginError, Warning, type _Register, build, combineExports, combineImports, createPlugin, build as default, defineConfig, isInputPath, pluginName as name, pluginName, safeBuild };
|
package/dist/index.js
CHANGED
|
@@ -2,10 +2,10 @@ import mod, { createRequire } from 'module';
|
|
|
2
2
|
import pc3 from 'picocolors';
|
|
3
3
|
import fs2, { remove } from 'fs-extra';
|
|
4
4
|
import seedrandom from 'seedrandom';
|
|
5
|
+
import path, { resolve, dirname, extname, relative, basename } from 'path';
|
|
5
6
|
import { switcher } from 'js-runtime';
|
|
6
|
-
import { camelCase, camelCaseTransformMerge } from 'change-case';
|
|
7
|
+
import { camelCase as camelCase$1, camelCaseTransformMerge, pascalCase as pascalCase$1, pascalCaseTransformMerge } from 'change-case';
|
|
7
8
|
import crypto2 from 'crypto';
|
|
8
|
-
import path, { resolve, dirname, extname } from 'path';
|
|
9
9
|
import { print } from '@kubb/parser';
|
|
10
10
|
import * as factory from '@kubb/parser/factory';
|
|
11
11
|
import isEqual from 'lodash.isequal';
|
|
@@ -128,6 +128,24 @@ function randomPicoColour(text, colors = defaultColours) {
|
|
|
128
128
|
}
|
|
129
129
|
return formatter(text);
|
|
130
130
|
}
|
|
131
|
+
function slash(path3, platform = "linux") {
|
|
132
|
+
const isWindowsPath = /^\\\\\?\\/.test(path3);
|
|
133
|
+
if (["linux", "mac"].includes(platform) && !isWindowsPath) {
|
|
134
|
+
return path3.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
|
|
135
|
+
}
|
|
136
|
+
return path3.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
|
|
137
|
+
}
|
|
138
|
+
function getRelativePath(rootDir, filePath, platform = "linux") {
|
|
139
|
+
if (!rootDir || !filePath) {
|
|
140
|
+
throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ""} ${filePath || ""}`);
|
|
141
|
+
}
|
|
142
|
+
const relativePath = relative(rootDir, filePath);
|
|
143
|
+
const slashedPath = slash(relativePath, platform);
|
|
144
|
+
if (slashedPath.startsWith("../")) {
|
|
145
|
+
return slashedPath.replace(basename(slashedPath), basename(slashedPath, extname(filePath)));
|
|
146
|
+
}
|
|
147
|
+
return `./${slashedPath.replace(basename(slashedPath), basename(slashedPath, extname(filePath)))}`;
|
|
148
|
+
}
|
|
131
149
|
var reader = switcher(
|
|
132
150
|
{
|
|
133
151
|
node: async (path3) => {
|
|
@@ -154,141 +172,30 @@ switcher(
|
|
|
154
172
|
async function read(path3) {
|
|
155
173
|
return reader(path3);
|
|
156
174
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
this.path = path3;
|
|
160
|
-
return this;
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Convert Swagger path to URLPath(syntax of Express)
|
|
164
|
-
* @example /pet/{petId} => /pet/:petId
|
|
165
|
-
*/
|
|
166
|
-
get URL() {
|
|
167
|
-
return this.toURLPath();
|
|
168
|
-
}
|
|
169
|
-
get isURL() {
|
|
170
|
-
try {
|
|
171
|
-
const url = new URL(this.path);
|
|
172
|
-
if (url?.href) {
|
|
173
|
-
return true;
|
|
174
|
-
}
|
|
175
|
-
} catch (error) {
|
|
176
|
-
return false;
|
|
177
|
-
}
|
|
178
|
-
return false;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
182
|
-
* @example /pet/{petId} => `/pet/${petId}`
|
|
183
|
-
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
184
|
-
* @example /account/userID => `/account/${userId}`
|
|
185
|
-
*/
|
|
186
|
-
get template() {
|
|
187
|
-
return this.toTemplateString();
|
|
188
|
-
}
|
|
189
|
-
get object() {
|
|
190
|
-
return this.toObject();
|
|
191
|
-
}
|
|
192
|
-
get params() {
|
|
193
|
-
return this.getParams();
|
|
194
|
-
}
|
|
195
|
-
toObject({ type = "path", replacer, stringify } = {}) {
|
|
196
|
-
const object = {
|
|
197
|
-
url: type === "path" ? this.toURLPath() : this.toTemplateString(replacer),
|
|
198
|
-
params: this.getParams()
|
|
199
|
-
};
|
|
200
|
-
if (stringify) {
|
|
201
|
-
if (type === "template") {
|
|
202
|
-
return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
203
|
-
}
|
|
204
|
-
if (object.params) {
|
|
205
|
-
return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
|
|
206
|
-
}
|
|
207
|
-
return `{ url: '${object.url}' }`;
|
|
208
|
-
}
|
|
209
|
-
return object;
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
213
|
-
* @example /pet/{petId} => `/pet/${petId}`
|
|
214
|
-
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
215
|
-
* @example /account/userID => `/account/${userId}`
|
|
216
|
-
*/
|
|
217
|
-
toTemplateString(replacer) {
|
|
218
|
-
const regex = /{(\w|-)*}/g;
|
|
219
|
-
const found = this.path.match(regex);
|
|
220
|
-
let newPath = this.path.replaceAll("{", "${");
|
|
221
|
-
if (found) {
|
|
222
|
-
newPath = found.reduce((prev, curr) => {
|
|
223
|
-
const pathParam = replacer ? replacer(camelCase(curr, { delimiter: "", transform: camelCaseTransformMerge })) : camelCase(curr, { delimiter: "", transform: camelCaseTransformMerge });
|
|
224
|
-
const replacement = `\${${pathParam}}`;
|
|
225
|
-
return prev.replace(curr, replacement);
|
|
226
|
-
}, this.path);
|
|
227
|
-
}
|
|
228
|
-
return `\`${newPath}\``;
|
|
229
|
-
}
|
|
230
|
-
getParams(replacer) {
|
|
231
|
-
const regex = /{(\w|-)*}/g;
|
|
232
|
-
const found = this.path.match(regex);
|
|
233
|
-
if (!found) {
|
|
234
|
-
return void 0;
|
|
235
|
-
}
|
|
236
|
-
const params = {};
|
|
237
|
-
found.forEach((item) => {
|
|
238
|
-
item = item.replaceAll("{", "").replaceAll("}", "");
|
|
239
|
-
const pathParam = replacer ? replacer(camelCase(item, { delimiter: "", transform: camelCaseTransformMerge })) : camelCase(item, { delimiter: "", transform: camelCaseTransformMerge });
|
|
240
|
-
params[pathParam] = pathParam;
|
|
241
|
-
}, this.path);
|
|
242
|
-
return params;
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Convert Swagger path to URLPath(syntax of Express)
|
|
246
|
-
* @example /pet/{petId} => /pet/:petId
|
|
247
|
-
*/
|
|
248
|
-
toURLPath() {
|
|
249
|
-
return this.path.replaceAll("{", ":").replaceAll("}", "");
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
// src/config.ts
|
|
254
|
-
function defineConfig(options) {
|
|
255
|
-
return options;
|
|
175
|
+
function camelCase(text) {
|
|
176
|
+
return camelCase$1(text, { delimiter: "", stripRegexp: /[^A-Z0-9$]/gi, transform: camelCaseTransformMerge });
|
|
256
177
|
}
|
|
257
|
-
function
|
|
258
|
-
return
|
|
178
|
+
function pascalCase(text) {
|
|
179
|
+
return pascalCase$1(text, { delimiter: "", stripRegexp: /[^A-Z0-9$]/gi, transform: pascalCaseTransformMerge });
|
|
259
180
|
}
|
|
260
181
|
|
|
261
|
-
// src/
|
|
262
|
-
async function timeout(ms) {
|
|
263
|
-
return new Promise((resolve2) => {
|
|
264
|
-
setTimeout(() => {
|
|
265
|
-
resolve2(true);
|
|
266
|
-
}, ms);
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// src/utils/transformers/combineCodes.ts
|
|
182
|
+
// src/transformers/combineCodes.ts
|
|
271
183
|
function combineCodes(codes) {
|
|
272
184
|
return codes.join("\n");
|
|
273
185
|
}
|
|
274
186
|
|
|
275
|
-
// src/
|
|
276
|
-
function createJSDocBlockText({ comments
|
|
187
|
+
// src/transformers/createJSDocBlockText.ts
|
|
188
|
+
function createJSDocBlockText({ comments }) {
|
|
277
189
|
const filteredComments = comments.filter(Boolean);
|
|
278
190
|
if (!filteredComments.length) {
|
|
279
191
|
return "";
|
|
280
192
|
}
|
|
281
|
-
|
|
193
|
+
return `/**
|
|
282
194
|
* ${filteredComments.join("\n * ")}
|
|
283
195
|
*/`;
|
|
284
|
-
if (newLine) {
|
|
285
|
-
return `${source}
|
|
286
|
-
`;
|
|
287
|
-
}
|
|
288
|
-
return source;
|
|
289
196
|
}
|
|
290
197
|
|
|
291
|
-
// src/
|
|
198
|
+
// src/transformers/escape.ts
|
|
292
199
|
function escape(text) {
|
|
293
200
|
return text ? text.replaceAll("`", "\\`") : "";
|
|
294
201
|
}
|
|
@@ -313,12 +220,12 @@ function jsStringEscape(input) {
|
|
|
313
220
|
});
|
|
314
221
|
}
|
|
315
222
|
|
|
316
|
-
// src/
|
|
223
|
+
// src/transformers/indent.ts
|
|
317
224
|
function createIndent(size) {
|
|
318
225
|
return Array.from({ length: size + 1 }).join(" ");
|
|
319
226
|
}
|
|
320
227
|
|
|
321
|
-
// src/
|
|
228
|
+
// src/transformers/nameSorter.ts
|
|
322
229
|
function nameSorter(a, b) {
|
|
323
230
|
if (a.name < b.name) {
|
|
324
231
|
return -1;
|
|
@@ -329,7 +236,7 @@ function nameSorter(a, b) {
|
|
|
329
236
|
return 0;
|
|
330
237
|
}
|
|
331
238
|
|
|
332
|
-
// src/
|
|
239
|
+
// src/transformers/searchAndReplace.ts
|
|
333
240
|
function searchAndReplace(options) {
|
|
334
241
|
const { text, replaceBy, prefix = "", key } = options;
|
|
335
242
|
const searchValues = options.searchValues?.(prefix, key) || [
|
|
@@ -346,7 +253,7 @@ function searchAndReplace(options) {
|
|
|
346
253
|
}, text);
|
|
347
254
|
}
|
|
348
255
|
|
|
349
|
-
// src/
|
|
256
|
+
// src/transformers/transformReservedWord.ts
|
|
350
257
|
var reservedWords = [
|
|
351
258
|
"abstract",
|
|
352
259
|
"arguments",
|
|
@@ -439,13 +346,16 @@ function transformReservedWord(word) {
|
|
|
439
346
|
return word;
|
|
440
347
|
}
|
|
441
348
|
|
|
442
|
-
// src/
|
|
349
|
+
// src/transformers/trim.ts
|
|
443
350
|
function trim(text) {
|
|
444
351
|
return text.replaceAll(/\n/g, "").trim();
|
|
445
352
|
}
|
|
353
|
+
function trimExtName(text) {
|
|
354
|
+
return text.replace(/\.[^/.]+$/, "");
|
|
355
|
+
}
|
|
446
356
|
|
|
447
|
-
// src/
|
|
448
|
-
var
|
|
357
|
+
// src/transformers/index.ts
|
|
358
|
+
var transformers_default = {
|
|
449
359
|
combineCodes,
|
|
450
360
|
escape,
|
|
451
361
|
jsStringEscape,
|
|
@@ -454,10 +364,127 @@ var transformers = {
|
|
|
454
364
|
nameSorter,
|
|
455
365
|
searchAndReplace,
|
|
456
366
|
trim,
|
|
367
|
+
trimExtName,
|
|
457
368
|
JSDoc: {
|
|
458
369
|
createJSDocBlockText
|
|
370
|
+
},
|
|
371
|
+
camelCase,
|
|
372
|
+
pascalCase
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
// src/utils/URLPath.ts
|
|
376
|
+
var URLPath = class {
|
|
377
|
+
constructor(path3) {
|
|
378
|
+
this.path = path3;
|
|
379
|
+
return this;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Convert Swagger path to URLPath(syntax of Express)
|
|
383
|
+
* @example /pet/{petId} => /pet/:petId
|
|
384
|
+
*/
|
|
385
|
+
get URL() {
|
|
386
|
+
return this.toURLPath();
|
|
387
|
+
}
|
|
388
|
+
get isURL() {
|
|
389
|
+
try {
|
|
390
|
+
const url = new URL(this.path);
|
|
391
|
+
if (url?.href) {
|
|
392
|
+
return true;
|
|
393
|
+
}
|
|
394
|
+
} catch (error) {
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
return false;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
401
|
+
* @example /pet/{petId} => `/pet/${petId}`
|
|
402
|
+
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
403
|
+
* @example /account/userID => `/account/${userId}`
|
|
404
|
+
*/
|
|
405
|
+
get template() {
|
|
406
|
+
return this.toTemplateString();
|
|
407
|
+
}
|
|
408
|
+
get object() {
|
|
409
|
+
return this.toObject();
|
|
410
|
+
}
|
|
411
|
+
get params() {
|
|
412
|
+
return this.getParams();
|
|
413
|
+
}
|
|
414
|
+
toObject({ type = "path", replacer, stringify } = {}) {
|
|
415
|
+
const object = {
|
|
416
|
+
url: type === "path" ? this.toURLPath() : this.toTemplateString(replacer),
|
|
417
|
+
params: this.getParams()
|
|
418
|
+
};
|
|
419
|
+
if (stringify) {
|
|
420
|
+
if (type === "template") {
|
|
421
|
+
return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
422
|
+
}
|
|
423
|
+
if (object.params) {
|
|
424
|
+
return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
|
|
425
|
+
}
|
|
426
|
+
return `{ url: '${object.url}' }`;
|
|
427
|
+
}
|
|
428
|
+
return object;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
432
|
+
* @example /pet/{petId} => `/pet/${petId}`
|
|
433
|
+
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
434
|
+
* @example /account/userID => `/account/${userId}`
|
|
435
|
+
*/
|
|
436
|
+
toTemplateString(replacer) {
|
|
437
|
+
const regex = /{(\w|-)*}/g;
|
|
438
|
+
const found = this.path.match(regex);
|
|
439
|
+
let newPath = this.path.replaceAll("{", "${");
|
|
440
|
+
if (found) {
|
|
441
|
+
newPath = found.reduce((prev, curr) => {
|
|
442
|
+
const pathParam = replacer ? replacer(transformers_default.camelCase(curr)) : transformers_default.camelCase(curr);
|
|
443
|
+
const replacement = `\${${pathParam}}`;
|
|
444
|
+
return prev.replace(curr, replacement);
|
|
445
|
+
}, this.path);
|
|
446
|
+
}
|
|
447
|
+
return `\`${newPath}\``;
|
|
448
|
+
}
|
|
449
|
+
getParams(replacer) {
|
|
450
|
+
const regex = /{(\w|-)*}/g;
|
|
451
|
+
const found = this.path.match(regex);
|
|
452
|
+
if (!found) {
|
|
453
|
+
return void 0;
|
|
454
|
+
}
|
|
455
|
+
const params = {};
|
|
456
|
+
found.forEach((item) => {
|
|
457
|
+
item = item.replaceAll("{", "").replaceAll("}", "");
|
|
458
|
+
const pathParam = replacer ? replacer(transformers_default.camelCase(item)) : transformers_default.camelCase(item);
|
|
459
|
+
params[pathParam] = pathParam;
|
|
460
|
+
}, this.path);
|
|
461
|
+
return params;
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Convert Swagger path to URLPath(syntax of Express)
|
|
465
|
+
* @example /pet/{petId} => /pet/:petId
|
|
466
|
+
*/
|
|
467
|
+
toURLPath() {
|
|
468
|
+
return this.path.replaceAll("{", ":").replaceAll("}", "");
|
|
459
469
|
}
|
|
460
470
|
};
|
|
471
|
+
|
|
472
|
+
// src/config.ts
|
|
473
|
+
function defineConfig(options) {
|
|
474
|
+
return options;
|
|
475
|
+
}
|
|
476
|
+
function isInputPath(result) {
|
|
477
|
+
return !!result && "path" in result;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// src/utils/timeout.ts
|
|
481
|
+
async function timeout(ms) {
|
|
482
|
+
return new Promise((resolve2) => {
|
|
483
|
+
setTimeout(() => {
|
|
484
|
+
resolve2(true);
|
|
485
|
+
}, ms);
|
|
486
|
+
});
|
|
487
|
+
}
|
|
461
488
|
async function saveCreateDirectory(path3) {
|
|
462
489
|
const passedPath = dirname(resolve(path3));
|
|
463
490
|
await fs2.mkdir(passedPath, { recursive: true });
|
|
@@ -688,7 +715,7 @@ _options = new WeakMap();
|
|
|
688
715
|
var KubbFile;
|
|
689
716
|
((KubbFile2) => {
|
|
690
717
|
})(KubbFile || (KubbFile = {}));
|
|
691
|
-
var _cache, _task, _isWriting, _timeout, _queue, _validate,
|
|
718
|
+
var _cache, _task, _isWriting, _timeout, _queue, _validate, _add, add_fn, _addOrAppend, addOrAppend_fn;
|
|
692
719
|
var _FileManager = class _FileManager {
|
|
693
720
|
constructor(options) {
|
|
694
721
|
__privateAdd(this, _validate);
|
|
@@ -721,7 +748,6 @@ var _FileManager = class _FileManager {
|
|
|
721
748
|
}
|
|
722
749
|
async add(...files) {
|
|
723
750
|
const promises = files.map((file) => {
|
|
724
|
-
__privateMethod(this, _validate, validate_fn).call(this, file);
|
|
725
751
|
if (file.override) {
|
|
726
752
|
return __privateMethod(this, _add, add_fn).call(this, file);
|
|
727
753
|
}
|
|
@@ -785,9 +811,22 @@ var _FileManager = class _FileManager {
|
|
|
785
811
|
}
|
|
786
812
|
const exports = file.exports ? combineExports(file.exports) : [];
|
|
787
813
|
const imports = file.imports ? combineImports(file.imports, exports, file.source) : [];
|
|
788
|
-
const importNodes = imports.
|
|
814
|
+
const importNodes = imports.filter((item) => {
|
|
815
|
+
return item.path !== transformers_default.trimExtName(file.path);
|
|
816
|
+
}).map((item) => {
|
|
817
|
+
return factory.createImportDeclaration({
|
|
818
|
+
name: item.name,
|
|
819
|
+
path: item.root ? getRelativePath(item.root, item.path) : item.path,
|
|
820
|
+
isTypeOnly: item.isTypeOnly
|
|
821
|
+
});
|
|
822
|
+
});
|
|
789
823
|
const exportNodes = exports.map(
|
|
790
|
-
(item) => factory.createExportDeclaration({
|
|
824
|
+
(item) => factory.createExportDeclaration({
|
|
825
|
+
name: item.name,
|
|
826
|
+
path: item.path,
|
|
827
|
+
isTypeOnly: item.isTypeOnly,
|
|
828
|
+
asAlias: item.asAlias
|
|
829
|
+
})
|
|
791
830
|
);
|
|
792
831
|
return [print([...importNodes, ...exportNodes]), getEnvSource(file.source, file.env)].join("\n");
|
|
793
832
|
}
|
|
@@ -838,14 +877,6 @@ _isWriting = new WeakMap();
|
|
|
838
877
|
_timeout = new WeakMap();
|
|
839
878
|
_queue = new WeakMap();
|
|
840
879
|
_validate = new WeakSet();
|
|
841
|
-
validate_fn = function(file) {
|
|
842
|
-
if (!file.validate) {
|
|
843
|
-
return;
|
|
844
|
-
}
|
|
845
|
-
if (!file.path.toLowerCase().endsWith(file.baseName.toLowerCase())) {
|
|
846
|
-
throw new Error(`${file.path} should end with the baseName ${file.baseName}`);
|
|
847
|
-
}
|
|
848
|
-
};
|
|
849
880
|
_add = new WeakSet();
|
|
850
881
|
add_fn = async function(file) {
|
|
851
882
|
const controller = new AbortController();
|
|
@@ -922,7 +953,7 @@ function combineImports(imports, exports, source) {
|
|
|
922
953
|
return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
|
|
923
954
|
};
|
|
924
955
|
if (Array.isArray(name)) {
|
|
925
|
-
name = name.filter((item) => hasImportInSource(item));
|
|
956
|
+
name = name.filter((item) => typeof item === "string" ? hasImportInSource(item) : hasImportInSource(item.propertyName));
|
|
926
957
|
}
|
|
927
958
|
const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
|
|
928
959
|
const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
|
|
@@ -968,8 +999,8 @@ function getEnvSource(source, env) {
|
|
|
968
999
|
throw new TypeError(`Environment should be in upperCase for ${key}`);
|
|
969
1000
|
}
|
|
970
1001
|
if (typeof replaceBy === "string") {
|
|
971
|
-
prev =
|
|
972
|
-
prev =
|
|
1002
|
+
prev = transformers_default.searchAndReplace({ text: prev.replaceAll(`process.env.${key}`, replaceBy), replaceBy, prefix: "process.env", key });
|
|
1003
|
+
prev = transformers_default.searchAndReplace({ text: prev.replaceAll(new RegExp(`(declare const).*
|
|
973
1004
|
`, "ig"), ""), replaceBy, key });
|
|
974
1005
|
}
|
|
975
1006
|
return prev;
|
|
@@ -1263,11 +1294,14 @@ var PluginManager = class {
|
|
|
1263
1294
|
hookName: "resolvePath",
|
|
1264
1295
|
parameters: [params.baseName, params.directory, params.options]
|
|
1265
1296
|
});
|
|
1266
|
-
if (paths && paths?.length > 1) {
|
|
1267
|
-
|
|
1297
|
+
if (paths && paths?.length > 1 && this.logger.logLevel === LogLevel.debug) {
|
|
1298
|
+
this.logger.warn(
|
|
1268
1299
|
`Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
|
|
1269
1300
|
|
|
1270
|
-
Paths: ${JSON.stringify(paths, void 0, 2)}
|
|
1301
|
+
Paths: ${JSON.stringify(paths, void 0, 2)}
|
|
1302
|
+
|
|
1303
|
+
Falling back on the first item.
|
|
1304
|
+
`
|
|
1271
1305
|
);
|
|
1272
1306
|
}
|
|
1273
1307
|
return paths?.at(0);
|
|
@@ -1284,11 +1318,14 @@ Paths: ${JSON.stringify(paths, void 0, 2)}`
|
|
|
1284
1318
|
hookName: "resolveName",
|
|
1285
1319
|
parameters: [params.name, params.type]
|
|
1286
1320
|
});
|
|
1287
|
-
if (names && names?.length > 1) {
|
|
1288
|
-
|
|
1321
|
+
if (names && names?.length > 1 && this.logger.logLevel === LogLevel.debug) {
|
|
1322
|
+
this.logger.warn(
|
|
1289
1323
|
`Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough
|
|
1290
1324
|
|
|
1291
|
-
Names: ${JSON.stringify(names, void 0, 2)}
|
|
1325
|
+
Names: ${JSON.stringify(names, void 0, 2)}
|
|
1326
|
+
|
|
1327
|
+
Falling back on the first item.
|
|
1328
|
+
`
|
|
1292
1329
|
);
|
|
1293
1330
|
}
|
|
1294
1331
|
return transformReservedWord(names?.at(0) || params.name);
|
|
@@ -1483,7 +1520,7 @@ Names: ${JSON.stringify(names, void 0, 2)}`
|
|
|
1483
1520
|
});
|
|
1484
1521
|
if (!pluginByPluginName?.length) {
|
|
1485
1522
|
const corePlugin = plugins.find((plugin) => plugin.name === "core" && plugin[hookName]);
|
|
1486
|
-
if (this.logger.logLevel ===
|
|
1523
|
+
if (this.logger.logLevel === LogLevel.debug) {
|
|
1487
1524
|
if (corePlugin) {
|
|
1488
1525
|
this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`);
|
|
1489
1526
|
} else {
|
|
@@ -1521,7 +1558,7 @@ _getSortedPlugins = new WeakSet();
|
|
|
1521
1558
|
getSortedPlugins_fn = function(hookName) {
|
|
1522
1559
|
const plugins = [...this.plugins].filter((plugin) => plugin.name !== "core");
|
|
1523
1560
|
if (hookName) {
|
|
1524
|
-
if (this.logger.logLevel ===
|
|
1561
|
+
if (this.logger.logLevel === LogLevel.info) {
|
|
1525
1562
|
const containsHookName = plugins.some((item) => item[hookName]);
|
|
1526
1563
|
if (!containsHookName) {
|
|
1527
1564
|
this.logger.warn(`No hook ${hookName} found`);
|
|
@@ -1724,7 +1761,7 @@ async function setup(options) {
|
|
|
1724
1761
|
if (logger.logLevel === LogLevel.info) {
|
|
1725
1762
|
logger.spinner.start(`\u{1F4BE} Writing`);
|
|
1726
1763
|
}
|
|
1727
|
-
if (logger.logLevel ===
|
|
1764
|
+
if (logger.logLevel === LogLevel.debug) {
|
|
1728
1765
|
logger.info(`PluginKey ${pc3.dim(JSON.stringify(plugin.key))}
|
|
1729
1766
|
with source
|
|
1730
1767
|
|
|
@@ -1944,13 +1981,9 @@ match_fn = function(packageJSON, dependency) {
|
|
|
1944
1981
|
__privateAdd(_PackageManager, _cache2, {});
|
|
1945
1982
|
var PackageManager = _PackageManager;
|
|
1946
1983
|
|
|
1947
|
-
// src/SchemaGenerator.ts
|
|
1948
|
-
var SchemaGenerator = class extends Generator {
|
|
1949
|
-
};
|
|
1950
|
-
|
|
1951
1984
|
// src/index.ts
|
|
1952
1985
|
var src_default = build;
|
|
1953
1986
|
|
|
1954
|
-
export { FileManager, Generator, KubbFile, PackageManager, PluginManager, PromiseManager,
|
|
1987
|
+
export { FileManager, Generator, KubbFile, PackageManager, PluginManager, PromiseManager, ValidationPluginError, Warning, build, combineExports, combineImports, createPlugin, src_default as default, defineConfig, isInputPath, pluginName as name, pluginName, safeBuild };
|
|
1955
1988
|
//# sourceMappingURL=out.js.map
|
|
1956
1989
|
//# sourceMappingURL=index.js.map
|