@kubb/ast 5.0.0-beta.42 → 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 CHANGED
@@ -1,247 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region \0rolldown/runtime.js
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
- //#endregion
181
- //#region ../../internals/utils/src/casing.ts
182
- /**
183
- * Shared implementation for camelCase and PascalCase conversion.
184
- * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
185
- * and capitalizes each word according to `pascal`.
186
- *
187
- * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
188
- */
189
- function toCamelOrPascal(text, pascal) {
190
- 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) => {
191
- if (word.length > 1 && word === word.toUpperCase()) return word;
192
- if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1);
193
- return word.charAt(0).toUpperCase() + word.slice(1);
194
- }).join("").replace(/[^a-zA-Z0-9]/g, "");
195
- }
196
- /**
197
- * Splits `text` on `.` and applies `transformPart` to each segment.
198
- * The last segment receives `isLast = true`, all earlier segments receive `false`.
199
- * Segments are joined with `/` to form a file path.
200
- *
201
- * Only splits on dots followed by a letter so that version numbers
202
- * embedded in operationIds (e.g. `v2025.0`) are kept intact.
203
- *
204
- * Empty segments are filtered before joining. They arise when the text starts with
205
- * a dot followed immediately by a letter (e.g. `..Schema` splits into `['..', 'Schema']`
206
- * and `'..'` transforms to an empty string). Without this filter the join would produce
207
- * a leading `/`, which `path.resolve` would interpret as an absolute path, allowing
208
- * generated files to escape the configured output directory.
209
- */
210
- function applyToFileParts(text, transformPart) {
211
- const parts = text.split(/\.(?=[a-zA-Z])/);
212
- return parts.map((part, i) => transformPart(part, i === parts.length - 1)).filter(Boolean).join("/");
213
- }
214
- /**
215
- * Converts `text` to camelCase.
216
- * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
217
- *
218
- * @example
219
- * camelCase('hello-world') // 'helloWorld'
220
- * camelCase('pet.petId', { isFile: true }) // 'pet/petId'
221
- */
222
- function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
223
- if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
224
- prefix,
225
- suffix
226
- } : {}));
227
- return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
228
- }
229
- /**
230
- * Converts `text` to PascalCase.
231
- * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.
232
- *
233
- * @example
234
- * pascalCase('hello-world') // 'HelloWorld'
235
- * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'
236
- */
237
- function pascalCase(text, { isFile, prefix = "", suffix = "" } = {}) {
238
- if (isFile) return applyToFileParts(text, (part, isLast) => isLast ? pascalCase(part, {
239
- prefix,
240
- suffix
241
- }) : camelCase(part));
242
- return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
243
- }
244
- //#endregion
5
+ node_path = require_utils.__toESM(node_path, 1);
245
6
  //#region ../../internals/utils/src/promise.ts
246
7
  /**
247
8
  * Wraps `factory` with a keyed cache backed by the provided store.
@@ -282,126 +43,6 @@ function memoize(store, factory) {
282
43
  };
283
44
  }
284
45
  //#endregion
285
- //#region ../../internals/utils/src/reserved.ts
286
- /**
287
- * JavaScript and Java reserved words.
288
- * @link https://github.com/jonschlinkert/reserved/blob/master/index.js
289
- */
290
- const reservedWords = new Set([
291
- "abstract",
292
- "arguments",
293
- "boolean",
294
- "break",
295
- "byte",
296
- "case",
297
- "catch",
298
- "char",
299
- "class",
300
- "const",
301
- "continue",
302
- "debugger",
303
- "default",
304
- "delete",
305
- "do",
306
- "double",
307
- "else",
308
- "enum",
309
- "eval",
310
- "export",
311
- "extends",
312
- "false",
313
- "final",
314
- "finally",
315
- "float",
316
- "for",
317
- "function",
318
- "goto",
319
- "if",
320
- "implements",
321
- "import",
322
- "in",
323
- "instanceof",
324
- "int",
325
- "interface",
326
- "let",
327
- "long",
328
- "native",
329
- "new",
330
- "null",
331
- "package",
332
- "private",
333
- "protected",
334
- "public",
335
- "return",
336
- "short",
337
- "static",
338
- "super",
339
- "switch",
340
- "synchronized",
341
- "this",
342
- "throw",
343
- "throws",
344
- "transient",
345
- "true",
346
- "try",
347
- "typeof",
348
- "var",
349
- "void",
350
- "volatile",
351
- "while",
352
- "with",
353
- "yield",
354
- "Array",
355
- "Date",
356
- "hasOwnProperty",
357
- "Infinity",
358
- "isFinite",
359
- "isNaN",
360
- "isPrototypeOf",
361
- "length",
362
- "Math",
363
- "name",
364
- "NaN",
365
- "Number",
366
- "Object",
367
- "prototype",
368
- "String",
369
- "toString",
370
- "undefined",
371
- "valueOf"
372
- ]);
373
- /**
374
- * Returns `true` when `name` is a syntactically valid JavaScript variable name.
375
- *
376
- * @example
377
- * ```ts
378
- * isValidVarName('status') // true
379
- * isValidVarName('class') // false (reserved word)
380
- * isValidVarName('42foo') // false (starts with digit)
381
- * ```
382
- */
383
- function isValidVarName(name) {
384
- if (!name || reservedWords.has(name)) return false;
385
- return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
386
- }
387
- //#endregion
388
- //#region ../../internals/utils/src/string.ts
389
- /**
390
- * Strips the file extension from a path or file name.
391
- * Only removes the last `.ext` segment when the dot is not part of a directory name.
392
- *
393
- * @example
394
- * trimExtName('petStore.ts') // 'petStore'
395
- * trimExtName('/src/models/pet.ts') // '/src/models/pet'
396
- * trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'
397
- * trimExtName('noExtension') // 'noExtension'
398
- */
399
- function trimExtName(text) {
400
- const dotIndex = text.lastIndexOf(".");
401
- if (dotIndex > 0 && !text.includes("/", dotIndex)) return text.slice(0, dotIndex);
402
- return text;
403
- }
404
- //#endregion
405
46
  //#region src/guards.ts
406
47
  /**
407
48
  * Narrows a `SchemaNode` to the variant that matches `type`.
@@ -476,21 +117,6 @@ function isHttpOperationNode(node) {
476
117
  */
477
118
  const isSchemaNode = isKind("Schema");
478
119
  //#endregion
479
- //#region src/refs.ts
480
- /**
481
- * Returns the last path segment of a reference string.
482
- *
483
- * Example: `#/components/schemas/Pet` becomes `Pet`.
484
- *
485
- * @example
486
- * ```ts
487
- * extractRefName('#/components/schemas/Pet') // 'Pet'
488
- * ```
489
- */
490
- function extractRefName(ref) {
491
- return ref.split("/").at(-1) ?? ref;
492
- }
493
- //#endregion
494
120
  //#region src/visitor.ts
495
121
  /**
496
122
  * Creates a small async concurrency limiter.
@@ -627,7 +253,7 @@ function applyVisitor(node, visitor, parent) {
627
253
  * ```
628
254
  */
629
255
  async function walk(node, options) {
630
- 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);
631
257
  }
632
258
  async function _walk(node, visitor, recurse, limit, parent) {
633
259
  await limit(() => applyVisitor(node, visitor, parent));
@@ -637,7 +263,7 @@ async function _walk(node, visitor, recurse, limit, parent) {
637
263
  }
638
264
  function transform(node, options) {
639
265
  const { depth, parent, ...visitor } = options;
640
- const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep;
266
+ const recurse = (depth ?? require_utils.visitorDepths.deep) === require_utils.visitorDepths.deep;
641
267
  const rebuilt = transformChildren(applyVisitor(node, visitor, parent) ?? node, options, recurse);
642
268
  if (rebuilt === node) return node;
643
269
  const finalize = nodeFinalizers[rebuilt.kind];
@@ -707,7 +333,7 @@ function transformChildren(node, options, recurse) {
707
333
  */
708
334
  function* collectLazy(node, options) {
709
335
  const { depth, parent, ...visitor } = options;
710
- const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep;
336
+ const recurse = (depth ?? require_utils.visitorDepths.deep) === require_utils.visitorDepths.deep;
711
337
  const v = applyVisitor(node, visitor, parent);
712
338
  if (v != null) yield v;
713
339
  for (const child of getChildren(node, recurse)) yield* collectLazy(child, {
@@ -732,7 +358,7 @@ function collect(node, options) {
732
358
  return Array.from(collectLazy(node, options));
733
359
  }
734
360
  //#endregion
735
- //#region src/utils.ts
361
+ //#region src/utils/ast.ts
736
362
  const plainStringTypes = new Set([
737
363
  "string",
738
364
  "uuid",
@@ -784,7 +410,7 @@ function isStringType(node) {
784
410
  * The input array is not mutated. When `casing` is not set, the original array is returned unchanged.
785
411
  */
786
412
  const caseParamsMemo = memoize(/* @__PURE__ */ new WeakMap(), (params) => memoize(/* @__PURE__ */ new Map(), (casing) => params.map((param) => {
787
- 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;
788
414
  return {
789
415
  ...param,
790
416
  name: transformed
@@ -1216,7 +842,7 @@ function extractStringsFromNodes(nodes) {
1216
842
  */
1217
843
  function resolveRefName(node) {
1218
844
  if (!node || node.type !== "ref") return null;
1219
- 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;
1220
846
  return node.name ?? node.schema?.name ?? null;
1221
847
  }
1222
848
  /**
@@ -1845,7 +1471,7 @@ function createFile(input) {
1845
1471
  kind: "File",
1846
1472
  ...input,
1847
1473
  id: (0, node_crypto.hash)("sha256", input.path, "hex"),
1848
- name: trimExtName(input.baseName),
1474
+ name: require_utils.trimExtName(input.baseName),
1849
1475
  extname,
1850
1476
  imports: resolvedImports,
1851
1477
  exports: resolvedExports,
@@ -2049,7 +1675,7 @@ function flagsDescriptor(node) {
2049
1675
  return `${node.primitive ?? ""};${node.format ?? ""};${node.nullable ? 1 : 0}`;
2050
1676
  }
2051
1677
  function refTargetName(node) {
2052
- if (node.ref) return extractRefName(node.ref);
1678
+ if (node.ref) return require_utils.extractRefName(node.ref);
2053
1679
  return node.name ?? "";
2054
1680
  }
2055
1681
  const arrayTupleFields = [
@@ -2554,20 +2180,6 @@ function createPrinterFactory(getKey) {
2554
2180
  }
2555
2181
  //#endregion
2556
2182
  //#region src/resolvers.ts
2557
- function findDiscriminator(mapping, ref) {
2558
- if (!mapping || !ref) return null;
2559
- return Object.entries(mapping).find(([, value]) => value === ref)?.[0] ?? null;
2560
- }
2561
- function childName(parentName, propName) {
2562
- return parentName ? pascalCase([parentName, propName].join(" ")) : null;
2563
- }
2564
- function enumPropName(parentName, propName, enumSuffix) {
2565
- return pascalCase([
2566
- parentName,
2567
- propName,
2568
- enumSuffix
2569
- ].filter(Boolean).join(" "));
2570
- }
2571
2183
  /**
2572
2184
  * Collects import entries for all `ref` schema nodes in `node`.
2573
2185
  */
@@ -2575,7 +2187,7 @@ function collectImports({ node, nameMapping, resolve }) {
2575
2187
  return collect(node, { schema(schemaNode) {
2576
2188
  const schemaRef = narrowSchema(schemaNode, "ref");
2577
2189
  if (!schemaRef?.ref) return null;
2578
- const rawName = extractRefName(schemaRef.ref);
2190
+ const rawName = require_utils.extractRefName(schemaRef.ref);
2579
2191
  const result = resolve(nameMapping.get(rawName) ?? rawName);
2580
2192
  if (!result) return null;
2581
2193
  return result;
@@ -2663,7 +2275,7 @@ function* mergeAdjacentObjectsLazy(members) {
2663
2275
  * ```
2664
2276
  */
2665
2277
  function simplifyUnion(members) {
2666
- 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));
2667
2279
  if (!scalarPrimitives.size) return members;
2668
2280
  return members.filter((member) => {
2669
2281
  const enumNode = narrowSchema(member, "enum");
@@ -2684,7 +2296,7 @@ function setEnumName(propNode, parentName, propName, enumSuffix) {
2684
2296
  };
2685
2297
  if (enumNode) return {
2686
2298
  ...propNode,
2687
- name: enumPropName(parentName, propName, enumSuffix)
2299
+ name: require_utils.enumPropName(parentName, propName, enumSuffix)
2688
2300
  };
2689
2301
  return propNode;
2690
2302
  }
@@ -2692,7 +2304,6 @@ function setEnumName(propNode, parentName, propName, enumSuffix) {
2692
2304
  exports.applyDedupe = applyDedupe;
2693
2305
  exports.buildDedupePlan = buildDedupePlan;
2694
2306
  exports.caseParams = caseParams;
2695
- exports.childName = childName;
2696
2307
  exports.collect = collect;
2697
2308
  exports.collectImports = collectImports;
2698
2309
  exports.collectUsedSchemaNames = collectUsedSchemaNames;
@@ -2726,12 +2337,9 @@ exports.createType = createType;
2726
2337
  exports.definePrinter = definePrinter;
2727
2338
  exports.defineSchemaDialect = defineSchemaDialect;
2728
2339
  exports.dispatch = dispatch;
2729
- exports.enumPropName = enumPropName;
2730
- exports.extractRefName = extractRefName;
2731
2340
  exports.extractStringsFromNodes = extractStringsFromNodes;
2732
2341
  exports.findCircularSchemas = findCircularSchemas;
2733
- exports.findDiscriminator = findDiscriminator;
2734
- exports.httpMethods = httpMethods;
2342
+ exports.httpMethods = require_utils.httpMethods;
2735
2343
  exports.isHttpOperationNode = isHttpOperationNode;
2736
2344
  exports.isInputNode = isInputNode;
2737
2345
  exports.isOperationNode = isOperationNode;
@@ -2741,7 +2349,7 @@ exports.isStringType = isStringType;
2741
2349
  exports.mergeAdjacentObjectsLazy = mergeAdjacentObjectsLazy;
2742
2350
  exports.narrowSchema = narrowSchema;
2743
2351
  exports.schemaSignature = schemaSignature;
2744
- exports.schemaTypes = schemaTypes;
2352
+ exports.schemaTypes = require_utils.schemaTypes;
2745
2353
  exports.setDiscriminatorEnum = setDiscriminatorEnum;
2746
2354
  exports.setEnumName = setEnumName;
2747
2355
  exports.simplifyUnion = simplifyUnion;