@openpkg-ts/sdk 0.47.2 → 0.48.1

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
@@ -79,7 +79,12 @@ function mergeConfig(fileConfig, cliOptions) {
79
79
  depth: cliOptions.externals?.depth ?? fileConfig.externals?.depth
80
80
  };
81
81
  const hasExternals = externals.include || externals.exclude || externals.depth !== undefined;
82
- return hasExternals ? { externals } : {};
82
+ return {
83
+ ...hasExternals ? { externals } : {},
84
+ followExternal: cliOptions.followExternal ?? fileConfig.followExternal,
85
+ only: cliOptions.only ?? fileConfig.only,
86
+ ignore: cliOptions.ignore ?? fileConfig.ignore
87
+ };
83
88
  }
84
89
  // src/core/loader.ts
85
90
  import * as fs2 from "node:fs";
@@ -1295,7 +1300,7 @@ function filterSpec(spec, criteria) {
1295
1300
  };
1296
1301
  }
1297
1302
  // src/primitives/get.ts
1298
- import ts11 from "typescript";
1303
+ import ts12 from "typescript";
1299
1304
 
1300
1305
  // src/ast/utils.ts
1301
1306
  import * as path2 from "node:path";
@@ -1841,13 +1846,84 @@ function createProgram(options) {
1841
1846
  }
1842
1847
 
1843
1848
  // src/serializers/classes.ts
1844
- import ts7 from "typescript";
1849
+ import ts8 from "typescript";
1845
1850
 
1846
1851
  // src/types/parameters.ts
1847
- import ts4 from "typescript";
1852
+ import ts5 from "typescript";
1848
1853
 
1849
1854
  // src/types/schema-builder.ts
1855
+ import ts4 from "typescript";
1856
+
1857
+ // src/ast/type-identity.ts
1858
+ import * as path4 from "node:path";
1850
1859
  import ts3 from "typescript";
1860
+ var NODE_MODULES_PKG = /node_modules\/(@[^/]+\/[^/]+|[^/]+)/;
1861
+ function packageLabel(fileName, workspacePackages) {
1862
+ const match = fileName.match(NODE_MODULES_PKG);
1863
+ let pkg = match?.[1];
1864
+ if (!pkg) {
1865
+ for (const [name, dir] of workspacePackages) {
1866
+ if (fileName.startsWith(`${path4.resolve(dir)}${path4.sep}`)) {
1867
+ pkg = name;
1868
+ break;
1869
+ }
1870
+ }
1871
+ }
1872
+ return (pkg ?? "local").replace(/^@/, "").replace(/\//g, "-");
1873
+ }
1874
+ function declKey(symbol, checker) {
1875
+ let resolved = symbol;
1876
+ if (symbol.flags & ts3.SymbolFlags.Alias) {
1877
+ try {
1878
+ resolved = checker.getAliasedSymbol(symbol);
1879
+ } catch {}
1880
+ }
1881
+ const decl = resolved.declarations?.[0];
1882
+ if (!decl)
1883
+ return;
1884
+ return `${decl.getSourceFile().fileName}#${decl.getStart()}`;
1885
+ }
1886
+ function resolveTypeId(symbol, ctx) {
1887
+ const cached = ctx.typeIds.get(symbol);
1888
+ if (cached)
1889
+ return cached;
1890
+ const key = declKey(symbol, ctx.typeChecker);
1891
+ if (key) {
1892
+ const existing = ctx.declIds.get(key);
1893
+ if (existing) {
1894
+ ctx.typeIds.set(symbol, existing);
1895
+ return existing;
1896
+ }
1897
+ }
1898
+ const claim = (id) => {
1899
+ ctx.typeIds.set(symbol, id);
1900
+ if (key)
1901
+ ctx.declIds.set(key, id);
1902
+ ctx.idOwner.set(id, key ?? id);
1903
+ return id;
1904
+ };
1905
+ const name = symbol.getName();
1906
+ const owner = ctx.idOwner.get(name);
1907
+ if (!owner || owner === key)
1908
+ return claim(name);
1909
+ const file = symbol.declarations?.[0]?.getSourceFile().fileName ?? "";
1910
+ const scoped = `${packageLabel(file, ctx.workspacePackages)}.${name}`;
1911
+ const scopedOwner = ctx.idOwner.get(scoped);
1912
+ if (!scopedOwner || scopedOwner === key)
1913
+ return claim(scoped);
1914
+ let n = 2;
1915
+ while (ctx.idOwner.has(`${name}_${n}`))
1916
+ n++;
1917
+ return claim(`${name}_${n}`);
1918
+ }
1919
+ function typeRefId(type, ctx) {
1920
+ const symbol = type.aliasSymbol ?? type.getSymbol();
1921
+ if (!symbol)
1922
+ return "";
1923
+ if (!ctx)
1924
+ return symbol.getName();
1925
+ return resolveTypeId(symbol, ctx);
1926
+ }
1851
1927
 
1852
1928
  // src/schema/builtins.ts
1853
1929
  var BUILTIN_TYPE_SCHEMAS = {
@@ -1884,11 +1960,11 @@ function escapeRegex(text) {
1884
1960
  }
1885
1961
  function buildTemplatePattern(type) {
1886
1962
  const slotPattern = (slot) => {
1887
- if (slot.flags & ts3.TypeFlags.NumberLike)
1963
+ if (slot.flags & ts4.TypeFlags.NumberLike)
1888
1964
  return "-?\\d+(?:\\.\\d+)?";
1889
- if (slot.flags & ts3.TypeFlags.BigIntLike)
1965
+ if (slot.flags & ts4.TypeFlags.BigIntLike)
1890
1966
  return "-?\\d+";
1891
- if (slot.flags & ts3.TypeFlags.BooleanLike)
1967
+ if (slot.flags & ts4.TypeFlags.BooleanLike)
1892
1968
  return "(?:true|false)";
1893
1969
  return ".*";
1894
1970
  };
@@ -1898,6 +1974,11 @@ function buildTemplatePattern(type) {
1898
1974
  });
1899
1975
  return `${pattern}$`;
1900
1976
  }
1977
+ function namedRefId(type, name, ctx) {
1978
+ if (!ctx)
1979
+ return name;
1980
+ return typeRefId(type, ctx) || name;
1981
+ }
1901
1982
  function builtinSchema(name) {
1902
1983
  const schema = { ...BUILTIN_TYPE_SCHEMAS[name] ?? { type: "object" } };
1903
1984
  setSchemaExtension(schema, "x-ts-type", name);
@@ -1910,12 +1991,12 @@ function scrubImportQualifiers(text) {
1910
1991
  return text.replace(/import\((?:"[^"]*"|'[^']*')\)\./g, "");
1911
1992
  }
1912
1993
  function renderTypeText(type, checker, enclosing, extraFlags = 0) {
1913
- return scrubImportQualifiers(checker.typeToString(type, enclosing, ts3.TypeFormatFlags.NoTruncation | extraFlags));
1994
+ return scrubImportQualifiers(checker.typeToString(type, enclosing, ts4.TypeFormatFlags.NoTruncation | extraFlags));
1914
1995
  }
1915
1996
  function stripUndefinedFromType(type, checker) {
1916
1997
  if (!type.isUnion())
1917
1998
  return type;
1918
- const nonUndefinedTypes = type.types.filter((t) => !(t.flags & ts3.TypeFlags.Undefined));
1999
+ const nonUndefinedTypes = type.types.filter((t) => !(t.flags & ts4.TypeFlags.Undefined));
1919
2000
  if (nonUndefinedTypes.length === 0)
1920
2001
  return type;
1921
2002
  if (nonUndefinedTypes.length === 1)
@@ -1924,13 +2005,13 @@ function stripUndefinedFromType(type, checker) {
1924
2005
  }
1925
2006
  function isReadonlyPropertySymbol(prop) {
1926
2007
  const decls = prop.getDeclarations() ?? [];
1927
- return decls.some((d) => (ts3.getCombinedModifierFlags(d) & ts3.ModifierFlags.Readonly) !== 0);
2008
+ return decls.some((d) => (ts4.getCombinedModifierFlags(d) & ts4.ModifierFlags.Readonly) !== 0);
1928
2009
  }
1929
2010
  function decoratePropertySchema(schema, prop, propType, checker) {
1930
2011
  if (typeof schema !== "object" || schema === null || Array.isArray(schema))
1931
2012
  return schema;
1932
2013
  const decl = prop.valueDeclaration ?? prop.getDeclarations()?.[0];
1933
- const optional = !!(prop.flags & ts3.SymbolFlags.Optional);
2014
+ const optional = !!(prop.flags & ts4.SymbolFlags.Optional);
1934
2015
  const textType = optional ? stripUndefinedFromType(propType, checker) : propType;
1935
2016
  const text = renderTypeText(textType, checker, decl);
1936
2017
  const obj = schema;
@@ -1943,13 +2024,13 @@ function decoratePropertySchema(schema, prop, propType, checker) {
1943
2024
  if (isReadonlyPropertySymbol(prop) && !("readOnly" in obj)) {
1944
2025
  result = { ...result, readOnly: true };
1945
2026
  }
1946
- if (prop.flags & ts3.SymbolFlags.Method && !("x-ts-method" in obj)) {
2027
+ if (prop.flags & ts4.SymbolFlags.Method && !("x-ts-method" in obj)) {
1947
2028
  result = { ...result, "x-ts-method": true };
1948
2029
  }
1949
2030
  return result;
1950
2031
  }
1951
2032
  function shouldEmitAliasTypeText(typeNode) {
1952
- return !ts3.isTypeLiteralNode(typeNode) && !ts3.isMappedTypeNode(typeNode);
2033
+ return !ts4.isTypeLiteralNode(typeNode) && !ts4.isMappedTypeNode(typeNode);
1953
2034
  }
1954
2035
  var PRIMITIVES = new Set([
1955
2036
  "string",
@@ -2200,7 +2281,7 @@ function buildSchema(type, checker, ctx) {
2200
2281
  return ensureNonEmptySchema(schema, type, checker);
2201
2282
  }
2202
2283
  function buildMaxDepthSchema(type, checker) {
2203
- if (type.flags & ts3.TypeFlags.TypeParameter && type.isThisType !== true) {
2284
+ if (type.flags & ts4.TypeFlags.TypeParameter && type.isThisType !== true) {
2204
2285
  return { "x-ts-type": checker.typeToString(type) };
2205
2286
  }
2206
2287
  const symbol = type.getSymbol() || type.aliasSymbol;
@@ -2213,19 +2294,19 @@ function buildMaxDepthSchema(type, checker) {
2213
2294
  return { $ref: `#/types/${name}` };
2214
2295
  }
2215
2296
  }
2216
- if (type.flags & ts3.TypeFlags.String)
2297
+ if (type.flags & ts4.TypeFlags.String)
2217
2298
  return { type: "string" };
2218
- if (type.flags & ts3.TypeFlags.Number)
2299
+ if (type.flags & ts4.TypeFlags.Number)
2219
2300
  return { type: "number" };
2220
- if (type.flags & ts3.TypeFlags.Boolean)
2301
+ if (type.flags & ts4.TypeFlags.Boolean)
2221
2302
  return { type: "boolean" };
2222
- if (type.flags & ts3.TypeFlags.Undefined)
2303
+ if (type.flags & ts4.TypeFlags.Undefined)
2223
2304
  return { type: "undefined" };
2224
- if (type.flags & ts3.TypeFlags.Null)
2305
+ if (type.flags & ts4.TypeFlags.Null)
2225
2306
  return { type: "null" };
2226
- if (type.flags & ts3.TypeFlags.Void)
2307
+ if (type.flags & ts4.TypeFlags.Void)
2227
2308
  return { type: "void" };
2228
- if (type.flags & ts3.TypeFlags.TemplateLiteral) {
2309
+ if (type.flags & ts4.TypeFlags.TemplateLiteral) {
2229
2310
  return {
2230
2311
  type: "string",
2231
2312
  pattern: buildTemplatePattern(type),
@@ -2257,59 +2338,59 @@ function buildSchemaInternal(type, checker, ctx) {
2257
2338
  if (BUILTIN_TYPES.has(name) || isBuiltinGeneric(name)) {
2258
2339
  return builtinSchema(name);
2259
2340
  }
2260
- return { $ref: `#/types/${name}` };
2341
+ return { $ref: `#/types/${namedRefId(type, name, ctx)}` };
2261
2342
  }
2262
2343
  return { type: checker.typeToString(type) };
2263
2344
  }
2264
- const addedToVisited = !!(ctx && type.flags & ts3.TypeFlags.Object);
2345
+ const addedToVisited = !!(ctx && type.flags & ts4.TypeFlags.Object);
2265
2346
  if (addedToVisited) {
2266
2347
  ctx.visitedTypes.add(type);
2267
2348
  }
2268
2349
  try {
2269
- if (type.flags & ts3.TypeFlags.String)
2350
+ if (type.flags & ts4.TypeFlags.String)
2270
2351
  return { type: "string" };
2271
- if (type.flags & ts3.TypeFlags.Number)
2352
+ if (type.flags & ts4.TypeFlags.Number)
2272
2353
  return { type: "number" };
2273
- if (type.flags & ts3.TypeFlags.Boolean)
2354
+ if (type.flags & ts4.TypeFlags.Boolean)
2274
2355
  return { type: "boolean" };
2275
- if (type.flags & ts3.TypeFlags.Undefined)
2356
+ if (type.flags & ts4.TypeFlags.Undefined)
2276
2357
  return { type: "undefined" };
2277
- if (type.flags & ts3.TypeFlags.Null)
2358
+ if (type.flags & ts4.TypeFlags.Null)
2278
2359
  return { type: "null" };
2279
- if (type.flags & ts3.TypeFlags.Void)
2360
+ if (type.flags & ts4.TypeFlags.Void)
2280
2361
  return { type: "void" };
2281
- if (type.flags & ts3.TypeFlags.Any)
2362
+ if (type.flags & ts4.TypeFlags.Any)
2282
2363
  return { type: "any" };
2283
- if (type.flags & ts3.TypeFlags.Unknown)
2364
+ if (type.flags & ts4.TypeFlags.Unknown)
2284
2365
  return { type: "unknown" };
2285
- if (type.flags & ts3.TypeFlags.Never)
2366
+ if (type.flags & ts4.TypeFlags.Never)
2286
2367
  return { type: "never" };
2287
- if (type.flags & ts3.TypeFlags.BigInt)
2368
+ if (type.flags & ts4.TypeFlags.BigInt)
2288
2369
  return { type: "bigint" };
2289
- if (type.flags & ts3.TypeFlags.ESSymbol)
2370
+ if (type.flags & ts4.TypeFlags.ESSymbol)
2290
2371
  return { type: "symbol" };
2291
2372
  if (type.isThisType === true) {
2292
2373
  const constraint = type.getConstraint?.();
2293
2374
  const symbol2 = constraint?.getSymbol() ?? type.getSymbol();
2294
2375
  if (symbol2 && !isAnonymous(type)) {
2295
2376
  return {
2296
- $ref: `#/types/${symbol2.getName()}`,
2377
+ $ref: `#/types/${ctx ? resolveTypeId(symbol2, ctx) : symbol2.getName()}`,
2297
2378
  "x-ts-type": "this"
2298
2379
  };
2299
2380
  }
2300
2381
  }
2301
- if (type.flags & ts3.TypeFlags.TypeParameter) {
2382
+ if (type.flags & ts4.TypeFlags.TypeParameter) {
2302
2383
  return { "x-ts-type": checker.typeToString(type) };
2303
2384
  }
2304
- if (type.flags & ts3.TypeFlags.StringLiteral) {
2385
+ if (type.flags & ts4.TypeFlags.StringLiteral) {
2305
2386
  const literal = type.value;
2306
2387
  return { type: "string", enum: [literal] };
2307
2388
  }
2308
- if (type.flags & ts3.TypeFlags.NumberLiteral) {
2389
+ if (type.flags & ts4.TypeFlags.NumberLiteral) {
2309
2390
  const literal = type.value;
2310
2391
  return { type: "number", enum: [literal] };
2311
2392
  }
2312
- if (type.flags & ts3.TypeFlags.BooleanLiteral) {
2393
+ if (type.flags & ts4.TypeFlags.BooleanLiteral) {
2313
2394
  const typeString2 = checker.typeToString(type);
2314
2395
  return { type: "boolean", enum: [typeString2 === "true"] };
2315
2396
  }
@@ -2317,40 +2398,40 @@ function buildSchemaInternal(type, checker, ctx) {
2317
2398
  const aliasName = type.aliasSymbol.getName();
2318
2399
  if (!aliasName.startsWith("__") && !isPrimitiveName(aliasName)) {
2319
2400
  const packageOrigin = getTypeOrigin(type, checker);
2320
- const schema = { $ref: `#/types/${aliasName}` };
2401
+ const schema = { $ref: `#/types/${namedRefId(type, aliasName, ctx)}` };
2321
2402
  if (packageOrigin) {
2322
2403
  setSchemaExtension(schema, "x-ts-package", packageOrigin);
2323
2404
  }
2324
2405
  return schema;
2325
2406
  }
2326
2407
  }
2327
- if (type.flags & ts3.TypeFlags.TemplateLiteral) {
2408
+ if (type.flags & ts4.TypeFlags.TemplateLiteral) {
2328
2409
  return {
2329
2410
  type: "string",
2330
2411
  pattern: buildTemplatePattern(type),
2331
2412
  "x-ts-type": renderTypeText(type, checker)
2332
2413
  };
2333
2414
  }
2334
- if (type.flags & ts3.TypeFlags.StringMapping) {
2415
+ if (type.flags & ts4.TypeFlags.StringMapping) {
2335
2416
  return { type: "string", "x-ts-type": renderTypeText(type, checker) };
2336
2417
  }
2337
2418
  if (type.isUnion()) {
2338
2419
  const types = type.types;
2339
- const allStringLiterals = types.every((t) => t.flags & ts3.TypeFlags.StringLiteral);
2420
+ const allStringLiterals = types.every((t) => t.flags & ts4.TypeFlags.StringLiteral);
2340
2421
  if (allStringLiterals) {
2341
2422
  const enumValues = types.map((t) => t.value);
2342
2423
  return { type: "string", enum: enumValues };
2343
2424
  }
2344
- const allNumberLiterals = types.every((t) => t.flags & ts3.TypeFlags.NumberLiteral);
2425
+ const allNumberLiterals = types.every((t) => t.flags & ts4.TypeFlags.NumberLiteral);
2345
2426
  if (allNumberLiterals) {
2346
2427
  const enumValues = types.map((t) => t.value);
2347
2428
  return { type: "number", enum: enumValues };
2348
2429
  }
2349
- const allBooleanLiterals = types.every((t) => t.flags & ts3.TypeFlags.BooleanLiteral);
2430
+ const allBooleanLiterals = types.every((t) => t.flags & ts4.TypeFlags.BooleanLiteral);
2350
2431
  if (allBooleanLiterals) {
2351
2432
  return { type: "boolean" };
2352
2433
  }
2353
- const isBoolLiteral = (t) => !!(t.flags & ts3.TypeFlags.BooleanLiteral);
2434
+ const isBoolLiteral = (t) => !!(t.flags & ts4.TypeFlags.BooleanLiteral);
2354
2435
  let members = types;
2355
2436
  if (types.filter(isBoolLiteral).length === 2) {
2356
2437
  const firstBool = types.findIndex(isBoolLiteral);
@@ -2364,10 +2445,10 @@ function buildSchemaInternal(type, checker, ctx) {
2364
2445
  }
2365
2446
  return { anyOf: members.map(buildBranch) };
2366
2447
  }
2367
- const isIntersectionType = type.isIntersection() || !!(type.flags & ts3.TypeFlags.Intersection);
2448
+ const isIntersectionType = type.isIntersection() || !!(type.flags & ts4.TypeFlags.Intersection);
2368
2449
  if (isIntersectionType && "types" in type) {
2369
2450
  const intersectionType = type;
2370
- const filteredTypes = intersectionType.types.filter((t) => !(t.flags & ts3.TypeFlags.Never));
2451
+ const filteredTypes = intersectionType.types.filter((t) => !(t.flags & ts4.TypeFlags.Never));
2371
2452
  if (filteredTypes.length === 0) {
2372
2453
  return { type: "never" };
2373
2454
  }
@@ -2456,7 +2537,7 @@ function buildSchemaInternal(type, checker, ctx) {
2456
2537
  if (ctx) {
2457
2538
  return withDepth(ctx, () => {
2458
2539
  const schema2 = {
2459
- $ref: `#/types/${name}`,
2540
+ $ref: `#/types/${namedRefId(typeRef.target, name, ctx)}`,
2460
2541
  typeArguments: typeArgs.map((t) => buildSchema(t, checker, ctx))
2461
2542
  };
2462
2543
  if (packageOrigin) {
@@ -2482,7 +2563,7 @@ function buildSchemaInternal(type, checker, ctx) {
2482
2563
  if (BUILTIN_TYPES.has(name)) {
2483
2564
  return builtinSchema(name);
2484
2565
  }
2485
- if (RESOLVED_UTILITY_TYPES.has(name) && type.flags & ts3.TypeFlags.Object) {
2566
+ if (RESOLVED_UTILITY_TYPES.has(name) && type.flags & ts4.TypeFlags.Object) {
2486
2567
  const props = type.getProperties();
2487
2568
  const hasIndex = checker.getIndexInfosOfType(type).length > 0;
2488
2569
  if (props.length > 0 || hasIndex) {
@@ -2501,7 +2582,7 @@ function buildSchemaInternal(type, checker, ctx) {
2501
2582
  if (ctx) {
2502
2583
  return withDepth(ctx, () => {
2503
2584
  const schema2 = {
2504
- $ref: `#/types/${name}`,
2585
+ $ref: `#/types/${namedRefId(type, name, ctx)}`,
2505
2586
  typeArguments: aliasTypeArgs.map((t) => buildSchema(t, checker, ctx))
2506
2587
  };
2507
2588
  if (packageOrigin) {
@@ -2520,7 +2601,7 @@ function buildSchemaInternal(type, checker, ctx) {
2520
2601
  return schema;
2521
2602
  }
2522
2603
  }
2523
- if (type.flags & ts3.TypeFlags.Object) {
2604
+ if (type.flags & ts4.TypeFlags.Object) {
2524
2605
  const callSignatures = type.getCallSignatures();
2525
2606
  if (callSignatures.length > 0) {
2526
2607
  return buildFunctionSchema(callSignatures, checker, ctx);
@@ -2539,17 +2620,17 @@ function buildSchemaInternal(type, checker, ctx) {
2539
2620
  }
2540
2621
  if (!name.startsWith("__")) {
2541
2622
  const packageOrigin = getTypeOrigin(type, checker);
2542
- const schema = { $ref: `#/types/${name}` };
2623
+ const schema = { $ref: `#/types/${namedRefId(type, name, ctx)}` };
2543
2624
  if (packageOrigin) {
2544
2625
  setSchemaExtension(schema, "x-ts-package", packageOrigin);
2545
2626
  }
2546
2627
  return schema;
2547
2628
  }
2548
2629
  }
2549
- if (type.flags & ts3.TypeFlags.Object) {
2630
+ if (type.flags & ts4.TypeFlags.Object) {
2550
2631
  const objectType = type;
2551
2632
  const properties = type.getProperties();
2552
- if (properties.length > 0 || objectType.objectFlags & ts3.ObjectFlags.Anonymous || checker.getIndexInfosOfType(type).length > 0) {
2633
+ if (properties.length > 0 || objectType.objectFlags & ts4.ObjectFlags.Anonymous || checker.getIndexInfosOfType(type).length > 0) {
2553
2634
  return buildObjectSchema(properties, checker, ctx, type);
2554
2635
  }
2555
2636
  }
@@ -2593,8 +2674,8 @@ function buildFunctionSchema(callSignatures, checker, ctx) {
2593
2674
  }
2594
2675
  function buildObjectSchema(properties, checker, ctx, originalType) {
2595
2676
  const isArrayLikeType = originalType ? checker.isArrayType(originalType) || checker.isTupleType(originalType) || originalType.symbol?.getName() === "Array" && isBuiltinSymbol(originalType.symbol) : false;
2596
- const isStringLikeType = !!(originalType && originalType.flags & ts3.TypeFlags.StringLike);
2597
- const isNumberLikeType = !!(originalType && originalType.flags & ts3.TypeFlags.NumberLike);
2677
+ const isStringLikeType = !!(originalType && originalType.flags & ts4.TypeFlags.StringLike);
2678
+ const isNumberLikeType = !!(originalType && originalType.flags & ts4.TypeFlags.NumberLike);
2598
2679
  const buildProps = () => {
2599
2680
  const props = {};
2600
2681
  const required = [];
@@ -2611,7 +2692,7 @@ function buildObjectSchema(properties, checker, ctx, originalType) {
2611
2692
  if (isNumberLikeType && NUMBER_PROTOTYPE_METHODS.has(propName)) {
2612
2693
  continue;
2613
2694
  }
2614
- const isOptionalProp = !!(prop.flags & ts3.SymbolFlags.Optional);
2695
+ const isOptionalProp = !!(prop.flags & ts4.SymbolFlags.Optional);
2615
2696
  const rawPropType = checker.getTypeOfSymbol(prop);
2616
2697
  const propType = isOptionalProp ? stripUndefinedFromType(rawPropType, checker) : rawPropType;
2617
2698
  let propSchema = buildSchema(propType, checker, ctx);
@@ -2629,7 +2710,7 @@ function buildObjectSchema(properties, checker, ctx, originalType) {
2629
2710
  }
2630
2711
  propSchema = decoratePropertySchema(propSchema, prop, propType, checker);
2631
2712
  props[propName] = propSchema;
2632
- if (!(prop.flags & ts3.SymbolFlags.Optional)) {
2713
+ if (!(prop.flags & ts4.SymbolFlags.Optional)) {
2633
2714
  required.push(propName);
2634
2715
  }
2635
2716
  }
@@ -2639,11 +2720,11 @@ function buildObjectSchema(properties, checker, ctx, originalType) {
2639
2720
  ...required.length > 0 ? { required } : {}
2640
2721
  };
2641
2722
  const indexInfos = originalType ? checker.getIndexInfosOfType(originalType) : [];
2642
- const stringIndex = indexInfos.find((i) => i.keyType.flags & ts3.TypeFlags.String);
2723
+ const stringIndex = indexInfos.find((i) => i.keyType.flags & ts4.TypeFlags.String);
2643
2724
  if (stringIndex) {
2644
2725
  schema.additionalProperties = buildSchema(stringIndex.type, checker, ctx);
2645
2726
  }
2646
- const numberIndex = indexInfos.find((i) => i.keyType.flags & ts3.TypeFlags.Number);
2727
+ const numberIndex = indexInfos.find((i) => i.keyType.flags & ts4.TypeFlags.Number);
2647
2728
  if (numberIndex) {
2648
2729
  schema.patternProperties = {
2649
2730
  "^\\d+$": buildSchema(numberIndex.type, checker, ctx)
@@ -2732,7 +2813,7 @@ function deduplicateSchemas(schemas) {
2732
2813
  function findDiscriminatorProperty(unionTypes, checker) {
2733
2814
  const memberProps = [];
2734
2815
  for (const t of unionTypes) {
2735
- if (t.flags & (ts3.TypeFlags.Null | ts3.TypeFlags.Undefined)) {
2816
+ if (t.flags & (ts4.TypeFlags.Null | ts4.TypeFlags.Undefined)) {
2736
2817
  continue;
2737
2818
  }
2738
2819
  const props = t.getProperties();
@@ -2786,13 +2867,13 @@ function extractParameters(signature, ctx) {
2786
2867
  const { typeChecker: checker } = ctx;
2787
2868
  const result = [];
2788
2869
  const signatureDecl = signature.getDeclaration();
2789
- const jsdocTags = signatureDecl ? ts4.getJSDocTags(signatureDecl) : [];
2870
+ const jsdocTags = signatureDecl ? ts5.getJSDocTags(signatureDecl) : [];
2790
2871
  for (const param of signature.getParameters()) {
2791
2872
  const decl = param.valueDeclaration;
2792
2873
  if (!decl)
2793
2874
  continue;
2794
2875
  const type = checker.getTypeOfSymbolAtLocation(param, decl);
2795
- if (decl && ts4.isObjectBindingPattern(decl.name)) {
2876
+ if (decl && ts5.isObjectBindingPattern(decl.name)) {
2796
2877
  const expandedParams = expandBindingPattern(decl, type, jsdocTags, ctx);
2797
2878
  result.push(...expandedParams);
2798
2879
  } else {
@@ -2824,13 +2905,13 @@ function expandBindingPattern(paramDecl, paramType, jsdocTags, ctx) {
2824
2905
  const allProperties = getEffectiveProperties(paramType, checker);
2825
2906
  const inferredAlias = inferParamAlias(jsdocTags);
2826
2907
  for (const element of bindingPattern.elements) {
2827
- if (!ts4.isBindingElement(element))
2908
+ if (!ts5.isBindingElement(element))
2828
2909
  continue;
2829
- const propertyName = element.propertyName ? ts4.isIdentifier(element.propertyName) ? element.propertyName.text : element.propertyName.getText() : ts4.isIdentifier(element.name) ? element.name.text : element.name.getText();
2910
+ const propertyName = element.propertyName ? ts5.isIdentifier(element.propertyName) ? element.propertyName.text : element.propertyName.getText() : ts5.isIdentifier(element.name) ? element.name.text : element.name.getText();
2830
2911
  const propSymbol = allProperties.get(propertyName);
2831
2912
  if (!propSymbol)
2832
2913
  continue;
2833
- const isOptional = !!(propSymbol.flags & ts4.SymbolFlags.Optional) || element.initializer !== undefined;
2914
+ const isOptional = !!(propSymbol.flags & ts5.SymbolFlags.Optional) || element.initializer !== undefined;
2834
2915
  const propType = checker.getTypeOfSymbol(propSymbol);
2835
2916
  const effectiveType = isOptional ? stripUndefinedFromType(propType, checker) : propType;
2836
2917
  registerReferencedTypes(effectiveType, ctx);
@@ -2870,7 +2951,7 @@ function inferParamAlias(jsdocTags) {
2870
2951
  for (const tag of jsdocTags) {
2871
2952
  if (tag.tagName.text !== "param")
2872
2953
  continue;
2873
- const tagText = typeof tag.comment === "string" ? tag.comment : ts4.getTextOfJSDocComment(tag.comment) ?? "";
2954
+ const tagText = typeof tag.comment === "string" ? tag.comment : ts5.getTextOfJSDocComment(tag.comment) ?? "";
2874
2955
  const paramTag = tag;
2875
2956
  const paramName = paramTag.name?.getText() ?? "";
2876
2957
  if (paramName.includes(".")) {
@@ -2893,22 +2974,22 @@ function inferParamAlias(jsdocTags) {
2893
2974
  return Array.from(counts.entries()).sort((a, b) => b[1] - a[1])[0]?.[0];
2894
2975
  }
2895
2976
  function extractLiteralDefault(initializer) {
2896
- if (ts4.isStringLiteral(initializer)) {
2977
+ if (ts5.isStringLiteral(initializer)) {
2897
2978
  return { literal: true, value: initializer.text };
2898
2979
  }
2899
- if (ts4.isNumericLiteral(initializer)) {
2980
+ if (ts5.isNumericLiteral(initializer)) {
2900
2981
  return { literal: true, value: Number(initializer.text) };
2901
2982
  }
2902
- if (ts4.isPrefixUnaryExpression(initializer) && initializer.operator === ts4.SyntaxKind.MinusToken && ts4.isNumericLiteral(initializer.operand)) {
2983
+ if (ts5.isPrefixUnaryExpression(initializer) && initializer.operator === ts5.SyntaxKind.MinusToken && ts5.isNumericLiteral(initializer.operand)) {
2903
2984
  return { literal: true, value: -Number(initializer.operand.text) };
2904
2985
  }
2905
- if (initializer.kind === ts4.SyntaxKind.TrueKeyword) {
2986
+ if (initializer.kind === ts5.SyntaxKind.TrueKeyword) {
2906
2987
  return { literal: true, value: true };
2907
2988
  }
2908
- if (initializer.kind === ts4.SyntaxKind.FalseKeyword) {
2989
+ if (initializer.kind === ts5.SyntaxKind.FalseKeyword) {
2909
2990
  return { literal: true, value: false };
2910
2991
  }
2911
- if (initializer.kind === ts4.SyntaxKind.NullKeyword) {
2992
+ if (initializer.kind === ts5.SyntaxKind.NullKeyword) {
2912
2993
  return { literal: true, value: null };
2913
2994
  }
2914
2995
  return { literal: false, text: initializer.getText() };
@@ -2929,7 +3010,7 @@ function registerReferencedTypes(type, ctx, depth = 0) {
2929
3010
  return;
2930
3011
  if (ctx.registeredTypes.has(type))
2931
3012
  return;
2932
- const isPrimitive = type.flags & (ts4.TypeFlags.String | ts4.TypeFlags.Number | ts4.TypeFlags.Boolean | ts4.TypeFlags.Void | ts4.TypeFlags.Undefined | ts4.TypeFlags.Null | ts4.TypeFlags.Any | ts4.TypeFlags.Unknown | ts4.TypeFlags.Never | ts4.TypeFlags.StringLiteral | ts4.TypeFlags.NumberLiteral | ts4.TypeFlags.BooleanLiteral);
3013
+ 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);
2933
3014
  if (!isPrimitive) {
2934
3015
  ctx.registeredTypes.add(type);
2935
3016
  }
@@ -2955,7 +3036,7 @@ function registerReferencedTypes(type, ctx, depth = 0) {
2955
3036
  if (typeSymbol && ctx.shouldExpandExternal && !typeSymbol.getName().startsWith("__") && !ctx.shouldExpandExternal(typeSymbol)) {
2956
3037
  return;
2957
3038
  }
2958
- if (type.flags & ts4.TypeFlags.Object) {
3039
+ if (type.flags & ts5.TypeFlags.Object) {
2959
3040
  const props = type.getProperties();
2960
3041
  const limit = ctx.maxProperties;
2961
3042
  if (props.length > limit && ctx.onTruncation) {
@@ -2970,10 +3051,10 @@ function registerReferencedTypes(type, ctx, depth = 0) {
2970
3051
  }
2971
3052
 
2972
3053
  // src/serializers/context.ts
2973
- import ts6 from "typescript";
3054
+ import ts7 from "typescript";
2974
3055
 
2975
3056
  // src/ast/registry.ts
2976
- import ts5 from "typescript";
3057
+ import ts6 from "typescript";
2977
3058
  var BUILTINS = new Set([
2978
3059
  "Array",
2979
3060
  "ArrayBuffer",
@@ -3077,61 +3158,68 @@ class TypeRegistry {
3077
3158
  return;
3078
3159
  if (name.startsWith("__"))
3079
3160
  return;
3080
- if (symbol.flags & ts5.SymbolFlags.EnumMember)
3161
+ if (symbol.flags & ts6.SymbolFlags.EnumMember)
3081
3162
  return;
3082
- if (symbol.flags & ts5.SymbolFlags.TypeParameter)
3163
+ if (symbol.flags & ts6.SymbolFlags.TypeParameter)
3083
3164
  return;
3084
- if (symbol.flags & ts5.SymbolFlags.Method)
3165
+ if (symbol.flags & ts6.SymbolFlags.Method)
3085
3166
  return;
3086
- if (symbol.flags & ts5.SymbolFlags.Function)
3167
+ if (symbol.flags & ts6.SymbolFlags.Function)
3087
3168
  return;
3088
3169
  if (isGenericTypeParameter(name))
3089
3170
  return;
3090
- if (this.has(name))
3091
- return name;
3171
+ const id = resolveTypeId(symbol, ctx);
3172
+ if (this.has(id))
3173
+ return id;
3092
3174
  if (ctx.shouldExpandExternal && !ctx.shouldExpandExternal(symbol)) {
3175
+ const origin = getTypeOrigin(type, ctx.typeChecker);
3176
+ const schema = {
3177
+ "x-ts-type": renderTypeText(type, ctx.typeChecker)
3178
+ };
3179
+ if (origin)
3180
+ schema["x-ts-package"] = origin;
3093
3181
  this.add({
3094
- id: name,
3182
+ id,
3095
3183
  name,
3096
3184
  kind: "external",
3097
3185
  external: true,
3098
- schema: { "x-ts-type": renderTypeText(type, ctx.typeChecker) }
3186
+ schema
3099
3187
  });
3100
- return name;
3188
+ return id;
3101
3189
  }
3102
- if (this.processing.has(name))
3103
- return name;
3104
- this.processing.add(name);
3190
+ if (this.processing.has(id))
3191
+ return id;
3192
+ this.processing.add(id);
3105
3193
  try {
3106
- const specType = this.buildSpecType(type, symbol, ctx);
3194
+ const specType = this.buildSpecType(type, symbol, id, ctx);
3107
3195
  if (specType) {
3108
3196
  this.add(specType);
3109
3197
  return specType.id;
3110
3198
  }
3111
3199
  } finally {
3112
- this.processing.delete(name);
3200
+ this.processing.delete(id);
3113
3201
  }
3114
3202
  return;
3115
3203
  }
3116
- buildSpecType(type, symbol, ctx) {
3204
+ buildSpecType(type, symbol, id, ctx) {
3117
3205
  const name = symbol.getName();
3118
3206
  const decl = symbol.declarations?.[0];
3119
3207
  const checker = ctx.typeChecker;
3120
3208
  let kind = "type";
3121
3209
  const external = decl ? isExternalType(decl) : false;
3122
3210
  if (decl) {
3123
- if (ts5.isClassDeclaration(decl))
3211
+ if (ts6.isClassDeclaration(decl))
3124
3212
  kind = "class";
3125
- else if (ts5.isInterfaceDeclaration(decl))
3213
+ else if (ts6.isInterfaceDeclaration(decl))
3126
3214
  kind = "interface";
3127
- else if (ts5.isEnumDeclaration(decl))
3215
+ else if (ts6.isEnumDeclaration(decl))
3128
3216
  kind = "enum";
3129
3217
  }
3130
3218
  if (external) {
3131
3219
  kind = "external";
3132
3220
  }
3133
3221
  let schema = buildSchema(type, checker, ctx);
3134
- if (this.isSelfRef(schema, name)) {
3222
+ if (this.isSelfRef(schema, id)) {
3135
3223
  schema = this.resolveSelRefSchema(type, checker, ctx);
3136
3224
  }
3137
3225
  if (kind === "enum") {
@@ -3140,18 +3228,18 @@ class TypeRegistry {
3140
3228
  schema = enumSchema;
3141
3229
  }
3142
3230
  }
3143
- if (kind === "type" && decl && ts5.isTypeAliasDeclaration(decl) && shouldEmitAliasTypeText(decl.type) && typeof schema === "object" && schema !== null && !("x-ts-type" in schema)) {
3144
- const text = renderTypeText(type, checker, decl, ts5.TypeFormatFlags.InTypeAlias);
3231
+ if (kind === "type" && decl && ts6.isTypeAliasDeclaration(decl) && shouldEmitAliasTypeText(decl.type) && typeof schema === "object" && schema !== null && !("x-ts-type" in schema)) {
3232
+ const text = renderTypeText(type, checker, decl, ts6.TypeFormatFlags.InTypeAlias);
3145
3233
  if (!PRIMITIVES.has(text) && text !== name) {
3146
3234
  schema["x-ts-type"] = text;
3147
3235
  }
3148
3236
  }
3149
3237
  let typeParameters;
3150
- if (decl && (ts5.isTypeAliasDeclaration(decl) || ts5.isInterfaceDeclaration(decl) || ts5.isClassDeclaration(decl))) {
3238
+ if (decl && (ts6.isTypeAliasDeclaration(decl) || ts6.isInterfaceDeclaration(decl) || ts6.isClassDeclaration(decl))) {
3151
3239
  typeParameters = extractTypeParameters(decl, checker);
3152
3240
  }
3153
3241
  return {
3154
- id: name,
3242
+ id,
3155
3243
  name,
3156
3244
  kind,
3157
3245
  ...typeParameters && typeParameters.length > 0 ? { typeParameters } : {},
@@ -3168,14 +3256,14 @@ class TypeRegistry {
3168
3256
  resolveSelRefSchema(type, checker, ctx) {
3169
3257
  if (type.isUnion()) {
3170
3258
  const types = type.types;
3171
- const allStringLiterals = types.every((t) => t.flags & ts5.TypeFlags.StringLiteral);
3259
+ const allStringLiterals = types.every((t) => t.flags & ts6.TypeFlags.StringLiteral);
3172
3260
  if (allStringLiterals) {
3173
3261
  return {
3174
3262
  type: "string",
3175
3263
  enum: types.map((t) => t.value)
3176
3264
  };
3177
3265
  }
3178
- const allNumberLiterals = types.every((t) => t.flags & ts5.TypeFlags.NumberLiteral);
3266
+ const allNumberLiterals = types.every((t) => t.flags & ts6.TypeFlags.NumberLiteral);
3179
3267
  if (allNumberLiterals) {
3180
3268
  return {
3181
3269
  type: "number",
@@ -3210,18 +3298,18 @@ class TypeRegistry {
3210
3298
  const elementType = checker.getTypeArguments(type)?.[0];
3211
3299
  return elementType ? { type: "array", items: buildSchema(elementType, checker, ctx) } : { type: "array" };
3212
3300
  }
3213
- if (type.flags & ts5.TypeFlags.Conditional) {
3301
+ if (type.flags & ts6.TypeFlags.Conditional) {
3214
3302
  return { "x-ts-type": renderTypeText(type, checker) };
3215
3303
  }
3216
3304
  const constraint = checker.getBaseConstraintOfType(type);
3217
- const primitive = constraint && constraint.flags & ts5.TypeFlags.StringLike ? "string" : constraint && constraint.flags & ts5.TypeFlags.NumberLike ? "number" : constraint && constraint.flags & ts5.TypeFlags.BooleanLike ? "boolean" : undefined;
3305
+ const primitive = constraint && constraint.flags & ts6.TypeFlags.StringLike ? "string" : constraint && constraint.flags & ts6.TypeFlags.NumberLike ? "number" : constraint && constraint.flags & ts6.TypeFlags.BooleanLike ? "boolean" : undefined;
3218
3306
  if (primitive) {
3219
3307
  return { type: primitive, "x-ts-type": renderTypeText(type, checker) };
3220
3308
  }
3221
3309
  return this.buildObjectSchemaFromProperties(type, checker, ctx);
3222
3310
  }
3223
3311
  buildEnumSchema(symbol, checker) {
3224
- const decl = symbol.declarations?.find(ts5.isEnumDeclaration);
3312
+ const decl = symbol.declarations?.find(ts6.isEnumDeclaration);
3225
3313
  if (!decl)
3226
3314
  return;
3227
3315
  const members = [];
@@ -3248,8 +3336,8 @@ class TypeRegistry {
3248
3336
  buildObjectSchemaFromProperties(type, checker, ctx) {
3249
3337
  const properties = type.getProperties();
3250
3338
  const indexInfos = checker.getIndexInfosOfType(type);
3251
- const stringIndex = indexInfos.find((i) => i.keyType.flags & ts5.TypeFlags.String);
3252
- const numberIndex = indexInfos.find((i) => i.keyType.flags & ts5.TypeFlags.Number);
3339
+ const stringIndex = indexInfos.find((i) => i.keyType.flags & ts6.TypeFlags.String);
3340
+ const numberIndex = indexInfos.find((i) => i.keyType.flags & ts6.TypeFlags.Number);
3253
3341
  if (properties.length === 0 && !stringIndex && !numberIndex) {
3254
3342
  return { type: checker.typeToString(type) };
3255
3343
  }
@@ -3257,8 +3345,8 @@ class TypeRegistry {
3257
3345
  const required = [];
3258
3346
  const limit = ctx.maxProperties;
3259
3347
  const isArrayLike = checker.isArrayType(type) || checker.isTupleType(type) || type.symbol?.getName() === "Array" && type.symbol?.getDeclarations()?.[0]?.getSourceFile()?.fileName?.includes("/typescript/lib/lib.");
3260
- const isStringLike = type.flags & ts5.TypeFlags.StringLike;
3261
- const isNumberLike = type.flags & ts5.TypeFlags.NumberLike;
3348
+ const isStringLike = type.flags & ts6.TypeFlags.StringLike;
3349
+ const isNumberLike = type.flags & ts6.TypeFlags.NumberLike;
3262
3350
  const included = properties.filter((prop) => {
3263
3351
  const propName = prop.getName();
3264
3352
  if (propName.startsWith("__@"))
@@ -3278,7 +3366,7 @@ class TypeRegistry {
3278
3366
  for (const prop of included.slice(0, limit)) {
3279
3367
  const propName = prop.getName();
3280
3368
  const rawPropType = checker.getTypeOfSymbol(prop);
3281
- const propType = prop.flags & ts5.SymbolFlags.Optional ? stripUndefinedFromType(rawPropType, checker) : rawPropType;
3369
+ const propType = prop.flags & ts6.SymbolFlags.Optional ? stripUndefinedFromType(rawPropType, checker) : rawPropType;
3282
3370
  this.registerType(propType, ctx);
3283
3371
  let propSchema = buildSchema(propType, checker, ctx);
3284
3372
  const docComment = prop.getDocumentationComment(checker);
@@ -3295,7 +3383,7 @@ class TypeRegistry {
3295
3383
  }
3296
3384
  propSchema = decoratePropertySchema(propSchema, prop, propType, checker);
3297
3385
  props[propName] = propSchema;
3298
- if (!(prop.flags & ts5.SymbolFlags.Optional)) {
3386
+ if (!(prop.flags & ts6.SymbolFlags.Optional)) {
3299
3387
  required.push(propName);
3300
3388
  }
3301
3389
  }
@@ -3329,7 +3417,11 @@ function createContext(program, sourceFile, options = {}) {
3329
3417
  includePrivate: options.includePrivate ?? false,
3330
3418
  maxProperties: options.maxProperties ?? 500,
3331
3419
  onTruncation: options.onTruncation,
3332
- shouldExpandExternal: options.shouldExpandExternal
3420
+ shouldExpandExternal: options.shouldExpandExternal,
3421
+ typeIds: new Map,
3422
+ declIds: new Map,
3423
+ idOwner: new Map,
3424
+ workspacePackages: options.workspacePackages ?? new Map
3333
3425
  };
3334
3426
  }
3335
3427
  function getInheritedMembers(classType, ownMemberNames, ctx, isStatic = false) {
@@ -3398,15 +3490,15 @@ function serializeInheritedMember(symbol, inheritedFrom, ctx, isStatic) {
3398
3490
  const type = checker.getTypeOfSymbol(symbol);
3399
3491
  registerReferencedTypes(type, ctx);
3400
3492
  let visibility;
3401
- if (decl && ts6.canHaveModifiers(decl)) {
3402
- const modifiers = ts6.getModifiers(decl);
3493
+ if (decl && ts7.canHaveModifiers(decl)) {
3494
+ const modifiers = ts7.getModifiers(decl);
3403
3495
  if (modifiers) {
3404
3496
  for (const mod of modifiers) {
3405
- if (mod.kind === ts6.SyntaxKind.PrivateKeyword)
3497
+ if (mod.kind === ts7.SyntaxKind.PrivateKeyword)
3406
3498
  visibility = "private";
3407
- else if (mod.kind === ts6.SyntaxKind.ProtectedKeyword)
3499
+ else if (mod.kind === ts7.SyntaxKind.ProtectedKeyword)
3408
3500
  visibility = "protected";
3409
- else if (mod.kind === ts6.SyntaxKind.PublicKeyword)
3501
+ else if (mod.kind === ts7.SyntaxKind.PublicKeyword)
3410
3502
  visibility = "public";
3411
3503
  }
3412
3504
  }
@@ -3418,17 +3510,17 @@ function serializeInheritedMember(symbol, inheritedFrom, ctx, isStatic) {
3418
3510
  const callSigs = type.getCallSignatures();
3419
3511
  if (callSigs.length > 0) {
3420
3512
  kind = "method";
3421
- } else if (ts6.isGetAccessorDeclaration(decl)) {
3513
+ } else if (ts7.isGetAccessorDeclaration(decl)) {
3422
3514
  kind = "getter";
3423
- } else if (ts6.isSetAccessorDeclaration(decl)) {
3515
+ } else if (ts7.isSetAccessorDeclaration(decl)) {
3424
3516
  kind = "setter";
3425
3517
  }
3426
3518
  const flags = {};
3427
3519
  if (isStatic)
3428
3520
  flags.static = true;
3429
- if (decl && ts6.canHaveModifiers(decl)) {
3430
- const modifiers = ts6.getModifiers(decl);
3431
- if (modifiers?.some((m) => m.kind === ts6.SyntaxKind.ReadonlyKeyword)) {
3521
+ if (decl && ts7.canHaveModifiers(decl)) {
3522
+ const modifiers = ts7.getModifiers(decl);
3523
+ if (modifiers?.some((m) => m.kind === ts7.SyntaxKind.ReadonlyKeyword)) {
3432
3524
  flags.readonly = true;
3433
3525
  }
3434
3526
  }
@@ -3505,11 +3597,11 @@ function serializeClass(node, ctx) {
3505
3597
  const memberName = getMemberName(member);
3506
3598
  if (memberName?.startsWith("#"))
3507
3599
  continue;
3508
- if (ts7.isPropertyDeclaration(member)) {
3600
+ if (ts8.isPropertyDeclaration(member)) {
3509
3601
  const propMember = serializeProperty(member, ctx);
3510
3602
  if (propMember)
3511
3603
  members.push(propMember);
3512
- } else if (ts7.isMethodDeclaration(member)) {
3604
+ } else if (ts8.isMethodDeclaration(member)) {
3513
3605
  const methodMember = serializeMethod(member, ctx);
3514
3606
  if (methodMember?.name) {
3515
3607
  if (!methodsByName.has(methodMember.name)) {
@@ -3526,11 +3618,11 @@ function serializeClass(node, ctx) {
3526
3618
  }
3527
3619
  }
3528
3620
  }
3529
- } else if (ts7.isConstructorDeclaration(member)) {
3621
+ } else if (ts8.isConstructorDeclaration(member)) {
3530
3622
  const ctorSig = serializeConstructor(member, ctx);
3531
3623
  if (ctorSig)
3532
3624
  signatures.push(ctorSig);
3533
- } else if (ts7.isGetAccessorDeclaration(member) || ts7.isSetAccessorDeclaration(member)) {
3625
+ } else if (ts8.isGetAccessorDeclaration(member) || ts8.isSetAccessorDeclaration(member)) {
3534
3626
  const accessorMember = serializeAccessor(member, ctx);
3535
3627
  if (accessorMember)
3536
3628
  members.push(accessorMember);
@@ -3554,8 +3646,8 @@ function serializeClass(node, ctx) {
3554
3646
  const extendsClause = getExtendsClause(node, checker);
3555
3647
  const implementsClause = getImplementsClause(node, checker);
3556
3648
  const classFlags = {};
3557
- const classModifiers = ts7.getModifiers(node);
3558
- if (classModifiers?.some((m) => m.kind === ts7.SyntaxKind.AbstractKeyword)) {
3649
+ const classModifiers = ts8.getModifiers(node);
3650
+ if (classModifiers?.some((m) => m.kind === ts8.SyntaxKind.AbstractKeyword)) {
3559
3651
  classFlags.abstract = true;
3560
3652
  }
3561
3653
  return {
@@ -3576,37 +3668,37 @@ function serializeClass(node, ctx) {
3576
3668
  };
3577
3669
  }
3578
3670
  function getMemberName(member) {
3579
- if (ts7.isConstructorDeclaration(member))
3671
+ if (ts8.isConstructorDeclaration(member))
3580
3672
  return "constructor";
3581
3673
  if (!member.name)
3582
3674
  return;
3583
- if (ts7.isIdentifier(member.name))
3675
+ if (ts8.isIdentifier(member.name))
3584
3676
  return member.name.text;
3585
- if (ts7.isPrivateIdentifier(member.name))
3677
+ if (ts8.isPrivateIdentifier(member.name))
3586
3678
  return member.name.text;
3587
3679
  return member.name.getText();
3588
3680
  }
3589
3681
  function getVisibility(member) {
3590
- const modifiers = ts7.canHaveModifiers(member) ? ts7.getModifiers(member) : undefined;
3682
+ const modifiers = ts8.canHaveModifiers(member) ? ts8.getModifiers(member) : undefined;
3591
3683
  if (!modifiers)
3592
3684
  return;
3593
3685
  for (const mod of modifiers) {
3594
- if (mod.kind === ts7.SyntaxKind.PrivateKeyword)
3686
+ if (mod.kind === ts8.SyntaxKind.PrivateKeyword)
3595
3687
  return "private";
3596
- if (mod.kind === ts7.SyntaxKind.ProtectedKeyword)
3688
+ if (mod.kind === ts8.SyntaxKind.ProtectedKeyword)
3597
3689
  return "protected";
3598
- if (mod.kind === ts7.SyntaxKind.PublicKeyword)
3690
+ if (mod.kind === ts8.SyntaxKind.PublicKeyword)
3599
3691
  return "public";
3600
3692
  }
3601
3693
  return;
3602
3694
  }
3603
3695
  function isStatic(member) {
3604
- const modifiers = ts7.canHaveModifiers(member) ? ts7.getModifiers(member) : undefined;
3605
- return modifiers?.some((m) => m.kind === ts7.SyntaxKind.StaticKeyword) ?? false;
3696
+ const modifiers = ts8.canHaveModifiers(member) ? ts8.getModifiers(member) : undefined;
3697
+ return modifiers?.some((m) => m.kind === ts8.SyntaxKind.StaticKeyword) ?? false;
3606
3698
  }
3607
3699
  function isReadonly(member) {
3608
- const modifiers = ts7.canHaveModifiers(member) ? ts7.getModifiers(member) : undefined;
3609
- return modifiers?.some((m) => m.kind === ts7.SyntaxKind.ReadonlyKeyword) ?? false;
3700
+ const modifiers = ts8.canHaveModifiers(member) ? ts8.getModifiers(member) : undefined;
3701
+ return modifiers?.some((m) => m.kind === ts8.SyntaxKind.ReadonlyKeyword) ?? false;
3610
3702
  }
3611
3703
  function serializeProperty(node, ctx) {
3612
3704
  const { typeChecker: checker } = ctx;
@@ -3664,11 +3756,11 @@ function serializeMethod(node, ctx) {
3664
3756
  if (node.asteriskToken)
3665
3757
  flags.generator = true;
3666
3758
  flags.methodSyntax = true;
3667
- const modifiers = ts7.getModifiers(node);
3668
- if (modifiers?.some((m) => m.kind === ts7.SyntaxKind.AsyncKeyword)) {
3759
+ const modifiers = ts8.getModifiers(node);
3760
+ if (modifiers?.some((m) => m.kind === ts8.SyntaxKind.AsyncKeyword)) {
3669
3761
  flags.async = true;
3670
3762
  }
3671
- if (modifiers?.some((m) => m.kind === ts7.SyntaxKind.AbstractKeyword)) {
3763
+ if (modifiers?.some((m) => m.kind === ts8.SyntaxKind.AbstractKeyword)) {
3672
3764
  flags.abstract = true;
3673
3765
  }
3674
3766
  const symbol = checker.getSymbolAtLocation(node.name ?? node);
@@ -3705,7 +3797,7 @@ function serializeConstructorSignature(node, sig, ctx) {
3705
3797
  }
3706
3798
  function serializeInheritedConstructors(node, ctx) {
3707
3799
  const { typeChecker: checker } = ctx;
3708
- const hasExtends = node.heritageClauses?.some((c) => c.token === ts7.SyntaxKind.ExtendsKeyword);
3800
+ const hasExtends = node.heritageClauses?.some((c) => c.token === ts8.SyntaxKind.ExtendsKeyword);
3709
3801
  if (!hasExtends)
3710
3802
  return [];
3711
3803
  const symbol = checker.getSymbolAtLocation(node.name ?? node);
@@ -3714,11 +3806,11 @@ function serializeInheritedConstructors(node, ctx) {
3714
3806
  const staticType = checker.getTypeOfSymbolAtLocation(symbol, node);
3715
3807
  const ctorSigs = staticType.getConstructSignatures().filter((sig) => {
3716
3808
  const decl = sig.getDeclaration();
3717
- return decl !== undefined && ts7.isConstructorDeclaration(decl);
3809
+ return decl !== undefined && ts8.isConstructorDeclaration(decl);
3718
3810
  });
3719
3811
  return ctorSigs.map((sig, index) => {
3720
3812
  const decl = sig.getDeclaration();
3721
- const owner = ts7.isClassLike(decl.parent) ? decl.parent.name?.text : undefined;
3813
+ const owner = ts8.isClassLike(decl.parent) ? decl.parent.name?.text : undefined;
3722
3814
  return {
3723
3815
  ...serializeConstructorSignature(decl, sig, ctx),
3724
3816
  ...owner ? { inheritedFrom: owner } : {},
@@ -3739,12 +3831,12 @@ function serializeAccessor(node, ctx) {
3739
3831
  const type = checker.getTypeAtLocation(node);
3740
3832
  const schema = buildSchema(type, checker, ctx);
3741
3833
  registerReferencedTypes(type, ctx);
3742
- const kind = ts7.isGetAccessorDeclaration(node) ? "getter" : "setter";
3834
+ const kind = ts8.isGetAccessorDeclaration(node) ? "getter" : "setter";
3743
3835
  const flags = {};
3744
3836
  if (isStatic(node))
3745
3837
  flags.static = true;
3746
3838
  let signatures;
3747
- if (ts7.isSetAccessorDeclaration(node) && node.parameters.length > 0) {
3839
+ if (ts8.isSetAccessorDeclaration(node) && node.parameters.length > 0) {
3748
3840
  const param = node.parameters[0];
3749
3841
  const paramName = param.name.getText();
3750
3842
  const paramType = checker.getTypeAtLocation(param);
@@ -3776,7 +3868,7 @@ function getExtendsClause(node, checker) {
3776
3868
  if (!node.heritageClauses)
3777
3869
  return;
3778
3870
  for (const clause of node.heritageClauses) {
3779
- if (clause.token === ts7.SyntaxKind.ExtendsKeyword) {
3871
+ if (clause.token === ts8.SyntaxKind.ExtendsKeyword) {
3780
3872
  const expr = clause.types[0];
3781
3873
  if (expr) {
3782
3874
  const type = checker.getTypeAtLocation(expr);
@@ -3791,7 +3883,7 @@ function getImplementsClause(node, checker) {
3791
3883
  if (!node.heritageClauses)
3792
3884
  return;
3793
3885
  for (const clause of node.heritageClauses) {
3794
- if (clause.token === ts7.SyntaxKind.ImplementsKeyword) {
3886
+ if (clause.token === ts8.SyntaxKind.ImplementsKeyword) {
3795
3887
  return clause.types.map((expr) => {
3796
3888
  const type = checker.getTypeAtLocation(expr);
3797
3889
  const symbol = type.getSymbol();
@@ -3845,16 +3937,16 @@ function serializeEnum(node, ctx) {
3845
3937
  }
3846
3938
 
3847
3939
  // src/serializers/functions.ts
3848
- import ts8 from "typescript";
3940
+ import ts9 from "typescript";
3849
3941
  function buildReturnSchema(sig, ctx) {
3850
3942
  const returnType = ctx.typeChecker.getReturnTypeOfSignature(sig);
3851
3943
  registerReferencedTypes(returnType, ctx);
3852
3944
  const schema = buildSchema(returnType, ctx.typeChecker, ctx);
3853
3945
  const declaration = sig.getDeclaration();
3854
- if (declaration && ts8.isFunctionLike(declaration) && declaration.type) {
3946
+ if (declaration && ts9.isFunctionLike(declaration) && declaration.type) {
3855
3947
  const returnTypeNode = declaration.type;
3856
- if (ts8.isTypePredicateNode(returnTypeNode)) {
3857
- const parameterName = ts8.isIdentifier(returnTypeNode.parameterName) ? returnTypeNode.parameterName.text : returnTypeNode.parameterName.getText();
3948
+ if (ts9.isTypePredicateNode(returnTypeNode)) {
3949
+ const parameterName = ts9.isIdentifier(returnTypeNode.parameterName) ? returnTypeNode.parameterName.text : returnTypeNode.parameterName.getText();
3858
3950
  let predicateTypeSchema = { type: "unknown" };
3859
3951
  if (returnTypeNode.type) {
3860
3952
  const predicateType = ctx.typeChecker.getTypeAtLocation(returnTypeNode.type);
@@ -3898,8 +3990,8 @@ function serializeFunctionExport(node, ctx, nameOverride) {
3898
3990
  };
3899
3991
  });
3900
3992
  const flags = {};
3901
- const modifiers = ts8.getModifiers(node);
3902
- if (modifiers?.some((m) => m.kind === ts8.SyntaxKind.AsyncKeyword)) {
3993
+ const modifiers = ts9.getModifiers(node);
3994
+ if (modifiers?.some((m) => m.kind === ts9.SyntaxKind.AsyncKeyword)) {
3903
3995
  flags.async = true;
3904
3996
  }
3905
3997
  if (node.asteriskToken) {
@@ -3921,7 +4013,7 @@ function serializeFunctionExport(node, ctx, nameOverride) {
3921
4013
  }
3922
4014
 
3923
4015
  // src/serializers/interfaces.ts
3924
- import ts9 from "typescript";
4016
+ import ts10 from "typescript";
3925
4017
  function serializeInterface(node, ctx) {
3926
4018
  const { typeChecker: checker } = ctx;
3927
4019
  const symbol = checker.getSymbolAtLocation(node.name ?? node);
@@ -3934,11 +4026,11 @@ function serializeInterface(node, ctx) {
3934
4026
  const methodsByName = new Map;
3935
4027
  let callSignatureMember = null;
3936
4028
  for (const member of node.members) {
3937
- if (ts9.isPropertySignature(member)) {
4029
+ if (ts10.isPropertySignature(member)) {
3938
4030
  const propMember = serializePropertySignature(member, ctx);
3939
4031
  if (propMember)
3940
4032
  members.push(propMember);
3941
- } else if (ts9.isMethodSignature(member)) {
4033
+ } else if (ts10.isMethodSignature(member)) {
3942
4034
  const methodMember = serializeMethodSignature(member, ctx);
3943
4035
  if (methodMember?.name && methodMember.signatures) {
3944
4036
  const existing = methodsByName.get(methodMember.name);
@@ -3959,7 +4051,7 @@ function serializeInterface(node, ctx) {
3959
4051
  methodsByName.set(methodMember.name, methodMember);
3960
4052
  }
3961
4053
  }
3962
- } else if (ts9.isCallSignatureDeclaration(member)) {
4054
+ } else if (ts10.isCallSignatureDeclaration(member)) {
3963
4055
  const callSig = serializeCallSignature(member, ctx);
3964
4056
  if (callSig?.signatures) {
3965
4057
  if (callSignatureMember?.signatures) {
@@ -3982,7 +4074,7 @@ function serializeInterface(node, ctx) {
3982
4074
  callSignatureMember = callSig;
3983
4075
  }
3984
4076
  }
3985
- } else if (ts9.isIndexSignatureDeclaration(member)) {
4077
+ } else if (ts10.isIndexSignatureDeclaration(member)) {
3986
4078
  const indexMember = serializeIndexSignature(member, ctx);
3987
4079
  if (indexMember)
3988
4080
  members.push(indexMember);
@@ -4020,7 +4112,7 @@ function serializePropertySignature(node, ctx) {
4020
4112
  const flags = {};
4021
4113
  if (node.questionToken)
4022
4114
  flags.optional = true;
4023
- if (node.modifiers?.some((m) => m.kind === ts9.SyntaxKind.ReadonlyKeyword)) {
4115
+ if (node.modifiers?.some((m) => m.kind === ts10.SyntaxKind.ReadonlyKeyword)) {
4024
4116
  flags.readonly = true;
4025
4117
  }
4026
4118
  const symbol = checker.getSymbolAtLocation(node.name);
@@ -4108,7 +4200,7 @@ function getInterfaceExtends(node, checker) {
4108
4200
  if (!node.heritageClauses)
4109
4201
  return;
4110
4202
  for (const clause of node.heritageClauses) {
4111
- if (clause.token === ts9.SyntaxKind.ExtendsKeyword && clause.types.length > 0) {
4203
+ if (clause.token === ts10.SyntaxKind.ExtendsKeyword && clause.types.length > 0) {
4112
4204
  const names = clause.types.map((expr) => {
4113
4205
  const type = checker.getTypeAtLocation(expr);
4114
4206
  return type.getSymbol()?.getName() ?? expr.expression.getText();
@@ -4120,7 +4212,7 @@ function getInterfaceExtends(node, checker) {
4120
4212
  }
4121
4213
 
4122
4214
  // src/serializers/type-aliases.ts
4123
- import ts10 from "typescript";
4215
+ import ts11 from "typescript";
4124
4216
  function buildIntersectionSchemaFromNode(node, ctx) {
4125
4217
  const types = node.types;
4126
4218
  const schemas = [];
@@ -4148,14 +4240,14 @@ function serializeTypeAlias(node, ctx) {
4148
4240
  registerReferencedTypes(type, ctx);
4149
4241
  let schema;
4150
4242
  let members;
4151
- if (ts10.isIntersectionTypeNode(node.type)) {
4243
+ if (ts11.isIntersectionTypeNode(node.type)) {
4152
4244
  schema = buildIntersectionSchemaFromNode(node.type, ctx);
4153
4245
  if (type.getProperties().length > 0 && type.getCallSignatures().length === 0) {
4154
4246
  members = serializeResolvedMembers(type, node, ctx);
4155
4247
  }
4156
4248
  } else if (isInlineFunctionAlias(node.type) && type.getCallSignatures().length > 0) {
4157
4249
  schema = buildFunctionSchema(type.getCallSignatures(), ctx.typeChecker, ctx);
4158
- } else if ((ts10.isMappedTypeNode(node.type) || ts10.isConditionalTypeNode(node.type)) && type.getProperties().length > 0 && type.getCallSignatures().length === 0 && !(type.flags & ts10.TypeFlags.Conditional) && !(type.flags & (ts10.TypeFlags.StringLike | ts10.TypeFlags.NumberLike))) {
4250
+ } 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))) {
4159
4251
  schema = buildObjectSchema(type.getProperties(), ctx.typeChecker, ctx, type);
4160
4252
  members = serializeResolvedMembers(type, node, ctx);
4161
4253
  } else {
@@ -4165,7 +4257,7 @@ function serializeTypeAlias(node, ctx) {
4165
4257
  }
4166
4258
  }
4167
4259
  if (shouldEmitAliasTypeText(node.type) && typeof schema === "object" && schema !== null && !("x-ts-type" in schema)) {
4168
- const text = renderTypeText(type, ctx.typeChecker, node, ts10.TypeFormatFlags.InTypeAlias);
4260
+ const text = renderTypeText(type, ctx.typeChecker, node, ts11.TypeFormatFlags.InTypeAlias);
4169
4261
  if (!PRIMITIVES.has(text) && text !== name) {
4170
4262
  schema["x-ts-type"] = text;
4171
4263
  }
@@ -4186,12 +4278,12 @@ function serializeTypeAlias(node, ctx) {
4186
4278
  }
4187
4279
  function isObjectShapedAlias(type, ctx) {
4188
4280
  const { typeChecker: checker } = ctx;
4189
- if (!(type.flags & ts10.TypeFlags.Object))
4281
+ if (!(type.flags & ts11.TypeFlags.Object))
4190
4282
  return false;
4191
4283
  if (checker.isArrayType(type) || checker.isTupleType(type))
4192
4284
  return false;
4193
4285
  const objectFlags = type.objectFlags;
4194
- if (!(objectFlags & ts10.ObjectFlags.Mapped)) {
4286
+ if (!(objectFlags & ts11.ObjectFlags.Mapped)) {
4195
4287
  const targetSymbol = type.target?.getSymbol?.() ?? type.getSymbol();
4196
4288
  if (isBuiltinSymbol(targetSymbol))
4197
4289
  return false;
@@ -4199,19 +4291,19 @@ function isObjectShapedAlias(type, ctx) {
4199
4291
  return type.getProperties().length > 0 && type.getCallSignatures().length === 0;
4200
4292
  }
4201
4293
  function isInlineFunctionAlias(typeNode) {
4202
- return ts10.isFunctionTypeNode(typeNode) || ts10.isTypeLiteralNode(typeNode) && typeNode.members.some(ts10.isCallSignatureDeclaration);
4294
+ return ts11.isFunctionTypeNode(typeNode) || ts11.isTypeLiteralNode(typeNode) && typeNode.members.some(ts11.isCallSignatureDeclaration);
4203
4295
  }
4204
4296
  function buildConditionalArmDocs(typeNode, checker) {
4205
4297
  const docs = new Map;
4206
- if (!ts10.isMappedTypeNode(typeNode) || !typeNode.type)
4298
+ if (!ts11.isMappedTypeNode(typeNode) || !typeNode.type)
4207
4299
  return docs;
4208
4300
  const literalKeys = (extendsType) => {
4209
4301
  const keys = [];
4210
4302
  const visit = (n) => {
4211
- if (ts10.isUnionTypeNode(n)) {
4303
+ if (ts11.isUnionTypeNode(n)) {
4212
4304
  for (const member of n.types)
4213
4305
  visit(member);
4214
- } else if (ts10.isLiteralTypeNode(n) && ts10.isStringLiteral(n.literal)) {
4306
+ } else if (ts11.isLiteralTypeNode(n) && ts11.isStringLiteral(n.literal)) {
4215
4307
  keys.push(n.literal.text);
4216
4308
  }
4217
4309
  };
@@ -4219,12 +4311,12 @@ function buildConditionalArmDocs(typeNode, checker) {
4219
4311
  return keys;
4220
4312
  };
4221
4313
  const armDoc = (armType) => {
4222
- if (!ts10.isTypeReferenceNode(armType))
4314
+ if (!ts11.isTypeReferenceNode(armType))
4223
4315
  return;
4224
4316
  const symbol = checker.getSymbolAtLocation(armType.typeName);
4225
4317
  if (!symbol)
4226
4318
  return;
4227
- const target = symbol.flags & ts10.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
4319
+ const target = symbol.flags & ts11.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
4228
4320
  const { deprecated, reason } = isSymbolDeprecated(target);
4229
4321
  const targetDecl = target.getDeclarations()?.[0];
4230
4322
  const description = targetDecl ? getJSDocComment(targetDecl, target, checker).description : undefined;
@@ -4233,7 +4325,7 @@ function buildConditionalArmDocs(typeNode, checker) {
4233
4325
  return { deprecated, deprecationReason: reason, description };
4234
4326
  };
4235
4327
  let current = typeNode.type;
4236
- while (current && ts10.isConditionalTypeNode(current)) {
4328
+ while (current && ts11.isConditionalTypeNode(current)) {
4237
4329
  const doc = armDoc(current.trueType);
4238
4330
  if (doc) {
4239
4331
  for (const key of literalKeys(current.extendsType)) {
@@ -4252,10 +4344,10 @@ function serializeResolvedMembers(type, node, ctx) {
4252
4344
  for (const prop of type.getProperties()) {
4253
4345
  const decl = prop.getDeclarations()?.[0] ?? node;
4254
4346
  const rawPropType = checker.getTypeOfSymbolAtLocation(prop, decl);
4255
- const propType = prop.flags & ts10.SymbolFlags.Optional ? stripUndefinedFromType(rawPropType, checker) : rawPropType;
4347
+ const propType = prop.flags & ts11.SymbolFlags.Optional ? stripUndefinedFromType(rawPropType, checker) : rawPropType;
4256
4348
  registerReferencedTypes(propType, ctx);
4257
4349
  const callSigs = propType.getCallSignatures();
4258
- const isMethodDecl = ts10.isMethodSignature(decl) || ts10.isMethodDeclaration(decl) || ts10.isFunctionDeclaration(decl);
4350
+ const isMethodDecl = ts11.isMethodSignature(decl) || ts11.isMethodDeclaration(decl) || ts11.isFunctionDeclaration(decl);
4259
4351
  const kind = callSigs.length > 0 && isMethodDecl ? "method" : "property";
4260
4352
  let { description, tags } = getJSDocComment(decl, prop, checker);
4261
4353
  let { deprecated, reason: deprecationReason } = isSymbolDeprecated(prop);
@@ -4273,11 +4365,11 @@ function serializeResolvedMembers(type, node, ctx) {
4273
4365
  ({ deprecated, reason: deprecationReason } = isSymbolDeprecated(armAlias));
4274
4366
  }
4275
4367
  const flags = {};
4276
- if (prop.flags & ts10.SymbolFlags.Optional)
4368
+ if (prop.flags & ts11.SymbolFlags.Optional)
4277
4369
  flags.optional = true;
4278
4370
  if (isReadonlyPropertySymbol(prop))
4279
4371
  flags.readonly = true;
4280
- if (prop.flags & ts10.SymbolFlags.Method)
4372
+ if (prop.flags & ts11.SymbolFlags.Method)
4281
4373
  flags.methodSyntax = true;
4282
4374
  const schema = kind === "property" ? decoratePropertySchema(buildSchema(propType, checker, ctx), prop, propType, checker) : decoratePropertySchema({ "x-ts-function": true }, prop, propType, checker);
4283
4375
  members.push({
@@ -5055,7 +5147,7 @@ async function getExport(options) {
5055
5147
  ctx.exportedIds = exportedIds;
5056
5148
  try {
5057
5149
  const originalDecls = targetSymbol.declarations ?? [];
5058
- const isNamespaceExportDecl = originalDecls.some((d) => ts11.isNamespaceExport(d) || ts11.isNamespaceImport(d));
5150
+ const isNamespaceExportDecl = originalDecls.some((d) => ts12.isNamespaceExport(d) || ts12.isNamespaceImport(d));
5059
5151
  if (isNamespaceExportDecl) {
5060
5152
  const spec2 = serializeNamespaceForGet(targetSymbol, exportName, ctx);
5061
5153
  const types2 = ctx.typeRegistry.getAll().map((t) => normalizeType(t));
@@ -5106,42 +5198,42 @@ function resolveExportTarget(symbol, checker) {
5106
5198
  let isTypeOnly = false;
5107
5199
  const declarations = symbol.declarations ?? [];
5108
5200
  for (const decl of declarations) {
5109
- if (ts11.isExportSpecifier(decl)) {
5201
+ if (ts12.isExportSpecifier(decl)) {
5110
5202
  if (decl.isTypeOnly)
5111
5203
  isTypeOnly = true;
5112
5204
  const exportDecl = decl.parent?.parent;
5113
- if (exportDecl && ts11.isExportDeclaration(exportDecl) && exportDecl.isTypeOnly) {
5205
+ if (exportDecl && ts12.isExportDeclaration(exportDecl) && exportDecl.isTypeOnly) {
5114
5206
  isTypeOnly = true;
5115
5207
  }
5116
5208
  }
5117
5209
  }
5118
- if (symbol.flags & ts11.SymbolFlags.Alias) {
5210
+ if (symbol.flags & ts12.SymbolFlags.Alias) {
5119
5211
  const aliased = checker.getAliasedSymbol(symbol);
5120
5212
  if (aliased && aliased !== symbol) {
5121
5213
  resolvedSymbol = aliased;
5122
5214
  }
5123
5215
  }
5124
5216
  const targetDeclarations = resolvedSymbol.declarations ?? [];
5125
- const declaration = resolvedSymbol.valueDeclaration || targetDeclarations.find((d) => d.kind !== ts11.SyntaxKind.ExportSpecifier) || targetDeclarations[0];
5217
+ const declaration = resolvedSymbol.valueDeclaration || targetDeclarations.find((d) => d.kind !== ts12.SyntaxKind.ExportSpecifier) || targetDeclarations[0];
5126
5218
  return { declaration, resolvedSymbol, isTypeOnly };
5127
5219
  }
5128
5220
  function serializeDeclaration(declaration, _exportSymbol, _targetSymbol, exportName, ctx, isTypeOnly) {
5129
5221
  let result = null;
5130
- if (ts11.isFunctionDeclaration(declaration)) {
5222
+ if (ts12.isFunctionDeclaration(declaration)) {
5131
5223
  result = serializeFunctionExport(declaration, ctx);
5132
- } else if (ts11.isClassDeclaration(declaration)) {
5224
+ } else if (ts12.isClassDeclaration(declaration)) {
5133
5225
  result = serializeClass(declaration, ctx);
5134
- } else if (ts11.isInterfaceDeclaration(declaration)) {
5226
+ } else if (ts12.isInterfaceDeclaration(declaration)) {
5135
5227
  result = serializeInterface(declaration, ctx);
5136
- } else if (ts11.isTypeAliasDeclaration(declaration)) {
5228
+ } else if (ts12.isTypeAliasDeclaration(declaration)) {
5137
5229
  result = serializeTypeAlias(declaration, ctx);
5138
- } else if (ts11.isEnumDeclaration(declaration)) {
5230
+ } else if (ts12.isEnumDeclaration(declaration)) {
5139
5231
  result = serializeEnum(declaration, ctx);
5140
- } else if (ts11.isVariableDeclaration(declaration)) {
5232
+ } else if (ts12.isVariableDeclaration(declaration)) {
5141
5233
  const varStatement = declaration.parent?.parent;
5142
- if (varStatement && ts11.isVariableStatement(varStatement)) {
5143
- if (declaration.initializer && (ts11.isArrowFunction(declaration.initializer) || ts11.isFunctionExpression(declaration.initializer))) {
5144
- const varName = ts11.isIdentifier(declaration.name) ? declaration.name.text : declaration.name.getText();
5234
+ if (varStatement && ts12.isVariableStatement(varStatement)) {
5235
+ if (declaration.initializer && (ts12.isArrowFunction(declaration.initializer) || ts12.isFunctionExpression(declaration.initializer))) {
5236
+ const varName = ts12.isIdentifier(declaration.name) ? declaration.name.text : declaration.name.getText();
5145
5237
  result = serializeFunctionExport(declaration.initializer, ctx, varName);
5146
5238
  } else {
5147
5239
  const checker = ctx.program.getTypeChecker();
@@ -5155,7 +5247,7 @@ function serializeDeclaration(declaration, _exportSymbol, _targetSymbol, exportN
5155
5247
  }
5156
5248
  }
5157
5249
  }
5158
- } else if (ts11.isNamespaceExport(declaration) || ts11.isModuleDeclaration(declaration) || ts11.isNamespaceImport(declaration) || ts11.isSourceFile(declaration)) {
5250
+ } else if (ts12.isNamespaceExport(declaration) || ts12.isModuleDeclaration(declaration) || ts12.isNamespaceImport(declaration) || ts12.isSourceFile(declaration)) {
5159
5251
  result = serializeNamespaceForGet(_exportSymbol, exportName, ctx);
5160
5252
  }
5161
5253
  if (result) {
@@ -5171,7 +5263,7 @@ function serializeDeclaration(declaration, _exportSymbol, _targetSymbol, exportN
5171
5263
  function serializeNamespaceForGet(symbol, exportName, ctx) {
5172
5264
  const checker = ctx.program.getTypeChecker();
5173
5265
  let targetSymbol = symbol;
5174
- if (symbol.flags & ts11.SymbolFlags.Alias) {
5266
+ if (symbol.flags & ts12.SymbolFlags.Alias) {
5175
5267
  const aliased = checker.getAliasedSymbol(symbol);
5176
5268
  if (aliased && aliased !== symbol) {
5177
5269
  targetSymbol = aliased;
@@ -5201,7 +5293,7 @@ function serializeNamespaceForGet(symbol, exportName, ctx) {
5201
5293
  }
5202
5294
  function detectExternalPackage(symbol, checker) {
5203
5295
  let targetSymbol = symbol;
5204
- if (symbol.flags & ts11.SymbolFlags.Alias) {
5296
+ if (symbol.flags & ts12.SymbolFlags.Alias) {
5205
5297
  const aliased = checker.getAliasedSymbol(symbol);
5206
5298
  if (aliased && aliased !== symbol) {
5207
5299
  targetSymbol = aliased;
@@ -5215,9 +5307,9 @@ function detectExternalPackage(symbol, checker) {
5215
5307
  if (match)
5216
5308
  return match[1];
5217
5309
  }
5218
- if (ts11.isExportSpecifier(decl)) {
5310
+ if (ts12.isExportSpecifier(decl)) {
5219
5311
  const exportDecl = decl.parent?.parent;
5220
- if (exportDecl && ts11.isExportDeclaration(exportDecl) && exportDecl.moduleSpecifier) {
5312
+ if (exportDecl && ts12.isExportDeclaration(exportDecl) && exportDecl.moduleSpecifier) {
5221
5313
  const moduleText = exportDecl.moduleSpecifier.text;
5222
5314
  if (!moduleText.startsWith(".") && !moduleText.startsWith("/")) {
5223
5315
  return moduleText;
@@ -5228,8 +5320,8 @@ function detectExternalPackage(symbol, checker) {
5228
5320
  return;
5229
5321
  }
5230
5322
  // src/primitives/list.ts
5231
- import * as path4 from "node:path";
5232
- import ts12 from "typescript";
5323
+ import * as path5 from "node:path";
5324
+ import ts13 from "typescript";
5233
5325
  async function listExports(options) {
5234
5326
  const { entryFile, baseDir, content } = options;
5235
5327
  const errors = [];
@@ -5272,16 +5364,16 @@ async function listExports(options) {
5272
5364
  }
5273
5365
  function extractExportItem(symbol, checker, entryFile, entrySourceFile) {
5274
5366
  const name = symbol.getName();
5275
- const isReexport = !!(symbol.flags & ts12.SymbolFlags.Alias);
5367
+ const isReexport = !!(symbol.flags & ts13.SymbolFlags.Alias);
5276
5368
  let targetSymbol = symbol;
5277
- if (symbol.flags & ts12.SymbolFlags.Alias) {
5369
+ if (symbol.flags & ts13.SymbolFlags.Alias) {
5278
5370
  const aliased = checker.getAliasedSymbol(symbol);
5279
5371
  if (aliased && aliased !== symbol) {
5280
5372
  targetSymbol = aliased;
5281
5373
  }
5282
5374
  }
5283
5375
  const declarations = targetSymbol.declarations ?? [];
5284
- const declaration = targetSymbol.valueDeclaration || declarations.find((d) => d.kind !== ts12.SyntaxKind.ExportSpecifier) || declarations[0];
5376
+ const declaration = targetSymbol.valueDeclaration || declarations.find((d) => d.kind !== ts13.SyntaxKind.ExportSpecifier) || declarations[0];
5285
5377
  if (!declaration) {
5286
5378
  return {
5287
5379
  name,
@@ -5291,11 +5383,11 @@ function extractExportItem(symbol, checker, entryFile, entrySourceFile) {
5291
5383
  reexport: true
5292
5384
  };
5293
5385
  }
5294
- if (ts12.isSourceFile(declaration)) {
5386
+ if (ts13.isSourceFile(declaration)) {
5295
5387
  return {
5296
5388
  name,
5297
5389
  kind: "namespace",
5298
- file: path4.relative(path4.dirname(entryFile), declaration.fileName),
5390
+ file: path5.relative(path5.dirname(entryFile), declaration.fileName),
5299
5391
  line: 1,
5300
5392
  reexport: true
5301
5393
  };
@@ -5309,7 +5401,7 @@ function extractExportItem(symbol, checker, entryFile, entrySourceFile) {
5309
5401
  return {
5310
5402
  name,
5311
5403
  kind,
5312
- file: path4.relative(path4.dirname(entryFile), sourceFile.fileName),
5404
+ file: path5.relative(path5.dirname(entryFile), sourceFile.fileName),
5313
5405
  line: line + 1,
5314
5406
  ...description ? { description } : {},
5315
5407
  ...deprecated ? { deprecated: true } : {},
@@ -5330,21 +5422,21 @@ function getDescriptionPreview(symbol, checker) {
5330
5422
  return `${firstLine.slice(0, 77)}...`;
5331
5423
  }
5332
5424
  // src/builder/spec-builder.ts
5333
- import * as fs7 from "node:fs";
5425
+ import * as fs6 from "node:fs";
5334
5426
  import * as path9 from "node:path";
5335
5427
  import { SCHEMA_URL, SCHEMA_VERSION } from "@openpkg-ts/spec";
5336
- import ts17 from "typescript";
5428
+ import ts18 from "typescript";
5337
5429
 
5338
5430
  // src/ast/resolve.ts
5339
- import ts13 from "typescript";
5431
+ import ts14 from "typescript";
5340
5432
  function isTypeOnlyExport(symbol) {
5341
5433
  const declarations = symbol.declarations ?? [];
5342
5434
  for (const decl of declarations) {
5343
- if (ts13.isExportSpecifier(decl)) {
5435
+ if (ts14.isExportSpecifier(decl)) {
5344
5436
  if (decl.isTypeOnly)
5345
5437
  return true;
5346
5438
  const exportDecl = decl.parent?.parent;
5347
- if (exportDecl && ts13.isExportDeclaration(exportDecl) && exportDecl.isTypeOnly) {
5439
+ if (exportDecl && ts14.isExportDeclaration(exportDecl) && exportDecl.isTypeOnly) {
5348
5440
  return true;
5349
5441
  }
5350
5442
  }
@@ -5354,14 +5446,14 @@ function isTypeOnlyExport(symbol) {
5354
5446
  function resolveExportTarget2(symbol, checker) {
5355
5447
  let targetSymbol = symbol;
5356
5448
  const isTypeOnly = isTypeOnlyExport(symbol);
5357
- if (symbol.flags & ts13.SymbolFlags.Alias) {
5449
+ if (symbol.flags & ts14.SymbolFlags.Alias) {
5358
5450
  const aliasTarget = checker.getAliasedSymbol(symbol);
5359
5451
  if (aliasTarget && aliasTarget !== symbol) {
5360
5452
  targetSymbol = aliasTarget;
5361
5453
  }
5362
5454
  }
5363
5455
  const declarations = targetSymbol.declarations ?? [];
5364
- const declaration = targetSymbol.valueDeclaration || declarations.find((decl) => decl.kind !== ts13.SyntaxKind.ExportSpecifier) || declarations[0];
5456
+ const declaration = targetSymbol.valueDeclaration || declarations.find((decl) => decl.kind !== ts14.SyntaxKind.ExportSpecifier) || declarations[0];
5365
5457
  return { declaration, targetSymbol, isTypeOnly };
5366
5458
  }
5367
5459
 
@@ -5369,7 +5461,7 @@ function resolveExportTarget2(symbol, checker) {
5369
5461
  import { spawn, spawnSync } from "node:child_process";
5370
5462
  import * as fs4 from "node:fs";
5371
5463
  import * as os from "node:os";
5372
- import * as path5 from "node:path";
5464
+ import * as path6 from "node:path";
5373
5465
  var MAX_BUFFER_SIZE = 10 * 1024 * 1024;
5374
5466
  function isStandardJSONSchema(obj) {
5375
5467
  if (typeof obj !== "object" || obj === null)
@@ -5628,16 +5720,16 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
5628
5720
  return result;
5629
5721
  }
5630
5722
  const tempDir = os.tmpdir();
5631
- const workerPath = path5.join(tempDir, `openpkg-extract-worker-${Date.now()}.ts`);
5723
+ const workerPath = path6.join(tempDir, `openpkg-extract-worker-${Date.now()}.ts`);
5632
5724
  try {
5633
5725
  fs4.writeFileSync(workerPath, TS_WORKER_SCRIPT);
5634
5726
  const optionsJson = JSON.stringify({ target, libraryOptions });
5635
5727
  const args = [...runtime.args, workerPath, tsFilePath, optionsJson];
5636
- return await new Promise((resolve2) => {
5728
+ return await new Promise((resolve3) => {
5637
5729
  const child = spawn(runtime.cmd, args, {
5638
5730
  timeout,
5639
5731
  stdio: ["ignore", "pipe", "pipe"],
5640
- cwd: path5.dirname(tsFilePath)
5732
+ cwd: path6.dirname(tsFilePath)
5641
5733
  });
5642
5734
  let stdout = "";
5643
5735
  let stderr = "";
@@ -5669,14 +5761,14 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
5669
5761
  }
5670
5762
  if (code !== 0) {
5671
5763
  result.errors.push(`Extraction failed (${runtime.name}): ${stderr || `exit code ${code}`}`);
5672
- resolve2(result);
5764
+ resolve3(result);
5673
5765
  return;
5674
5766
  }
5675
5767
  try {
5676
5768
  const parsed = JSON.parse(stdout);
5677
5769
  if (!parsed.success) {
5678
5770
  result.errors.push(`Extraction failed: ${parsed.error}`);
5679
- resolve2(result);
5771
+ resolve3(result);
5680
5772
  return;
5681
5773
  }
5682
5774
  for (const item of parsed.results) {
@@ -5711,7 +5803,7 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
5711
5803
  message: "stderr exceeded 10MB buffer limit"
5712
5804
  });
5713
5805
  }
5714
- resolve2(result);
5806
+ resolve3(result);
5715
5807
  });
5716
5808
  child.on("error", (err) => {
5717
5809
  try {
@@ -5722,7 +5814,7 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
5722
5814
  }
5723
5815
  }
5724
5816
  result.errors.push(`Subprocess error: ${err.message}`);
5725
- resolve2(result);
5817
+ resolve3(result);
5726
5818
  });
5727
5819
  });
5728
5820
  } catch (e) {
@@ -5738,7 +5830,7 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
5738
5830
  }
5739
5831
  }
5740
5832
  function readTsconfigOutDir(baseDir) {
5741
- const tsconfigPath = path5.join(baseDir, "tsconfig.json");
5833
+ const tsconfigPath = path6.join(baseDir, "tsconfig.json");
5742
5834
  try {
5743
5835
  if (!fs4.existsSync(tsconfigPath)) {
5744
5836
  return null;
@@ -5753,7 +5845,7 @@ function readTsconfigOutDir(baseDir) {
5753
5845
  return null;
5754
5846
  }
5755
5847
  function resolveCompiledPath(tsPath, baseDir) {
5756
- const relativePath = path5.relative(baseDir, tsPath);
5848
+ const relativePath = path6.relative(baseDir, tsPath);
5757
5849
  const withoutExt = relativePath.replace(/\.tsx?$/, "");
5758
5850
  const srcPrefix = withoutExt.replace(/^src\//, "");
5759
5851
  const tsconfigOutDir = readTsconfigOutDir(baseDir);
@@ -5761,7 +5853,7 @@ function resolveCompiledPath(tsPath, baseDir) {
5761
5853
  const candidates = [];
5762
5854
  if (tsconfigOutDir) {
5763
5855
  for (const ext of extensions) {
5764
- candidates.push(path5.join(baseDir, tsconfigOutDir, `${srcPrefix}${ext}`));
5856
+ candidates.push(path6.join(baseDir, tsconfigOutDir, `${srcPrefix}${ext}`));
5765
5857
  }
5766
5858
  }
5767
5859
  const commonOutDirs = ["dist", "build", "lib", "out"];
@@ -5769,17 +5861,17 @@ function resolveCompiledPath(tsPath, baseDir) {
5769
5861
  if (outDir === tsconfigOutDir)
5770
5862
  continue;
5771
5863
  for (const ext of extensions) {
5772
- candidates.push(path5.join(baseDir, outDir, `${srcPrefix}${ext}`));
5864
+ candidates.push(path6.join(baseDir, outDir, `${srcPrefix}${ext}`));
5773
5865
  }
5774
5866
  }
5775
5867
  for (const ext of extensions) {
5776
- candidates.push(path5.join(baseDir, `${withoutExt}${ext}`));
5868
+ candidates.push(path6.join(baseDir, `${withoutExt}${ext}`));
5777
5869
  }
5778
5870
  const workspaceMatch = baseDir.match(/^(.+\/packages\/[^/]+)$/);
5779
5871
  if (workspaceMatch) {
5780
5872
  const pkgRoot = workspaceMatch[1];
5781
5873
  for (const ext of extensions) {
5782
- candidates.push(path5.join(pkgRoot, "dist", `${srcPrefix}${ext}`));
5874
+ candidates.push(path6.join(pkgRoot, "dist", `${srcPrefix}${ext}`));
5783
5875
  }
5784
5876
  }
5785
5877
  for (const candidate of candidates) {
@@ -5801,7 +5893,7 @@ async function extractStandardSchemas(compiledJsPath, options = {}) {
5801
5893
  return result;
5802
5894
  }
5803
5895
  const optionsJson = JSON.stringify({ target, libraryOptions });
5804
- return new Promise((resolve2) => {
5896
+ return new Promise((resolve3) => {
5805
5897
  const child = spawn("node", ["-e", WORKER_SCRIPT, compiledJsPath, optionsJson], {
5806
5898
  timeout,
5807
5899
  stdio: ["ignore", "pipe", "pipe"]
@@ -5829,14 +5921,14 @@ async function extractStandardSchemas(compiledJsPath, options = {}) {
5829
5921
  child.on("close", (code) => {
5830
5922
  if (code !== 0) {
5831
5923
  result.errors.push(`Extraction process failed: ${stderr || `exit code ${code}`}`);
5832
- resolve2(result);
5924
+ resolve3(result);
5833
5925
  return;
5834
5926
  }
5835
5927
  try {
5836
5928
  const parsed = JSON.parse(stdout);
5837
5929
  if (!parsed.success) {
5838
5930
  result.errors.push(`Extraction failed: ${parsed.error}`);
5839
- resolve2(result);
5931
+ resolve3(result);
5840
5932
  return;
5841
5933
  }
5842
5934
  for (const item of parsed.results) {
@@ -5871,11 +5963,11 @@ async function extractStandardSchemas(compiledJsPath, options = {}) {
5871
5963
  message: "stderr exceeded 10MB buffer limit"
5872
5964
  });
5873
5965
  }
5874
- resolve2(result);
5966
+ resolve3(result);
5875
5967
  });
5876
5968
  child.on("error", (err) => {
5877
5969
  result.errors.push(`Subprocess error: ${err.message}`);
5878
- resolve2(result);
5970
+ resolve3(result);
5879
5971
  });
5880
5972
  });
5881
5973
  }
@@ -5913,9 +6005,9 @@ async function extractStandardSchemasFromProject(entryFile, baseDir, options = {
5913
6005
 
5914
6006
  // src/builder/external-resolver.ts
5915
6007
  import * as fs5 from "node:fs";
5916
- import * as path6 from "node:path";
6008
+ import * as path7 from "node:path";
5917
6009
  import picomatch from "picomatch";
5918
- import ts14 from "typescript";
6010
+ import ts15 from "typescript";
5919
6011
  function matchesExternalPattern(packageName, include, exclude) {
5920
6012
  if (!include?.length)
5921
6013
  return false;
@@ -5931,7 +6023,7 @@ function matchesExternalPattern(packageName, include, exclude) {
5931
6023
  return true;
5932
6024
  }
5933
6025
  function resolveExternalModule(moduleSpecifier, containingFile, compilerOptions) {
5934
- const resolved = ts14.resolveModuleName(moduleSpecifier, containingFile, compilerOptions, ts14.sys);
6026
+ const resolved = ts15.resolveModuleName(moduleSpecifier, containingFile, compilerOptions, ts15.sys);
5935
6027
  if (!resolved.resolvedModule) {
5936
6028
  return null;
5937
6029
  }
@@ -5947,11 +6039,11 @@ function findPackageJson(resolvedPath, packageName) {
5947
6039
  const isScoped = packageName.startsWith("@");
5948
6040
  const packageParts = isScoped ? packageName.split("/").slice(0, 2) : [packageName.split("/")[0]];
5949
6041
  const packageDir = packageParts.join("/");
5950
- let dir = path6.dirname(resolvedPath);
6042
+ let dir = path7.dirname(resolvedPath);
5951
6043
  const maxDepth = 10;
5952
6044
  for (let i = 0;i < maxDepth; i++) {
5953
6045
  if (dir.endsWith(`node_modules/${packageDir}`)) {
5954
- const pkgPath = path6.join(dir, "package.json");
6046
+ const pkgPath = path7.join(dir, "package.json");
5955
6047
  if (fs5.existsSync(pkgPath)) {
5956
6048
  try {
5957
6049
  return JSON.parse(fs5.readFileSync(pkgPath, "utf-8"));
@@ -5960,7 +6052,7 @@ function findPackageJson(resolvedPath, packageName) {
5960
6052
  }
5961
6053
  }
5962
6054
  }
5963
- const parent = path6.dirname(dir);
6055
+ const parent = path7.dirname(dir);
5964
6056
  if (parent === dir)
5965
6057
  break;
5966
6058
  dir = parent;
@@ -5996,7 +6088,7 @@ function extractExternalExport(exportName, resolvedModule, program, ctx, visited
5996
6088
  return null;
5997
6089
  }
5998
6090
  let resolvedSymbol = targetExport;
5999
- if (targetExport.flags & ts14.SymbolFlags.Alias) {
6091
+ if (targetExport.flags & ts15.SymbolFlags.Alias) {
6000
6092
  const aliased = checker.getAliasedSymbol(targetExport);
6001
6093
  if (aliased && aliased !== targetExport) {
6002
6094
  resolvedSymbol = aliased;
@@ -6067,7 +6159,7 @@ function mergeRuntimeSchemas(staticExports, runtimeSchemas) {
6067
6159
  }
6068
6160
 
6069
6161
  // src/builder/type-cache.ts
6070
- import ts15 from "typescript";
6162
+ import ts16 from "typescript";
6071
6163
 
6072
6164
  // src/utils/cache-manager.ts
6073
6165
  class CacheManager {
@@ -6174,10 +6266,10 @@ function findTypeDefinition(typeName, program, sourceFile) {
6174
6266
  return typeDefinitionCache.getOrCompute(typeName, () => {
6175
6267
  const checker = program.getTypeChecker();
6176
6268
  const findInNode = (node) => {
6177
- if ((ts15.isInterfaceDeclaration(node) || ts15.isTypeAliasDeclaration(node) || ts15.isClassDeclaration(node) || ts15.isEnumDeclaration(node)) && node.name?.text === typeName) {
6269
+ if ((ts16.isInterfaceDeclaration(node) || ts16.isTypeAliasDeclaration(node) || ts16.isClassDeclaration(node) || ts16.isEnumDeclaration(node)) && node.name?.text === typeName) {
6178
6270
  return node.getSourceFile().fileName;
6179
6271
  }
6180
- return ts15.forEachChild(node, findInNode);
6272
+ return ts16.forEachChild(node, findInNode);
6181
6273
  };
6182
6274
  const entryResult = findInNode(sourceFile);
6183
6275
  if (entryResult)
@@ -6189,14 +6281,14 @@ function findTypeDefinition(typeName, program, sourceFile) {
6189
6281
  return result;
6190
6282
  }
6191
6283
  }
6192
- const symbol = checker.resolveName(typeName, sourceFile, ts15.SymbolFlags.Type, false);
6284
+ const symbol = checker.resolveName(typeName, sourceFile, ts16.SymbolFlags.Type, false);
6193
6285
  return symbol?.declarations?.[0]?.getSourceFile().fileName;
6194
6286
  });
6195
6287
  }
6196
6288
  function hasInternalTag(typeName, program, sourceFile) {
6197
6289
  return internalTagCache.getOrCompute(typeName, () => {
6198
6290
  const checker = program.getTypeChecker();
6199
- const symbol = checker.resolveName(typeName, sourceFile, ts15.SymbolFlags.Type, false);
6291
+ const symbol = checker.resolveName(typeName, sourceFile, ts16.SymbolFlags.Type, false);
6200
6292
  if (!symbol)
6201
6293
  return false;
6202
6294
  return symbol.getJsDocTags().some((tag) => tag.name === "internal");
@@ -6204,31 +6296,24 @@ function hasInternalTag(typeName, program, sourceFile) {
6204
6296
  }
6205
6297
 
6206
6298
  // src/builder/type-expansion.ts
6207
- import * as fs6 from "node:fs";
6208
- import * as path7 from "node:path";
6209
- import ts16 from "typescript";
6210
- function findPackageDir(fromFile) {
6211
- let dir = path7.dirname(path7.resolve(fromFile));
6212
- while (true) {
6213
- if (fs6.existsSync(path7.join(dir, "package.json")))
6214
- return dir;
6215
- const parent = path7.dirname(dir);
6216
- if (parent === dir)
6217
- return;
6218
- dir = parent;
6219
- }
6220
- }
6221
- var NODE_MODULES_PKG = /node_modules\/(@[^/]+\/[^/]+|[^/]+)/;
6299
+ import ts17 from "typescript";
6300
+ var NODE_MODULES_PKG2 = /node_modules\/(@[^/]+\/[^/]+|[^/]+)/;
6222
6301
  function isLibFile(fileName) {
6223
6302
  return fileName.includes("/typescript/lib/lib.") || fileName.includes("\\typescript\\lib\\lib.");
6224
6303
  }
6225
6304
  function createExternalExpansionPredicate(opts) {
6305
+ const matchesEntry = (entry, pkg) => {
6306
+ if (!entry.includes("*"))
6307
+ return entry === pkg;
6308
+ const rx = new RegExp(`^${entry.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*")}$`);
6309
+ return rx.test(pkg);
6310
+ };
6226
6311
  const packageAllowed = (pkg) => {
6227
6312
  if (pkg === "typescript")
6228
6313
  return false;
6229
6314
  if (opts.followExternal === true)
6230
6315
  return true;
6231
- if (Array.isArray(opts.followExternal) && opts.followExternal.includes(pkg))
6316
+ if (Array.isArray(opts.followExternal) && opts.followExternal.some((e) => matchesEntry(e, pkg)))
6232
6317
  return true;
6233
6318
  return opts.workspacePackages.has(pkg);
6234
6319
  };
@@ -6239,7 +6324,7 @@ function createExternalExpansionPredicate(opts) {
6239
6324
  const fileName = decl.getSourceFile().fileName;
6240
6325
  if (isLibFile(fileName))
6241
6326
  return false;
6242
- const match = fileName.match(NODE_MODULES_PKG);
6327
+ const match = fileName.match(NODE_MODULES_PKG2);
6243
6328
  if (match)
6244
6329
  return packageAllowed(match[1]);
6245
6330
  return true;
@@ -6251,20 +6336,6 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
6251
6336
  const checker = ctx.typeChecker;
6252
6337
  const visited = new Set;
6253
6338
  const MAX_DEPTH = 30;
6254
- const entryPackageDir = findPackageDir(opts.entryFile);
6255
- const packageLabel = (fileName) => {
6256
- const match = fileName.match(NODE_MODULES_PKG);
6257
- let pkg = match?.[1];
6258
- if (!pkg) {
6259
- for (const [name, dir] of opts.workspacePackages) {
6260
- if (fileName.startsWith(`${path7.resolve(dir)}${path7.sep}`)) {
6261
- pkg = name;
6262
- break;
6263
- }
6264
- }
6265
- }
6266
- return (pkg ?? "local").replace(/^@/, "").replace(/\//g, "-");
6267
- };
6268
6339
  const symbolAllowed = createExternalExpansionPredicate(opts);
6269
6340
  const visit = (type, depth) => {
6270
6341
  if (!type || depth > MAX_DEPTH || visited.has(type))
@@ -6294,7 +6365,7 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
6294
6365
  visit(t, depth + 1);
6295
6366
  }
6296
6367
  }
6297
- if (!allowed || !(type.flags & ts16.TypeFlags.Object || type.isClassOrInterface())) {
6368
+ if (!allowed || !(type.flags & ts17.TypeFlags.Object || type.isClassOrInterface())) {
6298
6369
  return;
6299
6370
  }
6300
6371
  if (type.isClassOrInterface()) {
@@ -6317,19 +6388,19 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
6317
6388
  visit(info.type, depth + 1);
6318
6389
  }
6319
6390
  };
6320
- const TYPE_SYMBOL_FLAGS = ts16.SymbolFlags.Interface | ts16.SymbolFlags.TypeAlias | ts16.SymbolFlags.Class | ts16.SymbolFlags.RegularEnum | ts16.SymbolFlags.ConstEnum;
6391
+ const TYPE_SYMBOL_FLAGS = ts17.SymbolFlags.Interface | ts17.SymbolFlags.TypeAlias | ts17.SymbolFlags.Class | ts17.SymbolFlags.RegularEnum | ts17.SymbolFlags.ConstEnum;
6321
6392
  const visitedSymbols = new Set;
6322
6393
  const symbolKind = (symbol) => {
6323
- if (symbol.flags & ts16.SymbolFlags.Interface)
6394
+ if (symbol.flags & ts17.SymbolFlags.Interface)
6324
6395
  return "interface";
6325
- if (symbol.flags & ts16.SymbolFlags.Class)
6396
+ if (symbol.flags & ts17.SymbolFlags.Class)
6326
6397
  return "class";
6327
- if (symbol.flags & (ts16.SymbolFlags.RegularEnum | ts16.SymbolFlags.ConstEnum))
6398
+ if (symbol.flags & (ts17.SymbolFlags.RegularEnum | ts17.SymbolFlags.ConstEnum))
6328
6399
  return "enum";
6329
6400
  return "type";
6330
6401
  };
6331
6402
  const resolveAlias = (symbol) => {
6332
- if (symbol.flags & ts16.SymbolFlags.Alias) {
6403
+ if (symbol.flags & ts17.SymbolFlags.Alias) {
6333
6404
  try {
6334
6405
  return checker.getAliasedSymbol(symbol);
6335
6406
  } catch {
@@ -6351,37 +6422,16 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
6351
6422
  walkDeclarations(symbol);
6352
6423
  return;
6353
6424
  }
6354
- if (ctx.typeRegistry.has(name)) {
6355
- const prior = symbolByName.get(name);
6356
- if (prior !== symbol) {
6357
- const declFile = symbol.declarations?.[0]?.getSourceFile().fileName ?? "";
6358
- const foreign = !!entryPackageDir && !declFile.startsWith(`${entryPackageDir}${path7.sep}`);
6359
- if (prior !== undefined || foreign) {
6360
- const scopedId = `${packageLabel(declFile)}.${name}`;
6361
- if (!ctx.typeRegistry.has(scopedId)) {
6362
- const declared2 = checker.getDeclaredTypeOfSymbol(symbol);
6363
- const schema = ensureNonEmptySchema(buildSchema(declared2, checker, ctx), declared2, checker);
6364
- const selfRef = JSON.stringify(schema) === JSON.stringify({ $ref: `#/types/${name}` });
6365
- if (!selfRef && JSON.stringify(ctx.typeRegistry.get(name)?.schema) !== JSON.stringify(schema)) {
6366
- ctx.typeRegistry.add({
6367
- id: scopedId,
6368
- name,
6369
- kind: symbolKind(symbol),
6370
- schema
6371
- });
6372
- visit(declared2, 0);
6373
- }
6374
- }
6375
- }
6376
- }
6425
+ const id = resolveTypeId(symbol, ctx);
6426
+ if (ctx.typeRegistry.has(id)) {
6377
6427
  walkDeclarations(symbol);
6378
6428
  return;
6379
6429
  }
6380
6430
  const declared = checker.getDeclaredTypeOfSymbol(symbol);
6381
6431
  ctx.typeRegistry.registerType(declared, ctx);
6382
- if (!ctx.typeRegistry.has(name)) {
6432
+ if (!ctx.typeRegistry.has(id)) {
6383
6433
  ctx.typeRegistry.add({
6384
- id: name,
6434
+ id,
6385
6435
  name,
6386
6436
  kind: symbolKind(symbol),
6387
6437
  schema: ensureNonEmptySchema(buildSchema(declared, checker, ctx), declared, checker)
@@ -6402,7 +6452,7 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
6402
6452
  const target = symbol && resolveAlias(symbol);
6403
6453
  if (!target || visitedSymbols.has(target))
6404
6454
  return;
6405
- if (!(target.flags & (ts16.SymbolFlags.ValueModule | ts16.SymbolFlags.NamespaceModule)))
6455
+ if (!(target.flags & (ts17.SymbolFlags.ValueModule | ts17.SymbolFlags.NamespaceModule)))
6406
6456
  return;
6407
6457
  if (!symbolAllowed(target))
6408
6458
  return;
@@ -6417,22 +6467,22 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
6417
6467
  }
6418
6468
  };
6419
6469
  const walkNode = (node) => {
6420
- if (ts16.isTypeReferenceNode(node)) {
6470
+ if (ts17.isTypeReferenceNode(node)) {
6421
6471
  handleRef(node.typeName);
6422
- if (ts16.isQualifiedName(node.typeName)) {
6472
+ if (ts17.isQualifiedName(node.typeName)) {
6423
6473
  handleNamespaceRef(node.typeName.left);
6424
6474
  }
6425
- } else if (ts16.isExpressionWithTypeArguments(node)) {
6475
+ } else if (ts17.isExpressionWithTypeArguments(node)) {
6426
6476
  handleRef(node.expression);
6427
- } else if (ts16.isTypeQueryNode(node)) {
6477
+ } else if (ts17.isTypeQueryNode(node)) {
6428
6478
  handleRef(node.exprName);
6429
- if (ts16.isQualifiedName(node.exprName)) {
6479
+ if (ts17.isQualifiedName(node.exprName)) {
6430
6480
  handleRef(node.exprName.left);
6431
6481
  handleNamespaceRef(node.exprName.left);
6432
6482
  }
6433
- } else if (ts16.isImportTypeNode(node) && node.qualifier) {
6483
+ } else if (ts17.isImportTypeNode(node) && node.qualifier) {
6434
6484
  handleRef(node.qualifier);
6435
- if (ts16.isQualifiedName(node.qualifier)) {
6485
+ if (ts17.isQualifiedName(node.qualifier)) {
6436
6486
  handleNamespaceRef(node.qualifier.left);
6437
6487
  }
6438
6488
  }
@@ -6448,7 +6498,7 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
6448
6498
  };
6449
6499
  for (const exportSymbol of exportedSymbols) {
6450
6500
  let target = exportSymbol;
6451
- if (exportSymbol.flags & ts16.SymbolFlags.Alias) {
6501
+ if (exportSymbol.flags & ts17.SymbolFlags.Alias) {
6452
6502
  try {
6453
6503
  target = checker.getAliasedSymbol(exportSymbol);
6454
6504
  } catch {
@@ -6781,7 +6831,8 @@ async function extract(options) {
6781
6831
  shouldExpandExternal: createExternalExpansionPredicate({
6782
6832
  followExternal: options.followExternal,
6783
6833
  workspacePackages: result.workspacePackages ?? new Map
6784
- })
6834
+ }),
6835
+ workspacePackages: result.workspacePackages ?? new Map
6785
6836
  });
6786
6837
  ctx.exportedIds = exportedIds;
6787
6838
  const filteredSymbols = exportedSymbols.filter((s) => shouldIncludeExport(s.getName(), only, ignore));
@@ -6810,9 +6861,9 @@ async function extract(options) {
6810
6861
  break;
6811
6862
  }
6812
6863
  }
6813
- if (ts17.isExportSpecifier(decl)) {
6864
+ if (ts18.isExportSpecifier(decl)) {
6814
6865
  const exportDecl = decl.parent?.parent;
6815
- if (exportDecl && ts17.isExportDeclaration(exportDecl) && exportDecl.moduleSpecifier) {
6866
+ if (exportDecl && ts18.isExportDeclaration(exportDecl) && exportDecl.moduleSpecifier) {
6816
6867
  const moduleText = exportDecl.moduleSpecifier.getText().slice(1, -1);
6817
6868
  if (!moduleText.startsWith(".") && !moduleText.startsWith("/")) {
6818
6869
  externalPackage = moduleText;
@@ -6881,7 +6932,7 @@ async function extract(options) {
6881
6932
  entryFile
6882
6933
  });
6883
6934
  {
6884
- const symFlags = ts17.SymbolFlags.Type | ts17.SymbolFlags.Interface | ts17.SymbolFlags.Class;
6935
+ const symFlags = ts18.SymbolFlags.Type | ts18.SymbolFlags.Interface | ts18.SymbolFlags.Class;
6885
6936
  const maxPasses = 5;
6886
6937
  for (let pass = 0;pass < maxPasses; pass++) {
6887
6938
  const allRefs = new Map;
@@ -7028,21 +7079,21 @@ async function extract(options) {
7028
7079
  }
7029
7080
  function serializeDeclaration2(declaration, exportSymbol, exportName, ctx, isTypeOnly = false) {
7030
7081
  let result = null;
7031
- if (ts17.isFunctionDeclaration(declaration)) {
7082
+ if (ts18.isFunctionDeclaration(declaration)) {
7032
7083
  result = serializeFunctionExport(declaration, ctx);
7033
- } else if (ts17.isClassDeclaration(declaration)) {
7084
+ } else if (ts18.isClassDeclaration(declaration)) {
7034
7085
  result = serializeClass(declaration, ctx);
7035
- } else if (ts17.isInterfaceDeclaration(declaration)) {
7086
+ } else if (ts18.isInterfaceDeclaration(declaration)) {
7036
7087
  result = serializeInterface(declaration, ctx);
7037
- } else if (ts17.isTypeAliasDeclaration(declaration)) {
7088
+ } else if (ts18.isTypeAliasDeclaration(declaration)) {
7038
7089
  result = serializeTypeAlias(declaration, ctx);
7039
- } else if (ts17.isEnumDeclaration(declaration)) {
7090
+ } else if (ts18.isEnumDeclaration(declaration)) {
7040
7091
  result = serializeEnum(declaration, ctx);
7041
- } else if (ts17.isVariableDeclaration(declaration)) {
7092
+ } else if (ts18.isVariableDeclaration(declaration)) {
7042
7093
  const varStatement = declaration.parent?.parent;
7043
- if (varStatement && ts17.isVariableStatement(varStatement)) {
7044
- if (declaration.initializer && (ts17.isArrowFunction(declaration.initializer) || ts17.isFunctionExpression(declaration.initializer))) {
7045
- const varName = ts17.isIdentifier(declaration.name) ? declaration.name.text : declaration.name.getText();
7094
+ if (varStatement && ts18.isVariableStatement(varStatement)) {
7095
+ if (declaration.initializer && (ts18.isArrowFunction(declaration.initializer) || ts18.isFunctionExpression(declaration.initializer))) {
7096
+ const varName = ts18.isIdentifier(declaration.name) ? declaration.name.text : declaration.name.getText();
7046
7097
  result = serializeFunctionExport(declaration.initializer, ctx, varName);
7047
7098
  } else {
7048
7099
  result = serializeVariable(declaration, varStatement, ctx);
@@ -7054,7 +7105,7 @@ function serializeDeclaration2(declaration, exportSymbol, exportName, ctx, isTyp
7054
7105
  }
7055
7106
  }
7056
7107
  }
7057
- } else if (ts17.isNamespaceExport(declaration) || ts17.isModuleDeclaration(declaration) || ts17.isNamespaceImport(declaration) || ts17.isSourceFile(declaration)) {
7108
+ } else if (ts18.isNamespaceExport(declaration) || ts18.isModuleDeclaration(declaration) || ts18.isNamespaceImport(declaration) || ts18.isSourceFile(declaration)) {
7058
7109
  try {
7059
7110
  result = serializeNamespaceExport(exportSymbol, exportName, ctx);
7060
7111
  } catch {
@@ -7090,7 +7141,7 @@ function serializeNamespaceExport(symbol, exportName, ctx) {
7090
7141
  const members = [];
7091
7142
  const checker = ctx.program.getTypeChecker();
7092
7143
  let targetSymbol = symbol;
7093
- if (symbol.flags & ts17.SymbolFlags.Alias) {
7144
+ if (symbol.flags & ts18.SymbolFlags.Alias) {
7094
7145
  const aliased = checker.getAliasedSymbol(symbol);
7095
7146
  if (aliased && aliased !== symbol) {
7096
7147
  targetSymbol = aliased;
@@ -7117,31 +7168,31 @@ function serializeNamespaceExport(symbol, exportName, ctx) {
7117
7168
  function serializeNamespaceMember(symbol, memberName, ctx) {
7118
7169
  const checker = ctx.program.getTypeChecker();
7119
7170
  let targetSymbol = symbol;
7120
- if (symbol.flags & ts17.SymbolFlags.Alias) {
7171
+ if (symbol.flags & ts18.SymbolFlags.Alias) {
7121
7172
  const aliased = checker.getAliasedSymbol(symbol);
7122
7173
  if (aliased && aliased !== symbol) {
7123
7174
  targetSymbol = aliased;
7124
7175
  }
7125
7176
  }
7126
7177
  const declarations = targetSymbol.declarations ?? [];
7127
- const declaration = targetSymbol.valueDeclaration || declarations.find((d) => d.kind !== ts17.SyntaxKind.ExportSpecifier) || declarations[0];
7178
+ const declaration = targetSymbol.valueDeclaration || declarations.find((d) => d.kind !== ts18.SyntaxKind.ExportSpecifier) || declarations[0];
7128
7179
  if (!declaration)
7129
7180
  return null;
7130
7181
  const type = checker.getTypeAtLocation(declaration);
7131
7182
  const callSignatures = type.getCallSignatures();
7132
7183
  const { deprecated } = isSymbolDeprecated(targetSymbol);
7133
7184
  let kind = "variable";
7134
- if (ts17.isFunctionDeclaration(declaration) || ts17.isFunctionExpression(declaration)) {
7185
+ if (ts18.isFunctionDeclaration(declaration) || ts18.isFunctionExpression(declaration)) {
7135
7186
  kind = "function";
7136
- } else if (ts17.isClassDeclaration(declaration)) {
7187
+ } else if (ts18.isClassDeclaration(declaration)) {
7137
7188
  kind = "class";
7138
- } else if (ts17.isInterfaceDeclaration(declaration)) {
7189
+ } else if (ts18.isInterfaceDeclaration(declaration)) {
7139
7190
  kind = "interface";
7140
- } else if (ts17.isTypeAliasDeclaration(declaration)) {
7191
+ } else if (ts18.isTypeAliasDeclaration(declaration)) {
7141
7192
  kind = "type";
7142
- } else if (ts17.isEnumDeclaration(declaration)) {
7193
+ } else if (ts18.isEnumDeclaration(declaration)) {
7143
7194
  kind = "enum";
7144
- } else if (ts17.isVariableDeclaration(declaration)) {
7195
+ } else if (ts18.isVariableDeclaration(declaration)) {
7145
7196
  if (callSignatures.length > 0) {
7146
7197
  kind = "function";
7147
7198
  }
@@ -7172,11 +7223,11 @@ function getJSDocFromExportSymbol(symbol) {
7172
7223
  const examples = [];
7173
7224
  const decl = symbol.declarations?.[0];
7174
7225
  if (decl) {
7175
- const exportDecl = ts17.isNamespaceExport(decl) ? decl.parent : decl;
7176
- if (exportDecl && ts17.isExportDeclaration(exportDecl)) {
7177
- const jsDocs = ts17.getJSDocCommentsAndTags(exportDecl);
7226
+ const exportDecl = ts18.isNamespaceExport(decl) ? decl.parent : decl;
7227
+ if (exportDecl && ts18.isExportDeclaration(exportDecl)) {
7228
+ const jsDocs = ts18.getJSDocCommentsAndTags(exportDecl);
7178
7229
  for (const doc of jsDocs) {
7179
- if (ts17.isJSDoc(doc) && doc.comment) {
7230
+ if (ts18.isJSDoc(doc) && doc.comment) {
7180
7231
  const commentText = typeof doc.comment === "string" ? doc.comment : doc.comment.map((c) => ("text" in c) ? c.text : "").join("");
7181
7232
  if (commentText) {
7182
7233
  return {
@@ -7274,8 +7325,8 @@ async function getPackageMeta(entryFile, baseDir) {
7274
7325
  while (dir !== path9.dirname(dir)) {
7275
7326
  const pkgPath = path9.join(dir, "package.json");
7276
7327
  try {
7277
- if (fs7.existsSync(pkgPath)) {
7278
- const pkg = JSON.parse(fs7.readFileSync(pkgPath, "utf-8"));
7328
+ if (fs6.existsSync(pkgPath)) {
7329
+ const pkg = JSON.parse(fs6.readFileSync(pkgPath, "utf-8"));
7279
7330
  return {
7280
7331
  name: pkg.name ?? path9.basename(dir),
7281
7332
  version: pkg.version,
@@ -7770,12 +7821,12 @@ function toToolSchema(exp, spec, options) {
7770
7821
  };
7771
7822
  }
7772
7823
  // src/types/utils.ts
7773
- import ts18 from "typescript";
7824
+ import ts19 from "typescript";
7774
7825
  function isExported(node) {
7775
7826
  const modifiers = node.modifiers;
7776
7827
  if (!modifiers)
7777
7828
  return false;
7778
- return modifiers.some((m) => m.kind === ts18.SyntaxKind.ExportKeyword);
7829
+ return modifiers.some((m) => m.kind === ts19.SyntaxKind.ExportKeyword);
7779
7830
  }
7780
7831
  function getNodeName(node) {
7781
7832
  if ("name" in node && node.name) {