@kubb/ast 5.0.0-beta.84 → 5.0.0-beta.86
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 +49 -408
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +31 -178
- package/dist/index.js +47 -397
- package/dist/index.js.map +1 -1
- package/dist/{types-XcYJovdT.d.ts → types-BvAfoVB3.d.ts} +11 -45
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -470,141 +470,6 @@ function memoize(store, factory) {
|
|
|
470
470
|
};
|
|
471
471
|
}
|
|
472
472
|
//#endregion
|
|
473
|
-
//#region ../../internals/utils/src/reserved.ts
|
|
474
|
-
/**
|
|
475
|
-
* JavaScript and Java reserved words.
|
|
476
|
-
* @link https://github.com/jonschlinkert/reserved/blob/master/index.js
|
|
477
|
-
*/
|
|
478
|
-
const reservedWords = /* @__PURE__ */ new Set([
|
|
479
|
-
"abstract",
|
|
480
|
-
"arguments",
|
|
481
|
-
"boolean",
|
|
482
|
-
"break",
|
|
483
|
-
"byte",
|
|
484
|
-
"case",
|
|
485
|
-
"catch",
|
|
486
|
-
"char",
|
|
487
|
-
"class",
|
|
488
|
-
"const",
|
|
489
|
-
"continue",
|
|
490
|
-
"debugger",
|
|
491
|
-
"default",
|
|
492
|
-
"delete",
|
|
493
|
-
"do",
|
|
494
|
-
"double",
|
|
495
|
-
"else",
|
|
496
|
-
"enum",
|
|
497
|
-
"eval",
|
|
498
|
-
"export",
|
|
499
|
-
"extends",
|
|
500
|
-
"false",
|
|
501
|
-
"final",
|
|
502
|
-
"finally",
|
|
503
|
-
"float",
|
|
504
|
-
"for",
|
|
505
|
-
"function",
|
|
506
|
-
"goto",
|
|
507
|
-
"if",
|
|
508
|
-
"implements",
|
|
509
|
-
"import",
|
|
510
|
-
"in",
|
|
511
|
-
"instanceof",
|
|
512
|
-
"int",
|
|
513
|
-
"interface",
|
|
514
|
-
"let",
|
|
515
|
-
"long",
|
|
516
|
-
"native",
|
|
517
|
-
"new",
|
|
518
|
-
"null",
|
|
519
|
-
"package",
|
|
520
|
-
"private",
|
|
521
|
-
"protected",
|
|
522
|
-
"public",
|
|
523
|
-
"return",
|
|
524
|
-
"short",
|
|
525
|
-
"static",
|
|
526
|
-
"super",
|
|
527
|
-
"switch",
|
|
528
|
-
"synchronized",
|
|
529
|
-
"this",
|
|
530
|
-
"throw",
|
|
531
|
-
"throws",
|
|
532
|
-
"transient",
|
|
533
|
-
"true",
|
|
534
|
-
"try",
|
|
535
|
-
"typeof",
|
|
536
|
-
"var",
|
|
537
|
-
"void",
|
|
538
|
-
"volatile",
|
|
539
|
-
"while",
|
|
540
|
-
"with",
|
|
541
|
-
"yield",
|
|
542
|
-
"Array",
|
|
543
|
-
"Date",
|
|
544
|
-
"hasOwnProperty",
|
|
545
|
-
"Infinity",
|
|
546
|
-
"isFinite",
|
|
547
|
-
"isNaN",
|
|
548
|
-
"isPrototypeOf",
|
|
549
|
-
"length",
|
|
550
|
-
"Math",
|
|
551
|
-
"name",
|
|
552
|
-
"NaN",
|
|
553
|
-
"Number",
|
|
554
|
-
"Object",
|
|
555
|
-
"prototype",
|
|
556
|
-
"String",
|
|
557
|
-
"toString",
|
|
558
|
-
"undefined",
|
|
559
|
-
"valueOf"
|
|
560
|
-
]);
|
|
561
|
-
/**
|
|
562
|
-
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
563
|
-
*
|
|
564
|
-
* @example
|
|
565
|
-
* ```ts
|
|
566
|
-
* isValidVarName('status') // true
|
|
567
|
-
* isValidVarName('class') // false (reserved word)
|
|
568
|
-
* isValidVarName('42foo') // false (starts with digit)
|
|
569
|
-
* ```
|
|
570
|
-
*/
|
|
571
|
-
function isValidVarName(name) {
|
|
572
|
-
if (!name || reservedWords.has(name)) return false;
|
|
573
|
-
return isIdentifier(name);
|
|
574
|
-
}
|
|
575
|
-
/**
|
|
576
|
-
* Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.
|
|
577
|
-
*
|
|
578
|
-
* Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys
|
|
579
|
-
* even though they are not valid variable names, so use this (not {@link isValidVarName}) when
|
|
580
|
-
* deciding whether an object key needs quoting.
|
|
581
|
-
*
|
|
582
|
-
* @example
|
|
583
|
-
* ```ts
|
|
584
|
-
* isIdentifier('name') // true
|
|
585
|
-
* isIdentifier('x-total')// false
|
|
586
|
-
* ```
|
|
587
|
-
*/
|
|
588
|
-
function isIdentifier(name) {
|
|
589
|
-
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
590
|
-
}
|
|
591
|
-
//#endregion
|
|
592
|
-
//#region ../../internals/utils/src/string.ts
|
|
593
|
-
/**
|
|
594
|
-
* Wraps a value in single quotes for emitting a single-quoted JavaScript string literal, escaping
|
|
595
|
-
* any backslash or single quote in the content.
|
|
596
|
-
*
|
|
597
|
-
* @example
|
|
598
|
-
* ```ts
|
|
599
|
-
* singleQuote('foo') // "'foo'"
|
|
600
|
-
* singleQuote("o'clock") // "'o\\'clock'"
|
|
601
|
-
* ```
|
|
602
|
-
*/
|
|
603
|
-
function singleQuote(value) {
|
|
604
|
-
if (value === void 0 || value === null) return "''";
|
|
605
|
-
return `'${String(value).replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'`;
|
|
606
|
-
}
|
|
607
|
-
//#endregion
|
|
608
473
|
//#region src/utils/extractStringsFromNodes.ts
|
|
609
474
|
/**
|
|
610
475
|
* Extracts all string content from a `CodeNode` tree recursively.
|
|
@@ -641,7 +506,7 @@ function extractStringsFromNodes(nodes) {
|
|
|
641
506
|
return collected.join("\n");
|
|
642
507
|
}
|
|
643
508
|
//#endregion
|
|
644
|
-
//#region src/utils/
|
|
509
|
+
//#region src/utils/combineFileMembers.ts
|
|
645
510
|
function sourceKey(source) {
|
|
646
511
|
return `${source.name ?? extractStringsFromNodes(source.nodes)}:${source.isExportable ?? false}:${source.isTypeOnly ?? false}`;
|
|
647
512
|
}
|
|
@@ -873,16 +738,23 @@ const createSource = sourceDef.create;
|
|
|
873
738
|
* ```
|
|
874
739
|
*/
|
|
875
740
|
function createFile(input) {
|
|
876
|
-
const extname = node_path.default.extname(input.baseName)
|
|
741
|
+
const extname = node_path.default.extname(input.baseName);
|
|
877
742
|
if (!extname) throw new Error(`No extname found for ${input.baseName}`);
|
|
878
743
|
const resolvedExports = input.exports?.length ? combineExports(input.exports) : [];
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
const
|
|
744
|
+
const resolvedImports = (() => {
|
|
745
|
+
if (!input.imports?.length) return [];
|
|
746
|
+
const sourceParts = [];
|
|
747
|
+
const localNames = /* @__PURE__ */ new Set();
|
|
748
|
+
for (const item of input.sources ?? []) {
|
|
749
|
+
const extracted = item.nodes && extractStringsFromNodes(item.nodes);
|
|
750
|
+
if (extracted) sourceParts.push(extracted);
|
|
751
|
+
if (item.name) localNames.add(item.name);
|
|
752
|
+
}
|
|
753
|
+
const source = sourceParts.join("\n") || void 0;
|
|
882
754
|
const combinedImports = combineImports(input.imports, resolvedExports, source);
|
|
883
|
-
const localNames = new Set((input.sources ?? []).map((item) => item.name).filter((name) => Boolean(name)));
|
|
884
755
|
const nameOf = (item) => typeof item === "string" ? item : item.name ?? item.propertyName;
|
|
885
|
-
|
|
756
|
+
return combinedImports.flatMap((imp) => {
|
|
757
|
+
if (imp.path === input.path) return [];
|
|
886
758
|
if (!Array.isArray(imp.name)) return typeof imp.name === "string" && localNames.has(imp.name) ? [] : [imp];
|
|
887
759
|
const kept = imp.name.filter((item) => !localNames.has(nameOf(item)));
|
|
888
760
|
if (!kept.length) return [];
|
|
@@ -891,7 +763,7 @@ function createFile(input) {
|
|
|
891
763
|
name: kept
|
|
892
764
|
}];
|
|
893
765
|
});
|
|
894
|
-
}
|
|
766
|
+
})();
|
|
895
767
|
const resolvedSources = input.sources?.length ? combineSources(input.sources) : [];
|
|
896
768
|
return {
|
|
897
769
|
kind: "File",
|
|
@@ -924,31 +796,16 @@ const inputDef = defineNode({
|
|
|
924
796
|
visitorKey: "input"
|
|
925
797
|
});
|
|
926
798
|
/**
|
|
927
|
-
* Creates an `InputNode
|
|
928
|
-
*
|
|
929
|
-
* `schemas`/`operations`. Both variants get the defaulted `meta`.
|
|
799
|
+
* Creates an `InputNode`, defaulting `schemas`/`operations` to empty arrays and `meta` per
|
|
800
|
+
* {@link inputDef}.
|
|
930
801
|
*
|
|
931
|
-
* @example
|
|
802
|
+
* @example
|
|
932
803
|
* ```ts
|
|
933
804
|
* const input = createInput()
|
|
934
805
|
* // { kind: 'Input', schemas: [], operations: [] }
|
|
935
806
|
* ```
|
|
936
|
-
*
|
|
937
|
-
* @example Streaming
|
|
938
|
-
* ```ts
|
|
939
|
-
* const node = createInput({ stream: true, schemas: schemasIterable, operations: operationsIterable, meta: { title: 'My API' } })
|
|
940
|
-
* ```
|
|
941
807
|
*/
|
|
942
|
-
function createInput(
|
|
943
|
-
const { stream, ...overrides } = options;
|
|
944
|
-
if (stream) return {
|
|
945
|
-
kind: "Input",
|
|
946
|
-
meta: {
|
|
947
|
-
circularNames: [],
|
|
948
|
-
enumNames: []
|
|
949
|
-
},
|
|
950
|
-
...overrides
|
|
951
|
-
};
|
|
808
|
+
function createInput(overrides = {}) {
|
|
952
809
|
return inputDef.create(overrides);
|
|
953
810
|
}
|
|
954
811
|
//#endregion
|
|
@@ -1592,74 +1449,35 @@ function createPrinter(build) {
|
|
|
1592
1449
|
};
|
|
1593
1450
|
}
|
|
1594
1451
|
//#endregion
|
|
1595
|
-
//#region src/utils/
|
|
1596
|
-
/**
|
|
1597
|
-
* Builds a JSDoc comment block from an array of lines. Returns `fallback` when there are no
|
|
1598
|
-
* comments.
|
|
1599
|
-
*
|
|
1600
|
-
* @example
|
|
1601
|
-
* ```ts
|
|
1602
|
-
* buildJSDoc(['@type string', '@example hello'])
|
|
1603
|
-
* // '/**\n * @type string\n * @example hello\n *\/\n '
|
|
1604
|
-
* ```
|
|
1605
|
-
*/
|
|
1606
|
-
function buildJSDoc(comments, options = {}) {
|
|
1607
|
-
const { indent = " * ", suffix = "\n ", fallback = " " } = options;
|
|
1608
|
-
if (comments.length === 0) return fallback;
|
|
1609
|
-
return `/**\n${comments.map((c) => `${indent}${c}`).join("\n")}\n */${suffix}`;
|
|
1610
|
-
}
|
|
1452
|
+
//#region src/utils/mergeAdjacentSchemas.ts
|
|
1611
1453
|
/**
|
|
1612
|
-
*
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
if (!text) return "";
|
|
1616
|
-
return text.split("\n").map((line) => line.trim() ? ` ${line}` : "").join("\n");
|
|
1617
|
-
}
|
|
1618
|
-
/**
|
|
1619
|
-
* Renders an object key, quoting it with single quotes only when it is not a valid identifier.
|
|
1620
|
-
* Reserved words and globals (`name`, `class`, …) are valid bare keys and stay unquoted.
|
|
1621
|
-
*
|
|
1622
|
-
* @example
|
|
1623
|
-
* ```ts
|
|
1624
|
-
* objectKey('name') // 'name'
|
|
1625
|
-
* objectKey('x-total') // "'x-total'"
|
|
1626
|
-
* ```
|
|
1627
|
-
*/
|
|
1628
|
-
function objectKey(name) {
|
|
1629
|
-
return isIdentifier(name) ? name : singleQuote(name);
|
|
1630
|
-
}
|
|
1631
|
-
/**
|
|
1632
|
-
* Assembles a multi-line object literal from already-rendered `entries`, indenting each entry one
|
|
1633
|
-
* level and closing the brace at column zero. Entries that are themselves multi-line objects indent
|
|
1634
|
-
* cumulatively. Each entry ends with a trailing comma to match the formatter's multi-line style.
|
|
1635
|
-
*
|
|
1636
|
-
* @example
|
|
1637
|
-
* ```ts
|
|
1638
|
-
* buildObject(['id: z.number()', 'name: z.string()'])
|
|
1639
|
-
* // '{\n id: z.number(),\n name: z.string(),\n}'
|
|
1640
|
-
* ```
|
|
1641
|
-
*/
|
|
1642
|
-
function buildObject(entries) {
|
|
1643
|
-
if (entries.length === 0) return "{}";
|
|
1644
|
-
return `{\n${entries.map((entry) => `${indentLines(entry)},`).join("\n")}\n}`;
|
|
1645
|
-
}
|
|
1646
|
-
/**
|
|
1647
|
-
* Assembles a bracketed list (array by default) from already-rendered `items`. Keeps everything on
|
|
1648
|
-
* one line when no item spans multiple lines, and otherwise puts each item on its own line, indented
|
|
1649
|
-
* one level with a trailing comma and the closing bracket at column zero. Used for member lists such
|
|
1650
|
-
* as `z.union([…])` and `z.array([…])`.
|
|
1454
|
+
* Merges a run of adjacent anonymous object members into one. Named or non-object members break the
|
|
1455
|
+
* run and pass through unchanged. The merge follows member order, so callers control which members
|
|
1456
|
+
* combine by where they place them in the sequence.
|
|
1651
1457
|
*
|
|
1652
1458
|
* @example
|
|
1653
1459
|
* ```ts
|
|
1654
|
-
*
|
|
1655
|
-
* // '[z.string(), z.number()]'
|
|
1460
|
+
* const merged = [...mergeAdjacentObjectsLazy([objectA, objectB])]
|
|
1656
1461
|
* ```
|
|
1657
1462
|
*/
|
|
1658
|
-
function
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1463
|
+
function* mergeAdjacentObjectsLazy(members) {
|
|
1464
|
+
let acc;
|
|
1465
|
+
for (const member of members) {
|
|
1466
|
+
const objectMember = narrowSchema(member, "object");
|
|
1467
|
+
if (objectMember && !objectMember.name && acc !== void 0) {
|
|
1468
|
+
const accObject = narrowSchema(acc, "object");
|
|
1469
|
+
if (accObject && !accObject.name) {
|
|
1470
|
+
acc = createSchema({
|
|
1471
|
+
...accObject,
|
|
1472
|
+
properties: [...accObject.properties ?? [], ...objectMember.properties ?? []]
|
|
1473
|
+
});
|
|
1474
|
+
continue;
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
if (acc !== void 0) yield acc;
|
|
1478
|
+
acc = member;
|
|
1479
|
+
}
|
|
1480
|
+
if (acc !== void 0) yield acc;
|
|
1663
1481
|
}
|
|
1664
1482
|
//#endregion
|
|
1665
1483
|
//#region src/utils/refs.ts
|
|
@@ -1758,151 +1576,6 @@ function isStringType(node) {
|
|
|
1758
1576
|
return false;
|
|
1759
1577
|
}
|
|
1760
1578
|
//#endregion
|
|
1761
|
-
//#region src/utils/schemaMerge.ts
|
|
1762
|
-
/**
|
|
1763
|
-
* Merges a run of adjacent anonymous object members into one. Named or non-object members break the
|
|
1764
|
-
* run and pass through unchanged. The merge follows member order, so callers control which members
|
|
1765
|
-
* combine by where they place them in the sequence.
|
|
1766
|
-
*
|
|
1767
|
-
* @example
|
|
1768
|
-
* ```ts
|
|
1769
|
-
* const merged = [...mergeAdjacentObjectsLazy([objectA, objectB])]
|
|
1770
|
-
* ```
|
|
1771
|
-
*/
|
|
1772
|
-
function* mergeAdjacentObjectsLazy(members) {
|
|
1773
|
-
let acc;
|
|
1774
|
-
for (const member of members) {
|
|
1775
|
-
const objectMember = narrowSchema(member, "object");
|
|
1776
|
-
if (objectMember && !objectMember.name && acc !== void 0) {
|
|
1777
|
-
const accObject = narrowSchema(acc, "object");
|
|
1778
|
-
if (accObject && !accObject.name) {
|
|
1779
|
-
acc = createSchema({
|
|
1780
|
-
...accObject,
|
|
1781
|
-
properties: [...accObject.properties ?? [], ...objectMember.properties ?? []]
|
|
1782
|
-
});
|
|
1783
|
-
continue;
|
|
1784
|
-
}
|
|
1785
|
-
}
|
|
1786
|
-
if (acc !== void 0) yield acc;
|
|
1787
|
-
acc = member;
|
|
1788
|
-
}
|
|
1789
|
-
if (acc !== void 0) yield acc;
|
|
1790
|
-
}
|
|
1791
|
-
//#endregion
|
|
1792
|
-
//#region src/utils/strings.ts
|
|
1793
|
-
/**
|
|
1794
|
-
* Strips a single matching pair of `"..."`, `'...'`, or `` `...` `` from both ends of `text`.
|
|
1795
|
-
* Returns the string unchanged when no balanced quote pair is found.
|
|
1796
|
-
*
|
|
1797
|
-
* @example
|
|
1798
|
-
* ```ts
|
|
1799
|
-
* trimQuotes('"hello"') // 'hello'
|
|
1800
|
-
* trimQuotes('hello') // 'hello'
|
|
1801
|
-
* ```
|
|
1802
|
-
*/
|
|
1803
|
-
function trimQuotes(text) {
|
|
1804
|
-
if (text.length >= 2) {
|
|
1805
|
-
const first = text[0];
|
|
1806
|
-
const last = text[text.length - 1];
|
|
1807
|
-
if (first === "\"" && last === "\"" || first === "'" && last === "'" || first === "`" && last === "`") return text.slice(1, -1);
|
|
1808
|
-
}
|
|
1809
|
-
return text;
|
|
1810
|
-
}
|
|
1811
|
-
/**
|
|
1812
|
-
* Serializes a primitive to a single-quoted string literal, stripping any surrounding quotes first.
|
|
1813
|
-
*
|
|
1814
|
-
* Escaping runs through `JSON.stringify`, then the result switches to single quotes so the generated
|
|
1815
|
-
* code matches the repo style without a formatter.
|
|
1816
|
-
*
|
|
1817
|
-
* @example
|
|
1818
|
-
* ```ts
|
|
1819
|
-
* stringify('hello') // "'hello'"
|
|
1820
|
-
* stringify('"hello"') // "'hello'"
|
|
1821
|
-
* ```
|
|
1822
|
-
*/
|
|
1823
|
-
function stringify(value) {
|
|
1824
|
-
if (value === void 0 || value === null) return "''";
|
|
1825
|
-
return `'${JSON.stringify(trimQuotes(value.toString())).slice(1, -1).replace(/\\"/g, "\"").replace(/'/g, "\\'")}'`;
|
|
1826
|
-
}
|
|
1827
|
-
/**
|
|
1828
|
-
* Escapes characters that are not allowed inside JS string literals, covering quotes, backslashes,
|
|
1829
|
-
* and the Unicode line terminators U+2028 and U+2029.
|
|
1830
|
-
*
|
|
1831
|
-
* @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
|
|
1832
|
-
*
|
|
1833
|
-
* @example
|
|
1834
|
-
* ```ts
|
|
1835
|
-
* jsStringEscape('say "hi"\nbye') // 'say \\"hi\\"\\nbye'
|
|
1836
|
-
* ```
|
|
1837
|
-
*/
|
|
1838
|
-
function jsStringEscape(input) {
|
|
1839
|
-
return `${input}`.replace(/["'\\\n\r\u2028\u2029]/g, (character) => {
|
|
1840
|
-
switch (character) {
|
|
1841
|
-
case "\"":
|
|
1842
|
-
case "'":
|
|
1843
|
-
case "\\": return `\\${character}`;
|
|
1844
|
-
case "\n": return "\\n";
|
|
1845
|
-
case "\r": return "\\r";
|
|
1846
|
-
case "\u2028": return "\\u2028";
|
|
1847
|
-
case "\u2029": return "\\u2029";
|
|
1848
|
-
default: return "";
|
|
1849
|
-
}
|
|
1850
|
-
});
|
|
1851
|
-
}
|
|
1852
|
-
/**
|
|
1853
|
-
* Converts a pattern string into a `new RegExp(...)` constructor call or a regex literal string.
|
|
1854
|
-
* Inline flags expressed as a `^(?im)` prefix are extracted and applied to the resulting expression.
|
|
1855
|
-
* Pass `null` as the second argument to emit a `/pattern/flags` literal instead.
|
|
1856
|
-
*
|
|
1857
|
-
* @example
|
|
1858
|
-
* ```ts
|
|
1859
|
-
* toRegExpString('^(?im)foo') // 'new RegExp("^foo", "im")'
|
|
1860
|
-
* toRegExpString('^(?im)foo', null) // '/^foo/im'
|
|
1861
|
-
* ```
|
|
1862
|
-
*/
|
|
1863
|
-
function toRegExpString(text, func = "RegExp") {
|
|
1864
|
-
const raw = trimQuotes(text);
|
|
1865
|
-
const match = raw.match(/^\^(\(\?([igmsuy]+)\))/i);
|
|
1866
|
-
const replacementTarget = match?.[1] ?? "";
|
|
1867
|
-
const matchedFlags = match?.[2];
|
|
1868
|
-
const cleaned = raw.replace(/^\\?\//, "").replace(/\\?\/$/, "").replace(replacementTarget, "");
|
|
1869
|
-
const { source, flags } = new RegExp(cleaned, matchedFlags);
|
|
1870
|
-
if (func === null) return `/${source}/${flags}`;
|
|
1871
|
-
return `new ${func}(${JSON.stringify(source)}${flags ? `, ${JSON.stringify(flags)}` : ""})`;
|
|
1872
|
-
}
|
|
1873
|
-
/**
|
|
1874
|
-
* Renders a plain object as multi-line `key: value` source for embedding in generated code. Nested
|
|
1875
|
-
* objects recurse with fixed indentation, so the result drops straight into an object literal
|
|
1876
|
-
* without re-parsing.
|
|
1877
|
-
*
|
|
1878
|
-
* @example
|
|
1879
|
-
* ```ts
|
|
1880
|
-
* stringifyObject({ foo: 'bar', nested: { a: 1 } })
|
|
1881
|
-
* // 'foo: bar,\nnested: {\n a: 1\n }'
|
|
1882
|
-
* ```
|
|
1883
|
-
*/
|
|
1884
|
-
function stringifyObject(value) {
|
|
1885
|
-
return Object.entries(value).map(([key, val]) => {
|
|
1886
|
-
if (val !== null && typeof val === "object") return `${key}: {\n ${stringifyObject(val)}\n }`;
|
|
1887
|
-
return `${key}: ${val}`;
|
|
1888
|
-
}).filter(Boolean).join(",\n");
|
|
1889
|
-
}
|
|
1890
|
-
/**
|
|
1891
|
-
* Renders a dotted path or string array as an optional-chaining accessor expression rooted at
|
|
1892
|
-
* `accessor`. Returns `null` for an empty path.
|
|
1893
|
-
*
|
|
1894
|
-
* @example
|
|
1895
|
-
* ```ts
|
|
1896
|
-
* getNestedAccessor('pagination.next.id', 'lastPage')
|
|
1897
|
-
* // "lastPage?.['pagination']?.['next']?.['id']"
|
|
1898
|
-
* ```
|
|
1899
|
-
*/
|
|
1900
|
-
function getNestedAccessor(param, accessor) {
|
|
1901
|
-
const parts = Array.isArray(param) ? param : param.split(".");
|
|
1902
|
-
if (parts.length === 0 || parts.length === 1 && parts[0] === "") return null;
|
|
1903
|
-
return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
|
|
1904
|
-
}
|
|
1905
|
-
//#endregion
|
|
1906
1579
|
//#region src/utils/schemaGraph.ts
|
|
1907
1580
|
/**
|
|
1908
1581
|
* Memoized inner pass that walks a single node and returns the names of every schema it references.
|
|
@@ -1975,7 +1648,7 @@ function computeUsedSchemaNames(operations, schemas) {
|
|
|
1975
1648
|
*
|
|
1976
1649
|
* @example Only generate schemas referenced by included operations
|
|
1977
1650
|
* ```ts
|
|
1978
|
-
* const includedOps = operations.filter((op) => resolver.
|
|
1651
|
+
* const includedOps = operations.filter((op) => resolver.default.options(op, { options, include }) !== null)
|
|
1979
1652
|
* const allowed = collectUsedSchemaNames(includedOps, schemas)
|
|
1980
1653
|
*
|
|
1981
1654
|
* for (const schema of schemas) {
|
|
@@ -2081,20 +1754,6 @@ function mapSchemaItems(node, transform) {
|
|
|
2081
1754
|
output: transform(schema)
|
|
2082
1755
|
}));
|
|
2083
1756
|
}
|
|
2084
|
-
/**
|
|
2085
|
-
* Emits a lazy getter for a circular-ref property position, `get name() { return body }`. The key
|
|
2086
|
-
* is quoted only when it is not a valid identifier. Used by the string printers to defer evaluation
|
|
2087
|
-
* of a recursive schema until first access.
|
|
2088
|
-
*
|
|
2089
|
-
* @example
|
|
2090
|
-
* ```ts
|
|
2091
|
-
* lazyGetter({ name: 'parent', body: 'z.lazy(() => Pet)' })
|
|
2092
|
-
* // "get parent() { return z.lazy(() => Pet) }"
|
|
2093
|
-
* ```
|
|
2094
|
-
*/
|
|
2095
|
-
function lazyGetter({ name, body }) {
|
|
2096
|
-
return `get ${objectKey(name)}() { return ${body} }`;
|
|
2097
|
-
}
|
|
2098
1757
|
//#endregion
|
|
2099
1758
|
//#region src/macros/macroDiscriminatorEnum.ts
|
|
2100
1759
|
/**
|
|
@@ -2270,12 +1929,12 @@ var exports_exports = /* @__PURE__ */ __exportAll({
|
|
|
2270
1929
|
applyMacros: () => applyMacros,
|
|
2271
1930
|
arrowFunctionDef: () => arrowFunctionDef,
|
|
2272
1931
|
breakDef: () => breakDef,
|
|
2273
|
-
buildJSDoc: () => buildJSDoc,
|
|
2274
|
-
buildList: () => buildList,
|
|
2275
|
-
buildObject: () => buildObject,
|
|
2276
1932
|
childName: () => childName,
|
|
2277
1933
|
collect: () => collect,
|
|
2278
1934
|
collectUsedSchemaNames: () => collectUsedSchemaNames,
|
|
1935
|
+
combineExports: () => combineExports,
|
|
1936
|
+
combineImports: () => combineImports,
|
|
1937
|
+
combineSources: () => combineSources,
|
|
2279
1938
|
composeMacros: () => composeMacros,
|
|
2280
1939
|
constDef: () => constDef,
|
|
2281
1940
|
containsCircularRef: () => containsCircularRef,
|
|
@@ -2292,15 +1951,11 @@ var exports_exports = /* @__PURE__ */ __exportAll({
|
|
|
2292
1951
|
fileDef: () => fileDef,
|
|
2293
1952
|
findCircularSchemas: () => findCircularSchemas,
|
|
2294
1953
|
functionDef: () => functionDef,
|
|
2295
|
-
getNestedAccessor: () => getNestedAccessor,
|
|
2296
1954
|
importDef: () => importDef,
|
|
2297
1955
|
inputDef: () => inputDef,
|
|
2298
1956
|
isHttpOperationNode: () => isHttpOperationNode,
|
|
2299
1957
|
isStringType: () => isStringType,
|
|
2300
|
-
isValidVarName: () => isValidVarName,
|
|
2301
|
-
jsStringEscape: () => jsStringEscape,
|
|
2302
1958
|
jsxDef: () => jsxDef,
|
|
2303
|
-
lazyGetter: () => lazyGetter,
|
|
2304
1959
|
macroDiscriminatorEnum: () => macroDiscriminatorEnum,
|
|
2305
1960
|
macroEnumName: () => macroEnumName,
|
|
2306
1961
|
macroSimplifyUnion: () => macroSimplifyUnion,
|
|
@@ -2310,7 +1965,6 @@ var exports_exports = /* @__PURE__ */ __exportAll({
|
|
|
2310
1965
|
mergeAdjacentObjectsLazy: () => mergeAdjacentObjectsLazy,
|
|
2311
1966
|
narrowSchema: () => narrowSchema,
|
|
2312
1967
|
nodeDefs: () => nodeDefs,
|
|
2313
|
-
objectKey: () => objectKey,
|
|
2314
1968
|
operationDef: () => operationDef,
|
|
2315
1969
|
optionality: () => optionality,
|
|
2316
1970
|
outputDef: () => outputDef,
|
|
@@ -2321,13 +1975,9 @@ var exports_exports = /* @__PURE__ */ __exportAll({
|
|
|
2321
1975
|
schemaDef: () => schemaDef,
|
|
2322
1976
|
schemaTypes: () => schemaTypes,
|
|
2323
1977
|
sourceDef: () => sourceDef,
|
|
2324
|
-
stringify: () => stringify,
|
|
2325
|
-
stringifyObject: () => stringifyObject,
|
|
2326
1978
|
syncSchemaRef: () => syncSchemaRef,
|
|
2327
1979
|
textDef: () => textDef,
|
|
2328
|
-
toRegExpString: () => toRegExpString,
|
|
2329
1980
|
transform: () => transform,
|
|
2330
|
-
trimQuotes: () => trimQuotes,
|
|
2331
1981
|
typeDef: () => typeDef,
|
|
2332
1982
|
walk: () => walk
|
|
2333
1983
|
});
|
|
@@ -2341,12 +1991,12 @@ Object.defineProperty(exports, "ast", {
|
|
|
2341
1991
|
}
|
|
2342
1992
|
});
|
|
2343
1993
|
exports.breakDef = breakDef;
|
|
2344
|
-
exports.buildJSDoc = buildJSDoc;
|
|
2345
|
-
exports.buildList = buildList;
|
|
2346
|
-
exports.buildObject = buildObject;
|
|
2347
1994
|
exports.childName = childName;
|
|
2348
1995
|
exports.collect = collect;
|
|
2349
1996
|
exports.collectUsedSchemaNames = collectUsedSchemaNames;
|
|
1997
|
+
exports.combineExports = combineExports;
|
|
1998
|
+
exports.combineImports = combineImports;
|
|
1999
|
+
exports.combineSources = combineSources;
|
|
2350
2000
|
exports.composeMacros = composeMacros;
|
|
2351
2001
|
exports.constDef = constDef;
|
|
2352
2002
|
exports.containsCircularRef = containsCircularRef;
|
|
@@ -2368,15 +2018,11 @@ Object.defineProperty(exports, "factory", {
|
|
|
2368
2018
|
exports.fileDef = fileDef;
|
|
2369
2019
|
exports.findCircularSchemas = findCircularSchemas;
|
|
2370
2020
|
exports.functionDef = functionDef;
|
|
2371
|
-
exports.getNestedAccessor = getNestedAccessor;
|
|
2372
2021
|
exports.importDef = importDef;
|
|
2373
2022
|
exports.inputDef = inputDef;
|
|
2374
2023
|
exports.isHttpOperationNode = isHttpOperationNode;
|
|
2375
2024
|
exports.isStringType = isStringType;
|
|
2376
|
-
exports.isValidVarName = isValidVarName;
|
|
2377
|
-
exports.jsStringEscape = jsStringEscape;
|
|
2378
2025
|
exports.jsxDef = jsxDef;
|
|
2379
|
-
exports.lazyGetter = lazyGetter;
|
|
2380
2026
|
exports.macroDiscriminatorEnum = macroDiscriminatorEnum;
|
|
2381
2027
|
exports.macroEnumName = macroEnumName;
|
|
2382
2028
|
exports.macroSimplifyUnion = macroSimplifyUnion;
|
|
@@ -2386,7 +2032,6 @@ exports.mapSchemaProperties = mapSchemaProperties;
|
|
|
2386
2032
|
exports.mergeAdjacentObjectsLazy = mergeAdjacentObjectsLazy;
|
|
2387
2033
|
exports.narrowSchema = narrowSchema;
|
|
2388
2034
|
exports.nodeDefs = nodeDefs;
|
|
2389
|
-
exports.objectKey = objectKey;
|
|
2390
2035
|
exports.operationDef = operationDef;
|
|
2391
2036
|
exports.optionality = optionality;
|
|
2392
2037
|
exports.outputDef = outputDef;
|
|
@@ -2397,13 +2042,9 @@ exports.responseDef = responseDef;
|
|
|
2397
2042
|
exports.schemaDef = schemaDef;
|
|
2398
2043
|
exports.schemaTypes = schemaTypes;
|
|
2399
2044
|
exports.sourceDef = sourceDef;
|
|
2400
|
-
exports.stringify = stringify;
|
|
2401
|
-
exports.stringifyObject = stringifyObject;
|
|
2402
2045
|
exports.syncSchemaRef = syncSchemaRef;
|
|
2403
2046
|
exports.textDef = textDef;
|
|
2404
|
-
exports.toRegExpString = toRegExpString;
|
|
2405
2047
|
exports.transform = transform;
|
|
2406
|
-
exports.trimQuotes = trimQuotes;
|
|
2407
2048
|
exports.typeDef = typeDef;
|
|
2408
2049
|
exports.walk = walk;
|
|
2409
2050
|
|