@kubb/ast 5.0.0-beta.57 → 5.0.0-beta.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -7
- package/dist/casing-BE2R1RXg.cjs +88 -0
- package/dist/casing-BE2R1RXg.cjs.map +1 -0
- package/dist/chunk-CNktS9qV.js +17 -0
- package/dist/extractStringsFromNodes-WMYJ8nQL.d.ts +82 -0
- package/dist/factory-BmcGBdeg.cjs +1251 -0
- package/dist/factory-BmcGBdeg.cjs.map +1 -0
- package/dist/factory-Du7nEP4B.js +282 -0
- package/dist/factory-Du7nEP4B.js.map +1 -0
- package/dist/factory.cjs +28 -0
- package/dist/factory.d.ts +62 -0
- package/dist/factory.js +3 -0
- package/dist/{types-C5aVnRE1.d.ts → index-BzjwdK2M.d.ts} +94 -1146
- package/dist/index.cjs +220 -1481
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +96 -58
- package/dist/index.js +182 -1920
- package/dist/index.js.map +1 -1
- package/dist/operationParams-BZ07xDm0.d.ts +204 -0
- package/dist/response-DKxTr522.js +683 -0
- package/dist/response-DKxTr522.js.map +1 -0
- package/dist/types-olVl9v5p.d.ts +764 -0
- package/dist/types.d.ts +5 -2
- package/dist/utils-BCtRXfhI.cjs +275 -0
- package/dist/utils-BCtRXfhI.cjs.map +1 -0
- package/dist/utils-SdZU0F3H.js +1336 -0
- package/dist/utils-SdZU0F3H.js.map +1 -0
- package/dist/utils.cjs +129 -13
- package/dist/utils.d.ts +127 -76
- package/dist/utils.js +3 -2
- package/package.json +5 -1
- package/src/constants.ts +8 -14
- package/src/dedupe.ts +8 -0
- package/src/factory.ts +18 -1
- package/src/guards.ts +1 -1
- package/src/index.ts +7 -50
- package/src/node.ts +1 -1
- package/src/nodes/base.ts +0 -10
- package/src/nodes/code.ts +29 -47
- package/src/nodes/content.ts +2 -2
- package/src/nodes/file.ts +28 -23
- package/src/nodes/function.ts +2 -17
- package/src/nodes/index.ts +1 -1
- package/src/nodes/input.ts +20 -19
- package/src/nodes/operation.ts +1 -1
- package/src/nodes/parameter.ts +0 -3
- package/src/nodes/property.ts +0 -3
- package/src/nodes/requestBody.ts +3 -6
- package/src/nodes/schema.ts +3 -2
- package/src/printer.ts +4 -4
- package/src/registry.ts +31 -26
- package/src/signature.ts +3 -3
- package/src/transformers.ts +28 -1
- package/src/types.ts +2 -53
- package/src/utils/codegen.ts +104 -0
- package/src/utils/extractStringsFromNodes.ts +34 -0
- package/src/utils/fileMerge.ts +184 -0
- package/src/utils/index.ts +8 -296
- package/src/utils/operationParams.ts +353 -0
- package/src/utils/refs.ts +112 -0
- package/src/utils/schemaGraph.ts +169 -0
- package/src/utils/strings.ts +139 -0
- package/src/visitor.ts +43 -19
- package/dist/chunk-C0LytTxp.js +0 -8
- package/dist/utils-0p8ZO287.js +0 -570
- package/dist/utils-0p8ZO287.js.map +0 -1
- package/dist/utils-cdQ6Pzyi.cjs +0 -726
- package/dist/utils-cdQ6Pzyi.cjs.map +0 -1
- package/src/utils/ast.ts +0 -879
package/dist/utils-0p8ZO287.js
DELETED
|
@@ -1,570 +0,0 @@
|
|
|
1
|
-
import "./chunk-C0LytTxp.js";
|
|
2
|
-
//#region src/constants.ts
|
|
3
|
-
const visitorDepths = {
|
|
4
|
-
shallow: "shallow",
|
|
5
|
-
deep: "deep"
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Schema type discriminators used by all AST schema nodes.
|
|
9
|
-
*
|
|
10
|
-
* These values serve as stable discriminators across the AST (e.g., `schema.type === schemaTypes.object`).
|
|
11
|
-
* Grouped by category: primitives (`string`, `number`, `boolean`), structural types (`object`, `array`, `union`),
|
|
12
|
-
* and format-specific types (`date`, `uuid`, `email`). Use `isScalarPrimitive()` to check for scalar types.
|
|
13
|
-
*/
|
|
14
|
-
const schemaTypes = {
|
|
15
|
-
/**
|
|
16
|
-
* Text value.
|
|
17
|
-
*/
|
|
18
|
-
string: "string",
|
|
19
|
-
/**
|
|
20
|
-
* Floating-point number (`float`, `double`).
|
|
21
|
-
*/
|
|
22
|
-
number: "number",
|
|
23
|
-
/**
|
|
24
|
-
* Whole number (`int32`). Use `bigint` for `int64`.
|
|
25
|
-
*/
|
|
26
|
-
integer: "integer",
|
|
27
|
-
/**
|
|
28
|
-
* 64-bit integer (`int64`). Only used when `integerType` is set to `'bigint'`.
|
|
29
|
-
*/
|
|
30
|
-
bigint: "bigint",
|
|
31
|
-
/**
|
|
32
|
-
* Boolean value
|
|
33
|
-
*/
|
|
34
|
-
boolean: "boolean",
|
|
35
|
-
/**
|
|
36
|
-
* Explicit null value.
|
|
37
|
-
*/
|
|
38
|
-
null: "null",
|
|
39
|
-
/**
|
|
40
|
-
* Any value (no type restriction).
|
|
41
|
-
*/
|
|
42
|
-
any: "any",
|
|
43
|
-
/**
|
|
44
|
-
* Unknown value (must be narrowed before usage).
|
|
45
|
-
*/
|
|
46
|
-
unknown: "unknown",
|
|
47
|
-
/**
|
|
48
|
-
* No return value (`void`).
|
|
49
|
-
*/
|
|
50
|
-
void: "void",
|
|
51
|
-
/**
|
|
52
|
-
* Object with named properties.
|
|
53
|
-
*/
|
|
54
|
-
object: "object",
|
|
55
|
-
/**
|
|
56
|
-
* Sequential list of items.
|
|
57
|
-
*/
|
|
58
|
-
array: "array",
|
|
59
|
-
/**
|
|
60
|
-
* Fixed-length list with position-specific items.
|
|
61
|
-
*/
|
|
62
|
-
tuple: "tuple",
|
|
63
|
-
/**
|
|
64
|
-
* "One of" multiple schema members.
|
|
65
|
-
*/
|
|
66
|
-
union: "union",
|
|
67
|
-
/**
|
|
68
|
-
* "All of" multiple schema members.
|
|
69
|
-
*/
|
|
70
|
-
intersection: "intersection",
|
|
71
|
-
/**
|
|
72
|
-
* Enum schema.
|
|
73
|
-
*/
|
|
74
|
-
enum: "enum",
|
|
75
|
-
/**
|
|
76
|
-
* Reference to another schema.
|
|
77
|
-
*/
|
|
78
|
-
ref: "ref",
|
|
79
|
-
/**
|
|
80
|
-
* Calendar date (for example `2026-03-24`).
|
|
81
|
-
*/
|
|
82
|
-
date: "date",
|
|
83
|
-
/**
|
|
84
|
-
* Date-time value (for example `2026-03-24T09:00:00Z`).
|
|
85
|
-
*/
|
|
86
|
-
datetime: "datetime",
|
|
87
|
-
/**
|
|
88
|
-
* Time-only value (for example `09:00:00`).
|
|
89
|
-
*/
|
|
90
|
-
time: "time",
|
|
91
|
-
/**
|
|
92
|
-
* UUID value.
|
|
93
|
-
*/
|
|
94
|
-
uuid: "uuid",
|
|
95
|
-
/**
|
|
96
|
-
* Email address value.
|
|
97
|
-
*/
|
|
98
|
-
email: "email",
|
|
99
|
-
/**
|
|
100
|
-
* URL value.
|
|
101
|
-
*/
|
|
102
|
-
url: "url",
|
|
103
|
-
/**
|
|
104
|
-
* IPv4 address value.
|
|
105
|
-
*/
|
|
106
|
-
ipv4: "ipv4",
|
|
107
|
-
/**
|
|
108
|
-
* IPv6 address value.
|
|
109
|
-
*/
|
|
110
|
-
ipv6: "ipv6",
|
|
111
|
-
/**
|
|
112
|
-
* Binary/blob value.
|
|
113
|
-
*/
|
|
114
|
-
blob: "blob",
|
|
115
|
-
/**
|
|
116
|
-
* Impossible value (`never`).
|
|
117
|
-
*/
|
|
118
|
-
never: "never"
|
|
119
|
-
};
|
|
120
|
-
/**
|
|
121
|
-
* Scalar primitive schema types used for union simplification and type narrowing.
|
|
122
|
-
*
|
|
123
|
-
* Use `isScalarPrimitive()` to safely check whether a type is a scalar primitive.
|
|
124
|
-
*/
|
|
125
|
-
const SCALAR_PRIMITIVE_TYPES = new Set([
|
|
126
|
-
"string",
|
|
127
|
-
"number",
|
|
128
|
-
"integer",
|
|
129
|
-
"bigint",
|
|
130
|
-
"boolean"
|
|
131
|
-
]);
|
|
132
|
-
/**
|
|
133
|
-
* Type guard that returns `true` when `type` is a scalar primitive schema type.
|
|
134
|
-
*
|
|
135
|
-
* Use this to check if a schema type can be directly assigned without wrapping (e.g., `string | number | boolean`).
|
|
136
|
-
*/
|
|
137
|
-
function isScalarPrimitive(type) {
|
|
138
|
-
return SCALAR_PRIMITIVE_TYPES.has(type);
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* HTTP method identifiers used by operation nodes.
|
|
142
|
-
*
|
|
143
|
-
* Includes all standard HTTP methods (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS, TRACE).
|
|
144
|
-
*/
|
|
145
|
-
const httpMethods = {
|
|
146
|
-
get: "GET",
|
|
147
|
-
post: "POST",
|
|
148
|
-
put: "PUT",
|
|
149
|
-
patch: "PATCH",
|
|
150
|
-
delete: "DELETE",
|
|
151
|
-
head: "HEAD",
|
|
152
|
-
options: "OPTIONS",
|
|
153
|
-
trace: "TRACE"
|
|
154
|
-
};
|
|
155
|
-
/**
|
|
156
|
-
* One indentation level, derived from {@link INDENT_SIZE}.
|
|
157
|
-
*/
|
|
158
|
-
const INDENT = Array.from({ length: 2 }, () => " ").join("");
|
|
159
|
-
//#endregion
|
|
160
|
-
//#region ../../internals/utils/src/casing.ts
|
|
161
|
-
/**
|
|
162
|
-
* Shared implementation for camelCase and PascalCase conversion.
|
|
163
|
-
* Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
|
|
164
|
-
* and capitalizes each word according to `pascal`.
|
|
165
|
-
*
|
|
166
|
-
* When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
|
|
167
|
-
*/
|
|
168
|
-
function toCamelOrPascal(text, pascal) {
|
|
169
|
-
return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
|
|
170
|
-
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
171
|
-
return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
|
|
172
|
-
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Converts `text` to camelCase.
|
|
176
|
-
*
|
|
177
|
-
* @example Word boundaries
|
|
178
|
-
* `camelCase('hello-world') // 'helloWorld'`
|
|
179
|
-
*
|
|
180
|
-
* @example With a prefix
|
|
181
|
-
* `camelCase('tag', { prefix: 'create' }) // 'createTag'`
|
|
182
|
-
*/
|
|
183
|
-
function camelCase(text, { prefix = "", suffix = "" } = {}) {
|
|
184
|
-
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Converts `text` to PascalCase.
|
|
188
|
-
*
|
|
189
|
-
* @example Word boundaries
|
|
190
|
-
* `pascalCase('hello-world') // 'HelloWorld'`
|
|
191
|
-
*
|
|
192
|
-
* @example With a suffix
|
|
193
|
-
* `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'`
|
|
194
|
-
*/
|
|
195
|
-
function pascalCase(text, { prefix = "", suffix = "" } = {}) {
|
|
196
|
-
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
|
|
197
|
-
}
|
|
198
|
-
//#endregion
|
|
199
|
-
//#region ../../internals/utils/src/reserved.ts
|
|
200
|
-
/**
|
|
201
|
-
* JavaScript and Java reserved words.
|
|
202
|
-
* @link https://github.com/jonschlinkert/reserved/blob/master/index.js
|
|
203
|
-
*/
|
|
204
|
-
const reservedWords = new Set([
|
|
205
|
-
"abstract",
|
|
206
|
-
"arguments",
|
|
207
|
-
"boolean",
|
|
208
|
-
"break",
|
|
209
|
-
"byte",
|
|
210
|
-
"case",
|
|
211
|
-
"catch",
|
|
212
|
-
"char",
|
|
213
|
-
"class",
|
|
214
|
-
"const",
|
|
215
|
-
"continue",
|
|
216
|
-
"debugger",
|
|
217
|
-
"default",
|
|
218
|
-
"delete",
|
|
219
|
-
"do",
|
|
220
|
-
"double",
|
|
221
|
-
"else",
|
|
222
|
-
"enum",
|
|
223
|
-
"eval",
|
|
224
|
-
"export",
|
|
225
|
-
"extends",
|
|
226
|
-
"false",
|
|
227
|
-
"final",
|
|
228
|
-
"finally",
|
|
229
|
-
"float",
|
|
230
|
-
"for",
|
|
231
|
-
"function",
|
|
232
|
-
"goto",
|
|
233
|
-
"if",
|
|
234
|
-
"implements",
|
|
235
|
-
"import",
|
|
236
|
-
"in",
|
|
237
|
-
"instanceof",
|
|
238
|
-
"int",
|
|
239
|
-
"interface",
|
|
240
|
-
"let",
|
|
241
|
-
"long",
|
|
242
|
-
"native",
|
|
243
|
-
"new",
|
|
244
|
-
"null",
|
|
245
|
-
"package",
|
|
246
|
-
"private",
|
|
247
|
-
"protected",
|
|
248
|
-
"public",
|
|
249
|
-
"return",
|
|
250
|
-
"short",
|
|
251
|
-
"static",
|
|
252
|
-
"super",
|
|
253
|
-
"switch",
|
|
254
|
-
"synchronized",
|
|
255
|
-
"this",
|
|
256
|
-
"throw",
|
|
257
|
-
"throws",
|
|
258
|
-
"transient",
|
|
259
|
-
"true",
|
|
260
|
-
"try",
|
|
261
|
-
"typeof",
|
|
262
|
-
"var",
|
|
263
|
-
"void",
|
|
264
|
-
"volatile",
|
|
265
|
-
"while",
|
|
266
|
-
"with",
|
|
267
|
-
"yield",
|
|
268
|
-
"Array",
|
|
269
|
-
"Date",
|
|
270
|
-
"hasOwnProperty",
|
|
271
|
-
"Infinity",
|
|
272
|
-
"isFinite",
|
|
273
|
-
"isNaN",
|
|
274
|
-
"isPrototypeOf",
|
|
275
|
-
"length",
|
|
276
|
-
"Math",
|
|
277
|
-
"name",
|
|
278
|
-
"NaN",
|
|
279
|
-
"Number",
|
|
280
|
-
"Object",
|
|
281
|
-
"prototype",
|
|
282
|
-
"String",
|
|
283
|
-
"toString",
|
|
284
|
-
"undefined",
|
|
285
|
-
"valueOf"
|
|
286
|
-
]);
|
|
287
|
-
/**
|
|
288
|
-
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
289
|
-
*
|
|
290
|
-
* @example
|
|
291
|
-
* ```ts
|
|
292
|
-
* isValidVarName('status') // true
|
|
293
|
-
* isValidVarName('class') // false (reserved word)
|
|
294
|
-
* isValidVarName('42foo') // false (starts with digit)
|
|
295
|
-
* ```
|
|
296
|
-
*/
|
|
297
|
-
function isValidVarName(name) {
|
|
298
|
-
if (!name || reservedWords.has(name)) return false;
|
|
299
|
-
return isIdentifier(name);
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.
|
|
303
|
-
*
|
|
304
|
-
* Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys
|
|
305
|
-
* even though they are not valid variable names, so use this (not {@link isValidVarName}) when
|
|
306
|
-
* deciding whether an object key needs quoting.
|
|
307
|
-
*
|
|
308
|
-
* @example
|
|
309
|
-
* ```ts
|
|
310
|
-
* isIdentifier('name') // true
|
|
311
|
-
* isIdentifier('x-total')// false
|
|
312
|
-
* ```
|
|
313
|
-
*/
|
|
314
|
-
function isIdentifier(name) {
|
|
315
|
-
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
316
|
-
}
|
|
317
|
-
//#endregion
|
|
318
|
-
//#region ../../internals/utils/src/string.ts
|
|
319
|
-
/**
|
|
320
|
-
* Wraps a value in single quotes for emitting a single-quoted JavaScript string literal, escaping
|
|
321
|
-
* any backslash or single quote in the content.
|
|
322
|
-
*
|
|
323
|
-
* @example
|
|
324
|
-
* ```ts
|
|
325
|
-
* singleQuote('foo') // "'foo'"
|
|
326
|
-
* singleQuote("o'clock") // "'o\\'clock'"
|
|
327
|
-
* ```
|
|
328
|
-
*/
|
|
329
|
-
function singleQuote(value) {
|
|
330
|
-
if (value === void 0 || value === null) return "''";
|
|
331
|
-
return `'${String(value).replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'`;
|
|
332
|
-
}
|
|
333
|
-
//#endregion
|
|
334
|
-
//#region src/utils/index.ts
|
|
335
|
-
/**
|
|
336
|
-
* Strips a single matching pair of `"..."`, `'...'`, or `` `...` `` from both ends of `text`.
|
|
337
|
-
* Returns the string unchanged when no balanced quote pair is found.
|
|
338
|
-
*
|
|
339
|
-
* @example
|
|
340
|
-
* ```ts
|
|
341
|
-
* trimQuotes('"hello"') // 'hello'
|
|
342
|
-
* trimQuotes('hello') // 'hello'
|
|
343
|
-
* ```
|
|
344
|
-
*/
|
|
345
|
-
function trimQuotes(text) {
|
|
346
|
-
if (text.length >= 2) {
|
|
347
|
-
const first = text[0];
|
|
348
|
-
const last = text[text.length - 1];
|
|
349
|
-
if (first === "\"" && last === "\"" || first === "'" && last === "'" || first === "`" && last === "`") return text.slice(1, -1);
|
|
350
|
-
}
|
|
351
|
-
return text;
|
|
352
|
-
}
|
|
353
|
-
/**
|
|
354
|
-
* Serializes a primitive value to a single-quoted string literal, stripping any surrounding quote
|
|
355
|
-
* characters first. Escaping comes from `JSON.stringify`, then the quote style switches to single
|
|
356
|
-
* quotes so generated code matches the repo style without a formatter.
|
|
357
|
-
*
|
|
358
|
-
* @example
|
|
359
|
-
* ```ts
|
|
360
|
-
* stringify('hello') // "'hello'"
|
|
361
|
-
* stringify('"hello"') // "'hello'"
|
|
362
|
-
* ```
|
|
363
|
-
*/
|
|
364
|
-
function stringify(value) {
|
|
365
|
-
if (value === void 0 || value === null) return "''";
|
|
366
|
-
return `'${JSON.stringify(trimQuotes(value.toString())).slice(1, -1).replace(/\\"/g, "\"").replace(/'/g, "\\'")}'`;
|
|
367
|
-
}
|
|
368
|
-
/**
|
|
369
|
-
* Escapes characters that are not allowed inside JS string literals, covering quotes, backslashes,
|
|
370
|
-
* and the Unicode line terminators U+2028 and U+2029.
|
|
371
|
-
*
|
|
372
|
-
* @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
|
|
373
|
-
*
|
|
374
|
-
* @example
|
|
375
|
-
* ```ts
|
|
376
|
-
* jsStringEscape('say "hi"\nbye') // 'say \\"hi\\"\\nbye'
|
|
377
|
-
* ```
|
|
378
|
-
*/
|
|
379
|
-
function jsStringEscape(input) {
|
|
380
|
-
return `${input}`.replace(/["'\\\n\r\u2028\u2029]/g, (character) => {
|
|
381
|
-
switch (character) {
|
|
382
|
-
case "\"":
|
|
383
|
-
case "'":
|
|
384
|
-
case "\\": return `\\${character}`;
|
|
385
|
-
case "\n": return "\\n";
|
|
386
|
-
case "\r": return "\\r";
|
|
387
|
-
case "\u2028": return "\\u2028";
|
|
388
|
-
case "\u2029": return "\\u2029";
|
|
389
|
-
default: return "";
|
|
390
|
-
}
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
/**
|
|
394
|
-
* Converts a pattern string into a `new RegExp(...)` constructor call or a regex literal string.
|
|
395
|
-
* Inline flags expressed as a `^(?im)` prefix are extracted and applied to the resulting expression.
|
|
396
|
-
* Pass `null` as the second argument to emit a `/pattern/flags` literal instead.
|
|
397
|
-
*
|
|
398
|
-
* @example
|
|
399
|
-
* ```ts
|
|
400
|
-
* toRegExpString('^(?im)foo') // 'new RegExp("^foo", "im")'
|
|
401
|
-
* toRegExpString('^(?im)foo', null) // '/^foo/im'
|
|
402
|
-
* ```
|
|
403
|
-
*/
|
|
404
|
-
function toRegExpString(text, func = "RegExp") {
|
|
405
|
-
const raw = trimQuotes(text);
|
|
406
|
-
const match = raw.match(/^\^(\(\?([igmsuy]+)\))/i);
|
|
407
|
-
const replacementTarget = match?.[1] ?? "";
|
|
408
|
-
const matchedFlags = match?.[2];
|
|
409
|
-
const cleaned = raw.replace(/^\\?\//, "").replace(/\\?\/$/, "").replace(replacementTarget, "");
|
|
410
|
-
const { source, flags } = new RegExp(cleaned, matchedFlags);
|
|
411
|
-
if (func === null) return `/${source}/${flags}`;
|
|
412
|
-
return `new ${func}(${JSON.stringify(source)}${flags ? `, ${JSON.stringify(flags)}` : ""})`;
|
|
413
|
-
}
|
|
414
|
-
/**
|
|
415
|
-
* Renders a plain object as multi-line `key: value` source for embedding in generated code. Nested
|
|
416
|
-
* objects recurse with fixed indentation, so the result drops straight into an object literal
|
|
417
|
-
* without re-parsing.
|
|
418
|
-
*
|
|
419
|
-
* @example
|
|
420
|
-
* ```ts
|
|
421
|
-
* stringifyObject({ foo: 'bar', nested: { a: 1 } })
|
|
422
|
-
* // 'foo: bar,\nnested: {\n a: 1\n }'
|
|
423
|
-
* ```
|
|
424
|
-
*/
|
|
425
|
-
function stringifyObject(value) {
|
|
426
|
-
return Object.entries(value).map(([key, val]) => {
|
|
427
|
-
if (val !== null && typeof val === "object") return `${key}: {\n ${stringifyObject(val)}\n }`;
|
|
428
|
-
return `${key}: ${val}`;
|
|
429
|
-
}).filter(Boolean).join(",\n");
|
|
430
|
-
}
|
|
431
|
-
/**
|
|
432
|
-
* Renders a dotted path or string array as an optional-chaining accessor expression rooted at
|
|
433
|
-
* `accessor`. Returns `null` for an empty path.
|
|
434
|
-
*
|
|
435
|
-
* @example
|
|
436
|
-
* ```ts
|
|
437
|
-
* getNestedAccessor('pagination.next.id', 'lastPage')
|
|
438
|
-
* // "lastPage?.['pagination']?.['next']?.['id']"
|
|
439
|
-
* ```
|
|
440
|
-
*/
|
|
441
|
-
function getNestedAccessor(param, accessor) {
|
|
442
|
-
const parts = Array.isArray(param) ? param : param.split(".");
|
|
443
|
-
if (parts.length === 0 || parts.length === 1 && parts[0] === "") return null;
|
|
444
|
-
return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
|
|
445
|
-
}
|
|
446
|
-
/**
|
|
447
|
-
* Builds a JSDoc comment block from an array of lines, returning `fallback` when there are no
|
|
448
|
-
* comments so callers always get a usable string.
|
|
449
|
-
*
|
|
450
|
-
* @example
|
|
451
|
-
* ```ts
|
|
452
|
-
* buildJSDoc(['@type string', '@example hello'])
|
|
453
|
-
* // '/**\n * @type string\n * @example hello\n *\/\n '
|
|
454
|
-
* ```
|
|
455
|
-
*/
|
|
456
|
-
function buildJSDoc(comments, options = {}) {
|
|
457
|
-
const { indent = " * ", suffix = "\n ", fallback = " " } = options;
|
|
458
|
-
if (comments.length === 0) return fallback;
|
|
459
|
-
return `/**\n${comments.map((c) => `${indent}${c}`).join("\n")}\n */${suffix}`;
|
|
460
|
-
}
|
|
461
|
-
/**
|
|
462
|
-
* Indents every non-empty line of `text` by one indent level, leaving blank lines empty.
|
|
463
|
-
*/
|
|
464
|
-
function indentLines(text) {
|
|
465
|
-
if (!text) return "";
|
|
466
|
-
return text.split("\n").map((line) => line.trim() ? `${INDENT}${line}` : "").join("\n");
|
|
467
|
-
}
|
|
468
|
-
/**
|
|
469
|
-
* Renders an object key, quoting it with single quotes only when it is not a valid identifier.
|
|
470
|
-
* Reserved words and globals (`name`, `class`, …) are valid bare keys and stay unquoted.
|
|
471
|
-
*
|
|
472
|
-
* @example
|
|
473
|
-
* ```ts
|
|
474
|
-
* objectKey('name') // 'name'
|
|
475
|
-
* objectKey('x-total') // "'x-total'"
|
|
476
|
-
* ```
|
|
477
|
-
*/
|
|
478
|
-
function objectKey(name) {
|
|
479
|
-
return isIdentifier(name) ? name : singleQuote(name);
|
|
480
|
-
}
|
|
481
|
-
/**
|
|
482
|
-
* Assembles a multi-line object literal from already-rendered `entries`, indenting each entry one
|
|
483
|
-
* level and closing the brace at column zero. Nested objects built the same way indent cumulatively,
|
|
484
|
-
* so callers never re-parse the generated code. A trailing comma is added per entry to match the
|
|
485
|
-
* formatter's multi-line style.
|
|
486
|
-
*
|
|
487
|
-
* @example
|
|
488
|
-
* ```ts
|
|
489
|
-
* buildObject(['id: z.number()', 'name: z.string()'])
|
|
490
|
-
* // '{\n id: z.number(),\n name: z.string(),\n}'
|
|
491
|
-
* ```
|
|
492
|
-
*/
|
|
493
|
-
function buildObject(entries) {
|
|
494
|
-
if (entries.length === 0) return "{}";
|
|
495
|
-
return `{\n${entries.map((entry) => `${indentLines(entry)},`).join("\n")}\n}`;
|
|
496
|
-
}
|
|
497
|
-
/**
|
|
498
|
-
* Assembles a bracketed list (array by default) from already-rendered `items`. Keeps everything on
|
|
499
|
-
* one line when no item spans multiple lines, and otherwise puts each item on its own line, indented
|
|
500
|
-
* one level with a trailing comma and the closing bracket at column zero. Use it for `z.union([…])`,
|
|
501
|
-
* `z.array([…])`, and similar member lists so objects inside them nest correctly.
|
|
502
|
-
*
|
|
503
|
-
* @example
|
|
504
|
-
* ```ts
|
|
505
|
-
* buildList(['z.string()', 'z.number()'])
|
|
506
|
-
* // '[z.string(), z.number()]'
|
|
507
|
-
* ```
|
|
508
|
-
*/
|
|
509
|
-
function buildList(items, brackets = ["[", "]"]) {
|
|
510
|
-
const [open, close] = brackets;
|
|
511
|
-
if (items.length === 0) return `${open}${close}`;
|
|
512
|
-
if (!items.some((item) => item.includes("\n"))) return `${open}${items.join(", ")}${close}`;
|
|
513
|
-
return `${open}\n${items.map((item) => `${indentLines(item)},`).join("\n")}\n${close}`;
|
|
514
|
-
}
|
|
515
|
-
/**
|
|
516
|
-
* Returns the last path segment of a reference string.
|
|
517
|
-
*
|
|
518
|
-
* @example
|
|
519
|
-
* ```ts
|
|
520
|
-
* extractRefName('#/components/schemas/Pet') // 'Pet'
|
|
521
|
-
* ```
|
|
522
|
-
*/
|
|
523
|
-
function extractRefName(ref) {
|
|
524
|
-
return ref.split("/").at(-1) ?? ref;
|
|
525
|
-
}
|
|
526
|
-
/**
|
|
527
|
-
* Builds a PascalCase child schema name by joining a parent name and property name.
|
|
528
|
-
* Returns `null` when there is no parent to nest under.
|
|
529
|
-
*
|
|
530
|
-
* @example
|
|
531
|
-
* ```ts
|
|
532
|
-
* childName('Order', 'shipping_address') // 'OrderShippingAddress'
|
|
533
|
-
* childName(undefined, 'params') // null
|
|
534
|
-
* ```
|
|
535
|
-
*/
|
|
536
|
-
function childName(parentName, propName) {
|
|
537
|
-
return parentName ? pascalCase([parentName, propName].join(" ")) : null;
|
|
538
|
-
}
|
|
539
|
-
/**
|
|
540
|
-
* Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any
|
|
541
|
-
* empty parts.
|
|
542
|
-
*
|
|
543
|
-
* @example
|
|
544
|
-
* ```ts
|
|
545
|
-
* enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'
|
|
546
|
-
* ```
|
|
547
|
-
*/
|
|
548
|
-
function enumPropName(parentName, propName, enumSuffix) {
|
|
549
|
-
return pascalCase([
|
|
550
|
-
parentName,
|
|
551
|
-
propName,
|
|
552
|
-
enumSuffix
|
|
553
|
-
].filter(Boolean).join(" "));
|
|
554
|
-
}
|
|
555
|
-
/**
|
|
556
|
-
* Returns the discriminator key whose mapping value matches `ref`, or `null` when there is no match.
|
|
557
|
-
*
|
|
558
|
-
* @example
|
|
559
|
-
* ```ts
|
|
560
|
-
* findDiscriminator({ dog: '#/components/schemas/Dog' }, '#/components/schemas/Dog') // 'dog'
|
|
561
|
-
* ```
|
|
562
|
-
*/
|
|
563
|
-
function findDiscriminator(mapping, ref) {
|
|
564
|
-
if (!mapping || !ref) return null;
|
|
565
|
-
return Object.entries(mapping).find(([, value]) => value === ref)?.[0] ?? null;
|
|
566
|
-
}
|
|
567
|
-
//#endregion
|
|
568
|
-
export { httpMethods as _, enumPropName as a, visitorDepths as b, getNestedAccessor as c, stringify as d, stringifyObject as f, camelCase as g, isValidVarName as h, childName as i, jsStringEscape as l, trimQuotes as m, buildList as n, extractRefName as o, toRegExpString as p, buildObject as r, findDiscriminator as s, buildJSDoc as t, objectKey as u, isScalarPrimitive as v, schemaTypes as y };
|
|
569
|
-
|
|
570
|
-
//# sourceMappingURL=utils-0p8ZO287.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils-0p8ZO287.js","names":[],"sources":["../src/constants.ts","../../../internals/utils/src/casing.ts","../../../internals/utils/src/reserved.ts","../../../internals/utils/src/string.ts","../src/utils/index.ts"],"sourcesContent":["import type { HttpMethod } from './nodes/operation.ts'\nimport type { SchemaType } from './nodes/schema.ts'\n\n/**\n * Traversal depth for AST visitor utilities.\n *\n * - `'shallow'` visits only the immediate node, skipping children.\n * - `'deep'` recursively visits all descendant nodes.\n */\nexport type VisitorDepth = 'shallow' | 'deep'\n\nexport const visitorDepths = {\n shallow: 'shallow',\n deep: 'deep',\n} as const satisfies Record<VisitorDepth, VisitorDepth>\n\n/**\n * Schema type discriminators used by all AST schema nodes.\n *\n * These values serve as stable discriminators across the AST (e.g., `schema.type === schemaTypes.object`).\n * Grouped by category: primitives (`string`, `number`, `boolean`), structural types (`object`, `array`, `union`),\n * and format-specific types (`date`, `uuid`, `email`). Use `isScalarPrimitive()` to check for scalar types.\n */\nexport const schemaTypes = {\n /**\n * Text value.\n */\n string: 'string',\n /**\n * Floating-point number (`float`, `double`).\n */\n number: 'number',\n /**\n * Whole number (`int32`). Use `bigint` for `int64`.\n */\n integer: 'integer',\n /**\n * 64-bit integer (`int64`). Only used when `integerType` is set to `'bigint'`.\n */\n bigint: 'bigint',\n /**\n * Boolean value\n */\n boolean: 'boolean',\n /**\n * Explicit null value.\n */\n null: 'null',\n /**\n * Any value (no type restriction).\n */\n any: 'any',\n /**\n * Unknown value (must be narrowed before usage).\n */\n unknown: 'unknown',\n /**\n * No return value (`void`).\n */\n void: 'void',\n /**\n * Object with named properties.\n */\n object: 'object',\n /**\n * Sequential list of items.\n */\n array: 'array',\n /**\n * Fixed-length list with position-specific items.\n */\n tuple: 'tuple',\n /**\n * \"One of\" multiple schema members.\n */\n union: 'union',\n /**\n * \"All of\" multiple schema members.\n */\n intersection: 'intersection',\n /**\n * Enum schema.\n */\n enum: 'enum',\n /**\n * Reference to another schema.\n */\n ref: 'ref',\n /**\n * Calendar date (for example `2026-03-24`).\n */\n date: 'date',\n /**\n * Date-time value (for example `2026-03-24T09:00:00Z`).\n */\n datetime: 'datetime',\n /**\n * Time-only value (for example `09:00:00`).\n */\n time: 'time',\n /**\n * UUID value.\n */\n uuid: 'uuid',\n /**\n * Email address value.\n */\n email: 'email',\n /**\n * URL value.\n */\n url: 'url',\n /**\n * IPv4 address value.\n */\n ipv4: 'ipv4',\n /**\n * IPv6 address value.\n */\n ipv6: 'ipv6',\n /**\n * Binary/blob value.\n */\n blob: 'blob',\n /**\n * Impossible value (`never`).\n */\n never: 'never',\n} as const satisfies Record<SchemaType, SchemaType>\n\nexport type ScalarPrimitive = 'string' | 'number' | 'integer' | 'bigint' | 'boolean'\n\n/**\n * Scalar primitive schema types used for union simplification and type narrowing.\n *\n * Use `isScalarPrimitive()` to safely check whether a type is a scalar primitive.\n */\nconst SCALAR_PRIMITIVE_TYPES = new Set<ScalarPrimitive>(['string', 'number', 'integer', 'bigint', 'boolean'])\n\n/**\n * Type guard that returns `true` when `type` is a scalar primitive schema type.\n *\n * Use this to check if a schema type can be directly assigned without wrapping (e.g., `string | number | boolean`).\n */\nexport function isScalarPrimitive(type: string): type is ScalarPrimitive {\n return SCALAR_PRIMITIVE_TYPES.has(type as ScalarPrimitive)\n}\n\n/**\n * HTTP method identifiers used by operation nodes.\n *\n * Includes all standard HTTP methods (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS, TRACE).\n */\nexport const httpMethods = {\n get: 'GET',\n post: 'POST',\n put: 'PUT',\n patch: 'PATCH',\n delete: 'DELETE',\n head: 'HEAD',\n options: 'OPTIONS',\n trace: 'TRACE',\n} as const satisfies Record<Lowercase<HttpMethod>, HttpMethod>\n\n/**\n * Default concurrency limit for `walk()` traversal utility.\n *\n * Set to 30 to balance I/O-bound resolver parallelism against event loop pressure and memory usage during large spec traversals.\n * Use `WALK_CONCURRENCY` when calling `walk()` or override for different hardware constraints.\n *\n * @example\n * ```ts\n * import { walk, WALK_CONCURRENCY } from '@kubb/ast'\n *\n * walk(root, { concurrency: WALK_CONCURRENCY, root: () => {} })\n * ```\n */\nexport const WALK_CONCURRENCY = 30\n\n/**\n * Number of spaces in one indentation level when assembling multi-line code as strings.\n * Set to 2, 3, … to change the indent width used by `buildObject`/`buildList`.\n */\nconst INDENT_SIZE = 2\n\n/**\n * One indentation level, derived from {@link INDENT_SIZE}.\n */\nexport const INDENT = Array.from({ length: INDENT_SIZE }, () => ' ').join('')\n","type Options = {\n /**\n * Text prepended before casing is applied.\n */\n prefix?: string\n /**\n * Text appended before casing is applied.\n */\n suffix?: string\n}\n\n/**\n * Shared implementation for camelCase and PascalCase conversion.\n * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)\n * and capitalizes each word according to `pascal`.\n *\n * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.\n */\nfunction toCamelOrPascal(text: string, pascal: boolean): string {\n return text\n .trim()\n .replace(/([a-z\\d])([A-Z])/g, '$1 $2')\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')\n .replace(/(\\d)([a-z])/g, '$1 $2')\n .split(/[\\s\\-_./\\\\:]+/)\n .filter(Boolean)\n .map((word, i) => {\n if (word.length > 1 && word === word.toUpperCase()) return word\n const head = i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()\n return head + word.slice(1)\n })\n .join('')\n .replace(/[^a-zA-Z0-9]/g, '')\n}\n\n/**\n * Converts `text` to camelCase.\n *\n * @example Word boundaries\n * `camelCase('hello-world') // 'helloWorld'`\n *\n * @example With a prefix\n * `camelCase('tag', { prefix: 'create' }) // 'createTag'`\n */\nexport function camelCase(text: string, { prefix = '', suffix = '' }: Options = {}): string {\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false)\n}\n\n/**\n * Converts `text` to PascalCase.\n *\n * @example Word boundaries\n * `pascalCase('hello-world') // 'HelloWorld'`\n *\n * @example With a suffix\n * `pascalCase('tag', { suffix: 'schema' }) // 'TagSchema'`\n */\nexport function pascalCase(text: string, { prefix = '', suffix = '' }: Options = {}): string {\n return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true)\n}\n","/**\n * JavaScript and Java reserved words.\n * @link https://github.com/jonschlinkert/reserved/blob/master/index.js\n */\nconst reservedWords = new Set([\n 'abstract',\n 'arguments',\n 'boolean',\n 'break',\n 'byte',\n 'case',\n 'catch',\n 'char',\n 'class',\n 'const',\n 'continue',\n 'debugger',\n 'default',\n 'delete',\n 'do',\n 'double',\n 'else',\n 'enum',\n 'eval',\n 'export',\n 'extends',\n 'false',\n 'final',\n 'finally',\n 'float',\n 'for',\n 'function',\n 'goto',\n 'if',\n 'implements',\n 'import',\n 'in',\n 'instanceof',\n 'int',\n 'interface',\n 'let',\n 'long',\n 'native',\n 'new',\n 'null',\n 'package',\n 'private',\n 'protected',\n 'public',\n 'return',\n 'short',\n 'static',\n 'super',\n 'switch',\n 'synchronized',\n 'this',\n 'throw',\n 'throws',\n 'transient',\n 'true',\n 'try',\n 'typeof',\n 'var',\n 'void',\n 'volatile',\n 'while',\n 'with',\n 'yield',\n 'Array',\n 'Date',\n 'hasOwnProperty',\n 'Infinity',\n 'isFinite',\n 'isNaN',\n 'isPrototypeOf',\n 'length',\n 'Math',\n 'name',\n 'NaN',\n 'Number',\n 'Object',\n 'prototype',\n 'String',\n 'toString',\n 'undefined',\n 'valueOf',\n] as const)\n\n/**\n * Prefixes `word` with `_` when it is a reserved JavaScript/Java identifier or starts with a digit.\n *\n * @example\n * ```ts\n * transformReservedWord('class') // '_class'\n * transformReservedWord('42foo') // '_42foo'\n * transformReservedWord('status') // 'status'\n * ```\n */\nexport function transformReservedWord(word: string): string {\n const firstChar = word.charCodeAt(0)\n if (word && (reservedWords.has(word as 'valueOf') || (firstChar >= 48 && firstChar <= 57))) {\n return `_${word}`\n }\n return word\n}\n\n/**\n * Returns `true` when `name` is a syntactically valid JavaScript variable name.\n *\n * @example\n * ```ts\n * isValidVarName('status') // true\n * isValidVarName('class') // false (reserved word)\n * isValidVarName('42foo') // false (starts with digit)\n * ```\n */\nexport function isValidVarName(name: string): boolean {\n if (!name || reservedWords.has(name as 'valueOf')) {\n return false\n }\n return isIdentifier(name)\n}\n\n/**\n * Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.\n *\n * Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys\n * even though they are not valid variable names, so use this (not {@link isValidVarName}) when\n * deciding whether an object key needs quoting.\n *\n * @example\n * ```ts\n * isIdentifier('name') // true\n * isIdentifier('x-total')// false\n * ```\n */\nexport function isIdentifier(name: string): boolean {\n return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name)\n}\n","/**\n * Wraps a value in single quotes for emitting a single-quoted JavaScript string literal, escaping\n * any backslash or single quote in the content.\n *\n * @example\n * ```ts\n * singleQuote('foo') // \"'foo'\"\n * singleQuote(\"o'clock\") // \"'o\\\\'clock'\"\n * ```\n */\nexport function singleQuote(value: string | number | boolean | undefined | null): string {\n if (value === undefined || value === null) return \"''\"\n const escaped = String(value).replace(/\\\\/g, '\\\\\\\\').replace(/'/g, \"\\\\'\")\n\n return `'${escaped}'`\n}\n","import { isIdentifier, pascalCase, singleQuote } from '@internals/utils'\nimport { INDENT } from '../constants.ts'\n\nexport { isValidVarName } from '@internals/utils'\n\n/**\n * Strips a single matching pair of `\"...\"`, `'...'`, or `` `...` `` from both ends of `text`.\n * Returns the string unchanged when no balanced quote pair is found.\n *\n * @example\n * ```ts\n * trimQuotes('\"hello\"') // 'hello'\n * trimQuotes('hello') // 'hello'\n * ```\n */\nexport function trimQuotes(text: string): string {\n if (text.length >= 2) {\n const first = text[0]\n const last = text[text.length - 1]\n if ((first === '\"' && last === '\"') || (first === \"'\" && last === \"'\") || (first === '`' && last === '`')) {\n return text.slice(1, -1)\n }\n }\n return text\n}\n\n/**\n * Serializes a primitive value to a single-quoted string literal, stripping any surrounding quote\n * characters first. Escaping comes from `JSON.stringify`, then the quote style switches to single\n * quotes so generated code matches the repo style without a formatter.\n *\n * @example\n * ```ts\n * stringify('hello') // \"'hello'\"\n * stringify('\"hello\"') // \"'hello'\"\n * ```\n */\nexport function stringify(value: string | number | boolean | undefined): string {\n if (value === undefined || value === null) return \"''\"\n const json = JSON.stringify(trimQuotes(value.toString()))\n const inner = json.slice(1, -1).replace(/\\\\\"/g, '\"').replace(/'/g, \"\\\\'\")\n return `'${inner}'`\n}\n\n/**\n * Escapes characters that are not allowed inside JS string literals, covering quotes, backslashes,\n * and the Unicode line terminators U+2028 and U+2029.\n *\n * @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4\n *\n * @example\n * ```ts\n * jsStringEscape('say \"hi\"\\nbye') // 'say \\\\\"hi\\\\\"\\\\nbye'\n * ```\n */\nexport function jsStringEscape(input: unknown): string {\n return `${input}`.replace(/[\"'\\\\\\n\\r\\u2028\\u2029]/g, (character) => {\n switch (character) {\n case '\"':\n case \"'\":\n case '\\\\':\n return `\\\\${character}`\n case '\\n':\n return '\\\\n'\n case '\\r':\n return '\\\\r'\n case '\\u2028':\n return '\\\\u2028'\n case '\\u2029':\n return '\\\\u2029'\n default:\n return ''\n }\n })\n}\n\n/**\n * Converts a pattern string into a `new RegExp(...)` constructor call or a regex literal string.\n * Inline flags expressed as a `^(?im)` prefix are extracted and applied to the resulting expression.\n * Pass `null` as the second argument to emit a `/pattern/flags` literal instead.\n *\n * @example\n * ```ts\n * toRegExpString('^(?im)foo') // 'new RegExp(\"^foo\", \"im\")'\n * toRegExpString('^(?im)foo', null) // '/^foo/im'\n * ```\n */\nexport function toRegExpString(text: string, func: string | null = 'RegExp'): string {\n const raw = trimQuotes(text)\n\n const match = raw.match(/^\\^(\\(\\?([igmsuy]+)\\))/i)\n const replacementTarget = match?.[1] ?? ''\n const matchedFlags = match?.[2]\n const cleaned = raw\n .replace(/^\\\\?\\//, '')\n .replace(/\\\\?\\/$/, '')\n .replace(replacementTarget, '')\n\n const { source, flags } = new RegExp(cleaned, matchedFlags)\n\n if (func === null) return `/${source}/${flags}`\n\n return `new ${func}(${JSON.stringify(source)}${flags ? `, ${JSON.stringify(flags)}` : ''})`\n}\n\n/**\n * Renders a plain object as multi-line `key: value` source for embedding in generated code. Nested\n * objects recurse with fixed indentation, so the result drops straight into an object literal\n * without re-parsing.\n *\n * @example\n * ```ts\n * stringifyObject({ foo: 'bar', nested: { a: 1 } })\n * // 'foo: bar,\\nnested: {\\n a: 1\\n }'\n * ```\n */\nexport function stringifyObject(value: Record<string, unknown>): string {\n const items = Object.entries(value)\n .map(([key, val]) => {\n if (val !== null && typeof val === 'object') {\n return `${key}: {\\n ${stringifyObject(val as Record<string, unknown>)}\\n }`\n }\n return `${key}: ${val}`\n })\n .filter(Boolean)\n return items.join(',\\n')\n}\n\n/**\n * Renders a dotted path or string array as an optional-chaining accessor expression rooted at\n * `accessor`. Returns `null` for an empty path.\n *\n * @example\n * ```ts\n * getNestedAccessor('pagination.next.id', 'lastPage')\n * // \"lastPage?.['pagination']?.['next']?.['id']\"\n * ```\n */\nexport function getNestedAccessor(param: string | Array<string>, accessor: string): string | null {\n const parts = Array.isArray(param) ? param : param.split('.')\n if (parts.length === 0 || (parts.length === 1 && parts[0] === '')) return null\n return `${accessor}?.['${`${parts.join(\"']?.['\")}']`}`\n}\n\n/**\n * Builds a JSDoc comment block from an array of lines, returning `fallback` when there are no\n * comments so callers always get a usable string.\n *\n * @example\n * ```ts\n * buildJSDoc(['@type string', '@example hello'])\n * // '/**\\n * @type string\\n * @example hello\\n *\\/\\n '\n * ```\n */\nexport function buildJSDoc(\n comments: Array<string>,\n options: {\n /**\n * String used to indent each comment line.\n * @default ' * '\n */\n indent?: string\n /**\n * String appended after the closing tag.\n * @default '\\n '\n */\n suffix?: string\n /**\n * Returned as-is when `comments` is empty.\n * @default ' '\n */\n fallback?: string\n } = {},\n): string {\n const { indent = ' * ', suffix = '\\n ', fallback = ' ' } = options\n\n if (comments.length === 0) return fallback\n\n return `/**\\n${comments.map((c) => `${indent}${c}`).join('\\n')}\\n */${suffix}`\n}\n\n/**\n * Indents every non-empty line of `text` by one indent level, leaving blank lines empty.\n */\nfunction indentLines(text: string): string {\n if (!text) return ''\n return text\n .split('\\n')\n .map((line) => (line.trim() ? `${INDENT}${line}` : ''))\n .join('\\n')\n}\n\n/**\n * Renders an object key, quoting it with single quotes only when it is not a valid identifier.\n * Reserved words and globals (`name`, `class`, …) are valid bare keys and stay unquoted.\n *\n * @example\n * ```ts\n * objectKey('name') // 'name'\n * objectKey('x-total') // \"'x-total'\"\n * ```\n */\nexport function objectKey(name: string): string {\n return isIdentifier(name) ? name : singleQuote(name)\n}\n\n/**\n * Assembles a multi-line object literal from already-rendered `entries`, indenting each entry one\n * level and closing the brace at column zero. Nested objects built the same way indent cumulatively,\n * so callers never re-parse the generated code. A trailing comma is added per entry to match the\n * formatter's multi-line style.\n *\n * @example\n * ```ts\n * buildObject(['id: z.number()', 'name: z.string()'])\n * // '{\\n id: z.number(),\\n name: z.string(),\\n}'\n * ```\n */\nexport function buildObject(entries: Array<string>): string {\n if (entries.length === 0) return '{}'\n const body = entries.map((entry) => `${indentLines(entry)},`).join('\\n')\n\n return `{\\n${body}\\n}`\n}\n\n/**\n * Assembles a bracketed list (array by default) from already-rendered `items`. Keeps everything on\n * one line when no item spans multiple lines, and otherwise puts each item on its own line, indented\n * one level with a trailing comma and the closing bracket at column zero. Use it for `z.union([…])`,\n * `z.array([…])`, and similar member lists so objects inside them nest correctly.\n *\n * @example\n * ```ts\n * buildList(['z.string()', 'z.number()'])\n * // '[z.string(), z.number()]'\n * ```\n */\nexport function buildList(items: Array<string>, brackets: [open: string, close: string] = ['[', ']']): string {\n const [open, close] = brackets\n if (items.length === 0) return `${open}${close}`\n if (!items.some((item) => item.includes('\\n'))) return `${open}${items.join(', ')}${close}`\n const body = items.map((item) => `${indentLines(item)},`).join('\\n')\n\n return `${open}\\n${body}\\n${close}`\n}\n\n/**\n * Returns the last path segment of a reference string.\n *\n * @example\n * ```ts\n * extractRefName('#/components/schemas/Pet') // 'Pet'\n * ```\n */\nexport function extractRefName(ref: string): string {\n return ref.split('/').at(-1) ?? ref\n}\n\n/**\n * Builds a PascalCase child schema name by joining a parent name and property name.\n * Returns `null` when there is no parent to nest under.\n *\n * @example\n * ```ts\n * childName('Order', 'shipping_address') // 'OrderShippingAddress'\n * childName(undefined, 'params') // null\n * ```\n */\nexport function childName(parentName: string | null | undefined, propName: string): string | null {\n return parentName ? pascalCase([parentName, propName].join(' ')) : null\n}\n\n/**\n * Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any\n * empty parts.\n *\n * @example\n * ```ts\n * enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'\n * ```\n */\nexport function enumPropName(parentName: string | null | undefined, propName: string, enumSuffix: string): string {\n return pascalCase([parentName, propName, enumSuffix].filter(Boolean).join(' '))\n}\n\n/**\n * Returns the discriminator key whose mapping value matches `ref`, or `null` when there is no match.\n *\n * @example\n * ```ts\n * findDiscriminator({ dog: '#/components/schemas/Dog' }, '#/components/schemas/Dog') // 'dog'\n * ```\n */\nexport function findDiscriminator(mapping: Record<string, string> | undefined, ref: string | undefined): string | null {\n if (!mapping || !ref) return null\n return Object.entries(mapping).find(([, value]) => value === ref)?.[0] ?? null\n}\n"],"mappings":";;AAWA,MAAa,gBAAgB;CAC3B,SAAS;CACT,MAAM;AACR;;;;;;;;AASA,MAAa,cAAc;;;;CAIzB,QAAQ;;;;CAIR,QAAQ;;;;CAIR,SAAS;;;;CAIT,QAAQ;;;;CAIR,SAAS;;;;CAIT,MAAM;;;;CAIN,KAAK;;;;CAIL,SAAS;;;;CAIT,MAAM;;;;CAIN,QAAQ;;;;CAIR,OAAO;;;;CAIP,OAAO;;;;CAIP,OAAO;;;;CAIP,cAAc;;;;CAId,MAAM;;;;CAIN,KAAK;;;;CAIL,MAAM;;;;CAIN,UAAU;;;;CAIV,MAAM;;;;CAIN,MAAM;;;;CAIN,OAAO;;;;CAIP,KAAK;;;;CAIL,MAAM;;;;CAIN,MAAM;;;;CAIN,MAAM;;;;CAIN,OAAO;AACT;;;;;;AASA,MAAM,yBAAyB,IAAI,IAAqB;CAAC;CAAU;CAAU;CAAW;CAAU;AAAS,CAAC;;;;;;AAO5G,SAAgB,kBAAkB,MAAuC;CACvE,OAAO,uBAAuB,IAAI,IAAuB;AAC3D;;;;;;AAOA,MAAa,cAAc;CACzB,KAAK;CACL,MAAM;CACN,KAAK;CACL,OAAO;CACP,QAAQ;CACR,MAAM;CACN,SAAS;CACT,OAAO;AACT;;;;AA0B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