@kubb/plugin-ts 5.0.4 → 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/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 }))];