@openpkg-ts/sdk 0.54.1 → 0.54.3

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.d.ts CHANGED
@@ -41,9 +41,11 @@ interface ExtractOptions {
41
41
  * environment-dependent) member surface. Referenced-but-not-exported types
42
42
  * from the entry package and workspace siblings always expand fully.
43
43
  *
44
- * - `true` → fully expand every referenced package (restores pre-stub
45
- * behavior; output becomes environment-dependent for global types)
46
- * - `string[]` fully expand the listed packages (plus workspace siblings)
44
+ * - `true` → register named types from every referenced package.
45
+ * Does not walk foreign method graphs (zod/typescript OOMs).
46
+ * `types[]` is capped at 10k.
47
+ * - `string[]` → register named types from the listed packages
48
+ * (plus workspace siblings)
47
49
  * - `false` → disable the reachability-expansion pass entirely
48
50
  * - default → workspace siblings only; everything else stubbed
49
51
  */
@@ -1248,6 +1250,7 @@ declare class TypeRegistry {
1248
1250
  get(id: string): SpecType4 | undefined;
1249
1251
  has(id: string): boolean;
1250
1252
  getAll(): SpecType4[];
1253
+ get size(): number;
1251
1254
  /**
1252
1255
  * Register a type from a ts.Type with structured schema.
1253
1256
  * Returns the type ID if registered, undefined if skipped.
package/dist/index.js CHANGED
@@ -1787,9 +1787,22 @@ import ts13 from "typescript";
1787
1787
  import * as path3 from "node:path";
1788
1788
  import ts from "typescript";
1789
1789
  var NODE_MODULES_PKG = /node_modules\/(@[^/]+\/[^/]+|[^/]+)/g;
1790
+ var MAX_REGISTERED_TYPES = 1e4;
1791
+ function isForeignPackage(symbol, workspacePackages) {
1792
+ const decl = symbol?.declarations?.[0];
1793
+ if (!decl)
1794
+ return false;
1795
+ const pkg = packageNameFromPath(decl.getSourceFile().fileName);
1796
+ if (!pkg)
1797
+ return false;
1798
+ return !workspacePackages.has(pkg);
1799
+ }
1790
1800
  function isLibFile(fileName) {
1791
1801
  return fileName.includes("/typescript/lib/lib.") || fileName.includes("\\typescript\\lib\\lib.");
1792
1802
  }
1803
+ function isLibSymbol(symbol) {
1804
+ return symbol?.declarations?.some((d) => isLibFile(d.getSourceFile().fileName)) ?? false;
1805
+ }
1793
1806
  function packageNameFromPath(fileName) {
1794
1807
  return [...fileName.matchAll(NODE_MODULES_PKG)].at(-1)?.[1];
1795
1808
  }
@@ -2830,12 +2843,7 @@ function isPrimitiveName(name) {
2830
2843
  return PRIMITIVES.has(name);
2831
2844
  }
2832
2845
  function isBuiltinSymbol(symbol) {
2833
- if (!symbol)
2834
- return false;
2835
- const declarations = symbol.getDeclarations();
2836
- if (!declarations || declarations.length === 0)
2837
- return false;
2838
- return isLibFile(declarations[0].getSourceFile().fileName);
2846
+ return isLibSymbol(symbol);
2839
2847
  }
2840
2848
  function getTypeOrigin(type, _checker) {
2841
2849
  const symbol = type.getSymbol() ?? type.aliasSymbol;
@@ -2844,10 +2852,9 @@ function getTypeOrigin(type, _checker) {
2844
2852
  const declarations = symbol.getDeclarations();
2845
2853
  if (!declarations || declarations.length === 0)
2846
2854
  return;
2847
- const fileName = declarations[0].getSourceFile().fileName;
2848
- if (isLibFile(fileName))
2855
+ if (isLibSymbol(symbol))
2849
2856
  return;
2850
- return packageNameFromPath(fileName);
2857
+ return packageNameFromPath(declarations[0].getSourceFile().fileName);
2851
2858
  }
2852
2859
  function isBuiltinGeneric(name) {
2853
2860
  return BUILTIN_GENERICS.has(name);
@@ -3663,6 +3670,9 @@ function registerReferencedTypes(type, ctx, depth = 0) {
3663
3670
  if (typeSymbol && ctx.shouldExpandExternal && !typeSymbol.getName().startsWith("__") && !ctx.shouldExpandExternal(typeSymbol)) {
3664
3671
  return;
3665
3672
  }
3673
+ if (isForeignPackage(typeSymbol, ctx.workspacePackages)) {
3674
+ return;
3675
+ }
3666
3676
  if (type.flags & ts5.TypeFlags.Object) {
3667
3677
  const props = type.getProperties();
3668
3678
  const limit = ctx.maxProperties;
@@ -3774,6 +3784,9 @@ class TypeRegistry {
3774
3784
  getAll() {
3775
3785
  return Array.from(this.types.values());
3776
3786
  }
3787
+ get size() {
3788
+ return this.types.size;
3789
+ }
3777
3790
  registerType(type, ctx) {
3778
3791
  const symbol = type.aliasSymbol || type.getSymbol();
3779
3792
  if (!symbol)
@@ -3800,7 +3813,7 @@ class TypeRegistry {
3800
3813
  const id = resolveTypeId(symbol, ctx);
3801
3814
  if (this.has(id))
3802
3815
  return id;
3803
- if (ctx.shouldExpandExternal && !ctx.shouldExpandExternal(symbol)) {
3816
+ const stubExternal = () => {
3804
3817
  const origin = getTypeOrigin(type, ctx.typeChecker);
3805
3818
  const schema = {
3806
3819
  "x-ts-type": renderTypeText(type, ctx.typeChecker)
@@ -3815,6 +3828,12 @@ class TypeRegistry {
3815
3828
  schema
3816
3829
  });
3817
3830
  return id;
3831
+ };
3832
+ if (ctx.shouldExpandExternal && !ctx.shouldExpandExternal(symbol)) {
3833
+ return stubExternal();
3834
+ }
3835
+ if (this.types.size >= MAX_REGISTERED_TYPES) {
3836
+ return;
3818
3837
  }
3819
3838
  if (this.processing.has(id))
3820
3839
  return id;
@@ -6980,10 +6999,9 @@ function createExternalExpansionPredicate(opts) {
6980
6999
  const decl = symbol.declarations?.[0];
6981
7000
  if (!decl)
6982
7001
  return false;
6983
- const fileName = decl.getSourceFile().fileName;
6984
- if (isLibFile(fileName))
7002
+ if (isLibSymbol(symbol))
6985
7003
  return false;
6986
- const pkg = packageNameFromPath(fileName);
7004
+ const pkg = packageNameFromPath(decl.getSourceFile().fileName);
6987
7005
  if (pkg)
6988
7006
  return packageAllowed(pkg);
6989
7007
  return true;
@@ -6995,10 +7013,16 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
6995
7013
  const checker = ctx.typeChecker;
6996
7014
  const visited = new Set;
6997
7015
  const MAX_DEPTH = 30;
7016
+ let visits = 0;
7017
+ const MAX_VISITS = 50000;
6998
7018
  const symbolAllowed = createExternalExpansionPredicate(opts);
6999
7019
  const visit = (type, depth) => {
7000
7020
  if (!type || depth > MAX_DEPTH || visited.has(type))
7001
7021
  return;
7022
+ if (ctx.typeRegistry.size >= MAX_REGISTERED_TYPES)
7023
+ return;
7024
+ if (++visits > MAX_VISITS)
7025
+ return;
7002
7026
  visited.add(type);
7003
7027
  const symbol = type.aliasSymbol ?? type.getSymbol();
7004
7028
  const named = !!symbol && !symbol.getName().startsWith("__");
@@ -7027,6 +7051,9 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
7027
7051
  if (!allowed || !(type.flags & ts18.TypeFlags.Object || type.isClassOrInterface())) {
7028
7052
  return;
7029
7053
  }
7054
+ if (isForeignPackage(symbol, opts.workspacePackages)) {
7055
+ return;
7056
+ }
7030
7057
  if (type.isClassOrInterface()) {
7031
7058
  for (const base of checker.getBaseTypes(type) ?? []) {
7032
7059
  visit(base, depth + 1);
@@ -7082,7 +7109,7 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
7082
7109
  return;
7083
7110
  }
7084
7111
  const id = resolveTypeId(symbol, ctx);
7085
- if (ctx.typeRegistry.has(id)) {
7112
+ if (ctx.typeRegistry.has(id) || ctx.typeRegistry.size >= MAX_REGISTERED_TYPES) {
7086
7113
  walkDeclarations(symbol);
7087
7114
  return;
7088
7115
  }
@@ -7115,6 +7142,8 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
7115
7142
  return;
7116
7143
  if (!symbolAllowed(target))
7117
7144
  return;
7145
+ if (isForeignPackage(target, opts.workspacePackages))
7146
+ return;
7118
7147
  visitedSymbols.add(target);
7119
7148
  for (const exp of checker.getExportsOfModule(target)) {
7120
7149
  const expTarget = resolveAlias(exp);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpkg-ts/sdk",
3
- "version": "0.54.1",
3
+ "version": "0.54.3",
4
4
  "description": "TypeScript API extraction SDK - programmatic primitives for OpenPkg specs",
5
5
  "keywords": [
6
6
  "openpkg",