@kubb/ast 5.0.0-beta.43 → 5.0.0-beta.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +15 -467
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -18
- package/dist/index.js +3 -426
- package/dist/index.js.map +1 -1
- package/dist/{types-CC46hQUP.d.ts → types-lc8xMmUs.d.ts} +3 -39
- package/dist/types.d.ts +1 -1
- package/dist/utils-BIcKgbbc.js +626 -0
- package/dist/utils-BIcKgbbc.js.map +1 -0
- package/dist/utils-CMRZrT-w.cjs +794 -0
- package/dist/utils-CMRZrT-w.cjs.map +1 -0
- package/dist/utils.cjs +18 -0
- package/dist/utils.d.ts +205 -0
- package/dist/utils.js +2 -0
- package/package.json +5 -1
- package/src/factory.ts +1 -1
- package/src/index.ts +2 -6
- package/src/resolvers.ts +1 -15
- package/src/signature.ts +1 -1
- package/src/transformers.ts +1 -1
- package/src/types.ts +1 -1
- package/src/{utils.ts → utils/ast.ts} +6 -69
- package/src/utils/index.ts +295 -0
- package/src/refs.ts +0 -13
package/dist/index.cjs
CHANGED
|
@@ -1,251 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
-
key = keys[i];
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
-
get: ((k) => from[k]).bind(null, key),
|
|
14
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
-
value: mod,
|
|
21
|
-
enumerable: true
|
|
22
|
-
}) : target, mod));
|
|
23
|
-
//#endregion
|
|
2
|
+
const require_utils = require("./utils-CMRZrT-w.cjs");
|
|
24
3
|
let node_crypto = require("node:crypto");
|
|
25
4
|
let node_path = require("node:path");
|
|
26
|
-
node_path = __toESM(node_path, 1);
|
|
27
|
-
//#region src/constants.ts
|
|
28
|
-
const visitorDepths = {
|
|
29
|
-
shallow: "shallow",
|
|
30
|
-
deep: "deep"
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* Schema type discriminators used by all AST schema nodes.
|
|
34
|
-
*
|
|
35
|
-
* These values serve as stable discriminators across the AST (e.g., `schema.type === schemaTypes.object`).
|
|
36
|
-
* Grouped by category: primitives (`string`, `number`, `boolean`), structural types (`object`, `array`, `union`),
|
|
37
|
-
* and format-specific types (`date`, `uuid`, `email`). Use `isScalarPrimitive()` to check for scalar types.
|
|
38
|
-
*/
|
|
39
|
-
const schemaTypes = {
|
|
40
|
-
/**
|
|
41
|
-
* Text value.
|
|
42
|
-
*/
|
|
43
|
-
string: "string",
|
|
44
|
-
/**
|
|
45
|
-
* Floating-point number (`float`, `double`).
|
|
46
|
-
*/
|
|
47
|
-
number: "number",
|
|
48
|
-
/**
|
|
49
|
-
* Whole number (`int32`). Use `bigint` for `int64`.
|
|
50
|
-
*/
|
|
51
|
-
integer: "integer",
|
|
52
|
-
/**
|
|
53
|
-
* 64-bit integer (`int64`). Only used when `integerType` is set to `'bigint'`.
|
|
54
|
-
*/
|
|
55
|
-
bigint: "bigint",
|
|
56
|
-
/**
|
|
57
|
-
* Boolean value
|
|
58
|
-
*/
|
|
59
|
-
boolean: "boolean",
|
|
60
|
-
/**
|
|
61
|
-
* Explicit null value.
|
|
62
|
-
*/
|
|
63
|
-
null: "null",
|
|
64
|
-
/**
|
|
65
|
-
* Any value (no type restriction).
|
|
66
|
-
*/
|
|
67
|
-
any: "any",
|
|
68
|
-
/**
|
|
69
|
-
* Unknown value (must be narrowed before usage).
|
|
70
|
-
*/
|
|
71
|
-
unknown: "unknown",
|
|
72
|
-
/**
|
|
73
|
-
* No return value (`void`).
|
|
74
|
-
*/
|
|
75
|
-
void: "void",
|
|
76
|
-
/**
|
|
77
|
-
* Object with named properties.
|
|
78
|
-
*/
|
|
79
|
-
object: "object",
|
|
80
|
-
/**
|
|
81
|
-
* Sequential list of items.
|
|
82
|
-
*/
|
|
83
|
-
array: "array",
|
|
84
|
-
/**
|
|
85
|
-
* Fixed-length list with position-specific items.
|
|
86
|
-
*/
|
|
87
|
-
tuple: "tuple",
|
|
88
|
-
/**
|
|
89
|
-
* "One of" multiple schema members.
|
|
90
|
-
*/
|
|
91
|
-
union: "union",
|
|
92
|
-
/**
|
|
93
|
-
* "All of" multiple schema members.
|
|
94
|
-
*/
|
|
95
|
-
intersection: "intersection",
|
|
96
|
-
/**
|
|
97
|
-
* Enum schema.
|
|
98
|
-
*/
|
|
99
|
-
enum: "enum",
|
|
100
|
-
/**
|
|
101
|
-
* Reference to another schema.
|
|
102
|
-
*/
|
|
103
|
-
ref: "ref",
|
|
104
|
-
/**
|
|
105
|
-
* Calendar date (for example `2026-03-24`).
|
|
106
|
-
*/
|
|
107
|
-
date: "date",
|
|
108
|
-
/**
|
|
109
|
-
* Date-time value (for example `2026-03-24T09:00:00Z`).
|
|
110
|
-
*/
|
|
111
|
-
datetime: "datetime",
|
|
112
|
-
/**
|
|
113
|
-
* Time-only value (for example `09:00:00`).
|
|
114
|
-
*/
|
|
115
|
-
time: "time",
|
|
116
|
-
/**
|
|
117
|
-
* UUID value.
|
|
118
|
-
*/
|
|
119
|
-
uuid: "uuid",
|
|
120
|
-
/**
|
|
121
|
-
* Email address value.
|
|
122
|
-
*/
|
|
123
|
-
email: "email",
|
|
124
|
-
/**
|
|
125
|
-
* URL value.
|
|
126
|
-
*/
|
|
127
|
-
url: "url",
|
|
128
|
-
/**
|
|
129
|
-
* IPv4 address value.
|
|
130
|
-
*/
|
|
131
|
-
ipv4: "ipv4",
|
|
132
|
-
/**
|
|
133
|
-
* IPv6 address value.
|
|
134
|
-
*/
|
|
135
|
-
ipv6: "ipv6",
|
|
136
|
-
/**
|
|
137
|
-
* Binary/blob value.
|
|
138
|
-
*/
|
|
139
|
-
blob: "blob",
|
|
140
|
-
/**
|
|
141
|
-
* Impossible value (`never`).
|
|
142
|
-
*/
|
|
143
|
-
never: "never"
|
|
144
|
-
};
|
|
145
|
-
/**
|
|
146
|
-
* Scalar primitive schema types used for union simplification and type narrowing.
|
|
147
|
-
*
|
|
148
|
-
* Use `isScalarPrimitive()` to safely check whether a type is a scalar primitive.
|
|
149
|
-
*/
|
|
150
|
-
const SCALAR_PRIMITIVE_TYPES = new Set([
|
|
151
|
-
"string",
|
|
152
|
-
"number",
|
|
153
|
-
"integer",
|
|
154
|
-
"bigint",
|
|
155
|
-
"boolean"
|
|
156
|
-
]);
|
|
157
|
-
/**
|
|
158
|
-
* Type guard that returns `true` when `type` is a scalar primitive schema type.
|
|
159
|
-
*
|
|
160
|
-
* Use this to check if a schema type can be directly assigned without wrapping (e.g., `string | number | boolean`).
|
|
161
|
-
*/
|
|
162
|
-
function isScalarPrimitive(type) {
|
|
163
|
-
return SCALAR_PRIMITIVE_TYPES.has(type);
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* HTTP method identifiers used by operation nodes.
|
|
167
|
-
*
|
|
168
|
-
* Includes all standard HTTP methods (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS, TRACE).
|
|
169
|
-
*/
|
|
170
|
-
const httpMethods = {
|
|
171
|
-
get: "GET",
|
|
172
|
-
post: "POST",
|
|
173
|
-
put: "PUT",
|
|
174
|
-
patch: "PATCH",
|
|
175
|
-
delete: "DELETE",
|
|
176
|
-
head: "HEAD",
|
|
177
|
-
options: "OPTIONS",
|
|
178
|
-
trace: "TRACE"
|
|
179
|
-
};
|
|
180
|
-
/**
|
|
181
|
-
* One indentation level, derived from {@link INDENT_SIZE}.
|
|
182
|
-
*/
|
|
183
|
-
const INDENT = Array.from({ length: 2 }, () => " ").join("");
|
|
184
|
-
//#endregion
|
|
185
|
-
//#region ../../internals/utils/src/casing.ts
|
|
186
|
-
/**
|
|
187
|
-
* Shared implementation for camelCase and PascalCase conversion.
|
|
188
|
-
* Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
|
|
189
|
-
* and capitalizes each word according to `pascal`.
|
|
190
|
-
*
|
|
191
|
-
* When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
|
|
192
|
-
*/
|
|
193
|
-
function toCamelOrPascal(text, pascal) {
|
|
194
|
-
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) => {
|
|
195
|
-
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
196
|
-
if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1);
|
|
197
|
-
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
198
|
-
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Splits `text` on `.` and applies `transformPart` to each segment.
|
|
202
|
-
* The last segment receives `isLast = true`, all earlier segments receive `false`.
|
|
203
|
-
* Segments are joined with `/` to form a file path.
|
|
204
|
-
*
|
|
205
|
-
* Only splits on dots followed by a letter so that version numbers
|
|
206
|
-
* embedded in operationIds (e.g. `v2025.0`) are kept intact.
|
|
207
|
-
*
|
|
208
|
-
* Empty segments are filtered before joining. They arise when the text starts with
|
|
209
|
-
* a dot followed immediately by a letter (e.g. `..Schema` splits into `['..', 'Schema']`
|
|
210
|
-
* and `'..'` transforms to an empty string). Without this filter the join would produce
|
|
211
|
-
* a leading `/`, which `path.resolve` would interpret as an absolute path, allowing
|
|
212
|
-
* generated files to escape the configured output directory.
|
|
213
|
-
*/
|
|
214
|
-
function applyToFileParts(text, transformPart) {
|
|
215
|
-
const parts = text.split(/\.(?=[a-zA-Z])/);
|
|
216
|
-
return parts.map((part, i) => transformPart(part, i === parts.length - 1)).filter(Boolean).join("/");
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Converts `text` to camelCase.
|
|
220
|
-
* When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
|
|
221
|
-
*
|
|
222
|
-
* @example
|
|
223
|
-
* camelCase('hello-world') // 'helloWorld'
|
|
224
|
-
* camelCase('pet.petId', { isFile: true }) // 'pet/petId'
|
|
225
|
-
*/
|
|
226
|
-
function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
227
|
-
if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
|
|
228
|
-
prefix,
|
|
229
|
-
suffix
|
|
230
|
-
} : {}));
|
|
231
|
-
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Converts `text` to PascalCase.
|
|
235
|
-
* When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.
|
|
236
|
-
*
|
|
237
|
-
* @example
|
|
238
|
-
* pascalCase('hello-world') // 'HelloWorld'
|
|
239
|
-
* pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'
|
|
240
|
-
*/
|
|
241
|
-
function pascalCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
242
|
-
if (isFile) return applyToFileParts(text, (part, isLast) => isLast ? pascalCase(part, {
|
|
243
|
-
prefix,
|
|
244
|
-
suffix
|
|
245
|
-
}) : camelCase(part));
|
|
246
|
-
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
|
|
247
|
-
}
|
|
248
|
-
//#endregion
|
|
5
|
+
node_path = require_utils.__toESM(node_path, 1);
|
|
249
6
|
//#region ../../internals/utils/src/promise.ts
|
|
250
7
|
/**
|
|
251
8
|
* Wraps `factory` with a keyed cache backed by the provided store.
|
|
@@ -286,126 +43,6 @@ function memoize(store, factory) {
|
|
|
286
43
|
};
|
|
287
44
|
}
|
|
288
45
|
//#endregion
|
|
289
|
-
//#region ../../internals/utils/src/reserved.ts
|
|
290
|
-
/**
|
|
291
|
-
* JavaScript and Java reserved words.
|
|
292
|
-
* @link https://github.com/jonschlinkert/reserved/blob/master/index.js
|
|
293
|
-
*/
|
|
294
|
-
const reservedWords = new Set([
|
|
295
|
-
"abstract",
|
|
296
|
-
"arguments",
|
|
297
|
-
"boolean",
|
|
298
|
-
"break",
|
|
299
|
-
"byte",
|
|
300
|
-
"case",
|
|
301
|
-
"catch",
|
|
302
|
-
"char",
|
|
303
|
-
"class",
|
|
304
|
-
"const",
|
|
305
|
-
"continue",
|
|
306
|
-
"debugger",
|
|
307
|
-
"default",
|
|
308
|
-
"delete",
|
|
309
|
-
"do",
|
|
310
|
-
"double",
|
|
311
|
-
"else",
|
|
312
|
-
"enum",
|
|
313
|
-
"eval",
|
|
314
|
-
"export",
|
|
315
|
-
"extends",
|
|
316
|
-
"false",
|
|
317
|
-
"final",
|
|
318
|
-
"finally",
|
|
319
|
-
"float",
|
|
320
|
-
"for",
|
|
321
|
-
"function",
|
|
322
|
-
"goto",
|
|
323
|
-
"if",
|
|
324
|
-
"implements",
|
|
325
|
-
"import",
|
|
326
|
-
"in",
|
|
327
|
-
"instanceof",
|
|
328
|
-
"int",
|
|
329
|
-
"interface",
|
|
330
|
-
"let",
|
|
331
|
-
"long",
|
|
332
|
-
"native",
|
|
333
|
-
"new",
|
|
334
|
-
"null",
|
|
335
|
-
"package",
|
|
336
|
-
"private",
|
|
337
|
-
"protected",
|
|
338
|
-
"public",
|
|
339
|
-
"return",
|
|
340
|
-
"short",
|
|
341
|
-
"static",
|
|
342
|
-
"super",
|
|
343
|
-
"switch",
|
|
344
|
-
"synchronized",
|
|
345
|
-
"this",
|
|
346
|
-
"throw",
|
|
347
|
-
"throws",
|
|
348
|
-
"transient",
|
|
349
|
-
"true",
|
|
350
|
-
"try",
|
|
351
|
-
"typeof",
|
|
352
|
-
"var",
|
|
353
|
-
"void",
|
|
354
|
-
"volatile",
|
|
355
|
-
"while",
|
|
356
|
-
"with",
|
|
357
|
-
"yield",
|
|
358
|
-
"Array",
|
|
359
|
-
"Date",
|
|
360
|
-
"hasOwnProperty",
|
|
361
|
-
"Infinity",
|
|
362
|
-
"isFinite",
|
|
363
|
-
"isNaN",
|
|
364
|
-
"isPrototypeOf",
|
|
365
|
-
"length",
|
|
366
|
-
"Math",
|
|
367
|
-
"name",
|
|
368
|
-
"NaN",
|
|
369
|
-
"Number",
|
|
370
|
-
"Object",
|
|
371
|
-
"prototype",
|
|
372
|
-
"String",
|
|
373
|
-
"toString",
|
|
374
|
-
"undefined",
|
|
375
|
-
"valueOf"
|
|
376
|
-
]);
|
|
377
|
-
/**
|
|
378
|
-
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
379
|
-
*
|
|
380
|
-
* @example
|
|
381
|
-
* ```ts
|
|
382
|
-
* isValidVarName('status') // true
|
|
383
|
-
* isValidVarName('class') // false (reserved word)
|
|
384
|
-
* isValidVarName('42foo') // false (starts with digit)
|
|
385
|
-
* ```
|
|
386
|
-
*/
|
|
387
|
-
function isValidVarName(name) {
|
|
388
|
-
if (!name || reservedWords.has(name)) return false;
|
|
389
|
-
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
390
|
-
}
|
|
391
|
-
//#endregion
|
|
392
|
-
//#region ../../internals/utils/src/string.ts
|
|
393
|
-
/**
|
|
394
|
-
* Strips the file extension from a path or file name.
|
|
395
|
-
* Only removes the last `.ext` segment when the dot is not part of a directory name.
|
|
396
|
-
*
|
|
397
|
-
* @example
|
|
398
|
-
* trimExtName('petStore.ts') // 'petStore'
|
|
399
|
-
* trimExtName('/src/models/pet.ts') // '/src/models/pet'
|
|
400
|
-
* trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'
|
|
401
|
-
* trimExtName('noExtension') // 'noExtension'
|
|
402
|
-
*/
|
|
403
|
-
function trimExtName(text) {
|
|
404
|
-
const dotIndex = text.lastIndexOf(".");
|
|
405
|
-
if (dotIndex > 0 && !text.includes("/", dotIndex)) return text.slice(0, dotIndex);
|
|
406
|
-
return text;
|
|
407
|
-
}
|
|
408
|
-
//#endregion
|
|
409
46
|
//#region src/guards.ts
|
|
410
47
|
/**
|
|
411
48
|
* Narrows a `SchemaNode` to the variant that matches `type`.
|
|
@@ -480,21 +117,6 @@ function isHttpOperationNode(node) {
|
|
|
480
117
|
*/
|
|
481
118
|
const isSchemaNode = isKind("Schema");
|
|
482
119
|
//#endregion
|
|
483
|
-
//#region src/refs.ts
|
|
484
|
-
/**
|
|
485
|
-
* Returns the last path segment of a reference string.
|
|
486
|
-
*
|
|
487
|
-
* Example: `#/components/schemas/Pet` becomes `Pet`.
|
|
488
|
-
*
|
|
489
|
-
* @example
|
|
490
|
-
* ```ts
|
|
491
|
-
* extractRefName('#/components/schemas/Pet') // 'Pet'
|
|
492
|
-
* ```
|
|
493
|
-
*/
|
|
494
|
-
function extractRefName(ref) {
|
|
495
|
-
return ref.split("/").at(-1) ?? ref;
|
|
496
|
-
}
|
|
497
|
-
//#endregion
|
|
498
120
|
//#region src/visitor.ts
|
|
499
121
|
/**
|
|
500
122
|
* Creates a small async concurrency limiter.
|
|
@@ -631,7 +253,7 @@ function applyVisitor(node, visitor, parent) {
|
|
|
631
253
|
* ```
|
|
632
254
|
*/
|
|
633
255
|
async function walk(node, options) {
|
|
634
|
-
return _walk(node, options, (options.depth ?? visitorDepths.deep) === visitorDepths.deep, createLimit(options.concurrency ?? 30), void 0);
|
|
256
|
+
return _walk(node, options, (options.depth ?? require_utils.visitorDepths.deep) === require_utils.visitorDepths.deep, createLimit(options.concurrency ?? 30), void 0);
|
|
635
257
|
}
|
|
636
258
|
async function _walk(node, visitor, recurse, limit, parent) {
|
|
637
259
|
await limit(() => applyVisitor(node, visitor, parent));
|
|
@@ -641,7 +263,7 @@ async function _walk(node, visitor, recurse, limit, parent) {
|
|
|
641
263
|
}
|
|
642
264
|
function transform(node, options) {
|
|
643
265
|
const { depth, parent, ...visitor } = options;
|
|
644
|
-
const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep;
|
|
266
|
+
const recurse = (depth ?? require_utils.visitorDepths.deep) === require_utils.visitorDepths.deep;
|
|
645
267
|
const rebuilt = transformChildren(applyVisitor(node, visitor, parent) ?? node, options, recurse);
|
|
646
268
|
if (rebuilt === node) return node;
|
|
647
269
|
const finalize = nodeFinalizers[rebuilt.kind];
|
|
@@ -711,7 +333,7 @@ function transformChildren(node, options, recurse) {
|
|
|
711
333
|
*/
|
|
712
334
|
function* collectLazy(node, options) {
|
|
713
335
|
const { depth, parent, ...visitor } = options;
|
|
714
|
-
const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep;
|
|
336
|
+
const recurse = (depth ?? require_utils.visitorDepths.deep) === require_utils.visitorDepths.deep;
|
|
715
337
|
const v = applyVisitor(node, visitor, parent);
|
|
716
338
|
if (v != null) yield v;
|
|
717
339
|
for (const child of getChildren(node, recurse)) yield* collectLazy(child, {
|
|
@@ -736,7 +358,7 @@ function collect(node, options) {
|
|
|
736
358
|
return Array.from(collectLazy(node, options));
|
|
737
359
|
}
|
|
738
360
|
//#endregion
|
|
739
|
-
//#region src/utils.ts
|
|
361
|
+
//#region src/utils/ast.ts
|
|
740
362
|
const plainStringTypes = new Set([
|
|
741
363
|
"string",
|
|
742
364
|
"uuid",
|
|
@@ -788,7 +410,7 @@ function isStringType(node) {
|
|
|
788
410
|
* The input array is not mutated. When `casing` is not set, the original array is returned unchanged.
|
|
789
411
|
*/
|
|
790
412
|
const caseParamsMemo = memoize(/* @__PURE__ */ new WeakMap(), (params) => memoize(/* @__PURE__ */ new Map(), (casing) => params.map((param) => {
|
|
791
|
-
const transformed = casing === "camelcase" || !isValidVarName(param.name) ? camelCase(param.name) : param.name;
|
|
413
|
+
const transformed = casing === "camelcase" || !require_utils.isValidVarName(param.name) ? require_utils.camelCase(param.name) : param.name;
|
|
792
414
|
return {
|
|
793
415
|
...param,
|
|
794
416
|
name: transformed
|
|
@@ -1207,59 +829,6 @@ function extractStringsFromNodes(nodes) {
|
|
|
1207
829
|
}).filter(Boolean).join("\n");
|
|
1208
830
|
}
|
|
1209
831
|
/**
|
|
1210
|
-
* Indents every non-empty line of `text` by one indent level, leaving blank lines empty.
|
|
1211
|
-
*/
|
|
1212
|
-
function indentLines(text) {
|
|
1213
|
-
if (!text) return "";
|
|
1214
|
-
return text.split("\n").map((line) => line.trim() ? `${INDENT}${line}` : "").join("\n");
|
|
1215
|
-
}
|
|
1216
|
-
/**
|
|
1217
|
-
* Renders an object key, quoting it only when it is not a valid variable name.
|
|
1218
|
-
*
|
|
1219
|
-
* @example
|
|
1220
|
-
* ```ts
|
|
1221
|
-
* objectKey('id') // 'id'
|
|
1222
|
-
* objectKey('x-total') // '"x-total"'
|
|
1223
|
-
* ```
|
|
1224
|
-
*/
|
|
1225
|
-
function objectKey(name) {
|
|
1226
|
-
return isValidVarName(name) ? name : JSON.stringify(name);
|
|
1227
|
-
}
|
|
1228
|
-
/**
|
|
1229
|
-
* Assembles a multi-line object literal from already-rendered `entries`, indenting each entry one
|
|
1230
|
-
* level and closing the brace at column zero. Nested objects built the same way indent cumulatively,
|
|
1231
|
-
* so callers never re-parse the generated code. A trailing comma is added per entry to match the
|
|
1232
|
-
* formatter's multi-line style.
|
|
1233
|
-
*
|
|
1234
|
-
* @example
|
|
1235
|
-
* ```ts
|
|
1236
|
-
* buildObject(['id: z.number()', 'name: z.string()'])
|
|
1237
|
-
* // '{\n id: z.number(),\n name: z.string(),\n}'
|
|
1238
|
-
* ```
|
|
1239
|
-
*/
|
|
1240
|
-
function buildObject(entries) {
|
|
1241
|
-
if (entries.length === 0) return "{}";
|
|
1242
|
-
return `{\n${entries.map((entry) => `${indentLines(entry)},`).join("\n")}\n}`;
|
|
1243
|
-
}
|
|
1244
|
-
/**
|
|
1245
|
-
* Assembles a bracketed list (array by default) from already-rendered `items`. Keeps everything on
|
|
1246
|
-
* one line when no item spans multiple lines, and otherwise puts each item on its own line, indented
|
|
1247
|
-
* one level with a trailing comma and the closing bracket at column zero. Use it for `z.union([…])`,
|
|
1248
|
-
* `z.array([…])`, and similar member lists so objects inside them nest correctly.
|
|
1249
|
-
*
|
|
1250
|
-
* @example
|
|
1251
|
-
* ```ts
|
|
1252
|
-
* buildList(['z.string()', 'z.number()'])
|
|
1253
|
-
* // '[z.string(), z.number()]'
|
|
1254
|
-
* ```
|
|
1255
|
-
*/
|
|
1256
|
-
function buildList(items, brackets = ["[", "]"]) {
|
|
1257
|
-
const [open, close] = brackets;
|
|
1258
|
-
if (items.length === 0) return `${open}${close}`;
|
|
1259
|
-
if (!items.some((item) => item.includes("\n"))) return `${open}${items.join(", ")}${close}`;
|
|
1260
|
-
return `${open}\n${items.map((item) => `${indentLines(item)},`).join("\n")}\n${close}`;
|
|
1261
|
-
}
|
|
1262
|
-
/**
|
|
1263
832
|
* Resolves the schema name of a ref node, falling back through `ref` → `name` → nested `schema.name`.
|
|
1264
833
|
*
|
|
1265
834
|
* Returns `null` for non-ref nodes or when no name can be resolved. Use this to get a schema's
|
|
@@ -1273,7 +842,7 @@ function buildList(items, brackets = ["[", "]"]) {
|
|
|
1273
842
|
*/
|
|
1274
843
|
function resolveRefName(node) {
|
|
1275
844
|
if (!node || node.type !== "ref") return null;
|
|
1276
|
-
if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null;
|
|
845
|
+
if (node.ref) return require_utils.extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null;
|
|
1277
846
|
return node.name ?? node.schema?.name ?? null;
|
|
1278
847
|
}
|
|
1279
848
|
/**
|
|
@@ -1902,7 +1471,7 @@ function createFile(input) {
|
|
|
1902
1471
|
kind: "File",
|
|
1903
1472
|
...input,
|
|
1904
1473
|
id: (0, node_crypto.hash)("sha256", input.path, "hex"),
|
|
1905
|
-
name: trimExtName(input.baseName),
|
|
1474
|
+
name: require_utils.trimExtName(input.baseName),
|
|
1906
1475
|
extname,
|
|
1907
1476
|
imports: resolvedImports,
|
|
1908
1477
|
exports: resolvedExports,
|
|
@@ -2106,7 +1675,7 @@ function flagsDescriptor(node) {
|
|
|
2106
1675
|
return `${node.primitive ?? ""};${node.format ?? ""};${node.nullable ? 1 : 0}`;
|
|
2107
1676
|
}
|
|
2108
1677
|
function refTargetName(node) {
|
|
2109
|
-
if (node.ref) return extractRefName(node.ref);
|
|
1678
|
+
if (node.ref) return require_utils.extractRefName(node.ref);
|
|
2110
1679
|
return node.name ?? "";
|
|
2111
1680
|
}
|
|
2112
1681
|
const arrayTupleFields = [
|
|
@@ -2611,20 +2180,6 @@ function createPrinterFactory(getKey) {
|
|
|
2611
2180
|
}
|
|
2612
2181
|
//#endregion
|
|
2613
2182
|
//#region src/resolvers.ts
|
|
2614
|
-
function findDiscriminator(mapping, ref) {
|
|
2615
|
-
if (!mapping || !ref) return null;
|
|
2616
|
-
return Object.entries(mapping).find(([, value]) => value === ref)?.[0] ?? null;
|
|
2617
|
-
}
|
|
2618
|
-
function childName(parentName, propName) {
|
|
2619
|
-
return parentName ? pascalCase([parentName, propName].join(" ")) : null;
|
|
2620
|
-
}
|
|
2621
|
-
function enumPropName(parentName, propName, enumSuffix) {
|
|
2622
|
-
return pascalCase([
|
|
2623
|
-
parentName,
|
|
2624
|
-
propName,
|
|
2625
|
-
enumSuffix
|
|
2626
|
-
].filter(Boolean).join(" "));
|
|
2627
|
-
}
|
|
2628
2183
|
/**
|
|
2629
2184
|
* Collects import entries for all `ref` schema nodes in `node`.
|
|
2630
2185
|
*/
|
|
@@ -2632,7 +2187,7 @@ function collectImports({ node, nameMapping, resolve }) {
|
|
|
2632
2187
|
return collect(node, { schema(schemaNode) {
|
|
2633
2188
|
const schemaRef = narrowSchema(schemaNode, "ref");
|
|
2634
2189
|
if (!schemaRef?.ref) return null;
|
|
2635
|
-
const rawName = extractRefName(schemaRef.ref);
|
|
2190
|
+
const rawName = require_utils.extractRefName(schemaRef.ref);
|
|
2636
2191
|
const result = resolve(nameMapping.get(rawName) ?? rawName);
|
|
2637
2192
|
if (!result) return null;
|
|
2638
2193
|
return result;
|
|
@@ -2720,7 +2275,7 @@ function* mergeAdjacentObjectsLazy(members) {
|
|
|
2720
2275
|
* ```
|
|
2721
2276
|
*/
|
|
2722
2277
|
function simplifyUnion(members) {
|
|
2723
|
-
const scalarPrimitives = new Set(members.filter((member) => isScalarPrimitive(member.type)).map((m) => m.type));
|
|
2278
|
+
const scalarPrimitives = new Set(members.filter((member) => require_utils.isScalarPrimitive(member.type)).map((m) => m.type));
|
|
2724
2279
|
if (!scalarPrimitives.size) return members;
|
|
2725
2280
|
return members.filter((member) => {
|
|
2726
2281
|
const enumNode = narrowSchema(member, "enum");
|
|
@@ -2741,17 +2296,14 @@ function setEnumName(propNode, parentName, propName, enumSuffix) {
|
|
|
2741
2296
|
};
|
|
2742
2297
|
if (enumNode) return {
|
|
2743
2298
|
...propNode,
|
|
2744
|
-
name: enumPropName(parentName, propName, enumSuffix)
|
|
2299
|
+
name: require_utils.enumPropName(parentName, propName, enumSuffix)
|
|
2745
2300
|
};
|
|
2746
2301
|
return propNode;
|
|
2747
2302
|
}
|
|
2748
2303
|
//#endregion
|
|
2749
2304
|
exports.applyDedupe = applyDedupe;
|
|
2750
2305
|
exports.buildDedupePlan = buildDedupePlan;
|
|
2751
|
-
exports.buildList = buildList;
|
|
2752
|
-
exports.buildObject = buildObject;
|
|
2753
2306
|
exports.caseParams = caseParams;
|
|
2754
|
-
exports.childName = childName;
|
|
2755
2307
|
exports.collect = collect;
|
|
2756
2308
|
exports.collectImports = collectImports;
|
|
2757
2309
|
exports.collectUsedSchemaNames = collectUsedSchemaNames;
|
|
@@ -2785,12 +2337,9 @@ exports.createType = createType;
|
|
|
2785
2337
|
exports.definePrinter = definePrinter;
|
|
2786
2338
|
exports.defineSchemaDialect = defineSchemaDialect;
|
|
2787
2339
|
exports.dispatch = dispatch;
|
|
2788
|
-
exports.enumPropName = enumPropName;
|
|
2789
|
-
exports.extractRefName = extractRefName;
|
|
2790
2340
|
exports.extractStringsFromNodes = extractStringsFromNodes;
|
|
2791
2341
|
exports.findCircularSchemas = findCircularSchemas;
|
|
2792
|
-
exports.
|
|
2793
|
-
exports.httpMethods = httpMethods;
|
|
2342
|
+
exports.httpMethods = require_utils.httpMethods;
|
|
2794
2343
|
exports.isHttpOperationNode = isHttpOperationNode;
|
|
2795
2344
|
exports.isInputNode = isInputNode;
|
|
2796
2345
|
exports.isOperationNode = isOperationNode;
|
|
@@ -2799,9 +2348,8 @@ exports.isSchemaNode = isSchemaNode;
|
|
|
2799
2348
|
exports.isStringType = isStringType;
|
|
2800
2349
|
exports.mergeAdjacentObjectsLazy = mergeAdjacentObjectsLazy;
|
|
2801
2350
|
exports.narrowSchema = narrowSchema;
|
|
2802
|
-
exports.objectKey = objectKey;
|
|
2803
2351
|
exports.schemaSignature = schemaSignature;
|
|
2804
|
-
exports.schemaTypes = schemaTypes;
|
|
2352
|
+
exports.schemaTypes = require_utils.schemaTypes;
|
|
2805
2353
|
exports.setDiscriminatorEnum = setDiscriminatorEnum;
|
|
2806
2354
|
exports.setEnumName = setEnumName;
|
|
2807
2355
|
exports.simplifyUnion = simplifyUnion;
|