@kubb/ast 5.0.0-alpha.3 → 5.0.0-alpha.5

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.
@@ -46,6 +46,7 @@ declare const schemaTypes: {
46
46
  readonly email: "email";
47
47
  readonly url: "url";
48
48
  readonly blob: "blob";
49
+ readonly never: "never";
49
50
  };
50
51
  declare const httpMethods: {
51
52
  readonly get: "GET";
@@ -103,14 +104,14 @@ type PropertyNode = BaseNode & {
103
104
  };
104
105
  //#endregion
105
106
  //#region src/nodes/schema.d.ts
106
- type PrimitiveSchemaType = 'string' | 'number' | 'integer' | 'bigint' | 'boolean' | 'null' | 'any' | 'unknown' | 'void' | 'object' | 'array' | 'date';
107
+ type PrimitiveSchemaType = 'string' | 'number' | 'integer' | 'bigint' | 'boolean' | 'null' | 'any' | 'unknown' | 'void' | 'never' | 'object' | 'array' | 'date';
107
108
  type ComplexSchemaType = 'tuple' | 'union' | 'intersection' | 'enum';
108
109
  /**
109
110
  * Semantic types requiring special handling in code generation (e.g. generating a `Date` object or a branded type).
110
111
  */
111
112
  type SpecialSchemaType = 'ref' | 'datetime' | 'time' | 'uuid' | 'email' | 'url' | 'blob';
112
113
  type SchemaType = PrimitiveSchemaType | ComplexSchemaType | SpecialSchemaType;
113
- type ScalarSchemaType = Exclude<SchemaType, 'object' | 'array' | 'tuple' | 'union' | 'intersection' | 'enum' | 'ref' | 'datetime' | 'date' | 'time' | 'string' | 'number' | 'integer' | 'bigint'>;
114
+ type ScalarSchemaType = Exclude<SchemaType, 'object' | 'array' | 'tuple' | 'union' | 'intersection' | 'enum' | 'ref' | 'datetime' | 'date' | 'time' | 'string' | 'number' | 'integer' | 'bigint' | 'url'>;
114
115
  /**
115
116
  * Base fields shared by every schema variant. Does not include spec-specific fields.
116
117
  */
@@ -284,6 +285,16 @@ type NumberSchemaNode = SchemaNodeBase & {
284
285
  type ScalarSchemaNode = SchemaNodeBase & {
285
286
  type: ScalarSchemaType;
286
287
  };
288
+ /**
289
+ * URL schema, optionally carrying an Express-style path template for template literal generation.
290
+ */
291
+ type UrlSchemaNode = SchemaNodeBase & {
292
+ type: 'url';
293
+ /**
294
+ * Express-style path (e.g. `'/pets/:petId'`). When set, printers may emit a template literal type.
295
+ */
296
+ path?: string;
297
+ };
287
298
  /**
288
299
  * Maps each schema type string to its `SchemaNode` variant. Used by `narrowSchema`.
289
300
  */
@@ -307,15 +318,16 @@ type SchemaNodeByType = {
307
318
  any: ScalarSchemaNode;
308
319
  unknown: ScalarSchemaNode;
309
320
  void: ScalarSchemaNode;
321
+ never: ScalarSchemaNode;
310
322
  uuid: ScalarSchemaNode;
311
323
  email: ScalarSchemaNode;
312
- url: ScalarSchemaNode;
324
+ url: UrlSchemaNode;
313
325
  blob: ScalarSchemaNode;
314
326
  };
315
327
  /**
316
328
  * Discriminated union of all schema variants.
317
329
  */
318
- type SchemaNode = ObjectSchemaNode | ArraySchemaNode | UnionSchemaNode | IntersectionSchemaNode | EnumSchemaNode | RefSchemaNode | DatetimeSchemaNode | DateSchemaNode | TimeSchemaNode | StringSchemaNode | NumberSchemaNode | ScalarSchemaNode;
330
+ type SchemaNode = ObjectSchemaNode | ArraySchemaNode | UnionSchemaNode | IntersectionSchemaNode | EnumSchemaNode | RefSchemaNode | DatetimeSchemaNode | DateSchemaNode | TimeSchemaNode | StringSchemaNode | NumberSchemaNode | UrlSchemaNode | ScalarSchemaNode;
319
331
  //#endregion
320
332
  //#region src/nodes/parameter.d.ts
321
333
  type ParameterLocation = 'path' | 'query' | 'header' | 'cookie';
@@ -396,7 +408,13 @@ type OperationNode = BaseNode & {
396
408
  * Adapters populate whichever fields are available in their source format.
397
409
  */
398
410
  type RootMeta = {
399
- /** API title (from `info.title` in OAS/AsyncAPI). */title?: string; /** API version string (from `info.version` in OAS/AsyncAPI). */
411
+ /**
412
+ * API title (from `info.title` in OAS/AsyncAPI).
413
+ */
414
+ title?: string;
415
+ /**
416
+ * API version string (from `info.version` in OAS/AsyncAPI).
417
+ */
400
418
  version?: string;
401
419
  /**
402
420
  * Resolved base URL for the API.
@@ -412,7 +430,10 @@ type RootMeta = {
412
430
  type RootNode = BaseNode & {
413
431
  kind: 'Root';
414
432
  schemas: Array<SchemaNode>;
415
- operations: Array<OperationNode>; /** Format-agnostic document metadata populated by the adapter. */
433
+ operations: Array<OperationNode>;
434
+ /**
435
+ * Format-agnostic document metadata populated by the adapter.
436
+ */
416
437
  meta?: RootMeta;
417
438
  };
418
439
  //#endregion
@@ -649,5 +670,5 @@ declare function transform(node: Node, visitor: Visitor, options?: VisitorOption
649
670
  */
650
671
  declare function collect<T>(node: Node, visitor: CollectVisitor<T>, options?: VisitorOptions): Array<T>;
651
672
  //#endregion
652
- export { UnionSchemaNode as $, MediaType as A, IntersectionSchemaNode as B, Node as C, OperationNode as D, HttpMethod as E, ComplexSchemaType as F, ScalarSchemaNode as G, ObjectSchemaNode as H, DateSchemaNode as I, SchemaNodeByType as J, ScalarSchemaType as K, DatetimeSchemaNode as L, ParameterLocation as M, ParameterNode as N, ResponseNode as O, ArraySchemaNode as P, TimeSchemaNode as Q, EnumSchemaNode as R, createSchema as S, RootNode as T, PrimitiveSchemaType as U, NumberSchemaNode as V, RefSchemaNode as W, SpecialSchemaType as X, SchemaType as Y, StringSchemaNode as Z, createOperation as _, transform as a, mediaTypes as at, createResponse as b, buildRefMap as c, Printer as d, PropertyNode as et, PrinterFactoryOptions as f, DistributiveOmit as g, definePrinter as h, collect as i, httpMethods as it, StatusCode as j, HttpStatusCode as k, refMapToObject as l, PrinterHandlerContext as m, CollectVisitor as n, NodeKind as nt, walk as o, nodeKinds as ot, PrinterHandler as p, SchemaNode as q, Visitor as r, VisitorDepth as rt, RefMap as s, schemaTypes as st, AsyncVisitor as t, BaseNode as tt, resolveRef as u, createParameter as v, RootMeta as w, createRoot as x, createProperty as y, EnumValueNode as z };
653
- //# sourceMappingURL=visitor-oFfdU8QA.d.ts.map
673
+ export { UnionSchemaNode as $, MediaType as A, IntersectionSchemaNode as B, Node as C, OperationNode as D, HttpMethod as E, ComplexSchemaType as F, ScalarSchemaNode as G, ObjectSchemaNode as H, DateSchemaNode as I, SchemaNodeByType as J, ScalarSchemaType as K, DatetimeSchemaNode as L, ParameterLocation as M, ParameterNode as N, ResponseNode as O, ArraySchemaNode as P, TimeSchemaNode as Q, EnumSchemaNode as R, createSchema as S, RootNode as T, PrimitiveSchemaType as U, NumberSchemaNode as V, RefSchemaNode as W, SpecialSchemaType as X, SchemaType as Y, StringSchemaNode as Z, createOperation as _, transform as a, httpMethods as at, createResponse as b, buildRefMap as c, schemaTypes as ct, Printer as d, UrlSchemaNode as et, PrinterFactoryOptions as f, DistributiveOmit as g, definePrinter as h, collect as i, VisitorDepth as it, StatusCode as j, HttpStatusCode as k, refMapToObject as l, PrinterHandlerContext as m, CollectVisitor as n, BaseNode as nt, walk as o, mediaTypes as ot, PrinterHandler as p, SchemaNode as q, Visitor as r, NodeKind as rt, RefMap as s, nodeKinds as st, AsyncVisitor as t, PropertyNode as tt, resolveRef as u, createParameter as v, RootMeta as w, createRoot as x, createProperty as y, EnumValueNode as z };
674
+ //# sourceMappingURL=visitor-CE4-xBHW.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/ast",
3
- "version": "5.0.0-alpha.3",
3
+ "version": "5.0.0-alpha.5",
4
4
  "description": "Spec-agnostic AST layer for Kubb. Defines nodes, visitor pattern, and factory functions used across codegen plugins.",
5
5
  "keywords": [
6
6
  "kubb",
@@ -45,7 +45,8 @@
45
45
  "!/**/__snapshots__/**"
46
46
  ],
47
47
  "devDependencies": {
48
- "@types/node": "^22.19.15"
48
+ "@types/node": "^22.19.15",
49
+ "@internals/utils": "0.0.0"
49
50
  },
50
51
  "main": "./dist/index.cjs",
51
52
  "module": "./dist/index.js",
package/src/constants.ts CHANGED
@@ -56,6 +56,7 @@ export const schemaTypes = {
56
56
  email: 'email',
57
57
  url: 'url',
58
58
  blob: 'blob',
59
+ never: 'never',
59
60
  } as const satisfies Record<SchemaType, SchemaType>
60
61
 
61
62
  export const httpMethods = {
package/src/index.ts CHANGED
@@ -3,5 +3,5 @@ export { createOperation, createParameter, createProperty, createResponse, creat
3
3
  export { isOperationNode, isParameterNode, isPropertyNode, isResponseNode, isRootNode, isSchemaNode, narrowSchema } from './guards.ts'
4
4
  export { definePrinter } from './printer.ts'
5
5
  export { buildRefMap, refMapToObject, resolveRef } from './refs.ts'
6
- export { isPlainStringType } from './utils.ts'
6
+ export { applyParamsCasing, isPlainStringType } from './utils.ts'
7
7
  export { collect, transform, walk } from './visitor.ts'
@@ -33,6 +33,7 @@ export type {
33
33
  StringSchemaNode,
34
34
  TimeSchemaNode,
35
35
  UnionSchemaNode,
36
+ UrlSchemaNode,
36
37
  } from './schema.ts'
37
38
 
38
39
  /**
package/src/nodes/root.ts CHANGED
@@ -7,9 +7,13 @@ import type { SchemaNode } from './schema.ts'
7
7
  * Adapters populate whichever fields are available in their source format.
8
8
  */
9
9
  export type RootMeta = {
10
- /** API title (from `info.title` in OAS/AsyncAPI). */
10
+ /**
11
+ * API title (from `info.title` in OAS/AsyncAPI).
12
+ */
11
13
  title?: string
12
- /** API version string (from `info.version` in OAS/AsyncAPI). */
14
+ /**
15
+ * API version string (from `info.version` in OAS/AsyncAPI).
16
+ */
13
17
  version?: string
14
18
  /**
15
19
  * Resolved base URL for the API.
@@ -27,6 +31,8 @@ export type RootNode = BaseNode & {
27
31
  kind: 'Root'
28
32
  schemas: Array<SchemaNode>
29
33
  operations: Array<OperationNode>
30
- /** Format-agnostic document metadata populated by the adapter. */
34
+ /**
35
+ * Format-agnostic document metadata populated by the adapter.
36
+ */
31
37
  meta?: RootMeta
32
38
  }
@@ -1,7 +1,20 @@
1
1
  import type { BaseNode } from './base.ts'
2
2
  import type { PropertyNode } from './property.ts'
3
3
 
4
- export type PrimitiveSchemaType = 'string' | 'number' | 'integer' | 'bigint' | 'boolean' | 'null' | 'any' | 'unknown' | 'void' | 'object' | 'array' | 'date'
4
+ export type PrimitiveSchemaType =
5
+ | 'string'
6
+ | 'number'
7
+ | 'integer'
8
+ | 'bigint'
9
+ | 'boolean'
10
+ | 'null'
11
+ | 'any'
12
+ | 'unknown'
13
+ | 'void'
14
+ | 'never'
15
+ | 'object'
16
+ | 'array'
17
+ | 'date'
5
18
 
6
19
  export type ComplexSchemaType = 'tuple' | 'union' | 'intersection' | 'enum'
7
20
 
@@ -14,7 +27,7 @@ export type SchemaType = PrimitiveSchemaType | ComplexSchemaType | SpecialSchema
14
27
 
15
28
  export type ScalarSchemaType = Exclude<
16
29
  SchemaType,
17
- 'object' | 'array' | 'tuple' | 'union' | 'intersection' | 'enum' | 'ref' | 'datetime' | 'date' | 'time' | 'string' | 'number' | 'integer' | 'bigint'
30
+ 'object' | 'array' | 'tuple' | 'union' | 'intersection' | 'enum' | 'ref' | 'datetime' | 'date' | 'time' | 'string' | 'number' | 'integer' | 'bigint' | 'url'
18
31
  >
19
32
 
20
33
  /**
@@ -206,6 +219,17 @@ export type ScalarSchemaNode = SchemaNodeBase & {
206
219
  type: ScalarSchemaType
207
220
  }
208
221
 
222
+ /**
223
+ * URL schema, optionally carrying an Express-style path template for template literal generation.
224
+ */
225
+ export type UrlSchemaNode = SchemaNodeBase & {
226
+ type: 'url'
227
+ /**
228
+ * Express-style path (e.g. `'/pets/:petId'`). When set, printers may emit a template literal type.
229
+ */
230
+ path?: string
231
+ }
232
+
209
233
  /**
210
234
  * Maps each schema type string to its `SchemaNode` variant. Used by `narrowSchema`.
211
235
  */
@@ -229,9 +253,10 @@ export type SchemaNodeByType = {
229
253
  any: ScalarSchemaNode
230
254
  unknown: ScalarSchemaNode
231
255
  void: ScalarSchemaNode
256
+ never: ScalarSchemaNode
232
257
  uuid: ScalarSchemaNode
233
258
  email: ScalarSchemaNode
234
- url: ScalarSchemaNode
259
+ url: UrlSchemaNode
235
260
  blob: ScalarSchemaNode
236
261
  }
237
262
 
@@ -250,4 +275,5 @@ export type SchemaNode =
250
275
  | TimeSchemaNode
251
276
  | StringSchemaNode
252
277
  | NumberSchemaNode
278
+ | UrlSchemaNode
253
279
  | ScalarSchemaNode
package/src/types.ts CHANGED
@@ -35,6 +35,7 @@ export type {
35
35
  StringSchemaNode,
36
36
  TimeSchemaNode,
37
37
  UnionSchemaNode,
38
+ UrlSchemaNode,
38
39
  } from './nodes/index.ts'
39
40
  export type { Printer, PrinterFactoryOptions, PrinterHandler, PrinterHandlerContext } from './printer.ts'
40
41
  export type { RefMap } from './refs.ts'
package/src/utils.ts CHANGED
@@ -1,5 +1,7 @@
1
+ import { camelCase, isValidVarName } from '@internals/utils'
2
+
1
3
  import { narrowSchema } from './guards.ts'
2
- import type { SchemaNode } from './nodes/index.ts'
4
+ import type { ParameterNode, SchemaNode } from './nodes/index.ts'
3
5
  import type { SchemaType } from './nodes/schema.ts'
4
6
 
5
7
  const plainStringTypes = new Set<SchemaType>(['string', 'uuid', 'email', 'url', 'datetime'])
@@ -22,3 +24,25 @@ export function isPlainStringType(node: SchemaNode): boolean {
22
24
 
23
25
  return false
24
26
  }
27
+
28
+ /**
29
+ * Transforms the `name` field of each parameter node according to the given casing strategy.
30
+ *
31
+ * The original `params` array is never mutated — a new array of cloned nodes is returned.
32
+ * When no `casing` is provided the original array is returned as-is.
33
+ *
34
+ * Use this before passing parameters to schema builders so that property keys
35
+ * in the generated output match the desired casing while the original
36
+ * `OperationNode.parameters` array remains untouched for other consumers.
37
+ */
38
+ export function applyParamsCasing(params: Array<ParameterNode>, casing: 'camelcase' | undefined): Array<ParameterNode> {
39
+ if (!casing) {
40
+ return params
41
+ }
42
+
43
+ return params.map((param) => {
44
+ const transformed = casing === 'camelcase' || !isValidVarName(param.name) ? camelCase(param.name) : param.name
45
+
46
+ return { ...param, name: transformed }
47
+ })
48
+ }
package/src/visitor.ts CHANGED
@@ -2,6 +2,10 @@ import type { VisitorDepth } from './constants.ts'
2
2
  import { visitorDepths, WALK_CONCURRENCY } from './constants.ts'
3
3
  import type { Node, OperationNode, ParameterNode, PropertyNode, ResponseNode, RootNode, SchemaNode } from './nodes/index.ts'
4
4
 
5
+ /**
6
+ * Creates a concurrency-limiting wrapper. At most `concurrency` promises may be
7
+ * in-flight simultaneously; additional calls are queued and dispatched as slots free.
8
+ */
5
9
  function createLimit(concurrency: number) {
6
10
  let active = 0
7
11
  const queue: Array<() => void> = []
@@ -81,7 +85,10 @@ export type CollectVisitor<T> = {
81
85
  }
82
86
 
83
87
  /**
84
- * Traversable children of `node`, respecting `recurse` for schema nodes.
88
+ * Returns the immediate traversable children of `node`.
89
+ *
90
+ * For `Schema` nodes, children (properties, items, members) are only included
91
+ * when `recurse` is `true`; shallow traversal omits them entirely.
85
92
  */
86
93
  function getChildren(node: Node, recurse: boolean): Array<Node> {
87
94
  switch (node.kind) {
@@ -119,6 +126,9 @@ export async function walk(node: Node, visitor: AsyncVisitor, options: VisitorOp
119
126
  return _walk(node, visitor, recurse, limit)
120
127
  }
121
128
 
129
+ /**
130
+ * Internal recursive walk implementation — calls visitor then recurses into children.
131
+ */
122
132
  async function _walk(node: Node, visitor: AsyncVisitor, recurse: boolean, limit: LimitFn): Promise<void> {
123
133
  switch (node.kind) {
124
134
  case 'Root':