@kubb/plugin-ts 5.0.3 → 5.0.5

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/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
  [![Node][node-src]][node-href]
11
11
 
12
12
  <h4>
13
- <a href="https://kubb.dev/plugins/ts" target="_blank">Documentation</a>
13
+ <a href="https://kubb.dev/plugins/plugin-ts" target="_blank">Documentation</a>
14
14
  <span> · </span>
15
15
  <a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
16
16
  <span> · </span>
@@ -38,7 +38,7 @@ npm install @kubb/plugin-ts
38
38
 
39
39
  ## Documentation
40
40
 
41
- See the [full documentation](https://kubb.dev/plugins/ts) for configuration options and examples.
41
+ See the [full documentation](https://kubb.dev/plugins/plugin-ts) for configuration options and examples.
42
42
 
43
43
  ## Supporting Kubb
44
44
 
package/dist/index.cjs CHANGED
@@ -3,16 +3,11 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  //#region \0rolldown/runtime.js
6
- var __create = Object.create;
7
6
  var __defProp = Object.defineProperty;
8
7
  var __name = (target, value) => __defProp(target, "name", {
9
8
  value,
10
9
  configurable: true
11
10
  });
12
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
- var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
- var __hasOwnProp = Object.prototype.hasOwnProperty;
16
11
  var __exportAll = (all, no_symbols) => {
17
12
  let target = {};
18
13
  for (var name in all) __defProp(target, name, {
@@ -22,26 +17,11 @@ var __exportAll = (all, no_symbols) => {
22
17
  if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
23
18
  return target;
24
19
  };
25
- var __copyProps = (to, from, except, desc) => {
26
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
27
- key = keys[i];
28
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
29
- get: ((k) => from[k]).bind(null, key),
30
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
31
- });
32
- }
33
- return to;
34
- };
35
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
36
- value: mod,
37
- enumerable: true
38
- }) : target, mod));
39
20
  //#endregion
40
21
  let _kubb_parser_ts = require("@kubb/parser-ts");
41
22
  let kubb_jsx = require("kubb/jsx");
23
+ let node_module = require("node:module");
42
24
  let kubb_kit = require("kubb/kit");
43
- let typescript = require("typescript");
44
- typescript = __toESM(typescript, 1);
45
25
  let kubb_jsx_jsx_runtime = require("kubb/jsx/jsx-runtime");
46
26
  //#region ../../internals/utils/src/casing.ts
47
27
  /**
@@ -401,7 +381,12 @@ var factory_exports = /* @__PURE__ */ __exportAll({
401
381
  modifiers: () => modifiers,
402
382
  syntaxKind: () => syntaxKind
403
383
  });
404
- const { SyntaxKind, factory } = typescript.default;
384
+ /**
385
+ * Loaded with `require`, not `import`. When ESM imports a CommonJS package, Node keeps a second
386
+ * copy of its source to detect named exports, and for TypeScript that copy is about 9 MB.
387
+ */
388
+ const typescript = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("typescript");
389
+ const { SyntaxKind, factory } = typescript;
405
390
  /**
406
391
  * Compares two strings by UTF-16 code unit, keeping sorted output identical across platforms
407
392
  * regardless of locale.
@@ -418,10 +403,10 @@ function isNumber(value) {
418
403
  * TypeScript AST modifiers for common keywords (async, export, const, static).
419
404
  */
420
405
  const modifiers = {
421
- async: factory.createModifier(typescript.default.SyntaxKind.AsyncKeyword),
422
- export: factory.createModifier(typescript.default.SyntaxKind.ExportKeyword),
423
- const: factory.createModifier(typescript.default.SyntaxKind.ConstKeyword),
424
- static: factory.createModifier(typescript.default.SyntaxKind.StaticKeyword)
406
+ async: factory.createModifier(typescript.SyntaxKind.AsyncKeyword),
407
+ export: factory.createModifier(typescript.SyntaxKind.ExportKeyword),
408
+ const: factory.createModifier(typescript.SyntaxKind.ConstKeyword),
409
+ static: factory.createModifier(typescript.SyntaxKind.StaticKeyword)
425
410
  };
426
411
  /**
427
412
  * TypeScript syntax kind constants for union, literal, and string types.
@@ -438,10 +423,10 @@ __name(isNonNullable$1, "isNonNullable");
438
423
  function isValidIdentifier(str) {
439
424
  if (!str.length || str.trim() !== str) return false;
440
425
  let ch = str.codePointAt(0);
441
- if (!typescript.default.isIdentifierStart(ch, typescript.default.ScriptTarget.Latest)) return false;
426
+ if (!typescript.isIdentifierStart(ch, typescript.ScriptTarget.Latest)) return false;
442
427
  for (let i = ch > 65535 ? 2 : 1; i < str.length; i += ch > 65535 ? 2 : 1) {
443
428
  ch = str.codePointAt(i);
444
- if (!typescript.default.isIdentifierPart(ch, typescript.default.ScriptTarget.Latest)) return false;
429
+ if (!typescript.isIdentifierPart(ch, typescript.ScriptTarget.Latest)) return false;
445
430
  }
446
431
  return true;
447
432
  }
@@ -449,7 +434,7 @@ function propertyName(name) {
449
434
  if (typeof name === "string") return isValidIdentifier(name) ? factory.createIdentifier(name) : factory.createStringLiteral(name);
450
435
  return name;
451
436
  }
452
- const questionToken = factory.createToken(typescript.default.SyntaxKind.QuestionToken);
437
+ const questionToken = factory.createToken(typescript.SyntaxKind.QuestionToken);
453
438
  /**
454
439
  * Creates a question token for optional type annotations.
455
440
  * Pass `true` to use the cached token, or provide a pre-created token.
@@ -509,7 +494,7 @@ function createUnionDeclaration({ nodes, withParentheses }) {
509
494
  * Supports optional markers, readonly modifiers, and type annotations.
510
495
  */
511
496
  function createPropertySignature({ readOnly, modifiers = [], name, questionToken, type }) {
512
- return factory.createPropertySignature([...modifiers, readOnly ? factory.createToken(typescript.default.SyntaxKind.ReadonlyKeyword) : void 0].filter((modifier) => modifier !== void 0), propertyName(name), createQuestionToken(questionToken), type);
497
+ return factory.createPropertySignature([...modifiers, readOnly ? factory.createToken(typescript.SyntaxKind.ReadonlyKeyword) : void 0].filter((modifier) => modifier !== void 0), propertyName(name), createQuestionToken(questionToken), type);
513
498
  }
514
499
  /**
515
500
  * Creates a function parameter declaration with optional markers, rest parameters, and type annotations.
@@ -540,13 +525,13 @@ function appendJSDocToNode({ node, comments }) {
540
525
  const text = filteredComments.reduce((acc = "", comment = "") => {
541
526
  return `${acc}\n * ${comment.replaceAll("*/", "*\\/")}`;
542
527
  }, "*");
543
- return typescript.default.addSyntheticLeadingComment(node, typescript.default.SyntaxKind.MultiLineCommentTrivia, `${text || "*"}\n`, true);
528
+ return typescript.addSyntheticLeadingComment(node, typescript.SyntaxKind.MultiLineCommentTrivia, `${text || "*"}\n`, true);
544
529
  }
545
530
  /**
546
531
  * Creates a TypeScript index signature for dynamic property access.
547
532
  * Defines the key type (default: `string`) and value type on an object.
548
533
  */
549
- function createIndexSignature(type, { modifiers, indexName = "key", indexType = factory.createKeywordTypeNode(typescript.default.SyntaxKind.StringKeyword) } = {}) {
534
+ function createIndexSignature(type, { modifiers, indexName = "key", indexType = factory.createKeywordTypeNode(typescript.SyntaxKind.StringKeyword) } = {}) {
550
535
  return factory.createIndexSignature(modifiers, [createParameterSignature(indexName, { type: indexType })], type);
551
536
  }
552
537
  /**
@@ -566,7 +551,7 @@ function createInterfaceDeclaration({ modifiers, name, typeParameters, members }
566
551
  * Intelligently selects the syntax based on the type structure and attaches JSDoc comments.
567
552
  */
568
553
  function createTypeDeclaration({ syntax, isExportable, comments, name, type }) {
569
- if (syntax === "interface" && typescript.default.isTypeLiteralNode(type)) return appendJSDocToNode({
554
+ if (syntax === "interface" && typescript.isTypeLiteralNode(type)) return appendJSDocToNode({
570
555
  node: createInterfaceDeclaration({
571
556
  members: [...type.members],
572
557
  modifiers: isExportable ? [modifiers.export] : [],
@@ -655,18 +640,18 @@ function applyEnumKeyCasing(key, casing = "none") {
655
640
  * ```
656
641
  */
657
642
  function createEnumDeclaration({ type = "enum", name, typeName, enums, enumKeyCasing = "none" }) {
658
- if (type === "literal" || type === "inlineLiteral") return [void 0, factory.createTypeAliasDeclaration([factory.createToken(typescript.default.SyntaxKind.ExportKeyword)], factory.createIdentifier(typeName), void 0, factory.createUnionTypeNode(enums.map(([_key, value]) => {
643
+ if (type === "literal" || type === "inlineLiteral") return [void 0, factory.createTypeAliasDeclaration([factory.createToken(typescript.SyntaxKind.ExportKeyword)], factory.createIdentifier(typeName), void 0, factory.createUnionTypeNode(enums.map(([_key, value]) => {
659
644
  if (isNumber(value)) {
660
- if (value < 0) return factory.createLiteralTypeNode(factory.createPrefixUnaryExpression(typescript.default.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value))));
645
+ if (value < 0) return factory.createLiteralTypeNode(factory.createPrefixUnaryExpression(typescript.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value))));
661
646
  return factory.createLiteralTypeNode(factory.createNumericLiteral(value?.toString()));
662
647
  }
663
648
  if (typeof value === "boolean") return factory.createLiteralTypeNode(value ? factory.createTrue() : factory.createFalse());
664
649
  if (value !== null && value !== void 0) return factory.createLiteralTypeNode(factory.createStringLiteral(value.toString()));
665
650
  }).filter((node) => node !== void 0)))];
666
- if (type === "enum" || type === "constEnum") return [void 0, factory.createEnumDeclaration([factory.createToken(typescript.default.SyntaxKind.ExportKeyword), type === "constEnum" ? factory.createToken(typescript.default.SyntaxKind.ConstKeyword) : void 0].filter((modifier) => modifier !== void 0), factory.createIdentifier(typeName), enums.map(([key, value, description]) => {
651
+ if (type === "enum" || type === "constEnum") return [void 0, factory.createEnumDeclaration([factory.createToken(typescript.SyntaxKind.ExportKeyword), type === "constEnum" ? factory.createToken(typescript.SyntaxKind.ConstKeyword) : void 0].filter((modifier) => modifier !== void 0), factory.createIdentifier(typeName), enums.map(([key, value, description]) => {
667
652
  let initializer = factory.createStringLiteral(value?.toString());
668
653
  if (Number.parseInt(value.toString(), 10) === value && isNumber(value)) {
669
- if (value < 0) initializer = factory.createPrefixUnaryExpression(typescript.default.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)));
654
+ if (value < 0) initializer = factory.createPrefixUnaryExpression(typescript.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)));
670
655
  else initializer = factory.createNumericLiteral(value);
671
656
  }
672
657
  if (typeof value === "boolean") initializer = value ? factory.createTrue() : factory.createFalse();
@@ -686,11 +671,11 @@ function createEnumDeclaration({ type = "enum", name, typeName, enums, enumKeyCa
686
671
  }
687
672
  }).filter((member) => member !== void 0))];
688
673
  const identifierName = name;
689
- if (enums.length === 0) return [void 0, factory.createTypeAliasDeclaration([factory.createToken(typescript.default.SyntaxKind.ExportKeyword)], factory.createIdentifier(typeName), void 0, factory.createKeywordTypeNode(typescript.default.SyntaxKind.NeverKeyword))];
690
- return [factory.createVariableStatement([factory.createToken(typescript.default.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier(identifierName), void 0, void 0, factory.createAsExpression(factory.createObjectLiteralExpression(enums.map(([key, value, description]) => {
674
+ if (enums.length === 0) return [void 0, factory.createTypeAliasDeclaration([factory.createToken(typescript.SyntaxKind.ExportKeyword)], factory.createIdentifier(typeName), void 0, factory.createKeywordTypeNode(typescript.SyntaxKind.NeverKeyword))];
675
+ return [factory.createVariableStatement([factory.createToken(typescript.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier(identifierName), void 0, void 0, factory.createAsExpression(factory.createObjectLiteralExpression(enums.map(([key, value, description]) => {
691
676
  let initializer = factory.createStringLiteral(value?.toString());
692
677
  if (isNumber(value)) {
693
- if (value < 0) initializer = factory.createPrefixUnaryExpression(typescript.default.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)));
678
+ if (value < 0) initializer = factory.createPrefixUnaryExpression(typescript.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)));
694
679
  else initializer = factory.createNumericLiteral(value);
695
680
  }
696
681
  if (typeof value === "boolean") initializer = value ? factory.createTrue() : factory.createFalse();
@@ -701,7 +686,7 @@ function createEnumDeclaration({ type = "enum", name, typeName, enums, enumKeyCa
701
686
  comments: [description]
702
687
  });
703
688
  }
704
- }).filter((property) => property !== void 0), true), factory.createTypeReferenceNode(factory.createIdentifier("const"), void 0)))], typescript.default.NodeFlags.Const)), factory.createTypeAliasDeclaration([factory.createToken(typescript.default.SyntaxKind.ExportKeyword)], factory.createIdentifier(typeName), void 0, factory.createIndexedAccessTypeNode(factory.createParenthesizedType(factory.createTypeQueryNode(factory.createIdentifier(identifierName), void 0)), factory.createTypeOperatorNode(typescript.default.SyntaxKind.KeyOfKeyword, factory.createTypeQueryNode(factory.createIdentifier(identifierName), void 0))))];
689
+ }).filter((property) => property !== void 0), true), factory.createTypeReferenceNode(factory.createIdentifier("const"), void 0)))], typescript.NodeFlags.Const)), factory.createTypeAliasDeclaration([factory.createToken(typescript.SyntaxKind.ExportKeyword)], factory.createIdentifier(typeName), void 0, factory.createIndexedAccessTypeNode(factory.createParenthesizedType(factory.createTypeQueryNode(factory.createIdentifier(identifierName), void 0)), factory.createTypeOperatorNode(typescript.SyntaxKind.KeyOfKeyword, factory.createTypeQueryNode(factory.createIdentifier(identifierName), void 0))))];
705
690
  }
706
691
  /**
707
692
  * Creates a TypeScript `Omit<T, Keys>` type reference node.
@@ -719,18 +704,18 @@ function createOmitDeclaration({ keys, type, nonNullable }) {
719
704
  * Use these to avoid repeatedly creating the same type nodes.
720
705
  */
721
706
  const keywordTypeNodes = {
722
- any: factory.createKeywordTypeNode(typescript.default.SyntaxKind.AnyKeyword),
723
- unknown: factory.createKeywordTypeNode(typescript.default.SyntaxKind.UnknownKeyword),
724
- void: factory.createKeywordTypeNode(typescript.default.SyntaxKind.VoidKeyword),
725
- number: factory.createKeywordTypeNode(typescript.default.SyntaxKind.NumberKeyword),
726
- integer: factory.createKeywordTypeNode(typescript.default.SyntaxKind.NumberKeyword),
727
- bigint: factory.createKeywordTypeNode(typescript.default.SyntaxKind.BigIntKeyword),
728
- object: factory.createKeywordTypeNode(typescript.default.SyntaxKind.ObjectKeyword),
729
- string: factory.createKeywordTypeNode(typescript.default.SyntaxKind.StringKeyword),
730
- boolean: factory.createKeywordTypeNode(typescript.default.SyntaxKind.BooleanKeyword),
731
- undefined: factory.createKeywordTypeNode(typescript.default.SyntaxKind.UndefinedKeyword),
732
- null: factory.createLiteralTypeNode(factory.createToken(typescript.default.SyntaxKind.NullKeyword)),
733
- never: factory.createKeywordTypeNode(typescript.default.SyntaxKind.NeverKeyword)
707
+ any: factory.createKeywordTypeNode(typescript.SyntaxKind.AnyKeyword),
708
+ unknown: factory.createKeywordTypeNode(typescript.SyntaxKind.UnknownKeyword),
709
+ void: factory.createKeywordTypeNode(typescript.SyntaxKind.VoidKeyword),
710
+ number: factory.createKeywordTypeNode(typescript.SyntaxKind.NumberKeyword),
711
+ integer: factory.createKeywordTypeNode(typescript.SyntaxKind.NumberKeyword),
712
+ bigint: factory.createKeywordTypeNode(typescript.SyntaxKind.BigIntKeyword),
713
+ object: factory.createKeywordTypeNode(typescript.SyntaxKind.ObjectKeyword),
714
+ string: factory.createKeywordTypeNode(typescript.SyntaxKind.StringKeyword),
715
+ boolean: factory.createKeywordTypeNode(typescript.SyntaxKind.BooleanKeyword),
716
+ undefined: factory.createKeywordTypeNode(typescript.SyntaxKind.UndefinedKeyword),
717
+ null: factory.createLiteralTypeNode(factory.createToken(typescript.SyntaxKind.NullKeyword)),
718
+ never: factory.createKeywordTypeNode(typescript.SyntaxKind.NeverKeyword)
734
719
  };
735
720
  /**
736
721
  * Converts a path like '/pet/{petId}/uploadImage' to a template literal type
@@ -753,15 +738,15 @@ function createUrlTemplateType(path) {
753
738
  parts.push(segment);
754
739
  } else if (segment) parts.push(segment);
755
740
  });
756
- const head = typescript.default.factory.createTemplateHead(parts[0] || "");
741
+ const head = typescript.factory.createTemplateHead(parts[0] || "");
757
742
  const templateSpans = [];
758
743
  parameterIndices.forEach((paramIndex, i) => {
759
744
  const isLast = i === parameterIndices.length - 1;
760
745
  const nextPart = parts[paramIndex + 1] || "";
761
- const literal = isLast ? typescript.default.factory.createTemplateTail(nextPart) : typescript.default.factory.createTemplateMiddle(nextPart);
762
- templateSpans.push(typescript.default.factory.createTemplateLiteralTypeSpan(keywordTypeNodes.string, literal));
746
+ const literal = isLast ? typescript.factory.createTemplateTail(nextPart) : typescript.factory.createTemplateMiddle(nextPart);
747
+ templateSpans.push(typescript.factory.createTemplateLiteralTypeSpan(keywordTypeNodes.string, literal));
763
748
  });
764
- return typescript.default.factory.createTemplateLiteralType(head, templateSpans);
749
+ return typescript.factory.createTemplateLiteralType(head, templateSpans);
765
750
  }
766
751
  /**
767
752
  * Creates a TypeScript type literal node (anonymous object type).
@@ -866,8 +851,8 @@ function buildPropertyType(schema, baseType, optionalType, optional) {
866
851
  if ((optional || meta.nullish || meta.optional) && addsUndefined) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
867
852
  return type;
868
853
  }
869
- const indexSignaturePrinter = typescript.default.createPrinter();
870
- const indexSignatureSource = typescript.default.createSourceFile("", "", typescript.default.ScriptTarget.Latest);
854
+ const indexSignaturePrinter = typescript.createPrinter();
855
+ const indexSignatureSource = typescript.createSourceFile("", "", typescript.ScriptTarget.Latest);
871
856
  /**
872
857
  * Creates a TypeScript index signature for `additionalProperties` and `patternProperties` on an
873
858
  * object schema node. TypeScript allows only one string index signature and its value must be
@@ -886,7 +871,7 @@ function buildIndexSignatures(node, propertyCount, print) {
886
871
  if (valueTypes.length === 0) return [];
887
872
  const seen = /* @__PURE__ */ new Set();
888
873
  const distinct = valueTypes.filter((type) => {
889
- const key = indexSignaturePrinter.printNode(typescript.default.EmitHint.Unspecified, type, indexSignatureSource);
874
+ const key = indexSignaturePrinter.printNode(typescript.EmitHint.Unspecified, type, indexSignatureSource);
890
875
  return seen.has(key) ? false : (seen.add(key), true);
891
876
  });
892
877
  return [createIndexSignature(propertyCount > 0 ? keywordTypeNodes.unknown : createUnionDeclaration({ nodes: distinct }))];
@@ -954,115 +939,6 @@ function Enum({ node, enum: enumOptions, resolver }) {
954
939
  })] });
955
940
  }
956
941
  //#endregion
957
- //#region src/utils.ts
958
- /**
959
- * Tells whether a `const` (single-value enum) should render as a bare literal type (`'active'`)
960
- * rather than a named enum reference or a runtime enum declaration.
961
- *
962
- * The parser folds `const` into a single-value enum node. The adapter decides which schemas are
963
- * named enums and lists them in `enumSchemaNames`, and references to those names get suffixed (for
964
- * example `StatusKey`). A const renders as a literal only when the adapter has not registered it as
965
- * a named enum, which keeps the declaration and its references in sync across adapter versions.
966
- */
967
- function isInlineConstEnum(node, enumSchemaNames) {
968
- return (node.namedEnumValues ?? node.enumValues ?? []).length === 1 && !(node.name && enumSchemaNames?.has(node.name));
969
- }
970
- /**
971
- * Collects JSDoc annotation strings for a schema node.
972
- *
973
- * Only uses official JSDoc tags from https://jsdoc.app/: `@description`, `@deprecated`, `@default`, `@example`, `@type`.
974
- * Constraint metadata (min/max length, pattern, multipleOf, min/maxProperties) is emitted as plain-text lines.
975
-
976
- */
977
- function isSchemaOptional(schema) {
978
- return Boolean("optional" in schema && schema.optional || "nullish" in schema && schema.nullish);
979
- }
980
- function formatExample(value) {
981
- if (value === null || typeof value !== "object") return String(value);
982
- return (JSON.stringify(value) ?? String(value)).replaceAll("*/", "*\\/");
983
- }
984
- function buildPropertyJSDocComments(schema, optional) {
985
- const meta = (0, kubb_kit.syncSchemaRef)(schema);
986
- const isArray = meta?.primitive === "array";
987
- const hasDescription = meta && "description" in meta && meta.description;
988
- const formatComment = meta && "format" in meta && meta.format ? hasDescription ? [" ", `Format: \`${meta.format}\``] : ["@description", `Format: \`${meta.format}\``] : [];
989
- const exampleValues = meta?.examples ?? [];
990
- const comments = [
991
- hasDescription ? `@description ${jsStringEscape(meta.description)}` : null,
992
- ...formatComment,
993
- meta && "deprecated" in meta && meta.deprecated ? "@deprecated" : null,
994
- !isArray && meta && "min" in meta && meta.min !== void 0 ? `@minLength ${meta.min}` : null,
995
- !isArray && meta && "max" in meta && meta.max !== void 0 ? `@maxLength ${meta.max}` : null,
996
- meta && "pattern" in meta && meta.pattern ? `@pattern ${meta.pattern}` : null,
997
- meta && "default" in meta && meta.default !== void 0 ? `@default ${"primitive" in meta && meta.primitive === "string" && typeof meta.default === "string" ? stringify(meta.default) : meta.default}` : null,
998
- ...exampleValues.map((example) => `@example ${formatExample(example)}`)
999
- ].filter(Boolean);
1000
- const typeTag = comments.length && meta && "primitive" in meta && meta.primitive ? [`@type ${meta.primitive}`, optional ?? isSchemaOptional(schema) ? " | undefined" : null].filter(Boolean).join("") : null;
1001
- return [...comments, typeTag].filter(Boolean);
1002
- }
1003
- /**
1004
- * Builds the object schema for a group of parameters sharing one `in` location (path, query, or
1005
- * header), embedding each param's own schema (and JSDoc) directly rather than referencing a
1006
- * separate per-param type — the group itself is the only type these params get exported as.
1007
- */
1008
- function buildParams({ params }) {
1009
- return kubb_kit.ast.factory.createSchema({
1010
- type: "object",
1011
- properties: params.map((param) => kubb_kit.ast.factory.createProperty({
1012
- name: param.name,
1013
- required: param.required,
1014
- schema: kubb_kit.ast.factory.createSchema({
1015
- ...param.schema,
1016
- optional: !param.required
1017
- })
1018
- }))
1019
- });
1020
- }
1021
- function buildResponseUnion(node, { resolver }) {
1022
- const responsesWithSchema = node.responses.filter((res) => res.content?.some((entry) => entry.schema));
1023
- if (responsesWithSchema.length === 0) return null;
1024
- return kubb_kit.ast.factory.createSchema({
1025
- type: "union",
1026
- members: responsesWithSchema.map((res) => kubb_kit.ast.factory.createSchema({
1027
- type: "ref",
1028
- name: resolver.response.status(node, res.statusCode)
1029
- }))
1030
- });
1031
- }
1032
- //#endregion
1033
- //#region src/components/Type.tsx
1034
- function Type({ name, node, printer, enum: enumOptions, resolver }) {
1035
- const enumSchemaNodes = kubb_kit.ast.collectSync(node, { schema(n) {
1036
- const enumNode = kubb_kit.ast.narrowSchema(n, kubb_kit.ast.schemaTypes.enum);
1037
- if (enumNode?.name && !isInlineConstEnum(enumNode, printer.options.enumSchemaNames)) return enumNode;
1038
- } });
1039
- const output = printer.print(node);
1040
- if (!output) return;
1041
- const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((node) => {
1042
- return {
1043
- node,
1044
- ...getEnumNames({
1045
- node,
1046
- enum: enumOptions,
1047
- resolver
1048
- })
1049
- };
1050
- });
1051
- const shouldExportEnums = enumOptions.type !== "inlineLiteral";
1052
- const shouldExportType = enumOptions.type === "inlineLiteral" || enums.every((item) => item.typeName !== name);
1053
- return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [shouldExportEnums && enums.map(({ node }) => /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(Enum, {
1054
- node,
1055
- enum: enumOptions,
1056
- resolver
1057
- }, node.name)), shouldExportType && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1058
- name,
1059
- isTypeOnly: true,
1060
- isExportable: true,
1061
- isIndexable: true,
1062
- children: output
1063
- })] });
1064
- }
1065
- //#endregion
1066
942
  //#region ../../internals/shared/src/params.ts
1067
943
  /**
1068
944
  * Drops parameters that share the same name, keeping the first.
@@ -1262,6 +1138,14 @@ function buildResponses(node, resolver) {
1262
1138
  }))
1263
1139
  });
1264
1140
  }
1141
+ function getStatusCodeNumber(statusCode) {
1142
+ const code = Number(statusCode);
1143
+ return Number.isNaN(code) ? null : code;
1144
+ }
1145
+ function isSuccessStatusCode(statusCode) {
1146
+ const code = getStatusCodeNumber(statusCode);
1147
+ return code !== null && code >= 200 && code < 300;
1148
+ }
1265
1149
  //#endregion
1266
1150
  //#region ../../internals/shared/src/resolver.ts
1267
1151
  /**
@@ -1412,6 +1296,117 @@ function mapSchemaItems(node, transform) {
1412
1296
  }));
1413
1297
  }
1414
1298
  //#endregion
1299
+ //#region src/utils.ts
1300
+ /**
1301
+ * Tells whether a `const` (single-value enum) should render as a bare literal type (`'active'`)
1302
+ * rather than a named enum reference or a runtime enum declaration.
1303
+ *
1304
+ * The parser folds `const` into a single-value enum node. The adapter decides which schemas are
1305
+ * named enums and lists them in `enumSchemaNames`, and references to those names get suffixed (for
1306
+ * example `StatusKey`). A const renders as a literal only when the adapter has not registered it as
1307
+ * a named enum, which keeps the declaration and its references in sync across adapter versions.
1308
+ */
1309
+ function isInlineConstEnum(node, enumSchemaNames) {
1310
+ return (node.namedEnumValues ?? node.enumValues ?? []).length === 1 && !(node.name && enumSchemaNames?.has(node.name));
1311
+ }
1312
+ /**
1313
+ * Collects JSDoc annotation strings for a schema node.
1314
+ *
1315
+ * Only uses official JSDoc tags from https://jsdoc.app/: `@description`, `@deprecated`, `@default`, `@example`, `@type`.
1316
+ * Constraint metadata (min/max length, pattern, multipleOf, min/maxProperties) is emitted as plain-text lines.
1317
+
1318
+ */
1319
+ function isSchemaOptional(schema) {
1320
+ return Boolean("optional" in schema && schema.optional || "nullish" in schema && schema.nullish);
1321
+ }
1322
+ function formatExample(value) {
1323
+ if (value === null || typeof value !== "object") return String(value);
1324
+ return (JSON.stringify(value) ?? String(value)).replaceAll("*/", "*\\/");
1325
+ }
1326
+ function buildPropertyJSDocComments(schema, optional) {
1327
+ const meta = (0, kubb_kit.syncSchemaRef)(schema);
1328
+ const isArray = meta?.primitive === "array";
1329
+ const hasDescription = meta && "description" in meta && meta.description;
1330
+ const formatComment = meta && "format" in meta && meta.format ? hasDescription ? [" ", `Format: \`${meta.format}\``] : ["@description", `Format: \`${meta.format}\``] : [];
1331
+ const exampleValues = meta?.examples ?? [];
1332
+ const comments = [
1333
+ hasDescription ? `@description ${jsStringEscape(meta.description)}` : null,
1334
+ ...formatComment,
1335
+ meta && "deprecated" in meta && meta.deprecated ? "@deprecated" : null,
1336
+ !isArray && meta && "min" in meta && meta.min !== void 0 ? `@minLength ${meta.min}` : null,
1337
+ !isArray && meta && "max" in meta && meta.max !== void 0 ? `@maxLength ${meta.max}` : null,
1338
+ meta && "pattern" in meta && meta.pattern ? `@pattern ${meta.pattern}` : null,
1339
+ meta && "default" in meta && meta.default !== void 0 ? `@default ${"primitive" in meta && meta.primitive === "string" && typeof meta.default === "string" ? stringify(meta.default) : meta.default}` : null,
1340
+ ...exampleValues.map((example) => `@example ${formatExample(example)}`)
1341
+ ].filter(Boolean);
1342
+ const typeTag = comments.length && meta && "primitive" in meta && meta.primitive ? [`@type ${meta.primitive}`, optional ?? isSchemaOptional(schema) ? " | undefined" : null].filter(Boolean).join("") : null;
1343
+ return [...comments, typeTag].filter(Boolean);
1344
+ }
1345
+ /**
1346
+ * Builds the object schema for a group of parameters sharing one `in` location (path, query, or
1347
+ * header), embedding each param's own schema (and JSDoc) directly rather than referencing a
1348
+ * separate per-param type — the group itself is the only type these params get exported as.
1349
+ */
1350
+ function buildParams({ params }) {
1351
+ return kubb_kit.ast.factory.createSchema({
1352
+ type: "object",
1353
+ properties: params.map((param) => kubb_kit.ast.factory.createProperty({
1354
+ name: param.name,
1355
+ required: param.required,
1356
+ schema: kubb_kit.ast.factory.createSchema({
1357
+ ...param.schema,
1358
+ optional: !param.required
1359
+ })
1360
+ }))
1361
+ });
1362
+ }
1363
+ function buildResponseUnion(node, { resolver }) {
1364
+ const allWithSchema = node.responses.filter((res) => res.content?.some((entry) => entry.schema));
1365
+ const successWithSchema = allWithSchema.filter((res) => isSuccessStatusCode(res.statusCode));
1366
+ const responsesWithSchema = successWithSchema.length > 0 ? successWithSchema : allWithSchema;
1367
+ if (responsesWithSchema.length === 0) return null;
1368
+ return kubb_kit.ast.factory.createSchema({
1369
+ type: "union",
1370
+ members: responsesWithSchema.map((res) => kubb_kit.ast.factory.createSchema({
1371
+ type: "ref",
1372
+ name: resolver.response.status(node, res.statusCode)
1373
+ }))
1374
+ });
1375
+ }
1376
+ //#endregion
1377
+ //#region src/components/Type.tsx
1378
+ function Type({ name, node, printer, enum: enumOptions, resolver }) {
1379
+ const enumSchemaNodes = kubb_kit.ast.collectSync(node, { schema(n) {
1380
+ const enumNode = kubb_kit.ast.narrowSchema(n, kubb_kit.ast.schemaTypes.enum);
1381
+ if (enumNode?.name && !isInlineConstEnum(enumNode, printer.options.enumSchemaNames)) return enumNode;
1382
+ } });
1383
+ const output = printer.print(node);
1384
+ if (!output) return;
1385
+ const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((node) => {
1386
+ return {
1387
+ node,
1388
+ ...getEnumNames({
1389
+ node,
1390
+ enum: enumOptions,
1391
+ resolver
1392
+ })
1393
+ };
1394
+ });
1395
+ const shouldExportEnums = enumOptions.type !== "inlineLiteral";
1396
+ const shouldExportType = enumOptions.type === "inlineLiteral" || enums.every((item) => item.typeName !== name);
1397
+ return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [shouldExportEnums && enums.map(({ node }) => /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(Enum, {
1398
+ node,
1399
+ enum: enumOptions,
1400
+ resolver
1401
+ }, node.name)), shouldExportType && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1402
+ name,
1403
+ isTypeOnly: true,
1404
+ isExportable: true,
1405
+ isIndexable: true,
1406
+ children: output
1407
+ })] });
1408
+ }
1409
+ //#endregion
1415
1410
  //#region src/printers/printerTs.ts
1416
1411
  const { isNonNullable } = factory_exports;
1417
1412
  /**