@kubb/plugin-ts 5.0.14 → 5.0.16
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 +21 -83
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +22 -84
- package/dist/index.js.map +1 -1
- package/docs/guides/customization.md +2 -2
- package/kubb-extension.json +14 -0
- package/package.json +7 -5
package/dist/index.cjs
CHANGED
|
@@ -31,12 +31,23 @@ let kubb_jsx_jsx_runtime = require("kubb/jsx/jsx-runtime");
|
|
|
31
31
|
*
|
|
32
32
|
* When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
|
|
33
33
|
*/
|
|
34
|
-
function
|
|
34
|
+
function convert(text, pascal) {
|
|
35
35
|
return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
|
|
36
36
|
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
37
37
|
return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
|
|
38
38
|
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
39
39
|
}
|
|
40
|
+
const cache = /* @__PURE__ */ new Map();
|
|
41
|
+
const cacheLimit = 1e4;
|
|
42
|
+
function toCamelOrPascal(text, pascal) {
|
|
43
|
+
const key = `${pascal ? "P" : "c"}${text}`;
|
|
44
|
+
const cached = cache.get(key);
|
|
45
|
+
if (cached !== void 0) return cached;
|
|
46
|
+
const result = convert(text, pascal);
|
|
47
|
+
if (cache.size >= cacheLimit) cache.clear();
|
|
48
|
+
cache.set(key, result);
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
40
51
|
/**
|
|
41
52
|
* Converts `text` to camelCase.
|
|
42
53
|
*
|
|
@@ -261,29 +272,16 @@ function stringify(value) {
|
|
|
261
272
|
return `'${JSON.stringify(trimQuotes(value.toString())).slice(1, -1).replace(/\\"/g, "\"").replace(/'/g, "\\'")}'`;
|
|
262
273
|
}
|
|
263
274
|
/**
|
|
264
|
-
* Escapes
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
* @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
|
|
275
|
+
* Escapes an `@` at the start of a line, so a multi-line description can't start a new JSDoc tag.
|
|
276
|
+
* Editors render `\@` as `@` in hovers.
|
|
268
277
|
*
|
|
269
278
|
* @example
|
|
270
279
|
* ```ts
|
|
271
|
-
*
|
|
280
|
+
* jsDocEscape('intro\n@example value') // 'intro\n\\@example value'
|
|
272
281
|
* ```
|
|
273
282
|
*/
|
|
274
|
-
function
|
|
275
|
-
return `${input}`.replace(
|
|
276
|
-
switch (character) {
|
|
277
|
-
case "\"":
|
|
278
|
-
case "'":
|
|
279
|
-
case "\\": return `\\${character}`;
|
|
280
|
-
case "\n": return "\\n";
|
|
281
|
-
case "\r": return "\\r";
|
|
282
|
-
case "\u2028": return "\\u2028";
|
|
283
|
-
case "\u2029": return "\\u2029";
|
|
284
|
-
default: return "";
|
|
285
|
-
}
|
|
286
|
-
});
|
|
283
|
+
function jsDocEscape(input) {
|
|
284
|
+
return `${input}`.replace(/^(\s*)@/gm, "$1\\@");
|
|
287
285
|
}
|
|
288
286
|
//#endregion
|
|
289
287
|
//#region ../../internals/utils/src/fs.ts
|
|
@@ -340,7 +338,7 @@ var factory_exports = /* @__PURE__ */ __exportAll({
|
|
|
340
338
|
* Loaded with `require`, not `import`. When ESM imports a CommonJS package, Node keeps a second
|
|
341
339
|
* copy of its source to detect named exports, and for TypeScript that copy is about 9 MB.
|
|
342
340
|
*/
|
|
343
|
-
const typescript = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("typescript");
|
|
341
|
+
const typescript = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("@typescript/typescript6");
|
|
344
342
|
const { SyntaxKind, factory } = typescript;
|
|
345
343
|
function isNumber(value) {
|
|
346
344
|
return typeof value === "number" && !Number.isNaN(value);
|
|
@@ -438,7 +436,7 @@ function createPropertySignature({ readOnly, modifiers = [], name, questionToken
|
|
|
438
436
|
function appendJSDocToNode({ node, comments }) {
|
|
439
437
|
const filteredComments = comments.filter(Boolean);
|
|
440
438
|
if (!filteredComments.length) return node;
|
|
441
|
-
const text = filteredComments.reduce((acc = "", comment = "") => {
|
|
439
|
+
const text = filteredComments.flatMap((comment = "") => comment.split(/\r?\n/)).reduce((acc = "", comment = "") => {
|
|
442
440
|
return `${acc}\n * ${comment.replaceAll("*/", "*\\/")}`;
|
|
443
441
|
}, "*");
|
|
444
442
|
return typescript.addSyntheticLeadingComment(node, typescript.SyntaxKind.MultiLineCommentTrivia, `${text || "*"}\n`, true);
|
|
@@ -1119,7 +1117,7 @@ function buildPropertyJSDocComments(schema, optional) {
|
|
|
1119
1117
|
const formatComment = meta && "format" in meta && meta.format ? hasDescription ? [" ", `Format: \`${meta.format}\``] : ["@description", `Format: \`${meta.format}\``] : [];
|
|
1120
1118
|
const exampleValues = meta?.examples ?? [];
|
|
1121
1119
|
const comments = [
|
|
1122
|
-
hasDescription ? `@description ${
|
|
1120
|
+
hasDescription ? `@description ${jsDocEscape(meta.description)}` : null,
|
|
1123
1121
|
...formatComment,
|
|
1124
1122
|
meta && "deprecated" in meta && meta.deprecated ? "@deprecated" : null,
|
|
1125
1123
|
!isArray && meta && "min" in meta && meta.min !== void 0 ? `@minLength ${meta.min}` : null,
|
|
@@ -1644,7 +1642,7 @@ var compatibility = {
|
|
|
1644
1642
|
};
|
|
1645
1643
|
//#endregion
|
|
1646
1644
|
//#region package.json
|
|
1647
|
-
var version = "5.0.
|
|
1645
|
+
var version = "5.0.16";
|
|
1648
1646
|
//#endregion
|
|
1649
1647
|
//#region src/resolvers/resolverTs.ts
|
|
1650
1648
|
/**
|
|
@@ -1690,53 +1688,6 @@ const resolverTs = (0, kubb_kit.createResolver)({
|
|
|
1690
1688
|
* cross-plugin dependency references.
|
|
1691
1689
|
*/
|
|
1692
1690
|
const pluginTsName = "plugin-ts";
|
|
1693
|
-
const allowedEnumTypes = [
|
|
1694
|
-
"asConst",
|
|
1695
|
-
"enum",
|
|
1696
|
-
"constEnum",
|
|
1697
|
-
"literal",
|
|
1698
|
-
"inlineLiteral"
|
|
1699
|
-
];
|
|
1700
|
-
const allowedSyntaxTypes = ["type", "interface"];
|
|
1701
|
-
const allowedArrayTypes = ["array", "generic"];
|
|
1702
|
-
const allowedOptionalTypes = [
|
|
1703
|
-
"questionToken",
|
|
1704
|
-
"undefined",
|
|
1705
|
-
"questionTokenAndUndefined"
|
|
1706
|
-
];
|
|
1707
|
-
/**
|
|
1708
|
-
* Throws when an enum-like option holds a value outside its allowed set. Options left out are skipped.
|
|
1709
|
-
*/
|
|
1710
|
-
function assertEnumLikeOptions({ prefix, options }) {
|
|
1711
|
-
const checks = [
|
|
1712
|
-
{
|
|
1713
|
-
option: "enum.type",
|
|
1714
|
-
value: options.enum?.type,
|
|
1715
|
-
allowed: allowedEnumTypes
|
|
1716
|
-
},
|
|
1717
|
-
{
|
|
1718
|
-
option: "syntaxType",
|
|
1719
|
-
value: options.syntaxType,
|
|
1720
|
-
allowed: allowedSyntaxTypes
|
|
1721
|
-
},
|
|
1722
|
-
{
|
|
1723
|
-
option: "arrayType",
|
|
1724
|
-
value: options.arrayType,
|
|
1725
|
-
allowed: allowedArrayTypes
|
|
1726
|
-
},
|
|
1727
|
-
{
|
|
1728
|
-
option: "optionalType",
|
|
1729
|
-
value: options.optionalType,
|
|
1730
|
-
allowed: allowedOptionalTypes
|
|
1731
|
-
}
|
|
1732
|
-
];
|
|
1733
|
-
for (const { option, value, allowed } of checks) if (value !== void 0) (0, kubb_kit.assertPluginOption)({
|
|
1734
|
-
plugin: pluginTsName,
|
|
1735
|
-
option: `${prefix}${option}`,
|
|
1736
|
-
value,
|
|
1737
|
-
allowed
|
|
1738
|
-
});
|
|
1739
|
-
}
|
|
1740
1691
|
/**
|
|
1741
1692
|
* Generates TypeScript `type` aliases and `interface` declarations from an
|
|
1742
1693
|
* OpenAPI spec. The foundation that every other Kubb plugin builds on:
|
|
@@ -1779,19 +1730,6 @@ const pluginTs = (0, kubb_kit.defineExtension)({
|
|
|
1779
1730
|
typeSuffix: enumOptions.typeSuffix ?? "Key",
|
|
1780
1731
|
keyCasing: enumOptions.keyCasing ?? "none"
|
|
1781
1732
|
};
|
|
1782
|
-
assertEnumLikeOptions({
|
|
1783
|
-
prefix: "",
|
|
1784
|
-
options: {
|
|
1785
|
-
enum: resolvedEnum,
|
|
1786
|
-
syntaxType,
|
|
1787
|
-
arrayType,
|
|
1788
|
-
optionalType
|
|
1789
|
-
}
|
|
1790
|
-
});
|
|
1791
|
-
for (const [index, entry] of override.entries()) assertEnumLikeOptions({
|
|
1792
|
-
prefix: `override[${index}].options.`,
|
|
1793
|
-
options: entry.options
|
|
1794
|
-
});
|
|
1795
1733
|
(0, kubb_kit.setResolver)(userResolver ? kubb_kit.Resolver.merge(resolverTs, userResolver) : resolverTs);
|
|
1796
1734
|
if (userMacros?.length) (0, kubb_kit.setMacros)(userMacros);
|
|
1797
1735
|
(0, kubb_kit.addGenerator)(typeGenerator);
|