@kubb/ast 5.15.1 → 5.15.3
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 +120 -234
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +48 -202
- package/dist/index.d.ts +48 -202
- package/dist/index.js +120 -230
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -272,22 +272,6 @@ function getChildren(node, recurse) {
|
|
|
272
272
|
});
|
|
273
273
|
return children;
|
|
274
274
|
}
|
|
275
|
-
/**
|
|
276
|
-
* Visits each direct child node in the AST's traversal order.
|
|
277
|
-
*
|
|
278
|
-
* @example
|
|
279
|
-
* ```ts
|
|
280
|
-
* forEachChild(operationNode, (child) => {
|
|
281
|
-
* console.log(child.kind)
|
|
282
|
-
* })
|
|
283
|
-
* ```
|
|
284
|
-
*/
|
|
285
|
-
function forEachChild(node, visit) {
|
|
286
|
-
visitChildNodes(node, (child) => {
|
|
287
|
-
visit(child);
|
|
288
|
-
return false;
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
275
|
function visitChildNodes(node, visit) {
|
|
292
276
|
const keys = VISITOR_KEYS[node.kind];
|
|
293
277
|
if (!keys) return false;
|
|
@@ -311,23 +295,6 @@ function visitChildNodes(node, visit) {
|
|
|
311
295
|
return false;
|
|
312
296
|
}
|
|
313
297
|
/**
|
|
314
|
-
* Visits each schema in a node's child tree in depth-first order. Includes `node` when it is a schema.
|
|
315
|
-
*
|
|
316
|
-
* @example
|
|
317
|
-
* ```ts
|
|
318
|
-
* forEachSchema(operationNode, (schema) => {
|
|
319
|
-
* console.log(schema.type)
|
|
320
|
-
* })
|
|
321
|
-
* ```
|
|
322
|
-
*/
|
|
323
|
-
function forEachSchema(node, visit) {
|
|
324
|
-
const walk = (current) => {
|
|
325
|
-
if (current.kind === nodeKinds.schema) visit(current);
|
|
326
|
-
forEachChild(current, walk);
|
|
327
|
-
};
|
|
328
|
-
walk(node);
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
298
|
* Finds the first schema that matches `predicate` in depth-first order. Set `followRefs` to include resolved ref targets.
|
|
332
299
|
*
|
|
333
300
|
* @example
|
|
@@ -516,6 +483,16 @@ function enforceWeight(enforce) {
|
|
|
516
483
|
return 1;
|
|
517
484
|
}
|
|
518
485
|
/**
|
|
486
|
+
* Compares two `enforce` hints for `Array.prototype.sort`: `pre` first, unmarked next, `post`
|
|
487
|
+
* last. Equal hints compare as `0`, so a stable sort keeps authored order within a bucket.
|
|
488
|
+
*
|
|
489
|
+
* @example
|
|
490
|
+
* `plugins.sort((a, b) => compareEnforce(a.enforce, b.enforce))`
|
|
491
|
+
*/
|
|
492
|
+
function compareEnforce(a, b) {
|
|
493
|
+
return enforceWeight(a) - enforceWeight(b);
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
519
496
|
* Types a macro for inference and a single construction site, mirroring `defineExtension`.
|
|
520
497
|
* Adds no runtime behavior.
|
|
521
498
|
*
|
|
@@ -549,19 +526,11 @@ function chain({ macros, key, node, context }) {
|
|
|
549
526
|
return current === node ? void 0 : current;
|
|
550
527
|
}
|
|
551
528
|
/**
|
|
552
|
-
* Folds an ordered list of macros into a single {@link Visitor}
|
|
553
|
-
*
|
|
554
|
-
* sequentially per node so later macros see earlier output. This differs from a plain visitor, which
|
|
555
|
-
* has no names, ordering, or composition.
|
|
556
|
-
*
|
|
557
|
-
* @example
|
|
558
|
-
* ```ts
|
|
559
|
-
* const visitor = composeMacros([macroSimplifyUnion, macroDiscriminatorEnum])
|
|
560
|
-
* const next = transform(root, visitor)
|
|
561
|
-
* ```
|
|
529
|
+
* Folds an ordered list of macros into a single {@link Visitor} for `transform`. Macros are
|
|
530
|
+
* stable-sorted by `enforce`, then applied sequentially per node so later macros see earlier output.
|
|
562
531
|
*/
|
|
563
532
|
function composeMacros(macros) {
|
|
564
|
-
const ordered = [...macros].sort((a, b) =>
|
|
533
|
+
const ordered = [...macros].sort((a, b) => compareEnforce(a.enforce, b.enforce));
|
|
565
534
|
const visitor = {};
|
|
566
535
|
for (const key of visitorKeys) {
|
|
567
536
|
if (!ordered.some((macro) => typeof macro[key] === "function")) continue;
|
|
@@ -683,11 +652,25 @@ function createPrinter(build) {
|
|
|
683
652
|
};
|
|
684
653
|
}
|
|
685
654
|
// src/utils/extractStringsFromNodes.ts
|
|
655
|
+
const CODE_NODE_TEXT_FIELDS = {
|
|
656
|
+
Text: ["value"],
|
|
657
|
+
Jsx: ["value"],
|
|
658
|
+
Function: [
|
|
659
|
+
"params",
|
|
660
|
+
"generics",
|
|
661
|
+
"returnType"
|
|
662
|
+
],
|
|
663
|
+
ArrowFunction: [
|
|
664
|
+
"params",
|
|
665
|
+
"generics",
|
|
666
|
+
"returnType"
|
|
667
|
+
],
|
|
668
|
+
Const: ["type"]
|
|
669
|
+
};
|
|
686
670
|
/**
|
|
687
671
|
* Extracts all string content from a `CodeNode` tree recursively.
|
|
688
672
|
*
|
|
689
|
-
* Collects text node
|
|
690
|
-
* and nested node content. Used to build the full source string for import filtering.
|
|
673
|
+
* Collects the text fields and nested node content, to build the source string for import filtering.
|
|
691
674
|
*/
|
|
692
675
|
function extractStringsFromNodes(nodes) {
|
|
693
676
|
if (!nodes?.length) return "";
|
|
@@ -697,17 +680,15 @@ function extractStringsFromNodes(nodes) {
|
|
|
697
680
|
if (node) collected.push(node);
|
|
698
681
|
continue;
|
|
699
682
|
}
|
|
700
|
-
if (node.kind === nodeKinds.text || node.kind === nodeKinds.jsx) {
|
|
701
|
-
if (node.value) collected.push(node.value);
|
|
702
|
-
continue;
|
|
703
|
-
}
|
|
704
683
|
if (node.kind === nodeKinds.break) continue;
|
|
705
684
|
const parts = [];
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
685
|
+
const record = node;
|
|
686
|
+
for (const field of CODE_NODE_TEXT_FIELDS[node.kind] ?? []) {
|
|
687
|
+
const value = record[field];
|
|
688
|
+
if (Array.isArray(value)) parts.push(value.join(", "));
|
|
689
|
+
if (typeof value === "string" && value) parts.push(value);
|
|
690
|
+
}
|
|
691
|
+
const nested = "nodes" in node ? extractStringsFromNodes(node.nodes) : "";
|
|
711
692
|
if (nested) parts.push(nested);
|
|
712
693
|
if (parts.length) collected.push(parts.join("\n"));
|
|
713
694
|
}
|
|
@@ -975,17 +956,11 @@ function createFile(input) {
|
|
|
975
956
|
}
|
|
976
957
|
// src/utils/inline.ts
|
|
977
958
|
/**
|
|
978
|
-
*
|
|
979
|
-
*/
|
|
980
|
-
function isVirtualFile(file) {
|
|
981
|
-
return file.sources.length > 0 && file.sources.every((source) => source.inline);
|
|
982
|
-
}
|
|
983
|
-
/**
|
|
984
|
-
* Replaces every name a file imports from a virtual file (see {@link isVirtualFile}) with that name's
|
|
959
|
+
* Replaces every name a file imports from a virtual file (one whose sources are all inline, so it is never written) with that name's
|
|
985
960
|
* `inline.expression`, until no inline names are left. The definitions' own imports move to the importing file.
|
|
986
961
|
*/
|
|
987
962
|
function inlineFiles(files, { language }) {
|
|
988
|
-
const virtualFiles = new Map(files.filter(
|
|
963
|
+
const virtualFiles = new Map(files.filter((file) => file.sources.length > 0 && file.sources.every((source) => source.inline)).map((file) => [file.path, file]));
|
|
989
964
|
const result = {
|
|
990
965
|
files: [],
|
|
991
966
|
virtualPaths: [...virtualFiles.keys()],
|
|
@@ -1090,31 +1065,15 @@ function pickNames(imp, used) {
|
|
|
1090
1065
|
function rewriteNodes(nodes, rewrite) {
|
|
1091
1066
|
return nodes?.map((node) => {
|
|
1092
1067
|
if (typeof node === "string") return rewrite(node);
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
};
|
|
1100
|
-
case nodeKinds.function:
|
|
1101
|
-
case nodeKinds.arrowFunction: return {
|
|
1102
|
-
...node,
|
|
1103
|
-
params: node.params && rewrite(node.params),
|
|
1104
|
-
generics: Array.isArray(node.generics) ? node.generics.map(rewrite) : node.generics && rewrite(node.generics),
|
|
1105
|
-
returnType: node.returnType && rewrite(node.returnType),
|
|
1106
|
-
nodes: rewriteNodes(node.nodes, rewrite)
|
|
1107
|
-
};
|
|
1108
|
-
case nodeKinds.const: return {
|
|
1109
|
-
...node,
|
|
1110
|
-
type: node.type && rewrite(node.type),
|
|
1111
|
-
nodes: rewriteNodes(node.nodes, rewrite)
|
|
1112
|
-
};
|
|
1113
|
-
default: return {
|
|
1114
|
-
...node,
|
|
1115
|
-
nodes: rewriteNodes(node.nodes, rewrite)
|
|
1116
|
-
};
|
|
1068
|
+
if (node.kind === nodeKinds.break) return node;
|
|
1069
|
+
const next = { ...node };
|
|
1070
|
+
for (const field of CODE_NODE_TEXT_FIELDS[node.kind] ?? []) {
|
|
1071
|
+
const value = next[field];
|
|
1072
|
+
if (Array.isArray(value)) next[field] = value.map(rewrite);
|
|
1073
|
+
if (typeof value === "string" && value) next[field] = rewrite(value);
|
|
1117
1074
|
}
|
|
1075
|
+
if ("nodes" in node && node.nodes) next.nodes = rewriteNodes(node.nodes, rewrite);
|
|
1076
|
+
return next;
|
|
1118
1077
|
});
|
|
1119
1078
|
}
|
|
1120
1079
|
// src/utils/refs.ts
|
|
@@ -1220,49 +1179,42 @@ function isBareRef(node, keysToOmit) {
|
|
|
1220
1179
|
}
|
|
1221
1180
|
// ../../internals/utils/src/promise.ts
|
|
1222
1181
|
/**
|
|
1223
|
-
*
|
|
1182
|
+
* Returns the value cached under `key` in `store`, computing and storing it on the first call.
|
|
1183
|
+
* Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive
|
|
1184
|
+
* keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.
|
|
1224
1185
|
*
|
|
1225
|
-
*
|
|
1226
|
-
*
|
|
1227
|
-
* nest two `memoize` calls — the outer keyed by the first argument, the
|
|
1228
|
-
* inner (created once per outer miss) keyed by the second.
|
|
1229
|
-
*
|
|
1230
|
-
* Because the cache is owned by the caller, it can be shared, inspected, or
|
|
1231
|
-
* cleared independently of the memoized function.
|
|
1232
|
-
*
|
|
1233
|
-
* @example Single WeakMap key
|
|
1234
|
-
* ```ts
|
|
1235
|
-
* const cache = new WeakMap<SchemaNode, Set<string>>()
|
|
1236
|
-
* const getRefs = memoize(cache, (node) => collectRefs(node))
|
|
1237
|
-
* ```
|
|
1238
|
-
*
|
|
1239
|
-
* @example Single Map key (primitive)
|
|
1240
|
-
* ```ts
|
|
1241
|
-
* const cache = new Map<string, Resolver>()
|
|
1242
|
-
* const getResolver = memoize(cache, (name) => buildResolver(name))
|
|
1243
|
-
* ```
|
|
1244
|
-
*
|
|
1245
|
-
* @example Two-level (object + primitive)
|
|
1246
|
-
* ```ts
|
|
1247
|
-
* const outer = new WeakMap<Params[], Map<string, Params[]>>()
|
|
1248
|
-
* const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))
|
|
1249
|
-
* fn(params)('camelcase')
|
|
1250
|
-
* ```
|
|
1186
|
+
* @example
|
|
1187
|
+
* `const refs = memo(refCache, node, () => collectRefs(node))`
|
|
1251
1188
|
*/
|
|
1252
|
-
function
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
return value;
|
|
1258
|
-
};
|
|
1189
|
+
function memo(store, key, compute) {
|
|
1190
|
+
if (store.has(key)) return store.get(key);
|
|
1191
|
+
const value = compute();
|
|
1192
|
+
store.set(key, value);
|
|
1193
|
+
return value;
|
|
1259
1194
|
}
|
|
1260
1195
|
// src/utils/schemaGraph.ts
|
|
1261
1196
|
/**
|
|
1197
|
+
* Walks a node's subtree once and lists every ref it holds, in traversal order, as the resolved
|
|
1198
|
+
* name plus whether the ref carries a `$ref` pointer. Memoized by node identity, so
|
|
1199
|
+
* `collectSchemaRefs` and `collectImportedRefNames` share one scan per schema.
|
|
1200
|
+
*/
|
|
1201
|
+
const refEntries = /* @__PURE__ */ new WeakMap();
|
|
1202
|
+
const schemaRefs = /* @__PURE__ */ new WeakMap();
|
|
1203
|
+
const importedRefNames = /* @__PURE__ */ new WeakMap();
|
|
1204
|
+
function collectRefEntries(node) {
|
|
1205
|
+
return memo(refEntries, node, () => collectSync(node, { schema(child) {
|
|
1206
|
+
if (child.type !== "ref") return void 0;
|
|
1207
|
+
const name = resolveRefName(child);
|
|
1208
|
+
return name ? {
|
|
1209
|
+
name,
|
|
1210
|
+
hasPointer: Boolean(child.ref)
|
|
1211
|
+
} : void 0;
|
|
1212
|
+
} }));
|
|
1213
|
+
}
|
|
1214
|
+
/**
|
|
1262
1215
|
* Collects the names of every schema a node's subtree references, resolved with `resolveRefName`.
|
|
1263
|
-
* Each ref contributes its name only, so the schema it points to is never traversed.
|
|
1264
|
-
*
|
|
1265
|
-
* scan per schema.
|
|
1216
|
+
* Each ref contributes its name only, so the schema it points to is never traversed. Memoized by
|
|
1217
|
+
* node identity, which lets `findCircularSchemas` and `containsCircularRef` share one scan per schema.
|
|
1266
1218
|
*
|
|
1267
1219
|
* @example
|
|
1268
1220
|
* ```ts
|
|
@@ -1270,21 +1222,13 @@ function memoize(store, factory) {
|
|
|
1270
1222
|
* // Set { 'Category', 'Tag' }
|
|
1271
1223
|
* ```
|
|
1272
1224
|
*/
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
if (child.type === "ref") {
|
|
1277
|
-
const name = resolveRefName(child);
|
|
1278
|
-
if (name) refs.add(name);
|
|
1279
|
-
}
|
|
1280
|
-
} });
|
|
1281
|
-
return refs;
|
|
1282
|
-
});
|
|
1225
|
+
function collectSchemaRefs(node) {
|
|
1226
|
+
return memo(schemaRefs, node, () => new Set(collectRefEntries(node).map((entry) => entry.name)));
|
|
1227
|
+
}
|
|
1283
1228
|
/**
|
|
1284
1229
|
* Collects the de-duplicated target names of every pointer-carrying ref in a node's subtree, in
|
|
1285
|
-
* first-occurrence order.
|
|
1286
|
-
*
|
|
1287
|
-
* re-scanning the same schema per plugin.
|
|
1230
|
+
* first-occurrence order. Memoized by node identity, so `resolver.imports` reads the same result
|
|
1231
|
+
* across the ts, zod, and faker plugins instead of re-scanning the same schema per plugin.
|
|
1288
1232
|
*
|
|
1289
1233
|
* Only refs that carry a `$ref` pointer count, so a synthesized ref pointing at a sibling in the
|
|
1290
1234
|
* same file (a union member created by name) is left out. That leaves exactly the set
|
|
@@ -1296,19 +1240,9 @@ const collectSchemaRefs = memoize(/* @__PURE__ */ new WeakMap(), (node) => {
|
|
|
1296
1240
|
* // ['Category', 'Tag']
|
|
1297
1241
|
* ```
|
|
1298
1242
|
*/
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
collectSync(node, { schema(child) {
|
|
1303
|
-
if (child.type !== "ref" || !child.ref) return;
|
|
1304
|
-
const name = resolveRefName(child);
|
|
1305
|
-
if (name && !seen.has(name)) {
|
|
1306
|
-
seen.add(name);
|
|
1307
|
-
names.push(name);
|
|
1308
|
-
}
|
|
1309
|
-
} });
|
|
1310
|
-
return names;
|
|
1311
|
-
});
|
|
1243
|
+
function collectImportedRefNames(node) {
|
|
1244
|
+
return memo(importedRefNames, node, () => [...new Set(collectRefEntries(node).flatMap((entry) => entry.hasPointer ? [entry.name] : []))]);
|
|
1245
|
+
}
|
|
1312
1246
|
/**
|
|
1313
1247
|
* Collects the names of all top-level schemas transitively used by a set of operations.
|
|
1314
1248
|
*
|
|
@@ -1347,23 +1281,17 @@ function collectUsedSchemaNames(operations, schemas) {
|
|
|
1347
1281
|
return result;
|
|
1348
1282
|
}
|
|
1349
1283
|
/**
|
|
1350
|
-
* Finds every schema that takes part in a circular dependency chain
|
|
1351
|
-
* that maps each schema name to the names it references directly.
|
|
1284
|
+
* Finds every schema that takes part in a circular dependency chain, including direct self-loops.
|
|
1352
1285
|
*
|
|
1353
|
-
*
|
|
1354
|
-
*
|
|
1355
|
-
*
|
|
1286
|
+
* Wrap the returned schema positions in a deferred construct (a lazy getter or `z.lazy(() => …)`) so
|
|
1287
|
+
* the generated code does not recurse forever. Refs are followed by name only, so the walk stays
|
|
1288
|
+
* linear in the size of the schema graph.
|
|
1356
1289
|
*
|
|
1357
|
-
* @
|
|
1358
|
-
* ```ts
|
|
1359
|
-
* const graph = new Map([
|
|
1360
|
-
* ['Pet', new Set(['Category'])],
|
|
1361
|
-
* ['Category', new Set(['Pet'])],
|
|
1362
|
-
* ])
|
|
1363
|
-
* findCircularSchemasFromGraph(graph) // Set { 'Pet', 'Category' }
|
|
1364
|
-
* ```
|
|
1290
|
+
* @note Call this once on the full graph, then check individual schemas with `containsCircularRef()`.
|
|
1365
1291
|
*/
|
|
1366
|
-
function
|
|
1292
|
+
function findCircularSchemas(schemas) {
|
|
1293
|
+
const graph = /* @__PURE__ */ new Map();
|
|
1294
|
+
for (const schema of schemas) if (schema.name) graph.set(schema.name, collectSchemaRefs(schema));
|
|
1367
1295
|
const circular = /* @__PURE__ */ new Set();
|
|
1368
1296
|
for (const start of graph.keys()) {
|
|
1369
1297
|
const visited = /* @__PURE__ */ new Set();
|
|
@@ -1382,20 +1310,6 @@ function findCircularSchemasFromGraph(graph) {
|
|
|
1382
1310
|
}
|
|
1383
1311
|
return circular;
|
|
1384
1312
|
}
|
|
1385
|
-
/**
|
|
1386
|
-
* Finds every schema that takes part in a circular dependency chain, including direct self-loops.
|
|
1387
|
-
*
|
|
1388
|
-
* Wrap the returned schema positions in a deferred construct (a lazy getter or `z.lazy(() => …)`) so
|
|
1389
|
-
* the generated code does not recurse forever. Refs are followed by name only, so the walk stays
|
|
1390
|
-
* linear in the size of the schema graph.
|
|
1391
|
-
*
|
|
1392
|
-
* @note Call this once on the full graph, then check individual schemas with `containsCircularRef()`.
|
|
1393
|
-
*/
|
|
1394
|
-
function findCircularSchemas(schemas) {
|
|
1395
|
-
const graph = /* @__PURE__ */ new Map();
|
|
1396
|
-
for (const schema of schemas) if (schema.name) graph.set(schema.name, collectSchemaRefs(schema));
|
|
1397
|
-
return findCircularSchemasFromGraph(graph);
|
|
1398
|
-
}
|
|
1399
1313
|
// src/utils/schemaProperties.ts
|
|
1400
1314
|
/**
|
|
1401
1315
|
* Finds every matching property exposed by an object, resolved reference, or intersection.
|
|
@@ -1428,23 +1342,23 @@ function findCircularSchemas(schemas) {
|
|
|
1428
1342
|
*/
|
|
1429
1343
|
function resolveSchemaProperties({ node, propertyName }) {
|
|
1430
1344
|
const properties = [];
|
|
1345
|
+
walkSchema(node, "intersection", (current) => {
|
|
1346
|
+
if (current.type !== "object") return;
|
|
1347
|
+
const property = current.properties.find((candidate) => candidate.name === propertyName);
|
|
1348
|
+
if (property) properties.push(property);
|
|
1349
|
+
});
|
|
1350
|
+
return properties;
|
|
1351
|
+
}
|
|
1352
|
+
function walkSchema(node, through, visit) {
|
|
1431
1353
|
const visited = /* @__PURE__ */ new WeakSet();
|
|
1432
|
-
function
|
|
1354
|
+
function walk(current) {
|
|
1433
1355
|
if (!current || visited.has(current)) return;
|
|
1434
1356
|
visited.add(current);
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
return;
|
|
1439
|
-
}
|
|
1440
|
-
if (current.type === "ref") {
|
|
1441
|
-
visit(current.schema);
|
|
1442
|
-
return;
|
|
1443
|
-
}
|
|
1444
|
-
if (current.type === "intersection") for (const member of current.members ?? []) visit(member);
|
|
1357
|
+
visit(current);
|
|
1358
|
+
if (current.type === "ref") return walk(current.schema);
|
|
1359
|
+
if (current.type === through) for (const member of current.members ?? []) walk(member);
|
|
1445
1360
|
}
|
|
1446
|
-
|
|
1447
|
-
return properties;
|
|
1361
|
+
walk(node);
|
|
1448
1362
|
}
|
|
1449
1363
|
/**
|
|
1450
1364
|
* Reads the unique literal values represented by an enum, resolved reference, or union.
|
|
@@ -1460,35 +1374,18 @@ function resolveSchemaProperties({ node, propertyName }) {
|
|
|
1460
1374
|
*/
|
|
1461
1375
|
function getSchemaLiteralValues(node) {
|
|
1462
1376
|
const values = /* @__PURE__ */ new Set();
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
if (current.type === "enum") {
|
|
1468
|
-
const enumValues = current.namedEnumValues?.map(({ value }) => value) ?? current.enumValues ?? [];
|
|
1469
|
-
for (const value of enumValues) values.add(value);
|
|
1470
|
-
return;
|
|
1471
|
-
}
|
|
1472
|
-
if (current.type === "ref") {
|
|
1473
|
-
visit(current.schema);
|
|
1474
|
-
return;
|
|
1475
|
-
}
|
|
1476
|
-
if (current.type === "union") for (const member of current.members ?? []) visit(member);
|
|
1477
|
-
}
|
|
1478
|
-
visit(node);
|
|
1377
|
+
walkSchema(node, "union", (current) => {
|
|
1378
|
+
if (current.type !== "enum") return;
|
|
1379
|
+
for (const { value } of current.namedEnumValues ?? current.enumValues?.map((value) => ({ value })) ?? []) values.add(value);
|
|
1380
|
+
});
|
|
1479
1381
|
return [...values];
|
|
1480
1382
|
}
|
|
1481
|
-
function collectPropertyNames(node
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
const names = /* @__PURE__ */ new Set();
|
|
1488
|
-
for (const member of node.members ?? []) for (const name of collectPropertyNames(member, visited)) names.add(name);
|
|
1489
|
-
return names;
|
|
1490
|
-
}
|
|
1491
|
-
return /* @__PURE__ */ new Set();
|
|
1383
|
+
function collectPropertyNames(node) {
|
|
1384
|
+
const names = /* @__PURE__ */ new Set();
|
|
1385
|
+
walkSchema(node, "intersection", (current) => {
|
|
1386
|
+
if (current.type === "object") for (const property of current.properties) names.add(property.name);
|
|
1387
|
+
});
|
|
1388
|
+
return names;
|
|
1492
1389
|
}
|
|
1493
1390
|
/**
|
|
1494
1391
|
* Infers an implicit discriminator: a property every member exposes with a distinct single
|
|
@@ -1602,8 +1499,8 @@ function createJsx(value) {
|
|
|
1602
1499
|
const createContent = nodeFactory(nodeKinds.content);
|
|
1603
1500
|
// src/nodes/input.ts
|
|
1604
1501
|
/**
|
|
1605
|
-
* Creates an `InputNode`, defaulting `schemas`/`operations` to empty arrays and `meta` to empty
|
|
1606
|
-
*
|
|
1502
|
+
* Creates an `InputNode`, defaulting `schemas`/`operations` to empty arrays and `meta` to an empty
|
|
1503
|
+
* object. Every call allocates fresh defaults so no two inputs share them.
|
|
1607
1504
|
*
|
|
1608
1505
|
* @example
|
|
1609
1506
|
* ```ts
|
|
@@ -1615,10 +1512,7 @@ function createInput(overrides = {}) {
|
|
|
1615
1512
|
return {
|
|
1616
1513
|
schemas: [],
|
|
1617
1514
|
operations: [],
|
|
1618
|
-
meta: {
|
|
1619
|
-
circularNames: /* @__PURE__ */ new Set(),
|
|
1620
|
-
enumNames: /* @__PURE__ */ new Set()
|
|
1621
|
-
},
|
|
1515
|
+
meta: {},
|
|
1622
1516
|
...overrides,
|
|
1623
1517
|
kind: nodeKinds.input
|
|
1624
1518
|
};
|
|
@@ -1786,22 +1680,18 @@ var src_exports = /* @__PURE__ */ __exportAll({
|
|
|
1786
1680
|
collectSchemaRefs: () => collectSchemaRefs,
|
|
1787
1681
|
collectSync: () => collectSync,
|
|
1788
1682
|
collectUsedSchemaNames: () => collectUsedSchemaNames,
|
|
1789
|
-
|
|
1683
|
+
compareEnforce: () => compareEnforce,
|
|
1790
1684
|
createPrinter: () => createPrinter,
|
|
1791
1685
|
defineMacro: () => defineMacro,
|
|
1792
1686
|
extractStringsFromNodes: () => extractStringsFromNodes,
|
|
1793
1687
|
factory: () => nodes_exports,
|
|
1794
1688
|
findCircularSchemas: () => findCircularSchemas,
|
|
1795
|
-
findCircularSchemasFromGraph: () => findCircularSchemasFromGraph,
|
|
1796
1689
|
findSchema: () => findSchema,
|
|
1797
|
-
forEachChild: () => forEachChild,
|
|
1798
|
-
forEachSchema: () => forEachSchema,
|
|
1799
1690
|
getSchemaLiteralValues: () => getSchemaLiteralValues,
|
|
1800
1691
|
inferDiscriminatorPropertyName: () => inferDiscriminatorPropertyName,
|
|
1801
1692
|
inlineFiles: () => inlineFiles,
|
|
1802
1693
|
isBareRef: () => isBareRef,
|
|
1803
1694
|
isHttpOperationNode: () => isHttpOperationNode,
|
|
1804
|
-
isVirtualFile: () => isVirtualFile,
|
|
1805
1695
|
mergeRefWithSchema: () => mergeRefWithSchema,
|
|
1806
1696
|
narrowSchema: () => narrowSchema,
|
|
1807
1697
|
nodeKinds: () => nodeKinds,
|
|
@@ -1825,7 +1715,7 @@ exports.collectImportedRefNames = collectImportedRefNames;
|
|
|
1825
1715
|
exports.collectSchemaRefs = collectSchemaRefs;
|
|
1826
1716
|
exports.collectSync = collectSync;
|
|
1827
1717
|
exports.collectUsedSchemaNames = collectUsedSchemaNames;
|
|
1828
|
-
exports.
|
|
1718
|
+
exports.compareEnforce = compareEnforce;
|
|
1829
1719
|
exports.createPrinter = createPrinter;
|
|
1830
1720
|
exports.defineMacro = defineMacro;
|
|
1831
1721
|
exports.extractStringsFromNodes = extractStringsFromNodes;
|
|
@@ -1836,16 +1726,12 @@ Object.defineProperty(exports, "factory", {
|
|
|
1836
1726
|
}
|
|
1837
1727
|
});
|
|
1838
1728
|
exports.findCircularSchemas = findCircularSchemas;
|
|
1839
|
-
exports.findCircularSchemasFromGraph = findCircularSchemasFromGraph;
|
|
1840
1729
|
exports.findSchema = findSchema;
|
|
1841
|
-
exports.forEachChild = forEachChild;
|
|
1842
|
-
exports.forEachSchema = forEachSchema;
|
|
1843
1730
|
exports.getSchemaLiteralValues = getSchemaLiteralValues;
|
|
1844
1731
|
exports.inferDiscriminatorPropertyName = inferDiscriminatorPropertyName;
|
|
1845
1732
|
exports.inlineFiles = inlineFiles;
|
|
1846
1733
|
exports.isBareRef = isBareRef;
|
|
1847
1734
|
exports.isHttpOperationNode = isHttpOperationNode;
|
|
1848
|
-
exports.isVirtualFile = isVirtualFile;
|
|
1849
1735
|
exports.mergeRefWithSchema = mergeRefWithSchema;
|
|
1850
1736
|
exports.narrowSchema = narrowSchema;
|
|
1851
1737
|
exports.nodeKinds = nodeKinds;
|