@kubb/plugin-ts 5.2.0-canary.20261024T235331 → 5.2.0

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
@@ -1282,40 +1282,6 @@ function buildResponseUnion(node, { resolver }) {
1282
1282
  });
1283
1283
  }
1284
1284
  //#endregion
1285
- //#region src/components/Type.tsx
1286
- function Type({ name, node, printer, enum: enumOptions, resolver }) {
1287
- const enumSchemaNodes = kubb_kit.ast.collectSync(node, { schema(n) {
1288
- const enumNode = kubb_kit.ast.narrowSchema(n, kubb_kit.ast.schemaTypes.enum);
1289
- if (enumNode?.name && !isInlineConstEnum(enumNode, printer.options.enumSchemaNames)) return enumNode;
1290
- } });
1291
- const output = printer.print(node);
1292
- if (!output) return;
1293
- const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((node) => {
1294
- return {
1295
- node,
1296
- ...getEnumNames({
1297
- node,
1298
- enum: enumOptions,
1299
- resolver
1300
- })
1301
- };
1302
- });
1303
- const shouldExportEnums = enumOptions.type !== "inlineLiteral";
1304
- const shouldExportType = enumOptions.type === "inlineLiteral" || enums.every((item) => item.typeName !== name);
1305
- 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, {
1306
- node,
1307
- enum: enumOptions,
1308
- resolver
1309
- }, node.name)), shouldExportType && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1310
- name,
1311
- pointer: node.pointer,
1312
- isTypeOnly: true,
1313
- isExportable: true,
1314
- isIndexable: true,
1315
- children: output
1316
- })] });
1317
- }
1318
- //#endregion
1319
1285
  //#region src/printers/printerTs.ts
1320
1286
  const { isNonNullable } = factory_exports;
1321
1287
  /**
@@ -1461,7 +1427,11 @@ const printerTs = kubb_kit.ast.createPrinter((options) => {
1461
1427
  const transformed = this.transform(node);
1462
1428
  if (!transformed) return null;
1463
1429
  const meta = (0, kubb_kit.syncSchemaRef)(node);
1464
- if (!name) return print(wrapNullableOptional(transformed, !!meta.nullable, !!(meta.nullish || meta.optional) && addsUndefined));
1430
+ if (!name) return print(wrapNullableOptional(keysToOmit?.length ? createOmitDeclaration({
1431
+ keys: keysToOmit,
1432
+ type: transformed,
1433
+ nonNullable: true
1434
+ }) : transformed, !!meta.nullable, !!(meta.nullish || meta.optional) && addsUndefined));
1465
1435
  return createTypeDeclaration({
1466
1436
  name,
1467
1437
  isExportable: true,
@@ -1482,6 +1452,59 @@ const printerTs = kubb_kit.ast.createPrinter((options) => {
1482
1452
  };
1483
1453
  });
1484
1454
  //#endregion
1455
+ //#region src/components/Type.tsx
1456
+ function Type({ name, node, printer, enum: enumOptions, resolver, inline }) {
1457
+ if (inline) {
1458
+ const withoutEnums = kubb_kit.ast.transform(node, { schema: (n) => n.type === kubb_kit.ast.schemaTypes.enum && n.name ? {
1459
+ ...n,
1460
+ name: void 0
1461
+ } : void 0 });
1462
+ const expression = printerTs({
1463
+ ...printer.options,
1464
+ name: void 0
1465
+ }).print(withoutEnums)?.replace(/\/\*\*[\s\S]*?\*\/\s*/g, "");
1466
+ if (!expression) return;
1467
+ return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1468
+ name,
1469
+ isTypeOnly: true,
1470
+ isExportable: true,
1471
+ isIndexable: true,
1472
+ inline: { expression },
1473
+ children: expression
1474
+ });
1475
+ }
1476
+ const enumSchemaNodes = kubb_kit.ast.collectSync(node, { schema(n) {
1477
+ const enumNode = kubb_kit.ast.narrowSchema(n, kubb_kit.ast.schemaTypes.enum);
1478
+ if (enumNode?.name && !isInlineConstEnum(enumNode, printer.options.enumSchemaNames)) return enumNode;
1479
+ } });
1480
+ const output = printer.print(node);
1481
+ if (!output) return;
1482
+ const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((node) => {
1483
+ return {
1484
+ node,
1485
+ ...getEnumNames({
1486
+ node,
1487
+ enum: enumOptions,
1488
+ resolver
1489
+ })
1490
+ };
1491
+ });
1492
+ const shouldExportEnums = enumOptions.type !== "inlineLiteral";
1493
+ const shouldExportType = enumOptions.type === "inlineLiteral" || enums.every((item) => item.typeName !== name);
1494
+ 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, {
1495
+ node,
1496
+ enum: enumOptions,
1497
+ resolver
1498
+ }, node.name)), shouldExportType && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1499
+ name,
1500
+ pointer: node.pointer,
1501
+ isTypeOnly: true,
1502
+ isExportable: true,
1503
+ isIndexable: true,
1504
+ children: output
1505
+ })] });
1506
+ }
1507
+ //#endregion
1485
1508
  //#region src/generators/typeGenerator.tsx
1486
1509
  /**
1487
1510
  * Built-in generator for `@kubb/plugin-ts`. Emits one TypeScript file per
@@ -1572,8 +1595,9 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
1572
1595
  });
1573
1596
  },
1574
1597
  operation(node, ctx) {
1575
- const { enum: enumOptions, optionalType, arrayType, syntaxType, group, output, printer } = ctx.options;
1598
+ const { enum: enumOptions, optionalType, arrayType, syntaxType, group, output, printer, operations } = ctx.options;
1576
1599
  const { config, resolver, root } = ctx;
1600
+ const inline = operations === "inline";
1577
1601
  const meta = { file: resolver.file({
1578
1602
  name: node.operationId,
1579
1603
  extname: ".ts",
@@ -1590,6 +1614,15 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
1590
1614
  enumOptions,
1591
1615
  isEnum: enumSchemaNames.has(schemaName)
1592
1616
  });
1617
+ const inlinePrinter = inline ? printerTs({
1618
+ optionalType,
1619
+ arrayType,
1620
+ enum: enumOptions,
1621
+ syntaxType,
1622
+ resolver,
1623
+ enumSchemaNames,
1624
+ nodes: printer?.nodes
1625
+ }) : null;
1593
1626
  function renderSchemaType({ schema, name, keysToOmit }) {
1594
1627
  if (!schema) return null;
1595
1628
  const imports = resolver.imports({
@@ -1625,7 +1658,8 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
1625
1658
  node: schema,
1626
1659
  enum: enumOptions,
1627
1660
  resolver,
1628
- printer: schemaPrinter
1661
+ printer: schemaPrinter,
1662
+ inline
1629
1663
  })] });
1630
1664
  }
1631
1665
  /**
@@ -1636,10 +1670,12 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
1636
1670
  */
1637
1671
  function buildContentTypeVariants(entries, baseName, pointer, decorate) {
1638
1672
  const variants = resolveContentTypeVariants(entries, baseName);
1673
+ const keys = variants.map((variant) => inlinePrinter ? `${inlinePrinter.print(variant.schema)}:${variant.keysToOmit ?? ""}` : variant.name);
1674
+ const members = variants.filter((_, index) => keys.indexOf(keys[index]) === index);
1639
1675
  const unionSchema = kubb_kit.ast.factory.createSchema({
1640
1676
  type: "union",
1641
1677
  pointer,
1642
- members: variants.map((variant) => kubb_kit.ast.factory.createSchema({
1678
+ members: members.map((variant) => kubb_kit.ast.factory.createSchema({
1643
1679
  type: "ref",
1644
1680
  name: variant.name
1645
1681
  }))
@@ -1760,12 +1796,12 @@ const typeGenerator = (0, kubb_kit.defineGenerator)({
1760
1796
  //#endregion
1761
1797
  //#region kubb-extension.json
1762
1798
  var compatibility = {
1763
- "kubb": ">=5.8.3",
1799
+ "kubb": ">=5.14.0",
1764
1800
  "node": ">=22.22"
1765
1801
  };
1766
1802
  //#endregion
1767
1803
  //#region package.json
1768
- var version = "5.2.0-canary.20261024T235331";
1804
+ var version = "5.2.0";
1769
1805
  //#endregion
1770
1806
  //#region src/resolvers/resolverTs.ts
1771
1807
  /**
@@ -1846,7 +1882,7 @@ const pluginTs = (0, kubb_kit.defineExtension)({
1846
1882
  const { output = {
1847
1883
  path: "types",
1848
1884
  barrel: { type: "named" }
1849
- }, group, exclude = [], include, override = [], enum: enumOptions = {}, optionalType = "questionToken", arrayType = "array", syntaxType = "type", printer, resolver: userResolver, macros: userMacros } = options;
1885
+ }, group, exclude = [], include, override = [], enum: enumOptions = {}, optionalType = "questionToken", arrayType = "array", syntaxType = "type", operations = "export", printer, resolver: userResolver, macros: userMacros } = options;
1850
1886
  const resolvedEnum = {
1851
1887
  type: enumOptions.type ?? "asConst",
1852
1888
  constCasing: enumOptions.constCasing ?? "camelCase",
@@ -1866,6 +1902,7 @@ const pluginTs = (0, kubb_kit.defineExtension)({
1866
1902
  arrayType,
1867
1903
  enum: resolvedEnum,
1868
1904
  syntaxType,
1905
+ operations,
1869
1906
  printer
1870
1907
  };
1871
1908
  }