@openpkg-ts/sdk 0.54.3 → 0.54.5

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.js CHANGED
@@ -1781,7 +1781,7 @@ function filterSpec(spec, criteria) {
1781
1781
  };
1782
1782
  }
1783
1783
  // src/primitives/get.ts
1784
- import ts13 from "typescript";
1784
+ import ts14 from "typescript";
1785
1785
 
1786
1786
  // src/ast/type-identity.ts
1787
1787
  import * as path3 from "node:path";
@@ -2102,22 +2102,14 @@ function extractVarianceModifiers(modifiers) {
2102
2102
  const variance = hasIn && hasOut ? "inout" : hasIn ? "in" : hasOut ? "out" : undefined;
2103
2103
  return { variance, isConst };
2104
2104
  }
2105
- function extractTypeParameters(node, checker) {
2105
+ function extractTypeParameters(node, _checker) {
2106
2106
  if (!node.typeParameters || node.typeParameters.length === 0) {
2107
2107
  return;
2108
2108
  }
2109
2109
  return node.typeParameters.map((tp) => {
2110
2110
  const name = tp.name.text;
2111
- let constraint;
2112
- if (tp.constraint) {
2113
- const constraintType = checker.getTypeAtLocation(tp.constraint);
2114
- constraint = checker.typeToString(constraintType);
2115
- }
2116
- let defaultType;
2117
- if (tp.default) {
2118
- const defType = checker.getTypeAtLocation(tp.default);
2119
- defaultType = checker.typeToString(defType);
2120
- }
2111
+ const constraint = tp.constraint ? tp.constraint.getText() : undefined;
2112
+ const defaultType = tp.default ? tp.default.getText() : undefined;
2121
2113
  const { variance, isConst } = extractVarianceModifiers(ts2.getModifiers(tp));
2122
2114
  return {
2123
2115
  name,
@@ -2175,7 +2167,7 @@ function getJSDocForSignature(signature, checker) {
2175
2167
  const symbol = checker?.getSymbolAtLocation(decl);
2176
2168
  return getJSDocComment(decl, symbol, checker);
2177
2169
  }
2178
- function extractTypeParametersFromSignature(signature, checker) {
2170
+ function extractTypeParametersFromSignature(signature, _checker) {
2179
2171
  const typeParams = signature.getTypeParameters();
2180
2172
  if (!typeParams || typeParams.length === 0) {
2181
2173
  return;
@@ -2183,15 +2175,7 @@ function extractTypeParametersFromSignature(signature, checker) {
2183
2175
  return typeParams.map((tp) => {
2184
2176
  const name = tp.getSymbol()?.getName() ?? "T";
2185
2177
  let constraint;
2186
- const constraintType = tp.getConstraint();
2187
- if (constraintType) {
2188
- constraint = checker.typeToString(constraintType);
2189
- }
2190
2178
  let defaultType;
2191
- const defaultT = tp.getDefault();
2192
- if (defaultT) {
2193
- defaultType = checker.typeToString(defaultT);
2194
- }
2195
2179
  let variance;
2196
2180
  let isConst;
2197
2181
  const tpSymbol = tp.getSymbol();
@@ -2199,6 +2183,10 @@ function extractTypeParametersFromSignature(signature, checker) {
2199
2183
  for (const decl of declarations) {
2200
2184
  if (ts2.isTypeParameterDeclaration(decl)) {
2201
2185
  ({ variance, isConst } = extractVarianceModifiers(ts2.getModifiers(decl)));
2186
+ if (decl.constraint)
2187
+ constraint = decl.constraint.getText();
2188
+ if (decl.default)
2189
+ defaultType = decl.default.getText();
2202
2190
  break;
2203
2191
  }
2204
2192
  }
@@ -2235,6 +2223,37 @@ function getExportKind(declaration, type) {
2235
2223
  import * as fs4 from "node:fs";
2236
2224
  import * as path5 from "node:path";
2237
2225
  import ts3 from "typescript";
2226
+ function collectLocalModuleFiles(entryFile, host, options) {
2227
+ const seen = new Set;
2228
+ const queue = [entryFile];
2229
+ while (queue.length > 0) {
2230
+ const file = queue.pop();
2231
+ if (seen.has(file))
2232
+ continue;
2233
+ seen.add(file);
2234
+ const text = host.readFile(file);
2235
+ if (text === undefined)
2236
+ continue;
2237
+ const sf = ts3.createSourceFile(file, text, ts3.ScriptTarget.Latest, true, getScriptKind(file));
2238
+ for (const stmt of sf.statements) {
2239
+ let spec;
2240
+ if (ts3.isImportDeclaration(stmt))
2241
+ spec = stmt.moduleSpecifier;
2242
+ else if (ts3.isExportDeclaration(stmt))
2243
+ spec = stmt.moduleSpecifier;
2244
+ if (!spec || !ts3.isStringLiteral(spec))
2245
+ continue;
2246
+ if (!spec.text.startsWith("."))
2247
+ continue;
2248
+ const resolved = ts3.resolveModuleName(spec.text, file, options, host);
2249
+ const resolvedFile = resolved.resolvedModule?.resolvedFileName;
2250
+ if (resolvedFile && !resolvedFile.includes(`${path5.sep}node_modules${path5.sep}`)) {
2251
+ queue.push(resolvedFile);
2252
+ }
2253
+ }
2254
+ }
2255
+ return [...seen];
2256
+ }
2238
2257
  function isJsFile(file) {
2239
2258
  return /\.(js|mjs|cjs|jsx)$/.test(file);
2240
2259
  }
@@ -2499,6 +2518,7 @@ function createProgram(options) {
2499
2518
  return ts3.resolveModuleName(literal.text, containingFile, options2, compilerHost, undefined, redirectedReference, mode);
2500
2519
  });
2501
2520
  }
2521
+ const localRoots = collectLocalModuleFiles(entryFile, compilerHost, compilerOptions);
2502
2522
  if (content !== undefined) {
2503
2523
  inMemorySource = ts3.createSourceFile(entryFile, content, ts3.ScriptTarget.Latest, true, getScriptKind(entryFile));
2504
2524
  const originalGetSourceFile = compilerHost.getSourceFile.bind(compilerHost);
@@ -2509,7 +2529,7 @@ function createProgram(options) {
2509
2529
  return originalGetSourceFile(fileName, languageVersion, onError, shouldCreateNewSourceFile);
2510
2530
  };
2511
2531
  }
2512
- const rootFiles = [entryFile, ...additionalRootFiles];
2532
+ const rootFiles = [...new Set([entryFile, ...localRoots, ...additionalRootFiles])];
2513
2533
  const program = ts3.createProgram(rootFiles, compilerOptions, compilerHost);
2514
2534
  const sourceFile = inMemorySource ?? program.getSourceFile(entryFile);
2515
2535
  return {
@@ -2523,13 +2543,144 @@ function createProgram(options) {
2523
2543
  }
2524
2544
 
2525
2545
  // src/serializers/classes.ts
2526
- import ts8 from "typescript";
2546
+ import ts9 from "typescript";
2527
2547
 
2528
2548
  // src/types/parameters.ts
2529
- import ts5 from "typescript";
2549
+ import ts6 from "typescript";
2530
2550
 
2531
2551
  // src/types/schema-builder.ts
2552
+ import ts5 from "typescript";
2553
+
2554
+ // src/ast/resolve.ts
2532
2555
  import ts4 from "typescript";
2556
+ function isTypeOnlyExport(symbol) {
2557
+ const declarations = symbol.declarations ?? [];
2558
+ for (const decl of declarations) {
2559
+ if (ts4.isExportSpecifier(decl)) {
2560
+ if (decl.isTypeOnly)
2561
+ return true;
2562
+ const exportDecl = decl.parent?.parent;
2563
+ if (exportDecl && ts4.isExportDeclaration(exportDecl) && exportDecl.isTypeOnly) {
2564
+ return true;
2565
+ }
2566
+ }
2567
+ }
2568
+ return false;
2569
+ }
2570
+ function resolveExportTarget(symbol, checker, program) {
2571
+ const isTypeOnly = isTypeOnlyExport(symbol);
2572
+ const targetSymbol = resolveAliasSymbol(symbol, checker, undefined, program);
2573
+ const declarations = targetSymbol.declarations ?? [];
2574
+ const declaration = targetSymbol.valueDeclaration || declarations.find((decl) => decl.kind !== ts4.SyntaxKind.ExportSpecifier && decl.kind !== ts4.SyntaxKind.ImportSpecifier && decl.kind !== ts4.SyntaxKind.ExportDeclaration && decl.kind !== ts4.SyntaxKind.ImportClause && decl.kind !== ts4.SyntaxKind.NamespaceExport);
2575
+ return { declaration, targetSymbol, isTypeOnly };
2576
+ }
2577
+ function resolveAliasSymbol(symbol, checker, seen = new Set, program) {
2578
+ if (seen.has(symbol))
2579
+ return symbol;
2580
+ seen.add(symbol);
2581
+ if (symbol.flags & ts4.SymbolFlags.Alias) {
2582
+ try {
2583
+ const aliased = checker.getAliasedSymbol(symbol);
2584
+ if (aliased && aliased !== symbol && hasConcreteDeclaration(aliased)) {
2585
+ return resolveAliasSymbol(aliased, checker, seen, program);
2586
+ }
2587
+ } catch {}
2588
+ }
2589
+ for (const decl of symbol.declarations ?? []) {
2590
+ const fromModule = resolveFromModuleSpecifier(decl, symbol, checker, program);
2591
+ if (fromModule && fromModule !== symbol) {
2592
+ return resolveAliasSymbol(fromModule, checker, seen, program);
2593
+ }
2594
+ }
2595
+ return symbol;
2596
+ }
2597
+ function hasConcreteDeclaration(symbol) {
2598
+ if (symbol.valueDeclaration)
2599
+ return true;
2600
+ return (symbol.declarations ?? []).some((d) => d.kind !== ts4.SyntaxKind.ExportSpecifier && d.kind !== ts4.SyntaxKind.ImportSpecifier && d.kind !== ts4.SyntaxKind.ExportDeclaration && d.kind !== ts4.SyntaxKind.NamespaceExport);
2601
+ }
2602
+ function resolveFromModuleSpecifier(decl, symbol, checker, program) {
2603
+ let moduleSpecifier;
2604
+ let importedName;
2605
+ if (ts4.isExportSpecifier(decl)) {
2606
+ const exportDecl = decl.parent?.parent;
2607
+ if (exportDecl && ts4.isExportDeclaration(exportDecl)) {
2608
+ moduleSpecifier = exportDecl.moduleSpecifier;
2609
+ importedName = (decl.propertyName ?? decl.name).text;
2610
+ }
2611
+ } else if (ts4.isImportSpecifier(decl)) {
2612
+ const importDecl = decl.parent?.parent?.parent;
2613
+ if (importDecl && ts4.isImportDeclaration(importDecl)) {
2614
+ moduleSpecifier = importDecl.moduleSpecifier;
2615
+ importedName = (decl.propertyName ?? decl.name).text;
2616
+ }
2617
+ } else if (ts4.isImportClause(decl) && decl.name) {
2618
+ const importDecl = decl.parent;
2619
+ if (ts4.isImportDeclaration(importDecl)) {
2620
+ moduleSpecifier = importDecl.moduleSpecifier;
2621
+ importedName = "default";
2622
+ }
2623
+ }
2624
+ if (!moduleSpecifier || importedName === undefined || !ts4.isStringLiteral(moduleSpecifier)) {
2625
+ return;
2626
+ }
2627
+ let modSym = checker.getSymbolAtLocation(moduleSpecifier);
2628
+ if (!modSym && program) {
2629
+ const containing = decl.getSourceFile().fileName;
2630
+ const resolved = ts4.resolveModuleName(moduleSpecifier.text, containing, program.getCompilerOptions(), ts4.sys);
2631
+ const file = resolved.resolvedModule?.resolvedFileName;
2632
+ const sf = file ? program.getSourceFile(file) : undefined;
2633
+ if (sf)
2634
+ modSym = checker.getSymbolAtLocation(sf);
2635
+ }
2636
+ if (!modSym)
2637
+ return;
2638
+ if (modSym.flags & ts4.SymbolFlags.Alias) {
2639
+ try {
2640
+ modSym = checker.getAliasedSymbol(modSym);
2641
+ } catch {
2642
+ return;
2643
+ }
2644
+ }
2645
+ if (!modSym)
2646
+ return;
2647
+ const exported = getModuleExportsFollowingStars(modSym, checker, program);
2648
+ const match = exported.find((e) => e.getName() === importedName);
2649
+ return match && match !== symbol ? match : undefined;
2650
+ }
2651
+ function getModuleExportsFollowingStars(modSym, checker, program, seen = new Set) {
2652
+ if (seen.has(modSym))
2653
+ return [];
2654
+ seen.add(modSym);
2655
+ const byName = new Map;
2656
+ for (const s of checker.getExportsOfModule(modSym)) {
2657
+ byName.set(s.getName(), s);
2658
+ }
2659
+ for (const decl of modSym.declarations ?? []) {
2660
+ const sf = ts4.isSourceFile(decl) ? decl : decl.getSourceFile();
2661
+ for (const stmt of sf.statements) {
2662
+ if (!ts4.isExportDeclaration(stmt) || stmt.exportClause || !stmt.moduleSpecifier || !ts4.isStringLiteral(stmt.moduleSpecifier)) {
2663
+ continue;
2664
+ }
2665
+ const nested = moduleSymbolFromPath(stmt.moduleSpecifier.text, sf.fileName, checker, program);
2666
+ if (!nested)
2667
+ continue;
2668
+ for (const s of getModuleExportsFollowingStars(nested, checker, program, seen)) {
2669
+ if (!byName.has(s.getName()))
2670
+ byName.set(s.getName(), s);
2671
+ }
2672
+ }
2673
+ }
2674
+ return [...byName.values()];
2675
+ }
2676
+ function moduleSymbolFromPath(spec, containingFile, checker, program) {
2677
+ if (!program)
2678
+ return;
2679
+ const resolved = ts4.resolveModuleName(spec, containingFile, program.getCompilerOptions(), ts4.sys);
2680
+ const file = resolved.resolvedModule?.resolvedFileName;
2681
+ const sf = file ? program.getSourceFile(file) : undefined;
2682
+ return sf ? checker.getSymbolAtLocation(sf) : undefined;
2683
+ }
2533
2684
 
2534
2685
  // src/schema/builtins.ts
2535
2686
  var BUILTIN_TYPE_SCHEMAS = {
@@ -2566,11 +2717,11 @@ function escapeRegex(text) {
2566
2717
  }
2567
2718
  function buildTemplatePattern(type) {
2568
2719
  const slotPattern = (slot) => {
2569
- if (slot.flags & ts4.TypeFlags.NumberLike)
2720
+ if (slot.flags & ts5.TypeFlags.NumberLike)
2570
2721
  return "-?\\d+(?:\\.\\d+)?";
2571
- if (slot.flags & ts4.TypeFlags.BigIntLike)
2722
+ if (slot.flags & ts5.TypeFlags.BigIntLike)
2572
2723
  return "-?\\d+";
2573
- if (slot.flags & ts4.TypeFlags.BooleanLike)
2724
+ if (slot.flags & ts5.TypeFlags.BooleanLike)
2574
2725
  return "(?:true|false)";
2575
2726
  return ".*";
2576
2727
  };
@@ -2597,12 +2748,12 @@ function scrubImportQualifiers(text) {
2597
2748
  return text.replace(/import\((?:"[^"]*"|'[^']*')\)\./g, "");
2598
2749
  }
2599
2750
  function renderTypeText(type, checker, enclosing, extraFlags = 0) {
2600
- return scrubImportQualifiers(checker.typeToString(type, enclosing, ts4.TypeFormatFlags.NoTruncation | extraFlags));
2751
+ return scrubImportQualifiers(checker.typeToString(type, enclosing, ts5.TypeFormatFlags.NoTruncation | extraFlags));
2601
2752
  }
2602
2753
  function writtenTypeText(typeNode) {
2603
2754
  if (!typeNode)
2604
2755
  return;
2605
- if (!ts4.isTypeReferenceNode(typeNode) && !ts4.isUnionTypeNode(typeNode))
2756
+ if (!ts5.isTypeReferenceNode(typeNode) && !ts5.isUnionTypeNode(typeNode))
2606
2757
  return;
2607
2758
  try {
2608
2759
  const text = scrubImportQualifiers(typeNode.getText().replace(/\s+/g, " ").replace(/^\|\s*/, "").trim());
@@ -2615,10 +2766,97 @@ function declaredTypeNode(decl) {
2615
2766
  const withType = decl;
2616
2767
  return withType?.type;
2617
2768
  }
2769
+ function typeNodeOfSignature(sig) {
2770
+ const decl = sig.getDeclaration();
2771
+ if (!decl || !ts5.isFunctionLike(decl))
2772
+ return;
2773
+ return decl.type;
2774
+ }
2775
+ function resolvedSymbol(symbol, checker) {
2776
+ if (!symbol)
2777
+ return;
2778
+ if (symbol.flags & ts5.SymbolFlags.Alias) {
2779
+ try {
2780
+ return checker.getAliasedSymbol(symbol);
2781
+ } catch {
2782
+ return symbol;
2783
+ }
2784
+ }
2785
+ return symbol;
2786
+ }
2787
+ function buildSchemaFromTypeNode(node, checker, ctx) {
2788
+ if (ts5.isParenthesizedTypeNode(node)) {
2789
+ return buildSchemaFromTypeNode(node.type, checker, ctx);
2790
+ }
2791
+ if (ts5.isUnionTypeNode(node)) {
2792
+ return { anyOf: node.types.map((t2) => buildSchemaFromTypeNode(t2, checker, ctx)) };
2793
+ }
2794
+ if (ts5.isIntersectionTypeNode(node)) {
2795
+ return { allOf: node.types.map((t2) => buildSchemaFromTypeNode(t2, checker, ctx)) };
2796
+ }
2797
+ if (node.kind === ts5.SyntaxKind.NullKeyword) {
2798
+ return { type: "null" };
2799
+ }
2800
+ if (ts5.isLiteralTypeNode(node) && node.literal.kind === ts5.SyntaxKind.NullKeyword) {
2801
+ return { type: "null" };
2802
+ }
2803
+ if (node.kind === ts5.SyntaxKind.UndefinedKeyword) {
2804
+ return { type: "undefined" };
2805
+ }
2806
+ if (node.kind === ts5.SyntaxKind.VoidKeyword) {
2807
+ return { type: "void" };
2808
+ }
2809
+ if (node.kind === ts5.SyntaxKind.AnyKeyword) {
2810
+ return { "x-ts-type": "any" };
2811
+ }
2812
+ if (node.kind === ts5.SyntaxKind.UnknownKeyword) {
2813
+ return { type: "unknown" };
2814
+ }
2815
+ if (ts5.isTypeReferenceNode(node)) {
2816
+ const raw = checker.getSymbolAtLocation(ts5.isQualifiedName(node.typeName) ? node.typeName.right : node.typeName);
2817
+ const symbol = resolvedSymbol(raw, checker);
2818
+ const name = symbol?.getName() ?? node.typeName.getText();
2819
+ const args = node.typeArguments?.map((arg) => {
2820
+ if (typeNodeDefersExpansion(arg, checker, ctx?.program)) {
2821
+ return buildSchemaFromTypeNode(arg, checker, ctx);
2822
+ }
2823
+ const argType = checker.getTypeFromTypeNode(arg);
2824
+ return buildSchema(argType, checker, ctx, arg);
2825
+ });
2826
+ const withArgs = (schema) => {
2827
+ if (!args || args.length === 0)
2828
+ return schema;
2829
+ if (typeof schema !== "object" || schema === null || Array.isArray(schema)) {
2830
+ return schema;
2831
+ }
2832
+ return { ...schema, typeArguments: args };
2833
+ };
2834
+ if (name && isBuiltinGeneric(name) && (!symbol || isBuiltinSymbol(symbol))) {
2835
+ return withArgs({ ...builtinSchema(name) });
2836
+ }
2837
+ if (name && !name.startsWith("__")) {
2838
+ let refId = name;
2839
+ if (symbol && ctx) {
2840
+ try {
2841
+ refId = namedRefId(checker.getDeclaredTypeOfSymbol(symbol), name, ctx);
2842
+ } catch {
2843
+ refId = name;
2844
+ }
2845
+ }
2846
+ return withArgs({ $ref: `#/types/${refId}` });
2847
+ }
2848
+ return { "x-ts-type": scrubImportQualifiers(node.getText()) };
2849
+ }
2850
+ const t = checker.getTypeFromTypeNode(node);
2851
+ if (!(t.flags & ts5.TypeFlags.Any)) {
2852
+ return buildSchema(t, checker, ctx);
2853
+ }
2854
+ return { "x-ts-type": scrubImportQualifiers(node.getText()) };
2855
+ }
2618
2856
  function stripUndefinedFromType(type, checker) {
2619
2857
  if (!type.isUnion())
2620
2858
  return type;
2621
- const nonUndefinedTypes = type.types.filter((t) => !(t.flags & ts4.TypeFlags.Undefined));
2859
+ const nonUndefinedTypes = type.types.filter((t) => !(t.flags & ts5.TypeFlags.Undefined));
2622
2860
  if (nonUndefinedTypes.length === 0)
2623
2861
  return type;
2624
2862
  if (nonUndefinedTypes.length === 1)
@@ -2627,13 +2865,13 @@ function stripUndefinedFromType(type, checker) {
2627
2865
  }
2628
2866
  function isReadonlyPropertySymbol(prop) {
2629
2867
  const decls = prop.getDeclarations() ?? [];
2630
- return decls.some((d) => (ts4.getCombinedModifierFlags(d) & ts4.ModifierFlags.Readonly) !== 0);
2868
+ return decls.some((d) => (ts5.getCombinedModifierFlags(d) & ts5.ModifierFlags.Readonly) !== 0);
2631
2869
  }
2632
2870
  function decoratePropertySchema(schema, prop, propType, checker) {
2633
2871
  if (typeof schema !== "object" || schema === null || Array.isArray(schema))
2634
2872
  return schema;
2635
2873
  const decl = prop.valueDeclaration ?? prop.getDeclarations()?.[0];
2636
- const optional = !!(prop.flags & ts4.SymbolFlags.Optional);
2874
+ const optional = !!(prop.flags & ts5.SymbolFlags.Optional);
2637
2875
  const textType = optional ? stripUndefinedFromType(propType, checker) : propType;
2638
2876
  const text = renderTypeText(textType, checker, decl);
2639
2877
  const obj = schema;
@@ -2650,16 +2888,16 @@ function decoratePropertySchema(schema, prop, propType, checker) {
2650
2888
  if (isReadonlyPropertySymbol(prop) && !("readOnly" in obj)) {
2651
2889
  result = { ...result, readOnly: true };
2652
2890
  }
2653
- if (prop.flags & ts4.SymbolFlags.Method && !("x-ts-method" in obj)) {
2891
+ if (prop.flags & ts5.SymbolFlags.Method && !("x-ts-method" in obj)) {
2654
2892
  result = { ...result, "x-ts-method": true };
2655
2893
  }
2656
2894
  return result;
2657
2895
  }
2658
2896
  function shouldEmitAliasTypeText(typeNode) {
2659
- if (ts4.isMappedTypeNode(typeNode))
2897
+ if (ts5.isMappedTypeNode(typeNode))
2660
2898
  return false;
2661
- if (ts4.isTypeLiteralNode(typeNode)) {
2662
- return typeNode.members.length > 0 && typeNode.members.every((m) => ts4.isIndexSignatureDeclaration(m));
2899
+ if (ts5.isTypeLiteralNode(typeNode)) {
2900
+ return typeNode.members.length > 0 && typeNode.members.every((m) => ts5.isIndexSignatureDeclaration(m));
2663
2901
  }
2664
2902
  return true;
2665
2903
  }
@@ -2721,6 +2959,104 @@ var RESOLVED_UTILITY_TYPES = new Set([
2721
2959
  "NonNullable",
2722
2960
  "Awaited"
2723
2961
  ]);
2962
+ function isDeferredMappedOrConditional(type) {
2963
+ if (shouldDeferAlias(type.aliasSymbol))
2964
+ return true;
2965
+ const target = type.target;
2966
+ if (target && target !== type) {
2967
+ if (shouldDeferAlias(target.aliasSymbol ?? target.getSymbol()))
2968
+ return true;
2969
+ const targetName = target.aliasSymbol?.getName() ?? target.getSymbol()?.getName();
2970
+ if (targetName && RESOLVED_UTILITY_TYPES.has(targetName))
2971
+ return false;
2972
+ }
2973
+ if (type.flags & ts5.TypeFlags.Conditional) {
2974
+ const name = type.aliasSymbol?.getName();
2975
+ if (name && RESOLVED_UTILITY_TYPES.has(name))
2976
+ return false;
2977
+ return true;
2978
+ }
2979
+ const objectFlags = type.objectFlags ?? 0;
2980
+ if (objectFlags & ts5.ObjectFlags.Mapped) {
2981
+ const name = type.aliasSymbol?.getName();
2982
+ if (name && RESOLVED_UTILITY_TYPES.has(name))
2983
+ return false;
2984
+ if (aliasRhsIsUtility(type.aliasSymbol))
2985
+ return false;
2986
+ return true;
2987
+ }
2988
+ return false;
2989
+ }
2990
+ function typeRefName(node) {
2991
+ return ts5.isQualifiedName(node.typeName) ? node.typeName.right.text : node.typeName.getText();
2992
+ }
2993
+ function aliasRhsIsUtility(symbol) {
2994
+ const alias = symbol?.declarations?.find(ts5.isTypeAliasDeclaration);
2995
+ if (!alias || !ts5.isTypeReferenceNode(alias.type))
2996
+ return false;
2997
+ return RESOLVED_UTILITY_TYPES.has(typeRefName(alias.type));
2998
+ }
2999
+ function isMappedOrConditionalBody(node) {
3000
+ if (ts5.isParenthesizedTypeNode(node))
3001
+ return isMappedOrConditionalBody(node.type);
3002
+ if (ts5.isMappedTypeNode(node) || ts5.isConditionalTypeNode(node))
3003
+ return true;
3004
+ if (ts5.isUnionTypeNode(node) || ts5.isIntersectionTypeNode(node)) {
3005
+ return node.types.some(isMappedOrConditionalBody);
3006
+ }
3007
+ return false;
3008
+ }
3009
+ function shouldDeferAlias(symbol) {
3010
+ if (!symbol)
3011
+ return false;
3012
+ const name = symbol.getName();
3013
+ if (!name || name.startsWith("__") || RESOLVED_UTILITY_TYPES.has(name))
3014
+ return false;
3015
+ if (aliasRhsIsUtility(symbol))
3016
+ return false;
3017
+ const alias = symbol.declarations?.find(ts5.isTypeAliasDeclaration);
3018
+ if (!alias)
3019
+ return false;
3020
+ return isMappedOrConditionalBody(alias.type);
3021
+ }
3022
+ function typeNodeDefersExpansion(node, checker, program) {
3023
+ if (!node)
3024
+ return false;
3025
+ if (ts5.isParenthesizedTypeNode(node))
3026
+ return typeNodeDefersExpansion(node.type, checker, program);
3027
+ if (ts5.isUnionTypeNode(node) || ts5.isIntersectionTypeNode(node)) {
3028
+ return node.types.some((t) => typeNodeDefersExpansion(t, checker, program));
3029
+ }
3030
+ if (!ts5.isTypeReferenceNode(node))
3031
+ return false;
3032
+ const raw = checker.getSymbolAtLocation(ts5.isQualifiedName(node.typeName) ? node.typeName.right : node.typeName);
3033
+ if (!raw)
3034
+ return false;
3035
+ const symbol = resolveAliasSymbol(raw, checker, undefined, program);
3036
+ return shouldDeferAlias(symbol);
3037
+ }
3038
+ function cheapTypeText(type, _checker, typeNode) {
3039
+ if (typeNode) {
3040
+ try {
3041
+ const text = scrubImportQualifiers(typeNode.getText().replace(/\s+/g, " ").trim());
3042
+ if (text)
3043
+ return text;
3044
+ } catch {}
3045
+ }
3046
+ const alias = type.aliasSymbol;
3047
+ const decl = alias?.declarations?.find(ts5.isTypeAliasDeclaration);
3048
+ if (decl?.type) {
3049
+ try {
3050
+ const text = scrubImportQualifiers(decl.type.getText().replace(/\s+/g, " ").trim());
3051
+ if (text)
3052
+ return text;
3053
+ } catch {}
3054
+ }
3055
+ const name = alias?.getName() ?? type.getSymbol()?.getName();
3056
+ if (name && !name.startsWith("__"))
3057
+ return name;
3058
+ return "unknown";
3059
+ }
2724
3060
  var BUILTIN_TYPES = new Set([
2725
3061
  "Date",
2726
3062
  "RegExp",
@@ -2867,12 +3203,12 @@ function isAnonymous(type) {
2867
3203
  return name.startsWith("__") || name === "";
2868
3204
  }
2869
3205
  function isFluentThisType(type) {
2870
- if (!(type.flags & ts4.TypeFlags.TypeParameter))
3206
+ if (!(type.flags & ts5.TypeFlags.TypeParameter))
2871
3207
  return false;
2872
3208
  const declarations = type.getSymbol()?.declarations;
2873
3209
  if (!declarations || declarations.length === 0)
2874
3210
  return false;
2875
- return declarations.some((decl) => ts4.isClassDeclaration(decl) || ts4.isClassExpression(decl) || ts4.isInterfaceDeclaration(decl));
3211
+ return declarations.some((decl) => ts5.isClassDeclaration(decl) || ts5.isClassExpression(decl) || ts5.isInterfaceDeclaration(decl));
2876
3212
  }
2877
3213
  function withDepth(ctx, fn) {
2878
3214
  ctx.currentDepth++;
@@ -2904,12 +3240,17 @@ function ensureNonEmptySchema(schema, type, checker) {
2904
3240
  }
2905
3241
  return schema;
2906
3242
  }
2907
- function buildSchema(type, checker, ctx) {
2908
- const schema = buildSchemaInternal(type, checker, ctx);
3243
+ function buildSchema(type, checker, ctx, typeNode) {
3244
+ const schema = buildSchemaInternal(type, checker, ctx, typeNode);
2909
3245
  return ensureNonEmptySchema(schema, type, checker);
2910
3246
  }
2911
- function buildMaxDepthSchema(type, checker) {
2912
- if (type.flags & ts4.TypeFlags.TypeParameter && !isFluentThisType(type)) {
3247
+ function buildMaxDepthSchema(type, checker, typeNode) {
3248
+ if (type.flags & ts5.TypeFlags.Any) {
3249
+ if (typeNode)
3250
+ return buildSchemaFromTypeNode(typeNode, checker);
3251
+ return { "x-ts-type": checker.typeToString(type) };
3252
+ }
3253
+ if (type.flags & ts5.TypeFlags.TypeParameter && !isFluentThisType(type)) {
2913
3254
  return { "x-ts-type": checker.typeToString(type) };
2914
3255
  }
2915
3256
  const symbol = type.getSymbol() || type.aliasSymbol;
@@ -2922,19 +3263,19 @@ function buildMaxDepthSchema(type, checker) {
2922
3263
  return { $ref: `#/types/${name}` };
2923
3264
  }
2924
3265
  }
2925
- if (type.flags & ts4.TypeFlags.String)
3266
+ if (type.flags & ts5.TypeFlags.String)
2926
3267
  return { type: "string" };
2927
- if (type.flags & ts4.TypeFlags.Number)
3268
+ if (type.flags & ts5.TypeFlags.Number)
2928
3269
  return { type: "number" };
2929
- if (type.flags & ts4.TypeFlags.Boolean)
3270
+ if (type.flags & ts5.TypeFlags.Boolean)
2930
3271
  return { type: "boolean" };
2931
- if (type.flags & ts4.TypeFlags.Undefined)
3272
+ if (type.flags & ts5.TypeFlags.Undefined)
2932
3273
  return { type: "undefined" };
2933
- if (type.flags & ts4.TypeFlags.Null)
3274
+ if (type.flags & ts5.TypeFlags.Null)
2934
3275
  return { type: "null" };
2935
- if (type.flags & ts4.TypeFlags.Void)
3276
+ if (type.flags & ts5.TypeFlags.Void)
2936
3277
  return { type: "void" };
2937
- if (type.flags & ts4.TypeFlags.TemplateLiteral) {
3278
+ if (type.flags & ts5.TypeFlags.TemplateLiteral) {
2938
3279
  return {
2939
3280
  type: "string",
2940
3281
  pattern: buildTemplatePattern(type),
@@ -2951,9 +3292,21 @@ function buildMaxDepthSchema(type, checker) {
2951
3292
  }
2952
3293
  return { type: checker.typeToString(type) };
2953
3294
  }
2954
- function buildSchemaInternal(type, checker, ctx) {
3295
+ function buildSchemaInternal(type, checker, ctx, typeNode) {
2955
3296
  if (isAtMaxDepth(ctx)) {
2956
- return buildMaxDepthSchema(type, checker);
3297
+ return buildMaxDepthSchema(type, checker, typeNode);
3298
+ }
3299
+ if (ctx) {
3300
+ ctx.schemaOps += 1;
3301
+ if (ctx.schemaOps > ctx.maxSchemaOps) {
3302
+ ctx.budgetExceeded = true;
3303
+ return { "x-ts-type": cheapTypeText(type, checker, typeNode) };
3304
+ }
3305
+ }
3306
+ if (isDeferredMappedOrConditional(type)) {
3307
+ if (ctx)
3308
+ ctx.budgetExceeded = true;
3309
+ return { "x-ts-type": cheapTypeText(type, checker, typeNode) };
2957
3310
  }
2958
3311
  if (ctx?.visitedTypes.has(type)) {
2959
3312
  const callSignatures = type.getCallSignatures();
@@ -2970,32 +3323,35 @@ function buildSchemaInternal(type, checker, ctx) {
2970
3323
  }
2971
3324
  return { type: checker.typeToString(type) };
2972
3325
  }
2973
- const addedToVisited = !!(ctx && type.flags & ts4.TypeFlags.Object);
3326
+ const addedToVisited = !!(ctx && type.flags & ts5.TypeFlags.Object);
2974
3327
  if (addedToVisited) {
2975
3328
  ctx.visitedTypes.add(type);
2976
3329
  }
2977
3330
  try {
2978
- if (type.flags & ts4.TypeFlags.String)
3331
+ if (type.flags & ts5.TypeFlags.String)
2979
3332
  return { type: "string" };
2980
- if (type.flags & ts4.TypeFlags.Number)
3333
+ if (type.flags & ts5.TypeFlags.Number)
2981
3334
  return { type: "number" };
2982
- if (type.flags & ts4.TypeFlags.Boolean)
3335
+ if (type.flags & ts5.TypeFlags.Boolean)
2983
3336
  return { type: "boolean" };
2984
- if (type.flags & ts4.TypeFlags.Undefined)
3337
+ if (type.flags & ts5.TypeFlags.Undefined)
2985
3338
  return { type: "undefined" };
2986
- if (type.flags & ts4.TypeFlags.Null)
3339
+ if (type.flags & ts5.TypeFlags.Null)
2987
3340
  return { type: "null" };
2988
- if (type.flags & ts4.TypeFlags.Void)
3341
+ if (type.flags & ts5.TypeFlags.Void)
2989
3342
  return { type: "void" };
2990
- if (type.flags & ts4.TypeFlags.Any)
2991
- return { type: "any" };
2992
- if (type.flags & ts4.TypeFlags.Unknown)
3343
+ if (type.flags & ts5.TypeFlags.Any) {
3344
+ if (typeNode)
3345
+ return buildSchemaFromTypeNode(typeNode, checker, ctx);
3346
+ return { "x-ts-type": checker.typeToString(type) };
3347
+ }
3348
+ if (type.flags & ts5.TypeFlags.Unknown)
2993
3349
  return { type: "unknown" };
2994
- if (type.flags & ts4.TypeFlags.Never)
3350
+ if (type.flags & ts5.TypeFlags.Never)
2995
3351
  return { type: "never" };
2996
- if (type.flags & ts4.TypeFlags.BigInt)
3352
+ if (type.flags & ts5.TypeFlags.BigInt)
2997
3353
  return { type: "bigint" };
2998
- if (type.flags & ts4.TypeFlags.ESSymbol)
3354
+ if (type.flags & ts5.TypeFlags.ESSymbol)
2999
3355
  return { type: "symbol" };
3000
3356
  if (isFluentThisType(type)) {
3001
3357
  const constraint = type.getConstraint?.();
@@ -3007,18 +3363,18 @@ function buildSchemaInternal(type, checker, ctx) {
3007
3363
  };
3008
3364
  }
3009
3365
  }
3010
- if (type.flags & ts4.TypeFlags.TypeParameter) {
3366
+ if (type.flags & ts5.TypeFlags.TypeParameter) {
3011
3367
  return { "x-ts-type": checker.typeToString(type) };
3012
3368
  }
3013
- if (type.flags & ts4.TypeFlags.StringLiteral) {
3369
+ if (type.flags & ts5.TypeFlags.StringLiteral) {
3014
3370
  const literal = type.value;
3015
3371
  return { type: "string", enum: [literal] };
3016
3372
  }
3017
- if (type.flags & ts4.TypeFlags.NumberLiteral) {
3373
+ if (type.flags & ts5.TypeFlags.NumberLiteral) {
3018
3374
  const literal = type.value;
3019
3375
  return { type: "number", enum: [literal] };
3020
3376
  }
3021
- if (type.flags & ts4.TypeFlags.BooleanLiteral) {
3377
+ if (type.flags & ts5.TypeFlags.BooleanLiteral) {
3022
3378
  const typeString2 = checker.typeToString(type);
3023
3379
  return { type: "boolean", enum: [typeString2 === "true"] };
3024
3380
  }
@@ -3033,33 +3389,33 @@ function buildSchemaInternal(type, checker, ctx) {
3033
3389
  return schema;
3034
3390
  }
3035
3391
  }
3036
- if (type.flags & ts4.TypeFlags.TemplateLiteral) {
3392
+ if (type.flags & ts5.TypeFlags.TemplateLiteral) {
3037
3393
  return {
3038
3394
  type: "string",
3039
3395
  pattern: buildTemplatePattern(type),
3040
3396
  "x-ts-type": renderTypeText(type, checker)
3041
3397
  };
3042
3398
  }
3043
- if (type.flags & ts4.TypeFlags.StringMapping) {
3399
+ if (type.flags & ts5.TypeFlags.StringMapping) {
3044
3400
  return { type: "string", "x-ts-type": renderTypeText(type, checker) };
3045
3401
  }
3046
3402
  if (type.isUnion()) {
3047
3403
  const types = type.types;
3048
- const allStringLiterals = types.every((t) => t.flags & ts4.TypeFlags.StringLiteral);
3404
+ const allStringLiterals = types.every((t) => t.flags & ts5.TypeFlags.StringLiteral);
3049
3405
  if (allStringLiterals) {
3050
3406
  const enumValues = types.map((t) => t.value);
3051
3407
  return { type: "string", enum: enumValues };
3052
3408
  }
3053
- const allNumberLiterals = types.every((t) => t.flags & ts4.TypeFlags.NumberLiteral);
3409
+ const allNumberLiterals = types.every((t) => t.flags & ts5.TypeFlags.NumberLiteral);
3054
3410
  if (allNumberLiterals) {
3055
3411
  const enumValues = types.map((t) => t.value);
3056
3412
  return { type: "number", enum: enumValues };
3057
3413
  }
3058
- const allBooleanLiterals = types.every((t) => t.flags & ts4.TypeFlags.BooleanLiteral);
3414
+ const allBooleanLiterals = types.every((t) => t.flags & ts5.TypeFlags.BooleanLiteral);
3059
3415
  if (allBooleanLiterals) {
3060
3416
  return { type: "boolean" };
3061
3417
  }
3062
- const isBoolLiteral = (t) => !!(t.flags & ts4.TypeFlags.BooleanLiteral);
3418
+ const isBoolLiteral = (t) => !!(t.flags & ts5.TypeFlags.BooleanLiteral);
3063
3419
  let members = types;
3064
3420
  if (types.filter(isBoolLiteral).length === 2) {
3065
3421
  const firstBool = types.findIndex(isBoolLiteral);
@@ -3073,10 +3429,10 @@ function buildSchemaInternal(type, checker, ctx) {
3073
3429
  }
3074
3430
  return { anyOf: members.map(buildBranch) };
3075
3431
  }
3076
- const isIntersectionType = type.isIntersection() || !!(type.flags & ts4.TypeFlags.Intersection);
3432
+ const isIntersectionType = type.isIntersection() || !!(type.flags & ts5.TypeFlags.Intersection);
3077
3433
  if (isIntersectionType && "types" in type) {
3078
3434
  const intersectionType = type;
3079
- const filteredTypes = intersectionType.types.filter((t) => !(t.flags & ts4.TypeFlags.Never));
3435
+ const filteredTypes = intersectionType.types.filter((t) => !(t.flags & ts5.TypeFlags.Never));
3080
3436
  if (filteredTypes.length === 0) {
3081
3437
  return { type: "never" };
3082
3438
  }
@@ -3191,7 +3547,7 @@ function buildSchemaInternal(type, checker, ctx) {
3191
3547
  if (BUILTIN_TYPES.has(name)) {
3192
3548
  return builtinSchema(name);
3193
3549
  }
3194
- if (RESOLVED_UTILITY_TYPES.has(name) && type.flags & ts4.TypeFlags.Object) {
3550
+ if (RESOLVED_UTILITY_TYPES.has(name) && type.flags & ts5.TypeFlags.Object) {
3195
3551
  const props = type.getProperties();
3196
3552
  const hasIndex = checker.getIndexInfosOfType(type).length > 0;
3197
3553
  if (props.length > 0 || hasIndex) {
@@ -3229,7 +3585,7 @@ function buildSchemaInternal(type, checker, ctx) {
3229
3585
  return schema;
3230
3586
  }
3231
3587
  }
3232
- if (type.flags & ts4.TypeFlags.Object) {
3588
+ if (type.flags & ts5.TypeFlags.Object) {
3233
3589
  const callSignatures = type.getCallSignatures();
3234
3590
  if (callSignatures.length > 0) {
3235
3591
  return buildFunctionSchema(callSignatures, checker, ctx);
@@ -3255,10 +3611,10 @@ function buildSchemaInternal(type, checker, ctx) {
3255
3611
  return schema;
3256
3612
  }
3257
3613
  }
3258
- if (type.flags & ts4.TypeFlags.Object) {
3614
+ if (type.flags & ts5.TypeFlags.Object) {
3259
3615
  const objectType = type;
3260
3616
  const properties = type.getProperties();
3261
- if (properties.length > 0 || objectType.objectFlags & ts4.ObjectFlags.Anonymous || checker.getIndexInfosOfType(type).length > 0) {
3617
+ if (properties.length > 0 || objectType.objectFlags & ts5.ObjectFlags.Anonymous || checker.getIndexInfosOfType(type).length > 0) {
3262
3618
  return buildObjectSchema(properties, checker, ctx, type);
3263
3619
  }
3264
3620
  }
@@ -3281,7 +3637,7 @@ function buildFunctionSchema(callSignatures, checker, ctx) {
3281
3637
  const effectiveType = isOptional ? stripUndefinedFromType(paramType, checker) : paramType;
3282
3638
  return {
3283
3639
  name: param.getName(),
3284
- schema: buildSchema(effectiveType, checker, ctx),
3640
+ schema: buildSchema(effectiveType, checker, ctx, decl.type),
3285
3641
  required: !isOptional
3286
3642
  };
3287
3643
  });
@@ -3289,7 +3645,7 @@ function buildFunctionSchema(callSignatures, checker, ctx) {
3289
3645
  return {
3290
3646
  parameters: params,
3291
3647
  returns: {
3292
- schema: buildSchema(returnType, checker, ctx)
3648
+ schema: buildSchema(returnType, checker, ctx, typeNodeOfSignature(sig))
3293
3649
  }
3294
3650
  };
3295
3651
  });
@@ -3302,8 +3658,8 @@ function buildFunctionSchema(callSignatures, checker, ctx) {
3302
3658
  }
3303
3659
  function buildObjectSchema(properties, checker, ctx, originalType) {
3304
3660
  const isArrayLikeType = originalType ? checker.isArrayType(originalType) || checker.isTupleType(originalType) || originalType.symbol?.getName() === "Array" && isBuiltinSymbol(originalType.symbol) : false;
3305
- const isStringLikeType = !!(originalType && originalType.flags & ts4.TypeFlags.StringLike);
3306
- const isNumberLikeType = !!(originalType && originalType.flags & ts4.TypeFlags.NumberLike);
3661
+ const isStringLikeType = !!(originalType && originalType.flags & ts5.TypeFlags.StringLike);
3662
+ const isNumberLikeType = !!(originalType && originalType.flags & ts5.TypeFlags.NumberLike);
3307
3663
  const buildProps = () => {
3308
3664
  const props = {};
3309
3665
  const required = [];
@@ -3320,10 +3676,11 @@ function buildObjectSchema(properties, checker, ctx, originalType) {
3320
3676
  if (isNumberLikeType && NUMBER_PROTOTYPE_METHODS.has(propName)) {
3321
3677
  continue;
3322
3678
  }
3323
- const isOptionalProp = !!(prop.flags & ts4.SymbolFlags.Optional);
3679
+ const isOptionalProp = !!(prop.flags & ts5.SymbolFlags.Optional);
3324
3680
  const rawPropType = checker.getTypeOfSymbol(prop);
3325
3681
  const propType = isOptionalProp ? stripUndefinedFromType(rawPropType, checker) : rawPropType;
3326
- let propSchema = buildSchema(propType, checker, ctx);
3682
+ const decl = prop.valueDeclaration ?? prop.getDeclarations()?.[0];
3683
+ let propSchema = buildSchema(propType, checker, ctx, declaredTypeNode(decl));
3327
3684
  const docComment = prop.getDocumentationComment(checker);
3328
3685
  if (docComment.length > 0) {
3329
3686
  const description = docComment.map((c) => c.text).join(`
@@ -3338,7 +3695,7 @@ function buildObjectSchema(properties, checker, ctx, originalType) {
3338
3695
  }
3339
3696
  propSchema = decoratePropertySchema(propSchema, prop, propType, checker);
3340
3697
  props[propName] = propSchema;
3341
- if (!(prop.flags & ts4.SymbolFlags.Optional)) {
3698
+ if (!(prop.flags & ts5.SymbolFlags.Optional)) {
3342
3699
  required.push(propName);
3343
3700
  }
3344
3701
  }
@@ -3348,11 +3705,11 @@ function buildObjectSchema(properties, checker, ctx, originalType) {
3348
3705
  ...required.length > 0 ? { required } : {}
3349
3706
  };
3350
3707
  const indexInfos = originalType ? checker.getIndexInfosOfType(originalType) : [];
3351
- const stringIndex = indexInfos.find((i) => i.keyType.flags & ts4.TypeFlags.String);
3708
+ const stringIndex = indexInfos.find((i) => i.keyType.flags & ts5.TypeFlags.String);
3352
3709
  if (stringIndex) {
3353
3710
  schema.additionalProperties = buildSchema(stringIndex.type, checker, ctx);
3354
3711
  }
3355
- const numberIndex = indexInfos.find((i) => i.keyType.flags & ts4.TypeFlags.Number);
3712
+ const numberIndex = indexInfos.find((i) => i.keyType.flags & ts5.TypeFlags.Number);
3356
3713
  if (numberIndex) {
3357
3714
  schema.patternProperties = {
3358
3715
  "^\\d+$": buildSchema(numberIndex.type, checker, ctx)
@@ -3441,7 +3798,7 @@ function deduplicateSchemas(schemas) {
3441
3798
  function findDiscriminatorProperty(unionTypes, checker) {
3442
3799
  const memberProps = [];
3443
3800
  for (const t of unionTypes) {
3444
- if (t.flags & (ts4.TypeFlags.Null | ts4.TypeFlags.Undefined)) {
3801
+ if (t.flags & (ts5.TypeFlags.Null | ts5.TypeFlags.Undefined)) {
3445
3802
  continue;
3446
3803
  }
3447
3804
  const props = t.getProperties();
@@ -3495,24 +3852,27 @@ function extractParameters(signature, ctx) {
3495
3852
  const { typeChecker: checker } = ctx;
3496
3853
  const result = [];
3497
3854
  const signatureDecl = signature.getDeclaration();
3498
- const jsdocTags = signatureDecl ? ts5.getJSDocTags(signatureDecl) : [];
3855
+ const jsdocTags = signatureDecl ? ts6.getJSDocTags(signatureDecl) : [];
3499
3856
  for (const param of signature.getParameters()) {
3500
3857
  const decl = param.valueDeclaration;
3501
3858
  if (!decl)
3502
3859
  continue;
3503
- const type = checker.getTypeOfSymbolAtLocation(param, decl);
3504
- if (decl && ts5.isObjectBindingPattern(decl.name)) {
3505
- const expandedParams = expandBindingPattern(decl, type, jsdocTags, ctx);
3860
+ const defer = typeNodeDefersExpansion(decl.type, checker, ctx.program);
3861
+ const type = defer ? undefined : checker.getTypeOfSymbolAtLocation(param, decl);
3862
+ if (decl && ts6.isObjectBindingPattern(decl.name)) {
3863
+ const expandedParams = expandBindingPattern(decl, type ?? checker.getTypeOfSymbolAtLocation(param, decl), jsdocTags, ctx);
3506
3864
  result.push(...expandedParams);
3507
3865
  } else {
3508
3866
  const isOptional = !!decl?.questionToken || !!decl?.initializer;
3509
- const effectiveType = isOptional ? stripUndefinedFromType(type, checker) : type;
3510
- registerReferencedTypes(effectiveType, ctx);
3511
3867
  const paramName = param.getName();
3512
3868
  const description = getParamDescription(paramName, jsdocTags);
3869
+ const schema = defer ? buildSchemaFromTypeNode(decl.type, checker, ctx) : buildSchema(isOptional ? stripUndefinedFromType(type, checker) : type, checker, ctx, decl.type);
3870
+ if (!defer && type) {
3871
+ registerReferencedTypes(isOptional ? stripUndefinedFromType(type, checker) : type, ctx);
3872
+ }
3513
3873
  const paramResult = {
3514
3874
  name: paramName,
3515
- schema: buildSchema(effectiveType, checker, ctx),
3875
+ schema,
3516
3876
  required: !isOptional
3517
3877
  };
3518
3878
  if (description) {
@@ -3536,20 +3896,20 @@ function expandBindingPattern(paramDecl, paramType, jsdocTags, ctx) {
3536
3896
  const allProperties = getEffectiveProperties(paramType, checker);
3537
3897
  const inferredAlias = inferParamAlias(jsdocTags);
3538
3898
  for (const element of bindingPattern.elements) {
3539
- if (!ts5.isBindingElement(element))
3899
+ if (!ts6.isBindingElement(element))
3540
3900
  continue;
3541
- const propertyName = element.propertyName ? ts5.isIdentifier(element.propertyName) ? element.propertyName.text : element.propertyName.getText() : ts5.isIdentifier(element.name) ? element.name.text : element.name.getText();
3901
+ const propertyName = element.propertyName ? ts6.isIdentifier(element.propertyName) ? element.propertyName.text : element.propertyName.getText() : ts6.isIdentifier(element.name) ? element.name.text : element.name.getText();
3542
3902
  const propSymbol = allProperties.get(propertyName);
3543
3903
  if (!propSymbol)
3544
3904
  continue;
3545
- const isOptional = !!(propSymbol.flags & ts5.SymbolFlags.Optional) || element.initializer !== undefined;
3905
+ const isOptional = !!(propSymbol.flags & ts6.SymbolFlags.Optional) || element.initializer !== undefined;
3546
3906
  const propType = checker.getTypeOfSymbol(propSymbol);
3547
3907
  const effectiveType = isOptional ? stripUndefinedFromType(propType, checker) : propType;
3548
3908
  registerReferencedTypes(effectiveType, ctx);
3549
3909
  const description = getParamDescription(propertyName, jsdocTags, inferredAlias);
3550
3910
  const param = {
3551
3911
  name: propertyName,
3552
- schema: buildSchema(effectiveType, checker, ctx),
3912
+ schema: buildSchema(effectiveType, checker, ctx, declaredTypeNode(propSymbol.valueDeclaration)),
3553
3913
  required: !isOptional
3554
3914
  };
3555
3915
  if (description) {
@@ -3585,7 +3945,7 @@ function inferParamAlias(jsdocTags) {
3585
3945
  for (const tag of jsdocTags) {
3586
3946
  if (tag.tagName.text !== "param")
3587
3947
  continue;
3588
- const tagText = typeof tag.comment === "string" ? tag.comment : ts5.getTextOfJSDocComment(tag.comment) ?? "";
3948
+ const tagText = typeof tag.comment === "string" ? tag.comment : ts6.getTextOfJSDocComment(tag.comment) ?? "";
3589
3949
  const paramTag = tag;
3590
3950
  const paramName = paramTag.name?.getText() ?? "";
3591
3951
  if (paramName.includes(".")) {
@@ -3608,22 +3968,22 @@ function inferParamAlias(jsdocTags) {
3608
3968
  return Array.from(counts.entries()).sort((a, b) => b[1] - a[1])[0]?.[0];
3609
3969
  }
3610
3970
  function extractLiteralDefault(initializer) {
3611
- if (ts5.isStringLiteral(initializer)) {
3971
+ if (ts6.isStringLiteral(initializer)) {
3612
3972
  return { literal: true, value: initializer.text };
3613
3973
  }
3614
- if (ts5.isNumericLiteral(initializer)) {
3974
+ if (ts6.isNumericLiteral(initializer)) {
3615
3975
  return { literal: true, value: Number(initializer.text) };
3616
3976
  }
3617
- if (ts5.isPrefixUnaryExpression(initializer) && initializer.operator === ts5.SyntaxKind.MinusToken && ts5.isNumericLiteral(initializer.operand)) {
3977
+ if (ts6.isPrefixUnaryExpression(initializer) && initializer.operator === ts6.SyntaxKind.MinusToken && ts6.isNumericLiteral(initializer.operand)) {
3618
3978
  return { literal: true, value: -Number(initializer.operand.text) };
3619
3979
  }
3620
- if (initializer.kind === ts5.SyntaxKind.TrueKeyword) {
3980
+ if (initializer.kind === ts6.SyntaxKind.TrueKeyword) {
3621
3981
  return { literal: true, value: true };
3622
3982
  }
3623
- if (initializer.kind === ts5.SyntaxKind.FalseKeyword) {
3983
+ if (initializer.kind === ts6.SyntaxKind.FalseKeyword) {
3624
3984
  return { literal: true, value: false };
3625
3985
  }
3626
- if (initializer.kind === ts5.SyntaxKind.NullKeyword) {
3986
+ if (initializer.kind === ts6.SyntaxKind.NullKeyword) {
3627
3987
  return { literal: true, value: null };
3628
3988
  }
3629
3989
  return { literal: false, text: initializer.getText() };
@@ -3644,7 +4004,7 @@ function registerReferencedTypes(type, ctx, depth = 0) {
3644
4004
  return;
3645
4005
  if (ctx.registeredTypes.has(type))
3646
4006
  return;
3647
- const isPrimitive = type.flags & (ts5.TypeFlags.String | ts5.TypeFlags.Number | ts5.TypeFlags.Boolean | ts5.TypeFlags.Void | ts5.TypeFlags.Undefined | ts5.TypeFlags.Null | ts5.TypeFlags.Any | ts5.TypeFlags.Unknown | ts5.TypeFlags.Never | ts5.TypeFlags.StringLiteral | ts5.TypeFlags.NumberLiteral | ts5.TypeFlags.BooleanLiteral);
4007
+ const isPrimitive = type.flags & (ts6.TypeFlags.String | ts6.TypeFlags.Number | ts6.TypeFlags.Boolean | ts6.TypeFlags.Void | ts6.TypeFlags.Undefined | ts6.TypeFlags.Null | ts6.TypeFlags.Any | ts6.TypeFlags.Unknown | ts6.TypeFlags.Never | ts6.TypeFlags.StringLiteral | ts6.TypeFlags.NumberLiteral | ts6.TypeFlags.BooleanLiteral);
3648
4008
  if (!isPrimitive) {
3649
4009
  ctx.registeredTypes.add(type);
3650
4010
  }
@@ -3673,7 +4033,10 @@ function registerReferencedTypes(type, ctx, depth = 0) {
3673
4033
  if (isForeignPackage(typeSymbol, ctx.workspacePackages)) {
3674
4034
  return;
3675
4035
  }
3676
- if (type.flags & ts5.TypeFlags.Object) {
4036
+ if (isDeferredMappedOrConditional(type)) {
4037
+ return;
4038
+ }
4039
+ if (type.flags & ts6.TypeFlags.Object) {
3677
4040
  const props = type.getProperties();
3678
4041
  const limit = ctx.maxProperties;
3679
4042
  if (props.length > limit && ctx.onTruncation) {
@@ -3688,10 +4051,10 @@ function registerReferencedTypes(type, ctx, depth = 0) {
3688
4051
  }
3689
4052
 
3690
4053
  // src/serializers/context.ts
3691
- import ts7 from "typescript";
4054
+ import ts8 from "typescript";
3692
4055
 
3693
4056
  // src/ast/registry.ts
3694
- import ts6 from "typescript";
4057
+ import ts7 from "typescript";
3695
4058
  var BUILTINS = new Set([
3696
4059
  "Array",
3697
4060
  "ArrayBuffer",
@@ -3788,9 +4151,10 @@ class TypeRegistry {
3788
4151
  return this.types.size;
3789
4152
  }
3790
4153
  registerType(type, ctx) {
3791
- const symbol = type.aliasSymbol || type.getSymbol();
3792
- if (!symbol)
4154
+ const rawSymbol = type.aliasSymbol || type.getSymbol();
4155
+ if (!rawSymbol)
3793
4156
  return;
4157
+ const symbol = resolveAliasSymbol(rawSymbol, ctx.typeChecker, undefined, ctx.program);
3794
4158
  const name = symbol.getName();
3795
4159
  if (PRIMITIVES.has(name))
3796
4160
  return;
@@ -3800,13 +4164,13 @@ class TypeRegistry {
3800
4164
  return;
3801
4165
  if (name.startsWith('"'))
3802
4166
  return;
3803
- if (symbol.flags & ts6.SymbolFlags.EnumMember)
4167
+ if (symbol.flags & ts7.SymbolFlags.EnumMember)
3804
4168
  return;
3805
- if (symbol.flags & ts6.SymbolFlags.TypeParameter)
4169
+ if (symbol.flags & ts7.SymbolFlags.TypeParameter)
3806
4170
  return;
3807
- if (symbol.flags & ts6.SymbolFlags.Method)
4171
+ if (symbol.flags & ts7.SymbolFlags.Method)
3808
4172
  return;
3809
- if (symbol.flags & ts6.SymbolFlags.Function)
4173
+ if (symbol.flags & ts7.SymbolFlags.Function)
3810
4174
  return;
3811
4175
  if (isGenericTypeParameter(name))
3812
4176
  return;
@@ -3829,7 +4193,7 @@ class TypeRegistry {
3829
4193
  });
3830
4194
  return id;
3831
4195
  };
3832
- if (ctx.shouldExpandExternal && !ctx.shouldExpandExternal(symbol)) {
4196
+ if (symbol.declarations?.[0] && ctx.shouldExpandExternal && !ctx.shouldExpandExternal(symbol)) {
3833
4197
  return stubExternal();
3834
4198
  }
3835
4199
  if (this.types.size >= MAX_REGISTERED_TYPES) {
@@ -3856,11 +4220,11 @@ class TypeRegistry {
3856
4220
  let kind = "type";
3857
4221
  const external = decl ? isExternalType(decl) : false;
3858
4222
  if (decl) {
3859
- if (ts6.isClassDeclaration(decl))
4223
+ if (ts7.isClassDeclaration(decl))
3860
4224
  kind = "class";
3861
- else if (ts6.isInterfaceDeclaration(decl))
4225
+ else if (ts7.isInterfaceDeclaration(decl))
3862
4226
  kind = "interface";
3863
- else if (ts6.isEnumDeclaration(decl))
4227
+ else if (ts7.isEnumDeclaration(decl))
3864
4228
  kind = "enum";
3865
4229
  }
3866
4230
  if (external) {
@@ -3876,8 +4240,8 @@ class TypeRegistry {
3876
4240
  schema = enumSchema;
3877
4241
  }
3878
4242
  }
3879
- if (kind === "type" && decl && ts6.isTypeAliasDeclaration(decl) && shouldEmitAliasTypeText(decl.type) && typeof schema === "object" && schema !== null && !("x-ts-type" in schema)) {
3880
- const text = renderTypeText(type, checker, decl, ts6.TypeFormatFlags.InTypeAlias);
4243
+ if (kind === "type" && decl && ts7.isTypeAliasDeclaration(decl) && shouldEmitAliasTypeText(decl.type) && typeof schema === "object" && schema !== null && !("x-ts-type" in schema)) {
4244
+ const text = renderTypeText(type, checker, decl, ts7.TypeFormatFlags.InTypeAlias);
3881
4245
  if (!PRIMITIVES.has(text) && text !== name) {
3882
4246
  schema["x-ts-type"] = text;
3883
4247
  const declared = writtenTypeText(declaredTypeNode(decl));
@@ -3887,7 +4251,7 @@ class TypeRegistry {
3887
4251
  }
3888
4252
  }
3889
4253
  let typeParameters;
3890
- if (decl && (ts6.isTypeAliasDeclaration(decl) || ts6.isInterfaceDeclaration(decl) || ts6.isClassDeclaration(decl))) {
4254
+ if (decl && (ts7.isTypeAliasDeclaration(decl) || ts7.isInterfaceDeclaration(decl) || ts7.isClassDeclaration(decl))) {
3891
4255
  typeParameters = extractTypeParameters(decl, checker);
3892
4256
  }
3893
4257
  return {
@@ -3908,14 +4272,14 @@ class TypeRegistry {
3908
4272
  resolveSelRefSchema(type, checker, ctx) {
3909
4273
  if (type.isUnion()) {
3910
4274
  const types = type.types;
3911
- const allStringLiterals = types.every((t) => t.flags & ts6.TypeFlags.StringLiteral);
4275
+ const allStringLiterals = types.every((t) => t.flags & ts7.TypeFlags.StringLiteral);
3912
4276
  if (allStringLiterals) {
3913
4277
  return {
3914
4278
  type: "string",
3915
4279
  enum: types.map((t) => t.value)
3916
4280
  };
3917
4281
  }
3918
- const allNumberLiterals = types.every((t) => t.flags & ts6.TypeFlags.NumberLiteral);
4282
+ const allNumberLiterals = types.every((t) => t.flags & ts7.TypeFlags.NumberLiteral);
3919
4283
  if (allNumberLiterals) {
3920
4284
  return {
3921
4285
  type: "number",
@@ -3950,18 +4314,18 @@ class TypeRegistry {
3950
4314
  const elementType = checker.getTypeArguments(type)?.[0];
3951
4315
  return elementType ? { type: "array", items: buildSchema(elementType, checker, ctx) } : { type: "array" };
3952
4316
  }
3953
- if (type.flags & ts6.TypeFlags.Conditional) {
4317
+ if (type.flags & ts7.TypeFlags.Conditional) {
3954
4318
  return { "x-ts-type": renderTypeText(type, checker) };
3955
4319
  }
3956
4320
  const constraint = checker.getBaseConstraintOfType(type);
3957
- const primitive = constraint && constraint.flags & ts6.TypeFlags.StringLike ? "string" : constraint && constraint.flags & ts6.TypeFlags.NumberLike ? "number" : constraint && constraint.flags & ts6.TypeFlags.BooleanLike ? "boolean" : undefined;
4321
+ const primitive = constraint && constraint.flags & ts7.TypeFlags.StringLike ? "string" : constraint && constraint.flags & ts7.TypeFlags.NumberLike ? "number" : constraint && constraint.flags & ts7.TypeFlags.BooleanLike ? "boolean" : undefined;
3958
4322
  if (primitive) {
3959
4323
  return { type: primitive, "x-ts-type": renderTypeText(type, checker) };
3960
4324
  }
3961
4325
  return this.buildObjectSchemaFromProperties(type, checker, ctx);
3962
4326
  }
3963
4327
  buildEnumSchema(symbol, checker) {
3964
- const decl = symbol.declarations?.find(ts6.isEnumDeclaration);
4328
+ const decl = symbol.declarations?.find(ts7.isEnumDeclaration);
3965
4329
  if (!decl)
3966
4330
  return;
3967
4331
  const members = [];
@@ -3988,8 +4352,8 @@ class TypeRegistry {
3988
4352
  buildObjectSchemaFromProperties(type, checker, ctx) {
3989
4353
  const properties = type.getProperties();
3990
4354
  const indexInfos = checker.getIndexInfosOfType(type);
3991
- const stringIndex = indexInfos.find((i) => i.keyType.flags & ts6.TypeFlags.String);
3992
- const numberIndex = indexInfos.find((i) => i.keyType.flags & ts6.TypeFlags.Number);
4355
+ const stringIndex = indexInfos.find((i) => i.keyType.flags & ts7.TypeFlags.String);
4356
+ const numberIndex = indexInfos.find((i) => i.keyType.flags & ts7.TypeFlags.Number);
3993
4357
  if (properties.length === 0 && !stringIndex && !numberIndex) {
3994
4358
  return { type: checker.typeToString(type) };
3995
4359
  }
@@ -3997,8 +4361,8 @@ class TypeRegistry {
3997
4361
  const required = [];
3998
4362
  const limit = ctx.maxProperties;
3999
4363
  const isArrayLike = checker.isArrayType(type) || checker.isTupleType(type) || type.symbol?.getName() === "Array" && isLibFile(type.symbol?.getDeclarations()?.[0]?.getSourceFile()?.fileName ?? "");
4000
- const isStringLike = type.flags & ts6.TypeFlags.StringLike;
4001
- const isNumberLike = type.flags & ts6.TypeFlags.NumberLike;
4364
+ const isStringLike = type.flags & ts7.TypeFlags.StringLike;
4365
+ const isNumberLike = type.flags & ts7.TypeFlags.NumberLike;
4002
4366
  const included = properties.filter((prop) => {
4003
4367
  const propName = prop.getName();
4004
4368
  if (propName.startsWith("__@"))
@@ -4018,9 +4382,9 @@ class TypeRegistry {
4018
4382
  for (const prop of included.slice(0, limit)) {
4019
4383
  const propName = prop.getName();
4020
4384
  const rawPropType = checker.getTypeOfSymbol(prop);
4021
- const propType = prop.flags & ts6.SymbolFlags.Optional ? stripUndefinedFromType(rawPropType, checker) : rawPropType;
4385
+ const propType = prop.flags & ts7.SymbolFlags.Optional ? stripUndefinedFromType(rawPropType, checker) : rawPropType;
4022
4386
  this.registerType(propType, ctx);
4023
- let propSchema = buildSchema(propType, checker, ctx);
4387
+ let propSchema = buildSchema(propType, checker, ctx, declaredTypeNode(prop.valueDeclaration ?? prop.getDeclarations()?.[0]));
4024
4388
  const docComment = prop.getDocumentationComment(checker);
4025
4389
  if (docComment.length > 0) {
4026
4390
  const description = docComment.map((c) => c.text).join(`
@@ -4035,7 +4399,7 @@ class TypeRegistry {
4035
4399
  }
4036
4400
  propSchema = decoratePropertySchema(propSchema, prop, propType, checker);
4037
4401
  props[propName] = propSchema;
4038
- if (!(prop.flags & ts6.SymbolFlags.Optional)) {
4402
+ if (!(prop.flags & ts7.SymbolFlags.Optional)) {
4039
4403
  required.push(propName);
4040
4404
  }
4041
4405
  }
@@ -4071,7 +4435,10 @@ function createContext(program, sourceFile, options = {}) {
4071
4435
  typeIds: new Map,
4072
4436
  declIds: new Map,
4073
4437
  idOwner: new Map,
4074
- workspacePackages: options.workspacePackages ?? new Map
4438
+ workspacePackages: options.workspacePackages ?? new Map,
4439
+ schemaOps: 0,
4440
+ maxSchemaOps: 20000,
4441
+ budgetExceeded: false
4075
4442
  };
4076
4443
  }
4077
4444
  function getInheritedMembers(classType, ownMemberNames, ctx, isStatic = false) {
@@ -4140,15 +4507,15 @@ function serializeInheritedMember(symbol, inheritedFrom, ctx, isStatic) {
4140
4507
  const type = checker.getTypeOfSymbol(symbol);
4141
4508
  registerReferencedTypes(type, ctx);
4142
4509
  let visibility;
4143
- if (decl && ts7.canHaveModifiers(decl)) {
4144
- const modifiers = ts7.getModifiers(decl);
4510
+ if (decl && ts8.canHaveModifiers(decl)) {
4511
+ const modifiers = ts8.getModifiers(decl);
4145
4512
  if (modifiers) {
4146
4513
  for (const mod of modifiers) {
4147
- if (mod.kind === ts7.SyntaxKind.PrivateKeyword)
4514
+ if (mod.kind === ts8.SyntaxKind.PrivateKeyword)
4148
4515
  visibility = "private";
4149
- else if (mod.kind === ts7.SyntaxKind.ProtectedKeyword)
4516
+ else if (mod.kind === ts8.SyntaxKind.ProtectedKeyword)
4150
4517
  visibility = "protected";
4151
- else if (mod.kind === ts7.SyntaxKind.PublicKeyword)
4518
+ else if (mod.kind === ts8.SyntaxKind.PublicKeyword)
4152
4519
  visibility = "public";
4153
4520
  }
4154
4521
  }
@@ -4160,17 +4527,17 @@ function serializeInheritedMember(symbol, inheritedFrom, ctx, isStatic) {
4160
4527
  const callSigs = type.getCallSignatures();
4161
4528
  if (callSigs.length > 0) {
4162
4529
  kind = "method";
4163
- } else if (ts7.isGetAccessorDeclaration(decl)) {
4530
+ } else if (ts8.isGetAccessorDeclaration(decl)) {
4164
4531
  kind = "getter";
4165
- } else if (ts7.isSetAccessorDeclaration(decl)) {
4532
+ } else if (ts8.isSetAccessorDeclaration(decl)) {
4166
4533
  kind = "setter";
4167
4534
  }
4168
4535
  const flags = {};
4169
4536
  if (isStatic)
4170
4537
  flags.static = true;
4171
- if (decl && ts7.canHaveModifiers(decl)) {
4172
- const modifiers = ts7.getModifiers(decl);
4173
- if (modifiers?.some((m) => m.kind === ts7.SyntaxKind.ReadonlyKeyword)) {
4538
+ if (decl && ts8.canHaveModifiers(decl)) {
4539
+ const modifiers = ts8.getModifiers(decl);
4540
+ if (modifiers?.some((m) => m.kind === ts8.SyntaxKind.ReadonlyKeyword)) {
4174
4541
  flags.readonly = true;
4175
4542
  }
4176
4543
  }
@@ -4184,7 +4551,7 @@ function serializeInheritedMember(symbol, inheritedFrom, ctx, isStatic) {
4184
4551
  return {
4185
4552
  parameters: params.length > 0 ? params : undefined,
4186
4553
  returns: {
4187
- schema: buildSchema(returnType, checker, ctx)
4554
+ schema: buildSchema(returnType, checker, ctx, typeNodeOfSignature(sig))
4188
4555
  },
4189
4556
  ...sigDoc.description ? { description: sigDoc.description } : {},
4190
4557
  ...sigDoc.tags.length > 0 ? { tags: sigDoc.tags } : {},
@@ -4200,7 +4567,7 @@ function serializeInheritedMember(symbol, inheritedFrom, ctx, isStatic) {
4200
4567
  description,
4201
4568
  tags: tags.length > 0 ? tags : undefined,
4202
4569
  visibility,
4203
- schema: kind !== "method" ? buildSchema(type, checker, ctx) : decoratePropertySchema({ "x-ts-function": true }, symbol, type, checker),
4570
+ schema: kind !== "method" ? buildSchema(type, checker, ctx, declaredTypeNode(decl)) : decoratePropertySchema({ "x-ts-function": true }, symbol, type, checker),
4204
4571
  signatures,
4205
4572
  flags: Object.keys(flags).length > 0 ? flags : undefined,
4206
4573
  ...inlineTags ? { inlineTags } : {}
@@ -4223,7 +4590,7 @@ function buildSignatures(callSignatures, checker, ctx) {
4223
4590
  const sigTypeParams = extractTypeParametersFromSignature(sig, checker);
4224
4591
  return {
4225
4592
  parameters: params.length > 0 ? params : undefined,
4226
- returns: { schema: buildSchema(returnType, checker, ctx) },
4593
+ returns: { schema: buildSchema(returnType, checker, ctx, typeNodeOfSignature(sig)) },
4227
4594
  ...sigDoc.description ? { description: sigDoc.description } : {},
4228
4595
  ...sigDoc.tags.length > 0 ? { tags: sigDoc.tags } : {},
4229
4596
  ...sigDoc.examples.length > 0 ? { examples: sigDoc.examples } : {},
@@ -4250,11 +4617,11 @@ function serializeClass(node, ctx) {
4250
4617
  const memberName = getMemberName(member);
4251
4618
  if (memberName?.startsWith("#"))
4252
4619
  continue;
4253
- if (ts8.isPropertyDeclaration(member)) {
4620
+ if (ts9.isPropertyDeclaration(member)) {
4254
4621
  const propMember = serializeProperty(member, ctx);
4255
4622
  if (propMember)
4256
4623
  members.push(propMember);
4257
- } else if (ts8.isMethodDeclaration(member)) {
4624
+ } else if (ts9.isMethodDeclaration(member)) {
4258
4625
  const methodMember = serializeMethod(member, ctx);
4259
4626
  if (methodMember?.name) {
4260
4627
  if (!methodsByName.has(methodMember.name)) {
@@ -4271,11 +4638,11 @@ function serializeClass(node, ctx) {
4271
4638
  }
4272
4639
  }
4273
4640
  }
4274
- } else if (ts8.isConstructorDeclaration(member)) {
4641
+ } else if (ts9.isConstructorDeclaration(member)) {
4275
4642
  const ctorSig = serializeConstructor(member, ctx);
4276
4643
  if (ctorSig)
4277
4644
  signatures.push(ctorSig);
4278
- } else if (ts8.isGetAccessorDeclaration(member) || ts8.isSetAccessorDeclaration(member)) {
4645
+ } else if (ts9.isGetAccessorDeclaration(member) || ts9.isSetAccessorDeclaration(member)) {
4279
4646
  const accessorMember = serializeAccessor(member, ctx);
4280
4647
  if (accessorMember)
4281
4648
  members.push(accessorMember);
@@ -4299,8 +4666,8 @@ function serializeClass(node, ctx) {
4299
4666
  const extendsClause = getExtendsClause(node, checker);
4300
4667
  const implementsClause = getImplementsClause(node, checker);
4301
4668
  const classFlags = {};
4302
- const classModifiers = ts8.getModifiers(node);
4303
- if (classModifiers?.some((m) => m.kind === ts8.SyntaxKind.AbstractKeyword)) {
4669
+ const classModifiers = ts9.getModifiers(node);
4670
+ if (classModifiers?.some((m) => m.kind === ts9.SyntaxKind.AbstractKeyword)) {
4304
4671
  classFlags.abstract = true;
4305
4672
  }
4306
4673
  return {
@@ -4322,37 +4689,37 @@ function serializeClass(node, ctx) {
4322
4689
  };
4323
4690
  }
4324
4691
  function getMemberName(member) {
4325
- if (ts8.isConstructorDeclaration(member))
4692
+ if (ts9.isConstructorDeclaration(member))
4326
4693
  return "constructor";
4327
4694
  if (!member.name)
4328
4695
  return;
4329
- if (ts8.isIdentifier(member.name))
4696
+ if (ts9.isIdentifier(member.name))
4330
4697
  return member.name.text;
4331
- if (ts8.isPrivateIdentifier(member.name))
4698
+ if (ts9.isPrivateIdentifier(member.name))
4332
4699
  return member.name.text;
4333
4700
  return member.name.getText();
4334
4701
  }
4335
4702
  function getVisibility(member) {
4336
- const modifiers = ts8.canHaveModifiers(member) ? ts8.getModifiers(member) : undefined;
4703
+ const modifiers = ts9.canHaveModifiers(member) ? ts9.getModifiers(member) : undefined;
4337
4704
  if (!modifiers)
4338
4705
  return;
4339
4706
  for (const mod of modifiers) {
4340
- if (mod.kind === ts8.SyntaxKind.PrivateKeyword)
4707
+ if (mod.kind === ts9.SyntaxKind.PrivateKeyword)
4341
4708
  return "private";
4342
- if (mod.kind === ts8.SyntaxKind.ProtectedKeyword)
4709
+ if (mod.kind === ts9.SyntaxKind.ProtectedKeyword)
4343
4710
  return "protected";
4344
- if (mod.kind === ts8.SyntaxKind.PublicKeyword)
4711
+ if (mod.kind === ts9.SyntaxKind.PublicKeyword)
4345
4712
  return "public";
4346
4713
  }
4347
4714
  return;
4348
4715
  }
4349
4716
  function isStatic(member) {
4350
- const modifiers = ts8.canHaveModifiers(member) ? ts8.getModifiers(member) : undefined;
4351
- return modifiers?.some((m) => m.kind === ts8.SyntaxKind.StaticKeyword) ?? false;
4717
+ const modifiers = ts9.canHaveModifiers(member) ? ts9.getModifiers(member) : undefined;
4718
+ return modifiers?.some((m) => m.kind === ts9.SyntaxKind.StaticKeyword) ?? false;
4352
4719
  }
4353
4720
  function isReadonly(member) {
4354
- const modifiers = ts8.canHaveModifiers(member) ? ts8.getModifiers(member) : undefined;
4355
- return modifiers?.some((m) => m.kind === ts8.SyntaxKind.ReadonlyKeyword) ?? false;
4721
+ const modifiers = ts9.canHaveModifiers(member) ? ts9.getModifiers(member) : undefined;
4722
+ return modifiers?.some((m) => m.kind === ts9.SyntaxKind.ReadonlyKeyword) ?? false;
4356
4723
  }
4357
4724
  function serializeProperty(node, ctx) {
4358
4725
  const { typeChecker: checker } = ctx;
@@ -4367,7 +4734,7 @@ function serializeProperty(node, ctx) {
4367
4734
  const rawType = checker.getTypeAtLocation(node);
4368
4735
  const type = node.questionToken ? stripUndefinedFromType(rawType, checker) : rawType;
4369
4736
  registerReferencedTypes(type, ctx);
4370
- let schema = buildSchema(type, checker, ctx);
4737
+ let schema = buildSchema(type, checker, ctx, node.type);
4371
4738
  const flags = {};
4372
4739
  if (isStatic(node))
4373
4740
  flags.static = true;
@@ -4411,11 +4778,11 @@ function serializeMethod(node, ctx) {
4411
4778
  if (node.asteriskToken)
4412
4779
  flags.generator = true;
4413
4780
  flags.methodSyntax = true;
4414
- const modifiers = ts8.getModifiers(node);
4415
- if (modifiers?.some((m) => m.kind === ts8.SyntaxKind.AsyncKeyword)) {
4781
+ const modifiers = ts9.getModifiers(node);
4782
+ if (modifiers?.some((m) => m.kind === ts9.SyntaxKind.AsyncKeyword)) {
4416
4783
  flags.async = true;
4417
4784
  }
4418
- if (modifiers?.some((m) => m.kind === ts8.SyntaxKind.AbstractKeyword)) {
4785
+ if (modifiers?.some((m) => m.kind === ts9.SyntaxKind.AbstractKeyword)) {
4419
4786
  flags.abstract = true;
4420
4787
  }
4421
4788
  const symbol = checker.getSymbolAtLocation(node.name ?? node);
@@ -4454,7 +4821,7 @@ function serializeConstructorSignature(node, sig, ctx) {
4454
4821
  }
4455
4822
  function serializeInheritedConstructors(node, ctx) {
4456
4823
  const { typeChecker: checker } = ctx;
4457
- const hasExtends = node.heritageClauses?.some((c) => c.token === ts8.SyntaxKind.ExtendsKeyword);
4824
+ const hasExtends = node.heritageClauses?.some((c) => c.token === ts9.SyntaxKind.ExtendsKeyword);
4458
4825
  if (!hasExtends)
4459
4826
  return [];
4460
4827
  const symbol = checker.getSymbolAtLocation(node.name ?? node);
@@ -4463,11 +4830,11 @@ function serializeInheritedConstructors(node, ctx) {
4463
4830
  const staticType = checker.getTypeOfSymbolAtLocation(symbol, node);
4464
4831
  const ctorSigs = staticType.getConstructSignatures().filter((sig) => {
4465
4832
  const decl = sig.getDeclaration();
4466
- return decl !== undefined && ts8.isConstructorDeclaration(decl);
4833
+ return decl !== undefined && ts9.isConstructorDeclaration(decl);
4467
4834
  });
4468
4835
  return ctorSigs.map((sig, index) => {
4469
4836
  const decl = sig.getDeclaration();
4470
- const owner = ts8.isClassLike(decl.parent) ? decl.parent.name?.text : undefined;
4837
+ const owner = ts9.isClassLike(decl.parent) ? decl.parent.name?.text : undefined;
4471
4838
  return {
4472
4839
  ...serializeConstructorSignature(decl, sig, ctx),
4473
4840
  ...owner ? { inheritedFrom: owner } : {},
@@ -4486,14 +4853,14 @@ function serializeAccessor(node, ctx) {
4486
4853
  return null;
4487
4854
  }
4488
4855
  const type = checker.getTypeAtLocation(node);
4489
- const schema = buildSchema(type, checker, ctx);
4856
+ const schema = buildSchema(type, checker, ctx, ts9.isGetAccessorDeclaration(node) ? node.type : undefined);
4490
4857
  registerReferencedTypes(type, ctx);
4491
- const kind = ts8.isGetAccessorDeclaration(node) ? "getter" : "setter";
4858
+ const kind = ts9.isGetAccessorDeclaration(node) ? "getter" : "setter";
4492
4859
  const flags = {};
4493
4860
  if (isStatic(node))
4494
4861
  flags.static = true;
4495
4862
  let signatures;
4496
- if (ts8.isSetAccessorDeclaration(node) && node.parameters.length > 0) {
4863
+ if (ts9.isSetAccessorDeclaration(node) && node.parameters.length > 0) {
4497
4864
  const param = node.parameters[0];
4498
4865
  const paramName = param.name.getText();
4499
4866
  const paramType = checker.getTypeAtLocation(param);
@@ -4503,7 +4870,7 @@ function serializeAccessor(node, ctx) {
4503
4870
  parameters: [
4504
4871
  {
4505
4872
  name: paramName,
4506
- schema: buildSchema(paramType, checker, ctx),
4873
+ schema: buildSchema(paramType, checker, ctx, param.type),
4507
4874
  required: true
4508
4875
  }
4509
4876
  ]
@@ -4526,7 +4893,7 @@ function getExtendsClause(node, checker) {
4526
4893
  if (!node.heritageClauses)
4527
4894
  return;
4528
4895
  for (const clause of node.heritageClauses) {
4529
- if (clause.token === ts8.SyntaxKind.ExtendsKeyword) {
4896
+ if (clause.token === ts9.SyntaxKind.ExtendsKeyword) {
4530
4897
  const expr = clause.types[0];
4531
4898
  if (expr) {
4532
4899
  const type = checker.getTypeAtLocation(expr);
@@ -4541,7 +4908,7 @@ function getImplementsClause(node, checker) {
4541
4908
  if (!node.heritageClauses)
4542
4909
  return;
4543
4910
  for (const clause of node.heritageClauses) {
4544
- if (clause.token === ts8.SyntaxKind.ImplementsKeyword) {
4911
+ if (clause.token === ts9.SyntaxKind.ImplementsKeyword) {
4545
4912
  return clause.types.map((expr) => {
4546
4913
  const type = checker.getTypeAtLocation(expr);
4547
4914
  const symbol = type.getSymbol();
@@ -4604,16 +4971,16 @@ function serializeEnum(node, ctx) {
4604
4971
  }
4605
4972
 
4606
4973
  // src/serializers/functions.ts
4607
- import ts9 from "typescript";
4974
+ import ts10 from "typescript";
4608
4975
  function buildReturnSchema(sig, ctx) {
4609
4976
  const returnType = ctx.typeChecker.getReturnTypeOfSignature(sig);
4610
4977
  registerReferencedTypes(returnType, ctx);
4611
- const schema = buildSchema(returnType, ctx.typeChecker, ctx);
4978
+ const schema = buildSchema(returnType, ctx.typeChecker, ctx, typeNodeOfSignature(sig));
4612
4979
  const declaration = sig.getDeclaration();
4613
- if (declaration && ts9.isFunctionLike(declaration) && declaration.type) {
4980
+ if (declaration && ts10.isFunctionLike(declaration) && declaration.type) {
4614
4981
  const returnTypeNode = declaration.type;
4615
- if (ts9.isTypePredicateNode(returnTypeNode)) {
4616
- const parameterName = ts9.isIdentifier(returnTypeNode.parameterName) ? returnTypeNode.parameterName.text : returnTypeNode.parameterName.getText();
4982
+ if (ts10.isTypePredicateNode(returnTypeNode)) {
4983
+ const parameterName = ts10.isIdentifier(returnTypeNode.parameterName) ? returnTypeNode.parameterName.text : returnTypeNode.parameterName.getText();
4617
4984
  let predicateTypeSchema = { type: "unknown" };
4618
4985
  if (returnTypeNode.type) {
4619
4986
  const predicateType = ctx.typeChecker.getTypeAtLocation(returnTypeNode.type);
@@ -4633,21 +5000,82 @@ function buildReturnSchema(sig, ctx) {
4633
5000
  }
4634
5001
  return { schema };
4635
5002
  }
4636
- function serializeFunctionExport(node, ctx, nameOverride) {
4637
- const symbol = ctx.typeChecker.getSymbolAtLocation(node.name ?? node);
4638
- const name = nameOverride ?? symbol?.getName() ?? node.name?.getText();
4639
- if (!name)
4640
- return null;
4641
- const { description, tags, examples, source, deprecated, deprecationReason, inlineTags } = extractExportMetadata(node, symbol, ctx.typeChecker);
4642
- const typeParameters = extractTypeParameters(node, ctx.typeChecker);
5003
+ function functionSignatureDecls(node, ctx) {
5004
+ if (!ts10.isFunctionDeclaration(node) || !node.name)
5005
+ return [node];
5006
+ const symbol = ctx.typeChecker.getSymbolAtLocation(node.name);
5007
+ const fns = (symbol?.declarations ?? []).filter(ts10.isFunctionDeclaration);
5008
+ const overloads = fns.filter((d) => !d.body);
5009
+ return overloads.length > 0 ? overloads : [node];
5010
+ }
5011
+ function signatureDeclDefers(decl, ctx) {
5012
+ const checker = ctx.typeChecker;
5013
+ if (decl.typeParameters) {
5014
+ for (const tp of decl.typeParameters) {
5015
+ if (typeNodeDefersExpansion(tp.constraint, checker, ctx.program))
5016
+ return true;
5017
+ if (typeNodeDefersExpansion(tp.default, checker, ctx.program))
5018
+ return true;
5019
+ }
5020
+ }
5021
+ for (const p of decl.parameters) {
5022
+ if (typeNodeDefersExpansion(p.type, checker, ctx.program))
5023
+ return true;
5024
+ }
5025
+ return typeNodeDefersExpansion(decl.type, checker, ctx.program);
5026
+ }
5027
+ function anySignatureDefers(node, ctx) {
5028
+ return functionSignatureDecls(node, ctx).some((d) => signatureDeclDefers(d, ctx));
5029
+ }
5030
+ function schemaFromTypeNode(node, ctx) {
5031
+ if (!node)
5032
+ return { type: "unknown" };
5033
+ if (typeNodeDefersExpansion(node, ctx.typeChecker, ctx.program)) {
5034
+ return buildSchemaFromTypeNode(node, ctx.typeChecker, ctx);
5035
+ }
5036
+ return buildSchema(ctx.typeChecker.getTypeFromTypeNode(node), ctx.typeChecker, ctx, node);
5037
+ }
5038
+ function parametersFromAst(decl, ctx) {
5039
+ const jsdocTags = ts10.getJSDocTags(decl);
5040
+ return decl.parameters.map((p) => {
5041
+ const name = ts10.isIdentifier(p.name) ? p.name.text : p.name.getText();
5042
+ const isOptional = !!p.questionToken || !!p.initializer;
5043
+ const param = {
5044
+ name,
5045
+ schema: schemaFromTypeNode(p.type, ctx),
5046
+ required: !isOptional
5047
+ };
5048
+ const description = getParamDescription(name, jsdocTags);
5049
+ if (description)
5050
+ param.description = description;
5051
+ return param;
5052
+ });
5053
+ }
5054
+ function signaturesFromAst(node, ctx) {
5055
+ const decls = functionSignatureDecls(node, ctx);
5056
+ return decls.map((decl, index) => {
5057
+ const sigDoc = getJSDocComment(decl);
5058
+ const sigTypeParams = ts10.isFunctionDeclaration(decl) || ts10.isArrowFunction(decl) || ts10.isFunctionExpression(decl) ? extractTypeParameters(decl, ctx.typeChecker) : undefined;
5059
+ const returns = { schema: schemaFromTypeNode(decl.type, ctx) };
5060
+ return {
5061
+ parameters: parametersFromAst(decl, ctx),
5062
+ returns,
5063
+ ...sigDoc.description ? { description: sigDoc.description } : {},
5064
+ ...sigDoc.tags.length > 0 ? { tags: sigDoc.tags } : {},
5065
+ ...sigDoc.examples.length > 0 ? { examples: sigDoc.examples } : {},
5066
+ ...sigTypeParams ? { typeParameters: sigTypeParams } : {},
5067
+ ...decls.length > 1 ? { overloadIndex: index } : {}
5068
+ };
5069
+ });
5070
+ }
5071
+ function signaturesFromChecker(node, ctx) {
4643
5072
  const type = ctx.typeChecker.getTypeAtLocation(node);
4644
5073
  const callSignatures = type.getCallSignatures();
4645
- const signatures = callSignatures.map((sig, index) => {
4646
- const params = extractParameters(sig, ctx);
5074
+ return callSignatures.map((sig, index) => {
4647
5075
  const sigDoc = getJSDocForSignature(sig, ctx.typeChecker);
4648
5076
  const sigTypeParams = extractTypeParametersFromSignature(sig, ctx.typeChecker);
4649
5077
  return {
4650
- parameters: params,
5078
+ parameters: extractParameters(sig, ctx),
4651
5079
  returns: buildReturnSchema(sig, ctx),
4652
5080
  ...sigDoc.description ? { description: sigDoc.description } : {},
4653
5081
  ...sigDoc.tags.length > 0 ? { tags: sigDoc.tags } : {},
@@ -4656,9 +5084,18 @@ function serializeFunctionExport(node, ctx, nameOverride) {
4656
5084
  ...callSignatures.length > 1 ? { overloadIndex: index } : {}
4657
5085
  };
4658
5086
  });
5087
+ }
5088
+ function serializeFunctionExport(node, ctx, nameOverride) {
5089
+ const symbol = ctx.typeChecker.getSymbolAtLocation(node.name ?? node);
5090
+ const name = nameOverride ?? symbol?.getName() ?? node.name?.getText();
5091
+ if (!name)
5092
+ return null;
5093
+ const { description, tags, examples, source, deprecated, deprecationReason, inlineTags } = extractExportMetadata(node, symbol, ctx.typeChecker);
5094
+ const typeParameters = extractTypeParameters(node, ctx.typeChecker);
5095
+ const signatures = anySignatureDefers(node, ctx) ? signaturesFromAst(node, ctx) : signaturesFromChecker(node, ctx);
4659
5096
  const flags = {};
4660
- const modifiers = ts9.getModifiers(node);
4661
- if (modifiers?.some((m) => m.kind === ts9.SyntaxKind.AsyncKeyword)) {
5097
+ const modifiers = ts10.getModifiers(node);
5098
+ if (modifiers?.some((m) => m.kind === ts10.SyntaxKind.AsyncKeyword)) {
4662
5099
  flags.async = true;
4663
5100
  }
4664
5101
  if (node.asteriskToken) {
@@ -4681,7 +5118,7 @@ function serializeFunctionExport(node, ctx, nameOverride) {
4681
5118
  }
4682
5119
 
4683
5120
  // src/serializers/interfaces.ts
4684
- import ts10 from "typescript";
5121
+ import ts11 from "typescript";
4685
5122
  function serializeInterface(node, ctx) {
4686
5123
  const { typeChecker: checker } = ctx;
4687
5124
  const symbol = checker.getSymbolAtLocation(node.name ?? node);
@@ -4694,11 +5131,11 @@ function serializeInterface(node, ctx) {
4694
5131
  const methodsByName = new Map;
4695
5132
  let callSignatureMember = null;
4696
5133
  for (const member of node.members) {
4697
- if (ts10.isPropertySignature(member)) {
5134
+ if (ts11.isPropertySignature(member)) {
4698
5135
  const propMember = serializePropertySignature(member, ctx);
4699
5136
  if (propMember)
4700
5137
  members.push(propMember);
4701
- } else if (ts10.isMethodSignature(member)) {
5138
+ } else if (ts11.isMethodSignature(member)) {
4702
5139
  const methodMember = serializeMethodSignature(member, ctx);
4703
5140
  if (methodMember?.name && methodMember.signatures) {
4704
5141
  const existing = methodsByName.get(methodMember.name);
@@ -4719,7 +5156,7 @@ function serializeInterface(node, ctx) {
4719
5156
  methodsByName.set(methodMember.name, methodMember);
4720
5157
  }
4721
5158
  }
4722
- } else if (ts10.isCallSignatureDeclaration(member)) {
5159
+ } else if (ts11.isCallSignatureDeclaration(member)) {
4723
5160
  const callSig = serializeCallSignature(member, ctx);
4724
5161
  if (callSig?.signatures) {
4725
5162
  if (callSignatureMember?.signatures) {
@@ -4742,7 +5179,7 @@ function serializeInterface(node, ctx) {
4742
5179
  callSignatureMember = callSig;
4743
5180
  }
4744
5181
  }
4745
- } else if (ts10.isIndexSignatureDeclaration(member)) {
5182
+ } else if (ts11.isIndexSignatureDeclaration(member)) {
4746
5183
  const indexMember = serializeIndexSignature(member, ctx);
4747
5184
  if (indexMember)
4748
5185
  members.push(indexMember);
@@ -4776,12 +5213,12 @@ function serializePropertySignature(node, ctx) {
4776
5213
  const { description, tags, inlineTags } = getJSDocComment(node);
4777
5214
  const rawType = checker.getTypeAtLocation(node);
4778
5215
  const type = node.questionToken ? stripUndefinedFromType(rawType, checker) : rawType;
4779
- let schema = buildSchema(type, checker, ctx);
5216
+ let schema = buildSchema(type, checker, ctx, node.type);
4780
5217
  registerReferencedTypes(type, ctx);
4781
5218
  const flags = {};
4782
5219
  if (node.questionToken)
4783
5220
  flags.optional = true;
4784
- if (node.modifiers?.some((m) => m.kind === ts10.SyntaxKind.ReadonlyKeyword)) {
5221
+ if (node.modifiers?.some((m) => m.kind === ts11.SyntaxKind.ReadonlyKeyword)) {
4785
5222
  flags.readonly = true;
4786
5223
  }
4787
5224
  const symbol = checker.getSymbolAtLocation(node.name);
@@ -4845,7 +5282,7 @@ function serializeCallSignature(node, ctx) {
4845
5282
  {
4846
5283
  parameters: params.length > 0 ? params : undefined,
4847
5284
  returns: {
4848
- schema: buildSchema(returnType, checker, ctx)
5285
+ schema: buildSchema(returnType, checker, ctx, node.type)
4849
5286
  }
4850
5287
  }
4851
5288
  ]
@@ -4855,7 +5292,7 @@ function serializeIndexSignature(node, ctx) {
4855
5292
  const { typeChecker: checker } = ctx;
4856
5293
  const { description, tags, inlineTags } = getJSDocComment(node);
4857
5294
  const valueType = node.type ? checker.getTypeAtLocation(node.type) : checker.getAnyType();
4858
- const valueSchema = buildSchema(valueType, checker, ctx);
5295
+ const valueSchema = buildSchema(valueType, checker, ctx, node.type);
4859
5296
  registerReferencedTypes(valueType, ctx);
4860
5297
  const keyParam = node.parameters[0];
4861
5298
  const keyType = keyParam?.type ? checker.getTypeAtLocation(keyParam.type) : checker.getStringType();
@@ -4873,7 +5310,7 @@ function getInterfaceExtends(node, checker) {
4873
5310
  if (!node.heritageClauses)
4874
5311
  return;
4875
5312
  for (const clause of node.heritageClauses) {
4876
- if (clause.token === ts10.SyntaxKind.ExtendsKeyword && clause.types.length > 0) {
5313
+ if (clause.token === ts11.SyntaxKind.ExtendsKeyword && clause.types.length > 0) {
4877
5314
  const names = clause.types.map((expr) => {
4878
5315
  const type = checker.getTypeAtLocation(expr);
4879
5316
  return type.getSymbol()?.getName() ?? expr.expression.getText();
@@ -4885,7 +5322,7 @@ function getInterfaceExtends(node, checker) {
4885
5322
  }
4886
5323
 
4887
5324
  // src/serializers/type-aliases.ts
4888
- import ts11 from "typescript";
5325
+ import ts12 from "typescript";
4889
5326
  function buildIntersectionSchemaFromNode(node, ctx) {
4890
5327
  const types = node.types;
4891
5328
  const schemas = [];
@@ -4913,7 +5350,7 @@ function serializeTypeAlias(node, ctx) {
4913
5350
  registerReferencedTypes(type, ctx);
4914
5351
  let schema;
4915
5352
  let members;
4916
- if (ts11.isIntersectionTypeNode(node.type)) {
5353
+ if (ts12.isIntersectionTypeNode(node.type)) {
4917
5354
  schema = buildIntersectionSchemaFromNode(node.type, ctx);
4918
5355
  if (type.getProperties().length > 0 && type.getCallSignatures().length === 0) {
4919
5356
  members = serializeResolvedMembers(type, node, ctx);
@@ -4923,7 +5360,7 @@ function serializeTypeAlias(node, ctx) {
4923
5360
  if (type.getProperties().length > 0) {
4924
5361
  members = serializeResolvedMembers(type, node, ctx);
4925
5362
  }
4926
- } else if ((ts11.isMappedTypeNode(node.type) || ts11.isConditionalTypeNode(node.type)) && type.getProperties().length > 0 && type.getCallSignatures().length === 0 && !(type.flags & ts11.TypeFlags.Conditional) && !(type.flags & (ts11.TypeFlags.StringLike | ts11.TypeFlags.NumberLike))) {
5363
+ } else if ((ts12.isMappedTypeNode(node.type) || ts12.isConditionalTypeNode(node.type)) && type.getProperties().length > 0 && type.getCallSignatures().length === 0 && !(type.flags & ts12.TypeFlags.Conditional) && !(type.flags & (ts12.TypeFlags.StringLike | ts12.TypeFlags.NumberLike))) {
4927
5364
  schema = buildObjectSchema(type.getProperties(), ctx.typeChecker, ctx, type);
4928
5365
  members = serializeResolvedMembers(type, node, ctx);
4929
5366
  } else {
@@ -4933,7 +5370,7 @@ function serializeTypeAlias(node, ctx) {
4933
5370
  }
4934
5371
  }
4935
5372
  if (shouldEmitAliasTypeText(node.type) && typeof schema === "object" && schema !== null && !("x-ts-type" in schema)) {
4936
- const text = renderTypeText(type, ctx.typeChecker, node, ts11.TypeFormatFlags.InTypeAlias);
5373
+ const text = renderTypeText(type, ctx.typeChecker, node, ts12.TypeFormatFlags.InTypeAlias);
4937
5374
  if (!PRIMITIVES.has(text) && text !== name) {
4938
5375
  schema["x-ts-type"] = text;
4939
5376
  const declared = writtenTypeText(declaredTypeNode(node));
@@ -4959,12 +5396,12 @@ function serializeTypeAlias(node, ctx) {
4959
5396
  }
4960
5397
  function isObjectShapedAlias(type, ctx) {
4961
5398
  const { typeChecker: checker } = ctx;
4962
- if (!(type.flags & ts11.TypeFlags.Object))
5399
+ if (!(type.flags & ts12.TypeFlags.Object))
4963
5400
  return false;
4964
5401
  if (checker.isArrayType(type) || checker.isTupleType(type))
4965
5402
  return false;
4966
5403
  const objectFlags = type.objectFlags;
4967
- if (!(objectFlags & ts11.ObjectFlags.Mapped)) {
5404
+ if (!(objectFlags & ts12.ObjectFlags.Mapped)) {
4968
5405
  const targetSymbol = type.target?.getSymbol?.() ?? type.getSymbol();
4969
5406
  if (isBuiltinSymbol(targetSymbol))
4970
5407
  return false;
@@ -4972,19 +5409,19 @@ function isObjectShapedAlias(type, ctx) {
4972
5409
  return type.getProperties().length > 0 && type.getCallSignatures().length === 0;
4973
5410
  }
4974
5411
  function isInlineFunctionAlias(typeNode) {
4975
- return ts11.isFunctionTypeNode(typeNode) || ts11.isTypeLiteralNode(typeNode) && typeNode.members.some(ts11.isCallSignatureDeclaration);
5412
+ return ts12.isFunctionTypeNode(typeNode) || ts12.isTypeLiteralNode(typeNode) && typeNode.members.some(ts12.isCallSignatureDeclaration);
4976
5413
  }
4977
5414
  function buildConditionalArmDocs(typeNode, checker) {
4978
5415
  const docs = new Map;
4979
- if (!ts11.isMappedTypeNode(typeNode) || !typeNode.type)
5416
+ if (!ts12.isMappedTypeNode(typeNode) || !typeNode.type)
4980
5417
  return docs;
4981
5418
  const literalKeys = (extendsType) => {
4982
5419
  const keys = [];
4983
5420
  const visit = (n) => {
4984
- if (ts11.isUnionTypeNode(n)) {
5421
+ if (ts12.isUnionTypeNode(n)) {
4985
5422
  for (const member of n.types)
4986
5423
  visit(member);
4987
- } else if (ts11.isLiteralTypeNode(n) && ts11.isStringLiteral(n.literal)) {
5424
+ } else if (ts12.isLiteralTypeNode(n) && ts12.isStringLiteral(n.literal)) {
4988
5425
  keys.push(n.literal.text);
4989
5426
  }
4990
5427
  };
@@ -4992,12 +5429,12 @@ function buildConditionalArmDocs(typeNode, checker) {
4992
5429
  return keys;
4993
5430
  };
4994
5431
  const armDoc = (armType) => {
4995
- if (!ts11.isTypeReferenceNode(armType))
5432
+ if (!ts12.isTypeReferenceNode(armType))
4996
5433
  return;
4997
5434
  const symbol = checker.getSymbolAtLocation(armType.typeName);
4998
5435
  if (!symbol)
4999
5436
  return;
5000
- const target = symbol.flags & ts11.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
5437
+ const target = symbol.flags & ts12.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
5001
5438
  const { deprecated, reason } = isSymbolDeprecated(target);
5002
5439
  const targetDecl = target.getDeclarations()?.[0];
5003
5440
  const description = targetDecl ? getJSDocComment(targetDecl, target, checker).description : undefined;
@@ -5006,7 +5443,7 @@ function buildConditionalArmDocs(typeNode, checker) {
5006
5443
  return { deprecated, deprecationReason: reason, description };
5007
5444
  };
5008
5445
  let current = typeNode.type;
5009
- while (current && ts11.isConditionalTypeNode(current)) {
5446
+ while (current && ts12.isConditionalTypeNode(current)) {
5010
5447
  const doc = armDoc(current.trueType);
5011
5448
  if (doc) {
5012
5449
  for (const key of literalKeys(current.extendsType)) {
@@ -5025,10 +5462,10 @@ function serializeResolvedMembers(type, node, ctx) {
5025
5462
  for (const prop of type.getProperties()) {
5026
5463
  const decl = prop.getDeclarations()?.[0] ?? node;
5027
5464
  const rawPropType = checker.getTypeOfSymbolAtLocation(prop, decl);
5028
- const propType = prop.flags & ts11.SymbolFlags.Optional ? stripUndefinedFromType(rawPropType, checker) : rawPropType;
5465
+ const propType = prop.flags & ts12.SymbolFlags.Optional ? stripUndefinedFromType(rawPropType, checker) : rawPropType;
5029
5466
  registerReferencedTypes(propType, ctx);
5030
5467
  const callSigs = propType.getCallSignatures();
5031
- const isMethodDecl = ts11.isMethodSignature(decl) || ts11.isMethodDeclaration(decl) || ts11.isFunctionDeclaration(decl);
5468
+ const isMethodDecl = ts12.isMethodSignature(decl) || ts12.isMethodDeclaration(decl) || ts12.isFunctionDeclaration(decl);
5032
5469
  const kind = callSigs.length > 0 && isMethodDecl ? "method" : "property";
5033
5470
  let { description, tags } = getJSDocComment(decl, prop, checker);
5034
5471
  let { deprecated, reason: deprecationReason } = isSymbolDeprecated(prop);
@@ -5046,13 +5483,13 @@ function serializeResolvedMembers(type, node, ctx) {
5046
5483
  ({ deprecated, reason: deprecationReason } = isSymbolDeprecated(armAlias));
5047
5484
  }
5048
5485
  const flags = {};
5049
- if (prop.flags & ts11.SymbolFlags.Optional)
5486
+ if (prop.flags & ts12.SymbolFlags.Optional)
5050
5487
  flags.optional = true;
5051
5488
  if (isReadonlyPropertySymbol(prop))
5052
5489
  flags.readonly = true;
5053
- if (prop.flags & ts11.SymbolFlags.Method)
5490
+ if (prop.flags & ts12.SymbolFlags.Method)
5054
5491
  flags.methodSyntax = true;
5055
- const schema = kind === "property" ? decoratePropertySchema(buildSchema(propType, checker, ctx), prop, propType, checker) : decoratePropertySchema({ "x-ts-function": true }, prop, propType, checker);
5492
+ const schema = kind === "property" ? decoratePropertySchema(buildSchema(propType, checker, ctx, declaredTypeNode(prop.valueDeclaration ?? prop.getDeclarations()?.[0])), prop, propType, checker) : decoratePropertySchema({ "x-ts-function": true }, prop, propType, checker);
5056
5493
  const inlineTags = parseInlineTags(description);
5057
5494
  members.push({
5058
5495
  name: prop.getName(),
@@ -5070,13 +5507,13 @@ function serializeResolvedMembers(type, node, ctx) {
5070
5507
  }
5071
5508
 
5072
5509
  // src/schema/registry.ts
5073
- import ts12 from "typescript";
5510
+ import ts13 from "typescript";
5074
5511
  function isTypeReference(type) {
5075
- return !!(type.flags & ts12.TypeFlags.Object && type.objectFlags && type.objectFlags & ts12.ObjectFlags.Reference);
5512
+ return !!(type.flags & ts13.TypeFlags.Object && type.objectFlags && type.objectFlags & ts13.ObjectFlags.Reference);
5076
5513
  }
5077
5514
  function getNonNullableType(type) {
5078
5515
  if (type.isUnion()) {
5079
- const nonNullable = type.types.filter((t) => !(t.flags & ts12.TypeFlags.Undefined) && !(t.flags & ts12.TypeFlags.Null));
5516
+ const nonNullable = type.types.filter((t) => !(t.flags & ts13.TypeFlags.Undefined) && !(t.flags & ts13.TypeFlags.Null));
5080
5517
  if (nonNullable.length === 1) {
5081
5518
  return nonNullable[0];
5082
5519
  }
@@ -5244,7 +5681,7 @@ function serializeVariable(node, statement, ctx) {
5244
5681
  const schemaExtraction = extractSchemaType(type, ctx.typeChecker);
5245
5682
  const typeToSerialize = schemaExtraction?.outputType ?? type;
5246
5683
  registerReferencedTypes(typeToSerialize, ctx);
5247
- const schema = buildSchema(typeToSerialize, ctx.typeChecker, ctx);
5684
+ const schema = buildSchema(typeToSerialize, ctx.typeChecker, ctx, node.type);
5248
5685
  const flags = schemaExtraction ? {
5249
5686
  schemaLibrary: schemaExtraction.adapter.id,
5250
5687
  ...schemaExtraction.inputType && schemaExtraction.inputType !== schemaExtraction.outputType ? { hasTransform: true } : {}
@@ -5269,9 +5706,9 @@ import { JSON_SCHEMA_DRAFT } from "@openpkg-ts/spec";
5269
5706
  var TS_PRIMITIVE_NORMALIZATIONS = {
5270
5707
  void: () => ({ type: "null", "x-ts-type": "void" }),
5271
5708
  never: () => ({ not: {} }),
5272
- any: () => ({}),
5709
+ any: () => ({ "x-ts-type": "any" }),
5273
5710
  unknown: () => ({ "x-ts-type": "unknown" }),
5274
- undefined: () => ({ type: "null" }),
5711
+ undefined: () => ({ type: "null", "x-ts-type": "undefined" }),
5275
5712
  bigint: () => ({ type: "integer", "x-ts-type": "bigint" }),
5276
5713
  symbol: () => ({ type: "string", "x-ts-type": "symbol" })
5277
5714
  };
@@ -5832,7 +6269,7 @@ async function getExport(options) {
5832
6269
  ctx.exportedIds = exportedIds;
5833
6270
  try {
5834
6271
  const originalDecls = targetSymbol.declarations ?? [];
5835
- const isNamespaceExportDecl = originalDecls.some((d) => ts13.isNamespaceExport(d) || ts13.isNamespaceImport(d));
6272
+ const isNamespaceExportDecl = originalDecls.some((d) => ts14.isNamespaceExport(d) || ts14.isNamespaceImport(d));
5836
6273
  if (isNamespaceExportDecl) {
5837
6274
  const spec2 = serializeNamespaceForGet(targetSymbol, exportName, ctx);
5838
6275
  const types2 = ctx.typeRegistry.getAll().map((t) => normalizeType(t));
@@ -5842,7 +6279,7 @@ async function getExport(options) {
5842
6279
  errors
5843
6280
  };
5844
6281
  }
5845
- const { declaration, resolvedSymbol, isTypeOnly } = resolveExportTarget(targetSymbol, checker);
6282
+ const { declaration, resolvedSymbol: resolvedSymbol2, isTypeOnly } = resolveExportTarget2(targetSymbol, checker);
5846
6283
  if (!declaration) {
5847
6284
  const externalPackage = detectExternalPackage(targetSymbol, checker);
5848
6285
  if (externalPackage) {
@@ -5856,7 +6293,7 @@ async function getExport(options) {
5856
6293
  }
5857
6294
  return { export: null, types: [], errors: [`No declaration found for '${exportName}'`] };
5858
6295
  }
5859
- let spec = serializeDeclaration(declaration, targetSymbol, resolvedSymbol, exportName, ctx, isTypeOnly);
6296
+ let spec = serializeDeclaration(declaration, targetSymbol, resolvedSymbol2, exportName, ctx, isTypeOnly);
5860
6297
  if (!spec) {
5861
6298
  const externalPackage = detectExternalPackage(targetSymbol, checker);
5862
6299
  if (externalPackage) {
@@ -5878,47 +6315,47 @@ async function getExport(options) {
5878
6315
  return { export: null, types: [], errors };
5879
6316
  }
5880
6317
  }
5881
- function resolveExportTarget(symbol, checker) {
5882
- let resolvedSymbol = symbol;
6318
+ function resolveExportTarget2(symbol, checker) {
6319
+ let resolvedSymbol2 = symbol;
5883
6320
  let isTypeOnly = false;
5884
6321
  const declarations = symbol.declarations ?? [];
5885
6322
  for (const decl of declarations) {
5886
- if (ts13.isExportSpecifier(decl)) {
6323
+ if (ts14.isExportSpecifier(decl)) {
5887
6324
  if (decl.isTypeOnly)
5888
6325
  isTypeOnly = true;
5889
6326
  const exportDecl = decl.parent?.parent;
5890
- if (exportDecl && ts13.isExportDeclaration(exportDecl) && exportDecl.isTypeOnly) {
6327
+ if (exportDecl && ts14.isExportDeclaration(exportDecl) && exportDecl.isTypeOnly) {
5891
6328
  isTypeOnly = true;
5892
6329
  }
5893
6330
  }
5894
6331
  }
5895
- if (symbol.flags & ts13.SymbolFlags.Alias) {
6332
+ if (symbol.flags & ts14.SymbolFlags.Alias) {
5896
6333
  const aliased = checker.getAliasedSymbol(symbol);
5897
6334
  if (aliased && aliased !== symbol) {
5898
- resolvedSymbol = aliased;
6335
+ resolvedSymbol2 = aliased;
5899
6336
  }
5900
6337
  }
5901
- const targetDeclarations = resolvedSymbol.declarations ?? [];
5902
- const declaration = resolvedSymbol.valueDeclaration || targetDeclarations.find((d) => d.kind !== ts13.SyntaxKind.ExportSpecifier) || targetDeclarations[0];
5903
- return { declaration, resolvedSymbol, isTypeOnly };
6338
+ const targetDeclarations = resolvedSymbol2.declarations ?? [];
6339
+ const declaration = resolvedSymbol2.valueDeclaration || targetDeclarations.find((d) => d.kind !== ts14.SyntaxKind.ExportSpecifier) || targetDeclarations[0];
6340
+ return { declaration, resolvedSymbol: resolvedSymbol2, isTypeOnly };
5904
6341
  }
5905
6342
  function serializeDeclaration(declaration, _exportSymbol, _targetSymbol, exportName, ctx, isTypeOnly) {
5906
6343
  let result = null;
5907
- if (ts13.isFunctionDeclaration(declaration)) {
6344
+ if (ts14.isFunctionDeclaration(declaration)) {
5908
6345
  result = serializeFunctionExport(declaration, ctx);
5909
- } else if (ts13.isClassDeclaration(declaration)) {
6346
+ } else if (ts14.isClassDeclaration(declaration)) {
5910
6347
  result = serializeClass(declaration, ctx);
5911
- } else if (ts13.isInterfaceDeclaration(declaration)) {
6348
+ } else if (ts14.isInterfaceDeclaration(declaration)) {
5912
6349
  result = serializeInterface(declaration, ctx);
5913
- } else if (ts13.isTypeAliasDeclaration(declaration)) {
6350
+ } else if (ts14.isTypeAliasDeclaration(declaration)) {
5914
6351
  result = serializeTypeAlias(declaration, ctx);
5915
- } else if (ts13.isEnumDeclaration(declaration)) {
6352
+ } else if (ts14.isEnumDeclaration(declaration)) {
5916
6353
  result = serializeEnum(declaration, ctx);
5917
- } else if (ts13.isVariableDeclaration(declaration)) {
6354
+ } else if (ts14.isVariableDeclaration(declaration)) {
5918
6355
  const varStatement = declaration.parent?.parent;
5919
- if (varStatement && ts13.isVariableStatement(varStatement)) {
5920
- if (declaration.initializer && (ts13.isArrowFunction(declaration.initializer) || ts13.isFunctionExpression(declaration.initializer))) {
5921
- const varName = ts13.isIdentifier(declaration.name) ? declaration.name.text : declaration.name.getText();
6356
+ if (varStatement && ts14.isVariableStatement(varStatement)) {
6357
+ if (declaration.initializer && (ts14.isArrowFunction(declaration.initializer) || ts14.isFunctionExpression(declaration.initializer))) {
6358
+ const varName = ts14.isIdentifier(declaration.name) ? declaration.name.text : declaration.name.getText();
5922
6359
  result = serializeFunctionExport(declaration.initializer, ctx, varName);
5923
6360
  } else {
5924
6361
  const checker = ctx.program.getTypeChecker();
@@ -5932,7 +6369,7 @@ function serializeDeclaration(declaration, _exportSymbol, _targetSymbol, exportN
5932
6369
  }
5933
6370
  }
5934
6371
  }
5935
- } else if (ts13.isNamespaceExport(declaration) || ts13.isModuleDeclaration(declaration) || ts13.isNamespaceImport(declaration) || ts13.isSourceFile(declaration)) {
6372
+ } else if (ts14.isNamespaceExport(declaration) || ts14.isModuleDeclaration(declaration) || ts14.isNamespaceImport(declaration) || ts14.isSourceFile(declaration)) {
5936
6373
  result = serializeNamespaceForGet(_exportSymbol, exportName, ctx);
5937
6374
  }
5938
6375
  if (result) {
@@ -5948,7 +6385,7 @@ function serializeDeclaration(declaration, _exportSymbol, _targetSymbol, exportN
5948
6385
  function serializeNamespaceForGet(symbol, exportName, ctx) {
5949
6386
  const checker = ctx.program.getTypeChecker();
5950
6387
  let targetSymbol = symbol;
5951
- if (symbol.flags & ts13.SymbolFlags.Alias) {
6388
+ if (symbol.flags & ts14.SymbolFlags.Alias) {
5952
6389
  const aliased = checker.getAliasedSymbol(symbol);
5953
6390
  if (aliased && aliased !== symbol) {
5954
6391
  targetSymbol = aliased;
@@ -5978,7 +6415,7 @@ function serializeNamespaceForGet(symbol, exportName, ctx) {
5978
6415
  }
5979
6416
  function detectExternalPackage(symbol, checker) {
5980
6417
  let targetSymbol = symbol;
5981
- if (symbol.flags & ts13.SymbolFlags.Alias) {
6418
+ if (symbol.flags & ts14.SymbolFlags.Alias) {
5982
6419
  const aliased = checker.getAliasedSymbol(symbol);
5983
6420
  if (aliased && aliased !== symbol) {
5984
6421
  targetSymbol = aliased;
@@ -5990,9 +6427,9 @@ function detectExternalPackage(symbol, checker) {
5990
6427
  const pkg = sf && packageNameFromPath(sf.fileName);
5991
6428
  if (pkg)
5992
6429
  return pkg;
5993
- if (ts13.isExportSpecifier(decl)) {
6430
+ if (ts14.isExportSpecifier(decl)) {
5994
6431
  const exportDecl = decl.parent?.parent;
5995
- if (exportDecl && ts13.isExportDeclaration(exportDecl) && exportDecl.moduleSpecifier) {
6432
+ if (exportDecl && ts14.isExportDeclaration(exportDecl) && exportDecl.moduleSpecifier) {
5996
6433
  const moduleText = exportDecl.moduleSpecifier.text;
5997
6434
  if (!moduleText.startsWith(".") && !moduleText.startsWith("/")) {
5998
6435
  return moduleText;
@@ -6004,7 +6441,7 @@ function detectExternalPackage(symbol, checker) {
6004
6441
  }
6005
6442
  // src/primitives/list.ts
6006
6443
  import * as path6 from "node:path";
6007
- import ts14 from "typescript";
6444
+ import ts15 from "typescript";
6008
6445
  async function listExports(options) {
6009
6446
  const { entryFile, baseDir, content } = options;
6010
6447
  const errors = [];
@@ -6047,16 +6484,16 @@ async function listExports(options) {
6047
6484
  }
6048
6485
  function extractExportItem(symbol, checker, entryFile, entrySourceFile) {
6049
6486
  const name = symbol.getName();
6050
- const isReexport = !!(symbol.flags & ts14.SymbolFlags.Alias);
6487
+ const isReexport = !!(symbol.flags & ts15.SymbolFlags.Alias);
6051
6488
  let targetSymbol = symbol;
6052
- if (symbol.flags & ts14.SymbolFlags.Alias) {
6489
+ if (symbol.flags & ts15.SymbolFlags.Alias) {
6053
6490
  const aliased = checker.getAliasedSymbol(symbol);
6054
6491
  if (aliased && aliased !== symbol) {
6055
6492
  targetSymbol = aliased;
6056
6493
  }
6057
6494
  }
6058
6495
  const declarations = targetSymbol.declarations ?? [];
6059
- const declaration = targetSymbol.valueDeclaration || declarations.find((d) => d.kind !== ts14.SyntaxKind.ExportSpecifier) || declarations[0];
6496
+ const declaration = targetSymbol.valueDeclaration || declarations.find((d) => d.kind !== ts15.SyntaxKind.ExportSpecifier) || declarations[0];
6060
6497
  if (!declaration) {
6061
6498
  return {
6062
6499
  name,
@@ -6066,7 +6503,7 @@ function extractExportItem(symbol, checker, entryFile, entrySourceFile) {
6066
6503
  reexport: true
6067
6504
  };
6068
6505
  }
6069
- if (ts14.isSourceFile(declaration)) {
6506
+ if (ts15.isSourceFile(declaration)) {
6070
6507
  return {
6071
6508
  name,
6072
6509
  kind: "namespace",
@@ -6110,36 +6547,6 @@ import * as path10 from "node:path";
6110
6547
  import { SCHEMA_URL, SCHEMA_VERSION } from "@openpkg-ts/spec";
6111
6548
  import ts19 from "typescript";
6112
6549
 
6113
- // src/ast/resolve.ts
6114
- import ts15 from "typescript";
6115
- function isTypeOnlyExport(symbol) {
6116
- const declarations = symbol.declarations ?? [];
6117
- for (const decl of declarations) {
6118
- if (ts15.isExportSpecifier(decl)) {
6119
- if (decl.isTypeOnly)
6120
- return true;
6121
- const exportDecl = decl.parent?.parent;
6122
- if (exportDecl && ts15.isExportDeclaration(exportDecl) && exportDecl.isTypeOnly) {
6123
- return true;
6124
- }
6125
- }
6126
- }
6127
- return false;
6128
- }
6129
- function resolveExportTarget2(symbol, checker) {
6130
- let targetSymbol = symbol;
6131
- const isTypeOnly = isTypeOnlyExport(symbol);
6132
- if (symbol.flags & ts15.SymbolFlags.Alias) {
6133
- const aliasTarget = checker.getAliasedSymbol(symbol);
6134
- if (aliasTarget && aliasTarget !== symbol) {
6135
- targetSymbol = aliasTarget;
6136
- }
6137
- }
6138
- const declarations = targetSymbol.declarations ?? [];
6139
- const declaration = targetSymbol.valueDeclaration || declarations.find((decl) => decl.kind !== ts15.SyntaxKind.ExportSpecifier) || declarations[0];
6140
- return { declaration, targetSymbol, isTypeOnly };
6141
- }
6142
-
6143
6550
  // src/schema/standard-schema.ts
6144
6551
  import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
6145
6552
  import * as fs5 from "node:fs";
@@ -6770,16 +7177,16 @@ function extractExternalExport(exportName, resolvedModule, program, ctx, visited
6770
7177
  if (!targetExport) {
6771
7178
  return null;
6772
7179
  }
6773
- let resolvedSymbol = targetExport;
7180
+ let resolvedSymbol2 = targetExport;
6774
7181
  if (targetExport.flags & ts16.SymbolFlags.Alias) {
6775
7182
  const aliased = checker.getAliasedSymbol(targetExport);
6776
7183
  if (aliased && aliased !== targetExport) {
6777
- resolvedSymbol = aliased;
7184
+ resolvedSymbol2 = aliased;
6778
7185
  }
6779
7186
  }
6780
- const decl = (resolvedSymbol.declarations ?? [])[0];
7187
+ const decl = (resolvedSymbol2.declarations ?? [])[0];
6781
7188
  const kind = decl ? getExportKind(decl, checker.getTypeAtLocation(decl)) : "variable";
6782
- const docComment = resolvedSymbol.getDocumentationComment(checker);
7189
+ const docComment = resolvedSymbol2.getDocumentationComment(checker);
6783
7190
  const description = docComment.length > 0 ? docComment.map((c) => c.text).join(`
6784
7191
  `) : undefined;
6785
7192
  const specExport = {
@@ -6794,18 +7201,18 @@ function extractExternalExport(exportName, resolvedModule, program, ctx, visited
6794
7201
  }
6795
7202
  };
6796
7203
  if (kind === "function") {
6797
- const type = checker.getTypeOfSymbol(resolvedSymbol);
7204
+ const type = checker.getTypeOfSymbol(resolvedSymbol2);
6798
7205
  const callSignatures = type.getCallSignatures();
6799
7206
  if (callSignatures.length > 0) {
6800
7207
  specExport.signatures = buildSignatures(callSignatures, checker, ctx);
6801
7208
  }
6802
7209
  } else if (kind === "interface" || kind === "type" || kind === "class") {
6803
- const type = checker.getTypeOfSymbol(resolvedSymbol);
7210
+ const type = checker.getTypeOfSymbol(resolvedSymbol2);
6804
7211
  registerReferencedTypes(type, ctx);
6805
7212
  const schema = buildSchema(type, checker, ctx);
6806
7213
  specExport.schema = schema;
6807
7214
  } else if (kind === "variable") {
6808
- const type = checker.getTypeOfSymbol(resolvedSymbol);
7215
+ const type = checker.getTypeOfSymbol(resolvedSymbol2);
6809
7216
  registerReferencedTypes(type, ctx);
6810
7217
  const schema = buildSchema(type, checker, ctx);
6811
7218
  specExport.schema = schema;
@@ -6996,10 +7403,11 @@ function createExternalExpansionPredicate(opts) {
6996
7403
  return opts.workspacePackages.has(pkg);
6997
7404
  };
6998
7405
  return (symbol) => {
6999
- const decl = symbol.declarations?.[0];
7406
+ const resolved = resolveAliasSymbol(symbol, opts.checker, undefined, opts.program);
7407
+ const decl = (resolved.declarations ?? symbol.declarations)?.[0];
7000
7408
  if (!decl)
7001
7409
  return false;
7002
- if (isLibSymbol(symbol))
7410
+ if (isLibSymbol(resolved) || isLibSymbol(symbol))
7003
7411
  return false;
7004
7412
  const pkg = packageNameFromPath(decl.getSourceFile().fileName);
7005
7413
  if (pkg)
@@ -7015,7 +7423,12 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
7015
7423
  const MAX_DEPTH = 30;
7016
7424
  let visits = 0;
7017
7425
  const MAX_VISITS = 50000;
7018
- const symbolAllowed = createExternalExpansionPredicate(opts);
7426
+ const symbolAllowed = createExternalExpansionPredicate({
7427
+ followExternal: opts.followExternal,
7428
+ workspacePackages: opts.workspacePackages,
7429
+ checker: ctx.typeChecker,
7430
+ program: ctx.program
7431
+ });
7019
7432
  const visit = (type, depth) => {
7020
7433
  if (!type || depth > MAX_DEPTH || visited.has(type))
7021
7434
  return;
@@ -7048,7 +7461,7 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
7048
7461
  visit(t, depth + 1);
7049
7462
  }
7050
7463
  }
7051
- if (!allowed || !(type.flags & ts18.TypeFlags.Object || type.isClassOrInterface())) {
7464
+ if (!allowed || isDeferredMappedOrConditional(type) || !(type.flags & ts18.TypeFlags.Object || type.isClassOrInterface())) {
7052
7465
  return;
7053
7466
  }
7054
7467
  if (isForeignPackage(symbol, opts.workspacePackages)) {
@@ -7086,14 +7499,8 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
7086
7499
  return "type";
7087
7500
  };
7088
7501
  const resolveAlias = (symbol) => {
7089
- if (symbol.flags & ts18.SymbolFlags.Alias) {
7090
- try {
7091
- return checker.getAliasedSymbol(symbol);
7092
- } catch {
7093
- return;
7094
- }
7095
- }
7096
- return symbol;
7502
+ const resolved = resolveAliasSymbol(symbol, checker, undefined, ctx.program);
7503
+ return resolved;
7097
7504
  };
7098
7505
  const symbolByName = new Map;
7099
7506
  const registerTypeSymbol = (symbol) => {
@@ -7494,7 +7901,9 @@ async function extract(options) {
7494
7901
  onTruncation,
7495
7902
  shouldExpandExternal: createExternalExpansionPredicate({
7496
7903
  followExternal,
7497
- workspacePackages: result.workspacePackages ?? new Map
7904
+ workspacePackages: result.workspacePackages ?? new Map,
7905
+ checker: typeChecker,
7906
+ program
7498
7907
  }),
7499
7908
  workspacePackages: result.workspacePackages ?? new Map
7500
7909
  });
@@ -7512,7 +7921,7 @@ async function extract(options) {
7512
7921
  await new Promise((r) => setImmediate(r));
7513
7922
  }
7514
7923
  try {
7515
- const { declaration, targetSymbol, isTypeOnly } = resolveExportTarget2(symbol, typeChecker);
7924
+ const { declaration, targetSymbol, isTypeOnly } = resolveExportTarget(symbol, typeChecker, program);
7516
7925
  if (!declaration) {
7517
7926
  let externalPackage;
7518
7927
  const allDecls = [...targetSymbol.declarations ?? [], ...symbol.declarations ?? []];
@@ -7593,6 +8002,13 @@ async function extract(options) {
7593
8002
  workspacePackages: result.workspacePackages ?? new Map,
7594
8003
  entryFile
7595
8004
  });
8005
+ if (ctx.budgetExceeded) {
8006
+ diagnostics.push({
8007
+ message: "Stopped expanding some types after hitting the schema expansion budget",
8008
+ severity: "warning",
8009
+ code: "TYPE_EXPANSION_LIMIT"
8010
+ });
8011
+ }
7596
8012
  {
7597
8013
  const symFlags = ts19.SymbolFlags.Type | ts19.SymbolFlags.Interface | ts19.SymbolFlags.Class;
7598
8014
  const maxPasses = 5;
@@ -7762,6 +8178,15 @@ function serializeDeclaration2(declaration, exportSymbol, exportName, ctx, isTyp
7762
8178
  const type = ctx.typeChecker.getTypeAtLocation(declaration);
7763
8179
  if (type.getConstructSignatures().length > 0) {
7764
8180
  result = { ...result, kind: "class" };
8181
+ } else {
8182
+ const callSigs = callSignaturesForVariable(declaration, ctx);
8183
+ if (callSigs.length > 0) {
8184
+ result = {
8185
+ ...result,
8186
+ kind: "function",
8187
+ signatures: buildSignatures(callSigs, ctx.typeChecker, ctx)
8188
+ };
8189
+ }
7765
8190
  }
7766
8191
  }
7767
8192
  }
@@ -7946,6 +8371,35 @@ function extractExamples(doc) {
7946
8371
  }
7947
8372
  return examples;
7948
8373
  }
8374
+ function callSignaturesForVariable(declaration, ctx) {
8375
+ const checker = ctx.typeChecker;
8376
+ if (declaration.type && ts19.isTypeReferenceNode(declaration.type)) {
8377
+ const nameNode = ts19.isQualifiedName(declaration.type.typeName) ? declaration.type.typeName.right : declaration.type.typeName;
8378
+ const raw = checker.getSymbolAtLocation(nameNode);
8379
+ if (raw) {
8380
+ const symbol = resolveAliasSymbol(raw, checker, undefined, ctx.program);
8381
+ const iface = symbol.declarations?.find((d) => ts19.isInterfaceDeclaration(d));
8382
+ try {
8383
+ const declared = checker.getDeclaredTypeOfSymbol(symbol);
8384
+ const sigs = declared.getCallSignatures();
8385
+ if (sigs.length > 0)
8386
+ return sigs;
8387
+ if (iface) {
8388
+ const fromDecl = checker.getTypeAtLocation(iface).getCallSignatures();
8389
+ if (fromDecl.length > 0)
8390
+ return fromDecl;
8391
+ }
8392
+ } catch {
8393
+ if (iface) {
8394
+ try {
8395
+ return checker.getTypeAtLocation(iface).getCallSignatures();
8396
+ } catch {}
8397
+ }
8398
+ }
8399
+ }
8400
+ }
8401
+ return checker.getTypeAtLocation(declaration).getCallSignatures();
8402
+ }
7949
8403
  function withExportName(entry, exportName) {
7950
8404
  if (entry.name === exportName) {
7951
8405
  return entry;
@@ -8522,6 +8976,8 @@ export {
8522
8976
  validateSpec2 as validateSpec,
8523
8977
  valibotAdapter,
8524
8978
  typeboxAdapter,
8979
+ typeNodeOfSignature,
8980
+ typeNodeDefersExpansion,
8525
8981
  toToolSchema,
8526
8982
  toSearchIndexJSON,
8527
8983
  toSearchIndex,
@@ -8550,8 +9006,9 @@ export {
8550
9006
  schemaIsAny,
8551
9007
  resolveTypeRef,
8552
9008
  resolveTarget,
8553
- resolveExportTarget2 as resolveExportTarget,
9009
+ resolveExportTarget,
8554
9010
  resolveCompiledPath,
9011
+ resolveAliasSymbol,
8555
9012
  renderTypeText,
8556
9013
  registerReferencedTypes,
8557
9014
  registerAdapter,
@@ -8581,6 +9038,7 @@ export {
8581
9038
  isMethod,
8582
9039
  isExported,
8583
9040
  isEntryFilePath,
9041
+ isDeferredMappedOrConditional,
8584
9042
  isBuiltinSymbol,
8585
9043
  isBuiltinGeneric,
8586
9044
  isAnonymous,
@@ -8635,6 +9093,7 @@ export {
8635
9093
  calculateNextVersion,
8636
9094
  bundleRefs,
8637
9095
  buildSignatureString,
9096
+ buildSchemaFromTypeNode,
8638
9097
  buildSchema,
8639
9098
  buildObjectSchema,
8640
9099
  buildFunctionSchema,