@kubb/plugin-ts 4.1.4 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,580 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+ let __kubb_core_transformers = require("@kubb/core/transformers");
25
+ __kubb_core_transformers = __toESM(__kubb_core_transformers);
26
+ let __kubb_plugin_oas = require("@kubb/plugin-oas");
27
+ __kubb_plugin_oas = __toESM(__kubb_plugin_oas);
28
+ let __kubb_fabric_core_parsers_typescript = require("@kubb/fabric-core/parsers/typescript");
29
+ __kubb_fabric_core_parsers_typescript = __toESM(__kubb_fabric_core_parsers_typescript);
30
+ let __kubb_react = require("@kubb/react");
31
+ __kubb_react = __toESM(__kubb_react);
32
+ let __kubb_react_jsx_runtime = require("@kubb/react/jsx-runtime");
33
+ __kubb_react_jsx_runtime = __toESM(__kubb_react_jsx_runtime);
34
+ let remeda = require("remeda");
35
+ remeda = __toESM(remeda);
36
+ let typescript = require("typescript");
37
+ typescript = __toESM(typescript);
38
+
39
+ //#region src/components/OasType.tsx
40
+ function OasType({ name, typeName, api }) {
41
+ return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react_jsx_runtime.Fragment, { children: [
42
+ /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
43
+ name,
44
+ isExportable: true,
45
+ isIndexable: true,
46
+ children: `export const ${name} = ${JSON.stringify(api, void 0, 2)} as const`
47
+ }),
48
+ /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)("br", {}),
49
+ /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
50
+ name: typeName,
51
+ isExportable: true,
52
+ isIndexable: true,
53
+ isTypeOnly: true,
54
+ children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.Type, {
55
+ name: typeName,
56
+ export: true,
57
+ children: `Infer<typeof ${name}>`
58
+ })
59
+ })
60
+ ] });
61
+ }
62
+
63
+ //#endregion
64
+ //#region src/factory.ts
65
+ const { SyntaxKind, factory } = typescript.default;
66
+ const modifiers = {
67
+ async: factory.createModifier(typescript.default.SyntaxKind.AsyncKeyword),
68
+ export: factory.createModifier(typescript.default.SyntaxKind.ExportKeyword),
69
+ const: factory.createModifier(typescript.default.SyntaxKind.ConstKeyword),
70
+ static: factory.createModifier(typescript.default.SyntaxKind.StaticKeyword)
71
+ };
72
+ const syntaxKind = { union: SyntaxKind.UnionType };
73
+ function isValidIdentifier(str) {
74
+ if (!str.length || str.trim() !== str) return false;
75
+ const node = typescript.default.parseIsolatedEntityName(str, typescript.default.ScriptTarget.Latest);
76
+ return !!node && node.kind === typescript.default.SyntaxKind.Identifier && typescript.default.identifierToKeywordKind(node.kind) === void 0;
77
+ }
78
+ function propertyName(name) {
79
+ if (typeof name === "string") return isValidIdentifier(name) ? factory.createIdentifier(name) : factory.createStringLiteral(name);
80
+ return name;
81
+ }
82
+ const questionToken = factory.createToken(typescript.default.SyntaxKind.QuestionToken);
83
+ function createQuestionToken(token) {
84
+ if (!token) return;
85
+ if (token === true) return questionToken;
86
+ return token;
87
+ }
88
+ function createIntersectionDeclaration({ nodes, withParentheses }) {
89
+ if (!nodes.length) return null;
90
+ if (nodes.length === 1) return nodes[0] || null;
91
+ const node = factory.createIntersectionTypeNode(nodes);
92
+ if (withParentheses) return factory.createParenthesizedType(node);
93
+ return node;
94
+ }
95
+ function createArrayDeclaration({ nodes }) {
96
+ if (!nodes.length) return factory.createTupleTypeNode([]);
97
+ if (nodes.length === 1) return factory.createArrayTypeNode(nodes.at(0));
98
+ return factory.createExpressionWithTypeArguments(factory.createIdentifier("Array"), [factory.createUnionTypeNode(nodes)]);
99
+ }
100
+ /**
101
+ * Minimum nodes length of 2
102
+ * @example `string | number`
103
+ */
104
+ function createUnionDeclaration({ nodes, withParentheses }) {
105
+ if (!nodes.length) return keywordTypeNodes.any;
106
+ if (nodes.length === 1) return nodes[0];
107
+ const node = factory.createUnionTypeNode(nodes);
108
+ if (withParentheses) return factory.createParenthesizedType(node);
109
+ return node;
110
+ }
111
+ function createPropertySignature({ readOnly, modifiers: modifiers$1 = [], name, questionToken: questionToken$1, type }) {
112
+ return factory.createPropertySignature([...modifiers$1, readOnly ? factory.createToken(typescript.default.SyntaxKind.ReadonlyKeyword) : void 0].filter(Boolean), propertyName(name), createQuestionToken(questionToken$1), type);
113
+ }
114
+ function createParameterSignature(name, { modifiers: modifiers$1, dotDotDotToken, questionToken: questionToken$1, type, initializer }) {
115
+ return factory.createParameterDeclaration(modifiers$1, dotDotDotToken, name, createQuestionToken(questionToken$1), type, initializer);
116
+ }
117
+ /**
118
+ * @link https://github.com/microsoft/TypeScript/issues/44151
119
+ */
120
+ function appendJSDocToNode({ node, comments }) {
121
+ const filteredComments = comments.filter(Boolean);
122
+ if (!filteredComments.length) return node;
123
+ const text = filteredComments.reduce((acc = "", comment = "") => {
124
+ return `${acc}\n * ${comment.replaceAll("*/", "*\\/")}`;
125
+ }, "*");
126
+ return typescript.default.addSyntheticLeadingComment({ ...node }, typescript.default.SyntaxKind.MultiLineCommentTrivia, `${text || "*"}\n`, true);
127
+ }
128
+ function createIndexSignature(type, { modifiers: modifiers$1, indexName = "key", indexType = factory.createKeywordTypeNode(typescript.default.SyntaxKind.StringKeyword) } = {}) {
129
+ return factory.createIndexSignature(modifiers$1, [createParameterSignature(indexName, { type: indexType })], type);
130
+ }
131
+ function createTypeAliasDeclaration({ modifiers: modifiers$1, name, typeParameters, type }) {
132
+ return factory.createTypeAliasDeclaration(modifiers$1, name, typeParameters, type);
133
+ }
134
+ function createInterfaceDeclaration({ modifiers: modifiers$1, name, typeParameters, members }) {
135
+ return factory.createInterfaceDeclaration(modifiers$1, name, typeParameters, void 0, members);
136
+ }
137
+ function createTypeDeclaration({ syntax, isExportable, comments, name, type }) {
138
+ if (syntax === "interface" && "members" in type) return appendJSDocToNode({
139
+ node: createInterfaceDeclaration({
140
+ members: type.members,
141
+ modifiers: isExportable ? [modifiers.export] : [],
142
+ name,
143
+ typeParameters: void 0
144
+ }),
145
+ comments
146
+ });
147
+ return appendJSDocToNode({
148
+ node: createTypeAliasDeclaration({
149
+ type,
150
+ modifiers: isExportable ? [modifiers.export] : [],
151
+ name,
152
+ typeParameters: void 0
153
+ }),
154
+ comments
155
+ });
156
+ }
157
+ function createEnumDeclaration({ type = "enum", name, typeName, enums }) {
158
+ if (type === "literal") return [void 0, factory.createTypeAliasDeclaration([factory.createToken(typescript.default.SyntaxKind.ExportKeyword)], factory.createIdentifier(typeName), void 0, factory.createUnionTypeNode(enums.map(([_key, value]) => {
159
+ if ((0, remeda.isNumber)(value)) return factory.createLiteralTypeNode(factory.createNumericLiteral(value?.toString()));
160
+ if (typeof value === "boolean") return factory.createLiteralTypeNode(value ? factory.createTrue() : factory.createFalse());
161
+ if (value) return factory.createLiteralTypeNode(factory.createStringLiteral(value.toString()));
162
+ }).filter(Boolean)))];
163
+ 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]) => {
164
+ let initializer = factory.createStringLiteral(value?.toString());
165
+ if (Number.parseInt(value.toString(), 10) === value && (0, remeda.isNumber)(Number.parseInt(value.toString(), 10))) initializer = factory.createNumericLiteral(value);
166
+ if (typeof value === "boolean") initializer = value ? factory.createTrue() : factory.createFalse();
167
+ if ((0, remeda.isNumber)(Number.parseInt(key.toString(), 10))) return factory.createEnumMember(factory.createStringLiteral(`${typeName}_${key}`), initializer);
168
+ if (key) return factory.createEnumMember(factory.createStringLiteral(`${key}`), initializer);
169
+ }).filter(Boolean))];
170
+ const identifierName = type === "asPascalConst" ? typeName : name;
171
+ 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]) => {
172
+ let initializer = factory.createStringLiteral(value?.toString());
173
+ if ((0, remeda.isNumber)(value)) if (value < 0) initializer = factory.createPrefixUnaryExpression(typescript.default.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)));
174
+ else initializer = factory.createNumericLiteral(value);
175
+ if (typeof value === "boolean") initializer = value ? factory.createTrue() : factory.createFalse();
176
+ if (key) return factory.createPropertyAssignment(factory.createStringLiteral(`${key}`), initializer);
177
+ }).filter(Boolean), true), factory.createTypeReferenceNode(factory.createIdentifier("const"), void 0)))], typescript.default.NodeFlags.Const)), factory.createTypeAliasDeclaration(type === "asPascalConst" ? [] : [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))))];
178
+ }
179
+ function createOmitDeclaration({ keys, type, nonNullable }) {
180
+ const node = nonNullable ? factory.createTypeReferenceNode(factory.createIdentifier("NonNullable"), [type]) : type;
181
+ if (Array.isArray(keys)) return factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [node, factory.createUnionTypeNode(keys.map((key) => {
182
+ return factory.createLiteralTypeNode(factory.createStringLiteral(key));
183
+ }))]);
184
+ return factory.createTypeReferenceNode(factory.createIdentifier("Omit"), [node, factory.createLiteralTypeNode(factory.createStringLiteral(keys))]);
185
+ }
186
+ const keywordTypeNodes = {
187
+ any: factory.createKeywordTypeNode(typescript.default.SyntaxKind.AnyKeyword),
188
+ unknown: factory.createKeywordTypeNode(typescript.default.SyntaxKind.UnknownKeyword),
189
+ void: factory.createKeywordTypeNode(typescript.default.SyntaxKind.VoidKeyword),
190
+ number: factory.createKeywordTypeNode(typescript.default.SyntaxKind.NumberKeyword),
191
+ integer: factory.createKeywordTypeNode(typescript.default.SyntaxKind.NumberKeyword),
192
+ object: factory.createKeywordTypeNode(typescript.default.SyntaxKind.ObjectKeyword),
193
+ string: factory.createKeywordTypeNode(typescript.default.SyntaxKind.StringKeyword),
194
+ boolean: factory.createKeywordTypeNode(typescript.default.SyntaxKind.BooleanKeyword),
195
+ undefined: factory.createKeywordTypeNode(typescript.default.SyntaxKind.UndefinedKeyword),
196
+ null: factory.createLiteralTypeNode(factory.createToken(typescript.default.SyntaxKind.NullKeyword))
197
+ };
198
+ const createTypeLiteralNode = factory.createTypeLiteralNode;
199
+ const createTypeReferenceNode = factory.createTypeReferenceNode;
200
+ const createNumericLiteral = factory.createNumericLiteral;
201
+ const createStringLiteral = factory.createStringLiteral;
202
+ const createArrayTypeNode = factory.createArrayTypeNode;
203
+ const createLiteralTypeNode = factory.createLiteralTypeNode;
204
+ const createNull = factory.createNull;
205
+ const createIdentifier = factory.createIdentifier;
206
+ const createOptionalTypeNode = factory.createOptionalTypeNode;
207
+ const createTupleTypeNode = factory.createTupleTypeNode;
208
+ const createRestTypeNode = factory.createRestTypeNode;
209
+ const createTrue = factory.createTrue;
210
+ const createFalse = factory.createFalse;
211
+
212
+ //#endregion
213
+ //#region src/parser.ts
214
+ const typeKeywordMapper = {
215
+ any: () => keywordTypeNodes.any,
216
+ unknown: () => keywordTypeNodes.unknown,
217
+ void: () => keywordTypeNodes.void,
218
+ number: () => keywordTypeNodes.number,
219
+ integer: () => keywordTypeNodes.number,
220
+ object: (nodes) => {
221
+ if (!nodes || !nodes.length) return keywordTypeNodes.object;
222
+ return createTypeLiteralNode(nodes);
223
+ },
224
+ string: () => keywordTypeNodes.string,
225
+ boolean: () => keywordTypeNodes.boolean,
226
+ undefined: () => keywordTypeNodes.undefined,
227
+ nullable: void 0,
228
+ null: () => keywordTypeNodes.null,
229
+ nullish: void 0,
230
+ array: (nodes) => {
231
+ if (!nodes) return;
232
+ return createArrayDeclaration({ nodes });
233
+ },
234
+ tuple: (nodes, rest, min, max) => {
235
+ if (!nodes) return;
236
+ if (max) {
237
+ nodes = nodes.slice(0, max);
238
+ if (nodes.length < max && rest) nodes = [...nodes, ...Array(max - nodes.length).fill(rest)];
239
+ }
240
+ if (min) nodes = nodes.map((node, index) => index >= min ? createOptionalTypeNode(node) : node);
241
+ if (typeof max === "undefined" && rest) nodes.push(createRestTypeNode(createArrayTypeNode(rest)));
242
+ return createTupleTypeNode(nodes);
243
+ },
244
+ enum: (name) => {
245
+ if (!name) return;
246
+ return createTypeReferenceNode(name, void 0);
247
+ },
248
+ union: (nodes) => {
249
+ if (!nodes) return;
250
+ return createUnionDeclaration({
251
+ withParentheses: true,
252
+ nodes
253
+ });
254
+ },
255
+ const: (name, format) => {
256
+ if (name === null || name === void 0 || name === "") return;
257
+ if (format === "boolean") {
258
+ if (name === true) return createLiteralTypeNode(createTrue());
259
+ return createLiteralTypeNode(createFalse());
260
+ }
261
+ if (format === "number" && typeof name === "number") return createLiteralTypeNode(createNumericLiteral(name));
262
+ return createLiteralTypeNode(createStringLiteral(name.toString()));
263
+ },
264
+ datetime: () => keywordTypeNodes.string,
265
+ date: (type = "string") => type === "string" ? keywordTypeNodes.string : createTypeReferenceNode(createIdentifier("Date")),
266
+ time: (type = "string") => type === "string" ? keywordTypeNodes.string : createTypeReferenceNode(createIdentifier("Date")),
267
+ uuid: () => keywordTypeNodes.string,
268
+ url: () => keywordTypeNodes.string,
269
+ default: void 0,
270
+ and: (nodes) => {
271
+ if (!nodes) return;
272
+ return createIntersectionDeclaration({
273
+ withParentheses: true,
274
+ nodes
275
+ });
276
+ },
277
+ describe: void 0,
278
+ min: void 0,
279
+ max: void 0,
280
+ optional: void 0,
281
+ matches: () => keywordTypeNodes.string,
282
+ email: () => keywordTypeNodes.string,
283
+ firstName: void 0,
284
+ lastName: void 0,
285
+ password: void 0,
286
+ phone: void 0,
287
+ readOnly: void 0,
288
+ writeOnly: void 0,
289
+ ref: (propertyName$1) => {
290
+ if (!propertyName$1) return;
291
+ return createTypeReferenceNode(propertyName$1, void 0);
292
+ },
293
+ blob: () => createTypeReferenceNode("Blob", []),
294
+ deprecated: void 0,
295
+ example: void 0,
296
+ schema: void 0,
297
+ catchall: void 0,
298
+ name: void 0,
299
+ interface: void 0
300
+ };
301
+ /**
302
+ * Recursively parses a schema tree node into a corresponding TypeScript AST node.
303
+ *
304
+ * Maps OpenAPI schema keywords to TypeScript AST nodes using the `typeKeywordMapper`, handling complex types such as unions, intersections, arrays, tuples (with optional/rest elements and length constraints), enums, constants, references, and objects with property modifiers and documentation annotations.
305
+ *
306
+ * @param current - The schema node to parse.
307
+ * @param siblings - Sibling schema nodes, used for context in certain mappings.
308
+ * @param name - The name of the schema or property being parsed.
309
+ * @param options - Parsing options controlling output style, property handling, and custom mappers.
310
+ * @returns The generated TypeScript AST node, or `undefined` if the schema keyword is not mapped.
311
+ */
312
+ function parse({ current, siblings, name }, options) {
313
+ const value = typeKeywordMapper[current.keyword];
314
+ if (!value) return;
315
+ if ((0, __kubb_plugin_oas.isKeyword)(current, __kubb_plugin_oas.schemaKeywords.union)) return typeKeywordMapper.union(current.args.map((schema) => parse({
316
+ parent: current,
317
+ name,
318
+ current: schema,
319
+ siblings
320
+ }, options)).filter(Boolean));
321
+ if ((0, __kubb_plugin_oas.isKeyword)(current, __kubb_plugin_oas.schemaKeywords.and)) return typeKeywordMapper.and(current.args.map((schema) => parse({
322
+ parent: current,
323
+ name,
324
+ current: schema,
325
+ siblings
326
+ }, options)).filter(Boolean));
327
+ if ((0, __kubb_plugin_oas.isKeyword)(current, __kubb_plugin_oas.schemaKeywords.array)) return typeKeywordMapper.array(current.args.items.map((schema) => parse({
328
+ parent: current,
329
+ name,
330
+ current: schema,
331
+ siblings
332
+ }, options)).filter(Boolean));
333
+ if ((0, __kubb_plugin_oas.isKeyword)(current, __kubb_plugin_oas.schemaKeywords.enum)) return typeKeywordMapper.enum(options.enumType === "asConst" ? `${current.args.typeName}Key` : current.args.typeName);
334
+ if ((0, __kubb_plugin_oas.isKeyword)(current, __kubb_plugin_oas.schemaKeywords.ref)) return typeKeywordMapper.ref(current.args.name);
335
+ if ((0, __kubb_plugin_oas.isKeyword)(current, __kubb_plugin_oas.schemaKeywords.blob)) return value();
336
+ if ((0, __kubb_plugin_oas.isKeyword)(current, __kubb_plugin_oas.schemaKeywords.tuple)) return typeKeywordMapper.tuple(current.args.items.map((schema) => parse({
337
+ parent: current,
338
+ name,
339
+ current: schema,
340
+ siblings
341
+ }, options)).filter(Boolean), current.args.rest && (parse({
342
+ parent: current,
343
+ name,
344
+ current: current.args.rest,
345
+ siblings
346
+ }, options) ?? void 0), current.args.min, current.args.max);
347
+ if ((0, __kubb_plugin_oas.isKeyword)(current, __kubb_plugin_oas.schemaKeywords.const)) return typeKeywordMapper.const(current.args.name, current.args.format);
348
+ if ((0, __kubb_plugin_oas.isKeyword)(current, __kubb_plugin_oas.schemaKeywords.object)) {
349
+ const properties = Object.entries(current.args?.properties || {}).filter((item) => {
350
+ const schemas = item[1];
351
+ return schemas && typeof schemas.map === "function";
352
+ }).map(([name$1, schemas]) => {
353
+ const mappedName = schemas.find((schema) => schema.keyword === __kubb_plugin_oas.schemaKeywords.name)?.args || name$1;
354
+ if (options.mapper?.[mappedName]) return options.mapper?.[mappedName];
355
+ const isNullish = schemas.some((schema) => schema.keyword === __kubb_plugin_oas.schemaKeywords.nullish);
356
+ const isNullable = schemas.some((schema) => schema.keyword === __kubb_plugin_oas.schemaKeywords.nullable);
357
+ const isOptional = schemas.some((schema) => schema.keyword === __kubb_plugin_oas.schemaKeywords.optional);
358
+ const isReadonly = schemas.some((schema) => schema.keyword === __kubb_plugin_oas.schemaKeywords.readOnly);
359
+ const describeSchema = schemas.find((schema) => schema.keyword === __kubb_plugin_oas.schemaKeywords.describe);
360
+ const deprecatedSchema = schemas.find((schema) => schema.keyword === __kubb_plugin_oas.schemaKeywords.deprecated);
361
+ const defaultSchema = schemas.find((schema) => schema.keyword === __kubb_plugin_oas.schemaKeywords.default);
362
+ const exampleSchema = schemas.find((schema) => schema.keyword === __kubb_plugin_oas.schemaKeywords.example);
363
+ const schemaSchema = schemas.find((schema) => schema.keyword === __kubb_plugin_oas.schemaKeywords.schema);
364
+ const minSchema = schemas.find((schema) => schema.keyword === __kubb_plugin_oas.schemaKeywords.min);
365
+ const maxSchema = schemas.find((schema) => schema.keyword === __kubb_plugin_oas.schemaKeywords.max);
366
+ const matchesSchema = schemas.find((schema) => schema.keyword === __kubb_plugin_oas.schemaKeywords.matches);
367
+ let type = schemas.map((schema) => parse({
368
+ parent: current,
369
+ name: name$1,
370
+ current: schema,
371
+ siblings: schemas
372
+ }, options)).filter(Boolean)[0];
373
+ if (isNullable) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] });
374
+ if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(options.optionalType)) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
375
+ if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(options.optionalType)) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
376
+ const propertyNode = createPropertySignature({
377
+ questionToken: isOptional || isNullish ? ["questionToken", "questionTokenAndUndefined"].includes(options.optionalType) : false,
378
+ name: mappedName,
379
+ type,
380
+ readOnly: isReadonly
381
+ });
382
+ return appendJSDocToNode({
383
+ node: propertyNode,
384
+ comments: [
385
+ describeSchema ? `@description ${__kubb_core_transformers.default.jsStringEscape(describeSchema.args)}` : void 0,
386
+ deprecatedSchema ? "@deprecated" : void 0,
387
+ minSchema ? `@minLength ${minSchema.args}` : void 0,
388
+ maxSchema ? `@maxLength ${maxSchema.args}` : void 0,
389
+ matchesSchema ? `@pattern ${matchesSchema.args}` : void 0,
390
+ defaultSchema ? `@default ${defaultSchema.args}` : void 0,
391
+ exampleSchema ? `@example ${exampleSchema.args}` : void 0,
392
+ schemaSchema?.args?.type || schemaSchema?.args?.format ? [`@type ${schemaSchema?.args?.type || "unknown"}${!isOptional ? "" : " | undefined"}`, schemaSchema?.args?.format].filter(Boolean).join(", ") : void 0
393
+ ].filter(Boolean)
394
+ });
395
+ });
396
+ let additionalProperties;
397
+ if (current.args?.additionalProperties?.length) {
398
+ additionalProperties = current.args.additionalProperties.map((schema) => parse({
399
+ parent: current,
400
+ name,
401
+ current: schema,
402
+ siblings
403
+ }, options)).filter(Boolean).at(0);
404
+ if (current.args?.additionalProperties.some((schema) => (0, __kubb_plugin_oas.isKeyword)(schema, __kubb_plugin_oas.schemaKeywords.nullable))) additionalProperties = createUnionDeclaration({ nodes: [additionalProperties, keywordTypeNodes.null] });
405
+ additionalProperties = createIndexSignature(additionalProperties);
406
+ }
407
+ return typeKeywordMapper.object([...properties, additionalProperties].filter(Boolean));
408
+ }
409
+ if ((0, __kubb_plugin_oas.isKeyword)(current, __kubb_plugin_oas.schemaKeywords.datetime)) return typeKeywordMapper.datetime();
410
+ if ((0, __kubb_plugin_oas.isKeyword)(current, __kubb_plugin_oas.schemaKeywords.date)) return typeKeywordMapper.date(current.args.type);
411
+ if ((0, __kubb_plugin_oas.isKeyword)(current, __kubb_plugin_oas.schemaKeywords.time)) return typeKeywordMapper.time(current.args.type);
412
+ if (current.keyword in typeKeywordMapper) return value();
413
+ }
414
+
415
+ //#endregion
416
+ //#region src/components/Type.tsx
417
+ function Type({ name, typedName, tree, keysToOmit, schema, optionalType, syntaxType, enumType, mapper, description }) {
418
+ const typeNodes = [];
419
+ if (!tree.length) return "";
420
+ const schemaFromTree = tree.find((item) => item.keyword === __kubb_plugin_oas.schemaKeywords.schema);
421
+ const enumSchemas = __kubb_plugin_oas.SchemaGenerator.deepSearch(tree, __kubb_plugin_oas.schemaKeywords.enum);
422
+ let type = tree.map((current, _index, siblings) => parse({
423
+ parent: void 0,
424
+ current,
425
+ siblings
426
+ }, {
427
+ name,
428
+ typedName,
429
+ description,
430
+ keysToOmit,
431
+ optionalType,
432
+ enumType,
433
+ mapper,
434
+ syntaxType
435
+ })).filter(Boolean).at(0) || typeKeywordMapper.undefined();
436
+ if (enumType === "asConst" && enumSchemas.length > 0) {
437
+ const isDirectEnum = schema.type === "array" && schema.items !== void 0;
438
+ const isEnumOnly = "enum" in schema && schema.enum;
439
+ if (isDirectEnum || isEnumOnly) {
440
+ const typeNameWithKey = `${enumSchemas[0].args.typeName}Key`;
441
+ type = createTypeReferenceNode(typeNameWithKey);
442
+ if (schema.type === "array") type = createArrayTypeNode(type);
443
+ }
444
+ }
445
+ if (schemaFromTree && (0, __kubb_plugin_oas.isKeyword)(schemaFromTree, __kubb_plugin_oas.schemaKeywords.schema)) {
446
+ const isNullish = tree.some((item) => item.keyword === __kubb_plugin_oas.schemaKeywords.nullish);
447
+ const isNullable = tree.some((item) => item.keyword === __kubb_plugin_oas.schemaKeywords.nullable);
448
+ const isOptional = tree.some((item) => item.keyword === __kubb_plugin_oas.schemaKeywords.optional);
449
+ if (isNullable) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.null] });
450
+ if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
451
+ if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) type = createUnionDeclaration({ nodes: [type, keywordTypeNodes.undefined] });
452
+ }
453
+ const useTypeGeneration = syntaxType === "type" || [syntaxKind.union].includes(type.kind) || !!keysToOmit?.length;
454
+ typeNodes.push(createTypeDeclaration({
455
+ name,
456
+ isExportable: true,
457
+ type: keysToOmit?.length ? createOmitDeclaration({
458
+ keys: keysToOmit,
459
+ type,
460
+ nonNullable: true
461
+ }) : type,
462
+ syntax: useTypeGeneration ? "type" : "interface",
463
+ comments: [
464
+ description ? `@description ${__kubb_core_transformers.default.jsStringEscape(description)}` : void 0,
465
+ schema.deprecated ? "@deprecated" : void 0,
466
+ schema.minLength ? `@minLength ${schema.minLength}` : void 0,
467
+ schema.maxLength ? `@maxLength ${schema.maxLength}` : void 0,
468
+ schema.pattern ? `@pattern ${schema.pattern}` : void 0,
469
+ schema.default ? `@default ${schema.default}` : void 0,
470
+ schema.example ? `@example ${schema.example}` : void 0
471
+ ]
472
+ }));
473
+ const enums = [...new Set(enumSchemas)].map((enumSchema) => {
474
+ const name$1 = enumType === "asPascalConst" ? __kubb_core_transformers.default.pascalCase(enumSchema.args.name) : __kubb_core_transformers.default.camelCase(enumSchema.args.name);
475
+ const typeName = enumType === "asConst" ? `${enumSchema.args.typeName}Key` : enumSchema.args.typeName;
476
+ const [nameNode, typeNode] = createEnumDeclaration({
477
+ name: name$1,
478
+ typeName,
479
+ enums: enumSchema.args.items.map((item) => item.value === void 0 ? void 0 : [__kubb_core_transformers.default.trimQuotes(item.name?.toString()), item.value]).filter(Boolean),
480
+ type: enumType
481
+ });
482
+ return {
483
+ nameNode,
484
+ typeNode,
485
+ name: name$1,
486
+ typeName
487
+ };
488
+ });
489
+ return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react_jsx_runtime.Fragment, { children: [enums.map(({ name: name$1, nameNode, typeName, typeNode }) => /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react_jsx_runtime.Fragment, { children: [nameNode && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
490
+ name: name$1,
491
+ isExportable: true,
492
+ isIndexable: true,
493
+ children: (0, __kubb_fabric_core_parsers_typescript.print)([nameNode])
494
+ }), /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
495
+ name: typeName,
496
+ isIndexable: true,
497
+ isExportable: [
498
+ "enum",
499
+ "asConst",
500
+ "constEnum",
501
+ "literal",
502
+ void 0
503
+ ].includes(enumType),
504
+ isTypeOnly: [
505
+ "asConst",
506
+ "literal",
507
+ void 0
508
+ ].includes(enumType),
509
+ children: (0, __kubb_fabric_core_parsers_typescript.print)([typeNode])
510
+ })] })), enums.every((item) => item.typeName !== name) && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Source, {
511
+ name: typedName,
512
+ isTypeOnly: true,
513
+ isExportable: true,
514
+ isIndexable: true,
515
+ children: (0, __kubb_fabric_core_parsers_typescript.print)(typeNodes)
516
+ })] });
517
+ }
518
+
519
+ //#endregion
520
+ Object.defineProperty(exports, 'OasType', {
521
+ enumerable: true,
522
+ get: function () {
523
+ return OasType;
524
+ }
525
+ });
526
+ Object.defineProperty(exports, 'Type', {
527
+ enumerable: true,
528
+ get: function () {
529
+ return Type;
530
+ }
531
+ });
532
+ Object.defineProperty(exports, '__toESM', {
533
+ enumerable: true,
534
+ get: function () {
535
+ return __toESM;
536
+ }
537
+ });
538
+ Object.defineProperty(exports, 'createIdentifier', {
539
+ enumerable: true,
540
+ get: function () {
541
+ return createIdentifier;
542
+ }
543
+ });
544
+ Object.defineProperty(exports, 'createPropertySignature', {
545
+ enumerable: true,
546
+ get: function () {
547
+ return createPropertySignature;
548
+ }
549
+ });
550
+ Object.defineProperty(exports, 'createTypeAliasDeclaration', {
551
+ enumerable: true,
552
+ get: function () {
553
+ return createTypeAliasDeclaration;
554
+ }
555
+ });
556
+ Object.defineProperty(exports, 'createTypeLiteralNode', {
557
+ enumerable: true,
558
+ get: function () {
559
+ return createTypeLiteralNode;
560
+ }
561
+ });
562
+ Object.defineProperty(exports, 'createTypeReferenceNode', {
563
+ enumerable: true,
564
+ get: function () {
565
+ return createTypeReferenceNode;
566
+ }
567
+ });
568
+ Object.defineProperty(exports, 'createUnionDeclaration', {
569
+ enumerable: true,
570
+ get: function () {
571
+ return createUnionDeclaration;
572
+ }
573
+ });
574
+ Object.defineProperty(exports, 'modifiers', {
575
+ enumerable: true,
576
+ get: function () {
577
+ return modifiers;
578
+ }
579
+ });
580
+ //# sourceMappingURL=components-Cf7RuPmU.cjs.map