@doccov/sdk 0.2.1

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 ADDED
@@ -0,0 +1,68 @@
1
+ # @doccov/sdk
2
+
3
+ Programmatic API for documentation coverage analysis and drift detection in TypeScript.
4
+
5
+ ## Install
6
+ ```bash
7
+ npm install @doccov/sdk
8
+ ```
9
+
10
+ ## Minimal Usage
11
+ ```ts
12
+ import { DocCov } from '@doccov/sdk';
13
+
14
+ const doccov = new DocCov();
15
+ const { spec, diagnostics } = await doccov.analyzeFileWithDiagnostics('src/index.ts');
16
+
17
+ console.log(`Coverage: ${spec.docs?.coverageScore}%`);
18
+ console.log(`${spec.exports.length} exports analyzed`);
19
+ ```
20
+
21
+ ## Checking for Drift
22
+ ```ts
23
+ for (const exp of spec.exports) {
24
+ const drift = exp.docs?.drift ?? [];
25
+ if (drift.length > 0) {
26
+ console.log(`${exp.name}: ${drift.length} drift issues`);
27
+ for (const d of drift) {
28
+ console.log(` - ${d.issue}`);
29
+ if (d.suggestion) {
30
+ console.log(` Suggestion: ${d.suggestion}`);
31
+ }
32
+ }
33
+ }
34
+ }
35
+ ```
36
+
37
+ ## Helper Functions
38
+ - `analyze(code)` – analyze an in-memory string
39
+ - `analyzeFile(path)` – analyze a single entry point
40
+ - `analyzeWithDiagnostics` / `analyzeFileWithDiagnostics` – include TypeScript diagnostics
41
+ - `extractPackageSpec` – lower-level hook used by the CLI
42
+
43
+ ## Filters
44
+ ```ts
45
+ const { spec } = await doccov.analyzeFileWithDiagnostics('src/index.ts', {
46
+ filters: {
47
+ include: ['publicApi'],
48
+ exclude: ['internalHelper'],
49
+ },
50
+ });
51
+ ```
52
+
53
+ ## Coverage Metadata
54
+ Each export includes documentation health info:
55
+ ```ts
56
+ interface SpecDocsMetadata {
57
+ coverageScore?: number; // 0-100
58
+ missing?: ('description' | 'params' | 'returns' | 'examples')[];
59
+ drift?: SpecDocDrift[]; // List of drift issues
60
+ }
61
+ ```
62
+
63
+ ## See Also
64
+ - [Spec helpers](../spec/README.md)
65
+ - [CLI usage](../cli/README.md)
66
+ - [Fixtures](../../tests/fixtures/README.md)
67
+
68
+ MIT License
@@ -0,0 +1,57 @@
1
+ import { OpenPkg } from "@openpkg-ts/spec";
2
+ type OpenPkgSpec = OpenPkg;
3
+ interface DocCovOptions {
4
+ includePrivate?: boolean;
5
+ followImports?: boolean;
6
+ maxDepth?: number;
7
+ resolveExternalTypes?: boolean;
8
+ }
9
+ /** @deprecated Use DocCovOptions instead */
10
+ type OpenPkgOptions = DocCovOptions;
11
+ declare function extractPackageSpec(entryFile: string, packageDir?: string, content?: string, options?: OpenPkgOptions): Promise<OpenPkgSpec>;
12
+ interface FilterOptions {
13
+ include?: string[];
14
+ exclude?: string[];
15
+ }
16
+ interface Diagnostic {
17
+ message: string;
18
+ severity: "error" | "warning" | "info";
19
+ location?: {
20
+ file: string;
21
+ line?: number;
22
+ column?: number;
23
+ };
24
+ }
25
+ interface AnalysisResult {
26
+ spec: OpenPkgSpec;
27
+ diagnostics: Diagnostic[];
28
+ metadata: AnalysisMetadata;
29
+ }
30
+ interface AnalysisMetadata {
31
+ baseDir: string;
32
+ configPath?: string;
33
+ packageJsonPath?: string;
34
+ hasNodeModules: boolean;
35
+ resolveExternalTypes: boolean;
36
+ }
37
+ interface AnalyzeOptions {
38
+ filters?: FilterOptions;
39
+ }
40
+ declare class DocCov {
41
+ private readonly options;
42
+ constructor(options?: DocCovOptions);
43
+ analyze(code: string, fileName?: string, analyzeOptions?: AnalyzeOptions): Promise<OpenPkgSpec>;
44
+ analyzeFile(filePath: string, analyzeOptions?: AnalyzeOptions): Promise<OpenPkgSpec>;
45
+ analyzeProject(entryPath: string, analyzeOptions?: AnalyzeOptions): Promise<OpenPkgSpec>;
46
+ analyzeWithDiagnostics(code: string, fileName?: string, analyzeOptions?: AnalyzeOptions): Promise<AnalysisResult>;
47
+ analyzeFileWithDiagnostics(filePath: string, analyzeOptions?: AnalyzeOptions): Promise<AnalysisResult>;
48
+ private normalizeDiagnostic;
49
+ private mapSeverity;
50
+ private normalizeMetadata;
51
+ private applySpecFilters;
52
+ }
53
+ declare function analyze(code: string, options?: AnalyzeOptions): Promise<OpenPkgSpec>;
54
+ declare function analyzeFile(filePath: string, options?: AnalyzeOptions): Promise<OpenPkgSpec>;
55
+ /** @deprecated Use DocCov instead */
56
+ declare const OpenPkg2: typeof DocCov;
57
+ export { extractPackageSpec, analyzeFile, analyze, OpenPkgSpec, OpenPkgOptions, OpenPkg2 as OpenPkg, FilterOptions, DocCovOptions, DocCov, Diagnostic, AnalyzeOptions, AnalysisResult };