@kubb/agent 5.0.0-alpha.11 → 5.0.0-alpha.12

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.
@@ -14,7 +14,7 @@ import process$1, { version as version$2 } from 'node:process';
14
14
  import { Logtail } from '@logtail/node';
15
15
  import { consola } from 'consola';
16
16
  import { access, rm, readFile as readFile$1, readdir as readdir$1, mkdir, writeFile as writeFile$1 } from 'node:fs/promises';
17
- import { createFabric, createReactFabric, Fabric, File, Function as Function$1, Const, FunctionParams, Type as Type$2, useFabric } from '@kubb/react-fabric';
17
+ import { createFabric, createReactFabric, Fabric, File, Function as Function$1, Const, FunctionParams, Type as Type$1, useFabric } from '@kubb/react-fabric';
18
18
  import { typescriptParser } from '@kubb/react-fabric/parsers';
19
19
  import { fsPlugin } from '@kubb/react-fabric/plugins';
20
20
  import { performance as performance$1 } from 'node:perf_hooks';
@@ -4713,7 +4713,7 @@ function toCamelOrPascal$f(text, pascal) {
4713
4713
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
4714
4714
  }
4715
4715
  function applyToFileParts$f(text, transformPart) {
4716
- const parts = text.split(".");
4716
+ const parts = text.split(/\.(?=[a-zA-Z])/);
4717
4717
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
4718
4718
  }
4719
4719
  function camelCase$f(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -4794,13 +4794,14 @@ function createLimit(concurrency) {
4794
4794
  };
4795
4795
  }
4796
4796
  function getChildren(node, recurse) {
4797
+ var _a;
4797
4798
  switch (node.kind) {
4798
4799
  case "Root":
4799
4800
  return [...node.schemas, ...node.operations];
4800
4801
  case "Operation":
4801
4802
  return [
4802
4803
  ...node.parameters,
4803
- ...node.requestBody ? [node.requestBody] : [],
4804
+ ...((_a = node.requestBody) == null ? void 0 : _a.schema) ? [node.requestBody.schema] : [],
4804
4805
  ...node.responses
4805
4806
  ];
4806
4807
  case "Schema": {
@@ -4870,6 +4871,79 @@ async function _walk(node, visitor, recurse, limit) {
4870
4871
  const children = getChildren(node, recurse);
4871
4872
  await Promise.all(children.map((child) => _walk(child, visitor, recurse, limit)));
4872
4873
  }
4874
+ function transform(node, visitor, options = {}) {
4875
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
4876
+ const recurse = ((_a = options.depth) != null ? _a : visitorDepths.deep) === visitorDepths.deep;
4877
+ switch (node.kind) {
4878
+ case "Root": {
4879
+ let root = node;
4880
+ const replaced = (_b = visitor.root) == null ? void 0 : _b.call(visitor, root);
4881
+ if (replaced) root = replaced;
4882
+ return {
4883
+ ...root,
4884
+ schemas: root.schemas.map((s) => transform(s, visitor, options)),
4885
+ operations: root.operations.map((op) => transform(op, visitor, options))
4886
+ };
4887
+ }
4888
+ case "Operation": {
4889
+ let op = node;
4890
+ const replaced = (_c = visitor.operation) == null ? void 0 : _c.call(visitor, op);
4891
+ if (replaced) op = replaced;
4892
+ return {
4893
+ ...op,
4894
+ parameters: op.parameters.map((p) => transform(p, visitor, options)),
4895
+ requestBody: op.requestBody ? {
4896
+ ...op.requestBody,
4897
+ schema: op.requestBody.schema ? transform(op.requestBody.schema, visitor, options) : void 0
4898
+ } : void 0,
4899
+ responses: op.responses.map((r) => transform(r, visitor, options))
4900
+ };
4901
+ }
4902
+ case "Schema": {
4903
+ let schema = node;
4904
+ const replaced = (_d = visitor.schema) == null ? void 0 : _d.call(visitor, schema);
4905
+ if (replaced) schema = replaced;
4906
+ return {
4907
+ ...schema,
4908
+ ..."properties" in schema && recurse ? { properties: schema.properties.map((p) => transform(p, visitor, options)) } : {},
4909
+ ..."items" in schema && recurse ? { items: (_e = schema.items) == null ? void 0 : _e.map((i) => transform(i, visitor, options)) } : {},
4910
+ ..."members" in schema && recurse ? { members: (_f = schema.members) == null ? void 0 : _f.map((m) => transform(m, visitor, options)) } : {},
4911
+ ..."additionalProperties" in schema && recurse && schema.additionalProperties && schema.additionalProperties !== true ? { additionalProperties: transform(schema.additionalProperties, visitor, options) } : {}
4912
+ };
4913
+ }
4914
+ case "Property": {
4915
+ let prop = node;
4916
+ const replaced = (_g = visitor.property) == null ? void 0 : _g.call(visitor, prop);
4917
+ if (replaced) prop = replaced;
4918
+ return {
4919
+ ...prop,
4920
+ schema: transform(prop.schema, visitor, options)
4921
+ };
4922
+ }
4923
+ case "Parameter": {
4924
+ let param = node;
4925
+ const replaced = (_h = visitor.parameter) == null ? void 0 : _h.call(visitor, param);
4926
+ if (replaced) param = replaced;
4927
+ return {
4928
+ ...param,
4929
+ schema: transform(param.schema, visitor, options)
4930
+ };
4931
+ }
4932
+ case "Response": {
4933
+ let response = node;
4934
+ const replaced = (_i = visitor.response) == null ? void 0 : _i.call(visitor, response);
4935
+ if (replaced) response = replaced;
4936
+ return {
4937
+ ...response,
4938
+ schema: transform(response.schema, visitor, options)
4939
+ };
4940
+ }
4941
+ case "FunctionParameter":
4942
+ case "ObjectBindingParameter":
4943
+ case "FunctionParameters":
4944
+ return node;
4945
+ }
4946
+ }
4873
4947
  function collect(node, visitor, options = {}) {
4874
4948
  var _a, _b, _c, _d, _e, _f, _g;
4875
4949
  const recurse = ((_a = options.depth) != null ? _a : visitorDepths.deep) === visitorDepths.deep;
@@ -4984,7 +5058,7 @@ function toCamelOrPascal$e(text, pascal) {
4984
5058
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
4985
5059
  }
4986
5060
  function applyToFileParts$e(text, transformPart) {
4987
- const parts = text.split(".");
5061
+ const parts = text.split(/\.(?=[a-zA-Z])/);
4988
5062
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
4989
5063
  }
4990
5064
  function camelCase$e(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -5955,7 +6029,7 @@ const fsStorage = createStorage(() => ({
5955
6029
  await clean(resolve(base));
5956
6030
  }
5957
6031
  }));
5958
- var version$1 = "5.0.0-alpha.11";
6032
+ var version$1 = "5.0.0-alpha.12";
5959
6033
  function getDiagnosticInfo() {
5960
6034
  return {
5961
6035
  nodeVersion: version$2,
@@ -6742,7 +6816,7 @@ function satisfiesDependency(dependency, version2, cwd) {
6742
6816
  return satisfies(semVer, version2);
6743
6817
  }
6744
6818
 
6745
- var version = "5.0.0-alpha.11";
6819
+ var version = "5.0.0-alpha.12";
6746
6820
 
6747
6821
  function isCommandMessage(msg) {
6748
6822
  return msg.type === "command";
@@ -6947,7 +7021,7 @@ function toCamelOrPascal$d(text, pascal) {
6947
7021
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
6948
7022
  }
6949
7023
  function applyToFileParts$d(text, transformPart) {
6950
- const parts = text.split(".");
7024
+ const parts = text.split(/\.(?=[a-zA-Z])/);
6951
7025
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
6952
7026
  }
6953
7027
  function camelCase$d(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -7097,7 +7171,7 @@ function toCamelOrPascal$c(text, pascal) {
7097
7171
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
7098
7172
  }
7099
7173
  function applyToFileParts$c(text, transformPart) {
7100
- const parts = text.split(".");
7174
+ const parts = text.split(/\.(?=[a-zA-Z])/);
7101
7175
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
7102
7176
  }
7103
7177
  function camelCase$c(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -7267,8 +7341,8 @@ function getDefaultValue(schema) {
7267
7341
  }
7268
7342
  if (schema.type === "object" || schema.properties) return "{}";
7269
7343
  }
7270
- async function parse$3(pathOrApi, { oasClass = Oas, canBundle = true, enablePaths = true } = {}) {
7271
- if (typeof pathOrApi === "string" && canBundle) return parse$3((await bundle({
7344
+ async function parse$2(pathOrApi, { oasClass = Oas, canBundle = true, enablePaths = true } = {}) {
7345
+ if (typeof pathOrApi === "string" && canBundle) return parse$2((await bundle({
7272
7346
  ref: pathOrApi,
7273
7347
  config: await loadConfig$1(),
7274
7348
  base: pathOrApi
@@ -7288,13 +7362,13 @@ async function parse$3(pathOrApi, { oasClass = Oas, canBundle = true, enablePath
7288
7362
  return new oasClass(document);
7289
7363
  }
7290
7364
  async function merge(pathOrApi, { oasClass = Oas } = {}) {
7291
- const instances = await Promise.all(pathOrApi.map((p) => parse$3(p, {
7365
+ const instances = await Promise.all(pathOrApi.map((p) => parse$2(p, {
7292
7366
  oasClass,
7293
7367
  enablePaths: false,
7294
7368
  canBundle: false
7295
7369
  })));
7296
7370
  if (instances.length === 0) throw new Error("No OAS instances provided for merging.");
7297
- return parse$3(instances.reduce((acc, current) => {
7371
+ return parse$2(instances.reduce((acc, current) => {
7298
7372
  return mergeDeep(acc, current.document);
7299
7373
  }, {
7300
7374
  openapi: "3.0.0",
@@ -7308,16 +7382,16 @@ async function merge(pathOrApi, { oasClass = Oas } = {}) {
7308
7382
  }
7309
7383
  function parseFromConfig(config, oasClass = Oas) {
7310
7384
  if ("data" in config.input) {
7311
- if (typeof config.input.data === "object") return parse$3(structuredClone(config.input.data), { oasClass });
7385
+ if (typeof config.input.data === "object") return parse$2(structuredClone(config.input.data), { oasClass });
7312
7386
  try {
7313
- return parse$3(yaml.parse(config.input.data), { oasClass });
7387
+ return parse$2(yaml.parse(config.input.data), { oasClass });
7314
7388
  } catch (_e) {
7315
- return parse$3(config.input.data, { oasClass });
7389
+ return parse$2(config.input.data, { oasClass });
7316
7390
  }
7317
7391
  }
7318
7392
  if (Array.isArray(config.input)) return merge(config.input.map((input) => path$2.resolve(config.root, input.path)), { oasClass });
7319
- if (new URLPath$9(config.input.path).isURL) return parse$3(config.input.path, { oasClass });
7320
- return parse$3(path$2.resolve(config.root, config.input.path), { oasClass });
7393
+ if (new URLPath$9(config.input.path).isURL) return parse$2(config.input.path, { oasClass });
7394
+ return parse$2(path$2.resolve(config.root, config.input.path), { oasClass });
7321
7395
  }
7322
7396
  function flattenSchema(schema) {
7323
7397
  if (!(schema == null ? void 0 : schema.allOf) || schema.allOf.length === 0) return schema || null;
@@ -9234,7 +9308,7 @@ function toCamelOrPascal$b(text, pascal) {
9234
9308
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
9235
9309
  }
9236
9310
  function applyToFileParts$b(text, transformPart) {
9237
- const parts = text.split(".");
9311
+ const parts = text.split(/\.(?=[a-zA-Z])/);
9238
9312
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
9239
9313
  }
9240
9314
  function camelCase$b(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -10296,7 +10370,7 @@ function Operations({ name, operations }) {
10296
10370
  name: "OperationSchema",
10297
10371
  isExportable: true,
10298
10372
  isIndexable: true,
10299
- children: /* @__PURE__ */ jsx(Type$2, {
10373
+ children: /* @__PURE__ */ jsx(Type$1, {
10300
10374
  name: "OperationSchema",
10301
10375
  export: true,
10302
10376
  children: `{
@@ -10320,7 +10394,7 @@ function Operations({ name, operations }) {
10320
10394
  name: "OperationsMap",
10321
10395
  isExportable: true,
10322
10396
  isIndexable: true,
10323
- children: /* @__PURE__ */ jsx(Type$2, {
10397
+ children: /* @__PURE__ */ jsx(Type$1, {
10324
10398
  name: "OperationsMap",
10325
10399
  export: true,
10326
10400
  children: "Record<string, OperationSchema>"
@@ -10631,11 +10705,26 @@ const miniModifierKeywords = [
10631
10705
  function extractMiniModifiers(schemas) {
10632
10706
  const defaultSchema = schemas.find((item) => isKeyword(item, schemaKeywords.default));
10633
10707
  const isBigInt = schemas.some((item) => isKeyword(item, schemaKeywords.bigint));
10708
+ let defaultValue = defaultSchema == null ? void 0 : defaultSchema.args;
10709
+ if (defaultValue !== void 0) {
10710
+ const enumSchema = schemas.find((it) => isKeyword(it, schemaKeywords.enum));
10711
+ if (enumSchema) {
10712
+ let rawDefault = defaultValue;
10713
+ if (typeof rawDefault === "string") try {
10714
+ rawDefault = JSON.parse(rawDefault);
10715
+ } catch {
10716
+ }
10717
+ if (!enumSchema.args.items.map((item) => {
10718
+ var _a;
10719
+ return (_a = item.value) != null ? _a : item.name;
10720
+ }).includes(rawDefault)) defaultValue = void 0;
10721
+ }
10722
+ }
10634
10723
  return {
10635
10724
  hasOptional: schemas.some((item) => isKeyword(item, schemaKeywords.optional)),
10636
10725
  hasNullable: schemas.some((item) => isKeyword(item, schemaKeywords.nullable)),
10637
10726
  hasNullish: schemas.some((item) => isKeyword(item, schemaKeywords.nullish)),
10638
- defaultValue: defaultSchema == null ? void 0 : defaultSchema.args,
10727
+ defaultValue,
10639
10728
  isBigInt
10640
10729
  };
10641
10730
  }
@@ -10657,7 +10746,7 @@ const shouldCoerce = (coercion, type) => {
10657
10746
  if (typeof coercion === "boolean") return coercion;
10658
10747
  return !!coercion[type];
10659
10748
  };
10660
- const parse$2 = createParser({
10749
+ const parse$1 = createParser({
10661
10750
  mapper: zodKeywordMapper,
10662
10751
  handlers: {
10663
10752
  union(tree, options) {
@@ -10848,7 +10937,21 @@ const parse$2 = createParser({
10848
10937
  const { current, siblings } = tree;
10849
10938
  if (options.mini) return;
10850
10939
  const isBigInt = siblings.some((it) => isKeyword(it, schemaKeywords.bigint));
10851
- if (current.args !== void 0) return zodKeywordMapper.default(current.args, void 0, void 0, isBigInt);
10940
+ if (current.args !== void 0) {
10941
+ const enumSchema = siblings.find((it) => isKeyword(it, schemaKeywords.enum));
10942
+ if (enumSchema) {
10943
+ let rawDefault = current.args;
10944
+ if (typeof rawDefault === "string") try {
10945
+ rawDefault = JSON.parse(rawDefault);
10946
+ } catch {
10947
+ }
10948
+ if (!enumSchema.args.items.map((item) => {
10949
+ var _a;
10950
+ return (_a = item.value) != null ? _a : item.name;
10951
+ }).includes(rawDefault)) return;
10952
+ }
10953
+ return zodKeywordMapper.default(current.args, void 0, void 0, isBigInt);
10954
+ }
10852
10955
  return zodKeywordMapper.default();
10853
10956
  },
10854
10957
  describe(tree, options) {
@@ -10927,7 +11030,7 @@ function Zod({ name, typeName, tree, schema, inferTypeName, mapper, coercion, ke
10927
11030
  });
10928
11031
  const baseSchemas = mini ? filterMiniModifiers(schemas) : schemas;
10929
11032
  const output = baseSchemas.map((schemaKeyword, index) => {
10930
- return parse$2({
11033
+ return parse$1({
10931
11034
  schema,
10932
11035
  parent: void 0,
10933
11036
  current: schemaKeyword,
@@ -10952,7 +11055,7 @@ function Zod({ name, typeName, tree, schema, inferTypeName, mapper, coercion, ke
10952
11055
  if (firstSchema && isKeyword(firstSchema, schemaKeywords.ref)) if (version === "3") suffix = ".schema";
10953
11056
  else suffix = ".unwrap()";
10954
11057
  }
10955
- const emptyValue = parse$2({
11058
+ const emptyValue = parse$1({
10956
11059
  schema,
10957
11060
  parent: void 0,
10958
11061
  current: { keyword: schemaKeywords[emptySchemaType] },
@@ -10987,11 +11090,11 @@ function Zod({ name, typeName, tree, schema, inferTypeName, mapper, coercion, ke
10987
11090
  isExportable: true,
10988
11091
  isIndexable: true,
10989
11092
  isTypeOnly: true,
10990
- children: [typeName && /* @__PURE__ */ jsx(Type$2, {
11093
+ children: [typeName && /* @__PURE__ */ jsx(Type$1, {
10991
11094
  export: true,
10992
11095
  name: inferTypeName,
10993
11096
  children: typeName
10994
- }), !typeName && /* @__PURE__ */ jsx(Type$2, {
11097
+ }), !typeName && /* @__PURE__ */ jsx(Type$1, {
10995
11098
  export: true,
10996
11099
  name: inferTypeName,
10997
11100
  children: `z.infer<typeof ${name}>`
@@ -208891,7 +208994,7 @@ function toCamelOrPascal$a(text, pascal) {
208891
208994
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
208892
208995
  }
208893
208996
  function applyToFileParts$a(text, transformPart) {
208894
- const parts = text.split(".");
208997
+ const parts = text.split(/\.(?=[a-zA-Z])/);
208895
208998
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
208896
208999
  }
208897
209000
  function camelCase$a(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -208945,6 +209048,27 @@ function jsStringEscape$1(input) {
208945
209048
  }
208946
209049
  });
208947
209050
  }
209051
+ function stringify$1(value) {
209052
+ if (value === void 0 || value === null) return '""';
209053
+ return JSON.stringify(trimQuotes$1(value.toString()));
209054
+ }
209055
+ const OPTIONAL_ADDS_UNDEFINED = /* @__PURE__ */ new Set(["undefined", "questionTokenAndUndefined"]);
209056
+ const OPTIONAL_ADDS_QUESTION_TOKEN = /* @__PURE__ */ new Set(["questionToken", "questionTokenAndUndefined"]);
209057
+ const ENUM_TYPES_WITH_KEY_SUFFIX = /* @__PURE__ */ new Set(["asConst", "asPascalConst"]);
209058
+ const ENUM_TYPES_WITH_RUNTIME_VALUE = /* @__PURE__ */ new Set([
209059
+ "enum",
209060
+ "asConst",
209061
+ "asPascalConst",
209062
+ "constEnum",
209063
+ "literal",
209064
+ void 0
209065
+ ]);
209066
+ const ENUM_TYPES_WITH_TYPE_ONLY = /* @__PURE__ */ new Set([
209067
+ "asConst",
209068
+ "asPascalConst",
209069
+ "literal",
209070
+ void 0
209071
+ ]);
208948
209072
  const { SyntaxKind, factory } = ts;
208949
209073
  const modifiers = {
208950
209074
  async: factory.createModifier(ts.SyntaxKind.AsyncKeyword),
@@ -208957,11 +209081,6 @@ const syntaxKind = {
208957
209081
  literalType: SyntaxKind.LiteralType,
208958
209082
  stringLiteral: SyntaxKind.StringLiteral
208959
209083
  };
208960
- function getUnknownType(unknownType) {
208961
- if (unknownType === "any") return keywordTypeNodes.any;
208962
- if (unknownType === "void") return keywordTypeNodes.void;
208963
- return keywordTypeNodes.unknown;
208964
- }
208965
209084
  function isValidIdentifier(str) {
208966
209085
  if (!str.length || str.trim() !== str) return false;
208967
209086
  const node = ts.parseIsolatedEntityName(str, ts.ScriptTarget.Latest);
@@ -209148,376 +209267,290 @@ const createTupleTypeNode = factory.createTupleTypeNode;
209148
209267
  const createRestTypeNode = factory.createRestTypeNode;
209149
209268
  const createTrue = factory.createTrue;
209150
209269
  const createFalse = factory.createFalse;
209151
- const createIndexedAccessTypeNode = factory.createIndexedAccessTypeNode;
209152
- const createTypeOperatorNode = factory.createTypeOperatorNode;
209270
+ factory.createIndexedAccessTypeNode;
209271
+ factory.createTypeOperatorNode;
209153
209272
  const createPrefixUnaryExpression = factory.createPrefixUnaryExpression;
209154
- const typeKeywordMapper = {
209155
- any: () => keywordTypeNodes.any,
209156
- unknown: () => keywordTypeNodes.unknown,
209157
- void: () => keywordTypeNodes.void,
209158
- number: () => keywordTypeNodes.number,
209159
- integer: () => keywordTypeNodes.number,
209160
- bigint: () => keywordTypeNodes.bigint,
209161
- object: (nodes) => {
209162
- if (!nodes || !nodes.length) return keywordTypeNodes.object;
209163
- return createTypeLiteralNode(nodes);
209164
- },
209165
- string: () => keywordTypeNodes.string,
209166
- boolean: () => keywordTypeNodes.boolean,
209167
- undefined: () => keywordTypeNodes.undefined,
209168
- nullable: void 0,
209169
- null: () => keywordTypeNodes.null,
209170
- nullish: void 0,
209171
- array: (nodes, arrayType) => {
209172
- if (!nodes) return;
209173
- return createArrayDeclaration({
209174
- nodes,
209175
- arrayType
209176
- });
209177
- },
209178
- tuple: (nodes, rest, min, max) => {
209179
- if (!nodes) return;
209180
- if (max) {
209181
- nodes = nodes.slice(0, max);
209182
- if (nodes.length < max && rest) nodes = [...nodes, ...Array(max - nodes.length).fill(rest)];
209183
- }
209184
- if (min) nodes = nodes.map((node, index) => index >= min ? createOptionalTypeNode(node) : node);
209185
- if (typeof max === "undefined" && rest) nodes.push(createRestTypeNode(createArrayTypeNode(rest)));
209186
- return createTupleTypeNode(nodes);
209187
- },
209188
- enum: (name) => {
209189
- if (!name) return;
209190
- return createTypeReferenceNode(name, void 0);
209191
- },
209192
- union: (nodes) => {
209193
- if (!nodes) return;
209194
- return createUnionDeclaration({
209195
- withParentheses: true,
209196
- nodes
209197
- });
209198
- },
209199
- const: (name, format) => {
209200
- if (name === null || name === void 0 || name === "") return;
209201
- if (format === "boolean") {
209202
- if (name === true) return createLiteralTypeNode(createTrue());
209203
- return createLiteralTypeNode(createFalse());
209273
+ function constToTypeNode(value, format) {
209274
+ if (format === "boolean") return createLiteralTypeNode(value === true ? createTrue() : createFalse());
209275
+ if (format === "number" && typeof value === "number") {
209276
+ if (value < 0) return createLiteralTypeNode(createPrefixUnaryExpression(SyntaxKind.MinusToken, createNumericLiteral(Math.abs(value))));
209277
+ return createLiteralTypeNode(createNumericLiteral(value));
209278
+ }
209279
+ return createLiteralTypeNode(createStringLiteral(String(value)));
209280
+ }
209281
+ function dateOrStringNode(node) {
209282
+ return node.representation === "date" ? createTypeReferenceNode(createIdentifier("Date")) : keywordTypeNodes.string;
209283
+ }
209284
+ function buildMemberNodes(members, print) {
209285
+ return (members != null ? members : []).map(print).filter(Boolean);
209286
+ }
209287
+ function buildTupleNode(node, print) {
209288
+ var _a, _b;
209289
+ let items = ((_a = node.items) != null ? _a : []).map(print).filter(Boolean);
209290
+ const restNode = node.rest ? (_b = print(node.rest)) != null ? _b : void 0 : void 0;
209291
+ const { min, max } = node;
209292
+ if (max !== void 0) {
209293
+ items = items.slice(0, max);
209294
+ if (items.length < max && restNode) items = [...items, ...Array(max - items.length).fill(restNode)];
209295
+ }
209296
+ if (min !== void 0) items = items.map((item, i) => i >= min ? createOptionalTypeNode(item) : item);
209297
+ if (max === void 0 && restNode) items.push(createRestTypeNode(createArrayTypeNode(restNode)));
209298
+ return createTupleTypeNode(items);
209299
+ }
209300
+ function buildPropertyType(schema, baseType, optionalType) {
209301
+ const addsUndefined = OPTIONAL_ADDS_UNDEFINED.has(optionalType);
209302
+ let type = baseType;
209303
+ if (schema.nullable) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] });
209304
+ if ((schema.nullish || schema.optional) && addsUndefined) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
209305
+ return type;
209306
+ }
209307
+ function buildPropertyJSDocComments(schema) {
209308
+ return [
209309
+ "description" in schema && schema.description ? `@description ${jsStringEscape$1(schema.description)}` : void 0,
209310
+ "deprecated" in schema && schema.deprecated ? "@deprecated" : void 0,
209311
+ "min" in schema && schema.min !== void 0 ? `@minLength ${schema.min}` : void 0,
209312
+ "max" in schema && schema.max !== void 0 ? `@maxLength ${schema.max}` : void 0,
209313
+ "pattern" in schema && schema.pattern ? `@pattern ${schema.pattern}` : void 0,
209314
+ "default" in schema && schema.default !== void 0 ? `@default ${"primitive" in schema && schema.primitive === "string" ? stringify$1(schema.default) : schema.default}` : void 0,
209315
+ "example" in schema && schema.example !== void 0 ? `@example ${schema.example}` : void 0,
209316
+ "primitive" in schema && schema.primitive ? [`@type ${schema.primitive || "unknown"}`, "optional" in schema && schema.optional ? " | undefined" : void 0].filter(Boolean).join("") : void 0
209317
+ ];
209318
+ }
209319
+ function buildIndexSignatures(node, propertyCount, print) {
209320
+ var _a, _b;
209321
+ const elements = [];
209322
+ if (node.additionalProperties && node.additionalProperties !== true) {
209323
+ const additionalType = (_a = print(node.additionalProperties)) != null ? _a : keywordTypeNodes.unknown;
209324
+ elements.push(createIndexSignature(propertyCount > 0 ? keywordTypeNodes.unknown : additionalType));
209325
+ } else if (node.additionalProperties === true) elements.push(createIndexSignature(keywordTypeNodes.unknown));
209326
+ if (node.patternProperties) {
209327
+ const first = Object.values(node.patternProperties)[0];
209328
+ if (first) {
209329
+ let patternType = (_b = print(first)) != null ? _b : keywordTypeNodes.unknown;
209330
+ if (first.nullable) patternType = createUnionDeclaration({ nodes: [patternType, keywordTypeNodes.null] });
209331
+ elements.push(createIndexSignature(patternType));
209204
209332
  }
209205
- if (format === "number" && typeof name === "number") return createLiteralTypeNode(createNumericLiteral(name));
209206
- return createLiteralTypeNode(createStringLiteral(name.toString()));
209207
- },
209208
- datetime: () => keywordTypeNodes.string,
209209
- date: (type = "string") => type === "string" ? keywordTypeNodes.string : createTypeReferenceNode(createIdentifier("Date")),
209210
- time: (type = "string") => type === "string" ? keywordTypeNodes.string : createTypeReferenceNode(createIdentifier("Date")),
209211
- uuid: () => keywordTypeNodes.string,
209212
- url: () => keywordTypeNodes.string,
209213
- default: void 0,
209214
- and: (nodes) => {
209215
- if (!nodes) return;
209216
- return createIntersectionDeclaration({
209217
- withParentheses: true,
209218
- nodes
209219
- });
209220
- },
209221
- describe: void 0,
209222
- min: void 0,
209223
- max: void 0,
209224
- optional: void 0,
209225
- matches: () => keywordTypeNodes.string,
209226
- email: () => keywordTypeNodes.string,
209227
- firstName: void 0,
209228
- lastName: void 0,
209229
- password: void 0,
209230
- phone: void 0,
209231
- readOnly: void 0,
209232
- writeOnly: void 0,
209233
- ref: (propertyName2) => {
209234
- if (!propertyName2) return;
209235
- return createTypeReferenceNode(propertyName2, void 0);
209236
- },
209237
- blob: () => createTypeReferenceNode("Blob", []),
209238
- deprecated: void 0,
209239
- example: void 0,
209240
- schema: void 0,
209241
- catchall: void 0,
209242
- name: void 0,
209243
- interface: void 0,
209244
- exclusiveMaximum: void 0,
209245
- exclusiveMinimum: void 0
209246
- };
209247
- const parse$1 = createParser({
209248
- mapper: typeKeywordMapper,
209249
- handlers: {
209250
- union(tree, options) {
209251
- const { current, schema, name } = tree;
209252
- return typeKeywordMapper.union(current.args.map((it) => this.parse({
209253
- schema,
209254
- parent: current,
209255
- name,
209256
- current: it,
209257
- siblings: []
209258
- }, options)).filter(Boolean));
209259
- },
209260
- and(tree, options) {
209261
- const { current, schema, name } = tree;
209262
- return typeKeywordMapper.and(current.args.map((it) => this.parse({
209263
- schema,
209264
- parent: current,
209265
- name,
209266
- current: it,
209267
- siblings: []
209268
- }, options)).filter(Boolean));
209269
- },
209270
- array(tree, options) {
209271
- const { current, schema, name } = tree;
209272
- return typeKeywordMapper.array(current.args.items.map((it) => this.parse({
209273
- schema,
209274
- parent: current,
209275
- name,
209276
- current: it,
209277
- siblings: []
209278
- }, options)).filter(Boolean), options.arrayType);
209279
- },
209280
- enum(tree, options) {
209281
- const { current } = tree;
209282
- if (options.enumType === "inlineLiteral") {
209283
- const enumValues = current.args.items.map((item) => item.value).filter((value) => value !== void 0 && value !== null).map((value) => {
209284
- const format = typeof value === "number" ? "number" : typeof value === "boolean" ? "boolean" : "string";
209285
- return typeKeywordMapper.const(value, format);
209286
- }).filter(Boolean);
209287
- return typeKeywordMapper.union(enumValues);
209288
- }
209289
- return typeKeywordMapper.enum(["asConst", "asPascalConst"].includes(options.enumType) ? `${current.args.typeName}Key` : current.args.typeName);
209290
- },
209291
- ref(tree, _options) {
209292
- const { current } = tree;
209293
- return typeKeywordMapper.ref(current.args.name);
209294
- },
209295
- blob() {
209296
- return typeKeywordMapper.blob();
209297
- },
209298
- tuple(tree, options) {
209299
- var _a;
209300
- const { current, schema, name } = tree;
209301
- return typeKeywordMapper.tuple(current.args.items.map((it) => this.parse({
209302
- schema,
209303
- parent: current,
209304
- name,
209305
- current: it,
209306
- siblings: []
209307
- }, options)).filter(Boolean), current.args.rest && ((_a = this.parse({
209308
- schema,
209309
- parent: current,
209310
- name,
209311
- current: current.args.rest,
209312
- siblings: []
209313
- }, options)) != null ? _a : void 0), current.args.min, current.args.max);
209314
- },
209315
- const(tree, _options) {
209316
- const { current } = tree;
209317
- return typeKeywordMapper.const(current.args.name, current.args.format);
209318
- },
209319
- object(tree, options) {
209320
- var _a, _b, _c, _d, _e;
209321
- const { current, schema, name } = tree;
209322
- const properties = Object.entries(((_a = current.args) == null ? void 0 : _a.properties) || {}).filter((item) => {
209323
- const schemas = item[1];
209324
- return schemas && typeof schemas.map === "function";
209325
- }).map(([name2, schemas]) => {
209326
- var _a2, _b2, _c2, _d2, _e2;
209327
- const mappedName = ((_a2 = schemas.find((schema2) => schema2.keyword === schemaKeywords.name)) == null ? void 0 : _a2.args) || name2;
209328
- const isNullish = schemas.some((schema2) => schema2.keyword === schemaKeywords.nullish);
209329
- const isNullable = schemas.some((schema2) => schema2.keyword === schemaKeywords.nullable);
209330
- const isOptional = schemas.some((schema2) => schema2.keyword === schemaKeywords.optional);
209331
- const isReadonly = schemas.some((schema2) => schema2.keyword === schemaKeywords.readOnly);
209332
- const describeSchema = schemas.find((schema2) => schema2.keyword === schemaKeywords.describe);
209333
- const deprecatedSchema = schemas.find((schema2) => schema2.keyword === schemaKeywords.deprecated);
209334
- const defaultSchema = schemas.find((schema2) => schema2.keyword === schemaKeywords.default);
209335
- const exampleSchema = schemas.find((schema2) => schema2.keyword === schemaKeywords.example);
209336
- const schemaSchema = schemas.find((schema2) => schema2.keyword === schemaKeywords.schema);
209337
- const minSchema = schemas.find((schema2) => schema2.keyword === schemaKeywords.min);
209338
- const maxSchema = schemas.find((schema2) => schema2.keyword === schemaKeywords.max);
209339
- const matchesSchema = schemas.find((schema2) => schema2.keyword === schemaKeywords.matches);
209340
- let type = schemas.map((it) => this.parse({
209341
- schema,
209342
- parent: current,
209343
- name: name2,
209344
- current: it,
209345
- siblings: schemas
209346
- }, options)).filter(Boolean)[0];
209347
- if (isNullable) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] });
209348
- if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(options.optionalType)) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
209349
- if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(options.optionalType)) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
209350
- return appendJSDocToNode({
209351
- node: createPropertySignature({
209352
- questionToken: isOptional || isNullish ? ["questionToken", "questionTokenAndUndefined"].includes(options.optionalType) : false,
209353
- name: mappedName,
209354
- type,
209355
- readOnly: isReadonly
209356
- }),
209357
- comments: [
209358
- describeSchema ? `@description ${jsStringEscape$1(describeSchema.args)}` : void 0,
209359
- deprecatedSchema ? "@deprecated" : void 0,
209360
- minSchema ? `@minLength ${minSchema.args}` : void 0,
209361
- maxSchema ? `@maxLength ${maxSchema.args}` : void 0,
209362
- matchesSchema ? `@pattern ${matchesSchema.args}` : void 0,
209363
- defaultSchema ? `@default ${defaultSchema.args}` : void 0,
209364
- exampleSchema ? `@example ${exampleSchema.args}` : void 0,
209365
- ((_b2 = schemaSchema == null ? void 0 : schemaSchema.args) == null ? void 0 : _b2.type) || ((_c2 = schemaSchema == null ? void 0 : schemaSchema.args) == null ? void 0 : _c2.format) ? [`@type ${((_d2 = schemaSchema == null ? void 0 : schemaSchema.args) == null ? void 0 : _d2.type) || "unknown"}${!isOptional ? "" : " | undefined"}`, (_e2 = schemaSchema == null ? void 0 : schemaSchema.args) == null ? void 0 : _e2.format].filter(Boolean).join(", ") : void 0
209366
- ].filter(Boolean)
209333
+ }
209334
+ return elements;
209335
+ }
209336
+ const printerTs = definePrinter((options) => {
209337
+ const addsUndefined = OPTIONAL_ADDS_UNDEFINED.has(options.optionalType);
209338
+ return {
209339
+ name: "typescript",
209340
+ options,
209341
+ nodes: {
209342
+ any: () => keywordTypeNodes.any,
209343
+ unknown: () => keywordTypeNodes.unknown,
209344
+ void: () => keywordTypeNodes.void,
209345
+ never: () => keywordTypeNodes.never,
209346
+ boolean: () => keywordTypeNodes.boolean,
209347
+ null: () => keywordTypeNodes.null,
209348
+ blob: () => createTypeReferenceNode("Blob", []),
209349
+ string: () => keywordTypeNodes.string,
209350
+ uuid: () => keywordTypeNodes.string,
209351
+ email: () => keywordTypeNodes.string,
209352
+ url: (node) => {
209353
+ if (node.path) return createUrlTemplateType(node.path);
209354
+ return keywordTypeNodes.string;
209355
+ },
209356
+ datetime: () => keywordTypeNodes.string,
209357
+ number: () => keywordTypeNodes.number,
209358
+ integer: () => keywordTypeNodes.number,
209359
+ bigint: () => keywordTypeNodes.bigint,
209360
+ date: dateOrStringNode,
209361
+ time: dateOrStringNode,
209362
+ ref(node) {
209363
+ var _a;
209364
+ if (!node.name) return;
209365
+ const refName = node.ref ? (_a = node.ref.split("/").at(-1)) != null ? _a : node.name : node.name;
209366
+ return createTypeReferenceNode(node.ref ? this.options.resolver.default(refName, "type") : refName, void 0);
209367
+ },
209368
+ enum(node) {
209369
+ var _a, _b, _c, _d;
209370
+ const values = (_c = (_b = (_a = node.namedEnumValues) == null ? void 0 : _a.map((v) => v.value)) != null ? _b : node.enumValues) != null ? _c : [];
209371
+ if (this.options.enumType === "inlineLiteral" || !node.name) return (_d = createUnionDeclaration({
209372
+ withParentheses: true,
209373
+ nodes: values.filter((v) => v !== null).map((value) => constToTypeNode(value, typeof value)).filter(Boolean)
209374
+ })) != null ? _d : void 0;
209375
+ const resolvedName = this.options.resolver.default(node.name, "type");
209376
+ return createTypeReferenceNode(ENUM_TYPES_WITH_KEY_SUFFIX.has(this.options.enumType) ? `${resolvedName}Key` : resolvedName, void 0);
209377
+ },
209378
+ union(node) {
209379
+ var _a, _b, _c;
209380
+ const members = (_a = node.members) != null ? _a : [];
209381
+ const hasStringLiteral = members.some((m) => m.type === "enum" && (m.enumType === "string" || m.primitive === "string"));
209382
+ const hasPlainString = members.some((m) => isPlainStringType(m));
209383
+ if (hasStringLiteral && hasPlainString) return (_b = createUnionDeclaration({
209384
+ withParentheses: true,
209385
+ nodes: members.map((m) => {
209386
+ if (isPlainStringType(m)) return createIntersectionDeclaration({
209387
+ nodes: [keywordTypeNodes.string, createTypeLiteralNode([])],
209388
+ withParentheses: true
209389
+ });
209390
+ return this.print(m);
209391
+ }).filter(Boolean)
209392
+ })) != null ? _b : void 0;
209393
+ return (_c = createUnionDeclaration({
209394
+ withParentheses: true,
209395
+ nodes: buildMemberNodes(members, this.print)
209396
+ })) != null ? _c : void 0;
209397
+ },
209398
+ intersection(node) {
209399
+ var _a;
209400
+ return (_a = createIntersectionDeclaration({
209401
+ withParentheses: true,
209402
+ nodes: buildMemberNodes(node.members, this.print)
209403
+ })) != null ? _a : void 0;
209404
+ },
209405
+ array(node) {
209406
+ var _a, _b;
209407
+ return (_b = createArrayDeclaration({
209408
+ nodes: ((_a = node.items) != null ? _a : []).map((item) => this.print(item)).filter(Boolean),
209409
+ arrayType: this.options.arrayType
209410
+ })) != null ? _b : void 0;
209411
+ },
209412
+ tuple(node) {
209413
+ return buildTupleNode(node, this.print);
209414
+ },
209415
+ object(node) {
209416
+ const { print, options: options2 } = this;
209417
+ const addsQuestionToken = OPTIONAL_ADDS_QUESTION_TOKEN.has(options2.optionalType);
209418
+ const propertyNodes = node.properties.map((prop) => {
209419
+ var _a;
209420
+ const baseType = (_a = print(prop.schema)) != null ? _a : keywordTypeNodes.unknown;
209421
+ const type = buildPropertyType(prop.schema, baseType, options2.optionalType);
209422
+ return appendJSDocToNode({
209423
+ node: createPropertySignature({
209424
+ questionToken: prop.schema.optional || prop.schema.nullish ? addsQuestionToken : false,
209425
+ name: prop.name,
209426
+ type,
209427
+ readOnly: prop.schema.readOnly
209428
+ }),
209429
+ comments: buildPropertyJSDocComments(prop.schema)
209430
+ });
209367
209431
  });
209368
- });
209369
- let additionalProperties;
209370
- if ((_c = (_b = current.args) == null ? void 0 : _b.additionalProperties) == null ? void 0 : _c.length) {
209371
- let additionalPropertiesType = current.args.additionalProperties.map((it) => this.parse({
209372
- schema,
209373
- parent: current,
209374
- name,
209375
- current: it,
209376
- siblings: []
209377
- }, options)).filter(Boolean).at(0);
209378
- if ((_d = current.args) == null ? void 0 : _d.additionalProperties.some((schema2) => isKeyword(schema2, schemaKeywords.nullable))) additionalPropertiesType = createUnionDeclaration({ nodes: [additionalPropertiesType, keywordTypeNodes.null] });
209379
- additionalProperties = createIndexSignature(properties.length > 0 ? keywordTypeNodes.unknown : additionalPropertiesType);
209380
- }
209381
- let patternProperties;
209382
- if ((_e = current.args) == null ? void 0 : _e.patternProperties) {
209383
- const allPatternSchemas = Object.values(current.args.patternProperties).flat();
209384
- if (allPatternSchemas.length > 0) {
209385
- patternProperties = allPatternSchemas.map((it) => this.parse({
209386
- schema,
209387
- parent: current,
209388
- name,
209389
- current: it,
209390
- siblings: []
209391
- }, options)).filter(Boolean).at(0);
209392
- if (allPatternSchemas.some((schema2) => isKeyword(schema2, schemaKeywords.nullable))) patternProperties = createUnionDeclaration({ nodes: [patternProperties, keywordTypeNodes.null] });
209393
- patternProperties = createIndexSignature(patternProperties);
209394
- }
209432
+ const allElements = [...propertyNodes, ...buildIndexSignatures(node, propertyNodes.length, print)];
209433
+ if (!allElements.length) return keywordTypeNodes.object;
209434
+ return createTypeLiteralNode(allElements);
209395
209435
  }
209396
- return typeKeywordMapper.object([
209397
- ...properties,
209398
- additionalProperties,
209399
- patternProperties
209400
- ].filter(Boolean));
209401
- },
209402
- datetime() {
209403
- return typeKeywordMapper.datetime();
209404
- },
209405
- date(tree) {
209406
- const { current } = tree;
209407
- return typeKeywordMapper.date(current.args.type);
209408
209436
  },
209409
- time(tree) {
209410
- const { current } = tree;
209411
- return typeKeywordMapper.time(current.args.type);
209437
+ print(node) {
209438
+ let type = this.print(node);
209439
+ if (!type) return;
209440
+ if (node.nullable) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] });
209441
+ if ((node.nullish || node.optional) && addsUndefined) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
209442
+ const { typeName, syntaxType = "type", description, keysToOmit } = this.options;
209443
+ if (!typeName) return type;
209444
+ const useTypeGeneration = syntaxType === "type" || type.kind === syntaxKind.union || !!(keysToOmit == null ? void 0 : keysToOmit.length);
209445
+ return createTypeDeclaration({
209446
+ name: typeName,
209447
+ isExportable: true,
209448
+ type: (keysToOmit == null ? void 0 : keysToOmit.length) ? createOmitDeclaration({
209449
+ keys: keysToOmit,
209450
+ type,
209451
+ nonNullable: true
209452
+ }) : type,
209453
+ syntax: useTypeGeneration ? "type" : "interface",
209454
+ comments: [
209455
+ (node == null ? void 0 : node.title) ? jsStringEscape$1(node.title) : void 0,
209456
+ description ? `@description ${jsStringEscape$1(description)}` : void 0,
209457
+ (node == null ? void 0 : node.deprecated) ? "@deprecated" : void 0,
209458
+ node && "min" in node && node.min !== void 0 ? `@minLength ${node.min}` : void 0,
209459
+ node && "max" in node && node.max !== void 0 ? `@maxLength ${node.max}` : void 0,
209460
+ node && "pattern" in node && node.pattern ? `@pattern ${node.pattern}` : void 0,
209461
+ (node == null ? void 0 : node.default) ? `@default ${node.default}` : void 0,
209462
+ (node == null ? void 0 : node.example) ? `@example ${node.example}` : void 0
209463
+ ]
209464
+ });
209412
209465
  }
209413
- }
209466
+ };
209414
209467
  });
209415
- function Type$1({ name, typedName, tree, keysToOmit, schema, optionalType, arrayType, syntaxType, enumType, enumKeyCasing, description }) {
209416
- const typeNodes = [];
209417
- if (!tree.length) return "";
209418
- const schemaFromTree = tree.find((item) => item.keyword === schemaKeywords.schema);
209419
- const enumSchemas = SchemaGenerator.deepSearch(tree, schemaKeywords.enum);
209420
- let type = tree.map((current, _index, siblings) => parse$1({
209421
- name,
209422
- schema,
209423
- parent: void 0,
209424
- current,
209425
- siblings
209426
- }, {
209468
+ function getEnumNames({ node, enumType, resolver }) {
209469
+ const resolved = resolver.default(node.name, "type");
209470
+ return {
209471
+ enumName: enumType === "asPascalConst" ? resolved : camelCase$a(node.name),
209472
+ typeName: ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) ? `${resolved}Key` : resolved,
209473
+ refName: resolved
209474
+ };
209475
+ }
209476
+ function Enum({ node, enumType, enumKeyCasing, resolver }) {
209477
+ var _a, _b, _c, _d;
209478
+ const { enumName, typeName, refName } = getEnumNames({
209479
+ node,
209480
+ enumType,
209481
+ resolver
209482
+ });
209483
+ const [nameNode, typeNode] = createEnumDeclaration({
209484
+ name: enumName,
209485
+ typeName,
209486
+ enums: (_d = (_c = (_a = node.namedEnumValues) == null ? void 0 : _a.map((v) => [trimQuotes$1(v.name.toString()), v.value])) != null ? _c : (_b = node.enumValues) == null ? void 0 : _b.filter((v) => v !== null && v !== void 0).map((v) => [trimQuotes$1(v.toString()), v])) != null ? _d : [],
209487
+ type: enumType,
209488
+ enumKeyCasing
209489
+ });
209490
+ const needsRefAlias = ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && refName !== typeName;
209491
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
209492
+ nameNode && /* @__PURE__ */ jsx(File.Source, {
209493
+ name: enumName,
209494
+ isExportable: true,
209495
+ isIndexable: true,
209496
+ isTypeOnly: false,
209497
+ children: safePrint(nameNode)
209498
+ }),
209499
+ /* @__PURE__ */ jsx(File.Source, {
209500
+ name: typeName,
209501
+ isIndexable: true,
209502
+ isExportable: ENUM_TYPES_WITH_RUNTIME_VALUE.has(enumType),
209503
+ isTypeOnly: ENUM_TYPES_WITH_TYPE_ONLY.has(enumType),
209504
+ children: safePrint(typeNode)
209505
+ }),
209506
+ needsRefAlias && /* @__PURE__ */ jsx(File.Source, {
209507
+ name: refName,
209508
+ isExportable: true,
209509
+ isIndexable: true,
209510
+ isTypeOnly: true,
209511
+ children: `export type ${refName} = ${typeName}`
209512
+ })
209513
+ ] });
209514
+ }
209515
+ function Type({ name, typedName, node, keysToOmit, optionalType, arrayType, syntaxType, enumType, enumKeyCasing, description, resolver }) {
209516
+ const resolvedDescription = description || (node == null ? void 0 : node.description);
209517
+ const enumSchemaNodes = collect(node, { schema(n) {
209518
+ if (n.type === "enum" && n.name) return n;
209519
+ } });
209520
+ const typeNode = printerTs({
209427
209521
  optionalType,
209428
209522
  arrayType,
209429
- enumType
209430
- })).filter(Boolean).at(0) || typeKeywordMapper.undefined();
209431
- if (["asConst", "asPascalConst"].includes(enumType) && enumSchemas.length > 0) {
209432
- const isDirectEnum = schema.type === "array" && schema.items !== void 0;
209433
- const isEnumOnly = "enum" in schema && schema.enum;
209434
- if (isDirectEnum || isEnumOnly) {
209435
- type = createTypeReferenceNode(`${enumSchemas[0].args.typeName}Key`);
209436
- if (schema.type === "array") if (arrayType === "generic") type = createTypeReferenceNode(createIdentifier("Array"), [type]);
209437
- else type = createArrayTypeNode(type);
209438
- }
209439
- }
209440
- if (schemaFromTree && isKeyword(schemaFromTree, schemaKeywords.schema)) {
209441
- const isNullish = tree.some((item) => item.keyword === schemaKeywords.nullish);
209442
- const isNullable = tree.some((item) => item.keyword === schemaKeywords.nullable);
209443
- const isOptional = tree.some((item) => item.keyword === schemaKeywords.optional);
209444
- if (isNullable) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] });
209445
- if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
209446
- if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
209447
- }
209448
- const useTypeGeneration = syntaxType === "type" || [syntaxKind.union].includes(type.kind) || !!(keysToOmit == null ? void 0 : keysToOmit.length);
209449
- typeNodes.push(createTypeDeclaration({
209450
- name,
209451
- isExportable: true,
209452
- type: (keysToOmit == null ? void 0 : keysToOmit.length) ? createOmitDeclaration({
209453
- keys: keysToOmit,
209454
- type,
209455
- nonNullable: true
209456
- }) : type,
209457
- syntax: useTypeGeneration ? "type" : "interface",
209458
- comments: [
209459
- schema.title ? `${jsStringEscape$1(schema.title)}` : void 0,
209460
- description ? `@description ${jsStringEscape$1(description)}` : void 0,
209461
- schema.deprecated ? "@deprecated" : void 0,
209462
- schema.minLength ? `@minLength ${schema.minLength}` : void 0,
209463
- schema.maxLength ? `@maxLength ${schema.maxLength}` : void 0,
209464
- schema.pattern ? `@pattern ${schema.pattern}` : void 0,
209465
- schema.default ? `@default ${schema.default}` : void 0,
209466
- schema.example ? `@example ${schema.example}` : void 0
209467
- ]
209468
- }));
209469
- const enums = [...new Set(enumSchemas)].map((enumSchema) => {
209470
- const name2 = enumType === "asPascalConst" ? pascalCase$6(enumSchema.args.name) : camelCase$a(enumSchema.args.name);
209471
- const typeName = ["asConst", "asPascalConst"].includes(enumType) ? `${enumSchema.args.typeName}Key` : enumSchema.args.typeName;
209472
- const [nameNode, typeNode] = createEnumDeclaration({
209473
- name: name2,
209474
- typeName,
209475
- enums: enumSchema.args.items.map((item) => {
209476
- var _a;
209477
- return item.value === void 0 ? void 0 : [trimQuotes$1((_a = item.name) == null ? void 0 : _a.toString()), item.value];
209478
- }).filter(Boolean),
209479
- type: enumType,
209480
- enumKeyCasing
209481
- });
209523
+ enumType,
209524
+ typeName: name,
209525
+ syntaxType,
209526
+ description: resolvedDescription,
209527
+ keysToOmit,
209528
+ resolver
209529
+ }).print(node);
209530
+ if (!typeNode) return;
209531
+ const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((node2) => {
209482
209532
  return {
209483
- nameNode,
209484
- typeNode,
209485
- name: name2,
209486
- typeName
209533
+ node: node2,
209534
+ ...getEnumNames({
209535
+ node: node2,
209536
+ enumType,
209537
+ resolver
209538
+ })
209487
209539
  };
209488
209540
  });
209489
209541
  const shouldExportEnums = enumType !== "inlineLiteral";
209490
209542
  const shouldExportType = enumType === "inlineLiteral" || enums.every((item) => item.typeName !== name);
209491
- return /* @__PURE__ */ jsxs(Fragment, { children: [shouldExportEnums && enums.map(({ name: name2, nameNode, typeName, typeNode }) => /* @__PURE__ */ jsxs(Fragment, { children: [nameNode && /* @__PURE__ */ jsx(File.Source, {
209492
- name: name2,
209493
- isExportable: true,
209494
- isIndexable: true,
209495
- isTypeOnly: false,
209496
- children: safePrint(nameNode)
209497
- }), /* @__PURE__ */ jsx(File.Source, {
209498
- name: typeName,
209499
- isIndexable: true,
209500
- isExportable: [
209501
- "enum",
209502
- "asConst",
209503
- "asPascalConst",
209504
- "constEnum",
209505
- "literal",
209506
- void 0
209507
- ].includes(enumType),
209508
- isTypeOnly: [
209509
- "asConst",
209510
- "asPascalConst",
209511
- "literal",
209512
- void 0
209513
- ].includes(enumType),
209514
- children: safePrint(typeNode)
209515
- })] })), shouldExportType && /* @__PURE__ */ jsx(File.Source, {
209543
+ return /* @__PURE__ */ jsxs(Fragment, { children: [shouldExportEnums && enums.map(({ node: node2 }) => /* @__PURE__ */ jsx(Enum, {
209544
+ node: node2,
209545
+ enumType,
209546
+ enumKeyCasing,
209547
+ resolver
209548
+ })), shouldExportType && /* @__PURE__ */ jsx(File.Source, {
209516
209549
  name: typedName,
209517
209550
  isTypeOnly: true,
209518
209551
  isExportable: true,
209519
209552
  isIndexable: true,
209520
- children: safePrint(...typeNodes)
209553
+ children: safePrint(typeNode)
209521
209554
  })] });
209522
209555
  }
209523
209556
 
@@ -209599,871 +209632,21 @@ function usePluginDriver() {
209599
209632
  return meta.driver;
209600
209633
  }
209601
209634
 
209602
- function useOas() {
209603
- const { meta } = useFabric();
209604
- return meta.oas;
209605
- }
209606
- function useOperationManager(generator) {
209607
- const plugin = usePlugin();
209608
- const driver = usePluginDriver();
209609
- const defaultPluginName = plugin.name;
209610
- const getName = (operation, { prefix = "", suffix = "", pluginName = defaultPluginName, type }) => {
209611
- return driver.resolveName({
209612
- name: `${prefix} ${operation.getOperationId()} ${suffix}`,
209613
- pluginName,
209614
- type
209615
- });
209616
- };
209617
- const getGroup = (operation) => {
209618
- var _a;
209619
- return {
209620
- tag: (_a = operation.getTags().at(0)) == null ? void 0 : _a.name,
209621
- path: operation.path
209622
- };
209623
- };
209624
- const getSchemas = (operation, params) => {
209625
- if (!generator) throw new Error(`useOperationManager: 'generator' parameter is required but was not provided`);
209626
- return generator.getSchemas(operation, { resolveName: (name) => {
209627
- var _a;
209628
- return driver.resolveName({
209629
- name,
209630
- pluginName: (_a = params == null ? void 0 : params.pluginName) != null ? _a : defaultPluginName,
209631
- type: params == null ? void 0 : params.type
209632
- });
209633
- } });
209634
- };
209635
- const getFile = (operation, { prefix, suffix, pluginName = defaultPluginName, extname = ".ts" } = {}) => {
209636
- const name = getName(operation, {
209637
- type: "file",
209638
- pluginName,
209639
- prefix,
209640
- suffix
209641
- });
209642
- const group = getGroup(operation);
209643
- const file = driver.getFile({
209644
- name,
209645
- extname,
209646
- pluginName,
209647
- options: {
209648
- type: "file",
209649
- pluginName,
209650
- group
209651
- }
209652
- });
209653
- return {
209654
- ...file,
209655
- meta: {
209656
- ...file.meta,
209657
- name,
209658
- pluginName,
209659
- group
209660
- }
209661
- };
209662
- };
209663
- const groupSchemasByName = (operation, { pluginName = defaultPluginName, type }) => {
209664
- var _a, _b, _c, _d;
209665
- if (!generator) throw new Error(`useOperationManager: 'generator' parameter is required but was not provided`);
209666
- const schemas = getSchemas(operation);
209667
- const errors = (schemas.errors || []).reduce((prev, acc) => {
209668
- if (!acc.statusCode) return prev;
209669
- prev[acc.statusCode] = driver.resolveName({
209670
- name: acc.name,
209671
- pluginName,
209672
- type
209673
- });
209674
- return prev;
209675
- }, {});
209676
- const responses = (schemas.responses || []).reduce((prev, acc) => {
209677
- if (!acc.statusCode) return prev;
209678
- prev[acc.statusCode] = driver.resolveName({
209679
- name: acc.name,
209680
- pluginName,
209681
- type
209682
- });
209683
- return prev;
209684
- }, {});
209685
- return {
209686
- request: ((_a = schemas.request) == null ? void 0 : _a.name) ? driver.resolveName({
209687
- name: schemas.request.name,
209688
- pluginName,
209689
- type
209690
- }) : void 0,
209691
- parameters: {
209692
- path: ((_b = schemas.pathParams) == null ? void 0 : _b.name) ? driver.resolveName({
209693
- name: schemas.pathParams.name,
209694
- pluginName,
209695
- type
209696
- }) : void 0,
209697
- query: ((_c = schemas.queryParams) == null ? void 0 : _c.name) ? driver.resolveName({
209698
- name: schemas.queryParams.name,
209699
- pluginName,
209700
- type
209701
- }) : void 0,
209702
- header: ((_d = schemas.headerParams) == null ? void 0 : _d.name) ? driver.resolveName({
209703
- name: schemas.headerParams.name,
209704
- pluginName,
209705
- type
209706
- }) : void 0
209707
- },
209708
- responses: {
209709
- ...responses,
209710
- ["default"]: driver.resolveName({
209711
- name: schemas.response.name,
209712
- pluginName,
209713
- type
209714
- }),
209715
- ...errors
209716
- },
209717
- errors
209718
- };
209719
- };
209720
- return {
209721
- getName,
209722
- getFile,
209723
- getSchemas,
209724
- groupSchemasByName,
209725
- getGroup
209726
- };
209727
- }
209728
- function useSchemaManager() {
209729
- const plugin = usePlugin();
209730
- const driver = usePluginDriver();
209731
- const getName = (name, { pluginName = plugin.name, type }) => {
209732
- return driver.resolveName({
209733
- name,
209734
- pluginName,
209735
- type
209736
- });
209737
- };
209738
- const getFile = (name, { mode = "split", pluginName = plugin.name, extname = ".ts", group } = {}) => {
209739
- const resolvedName = mode === "single" ? "" : getName(name, {
209740
- type: "file",
209741
- pluginName
209742
- });
209743
- const file = driver.getFile({
209744
- name: resolvedName,
209745
- extname,
209746
- pluginName,
209747
- options: {
209748
- type: "file",
209749
- pluginName,
209750
- group
209751
- }
209752
- });
209753
- return {
209754
- ...file,
209755
- meta: {
209756
- ...file.meta,
209757
- name: resolvedName,
209758
- pluginName
209759
- }
209760
- };
209761
- };
209762
- return {
209763
- getName,
209764
- getFile
209765
- };
209766
- }
209767
-
209768
- function stringify$1(value) {
209769
- if (value === void 0 || value === null) return '""';
209770
- return JSON.stringify(trimQuotes$1(value.toString()));
209771
- }
209772
- function printCombinedSchema({ name, schemas, driver }) {
209773
- const properties = {};
209774
- if (schemas.response) properties["response"] = createUnionDeclaration({ nodes: schemas.responses.map((res) => {
209775
- return createTypeReferenceNode(createIdentifier(driver.resolveName({
209776
- name: res.name,
209777
- pluginName: pluginTsName,
209778
- type: "function"
209779
- })), void 0);
209780
- }) });
209781
- if (schemas.request) properties["request"] = createTypeReferenceNode(createIdentifier(driver.resolveName({
209782
- name: schemas.request.name,
209783
- pluginName: pluginTsName,
209784
- type: "function"
209785
- })), void 0);
209786
- if (schemas.pathParams) properties["pathParams"] = createTypeReferenceNode(createIdentifier(driver.resolveName({
209787
- name: schemas.pathParams.name,
209788
- pluginName: pluginTsName,
209789
- type: "function"
209790
- })), void 0);
209791
- if (schemas.queryParams) properties["queryParams"] = createTypeReferenceNode(createIdentifier(driver.resolveName({
209792
- name: schemas.queryParams.name,
209793
- pluginName: pluginTsName,
209794
- type: "function"
209795
- })), void 0);
209796
- if (schemas.headerParams) properties["headerParams"] = createTypeReferenceNode(createIdentifier(driver.resolveName({
209797
- name: schemas.headerParams.name,
209798
- pluginName: pluginTsName,
209799
- type: "function"
209800
- })), void 0);
209801
- if (schemas.errors) properties["errors"] = createUnionDeclaration({ nodes: schemas.errors.map((error) => {
209802
- return createTypeReferenceNode(createIdentifier(driver.resolveName({
209803
- name: error.name,
209804
- pluginName: pluginTsName,
209805
- type: "function"
209806
- })), void 0);
209807
- }) });
209808
- return safePrint(createTypeAliasDeclaration({
209809
- name,
209810
- type: createTypeLiteralNode(Object.keys(properties).map((key) => {
209811
- const type = properties[key];
209812
- if (!type) return;
209813
- return createPropertySignature({
209814
- name: pascalCase$6(key),
209815
- type
209816
- });
209817
- }).filter(Boolean)),
209818
- modifiers: [modifiers.export]
209819
- }));
209820
- }
209821
- function printRequestSchema({ baseName, operation, schemas, driver }) {
209822
- const name = driver.resolveName({
209823
- name: `${baseName} Request`,
209824
- pluginName: pluginTsName,
209825
- type: "type"
209826
- });
209827
- const results = [];
209828
- const dataRequestProperties = [];
209829
- if (schemas.request) {
209830
- const identifier = driver.resolveName({
209831
- name: schemas.request.name,
209832
- pluginName: pluginTsName,
209833
- type: "type"
209834
- });
209835
- dataRequestProperties.push(createPropertySignature({
209836
- name: "data",
209837
- questionToken: true,
209838
- type: createTypeReferenceNode(createIdentifier(identifier), void 0)
209839
- }));
209840
- } else dataRequestProperties.push(createPropertySignature({
209841
- name: "data",
209842
- questionToken: true,
209843
- type: keywordTypeNodes.never
209844
- }));
209845
- if (schemas.pathParams) {
209846
- const identifier = driver.resolveName({
209847
- name: schemas.pathParams.name,
209848
- pluginName: pluginTsName,
209849
- type: "type"
209850
- });
209851
- dataRequestProperties.push(createPropertySignature({
209852
- name: "pathParams",
209853
- type: createTypeReferenceNode(createIdentifier(identifier), void 0)
209854
- }));
209855
- } else dataRequestProperties.push(createPropertySignature({
209856
- name: "pathParams",
209857
- questionToken: true,
209858
- type: keywordTypeNodes.never
209859
- }));
209860
- if (schemas.queryParams) {
209861
- const identifier = driver.resolveName({
209862
- name: schemas.queryParams.name,
209863
- pluginName: pluginTsName,
209864
- type: "type"
209865
- });
209866
- dataRequestProperties.push(createPropertySignature({
209867
- name: "queryParams",
209868
- questionToken: true,
209869
- type: createTypeReferenceNode(createIdentifier(identifier), void 0)
209870
- }));
209871
- } else dataRequestProperties.push(createPropertySignature({
209872
- name: "queryParams",
209873
- questionToken: true,
209874
- type: keywordTypeNodes.never
209875
- }));
209876
- if (schemas.headerParams) {
209877
- const identifier = driver.resolveName({
209878
- name: schemas.headerParams.name,
209879
- pluginName: pluginTsName,
209880
- type: "type"
209881
- });
209882
- dataRequestProperties.push(createPropertySignature({
209883
- name: "headerParams",
209884
- questionToken: true,
209885
- type: createTypeReferenceNode(createIdentifier(identifier), void 0)
209886
- }));
209887
- } else dataRequestProperties.push(createPropertySignature({
209888
- name: "headerParams",
209889
- questionToken: true,
209890
- type: keywordTypeNodes.never
209891
- }));
209892
- dataRequestProperties.push(createPropertySignature({
209893
- name: "url",
209894
- type: createUrlTemplateType(operation.path)
209895
- }));
209896
- const dataRequestNode = createTypeAliasDeclaration({
209897
- name,
209898
- type: createTypeLiteralNode(dataRequestProperties),
209899
- modifiers: [modifiers.export]
209900
- });
209901
- results.push(safePrint(dataRequestNode));
209902
- return results.join("\n\n");
209903
- }
209904
- function printResponseSchema({ baseName, schemas, driver, unknownType }) {
209905
- const results = [];
209906
- const name = driver.resolveName({
209907
- name: `${baseName} ResponseData`,
209908
- pluginName: pluginTsName,
209909
- type: "type"
209910
- });
209911
- if (schemas.responses && schemas.responses.length > 0) {
209912
- const responsesProperties = schemas.responses.map((res) => {
209913
- var _a, _b;
209914
- const identifier = driver.resolveName({
209915
- name: res.name,
209916
- pluginName: pluginTsName,
209917
- type: "type"
209918
- });
209919
- return createPropertySignature({
209920
- name: (_b = (_a = res.statusCode) == null ? void 0 : _a.toString()) != null ? _b : "default",
209921
- type: createTypeReferenceNode(createIdentifier(identifier), void 0)
209922
- });
209923
- });
209924
- const responsesNode = createTypeAliasDeclaration({
209925
- name: `${baseName}Responses`,
209926
- type: createTypeLiteralNode(responsesProperties),
209927
- modifiers: [modifiers.export]
209928
- });
209929
- results.push(safePrint(responsesNode));
209930
- const responseNode = createTypeAliasDeclaration({
209931
- name,
209932
- type: createIndexedAccessTypeNode(createTypeReferenceNode(createIdentifier(`${baseName}Responses`), void 0), createTypeOperatorNode(ts.SyntaxKind.KeyOfKeyword, createTypeReferenceNode(createIdentifier(`${baseName}Responses`), void 0))),
209933
- modifiers: [modifiers.export]
209934
- });
209935
- results.push(safePrint(responseNode));
209936
- } else {
209937
- const responseNode = createTypeAliasDeclaration({
209938
- name,
209939
- modifiers: [modifiers.export],
209940
- type: getUnknownType(unknownType)
209941
- });
209942
- results.push(safePrint(responseNode));
209943
- }
209944
- return results.join("\n\n");
209945
- }
209946
- const typeGenerator$1 = createReactGenerator({
209947
- name: "typescript",
209948
- Operation({ operation, generator, plugin }) {
209949
- const { options, options: { enumType, enumKeyCasing, syntaxType, optionalType, arrayType, unknownType, paramsCasing } } = plugin;
209950
- const mode = useMode();
209951
- const driver = usePluginDriver();
209952
- const oas = useOas();
209953
- const { getSchemas, getFile, getName, getGroup } = useOperationManager(generator);
209954
- const schemaManager = useSchemaManager();
209955
- const name = getName(operation, {
209956
- type: "type",
209957
- pluginName: pluginTsName
209958
- });
209959
- const file = getFile(operation);
209960
- const schemas = getSchemas(operation);
209961
- const schemaGenerator = new SchemaGenerator(options, {
209962
- fabric: generator.context.fabric,
209963
- oas,
209964
- events: generator.context.events,
209965
- plugin,
209966
- driver,
209967
- mode,
209968
- override: options.override
209969
- });
209970
- const operationSchemas = [
209971
- schemas.pathParams,
209972
- schemas.queryParams,
209973
- schemas.headerParams,
209974
- schemas.statusCodes,
209975
- schemas.request,
209976
- schemas.response
209977
- ].flat().filter(Boolean);
209978
- const mapOperationSchema = ({ name: name2, schema, description, keysToOmit, ...options2 }) => {
209979
- const transformedSchema = paramsCasing && isParameterSchema(name2) ? applyParamsCasing(schema, paramsCasing) : schema;
209980
- const tree = schemaGenerator.parse({
209981
- schema: transformedSchema,
209982
- name: name2,
209983
- parentName: null
209984
- });
209985
- const imports = getImports(tree);
209986
- const group = options2.operation ? getGroup(options2.operation) : void 0;
209987
- const type = {
209988
- name: schemaManager.getName(name2, { type: "type" }),
209989
- typedName: schemaManager.getName(name2, { type: "type" }),
209990
- file: schemaManager.getFile(options2.operationName || name2, { group })
209991
- };
209992
- return /* @__PURE__ */ jsxs(Fragment, { children: [mode === "split" && imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
209993
- root: file.path,
209994
- path: imp.path,
209995
- name: imp.name,
209996
- isTypeOnly: true
209997
- }, [
209998
- name2,
209999
- imp.name,
210000
- imp.path,
210001
- imp.isTypeOnly
210002
- ].join("-"))), /* @__PURE__ */ jsx(Type$1, {
210003
- name: type.name,
210004
- typedName: type.typedName,
210005
- description,
210006
- tree,
210007
- schema: transformedSchema,
210008
- enumType,
210009
- enumKeyCasing,
210010
- optionalType,
210011
- arrayType,
210012
- keysToOmit,
210013
- syntaxType
210014
- })] });
210015
- };
210016
- const responseName = schemaManager.getName(schemas.response.name, { type: "type" });
210017
- const combinedSchemaName = operation.method === "get" ? `${name}Query` : `${name}Mutation`;
210018
- return /* @__PURE__ */ jsxs(File, {
210019
- baseName: file.baseName,
210020
- path: file.path,
210021
- meta: file.meta,
210022
- banner: getBanner({
210023
- oas,
210024
- output: plugin.options.output,
210025
- config: driver.config
210026
- }),
210027
- footer: getFooter({
210028
- oas,
210029
- output: plugin.options.output
210030
- }),
210031
- children: [operationSchemas.map(mapOperationSchema), generator.context.UNSTABLE_NAMING ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Source, {
210032
- name: `${name}Request`,
210033
- isExportable: true,
210034
- isIndexable: true,
210035
- isTypeOnly: true,
210036
- children: printRequestSchema({
210037
- baseName: name,
210038
- operation,
210039
- schemas,
210040
- driver
210041
- })
210042
- }), /* @__PURE__ */ jsx(File.Source, {
210043
- name: responseName,
210044
- isExportable: true,
210045
- isIndexable: true,
210046
- isTypeOnly: true,
210047
- children: printResponseSchema({
210048
- baseName: name,
210049
- schemas,
210050
- driver,
210051
- unknownType
210052
- })
210053
- })] }) : /* @__PURE__ */ jsx(File.Source, {
210054
- name: combinedSchemaName,
210055
- isExportable: true,
210056
- isIndexable: true,
210057
- isTypeOnly: true,
210058
- children: printCombinedSchema({
210059
- name: combinedSchemaName,
210060
- schemas,
210061
- driver
210062
- })
210063
- })]
210064
- });
210065
- },
210066
- Schema({ schema, plugin }) {
210067
- const { options: { enumType, enumKeyCasing, syntaxType, optionalType, arrayType, output } } = plugin;
210068
- const mode = useMode();
210069
- const oas = useOas();
210070
- const driver = usePluginDriver();
210071
- const { getName, getFile } = useSchemaManager();
210072
- const imports = getImports(schema.tree);
210073
- const schemaFromTree = schema.tree.find((item) => item.keyword === schemaKeywords.schema);
210074
- let typedName = getName(schema.name, { type: "type" });
210075
- if (["asConst", "asPascalConst"].includes(enumType) && schemaFromTree && isKeyword(schemaFromTree, schemaKeywords.enum)) typedName = typedName += "Key";
210076
- const type = {
210077
- name: getName(schema.name, { type: "function" }),
210078
- typedName,
210079
- file: getFile(schema.name)
210080
- };
210081
- return /* @__PURE__ */ jsxs(File, {
210082
- baseName: type.file.baseName,
210083
- path: type.file.path,
210084
- meta: type.file.meta,
210085
- banner: getBanner({
210086
- oas,
210087
- output,
210088
- config: driver.config
210089
- }),
210090
- footer: getFooter({
210091
- oas,
210092
- output
210093
- }),
210094
- children: [mode === "split" && imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
210095
- root: type.file.path,
210096
- path: imp.path,
210097
- name: imp.name,
210098
- isTypeOnly: true
210099
- }, [
210100
- schema.name,
210101
- imp.path,
210102
- imp.isTypeOnly
210103
- ].join("-"))), /* @__PURE__ */ jsx(Type$1, {
210104
- name: type.name,
210105
- typedName: type.typedName,
210106
- description: schema.value.description,
210107
- tree: schema.tree,
210108
- schema: schema.value,
210109
- enumType,
210110
- enumKeyCasing,
210111
- optionalType,
210112
- arrayType,
210113
- syntaxType
210114
- })]
210115
- });
210116
- }
210117
- });
210118
- const OPTIONAL_ADDS_UNDEFINED = /* @__PURE__ */ new Set(["undefined", "questionTokenAndUndefined"]);
210119
- const OPTIONAL_ADDS_QUESTION_TOKEN = /* @__PURE__ */ new Set(["questionToken", "questionTokenAndUndefined"]);
210120
- const ENUM_TYPES_WITH_KEY_SUFFIX = /* @__PURE__ */ new Set(["asConst", "asPascalConst"]);
210121
- const ENUM_TYPES_WITH_RUNTIME_VALUE = /* @__PURE__ */ new Set([
210122
- "enum",
210123
- "asConst",
210124
- "asPascalConst",
210125
- "constEnum",
210126
- "literal",
210127
- void 0
210128
- ]);
210129
- const ENUM_TYPES_WITH_TYPE_ONLY = /* @__PURE__ */ new Set([
210130
- "asConst",
210131
- "asPascalConst",
210132
- "literal",
210133
- void 0
210134
- ]);
210135
- function constToTypeNode(value, format) {
210136
- if (format === "boolean") return createLiteralTypeNode(value === true ? createTrue() : createFalse());
210137
- if (format === "number" && typeof value === "number") {
210138
- if (value < 0) return createLiteralTypeNode(createPrefixUnaryExpression(SyntaxKind.MinusToken, createNumericLiteral(Math.abs(value))));
210139
- return createLiteralTypeNode(createNumericLiteral(value));
210140
- }
210141
- return createLiteralTypeNode(createStringLiteral(String(value)));
210142
- }
210143
- function dateOrStringNode(node) {
210144
- return node.representation === "date" ? createTypeReferenceNode(createIdentifier("Date")) : keywordTypeNodes.string;
210145
- }
210146
- function buildMemberNodes(members, print) {
210147
- return (members != null ? members : []).map(print).filter(Boolean);
210148
- }
210149
- function buildTupleNode(node, print) {
210150
- var _a, _b;
210151
- let items = ((_a = node.items) != null ? _a : []).map(print).filter(Boolean);
210152
- const restNode = node.rest ? (_b = print(node.rest)) != null ? _b : void 0 : void 0;
210153
- const { min, max } = node;
210154
- if (max !== void 0) {
210155
- items = items.slice(0, max);
210156
- if (items.length < max && restNode) items = [...items, ...Array(max - items.length).fill(restNode)];
210157
- }
210158
- if (min !== void 0) items = items.map((item, i) => i >= min ? createOptionalTypeNode(item) : item);
210159
- if (max === void 0 && restNode) items.push(createRestTypeNode(createArrayTypeNode(restNode)));
210160
- return createTupleTypeNode(items);
210161
- }
210162
- function buildPropertyType(schema, baseType, optionalType) {
210163
- const addsUndefined = OPTIONAL_ADDS_UNDEFINED.has(optionalType);
210164
- let type = baseType;
210165
- if (schema.nullable) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] });
210166
- if ((schema.nullish || schema.optional) && addsUndefined) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
210167
- return type;
210168
- }
210169
- function buildPropertyJSDocComments(schema) {
210170
- return [
210171
- "description" in schema && schema.description ? `@description ${jsStringEscape$1(schema.description)}` : void 0,
210172
- "deprecated" in schema && schema.deprecated ? "@deprecated" : void 0,
210173
- "min" in schema && schema.min !== void 0 ? `@minLength ${schema.min}` : void 0,
210174
- "max" in schema && schema.max !== void 0 ? `@maxLength ${schema.max}` : void 0,
210175
- "pattern" in schema && schema.pattern ? `@pattern ${schema.pattern}` : void 0,
210176
- "default" in schema && schema.default !== void 0 ? `@default ${"primitive" in schema && schema.primitive === "string" ? stringify$1(schema.default) : schema.default}` : void 0,
210177
- "example" in schema && schema.example !== void 0 ? `@example ${schema.example}` : void 0,
210178
- "primitive" in schema && schema.primitive ? [`@type ${schema.primitive || "unknown"}`, "optional" in schema && schema.optional ? " | undefined" : void 0].filter(Boolean).join("") : void 0
210179
- ];
210180
- }
210181
- function buildIndexSignatures(node, propertyCount, print) {
210182
- var _a, _b;
210183
- const elements = [];
210184
- if (node.additionalProperties && node.additionalProperties !== true) {
210185
- const additionalType = (_a = print(node.additionalProperties)) != null ? _a : keywordTypeNodes.unknown;
210186
- elements.push(createIndexSignature(propertyCount > 0 ? keywordTypeNodes.unknown : additionalType));
210187
- } else if (node.additionalProperties === true) elements.push(createIndexSignature(keywordTypeNodes.unknown));
210188
- if (node.patternProperties) {
210189
- const first = Object.values(node.patternProperties)[0];
210190
- if (first) {
210191
- let patternType = (_b = print(first)) != null ? _b : keywordTypeNodes.unknown;
210192
- if (first.nullable) patternType = createUnionDeclaration({ nodes: [patternType, keywordTypeNodes.null] });
210193
- elements.push(createIndexSignature(patternType));
210194
- }
210195
- }
210196
- return elements;
210197
- }
210198
- const printerTs = definePrinter((options) => {
210199
- const addsUndefined = OPTIONAL_ADDS_UNDEFINED.has(options.optionalType);
210200
- return {
210201
- name: "typescript",
210202
- options,
210203
- nodes: {
210204
- any: () => keywordTypeNodes.any,
210205
- unknown: () => keywordTypeNodes.unknown,
210206
- void: () => keywordTypeNodes.void,
210207
- never: () => keywordTypeNodes.never,
210208
- boolean: () => keywordTypeNodes.boolean,
210209
- null: () => keywordTypeNodes.null,
210210
- blob: () => createTypeReferenceNode("Blob", []),
210211
- string: () => keywordTypeNodes.string,
210212
- uuid: () => keywordTypeNodes.string,
210213
- email: () => keywordTypeNodes.string,
210214
- url: (node) => {
210215
- if (node.path) return createUrlTemplateType(node.path);
210216
- return keywordTypeNodes.string;
210217
- },
210218
- datetime: () => keywordTypeNodes.string,
210219
- number: () => keywordTypeNodes.number,
210220
- integer: () => keywordTypeNodes.number,
210221
- bigint: () => keywordTypeNodes.bigint,
210222
- date: dateOrStringNode,
210223
- time: dateOrStringNode,
210224
- ref(node) {
210225
- if (!node.name) return;
210226
- return createTypeReferenceNode(node.name, void 0);
210227
- },
210228
- enum(node) {
210229
- var _a, _b, _c, _d;
210230
- const values = (_c = (_b = (_a = node.namedEnumValues) == null ? void 0 : _a.map((v) => v.value)) != null ? _b : node.enumValues) != null ? _c : [];
210231
- if (this.options.enumType === "inlineLiteral" || !node.name) return (_d = createUnionDeclaration({
210232
- withParentheses: true,
210233
- nodes: values.filter((v) => v !== null).map((value) => constToTypeNode(value, typeof value)).filter(Boolean)
210234
- })) != null ? _d : void 0;
210235
- const resolvedName = pascalCase$6(node.name);
210236
- return createTypeReferenceNode(ENUM_TYPES_WITH_KEY_SUFFIX.has(this.options.enumType) ? `${resolvedName}Key` : resolvedName, void 0);
210237
- },
210238
- union(node) {
210239
- var _a, _b, _c;
210240
- const members = (_a = node.members) != null ? _a : [];
210241
- const hasStringLiteral = members.some((m) => m.type === "enum" && (m.enumType === "string" || m.primitive === "string"));
210242
- const hasPlainString = members.some((m) => isPlainStringType(m));
210243
- if (hasStringLiteral && hasPlainString) return (_b = createUnionDeclaration({
210244
- withParentheses: true,
210245
- nodes: members.map((m) => {
210246
- if (isPlainStringType(m)) return createIntersectionDeclaration({
210247
- nodes: [keywordTypeNodes.string, createTypeLiteralNode([])],
210248
- withParentheses: true
210249
- });
210250
- return this.print(m);
210251
- }).filter(Boolean)
210252
- })) != null ? _b : void 0;
210253
- return (_c = createUnionDeclaration({
210254
- withParentheses: true,
210255
- nodes: buildMemberNodes(members, this.print)
210256
- })) != null ? _c : void 0;
210257
- },
210258
- intersection(node) {
210259
- var _a;
210260
- return (_a = createIntersectionDeclaration({
210261
- withParentheses: true,
210262
- nodes: buildMemberNodes(node.members, this.print)
210263
- })) != null ? _a : void 0;
210264
- },
210265
- array(node) {
210266
- var _a, _b;
210267
- return (_b = createArrayDeclaration({
210268
- nodes: ((_a = node.items) != null ? _a : []).map((item) => this.print(item)).filter(Boolean),
210269
- arrayType: this.options.arrayType
210270
- })) != null ? _b : void 0;
210271
- },
210272
- tuple(node) {
210273
- return buildTupleNode(node, this.print);
210274
- },
210275
- object(node) {
210276
- const { print, options: options2 } = this;
210277
- const addsQuestionToken = OPTIONAL_ADDS_QUESTION_TOKEN.has(options2.optionalType);
210278
- const propertyNodes = node.properties.map((prop) => {
210279
- var _a;
210280
- const baseType = (_a = print(prop.schema)) != null ? _a : keywordTypeNodes.unknown;
210281
- const type = buildPropertyType(prop.schema, baseType, options2.optionalType);
210282
- return appendJSDocToNode({
210283
- node: createPropertySignature({
210284
- questionToken: prop.schema.optional || prop.schema.nullish ? addsQuestionToken : false,
210285
- name: prop.name,
210286
- type,
210287
- readOnly: prop.schema.readOnly
210288
- }),
210289
- comments: buildPropertyJSDocComments(prop.schema)
210290
- });
210291
- });
210292
- const allElements = [...propertyNodes, ...buildIndexSignatures(node, propertyNodes.length, print)];
210293
- if (!allElements.length) return keywordTypeNodes.object;
210294
- return createTypeLiteralNode(allElements);
210295
- }
210296
- },
210297
- print(node) {
210298
- let type = this.print(node);
210299
- if (!type) return;
210300
- if (node.nullable) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] });
210301
- if ((node.nullish || node.optional) && addsUndefined) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
210302
- const { typeName, syntaxType = "type", description, keysToOmit } = this.options;
210303
- if (!typeName) return type;
210304
- const useTypeGeneration = syntaxType === "type" || type.kind === syntaxKind.union || !!(keysToOmit == null ? void 0 : keysToOmit.length);
210305
- return createTypeDeclaration({
210306
- name: typeName,
210307
- isExportable: true,
210308
- type: (keysToOmit == null ? void 0 : keysToOmit.length) ? createOmitDeclaration({
210309
- keys: keysToOmit,
210310
- type,
210311
- nonNullable: true
210312
- }) : type,
210313
- syntax: useTypeGeneration ? "type" : "interface",
210314
- comments: [
210315
- (node == null ? void 0 : node.title) ? jsStringEscape$1(node.title) : void 0,
210316
- description ? `@description ${jsStringEscape$1(description)}` : void 0,
210317
- (node == null ? void 0 : node.deprecated) ? "@deprecated" : void 0,
210318
- node && "min" in node && node.min !== void 0 ? `@minLength ${node.min}` : void 0,
210319
- node && "max" in node && node.max !== void 0 ? `@maxLength ${node.max}` : void 0,
210320
- node && "pattern" in node && node.pattern ? `@pattern ${node.pattern}` : void 0,
210321
- (node == null ? void 0 : node.default) ? `@default ${node.default}` : void 0,
210322
- (node == null ? void 0 : node.example) ? `@example ${node.example}` : void 0
210323
- ]
210324
- });
210325
- }
210326
- };
210327
- });
210328
- function getEnumNames(node, enumType) {
210329
- const resolved = pascalCase$6(node.name);
210330
- return {
210331
- enumName: enumType === "asPascalConst" ? resolved : camelCase$a(node.name),
210332
- typeName: ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) ? `${resolved}Key` : resolved
210333
- };
210334
- }
210335
- function Enum({ node, enumType, enumKeyCasing }) {
210336
- var _a, _b, _c, _d;
210337
- const { enumName, typeName } = getEnumNames(node, enumType);
210338
- const [nameNode, typeNode] = createEnumDeclaration({
210339
- name: enumName,
210340
- typeName,
210341
- enums: (_d = (_c = (_a = node.namedEnumValues) == null ? void 0 : _a.map((v) => [trimQuotes$1(v.name.toString()), v.value])) != null ? _c : (_b = node.enumValues) == null ? void 0 : _b.filter((v) => v !== null && v !== void 0).map((v) => [trimQuotes$1(v.toString()), v])) != null ? _d : [],
210342
- type: enumType,
210343
- enumKeyCasing
210344
- });
210345
- return /* @__PURE__ */ jsxs(Fragment, { children: [nameNode && /* @__PURE__ */ jsx(File.Source, {
210346
- name: enumName,
210347
- isExportable: true,
210348
- isIndexable: true,
210349
- isTypeOnly: false,
210350
- children: safePrint(nameNode)
210351
- }), /* @__PURE__ */ jsx(File.Source, {
210352
- name: typeName,
210353
- isIndexable: true,
210354
- isExportable: ENUM_TYPES_WITH_RUNTIME_VALUE.has(enumType),
210355
- isTypeOnly: ENUM_TYPES_WITH_TYPE_ONLY.has(enumType),
210356
- children: safePrint(typeNode)
210357
- })] });
210358
- }
210359
- function Type({ name, typedName, node, keysToOmit, optionalType, arrayType, syntaxType, enumType, enumKeyCasing, description }) {
210360
- const resolvedDescription = description || (node == null ? void 0 : node.description);
210361
- const enumSchemaNodes = collect(node, { schema(n) {
210362
- if (n.type === "enum" && n.name) return n;
210363
- } });
210364
- const typeNode = printerTs({
210365
- optionalType,
210366
- arrayType,
210367
- enumType,
210368
- typeName: name,
210369
- syntaxType,
210370
- description: resolvedDescription,
210371
- keysToOmit
210372
- }).print(node);
210373
- if (!typeNode) return;
210374
- const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((node2) => {
210375
- return {
210376
- node: node2,
210377
- ...getEnumNames(node2, enumType)
210378
- };
210379
- });
210380
- const shouldExportEnums = enumType !== "inlineLiteral";
210381
- const shouldExportType = enumType === "inlineLiteral" || enums.every((item) => item.typeName !== name);
210382
- return /* @__PURE__ */ jsxs(Fragment, { children: [shouldExportEnums && enums.map(({ node: node2 }) => /* @__PURE__ */ jsx(Enum, {
210383
- node: node2,
210384
- enumType,
210385
- enumKeyCasing
210386
- })), shouldExportType && /* @__PURE__ */ jsx(File.Source, {
210387
- name: typedName,
210388
- isTypeOnly: true,
210389
- isExportable: true,
210390
- isIndexable: true,
210391
- children: safePrint(typeNode)
210392
- })] });
210393
- }
210394
- const resolverTs = defineResolver(() => {
210395
- return {
210396
- default(name, type) {
210397
- return pascalCase$6(name, { isFile: type === "file" });
210398
- },
210399
- resolveName(name) {
210400
- return this.default(name, "function");
210401
- },
210402
- resolveTypedName(name) {
210403
- return this.default(name, "type");
210404
- },
210405
- resolvePathName(name, type) {
210406
- return this.default(name, type);
210407
- },
210408
- resolveParamName(node, param) {
210409
- return this.resolveName(`${node.operationId} ${this.default(param.in)} ${param.name}`);
210410
- },
210411
- resolveParamTypedName(node, param) {
210412
- return this.resolveTypedName(`${node.operationId} ${this.default(param.in)} ${param.name}`);
210413
- },
210414
- resolveResponseStatusName(node, statusCode) {
210415
- return this.resolveName(`${node.operationId} Status ${statusCode}`);
210416
- },
210417
- resolveResponseStatusTypedName(node, statusCode) {
210418
- return this.resolveTypedName(`${node.operationId} Status ${statusCode}`);
210419
- },
210420
- resolveDataName(node) {
210421
- return this.resolveName(`${node.operationId} Data`);
210422
- },
210423
- resolveDataTypedName(node) {
210424
- return this.resolveTypedName(`${node.operationId} Data`);
210425
- },
210426
- resolveRequestConfigName(node) {
210427
- return this.resolveName(`${node.operationId} RequestConfig`);
210428
- },
210429
- resolveRequestConfigTypedName(node) {
210430
- return this.resolveTypedName(`${node.operationId} RequestConfig`);
210431
- },
210432
- resolveResponsesName(node) {
210433
- return this.resolveName(`${node.operationId} Responses`);
210434
- },
210435
- resolveResponsesTypedName(node) {
210436
- return this.resolveTypedName(`${node.operationId} Responses`);
210437
- },
210438
- resolveResponseName(node) {
210439
- return this.resolveName(`${node.operationId} Response`);
210440
- },
210441
- resolveResponseTypedName(node) {
210442
- return this.resolveTypedName(`${node.operationId} Response`);
210443
- },
210444
- resolveEnumKeyTypedName(node) {
210445
- var _a;
210446
- return `${this.resolveTypedName((_a = node.name) != null ? _a : "")}Key`;
210447
- }
210448
- };
210449
- });
210450
- function buildParamsSchema({ params, operationId, resolveName }) {
209635
+ function buildParamsSchema({ params, node, resolver }) {
210451
209636
  return createSchema({
210452
209637
  type: "object",
210453
209638
  properties: params.map((param) => createProperty({
210454
209639
  name: param.name,
210455
209640
  schema: createSchema({
210456
209641
  type: "ref",
210457
- name: resolveName({
210458
- name: `${operationId} ${pascalCase$6(param.in)} ${param.name}`,
210459
- type: "function"
210460
- }),
209642
+ name: resolver.resolveParamName(node, param),
210461
209643
  optional: !param.required
210462
209644
  })
210463
209645
  }))
210464
209646
  });
210465
209647
  }
210466
- function buildDataSchemaNode({ node, resolveName }) {
209648
+ function buildDataSchemaNode({ node, resolver }) {
209649
+ var _a;
210467
209650
  const pathParams = node.parameters.filter((p) => p.in === "path");
210468
209651
  const queryParams = node.parameters.filter((p) => p.in === "query");
210469
209652
  const headerParams = node.parameters.filter((p) => p.in === "header");
@@ -210473,12 +209656,9 @@ function buildDataSchemaNode({ node, resolveName }) {
210473
209656
  properties: [
210474
209657
  createProperty({
210475
209658
  name: "data",
210476
- schema: node.requestBody ? createSchema({
209659
+ schema: ((_a = node.requestBody) == null ? void 0 : _a.schema) ? createSchema({
210477
209660
  type: "ref",
210478
- name: resolveName({
210479
- name: `${node.operationId} Data`,
210480
- type: "function"
210481
- }),
209661
+ name: resolver.resolveDataTypedName(node),
210482
209662
  optional: true
210483
209663
  }) : createSchema({
210484
209664
  type: "never",
@@ -210489,8 +209669,8 @@ function buildDataSchemaNode({ node, resolveName }) {
210489
209669
  name: "pathParams",
210490
209670
  schema: pathParams.length > 0 ? buildParamsSchema({
210491
209671
  params: pathParams,
210492
- operationId: node.operationId,
210493
- resolveName
209672
+ node,
209673
+ resolver
210494
209674
  }) : createSchema({
210495
209675
  type: "never",
210496
209676
  optional: true
@@ -210501,8 +209681,8 @@ function buildDataSchemaNode({ node, resolveName }) {
210501
209681
  schema: queryParams.length > 0 ? createSchema({
210502
209682
  ...buildParamsSchema({
210503
209683
  params: queryParams,
210504
- operationId: node.operationId,
210505
- resolveName
209684
+ node,
209685
+ resolver
210506
209686
  }),
210507
209687
  optional: true
210508
209688
  }) : createSchema({
@@ -210515,8 +209695,8 @@ function buildDataSchemaNode({ node, resolveName }) {
210515
209695
  schema: headerParams.length > 0 ? createSchema({
210516
209696
  ...buildParamsSchema({
210517
209697
  params: headerParams,
210518
- operationId: node.operationId,
210519
- resolveName
209698
+ node,
209699
+ resolver
210520
209700
  }),
210521
209701
  optional: true
210522
209702
  }) : createSchema({
@@ -210534,7 +209714,7 @@ function buildDataSchemaNode({ node, resolveName }) {
210534
209714
  ]
210535
209715
  });
210536
209716
  }
210537
- function buildResponsesSchemaNode({ node, resolveName }) {
209717
+ function buildResponsesSchemaNode({ node, resolver }) {
210538
209718
  if (node.responses.length === 0) return null;
210539
209719
  return createSchema({
210540
209720
  type: "object",
@@ -210542,48 +209722,174 @@ function buildResponsesSchemaNode({ node, resolveName }) {
210542
209722
  name: String(res.statusCode),
210543
209723
  schema: createSchema({
210544
209724
  type: "ref",
210545
- name: resolveName({
210546
- name: `${node.operationId} Status ${res.statusCode}`,
210547
- type: "function"
210548
- })
209725
+ name: resolver.resolveResponseStatusTypedName(node, res.statusCode)
210549
209726
  })
210550
209727
  }))
210551
209728
  });
210552
209729
  }
210553
- function buildResponseUnionSchemaNode({ node, resolveName }) {
209730
+ function buildResponseUnionSchemaNode({ node, resolver }) {
210554
209731
  const responsesWithSchema = node.responses.filter((res) => res.schema);
210555
209732
  if (responsesWithSchema.length === 0) return null;
210556
209733
  return createSchema({
210557
209734
  type: "union",
210558
209735
  members: responsesWithSchema.map((res) => createSchema({
210559
209736
  type: "ref",
210560
- name: resolveName({
210561
- name: `${node.operationId} Status ${res.statusCode}`,
210562
- type: "function"
210563
- })
209737
+ name: resolver.resolveResponseStatusTypedName(node, res.statusCode)
209738
+ }))
209739
+ });
209740
+ }
209741
+ function buildGroupedParamsSchema({ params, parentName }) {
209742
+ return createSchema({
209743
+ type: "object",
209744
+ properties: params.map((param) => {
209745
+ let schema = {
209746
+ ...param.schema,
209747
+ optional: !param.required
209748
+ };
209749
+ if (narrowSchema(schema, "enum") && !schema.name && parentName) schema = {
209750
+ ...schema,
209751
+ name: pascalCase$6([
209752
+ parentName,
209753
+ param.name,
209754
+ "enum"
209755
+ ].join(" "))
209756
+ };
209757
+ return createProperty({
209758
+ name: param.name,
209759
+ schema
209760
+ });
209761
+ })
209762
+ });
209763
+ }
209764
+ function buildLegacyResponsesSchemaNode({ node, resolver }) {
209765
+ var _a;
209766
+ const isGet = node.method.toLowerCase() === "get";
209767
+ const successResponses = node.responses.filter((res) => {
209768
+ const code = Number(res.statusCode);
209769
+ return !Number.isNaN(code) && code >= 200 && code < 300;
209770
+ });
209771
+ const errorResponses = node.responses.filter((res) => res.statusCode === "default" || Number(res.statusCode) >= 400);
209772
+ const responseSchema = successResponses.length > 0 ? successResponses.length === 1 ? createSchema({
209773
+ type: "ref",
209774
+ name: resolver.resolveResponseStatusTypedName(node, successResponses[0].statusCode)
209775
+ }) : createSchema({
209776
+ type: "union",
209777
+ members: successResponses.map((res) => createSchema({
209778
+ type: "ref",
209779
+ name: resolver.resolveResponseStatusTypedName(node, res.statusCode)
209780
+ }))
209781
+ }) : createSchema({ type: "any" });
209782
+ const errorsSchema = errorResponses.length > 0 ? errorResponses.length === 1 ? createSchema({
209783
+ type: "ref",
209784
+ name: resolver.resolveResponseStatusTypedName(node, errorResponses[0].statusCode)
209785
+ }) : createSchema({
209786
+ type: "union",
209787
+ members: errorResponses.map((res) => createSchema({
209788
+ type: "ref",
209789
+ name: resolver.resolveResponseStatusTypedName(node, res.statusCode)
210564
209790
  }))
209791
+ }) : createSchema({ type: "any" });
209792
+ const properties = [createProperty({
209793
+ name: "Response",
209794
+ schema: responseSchema
209795
+ })];
209796
+ if (!isGet && ((_a = node.requestBody) == null ? void 0 : _a.schema)) properties.push(createProperty({
209797
+ name: "Request",
209798
+ schema: createSchema({
209799
+ type: "ref",
209800
+ name: resolver.resolveDataTypedName(node)
209801
+ })
209802
+ }));
209803
+ else if (isGet && node.parameters.some((p) => p.in === "query")) properties.push(createProperty({
209804
+ name: "QueryParams",
209805
+ schema: createSchema({
209806
+ type: "ref",
209807
+ name: resolver.resolveQueryParamsTypedName(node)
209808
+ })
209809
+ }));
209810
+ if (node.parameters.some((p) => p.in === "path") && resolver.resolvePathParamsTypedName) properties.push(createProperty({
209811
+ name: "PathParams",
209812
+ schema: createSchema({
209813
+ type: "ref",
209814
+ name: resolver.resolvePathParamsTypedName(node)
209815
+ })
209816
+ }));
209817
+ if (node.parameters.some((p) => p.in === "header") && resolver.resolveHeaderParamsTypedName) properties.push(createProperty({
209818
+ name: "HeaderParams",
209819
+ schema: createSchema({
209820
+ type: "ref",
209821
+ name: resolver.resolveHeaderParamsTypedName(node)
209822
+ })
209823
+ }));
209824
+ properties.push(createProperty({
209825
+ name: "Errors",
209826
+ schema: errorsSchema
209827
+ }));
209828
+ return createSchema({
209829
+ type: "object",
209830
+ properties
209831
+ });
209832
+ }
209833
+ function buildLegacyResponseUnionSchemaNode({ node, resolver }) {
209834
+ const successResponses = node.responses.filter((res) => {
209835
+ const code = Number(res.statusCode);
209836
+ return !Number.isNaN(code) && code >= 200 && code < 300;
209837
+ });
209838
+ if (successResponses.length === 0) return createSchema({ type: "any" });
209839
+ if (successResponses.length === 1) return createSchema({
209840
+ type: "ref",
209841
+ name: resolver.resolveResponseStatusTypedName(node, successResponses[0].statusCode)
209842
+ });
209843
+ return createSchema({
209844
+ type: "union",
209845
+ members: successResponses.map((res) => createSchema({
209846
+ type: "ref",
209847
+ name: resolver.resolveResponseStatusTypedName(node, res.statusCode)
209848
+ }))
209849
+ });
209850
+ }
209851
+ function nameUnnamedEnums(node, parentName) {
209852
+ return transform(node, {
209853
+ schema(n) {
209854
+ if (n.type === "enum" && !n.name) return {
209855
+ ...n,
209856
+ name: pascalCase$6([parentName, "enum"].join(" "))
209857
+ };
209858
+ },
209859
+ property(p) {
209860
+ const enumNode = narrowSchema(p.schema, "enum");
209861
+ if (enumNode && !enumNode.name) return {
209862
+ ...p,
209863
+ schema: {
209864
+ ...enumNode,
209865
+ name: pascalCase$6([
209866
+ parentName,
209867
+ p.name,
209868
+ "enum"
209869
+ ].join(" "))
209870
+ }
209871
+ };
209872
+ }
210565
209873
  });
210566
209874
  }
210567
209875
  const typeGenerator = defineGenerator({
210568
209876
  name: "typescript",
210569
209877
  type: "react",
210570
209878
  Operation({ node, adapter, options }) {
210571
- const { enumType, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing, group } = options;
210572
- const { mode, getFile, resolveName, resolveBanner, resolveFooter } = useKubb();
209879
+ var _a, _b;
209880
+ const { enumType, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing, group, resolver, legacy } = options;
209881
+ const { mode, getFile, resolveBanner, resolveFooter } = useKubb();
210573
209882
  const file = getFile({
210574
209883
  name: node.operationId,
210575
209884
  extname: ".ts",
210576
209885
  mode,
210577
- options: { group: group ? group.type === "tag" ? { tag: node.tags[0] } : { path: node.path } : void 0 }
209886
+ options: { group: group ? group.type === "tag" ? { tag: (_a = node.tags[0]) != null ? _a : "default" } : { path: node.path } : void 0 }
210578
209887
  });
210579
209888
  const params = applyParamsCasing$1(node.parameters, paramsCasing);
210580
- function renderSchemaType({ node: schemaNode, name, typedName, description }) {
209889
+ function renderSchemaType({ node: schemaNode, name, typedName, description, keysToOmit }) {
210581
209890
  if (!schemaNode) return null;
210582
209891
  const imports = adapter.getImports(schemaNode, (schemaName) => ({
210583
- name: resolveName({
210584
- name: schemaName,
210585
- type: "type"
210586
- }),
209892
+ name: resolver.default(schemaName, "type"),
210587
209893
  path: getFile({
210588
209894
  name: schemaName,
210589
209895
  extname: ".ts",
@@ -210608,52 +209914,126 @@ const typeGenerator = defineGenerator({
210608
209914
  enumKeyCasing,
210609
209915
  optionalType,
210610
209916
  arrayType,
210611
- syntaxType
209917
+ syntaxType,
209918
+ resolver,
209919
+ keysToOmit
210612
209920
  })] });
210613
209921
  }
210614
- const paramTypes = params.map((param) => renderSchemaType({
210615
- node: param.schema,
210616
- name: resolverTs.resolveParamName(node, param),
210617
- typedName: resolverTs.resolveParamTypedName(node, param)
210618
- }));
210619
- const responseTypes = node.responses.map((res) => renderSchemaType({
209922
+ const responseTypes = legacy ? node.responses.map((res) => {
209923
+ const responseName = resolver.resolveResponseStatusName(node, res.statusCode);
209924
+ return renderSchemaType({
209925
+ node: res.schema ? nameUnnamedEnums(res.schema, responseName) : res.schema,
209926
+ name: responseName,
209927
+ typedName: resolver.resolveResponseStatusTypedName(node, res.statusCode),
209928
+ description: res.description,
209929
+ keysToOmit: res.keysToOmit
209930
+ });
209931
+ }) : node.responses.map((res) => renderSchemaType({
210620
209932
  node: res.schema,
210621
- name: resolverTs.resolveResponseStatusName(node, res.statusCode),
210622
- typedName: resolverTs.resolveResponseStatusTypedName(node, res.statusCode),
210623
- description: res.description
209933
+ name: resolver.resolveResponseStatusName(node, res.statusCode),
209934
+ typedName: resolver.resolveResponseStatusTypedName(node, res.statusCode),
209935
+ description: res.description,
209936
+ keysToOmit: res.keysToOmit
210624
209937
  }));
210625
- const requestType = node.requestBody ? renderSchemaType({
210626
- node: node.requestBody,
210627
- name: resolverTs.resolveDataName(node),
210628
- typedName: resolverTs.resolveDataTypedName(node),
210629
- description: node.requestBody.description
209938
+ const requestType = ((_b = node.requestBody) == null ? void 0 : _b.schema) ? renderSchemaType({
209939
+ node: legacy ? nameUnnamedEnums(node.requestBody.schema, resolver.resolveDataName(node)) : node.requestBody.schema,
209940
+ name: resolver.resolveDataName(node),
209941
+ typedName: resolver.resolveDataTypedName(node),
209942
+ description: node.requestBody.schema.description,
209943
+ keysToOmit: node.requestBody.keysToOmit
210630
209944
  }) : null;
209945
+ if (legacy) {
209946
+ const pathParams = params.filter((p) => p.in === "path");
209947
+ const queryParams = params.filter((p) => p.in === "query");
209948
+ const headerParams = params.filter((p) => p.in === "header");
209949
+ const legacyParamTypes = [
209950
+ pathParams.length > 0 ? renderSchemaType({
209951
+ node: buildGroupedParamsSchema({
209952
+ params: pathParams,
209953
+ parentName: resolver.resolvePathParamsName(node)
209954
+ }),
209955
+ name: resolver.resolvePathParamsName(node),
209956
+ typedName: resolver.resolvePathParamsTypedName(node)
209957
+ }) : null,
209958
+ queryParams.length > 0 ? renderSchemaType({
209959
+ node: buildGroupedParamsSchema({
209960
+ params: queryParams,
209961
+ parentName: resolver.resolveQueryParamsName(node)
209962
+ }),
209963
+ name: resolver.resolveQueryParamsName(node),
209964
+ typedName: resolver.resolveQueryParamsTypedName(node)
209965
+ }) : null,
209966
+ headerParams.length > 0 ? renderSchemaType({
209967
+ node: buildGroupedParamsSchema({
209968
+ params: headerParams,
209969
+ parentName: resolver.resolveHeaderParamsName(node)
209970
+ }),
209971
+ name: resolver.resolveHeaderParamsName(node),
209972
+ typedName: resolver.resolveHeaderParamsTypedName(node)
209973
+ }) : null
209974
+ ];
209975
+ const legacyResponsesType = renderSchemaType({
209976
+ node: buildLegacyResponsesSchemaNode({
209977
+ node,
209978
+ resolver
209979
+ }),
209980
+ name: resolver.resolveResponsesName(node),
209981
+ typedName: resolver.resolveResponsesTypedName(node)
209982
+ });
209983
+ const legacyResponseType = renderSchemaType({
209984
+ node: buildLegacyResponseUnionSchemaNode({
209985
+ node,
209986
+ resolver
209987
+ }),
209988
+ name: resolver.resolveResponseName(node),
209989
+ typedName: resolver.resolveResponseTypedName(node)
209990
+ });
209991
+ return /* @__PURE__ */ jsxs(File, {
209992
+ baseName: file.baseName,
209993
+ path: file.path,
209994
+ meta: file.meta,
209995
+ banner: resolveBanner(),
209996
+ footer: resolveFooter(),
209997
+ children: [
209998
+ legacyParamTypes,
209999
+ responseTypes,
210000
+ requestType,
210001
+ legacyResponsesType,
210002
+ legacyResponseType
210003
+ ]
210004
+ });
210005
+ }
210006
+ const paramTypes = params.map((param) => renderSchemaType({
210007
+ node: param.schema,
210008
+ name: resolver.resolveParamName(node, param),
210009
+ typedName: resolver.resolveParamTypedName(node, param)
210010
+ }));
210631
210011
  const dataType = renderSchemaType({
210632
210012
  node: buildDataSchemaNode({
210633
210013
  node: {
210634
210014
  ...node,
210635
210015
  parameters: params
210636
210016
  },
210637
- resolveName
210017
+ resolver
210638
210018
  }),
210639
- name: resolverTs.resolveRequestConfigName(node),
210640
- typedName: resolverTs.resolveRequestConfigTypedName(node)
210019
+ name: resolver.resolveRequestConfigName(node),
210020
+ typedName: resolver.resolveRequestConfigTypedName(node)
210641
210021
  });
210642
210022
  const responsesType = renderSchemaType({
210643
210023
  node: buildResponsesSchemaNode({
210644
210024
  node,
210645
- resolveName
210025
+ resolver
210646
210026
  }),
210647
- name: resolverTs.resolveResponsesName(node),
210648
- typedName: resolverTs.resolveResponsesTypedName(node)
210027
+ name: resolver.resolveResponsesName(node),
210028
+ typedName: resolver.resolveResponsesTypedName(node)
210649
210029
  });
210650
210030
  const responseType = renderSchemaType({
210651
210031
  node: buildResponseUnionSchemaNode({
210652
210032
  node,
210653
- resolveName
210033
+ resolver
210654
210034
  }),
210655
- name: resolverTs.resolveResponseName(node),
210656
- typedName: resolverTs.resolveResponseTypedName(node),
210035
+ name: resolver.resolveResponseName(node),
210036
+ typedName: resolver.resolveResponseTypedName(node),
210657
210037
  description: "Union of all possible responses"
210658
210038
  });
210659
210039
  return /* @__PURE__ */ jsxs(File, {
@@ -210673,14 +210053,11 @@ const typeGenerator = defineGenerator({
210673
210053
  });
210674
210054
  },
210675
210055
  Schema({ node, adapter, options }) {
210676
- const { enumType, enumKeyCasing, syntaxType, optionalType, arrayType } = options;
210677
- const { mode, resolveName, getFile, resolveBanner, resolveFooter } = useKubb();
210056
+ const { enumType, enumKeyCasing, syntaxType, optionalType, arrayType, resolver } = options;
210057
+ const { mode, getFile, resolveBanner, resolveFooter } = useKubb();
210678
210058
  if (!node.name) return;
210679
210059
  const imports = adapter.getImports(node, (schemaName) => ({
210680
- name: resolveName({
210681
- name: schemaName,
210682
- type: "type"
210683
- }),
210060
+ name: resolver.default(schemaName, "type"),
210684
210061
  path: getFile({
210685
210062
  name: schemaName,
210686
210063
  extname: ".ts",
@@ -210688,9 +210065,9 @@ const typeGenerator = defineGenerator({
210688
210065
  }).path
210689
210066
  }));
210690
210067
  const isEnumSchema = node.type === "enum";
210691
- const typedName = ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && isEnumSchema ? resolverTs.resolveEnumKeyTypedName(node) : resolverTs.resolveTypedName(node.name);
210068
+ const typedName = ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && isEnumSchema ? resolver.resolveEnumKeyTypedName(node) : resolver.resolveTypedName(node.name);
210692
210069
  const type = {
210693
- name: resolverTs.resolveName(node.name),
210070
+ name: resolver.resolveName(node.name),
210694
210071
  typedName,
210695
210072
  file: getFile({
210696
210073
  name: node.name,
@@ -210721,38 +210098,176 @@ const typeGenerator = defineGenerator({
210721
210098
  enumKeyCasing,
210722
210099
  optionalType,
210723
210100
  arrayType,
210724
- syntaxType
210101
+ syntaxType,
210102
+ resolver
210725
210103
  })]
210726
210104
  });
210727
210105
  }
210728
210106
  });
210107
+
210108
+ function resolveName(name, type) {
210109
+ return pascalCase$6(name, { isFile: type === "file" });
210110
+ }
210111
+ const resolverTs = defineResolver(() => {
210112
+ return {
210113
+ default(name, type) {
210114
+ return resolveName(name, type);
210115
+ },
210116
+ resolveName(name) {
210117
+ return this.default(name, "function");
210118
+ },
210119
+ resolveTypedName(name) {
210120
+ return this.default(name, "type");
210121
+ },
210122
+ resolvePathName(name, type) {
210123
+ return this.default(name, type);
210124
+ },
210125
+ resolveParamName(node, param) {
210126
+ return this.resolveName(`${node.operationId} ${this.default(param.in)} ${param.name}`);
210127
+ },
210128
+ resolveParamTypedName(node, param) {
210129
+ return this.resolveTypedName(`${node.operationId} ${this.default(param.in)} ${param.name}`);
210130
+ },
210131
+ resolveResponseStatusName(node, statusCode) {
210132
+ return this.resolveName(`${node.operationId} Status ${statusCode}`);
210133
+ },
210134
+ resolveResponseStatusTypedName(node, statusCode) {
210135
+ return this.resolveTypedName(`${node.operationId} Status ${statusCode}`);
210136
+ },
210137
+ resolveDataName(node) {
210138
+ return this.resolveName(`${node.operationId} Data`);
210139
+ },
210140
+ resolveDataTypedName(node) {
210141
+ return this.resolveTypedName(`${node.operationId} Data`);
210142
+ },
210143
+ resolveRequestConfigName(node) {
210144
+ return this.resolveName(`${node.operationId} RequestConfig`);
210145
+ },
210146
+ resolveRequestConfigTypedName(node) {
210147
+ return this.resolveTypedName(`${node.operationId} RequestConfig`);
210148
+ },
210149
+ resolveResponsesName(node) {
210150
+ return this.resolveName(`${node.operationId} Responses`);
210151
+ },
210152
+ resolveResponsesTypedName(node) {
210153
+ return this.resolveTypedName(`${node.operationId} Responses`);
210154
+ },
210155
+ resolveResponseName(node) {
210156
+ return this.resolveName(`${node.operationId} Response`);
210157
+ },
210158
+ resolveResponseTypedName(node) {
210159
+ return this.resolveTypedName(`${node.operationId} Response`);
210160
+ },
210161
+ resolveEnumKeyTypedName(node) {
210162
+ var _a;
210163
+ return `${this.resolveTypedName((_a = node.name) != null ? _a : "")}Key`;
210164
+ },
210165
+ resolvePathParamsName(_node) {
210166
+ throw new Error("resolvePathParamsName is only available in legacy mode (legacy: true). Use resolveParamName per individual parameter instead.");
210167
+ },
210168
+ resolvePathParamsTypedName(_node) {
210169
+ throw new Error("resolvePathParamsTypedName is only available in legacy mode (legacy: true). Use resolveParamTypedName per individual parameter instead.");
210170
+ },
210171
+ resolveQueryParamsName(_node) {
210172
+ throw new Error("resolveQueryParamsName is only available in legacy mode (legacy: true). Use resolveParamName per individual parameter instead.");
210173
+ },
210174
+ resolveQueryParamsTypedName(_node) {
210175
+ throw new Error("resolveQueryParamsTypedName is only available in legacy mode (legacy: true). Use resolveParamTypedName per individual parameter instead.");
210176
+ },
210177
+ resolveHeaderParamsName(_node) {
210178
+ throw new Error("resolveHeaderParamsName is only available in legacy mode (legacy: true). Use resolveParamName per individual parameter instead.");
210179
+ },
210180
+ resolveHeaderParamsTypedName(_node) {
210181
+ throw new Error("resolveHeaderParamsTypedName is only available in legacy mode (legacy: true). Use resolveParamTypedName per individual parameter instead.");
210182
+ }
210183
+ };
210184
+ });
210185
+ const resolverTsLegacy = defineResolver(() => {
210186
+ return {
210187
+ ...resolverTs,
210188
+ resolveResponseStatusName(node, statusCode) {
210189
+ if (statusCode === "default") return this.resolveName(`${node.operationId} Error`);
210190
+ return this.resolveName(`${node.operationId} ${statusCode}`);
210191
+ },
210192
+ resolveResponseStatusTypedName(node, statusCode) {
210193
+ if (statusCode === "default") return this.resolveTypedName(`${node.operationId} Error`);
210194
+ return this.resolveTypedName(`${node.operationId} ${statusCode}`);
210195
+ },
210196
+ resolveDataName(node) {
210197
+ const suffix = node.method === "GET" ? "QueryRequest" : "MutationRequest";
210198
+ return this.resolveName(`${node.operationId} ${suffix}`);
210199
+ },
210200
+ resolveDataTypedName(node) {
210201
+ const suffix = node.method === "GET" ? "QueryRequest" : "MutationRequest";
210202
+ return this.resolveTypedName(`${node.operationId} ${suffix}`);
210203
+ },
210204
+ resolveResponsesName(node) {
210205
+ const suffix = node.method === "GET" ? "Query" : "Mutation";
210206
+ return this.resolveName(`${node.operationId} ${suffix}`);
210207
+ },
210208
+ resolveResponsesTypedName(node) {
210209
+ const suffix = node.method === "GET" ? "Query" : "Mutation";
210210
+ return this.resolveTypedName(`${node.operationId} ${suffix}`);
210211
+ },
210212
+ resolveResponseName(node) {
210213
+ const suffix = node.method === "GET" ? "QueryResponse" : "MutationResponse";
210214
+ return this.resolveName(`${node.operationId} ${suffix}`);
210215
+ },
210216
+ resolveResponseTypedName(node) {
210217
+ const suffix = node.method === "GET" ? "QueryResponse" : "MutationResponse";
210218
+ return this.resolveTypedName(`${node.operationId} ${suffix}`);
210219
+ },
210220
+ resolvePathParamsName(node) {
210221
+ return this.resolveName(`${node.operationId} PathParams`);
210222
+ },
210223
+ resolvePathParamsTypedName(node) {
210224
+ return this.resolveTypedName(`${node.operationId} PathParams`);
210225
+ },
210226
+ resolveQueryParamsName(node) {
210227
+ return this.resolveName(`${node.operationId} QueryParams`);
210228
+ },
210229
+ resolveQueryParamsTypedName(node) {
210230
+ return this.resolveTypedName(`${node.operationId} QueryParams`);
210231
+ },
210232
+ resolveHeaderParamsName(node) {
210233
+ return this.resolveName(`${node.operationId} HeaderParams`);
210234
+ },
210235
+ resolveHeaderParamsTypedName(node) {
210236
+ return this.resolveTypedName(`${node.operationId} HeaderParams`);
210237
+ }
210238
+ };
210239
+ });
210729
210240
  const pluginTsName = "plugin-ts";
210730
210241
  const pluginTs = createPlugin((options) => {
210731
210242
  const { output = {
210732
210243
  path: "types",
210733
210244
  barrelType: "named"
210734
- }, group, exclude = [], include, override = [], enumType = "asConst", enumKeyCasing = "none", enumSuffix = "enum", dateType = "string", integerType = "number", unknownType = "any", optionalType = "questionToken", arrayType = "array", emptySchemaType = unknownType, syntaxType = "type", transformers = {}, paramsCasing, generators = [typeGenerator$1, typeGenerator].filter(Boolean), contentType, UNSTABLE_NAMING } = options;
210245
+ }, group, exclude = [], include, override = [], enumType = "asConst", enumKeyCasing = "none", optionalType = "questionToken", arrayType = "array", syntaxType = "type", transformers = {}, paramsCasing, generators = [typeGenerator].filter(Boolean), legacy = false } = options;
210246
+ const baseResolver = legacy ? resolverTsLegacy : resolverTs;
210247
+ const resolver = (transformers == null ? void 0 : transformers.name) ? {
210248
+ ...baseResolver,
210249
+ default(name, type) {
210250
+ const resolved = baseResolver.default(name, type);
210251
+ return transformers.name(resolved, type) || resolved;
210252
+ }
210253
+ } : baseResolver;
210254
+ let resolveNameWarning = false;
210735
210255
  return {
210736
210256
  name: pluginTsName,
210737
210257
  options: {
210738
210258
  output,
210739
210259
  transformers,
210740
- dateType,
210741
- integerType,
210742
210260
  optionalType,
210743
210261
  arrayType,
210744
210262
  enumType,
210745
210263
  enumKeyCasing,
210746
- enumSuffix,
210747
- unknownType,
210748
- emptySchemaType,
210749
210264
  syntaxType,
210750
210265
  group,
210751
210266
  override,
210752
210267
  paramsCasing,
210753
- usedEnumNames: {}
210268
+ legacy,
210269
+ resolver
210754
210270
  },
210755
- pre: [pluginOasName],
210756
210271
  resolvePath(baseName, pathMode, options2) {
210757
210272
  var _a, _b;
210758
210273
  const root = path$2.resolve(this.config.root, this.config.output.path);
@@ -210768,107 +210283,71 @@ const pluginTs = createPlugin((options) => {
210768
210283
  return path$2.resolve(root, output.path, baseName);
210769
210284
  },
210770
210285
  resolveName(name, type) {
210771
- var _a;
210772
- const resolvedName = resolverTs.default(name, type);
210773
- if (type) return ((_a = transformers == null ? void 0 : transformers.name) == null ? void 0 : _a.call(transformers, resolvedName, type)) || resolvedName;
210774
- return resolvedName;
210286
+ if (!resolveNameWarning) {
210287
+ this.driver.events.emit("warn", "Do not use resolveName for pluginTs, use resolverTs instead");
210288
+ resolveNameWarning = true;
210289
+ }
210290
+ return resolver.default(name, type);
210775
210291
  },
210776
210292
  async install() {
210777
- var _a, _b;
210293
+ var _a;
210778
210294
  const { config, fabric, plugin, adapter, rootNode, driver, openInStudio } = this;
210779
210295
  const root = path$2.resolve(config.root, config.output.path);
210780
210296
  const mode = getMode(path$2.resolve(root, output.path));
210781
- if (adapter) {
210782
- await openInStudio({ ast: true });
210783
- await walk(rootNode, {
210784
- async schema(schemaNode) {
210785
- const writeTasks = generators.map(async (generator) => {
210786
- if (generator.type === "react" && generator.version === "2") {
210787
- const options2 = resolverTs.resolveOptions(schemaNode, {
210788
- options: plugin.options,
210789
- exclude,
210790
- include,
210791
- override
210792
- });
210793
- if (options2 === null) return;
210794
- await renderSchema$1(schemaNode, {
210795
- options: options2,
210796
- adapter,
210797
- config,
210798
- fabric,
210799
- Component: generator.Schema,
210800
- plugin,
210801
- driver,
210802
- mode
210803
- });
210804
- }
210805
- });
210806
- await Promise.all(writeTasks);
210807
- },
210808
- async operation(operationNode) {
210809
- const writeTasks = generators.map(async (generator) => {
210810
- if (generator.type === "react" && generator.version === "2") {
210811
- const options2 = resolverTs.resolveOptions(operationNode, {
210812
- options: plugin.options,
210813
- exclude,
210814
- include,
210815
- override
210816
- });
210817
- if (options2 === null) return;
210818
- await renderOperation$1(operationNode, {
210819
- options: options2,
210820
- adapter,
210821
- config,
210822
- fabric,
210823
- Component: generator.Operation,
210824
- plugin,
210825
- driver,
210826
- mode
210827
- });
210828
- }
210829
- });
210830
- await Promise.all(writeTasks);
210831
- }
210832
- }, { depth: "shallow" });
210833
- const barrelFiles2 = await getBarrelFiles(this.fabric.files, {
210834
- type: (_a = output.barrelType) != null ? _a : "named",
210835
- root,
210836
- output,
210837
- meta: { pluginName: this.plugin.name }
210838
- });
210839
- await this.upsertFile(...barrelFiles2);
210840
- return;
210841
- }
210842
- const oas = await this.getOas();
210843
- const schemaFiles = await new SchemaGenerator(this.plugin.options, {
210844
- fabric: this.fabric,
210845
- oas,
210846
- driver: this.driver,
210847
- events: this.events,
210848
- plugin: this.plugin,
210849
- contentType,
210850
- include: void 0,
210851
- override,
210852
- mode,
210853
- output: output.path
210854
- }).build(...generators);
210855
- await this.upsertFile(...schemaFiles);
210856
- const operationFiles = await new OperationGenerator(this.plugin.options, {
210857
- fabric: this.fabric,
210858
- oas,
210859
- driver: this.driver,
210860
- events: this.events,
210861
- plugin: this.plugin,
210862
- contentType,
210863
- exclude,
210864
- include,
210865
- override,
210866
- mode,
210867
- UNSTABLE_NAMING
210868
- }).build(...generators);
210869
- await this.upsertFile(...operationFiles);
210297
+ if (!adapter) throw new Error("Plugin cannot work without adapter being set");
210298
+ await openInStudio({ ast: true });
210299
+ await walk(rootNode, {
210300
+ async schema(schemaNode) {
210301
+ const writeTasks = generators.map(async (generator) => {
210302
+ if (generator.type === "react" && generator.version === "2") {
210303
+ const options2 = resolver.resolveOptions(schemaNode, {
210304
+ options: plugin.options,
210305
+ exclude,
210306
+ include,
210307
+ override
210308
+ });
210309
+ if (options2 === null) return;
210310
+ await renderSchema$1(schemaNode, {
210311
+ options: options2,
210312
+ adapter,
210313
+ config,
210314
+ fabric,
210315
+ Component: generator.Schema,
210316
+ plugin,
210317
+ driver,
210318
+ mode
210319
+ });
210320
+ }
210321
+ });
210322
+ await Promise.all(writeTasks);
210323
+ },
210324
+ async operation(operationNode) {
210325
+ const writeTasks = generators.map(async (generator) => {
210326
+ if (generator.type === "react" && generator.version === "2") {
210327
+ const options2 = resolver.resolveOptions(operationNode, {
210328
+ options: plugin.options,
210329
+ exclude,
210330
+ include,
210331
+ override
210332
+ });
210333
+ if (options2 === null) return;
210334
+ await renderOperation$1(operationNode, {
210335
+ options: options2,
210336
+ adapter,
210337
+ config,
210338
+ fabric,
210339
+ Component: generator.Operation,
210340
+ plugin,
210341
+ driver,
210342
+ mode
210343
+ });
210344
+ }
210345
+ });
210346
+ await Promise.all(writeTasks);
210347
+ }
210348
+ }, { depth: "shallow" });
210870
210349
  const barrelFiles = await getBarrelFiles(this.fabric.files, {
210871
- type: (_b = output.barrelType) != null ? _b : "named",
210350
+ type: (_a = output.barrelType) != null ? _a : "named",
210872
210351
  root,
210873
210352
  output,
210874
210353
  meta: { pluginName: this.plugin.name }
@@ -210878,6 +210357,172 @@ const pluginTs = createPlugin((options) => {
210878
210357
  };
210879
210358
  });
210880
210359
 
210360
+ function useOas() {
210361
+ const { meta } = useFabric();
210362
+ return meta.oas;
210363
+ }
210364
+ function useOperationManager(generator) {
210365
+ const plugin = usePlugin();
210366
+ const driver = usePluginDriver();
210367
+ const defaultPluginName = plugin.name;
210368
+ const getName = (operation, { prefix = "", suffix = "", pluginName = defaultPluginName, type }) => {
210369
+ return driver.resolveName({
210370
+ name: `${prefix} ${operation.getOperationId()} ${suffix}`,
210371
+ pluginName,
210372
+ type
210373
+ });
210374
+ };
210375
+ const getGroup = (operation) => {
210376
+ var _a, _b;
210377
+ return {
210378
+ tag: (_b = (_a = operation.getTags().at(0)) == null ? void 0 : _a.name) != null ? _b : "default",
210379
+ path: operation.path
210380
+ };
210381
+ };
210382
+ const getSchemas = (operation, params) => {
210383
+ if (!generator) throw new Error(`useOperationManager: 'generator' parameter is required but was not provided`);
210384
+ return generator.getSchemas(operation, { resolveName: (name) => {
210385
+ var _a;
210386
+ return driver.resolveName({
210387
+ name,
210388
+ pluginName: (_a = params == null ? void 0 : params.pluginName) != null ? _a : defaultPluginName,
210389
+ type: params == null ? void 0 : params.type
210390
+ });
210391
+ } });
210392
+ };
210393
+ const getFile = (operation, { prefix, suffix, pluginName = defaultPluginName, extname = ".ts" } = {}) => {
210394
+ const name = getName(operation, {
210395
+ type: "file",
210396
+ pluginName,
210397
+ prefix,
210398
+ suffix
210399
+ });
210400
+ const group = getGroup(operation);
210401
+ const file = driver.getFile({
210402
+ name,
210403
+ extname,
210404
+ pluginName,
210405
+ options: {
210406
+ type: "file",
210407
+ pluginName,
210408
+ group
210409
+ }
210410
+ });
210411
+ return {
210412
+ ...file,
210413
+ meta: {
210414
+ ...file.meta,
210415
+ name,
210416
+ pluginName,
210417
+ group
210418
+ }
210419
+ };
210420
+ };
210421
+ const groupSchemasByName = (operation, { pluginName = defaultPluginName, type }) => {
210422
+ var _a, _b, _c, _d;
210423
+ if (!generator) throw new Error(`useOperationManager: 'generator' parameter is required but was not provided`);
210424
+ const schemas = getSchemas(operation);
210425
+ const errors = (schemas.errors || []).reduce((prev, acc) => {
210426
+ if (!acc.statusCode) return prev;
210427
+ prev[acc.statusCode] = driver.resolveName({
210428
+ name: acc.name,
210429
+ pluginName,
210430
+ type
210431
+ });
210432
+ return prev;
210433
+ }, {});
210434
+ const responses = (schemas.responses || []).reduce((prev, acc) => {
210435
+ if (!acc.statusCode) return prev;
210436
+ prev[acc.statusCode] = driver.resolveName({
210437
+ name: acc.name,
210438
+ pluginName,
210439
+ type
210440
+ });
210441
+ return prev;
210442
+ }, {});
210443
+ return {
210444
+ request: ((_a = schemas.request) == null ? void 0 : _a.name) ? driver.resolveName({
210445
+ name: schemas.request.name,
210446
+ pluginName,
210447
+ type
210448
+ }) : void 0,
210449
+ parameters: {
210450
+ path: ((_b = schemas.pathParams) == null ? void 0 : _b.name) ? driver.resolveName({
210451
+ name: schemas.pathParams.name,
210452
+ pluginName,
210453
+ type
210454
+ }) : void 0,
210455
+ query: ((_c = schemas.queryParams) == null ? void 0 : _c.name) ? driver.resolveName({
210456
+ name: schemas.queryParams.name,
210457
+ pluginName,
210458
+ type
210459
+ }) : void 0,
210460
+ header: ((_d = schemas.headerParams) == null ? void 0 : _d.name) ? driver.resolveName({
210461
+ name: schemas.headerParams.name,
210462
+ pluginName,
210463
+ type
210464
+ }) : void 0
210465
+ },
210466
+ responses: {
210467
+ ...responses,
210468
+ ["default"]: driver.resolveName({
210469
+ name: schemas.response.name,
210470
+ pluginName,
210471
+ type
210472
+ }),
210473
+ ...errors
210474
+ },
210475
+ errors
210476
+ };
210477
+ };
210478
+ return {
210479
+ getName,
210480
+ getFile,
210481
+ getSchemas,
210482
+ groupSchemasByName,
210483
+ getGroup
210484
+ };
210485
+ }
210486
+ function useSchemaManager() {
210487
+ const plugin = usePlugin();
210488
+ const driver = usePluginDriver();
210489
+ const getName = (name, { pluginName = plugin.name, type }) => {
210490
+ return driver.resolveName({
210491
+ name,
210492
+ pluginName,
210493
+ type
210494
+ });
210495
+ };
210496
+ const getFile = (name, { mode = "split", pluginName = plugin.name, extname = ".ts", group } = {}) => {
210497
+ const resolvedName = mode === "single" ? "" : getName(name, {
210498
+ type: "file",
210499
+ pluginName
210500
+ });
210501
+ const file = driver.getFile({
210502
+ name: resolvedName,
210503
+ extname,
210504
+ pluginName,
210505
+ options: {
210506
+ type: "file",
210507
+ pluginName,
210508
+ group
210509
+ }
210510
+ });
210511
+ return {
210512
+ ...file,
210513
+ meta: {
210514
+ ...file.meta,
210515
+ name: resolvedName,
210516
+ pluginName
210517
+ }
210518
+ };
210519
+ };
210520
+ return {
210521
+ getName,
210522
+ getFile
210523
+ };
210524
+ }
210525
+
210881
210526
  const operationsGenerator$1 = createReactGenerator({
210882
210527
  name: "operations",
210883
210528
  Operations({ operations, generator, plugin }) {
@@ -211162,7 +210807,7 @@ function toCamelOrPascal$9(text, pascal) {
211162
210807
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
211163
210808
  }
211164
210809
  function applyToFileParts$9(text, transformPart) {
211165
- const parts = text.split(".");
210810
+ const parts = text.split(/\.(?=[a-zA-Z])/);
211166
210811
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
211167
210812
  }
211168
210813
  function camelCase$9(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -212129,7 +211774,7 @@ function toCamelOrPascal$8(text, pascal) {
212129
211774
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
212130
211775
  }
212131
211776
  function applyToFileParts$8(text, transformPart) {
212132
- const parts = text.split(".");
211777
+ const parts = text.split(/\.(?=[a-zA-Z])/);
212133
211778
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
212134
211779
  }
212135
211780
  function camelCase$8(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -213038,7 +212683,7 @@ function toCamelOrPascal$7(text, pascal) {
213038
212683
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
213039
212684
  }
213040
212685
  function applyToFileParts$7(text, transformPart) {
213041
- const parts = text.split(".");
212686
+ const parts = text.split(/\.(?=[a-zA-Z])/);
213042
212687
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
213043
212688
  }
213044
212689
  function camelCase$7(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -213146,7 +212791,7 @@ function toCamelOrPascal$6(text, pascal) {
213146
212791
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
213147
212792
  }
213148
212793
  function applyToFileParts$6(text, transformPart) {
213149
- const parts = text.split(".");
212794
+ const parts = text.split(/\.(?=[a-zA-Z])/);
213150
212795
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
213151
212796
  }
213152
212797
  function camelCase$6(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -213664,7 +213309,7 @@ function toCamelOrPascal$5(text, pascal) {
213664
213309
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
213665
213310
  }
213666
213311
  function applyToFileParts$5(text, transformPart) {
213667
- const parts = text.split(".");
213312
+ const parts = text.split(/\.(?=[a-zA-Z])/);
213668
213313
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
213669
213314
  }
213670
213315
  function camelCase$5(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -214128,7 +213773,7 @@ function toCamelOrPascal$4(text, pascal) {
214128
213773
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
214129
213774
  }
214130
213775
  function applyToFileParts$4(text, transformPart) {
214131
- const parts = text.split(".");
213776
+ const parts = text.split(/\.(?=[a-zA-Z])/);
214132
213777
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
214133
213778
  }
214134
213779
  function camelCase$4(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -214281,7 +213926,7 @@ function MutationKey$4({ name, typeSchemas, pathParamsType, paramsCasing, operat
214281
213926
  isExportable: true,
214282
213927
  isIndexable: true,
214283
213928
  isTypeOnly: true,
214284
- children: /* @__PURE__ */ jsx(Type$2, {
213929
+ children: /* @__PURE__ */ jsx(Type$1, {
214285
213930
  name: typeName,
214286
213931
  export: true,
214287
213932
  children: `ReturnType<typeof ${name}>`
@@ -214349,7 +213994,7 @@ function QueryKey$4({ name, typeSchemas, paramsCasing, pathParamsType, operation
214349
213994
  isExportable: true,
214350
213995
  isIndexable: true,
214351
213996
  isTypeOnly: true,
214352
- children: /* @__PURE__ */ jsx(Type$2, {
213997
+ children: /* @__PURE__ */ jsx(Type$1, {
214353
213998
  name: typeName,
214354
213999
  export: true,
214355
214000
  children: `ReturnType<typeof ${name}>`
@@ -215842,7 +215487,7 @@ const hookOptionsGenerator = createReactGenerator({
215842
215487
  isExportable: true,
215843
215488
  isIndexable: true,
215844
215489
  isTypeOnly: true,
215845
- children: /* @__PURE__ */ jsx(Type$2, {
215490
+ children: /* @__PURE__ */ jsx(Type$1, {
215846
215491
  export: true,
215847
215492
  name,
215848
215493
  children: `{ ${Object.keys(hookOptions).map((key) => `${JSON.stringify(key)}: ${hookOptions[key]}`)} }`
@@ -217203,7 +216848,7 @@ function toCamelOrPascal$3(text, pascal) {
217203
216848
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
217204
216849
  }
217205
216850
  function applyToFileParts$3(text, transformPart) {
217206
- const parts = text.split(".");
216851
+ const parts = text.split(/\.(?=[a-zA-Z])/);
217207
216852
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
217208
216853
  }
217209
216854
  function camelCase$3(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -217351,7 +216996,7 @@ function MutationKey$3({ name, typeSchemas, pathParamsType, paramsCasing, operat
217351
216996
  isExportable: true,
217352
216997
  isIndexable: true,
217353
216998
  isTypeOnly: true,
217354
- children: /* @__PURE__ */ jsx(Type$2, {
216999
+ children: /* @__PURE__ */ jsx(Type$1, {
217355
217000
  name: typeName,
217356
217001
  export: true,
217357
217002
  children: `ReturnType<typeof ${name}>`
@@ -217419,7 +217064,7 @@ function QueryKey$3({ name, typeSchemas, paramsCasing, pathParamsType, operation
217419
217064
  isExportable: true,
217420
217065
  isIndexable: true,
217421
217066
  isTypeOnly: true,
217422
- children: /* @__PURE__ */ jsx(Type$2, {
217067
+ children: /* @__PURE__ */ jsx(Type$1, {
217423
217068
  name: typeName,
217424
217069
  export: true,
217425
217070
  children: `ReturnType<typeof ${name}>`
@@ -218353,7 +217998,7 @@ function toCamelOrPascal$2(text, pascal) {
218353
217998
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
218354
217999
  }
218355
218000
  function applyToFileParts$2(text, transformPart) {
218356
- const parts = text.split(".");
218001
+ const parts = text.split(/\.(?=[a-zA-Z])/);
218357
218002
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
218358
218003
  }
218359
218004
  function camelCase$2(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -218501,7 +218146,7 @@ function MutationKey$2({ name, typeSchemas, pathParamsType, paramsCasing, operat
218501
218146
  isExportable: true,
218502
218147
  isIndexable: true,
218503
218148
  isTypeOnly: true,
218504
- children: /* @__PURE__ */ jsx(Type$2, {
218149
+ children: /* @__PURE__ */ jsx(Type$1, {
218505
218150
  name: typeName,
218506
218151
  export: true,
218507
218152
  children: `ReturnType<typeof ${name}>`
@@ -218569,7 +218214,7 @@ function QueryKey$2({ name, typeSchemas, paramsCasing, pathParamsType, operation
218569
218214
  isExportable: true,
218570
218215
  isIndexable: true,
218571
218216
  isTypeOnly: true,
218572
- children: /* @__PURE__ */ jsx(Type$2, {
218217
+ children: /* @__PURE__ */ jsx(Type$1, {
218573
218218
  name: typeName,
218574
218219
  export: true,
218575
218220
  children: `ReturnType<typeof ${name}>`
@@ -219503,7 +219148,7 @@ function toCamelOrPascal$1(text, pascal) {
219503
219148
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
219504
219149
  }
219505
219150
  function applyToFileParts$1(text, transformPart) {
219506
- const parts = text.split(".");
219151
+ const parts = text.split(/\.(?=[a-zA-Z])/);
219507
219152
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
219508
219153
  }
219509
219154
  function camelCase$1(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -219651,7 +219296,7 @@ function MutationKey$1({ name, typeSchemas, pathParamsType, paramsCasing, operat
219651
219296
  isExportable: true,
219652
219297
  isIndexable: true,
219653
219298
  isTypeOnly: true,
219654
- children: /* @__PURE__ */ jsx(Type$2, {
219299
+ children: /* @__PURE__ */ jsx(Type$1, {
219655
219300
  name: typeName,
219656
219301
  export: true,
219657
219302
  children: `ReturnType<typeof ${name}>`
@@ -219719,7 +219364,7 @@ function QueryKey$1({ name, typeSchemas, paramsCasing, pathParamsType, operation
219719
219364
  isExportable: true,
219720
219365
  isIndexable: true,
219721
219366
  isTypeOnly: true,
219722
- children: /* @__PURE__ */ jsx(Type$2, {
219367
+ children: /* @__PURE__ */ jsx(Type$1, {
219723
219368
  name: typeName,
219724
219369
  export: true,
219725
219370
  children: `ReturnType<typeof ${name}>`
@@ -219848,7 +219493,7 @@ function Mutation$1({ name, clientName, mutationKeyName, mutationKeyTypeName, pa
219848
219493
  isExportable: true,
219849
219494
  isIndexable: true,
219850
219495
  isTypeOnly: true,
219851
- children: /* @__PURE__ */ jsx(Type$2, {
219496
+ children: /* @__PURE__ */ jsx(Type$1, {
219852
219497
  name: mutationArgTypeName,
219853
219498
  export: true,
219854
219499
  children: hasMutationParams ? `{${mutationArg}}` : "never"
@@ -220675,7 +220320,7 @@ function toCamelOrPascal(text, pascal) {
220675
220320
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
220676
220321
  }
220677
220322
  function applyToFileParts(text, transformPart) {
220678
- const parts = text.split(".");
220323
+ const parts = text.split(/\.(?=[a-zA-Z])/);
220679
220324
  return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
220680
220325
  }
220681
220326
  function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
@@ -220862,7 +220507,7 @@ function QueryKey({ name, typeSchemas, paramsCasing, pathParamsType, operation,
220862
220507
  isExportable: true,
220863
220508
  isIndexable: true,
220864
220509
  isTypeOnly: true,
220865
- children: /* @__PURE__ */ jsx(Type$2, {
220510
+ children: /* @__PURE__ */ jsx(Type$1, {
220866
220511
  name: typeName,
220867
220512
  export: true,
220868
220513
  children: `ReturnType<typeof ${name}>`
@@ -221340,7 +220985,7 @@ function MutationKey({ name, typeSchemas, pathParamsType, paramsCasing, operatio
221340
220985
  isExportable: true,
221341
220986
  isIndexable: true,
221342
220987
  isTypeOnly: true,
221343
- children: /* @__PURE__ */ jsx(Type$2, {
220988
+ children: /* @__PURE__ */ jsx(Type$1, {
221344
220989
  name: typeName,
221345
220990
  export: true,
221346
220991
  children: `ReturnType<typeof ${name}>`