@kubb/ast 5.15.1 → 5.15.2
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.js
CHANGED
|
@@ -251,22 +251,6 @@ function getChildren(node, recurse) {
|
|
|
251
251
|
});
|
|
252
252
|
return children;
|
|
253
253
|
}
|
|
254
|
-
/**
|
|
255
|
-
* Visits each direct child node in the AST's traversal order.
|
|
256
|
-
*
|
|
257
|
-
* @example
|
|
258
|
-
* ```ts
|
|
259
|
-
* forEachChild(operationNode, (child) => {
|
|
260
|
-
* console.log(child.kind)
|
|
261
|
-
* })
|
|
262
|
-
* ```
|
|
263
|
-
*/
|
|
264
|
-
function forEachChild(node, visit) {
|
|
265
|
-
visitChildNodes(node, (child) => {
|
|
266
|
-
visit(child);
|
|
267
|
-
return false;
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
254
|
function visitChildNodes(node, visit) {
|
|
271
255
|
const keys = VISITOR_KEYS[node.kind];
|
|
272
256
|
if (!keys) return false;
|
|
@@ -290,23 +274,6 @@ function visitChildNodes(node, visit) {
|
|
|
290
274
|
return false;
|
|
291
275
|
}
|
|
292
276
|
/**
|
|
293
|
-
* Visits each schema in a node's child tree in depth-first order. Includes `node` when it is a schema.
|
|
294
|
-
*
|
|
295
|
-
* @example
|
|
296
|
-
* ```ts
|
|
297
|
-
* forEachSchema(operationNode, (schema) => {
|
|
298
|
-
* console.log(schema.type)
|
|
299
|
-
* })
|
|
300
|
-
* ```
|
|
301
|
-
*/
|
|
302
|
-
function forEachSchema(node, visit) {
|
|
303
|
-
const walk = (current) => {
|
|
304
|
-
if (current.kind === nodeKinds.schema) visit(current);
|
|
305
|
-
forEachChild(current, walk);
|
|
306
|
-
};
|
|
307
|
-
walk(node);
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
277
|
* Finds the first schema that matches `predicate` in depth-first order. Set `followRefs` to include resolved ref targets.
|
|
311
278
|
*
|
|
312
279
|
* @example
|
|
@@ -495,6 +462,16 @@ function enforceWeight(enforce) {
|
|
|
495
462
|
return 1;
|
|
496
463
|
}
|
|
497
464
|
/**
|
|
465
|
+
* Compares two `enforce` hints for `Array.prototype.sort`: `pre` first, unmarked next, `post`
|
|
466
|
+
* last. Equal hints compare as `0`, so a stable sort keeps authored order within a bucket.
|
|
467
|
+
*
|
|
468
|
+
* @example
|
|
469
|
+
* `plugins.sort((a, b) => compareEnforce(a.enforce, b.enforce))`
|
|
470
|
+
*/
|
|
471
|
+
function compareEnforce(a, b) {
|
|
472
|
+
return enforceWeight(a) - enforceWeight(b);
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
498
475
|
* Types a macro for inference and a single construction site, mirroring `defineExtension`.
|
|
499
476
|
* Adds no runtime behavior.
|
|
500
477
|
*
|
|
@@ -528,19 +505,11 @@ function chain({ macros, key, node, context }) {
|
|
|
528
505
|
return current === node ? void 0 : current;
|
|
529
506
|
}
|
|
530
507
|
/**
|
|
531
|
-
* Folds an ordered list of macros into a single {@link Visitor}
|
|
532
|
-
*
|
|
533
|
-
* sequentially per node so later macros see earlier output. This differs from a plain visitor, which
|
|
534
|
-
* has no names, ordering, or composition.
|
|
535
|
-
*
|
|
536
|
-
* @example
|
|
537
|
-
* ```ts
|
|
538
|
-
* const visitor = composeMacros([macroSimplifyUnion, macroDiscriminatorEnum])
|
|
539
|
-
* const next = transform(root, visitor)
|
|
540
|
-
* ```
|
|
508
|
+
* Folds an ordered list of macros into a single {@link Visitor} for `transform`. Macros are
|
|
509
|
+
* stable-sorted by `enforce`, then applied sequentially per node so later macros see earlier output.
|
|
541
510
|
*/
|
|
542
511
|
function composeMacros(macros) {
|
|
543
|
-
const ordered = [...macros].sort((a, b) =>
|
|
512
|
+
const ordered = [...macros].sort((a, b) => compareEnforce(a.enforce, b.enforce));
|
|
544
513
|
const visitor = {};
|
|
545
514
|
for (const key of visitorKeys) {
|
|
546
515
|
if (!ordered.some((macro) => typeof macro[key] === "function")) continue;
|
|
@@ -662,11 +631,25 @@ function createPrinter(build) {
|
|
|
662
631
|
};
|
|
663
632
|
}
|
|
664
633
|
// src/utils/extractStringsFromNodes.ts
|
|
634
|
+
const CODE_NODE_TEXT_FIELDS = {
|
|
635
|
+
Text: ["value"],
|
|
636
|
+
Jsx: ["value"],
|
|
637
|
+
Function: [
|
|
638
|
+
"params",
|
|
639
|
+
"generics",
|
|
640
|
+
"returnType"
|
|
641
|
+
],
|
|
642
|
+
ArrowFunction: [
|
|
643
|
+
"params",
|
|
644
|
+
"generics",
|
|
645
|
+
"returnType"
|
|
646
|
+
],
|
|
647
|
+
Const: ["type"]
|
|
648
|
+
};
|
|
665
649
|
/**
|
|
666
650
|
* Extracts all string content from a `CodeNode` tree recursively.
|
|
667
651
|
*
|
|
668
|
-
* Collects text node
|
|
669
|
-
* and nested node content. Used to build the full source string for import filtering.
|
|
652
|
+
* Collects the text fields and nested node content, to build the source string for import filtering.
|
|
670
653
|
*/
|
|
671
654
|
function extractStringsFromNodes(nodes) {
|
|
672
655
|
if (!nodes?.length) return "";
|
|
@@ -676,17 +659,15 @@ function extractStringsFromNodes(nodes) {
|
|
|
676
659
|
if (node) collected.push(node);
|
|
677
660
|
continue;
|
|
678
661
|
}
|
|
679
|
-
if (node.kind === nodeKinds.text || node.kind === nodeKinds.jsx) {
|
|
680
|
-
if (node.value) collected.push(node.value);
|
|
681
|
-
continue;
|
|
682
|
-
}
|
|
683
662
|
if (node.kind === nodeKinds.break) continue;
|
|
684
663
|
const parts = [];
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
664
|
+
const record = node;
|
|
665
|
+
for (const field of CODE_NODE_TEXT_FIELDS[node.kind] ?? []) {
|
|
666
|
+
const value = record[field];
|
|
667
|
+
if (Array.isArray(value)) parts.push(value.join(", "));
|
|
668
|
+
if (typeof value === "string" && value) parts.push(value);
|
|
669
|
+
}
|
|
670
|
+
const nested = "nodes" in node ? extractStringsFromNodes(node.nodes) : "";
|
|
690
671
|
if (nested) parts.push(nested);
|
|
691
672
|
if (parts.length) collected.push(parts.join("\n"));
|
|
692
673
|
}
|
|
@@ -954,17 +935,11 @@ function createFile(input) {
|
|
|
954
935
|
}
|
|
955
936
|
// src/utils/inline.ts
|
|
956
937
|
/**
|
|
957
|
-
*
|
|
958
|
-
*/
|
|
959
|
-
function isVirtualFile(file) {
|
|
960
|
-
return file.sources.length > 0 && file.sources.every((source) => source.inline);
|
|
961
|
-
}
|
|
962
|
-
/**
|
|
963
|
-
* Replaces every name a file imports from a virtual file (see {@link isVirtualFile}) with that name's
|
|
938
|
+
* 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
|
|
964
939
|
* `inline.expression`, until no inline names are left. The definitions' own imports move to the importing file.
|
|
965
940
|
*/
|
|
966
941
|
function inlineFiles(files, { language }) {
|
|
967
|
-
const virtualFiles = new Map(files.filter(
|
|
942
|
+
const virtualFiles = new Map(files.filter((file) => file.sources.length > 0 && file.sources.every((source) => source.inline)).map((file) => [file.path, file]));
|
|
968
943
|
const result = {
|
|
969
944
|
files: [],
|
|
970
945
|
virtualPaths: [...virtualFiles.keys()],
|
|
@@ -1069,31 +1044,15 @@ function pickNames(imp, used) {
|
|
|
1069
1044
|
function rewriteNodes(nodes, rewrite) {
|
|
1070
1045
|
return nodes?.map((node) => {
|
|
1071
1046
|
if (typeof node === "string") return rewrite(node);
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
};
|
|
1079
|
-
case nodeKinds.function:
|
|
1080
|
-
case nodeKinds.arrowFunction: return {
|
|
1081
|
-
...node,
|
|
1082
|
-
params: node.params && rewrite(node.params),
|
|
1083
|
-
generics: Array.isArray(node.generics) ? node.generics.map(rewrite) : node.generics && rewrite(node.generics),
|
|
1084
|
-
returnType: node.returnType && rewrite(node.returnType),
|
|
1085
|
-
nodes: rewriteNodes(node.nodes, rewrite)
|
|
1086
|
-
};
|
|
1087
|
-
case nodeKinds.const: return {
|
|
1088
|
-
...node,
|
|
1089
|
-
type: node.type && rewrite(node.type),
|
|
1090
|
-
nodes: rewriteNodes(node.nodes, rewrite)
|
|
1091
|
-
};
|
|
1092
|
-
default: return {
|
|
1093
|
-
...node,
|
|
1094
|
-
nodes: rewriteNodes(node.nodes, rewrite)
|
|
1095
|
-
};
|
|
1047
|
+
if (node.kind === nodeKinds.break) return node;
|
|
1048
|
+
const next = { ...node };
|
|
1049
|
+
for (const field of CODE_NODE_TEXT_FIELDS[node.kind] ?? []) {
|
|
1050
|
+
const value = next[field];
|
|
1051
|
+
if (Array.isArray(value)) next[field] = value.map(rewrite);
|
|
1052
|
+
if (typeof value === "string" && value) next[field] = rewrite(value);
|
|
1096
1053
|
}
|
|
1054
|
+
if ("nodes" in node && node.nodes) next.nodes = rewriteNodes(node.nodes, rewrite);
|
|
1055
|
+
return next;
|
|
1097
1056
|
});
|
|
1098
1057
|
}
|
|
1099
1058
|
// src/utils/refs.ts
|
|
@@ -1199,49 +1158,42 @@ function isBareRef(node, keysToOmit) {
|
|
|
1199
1158
|
}
|
|
1200
1159
|
// ../../internals/utils/src/promise.ts
|
|
1201
1160
|
/**
|
|
1202
|
-
*
|
|
1161
|
+
* Returns the value cached under `key` in `store`, computing and storing it on the first call.
|
|
1162
|
+
* Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive
|
|
1163
|
+
* keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.
|
|
1203
1164
|
*
|
|
1204
|
-
*
|
|
1205
|
-
*
|
|
1206
|
-
* nest two `memoize` calls — the outer keyed by the first argument, the
|
|
1207
|
-
* inner (created once per outer miss) keyed by the second.
|
|
1208
|
-
*
|
|
1209
|
-
* Because the cache is owned by the caller, it can be shared, inspected, or
|
|
1210
|
-
* cleared independently of the memoized function.
|
|
1211
|
-
*
|
|
1212
|
-
* @example Single WeakMap key
|
|
1213
|
-
* ```ts
|
|
1214
|
-
* const cache = new WeakMap<SchemaNode, Set<string>>()
|
|
1215
|
-
* const getRefs = memoize(cache, (node) => collectRefs(node))
|
|
1216
|
-
* ```
|
|
1217
|
-
*
|
|
1218
|
-
* @example Single Map key (primitive)
|
|
1219
|
-
* ```ts
|
|
1220
|
-
* const cache = new Map<string, Resolver>()
|
|
1221
|
-
* const getResolver = memoize(cache, (name) => buildResolver(name))
|
|
1222
|
-
* ```
|
|
1223
|
-
*
|
|
1224
|
-
* @example Two-level (object + primitive)
|
|
1225
|
-
* ```ts
|
|
1226
|
-
* const outer = new WeakMap<Params[], Map<string, Params[]>>()
|
|
1227
|
-
* const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))
|
|
1228
|
-
* fn(params)('camelcase')
|
|
1229
|
-
* ```
|
|
1165
|
+
* @example
|
|
1166
|
+
* `const refs = memo(refCache, node, () => collectRefs(node))`
|
|
1230
1167
|
*/
|
|
1231
|
-
function
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
return value;
|
|
1237
|
-
};
|
|
1168
|
+
function memo(store, key, compute) {
|
|
1169
|
+
if (store.has(key)) return store.get(key);
|
|
1170
|
+
const value = compute();
|
|
1171
|
+
store.set(key, value);
|
|
1172
|
+
return value;
|
|
1238
1173
|
}
|
|
1239
1174
|
// src/utils/schemaGraph.ts
|
|
1240
1175
|
/**
|
|
1176
|
+
* Walks a node's subtree once and lists every ref it holds, in traversal order, as the resolved
|
|
1177
|
+
* name plus whether the ref carries a `$ref` pointer. Memoized by node identity, so
|
|
1178
|
+
* `collectSchemaRefs` and `collectImportedRefNames` share one scan per schema.
|
|
1179
|
+
*/
|
|
1180
|
+
const refEntries = /* @__PURE__ */ new WeakMap();
|
|
1181
|
+
const schemaRefs = /* @__PURE__ */ new WeakMap();
|
|
1182
|
+
const importedRefNames = /* @__PURE__ */ new WeakMap();
|
|
1183
|
+
function collectRefEntries(node) {
|
|
1184
|
+
return memo(refEntries, node, () => collectSync(node, { schema(child) {
|
|
1185
|
+
if (child.type !== "ref") return void 0;
|
|
1186
|
+
const name = resolveRefName(child);
|
|
1187
|
+
return name ? {
|
|
1188
|
+
name,
|
|
1189
|
+
hasPointer: Boolean(child.ref)
|
|
1190
|
+
} : void 0;
|
|
1191
|
+
} }));
|
|
1192
|
+
}
|
|
1193
|
+
/**
|
|
1241
1194
|
* Collects the names of every schema a node's subtree references, resolved with `resolveRefName`.
|
|
1242
|
-
* Each ref contributes its name only, so the schema it points to is never traversed.
|
|
1243
|
-
*
|
|
1244
|
-
* scan per schema.
|
|
1195
|
+
* Each ref contributes its name only, so the schema it points to is never traversed. Memoized by
|
|
1196
|
+
* node identity, which lets `findCircularSchemas` and `containsCircularRef` share one scan per schema.
|
|
1245
1197
|
*
|
|
1246
1198
|
* @example
|
|
1247
1199
|
* ```ts
|
|
@@ -1249,21 +1201,13 @@ function memoize(store, factory) {
|
|
|
1249
1201
|
* // Set { 'Category', 'Tag' }
|
|
1250
1202
|
* ```
|
|
1251
1203
|
*/
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
if (child.type === "ref") {
|
|
1256
|
-
const name = resolveRefName(child);
|
|
1257
|
-
if (name) refs.add(name);
|
|
1258
|
-
}
|
|
1259
|
-
} });
|
|
1260
|
-
return refs;
|
|
1261
|
-
});
|
|
1204
|
+
function collectSchemaRefs(node) {
|
|
1205
|
+
return memo(schemaRefs, node, () => new Set(collectRefEntries(node).map((entry) => entry.name)));
|
|
1206
|
+
}
|
|
1262
1207
|
/**
|
|
1263
1208
|
* Collects the de-duplicated target names of every pointer-carrying ref in a node's subtree, in
|
|
1264
|
-
* first-occurrence order.
|
|
1265
|
-
*
|
|
1266
|
-
* re-scanning the same schema per plugin.
|
|
1209
|
+
* first-occurrence order. Memoized by node identity, so `resolver.imports` reads the same result
|
|
1210
|
+
* across the ts, zod, and faker plugins instead of re-scanning the same schema per plugin.
|
|
1267
1211
|
*
|
|
1268
1212
|
* Only refs that carry a `$ref` pointer count, so a synthesized ref pointing at a sibling in the
|
|
1269
1213
|
* same file (a union member created by name) is left out. That leaves exactly the set
|
|
@@ -1275,19 +1219,9 @@ const collectSchemaRefs = memoize(/* @__PURE__ */ new WeakMap(), (node) => {
|
|
|
1275
1219
|
* // ['Category', 'Tag']
|
|
1276
1220
|
* ```
|
|
1277
1221
|
*/
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
collectSync(node, { schema(child) {
|
|
1282
|
-
if (child.type !== "ref" || !child.ref) return;
|
|
1283
|
-
const name = resolveRefName(child);
|
|
1284
|
-
if (name && !seen.has(name)) {
|
|
1285
|
-
seen.add(name);
|
|
1286
|
-
names.push(name);
|
|
1287
|
-
}
|
|
1288
|
-
} });
|
|
1289
|
-
return names;
|
|
1290
|
-
});
|
|
1222
|
+
function collectImportedRefNames(node) {
|
|
1223
|
+
return memo(importedRefNames, node, () => [...new Set(collectRefEntries(node).flatMap((entry) => entry.hasPointer ? [entry.name] : []))]);
|
|
1224
|
+
}
|
|
1291
1225
|
/**
|
|
1292
1226
|
* Collects the names of all top-level schemas transitively used by a set of operations.
|
|
1293
1227
|
*
|
|
@@ -1326,23 +1260,17 @@ function collectUsedSchemaNames(operations, schemas) {
|
|
|
1326
1260
|
return result;
|
|
1327
1261
|
}
|
|
1328
1262
|
/**
|
|
1329
|
-
* Finds every schema that takes part in a circular dependency chain
|
|
1330
|
-
* that maps each schema name to the names it references directly.
|
|
1263
|
+
* Finds every schema that takes part in a circular dependency chain, including direct self-loops.
|
|
1331
1264
|
*
|
|
1332
|
-
*
|
|
1333
|
-
*
|
|
1334
|
-
*
|
|
1265
|
+
* Wrap the returned schema positions in a deferred construct (a lazy getter or `z.lazy(() => …)`) so
|
|
1266
|
+
* the generated code does not recurse forever. Refs are followed by name only, so the walk stays
|
|
1267
|
+
* linear in the size of the schema graph.
|
|
1335
1268
|
*
|
|
1336
|
-
* @
|
|
1337
|
-
* ```ts
|
|
1338
|
-
* const graph = new Map([
|
|
1339
|
-
* ['Pet', new Set(['Category'])],
|
|
1340
|
-
* ['Category', new Set(['Pet'])],
|
|
1341
|
-
* ])
|
|
1342
|
-
* findCircularSchemasFromGraph(graph) // Set { 'Pet', 'Category' }
|
|
1343
|
-
* ```
|
|
1269
|
+
* @note Call this once on the full graph, then check individual schemas with `containsCircularRef()`.
|
|
1344
1270
|
*/
|
|
1345
|
-
function
|
|
1271
|
+
function findCircularSchemas(schemas) {
|
|
1272
|
+
const graph = /* @__PURE__ */ new Map();
|
|
1273
|
+
for (const schema of schemas) if (schema.name) graph.set(schema.name, collectSchemaRefs(schema));
|
|
1346
1274
|
const circular = /* @__PURE__ */ new Set();
|
|
1347
1275
|
for (const start of graph.keys()) {
|
|
1348
1276
|
const visited = /* @__PURE__ */ new Set();
|
|
@@ -1361,20 +1289,6 @@ function findCircularSchemasFromGraph(graph) {
|
|
|
1361
1289
|
}
|
|
1362
1290
|
return circular;
|
|
1363
1291
|
}
|
|
1364
|
-
/**
|
|
1365
|
-
* Finds every schema that takes part in a circular dependency chain, including direct self-loops.
|
|
1366
|
-
*
|
|
1367
|
-
* Wrap the returned schema positions in a deferred construct (a lazy getter or `z.lazy(() => …)`) so
|
|
1368
|
-
* the generated code does not recurse forever. Refs are followed by name only, so the walk stays
|
|
1369
|
-
* linear in the size of the schema graph.
|
|
1370
|
-
*
|
|
1371
|
-
* @note Call this once on the full graph, then check individual schemas with `containsCircularRef()`.
|
|
1372
|
-
*/
|
|
1373
|
-
function findCircularSchemas(schemas) {
|
|
1374
|
-
const graph = /* @__PURE__ */ new Map();
|
|
1375
|
-
for (const schema of schemas) if (schema.name) graph.set(schema.name, collectSchemaRefs(schema));
|
|
1376
|
-
return findCircularSchemasFromGraph(graph);
|
|
1377
|
-
}
|
|
1378
1292
|
// src/utils/schemaProperties.ts
|
|
1379
1293
|
/**
|
|
1380
1294
|
* Finds every matching property exposed by an object, resolved reference, or intersection.
|
|
@@ -1407,23 +1321,23 @@ function findCircularSchemas(schemas) {
|
|
|
1407
1321
|
*/
|
|
1408
1322
|
function resolveSchemaProperties({ node, propertyName }) {
|
|
1409
1323
|
const properties = [];
|
|
1324
|
+
walkSchema(node, "intersection", (current) => {
|
|
1325
|
+
if (current.type !== "object") return;
|
|
1326
|
+
const property = current.properties.find((candidate) => candidate.name === propertyName);
|
|
1327
|
+
if (property) properties.push(property);
|
|
1328
|
+
});
|
|
1329
|
+
return properties;
|
|
1330
|
+
}
|
|
1331
|
+
function walkSchema(node, through, visit) {
|
|
1410
1332
|
const visited = /* @__PURE__ */ new WeakSet();
|
|
1411
|
-
function
|
|
1333
|
+
function walk(current) {
|
|
1412
1334
|
if (!current || visited.has(current)) return;
|
|
1413
1335
|
visited.add(current);
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
return;
|
|
1418
|
-
}
|
|
1419
|
-
if (current.type === "ref") {
|
|
1420
|
-
visit(current.schema);
|
|
1421
|
-
return;
|
|
1422
|
-
}
|
|
1423
|
-
if (current.type === "intersection") for (const member of current.members ?? []) visit(member);
|
|
1336
|
+
visit(current);
|
|
1337
|
+
if (current.type === "ref") return walk(current.schema);
|
|
1338
|
+
if (current.type === through) for (const member of current.members ?? []) walk(member);
|
|
1424
1339
|
}
|
|
1425
|
-
|
|
1426
|
-
return properties;
|
|
1340
|
+
walk(node);
|
|
1427
1341
|
}
|
|
1428
1342
|
/**
|
|
1429
1343
|
* Reads the unique literal values represented by an enum, resolved reference, or union.
|
|
@@ -1439,35 +1353,18 @@ function resolveSchemaProperties({ node, propertyName }) {
|
|
|
1439
1353
|
*/
|
|
1440
1354
|
function getSchemaLiteralValues(node) {
|
|
1441
1355
|
const values = /* @__PURE__ */ new Set();
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
if (current.type === "enum") {
|
|
1447
|
-
const enumValues = current.namedEnumValues?.map(({ value }) => value) ?? current.enumValues ?? [];
|
|
1448
|
-
for (const value of enumValues) values.add(value);
|
|
1449
|
-
return;
|
|
1450
|
-
}
|
|
1451
|
-
if (current.type === "ref") {
|
|
1452
|
-
visit(current.schema);
|
|
1453
|
-
return;
|
|
1454
|
-
}
|
|
1455
|
-
if (current.type === "union") for (const member of current.members ?? []) visit(member);
|
|
1456
|
-
}
|
|
1457
|
-
visit(node);
|
|
1356
|
+
walkSchema(node, "union", (current) => {
|
|
1357
|
+
if (current.type !== "enum") return;
|
|
1358
|
+
for (const { value } of current.namedEnumValues ?? current.enumValues?.map((value) => ({ value })) ?? []) values.add(value);
|
|
1359
|
+
});
|
|
1458
1360
|
return [...values];
|
|
1459
1361
|
}
|
|
1460
|
-
function collectPropertyNames(node
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
const names = /* @__PURE__ */ new Set();
|
|
1467
|
-
for (const member of node.members ?? []) for (const name of collectPropertyNames(member, visited)) names.add(name);
|
|
1468
|
-
return names;
|
|
1469
|
-
}
|
|
1470
|
-
return /* @__PURE__ */ new Set();
|
|
1362
|
+
function collectPropertyNames(node) {
|
|
1363
|
+
const names = /* @__PURE__ */ new Set();
|
|
1364
|
+
walkSchema(node, "intersection", (current) => {
|
|
1365
|
+
if (current.type === "object") for (const property of current.properties) names.add(property.name);
|
|
1366
|
+
});
|
|
1367
|
+
return names;
|
|
1471
1368
|
}
|
|
1472
1369
|
/**
|
|
1473
1370
|
* Infers an implicit discriminator: a property every member exposes with a distinct single
|
|
@@ -1581,8 +1478,8 @@ function createJsx(value) {
|
|
|
1581
1478
|
const createContent = nodeFactory(nodeKinds.content);
|
|
1582
1479
|
// src/nodes/input.ts
|
|
1583
1480
|
/**
|
|
1584
|
-
* Creates an `InputNode`, defaulting `schemas`/`operations` to empty arrays and `meta` to empty
|
|
1585
|
-
*
|
|
1481
|
+
* Creates an `InputNode`, defaulting `schemas`/`operations` to empty arrays and `meta` to an empty
|
|
1482
|
+
* object. Every call allocates fresh defaults so no two inputs share them.
|
|
1586
1483
|
*
|
|
1587
1484
|
* @example
|
|
1588
1485
|
* ```ts
|
|
@@ -1594,10 +1491,7 @@ function createInput(overrides = {}) {
|
|
|
1594
1491
|
return {
|
|
1595
1492
|
schemas: [],
|
|
1596
1493
|
operations: [],
|
|
1597
|
-
meta: {
|
|
1598
|
-
circularNames: /* @__PURE__ */ new Set(),
|
|
1599
|
-
enumNames: /* @__PURE__ */ new Set()
|
|
1600
|
-
},
|
|
1494
|
+
meta: {},
|
|
1601
1495
|
...overrides,
|
|
1602
1496
|
kind: nodeKinds.input
|
|
1603
1497
|
};
|
|
@@ -1765,22 +1659,18 @@ var src_exports = /* @__PURE__ */ __exportAll({
|
|
|
1765
1659
|
collectSchemaRefs: () => collectSchemaRefs,
|
|
1766
1660
|
collectSync: () => collectSync,
|
|
1767
1661
|
collectUsedSchemaNames: () => collectUsedSchemaNames,
|
|
1768
|
-
|
|
1662
|
+
compareEnforce: () => compareEnforce,
|
|
1769
1663
|
createPrinter: () => createPrinter,
|
|
1770
1664
|
defineMacro: () => defineMacro,
|
|
1771
1665
|
extractStringsFromNodes: () => extractStringsFromNodes,
|
|
1772
1666
|
factory: () => nodes_exports,
|
|
1773
1667
|
findCircularSchemas: () => findCircularSchemas,
|
|
1774
|
-
findCircularSchemasFromGraph: () => findCircularSchemasFromGraph,
|
|
1775
1668
|
findSchema: () => findSchema,
|
|
1776
|
-
forEachChild: () => forEachChild,
|
|
1777
|
-
forEachSchema: () => forEachSchema,
|
|
1778
1669
|
getSchemaLiteralValues: () => getSchemaLiteralValues,
|
|
1779
1670
|
inferDiscriminatorPropertyName: () => inferDiscriminatorPropertyName,
|
|
1780
1671
|
inlineFiles: () => inlineFiles,
|
|
1781
1672
|
isBareRef: () => isBareRef,
|
|
1782
1673
|
isHttpOperationNode: () => isHttpOperationNode,
|
|
1783
|
-
isVirtualFile: () => isVirtualFile,
|
|
1784
1674
|
mergeRefWithSchema: () => mergeRefWithSchema,
|
|
1785
1675
|
narrowSchema: () => narrowSchema,
|
|
1786
1676
|
nodeKinds: () => nodeKinds,
|
|
@@ -1792,6 +1682,6 @@ var src_exports = /* @__PURE__ */ __exportAll({
|
|
|
1792
1682
|
schemaTypes: () => schemaTypes,
|
|
1793
1683
|
transform: () => transform
|
|
1794
1684
|
});
|
|
1795
|
-
export { applyMacros, src_exports as ast, collect, collectImportedRefNames, collectSchemaRefs, collectSync, collectUsedSchemaNames,
|
|
1685
|
+
export { applyMacros, src_exports as ast, collect, collectImportedRefNames, collectSchemaRefs, collectSync, collectUsedSchemaNames, compareEnforce, createPrinter, defineMacro, extractStringsFromNodes, nodes_exports as factory, findCircularSchemas, findSchema, getSchemaLiteralValues, inferDiscriminatorPropertyName, inlineFiles, isBareRef, isHttpOperationNode, mergeRefWithSchema, narrowSchema, nodeKinds, optionality, refName, resolveRef, resolveRefName, resolveSchemaProperties, schemaTypes, transform };
|
|
1796
1686
|
|
|
1797
1687
|
//# sourceMappingURL=index.js.map
|