@prodisco/search-libs 0.1.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/LICENSE +21 -0
- package/README.md +379 -0
- package/dist/__tests__/extractor.test.d.ts +5 -0
- package/dist/__tests__/extractor.test.d.ts.map +1 -0
- package/dist/__tests__/extractor.test.js +452 -0
- package/dist/__tests__/extractor.test.js.map +1 -0
- package/dist/__tests__/library-indexer.test.d.ts +5 -0
- package/dist/__tests__/library-indexer.test.d.ts.map +1 -0
- package/dist/__tests__/library-indexer.test.js +611 -0
- package/dist/__tests__/library-indexer.test.js.map +1 -0
- package/dist/__tests__/schema.test.d.ts +5 -0
- package/dist/__tests__/schema.test.d.ts.map +1 -0
- package/dist/__tests__/schema.test.js +231 -0
- package/dist/__tests__/schema.test.js.map +1 -0
- package/dist/__tests__/script-parser.test.d.ts +5 -0
- package/dist/__tests__/script-parser.test.d.ts.map +1 -0
- package/dist/__tests__/script-parser.test.js +178 -0
- package/dist/__tests__/script-parser.test.js.map +1 -0
- package/dist/__tests__/search-engine.test.d.ts +5 -0
- package/dist/__tests__/search-engine.test.d.ts.map +1 -0
- package/dist/__tests__/search-engine.test.js +497 -0
- package/dist/__tests__/search-engine.test.js.map +1 -0
- package/dist/extractor/ast-parser.d.ts +48 -0
- package/dist/extractor/ast-parser.d.ts.map +1 -0
- package/dist/extractor/ast-parser.js +118 -0
- package/dist/extractor/ast-parser.js.map +1 -0
- package/dist/extractor/function-extractor.d.ts +20 -0
- package/dist/extractor/function-extractor.d.ts.map +1 -0
- package/dist/extractor/function-extractor.js +169 -0
- package/dist/extractor/function-extractor.js.map +1 -0
- package/dist/extractor/index.d.ts +22 -0
- package/dist/extractor/index.d.ts.map +1 -0
- package/dist/extractor/index.js +194 -0
- package/dist/extractor/index.js.map +1 -0
- package/dist/extractor/method-extractor.d.ts +30 -0
- package/dist/extractor/method-extractor.d.ts.map +1 -0
- package/dist/extractor/method-extractor.js +163 -0
- package/dist/extractor/method-extractor.js.map +1 -0
- package/dist/extractor/package-resolver.d.ts +77 -0
- package/dist/extractor/package-resolver.d.ts.map +1 -0
- package/dist/extractor/package-resolver.js +766 -0
- package/dist/extractor/package-resolver.js.map +1 -0
- package/dist/extractor/type-extractor.d.ts +15 -0
- package/dist/extractor/type-extractor.d.ts.map +1 -0
- package/dist/extractor/type-extractor.js +206 -0
- package/dist/extractor/type-extractor.js.map +1 -0
- package/dist/extractor/types.d.ts +116 -0
- package/dist/extractor/types.d.ts.map +1 -0
- package/dist/extractor/types.js +5 -0
- package/dist/extractor/types.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/library-indexer.d.ts +104 -0
- package/dist/library-indexer.d.ts.map +1 -0
- package/dist/library-indexer.js +295 -0
- package/dist/library-indexer.js.map +1 -0
- package/dist/schema/base-schema.d.ts +63 -0
- package/dist/schema/base-schema.d.ts.map +1 -0
- package/dist/schema/base-schema.js +63 -0
- package/dist/schema/base-schema.js.map +1 -0
- package/dist/schema/index.d.ts +6 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +6 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/schema-builder.d.ts +47 -0
- package/dist/schema/schema-builder.d.ts.map +1 -0
- package/dist/schema/schema-builder.js +236 -0
- package/dist/schema/schema-builder.js.map +1 -0
- package/dist/script/index.d.ts +6 -0
- package/dist/script/index.d.ts.map +1 -0
- package/dist/script/index.js +5 -0
- package/dist/script/index.js.map +1 -0
- package/dist/script/script-parser.d.ts +18 -0
- package/dist/script/script-parser.d.ts.map +1 -0
- package/dist/script/script-parser.js +246 -0
- package/dist/script/script-parser.js.map +1 -0
- package/dist/script/types.d.ts +32 -0
- package/dist/script/types.d.ts.map +1 -0
- package/dist/script/types.js +5 -0
- package/dist/script/types.js.map +1 -0
- package/dist/search/index.d.ts +7 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +7 -0
- package/dist/search/index.js.map +1 -0
- package/dist/search/query-builder.d.ts +59 -0
- package/dist/search/query-builder.d.ts.map +1 -0
- package/dist/search/query-builder.js +103 -0
- package/dist/search/query-builder.js.map +1 -0
- package/dist/search/result-formatter.d.ts +61 -0
- package/dist/search/result-formatter.d.ts.map +1 -0
- package/dist/search/result-formatter.js +170 -0
- package/dist/search/result-formatter.js.map +1 -0
- package/dist/search/search-engine.d.ts +105 -0
- package/dist/search/search-engine.d.ts.map +1 -0
- package/dist/search/search-engine.js +245 -0
- package/dist/search/search-engine.js.map +1 -0
- package/package.json +41 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript AST parsing utilities
|
|
3
|
+
*/
|
|
4
|
+
import * as ts from 'typescript';
|
|
5
|
+
/**
|
|
6
|
+
* Create a TypeScript source file from source code
|
|
7
|
+
*/
|
|
8
|
+
export function createSourceFile(filePath, sourceCode) {
|
|
9
|
+
return ts.createSourceFile(filePath, sourceCode, ts.ScriptTarget.Latest, true);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Extract JSDoc comment from a node
|
|
13
|
+
*/
|
|
14
|
+
export function getJSDocDescription(node) {
|
|
15
|
+
const jsDocComments = ts.getJSDocCommentsAndTags(node);
|
|
16
|
+
for (const comment of jsDocComments) {
|
|
17
|
+
if (ts.isJSDoc(comment) && comment.comment) {
|
|
18
|
+
if (typeof comment.comment === 'string') {
|
|
19
|
+
return comment.comment;
|
|
20
|
+
}
|
|
21
|
+
// Handle JSDoc comment that is an array of nodes
|
|
22
|
+
if (Array.isArray(comment.comment)) {
|
|
23
|
+
return comment.comment
|
|
24
|
+
.map((c) => (typeof c === 'string' ? c : c.getText()))
|
|
25
|
+
.join('');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Extract nested type references from a TypeNode
|
|
33
|
+
* Returns all type references found in the node
|
|
34
|
+
*/
|
|
35
|
+
export function extractNestedTypeRefs(typeNode, sourceFile) {
|
|
36
|
+
if (!typeNode) {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
const refs = [];
|
|
40
|
+
function visit(node) {
|
|
41
|
+
if (ts.isTypeReferenceNode(node)) {
|
|
42
|
+
const typeName = node.typeName.getText(sourceFile);
|
|
43
|
+
if (!refs.includes(typeName)) {
|
|
44
|
+
refs.push(typeName);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
ts.forEachChild(node, visit);
|
|
48
|
+
}
|
|
49
|
+
visit(typeNode);
|
|
50
|
+
return refs;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Extract parameter information from a function/method signature
|
|
54
|
+
*/
|
|
55
|
+
export function extractParameterInfo(params, sourceFile) {
|
|
56
|
+
const result = [];
|
|
57
|
+
for (const param of params) {
|
|
58
|
+
const name = param.name.getText(sourceFile);
|
|
59
|
+
const type = param.type?.getText(sourceFile) || 'any';
|
|
60
|
+
const optional = !!param.questionToken || !!param.initializer;
|
|
61
|
+
const description = getJSDocDescription(param);
|
|
62
|
+
result.push({ name, type, optional, description });
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Split camelCase/PascalCase identifiers into separate words for better search matching
|
|
68
|
+
* e.g., "queryRange" -> "query Range", "queryRangeStream" -> "query Range Stream"
|
|
69
|
+
*/
|
|
70
|
+
export function splitCamelCase(identifier) {
|
|
71
|
+
return identifier.replace(/([a-z])([A-Z])/g, '$1 $2');
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Check if a node has a specific modifier
|
|
75
|
+
*/
|
|
76
|
+
export function hasModifier(node, kind) {
|
|
77
|
+
const modifiers = ts.canHaveModifiers(node) ? ts.getModifiers(node) : undefined;
|
|
78
|
+
return modifiers?.some((m) => m.kind === kind) ?? false;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Check if a method is async (has async modifier or returns Promise)
|
|
82
|
+
*/
|
|
83
|
+
export function isAsyncMethod(node, sourceFile) {
|
|
84
|
+
// Check for async modifier
|
|
85
|
+
if (hasModifier(node, ts.SyntaxKind.AsyncKeyword)) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
// Check if return type is Promise
|
|
89
|
+
const returnType = node.type?.getText(sourceFile);
|
|
90
|
+
return returnType?.startsWith('Promise<') ?? false;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Check if a method is static
|
|
94
|
+
*/
|
|
95
|
+
export function isStaticMethod(node) {
|
|
96
|
+
return hasModifier(node, ts.SyntaxKind.StaticKeyword);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Check if a member is private (has private modifier or starts with underscore)
|
|
100
|
+
*/
|
|
101
|
+
export function isPrivateMember(node, sourceFile, name) {
|
|
102
|
+
if (hasModifier(node, ts.SyntaxKind.PrivateKeyword)) {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
if (name && name.startsWith('_')) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Get the text of a node, safely handling undefined
|
|
112
|
+
*/
|
|
113
|
+
export function getNodeText(node, sourceFile) {
|
|
114
|
+
if (!node)
|
|
115
|
+
return '';
|
|
116
|
+
return node.getText(sourceFile);
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=ast-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast-parser.js","sourceRoot":"","sources":["../../src/extractor/ast-parser.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAGjC;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAgB,EAAE,UAAkB;IACnE,OAAO,EAAE,CAAC,g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|
+
import * as ts from 'typescript';
|
|
5
|
+
import type { ExtractedFunction } from './types.js';
|
|
6
|
+
export interface ExtractFunctionsOptions {
|
|
7
|
+
/** If provided, only functions whose *local* name is in the set will be returned. */
|
|
8
|
+
allowlist?: Set<string>;
|
|
9
|
+
/** Optional rename map from localName -> publicName */
|
|
10
|
+
aliases?: Map<string, string>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Extract all exported functions from a TypeScript file
|
|
14
|
+
*/
|
|
15
|
+
export declare function extractFunctionsFromFile(filePath: string, libraryName: string, options?: ExtractFunctionsOptions): ExtractedFunction[];
|
|
16
|
+
/**
|
|
17
|
+
* Extract functions from export declarations (for libraries that re-export)
|
|
18
|
+
*/
|
|
19
|
+
export declare function extractExportedFunctions(sourceFile: ts.SourceFile, libraryName: string, filePath: string, resolver?: (moduleName: string) => string | null): ExtractedFunction[];
|
|
20
|
+
//# sourceMappingURL=function-extractor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function-extractor.d.ts","sourceRoot":"","sources":["../../src/extractor/function-extractor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,YAAY,CAAC;AAQnE,MAAM,WAAW,uBAAuB;IACtC,qFAAqF;IACrF,SAAS,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,uDAAuD;IACvD,OAAO,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AAMD;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,uBAAuB,GAChC,iBAAiB,EAAE,CA+ErB;AAmGD;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,UAAU,EAAE,EAAE,CAAC,UAAU,EACzB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,GAC/C,iBAAiB,EAAE,CAkCrB"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract standalone functions from TypeScript files
|
|
3
|
+
*/
|
|
4
|
+
import * as ts from 'typescript';
|
|
5
|
+
import { readFileSync, existsSync } from 'fs';
|
|
6
|
+
import { createSourceFile, getJSDocDescription, extractParameterInfo, } from './ast-parser.js';
|
|
7
|
+
function isJavaScriptFile(filePath) {
|
|
8
|
+
return filePath.endsWith('.js') || filePath.endsWith('.mjs') || filePath.endsWith('.cjs');
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Extract all exported functions from a TypeScript file
|
|
12
|
+
*/
|
|
13
|
+
export function extractFunctionsFromFile(filePath, libraryName, options) {
|
|
14
|
+
if (!existsSync(filePath)) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
const sourceCode = readFileSync(filePath, 'utf-8');
|
|
18
|
+
const sourceFile = createSourceFile(filePath, sourceCode);
|
|
19
|
+
const functions = [];
|
|
20
|
+
const allowlist = options?.allowlist;
|
|
21
|
+
const aliases = options?.aliases;
|
|
22
|
+
const defaultReturnType = isJavaScriptFile(filePath) ? 'any' : 'void';
|
|
23
|
+
function pushWithAlias(func) {
|
|
24
|
+
const publicName = aliases?.get(func.name) ?? func.name;
|
|
25
|
+
if (publicName !== func.name) {
|
|
26
|
+
func = {
|
|
27
|
+
...func,
|
|
28
|
+
name: publicName,
|
|
29
|
+
signature: buildSignature(publicName, func.parameters, func.returnType),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
functions.push(func);
|
|
33
|
+
}
|
|
34
|
+
function visit(node) {
|
|
35
|
+
// Extract function declarations
|
|
36
|
+
if (ts.isFunctionDeclaration(node) && node.name) {
|
|
37
|
+
const localName = node.name.text;
|
|
38
|
+
if (allowlist && !allowlist.has(localName)) {
|
|
39
|
+
// Not part of the public surface (or not requested)
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const extracted = extractFunctionDeclaration(node, sourceFile, libraryName, filePath, defaultReturnType);
|
|
43
|
+
if (extracted)
|
|
44
|
+
pushWithAlias(extracted);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// Extract exported variable declarations that are arrow functions
|
|
48
|
+
if (ts.isVariableStatement(node)) {
|
|
49
|
+
const isExported = node.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword);
|
|
50
|
+
for (const decl of node.declarationList.declarations) {
|
|
51
|
+
if (ts.isIdentifier(decl.name) &&
|
|
52
|
+
decl.initializer &&
|
|
53
|
+
(ts.isArrowFunction(decl.initializer) ||
|
|
54
|
+
ts.isFunctionExpression(decl.initializer))) {
|
|
55
|
+
const localName = decl.name.text;
|
|
56
|
+
const shouldInclude = allowlist
|
|
57
|
+
? allowlist.has(localName)
|
|
58
|
+
: isExported;
|
|
59
|
+
if (!shouldInclude)
|
|
60
|
+
continue;
|
|
61
|
+
const extracted = extractArrowFunction(decl, decl.initializer, sourceFile, libraryName, filePath, defaultReturnType);
|
|
62
|
+
if (extracted)
|
|
63
|
+
pushWithAlias(extracted);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
ts.forEachChild(node, visit);
|
|
68
|
+
}
|
|
69
|
+
visit(sourceFile);
|
|
70
|
+
return functions;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Extract a function declaration
|
|
74
|
+
*/
|
|
75
|
+
function extractFunctionDeclaration(node, sourceFile, libraryName, filePath, defaultReturnType) {
|
|
76
|
+
if (!node.name)
|
|
77
|
+
return null;
|
|
78
|
+
const name = node.name.text;
|
|
79
|
+
// Skip internal functions
|
|
80
|
+
if (name.startsWith('_')) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
const description = getJSDocDescription(node) || `${name} function`;
|
|
84
|
+
const parameters = extractParameterInfo(node.parameters, sourceFile);
|
|
85
|
+
const returnType = node.type?.getText(sourceFile) || defaultReturnType;
|
|
86
|
+
const signature = buildSignature(name, parameters, returnType);
|
|
87
|
+
return {
|
|
88
|
+
name,
|
|
89
|
+
description,
|
|
90
|
+
signature,
|
|
91
|
+
parameters,
|
|
92
|
+
returnType,
|
|
93
|
+
sourceFile: filePath,
|
|
94
|
+
library: libraryName,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Extract an arrow function or function expression
|
|
99
|
+
*/
|
|
100
|
+
function extractArrowFunction(decl, func, sourceFile, libraryName, filePath, defaultReturnType) {
|
|
101
|
+
if (!ts.isIdentifier(decl.name))
|
|
102
|
+
return null;
|
|
103
|
+
const name = decl.name.text;
|
|
104
|
+
// Skip internal functions
|
|
105
|
+
if (name.startsWith('_')) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
const description = getJSDocDescription(decl) ||
|
|
109
|
+
getJSDocDescription(func) ||
|
|
110
|
+
`${name} function`;
|
|
111
|
+
const parameters = extractParameterInfo(func.parameters, sourceFile);
|
|
112
|
+
// Get return type from function or infer from arrow function
|
|
113
|
+
let returnType = func.type?.getText(sourceFile);
|
|
114
|
+
if (!returnType) {
|
|
115
|
+
// For JS (and TS without annotations), we default to a safe "any"
|
|
116
|
+
returnType = defaultReturnType === 'any' ? 'any' : ts.isArrowFunction(func) ? 'any' : defaultReturnType;
|
|
117
|
+
}
|
|
118
|
+
const signature = buildSignature(name, parameters, returnType);
|
|
119
|
+
return {
|
|
120
|
+
name,
|
|
121
|
+
description,
|
|
122
|
+
signature,
|
|
123
|
+
parameters,
|
|
124
|
+
returnType,
|
|
125
|
+
sourceFile: filePath,
|
|
126
|
+
library: libraryName,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Build a function signature string
|
|
131
|
+
*/
|
|
132
|
+
function buildSignature(name, parameters, returnType) {
|
|
133
|
+
const paramStr = parameters
|
|
134
|
+
.map((p) => `${p.name}${p.optional ? '?' : ''}: ${p.type}`)
|
|
135
|
+
.join(', ');
|
|
136
|
+
return `${name}(${paramStr}): ${returnType}`;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Extract functions from export declarations (for libraries that re-export)
|
|
140
|
+
*/
|
|
141
|
+
export function extractExportedFunctions(sourceFile, libraryName, filePath, resolver) {
|
|
142
|
+
const functions = [];
|
|
143
|
+
function visit(node) {
|
|
144
|
+
// Handle named exports: export { foo, bar }
|
|
145
|
+
if (ts.isExportDeclaration(node) &&
|
|
146
|
+
node.exportClause &&
|
|
147
|
+
ts.isNamedExports(node.exportClause)) {
|
|
148
|
+
for (const element of node.exportClause.elements) {
|
|
149
|
+
const exportName = element.name.getText(sourceFile);
|
|
150
|
+
// If there's a module specifier and a resolver, try to get the actual function
|
|
151
|
+
if (node.moduleSpecifier && resolver) {
|
|
152
|
+
const moduleSpec = node.moduleSpecifier.getText(sourceFile).replace(/['"]/g, '');
|
|
153
|
+
const resolvedPath = resolver(moduleSpec);
|
|
154
|
+
if (resolvedPath) {
|
|
155
|
+
const moduleFunctions = extractFunctionsFromFile(resolvedPath, libraryName);
|
|
156
|
+
const found = moduleFunctions.find((f) => f.name === exportName);
|
|
157
|
+
if (found) {
|
|
158
|
+
functions.push(found);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
ts.forEachChild(node, visit);
|
|
165
|
+
}
|
|
166
|
+
visit(sourceFile);
|
|
167
|
+
return functions;
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=function-extractor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function-extractor.js","sourceRoot":"","sources":["../../src/extractor/function-extractor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,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AK,UAAU,CAAC,CAAC;wBACjE,IAAI,KAAK,EAAE,CAAC;4BACV,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;wBACxB,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,CAAC;IAClB,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extractor module - Extract types, methods, and functions from TypeScript packages
|
|
3
|
+
*/
|
|
4
|
+
import type { ExtractionOptions, ExtractionResult } from './types.js';
|
|
5
|
+
export * from './types.js';
|
|
6
|
+
export { resolvePackage, findDtsFiles } from './package-resolver.js';
|
|
7
|
+
export { extractTypesFromFile } from './type-extractor.js';
|
|
8
|
+
export { extractMethodsFromFile } from './method-extractor.js';
|
|
9
|
+
export { extractFunctionsFromFile } from './function-extractor.js';
|
|
10
|
+
export * from './ast-parser.js';
|
|
11
|
+
/**
|
|
12
|
+
* Extract types, methods, and functions from an npm package
|
|
13
|
+
*/
|
|
14
|
+
export declare function extractFromPackage(options: ExtractionOptions): ExtractionResult;
|
|
15
|
+
/**
|
|
16
|
+
* Extract from specific .d.ts files
|
|
17
|
+
*/
|
|
18
|
+
export declare function extractFromFiles(files: string[], libraryName: string, options?: {
|
|
19
|
+
typeFilter?: RegExp | ((name: string) => boolean);
|
|
20
|
+
methodFilter?: RegExp | ((name: string) => boolean);
|
|
21
|
+
}): ExtractionResult;
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/extractor/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAKjB,MAAM,YAAY,CAAC;AAapB,cAAc,YAAY,CAAC;AAG3B,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACnE,cAAc,iBAAiB,CAAC;AAEhC;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,iBAAiB,GAAG,gBAAgB,CAyM/E;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EAAE,EACf,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE;IACR,UAAU,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC;IAClD,YAAY,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC;CACrD,GACA,gBAAgB,CAOlB"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extractor module - Extract types, methods, and functions from TypeScript packages
|
|
3
|
+
*/
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
import { resolvePackage, getPackageJson, findMainEsmJs, buildEsmExportSurface, } from './package-resolver.js';
|
|
6
|
+
import { extractTypesFromFile } from './type-extractor.js';
|
|
7
|
+
import { extractMethodsFromFile } from './method-extractor.js';
|
|
8
|
+
import { extractFunctionsFromFile } from './function-extractor.js';
|
|
9
|
+
// Re-export types
|
|
10
|
+
export * from './types.js';
|
|
11
|
+
// Re-export utilities
|
|
12
|
+
export { resolvePackage, findDtsFiles } from './package-resolver.js';
|
|
13
|
+
export { extractTypesFromFile } from './type-extractor.js';
|
|
14
|
+
export { extractMethodsFromFile } from './method-extractor.js';
|
|
15
|
+
export { extractFunctionsFromFile } from './function-extractor.js';
|
|
16
|
+
export * from './ast-parser.js';
|
|
17
|
+
/**
|
|
18
|
+
* Extract types, methods, and functions from an npm package
|
|
19
|
+
*/
|
|
20
|
+
export function extractFromPackage(options) {
|
|
21
|
+
const { packageName, dtsFiles: providedDtsFiles, typeFilter, methodFilter, classFilter, basePath = process.cwd(), } = options;
|
|
22
|
+
const types = [];
|
|
23
|
+
const methods = [];
|
|
24
|
+
const functions = [];
|
|
25
|
+
const errors = [];
|
|
26
|
+
// Resolve package if no files provided
|
|
27
|
+
let dtsFiles = providedDtsFiles;
|
|
28
|
+
let exportAliases;
|
|
29
|
+
let publicExports;
|
|
30
|
+
let jsSurface;
|
|
31
|
+
if (!dtsFiles || dtsFiles.length === 0) {
|
|
32
|
+
const packageInfo = resolvePackage(packageName, basePath);
|
|
33
|
+
if (!packageInfo) {
|
|
34
|
+
errors.push({
|
|
35
|
+
file: packageName,
|
|
36
|
+
message: `Could not resolve package: ${packageName}`,
|
|
37
|
+
});
|
|
38
|
+
return { packageName, types, methods, functions, errors };
|
|
39
|
+
}
|
|
40
|
+
dtsFiles = packageInfo.allDtsFiles;
|
|
41
|
+
exportAliases = packageInfo.exportAliases;
|
|
42
|
+
publicExports = packageInfo.publicExports;
|
|
43
|
+
// JS fallback: if no .d.ts files exist, attempt to index from ESM JavaScript source.
|
|
44
|
+
if (dtsFiles.length === 0) {
|
|
45
|
+
const packageJsonPath = join(packageInfo.packagePath, 'package.json');
|
|
46
|
+
const packageJson = getPackageJson(packageJsonPath);
|
|
47
|
+
if (!packageJson) {
|
|
48
|
+
errors.push({
|
|
49
|
+
file: packageName,
|
|
50
|
+
message: `No .d.ts files found and could not read package.json for package: ${packageName}`,
|
|
51
|
+
});
|
|
52
|
+
return { packageName, types, methods, functions, errors };
|
|
53
|
+
}
|
|
54
|
+
const entryFile = findMainEsmJs(packageInfo.packagePath, packageJson);
|
|
55
|
+
if (!entryFile) {
|
|
56
|
+
errors.push({
|
|
57
|
+
file: packageName,
|
|
58
|
+
message: `No .d.ts files found and no ESM JavaScript entrypoint found for package: ${packageName}`,
|
|
59
|
+
});
|
|
60
|
+
return { packageName, types, methods, functions, errors };
|
|
61
|
+
}
|
|
62
|
+
jsSurface = buildEsmExportSurface(entryFile);
|
|
63
|
+
if (jsSurface.publicExports.size === 0) {
|
|
64
|
+
errors.push({
|
|
65
|
+
file: packageName,
|
|
66
|
+
message: `No .d.ts files found and no ESM exports discovered for package: ${packageName}`,
|
|
67
|
+
});
|
|
68
|
+
return { packageName, types, methods, functions, errors };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Create filter functions
|
|
73
|
+
const typeFilterFn = typeof typeFilter === 'function'
|
|
74
|
+
? typeFilter
|
|
75
|
+
: typeFilter instanceof RegExp
|
|
76
|
+
? (name) => typeFilter.test(name)
|
|
77
|
+
: undefined;
|
|
78
|
+
const methodFilterFn = typeof methodFilter === 'function'
|
|
79
|
+
? methodFilter
|
|
80
|
+
: methodFilter instanceof RegExp
|
|
81
|
+
? (name) => methodFilter.test(name)
|
|
82
|
+
: undefined;
|
|
83
|
+
const classFilterFn = typeof classFilter === 'function'
|
|
84
|
+
? classFilter
|
|
85
|
+
: classFilter instanceof RegExp
|
|
86
|
+
? (name) => classFilter.test(name)
|
|
87
|
+
: undefined;
|
|
88
|
+
// === JS fallback extraction (ESM-only) ===
|
|
89
|
+
if (jsSurface) {
|
|
90
|
+
for (const filePath of jsSurface.filesToParse) {
|
|
91
|
+
const allowlist = jsSurface.exportAllowlistByFile.get(filePath);
|
|
92
|
+
if (!allowlist || allowlist.size === 0) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const aliases = jsSurface.aliasMapByFile.get(filePath);
|
|
96
|
+
try {
|
|
97
|
+
// Extract types (classes) and filter to public surface
|
|
98
|
+
const fileTypes = extractTypesFromFile(filePath, packageName, {
|
|
99
|
+
allowlist,
|
|
100
|
+
aliases,
|
|
101
|
+
});
|
|
102
|
+
const filteredTypes = typeFilterFn
|
|
103
|
+
? fileTypes.filter((t) => typeFilterFn(t.name))
|
|
104
|
+
: fileTypes;
|
|
105
|
+
types.push(...filteredTypes);
|
|
106
|
+
// Extract methods, then filter by exported classes (file-level allowlist) and apply aliases.
|
|
107
|
+
const rawMethods = extractMethodsFromFile(filePath, packageName);
|
|
108
|
+
const fileMethods = rawMethods
|
|
109
|
+
.filter((m) => allowlist.has(m.className))
|
|
110
|
+
.map((m) => {
|
|
111
|
+
const internalClassName = m.className;
|
|
112
|
+
const publicClassName = aliases?.get(internalClassName) ?? internalClassName;
|
|
113
|
+
const description = m.description === `${m.name} method of ${internalClassName}`
|
|
114
|
+
? `${m.name} method of ${publicClassName}`
|
|
115
|
+
: m.description;
|
|
116
|
+
return {
|
|
117
|
+
...m,
|
|
118
|
+
className: publicClassName,
|
|
119
|
+
description,
|
|
120
|
+
};
|
|
121
|
+
})
|
|
122
|
+
.filter((m) => (classFilterFn ? classFilterFn(m.className) : true));
|
|
123
|
+
const filteredMethods = methodFilterFn
|
|
124
|
+
? fileMethods.filter((m) => methodFilterFn(m.name))
|
|
125
|
+
: fileMethods;
|
|
126
|
+
methods.push(...filteredMethods);
|
|
127
|
+
// Extract functions and filter to public surface + apply aliases
|
|
128
|
+
const fileFunctions = extractFunctionsFromFile(filePath, packageName, {
|
|
129
|
+
allowlist,
|
|
130
|
+
aliases,
|
|
131
|
+
});
|
|
132
|
+
const filteredFunctions = methodFilterFn
|
|
133
|
+
? fileFunctions.filter((f) => methodFilterFn(f.name))
|
|
134
|
+
: fileFunctions;
|
|
135
|
+
functions.push(...filteredFunctions);
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
errors.push({
|
|
139
|
+
file: filePath,
|
|
140
|
+
message: error instanceof Error ? error.message : String(error),
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return { packageName, types, methods, functions, errors };
|
|
145
|
+
}
|
|
146
|
+
// === TypeScript declaration (.d.ts) extraction ===
|
|
147
|
+
for (const filePath of dtsFiles) {
|
|
148
|
+
try {
|
|
149
|
+
// Extract types
|
|
150
|
+
const fileTypes = extractTypesFromFile(filePath, packageName);
|
|
151
|
+
const filteredTypes = typeFilterFn
|
|
152
|
+
? fileTypes.filter((t) => typeFilterFn(t.name))
|
|
153
|
+
: fileTypes;
|
|
154
|
+
types.push(...filteredTypes);
|
|
155
|
+
// Extract methods (pass classFilter, exportAliases, and publicExports for proper filtering)
|
|
156
|
+
const fileMethods = extractMethodsFromFile(filePath, packageName, classFilterFn, exportAliases, publicExports);
|
|
157
|
+
const filteredMethods = methodFilterFn
|
|
158
|
+
? fileMethods.filter((m) => methodFilterFn(m.name))
|
|
159
|
+
: fileMethods;
|
|
160
|
+
methods.push(...filteredMethods);
|
|
161
|
+
// Extract functions
|
|
162
|
+
const fileFunctions = extractFunctionsFromFile(filePath, packageName);
|
|
163
|
+
const filteredFunctions = methodFilterFn
|
|
164
|
+
? fileFunctions.filter((f) => methodFilterFn(f.name))
|
|
165
|
+
: fileFunctions;
|
|
166
|
+
functions.push(...filteredFunctions);
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
errors.push({
|
|
170
|
+
file: filePath,
|
|
171
|
+
message: error instanceof Error ? error.message : String(error),
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
packageName,
|
|
177
|
+
types,
|
|
178
|
+
methods,
|
|
179
|
+
functions,
|
|
180
|
+
errors,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Extract from specific .d.ts files
|
|
185
|
+
*/
|
|
186
|
+
export function extractFromFiles(files, libraryName, options) {
|
|
187
|
+
return extractFromPackage({
|
|
188
|
+
packageName: libraryName,
|
|
189
|
+
dtsFiles: files,
|
|
190
|
+
typeFilter: options?.typeFilter,
|
|
191
|
+
methodFilter: options?.methodFilter,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=index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IACH,CAAC;IAED,OAAO;QACL,WAAW;QACX,KAAK;QACL,OAAO;QACP,SAAS;QACT,MAAM;KACP,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAe,EACf,WAAmB,EACnB,OAGC;IAED,OAAO,kBAAkB,CAAC;QACxB,WAAW,EAAE,WAAW;QACxB,QAAQ,EAAE,KAAK;QACf,UAAU,EAAE,OAAO,EAAE,UAAU;QAC/B,YAAY,EAAE,OAAO,EAAE,YAAY;KACpC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract methods from TypeScript class declarations
|
|
3
|
+
*/
|
|
4
|
+
import * as ts from 'typescript';
|
|
5
|
+
import type { ExtractedMethod } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Extract all methods from a TypeScript file
|
|
8
|
+
*
|
|
9
|
+
* @param filePath - Path to the .d.ts file
|
|
10
|
+
* @param libraryName - Name of the library
|
|
11
|
+
* @param classFilter - Optional filter function for class names
|
|
12
|
+
* @param exportAliases - Optional map of internal class names to exported aliases
|
|
13
|
+
* @param publicExports - Optional set of publicly exported names (only index these)
|
|
14
|
+
*/
|
|
15
|
+
export declare function extractMethodsFromFile(filePath: string, libraryName: string, classFilter?: (className: string) => boolean, exportAliases?: Map<string, string>, publicExports?: Set<string>): ExtractedMethod[];
|
|
16
|
+
/**
|
|
17
|
+
* Extract methods from a class declaration
|
|
18
|
+
*
|
|
19
|
+
* @param classNode - The class declaration AST node
|
|
20
|
+
* @param sourceFile - The source file containing the class
|
|
21
|
+
* @param libraryName - Name of the library
|
|
22
|
+
* @param filePath - Path to the source file
|
|
23
|
+
* @param resolvedClassName - Optional pre-resolved class name (with export alias applied)
|
|
24
|
+
*/
|
|
25
|
+
export declare function extractMethodsFromClass(classNode: ts.ClassDeclaration, sourceFile: ts.SourceFile, libraryName: string, filePath: string, resolvedClassName?: string): ExtractedMethod[];
|
|
26
|
+
/**
|
|
27
|
+
* Extract methods from an interface declaration (for type libraries)
|
|
28
|
+
*/
|
|
29
|
+
export declare function extractMethodsFromInterface(interfaceNode: ts.InterfaceDeclaration, sourceFile: ts.SourceFile, libraryName: string, filePath: string): ExtractedMethod[];
|
|
30
|
+
//# sourceMappingURL=method-extractor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"method-extractor.d.ts","sourceRoot":"","sources":["../../src/extractor/method-extractor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAUlD;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,WAAW,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,EAC5C,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACnC,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAC1B,eAAe,EAAE,CAmDnB;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,EAAE,CAAC,gBAAgB,EAC9B,UAAU,EAAE,EAAE,CAAC,UAAU,EACzB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,iBAAiB,CAAC,EAAE,MAAM,GACzB,eAAe,EAAE,CA6EnB;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,EAAE,CAAC,oBAAoB,EACtC,UAAU,EAAE,EAAE,CAAC,UAAU,EACzB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,GACf,eAAe,EAAE,CAyCnB"}
|