@kubb/plugin-ts 5.0.0-alpha.11 → 5.0.0-alpha.13

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.
Files changed (57) hide show
  1. package/dist/Type-C8EHVKjc.js +663 -0
  2. package/dist/Type-C8EHVKjc.js.map +1 -0
  3. package/dist/Type-DrOq6-nh.cjs +680 -0
  4. package/dist/Type-DrOq6-nh.cjs.map +1 -0
  5. package/dist/casing-Cp-jbC_k.js +84 -0
  6. package/dist/casing-Cp-jbC_k.js.map +1 -0
  7. package/dist/casing-D2uQKLWS.cjs +144 -0
  8. package/dist/casing-D2uQKLWS.cjs.map +1 -0
  9. package/dist/components.cjs +3 -2
  10. package/dist/components.d.ts +41 -9
  11. package/dist/components.js +2 -2
  12. package/dist/generators-CX3cSSdF.cjs +551 -0
  13. package/dist/generators-CX3cSSdF.cjs.map +1 -0
  14. package/dist/generators-dCqW0ECC.js +547 -0
  15. package/dist/generators-dCqW0ECC.js.map +1 -0
  16. package/dist/generators.cjs +2 -3
  17. package/dist/generators.d.ts +3 -503
  18. package/dist/generators.js +2 -2
  19. package/dist/index.cjs +135 -4
  20. package/dist/index.cjs.map +1 -0
  21. package/dist/index.d.ts +2 -41
  22. package/dist/index.js +134 -2
  23. package/dist/index.js.map +1 -0
  24. package/dist/resolvers-CH7hINyz.js +181 -0
  25. package/dist/resolvers-CH7hINyz.js.map +1 -0
  26. package/dist/resolvers-ebHaaCyw.cjs +191 -0
  27. package/dist/resolvers-ebHaaCyw.cjs.map +1 -0
  28. package/dist/resolvers.cjs +4 -0
  29. package/dist/resolvers.d.ts +51 -0
  30. package/dist/resolvers.js +2 -0
  31. package/dist/{types-mSXmB8WU.d.ts → types-BSRhtbGl.d.ts} +80 -57
  32. package/package.json +12 -5
  33. package/src/components/{v2/Enum.tsx → Enum.tsx} +27 -11
  34. package/src/components/Type.tsx +24 -141
  35. package/src/components/index.ts +1 -0
  36. package/src/generators/index.ts +0 -1
  37. package/src/generators/typeGenerator.tsx +204 -413
  38. package/src/generators/utils.ts +300 -0
  39. package/src/index.ts +0 -1
  40. package/src/plugin.ts +81 -126
  41. package/src/printer.ts +20 -6
  42. package/src/resolvers/index.ts +2 -0
  43. package/src/{resolverTs.ts → resolvers/resolverTs.ts} +26 -2
  44. package/src/resolvers/resolverTsLegacy.ts +85 -0
  45. package/src/types.ts +75 -52
  46. package/dist/components-CRu8IKY3.js +0 -729
  47. package/dist/components-CRu8IKY3.js.map +0 -1
  48. package/dist/components-DeNDKlzf.cjs +0 -982
  49. package/dist/components-DeNDKlzf.cjs.map +0 -1
  50. package/dist/plugin-CJ29AwE2.cjs +0 -1320
  51. package/dist/plugin-CJ29AwE2.cjs.map +0 -1
  52. package/dist/plugin-D60XNJSD.js +0 -1267
  53. package/dist/plugin-D60XNJSD.js.map +0 -1
  54. package/src/components/v2/Type.tsx +0 -59
  55. package/src/generators/v2/typeGenerator.tsx +0 -167
  56. package/src/generators/v2/utils.ts +0 -140
  57. package/src/parser.ts +0 -389
@@ -0,0 +1,680 @@
1
+ const require_casing = require("./casing-D2uQKLWS.cjs");
2
+ let _kubb_ast = require("@kubb/ast");
3
+ let _kubb_core = require("@kubb/core");
4
+ let _kubb_react_fabric = require("@kubb/react-fabric");
5
+ let _kubb_fabric_core_parsers_typescript = require("@kubb/fabric-core/parsers/typescript");
6
+ let remeda = require("remeda");
7
+ let typescript = require("typescript");
8
+ typescript = require_casing.__toESM(typescript);
9
+ let _kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime");
10
+ //#region ../../internals/utils/src/string.ts
11
+ /**
12
+ * Strips a single matching pair of `"..."`, `'...'`, or `` `...` `` from both ends of `text`.
13
+ * Returns the string unchanged when no balanced quote pair is found.
14
+ *
15
+ * @example
16
+ * trimQuotes('"hello"') // 'hello'
17
+ * trimQuotes('hello') // 'hello'
18
+ */
19
+ function trimQuotes(text) {
20
+ if (text.length >= 2) {
21
+ const first = text[0];
22
+ const last = text[text.length - 1];
23
+ if (first === "\"" && last === "\"" || first === "'" && last === "'" || first === "`" && last === "`") return text.slice(1, -1);
24
+ }
25
+ return text;
26
+ }
27
+ /**
28
+ * Escapes characters that are not allowed inside JS string literals.
29
+ * Handles quotes, backslashes, and Unicode line terminators (U+2028 / U+2029).
30
+ *
31
+ * @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
32
+ */
33
+ function jsStringEscape(input) {
34
+ return `${input}`.replace(/["'\\\n\r\u2028\u2029]/g, (character) => {
35
+ switch (character) {
36
+ case "\"":
37
+ case "'":
38
+ case "\\": return `\\${character}`;
39
+ case "\n": return "\\n";
40
+ case "\r": return "\\r";
41
+ case "\u2028": return "\\u2028";
42
+ case "\u2029": return "\\u2029";
43
+ default: return "";
44
+ }
45
+ });
46
+ }
47
+ //#endregion
48
+ //#region ../../internals/utils/src/object.ts
49
+ /**
50
+ * Serializes a primitive value to a JSON string literal, stripping any surrounding quote characters first.
51
+ *
52
+ * @example
53
+ * stringify('hello') // '"hello"'
54
+ * stringify('"hello"') // '"hello"'
55
+ */
56
+ function stringify(value) {
57
+ if (value === void 0 || value === null) return "\"\"";
58
+ return JSON.stringify(trimQuotes(value.toString()));
59
+ }
60
+ //#endregion
61
+ //#region src/constants.ts
62
+ /**
63
+ * `optionalType` values that cause a property's type to include `| undefined`.
64
+ */
65
+ const OPTIONAL_ADDS_UNDEFINED = new Set(["undefined", "questionTokenAndUndefined"]);
66
+ /**
67
+ * `optionalType` values that render the property key with a `?` token.
68
+ */
69
+ const OPTIONAL_ADDS_QUESTION_TOKEN = new Set(["questionToken", "questionTokenAndUndefined"]);
70
+ /**
71
+ * `enumType` values that append a `Key` suffix to the generated enum type alias.
72
+ */
73
+ const ENUM_TYPES_WITH_KEY_SUFFIX = new Set(["asConst", "asPascalConst"]);
74
+ /**
75
+ * `enumType` values that require a runtime value declaration (object, enum, or literal).
76
+ */
77
+ const ENUM_TYPES_WITH_RUNTIME_VALUE = new Set([
78
+ "enum",
79
+ "asConst",
80
+ "asPascalConst",
81
+ "constEnum",
82
+ "literal",
83
+ void 0
84
+ ]);
85
+ /**
86
+ * `enumType` values whose type declaration is type-only (no runtime value emitted for the type alias).
87
+ */
88
+ const ENUM_TYPES_WITH_TYPE_ONLY = new Set([
89
+ "asConst",
90
+ "asPascalConst",
91
+ "literal",
92
+ void 0
93
+ ]);
94
+ //#endregion
95
+ //#region src/factory.ts
96
+ const { SyntaxKind, factory } = typescript.default;
97
+ const modifiers = {
98
+ async: factory.createModifier(typescript.default.SyntaxKind.AsyncKeyword),
99
+ export: factory.createModifier(typescript.default.SyntaxKind.ExportKeyword),
100
+ const: factory.createModifier(typescript.default.SyntaxKind.ConstKeyword),
101
+ static: factory.createModifier(typescript.default.SyntaxKind.StaticKeyword)
102
+ };
103
+ const syntaxKind = {
104
+ union: SyntaxKind.UnionType,
105
+ literalType: SyntaxKind.LiteralType,
106
+ stringLiteral: SyntaxKind.StringLiteral
107
+ };
108
+ function isValidIdentifier(str) {
109
+ if (!str.length || str.trim() !== str) return false;
110
+ const node = typescript.default.parseIsolatedEntityName(str, typescript.default.ScriptTarget.Latest);
111
+ return !!node && node.kind === typescript.default.SyntaxKind.Identifier && typescript.default.identifierToKeywordKind(node.kind) === void 0;
112
+ }
113
+ function propertyName(name) {
114
+ if (typeof name === "string") return isValidIdentifier(name) ? factory.createIdentifier(name) : factory.createStringLiteral(name);
115
+ return name;
116
+ }
117
+ const questionToken = factory.createToken(typescript.default.SyntaxKind.QuestionToken);
118
+ function createQuestionToken(token) {
119
+ if (!token) return;
120
+ if (token === true) return questionToken;
121
+ return token;
122
+ }
123
+ function createIntersectionDeclaration({ nodes, withParentheses }) {
124
+ if (!nodes.length) return null;
125
+ if (nodes.length === 1) return nodes[0] || null;
126
+ const node = factory.createIntersectionTypeNode(nodes);
127
+ if (withParentheses) return factory.createParenthesizedType(node);
128
+ return node;
129
+ }
130
+ function createArrayDeclaration({ nodes, arrayType = "array" }) {
131
+ if (!nodes.length) return factory.createTupleTypeNode([]);
132
+ if (nodes.length === 1) {
133
+ const node = nodes[0];
134
+ if (!node) return null;
135
+ if (arrayType === "generic") return factory.createTypeReferenceNode(factory.createIdentifier("Array"), [node]);
136
+ return factory.createArrayTypeNode(node);
137
+ }
138
+ const unionType = factory.createUnionTypeNode(nodes);
139
+ if (arrayType === "generic") return factory.createTypeReferenceNode(factory.createIdentifier("Array"), [unionType]);
140
+ return factory.createArrayTypeNode(factory.createParenthesizedType(unionType));
141
+ }
142
+ /**
143
+ * Minimum nodes length of 2
144
+ * @example `string | number`
145
+ */
146
+ function createUnionDeclaration({ nodes, withParentheses }) {
147
+ if (!nodes.length) return keywordTypeNodes.any;
148
+ if (nodes.length === 1) return nodes[0];
149
+ const node = factory.createUnionTypeNode(nodes);
150
+ if (withParentheses) return factory.createParenthesizedType(node);
151
+ return node;
152
+ }
153
+ function createPropertySignature({ readOnly, modifiers = [], name, questionToken, type }) {
154
+ return factory.createPropertySignature([...modifiers, readOnly ? factory.createToken(typescript.default.SyntaxKind.ReadonlyKeyword) : void 0].filter(Boolean), propertyName(name), createQuestionToken(questionToken), type);
155
+ }
156
+ function createParameterSignature(name, { modifiers, dotDotDotToken, questionToken, type, initializer }) {
157
+ return factory.createParameterDeclaration(modifiers, dotDotDotToken, name, createQuestionToken(questionToken), type, initializer);
158
+ }
159
+ /**
160
+ * @link https://github.com/microsoft/TypeScript/issues/44151
161
+ */
162
+ function appendJSDocToNode({ node, comments }) {
163
+ const filteredComments = comments.filter(Boolean);
164
+ if (!filteredComments.length) return node;
165
+ const text = filteredComments.reduce((acc = "", comment = "") => {
166
+ return `${acc}\n * ${comment.replaceAll("*/", "*\\/")}`;
167
+ }, "*");
168
+ return typescript.default.addSyntheticLeadingComment(node, typescript.default.SyntaxKind.MultiLineCommentTrivia, `${text || "*"}\n`, true);
169
+ }
170
+ function createIndexSignature(type, { modifiers, indexName = "key", indexType = factory.createKeywordTypeNode(typescript.default.SyntaxKind.StringKeyword) } = {}) {
171
+ return factory.createIndexSignature(modifiers, [createParameterSignature(indexName, { type: indexType })], type);
172
+ }
173
+ function createTypeAliasDeclaration({ modifiers, name, typeParameters, type }) {
174
+ return factory.createTypeAliasDeclaration(modifiers, name, typeParameters, type);
175
+ }
176
+ function createInterfaceDeclaration({ modifiers, name, typeParameters, members }) {
177
+ return factory.createInterfaceDeclaration(modifiers, name, typeParameters, void 0, members);
178
+ }
179
+ function createTypeDeclaration({ syntax, isExportable, comments, name, type }) {
180
+ if (syntax === "interface" && "members" in type) return appendJSDocToNode({
181
+ node: createInterfaceDeclaration({
182
+ members: type.members,
183
+ modifiers: isExportable ? [modifiers.export] : [],
184
+ name,
185
+ typeParameters: void 0
186
+ }),
187
+ comments
188
+ });
189
+ return appendJSDocToNode({
190
+ node: createTypeAliasDeclaration({
191
+ type,
192
+ modifiers: isExportable ? [modifiers.export] : [],
193
+ name,
194
+ typeParameters: void 0
195
+ }),
196
+ comments
197
+ });
198
+ }
199
+ /**
200
+ * Apply casing transformation to enum keys
201
+ */
202
+ function applyEnumKeyCasing(key, casing = "none") {
203
+ if (casing === "none") return key;
204
+ if (casing === "screamingSnakeCase") return require_casing.screamingSnakeCase(key);
205
+ if (casing === "snakeCase") return require_casing.snakeCase(key);
206
+ if (casing === "pascalCase") return require_casing.pascalCase(key);
207
+ if (casing === "camelCase") return require_casing.camelCase(key);
208
+ return key;
209
+ }
210
+ function createEnumDeclaration({ type = "enum", name, typeName, enums, enumKeyCasing = "none" }) {
211
+ if (type === "literal" || type === "inlineLiteral") return [void 0, factory.createTypeAliasDeclaration([factory.createToken(typescript.default.SyntaxKind.ExportKeyword)], factory.createIdentifier(typeName), void 0, factory.createUnionTypeNode(enums.map(([_key, value]) => {
212
+ if ((0, remeda.isNumber)(value)) {
213
+ if (value < 0) return factory.createLiteralTypeNode(factory.createPrefixUnaryExpression(typescript.default.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value))));
214
+ return factory.createLiteralTypeNode(factory.createNumericLiteral(value?.toString()));
215
+ }
216
+ if (typeof value === "boolean") return factory.createLiteralTypeNode(value ? factory.createTrue() : factory.createFalse());
217
+ if (value) return factory.createLiteralTypeNode(factory.createStringLiteral(value.toString()));
218
+ }).filter(Boolean)))];
219
+ if (type === "enum" || type === "constEnum") return [void 0, factory.createEnumDeclaration([factory.createToken(typescript.default.SyntaxKind.ExportKeyword), type === "constEnum" ? factory.createToken(typescript.default.SyntaxKind.ConstKeyword) : void 0].filter(Boolean), factory.createIdentifier(typeName), enums.map(([key, value]) => {
220
+ let initializer = factory.createStringLiteral(value?.toString());
221
+ if (Number.parseInt(value.toString(), 10) === value && (0, remeda.isNumber)(Number.parseInt(value.toString(), 10))) if (value < 0) initializer = factory.createPrefixUnaryExpression(typescript.default.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)));
222
+ else initializer = factory.createNumericLiteral(value);
223
+ if (typeof value === "boolean") initializer = value ? factory.createTrue() : factory.createFalse();
224
+ if ((0, remeda.isNumber)(Number.parseInt(key.toString(), 10))) {
225
+ const casingKey = applyEnumKeyCasing(`${typeName}_${key}`, enumKeyCasing);
226
+ return factory.createEnumMember(propertyName(casingKey), initializer);
227
+ }
228
+ if (key) {
229
+ const casingKey = applyEnumKeyCasing(key.toString(), enumKeyCasing);
230
+ return factory.createEnumMember(propertyName(casingKey), initializer);
231
+ }
232
+ }).filter(Boolean))];
233
+ const identifierName = name;
234
+ if (enums.length === 0) return [void 0, factory.createTypeAliasDeclaration([factory.createToken(typescript.default.SyntaxKind.ExportKeyword)], factory.createIdentifier(typeName), void 0, factory.createKeywordTypeNode(typescript.default.SyntaxKind.NeverKeyword))];
235
+ return [factory.createVariableStatement([factory.createToken(typescript.default.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier(identifierName), void 0, void 0, factory.createAsExpression(factory.createObjectLiteralExpression(enums.map(([key, value]) => {
236
+ let initializer = factory.createStringLiteral(value?.toString());
237
+ if ((0, remeda.isNumber)(value)) if (value < 0) initializer = factory.createPrefixUnaryExpression(typescript.default.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)));
238
+ else initializer = factory.createNumericLiteral(value);
239
+ if (typeof value === "boolean") initializer = value ? factory.createTrue() : factory.createFalse();
240
+ if (key) {
241
+ const casingKey = applyEnumKeyCasing(key.toString(), enumKeyCasing);
242
+ return factory.createPropertyAssignment(propertyName(casingKey), initializer);
243
+ }
244
+ }).filter(Boolean), true), factory.createTypeReferenceNode(factory.createIdentifier("const"), void 0)))], typescript.default.NodeFlags.Const)), factory.createTypeAliasDeclaration([factory.createToken(typescript.default.SyntaxKind.ExportKeyword)], factory.createIdentifier(typeName), void 0, factory.createIndexedAccessTypeNode(factory.createParenthesizedType(factory.createTypeQueryNode(factory.createIdentifier(identifierName), void 0)), factory.createTypeOperatorNode(typescript.default.SyntaxKind.KeyOfKeyword, factory.createTypeQueryNode(factory.createIdentifier(identifierName), void 0))))];
245
+ }
246
+ function createOmitDeclaration({ keys, type, nonNullable }) {
247
+ const node = nonNullable ? factory.createTypeReferenceNode(factory.createIdentifier("NonNullable"), [type]) : type;
248
+ if (Array.isArray(keys)) return factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [node, factory.createUnionTypeNode(keys.map((key) => {
249
+ return factory.createLiteralTypeNode(factory.createStringLiteral(key));
250
+ }))]);
251
+ return factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [node, factory.createLiteralTypeNode(factory.createStringLiteral(keys))]);
252
+ }
253
+ const keywordTypeNodes = {
254
+ any: factory.createKeywordTypeNode(typescript.default.SyntaxKind.AnyKeyword),
255
+ unknown: factory.createKeywordTypeNode(typescript.default.SyntaxKind.UnknownKeyword),
256
+ void: factory.createKeywordTypeNode(typescript.default.SyntaxKind.VoidKeyword),
257
+ number: factory.createKeywordTypeNode(typescript.default.SyntaxKind.NumberKeyword),
258
+ integer: factory.createKeywordTypeNode(typescript.default.SyntaxKind.NumberKeyword),
259
+ bigint: factory.createKeywordTypeNode(typescript.default.SyntaxKind.BigIntKeyword),
260
+ object: factory.createKeywordTypeNode(typescript.default.SyntaxKind.ObjectKeyword),
261
+ string: factory.createKeywordTypeNode(typescript.default.SyntaxKind.StringKeyword),
262
+ boolean: factory.createKeywordTypeNode(typescript.default.SyntaxKind.BooleanKeyword),
263
+ undefined: factory.createKeywordTypeNode(typescript.default.SyntaxKind.UndefinedKeyword),
264
+ null: factory.createLiteralTypeNode(factory.createToken(typescript.default.SyntaxKind.NullKeyword)),
265
+ never: factory.createKeywordTypeNode(typescript.default.SyntaxKind.NeverKeyword)
266
+ };
267
+ /**
268
+ * Converts a path like '/pet/{petId}/uploadImage' to a template literal type
269
+ * like `/pet/${string}/uploadImage`
270
+ */
271
+ /**
272
+ * Converts an OAS-style path (e.g. `/pets/{petId}`) or an Express-style path
273
+ * (e.g. `/pets/:petId`) to a TypeScript template literal type
274
+ * like `` `/pets/${string}` ``.
275
+ */
276
+ function createUrlTemplateType(path) {
277
+ const normalized = path.replace(/:([^/]+)/g, "{$1}");
278
+ if (!normalized.includes("{")) return factory.createLiteralTypeNode(factory.createStringLiteral(normalized));
279
+ const segments = normalized.split(/(\{[^}]+\})/);
280
+ const parts = [];
281
+ const parameterIndices = [];
282
+ segments.forEach((segment) => {
283
+ if (segment.startsWith("{") && segment.endsWith("}")) {
284
+ parameterIndices.push(parts.length);
285
+ parts.push(segment);
286
+ } else if (segment) parts.push(segment);
287
+ });
288
+ const head = typescript.default.factory.createTemplateHead(parts[0] || "");
289
+ const templateSpans = [];
290
+ parameterIndices.forEach((paramIndex, i) => {
291
+ const isLast = i === parameterIndices.length - 1;
292
+ const nextPart = parts[paramIndex + 1] || "";
293
+ const literal = isLast ? typescript.default.factory.createTemplateTail(nextPart) : typescript.default.factory.createTemplateMiddle(nextPart);
294
+ templateSpans.push(typescript.default.factory.createTemplateLiteralTypeSpan(keywordTypeNodes.string, literal));
295
+ });
296
+ return typescript.default.factory.createTemplateLiteralType(head, templateSpans);
297
+ }
298
+ const createTypeLiteralNode = factory.createTypeLiteralNode;
299
+ const createTypeReferenceNode = factory.createTypeReferenceNode;
300
+ const createNumericLiteral = factory.createNumericLiteral;
301
+ const createStringLiteral = factory.createStringLiteral;
302
+ const createArrayTypeNode = factory.createArrayTypeNode;
303
+ factory.createParenthesizedType;
304
+ const createLiteralTypeNode = factory.createLiteralTypeNode;
305
+ factory.createNull;
306
+ const createIdentifier = factory.createIdentifier;
307
+ const createOptionalTypeNode = factory.createOptionalTypeNode;
308
+ const createTupleTypeNode = factory.createTupleTypeNode;
309
+ const createRestTypeNode = factory.createRestTypeNode;
310
+ const createTrue = factory.createTrue;
311
+ const createFalse = factory.createFalse;
312
+ factory.createIndexedAccessTypeNode;
313
+ factory.createTypeOperatorNode;
314
+ const createPrefixUnaryExpression = factory.createPrefixUnaryExpression;
315
+ //#endregion
316
+ //#region src/printer.ts
317
+ /**
318
+ * Converts a primitive const value to a TypeScript literal type node.
319
+ * Handles negative numbers via a prefix unary expression.
320
+ */
321
+ function constToTypeNode(value, format) {
322
+ if (format === "boolean") return createLiteralTypeNode(value === true ? createTrue() : createFalse());
323
+ if (format === "number" && typeof value === "number") {
324
+ if (value < 0) return createLiteralTypeNode(createPrefixUnaryExpression(SyntaxKind.MinusToken, createNumericLiteral(Math.abs(value))));
325
+ return createLiteralTypeNode(createNumericLiteral(value));
326
+ }
327
+ return createLiteralTypeNode(createStringLiteral(String(value)));
328
+ }
329
+ /**
330
+ * Returns a `Date` reference type node when `representation` is `'date'`, otherwise falls back to `string`.
331
+ */
332
+ function dateOrStringNode(node) {
333
+ return node.representation === "date" ? createTypeReferenceNode(createIdentifier("Date")) : keywordTypeNodes.string;
334
+ }
335
+ /**
336
+ * Maps an array of `SchemaNode`s through the printer, filtering out `null` and `undefined` results.
337
+ */
338
+ function buildMemberNodes(members, print) {
339
+ return (members ?? []).map(print).filter(Boolean);
340
+ }
341
+ /**
342
+ * Builds a TypeScript tuple type node from an array schema's `items`,
343
+ * applying min/max slice and optional/rest element rules.
344
+ */
345
+ function buildTupleNode(node, print) {
346
+ let items = (node.items ?? []).map(print).filter(Boolean);
347
+ const restNode = node.rest ? print(node.rest) ?? void 0 : void 0;
348
+ const { min, max } = node;
349
+ if (max !== void 0) {
350
+ items = items.slice(0, max);
351
+ if (items.length < max && restNode) items = [...items, ...Array(max - items.length).fill(restNode)];
352
+ }
353
+ if (min !== void 0) items = items.map((item, i) => i >= min ? createOptionalTypeNode(item) : item);
354
+ if (max === void 0 && restNode) items.push(createRestTypeNode(createArrayTypeNode(restNode)));
355
+ return createTupleTypeNode(items);
356
+ }
357
+ /**
358
+ * Applies `nullable` and optional/nullish `| undefined` union modifiers to a property's resolved base type.
359
+ */
360
+ function buildPropertyType(schema, baseType, optionalType) {
361
+ const addsUndefined = OPTIONAL_ADDS_UNDEFINED.has(optionalType);
362
+ let type = baseType;
363
+ if (schema.nullable) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] });
364
+ if ((schema.nullish || schema.optional) && addsUndefined) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
365
+ return type;
366
+ }
367
+ /**
368
+ * Collects JSDoc annotation strings (description, deprecated, min/max, pattern, default, example, type) for a schema node.
369
+ */
370
+ function buildPropertyJSDocComments(schema) {
371
+ const isArray = schema.type === "array";
372
+ return [
373
+ "description" in schema && schema.description ? `@description ${jsStringEscape(schema.description)}` : void 0,
374
+ "deprecated" in schema && schema.deprecated ? "@deprecated" : void 0,
375
+ !isArray && "min" in schema && schema.min !== void 0 ? `@minLength ${schema.min}` : void 0,
376
+ !isArray && "max" in schema && schema.max !== void 0 ? `@maxLength ${schema.max}` : void 0,
377
+ "pattern" in schema && schema.pattern ? `@pattern ${schema.pattern}` : void 0,
378
+ "default" in schema && schema.default !== void 0 ? `@default ${"primitive" in schema && schema.primitive === "string" ? stringify(schema.default) : schema.default}` : void 0,
379
+ "example" in schema && schema.example !== void 0 ? `@example ${schema.example}` : void 0,
380
+ "primitive" in schema && schema.primitive ? [`@type ${schema.primitive || "unknown"}`, "optional" in schema && schema.optional ? " | undefined" : void 0].filter(Boolean).join("") : void 0
381
+ ];
382
+ }
383
+ /**
384
+ * Creates TypeScript index signatures for `additionalProperties` and `patternProperties` on an object schema node.
385
+ */
386
+ function buildIndexSignatures(node, propertyCount, print) {
387
+ const elements = [];
388
+ if (node.additionalProperties && node.additionalProperties !== true) {
389
+ const additionalType = print(node.additionalProperties) ?? keywordTypeNodes.unknown;
390
+ elements.push(createIndexSignature(propertyCount > 0 ? keywordTypeNodes.unknown : additionalType));
391
+ } else if (node.additionalProperties === true) elements.push(createIndexSignature(keywordTypeNodes.unknown));
392
+ if (node.patternProperties) {
393
+ const first = Object.values(node.patternProperties)[0];
394
+ if (first) {
395
+ let patternType = print(first) ?? keywordTypeNodes.unknown;
396
+ if (first.nullable) patternType = createUnionDeclaration({ nodes: [patternType, keywordTypeNodes.null] });
397
+ elements.push(createIndexSignature(patternType));
398
+ }
399
+ }
400
+ return elements;
401
+ }
402
+ /**
403
+ * TypeScript type printer built with `definePrinter`.
404
+ *
405
+ * Converts a `SchemaNode` AST node into a TypeScript AST node:
406
+ * - **`printer.print(node)`** — when `options.typeName` is set, returns a full
407
+ * `type Name = …` or `interface Name { … }` declaration (`ts.Node`).
408
+ * Without `typeName`, returns the raw `ts.TypeNode` for the schema.
409
+ *
410
+ * Dispatches on `node.type` to the appropriate handler in `nodes`. Options are closed
411
+ * over per printer instance, so each call to `printerTs(options)` produces an independent printer.
412
+ *
413
+ * @example Raw type node (no `typeName`)
414
+ * ```ts
415
+ * const printer = printerTs({ optionalType: 'questionToken', arrayType: 'array', enumType: 'inlineLiteral' })
416
+ * const typeNode = printer.print(schemaNode) // ts.TypeNode
417
+ * ```
418
+ *
419
+ * @example Full declaration (with `typeName`)
420
+ * ```ts
421
+ * const printer = printerTs({ optionalType: 'questionToken', arrayType: 'array', enumType: 'inlineLiteral', typeName: 'MyType' })
422
+ * const declaration = printer.print(schemaNode) // ts.TypeAliasDeclaration | ts.InterfaceDeclaration
423
+ * ```
424
+ */
425
+ const printerTs = (0, _kubb_core.definePrinter)((options) => {
426
+ const addsUndefined = OPTIONAL_ADDS_UNDEFINED.has(options.optionalType);
427
+ return {
428
+ name: "typescript",
429
+ options,
430
+ nodes: {
431
+ any: () => keywordTypeNodes.any,
432
+ unknown: () => keywordTypeNodes.unknown,
433
+ void: () => keywordTypeNodes.void,
434
+ never: () => keywordTypeNodes.never,
435
+ boolean: () => keywordTypeNodes.boolean,
436
+ null: () => keywordTypeNodes.null,
437
+ blob: () => createTypeReferenceNode("Blob", []),
438
+ string: () => keywordTypeNodes.string,
439
+ uuid: () => keywordTypeNodes.string,
440
+ email: () => keywordTypeNodes.string,
441
+ url: (node) => {
442
+ if (node.path) return createUrlTemplateType(node.path);
443
+ return keywordTypeNodes.string;
444
+ },
445
+ datetime: () => keywordTypeNodes.string,
446
+ number: () => keywordTypeNodes.number,
447
+ integer: () => keywordTypeNodes.number,
448
+ bigint: () => keywordTypeNodes.bigint,
449
+ date: dateOrStringNode,
450
+ time: dateOrStringNode,
451
+ ref(node) {
452
+ if (!node.name) return;
453
+ const refName = node.ref ? node.ref.split("/").at(-1) ?? node.name : node.name;
454
+ return createTypeReferenceNode(node.ref ? this.options.resolver.default(refName, "type") : refName, void 0);
455
+ },
456
+ enum(node) {
457
+ const values = node.namedEnumValues?.map((v) => v.value) ?? node.enumValues ?? [];
458
+ if (this.options.enumType === "inlineLiteral" || !node.name) return createUnionDeclaration({
459
+ withParentheses: true,
460
+ nodes: values.filter((v) => v !== null).map((value) => constToTypeNode(value, typeof value)).filter(Boolean)
461
+ }) ?? void 0;
462
+ const resolvedName = this.options.resolver.default(node.name, "type");
463
+ return createTypeReferenceNode(ENUM_TYPES_WITH_KEY_SUFFIX.has(this.options.enumType) ? `${resolvedName}Key` : resolvedName, void 0);
464
+ },
465
+ union(node) {
466
+ const members = node.members ?? [];
467
+ const hasStringLiteral = members.some((m) => m.type === "enum" && (m.enumType === "string" || m.primitive === "string"));
468
+ const hasPlainString = members.some((m) => (0, _kubb_ast.isPlainStringType)(m));
469
+ if (hasStringLiteral && hasPlainString) return createUnionDeclaration({
470
+ withParentheses: true,
471
+ nodes: members.map((m) => {
472
+ if ((0, _kubb_ast.isPlainStringType)(m)) return createIntersectionDeclaration({
473
+ nodes: [keywordTypeNodes.string, createTypeLiteralNode([])],
474
+ withParentheses: true
475
+ });
476
+ return this.print(m);
477
+ }).filter(Boolean)
478
+ }) ?? void 0;
479
+ return createUnionDeclaration({
480
+ withParentheses: true,
481
+ nodes: buildMemberNodes(members, this.print)
482
+ }) ?? void 0;
483
+ },
484
+ intersection(node) {
485
+ return createIntersectionDeclaration({
486
+ withParentheses: true,
487
+ nodes: buildMemberNodes(node.members, this.print)
488
+ }) ?? void 0;
489
+ },
490
+ array(node) {
491
+ return createArrayDeclaration({
492
+ nodes: (node.items ?? []).map((item) => this.print(item)).filter(Boolean),
493
+ arrayType: this.options.arrayType
494
+ }) ?? void 0;
495
+ },
496
+ tuple(node) {
497
+ return buildTupleNode(node, this.print);
498
+ },
499
+ object(node) {
500
+ const { print, options } = this;
501
+ const addsQuestionToken = OPTIONAL_ADDS_QUESTION_TOKEN.has(options.optionalType);
502
+ const propertyNodes = node.properties.map((prop) => {
503
+ const baseType = print(prop.schema) ?? keywordTypeNodes.unknown;
504
+ const type = buildPropertyType(prop.schema, baseType, options.optionalType);
505
+ return appendJSDocToNode({
506
+ node: createPropertySignature({
507
+ questionToken: prop.schema.optional || prop.schema.nullish ? addsQuestionToken : false,
508
+ name: prop.name,
509
+ type,
510
+ readOnly: prop.schema.readOnly
511
+ }),
512
+ comments: buildPropertyJSDocComments(prop.schema)
513
+ });
514
+ });
515
+ const allElements = [...propertyNodes, ...buildIndexSignatures(node, propertyNodes.length, print)];
516
+ if (!allElements.length) return keywordTypeNodes.object;
517
+ return createTypeLiteralNode(allElements);
518
+ }
519
+ },
520
+ print(node) {
521
+ let type = this.print(node);
522
+ if (!type) return;
523
+ if (node.nullable) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] });
524
+ if ((node.nullish || node.optional) && addsUndefined) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
525
+ const { typeName, syntaxType = "type", description, keysToOmit } = this.options;
526
+ if (!typeName) return type;
527
+ const useTypeGeneration = syntaxType === "type" || type.kind === syntaxKind.union || !!keysToOmit?.length;
528
+ return createTypeDeclaration({
529
+ name: typeName,
530
+ isExportable: true,
531
+ type: keysToOmit?.length ? createOmitDeclaration({
532
+ keys: keysToOmit,
533
+ type,
534
+ nonNullable: true
535
+ }) : type,
536
+ syntax: useTypeGeneration ? "type" : "interface",
537
+ comments: [
538
+ node?.title ? jsStringEscape(node.title) : void 0,
539
+ description ? `@description ${jsStringEscape(description)}` : void 0,
540
+ node?.deprecated ? "@deprecated" : void 0,
541
+ node && "min" in node && node.min !== void 0 ? `@minLength ${node.min}` : void 0,
542
+ node && "max" in node && node.max !== void 0 ? `@maxLength ${node.max}` : void 0,
543
+ node && "pattern" in node && node.pattern ? `@pattern ${node.pattern}` : void 0,
544
+ node?.default ? `@default ${node.default}` : void 0,
545
+ node?.example ? `@example ${node.example}` : void 0
546
+ ]
547
+ });
548
+ }
549
+ };
550
+ });
551
+ //#endregion
552
+ //#region src/components/Enum.tsx
553
+ /**
554
+ * Resolves the runtime identifier name and the TypeScript type name for an enum schema node.
555
+ *
556
+ * The raw `node.name` may be a YAML key such as `"enumNames.Type"` which is not a
557
+ * valid TypeScript identifier. The resolver normalizes it; for inline enum
558
+ * properties the adapter already emits a PascalCase+suffix name so resolution is typically a no-op.
559
+ */
560
+ function getEnumNames({ node, enumType, resolver }) {
561
+ const resolved = resolver.default(node.name, "type");
562
+ return {
563
+ enumName: enumType === "asPascalConst" ? resolved : require_casing.camelCase(node.name),
564
+ typeName: ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) ? `${resolved}Key` : resolved,
565
+ refName: resolved
566
+ };
567
+ }
568
+ /**
569
+ * Renders the enum declaration(s) for a single named `EnumSchemaNode`.
570
+ *
571
+ * Depending on `enumType` this may emit:
572
+ * - A runtime object (`asConst` / `asPascalConst`) plus a `typeof` type alias
573
+ * - A `const enum` or plain `enum` declaration (`constEnum` / `enum`)
574
+ * - A union literal type alias (`literal`)
575
+ *
576
+ * The emitted `File.Source` nodes carry the resolved names so that the barrel
577
+ * index picks up the correct export identifiers.
578
+ */
579
+ function Enum({ node, enumType, enumKeyCasing, resolver }) {
580
+ const { enumName, typeName, refName } = getEnumNames({
581
+ node,
582
+ enumType,
583
+ resolver
584
+ });
585
+ const [nameNode, typeNode] = createEnumDeclaration({
586
+ name: enumName,
587
+ typeName,
588
+ enums: node.namedEnumValues?.map((v) => [trimQuotes(v.name.toString()), v.value]) ?? node.enumValues?.filter((v) => v !== null && v !== void 0).map((v) => [trimQuotes(v.toString()), v]) ?? [],
589
+ type: enumType,
590
+ enumKeyCasing
591
+ });
592
+ const needsRefAlias = ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && refName !== typeName;
593
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
594
+ nameNode && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
595
+ name: enumName,
596
+ isExportable: true,
597
+ isIndexable: true,
598
+ isTypeOnly: false,
599
+ children: (0, _kubb_fabric_core_parsers_typescript.safePrint)(nameNode)
600
+ }),
601
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
602
+ name: typeName,
603
+ isIndexable: true,
604
+ isExportable: ENUM_TYPES_WITH_RUNTIME_VALUE.has(enumType),
605
+ isTypeOnly: ENUM_TYPES_WITH_TYPE_ONLY.has(enumType),
606
+ children: (0, _kubb_fabric_core_parsers_typescript.safePrint)(typeNode)
607
+ }),
608
+ needsRefAlias && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
609
+ name: refName,
610
+ isExportable: true,
611
+ isIndexable: true,
612
+ isTypeOnly: true,
613
+ children: `export type ${refName} = ${typeName}`
614
+ })
615
+ ] });
616
+ }
617
+ //#endregion
618
+ //#region src/components/Type.tsx
619
+ function Type({ name, typedName, node, keysToOmit, optionalType, arrayType, syntaxType, enumType, enumKeyCasing, description, resolver }) {
620
+ const resolvedDescription = description || node?.description;
621
+ const enumSchemaNodes = (0, _kubb_ast.collect)(node, { schema(n) {
622
+ if (n.type === "enum" && n.name) return n;
623
+ } });
624
+ const typeNode = printerTs({
625
+ optionalType,
626
+ arrayType,
627
+ enumType,
628
+ typeName: name,
629
+ syntaxType,
630
+ description: resolvedDescription,
631
+ keysToOmit,
632
+ resolver
633
+ }).print(node);
634
+ if (!typeNode) return;
635
+ const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((node) => {
636
+ return {
637
+ node,
638
+ ...getEnumNames({
639
+ node,
640
+ enumType,
641
+ resolver
642
+ })
643
+ };
644
+ });
645
+ const shouldExportEnums = enumType !== "inlineLiteral";
646
+ const shouldExportType = enumType === "inlineLiteral" || enums.every((item) => item.typeName !== name);
647
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [shouldExportEnums && enums.map(({ node }) => /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Enum, {
648
+ node,
649
+ enumType,
650
+ enumKeyCasing,
651
+ resolver
652
+ })), shouldExportType && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
653
+ name: typedName,
654
+ isTypeOnly: true,
655
+ isExportable: true,
656
+ isIndexable: true,
657
+ children: (0, _kubb_fabric_core_parsers_typescript.safePrint)(typeNode)
658
+ })] });
659
+ }
660
+ //#endregion
661
+ Object.defineProperty(exports, "ENUM_TYPES_WITH_KEY_SUFFIX", {
662
+ enumerable: true,
663
+ get: function() {
664
+ return ENUM_TYPES_WITH_KEY_SUFFIX;
665
+ }
666
+ });
667
+ Object.defineProperty(exports, "Enum", {
668
+ enumerable: true,
669
+ get: function() {
670
+ return Enum;
671
+ }
672
+ });
673
+ Object.defineProperty(exports, "Type", {
674
+ enumerable: true,
675
+ get: function() {
676
+ return Type;
677
+ }
678
+ });
679
+
680
+ //# sourceMappingURL=Type-DrOq6-nh.cjs.map