@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.js
CHANGED
|
@@ -438,141 +438,6 @@ function memoize(store, factory) {
|
|
|
438
438
|
};
|
|
439
439
|
}
|
|
440
440
|
//#endregion
|
|
441
|
-
//#region ../../internals/utils/src/reserved.ts
|
|
442
|
-
/**
|
|
443
|
-
* JavaScript and Java reserved words.
|
|
444
|
-
* @link https://github.com/jonschlinkert/reserved/blob/master/index.js
|
|
445
|
-
*/
|
|
446
|
-
const reservedWords = /* @__PURE__ */ new Set([
|
|
447
|
-
"abstract",
|
|
448
|
-
"arguments",
|
|
449
|
-
"boolean",
|
|
450
|
-
"break",
|
|
451
|
-
"byte",
|
|
452
|
-
"case",
|
|
453
|
-
"catch",
|
|
454
|
-
"char",
|
|
455
|
-
"class",
|
|
456
|
-
"const",
|
|
457
|
-
"continue",
|
|
458
|
-
"debugger",
|
|
459
|
-
"default",
|
|
460
|
-
"delete",
|
|
461
|
-
"do",
|
|
462
|
-
"double",
|
|
463
|
-
"else",
|
|
464
|
-
"enum",
|
|
465
|
-
"eval",
|
|
466
|
-
"export",
|
|
467
|
-
"extends",
|
|
468
|
-
"false",
|
|
469
|
-
"final",
|
|
470
|
-
"finally",
|
|
471
|
-
"float",
|
|
472
|
-
"for",
|
|
473
|
-
"function",
|
|
474
|
-
"goto",
|
|
475
|
-
"if",
|
|
476
|
-
"implements",
|
|
477
|
-
"import",
|
|
478
|
-
"in",
|
|
479
|
-
"instanceof",
|
|
480
|
-
"int",
|
|
481
|
-
"interface",
|
|
482
|
-
"let",
|
|
483
|
-
"long",
|
|
484
|
-
"native",
|
|
485
|
-
"new",
|
|
486
|
-
"null",
|
|
487
|
-
"package",
|
|
488
|
-
"private",
|
|
489
|
-
"protected",
|
|
490
|
-
"public",
|
|
491
|
-
"return",
|
|
492
|
-
"short",
|
|
493
|
-
"static",
|
|
494
|
-
"super",
|
|
495
|
-
"switch",
|
|
496
|
-
"synchronized",
|
|
497
|
-
"this",
|
|
498
|
-
"throw",
|
|
499
|
-
"throws",
|
|
500
|
-
"transient",
|
|
501
|
-
"true",
|
|
502
|
-
"try",
|
|
503
|
-
"typeof",
|
|
504
|
-
"var",
|
|
505
|
-
"void",
|
|
506
|
-
"volatile",
|
|
507
|
-
"while",
|
|
508
|
-
"with",
|
|
509
|
-
"yield",
|
|
510
|
-
"Array",
|
|
511
|
-
"Date",
|
|
512
|
-
"hasOwnProperty",
|
|
513
|
-
"Infinity",
|
|
514
|
-
"isFinite",
|
|
515
|
-
"isNaN",
|
|
516
|
-
"isPrototypeOf",
|
|
517
|
-
"length",
|
|
518
|
-
"Math",
|
|
519
|
-
"name",
|
|
520
|
-
"NaN",
|
|
521
|
-
"Number",
|
|
522
|
-
"Object",
|
|
523
|
-
"prototype",
|
|
524
|
-
"String",
|
|
525
|
-
"toString",
|
|
526
|
-
"undefined",
|
|
527
|
-
"valueOf"
|
|
528
|
-
]);
|
|
529
|
-
/**
|
|
530
|
-
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
531
|
-
*
|
|
532
|
-
* @example
|
|
533
|
-
* ```ts
|
|
534
|
-
* isValidVarName('status') // true
|
|
535
|
-
* isValidVarName('class') // false (reserved word)
|
|
536
|
-
* isValidVarName('42foo') // false (starts with digit)
|
|
537
|
-
* ```
|
|
538
|
-
*/
|
|
539
|
-
function isValidVarName(name) {
|
|
540
|
-
if (!name || reservedWords.has(name)) return false;
|
|
541
|
-
return isIdentifier(name);
|
|
542
|
-
}
|
|
543
|
-
/**
|
|
544
|
-
* Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.
|
|
545
|
-
*
|
|
546
|
-
* Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys
|
|
547
|
-
* even though they are not valid variable names, so use this (not {@link isValidVarName}) when
|
|
548
|
-
* deciding whether an object key needs quoting.
|
|
549
|
-
*
|
|
550
|
-
* @example
|
|
551
|
-
* ```ts
|
|
552
|
-
* isIdentifier('name') // true
|
|
553
|
-
* isIdentifier('x-total')// false
|
|
554
|
-
* ```
|
|
555
|
-
*/
|
|
556
|
-
function isIdentifier(name) {
|
|
557
|
-
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
558
|
-
}
|
|
559
|
-
//#endregion
|
|
560
|
-
//#region ../../internals/utils/src/string.ts
|
|
561
|
-
/**
|
|
562
|
-
* Wraps a value in single quotes for emitting a single-quoted JavaScript string literal, escaping
|
|
563
|
-
* any backslash or single quote in the content.
|
|
564
|
-
*
|
|
565
|
-
* @example
|
|
566
|
-
* ```ts
|
|
567
|
-
* singleQuote('foo') // "'foo'"
|
|
568
|
-
* singleQuote("o'clock") // "'o\\'clock'"
|
|
569
|
-
* ```
|
|
570
|
-
*/
|
|
571
|
-
function singleQuote(value) {
|
|
572
|
-
if (value === void 0 || value === null) return "''";
|
|
573
|
-
return `'${String(value).replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'`;
|
|
574
|
-
}
|
|
575
|
-
//#endregion
|
|
576
441
|
//#region src/utils/extractStringsFromNodes.ts
|
|
577
442
|
/**
|
|
578
443
|
* Extracts all string content from a `CodeNode` tree recursively.
|
|
@@ -609,7 +474,7 @@ function extractStringsFromNodes(nodes) {
|
|
|
609
474
|
return collected.join("\n");
|
|
610
475
|
}
|
|
611
476
|
//#endregion
|
|
612
|
-
//#region src/utils/
|
|
477
|
+
//#region src/utils/combineFileMembers.ts
|
|
613
478
|
function sourceKey(source) {
|
|
614
479
|
return `${source.name ?? extractStringsFromNodes(source.nodes)}:${source.isExportable ?? false}:${source.isTypeOnly ?? false}`;
|
|
615
480
|
}
|
|
@@ -841,16 +706,23 @@ const createSource = sourceDef.create;
|
|
|
841
706
|
* ```
|
|
842
707
|
*/
|
|
843
708
|
function createFile(input) {
|
|
844
|
-
const extname = path.extname(input.baseName)
|
|
709
|
+
const extname = path.extname(input.baseName);
|
|
845
710
|
if (!extname) throw new Error(`No extname found for ${input.baseName}`);
|
|
846
711
|
const resolvedExports = input.exports?.length ? combineExports(input.exports) : [];
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
const
|
|
712
|
+
const resolvedImports = (() => {
|
|
713
|
+
if (!input.imports?.length) return [];
|
|
714
|
+
const sourceParts = [];
|
|
715
|
+
const localNames = /* @__PURE__ */ new Set();
|
|
716
|
+
for (const item of input.sources ?? []) {
|
|
717
|
+
const extracted = item.nodes && extractStringsFromNodes(item.nodes);
|
|
718
|
+
if (extracted) sourceParts.push(extracted);
|
|
719
|
+
if (item.name) localNames.add(item.name);
|
|
720
|
+
}
|
|
721
|
+
const source = sourceParts.join("\n") || void 0;
|
|
850
722
|
const combinedImports = combineImports(input.imports, resolvedExports, source);
|
|
851
|
-
const localNames = new Set((input.sources ?? []).map((item) => item.name).filter((name) => Boolean(name)));
|
|
852
723
|
const nameOf = (item) => typeof item === "string" ? item : item.name ?? item.propertyName;
|
|
853
|
-
|
|
724
|
+
return combinedImports.flatMap((imp) => {
|
|
725
|
+
if (imp.path === input.path) return [];
|
|
854
726
|
if (!Array.isArray(imp.name)) return typeof imp.name === "string" && localNames.has(imp.name) ? [] : [imp];
|
|
855
727
|
const kept = imp.name.filter((item) => !localNames.has(nameOf(item)));
|
|
856
728
|
if (!kept.length) return [];
|
|
@@ -859,7 +731,7 @@ function createFile(input) {
|
|
|
859
731
|
name: kept
|
|
860
732
|
}];
|
|
861
733
|
});
|
|
862
|
-
}
|
|
734
|
+
})();
|
|
863
735
|
const resolvedSources = input.sources?.length ? combineSources(input.sources) : [];
|
|
864
736
|
return {
|
|
865
737
|
kind: "File",
|
|
@@ -892,31 +764,16 @@ const inputDef = defineNode({
|
|
|
892
764
|
visitorKey: "input"
|
|
893
765
|
});
|
|
894
766
|
/**
|
|
895
|
-
* Creates an `InputNode
|
|
896
|
-
*
|
|
897
|
-
* `schemas`/`operations`. Both variants get the defaulted `meta`.
|
|
767
|
+
* Creates an `InputNode`, defaulting `schemas`/`operations` to empty arrays and `meta` per
|
|
768
|
+
* {@link inputDef}.
|
|
898
769
|
*
|
|
899
|
-
* @example
|
|
770
|
+
* @example
|
|
900
771
|
* ```ts
|
|
901
772
|
* const input = createInput()
|
|
902
773
|
* // { kind: 'Input', schemas: [], operations: [] }
|
|
903
774
|
* ```
|
|
904
|
-
*
|
|
905
|
-
* @example Streaming
|
|
906
|
-
* ```ts
|
|
907
|
-
* const node = createInput({ stream: true, schemas: schemasIterable, operations: operationsIterable, meta: { title: 'My API' } })
|
|
908
|
-
* ```
|
|
909
775
|
*/
|
|
910
|
-
function createInput(
|
|
911
|
-
const { stream, ...overrides } = options;
|
|
912
|
-
if (stream) return {
|
|
913
|
-
kind: "Input",
|
|
914
|
-
meta: {
|
|
915
|
-
circularNames: [],
|
|
916
|
-
enumNames: []
|
|
917
|
-
},
|
|
918
|
-
...overrides
|
|
919
|
-
};
|
|
776
|
+
function createInput(overrides = {}) {
|
|
920
777
|
return inputDef.create(overrides);
|
|
921
778
|
}
|
|
922
779
|
//#endregion
|
|
@@ -1560,74 +1417,35 @@ function createPrinter(build) {
|
|
|
1560
1417
|
};
|
|
1561
1418
|
}
|
|
1562
1419
|
//#endregion
|
|
1563
|
-
//#region src/utils/
|
|
1564
|
-
/**
|
|
1565
|
-
* Builds a JSDoc comment block from an array of lines. Returns `fallback` when there are no
|
|
1566
|
-
* comments.
|
|
1567
|
-
*
|
|
1568
|
-
* @example
|
|
1569
|
-
* ```ts
|
|
1570
|
-
* buildJSDoc(['@type string', '@example hello'])
|
|
1571
|
-
* // '/**\n * @type string\n * @example hello\n *\/\n '
|
|
1572
|
-
* ```
|
|
1573
|
-
*/
|
|
1574
|
-
function buildJSDoc(comments, options = {}) {
|
|
1575
|
-
const { indent = " * ", suffix = "\n ", fallback = " " } = options;
|
|
1576
|
-
if (comments.length === 0) return fallback;
|
|
1577
|
-
return `/**\n${comments.map((c) => `${indent}${c}`).join("\n")}\n */${suffix}`;
|
|
1578
|
-
}
|
|
1420
|
+
//#region src/utils/mergeAdjacentSchemas.ts
|
|
1579
1421
|
/**
|
|
1580
|
-
*
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
if (!text) return "";
|
|
1584
|
-
return text.split("\n").map((line) => line.trim() ? ` ${line}` : "").join("\n");
|
|
1585
|
-
}
|
|
1586
|
-
/**
|
|
1587
|
-
* Renders an object key, quoting it with single quotes only when it is not a valid identifier.
|
|
1588
|
-
* Reserved words and globals (`name`, `class`, …) are valid bare keys and stay unquoted.
|
|
1589
|
-
*
|
|
1590
|
-
* @example
|
|
1591
|
-
* ```ts
|
|
1592
|
-
* objectKey('name') // 'name'
|
|
1593
|
-
* objectKey('x-total') // "'x-total'"
|
|
1594
|
-
* ```
|
|
1595
|
-
*/
|
|
1596
|
-
function objectKey(name) {
|
|
1597
|
-
return isIdentifier(name) ? name : singleQuote(name);
|
|
1598
|
-
}
|
|
1599
|
-
/**
|
|
1600
|
-
* Assembles a multi-line object literal from already-rendered `entries`, indenting each entry one
|
|
1601
|
-
* level and closing the brace at column zero. Entries that are themselves multi-line objects indent
|
|
1602
|
-
* cumulatively. Each entry ends with a trailing comma to match the formatter's multi-line style.
|
|
1603
|
-
*
|
|
1604
|
-
* @example
|
|
1605
|
-
* ```ts
|
|
1606
|
-
* buildObject(['id: z.number()', 'name: z.string()'])
|
|
1607
|
-
* // '{\n id: z.number(),\n name: z.string(),\n}'
|
|
1608
|
-
* ```
|
|
1609
|
-
*/
|
|
1610
|
-
function buildObject(entries) {
|
|
1611
|
-
if (entries.length === 0) return "{}";
|
|
1612
|
-
return `{\n${entries.map((entry) => `${indentLines(entry)},`).join("\n")}\n}`;
|
|
1613
|
-
}
|
|
1614
|
-
/**
|
|
1615
|
-
* Assembles a bracketed list (array by default) from already-rendered `items`. Keeps everything on
|
|
1616
|
-
* one line when no item spans multiple lines, and otherwise puts each item on its own line, indented
|
|
1617
|
-
* one level with a trailing comma and the closing bracket at column zero. Used for member lists such
|
|
1618
|
-
* as `z.union([…])` and `z.array([…])`.
|
|
1422
|
+
* Merges a run of adjacent anonymous object members into one. Named or non-object members break the
|
|
1423
|
+
* run and pass through unchanged. The merge follows member order, so callers control which members
|
|
1424
|
+
* combine by where they place them in the sequence.
|
|
1619
1425
|
*
|
|
1620
1426
|
* @example
|
|
1621
1427
|
* ```ts
|
|
1622
|
-
*
|
|
1623
|
-
* // '[z.string(), z.number()]'
|
|
1428
|
+
* const merged = [...mergeAdjacentObjectsLazy([objectA, objectB])]
|
|
1624
1429
|
* ```
|
|
1625
1430
|
*/
|
|
1626
|
-
function
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1431
|
+
function* mergeAdjacentObjectsLazy(members) {
|
|
1432
|
+
let acc;
|
|
1433
|
+
for (const member of members) {
|
|
1434
|
+
const objectMember = narrowSchema(member, "object");
|
|
1435
|
+
if (objectMember && !objectMember.name && acc !== void 0) {
|
|
1436
|
+
const accObject = narrowSchema(acc, "object");
|
|
1437
|
+
if (accObject && !accObject.name) {
|
|
1438
|
+
acc = createSchema({
|
|
1439
|
+
...accObject,
|
|
1440
|
+
properties: [...accObject.properties ?? [], ...objectMember.properties ?? []]
|
|
1441
|
+
});
|
|
1442
|
+
continue;
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
if (acc !== void 0) yield acc;
|
|
1446
|
+
acc = member;
|
|
1447
|
+
}
|
|
1448
|
+
if (acc !== void 0) yield acc;
|
|
1631
1449
|
}
|
|
1632
1450
|
//#endregion
|
|
1633
1451
|
//#region src/utils/refs.ts
|
|
@@ -1726,151 +1544,6 @@ function isStringType(node) {
|
|
|
1726
1544
|
return false;
|
|
1727
1545
|
}
|
|
1728
1546
|
//#endregion
|
|
1729
|
-
//#region src/utils/schemaMerge.ts
|
|
1730
|
-
/**
|
|
1731
|
-
* Merges a run of adjacent anonymous object members into one. Named or non-object members break the
|
|
1732
|
-
* run and pass through unchanged. The merge follows member order, so callers control which members
|
|
1733
|
-
* combine by where they place them in the sequence.
|
|
1734
|
-
*
|
|
1735
|
-
* @example
|
|
1736
|
-
* ```ts
|
|
1737
|
-
* const merged = [...mergeAdjacentObjectsLazy([objectA, objectB])]
|
|
1738
|
-
* ```
|
|
1739
|
-
*/
|
|
1740
|
-
function* mergeAdjacentObjectsLazy(members) {
|
|
1741
|
-
let acc;
|
|
1742
|
-
for (const member of members) {
|
|
1743
|
-
const objectMember = narrowSchema(member, "object");
|
|
1744
|
-
if (objectMember && !objectMember.name && acc !== void 0) {
|
|
1745
|
-
const accObject = narrowSchema(acc, "object");
|
|
1746
|
-
if (accObject && !accObject.name) {
|
|
1747
|
-
acc = createSchema({
|
|
1748
|
-
...accObject,
|
|
1749
|
-
properties: [...accObject.properties ?? [], ...objectMember.properties ?? []]
|
|
1750
|
-
});
|
|
1751
|
-
continue;
|
|
1752
|
-
}
|
|
1753
|
-
}
|
|
1754
|
-
if (acc !== void 0) yield acc;
|
|
1755
|
-
acc = member;
|
|
1756
|
-
}
|
|
1757
|
-
if (acc !== void 0) yield acc;
|
|
1758
|
-
}
|
|
1759
|
-
//#endregion
|
|
1760
|
-
//#region src/utils/strings.ts
|
|
1761
|
-
/**
|
|
1762
|
-
* Strips a single matching pair of `"..."`, `'...'`, or `` `...` `` from both ends of `text`.
|
|
1763
|
-
* Returns the string unchanged when no balanced quote pair is found.
|
|
1764
|
-
*
|
|
1765
|
-
* @example
|
|
1766
|
-
* ```ts
|
|
1767
|
-
* trimQuotes('"hello"') // 'hello'
|
|
1768
|
-
* trimQuotes('hello') // 'hello'
|
|
1769
|
-
* ```
|
|
1770
|
-
*/
|
|
1771
|
-
function trimQuotes(text) {
|
|
1772
|
-
if (text.length >= 2) {
|
|
1773
|
-
const first = text[0];
|
|
1774
|
-
const last = text[text.length - 1];
|
|
1775
|
-
if (first === "\"" && last === "\"" || first === "'" && last === "'" || first === "`" && last === "`") return text.slice(1, -1);
|
|
1776
|
-
}
|
|
1777
|
-
return text;
|
|
1778
|
-
}
|
|
1779
|
-
/**
|
|
1780
|
-
* Serializes a primitive to a single-quoted string literal, stripping any surrounding quotes first.
|
|
1781
|
-
*
|
|
1782
|
-
* Escaping runs through `JSON.stringify`, then the result switches to single quotes so the generated
|
|
1783
|
-
* code matches the repo style without a formatter.
|
|
1784
|
-
*
|
|
1785
|
-
* @example
|
|
1786
|
-
* ```ts
|
|
1787
|
-
* stringify('hello') // "'hello'"
|
|
1788
|
-
* stringify('"hello"') // "'hello'"
|
|
1789
|
-
* ```
|
|
1790
|
-
*/
|
|
1791
|
-
function stringify(value) {
|
|
1792
|
-
if (value === void 0 || value === null) return "''";
|
|
1793
|
-
return `'${JSON.stringify(trimQuotes(value.toString())).slice(1, -1).replace(/\\"/g, "\"").replace(/'/g, "\\'")}'`;
|
|
1794
|
-
}
|
|
1795
|
-
/**
|
|
1796
|
-
* Escapes characters that are not allowed inside JS string literals, covering quotes, backslashes,
|
|
1797
|
-
* and the Unicode line terminators U+2028 and U+2029.
|
|
1798
|
-
*
|
|
1799
|
-
* @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
|
|
1800
|
-
*
|
|
1801
|
-
* @example
|
|
1802
|
-
* ```ts
|
|
1803
|
-
* jsStringEscape('say "hi"\nbye') // 'say \\"hi\\"\\nbye'
|
|
1804
|
-
* ```
|
|
1805
|
-
*/
|
|
1806
|
-
function jsStringEscape(input) {
|
|
1807
|
-
return `${input}`.replace(/["'\\\n\r\u2028\u2029]/g, (character) => {
|
|
1808
|
-
switch (character) {
|
|
1809
|
-
case "\"":
|
|
1810
|
-
case "'":
|
|
1811
|
-
case "\\": return `\\${character}`;
|
|
1812
|
-
case "\n": return "\\n";
|
|
1813
|
-
case "\r": return "\\r";
|
|
1814
|
-
case "\u2028": return "\\u2028";
|
|
1815
|
-
case "\u2029": return "\\u2029";
|
|
1816
|
-
default: return "";
|
|
1817
|
-
}
|
|
1818
|
-
});
|
|
1819
|
-
}
|
|
1820
|
-
/**
|
|
1821
|
-
* Converts a pattern string into a `new RegExp(...)` constructor call or a regex literal string.
|
|
1822
|
-
* Inline flags expressed as a `^(?im)` prefix are extracted and applied to the resulting expression.
|
|
1823
|
-
* Pass `null` as the second argument to emit a `/pattern/flags` literal instead.
|
|
1824
|
-
*
|
|
1825
|
-
* @example
|
|
1826
|
-
* ```ts
|
|
1827
|
-
* toRegExpString('^(?im)foo') // 'new RegExp("^foo", "im")'
|
|
1828
|
-
* toRegExpString('^(?im)foo', null) // '/^foo/im'
|
|
1829
|
-
* ```
|
|
1830
|
-
*/
|
|
1831
|
-
function toRegExpString(text, func = "RegExp") {
|
|
1832
|
-
const raw = trimQuotes(text);
|
|
1833
|
-
const match = raw.match(/^\^(\(\?([igmsuy]+)\))/i);
|
|
1834
|
-
const replacementTarget = match?.[1] ?? "";
|
|
1835
|
-
const matchedFlags = match?.[2];
|
|
1836
|
-
const cleaned = raw.replace(/^\\?\//, "").replace(/\\?\/$/, "").replace(replacementTarget, "");
|
|
1837
|
-
const { source, flags } = new RegExp(cleaned, matchedFlags);
|
|
1838
|
-
if (func === null) return `/${source}/${flags}`;
|
|
1839
|
-
return `new ${func}(${JSON.stringify(source)}${flags ? `, ${JSON.stringify(flags)}` : ""})`;
|
|
1840
|
-
}
|
|
1841
|
-
/**
|
|
1842
|
-
* Renders a plain object as multi-line `key: value` source for embedding in generated code. Nested
|
|
1843
|
-
* objects recurse with fixed indentation, so the result drops straight into an object literal
|
|
1844
|
-
* without re-parsing.
|
|
1845
|
-
*
|
|
1846
|
-
* @example
|
|
1847
|
-
* ```ts
|
|
1848
|
-
* stringifyObject({ foo: 'bar', nested: { a: 1 } })
|
|
1849
|
-
* // 'foo: bar,\nnested: {\n a: 1\n }'
|
|
1850
|
-
* ```
|
|
1851
|
-
*/
|
|
1852
|
-
function stringifyObject(value) {
|
|
1853
|
-
return Object.entries(value).map(([key, val]) => {
|
|
1854
|
-
if (val !== null && typeof val === "object") return `${key}: {\n ${stringifyObject(val)}\n }`;
|
|
1855
|
-
return `${key}: ${val}`;
|
|
1856
|
-
}).filter(Boolean).join(",\n");
|
|
1857
|
-
}
|
|
1858
|
-
/**
|
|
1859
|
-
* Renders a dotted path or string array as an optional-chaining accessor expression rooted at
|
|
1860
|
-
* `accessor`. Returns `null` for an empty path.
|
|
1861
|
-
*
|
|
1862
|
-
* @example
|
|
1863
|
-
* ```ts
|
|
1864
|
-
* getNestedAccessor('pagination.next.id', 'lastPage')
|
|
1865
|
-
* // "lastPage?.['pagination']?.['next']?.['id']"
|
|
1866
|
-
* ```
|
|
1867
|
-
*/
|
|
1868
|
-
function getNestedAccessor(param, accessor) {
|
|
1869
|
-
const parts = Array.isArray(param) ? param : param.split(".");
|
|
1870
|
-
if (parts.length === 0 || parts.length === 1 && parts[0] === "") return null;
|
|
1871
|
-
return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
|
|
1872
|
-
}
|
|
1873
|
-
//#endregion
|
|
1874
1547
|
//#region src/utils/schemaGraph.ts
|
|
1875
1548
|
/**
|
|
1876
1549
|
* Memoized inner pass that walks a single node and returns the names of every schema it references.
|
|
@@ -1943,7 +1616,7 @@ function computeUsedSchemaNames(operations, schemas) {
|
|
|
1943
1616
|
*
|
|
1944
1617
|
* @example Only generate schemas referenced by included operations
|
|
1945
1618
|
* ```ts
|
|
1946
|
-
* const includedOps = operations.filter((op) => resolver.
|
|
1619
|
+
* const includedOps = operations.filter((op) => resolver.default.options(op, { options, include }) !== null)
|
|
1947
1620
|
* const allowed = collectUsedSchemaNames(includedOps, schemas)
|
|
1948
1621
|
*
|
|
1949
1622
|
* for (const schema of schemas) {
|
|
@@ -2049,20 +1722,6 @@ function mapSchemaItems(node, transform) {
|
|
|
2049
1722
|
output: transform(schema)
|
|
2050
1723
|
}));
|
|
2051
1724
|
}
|
|
2052
|
-
/**
|
|
2053
|
-
* Emits a lazy getter for a circular-ref property position, `get name() { return body }`. The key
|
|
2054
|
-
* is quoted only when it is not a valid identifier. Used by the string printers to defer evaluation
|
|
2055
|
-
* of a recursive schema until first access.
|
|
2056
|
-
*
|
|
2057
|
-
* @example
|
|
2058
|
-
* ```ts
|
|
2059
|
-
* lazyGetter({ name: 'parent', body: 'z.lazy(() => Pet)' })
|
|
2060
|
-
* // "get parent() { return z.lazy(() => Pet) }"
|
|
2061
|
-
* ```
|
|
2062
|
-
*/
|
|
2063
|
-
function lazyGetter({ name, body }) {
|
|
2064
|
-
return `get ${objectKey(name)}() { return ${body} }`;
|
|
2065
|
-
}
|
|
2066
1725
|
//#endregion
|
|
2067
1726
|
//#region src/macros/macroDiscriminatorEnum.ts
|
|
2068
1727
|
/**
|
|
@@ -2238,12 +1897,12 @@ var exports_exports = /* @__PURE__ */ __exportAll({
|
|
|
2238
1897
|
applyMacros: () => applyMacros,
|
|
2239
1898
|
arrowFunctionDef: () => arrowFunctionDef,
|
|
2240
1899
|
breakDef: () => breakDef,
|
|
2241
|
-
buildJSDoc: () => buildJSDoc,
|
|
2242
|
-
buildList: () => buildList,
|
|
2243
|
-
buildObject: () => buildObject,
|
|
2244
1900
|
childName: () => childName,
|
|
2245
1901
|
collect: () => collect,
|
|
2246
1902
|
collectUsedSchemaNames: () => collectUsedSchemaNames,
|
|
1903
|
+
combineExports: () => combineExports,
|
|
1904
|
+
combineImports: () => combineImports,
|
|
1905
|
+
combineSources: () => combineSources,
|
|
2247
1906
|
composeMacros: () => composeMacros,
|
|
2248
1907
|
constDef: () => constDef,
|
|
2249
1908
|
containsCircularRef: () => containsCircularRef,
|
|
@@ -2260,15 +1919,11 @@ var exports_exports = /* @__PURE__ */ __exportAll({
|
|
|
2260
1919
|
fileDef: () => fileDef,
|
|
2261
1920
|
findCircularSchemas: () => findCircularSchemas,
|
|
2262
1921
|
functionDef: () => functionDef,
|
|
2263
|
-
getNestedAccessor: () => getNestedAccessor,
|
|
2264
1922
|
importDef: () => importDef,
|
|
2265
1923
|
inputDef: () => inputDef,
|
|
2266
1924
|
isHttpOperationNode: () => isHttpOperationNode,
|
|
2267
1925
|
isStringType: () => isStringType,
|
|
2268
|
-
isValidVarName: () => isValidVarName,
|
|
2269
|
-
jsStringEscape: () => jsStringEscape,
|
|
2270
1926
|
jsxDef: () => jsxDef,
|
|
2271
|
-
lazyGetter: () => lazyGetter,
|
|
2272
1927
|
macroDiscriminatorEnum: () => macroDiscriminatorEnum,
|
|
2273
1928
|
macroEnumName: () => macroEnumName,
|
|
2274
1929
|
macroSimplifyUnion: () => macroSimplifyUnion,
|
|
@@ -2278,7 +1933,6 @@ var exports_exports = /* @__PURE__ */ __exportAll({
|
|
|
2278
1933
|
mergeAdjacentObjectsLazy: () => mergeAdjacentObjectsLazy,
|
|
2279
1934
|
narrowSchema: () => narrowSchema,
|
|
2280
1935
|
nodeDefs: () => nodeDefs,
|
|
2281
|
-
objectKey: () => objectKey,
|
|
2282
1936
|
operationDef: () => operationDef,
|
|
2283
1937
|
optionality: () => optionality,
|
|
2284
1938
|
outputDef: () => outputDef,
|
|
@@ -2289,17 +1943,13 @@ var exports_exports = /* @__PURE__ */ __exportAll({
|
|
|
2289
1943
|
schemaDef: () => schemaDef,
|
|
2290
1944
|
schemaTypes: () => schemaTypes,
|
|
2291
1945
|
sourceDef: () => sourceDef,
|
|
2292
|
-
stringify: () => stringify,
|
|
2293
|
-
stringifyObject: () => stringifyObject,
|
|
2294
1946
|
syncSchemaRef: () => syncSchemaRef,
|
|
2295
1947
|
textDef: () => textDef,
|
|
2296
|
-
toRegExpString: () => toRegExpString,
|
|
2297
1948
|
transform: () => transform,
|
|
2298
|
-
trimQuotes: () => trimQuotes,
|
|
2299
1949
|
typeDef: () => typeDef,
|
|
2300
1950
|
walk: () => walk
|
|
2301
1951
|
});
|
|
2302
1952
|
//#endregion
|
|
2303
|
-
export { applyMacros, arrowFunctionDef, exports_exports as ast, breakDef,
|
|
1953
|
+
export { applyMacros, arrowFunctionDef, exports_exports as ast, breakDef, childName, collect, collectUsedSchemaNames, combineExports, combineImports, combineSources, composeMacros, constDef, containsCircularRef, contentDef, createPrinter, defineDialect, defineMacro, defineNode, enumPropName, exportDef, extractRefName, extractStringsFromNodes, factory_exports as factory, fileDef, findCircularSchemas, functionDef, importDef, inputDef, isHttpOperationNode, isStringType, jsxDef, macroDiscriminatorEnum, macroEnumName, macroSimplifyUnion, mapSchemaItems, mapSchemaMembers, mapSchemaProperties, mergeAdjacentObjectsLazy, narrowSchema, nodeDefs, operationDef, optionality, outputDef, parameterDef, propertyDef, requestBodyDef, responseDef, schemaDef, schemaTypes, sourceDef, syncSchemaRef, textDef, transform, typeDef, walk };
|
|
2304
1954
|
|
|
2305
1955
|
//# sourceMappingURL=index.js.map
|