@openpkg-ts/extract 0.14.5 → 0.16.0

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.
@@ -1,5 +1,19 @@
1
1
  import { SpecType } from "@openpkg-ts/spec";
2
+ import ts2 from "typescript";
2
3
  import ts from "typescript";
4
+ interface SerializerContext {
5
+ typeChecker: ts.TypeChecker;
6
+ program: ts.Program;
7
+ sourceFile: ts.SourceFile;
8
+ maxTypeDepth: number;
9
+ maxExternalTypeDepth: number;
10
+ currentDepth: number;
11
+ resolveExternalTypes: boolean;
12
+ typeRegistry: TypeRegistry;
13
+ exportedIds: Set<string>;
14
+ /** Track visited types to prevent infinite recursion */
15
+ visitedTypes: Set<ts.Type>;
16
+ }
3
17
  declare class TypeRegistry {
4
18
  private types;
5
19
  private processing;
@@ -8,24 +22,31 @@ declare class TypeRegistry {
8
22
  has(id: string): boolean;
9
23
  getAll(): SpecType[];
10
24
  /**
11
- * Register a type from a ts.Type (lightweight stub).
25
+ * Register a type from a ts.Type with structured schema.
12
26
  * Returns the type ID if registered, undefined if skipped.
13
27
  */
14
- registerType(type: ts.Type, checker: ts.TypeChecker, exportedIds: Set<string>): string | undefined;
28
+ registerType(type: ts2.Type, ctx: SerializerContext): string | undefined;
29
+ /**
30
+ * Build a SpecType with structured schema using buildSchema.
31
+ */
32
+ private buildSpecType;
33
+ /**
34
+ * Check if schema is a self-referential $ref
35
+ */
36
+ private isSelfRef;
15
37
  /**
16
- * Build a lightweight stub type (no deep schema extraction).
38
+ * Build object schema from type properties (for interfaces/classes)
17
39
  */
18
- private buildStubType;
19
- registerFromSymbol(symbol: ts.Symbol, checker: ts.TypeChecker): SpecType | undefined;
40
+ private buildObjectSchemaFromType;
20
41
  }
21
42
  import { SpecExample, SpecSource, SpecTag, SpecTypeParameter } from "@openpkg-ts/spec";
22
- import ts2 from "typescript";
23
- declare function getJSDocComment(node: ts2.Node): {
43
+ import ts3 from "typescript";
44
+ declare function getJSDocComment(node: ts3.Node): {
24
45
  description?: string;
25
46
  tags: SpecTag[];
26
47
  examples: SpecExample[];
27
48
  };
28
- declare function getSourceLocation(node: ts2.Node, sourceFile: ts2.SourceFile): SpecSource;
49
+ declare function getSourceLocation(node: ts3.Node, sourceFile: ts3.SourceFile): SpecSource;
29
50
  /**
30
51
  * Get description for a destructured parameter property from JSDoc @param tags.
31
52
  * Matches patterns like:
@@ -33,16 +54,16 @@ declare function getSourceLocation(node: ts2.Node, sourceFile: ts2.SourceFile):
33
54
  * - @param opts.paramName - dotted notation with alias
34
55
  * - @param {type} paramName - type annotation format
35
56
  */
36
- declare function getParamDescription(propertyName: string, jsdocTags: readonly ts2.JSDocTag[], inferredAlias?: string): string | undefined;
37
- type DeclarationWithTypeParams = ts2.FunctionDeclaration | ts2.ClassDeclaration | ts2.InterfaceDeclaration | ts2.TypeAliasDeclaration | ts2.MethodDeclaration | ts2.ArrowFunction;
57
+ declare function getParamDescription(propertyName: string, jsdocTags: readonly ts3.JSDocTag[], inferredAlias?: string): string | undefined;
58
+ type DeclarationWithTypeParams = ts3.FunctionDeclaration | ts3.ClassDeclaration | ts3.InterfaceDeclaration | ts3.TypeAliasDeclaration | ts3.MethodDeclaration | ts3.ArrowFunction;
38
59
  /**
39
60
  * Extract type parameters from declarations like `<T extends Base, K = Default>`
40
61
  */
41
- declare function extractTypeParameters(node: DeclarationWithTypeParams, checker: ts2.TypeChecker): SpecTypeParameter[] | undefined;
62
+ declare function extractTypeParameters(node: DeclarationWithTypeParams, checker: ts3.TypeChecker): SpecTypeParameter[] | undefined;
42
63
  /**
43
64
  * Check if a symbol is marked as deprecated via @deprecated JSDoc tag.
44
65
  */
45
- declare function isSymbolDeprecated(symbol: ts2.Symbol | undefined): boolean;
66
+ declare function isSymbolDeprecated(symbol: ts3.Symbol | undefined): boolean;
46
67
  import { OpenPkg } from "@openpkg-ts/spec";
47
68
  interface ExtractOptions {
48
69
  entryFile: string;
@@ -58,6 +79,7 @@ interface ExtractOptions {
58
79
  interface ExtractResult {
59
80
  spec: OpenPkg;
60
81
  diagnostics: Diagnostic[];
82
+ forgottenExports?: ForgottenExport[];
61
83
  }
62
84
  interface Diagnostic {
63
85
  message: string;
@@ -70,18 +92,33 @@ interface Diagnostic {
70
92
  column?: number;
71
93
  };
72
94
  }
95
+ /** Context tracking for type references in public API */
96
+ interface TypeReference2 {
97
+ typeName: string;
98
+ exportName: string;
99
+ location: "return" | "parameter" | "property" | "extends" | "type-parameter";
100
+ path?: string;
101
+ }
102
+ /** Structured data for forgotten exports */
103
+ interface ForgottenExport {
104
+ name: string;
105
+ definedIn?: string;
106
+ referencedBy: TypeReference2[];
107
+ isExternal: boolean;
108
+ fix?: string;
109
+ }
73
110
  declare function extract(options: ExtractOptions): Promise<ExtractResult>;
74
- import ts3 from "typescript";
111
+ import ts4 from "typescript";
75
112
  interface ProgramOptions {
76
113
  entryFile: string;
77
114
  baseDir?: string;
78
115
  content?: string;
79
116
  }
80
117
  interface ProgramResult {
81
- program: ts3.Program;
82
- compilerHost: ts3.CompilerHost;
83
- compilerOptions: ts3.CompilerOptions;
84
- sourceFile?: ts3.SourceFile;
118
+ program: ts4.Program;
119
+ compilerHost: ts4.CompilerHost;
120
+ compilerOptions: ts4.CompilerOptions;
121
+ sourceFile?: ts4.SourceFile;
85
122
  configPath?: string;
86
123
  }
87
124
  declare function createProgram({ entryFile, baseDir, content }: ProgramOptions): ProgramResult;
@@ -209,20 +246,6 @@ declare function extractStandardSchemas(compiledJsPath: string, options?: Extrac
209
246
  declare function extractStandardSchemasFromProject(entryFile: string, baseDir: string, options?: ExtractStandardSchemasOptions): Promise<StandardSchemaExtractionOutput>;
210
247
  import { SpecExport } from "@openpkg-ts/spec";
211
248
  import ts5 from "typescript";
212
- import ts4 from "typescript";
213
- interface SerializerContext {
214
- typeChecker: ts4.TypeChecker;
215
- program: ts4.Program;
216
- sourceFile: ts4.SourceFile;
217
- maxTypeDepth: number;
218
- maxExternalTypeDepth: number;
219
- currentDepth: number;
220
- resolveExternalTypes: boolean;
221
- typeRegistry: TypeRegistry;
222
- exportedIds: Set<string>;
223
- /** Track visited types to prevent infinite recursion */
224
- visitedTypes: Set<ts4.Type>;
225
- }
226
249
  declare function serializeClass(node: ts5.ClassDeclaration, ctx: SerializerContext): SpecExport | null;
227
250
  import { SpecExport as SpecExport2 } from "@openpkg-ts/spec";
228
251
  import ts6 from "typescript";
@@ -302,4 +325,4 @@ declare function findDiscriminatorProperty(unionTypes: ts12.Type[], checker: ts1
302
325
  import ts13 from "typescript";
303
326
  declare function isExported(node: ts13.Node): boolean;
304
327
  declare function getNodeName(node: ts13.Node): string | undefined;
305
- export { zodAdapter, withDescription, valibotAdapter, typeboxAdapter, serializeVariable, serializeTypeAlias, serializeInterface, serializeFunctionExport, serializeEnum, serializeClass, schemasAreEqual, schemaIsAny, resolveCompiledPath, registerReferencedTypes, registerAdapter, isTypeReference, isSymbolDeprecated, isStandardJSONSchema, isSchemaType, isPureRefSchema, isPrimitiveName, isExported, isBuiltinGeneric, isAnonymous, getSourceLocation, getParamDescription, getNonNullableType, getNodeName, getJSDocComment, findDiscriminatorProperty, findAdapter, extractTypeParameters, extractStandardSchemasFromProject, extractStandardSchemas, extractSchemaType, extractParameters, extract, deduplicateSchemas, createProgram, buildSchema, arktypeAdapter, TypeRegistry, StandardSchemaExtractionResult, StandardSchemaExtractionOutput, StandardJSONSchemaV1, SerializerContext, SchemaExtractionResult, SchemaAdapter, ProgramResult, ProgramOptions, ExtractStandardSchemasOptions, ExtractResult, ExtractOptions, Diagnostic, BUILTIN_TYPE_SCHEMAS };
328
+ export { zodAdapter, withDescription, valibotAdapter, typeboxAdapter, serializeVariable, serializeTypeAlias, serializeInterface, serializeFunctionExport, serializeEnum, serializeClass, schemasAreEqual, schemaIsAny, resolveCompiledPath, registerReferencedTypes, registerAdapter, isTypeReference, isSymbolDeprecated, isStandardJSONSchema, isSchemaType, isPureRefSchema, isPrimitiveName, isExported, isBuiltinGeneric, isAnonymous, getSourceLocation, getParamDescription, getNonNullableType, getNodeName, getJSDocComment, findDiscriminatorProperty, findAdapter, extractTypeParameters, extractStandardSchemasFromProject, extractStandardSchemas, extractSchemaType, extractParameters, extract, deduplicateSchemas, createProgram, buildSchema, arktypeAdapter, TypeRegistry, TypeReference2 as TypeReference, StandardSchemaExtractionResult, StandardSchemaExtractionOutput, StandardJSONSchemaV1, SerializerContext, SchemaExtractionResult, SchemaAdapter, ProgramResult, ProgramOptions, ForgottenExport, ExtractStandardSchemasOptions, ExtractResult, ExtractOptions, Diagnostic, BUILTIN_TYPE_SCHEMAS };
package/dist/src/index.js CHANGED
@@ -26,7 +26,7 @@ import {
26
26
  serializeTypeAlias,
27
27
  serializeVariable,
28
28
  withDescription
29
- } from "../shared/chunk-mhaxcbzq.js";
29
+ } from "../shared/chunk-2v40ecks.js";
30
30
  // src/schema/registry.ts
31
31
  function isTypeReference(type) {
32
32
  return !!(type.flags & 524288 && type.objectFlags && type.objectFlags & 4);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpkg-ts/extract",
3
- "version": "0.14.5",
3
+ "version": "0.16.0",
4
4
  "description": "TypeScript export extraction to OpenPkg spec",
5
5
  "keywords": [
6
6
  "openpkg",