@openpkg-ts/extract 0.11.4 → 0.13.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.
- package/dist/bin/tspec.js +1 -1
- package/dist/shared/chunk-ksf9k654.js +1662 -0
- package/dist/src/index.d.ts +40 -21
- package/dist/src/index.js +8 -27
- package/package.json +3 -2
- package/dist/shared/chunk-twaykyxs.js +0 -681
package/dist/src/index.d.ts
CHANGED
|
@@ -13,6 +13,16 @@ declare class TypeRegistry {
|
|
|
13
13
|
*/
|
|
14
14
|
registerType(type: ts.Type, checker: ts.TypeChecker, exportedIds: Set<string>): string | undefined;
|
|
15
15
|
private buildSpecType;
|
|
16
|
+
/**
|
|
17
|
+
* Build a shallow schema for registry types (no deep recursion).
|
|
18
|
+
* Only captures top-level structure with $refs.
|
|
19
|
+
*/
|
|
20
|
+
private buildShallowSchema;
|
|
21
|
+
/**
|
|
22
|
+
* Extract shallow members for classes/interfaces.
|
|
23
|
+
* Only captures property names and simple type info.
|
|
24
|
+
*/
|
|
25
|
+
private extractShallowMembers;
|
|
16
26
|
registerFromSymbol(symbol: ts.Symbol, checker: ts.TypeChecker): SpecType | undefined;
|
|
17
27
|
}
|
|
18
28
|
import { SpecExample, SpecSource, SpecTag } from "@openpkg-ts/spec";
|
|
@@ -24,14 +34,12 @@ declare function getJSDocComment(node: ts2.Node): {
|
|
|
24
34
|
};
|
|
25
35
|
declare function getSourceLocation(node: ts2.Node, sourceFile: ts2.SourceFile): SpecSource;
|
|
26
36
|
import { OpenPkg } from "@openpkg-ts/spec";
|
|
27
|
-
import { TypeChecker as TypeChecker_lrgbhchnsl } from "typescript";
|
|
28
|
-
import { Program as Program_jbfzpxflck } from "typescript";
|
|
29
|
-
import { SourceFile as SourceFile_eubaywigwb } from "typescript";
|
|
30
37
|
interface ExtractOptions {
|
|
31
38
|
entryFile: string;
|
|
32
39
|
baseDir?: string;
|
|
33
40
|
content?: string;
|
|
34
41
|
maxTypeDepth?: number;
|
|
42
|
+
maxExternalTypeDepth?: number;
|
|
35
43
|
resolveExternalTypes?: boolean;
|
|
36
44
|
schemaExtraction?: "static" | "hybrid";
|
|
37
45
|
}
|
|
@@ -48,13 +56,6 @@ interface Diagnostic {
|
|
|
48
56
|
column?: number;
|
|
49
57
|
};
|
|
50
58
|
}
|
|
51
|
-
interface SerializerContext {
|
|
52
|
-
typeChecker: TypeChecker_lrgbhchnsl;
|
|
53
|
-
program: Program_jbfzpxflck;
|
|
54
|
-
sourceFile: SourceFile_eubaywigwb;
|
|
55
|
-
maxTypeDepth: number;
|
|
56
|
-
resolveExternalTypes: boolean;
|
|
57
|
-
}
|
|
58
59
|
declare function extract(options: ExtractOptions): Promise<ExtractResult>;
|
|
59
60
|
import ts3 from "typescript";
|
|
60
61
|
interface ProgramOptions {
|
|
@@ -95,48 +96,66 @@ declare function extractStandardSchemas(_program: ts5.Program, _entryFile: strin
|
|
|
95
96
|
import { SpecExport } from "@openpkg-ts/spec";
|
|
96
97
|
import ts7 from "typescript";
|
|
97
98
|
import ts6 from "typescript";
|
|
98
|
-
interface
|
|
99
|
+
interface SerializerContext {
|
|
99
100
|
typeChecker: ts6.TypeChecker;
|
|
100
101
|
program: ts6.Program;
|
|
101
102
|
sourceFile: ts6.SourceFile;
|
|
102
103
|
maxTypeDepth: number;
|
|
104
|
+
maxExternalTypeDepth: number;
|
|
105
|
+
currentDepth: number;
|
|
103
106
|
resolveExternalTypes: boolean;
|
|
104
107
|
typeRegistry: TypeRegistry;
|
|
105
108
|
exportedIds: Set<string>;
|
|
106
109
|
/** Track visited types to prevent infinite recursion */
|
|
107
110
|
visitedTypes: Set<ts6.Type>;
|
|
108
111
|
}
|
|
109
|
-
declare function serializeClass(node: ts7.ClassDeclaration, ctx:
|
|
112
|
+
declare function serializeClass(node: ts7.ClassDeclaration, ctx: SerializerContext): SpecExport | null;
|
|
110
113
|
import { SpecExport as SpecExport2 } from "@openpkg-ts/spec";
|
|
111
114
|
import ts8 from "typescript";
|
|
112
|
-
declare function serializeEnum(node: ts8.EnumDeclaration, ctx:
|
|
115
|
+
declare function serializeEnum(node: ts8.EnumDeclaration, ctx: SerializerContext): SpecExport2 | null;
|
|
113
116
|
import { SpecExport as SpecExport3 } from "@openpkg-ts/spec";
|
|
114
117
|
import ts9 from "typescript";
|
|
115
|
-
declare function serializeFunctionExport(node: ts9.FunctionDeclaration | ts9.ArrowFunction, ctx:
|
|
118
|
+
declare function serializeFunctionExport(node: ts9.FunctionDeclaration | ts9.ArrowFunction, ctx: SerializerContext): SpecExport3 | null;
|
|
116
119
|
import { SpecExport as SpecExport4 } from "@openpkg-ts/spec";
|
|
117
120
|
import ts10 from "typescript";
|
|
118
|
-
declare function serializeInterface(node: ts10.InterfaceDeclaration, ctx:
|
|
121
|
+
declare function serializeInterface(node: ts10.InterfaceDeclaration, ctx: SerializerContext): SpecExport4 | null;
|
|
119
122
|
import { SpecExport as SpecExport5 } from "@openpkg-ts/spec";
|
|
120
123
|
import ts11 from "typescript";
|
|
121
|
-
declare function serializeTypeAlias(node: ts11.TypeAliasDeclaration, ctx:
|
|
124
|
+
declare function serializeTypeAlias(node: ts11.TypeAliasDeclaration, ctx: SerializerContext): SpecExport5 | null;
|
|
122
125
|
import { SpecExport as SpecExport6 } from "@openpkg-ts/spec";
|
|
123
126
|
import ts12 from "typescript";
|
|
124
|
-
declare function serializeVariable(node: ts12.VariableDeclaration, statement: ts12.VariableStatement, ctx:
|
|
127
|
+
declare function serializeVariable(node: ts12.VariableDeclaration, statement: ts12.VariableStatement, ctx: SerializerContext): SpecExport6 | null;
|
|
125
128
|
import ts13 from "typescript";
|
|
126
129
|
declare function formatTypeReference(type: ts13.Type, checker: ts13.TypeChecker): string;
|
|
127
130
|
declare function collectReferencedTypes(type: ts13.Type, checker: ts13.TypeChecker, visited?: Set<string>): string[];
|
|
128
131
|
import { SpecSignatureParameter } from "@openpkg-ts/spec";
|
|
129
132
|
import ts14 from "typescript";
|
|
130
|
-
declare function extractParameters(signature: ts14.Signature, ctx:
|
|
133
|
+
declare function extractParameters(signature: ts14.Signature, ctx: SerializerContext): SpecSignatureParameter[];
|
|
131
134
|
/**
|
|
132
135
|
* Recursively register types referenced by a ts.Type.
|
|
133
136
|
* Uses ctx.visitedTypes to prevent infinite recursion on circular types.
|
|
134
137
|
*/
|
|
135
|
-
declare function registerReferencedTypes(type: ts14.Type, ctx:
|
|
138
|
+
declare function registerReferencedTypes(type: ts14.Type, ctx: SerializerContext): void;
|
|
136
139
|
import { SpecSchema as SpecSchema3 } from "@openpkg-ts/spec";
|
|
137
140
|
import ts15 from "typescript";
|
|
138
|
-
|
|
141
|
+
/**
|
|
142
|
+
* Check if a name is a primitive type
|
|
143
|
+
*/
|
|
144
|
+
declare function isPrimitiveName(name: string): boolean;
|
|
145
|
+
/**
|
|
146
|
+
* Check if a name is a built-in generic type
|
|
147
|
+
*/
|
|
148
|
+
declare function isBuiltinGeneric(name: string): boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Check if a type is anonymous (no meaningful symbol name)
|
|
151
|
+
*/
|
|
152
|
+
declare function isAnonymous(type: ts15.Type): boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Build a structured SpecSchema from a TypeScript type.
|
|
155
|
+
* Uses $ref for named types and typeArguments for generics.
|
|
156
|
+
*/
|
|
157
|
+
declare function buildSchema(type: ts15.Type, checker: ts15.TypeChecker, ctx?: SerializerContext, _depth?: number): SpecSchema3;
|
|
139
158
|
import ts16 from "typescript";
|
|
140
159
|
declare function isExported(node: ts16.Node): boolean;
|
|
141
160
|
declare function getNodeName(node: ts16.Node): string | undefined;
|
|
142
|
-
export { zodAdapter, valibotAdapter, typeboxAdapter, serializeVariable, serializeTypeAlias, serializeInterface, serializeFunctionExport, serializeEnum, serializeClass, registerReferencedTypes, registerAdapter, isSchemaType, isExported, getSourceLocation, getNodeName, getJSDocComment, formatTypeReference, findAdapter, extractStandardSchemas, extractSchemaType, extractParameters, extract, createProgram, collectReferencedTypes, buildSchema, arktypeAdapter, TypeRegistry, StandardSchemaResult, SerializerContext, SchemaAdapter, ProgramResult, ProgramOptions, ExtractResult, ExtractOptions, Diagnostic };
|
|
161
|
+
export { zodAdapter, valibotAdapter, typeboxAdapter, serializeVariable, serializeTypeAlias, serializeInterface, serializeFunctionExport, serializeEnum, serializeClass, registerReferencedTypes, registerAdapter, isSchemaType, isPrimitiveName, isExported, isBuiltinGeneric, isAnonymous, getSourceLocation, getNodeName, getJSDocComment, formatTypeReference, findAdapter, extractStandardSchemas, extractSchemaType, extractParameters, extract, createProgram, collectReferencedTypes, buildSchema, arktypeAdapter, TypeRegistry, StandardSchemaResult, SerializerContext, SchemaAdapter, ProgramResult, ProgramOptions, ExtractResult, ExtractOptions, Diagnostic };
|
package/dist/src/index.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TypeRegistry,
|
|
3
|
+
buildSchema,
|
|
3
4
|
createProgram,
|
|
4
5
|
extract,
|
|
5
6
|
extractParameters,
|
|
6
7
|
getJSDocComment,
|
|
7
8
|
getSourceLocation,
|
|
9
|
+
isAnonymous,
|
|
10
|
+
isBuiltinGeneric,
|
|
11
|
+
isPrimitiveName,
|
|
8
12
|
registerReferencedTypes,
|
|
9
13
|
serializeClass,
|
|
10
14
|
serializeEnum,
|
|
@@ -12,7 +16,7 @@ import {
|
|
|
12
16
|
serializeInterface,
|
|
13
17
|
serializeTypeAlias,
|
|
14
18
|
serializeVariable
|
|
15
|
-
} from "../shared/chunk-
|
|
19
|
+
} from "../shared/chunk-ksf9k654.js";
|
|
16
20
|
// src/schema/adapters/arktype.ts
|
|
17
21
|
var arktypeAdapter = {
|
|
18
22
|
name: "arktype",
|
|
@@ -70,32 +74,6 @@ function collectReferencedTypes(type, checker, visited = new Set) {
|
|
|
70
74
|
visited.add(name);
|
|
71
75
|
return [name];
|
|
72
76
|
}
|
|
73
|
-
// src/types/schema-builder.ts
|
|
74
|
-
function buildSchema(type, checker, depth = 0) {
|
|
75
|
-
if (depth > 10) {
|
|
76
|
-
return { type: checker.typeToString(type) };
|
|
77
|
-
}
|
|
78
|
-
const typeString = checker.typeToString(type);
|
|
79
|
-
if (type.flags & 4)
|
|
80
|
-
return { type: "string" };
|
|
81
|
-
if (type.flags & 8)
|
|
82
|
-
return { type: "number" };
|
|
83
|
-
if (type.flags & 16)
|
|
84
|
-
return { type: "boolean" };
|
|
85
|
-
if (type.flags & 32768)
|
|
86
|
-
return { type: "undefined" };
|
|
87
|
-
if (type.flags & 65536)
|
|
88
|
-
return { type: "null" };
|
|
89
|
-
if (type.flags & 16384)
|
|
90
|
-
return { type: "void" };
|
|
91
|
-
if (type.flags & 1)
|
|
92
|
-
return { type: "any" };
|
|
93
|
-
if (type.flags & 2)
|
|
94
|
-
return { type: "unknown" };
|
|
95
|
-
if (type.flags & 131072)
|
|
96
|
-
return { type: "never" };
|
|
97
|
-
return { type: typeString };
|
|
98
|
-
}
|
|
99
77
|
// src/types/utils.ts
|
|
100
78
|
function isExported(node) {
|
|
101
79
|
const modifiers = node.modifiers;
|
|
@@ -123,7 +101,10 @@ export {
|
|
|
123
101
|
registerReferencedTypes,
|
|
124
102
|
registerAdapter,
|
|
125
103
|
isSchemaType,
|
|
104
|
+
isPrimitiveName,
|
|
126
105
|
isExported,
|
|
106
|
+
isBuiltinGeneric,
|
|
107
|
+
isAnonymous,
|
|
127
108
|
getSourceLocation,
|
|
128
109
|
getNodeName,
|
|
129
110
|
getJSDocComment,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpkg-ts/extract",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "TypeScript export extraction to OpenPkg spec",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openpkg",
|
|
@@ -40,8 +40,9 @@
|
|
|
40
40
|
"format": "biome format --write src/"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@openpkg-ts/spec": "^0.
|
|
43
|
+
"@openpkg-ts/spec": "^0.12.0",
|
|
44
44
|
"commander": "^12.0.0",
|
|
45
|
+
"tree-sitter-wasms": "^0.1.13",
|
|
45
46
|
"typescript": "^5.0.0"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|