@kubb/ast 5.0.0-beta.61 → 5.0.0-beta.63
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/{defineMacro-BLIR6k-j.d.ts → defineMacro-BATi7xoC.d.ts} +11 -20
- package/dist/{defineMacro-Bv9R_9a2.cjs → defineMacro-CEZHaCXE.cjs} +13 -21
- package/dist/defineMacro-CEZHaCXE.cjs.map +1 -0
- package/dist/{defineMacro-BTXvS8nI.js → defineMacro-Shz8f6SG.js} +12 -19
- package/dist/defineMacro-Shz8f6SG.js.map +1 -0
- package/dist/factory.cjs +88 -28
- package/dist/factory.cjs.map +1 -0
- package/dist/factory.d.ts +6 -41
- package/dist/factory.js +58 -3
- package/dist/factory.js.map +1 -0
- package/dist/{index-BzjwdK2M.d.ts → index-B9cc8MBS.d.ts} +164 -194
- package/dist/index.cjs +144 -274
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +43 -37
- package/dist/index.js +109 -235
- package/dist/index.js.map +1 -1
- package/dist/macros.cjs +41 -28
- package/dist/macros.cjs.map +1 -1
- package/dist/macros.d.ts +14 -12
- package/dist/macros.js +34 -21
- package/dist/macros.js.map +1 -1
- package/dist/{operationParams-BZ07xDm0.d.ts → operationParams-k5CKwSWZ.d.ts} +9 -2
- package/dist/{visitor-DJ6ZEJvq.js → refs-BjNDuCBD.js} +116 -159
- package/dist/refs-BjNDuCBD.js.map +1 -0
- package/dist/{visitor-DpKZ9Tk0.cjs → refs-u5SDdyV7.cjs} +140 -195
- package/dist/refs-u5SDdyV7.cjs.map +1 -0
- package/dist/{response-hnSw2NKE.cjs → schema-BkvrrOAr.cjs} +496 -231
- package/dist/schema-BkvrrOAr.cjs.map +1 -0
- package/dist/{response-KUdWiDWw.js → schema-Cbnxmz4b.js} +472 -220
- package/dist/schema-Cbnxmz4b.js.map +1 -0
- package/dist/{types-DyDzizSf.d.ts → types-BB_xgRJ3.d.ts} +49 -123
- package/dist/types.d.ts +5 -6
- package/dist/{utils-BLJwyza-.cjs → utils-CEepwqmb.cjs} +76 -69
- package/dist/utils-CEepwqmb.cjs.map +1 -0
- package/dist/{utils-CF_-Pn_c.js → utils-DaXkewb1.js} +58 -51
- package/dist/utils-DaXkewb1.js.map +1 -0
- package/dist/utils.cjs +11 -11
- package/dist/utils.d.ts +53 -30
- package/dist/utils.js +3 -3
- package/package.json +1 -1
- package/src/constants.ts +3 -36
- package/src/defineMacro.ts +20 -13
- package/src/{node.ts → defineNode.ts} +12 -38
- package/src/{printer.ts → definePrinter.ts} +5 -3
- package/src/dialect.ts +52 -19
- package/src/factory.ts +7 -94
- package/src/index.ts +7 -9
- package/src/infer.ts +1 -1
- package/src/macros/macroDiscriminatorEnum.ts +7 -1
- package/src/macros/macroEnumName.ts +10 -2
- package/src/macros/macroSimplifyUnion.ts +29 -19
- package/src/nodes/code.ts +40 -80
- package/src/nodes/content.ts +2 -7
- package/src/nodes/file.ts +107 -18
- package/src/nodes/function.ts +46 -46
- package/src/nodes/index.ts +2 -3
- package/src/nodes/input.ts +13 -9
- package/src/nodes/operation.ts +8 -5
- package/src/nodes/output.ts +1 -1
- package/src/nodes/parameter.ts +5 -5
- package/src/nodes/property.ts +5 -5
- package/src/nodes/requestBody.ts +6 -13
- package/src/nodes/response.ts +93 -8
- package/src/nodes/schema.ts +5 -5
- package/src/optionality.ts +15 -0
- package/src/registry.ts +1 -1
- package/src/types.ts +4 -6
- package/src/utils/codegen.ts +6 -7
- package/src/utils/extractStringsFromNodes.ts +1 -0
- package/src/utils/fileMerge.ts +7 -8
- package/src/utils/operationParams.ts +9 -9
- package/src/utils/refs.ts +14 -18
- package/src/utils/schemaGraph.ts +41 -33
- package/src/utils/schemaMerge.ts +2 -2
- package/src/visitor.ts +3 -14
- package/dist/defineMacro-BTXvS8nI.js.map +0 -1
- package/dist/defineMacro-Bv9R_9a2.cjs.map +0 -1
- package/dist/extractStringsFromNodes-Cja-xxx5.js +0 -29
- package/dist/extractStringsFromNodes-Cja-xxx5.js.map +0 -1
- package/dist/extractStringsFromNodes-DKgDjFO0.cjs +0 -34
- package/dist/extractStringsFromNodes-DKgDjFO0.cjs.map +0 -1
- package/dist/extractStringsFromNodes-p4mX1TQD.d.ts +0 -14
- package/dist/factory-CZNOGI-N.js +0 -283
- package/dist/factory-CZNOGI-N.js.map +0 -1
- package/dist/factory-DG1CVkEb.cjs +0 -300
- package/dist/factory-DG1CVkEb.cjs.map +0 -1
- package/dist/response-KUdWiDWw.js.map +0 -1
- package/dist/response-hnSw2NKE.cjs.map +0 -1
- package/dist/utils-BLJwyza-.cjs.map +0 -1
- package/dist/utils-CF_-Pn_c.js.map +0 -1
- package/dist/visitor-DJ6ZEJvq.js.map +0 -1
- package/dist/visitor-DpKZ9Tk0.cjs.map +0 -1
- package/src/dedupe.ts +0 -239
- package/src/mocks.ts +0 -56
- package/src/nodes/http.ts +0 -85
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_schema = require("./schema-BkvrrOAr.cjs");
|
|
2
2
|
//#region src/constants.ts
|
|
3
3
|
const visitorDepths = {
|
|
4
4
|
shallow: "shallow",
|
|
@@ -8,7 +8,6 @@ const visitorDepths = {
|
|
|
8
8
|
* Schema type discriminators used by all AST schema nodes.
|
|
9
9
|
*
|
|
10
10
|
* Each value is a stable discriminator across the AST (for example `schema.type === schemaTypes.object`).
|
|
11
|
-
* Call `isScalarPrimitive()` to check for the scalar types.
|
|
12
11
|
*/
|
|
13
12
|
const schemaTypes = {
|
|
14
13
|
/**
|
|
@@ -117,36 +116,6 @@ const schemaTypes = {
|
|
|
117
116
|
never: "never"
|
|
118
117
|
};
|
|
119
118
|
/**
|
|
120
|
-
* Scalar primitive schema types used for union simplification and type narrowing.
|
|
121
|
-
*/
|
|
122
|
-
const SCALAR_PRIMITIVE_TYPES = new Set([
|
|
123
|
-
"string",
|
|
124
|
-
"number",
|
|
125
|
-
"integer",
|
|
126
|
-
"bigint",
|
|
127
|
-
"boolean"
|
|
128
|
-
]);
|
|
129
|
-
/**
|
|
130
|
-
* Returns `true` when `type` is a scalar primitive that can be assigned without wrapping
|
|
131
|
-
* (for example `string | number | boolean`).
|
|
132
|
-
*/
|
|
133
|
-
function isScalarPrimitive(type) {
|
|
134
|
-
return SCALAR_PRIMITIVE_TYPES.has(type);
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* HTTP method identifiers used by operation nodes.
|
|
138
|
-
*/
|
|
139
|
-
const httpMethods = {
|
|
140
|
-
get: "GET",
|
|
141
|
-
post: "POST",
|
|
142
|
-
put: "PUT",
|
|
143
|
-
patch: "PATCH",
|
|
144
|
-
delete: "DELETE",
|
|
145
|
-
head: "HEAD",
|
|
146
|
-
options: "OPTIONS",
|
|
147
|
-
trace: "TRACE"
|
|
148
|
-
};
|
|
149
|
-
/**
|
|
150
119
|
* One indentation level, derived from {@link INDENT_SIZE}.
|
|
151
120
|
*/
|
|
152
121
|
const INDENT = Array.from({ length: 2 }, () => " ").join("");
|
|
@@ -178,153 +147,37 @@ function isHttpOperationNode(node) {
|
|
|
178
147
|
return node.protocol === "http" || node.method !== void 0 && node.path !== void 0;
|
|
179
148
|
}
|
|
180
149
|
//#endregion
|
|
181
|
-
//#region src/utils/refs.ts
|
|
182
|
-
const plainStringTypes = new Set([
|
|
183
|
-
"string",
|
|
184
|
-
"uuid",
|
|
185
|
-
"email",
|
|
186
|
-
"url",
|
|
187
|
-
"datetime"
|
|
188
|
-
]);
|
|
189
|
-
/**
|
|
190
|
-
* Returns the last path segment of a reference string.
|
|
191
|
-
*
|
|
192
|
-
* @example
|
|
193
|
-
* ```ts
|
|
194
|
-
* extractRefName('#/components/schemas/Pet') // 'Pet'
|
|
195
|
-
* ```
|
|
196
|
-
*/
|
|
197
|
-
function extractRefName(ref) {
|
|
198
|
-
return ref.split("/").at(-1) ?? ref;
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Resolves the schema name of a ref node, falling back through `ref` → `name` → nested `schema.name`.
|
|
202
|
-
*
|
|
203
|
-
* Returns `null` for non-ref nodes or when no name resolves.
|
|
204
|
-
*
|
|
205
|
-
* @example
|
|
206
|
-
* ```ts
|
|
207
|
-
* resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' })
|
|
208
|
-
* // => 'Pet'
|
|
209
|
-
* ```
|
|
210
|
-
*/
|
|
211
|
-
function resolveRefName(node) {
|
|
212
|
-
if (!node || node.type !== "ref") return null;
|
|
213
|
-
if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null;
|
|
214
|
-
return node.name ?? node.schema?.name ?? null;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Builds a PascalCase child schema name by joining a parent name and property name.
|
|
218
|
-
* Returns `null` when there is no parent to nest under.
|
|
219
|
-
*
|
|
220
|
-
* @example
|
|
221
|
-
* ```ts
|
|
222
|
-
* childName('Order', 'shipping_address') // 'OrderShippingAddress'
|
|
223
|
-
* childName(undefined, 'params') // null
|
|
224
|
-
* ```
|
|
225
|
-
*/
|
|
226
|
-
function childName(parentName, propName) {
|
|
227
|
-
return parentName ? require_response.pascalCase([parentName, propName].join(" ")) : null;
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any
|
|
231
|
-
* empty parts.
|
|
232
|
-
*
|
|
233
|
-
* @example
|
|
234
|
-
* ```ts
|
|
235
|
-
* enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'
|
|
236
|
-
* ```
|
|
237
|
-
*/
|
|
238
|
-
function enumPropName(parentName, propName, enumSuffix) {
|
|
239
|
-
return require_response.pascalCase([
|
|
240
|
-
parentName,
|
|
241
|
-
propName,
|
|
242
|
-
enumSuffix
|
|
243
|
-
].filter(Boolean).join(" "));
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Merges a ref node with its resolved schema, giving usage-site fields precedence.
|
|
247
|
-
*
|
|
248
|
-
* Usage-site fields (`description`, `readOnly`, `nullable`, `deprecated`) on the ref node override
|
|
249
|
-
* the same fields in the resolved `node.schema`. Non-ref nodes are returned unchanged.
|
|
250
|
-
*
|
|
251
|
-
* @example
|
|
252
|
-
* ```ts
|
|
253
|
-
* const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })
|
|
254
|
-
* const merged = syncSchemaRef(ref) // merges with resolved Pet schema
|
|
255
|
-
* ```
|
|
256
|
-
*/
|
|
257
|
-
function syncSchemaRef(node) {
|
|
258
|
-
const ref = narrowSchema(node, "ref");
|
|
259
|
-
if (!ref) return node;
|
|
260
|
-
if (!ref.schema) return node;
|
|
261
|
-
const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref;
|
|
262
|
-
const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== void 0));
|
|
263
|
-
return require_response.createSchema({
|
|
264
|
-
...ref.schema,
|
|
265
|
-
...definedOverrides
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Type guard that returns `true` when a schema emits as a plain `string` type.
|
|
270
|
-
*
|
|
271
|
-
* Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`
|
|
272
|
-
* types, returns `true` only when `representation` is `'string'` rather than `'date'`.
|
|
273
|
-
*/
|
|
274
|
-
function isStringType(node) {
|
|
275
|
-
if (plainStringTypes.has(node.type)) return true;
|
|
276
|
-
const temporal = narrowSchema(node, "date") ?? narrowSchema(node, "time");
|
|
277
|
-
if (temporal) return temporal.representation !== "date";
|
|
278
|
-
return false;
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Derives a {@link ParamGroupType} for a query or header group from the resolver.
|
|
282
|
-
*
|
|
283
|
-
* Returns `null` when there is no resolver, no params, or the group name equals the
|
|
284
|
-
* individual param name (so there is no real group to emit).
|
|
285
|
-
*/
|
|
286
|
-
function resolveGroupType({ node, params, group, resolver }) {
|
|
287
|
-
if (!resolver || !params.length) return null;
|
|
288
|
-
const firstParam = params[0];
|
|
289
|
-
const groupName = (group === "query" ? resolver.resolveQueryParamsName : resolver.resolveHeaderParamsName).call(resolver, node, firstParam);
|
|
290
|
-
if (groupName === resolver.resolveParamName(node, firstParam)) return null;
|
|
291
|
-
return {
|
|
292
|
-
type: groupName,
|
|
293
|
-
optional: params.every((p) => !p.required)
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
//#endregion
|
|
297
150
|
//#region src/registry.ts
|
|
298
151
|
/**
|
|
299
152
|
* Every node definition. Adding a node means adding its `defineNode` to one
|
|
300
153
|
* `nodes/*.ts` file and listing it here. The visitor tables in `visitor.ts` derive from it.
|
|
301
154
|
*/
|
|
302
155
|
const nodeDefs = [
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
156
|
+
require_schema.inputDef,
|
|
157
|
+
require_schema.outputDef,
|
|
158
|
+
require_schema.operationDef,
|
|
159
|
+
require_schema.requestBodyDef,
|
|
160
|
+
require_schema.contentDef,
|
|
161
|
+
require_schema.responseDef,
|
|
162
|
+
require_schema.schemaDef,
|
|
163
|
+
require_schema.propertyDef,
|
|
164
|
+
require_schema.parameterDef,
|
|
165
|
+
require_schema.functionParameterDef,
|
|
166
|
+
require_schema.functionParametersDef,
|
|
167
|
+
require_schema.typeLiteralDef,
|
|
168
|
+
require_schema.indexedAccessTypeDef,
|
|
169
|
+
require_schema.objectBindingPatternDef,
|
|
170
|
+
require_schema.constDef,
|
|
171
|
+
require_schema.typeDef,
|
|
172
|
+
require_schema.functionDef,
|
|
173
|
+
require_schema.arrowFunctionDef,
|
|
174
|
+
require_schema.textDef,
|
|
175
|
+
require_schema.breakDef,
|
|
176
|
+
require_schema.jsxDef,
|
|
177
|
+
require_schema.importDef,
|
|
178
|
+
require_schema.exportDef,
|
|
179
|
+
require_schema.sourceDef,
|
|
180
|
+
require_schema.fileDef
|
|
328
181
|
];
|
|
329
182
|
//#endregion
|
|
330
183
|
//#region src/visitor.ts
|
|
@@ -339,11 +192,6 @@ const VISITOR_KEYS = Object.fromEntries(nodeDefs.flatMap((def) => def.children ?
|
|
|
339
192
|
*/
|
|
340
193
|
const VISITOR_KEY_BY_KIND = Object.fromEntries(nodeDefs.flatMap((def) => def.visitorKey ? [[def.kind, def.visitorKey]] : []));
|
|
341
194
|
/**
|
|
342
|
-
* Per-kind builders rerun after children are rebuilt. Derived from each
|
|
343
|
-
* definition's `rebuild` flag.
|
|
344
|
-
*/
|
|
345
|
-
const nodeRebuilders = Object.fromEntries(nodeDefs.flatMap((def) => def.rebuild ? [[def.kind, def.create]] : []));
|
|
346
|
-
/**
|
|
347
195
|
* Creates a small async concurrency limiter.
|
|
348
196
|
*
|
|
349
197
|
* At most `concurrency` tasks are in flight at once. Extra tasks are queued.
|
|
@@ -457,10 +305,7 @@ async function _walk(node, visitor, recurse, limit, parent) {
|
|
|
457
305
|
function transform(node, options) {
|
|
458
306
|
const { depth, parent, ...visitor } = options;
|
|
459
307
|
const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep;
|
|
460
|
-
|
|
461
|
-
if (rebuilt === node) return node;
|
|
462
|
-
const rebuild = nodeRebuilders[rebuilt.kind];
|
|
463
|
-
return rebuild ? rebuild(rebuilt) : rebuilt;
|
|
308
|
+
return transformChildren(applyVisitor(node, visitor, parent) ?? node, options, recurse);
|
|
464
309
|
}
|
|
465
310
|
/**
|
|
466
311
|
* Immutably rebuilds a node's children using {@link VISITOR_KEYS}, transforming
|
|
@@ -542,6 +387,118 @@ function collect(node, options) {
|
|
|
542
387
|
return Array.from(collectLazy(node, options));
|
|
543
388
|
}
|
|
544
389
|
//#endregion
|
|
390
|
+
//#region src/utils/refs.ts
|
|
391
|
+
const plainStringTypes = new Set([
|
|
392
|
+
"string",
|
|
393
|
+
"uuid",
|
|
394
|
+
"email",
|
|
395
|
+
"url",
|
|
396
|
+
"datetime"
|
|
397
|
+
]);
|
|
398
|
+
/**
|
|
399
|
+
* Returns the last path segment of a reference string.
|
|
400
|
+
*
|
|
401
|
+
* @example
|
|
402
|
+
* `extractRefName('#/components/schemas/Pet') // 'Pet'`
|
|
403
|
+
*/
|
|
404
|
+
function extractRefName(ref) {
|
|
405
|
+
return ref.split("/").at(-1) ?? ref;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Resolves the schema name of a ref node. Uses the last segment of `ref` when set, otherwise falls
|
|
409
|
+
* back to `name` then nested `schema.name`.
|
|
410
|
+
*
|
|
411
|
+
* Returns `null` for non-ref nodes or when no name resolves.
|
|
412
|
+
*
|
|
413
|
+
* @example
|
|
414
|
+
* `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'`
|
|
415
|
+
*/
|
|
416
|
+
function resolveRefName(node) {
|
|
417
|
+
if (!node || node.type !== "ref") return null;
|
|
418
|
+
if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null;
|
|
419
|
+
return node.name ?? node.schema?.name ?? null;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Builds a PascalCase child schema name by joining a parent name and property name.
|
|
423
|
+
* Returns `null` when there is no parent to nest under.
|
|
424
|
+
*
|
|
425
|
+
* @example Nested under a parent
|
|
426
|
+
* `childName('Order', 'shipping_address') // 'OrderShippingAddress'`
|
|
427
|
+
*
|
|
428
|
+
* @example No parent
|
|
429
|
+
* `childName(undefined, 'params') // null`
|
|
430
|
+
*/
|
|
431
|
+
function childName(parentName, propName) {
|
|
432
|
+
return parentName ? require_schema.pascalCase([parentName, propName].join(" ")) : null;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any
|
|
436
|
+
* empty parts.
|
|
437
|
+
*
|
|
438
|
+
* @example
|
|
439
|
+
* `enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'`
|
|
440
|
+
*/
|
|
441
|
+
function enumPropName(parentName, propName, enumSuffix) {
|
|
442
|
+
return require_schema.pascalCase([
|
|
443
|
+
parentName,
|
|
444
|
+
propName,
|
|
445
|
+
enumSuffix
|
|
446
|
+
].filter(Boolean).join(" "));
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Merges a ref node with its resolved schema, giving usage-site fields precedence.
|
|
450
|
+
*
|
|
451
|
+
* Every field set on the ref node except `kind`, `type`, `name`, `ref`, and `schema` overrides the
|
|
452
|
+
* same field in the resolved `node.schema` (for example `description`, `nullable`, `readOnly`,
|
|
453
|
+
* `deprecated`). Fields left `undefined` on the ref do not shadow the resolved schema. Non-ref
|
|
454
|
+
* nodes and refs without a resolved `schema` are returned unchanged.
|
|
455
|
+
*
|
|
456
|
+
* @example
|
|
457
|
+
* ```ts
|
|
458
|
+
* const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })
|
|
459
|
+
* const merged = syncSchemaRef(ref) // merges with resolved Pet schema
|
|
460
|
+
* ```
|
|
461
|
+
*/
|
|
462
|
+
function syncSchemaRef(node) {
|
|
463
|
+
const ref = narrowSchema(node, "ref");
|
|
464
|
+
if (!ref) return node;
|
|
465
|
+
if (!ref.schema) return node;
|
|
466
|
+
const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref;
|
|
467
|
+
const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== void 0));
|
|
468
|
+
return require_schema.createSchema({
|
|
469
|
+
...ref.schema,
|
|
470
|
+
...definedOverrides
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Type guard that returns `true` when a schema emits as a plain `string` type.
|
|
475
|
+
*
|
|
476
|
+
* Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`
|
|
477
|
+
* types, returns `true` only when `representation` is `'string'` rather than `'date'`.
|
|
478
|
+
*/
|
|
479
|
+
function isStringType(node) {
|
|
480
|
+
if (plainStringTypes.has(node.type)) return true;
|
|
481
|
+
const temporal = narrowSchema(node, "date") ?? narrowSchema(node, "time");
|
|
482
|
+
if (temporal) return temporal.representation !== "date";
|
|
483
|
+
return false;
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Derives a {@link ParamGroupType} for a query or header group from the resolver.
|
|
487
|
+
*
|
|
488
|
+
* Returns `null` when there is no resolver, no params, or the group name equals the
|
|
489
|
+
* individual param name (so there is no real group to emit).
|
|
490
|
+
*/
|
|
491
|
+
function resolveGroupType({ node, params, group, resolver }) {
|
|
492
|
+
if (!resolver || !params.length) return null;
|
|
493
|
+
const firstParam = params[0];
|
|
494
|
+
const groupName = (group === "query" ? resolver.resolveQueryParamsName : resolver.resolveHeaderParamsName).call(resolver, node, firstParam);
|
|
495
|
+
if (groupName === resolver.resolveParamName(node, firstParam)) return null;
|
|
496
|
+
return {
|
|
497
|
+
type: groupName,
|
|
498
|
+
optional: params.every((p) => !p.required)
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
//#endregion
|
|
545
502
|
Object.defineProperty(exports, "INDENT", {
|
|
546
503
|
enumerable: true,
|
|
547
504
|
get: function() {
|
|
@@ -578,24 +535,12 @@ Object.defineProperty(exports, "extractRefName", {
|
|
|
578
535
|
return extractRefName;
|
|
579
536
|
}
|
|
580
537
|
});
|
|
581
|
-
Object.defineProperty(exports, "httpMethods", {
|
|
582
|
-
enumerable: true,
|
|
583
|
-
get: function() {
|
|
584
|
-
return httpMethods;
|
|
585
|
-
}
|
|
586
|
-
});
|
|
587
538
|
Object.defineProperty(exports, "isHttpOperationNode", {
|
|
588
539
|
enumerable: true,
|
|
589
540
|
get: function() {
|
|
590
541
|
return isHttpOperationNode;
|
|
591
542
|
}
|
|
592
543
|
});
|
|
593
|
-
Object.defineProperty(exports, "isScalarPrimitive", {
|
|
594
|
-
enumerable: true,
|
|
595
|
-
get: function() {
|
|
596
|
-
return isScalarPrimitive;
|
|
597
|
-
}
|
|
598
|
-
});
|
|
599
544
|
Object.defineProperty(exports, "isStringType", {
|
|
600
545
|
enumerable: true,
|
|
601
546
|
get: function() {
|
|
@@ -651,4 +596,4 @@ Object.defineProperty(exports, "walk", {
|
|
|
651
596
|
}
|
|
652
597
|
});
|
|
653
598
|
|
|
654
|
-
//# sourceMappingURL=
|
|
599
|
+
//# sourceMappingURL=refs-u5SDdyV7.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refs-u5SDdyV7.cjs","names":["inputDef","outputDef","operationDef","requestBodyDef","contentDef","responseDef","schemaDef","propertyDef","parameterDef","functionParameterDef","functionParametersDef","typeLiteralDef","indexedAccessTypeDef","objectBindingPatternDef","constDef","typeDef","functionDef","arrowFunctionDef","textDef","breakDef","jsxDef","importDef","exportDef","sourceDef","fileDef","pascalCase","createSchema"],"sources":["../src/constants.ts","../src/guards.ts","../src/registry.ts","../src/visitor.ts","../src/utils/refs.ts"],"sourcesContent":["import 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 * Each value is a stable discriminator across the AST (for example `schema.type === schemaTypes.object`).\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\n/**\n * Default sibling concurrency for `walk()`. Higher values overlap I/O-bound visitor work,\n * lower values reduce memory pressure. Pass `concurrency` to `walk()` to override it.\n *\n * @example\n * ```ts\n * import { walk, WALK_CONCURRENCY } from '@kubb/ast'\n *\n * walk(root, { concurrency: WALK_CONCURRENCY, operation: () => {} })\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","import type { HttpOperationNode, OperationNode, SchemaNode, SchemaNodeByType } from './nodes/index.ts'\n\n/**\n * Narrows a `SchemaNode` to the variant that matches `type`.\n *\n * @example\n * ```ts\n * const schema = createSchema({ type: 'string' })\n * const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | null\n * ```\n */\nexport function narrowSchema<T extends SchemaNode['type']>(node: SchemaNode | undefined, type: T): SchemaNodeByType[T] | null {\n return node?.type === type ? (node as SchemaNodeByType[T]) : null\n}\n\n/**\n * Narrows an `OperationNode` to an `HttpOperationNode` so `method` and `path` are present.\n *\n * @example\n * ```ts\n * if (isHttpOperationNode(node)) {\n * console.log(node.method, node.path)\n * }\n * ```\n */\nexport function isHttpOperationNode(node: OperationNode): node is HttpOperationNode {\n return node.protocol === 'http' || (node.method !== undefined && node.path !== undefined)\n}\n","import type { NodeDef } from './defineNode.ts'\nimport { arrowFunctionDef, breakDef, constDef, functionDef, jsxDef, textDef, typeDef } from './nodes/code.ts'\nimport { contentDef } from './nodes/content.ts'\nimport { exportDef, fileDef, importDef, sourceDef } from './nodes/file.ts'\nimport { functionParameterDef, functionParametersDef, indexedAccessTypeDef, objectBindingPatternDef, typeLiteralDef } from './nodes/function.ts'\nimport { inputDef } from './nodes/input.ts'\nimport { operationDef } from './nodes/operation.ts'\nimport { outputDef } from './nodes/output.ts'\nimport { parameterDef } from './nodes/parameter.ts'\nimport { propertyDef } from './nodes/property.ts'\nimport { requestBodyDef } from './nodes/requestBody.ts'\nimport { responseDef } from './nodes/response.ts'\nimport { schemaDef } from './nodes/schema.ts'\n\n// Surface every def from one place so the package barrel re-exports them with `export * from './registry.ts'`.\n// Adding a node means adding its `defineNode` to a `nodes/*.ts` file and listing it in `nodeDefs` below, nothing else.\nexport {\n arrowFunctionDef,\n breakDef,\n constDef,\n contentDef,\n exportDef,\n fileDef,\n functionDef,\n functionParameterDef,\n functionParametersDef,\n importDef,\n indexedAccessTypeDef,\n inputDef,\n jsxDef,\n objectBindingPatternDef,\n operationDef,\n outputDef,\n parameterDef,\n propertyDef,\n requestBodyDef,\n responseDef,\n schemaDef,\n sourceDef,\n textDef,\n typeDef,\n typeLiteralDef,\n}\n\n/**\n * Every node definition. Adding a node means adding its `defineNode` to one\n * `nodes/*.ts` file and listing it here. The visitor tables in `visitor.ts` derive from it.\n */\nexport const nodeDefs = [\n inputDef,\n outputDef,\n operationDef,\n requestBodyDef,\n contentDef,\n responseDef,\n schemaDef,\n propertyDef,\n parameterDef,\n functionParameterDef,\n functionParametersDef,\n typeLiteralDef,\n indexedAccessTypeDef,\n objectBindingPatternDef,\n constDef,\n typeDef,\n functionDef,\n arrowFunctionDef,\n textDef,\n breakDef,\n jsxDef,\n importDef,\n exportDef,\n sourceDef,\n fileDef,\n] satisfies ReadonlyArray<NodeDef>\n","import type { VisitorDepth } from './constants.ts'\nimport { visitorDepths, WALK_CONCURRENCY } from './constants.ts'\nimport type { NodeDef } from './defineNode.ts'\nimport type {\n ContentNode,\n InputNode,\n Node,\n NodeKind,\n OperationNode,\n OutputNode,\n ParameterNode,\n PropertyNode,\n RequestBodyNode,\n ResponseNode,\n SchemaNode,\n} from './nodes/index.ts'\nimport { nodeDefs } from './registry.ts'\n\n/**\n * Child node fields per node kind, in traversal order (Babel's `VISITOR_KEYS`).\n * Derived from each definition's `children`.\n */\nconst VISITOR_KEYS = Object.fromEntries(nodeDefs.flatMap((def) => (def.children ? [[def.kind, def.children] as const] : []))) as Partial<\n Record<NodeKind, ReadonlyArray<string>>\n>\n\n/**\n * Maps a node kind to the matching visitor callback name. Derived from each\n * definition's `visitorKey`.\n */\nconst VISITOR_KEY_BY_KIND = Object.fromEntries(nodeDefs.flatMap((def) => (def.visitorKey ? [[def.kind, def.visitorKey] as const] : []))) as Partial<\n Record<NodeKind, NonNullable<NodeDef['visitorKey']>>\n>\n\n/**\n * Creates a small async concurrency limiter.\n *\n * At most `concurrency` tasks are in flight at once. Extra tasks are queued.\n *\n * @example\n * ```ts\n * const limit = createLimit(2)\n * for (const task of [taskA, taskB, taskC]) {\n * await limit(() => task())\n * }\n * // only 2 tasks run at the same time\n * ```\n */\nfunction createLimit(concurrency: number) {\n let active = 0\n const queue: Array<() => void> = []\n\n function next() {\n if (active < concurrency && queue.length > 0) {\n active++\n queue.shift()!()\n }\n }\n\n return function limit<T>(fn: () => Promise<T> | T): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n queue.push(() => {\n Promise.resolve(fn())\n .then(resolve, reject)\n .finally(() => {\n active--\n next()\n })\n })\n next()\n })\n }\n}\n\ntype LimitFn = ReturnType<typeof createLimit>\n\n/**\n * Ordered mapping of `[NodeType, ParentType]` pairs.\n *\n * `ParentOf` uses this map to find parent types.\n */\ntype ParentNodeMap = [\n [InputNode, undefined],\n [OutputNode, undefined],\n [OperationNode, InputNode],\n [RequestBodyNode, OperationNode],\n [ContentNode, RequestBodyNode | ResponseNode],\n [SchemaNode, InputNode | ContentNode | SchemaNode | PropertyNode | ParameterNode],\n [PropertyNode, SchemaNode],\n [ParameterNode, OperationNode],\n [ResponseNode, OperationNode],\n]\n\n/**\n * Resolves the parent node type for a given AST node type.\n *\n * Visitor context relies on this so `ctx.parent` is typed for each callback.\n *\n * @example\n * ```ts\n * type InputParent = ParentOf<InputNode>\n * // undefined\n * ```\n *\n * @example\n * ```ts\n * type PropertyParent = ParentOf<PropertyNode>\n * // SchemaNode\n * ```\n *\n * @example\n * ```ts\n * type SchemaParent = ParentOf<SchemaNode>\n * // InputNode | ContentNode | SchemaNode | PropertyNode | ParameterNode\n * ```\n */\nexport type ParentOf<T extends Node, TEntries extends ReadonlyArray<[Node, unknown]> = ParentNodeMap> = TEntries extends [\n infer TEntry extends [Node, unknown],\n ...infer TRest extends ReadonlyArray<[Node, unknown]>,\n]\n ? T extends TEntry[0]\n ? TEntry[1]\n : ParentOf<T, TRest>\n : Node\n\n/**\n * Traversal context passed as the second argument to every visitor callback.\n * `parent` is typed from the current node type.\n *\n * @example\n * ```ts\n * const visitor: Visitor = {\n * schema(node, { parent }) {\n * // parent type is narrowed by node kind\n * },\n * }\n * ```\n */\nexport type VisitorContext<T extends Node = Node> = {\n /**\n * Parent node of the currently visited node.\n * For `InputNode`, this is `undefined`.\n */\n parent?: ParentOf<T>\n}\n\n/**\n * Synchronous visitor consumed by `transform`. Each optional callback runs\n * for the matching node type. Return a new node to replace it, or `undefined`\n * to leave it untouched.\n *\n * Plugins typically expose `transformer` so users can supply a `Visitor` that\n * rewrites the AST before printing.\n *\n * @example Prefix every operationId\n * ```ts\n * const visitor: Visitor = {\n * operation(node) {\n * return { ...node, operationId: `api_${node.operationId}` }\n * },\n * }\n * ```\n *\n * @example Strip schema descriptions\n * ```ts\n * const visitor: Visitor = {\n * schema(node) {\n * return { ...node, description: undefined }\n * },\n * }\n * ```\n */\nexport type Visitor = {\n input?(node: InputNode, context: VisitorContext<InputNode>): undefined | null | InputNode\n output?(node: OutputNode, context: VisitorContext<OutputNode>): undefined | null | OutputNode\n operation?(node: OperationNode, context: VisitorContext<OperationNode>): undefined | null | OperationNode\n schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): undefined | null | SchemaNode\n property?(node: PropertyNode, context: VisitorContext<PropertyNode>): undefined | null | PropertyNode\n parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): undefined | null | ParameterNode\n response?(node: ResponseNode, context: VisitorContext<ResponseNode>): undefined | null | ResponseNode\n}\n\n/**\n * A visitor callback result that may be sync or async.\n */\ntype MaybePromise<T> = T | Promise<T>\n\n/**\n * Async visitor for `walk`. Synchronous `Visitor` objects are compatible.\n *\n * @example\n * ```ts\n * const visitor: AsyncVisitor = {\n * async operation(node) {\n * await Promise.resolve(node.operationId)\n * },\n * }\n * ```\n */\ntype AsyncVisitor = {\n input?(node: InputNode, context: VisitorContext<InputNode>): MaybePromise<undefined | null | InputNode>\n output?(node: OutputNode, context: VisitorContext<OutputNode>): MaybePromise<undefined | null | OutputNode>\n operation?(node: OperationNode, context: VisitorContext<OperationNode>): MaybePromise<undefined | null | OperationNode>\n schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): MaybePromise<undefined | null | SchemaNode>\n property?(node: PropertyNode, context: VisitorContext<PropertyNode>): MaybePromise<undefined | null | PropertyNode>\n parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): MaybePromise<undefined | null | ParameterNode>\n response?(node: ResponseNode, context: VisitorContext<ResponseNode>): MaybePromise<undefined | null | ResponseNode>\n}\n\n/**\n * Visitor used by `collect`.\n *\n * @example\n * ```ts\n * const visitor: CollectVisitor<string> = {\n * operation(node) {\n * return node.operationId\n * },\n * }\n * ```\n */\ntype CollectVisitor<T> = {\n input?(node: InputNode, context: VisitorContext<InputNode>): T | null | undefined\n output?(node: OutputNode, context: VisitorContext<OutputNode>): T | null | undefined\n operation?(node: OperationNode, context: VisitorContext<OperationNode>): T | null | undefined\n schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): T | null | undefined\n property?(node: PropertyNode, context: VisitorContext<PropertyNode>): T | null | undefined\n parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): T | null | undefined\n response?(node: ResponseNode, context: VisitorContext<ResponseNode>): T | null | undefined\n}\n\n/**\n * Options for `transform`.\n *\n * @example\n * ```ts\n * const options: TransformOptions = { depth: 'deep', schema: (node) => node }\n * ```\n *\n * @example\n * ```ts\n * // Only transform the current node, not nested children\n * const options: TransformOptions = { depth: 'shallow', schema: (node) => node }\n * ```\n */\nexport type TransformOptions = Visitor & {\n /**\n * Traversal depth.\n * @default 'deep'\n */\n depth?: VisitorDepth\n /**\n * Internal parent override used during recursion.\n */\n parent?: Node\n}\n\n/**\n * Options for `walk`.\n *\n * @example\n * ```ts\n * const options: WalkOptions = { depth: 'deep', concurrency: 10, root: () => {} }\n * ```\n */\nexport type WalkOptions = AsyncVisitor & {\n /**\n * Traversal depth.\n * @default 'deep'\n */\n depth?: VisitorDepth\n /**\n * Maximum number of sibling nodes visited concurrently.\n * @default 30\n */\n concurrency?: number\n}\n\n/**\n * Options for `collect`.\n *\n * @example\n * ```ts\n * const options: CollectOptions<string> = { depth: 'shallow', schema: () => undefined }\n * ```\n */\nexport type CollectOptions<T> = CollectVisitor<T> & {\n /**\n * Traversal depth.\n * @default 'deep'\n */\n depth?: VisitorDepth\n /**\n * Internal parent override used during recursion.\n */\n parent?: Node\n}\n\nconst visitorKeysByKind = VISITOR_KEYS as Record<string, ReadonlyArray<string> | undefined>\n\n/**\n * Returns `true` when `value` is an AST node (an object carrying a `kind`).\n */\nfunction isNode(value: unknown): value is Node {\n return typeof value === 'object' && value !== null && 'kind' in value\n}\n\n/**\n * Returns the immediate traversable children of `node` based on {@link VISITOR_KEYS}.\n *\n * `Schema` children are only included when `recurse` is `true`. Shallow mode skips them.\n *\n * @example\n * ```ts\n * const children = getChildren(operationNode, true)\n * // returns parameters, the request body, and responses\n * ```\n */\nfunction* getChildren(node: Node, recurse: boolean): Generator<Node, void, undefined> {\n if (node.kind === 'Schema' && !recurse) return\n\n const keys = visitorKeysByKind[node.kind]\n if (!keys) return\n\n const record = node as unknown as Record<string, unknown>\n for (const key of keys) {\n const value = record[key]\n if (Array.isArray(value)) {\n for (const item of value) if (isNode(item)) yield item\n } else if (isNode(value)) {\n yield value\n }\n }\n}\n\n/**\n * Runs the visitor callback that matches `node.kind` with the traversal\n * context. The result is a replacement node, a collected value, or `undefined`\n * when no callback is registered for the kind.\n *\n * Shared by `walk`, `transform`, and `collectLazy` so node-kind dispatch lives\n * in one place. `TResult` is the caller's expected return: the same node type\n * for `transform`, the collected value type for `collectLazy`, ignored for `walk`.\n */\nfunction applyVisitor<TResult>(node: Node, visitor: Visitor | AsyncVisitor | CollectVisitor<unknown>, parent: Node | undefined): TResult | null | undefined {\n const key = VISITOR_KEY_BY_KIND[node.kind]\n if (!key) return undefined\n\n const fn = visitor[key] as ((node: Node, context: VisitorContext) => TResult | null | undefined) | undefined\n\n return fn?.(node, { parent })\n}\n\n/**\n * Async depth-first traversal for side effects. Visitor return values are\n * ignored. Use `transform` when you want to rewrite nodes.\n *\n * Sibling nodes at each depth run concurrently up to `options.concurrency`\n * (defaults to `WALK_CONCURRENCY`). Higher values overlap I/O-bound visitor\n * work. Lower values reduce memory pressure.\n *\n * @example Log every operation\n * ```ts\n * await walk(root, {\n * operation(node) {\n * console.log(node.operationId)\n * },\n * })\n * ```\n *\n * @example Only visit the root node\n * ```ts\n * await walk(root, { depth: 'shallow', input: () => {} })\n * ```\n */\nexport async function walk(node: Node, options: WalkOptions): Promise<void> {\n const recurse = (options.depth ?? visitorDepths.deep) === visitorDepths.deep\n const limit = createLimit(options.concurrency ?? WALK_CONCURRENCY)\n\n return _walk(node, options, recurse, limit, undefined)\n}\n\nasync function _walk(node: Node, visitor: AsyncVisitor, recurse: boolean, limit: LimitFn, parent: Node | undefined): Promise<void> {\n await limit(() => applyVisitor(node, visitor, parent))\n\n // Visit siblings concurrently and let the shared `limit` cap how many callbacks\n // run at once. Awaiting each child sequentially here would serialize the whole\n // traversal and make `concurrency` inert. Every visitor callback would run one\n // at a time regardless of the limit.\n const children = Array.from(getChildren(node, recurse))\n if (children.length === 0) return\n\n await Promise.all(children.map((child) => _walk(child, visitor, recurse, limit, node)))\n}\n\n/**\n * Synchronous depth-first transform. Each visitor callback can return a\n * replacement node. Returning `undefined` keeps the original.\n *\n * The original tree is never mutated, a new tree is returned. Pass\n * `depth: 'shallow'` to skip recursion into children.\n *\n * @example Prefix every operationId\n * ```ts\n * const next = transform(root, {\n * operation(node) {\n * return { ...node, operationId: `prefixed_${node.operationId}` }\n * },\n * })\n * ```\n *\n * @example Replace only the root node\n * ```ts\n * const next = transform(root, {\n * depth: 'shallow',\n * input: (node) => ({ ...node, meta: { ...node.meta, title: 'Rewritten' } }),\n * })\n * ```\n */\nexport function transform(node: InputNode, options: TransformOptions): InputNode\nexport function transform(node: OutputNode, options: TransformOptions): OutputNode\nexport function transform(node: OperationNode, options: TransformOptions): OperationNode\nexport function transform(node: SchemaNode, options: TransformOptions): SchemaNode\nexport function transform(node: PropertyNode, options: TransformOptions): PropertyNode\nexport function transform(node: ParameterNode, options: TransformOptions): ParameterNode\nexport function transform(node: ResponseNode, options: TransformOptions): ResponseNode\nexport function transform(node: Node, options: TransformOptions): Node\nexport function transform(node: Node, options: TransformOptions): Node {\n const { depth, parent, ...visitor } = options\n const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep\n\n const visited = applyVisitor<Node>(node, visitor, parent) ?? node\n const rebuilt = transformChildren(visited, options, recurse)\n\n // Structural sharing: when the visitor and child rebuild both left this node\n // untouched, return the original reference so callers can detect \"nothing\n // changed\" by identity and ancestors can avoid reallocating.\n return rebuilt\n}\n\n/**\n * Immutably rebuilds a node's children using {@link VISITOR_KEYS}, transforming\n * each child node and leaving non-node values (e.g. `additionalProperties: true`) intact.\n * `Schema` children are skipped in shallow mode.\n */\nfunction transformChildren(node: Node, options: TransformOptions, recurse: boolean): Node {\n if (node.kind === 'Schema' && !recurse) return node\n\n const keys = visitorKeysByKind[node.kind]\n if (!keys) return node\n\n const record = node as unknown as Record<string, unknown>\n const childOptions = { ...options, parent: node }\n let updates: Record<string, unknown> | undefined\n\n for (const key of keys) {\n if (!(key in record)) continue\n const value = record[key]\n if (Array.isArray(value)) {\n let changed = false\n const mapped = value.map((item) => {\n if (!isNode(item)) return item\n const next = transform(item, childOptions)\n if (next !== item) changed = true\n return next\n })\n if (changed) (updates ??= {})[key] = mapped\n } else if (isNode(value)) {\n const next = transform(value, childOptions)\n if (next !== value) (updates ??= {})[key] = next\n }\n }\n\n return updates ? ({ ...node, ...updates } as Node) : node\n}\n/**\n * Lazy depth-first collection pass. Yields every non-null value returned by\n * the visitor callbacks. Use `collect` for the eager array form.\n *\n * @example Collect every operationId\n * ```ts\n * const ids: string[] = []\n * for (const id of collectLazy<string>(root, {\n * operation(node) {\n * return node.operationId\n * },\n * })) {\n * ids.push(id)\n * }\n * ```\n */\nexport function* collectLazy<T>(node: Node, options: CollectOptions<T>): Generator<T, void, undefined> {\n const { depth, parent, ...visitor } = options\n const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep\n\n const v = applyVisitor<T>(node, visitor, parent)\n if (v != null) yield v\n\n for (const child of getChildren(node, recurse)) {\n yield* collectLazy(child, { ...options, parent: node })\n }\n}\n\n/**\n * Eager depth-first collection pass. Gathers every non-null value the visitor\n * callbacks return into an array.\n *\n * @example Collect every operationId\n * ```ts\n * const ids = collect<string>(root, {\n * operation(node) {\n * return node.operationId\n * },\n * })\n * ```\n */\nexport function collect<T>(node: Node, options: CollectOptions<T>): Array<T> {\n return Array.from(collectLazy(node, options))\n}\n","import { pascalCase } from '@internals/utils'\nimport { narrowSchema } from '../guards.ts'\nimport type { OperationNode, ParameterNode, SchemaNode } from '../nodes/index.ts'\nimport { createSchema, type SchemaType } from '../nodes/schema.ts'\nimport type { OperationParamsResolver, ParamGroupType } from './operationParams.ts'\n\nconst plainStringTypes = new Set<SchemaType>(['string', 'uuid', 'email', 'url', 'datetime'] as const)\n\n/**\n * Returns the last path segment of a reference string.\n *\n * @example\n * `extractRefName('#/components/schemas/Pet') // 'Pet'`\n */\nexport function extractRefName(ref: string): string {\n return ref.split('/').at(-1) ?? ref\n}\n\n/**\n * Resolves the schema name of a ref node. Uses the last segment of `ref` when set, otherwise falls\n * back to `name` then nested `schema.name`.\n *\n * Returns `null` for non-ref nodes or when no name resolves.\n *\n * @example\n * `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'`\n */\nexport function resolveRefName(node: SchemaNode | undefined): string | null {\n if (!node || node.type !== 'ref') return null\n if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null\n\n return node.name ?? node.schema?.name ?? null\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 Nested under a parent\n * `childName('Order', 'shipping_address') // 'OrderShippingAddress'`\n *\n * @example No parent\n * `childName(undefined, 'params') // null`\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 * `enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'`\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 * Merges a ref node with its resolved schema, giving usage-site fields precedence.\n *\n * Every field set on the ref node except `kind`, `type`, `name`, `ref`, and `schema` overrides the\n * same field in the resolved `node.schema` (for example `description`, `nullable`, `readOnly`,\n * `deprecated`). Fields left `undefined` on the ref do not shadow the resolved schema. Non-ref\n * nodes and refs without a resolved `schema` are returned unchanged.\n *\n * @example\n * ```ts\n * const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })\n * const merged = syncSchemaRef(ref) // merges with resolved Pet schema\n * ```\n */\nexport function syncSchemaRef(node: SchemaNode): SchemaNode {\n const ref = narrowSchema(node, 'ref')\n\n if (!ref) return node\n if (!ref.schema) return node\n\n const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref\n\n // Filter out undefined override values so they don't shadow the resolved schema's fields.\n const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== undefined))\n\n return createSchema({ ...ref.schema, ...definedOverrides })\n}\n\n/**\n * Type guard that returns `true` when a schema emits as a plain `string` type.\n *\n * Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`\n * types, returns `true` only when `representation` is `'string'` rather than `'date'`.\n */\nexport function isStringType(node: SchemaNode): boolean {\n if (plainStringTypes.has(node.type)) {\n return true\n }\n\n const temporal = narrowSchema(node, 'date') ?? narrowSchema(node, 'time')\n if (temporal) {\n return temporal.representation !== 'date'\n }\n\n return false\n}\n\n/**\n * Derives a {@link ParamGroupType} for a query or header group from the resolver.\n *\n * Returns `null` when there is no resolver, no params, or the group name equals the\n * individual param name (so there is no real group to emit).\n */\nexport function resolveGroupType({\n node,\n params,\n group,\n resolver,\n}: {\n node: OperationNode\n params: Array<ParameterNode>\n group: 'query' | 'header'\n resolver: OperationParamsResolver | undefined\n}): ParamGroupType | null {\n if (!resolver || !params.length) {\n return null\n }\n const firstParam = params[0]!\n const groupMethod = group === 'query' ? resolver.resolveQueryParamsName : resolver.resolveHeaderParamsName\n const groupName = groupMethod.call(resolver, node, firstParam)\n if (groupName === resolver.resolveParamName(node, firstParam)) {\n return null\n }\n return { type: groupName, optional: params.every((p) => !p.required) }\n}\n"],"mappings":";;AAUA,MAAa,gBAAgB;CAC3B,SAAS;CACT,MAAM;AACR;;;;;;AAOA,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;;;;AAwBA,MAAa,SAAS,MAAM,KAAK,EAAE,QAAQ,EAAY,SAAS,GAAG,CAAC,CAAC,KAAK,EAAE;;;;;;;;;;;;AC1I5E,SAAgB,aAA2C,MAA8B,MAAqC;CAC5H,OAAO,MAAM,SAAS,OAAQ,OAA+B;AAC/D;;;;;;;;;;;AAYA,SAAgB,oBAAoB,MAAgD;CAClF,OAAO,KAAK,aAAa,UAAW,KAAK,WAAW,KAAA,KAAa,KAAK,SAAS,KAAA;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