@openpkg-ts/extract 0.23.2 → 0.24.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.
@@ -13,6 +13,8 @@ interface SerializerContext {
13
13
  exportedIds: Set<string>;
14
14
  /** Track visited types to prevent infinite recursion */
15
15
  visitedTypes: Set<ts.Type>;
16
+ /** Flag to indicate we're processing tuple elements - skip Array prototype methods */
17
+ inTupleElement?: boolean;
16
18
  }
17
19
  declare class TypeRegistry {
18
20
  private types;
@@ -58,75 +60,13 @@ declare function getParamDescription(propertyName: string, jsdocTags: readonly t
58
60
  type DeclarationWithTypeParams = ts3.FunctionDeclaration | ts3.ClassDeclaration | ts3.InterfaceDeclaration | ts3.TypeAliasDeclaration | ts3.MethodDeclaration | ts3.ArrowFunction;
59
61
  /**
60
62
  * Extract type parameters from declarations like `<T extends Base, K = Default>`
63
+ * Also captures variance annotations (in/out) and const modifier.
61
64
  */
62
65
  declare function extractTypeParameters(node: DeclarationWithTypeParams, checker: ts3.TypeChecker): SpecTypeParameter[] | undefined;
63
66
  /**
64
67
  * Check if a symbol is marked as deprecated via @deprecated JSDoc tag.
65
68
  */
66
69
  declare function isSymbolDeprecated(symbol: ts3.Symbol | undefined): boolean;
67
- import { OpenPkg } from "@openpkg-ts/spec";
68
- interface ExtractOptions {
69
- entryFile: string;
70
- baseDir?: string;
71
- content?: string;
72
- maxTypeDepth?: number;
73
- maxExternalTypeDepth?: number;
74
- resolveExternalTypes?: boolean;
75
- schemaExtraction?: "static" | "hybrid";
76
- /** Target JSON Schema dialect for runtime schema extraction */
77
- schemaTarget?: "draft-2020-12" | "draft-07" | "openapi-3.0";
78
- /** Include $schema URL in output */
79
- includeSchema?: boolean;
80
- /** Only extract these exports (supports * wildcards) */
81
- only?: string[];
82
- /** Ignore these exports (supports * wildcards) */
83
- ignore?: string[];
84
- }
85
- interface ExtractResult {
86
- spec: OpenPkg;
87
- diagnostics: Diagnostic[];
88
- forgottenExports?: ForgottenExport[];
89
- /** Metadata about runtime schema extraction (when schemaExtraction: 'hybrid') */
90
- runtimeSchemas?: {
91
- /** Number of schema exports found */
92
- extracted: number;
93
- /** Number of schemas successfully merged with static types */
94
- merged: number;
95
- /** Schema vendors detected (e.g., 'zod', 'arktype', 'valibot', 'typebox') */
96
- vendors: string[];
97
- /** Any errors encountered during runtime extraction */
98
- errors: string[];
99
- /** Extraction method used: 'compiled' or 'direct-ts (runtime)' */
100
- method?: string;
101
- };
102
- }
103
- interface Diagnostic {
104
- message: string;
105
- severity: "error" | "warning" | "info";
106
- code?: string;
107
- suggestion?: string;
108
- location?: {
109
- file?: string;
110
- line?: number;
111
- column?: number;
112
- };
113
- }
114
- /** Context tracking for type references in public API */
115
- interface TypeReference2 {
116
- typeName: string;
117
- exportName: string;
118
- location: "return" | "parameter" | "property" | "extends" | "type-parameter";
119
- path?: string;
120
- }
121
- /** Structured data for forgotten exports */
122
- interface ForgottenExport {
123
- name: string;
124
- definedIn?: string;
125
- referencedBy: TypeReference2[];
126
- isExternal: boolean;
127
- fix?: string;
128
- }
129
- declare function extract(options: ExtractOptions): Promise<ExtractResult>;
130
70
  /**
131
71
  * Target version for JSON Schema generation.
132
72
  * @see https://standardschema.dev/json-schema
@@ -280,6 +220,69 @@ interface ProjectExtractionOutput extends StandardSchemaExtractionOutput {
280
220
  * @param options - Extraction options
281
221
  */
282
222
  declare function extractStandardSchemasFromProject(entryFile: string, baseDir: string, options?: ExtractFromProjectOptions): Promise<ProjectExtractionOutput>;
223
+ import { OpenPkg } from "@openpkg-ts/spec";
224
+ interface ExtractOptions {
225
+ entryFile: string;
226
+ baseDir?: string;
227
+ content?: string;
228
+ maxTypeDepth?: number;
229
+ maxExternalTypeDepth?: number;
230
+ resolveExternalTypes?: boolean;
231
+ schemaExtraction?: "static" | "hybrid";
232
+ /** Target JSON Schema dialect for runtime schema extraction */
233
+ schemaTarget?: "draft-2020-12" | "draft-07" | "openapi-3.0";
234
+ /** Include $schema URL in output */
235
+ includeSchema?: boolean;
236
+ /** Only extract these exports (supports * wildcards) */
237
+ only?: string[];
238
+ /** Ignore these exports (supports * wildcards) */
239
+ ignore?: string[];
240
+ }
241
+ interface ExtractResult {
242
+ spec: OpenPkg;
243
+ diagnostics: Diagnostic[];
244
+ forgottenExports?: ForgottenExport[];
245
+ /** Metadata about runtime schema extraction (when schemaExtraction: 'hybrid') */
246
+ runtimeSchemas?: {
247
+ /** Number of schema exports found */
248
+ extracted: number;
249
+ /** Number of schemas successfully merged with static types */
250
+ merged: number;
251
+ /** Schema vendors detected (e.g., 'zod', 'arktype', 'valibot', 'typebox') */
252
+ vendors: string[];
253
+ /** Any errors encountered during runtime extraction */
254
+ errors: string[];
255
+ /** Extraction method used: 'compiled' or 'direct-ts (runtime)' */
256
+ method?: string;
257
+ };
258
+ }
259
+ interface Diagnostic {
260
+ message: string;
261
+ severity: "error" | "warning" | "info";
262
+ code?: string;
263
+ suggestion?: string;
264
+ location?: {
265
+ file?: string;
266
+ line?: number;
267
+ column?: number;
268
+ };
269
+ }
270
+ /** Context tracking for type references in public API */
271
+ interface TypeReference2 {
272
+ typeName: string;
273
+ exportName: string;
274
+ location: "return" | "parameter" | "property" | "extends" | "type-parameter";
275
+ path?: string;
276
+ }
277
+ /** Structured data for forgotten exports */
278
+ interface ForgottenExport {
279
+ name: string;
280
+ definedIn?: string;
281
+ referencedBy: TypeReference2[];
282
+ isExternal: boolean;
283
+ fix?: string;
284
+ }
285
+ declare function extract(options: ExtractOptions): Promise<ExtractResult>;
283
286
  import ts4 from "typescript";
284
287
  interface ProgramOptions {
285
288
  entryFile: string;
@@ -380,11 +383,21 @@ import ts12 from "typescript";
380
383
  * Used for types that have specific serialization formats.
381
384
  */
382
385
  declare const BUILTIN_TYPE_SCHEMAS: Record<string, SpecSchema>;
386
+ declare const ARRAY_PROTOTYPE_METHODS: unknown;
383
387
  /**
384
388
  * Check if a name is a primitive type
385
389
  */
386
390
  declare function isPrimitiveName(name: string): boolean;
387
391
  /**
392
+ * Get the origin package name for a type if it comes from node_modules.
393
+ * Returns undefined for types defined in the current project.
394
+ *
395
+ * @example
396
+ * getTypeOrigin(trpcRouterType) // Returns '@trpc/server'
397
+ * getTypeOrigin(localUserType) // Returns undefined
398
+ */
399
+ declare function getTypeOrigin(type: ts12.Type, _checker: ts12.TypeChecker): string | undefined;
400
+ /**
388
401
  * Check if a name is a built-in generic type
389
402
  */
390
403
  declare function isBuiltinGeneric(name: string): boolean;
@@ -425,7 +438,7 @@ declare function deduplicateSchemas(schemas: SpecSchema[]): SpecSchema[];
425
438
  * A valid discriminator has a unique literal value in each union member.
426
439
  */
427
440
  declare function findDiscriminatorProperty(unionTypes: ts12.Type[], checker: ts12.TypeChecker): string | undefined;
428
- import { SpecSchema as SpecSchema2, SpecExport as SpecExport8, SpecType as SpecType2, SpecMember } from "@openpkg-ts/spec";
441
+ import { SpecExport as SpecExport8, SpecMember, SpecSchema as SpecSchema2, SpecType as SpecType2 } from "@openpkg-ts/spec";
429
442
  /**
430
443
  * Options for schema normalization
431
444
  */
@@ -490,4 +503,4 @@ declare function normalizeMembers(members: SpecMember[], options?: NormalizeOpti
490
503
  import ts13 from "typescript";
491
504
  declare function isExported(node: ts13.Node): boolean;
492
505
  declare function getNodeName(node: ts13.Node): string | undefined;
493
- export { zodAdapter, withDescription, valibotAdapter, typeboxAdapter, serializeVariable, serializeTypeAlias, serializeInterface, serializeFunctionExport, serializeEnum, serializeClass, schemasAreEqual, schemaIsAny, resolveCompiledPath, registerReferencedTypes, registerAdapter, normalizeType, normalizeSchema, normalizeMembers, normalizeExport, isTypeReference, isSymbolDeprecated, isStandardJSONSchema, isSchemaType, isPureRefSchema, isPrimitiveName, isExported, isBuiltinGeneric, isAnonymous, getSourceLocation, getParamDescription, getNonNullableType, getNodeName, getJSDocComment, findDiscriminatorProperty, findAdapter, extractTypeParameters, extractStandardSchemasFromTs, extractStandardSchemasFromProject, extractStandardSchemas, extractSchemaType, extractParameters, extract, detectTsRuntime, deduplicateSchemas, createProgram, buildSchema, arktypeAdapter, TypeRegistry, TypeReference2 as TypeReference, TsRuntime, StandardSchemaExtractionResult, StandardSchemaExtractionOutput, StandardJSONSchemaV1, StandardJSONSchemaTarget, StandardJSONSchemaOptions, SerializerContext, SchemaExtractionResult, SchemaAdapter, ProjectExtractionOutput, ProjectExtractionInfo, ProgramResult, ProgramOptions, NormalizeOptions, JSONSchema, ForgottenExport, ExtractStandardSchemasOptions, ExtractResult, ExtractOptions, ExtractFromProjectOptions, Diagnostic, BUILTIN_TYPE_SCHEMAS };
506
+ export { zodAdapter, withDescription, valibotAdapter, typeboxAdapter, serializeVariable, serializeTypeAlias, serializeInterface, serializeFunctionExport, serializeEnum, serializeClass, schemasAreEqual, schemaIsAny, resolveCompiledPath, registerReferencedTypes, registerAdapter, normalizeType, normalizeSchema, normalizeMembers, normalizeExport, isTypeReference, isSymbolDeprecated, isStandardJSONSchema, isSchemaType, isPureRefSchema, isPrimitiveName, isExported, isBuiltinGeneric, isAnonymous, getTypeOrigin, getSourceLocation, getParamDescription, getNonNullableType, getNodeName, getJSDocComment, findDiscriminatorProperty, findAdapter, extractTypeParameters, extractStandardSchemasFromTs, extractStandardSchemasFromProject, extractStandardSchemas, extractSchemaType, extractParameters, extract, detectTsRuntime, deduplicateSchemas, createProgram, buildSchema, arktypeAdapter, TypeRegistry, TypeReference2 as TypeReference, TsRuntime, StandardSchemaExtractionResult, StandardSchemaExtractionOutput, StandardJSONSchemaV1, StandardJSONSchemaTarget, StandardJSONSchemaOptions, SerializerContext, SchemaExtractionResult, SchemaAdapter, ProjectExtractionOutput, ProjectExtractionInfo, ProgramResult, ProgramOptions, NormalizeOptions, JSONSchema, ForgottenExport, ExtractStandardSchemasOptions, ExtractResult, ExtractOptions, ExtractFromProjectOptions, Diagnostic, BUILTIN_TYPE_SCHEMAS, ARRAY_PROTOTYPE_METHODS };
package/dist/src/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import {
2
+ ARRAY_PROTOTYPE_METHODS,
2
3
  BUILTIN_TYPE_SCHEMAS,
3
4
  TypeRegistry,
4
5
  arktypeAdapter,
@@ -19,6 +20,7 @@ import {
19
20
  getNonNullableType,
20
21
  getParamDescription,
21
22
  getSourceLocation,
23
+ getTypeOrigin,
22
24
  isAnonymous,
23
25
  isBuiltinGeneric,
24
26
  isPrimitiveName,
@@ -46,7 +48,7 @@ import {
46
48
  valibotAdapter,
47
49
  withDescription,
48
50
  zodAdapter
49
- } from "../shared/chunk-8898fs2f.js";
51
+ } from "../shared/chunk-bh378f7b.js";
50
52
  // src/types/utils.ts
51
53
  function isExported(node) {
52
54
  const modifiers = node.modifiers;
@@ -90,6 +92,7 @@ export {
90
92
  isExported,
91
93
  isBuiltinGeneric,
92
94
  isAnonymous,
95
+ getTypeOrigin,
93
96
  getSourceLocation,
94
97
  getParamDescription,
95
98
  getNonNullableType,
@@ -110,5 +113,6 @@ export {
110
113
  buildSchema,
111
114
  arktypeAdapter,
112
115
  TypeRegistry,
113
- BUILTIN_TYPE_SCHEMAS
116
+ BUILTIN_TYPE_SCHEMAS,
117
+ ARRAY_PROTOTYPE_METHODS
114
118
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpkg-ts/extract",
3
- "version": "0.23.2",
3
+ "version": "0.24.0",
4
4
  "description": "TypeScript export extraction to OpenPkg spec",
5
5
  "keywords": [
6
6
  "openpkg",
@@ -40,7 +40,7 @@
40
40
  "format": "biome format --write src/"
41
41
  },
42
42
  "dependencies": {
43
- "@openpkg-ts/spec": "^0.23.0",
43
+ "@openpkg-ts/spec": "^0.24.0",
44
44
  "chalk": "^5.4.1",
45
45
  "commander": "^12.0.0",
46
46
  "tree-sitter-wasms": "^0.1.13",