@kubb/ast 5.0.0-beta.65 → 5.0.0-beta.67
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/README.md +11 -9
- package/dist/{defineMacro-CEZHaCXE.cjs → defineMacro-BxfaP1iL.cjs} +3 -4
- package/dist/{defineMacro-CEZHaCXE.cjs.map → defineMacro-BxfaP1iL.cjs.map} +1 -1
- package/dist/{defineMacro-B76LsJwO.js → defineMacro-D2vgAdoH.js} +2 -3
- package/dist/{defineMacro-B76LsJwO.js.map → defineMacro-D2vgAdoH.js.map} +1 -1
- package/dist/index.cjs +136 -106
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +51 -32
- package/dist/index.js +79 -48
- package/dist/index.js.map +1 -1
- package/dist/macros.cjs +5 -6
- package/dist/macros.cjs.map +1 -1
- package/dist/macros.js +2 -3
- package/dist/macros.js.map +1 -1
- package/dist/{schema-YNbOtTCM.js → refs-CXp6uOHL.js} +502 -2
- package/dist/refs-CXp6uOHL.js.map +1 -0
- package/dist/{schema-BkvrrOAr.cjs → refs-DDIY_Tpn.cjs} +597 -7
- package/dist/refs-DDIY_Tpn.cjs.map +1 -0
- package/dist/{types-B6thixAv.d.ts → types-CkgvnJBm.d.ts} +10 -39
- package/dist/types.d.ts +3 -3
- package/dist/{utils-BJi0y-xg.js → utils-C2kwfetT.js} +2 -3
- package/dist/{utils-BJi0y-xg.js.map → utils-C2kwfetT.js.map} +1 -1
- package/dist/{utils-CEepwqmb.cjs → utils-DYhjlv0E.cjs} +13 -14
- package/dist/{utils-CEepwqmb.cjs.map → utils-DYhjlv0E.cjs.map} +1 -1
- package/dist/utils.cjs +3 -4
- package/dist/utils.js +2 -3
- package/package.json +1 -5
- package/dist/factory-B_qPwA1b.d.ts +0 -27
- package/dist/factory.cjs +0 -89
- package/dist/factory.cjs.map +0 -1
- package/dist/factory.d.ts +0 -3
- package/dist/factory.js +0 -58
- package/dist/factory.js.map +0 -1
- package/dist/refs-Dx6U5LoE.js +0 -505
- package/dist/refs-Dx6U5LoE.js.map +0 -1
- package/dist/refs-u5SDdyV7.cjs +0 -599
- package/dist/refs-u5SDdyV7.cjs.map +0 -1
- package/dist/schema-BkvrrOAr.cjs.map +0 -1
- package/dist/schema-YNbOtTCM.js.map +0 -1
|
@@ -36,6 +36,154 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
36
36
|
let node_crypto = require("node:crypto");
|
|
37
37
|
let node_path = require("node:path");
|
|
38
38
|
node_path = __toESM(node_path, 1);
|
|
39
|
+
//#region src/constants.ts
|
|
40
|
+
const visitorDepths = {
|
|
41
|
+
shallow: "shallow",
|
|
42
|
+
deep: "deep"
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Schema type discriminators used by all AST schema nodes.
|
|
46
|
+
*
|
|
47
|
+
* Each value is a stable discriminator across the AST (for example `schema.type === schemaTypes.object`).
|
|
48
|
+
*/
|
|
49
|
+
const schemaTypes = {
|
|
50
|
+
/**
|
|
51
|
+
* Text value.
|
|
52
|
+
*/
|
|
53
|
+
string: "string",
|
|
54
|
+
/**
|
|
55
|
+
* Floating-point number (`float`, `double`).
|
|
56
|
+
*/
|
|
57
|
+
number: "number",
|
|
58
|
+
/**
|
|
59
|
+
* Whole number (`int32`). Use `bigint` for `int64`.
|
|
60
|
+
*/
|
|
61
|
+
integer: "integer",
|
|
62
|
+
/**
|
|
63
|
+
* 64-bit integer (`int64`). Only used when `integerType` is set to `'bigint'`.
|
|
64
|
+
*/
|
|
65
|
+
bigint: "bigint",
|
|
66
|
+
/**
|
|
67
|
+
* Boolean value.
|
|
68
|
+
*/
|
|
69
|
+
boolean: "boolean",
|
|
70
|
+
/**
|
|
71
|
+
* Explicit null value.
|
|
72
|
+
*/
|
|
73
|
+
null: "null",
|
|
74
|
+
/**
|
|
75
|
+
* Any value (no type restriction).
|
|
76
|
+
*/
|
|
77
|
+
any: "any",
|
|
78
|
+
/**
|
|
79
|
+
* Unknown value (must be narrowed before usage).
|
|
80
|
+
*/
|
|
81
|
+
unknown: "unknown",
|
|
82
|
+
/**
|
|
83
|
+
* No return value (`void`).
|
|
84
|
+
*/
|
|
85
|
+
void: "void",
|
|
86
|
+
/**
|
|
87
|
+
* Object with named properties.
|
|
88
|
+
*/
|
|
89
|
+
object: "object",
|
|
90
|
+
/**
|
|
91
|
+
* Sequential list of items.
|
|
92
|
+
*/
|
|
93
|
+
array: "array",
|
|
94
|
+
/**
|
|
95
|
+
* Fixed-length list with position-specific items.
|
|
96
|
+
*/
|
|
97
|
+
tuple: "tuple",
|
|
98
|
+
/**
|
|
99
|
+
* "One of" multiple schema members.
|
|
100
|
+
*/
|
|
101
|
+
union: "union",
|
|
102
|
+
/**
|
|
103
|
+
* "All of" multiple schema members.
|
|
104
|
+
*/
|
|
105
|
+
intersection: "intersection",
|
|
106
|
+
/**
|
|
107
|
+
* Enum schema.
|
|
108
|
+
*/
|
|
109
|
+
enum: "enum",
|
|
110
|
+
/**
|
|
111
|
+
* Reference to another schema.
|
|
112
|
+
*/
|
|
113
|
+
ref: "ref",
|
|
114
|
+
/**
|
|
115
|
+
* Calendar date (for example `2026-03-24`).
|
|
116
|
+
*/
|
|
117
|
+
date: "date",
|
|
118
|
+
/**
|
|
119
|
+
* Date-time value (for example `2026-03-24T09:00:00Z`).
|
|
120
|
+
*/
|
|
121
|
+
datetime: "datetime",
|
|
122
|
+
/**
|
|
123
|
+
* Time-only value (for example `09:00:00`).
|
|
124
|
+
*/
|
|
125
|
+
time: "time",
|
|
126
|
+
/**
|
|
127
|
+
* UUID value.
|
|
128
|
+
*/
|
|
129
|
+
uuid: "uuid",
|
|
130
|
+
/**
|
|
131
|
+
* Email address value.
|
|
132
|
+
*/
|
|
133
|
+
email: "email",
|
|
134
|
+
/**
|
|
135
|
+
* URL value.
|
|
136
|
+
*/
|
|
137
|
+
url: "url",
|
|
138
|
+
/**
|
|
139
|
+
* IPv4 address value.
|
|
140
|
+
*/
|
|
141
|
+
ipv4: "ipv4",
|
|
142
|
+
/**
|
|
143
|
+
* IPv6 address value.
|
|
144
|
+
*/
|
|
145
|
+
ipv6: "ipv6",
|
|
146
|
+
/**
|
|
147
|
+
* Binary/blob value.
|
|
148
|
+
*/
|
|
149
|
+
blob: "blob",
|
|
150
|
+
/**
|
|
151
|
+
* Impossible value (`never`).
|
|
152
|
+
*/
|
|
153
|
+
never: "never"
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* One indentation level, derived from {@link INDENT_SIZE}.
|
|
157
|
+
*/
|
|
158
|
+
const INDENT = Array.from({ length: 2 }, () => " ").join("");
|
|
159
|
+
//#endregion
|
|
160
|
+
//#region src/guards.ts
|
|
161
|
+
/**
|
|
162
|
+
* Narrows a `SchemaNode` to the variant that matches `type`.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* const schema = createSchema({ type: 'string' })
|
|
167
|
+
* const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | null
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
function narrowSchema(node, type) {
|
|
171
|
+
return node?.type === type ? node : null;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Narrows an `OperationNode` to an `HttpOperationNode` so `method` and `path` are present.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```ts
|
|
178
|
+
* if (isHttpOperationNode(node)) {
|
|
179
|
+
* console.log(node.method, node.path)
|
|
180
|
+
* }
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
function isHttpOperationNode(node) {
|
|
184
|
+
return node.protocol === "http" || node.method !== void 0 && node.path !== void 0;
|
|
185
|
+
}
|
|
186
|
+
//#endregion
|
|
39
187
|
//#region src/defineNode.ts
|
|
40
188
|
/**
|
|
41
189
|
* Visitor callback names, one per traversable node kind, in traversal order.
|
|
@@ -940,6 +1088,364 @@ function createSchema(props) {
|
|
|
940
1088
|
return schemaDef.create(props);
|
|
941
1089
|
}
|
|
942
1090
|
//#endregion
|
|
1091
|
+
//#region src/registry.ts
|
|
1092
|
+
/**
|
|
1093
|
+
* Every node definition. Adding a node means adding its `defineNode` to one
|
|
1094
|
+
* `nodes/*.ts` file and listing it here. The visitor tables in `visitor.ts` derive from it.
|
|
1095
|
+
*/
|
|
1096
|
+
const nodeDefs = [
|
|
1097
|
+
inputDef,
|
|
1098
|
+
outputDef,
|
|
1099
|
+
operationDef,
|
|
1100
|
+
requestBodyDef,
|
|
1101
|
+
contentDef,
|
|
1102
|
+
responseDef,
|
|
1103
|
+
schemaDef,
|
|
1104
|
+
propertyDef,
|
|
1105
|
+
parameterDef,
|
|
1106
|
+
functionParameterDef,
|
|
1107
|
+
functionParametersDef,
|
|
1108
|
+
typeLiteralDef,
|
|
1109
|
+
indexedAccessTypeDef,
|
|
1110
|
+
objectBindingPatternDef,
|
|
1111
|
+
constDef,
|
|
1112
|
+
typeDef,
|
|
1113
|
+
functionDef,
|
|
1114
|
+
arrowFunctionDef,
|
|
1115
|
+
textDef,
|
|
1116
|
+
breakDef,
|
|
1117
|
+
jsxDef,
|
|
1118
|
+
importDef,
|
|
1119
|
+
exportDef,
|
|
1120
|
+
sourceDef,
|
|
1121
|
+
fileDef
|
|
1122
|
+
];
|
|
1123
|
+
//#endregion
|
|
1124
|
+
//#region src/visitor.ts
|
|
1125
|
+
/**
|
|
1126
|
+
* Child node fields per node kind, in traversal order (Babel's `VISITOR_KEYS`).
|
|
1127
|
+
* Derived from each definition's `children`.
|
|
1128
|
+
*/
|
|
1129
|
+
const VISITOR_KEYS = Object.fromEntries(nodeDefs.flatMap((def) => def.children ? [[def.kind, def.children]] : []));
|
|
1130
|
+
/**
|
|
1131
|
+
* Maps a node kind to the matching visitor callback name. Derived from each
|
|
1132
|
+
* definition's `visitorKey`.
|
|
1133
|
+
*/
|
|
1134
|
+
const VISITOR_KEY_BY_KIND = Object.fromEntries(nodeDefs.flatMap((def) => def.visitorKey ? [[def.kind, def.visitorKey]] : []));
|
|
1135
|
+
/**
|
|
1136
|
+
* Creates a small async concurrency limiter.
|
|
1137
|
+
*
|
|
1138
|
+
* At most `concurrency` tasks are in flight at once. Extra tasks are queued.
|
|
1139
|
+
*
|
|
1140
|
+
* @example
|
|
1141
|
+
* ```ts
|
|
1142
|
+
* const limit = createLimit(2)
|
|
1143
|
+
* for (const task of [taskA, taskB, taskC]) {
|
|
1144
|
+
* await limit(() => task())
|
|
1145
|
+
* }
|
|
1146
|
+
* // only 2 tasks run at the same time
|
|
1147
|
+
* ```
|
|
1148
|
+
*/
|
|
1149
|
+
function createLimit(concurrency) {
|
|
1150
|
+
let active = 0;
|
|
1151
|
+
const queue = [];
|
|
1152
|
+
function next() {
|
|
1153
|
+
if (active < concurrency && queue.length > 0) {
|
|
1154
|
+
active++;
|
|
1155
|
+
queue.shift()();
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
return function limit(fn) {
|
|
1159
|
+
return new Promise((resolve, reject) => {
|
|
1160
|
+
queue.push(() => {
|
|
1161
|
+
Promise.resolve(fn()).then(resolve, reject).finally(() => {
|
|
1162
|
+
active--;
|
|
1163
|
+
next();
|
|
1164
|
+
});
|
|
1165
|
+
});
|
|
1166
|
+
next();
|
|
1167
|
+
});
|
|
1168
|
+
};
|
|
1169
|
+
}
|
|
1170
|
+
const visitorKeysByKind = VISITOR_KEYS;
|
|
1171
|
+
/**
|
|
1172
|
+
* Returns `true` when `value` is an AST node (an object carrying a `kind`).
|
|
1173
|
+
*/
|
|
1174
|
+
function isNode(value) {
|
|
1175
|
+
return typeof value === "object" && value !== null && "kind" in value;
|
|
1176
|
+
}
|
|
1177
|
+
/**
|
|
1178
|
+
* Returns the immediate traversable children of `node` based on {@link VISITOR_KEYS}.
|
|
1179
|
+
*
|
|
1180
|
+
* `Schema` children are only included when `recurse` is `true`. Shallow mode skips them.
|
|
1181
|
+
*
|
|
1182
|
+
* @example
|
|
1183
|
+
* ```ts
|
|
1184
|
+
* const children = getChildren(operationNode, true)
|
|
1185
|
+
* // returns parameters, the request body, and responses
|
|
1186
|
+
* ```
|
|
1187
|
+
*/
|
|
1188
|
+
function* getChildren(node, recurse) {
|
|
1189
|
+
if (node.kind === "Schema" && !recurse) return;
|
|
1190
|
+
const keys = visitorKeysByKind[node.kind];
|
|
1191
|
+
if (!keys) return;
|
|
1192
|
+
const record = node;
|
|
1193
|
+
for (const key of keys) {
|
|
1194
|
+
const value = record[key];
|
|
1195
|
+
if (Array.isArray(value)) {
|
|
1196
|
+
for (const item of value) if (isNode(item)) yield item;
|
|
1197
|
+
} else if (isNode(value)) yield value;
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
/**
|
|
1201
|
+
* Runs the visitor callback that matches `node.kind` with the traversal
|
|
1202
|
+
* context. The result is a replacement node, a collected value, or `undefined`
|
|
1203
|
+
* when no callback is registered for the kind.
|
|
1204
|
+
*
|
|
1205
|
+
* Shared by `walk`, `transform`, and `collectLazy` so node-kind dispatch lives
|
|
1206
|
+
* in one place. `TResult` is the caller's expected return: the same node type
|
|
1207
|
+
* for `transform`, the collected value type for `collectLazy`, ignored for `walk`.
|
|
1208
|
+
*/
|
|
1209
|
+
function applyVisitor(node, visitor, parent) {
|
|
1210
|
+
const key = VISITOR_KEY_BY_KIND[node.kind];
|
|
1211
|
+
if (!key) return void 0;
|
|
1212
|
+
const fn = visitor[key];
|
|
1213
|
+
return fn?.(node, { parent });
|
|
1214
|
+
}
|
|
1215
|
+
/**
|
|
1216
|
+
* Async depth-first traversal for side effects. Visitor return values are
|
|
1217
|
+
* ignored. Use `transform` when you want to rewrite nodes.
|
|
1218
|
+
*
|
|
1219
|
+
* Sibling nodes at each depth run concurrently up to `options.concurrency`
|
|
1220
|
+
* (defaults to `WALK_CONCURRENCY`). Higher values overlap I/O-bound visitor
|
|
1221
|
+
* work. Lower values reduce memory pressure.
|
|
1222
|
+
*
|
|
1223
|
+
* @example Log every operation
|
|
1224
|
+
* ```ts
|
|
1225
|
+
* await walk(root, {
|
|
1226
|
+
* operation(node) {
|
|
1227
|
+
* console.log(node.operationId)
|
|
1228
|
+
* },
|
|
1229
|
+
* })
|
|
1230
|
+
* ```
|
|
1231
|
+
*
|
|
1232
|
+
* @example Only visit the root node
|
|
1233
|
+
* ```ts
|
|
1234
|
+
* await walk(root, { depth: 'shallow', input: () => {} })
|
|
1235
|
+
* ```
|
|
1236
|
+
*/
|
|
1237
|
+
async function walk(node, options) {
|
|
1238
|
+
return _walk(node, options, (options.depth ?? visitorDepths.deep) === visitorDepths.deep, createLimit(options.concurrency ?? 30), void 0);
|
|
1239
|
+
}
|
|
1240
|
+
async function _walk(node, visitor, recurse, limit, parent) {
|
|
1241
|
+
await limit(() => applyVisitor(node, visitor, parent));
|
|
1242
|
+
const children = Array.from(getChildren(node, recurse));
|
|
1243
|
+
if (children.length === 0) return;
|
|
1244
|
+
await Promise.all(children.map((child) => _walk(child, visitor, recurse, limit, node)));
|
|
1245
|
+
}
|
|
1246
|
+
function transform(node, options) {
|
|
1247
|
+
const { depth, parent, ...visitor } = options;
|
|
1248
|
+
const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep;
|
|
1249
|
+
return transformChildren(applyVisitor(node, visitor, parent) ?? node, options, recurse);
|
|
1250
|
+
}
|
|
1251
|
+
/**
|
|
1252
|
+
* Immutably rebuilds a node's children using {@link VISITOR_KEYS}, transforming
|
|
1253
|
+
* each child node and leaving non-node values (e.g. `additionalProperties: true`) intact.
|
|
1254
|
+
* `Schema` children are skipped in shallow mode.
|
|
1255
|
+
*/
|
|
1256
|
+
function transformChildren(node, options, recurse) {
|
|
1257
|
+
if (node.kind === "Schema" && !recurse) return node;
|
|
1258
|
+
const keys = visitorKeysByKind[node.kind];
|
|
1259
|
+
if (!keys) return node;
|
|
1260
|
+
const record = node;
|
|
1261
|
+
const childOptions = {
|
|
1262
|
+
...options,
|
|
1263
|
+
parent: node
|
|
1264
|
+
};
|
|
1265
|
+
let updates;
|
|
1266
|
+
for (const key of keys) {
|
|
1267
|
+
if (!(key in record)) continue;
|
|
1268
|
+
const value = record[key];
|
|
1269
|
+
if (Array.isArray(value)) {
|
|
1270
|
+
let changed = false;
|
|
1271
|
+
const mapped = value.map((item) => {
|
|
1272
|
+
if (!isNode(item)) return item;
|
|
1273
|
+
const next = transform(item, childOptions);
|
|
1274
|
+
if (next !== item) changed = true;
|
|
1275
|
+
return next;
|
|
1276
|
+
});
|
|
1277
|
+
if (changed) (updates ??= {})[key] = mapped;
|
|
1278
|
+
} else if (isNode(value)) {
|
|
1279
|
+
const next = transform(value, childOptions);
|
|
1280
|
+
if (next !== value) (updates ??= {})[key] = next;
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
return updates ? {
|
|
1284
|
+
...node,
|
|
1285
|
+
...updates
|
|
1286
|
+
} : node;
|
|
1287
|
+
}
|
|
1288
|
+
/**
|
|
1289
|
+
* Lazy depth-first collection pass. Yields every non-null value returned by
|
|
1290
|
+
* the visitor callbacks. Use `collect` for the eager array form.
|
|
1291
|
+
*
|
|
1292
|
+
* @example Collect every operationId
|
|
1293
|
+
* ```ts
|
|
1294
|
+
* const ids: string[] = []
|
|
1295
|
+
* for (const id of collectLazy<string>(root, {
|
|
1296
|
+
* operation(node) {
|
|
1297
|
+
* return node.operationId
|
|
1298
|
+
* },
|
|
1299
|
+
* })) {
|
|
1300
|
+
* ids.push(id)
|
|
1301
|
+
* }
|
|
1302
|
+
* ```
|
|
1303
|
+
*/
|
|
1304
|
+
function* collectLazy(node, options) {
|
|
1305
|
+
const { depth, parent, ...visitor } = options;
|
|
1306
|
+
const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep;
|
|
1307
|
+
const v = applyVisitor(node, visitor, parent);
|
|
1308
|
+
if (v != null) yield v;
|
|
1309
|
+
for (const child of getChildren(node, recurse)) yield* collectLazy(child, {
|
|
1310
|
+
...options,
|
|
1311
|
+
parent: node
|
|
1312
|
+
});
|
|
1313
|
+
}
|
|
1314
|
+
/**
|
|
1315
|
+
* Eager depth-first collection pass. Gathers every non-null value the visitor
|
|
1316
|
+
* callbacks return into an array.
|
|
1317
|
+
*
|
|
1318
|
+
* @example Collect every operationId
|
|
1319
|
+
* ```ts
|
|
1320
|
+
* const ids = collect<string>(root, {
|
|
1321
|
+
* operation(node) {
|
|
1322
|
+
* return node.operationId
|
|
1323
|
+
* },
|
|
1324
|
+
* })
|
|
1325
|
+
* ```
|
|
1326
|
+
*/
|
|
1327
|
+
function collect(node, options) {
|
|
1328
|
+
return Array.from(collectLazy(node, options));
|
|
1329
|
+
}
|
|
1330
|
+
//#endregion
|
|
1331
|
+
//#region src/utils/refs.ts
|
|
1332
|
+
const plainStringTypes = new Set([
|
|
1333
|
+
"string",
|
|
1334
|
+
"uuid",
|
|
1335
|
+
"email",
|
|
1336
|
+
"url",
|
|
1337
|
+
"datetime"
|
|
1338
|
+
]);
|
|
1339
|
+
/**
|
|
1340
|
+
* Returns the last path segment of a reference string.
|
|
1341
|
+
*
|
|
1342
|
+
* @example
|
|
1343
|
+
* `extractRefName('#/components/schemas/Pet') // 'Pet'`
|
|
1344
|
+
*/
|
|
1345
|
+
function extractRefName(ref) {
|
|
1346
|
+
return ref.split("/").at(-1) ?? ref;
|
|
1347
|
+
}
|
|
1348
|
+
/**
|
|
1349
|
+
* Resolves the schema name of a ref node. Uses the last segment of `ref` when set, otherwise falls
|
|
1350
|
+
* back to `name` then nested `schema.name`.
|
|
1351
|
+
*
|
|
1352
|
+
* Returns `null` for non-ref nodes or when no name resolves.
|
|
1353
|
+
*
|
|
1354
|
+
* @example
|
|
1355
|
+
* `resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'`
|
|
1356
|
+
*/
|
|
1357
|
+
function resolveRefName(node) {
|
|
1358
|
+
if (!node || node.type !== "ref") return null;
|
|
1359
|
+
if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null;
|
|
1360
|
+
return node.name ?? node.schema?.name ?? null;
|
|
1361
|
+
}
|
|
1362
|
+
/**
|
|
1363
|
+
* Builds a PascalCase child schema name by joining a parent name and property name.
|
|
1364
|
+
* Returns `null` when there is no parent to nest under.
|
|
1365
|
+
*
|
|
1366
|
+
* @example Nested under a parent
|
|
1367
|
+
* `childName('Order', 'shipping_address') // 'OrderShippingAddress'`
|
|
1368
|
+
*
|
|
1369
|
+
* @example No parent
|
|
1370
|
+
* `childName(undefined, 'params') // null`
|
|
1371
|
+
*/
|
|
1372
|
+
function childName(parentName, propName) {
|
|
1373
|
+
return parentName ? pascalCase([parentName, propName].join(" ")) : null;
|
|
1374
|
+
}
|
|
1375
|
+
/**
|
|
1376
|
+
* Builds a PascalCase enum name from the parent name, property name, and a suffix, skipping any
|
|
1377
|
+
* empty parts.
|
|
1378
|
+
*
|
|
1379
|
+
* @example
|
|
1380
|
+
* `enumPropName('Order', 'status', 'enum') // 'OrderStatusEnum'`
|
|
1381
|
+
*/
|
|
1382
|
+
function enumPropName(parentName, propName, enumSuffix) {
|
|
1383
|
+
return pascalCase([
|
|
1384
|
+
parentName,
|
|
1385
|
+
propName,
|
|
1386
|
+
enumSuffix
|
|
1387
|
+
].filter(Boolean).join(" "));
|
|
1388
|
+
}
|
|
1389
|
+
/**
|
|
1390
|
+
* Merges a ref node with its resolved schema, giving usage-site fields precedence.
|
|
1391
|
+
*
|
|
1392
|
+
* Every field set on the ref node except `kind`, `type`, `name`, `ref`, and `schema` overrides the
|
|
1393
|
+
* same field in the resolved `node.schema` (for example `description`, `nullable`, `readOnly`,
|
|
1394
|
+
* `deprecated`). Fields left `undefined` on the ref do not shadow the resolved schema. Non-ref
|
|
1395
|
+
* nodes and refs without a resolved `schema` are returned unchanged.
|
|
1396
|
+
*
|
|
1397
|
+
* @example
|
|
1398
|
+
* ```ts
|
|
1399
|
+
* const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })
|
|
1400
|
+
* const merged = syncSchemaRef(ref) // merges with resolved Pet schema
|
|
1401
|
+
* ```
|
|
1402
|
+
*/
|
|
1403
|
+
function syncSchemaRef(node) {
|
|
1404
|
+
const ref = narrowSchema(node, "ref");
|
|
1405
|
+
if (!ref) return node;
|
|
1406
|
+
if (!ref.schema) return node;
|
|
1407
|
+
const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref;
|
|
1408
|
+
const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== void 0));
|
|
1409
|
+
return createSchema({
|
|
1410
|
+
...ref.schema,
|
|
1411
|
+
...definedOverrides
|
|
1412
|
+
});
|
|
1413
|
+
}
|
|
1414
|
+
/**
|
|
1415
|
+
* Type guard that returns `true` when a schema emits as a plain `string` type.
|
|
1416
|
+
*
|
|
1417
|
+
* Covers `string`, `uuid`, `email`, `url`, and `datetime` types. For `date` and `time`
|
|
1418
|
+
* types, returns `true` only when `representation` is `'string'` rather than `'date'`.
|
|
1419
|
+
*/
|
|
1420
|
+
function isStringType(node) {
|
|
1421
|
+
if (plainStringTypes.has(node.type)) return true;
|
|
1422
|
+
const temporal = narrowSchema(node, "date") ?? narrowSchema(node, "time");
|
|
1423
|
+
if (temporal) return temporal.representation !== "date";
|
|
1424
|
+
return false;
|
|
1425
|
+
}
|
|
1426
|
+
/**
|
|
1427
|
+
* Derives a {@link ParamGroupType} for a query or header group from the resolver.
|
|
1428
|
+
*
|
|
1429
|
+
* Returns `null` when there is no resolver, no params, or the group name equals the
|
|
1430
|
+
* individual param name (so there is no real group to emit).
|
|
1431
|
+
*/
|
|
1432
|
+
function resolveGroupType({ node, params, group, resolver }) {
|
|
1433
|
+
if (!resolver || !params.length) return null;
|
|
1434
|
+
const firstParam = params[0];
|
|
1435
|
+
const groupName = (group === "query" ? resolver.resolveQueryParamsName : resolver.resolveHeaderParamsName).call(resolver, node, firstParam);
|
|
1436
|
+
if (groupName === resolver.resolveParamName(node, firstParam)) return null;
|
|
1437
|
+
return {
|
|
1438
|
+
type: groupName,
|
|
1439
|
+
optional: params.every((p) => !p.required)
|
|
1440
|
+
};
|
|
1441
|
+
}
|
|
1442
|
+
//#endregion
|
|
1443
|
+
Object.defineProperty(exports, "INDENT", {
|
|
1444
|
+
enumerable: true,
|
|
1445
|
+
get: function() {
|
|
1446
|
+
return INDENT;
|
|
1447
|
+
}
|
|
1448
|
+
});
|
|
943
1449
|
Object.defineProperty(exports, "__exportAll", {
|
|
944
1450
|
enumerable: true,
|
|
945
1451
|
get: function() {
|
|
@@ -970,6 +1476,24 @@ Object.defineProperty(exports, "camelCase", {
|
|
|
970
1476
|
return camelCase;
|
|
971
1477
|
}
|
|
972
1478
|
});
|
|
1479
|
+
Object.defineProperty(exports, "childName", {
|
|
1480
|
+
enumerable: true,
|
|
1481
|
+
get: function() {
|
|
1482
|
+
return childName;
|
|
1483
|
+
}
|
|
1484
|
+
});
|
|
1485
|
+
Object.defineProperty(exports, "collect", {
|
|
1486
|
+
enumerable: true,
|
|
1487
|
+
get: function() {
|
|
1488
|
+
return collect;
|
|
1489
|
+
}
|
|
1490
|
+
});
|
|
1491
|
+
Object.defineProperty(exports, "collectLazy", {
|
|
1492
|
+
enumerable: true,
|
|
1493
|
+
get: function() {
|
|
1494
|
+
return collectLazy;
|
|
1495
|
+
}
|
|
1496
|
+
});
|
|
973
1497
|
Object.defineProperty(exports, "constDef", {
|
|
974
1498
|
enumerable: true,
|
|
975
1499
|
get: function() {
|
|
@@ -1138,12 +1662,24 @@ Object.defineProperty(exports, "defineNode", {
|
|
|
1138
1662
|
return defineNode;
|
|
1139
1663
|
}
|
|
1140
1664
|
});
|
|
1665
|
+
Object.defineProperty(exports, "enumPropName", {
|
|
1666
|
+
enumerable: true,
|
|
1667
|
+
get: function() {
|
|
1668
|
+
return enumPropName;
|
|
1669
|
+
}
|
|
1670
|
+
});
|
|
1141
1671
|
Object.defineProperty(exports, "exportDef", {
|
|
1142
1672
|
enumerable: true,
|
|
1143
1673
|
get: function() {
|
|
1144
1674
|
return exportDef;
|
|
1145
1675
|
}
|
|
1146
1676
|
});
|
|
1677
|
+
Object.defineProperty(exports, "extractRefName", {
|
|
1678
|
+
enumerable: true,
|
|
1679
|
+
get: function() {
|
|
1680
|
+
return extractRefName;
|
|
1681
|
+
}
|
|
1682
|
+
});
|
|
1147
1683
|
Object.defineProperty(exports, "extractStringsFromNodes", {
|
|
1148
1684
|
enumerable: true,
|
|
1149
1685
|
get: function() {
|
|
@@ -1192,12 +1728,36 @@ Object.defineProperty(exports, "inputDef", {
|
|
|
1192
1728
|
return inputDef;
|
|
1193
1729
|
}
|
|
1194
1730
|
});
|
|
1731
|
+
Object.defineProperty(exports, "isHttpOperationNode", {
|
|
1732
|
+
enumerable: true,
|
|
1733
|
+
get: function() {
|
|
1734
|
+
return isHttpOperationNode;
|
|
1735
|
+
}
|
|
1736
|
+
});
|
|
1737
|
+
Object.defineProperty(exports, "isStringType", {
|
|
1738
|
+
enumerable: true,
|
|
1739
|
+
get: function() {
|
|
1740
|
+
return isStringType;
|
|
1741
|
+
}
|
|
1742
|
+
});
|
|
1195
1743
|
Object.defineProperty(exports, "jsxDef", {
|
|
1196
1744
|
enumerable: true,
|
|
1197
1745
|
get: function() {
|
|
1198
1746
|
return jsxDef;
|
|
1199
1747
|
}
|
|
1200
1748
|
});
|
|
1749
|
+
Object.defineProperty(exports, "narrowSchema", {
|
|
1750
|
+
enumerable: true,
|
|
1751
|
+
get: function() {
|
|
1752
|
+
return narrowSchema;
|
|
1753
|
+
}
|
|
1754
|
+
});
|
|
1755
|
+
Object.defineProperty(exports, "nodeDefs", {
|
|
1756
|
+
enumerable: true,
|
|
1757
|
+
get: function() {
|
|
1758
|
+
return nodeDefs;
|
|
1759
|
+
}
|
|
1760
|
+
});
|
|
1201
1761
|
Object.defineProperty(exports, "objectBindingPatternDef", {
|
|
1202
1762
|
enumerable: true,
|
|
1203
1763
|
get: function() {
|
|
@@ -1228,12 +1788,6 @@ Object.defineProperty(exports, "parameterDef", {
|
|
|
1228
1788
|
return parameterDef;
|
|
1229
1789
|
}
|
|
1230
1790
|
});
|
|
1231
|
-
Object.defineProperty(exports, "pascalCase", {
|
|
1232
|
-
enumerable: true,
|
|
1233
|
-
get: function() {
|
|
1234
|
-
return pascalCase;
|
|
1235
|
-
}
|
|
1236
|
-
});
|
|
1237
1791
|
Object.defineProperty(exports, "propertyDef", {
|
|
1238
1792
|
enumerable: true,
|
|
1239
1793
|
get: function() {
|
|
@@ -1246,6 +1800,18 @@ Object.defineProperty(exports, "requestBodyDef", {
|
|
|
1246
1800
|
return requestBodyDef;
|
|
1247
1801
|
}
|
|
1248
1802
|
});
|
|
1803
|
+
Object.defineProperty(exports, "resolveGroupType", {
|
|
1804
|
+
enumerable: true,
|
|
1805
|
+
get: function() {
|
|
1806
|
+
return resolveGroupType;
|
|
1807
|
+
}
|
|
1808
|
+
});
|
|
1809
|
+
Object.defineProperty(exports, "resolveRefName", {
|
|
1810
|
+
enumerable: true,
|
|
1811
|
+
get: function() {
|
|
1812
|
+
return resolveRefName;
|
|
1813
|
+
}
|
|
1814
|
+
});
|
|
1249
1815
|
Object.defineProperty(exports, "responseDef", {
|
|
1250
1816
|
enumerable: true,
|
|
1251
1817
|
get: function() {
|
|
@@ -1258,18 +1824,36 @@ Object.defineProperty(exports, "schemaDef", {
|
|
|
1258
1824
|
return schemaDef;
|
|
1259
1825
|
}
|
|
1260
1826
|
});
|
|
1827
|
+
Object.defineProperty(exports, "schemaTypes", {
|
|
1828
|
+
enumerable: true,
|
|
1829
|
+
get: function() {
|
|
1830
|
+
return schemaTypes;
|
|
1831
|
+
}
|
|
1832
|
+
});
|
|
1261
1833
|
Object.defineProperty(exports, "sourceDef", {
|
|
1262
1834
|
enumerable: true,
|
|
1263
1835
|
get: function() {
|
|
1264
1836
|
return sourceDef;
|
|
1265
1837
|
}
|
|
1266
1838
|
});
|
|
1839
|
+
Object.defineProperty(exports, "syncSchemaRef", {
|
|
1840
|
+
enumerable: true,
|
|
1841
|
+
get: function() {
|
|
1842
|
+
return syncSchemaRef;
|
|
1843
|
+
}
|
|
1844
|
+
});
|
|
1267
1845
|
Object.defineProperty(exports, "textDef", {
|
|
1268
1846
|
enumerable: true,
|
|
1269
1847
|
get: function() {
|
|
1270
1848
|
return textDef;
|
|
1271
1849
|
}
|
|
1272
1850
|
});
|
|
1851
|
+
Object.defineProperty(exports, "transform", {
|
|
1852
|
+
enumerable: true,
|
|
1853
|
+
get: function() {
|
|
1854
|
+
return transform;
|
|
1855
|
+
}
|
|
1856
|
+
});
|
|
1273
1857
|
Object.defineProperty(exports, "typeDef", {
|
|
1274
1858
|
enumerable: true,
|
|
1275
1859
|
get: function() {
|
|
@@ -1288,5 +1872,11 @@ Object.defineProperty(exports, "visitorKeys", {
|
|
|
1288
1872
|
return visitorKeys;
|
|
1289
1873
|
}
|
|
1290
1874
|
});
|
|
1875
|
+
Object.defineProperty(exports, "walk", {
|
|
1876
|
+
enumerable: true,
|
|
1877
|
+
get: function() {
|
|
1878
|
+
return walk;
|
|
1879
|
+
}
|
|
1880
|
+
});
|
|
1291
1881
|
|
|
1292
|
-
//# sourceMappingURL=
|
|
1882
|
+
//# sourceMappingURL=refs-DDIY_Tpn.cjs.map
|