@kubb/plugin-ts 5.2.0-canary.20261024T235810 → 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.d.cts CHANGED
@@ -582,6 +582,13 @@ type Options = OutputOptions & {
582
582
  * @default 'array'
583
583
  */
584
584
  arrayType?: 'generic' | 'array';
585
+ /**
586
+ * How operation types (`AddPetOptions`, `AddPetStatus200`) are emitted.
587
+ * - `'export'` — one file per operation with its aliases and aggregates.
588
+ * - `'inline'` — no operation files: clients, hooks, and mocks reference `Pet` and print the rest inline (`{ body: Pet }`).
589
+ * @default 'export'
590
+ */
591
+ operations?: 'export' | 'inline';
585
592
  /**
586
593
  * Override how names and file paths are built for generated symbols.
587
594
  * Methods you omit fall back to the default `resolverTs`. `this` is bound to the
@@ -647,6 +654,7 @@ type ResolvedOptions = {
647
654
  optionalType: NonNullable<Options['optionalType']>;
648
655
  arrayType: NonNullable<Options['arrayType']>;
649
656
  syntaxType: NonNullable<Options['syntaxType']>;
657
+ operations: NonNullable<Options['operations']>;
650
658
  printer: Options['printer'];
651
659
  };
652
660
  type PluginTs = PluginType<'plugin-ts', Options, ResolvedOptions, ResolverTs>;
@@ -690,8 +698,12 @@ type Props = {
690
698
  printer: ast.Printer<PrinterTsFactory>;
691
699
  enum: PluginTs['resolvedOptions']['enum'];
692
700
  resolver: ResolverTs;
701
+ /**
702
+ * Marks the source inline, so importing files absorb the type. Set by `pluginTs({ operations: 'inline' })`.
703
+ */
704
+ inline?: boolean;
693
705
  };
694
- export declare function Type({ name, node, printer, enum: enumOptions, resolver }: Props): KubbReactNode;
706
+ export declare function Type({ name, node, printer, enum: enumOptions, resolver, inline }: Props): KubbReactNode;
695
707
  //#endregion
696
708
  //#region src/generators/typeGenerator.d.ts
697
709
  /**
package/dist/index.d.ts CHANGED
@@ -582,6 +582,13 @@ type Options = OutputOptions & {
582
582
  * @default 'array'
583
583
  */
584
584
  arrayType?: 'generic' | 'array';
585
+ /**
586
+ * How operation types (`AddPetOptions`, `AddPetStatus200`) are emitted.
587
+ * - `'export'` — one file per operation with its aliases and aggregates.
588
+ * - `'inline'` — no operation files: clients, hooks, and mocks reference `Pet` and print the rest inline (`{ body: Pet }`).
589
+ * @default 'export'
590
+ */
591
+ operations?: 'export' | 'inline';
585
592
  /**
586
593
  * Override how names and file paths are built for generated symbols.
587
594
  * Methods you omit fall back to the default `resolverTs`. `this` is bound to the
@@ -647,6 +654,7 @@ type ResolvedOptions = {
647
654
  optionalType: NonNullable<Options['optionalType']>;
648
655
  arrayType: NonNullable<Options['arrayType']>;
649
656
  syntaxType: NonNullable<Options['syntaxType']>;
657
+ operations: NonNullable<Options['operations']>;
650
658
  printer: Options['printer'];
651
659
  };
652
660
  type PluginTs = PluginType<'plugin-ts', Options, ResolvedOptions, ResolverTs>;
@@ -690,8 +698,12 @@ type Props = {
690
698
  printer: ast.Printer<PrinterTsFactory>;
691
699
  enum: PluginTs['resolvedOptions']['enum'];
692
700
  resolver: ResolverTs;
701
+ /**
702
+ * Marks the source inline, so importing files absorb the type. Set by `pluginTs({ operations: 'inline' })`.
703
+ */
704
+ inline?: boolean;
693
705
  };
694
- export declare function Type({ name, node, printer, enum: enumOptions, resolver }: Props): KubbReactNode;
706
+ export declare function Type({ name, node, printer, enum: enumOptions, resolver, inline }: Props): KubbReactNode;
695
707
  //#endregion
696
708
  //#region src/generators/typeGenerator.d.ts
697
709
  /**
package/dist/index.js CHANGED
@@ -1278,40 +1278,6 @@ function buildResponseUnion(node, { resolver }) {
1278
1278
  });
1279
1279
  }
1280
1280
  //#endregion
1281
- //#region src/components/Type.tsx
1282
- function Type({ name, node, printer, enum: enumOptions, resolver }) {
1283
- const enumSchemaNodes = ast.collectSync(node, { schema(n) {
1284
- const enumNode = ast.narrowSchema(n, ast.schemaTypes.enum);
1285
- if (enumNode?.name && !isInlineConstEnum(enumNode, printer.options.enumSchemaNames)) return enumNode;
1286
- } });
1287
- const output = printer.print(node);
1288
- if (!output) return;
1289
- const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((node) => {
1290
- return {
1291
- node,
1292
- ...getEnumNames({
1293
- node,
1294
- enum: enumOptions,
1295
- resolver
1296
- })
1297
- };
1298
- });
1299
- const shouldExportEnums = enumOptions.type !== "inlineLiteral";
1300
- const shouldExportType = enumOptions.type === "inlineLiteral" || enums.every((item) => item.typeName !== name);
1301
- return /* @__PURE__ */ jsxs(Fragment, { children: [shouldExportEnums && enums.map(({ node }) => /* @__PURE__ */ jsx(Enum, {
1302
- node,
1303
- enum: enumOptions,
1304
- resolver
1305
- }, node.name)), shouldExportType && /* @__PURE__ */ jsx(File.Source, {
1306
- name,
1307
- pointer: node.pointer,
1308
- isTypeOnly: true,
1309
- isExportable: true,
1310
- isIndexable: true,
1311
- children: output
1312
- })] });
1313
- }
1314
- //#endregion
1315
1281
  //#region src/printers/printerTs.ts
1316
1282
  const { isNonNullable } = factory_exports;
1317
1283
  /**
@@ -1457,7 +1423,11 @@ const printerTs = ast.createPrinter((options) => {
1457
1423
  const transformed = this.transform(node);
1458
1424
  if (!transformed) return null;
1459
1425
  const meta = syncSchemaRef(node);
1460
- if (!name) return print(wrapNullableOptional(transformed, !!meta.nullable, !!(meta.nullish || meta.optional) && addsUndefined));
1426
+ if (!name) return print(wrapNullableOptional(keysToOmit?.length ? createOmitDeclaration({
1427
+ keys: keysToOmit,
1428
+ type: transformed,
1429
+ nonNullable: true
1430
+ }) : transformed, !!meta.nullable, !!(meta.nullish || meta.optional) && addsUndefined));
1461
1431
  return createTypeDeclaration({
1462
1432
  name,
1463
1433
  isExportable: true,
@@ -1478,6 +1448,59 @@ const printerTs = ast.createPrinter((options) => {
1478
1448
  };
1479
1449
  });
1480
1450
  //#endregion
1451
+ //#region src/components/Type.tsx
1452
+ function Type({ name, node, printer, enum: enumOptions, resolver, inline }) {
1453
+ if (inline) {
1454
+ const withoutEnums = ast.transform(node, { schema: (n) => n.type === ast.schemaTypes.enum && n.name ? {
1455
+ ...n,
1456
+ name: void 0
1457
+ } : void 0 });
1458
+ const expression = printerTs({
1459
+ ...printer.options,
1460
+ name: void 0
1461
+ }).print(withoutEnums)?.replace(/\/\*\*[\s\S]*?\*\/\s*/g, "");
1462
+ if (!expression) return;
1463
+ return /* @__PURE__ */ jsx(File.Source, {
1464
+ name,
1465
+ isTypeOnly: true,
1466
+ isExportable: true,
1467
+ isIndexable: true,
1468
+ inline: { expression },
1469
+ children: expression
1470
+ });
1471
+ }
1472
+ const enumSchemaNodes = ast.collectSync(node, { schema(n) {
1473
+ const enumNode = ast.narrowSchema(n, ast.schemaTypes.enum);
1474
+ if (enumNode?.name && !isInlineConstEnum(enumNode, printer.options.enumSchemaNames)) return enumNode;
1475
+ } });
1476
+ const output = printer.print(node);
1477
+ if (!output) return;
1478
+ const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((node) => {
1479
+ return {
1480
+ node,
1481
+ ...getEnumNames({
1482
+ node,
1483
+ enum: enumOptions,
1484
+ resolver
1485
+ })
1486
+ };
1487
+ });
1488
+ const shouldExportEnums = enumOptions.type !== "inlineLiteral";
1489
+ const shouldExportType = enumOptions.type === "inlineLiteral" || enums.every((item) => item.typeName !== name);
1490
+ return /* @__PURE__ */ jsxs(Fragment, { children: [shouldExportEnums && enums.map(({ node }) => /* @__PURE__ */ jsx(Enum, {
1491
+ node,
1492
+ enum: enumOptions,
1493
+ resolver
1494
+ }, node.name)), shouldExportType && /* @__PURE__ */ jsx(File.Source, {
1495
+ name,
1496
+ pointer: node.pointer,
1497
+ isTypeOnly: true,
1498
+ isExportable: true,
1499
+ isIndexable: true,
1500
+ children: output
1501
+ })] });
1502
+ }
1503
+ //#endregion
1481
1504
  //#region src/generators/typeGenerator.tsx
1482
1505
  /**
1483
1506
  * Built-in generator for `@kubb/plugin-ts`. Emits one TypeScript file per
@@ -1568,8 +1591,9 @@ const typeGenerator = defineGenerator({
1568
1591
  });
1569
1592
  },
1570
1593
  operation(node, ctx) {
1571
- const { enum: enumOptions, optionalType, arrayType, syntaxType, group, output, printer } = ctx.options;
1594
+ const { enum: enumOptions, optionalType, arrayType, syntaxType, group, output, printer, operations } = ctx.options;
1572
1595
  const { config, resolver, root } = ctx;
1596
+ const inline = operations === "inline";
1573
1597
  const meta = { file: resolver.file({
1574
1598
  name: node.operationId,
1575
1599
  extname: ".ts",
@@ -1586,6 +1610,15 @@ const typeGenerator = defineGenerator({
1586
1610
  enumOptions,
1587
1611
  isEnum: enumSchemaNames.has(schemaName)
1588
1612
  });
1613
+ const inlinePrinter = inline ? printerTs({
1614
+ optionalType,
1615
+ arrayType,
1616
+ enum: enumOptions,
1617
+ syntaxType,
1618
+ resolver,
1619
+ enumSchemaNames,
1620
+ nodes: printer?.nodes
1621
+ }) : null;
1589
1622
  function renderSchemaType({ schema, name, keysToOmit }) {
1590
1623
  if (!schema) return null;
1591
1624
  const imports = resolver.imports({
@@ -1621,7 +1654,8 @@ const typeGenerator = defineGenerator({
1621
1654
  node: schema,
1622
1655
  enum: enumOptions,
1623
1656
  resolver,
1624
- printer: schemaPrinter
1657
+ printer: schemaPrinter,
1658
+ inline
1625
1659
  })] });
1626
1660
  }
1627
1661
  /**
@@ -1632,10 +1666,12 @@ const typeGenerator = defineGenerator({
1632
1666
  */
1633
1667
  function buildContentTypeVariants(entries, baseName, pointer, decorate) {
1634
1668
  const variants = resolveContentTypeVariants(entries, baseName);
1669
+ const keys = variants.map((variant) => inlinePrinter ? `${inlinePrinter.print(variant.schema)}:${variant.keysToOmit ?? ""}` : variant.name);
1670
+ const members = variants.filter((_, index) => keys.indexOf(keys[index]) === index);
1635
1671
  const unionSchema = ast.factory.createSchema({
1636
1672
  type: "union",
1637
1673
  pointer,
1638
- members: variants.map((variant) => ast.factory.createSchema({
1674
+ members: members.map((variant) => ast.factory.createSchema({
1639
1675
  type: "ref",
1640
1676
  name: variant.name
1641
1677
  }))
@@ -1756,12 +1792,12 @@ const typeGenerator = defineGenerator({
1756
1792
  //#endregion
1757
1793
  //#region kubb-extension.json
1758
1794
  var compatibility = {
1759
- "kubb": ">=5.8.3",
1795
+ "kubb": ">=5.14.0",
1760
1796
  "node": ">=22.22"
1761
1797
  };
1762
1798
  //#endregion
1763
1799
  //#region package.json
1764
- var version = "5.2.0-canary.20261024T235810";
1800
+ var version = "5.2.0";
1765
1801
  //#endregion
1766
1802
  //#region src/resolvers/resolverTs.ts
1767
1803
  /**
@@ -1842,7 +1878,7 @@ const pluginTs = defineExtension({
1842
1878
  const { output = {
1843
1879
  path: "types",
1844
1880
  barrel: { type: "named" }
1845
- }, group, exclude = [], include, override = [], enum: enumOptions = {}, optionalType = "questionToken", arrayType = "array", syntaxType = "type", printer, resolver: userResolver, macros: userMacros } = options;
1881
+ }, group, exclude = [], include, override = [], enum: enumOptions = {}, optionalType = "questionToken", arrayType = "array", syntaxType = "type", operations = "export", printer, resolver: userResolver, macros: userMacros } = options;
1846
1882
  const resolvedEnum = {
1847
1883
  type: enumOptions.type ?? "asConst",
1848
1884
  constCasing: enumOptions.constCasing ?? "camelCase",
@@ -1862,6 +1898,7 @@ const pluginTs = defineExtension({
1862
1898
  arrayType,
1863
1899
  enum: resolvedEnum,
1864
1900
  syntaxType,
1901
+ operations,
1865
1902
  printer
1866
1903
  };
1867
1904
  }