@kubb/plugin-ts 5.0.0-alpha.34 → 5.0.0-alpha.35

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.js CHANGED
@@ -1,11 +1,10 @@
1
1
  import "./chunk--u3MIqq1.js";
2
2
  import { safePrint } from "@kubb/parser-ts";
3
- import { File } from "@kubb/renderer-jsx";
4
- import { caseParams, collect, createPrinterFactory, createProperty, createSchema, extractRefName, isStringType, narrowSchema, schemaTypes, syncSchemaRef, transform } from "@kubb/ast";
3
+ import { File, jsxRenderer } from "@kubb/renderer-jsx";
4
+ import { ast, defineGenerator, definePlugin, definePrinter, defineResolver } from "@kubb/core";
5
5
  import { isNumber } from "remeda";
6
6
  import ts from "typescript";
7
7
  import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
8
- import { createPlugin, defineGenerator, definePresets, definePrinter, defineResolver, getPreset, mergeGenerators } from "@kubb/core";
9
8
  //#region ../../internals/utils/src/casing.ts
10
9
  /**
11
10
  * Shared implementation for camelCase and PascalCase conversion.
@@ -450,7 +449,7 @@ function buildTupleNode(node, print) {
450
449
  */
451
450
  function buildPropertyType(schema, baseType, optionalType) {
452
451
  const addsUndefined = OPTIONAL_ADDS_UNDEFINED.has(optionalType);
453
- const meta = syncSchemaRef(schema);
452
+ const meta = ast.syncSchemaRef(schema);
454
453
  let type = baseType;
455
454
  if (meta.nullable) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] });
456
455
  if ((meta.nullish || meta.optional) && addsUndefined) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
@@ -533,8 +532,8 @@ function Enum({ node, enumType, enumTypeSuffix, enumKeyCasing, resolver }) {
533
532
  //#endregion
534
533
  //#region src/components/Type.tsx
535
534
  function Type({ name, node, printer, enumType, enumTypeSuffix, enumKeyCasing, resolver }) {
536
- const enumSchemaNodes = collect(node, { schema(n) {
537
- const enumNode = narrowSchema(n, schemaTypes.enum);
535
+ const enumSchemaNodes = ast.collect(node, { schema(n) {
536
+ const enumNode = ast.narrowSchema(n, ast.schemaTypes.enum);
538
537
  if (enumNode?.name) return enumNode;
539
538
  } });
540
539
  const output = printer.print(node);
@@ -576,7 +575,7 @@ function Type({ name, node, printer, enumType, enumTypeSuffix, enumKeyCasing, re
576
575
 
577
576
  */
578
577
  function buildPropertyJSDocComments(schema) {
579
- const meta = syncSchemaRef(schema);
578
+ const meta = ast.syncSchemaRef(schema);
580
579
  const isArray = meta?.primitive === "array";
581
580
  return [
582
581
  meta && "description" in meta && meta.description ? `@description ${jsStringEscape(meta.description)}` : void 0,
@@ -590,12 +589,12 @@ function buildPropertyJSDocComments(schema) {
590
589
  ].filter(Boolean);
591
590
  }
592
591
  function buildParams(node, { params, resolver }) {
593
- return createSchema({
592
+ return ast.createSchema({
594
593
  type: "object",
595
- properties: params.map((param) => createProperty({
594
+ properties: params.map((param) => ast.createProperty({
596
595
  name: param.name,
597
596
  required: param.required,
598
- schema: createSchema({
597
+ schema: ast.createSchema({
599
598
  type: "ref",
600
599
  name: resolver.resolveParamName(node, param)
601
600
  })
@@ -606,65 +605,65 @@ function buildData(node, { resolver }) {
606
605
  const pathParams = node.parameters.filter((p) => p.in === "path");
607
606
  const queryParams = node.parameters.filter((p) => p.in === "query");
608
607
  const headerParams = node.parameters.filter((p) => p.in === "header");
609
- return createSchema({
608
+ return ast.createSchema({
610
609
  type: "object",
611
610
  deprecated: node.deprecated,
612
611
  properties: [
613
- createProperty({
612
+ ast.createProperty({
614
613
  name: "data",
615
- schema: node.requestBody?.schema ? createSchema({
614
+ schema: node.requestBody?.schema ? ast.createSchema({
616
615
  type: "ref",
617
616
  name: resolver.resolveDataName(node),
618
617
  optional: true
619
- }) : createSchema({
618
+ }) : ast.createSchema({
620
619
  type: "never",
621
620
  primitive: void 0,
622
621
  optional: true
623
622
  })
624
623
  }),
625
- createProperty({
624
+ ast.createProperty({
626
625
  name: "pathParams",
627
626
  required: pathParams.length > 0,
628
627
  schema: pathParams.length > 0 ? buildParams(node, {
629
628
  params: pathParams,
630
629
  resolver
631
- }) : createSchema({
630
+ }) : ast.createSchema({
632
631
  type: "never",
633
632
  primitive: void 0
634
633
  })
635
634
  }),
636
- createProperty({
635
+ ast.createProperty({
637
636
  name: "queryParams",
638
- schema: queryParams.length > 0 ? createSchema({
637
+ schema: queryParams.length > 0 ? ast.createSchema({
639
638
  ...buildParams(node, {
640
639
  params: queryParams,
641
640
  resolver
642
641
  }),
643
642
  optional: true
644
- }) : createSchema({
643
+ }) : ast.createSchema({
645
644
  type: "never",
646
645
  primitive: void 0,
647
646
  optional: true
648
647
  })
649
648
  }),
650
- createProperty({
649
+ ast.createProperty({
651
650
  name: "headerParams",
652
- schema: headerParams.length > 0 ? createSchema({
651
+ schema: headerParams.length > 0 ? ast.createSchema({
653
652
  ...buildParams(node, {
654
653
  params: headerParams,
655
654
  resolver
656
655
  }),
657
656
  optional: true
658
- }) : createSchema({
657
+ }) : ast.createSchema({
659
658
  type: "never",
660
659
  primitive: void 0,
661
660
  optional: true
662
661
  })
663
662
  }),
664
- createProperty({
663
+ ast.createProperty({
665
664
  name: "url",
666
665
  required: true,
667
- schema: createSchema({
666
+ schema: ast.createSchema({
668
667
  type: "url",
669
668
  path: node.path
670
669
  })
@@ -674,12 +673,12 @@ function buildData(node, { resolver }) {
674
673
  }
675
674
  function buildResponses(node, { resolver }) {
676
675
  if (node.responses.length === 0) return null;
677
- return createSchema({
676
+ return ast.createSchema({
678
677
  type: "object",
679
- properties: node.responses.map((res) => createProperty({
678
+ properties: node.responses.map((res) => ast.createProperty({
680
679
  name: String(res.statusCode),
681
680
  required: true,
682
- schema: createSchema({
681
+ schema: ast.createSchema({
683
682
  type: "ref",
684
683
  name: resolver.resolveResponseStatusName(node, res.statusCode)
685
684
  })
@@ -689,9 +688,9 @@ function buildResponses(node, { resolver }) {
689
688
  function buildResponseUnion(node, { resolver }) {
690
689
  const responsesWithSchema = node.responses.filter((res) => res.schema);
691
690
  if (responsesWithSchema.length === 0) return null;
692
- return createSchema({
691
+ return ast.createSchema({
693
692
  type: "union",
694
- members: responsesWithSchema.map((res) => createSchema({
693
+ members: responsesWithSchema.map((res) => ast.createSchema({
695
694
  type: "ref",
696
695
  name: resolver.resolveResponseStatusName(node, res.statusCode)
697
696
  }))
@@ -752,7 +751,7 @@ const printerTs = definePrinter((options) => {
752
751
  time: dateOrStringNode,
753
752
  ref(node) {
754
753
  if (!node.name) return;
755
- const refName = node.ref ? extractRefName(node.ref) ?? node.name : node.name;
754
+ const refName = node.ref ? ast.extractRefName(node.ref) ?? node.name : node.name;
756
755
  return createTypeReferenceNode(node.ref && ENUM_TYPES_WITH_KEY_SUFFIX.has(this.options.enumType) && this.options.enumTypeSuffix && this.options.enumSchemaNames?.has(refName) ? this.options.resolver.resolveEnumKeyName({ name: refName }, this.options.enumTypeSuffix) : node.ref ? this.options.resolver.default(refName, "type") : refName, void 0);
757
756
  },
758
757
  enum(node) {
@@ -766,13 +765,13 @@ const printerTs = definePrinter((options) => {
766
765
  union(node) {
767
766
  const members = node.members ?? [];
768
767
  const hasStringLiteral = members.some((m) => {
769
- return narrowSchema(m, schemaTypes.enum)?.primitive === "string";
768
+ return ast.narrowSchema(m, ast.schemaTypes.enum)?.primitive === "string";
770
769
  });
771
- const hasPlainString = members.some((m) => isStringType(m));
770
+ const hasPlainString = members.some((m) => ast.isStringType(m));
772
771
  if (hasStringLiteral && hasPlainString) return createUnionDeclaration({
773
772
  withParentheses: true,
774
773
  nodes: members.map((m) => {
775
- if (isStringType(m)) return createIntersectionDeclaration({
774
+ if (ast.isStringType(m)) return createIntersectionDeclaration({
776
775
  nodes: [keywordTypeNodes.string, createTypeLiteralNode([])],
777
776
  withParentheses: true
778
777
  });
@@ -805,7 +804,7 @@ const printerTs = definePrinter((options) => {
805
804
  const propertyNodes = node.properties.map((prop) => {
806
805
  const baseType = transform(prop.schema) ?? keywordTypeNodes.unknown;
807
806
  const type = buildPropertyType(prop.schema, baseType, options.optionalType);
808
- const propMeta = syncSchemaRef(prop.schema);
807
+ const propMeta = ast.syncSchemaRef(prop.schema);
809
808
  return appendJSDocToNode({
810
809
  node: createPropertySignature({
811
810
  questionToken: prop.schema.optional || prop.schema.nullish ? addsQuestionToken : false,
@@ -826,7 +825,7 @@ const printerTs = definePrinter((options) => {
826
825
  const { name, syntaxType = "type", description, keysToOmit } = this.options;
827
826
  let base = this.transform(node);
828
827
  if (!base) return null;
829
- const meta = syncSchemaRef(node);
828
+ const meta = ast.syncSchemaRef(node);
830
829
  if (!name) {
831
830
  if (meta.nullable) base = createUnionDeclaration({ nodes: [base, keywordTypeNodes.null] });
832
831
  if ((meta.nullish || meta.optional) && addsUndefined) base = createUnionDeclaration({ nodes: [base, keywordTypeNodes.undefined] });
@@ -857,12 +856,13 @@ const printerTs = definePrinter((options) => {
857
856
  //#region src/generators/typeGenerator.tsx
858
857
  const typeGenerator = defineGenerator({
859
858
  name: "typescript",
860
- schema(node, options) {
861
- const { enumType, enumTypeSuffix, enumKeyCasing, syntaxType, optionalType, arrayType, output, group, printer } = options;
862
- const { adapter, config, resolver, root } = this;
859
+ renderer: jsxRenderer,
860
+ schema(node, ctx) {
861
+ const { enumType, enumTypeSuffix, enumKeyCasing, syntaxType, optionalType, arrayType, output, group, printer } = ctx.options;
862
+ const { adapter, config, resolver, root } = ctx;
863
863
  if (!node.name) return;
864
- const mode = this.getMode(output);
865
- const enumSchemaNames = new Set((adapter.inputNode?.schemas ?? []).filter((s) => narrowSchema(s, schemaTypes.enum) && s.name).map((s) => s.name));
864
+ const mode = ctx.getMode(output);
865
+ const enumSchemaNames = new Set((adapter.inputNode?.schemas ?? []).filter((s) => ast.narrowSchema(s, ast.schemaTypes.enum) && s.name).map((s) => s.name));
866
866
  function resolveImportName(schemaName) {
867
867
  if (ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && enumTypeSuffix && enumSchemaNames.has(schemaName)) return resolver.resolveEnumKeyName({ name: schemaName }, enumTypeSuffix);
868
868
  return resolver.resolveTypeName(schemaName);
@@ -878,7 +878,7 @@ const typeGenerator = defineGenerator({
878
878
  group
879
879
  }).path
880
880
  }));
881
- const isEnumSchema = !!narrowSchema(node, schemaTypes.enum);
881
+ const isEnumSchema = !!ast.narrowSchema(node, ast.schemaTypes.enum);
882
882
  const meta = {
883
883
  name: ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && isEnumSchema ? resolver.resolveEnumKeyName(node, enumTypeSuffix) : resolver.resolveTypeName(node.name),
884
884
  file: resolver.resolveFile({
@@ -934,11 +934,11 @@ const typeGenerator = defineGenerator({
934
934
  })]
935
935
  });
936
936
  },
937
- operation(node, options) {
938
- const { enumType, enumTypeSuffix, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing, group, output, printer } = options;
939
- const { adapter, config, resolver, root } = this;
940
- const mode = this.getMode(output);
941
- const params = caseParams(node.parameters, paramsCasing);
937
+ operation(node, ctx) {
938
+ const { enumType, enumTypeSuffix, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing, group, output, printer } = ctx.options;
939
+ const { adapter, config, resolver, root } = ctx;
940
+ const mode = ctx.getMode(output);
941
+ const params = ast.caseParams(node.parameters, paramsCasing);
942
942
  const meta = { file: resolver.resolveFile({
943
943
  name: node.operationId,
944
944
  extname: ".ts",
@@ -949,7 +949,7 @@ const typeGenerator = defineGenerator({
949
949
  output,
950
950
  group
951
951
  }) };
952
- const enumSchemaNames = new Set((adapter.inputNode?.schemas ?? []).filter((s) => narrowSchema(s, schemaTypes.enum) && s.name).map((s) => s.name));
952
+ const enumSchemaNames = new Set((adapter.inputNode?.schemas ?? []).filter((s) => ast.narrowSchema(s, ast.schemaTypes.enum) && s.name).map((s) => s.name));
953
953
  function resolveImportName(schemaName) {
954
954
  if (ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && enumTypeSuffix && enumSchemaNames.has(schemaName)) return resolver.resolveEnumKeyName({ name: schemaName }, enumTypeSuffix);
955
955
  return resolver.resolveTypeName(schemaName);
@@ -1058,9 +1058,6 @@ const typeGenerator = defineGenerator({
1058
1058
  }
1059
1059
  });
1060
1060
  //#endregion
1061
- //#region package.json
1062
- var version = "5.0.0-alpha.34";
1063
- //#endregion
1064
1061
  //#region src/resolvers/resolverTs.ts
1065
1062
  /**
1066
1063
  * Resolver for `@kubb/plugin-ts` that provides the default naming and path-resolution
@@ -1183,11 +1180,11 @@ const resolverTsLegacy = defineResolver(() => {
1183
1180
  //#endregion
1184
1181
  //#region src/generators/typeGeneratorLegacy.tsx
1185
1182
  function buildGroupedParamsSchema({ params, parentName }) {
1186
- return createSchema({
1183
+ return ast.createSchema({
1187
1184
  type: "object",
1188
1185
  properties: params.map((param) => {
1189
1186
  let schema = param.schema;
1190
- if (narrowSchema(schema, "enum") && !schema.name && parentName) schema = {
1187
+ if (ast.narrowSchema(schema, "enum") && !schema.name && parentName) schema = {
1191
1188
  ...schema,
1192
1189
  name: pascalCase([
1193
1190
  parentName,
@@ -1195,7 +1192,7 @@ function buildGroupedParamsSchema({ params, parentName }) {
1195
1192
  "enum"
1196
1193
  ].join(" "))
1197
1194
  };
1198
- return createProperty({
1195
+ return ast.createProperty({
1199
1196
  name: param.name,
1200
1197
  required: param.required,
1201
1198
  schema
@@ -1210,78 +1207,78 @@ function buildLegacyResponsesSchemaNode(node, { resolver }) {
1210
1207
  return !Number.isNaN(code) && code >= 200 && code < 300;
1211
1208
  });
1212
1209
  const errorResponses = node.responses.filter((res) => res.statusCode === "default" || Number(res.statusCode) >= 400);
1213
- const responseSchema = successResponses.length > 0 ? successResponses.length === 1 ? createSchema({
1210
+ const responseSchema = successResponses.length > 0 ? successResponses.length === 1 ? ast.createSchema({
1214
1211
  type: "ref",
1215
1212
  name: resolver.resolveResponseStatusName(node, successResponses[0].statusCode)
1216
- }) : createSchema({
1213
+ }) : ast.createSchema({
1217
1214
  type: "union",
1218
- members: successResponses.map((res) => createSchema({
1215
+ members: successResponses.map((res) => ast.createSchema({
1219
1216
  type: "ref",
1220
1217
  name: resolver.resolveResponseStatusName(node, res.statusCode)
1221
1218
  }))
1222
- }) : createSchema({
1219
+ }) : ast.createSchema({
1223
1220
  type: "any",
1224
1221
  primitive: void 0
1225
1222
  });
1226
- const errorsSchema = errorResponses.length > 0 ? errorResponses.length === 1 ? createSchema({
1223
+ const errorsSchema = errorResponses.length > 0 ? errorResponses.length === 1 ? ast.createSchema({
1227
1224
  type: "ref",
1228
1225
  name: resolver.resolveResponseStatusName(node, errorResponses[0].statusCode)
1229
- }) : createSchema({
1226
+ }) : ast.createSchema({
1230
1227
  type: "union",
1231
- members: errorResponses.map((res) => createSchema({
1228
+ members: errorResponses.map((res) => ast.createSchema({
1232
1229
  type: "ref",
1233
1230
  name: resolver.resolveResponseStatusName(node, res.statusCode)
1234
1231
  }))
1235
- }) : createSchema({
1232
+ }) : ast.createSchema({
1236
1233
  type: "any",
1237
1234
  primitive: void 0
1238
1235
  });
1239
- const properties = [createProperty({
1236
+ const properties = [ast.createProperty({
1240
1237
  name: "Response",
1241
1238
  required: true,
1242
1239
  schema: responseSchema
1243
1240
  })];
1244
- if (!isGet && node.requestBody?.schema) properties.push(createProperty({
1241
+ if (!isGet && node.requestBody?.schema) properties.push(ast.createProperty({
1245
1242
  name: "Request",
1246
1243
  required: true,
1247
- schema: createSchema({
1244
+ schema: ast.createSchema({
1248
1245
  type: "ref",
1249
1246
  name: resolver.resolveDataName(node)
1250
1247
  })
1251
1248
  }));
1252
1249
  const queryParam = node.parameters.find((p) => p.in === "query");
1253
- if (queryParam) properties.push(createProperty({
1250
+ if (queryParam) properties.push(ast.createProperty({
1254
1251
  name: "QueryParams",
1255
1252
  required: true,
1256
- schema: createSchema({
1253
+ schema: ast.createSchema({
1257
1254
  type: "ref",
1258
1255
  name: resolver.resolveQueryParamsName(node, queryParam)
1259
1256
  })
1260
1257
  }));
1261
1258
  const pathParam = node.parameters.find((p) => p.in === "path");
1262
- if (pathParam) properties.push(createProperty({
1259
+ if (pathParam) properties.push(ast.createProperty({
1263
1260
  name: "PathParams",
1264
1261
  required: true,
1265
- schema: createSchema({
1262
+ schema: ast.createSchema({
1266
1263
  type: "ref",
1267
1264
  name: resolver.resolvePathParamsName(node, pathParam)
1268
1265
  })
1269
1266
  }));
1270
1267
  const headerParam = node.parameters.find((p) => p.in === "header");
1271
- if (headerParam) properties.push(createProperty({
1268
+ if (headerParam) properties.push(ast.createProperty({
1272
1269
  name: "HeaderParams",
1273
1270
  required: true,
1274
- schema: createSchema({
1271
+ schema: ast.createSchema({
1275
1272
  type: "ref",
1276
1273
  name: resolver.resolveHeaderParamsName(node, headerParam)
1277
1274
  })
1278
1275
  }));
1279
- properties.push(createProperty({
1276
+ properties.push(ast.createProperty({
1280
1277
  name: "Errors",
1281
1278
  required: true,
1282
1279
  schema: errorsSchema
1283
1280
  }));
1284
- return createSchema({
1281
+ return ast.createSchema({
1285
1282
  type: "object",
1286
1283
  properties
1287
1284
  });
@@ -1291,33 +1288,33 @@ function buildLegacyResponseUnionSchemaNode(node, { resolver }) {
1291
1288
  const code = Number(res.statusCode);
1292
1289
  return !Number.isNaN(code) && code >= 200 && code < 300;
1293
1290
  });
1294
- if (successResponses.length === 0) return createSchema({
1291
+ if (successResponses.length === 0) return ast.createSchema({
1295
1292
  type: "any",
1296
1293
  primitive: void 0
1297
1294
  });
1298
- if (successResponses.length === 1) return createSchema({
1295
+ if (successResponses.length === 1) return ast.createSchema({
1299
1296
  type: "ref",
1300
1297
  name: resolver.resolveResponseStatusName(node, successResponses[0].statusCode)
1301
1298
  });
1302
- return createSchema({
1299
+ return ast.createSchema({
1303
1300
  type: "union",
1304
- members: successResponses.map((res) => createSchema({
1301
+ members: successResponses.map((res) => ast.createSchema({
1305
1302
  type: "ref",
1306
1303
  name: resolver.resolveResponseStatusName(node, res.statusCode)
1307
1304
  }))
1308
1305
  });
1309
1306
  }
1310
1307
  function nameUnnamedEnums(node, parentName) {
1311
- return transform(node, {
1308
+ return ast.transform(node, {
1312
1309
  schema(n) {
1313
- const enumNode = narrowSchema(n, "enum");
1310
+ const enumNode = ast.narrowSchema(n, "enum");
1314
1311
  if (enumNode && !enumNode.name) return {
1315
1312
  ...enumNode,
1316
1313
  name: pascalCase([parentName, "enum"].join(" "))
1317
1314
  };
1318
1315
  },
1319
1316
  property(p) {
1320
- const enumNode = narrowSchema(p.schema, "enum");
1317
+ const enumNode = ast.narrowSchema(p.schema, "enum");
1321
1318
  if (enumNode && !enumNode.name) return {
1322
1319
  ...p,
1323
1320
  schema: {
@@ -1334,11 +1331,12 @@ function nameUnnamedEnums(node, parentName) {
1334
1331
  }
1335
1332
  const typeGeneratorLegacy = defineGenerator({
1336
1333
  name: "typescript-legacy",
1337
- schema(node, options) {
1338
- const { enumType, enumTypeSuffix, enumKeyCasing, syntaxType, optionalType, arrayType, output, group } = options;
1339
- const { adapter, config, resolver, root } = this;
1334
+ renderer: jsxRenderer,
1335
+ schema(node, ctx) {
1336
+ const { enumType, enumTypeSuffix, enumKeyCasing, syntaxType, optionalType, arrayType, output, group } = ctx.options;
1337
+ const { adapter, config, resolver, root } = ctx;
1340
1338
  if (!node.name) return;
1341
- const mode = this.getMode(output);
1339
+ const mode = ctx.getMode(output);
1342
1340
  const imports = adapter.getImports(node, (schemaName) => ({
1343
1341
  name: resolver.resolveTypeName(schemaName),
1344
1342
  path: resolver.resolveFile({
@@ -1350,7 +1348,7 @@ const typeGeneratorLegacy = defineGenerator({
1350
1348
  group
1351
1349
  }).path
1352
1350
  }));
1353
- const isEnumSchema = !!narrowSchema(node, schemaTypes.enum);
1351
+ const isEnumSchema = !!ast.narrowSchema(node, ast.schemaTypes.enum);
1354
1352
  const meta = {
1355
1353
  name: ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && isEnumSchema ? resolver.resolveEnumKeyName(node, enumTypeSuffix) : resolver.resolveTypeName(node.name),
1356
1354
  file: resolver.resolveFile({
@@ -1404,11 +1402,11 @@ const typeGeneratorLegacy = defineGenerator({
1404
1402
  })]
1405
1403
  });
1406
1404
  },
1407
- operation(node, options) {
1408
- const { enumType, enumTypeSuffix, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing, group, output } = options;
1409
- const { adapter, config, resolver, root } = this;
1410
- const mode = this.getMode(output);
1411
- const params = caseParams(node.parameters, paramsCasing);
1405
+ operation(node, ctx) {
1406
+ const { enumType, enumTypeSuffix, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing, group, output } = ctx.options;
1407
+ const { adapter, config, resolver, root } = ctx;
1408
+ const mode = ctx.getMode(output);
1409
+ const params = ast.caseParams(node.parameters, paramsCasing);
1412
1410
  const meta = { file: resolver.resolveFile({
1413
1411
  name: node.operationId,
1414
1412
  extname: ".ts",
@@ -1535,28 +1533,6 @@ const typeGeneratorLegacy = defineGenerator({
1535
1533
  }
1536
1534
  });
1537
1535
  //#endregion
1538
- //#region src/presets.ts
1539
- /**
1540
- * Built-in preset registry for `@kubb/plugin-ts`.
1541
- *
1542
- * - `default` — uses `resolverTs` and `typeGenerator` (current naming conventions).
1543
- * - `kubbV4` — uses `resolverTsLegacy` and `typeGeneratorLegacy` (Kubb v4 naming conventions).
1544
- */
1545
- const presets = definePresets({
1546
- default: {
1547
- name: "default",
1548
- resolver: resolverTs,
1549
- generators: [typeGenerator],
1550
- printer: printerTs
1551
- },
1552
- kubbV4: {
1553
- name: "kubbV4",
1554
- resolver: resolverTsLegacy,
1555
- generators: [typeGeneratorLegacy],
1556
- printer: printerTs
1557
- }
1558
- });
1559
- //#endregion
1560
1536
  //#region src/plugin.ts
1561
1537
  /**
1562
1538
  * Canonical plugin name for `@kubb/plugin-ts`, used to identify the plugin in driver lookups and warnings.
@@ -1578,44 +1554,31 @@ const pluginTsName = "plugin-ts";
1578
1554
  * })
1579
1555
  * ```
1580
1556
  */
1581
- const pluginTs = createPlugin((options) => {
1557
+ const pluginTs = definePlugin((options) => {
1582
1558
  const { output = {
1583
1559
  path: "types",
1584
1560
  barrelType: "named"
1585
- }, group, exclude = [], include, override = [], enumType = "asConst", enumTypeSuffix = "Key", enumKeyCasing = "none", optionalType = "questionToken", arrayType = "array", syntaxType = "type", paramsCasing, printer, compatibilityPreset = "default", resolver: userResolver, transformer: userTransformer, generators: userGenerators = [] } = options;
1586
- const preset = getPreset({
1587
- preset: compatibilityPreset,
1588
- presets,
1589
- resolver: userResolver,
1590
- transformer: userTransformer,
1591
- generators: userGenerators
1592
- });
1593
- const mergedGenerator = mergeGenerators(preset.generators ?? []);
1594
- let resolveNameWarning = false;
1595
- let resolvePathWarning = false;
1561
+ }, group, exclude = [], include, override = [], enumType = "asConst", enumTypeSuffix = "Key", enumKeyCasing = "none", optionalType = "questionToken", arrayType = "array", syntaxType = "type", paramsCasing, printer, resolver: userResolver, transformer: userTransformer, generators: userGenerators = [], compatibilityPreset = "default" } = options;
1562
+ const defaultResolver = compatibilityPreset === "kubbV4" ? resolverTsLegacy : resolverTs;
1563
+ const defaultGenerator = compatibilityPreset === "kubbV4" ? typeGeneratorLegacy : typeGenerator;
1564
+ const groupConfig = group ? {
1565
+ ...group,
1566
+ name: (ctx) => {
1567
+ if (group.type === "path") return `${ctx.group.split("/")[1]}`;
1568
+ return `${camelCase(ctx.group)}Controller`;
1569
+ }
1570
+ } : void 0;
1596
1571
  return {
1597
1572
  name: pluginTsName,
1598
- version,
1599
- get resolver() {
1600
- return preset.resolver;
1601
- },
1602
- get transformer() {
1603
- return preset.transformer;
1604
- },
1605
- get options() {
1606
- return {
1573
+ options,
1574
+ hooks: { "kubb:plugin:setup"(ctx) {
1575
+ ctx.setOptions({
1607
1576
  output,
1608
1577
  exclude,
1609
1578
  include,
1610
1579
  override,
1611
1580
  optionalType,
1612
- group: group ? {
1613
- ...group,
1614
- name: (ctx) => {
1615
- if (group.type === "path") return `${ctx.group.split("/")[1]}`;
1616
- return `${camelCase(ctx.group)}Controller`;
1617
- }
1618
- } : void 0,
1581
+ group: groupConfig,
1619
1582
  arrayType,
1620
1583
  enumType,
1621
1584
  enumTypeSuffix,
@@ -1623,43 +1586,15 @@ const pluginTs = createPlugin((options) => {
1623
1586
  syntaxType,
1624
1587
  paramsCasing,
1625
1588
  printer
1626
- };
1627
- },
1628
- resolvePath(baseName, pathMode, options) {
1629
- if (!resolvePathWarning) {
1630
- this.warn("Do not use resolvePath for pluginTs, use resolverTs.resolvePath instead");
1631
- resolvePathWarning = true;
1632
- }
1633
- return this.plugin.resolver.resolvePath({
1634
- baseName,
1635
- pathMode,
1636
- tag: options?.group?.tag,
1637
- path: options?.group?.path
1638
- }, {
1639
- root: this.root,
1640
- output,
1641
- group: this.plugin.options.group
1642
1589
  });
1643
- },
1644
- resolveName(name, type) {
1645
- if (!resolveNameWarning) {
1646
- this.warn("Do not use resolveName for pluginTs, use resolverTs.default instead");
1647
- resolveNameWarning = true;
1648
- }
1649
- return this.plugin.resolver.default(name, type);
1650
- },
1651
- async schema(node, options) {
1652
- return mergedGenerator.schema?.call(this, node, options);
1653
- },
1654
- async operation(node, options) {
1655
- return mergedGenerator.operation?.call(this, node, options);
1656
- },
1657
- async operations(nodes, options) {
1658
- return mergedGenerator.operations?.call(this, nodes, options);
1659
- },
1660
- async buildStart() {
1661
- await this.openInStudio({ ast: true });
1662
- }
1590
+ ctx.setResolver(userResolver ? {
1591
+ ...defaultResolver,
1592
+ ...userResolver
1593
+ } : defaultResolver);
1594
+ if (userTransformer) ctx.setTransformer(userTransformer);
1595
+ ctx.addGenerator(defaultGenerator);
1596
+ for (const gen of userGenerators) ctx.addGenerator(gen);
1597
+ } }
1663
1598
  };
1664
1599
  });
1665
1600
  //#endregion
@@ -1676,7 +1611,7 @@ const kindToHandlerKey = {
1676
1611
  * Uses `createPrinterFactory` and dispatches handlers by `node.kind`
1677
1612
  * (for function nodes) rather than by `node.type` (for schema nodes).
1678
1613
  */
1679
- const defineFunctionPrinter = createPrinterFactory((node) => kindToHandlerKey[node.kind]);
1614
+ const defineFunctionPrinter = ast.createPrinterFactory((node) => kindToHandlerKey[node.kind]);
1680
1615
  function rank(param) {
1681
1616
  if (param.kind === "ParameterGroup") {
1682
1617
  if (param.default) return PARAM_RANK.withDefault;