@kubb/ast 5.18.0 → 5.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +54 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +54 -27
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1221,7 +1221,7 @@ type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
|
1221
1221
|
/**
|
|
1222
1222
|
* Response status code literal used by operations.
|
|
1223
1223
|
*
|
|
1224
|
-
* Includes three-digit HTTP status code strings, ranges such as `"
|
|
1224
|
+
* Includes three-digit HTTP status code strings, ranges such as `"2xx"`, and `"default"` for catch-all responses.
|
|
1225
1225
|
*
|
|
1226
1226
|
* @example
|
|
1227
1227
|
* ```ts
|
|
@@ -1229,7 +1229,7 @@ type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
|
1229
1229
|
* const fallback: StatusCode = 'default'
|
|
1230
1230
|
* ```
|
|
1231
1231
|
*/
|
|
1232
|
-
type StatusCode = `${1 | 2 | 3 | 4 | 5}${Digit}${Digit}` | `${1 | 2 | 3 | 4 | 5}
|
|
1232
|
+
type StatusCode = `${1 | 2 | 3 | 4 | 5}${Digit}${Digit}` | `${1 | 2 | 3 | 4 | 5}xx` | 'default';
|
|
1233
1233
|
/**
|
|
1234
1234
|
* AST node representing one operation response variant.
|
|
1235
1235
|
*
|
|
@@ -2663,7 +2663,8 @@ export declare function collectSchemaRefs(node: SchemaNode): ReadonlySet<string>
|
|
|
2663
2663
|
*
|
|
2664
2664
|
* Only refs that carry a `$ref` pointer count, so a synthesized ref pointing at a sibling in the
|
|
2665
2665
|
* same file (a union member created by name) is left out. That leaves exactly the set
|
|
2666
|
-
* `resolver.imports` emits.
|
|
2666
|
+
* `resolver.imports` emits. Refs inside `conditionals`, `contains` and `content` count only with
|
|
2667
|
+
* `checks: true`, for a plugin that prints those checks.
|
|
2667
2668
|
*
|
|
2668
2669
|
* @example
|
|
2669
2670
|
* ```ts
|
|
@@ -2671,7 +2672,9 @@ export declare function collectSchemaRefs(node: SchemaNode): ReadonlySet<string>
|
|
|
2671
2672
|
* // ['Category', 'Tag']
|
|
2672
2673
|
* ```
|
|
2673
2674
|
*/
|
|
2674
|
-
export declare function collectImportedRefNames(node: SchemaNode
|
|
2675
|
+
export declare function collectImportedRefNames(node: SchemaNode, { checks }?: {
|
|
2676
|
+
checks?: boolean;
|
|
2677
|
+
}): ReadonlyArray<string>;
|
|
2675
2678
|
/**
|
|
2676
2679
|
* Collects the names of all top-level schemas transitively used by a set of operations.
|
|
2677
2680
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1221,7 +1221,7 @@ type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
|
1221
1221
|
/**
|
|
1222
1222
|
* Response status code literal used by operations.
|
|
1223
1223
|
*
|
|
1224
|
-
* Includes three-digit HTTP status code strings, ranges such as `"
|
|
1224
|
+
* Includes three-digit HTTP status code strings, ranges such as `"2xx"`, and `"default"` for catch-all responses.
|
|
1225
1225
|
*
|
|
1226
1226
|
* @example
|
|
1227
1227
|
* ```ts
|
|
@@ -1229,7 +1229,7 @@ type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
|
1229
1229
|
* const fallback: StatusCode = 'default'
|
|
1230
1230
|
* ```
|
|
1231
1231
|
*/
|
|
1232
|
-
type StatusCode = `${1 | 2 | 3 | 4 | 5}${Digit}${Digit}` | `${1 | 2 | 3 | 4 | 5}
|
|
1232
|
+
type StatusCode = `${1 | 2 | 3 | 4 | 5}${Digit}${Digit}` | `${1 | 2 | 3 | 4 | 5}xx` | 'default';
|
|
1233
1233
|
/**
|
|
1234
1234
|
* AST node representing one operation response variant.
|
|
1235
1235
|
*
|
|
@@ -2663,7 +2663,8 @@ export declare function collectSchemaRefs(node: SchemaNode): ReadonlySet<string>
|
|
|
2663
2663
|
*
|
|
2664
2664
|
* Only refs that carry a `$ref` pointer count, so a synthesized ref pointing at a sibling in the
|
|
2665
2665
|
* same file (a union member created by name) is left out. That leaves exactly the set
|
|
2666
|
-
* `resolver.imports` emits.
|
|
2666
|
+
* `resolver.imports` emits. Refs inside `conditionals`, `contains` and `content` count only with
|
|
2667
|
+
* `checks: true`, for a plugin that prints those checks.
|
|
2667
2668
|
*
|
|
2668
2669
|
* @example
|
|
2669
2670
|
* ```ts
|
|
@@ -2671,7 +2672,9 @@ export declare function collectSchemaRefs(node: SchemaNode): ReadonlySet<string>
|
|
|
2671
2672
|
* // ['Category', 'Tag']
|
|
2672
2673
|
* ```
|
|
2673
2674
|
*/
|
|
2674
|
-
export declare function collectImportedRefNames(node: SchemaNode
|
|
2675
|
+
export declare function collectImportedRefNames(node: SchemaNode, { checks }?: {
|
|
2676
|
+
checks?: boolean;
|
|
2677
|
+
}): ReadonlyArray<string>;
|
|
2675
2678
|
/**
|
|
2676
2679
|
* Collects the names of all top-level schemas transitively used by a set of operations.
|
|
2677
2680
|
*
|
package/dist/index.js
CHANGED
|
@@ -201,6 +201,15 @@ const VISITOR_KEYS = {
|
|
|
201
201
|
Property: ["schema"],
|
|
202
202
|
Parameter: ["schema"]
|
|
203
203
|
};
|
|
204
|
+
/**
|
|
205
|
+
* Schema fields that hold checks rather than shape: the `conditionals` entries, `contains` and a string's `content`.
|
|
206
|
+
* `transform` and `collect` skip them, and `visitChildNodes` walks them with `checks: true`.
|
|
207
|
+
*/
|
|
208
|
+
const schemaCheckKeys = [
|
|
209
|
+
"conditionals",
|
|
210
|
+
"contains",
|
|
211
|
+
"content"
|
|
212
|
+
];
|
|
204
213
|
/** Visitor callback names in traversal order, the keys of {@link Visitor}. */
|
|
205
214
|
const visitorKeys = [
|
|
206
215
|
"input",
|
|
@@ -251,28 +260,35 @@ function getChildren(node, recurse) {
|
|
|
251
260
|
});
|
|
252
261
|
return children;
|
|
253
262
|
}
|
|
254
|
-
/**
|
|
255
|
-
|
|
256
|
-
|
|
263
|
+
/**
|
|
264
|
+
* Calls `visit` for each direct child node and stops at the first call that returns `true`.
|
|
265
|
+
* With `checks: true`, a schema's {@link schemaCheckKeys} fields are walked too.
|
|
266
|
+
*/
|
|
267
|
+
function visitChildNodes(node, visit, { checks = false } = {}) {
|
|
268
|
+
const keys = checks && node.kind === nodeKinds.schema ? [...VISITOR_KEYS[node.kind] ?? [], ...schemaCheckKeys] : VISITOR_KEYS[node.kind];
|
|
257
269
|
if (!keys) return false;
|
|
258
270
|
const record = node;
|
|
259
271
|
const seen = /* @__PURE__ */ new Set();
|
|
260
272
|
const visitOnce = (child) => !seen.has(child) && (seen.add(child), visit(child));
|
|
273
|
+
const visitRecord = (value) => {
|
|
274
|
+
for (const name in value) {
|
|
275
|
+
if (!Object.hasOwn(value, name)) continue;
|
|
276
|
+
const item = value[name];
|
|
277
|
+
if (isNode(item) && visitOnce(item)) return true;
|
|
278
|
+
}
|
|
279
|
+
return false;
|
|
280
|
+
};
|
|
261
281
|
for (const key of keys) {
|
|
262
282
|
const value = record[key];
|
|
263
283
|
if (Array.isArray(value)) {
|
|
264
|
-
for (const item of value) if (isNode(item)
|
|
284
|
+
for (const item of value) if (isNode(item) ? visitOnce(item) : isNodeRecord(item) && visitRecord(item)) return true;
|
|
265
285
|
continue;
|
|
266
286
|
}
|
|
267
287
|
if (isNode(value)) {
|
|
268
288
|
if (visitOnce(value)) return true;
|
|
269
289
|
continue;
|
|
270
290
|
}
|
|
271
|
-
if (isNodeRecord(value)
|
|
272
|
-
if (!Object.hasOwn(value, name)) continue;
|
|
273
|
-
const item = value[name];
|
|
274
|
-
if (isNode(item) && visitOnce(item)) return true;
|
|
275
|
-
}
|
|
291
|
+
if (isNodeRecord(value) && visitRecord(value)) return true;
|
|
276
292
|
}
|
|
277
293
|
return false;
|
|
278
294
|
}
|
|
@@ -1181,23 +1197,33 @@ function memo(store, key, compute) {
|
|
|
1181
1197
|
return value;
|
|
1182
1198
|
}
|
|
1183
1199
|
// src/utils/schemaGraph.ts
|
|
1184
|
-
/**
|
|
1185
|
-
* Walks a node's subtree once and lists every ref it holds, in traversal order, as the resolved
|
|
1186
|
-
* name plus whether the ref carries a `$ref` pointer. Memoized by node identity, so
|
|
1187
|
-
* `collectSchemaRefs` and `collectImportedRefNames` share one scan per schema.
|
|
1188
|
-
*/
|
|
1189
1200
|
const refEntries = /* @__PURE__ */ new WeakMap();
|
|
1201
|
+
const checkRefEntries = /* @__PURE__ */ new WeakMap();
|
|
1190
1202
|
const schemaRefs = /* @__PURE__ */ new WeakMap();
|
|
1191
1203
|
const importedRefNames = /* @__PURE__ */ new WeakMap();
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1204
|
+
const importedCheckRefNames = /* @__PURE__ */ new WeakMap();
|
|
1205
|
+
/**
|
|
1206
|
+
* Walks a node's subtree once and lists every ref it holds, in traversal order, as the resolved
|
|
1207
|
+
* name plus whether the ref carries a `$ref` pointer. Memoized per node and per `checks` mode, so
|
|
1208
|
+
* each helper below scans a schema once.
|
|
1209
|
+
*/
|
|
1210
|
+
function collectRefEntries(node, { checks }) {
|
|
1211
|
+
return memo(checks ? checkRefEntries : refEntries, node, () => {
|
|
1212
|
+
const entries = [];
|
|
1213
|
+
const walk = (current) => {
|
|
1214
|
+
if (current.kind === nodeKinds.schema && current.type === "ref") {
|
|
1215
|
+
const name = resolveRefName(current);
|
|
1216
|
+
if (name) entries.push({
|
|
1217
|
+
name,
|
|
1218
|
+
hasPointer: Boolean(current.ref)
|
|
1219
|
+
});
|
|
1220
|
+
}
|
|
1221
|
+
visitChildNodes(current, walk, { checks });
|
|
1222
|
+
return false;
|
|
1223
|
+
};
|
|
1224
|
+
walk(node);
|
|
1225
|
+
return entries;
|
|
1226
|
+
});
|
|
1201
1227
|
}
|
|
1202
1228
|
/**
|
|
1203
1229
|
* Collects the names of every schema a node's subtree references, resolved with `resolveRefName`.
|
|
@@ -1211,7 +1237,7 @@ function collectRefEntries(node) {
|
|
|
1211
1237
|
* ```
|
|
1212
1238
|
*/
|
|
1213
1239
|
function collectSchemaRefs(node) {
|
|
1214
|
-
return memo(schemaRefs, node, () => new Set(collectRefEntries(node).map((entry) => entry.name)));
|
|
1240
|
+
return memo(schemaRefs, node, () => new Set(collectRefEntries(node, { checks: true }).map((entry) => entry.name)));
|
|
1215
1241
|
}
|
|
1216
1242
|
/**
|
|
1217
1243
|
* Collects the de-duplicated target names of every pointer-carrying ref in a node's subtree, in
|
|
@@ -1220,7 +1246,8 @@ function collectSchemaRefs(node) {
|
|
|
1220
1246
|
*
|
|
1221
1247
|
* Only refs that carry a `$ref` pointer count, so a synthesized ref pointing at a sibling in the
|
|
1222
1248
|
* same file (a union member created by name) is left out. That leaves exactly the set
|
|
1223
|
-
* `resolver.imports` emits.
|
|
1249
|
+
* `resolver.imports` emits. Refs inside `conditionals`, `contains` and `content` count only with
|
|
1250
|
+
* `checks: true`, for a plugin that prints those checks.
|
|
1224
1251
|
*
|
|
1225
1252
|
* @example
|
|
1226
1253
|
* ```ts
|
|
@@ -1228,8 +1255,8 @@ function collectSchemaRefs(node) {
|
|
|
1228
1255
|
* // ['Category', 'Tag']
|
|
1229
1256
|
* ```
|
|
1230
1257
|
*/
|
|
1231
|
-
function collectImportedRefNames(node) {
|
|
1232
|
-
return memo(importedRefNames, node, () => [...new Set(collectRefEntries(node).flatMap((entry) => entry.hasPointer ? [entry.name] : []))]);
|
|
1258
|
+
function collectImportedRefNames(node, { checks = false } = {}) {
|
|
1259
|
+
return memo(checks ? importedCheckRefNames : importedRefNames, node, () => [...new Set(collectRefEntries(node, { checks }).flatMap((entry) => entry.hasPointer ? [entry.name] : []))]);
|
|
1233
1260
|
}
|
|
1234
1261
|
/**
|
|
1235
1262
|
* Collects the names of all top-level schemas transitively used by a set of operations.
|