@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.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
2
2
  import { KubbReactNode } from "kubb/jsx";
3
- import ts from "typescript";
3
+ import ts from "@typescript/typescript6";
4
4
  //#region src/printers/printerTs.d.ts
5
5
  /**
6
6
  * Partial map of node-type overrides for the TypeScript printer.
@@ -388,7 +388,7 @@ type Options = OutputOptions & {
388
388
  *
389
389
  * @example Use the JavaScript `Date` object for date schemas
390
390
  * ```ts
391
- * import ts from 'typescript'
391
+ * import ts from '@typescript/typescript6'
392
392
  * pluginTs({
393
393
  * printer: {
394
394
  * nodes: {
@@ -762,7 +762,7 @@ type FunctionPrinterOptions = {
762
762
  * ```
763
763
  */
764
764
  export declare function functionPrinter(options: FunctionPrinterOptions): {
765
- name: "functionParameters";
765
+ name: 'functionParameters';
766
766
  options: FunctionPrinterOptions;
767
767
  print(node: FunctionParametersNode): string;
768
768
  };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
2
2
  import { KubbReactNode } from "kubb/jsx";
3
- import ts from "typescript";
3
+ import ts from "@typescript/typescript6";
4
4
  //#region src/printers/printerTs.d.ts
5
5
  /**
6
6
  * Partial map of node-type overrides for the TypeScript printer.
@@ -388,7 +388,7 @@ type Options = OutputOptions & {
388
388
  *
389
389
  * @example Use the JavaScript `Date` object for date schemas
390
390
  * ```ts
391
- * import ts from 'typescript'
391
+ * import ts from '@typescript/typescript6'
392
392
  * pluginTs({
393
393
  * printer: {
394
394
  * nodes: {
@@ -762,7 +762,7 @@ type FunctionPrinterOptions = {
762
762
  * ```
763
763
  */
764
764
  export declare function functionPrinter(options: FunctionPrinterOptions): {
765
- name: "functionParameters";
765
+ name: 'functionParameters';
766
766
  options: FunctionPrinterOptions;
767
767
  print(node: FunctionParametersNode): string;
768
768
  };
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { parserTs } from "@kubb/parser-ts";
3
3
  import { File, jsxRenderer } from "kubb/jsx";
4
- import { Resolver, addGenerator, assertPluginOption, ast, createResolver, defineExtension, defineGenerator, isStringType, setMacros, setResolver, syncSchemaRef } from "kubb/kit";
4
+ import { Resolver, addGenerator, ast, createResolver, defineExtension, defineGenerator, isStringType, setMacros, setResolver, syncSchemaRef } from "kubb/kit";
5
5
  import { Fragment, jsx, jsxs } from "kubb/jsx/jsx-runtime";
6
6
  //#region \0rolldown/runtime.js
7
7
  var __defProp = Object.defineProperty;
@@ -27,12 +27,23 @@ var __exportAll = (all, no_symbols) => {
27
27
  *
28
28
  * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
29
29
  */
30
- function toCamelOrPascal(text, pascal) {
30
+ function convert(text, pascal) {
31
31
  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) => {
32
32
  if (word.length > 1 && word === word.toUpperCase()) return word;
33
33
  return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
34
34
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
35
35
  }
36
+ const cache = /* @__PURE__ */ new Map();
37
+ const cacheLimit = 1e4;
38
+ function toCamelOrPascal(text, pascal) {
39
+ const key = `${pascal ? "P" : "c"}${text}`;
40
+ const cached = cache.get(key);
41
+ if (cached !== void 0) return cached;
42
+ const result = convert(text, pascal);
43
+ if (cache.size >= cacheLimit) cache.clear();
44
+ cache.set(key, result);
45
+ return result;
46
+ }
36
47
  /**
37
48
  * Converts `text` to camelCase.
38
49
  *
@@ -257,29 +268,16 @@ function stringify(value) {
257
268
  return `'${JSON.stringify(trimQuotes(value.toString())).slice(1, -1).replace(/\\"/g, "\"").replace(/'/g, "\\'")}'`;
258
269
  }
259
270
  /**
260
- * Escapes characters that are not allowed inside JS string literals, covering quotes, backslashes,
261
- * and the Unicode line terminators U+2028 and U+2029.
262
- *
263
- * @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
271
+ * Escapes an `@` at the start of a line, so a multi-line description can't start a new JSDoc tag.
272
+ * Editors render `\@` as `@` in hovers.
264
273
  *
265
274
  * @example
266
275
  * ```ts
267
- * jsStringEscape('say "hi"\nbye') // 'say \\"hi\\"\\nbye'
276
+ * jsDocEscape('intro\n@example value') // 'intro\n\\@example value'
268
277
  * ```
269
278
  */
270
- function jsStringEscape(input) {
271
- return `${input}`.replace(/["'\\\n\r\u2028\u2029]/g, (character) => {
272
- switch (character) {
273
- case "\"":
274
- case "'":
275
- case "\\": return `\\${character}`;
276
- case "\n": return "\\n";
277
- case "\r": return "\\r";
278
- case "\u2028": return "\\u2028";
279
- case "\u2029": return "\\u2029";
280
- default: return "";
281
- }
282
- });
279
+ function jsDocEscape(input) {
280
+ return `${input}`.replace(/^(\s*)@/gm, "$1\\@");
283
281
  }
284
282
  //#endregion
285
283
  //#region ../../internals/utils/src/fs.ts
@@ -336,7 +334,7 @@ var factory_exports = /* @__PURE__ */ __exportAll({
336
334
  * Loaded with `require`, not `import`. When ESM imports a CommonJS package, Node keeps a second
337
335
  * copy of its source to detect named exports, and for TypeScript that copy is about 9 MB.
338
336
  */
339
- const typescript = createRequire(import.meta.url)("typescript");
337
+ const typescript = createRequire(import.meta.url)("@typescript/typescript6");
340
338
  const { SyntaxKind, factory } = typescript;
341
339
  function isNumber(value) {
342
340
  return typeof value === "number" && !Number.isNaN(value);
@@ -434,7 +432,7 @@ function createPropertySignature({ readOnly, modifiers = [], name, questionToken
434
432
  function appendJSDocToNode({ node, comments }) {
435
433
  const filteredComments = comments.filter(Boolean);
436
434
  if (!filteredComments.length) return node;
437
- const text = filteredComments.reduce((acc = "", comment = "") => {
435
+ const text = filteredComments.flatMap((comment = "") => comment.split(/\r?\n/)).reduce((acc = "", comment = "") => {
438
436
  return `${acc}\n * ${comment.replaceAll("*/", "*\\/")}`;
439
437
  }, "*");
440
438
  return typescript.addSyntheticLeadingComment(node, typescript.SyntaxKind.MultiLineCommentTrivia, `${text || "*"}\n`, true);
@@ -1115,7 +1113,7 @@ function buildPropertyJSDocComments(schema, optional) {
1115
1113
  const formatComment = meta && "format" in meta && meta.format ? hasDescription ? [" ", `Format: \`${meta.format}\``] : ["@description", `Format: \`${meta.format}\``] : [];
1116
1114
  const exampleValues = meta?.examples ?? [];
1117
1115
  const comments = [
1118
- hasDescription ? `@description ${jsStringEscape(meta.description)}` : null,
1116
+ hasDescription ? `@description ${jsDocEscape(meta.description)}` : null,
1119
1117
  ...formatComment,
1120
1118
  meta && "deprecated" in meta && meta.deprecated ? "@deprecated" : null,
1121
1119
  !isArray && meta && "min" in meta && meta.min !== void 0 ? `@minLength ${meta.min}` : null,
@@ -1640,7 +1638,7 @@ var compatibility = {
1640
1638
  };
1641
1639
  //#endregion
1642
1640
  //#region package.json
1643
- var version = "5.0.14";
1641
+ var version = "5.0.16";
1644
1642
  //#endregion
1645
1643
  //#region src/resolvers/resolverTs.ts
1646
1644
  /**
@@ -1686,53 +1684,6 @@ const resolverTs = createResolver({
1686
1684
  * cross-plugin dependency references.
1687
1685
  */
1688
1686
  const pluginTsName = "plugin-ts";
1689
- const allowedEnumTypes = [
1690
- "asConst",
1691
- "enum",
1692
- "constEnum",
1693
- "literal",
1694
- "inlineLiteral"
1695
- ];
1696
- const allowedSyntaxTypes = ["type", "interface"];
1697
- const allowedArrayTypes = ["array", "generic"];
1698
- const allowedOptionalTypes = [
1699
- "questionToken",
1700
- "undefined",
1701
- "questionTokenAndUndefined"
1702
- ];
1703
- /**
1704
- * Throws when an enum-like option holds a value outside its allowed set. Options left out are skipped.
1705
- */
1706
- function assertEnumLikeOptions({ prefix, options }) {
1707
- const checks = [
1708
- {
1709
- option: "enum.type",
1710
- value: options.enum?.type,
1711
- allowed: allowedEnumTypes
1712
- },
1713
- {
1714
- option: "syntaxType",
1715
- value: options.syntaxType,
1716
- allowed: allowedSyntaxTypes
1717
- },
1718
- {
1719
- option: "arrayType",
1720
- value: options.arrayType,
1721
- allowed: allowedArrayTypes
1722
- },
1723
- {
1724
- option: "optionalType",
1725
- value: options.optionalType,
1726
- allowed: allowedOptionalTypes
1727
- }
1728
- ];
1729
- for (const { option, value, allowed } of checks) if (value !== void 0) assertPluginOption({
1730
- plugin: pluginTsName,
1731
- option: `${prefix}${option}`,
1732
- value,
1733
- allowed
1734
- });
1735
- }
1736
1687
  /**
1737
1688
  * Generates TypeScript `type` aliases and `interface` declarations from an
1738
1689
  * OpenAPI spec. The foundation that every other Kubb plugin builds on:
@@ -1775,19 +1726,6 @@ const pluginTs = defineExtension({
1775
1726
  typeSuffix: enumOptions.typeSuffix ?? "Key",
1776
1727
  keyCasing: enumOptions.keyCasing ?? "none"
1777
1728
  };
1778
- assertEnumLikeOptions({
1779
- prefix: "",
1780
- options: {
1781
- enum: resolvedEnum,
1782
- syntaxType,
1783
- arrayType,
1784
- optionalType
1785
- }
1786
- });
1787
- for (const [index, entry] of override.entries()) assertEnumLikeOptions({
1788
- prefix: `override[${index}].options.`,
1789
- options: entry.options
1790
- });
1791
1729
  setResolver(userResolver ? Resolver.merge(resolverTs, userResolver) : resolverTs);
1792
1730
  if (userMacros?.length) setMacros(userMacros);
1793
1731
  addGenerator(typeGenerator);