@kubb/ast 5.22.0 → 5.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/dist/base-IpYuh3ZP.d.cts +173 -0
  2. package/dist/base-IpYuh3ZP.d.ts +173 -0
  3. package/dist/constants-Ckeonm-D.js +141 -0
  4. package/dist/constants-Ckeonm-D.js.map +1 -0
  5. package/dist/constants-CquR083U.cjs +152 -0
  6. package/dist/constants-CquR083U.cjs.map +1 -0
  7. package/dist/factory.cjs +23 -0
  8. package/dist/factory.d.cts +4 -0
  9. package/dist/factory.d.ts +4 -0
  10. package/dist/factory.js +4 -0
  11. package/dist/file-BVqSiSvV.d.cts +624 -0
  12. package/dist/file-Cg0T6cgz.cjs +319 -0
  13. package/dist/file-Cg0T6cgz.cjs.map +1 -0
  14. package/dist/file-CnuL8oUj.js +283 -0
  15. package/dist/file-CnuL8oUj.js.map +1 -0
  16. package/dist/file-CvlMAp_d.js +131 -0
  17. package/dist/file-CvlMAp_d.js.map +1 -0
  18. package/dist/file-Dd50jPkH.cjs +142 -0
  19. package/dist/file-Dd50jPkH.cjs.map +1 -0
  20. package/dist/file-xJnBQPGq.d.ts +624 -0
  21. package/dist/file.cjs +3 -0
  22. package/dist/file.d.cts +2 -0
  23. package/dist/file.d.ts +2 -0
  24. package/dist/file.js +1 -0
  25. package/dist/graph-BcwFCvei.js +144 -0
  26. package/dist/graph-BcwFCvei.js.map +1 -0
  27. package/dist/graph-DcIY6tQb.cjs +173 -0
  28. package/dist/graph-DcIY6tQb.cjs.map +1 -0
  29. package/dist/graph.cjs +6 -0
  30. package/dist/graph.d.cts +2 -0
  31. package/dist/graph.d.ts +2 -0
  32. package/dist/graph.js +1 -0
  33. package/dist/guards-B8qDgSaT.d.cts +23 -0
  34. package/dist/guards-COVJE6TU.cjs +41 -0
  35. package/dist/guards-COVJE6TU.cjs.map +1 -0
  36. package/dist/guards-D-h9R_sV.d.ts +23 -0
  37. package/dist/guards-DlJkKsT1.js +30 -0
  38. package/dist/guards-DlJkKsT1.js.map +1 -0
  39. package/dist/http-Bm5lhVK4.cjs +12 -0
  40. package/dist/http-Bm5lhVK4.cjs.map +1 -0
  41. package/dist/http-DwboM6pK.js +7 -0
  42. package/dist/http-DwboM6pK.js.map +1 -0
  43. package/dist/http.cjs +4 -0
  44. package/dist/http.d.cts +3 -0
  45. package/dist/http.d.ts +3 -0
  46. package/dist/http.js +2 -0
  47. package/dist/index-BWd95onW.d.cts +5 -0
  48. package/dist/index-Bb1kqq8H.d.cts +20 -0
  49. package/dist/index-BngGJux5.d.cts +12 -0
  50. package/dist/index-BwnMIoLl.d.ts +24 -0
  51. package/dist/index-C-vhkzwR.d.cts +79 -0
  52. package/dist/index-CAGuKv6t.d.ts +74 -0
  53. package/dist/index-CFH4ZC7q.d.ts +44 -0
  54. package/dist/index-CIqwy4EE.d.cts +74 -0
  55. package/dist/index-Cc2K3OzU.d.cts +11 -0
  56. package/dist/index-Cc2K3OzU.d.ts +11 -0
  57. package/dist/index-Csf8xsCc.d.cts +46 -0
  58. package/dist/index-D3M2spDR.d.ts +12 -0
  59. package/dist/index-DNiIem0x.d.ts +79 -0
  60. package/dist/index-DSVef1pp.d.cts +24 -0
  61. package/dist/index-DU_jYpBt.d.cts +44 -0
  62. package/dist/index-DYDha-3I.d.cts +67 -0
  63. package/dist/index-DaHsMJ_S.d.ts +5 -0
  64. package/dist/index-Dp50LM3a.d.ts +67 -0
  65. package/dist/index-cpjUxIik.d.ts +46 -0
  66. package/dist/index-eGkM4FE9.d.ts +20 -0
  67. package/dist/index.cjs +87 -2131
  68. package/dist/index.cjs.map +1 -1
  69. package/dist/index.d.cts +25 -2745
  70. package/dist/index.d.ts +25 -2745
  71. package/dist/index.js +40 -2052
  72. package/dist/index.js.map +1 -1
  73. package/dist/json-DH7_lcWm.js +74 -0
  74. package/dist/json-DH7_lcWm.js.map +1 -0
  75. package/dist/json-DURdtz9A.cjs +91 -0
  76. package/dist/json-DURdtz9A.cjs.map +1 -0
  77. package/dist/json.cjs +4 -0
  78. package/dist/json.d.cts +2 -0
  79. package/dist/json.d.ts +2 -0
  80. package/dist/json.js +1 -0
  81. package/dist/macro-D0KfNtff.js +104 -0
  82. package/dist/macro-D0KfNtff.js.map +1 -0
  83. package/dist/macro-DrTBT7fh.cjs +127 -0
  84. package/dist/macro-DrTBT7fh.cjs.map +1 -0
  85. package/dist/macro.cjs +4 -0
  86. package/dist/macro.d.cts +2 -0
  87. package/dist/macro.d.ts +2 -0
  88. package/dist/macro.js +1 -0
  89. package/dist/mediaType-CRjggmoG.js +19 -0
  90. package/dist/mediaType-CRjggmoG.js.map +1 -0
  91. package/dist/mediaType-D8uIO8sG.cjs +35 -0
  92. package/dist/mediaType-D8uIO8sG.cjs.map +1 -0
  93. package/dist/mediaType.cjs +4 -0
  94. package/dist/mediaType.d.cts +2 -0
  95. package/dist/mediaType.d.ts +2 -0
  96. package/dist/mediaType.js +1 -0
  97. package/dist/node-DjcETnc8.cjs +19 -0
  98. package/dist/node-DjcETnc8.cjs.map +1 -0
  99. package/dist/node-Djh-mZB2.js +14 -0
  100. package/dist/node-Djh-mZB2.js.map +1 -0
  101. package/dist/node.cjs +9 -0
  102. package/dist/node.d.cts +4 -0
  103. package/dist/node.d.ts +4 -0
  104. package/dist/node.js +5 -0
  105. package/dist/nodeText-DRb_rVd1.cjs +58 -0
  106. package/dist/nodeText-DRb_rVd1.cjs.map +1 -0
  107. package/dist/nodeText-DVVDZQjF.js +47 -0
  108. package/dist/nodeText-DVVDZQjF.js.map +1 -0
  109. package/dist/nodes-BB60Bq2H.cjs +320 -0
  110. package/dist/nodes-BB60Bq2H.cjs.map +1 -0
  111. package/dist/nodes-CWMa9xhW.js +231 -0
  112. package/dist/nodes-CWMa9xhW.js.map +1 -0
  113. package/dist/operation-BgRyVS7z.d.ts +1272 -0
  114. package/dist/operation-X7chCdL2.d.cts +1272 -0
  115. package/dist/optionality-D-zqzVMH.cjs +22 -0
  116. package/dist/optionality-D-zqzVMH.cjs.map +1 -0
  117. package/dist/optionality-DISn8ytP.js +17 -0
  118. package/dist/optionality-DISn8ytP.js.map +1 -0
  119. package/dist/promise-BOdlgT0N.cjs +50 -0
  120. package/dist/promise-BOdlgT0N.cjs.map +1 -0
  121. package/dist/promise-RpnEev9D.js +45 -0
  122. package/dist/promise-RpnEev9D.js.map +1 -0
  123. package/dist/ref-Bu7PoHar.js +22 -0
  124. package/dist/ref-Bu7PoHar.js.map +1 -0
  125. package/dist/ref-P0ZLT1Bg.cjs +39 -0
  126. package/dist/ref-P0ZLT1Bg.cjs.map +1 -0
  127. package/dist/ref.cjs +7 -0
  128. package/dist/ref.d.cts +2 -0
  129. package/dist/ref.d.ts +2 -0
  130. package/dist/ref.js +3 -0
  131. package/dist/refs-CYHpRlQo.cjs +131 -0
  132. package/dist/refs-CYHpRlQo.cjs.map +1 -0
  133. package/dist/refs-YCV3CznS.js +102 -0
  134. package/dist/refs-YCV3CznS.js.map +1 -0
  135. package/dist/rolldown-runtime-BV8xUvPy.cjs +52 -0
  136. package/dist/rolldown-runtime-BYyVTPww.js +16 -0
  137. package/dist/schema-2ZAQk7qE.js +44 -0
  138. package/dist/schema-2ZAQk7qE.js.map +1 -0
  139. package/dist/schema-BIErWqgc.cjs +214 -0
  140. package/dist/schema-BIErWqgc.cjs.map +1 -0
  141. package/dist/schema-DloctnMm.js +179 -0
  142. package/dist/schema-DloctnMm.js.map +1 -0
  143. package/dist/schema-hxMlgCrV.cjs +49 -0
  144. package/dist/schema-hxMlgCrV.cjs.map +1 -0
  145. package/dist/schema.cjs +16 -0
  146. package/dist/schema.d.cts +5 -0
  147. package/dist/schema.d.ts +5 -0
  148. package/dist/schema.js +6 -0
  149. package/dist/visitor-BZozlXBF.d.ts +179 -0
  150. package/dist/visitor-Bw_opzjF.d.cts +179 -0
  151. package/dist/visitor-DTrzvA3R.cjs +382 -0
  152. package/dist/visitor-DTrzvA3R.cjs.map +1 -0
  153. package/dist/visitor-NoQSUQTu.js +347 -0
  154. package/dist/visitor-NoQSUQTu.js.map +1 -0
  155. package/package.json +101 -1
@@ -0,0 +1,179 @@
1
+ import { t as Node } from "./index-BwnMIoLl.js";
2
+ import { H as SchemaNode, T as InputNode, X as PropertyNode, i as OperationNode, p as ParameterNode, s as ResponseNode } from "./operation-BgRyVS7z.js";
3
+ /**
4
+ * Traversal depth for AST visitor utilities.
5
+ *
6
+ * - `'shallow'` recurses through every node except nested `Schema` subtrees, which it treats as
7
+ * leaves: a schema node itself is visited, but its children are not.
8
+ * - `'deep'` recursively visits all descendant nodes, including schema subtrees.
9
+ */
10
+ type VisitorDepth = 'shallow' | 'deep';
11
+ /**
12
+ * Traversal context passed as the second argument to every visitor callback.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const visitor: Visitor = {
17
+ * schema(node, { parent }) {
18
+ * // parent is the node that holds this schema, or undefined at the root
19
+ * },
20
+ * }
21
+ * ```
22
+ */
23
+ type VisitorContext = {
24
+ /**
25
+ * Parent node of the currently visited node. For the root node, this is `undefined`.
26
+ */
27
+ parent?: Node;
28
+ };
29
+ /**
30
+ * Synchronous visitor consumed by `transform`. Each optional callback runs
31
+ * for the matching node type. Return a new node to replace it, or `undefined`
32
+ * to leave it untouched.
33
+ *
34
+ * Plugins typically expose `transformer` so users can supply a `Visitor` that
35
+ * rewrites the AST before printing.
36
+ *
37
+ * @example Prefix every operationId
38
+ * ```ts
39
+ * const visitor: Visitor = {
40
+ * operation(node) {
41
+ * return { ...node, operationId: `api_${node.operationId}` }
42
+ * },
43
+ * }
44
+ * ```
45
+ *
46
+ * @example Strip schema descriptions
47
+ * ```ts
48
+ * const visitor: Visitor = {
49
+ * schema(node) {
50
+ * return { ...node, description: undefined }
51
+ * },
52
+ * }
53
+ * ```
54
+ */
55
+ type Visitor = {
56
+ input?(node: InputNode, context: VisitorContext): undefined | null | InputNode;
57
+ operation?(node: OperationNode, context: VisitorContext): undefined | null | OperationNode;
58
+ schema?(node: SchemaNode, context: VisitorContext): undefined | null | SchemaNode;
59
+ property?(node: PropertyNode, context: VisitorContext): undefined | null | PropertyNode;
60
+ parameter?(node: ParameterNode, context: VisitorContext): undefined | null | ParameterNode;
61
+ response?(node: ResponseNode, context: VisitorContext): undefined | null | ResponseNode;
62
+ };
63
+ /**
64
+ * The callbacks of {@link Visitor} with every return type replaced by `TResult`. `collect` uses it
65
+ * so a visitor can yield values instead of replacement nodes.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * const visitor: VisitorOf<string> = {
70
+ * operation(node) {
71
+ * return node.operationId
72
+ * },
73
+ * }
74
+ * ```
75
+ */
76
+ type VisitorOf<TResult> = { [K in keyof Visitor]?: (node: Parameters<NonNullable<Visitor[K]>>[0], context: Parameters<NonNullable<Visitor[K]>>[1]) => TResult | null | undefined; };
77
+ type TraversalOptions = {
78
+ /**
79
+ * Traversal depth.
80
+ * @default 'deep'
81
+ */
82
+ depth?: VisitorDepth;
83
+ /**
84
+ * Internal parent override used during recursion.
85
+ */
86
+ parent?: Node;
87
+ };
88
+ /**
89
+ * Options for `transform`.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * const options: TransformOptions = { depth: 'deep', schema: (node) => node }
94
+ * ```
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * // Only transform the current node, not nested children
99
+ * const options: TransformOptions = { depth: 'shallow', schema: (node) => node }
100
+ * ```
101
+ */
102
+ type TransformOptions = Visitor & TraversalOptions;
103
+ /**
104
+ * Options for `collect`.
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * const options: CollectOptions<string> = { depth: 'shallow', schema: () => undefined }
109
+ * ```
110
+ */
111
+ type CollectOptions<T> = VisitorOf<T> & TraversalOptions;
112
+ /**
113
+ * Finds the first schema that matches `predicate` in depth-first order. Pass `follow: ['ref']` to include resolved ref targets.
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * const firstString = findSchema(operationNode, {
118
+ * predicate: (schema) => schema.type === 'string',
119
+ * })
120
+ * ```
121
+ */
122
+ declare function findSchema(node: Node, { predicate, follow, followRefs, cache }: {
123
+ predicate: (schema: SchemaNode) => boolean;
124
+ /**
125
+ * Links to follow on top of the walk over every child. `['ref']` also walks a resolved ref's target.
126
+ * @default []
127
+ */
128
+ follow?: ReadonlyArray<'ref'>;
129
+ /**
130
+ * @deprecated Use `follow: ['ref']`. Removed in Kubb v6.
131
+ */
132
+ followRefs?: boolean;
133
+ /**
134
+ * Remembers the match below each schema (`null` for none), so later calls skip the parts of the graph they share.
135
+ * Keep one cache per `predicate` and ref-following mode (`follow`, or the deprecated `followRefs`), for example one per build.
136
+ * In a cyclic graph, a cached call can return a different match than the first one in depth-first order.
137
+ */
138
+ cache?: WeakMap<SchemaNode, SchemaNode | null>;
139
+ }): SchemaNode | undefined;
140
+ /**
141
+ * Synchronous depth-first transform. Each visitor callback can return a
142
+ * replacement node. Returning `undefined` keeps the original.
143
+ *
144
+ * The original tree is never mutated, a new tree is returned. Pass
145
+ * `depth: 'shallow'` to skip the children of every schema node; other nodes are still walked.
146
+ *
147
+ * @example Prefix every operationId
148
+ * ```ts
149
+ * const next = transform(root, {
150
+ * operation(node) {
151
+ * return { ...node, operationId: `prefixed_${node.operationId}` }
152
+ * },
153
+ * })
154
+ * ```
155
+ *
156
+ * @example Rewrite the root node without walking its schemas
157
+ * ```ts
158
+ * const next = transform(root, {
159
+ * depth: 'shallow',
160
+ * input: (node) => ({ ...node, meta: { ...node.meta, title: 'Rewritten' } }),
161
+ * })
162
+ * ```
163
+ */
164
+ declare function transform<T extends Node>(node: T, options: TransformOptions): T;
165
+ /**
166
+ * Depth-first collection pass. Gathers every non-null value the visitor
167
+ * callbacks return into an array.
168
+ *
169
+ * @example Collect every operationId
170
+ * ```ts
171
+ * const ids = collect<string>(root, {
172
+ * operation(node) {
173
+ * return node.operationId
174
+ * },
175
+ * })
176
+ * ```
177
+ */
178
+ declare function collect<T>(node: Node, options: CollectOptions<T>): Array<T>;
179
+ export { findSchema as a, collect as i, VisitorContext as n, transform as o, VisitorDepth as r, Visitor as t };
@@ -0,0 +1,179 @@
1
+ import { t as Node } from "./index-DSVef1pp.cjs";
2
+ import { H as SchemaNode, T as InputNode, X as PropertyNode, i as OperationNode, p as ParameterNode, s as ResponseNode } from "./operation-X7chCdL2.cjs";
3
+ /**
4
+ * Traversal depth for AST visitor utilities.
5
+ *
6
+ * - `'shallow'` recurses through every node except nested `Schema` subtrees, which it treats as
7
+ * leaves: a schema node itself is visited, but its children are not.
8
+ * - `'deep'` recursively visits all descendant nodes, including schema subtrees.
9
+ */
10
+ type VisitorDepth = 'shallow' | 'deep';
11
+ /**
12
+ * Traversal context passed as the second argument to every visitor callback.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const visitor: Visitor = {
17
+ * schema(node, { parent }) {
18
+ * // parent is the node that holds this schema, or undefined at the root
19
+ * },
20
+ * }
21
+ * ```
22
+ */
23
+ type VisitorContext = {
24
+ /**
25
+ * Parent node of the currently visited node. For the root node, this is `undefined`.
26
+ */
27
+ parent?: Node;
28
+ };
29
+ /**
30
+ * Synchronous visitor consumed by `transform`. Each optional callback runs
31
+ * for the matching node type. Return a new node to replace it, or `undefined`
32
+ * to leave it untouched.
33
+ *
34
+ * Plugins typically expose `transformer` so users can supply a `Visitor` that
35
+ * rewrites the AST before printing.
36
+ *
37
+ * @example Prefix every operationId
38
+ * ```ts
39
+ * const visitor: Visitor = {
40
+ * operation(node) {
41
+ * return { ...node, operationId: `api_${node.operationId}` }
42
+ * },
43
+ * }
44
+ * ```
45
+ *
46
+ * @example Strip schema descriptions
47
+ * ```ts
48
+ * const visitor: Visitor = {
49
+ * schema(node) {
50
+ * return { ...node, description: undefined }
51
+ * },
52
+ * }
53
+ * ```
54
+ */
55
+ type Visitor = {
56
+ input?(node: InputNode, context: VisitorContext): undefined | null | InputNode;
57
+ operation?(node: OperationNode, context: VisitorContext): undefined | null | OperationNode;
58
+ schema?(node: SchemaNode, context: VisitorContext): undefined | null | SchemaNode;
59
+ property?(node: PropertyNode, context: VisitorContext): undefined | null | PropertyNode;
60
+ parameter?(node: ParameterNode, context: VisitorContext): undefined | null | ParameterNode;
61
+ response?(node: ResponseNode, context: VisitorContext): undefined | null | ResponseNode;
62
+ };
63
+ /**
64
+ * The callbacks of {@link Visitor} with every return type replaced by `TResult`. `collect` uses it
65
+ * so a visitor can yield values instead of replacement nodes.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * const visitor: VisitorOf<string> = {
70
+ * operation(node) {
71
+ * return node.operationId
72
+ * },
73
+ * }
74
+ * ```
75
+ */
76
+ type VisitorOf<TResult> = { [K in keyof Visitor]?: (node: Parameters<NonNullable<Visitor[K]>>[0], context: Parameters<NonNullable<Visitor[K]>>[1]) => TResult | null | undefined; };
77
+ type TraversalOptions = {
78
+ /**
79
+ * Traversal depth.
80
+ * @default 'deep'
81
+ */
82
+ depth?: VisitorDepth;
83
+ /**
84
+ * Internal parent override used during recursion.
85
+ */
86
+ parent?: Node;
87
+ };
88
+ /**
89
+ * Options for `transform`.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * const options: TransformOptions = { depth: 'deep', schema: (node) => node }
94
+ * ```
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * // Only transform the current node, not nested children
99
+ * const options: TransformOptions = { depth: 'shallow', schema: (node) => node }
100
+ * ```
101
+ */
102
+ type TransformOptions = Visitor & TraversalOptions;
103
+ /**
104
+ * Options for `collect`.
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * const options: CollectOptions<string> = { depth: 'shallow', schema: () => undefined }
109
+ * ```
110
+ */
111
+ type CollectOptions<T> = VisitorOf<T> & TraversalOptions;
112
+ /**
113
+ * Finds the first schema that matches `predicate` in depth-first order. Pass `follow: ['ref']` to include resolved ref targets.
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * const firstString = findSchema(operationNode, {
118
+ * predicate: (schema) => schema.type === 'string',
119
+ * })
120
+ * ```
121
+ */
122
+ declare function findSchema(node: Node, { predicate, follow, followRefs, cache }: {
123
+ predicate: (schema: SchemaNode) => boolean;
124
+ /**
125
+ * Links to follow on top of the walk over every child. `['ref']` also walks a resolved ref's target.
126
+ * @default []
127
+ */
128
+ follow?: ReadonlyArray<'ref'>;
129
+ /**
130
+ * @deprecated Use `follow: ['ref']`. Removed in Kubb v6.
131
+ */
132
+ followRefs?: boolean;
133
+ /**
134
+ * Remembers the match below each schema (`null` for none), so later calls skip the parts of the graph they share.
135
+ * Keep one cache per `predicate` and ref-following mode (`follow`, or the deprecated `followRefs`), for example one per build.
136
+ * In a cyclic graph, a cached call can return a different match than the first one in depth-first order.
137
+ */
138
+ cache?: WeakMap<SchemaNode, SchemaNode | null>;
139
+ }): SchemaNode | undefined;
140
+ /**
141
+ * Synchronous depth-first transform. Each visitor callback can return a
142
+ * replacement node. Returning `undefined` keeps the original.
143
+ *
144
+ * The original tree is never mutated, a new tree is returned. Pass
145
+ * `depth: 'shallow'` to skip the children of every schema node; other nodes are still walked.
146
+ *
147
+ * @example Prefix every operationId
148
+ * ```ts
149
+ * const next = transform(root, {
150
+ * operation(node) {
151
+ * return { ...node, operationId: `prefixed_${node.operationId}` }
152
+ * },
153
+ * })
154
+ * ```
155
+ *
156
+ * @example Rewrite the root node without walking its schemas
157
+ * ```ts
158
+ * const next = transform(root, {
159
+ * depth: 'shallow',
160
+ * input: (node) => ({ ...node, meta: { ...node.meta, title: 'Rewritten' } }),
161
+ * })
162
+ * ```
163
+ */
164
+ declare function transform<T extends Node>(node: T, options: TransformOptions): T;
165
+ /**
166
+ * Depth-first collection pass. Gathers every non-null value the visitor
167
+ * callbacks return into an array.
168
+ *
169
+ * @example Collect every operationId
170
+ * ```ts
171
+ * const ids = collect<string>(root, {
172
+ * operation(node) {
173
+ * return node.operationId
174
+ * },
175
+ * })
176
+ * ```
177
+ */
178
+ declare function collect<T>(node: Node, options: CollectOptions<T>): Array<T>;
179
+ export { findSchema as a, collect as i, VisitorContext as n, transform as o, VisitorDepth as r, Visitor as t };