@openpkg-ts/extract 0.14.2 → 0.14.3
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/README.md +77 -0
- package/dist/bin/tspec.js +1491 -11
- package/dist/shared/{chunk-khwn5myc.js → chunk-axmbd6k1.js} +2 -2
- package/dist/src/index.js +1 -1
- package/package.json +2 -1
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# @openpkg-ts/extract
|
|
2
|
+
|
|
3
|
+
TypeScript API extraction library. Generates OpenPkg specs from TypeScript source code.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @openpkg-ts/extract
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## CLI Usage
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# Extract API spec from entry point
|
|
15
|
+
tspec src/index.ts -o openpkg.json
|
|
16
|
+
|
|
17
|
+
# With options
|
|
18
|
+
tspec src/index.ts --max-depth 4 --verbose
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Programmatic Usage
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { extract } from '@openpkg-ts/extract';
|
|
25
|
+
|
|
26
|
+
const result = await extract({
|
|
27
|
+
entryFile: 'src/index.ts',
|
|
28
|
+
maxTypeDepth: 4,
|
|
29
|
+
resolveExternalTypes: true,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
console.log(`Extracted ${result.spec.exports.length} exports`);
|
|
33
|
+
console.log(`Found ${result.spec.types?.length ?? 0} types`);
|
|
34
|
+
|
|
35
|
+
// Check for diagnostics
|
|
36
|
+
for (const diag of result.diagnostics) {
|
|
37
|
+
console.warn(`${diag.severity}: ${diag.message}`);
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Options
|
|
42
|
+
|
|
43
|
+
| Option | Type | Default | Description |
|
|
44
|
+
|--------|------|---------|-------------|
|
|
45
|
+
| `entryFile` | `string` | required | Entry point file path |
|
|
46
|
+
| `baseDir` | `string` | cwd | Base directory for resolution |
|
|
47
|
+
| `maxTypeDepth` | `number` | 4 | Max depth for type traversal |
|
|
48
|
+
| `resolveExternalTypes` | `boolean` | true | Resolve types from node_modules |
|
|
49
|
+
| `schemaExtraction` | `'static' \| 'hybrid'` | 'static' | Schema extraction mode |
|
|
50
|
+
|
|
51
|
+
## Exports
|
|
52
|
+
|
|
53
|
+
### Core
|
|
54
|
+
- `extract(options)` - Main extraction function
|
|
55
|
+
|
|
56
|
+
### AST Utilities
|
|
57
|
+
- `getModuleExports` - Get exports from a module
|
|
58
|
+
- `resolveExportTarget` - Resolve re-exports to source
|
|
59
|
+
|
|
60
|
+
### Type Utilities
|
|
61
|
+
- `TypeRegistry` - Track and dedupe extracted types
|
|
62
|
+
- `serializeType` - Convert TS types to schema
|
|
63
|
+
|
|
64
|
+
### Schema Adapters
|
|
65
|
+
- `ZodAdapter`, `ValibotAdapter` - Runtime schema extraction
|
|
66
|
+
|
|
67
|
+
## How It Works
|
|
68
|
+
|
|
69
|
+
1. Creates a TypeScript program from the entry file
|
|
70
|
+
2. Extracts all exported symbols
|
|
71
|
+
3. Serializes each export (functions, classes, types, variables)
|
|
72
|
+
4. Resolves type references and builds a type registry
|
|
73
|
+
5. Outputs an OpenPkg-compliant JSON spec
|
|
74
|
+
|
|
75
|
+
## License
|
|
76
|
+
|
|
77
|
+
MIT
|