@openpkg-ts/sdk 0.54.2 → 0.54.4

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,6 +1787,16 @@ 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
  }
@@ -3660,6 +3670,9 @@ function registerReferencedTypes(type, ctx, depth = 0) {
3660
3670
  if (typeSymbol && ctx.shouldExpandExternal && !typeSymbol.getName().startsWith("__") && !ctx.shouldExpandExternal(typeSymbol)) {
3661
3671
  return;
3662
3672
  }
3673
+ if (isForeignPackage(typeSymbol, ctx.workspacePackages)) {
3674
+ return;
3675
+ }
3663
3676
  if (type.flags & ts5.TypeFlags.Object) {
3664
3677
  const props = type.getProperties();
3665
3678
  const limit = ctx.maxProperties;
@@ -3771,6 +3784,9 @@ class TypeRegistry {
3771
3784
  getAll() {
3772
3785
  return Array.from(this.types.values());
3773
3786
  }
3787
+ get size() {
3788
+ return this.types.size;
3789
+ }
3774
3790
  registerType(type, ctx) {
3775
3791
  const symbol = type.aliasSymbol || type.getSymbol();
3776
3792
  if (!symbol)
@@ -3797,7 +3813,7 @@ class TypeRegistry {
3797
3813
  const id = resolveTypeId(symbol, ctx);
3798
3814
  if (this.has(id))
3799
3815
  return id;
3800
- if (ctx.shouldExpandExternal && !ctx.shouldExpandExternal(symbol)) {
3816
+ const stubExternal = () => {
3801
3817
  const origin = getTypeOrigin(type, ctx.typeChecker);
3802
3818
  const schema = {
3803
3819
  "x-ts-type": renderTypeText(type, ctx.typeChecker)
@@ -3812,6 +3828,12 @@ class TypeRegistry {
3812
3828
  schema
3813
3829
  });
3814
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;
3815
3837
  }
3816
3838
  if (this.processing.has(id))
3817
3839
  return id;
@@ -5249,7 +5271,7 @@ var TS_PRIMITIVE_NORMALIZATIONS = {
5249
5271
  never: () => ({ not: {} }),
5250
5272
  any: () => ({}),
5251
5273
  unknown: () => ({ "x-ts-type": "unknown" }),
5252
- undefined: () => ({ type: "null" }),
5274
+ undefined: () => ({ type: "null", "x-ts-type": "undefined" }),
5253
5275
  bigint: () => ({ type: "integer", "x-ts-type": "bigint" }),
5254
5276
  symbol: () => ({ type: "string", "x-ts-type": "symbol" })
5255
5277
  };
@@ -6991,10 +7013,16 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
6991
7013
  const checker = ctx.typeChecker;
6992
7014
  const visited = new Set;
6993
7015
  const MAX_DEPTH = 30;
7016
+ let visits = 0;
7017
+ const MAX_VISITS = 50000;
6994
7018
  const symbolAllowed = createExternalExpansionPredicate(opts);
6995
7019
  const visit = (type, depth) => {
6996
7020
  if (!type || depth > MAX_DEPTH || visited.has(type))
6997
7021
  return;
7022
+ if (ctx.typeRegistry.size >= MAX_REGISTERED_TYPES)
7023
+ return;
7024
+ if (++visits > MAX_VISITS)
7025
+ return;
6998
7026
  visited.add(type);
6999
7027
  const symbol = type.aliasSymbol ?? type.getSymbol();
7000
7028
  const named = !!symbol && !symbol.getName().startsWith("__");
@@ -7023,6 +7051,9 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
7023
7051
  if (!allowed || !(type.flags & ts18.TypeFlags.Object || type.isClassOrInterface())) {
7024
7052
  return;
7025
7053
  }
7054
+ if (isForeignPackage(symbol, opts.workspacePackages)) {
7055
+ return;
7056
+ }
7026
7057
  if (type.isClassOrInterface()) {
7027
7058
  for (const base of checker.getBaseTypes(type) ?? []) {
7028
7059
  visit(base, depth + 1);
@@ -7078,7 +7109,7 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
7078
7109
  return;
7079
7110
  }
7080
7111
  const id = resolveTypeId(symbol, ctx);
7081
- if (ctx.typeRegistry.has(id)) {
7112
+ if (ctx.typeRegistry.has(id) || ctx.typeRegistry.size >= MAX_REGISTERED_TYPES) {
7082
7113
  walkDeclarations(symbol);
7083
7114
  return;
7084
7115
  }
@@ -7111,6 +7142,8 @@ function expandReachableTypes(exportedSymbols, ctx, opts) {
7111
7142
  return;
7112
7143
  if (!symbolAllowed(target))
7113
7144
  return;
7145
+ if (isForeignPackage(target, opts.workspacePackages))
7146
+ return;
7114
7147
  visitedSymbols.add(target);
7115
7148
  for (const exp of checker.getExportsOfModule(target)) {
7116
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.2",
3
+ "version": "0.54.4",
4
4
  "description": "TypeScript API extraction SDK - programmatic primitives for OpenPkg specs",
5
5
  "keywords": [
6
6
  "openpkg",
@@ -43,7 +43,7 @@
43
43
  "test": "bun test"
44
44
  },
45
45
  "dependencies": {
46
- "@openpkg-ts/spec": "^0.52.0",
46
+ "@openpkg-ts/spec": "^0.54.4",
47
47
  "picomatch": "4.0.3",
48
48
  "typescript": "^5.0.0 || ^6.0.0"
49
49
  },