@doccov/sdk 0.23.0 → 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.
- package/dist/analysis/index.d.ts +57 -16
- package/dist/analysis/index.js +57 -1
- package/dist/index.d.ts +94 -24
- package/dist/index.js +146 -1
- package/dist/shared/{chunk-nk2w5vws.js → chunk-c1f9mytc.js} +29 -2
- package/dist/types/index.d.ts +17 -5
- package/package.json +4 -2
package/dist/analysis/index.d.ts
CHANGED
|
@@ -5,8 +5,25 @@ interface DetectedSchemaEntry {
|
|
|
5
5
|
schema: Record<string, unknown>;
|
|
6
6
|
vendor: string;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* All possible drift type identifiers.
|
|
10
|
+
*/
|
|
11
|
+
type DriftType = "param-mismatch" | "param-type-mismatch" | "return-type-mismatch" | "generic-constraint-mismatch" | "optionality-mismatch" | "deprecated-mismatch" | "visibility-mismatch" | "async-mismatch" | "property-type-drift" | "example-drift" | "example-syntax-error" | "example-runtime-error" | "example-assertion-failed" | "broken-link";
|
|
12
|
+
type SpecDocDrift = {
|
|
13
|
+
type: DriftType;
|
|
14
|
+
target?: string;
|
|
15
|
+
issue: string;
|
|
16
|
+
suggestion?: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Drift categories group related drift types for progressive disclosure.
|
|
20
|
+
*/
|
|
21
|
+
type DriftCategory = "structural" | "semantic" | "example";
|
|
22
|
+
type SpecDocsMetadata = {
|
|
23
|
+
coverageScore?: number;
|
|
24
|
+
missing?: string[];
|
|
25
|
+
drift?: SpecDocDrift[];
|
|
26
|
+
};
|
|
10
27
|
/**
|
|
11
28
|
* Result of computing drift for a single export.
|
|
12
29
|
*/
|
|
@@ -72,7 +89,7 @@ interface DriftSummary {
|
|
|
72
89
|
* console.log(categorized.fixable); // => true
|
|
73
90
|
* ```
|
|
74
91
|
*/
|
|
75
|
-
declare function categorizeDrift(drift:
|
|
92
|
+
declare function categorizeDrift(drift: SpecDocDrift): CategorizedDrift;
|
|
76
93
|
/**
|
|
77
94
|
* Group drifts by category.
|
|
78
95
|
*
|
|
@@ -87,7 +104,7 @@ declare function categorizeDrift(drift: SpecDocDrift2): CategorizedDrift;
|
|
|
87
104
|
* console.log(grouped.example.length); // Number of example issues
|
|
88
105
|
* ```
|
|
89
106
|
*/
|
|
90
|
-
declare function groupDriftsByCategory(drifts:
|
|
107
|
+
declare function groupDriftsByCategory(drifts: SpecDocDrift[]): Record<DriftCategory, CategorizedDrift[]>;
|
|
91
108
|
/**
|
|
92
109
|
* Get drift summary counts by category.
|
|
93
110
|
*
|
|
@@ -101,7 +118,7 @@ declare function groupDriftsByCategory(drifts: SpecDocDrift2[]): Record<DriftCat
|
|
|
101
118
|
* // => "5 issues: 3 fixable"
|
|
102
119
|
* ```
|
|
103
120
|
*/
|
|
104
|
-
declare function getDriftSummary(drifts:
|
|
121
|
+
declare function getDriftSummary(drifts: SpecDocDrift[]): DriftSummary;
|
|
105
122
|
/**
|
|
106
123
|
* Format drift summary for CLI output (single line).
|
|
107
124
|
*
|
|
@@ -116,7 +133,7 @@ declare function getDriftSummary(drifts: SpecDocDrift2[]): DriftSummary;
|
|
|
116
133
|
* ```
|
|
117
134
|
*/
|
|
118
135
|
declare function formatDriftSummaryLine(summary: DriftSummary): string;
|
|
119
|
-
import {
|
|
136
|
+
import { SpecExport } from "@openpkg-ts/spec";
|
|
120
137
|
import { OpenPkg } from "@openpkg-ts/spec";
|
|
121
138
|
type OpenPkgSpec = OpenPkg;
|
|
122
139
|
/**
|
|
@@ -136,7 +153,7 @@ declare function computeDrift(spec: OpenPkgSpec): DriftResult;
|
|
|
136
153
|
* @param registry - Registry of known exports and types for validation
|
|
137
154
|
* @returns Array of drift issues detected
|
|
138
155
|
*/
|
|
139
|
-
declare function computeExportDrift(entry: SpecExport, registry?: ExportRegistry):
|
|
156
|
+
declare function computeExportDrift(entry: SpecExport, registry?: ExportRegistry): SpecDocDrift[];
|
|
140
157
|
/**
|
|
141
158
|
* Calculate aggregate coverage score from a spec's exports.
|
|
142
159
|
*
|
|
@@ -185,7 +202,7 @@ declare function ensureSpecCoverage(spec: OpenPkgSpec): OpenPkgSpec & {
|
|
|
185
202
|
coverageScore: number;
|
|
186
203
|
};
|
|
187
204
|
};
|
|
188
|
-
import {
|
|
205
|
+
import { SpecExport as SpecExport2 } from "@openpkg-ts/spec";
|
|
189
206
|
interface ExampleRunResult {
|
|
190
207
|
success: boolean;
|
|
191
208
|
stdout: string;
|
|
@@ -197,7 +214,7 @@ interface ExampleRunResult {
|
|
|
197
214
|
* Detect runtime errors in @example blocks.
|
|
198
215
|
* Results are provided externally after running examples via runExamples().
|
|
199
216
|
*/
|
|
200
|
-
declare function detectExampleRuntimeErrors(entry: SpecExport2, runtimeResults: Map<number, ExampleRunResult>):
|
|
217
|
+
declare function detectExampleRuntimeErrors(entry: SpecExport2, runtimeResults: Map<number, ExampleRunResult>): SpecDocDrift[];
|
|
201
218
|
/**
|
|
202
219
|
* Parse assertion comments from example code.
|
|
203
220
|
* Matches: // => expected_value
|
|
@@ -214,8 +231,8 @@ declare function hasNonAssertionComments(code: string): boolean;
|
|
|
214
231
|
/**
|
|
215
232
|
* Detect assertion failures by comparing stdout to expected values.
|
|
216
233
|
*/
|
|
217
|
-
declare function detectExampleAssertionFailures(entry: SpecExport2, runtimeResults: Map<number, ExampleRunResult>):
|
|
218
|
-
import { OpenPkg as OpenPkg2,
|
|
234
|
+
declare function detectExampleAssertionFailures(entry: SpecExport2, runtimeResults: Map<number, ExampleRunResult>): SpecDocDrift[];
|
|
235
|
+
import { OpenPkg as OpenPkg2, SpecExport as SpecExport7 } from "@openpkg-ts/spec";
|
|
219
236
|
/**
|
|
220
237
|
* An enriched with computed documentation metadata.
|
|
221
238
|
* Extends SpecExport with the `docs` field for coverage analysis.
|
|
@@ -242,7 +259,7 @@ interface EnrichOptions {
|
|
|
242
259
|
* Per-drift issues to include in enrichment.
|
|
243
260
|
* Map from ID to drift issues.
|
|
244
261
|
*/
|
|
245
|
-
driftByExport?: Map<string,
|
|
262
|
+
driftByExport?: Map<string, SpecDocDrift[]>;
|
|
246
263
|
}
|
|
247
264
|
/**
|
|
248
265
|
* Enrich an OpenPkg spec with documentation coverage metadata.
|
|
@@ -265,6 +282,31 @@ interface EnrichOptions {
|
|
|
265
282
|
* ```
|
|
266
283
|
*/
|
|
267
284
|
declare function enrichSpec(spec: OpenPkg2, options?: EnrichOptions): EnrichedOpenPkg;
|
|
285
|
+
import { SpecDiff } from "@openpkg-ts/spec";
|
|
286
|
+
/**
|
|
287
|
+
* Extended diff result with doccov-specific coverage tracking.
|
|
288
|
+
*/
|
|
289
|
+
interface EnrichedSpecDiff extends SpecDiff {
|
|
290
|
+
coverageDelta: number;
|
|
291
|
+
oldCoverage: number;
|
|
292
|
+
newCoverage: number;
|
|
293
|
+
newUndocumented: string[];
|
|
294
|
+
improvedExports: string[];
|
|
295
|
+
regressedExports: string[];
|
|
296
|
+
driftIntroduced: number;
|
|
297
|
+
driftResolved: number;
|
|
298
|
+
}
|
|
299
|
+
type ExportWithDocs = EnrichedExport & {
|
|
300
|
+
docs?: SpecDocsMetadata;
|
|
301
|
+
};
|
|
302
|
+
type SpecWithDocs = EnrichedOpenPkg & {
|
|
303
|
+
docs?: SpecDocsMetadata;
|
|
304
|
+
exports: ExportWithDocs[];
|
|
305
|
+
};
|
|
306
|
+
/**
|
|
307
|
+
* Compare two enriched OpenPkg specs with coverage tracking.
|
|
308
|
+
*/
|
|
309
|
+
declare function diffEnrichedSpec(oldSpec: SpecWithDocs, newSpec: SpecWithDocs): EnrichedSpecDiff;
|
|
268
310
|
import { OpenPkg as OpenPkg3 } from "@openpkg-ts/spec";
|
|
269
311
|
/** Directory for storing history snapshots */
|
|
270
312
|
declare const HISTORY_DIR = ".doccov/history";
|
|
@@ -449,7 +491,6 @@ declare function getExtendedTrend(spec: OpenPkg3, cwd: string, options?: {
|
|
|
449
491
|
tier?: RetentionTier;
|
|
450
492
|
}): ExtendedTrendAnalysis;
|
|
451
493
|
import { OpenPkg as OpenPkg4 } from "@openpkg-ts/spec";
|
|
452
|
-
import { DriftCategory as DriftCategory3, SpecDocDrift as SpecDocDrift9 } from "@openpkg-ts/spec";
|
|
453
494
|
/**
|
|
454
495
|
* Drift summary with category breakdown.
|
|
455
496
|
*/
|
|
@@ -461,7 +502,7 @@ interface DriftReportSummary {
|
|
|
461
502
|
/**
|
|
462
503
|
* Count of issues per category.
|
|
463
504
|
*/
|
|
464
|
-
byCategory: Record<
|
|
505
|
+
byCategory: Record<DriftCategory, number>;
|
|
465
506
|
/**
|
|
466
507
|
* Number of auto-fixable issues.
|
|
467
508
|
*/
|
|
@@ -519,7 +560,7 @@ interface ExportCoverageData {
|
|
|
519
560
|
/**
|
|
520
561
|
* Drift issues for this export.
|
|
521
562
|
*/
|
|
522
|
-
drift?:
|
|
563
|
+
drift?: SpecDocDrift[];
|
|
523
564
|
}
|
|
524
565
|
/**
|
|
525
566
|
* DocCov report - a persistable coverage analysis result.
|
|
@@ -647,4 +688,4 @@ interface SchemaDetectionResult {
|
|
|
647
688
|
noCompiledJsWarning?: boolean;
|
|
648
689
|
}
|
|
649
690
|
declare function detectRuntimeSchemas(context: SchemaDetectionContext): Promise<SchemaDetectionResult>;
|
|
650
|
-
export { saveSnapshot, saveReport, renderSparkline, renderApiSurface, pruneHistory, pruneByTier, parseAssertions, loadSnapshotsForDays, loadSnapshots, loadCachedReport, isCachedReportValid, hasNonAssertionComments, groupDriftsByCategory, getTrend, getExtendedTrend, getDriftSummary, generateWeeklySummaries, generateReportFromEnriched, generateReport, formatDriftSummaryLine, formatDelta, ensureSpecCoverage, enrichSpec, detectRuntimeSchemas, detectExampleRuntimeErrors, detectExampleAssertionFailures, computeSnapshot, computeExportDrift, computeDrift, categorizeDrift, calculateAggregateCoverage, buildExportRegistry, WeeklySummary, SchemaDetectionResult, SchemaDetectionContext, RetentionTier, RETENTION_DAYS, OpenPkgSpec, HISTORY_DIR, ExtendedTrendAnalysis, ExportDriftResult, EnrichedOpenPkg, EnrichedExport, EnrichedDocsMetadata, EnrichOptions, DriftSummary, DriftResult, DetectedSchemaEntry, CoverageTrend, CoverageSnapshot, CategorizedDrift };
|
|
691
|
+
export { saveSnapshot, saveReport, renderSparkline, renderApiSurface, pruneHistory, pruneByTier, parseAssertions, loadSnapshotsForDays, loadSnapshots, loadCachedReport, isCachedReportValid, hasNonAssertionComments, groupDriftsByCategory, getTrend, getExtendedTrend, getDriftSummary, generateWeeklySummaries, generateReportFromEnriched, generateReport, formatDriftSummaryLine, formatDelta, ensureSpecCoverage, enrichSpec, diffEnrichedSpec, detectRuntimeSchemas, detectExampleRuntimeErrors, detectExampleAssertionFailures, computeSnapshot, computeExportDrift, computeDrift, categorizeDrift, calculateAggregateCoverage, buildExportRegistry, WeeklySummary, SchemaDetectionResult, SchemaDetectionContext, RetentionTier, RETENTION_DAYS, OpenPkgSpec, HISTORY_DIR, ExtendedTrendAnalysis, ExportDriftResult, EnrichedSpecDiff, EnrichedOpenPkg, EnrichedExport, EnrichedDocsMetadata, EnrichOptions, DriftSummary, DriftResult, DetectedSchemaEntry, CoverageTrend, CoverageSnapshot, CategorizedDrift };
|
package/dist/analysis/index.js
CHANGED
|
@@ -33,8 +33,63 @@ import {
|
|
|
33
33
|
renderSparkline,
|
|
34
34
|
saveReport,
|
|
35
35
|
saveSnapshot
|
|
36
|
-
} from "../shared/chunk-
|
|
36
|
+
} from "../shared/chunk-c1f9mytc.js";
|
|
37
37
|
import"../shared/chunk-esptwrfq.js";
|
|
38
|
+
// src/analysis/diff-enriched.ts
|
|
39
|
+
import { diffSpec } from "@openpkg-ts/spec";
|
|
40
|
+
function diffEnrichedSpec(oldSpec, newSpec) {
|
|
41
|
+
const baseDiff = diffSpec(oldSpec, newSpec);
|
|
42
|
+
const result = {
|
|
43
|
+
...baseDiff,
|
|
44
|
+
coverageDelta: 0,
|
|
45
|
+
oldCoverage: 0,
|
|
46
|
+
newCoverage: 0,
|
|
47
|
+
newUndocumented: [],
|
|
48
|
+
improvedExports: [],
|
|
49
|
+
regressedExports: [],
|
|
50
|
+
driftIntroduced: 0,
|
|
51
|
+
driftResolved: 0
|
|
52
|
+
};
|
|
53
|
+
result.oldCoverage = oldSpec.docs?.coverageScore ?? 0;
|
|
54
|
+
result.newCoverage = newSpec.docs?.coverageScore ?? 0;
|
|
55
|
+
result.coverageDelta = Math.round((result.newCoverage - result.oldCoverage) * 10) / 10;
|
|
56
|
+
const oldExportMap = toExportMap(oldSpec.exports);
|
|
57
|
+
const newExportMap = toExportMap(newSpec.exports);
|
|
58
|
+
for (const [id, newExport] of newExportMap.entries()) {
|
|
59
|
+
const oldExport = oldExportMap.get(id);
|
|
60
|
+
const newScore = newExport.docs?.coverageScore ?? 0;
|
|
61
|
+
const newDriftCount = newExport.docs?.drift?.length ?? 0;
|
|
62
|
+
if (!oldExport) {
|
|
63
|
+
if (newScore < 100 || (newExport.docs?.missing?.length ?? 0) > 0) {
|
|
64
|
+
result.newUndocumented.push(id);
|
|
65
|
+
}
|
|
66
|
+
result.driftIntroduced += newDriftCount;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const oldScore = oldExport.docs?.coverageScore ?? 0;
|
|
70
|
+
const oldDriftCount = oldExport.docs?.drift?.length ?? 0;
|
|
71
|
+
if (newScore > oldScore) {
|
|
72
|
+
result.improvedExports.push(id);
|
|
73
|
+
} else if (newScore < oldScore) {
|
|
74
|
+
result.regressedExports.push(id);
|
|
75
|
+
}
|
|
76
|
+
if (newDriftCount > oldDriftCount) {
|
|
77
|
+
result.driftIntroduced += newDriftCount - oldDriftCount;
|
|
78
|
+
} else if (oldDriftCount > newDriftCount) {
|
|
79
|
+
result.driftResolved += oldDriftCount - newDriftCount;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
function toExportMap(exports) {
|
|
85
|
+
const map = new Map;
|
|
86
|
+
for (const exp of exports) {
|
|
87
|
+
if (exp && typeof exp.id === "string") {
|
|
88
|
+
map.set(exp.id, exp);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return map;
|
|
92
|
+
}
|
|
38
93
|
export {
|
|
39
94
|
saveSnapshot,
|
|
40
95
|
saveReport,
|
|
@@ -59,6 +114,7 @@ export {
|
|
|
59
114
|
formatDelta,
|
|
60
115
|
ensureSpecCoverage,
|
|
61
116
|
enrichSpec,
|
|
117
|
+
diffEnrichedSpec,
|
|
62
118
|
detectRuntimeSchemas,
|
|
63
119
|
detectExampleRuntimeErrors,
|
|
64
120
|
detectExampleAssertionFailures,
|
package/dist/index.d.ts
CHANGED
|
@@ -367,9 +367,38 @@ declare class DocCov {
|
|
|
367
367
|
}
|
|
368
368
|
declare function analyze(code: string, options?: AnalyzeOptions): Promise<OpenPkgSpec>;
|
|
369
369
|
declare function analyzeFile(filePath: string, options?: AnalyzeOptions): Promise<OpenPkgSpec>;
|
|
370
|
-
import { OpenPkg as OpenPkg4,
|
|
371
|
-
|
|
372
|
-
|
|
370
|
+
import { OpenPkg as OpenPkg4, SpecExport as SpecExport7 } from "@openpkg-ts/spec";
|
|
371
|
+
/**
|
|
372
|
+
* All possible drift type identifiers.
|
|
373
|
+
*/
|
|
374
|
+
type DriftType = "param-mismatch" | "param-type-mismatch" | "return-type-mismatch" | "generic-constraint-mismatch" | "optionality-mismatch" | "deprecated-mismatch" | "visibility-mismatch" | "async-mismatch" | "property-type-drift" | "example-drift" | "example-syntax-error" | "example-runtime-error" | "example-assertion-failed" | "broken-link";
|
|
375
|
+
type SpecDocDrift = {
|
|
376
|
+
type: DriftType;
|
|
377
|
+
target?: string;
|
|
378
|
+
issue: string;
|
|
379
|
+
suggestion?: string;
|
|
380
|
+
};
|
|
381
|
+
/**
|
|
382
|
+
* Drift categories group related drift types for progressive disclosure.
|
|
383
|
+
*/
|
|
384
|
+
type DriftCategory = "structural" | "semantic" | "example";
|
|
385
|
+
/**
|
|
386
|
+
* Maps each drift type to its category.
|
|
387
|
+
*/
|
|
388
|
+
declare const DRIFT_CATEGORIES: Record<DriftType, DriftCategory>;
|
|
389
|
+
/**
|
|
390
|
+
* Human-readable category labels.
|
|
391
|
+
*/
|
|
392
|
+
declare const DRIFT_CATEGORY_LABELS: Record<DriftCategory, string>;
|
|
393
|
+
/**
|
|
394
|
+
* Category descriptions for help text.
|
|
395
|
+
*/
|
|
396
|
+
declare const DRIFT_CATEGORY_DESCRIPTIONS: Record<DriftCategory, string>;
|
|
397
|
+
type SpecDocsMetadata = {
|
|
398
|
+
coverageScore?: number;
|
|
399
|
+
missing?: string[];
|
|
400
|
+
drift?: SpecDocDrift[];
|
|
401
|
+
};
|
|
373
402
|
/**
|
|
374
403
|
* Result of computing drift for a single export.
|
|
375
404
|
*/
|
|
@@ -435,7 +464,7 @@ interface DriftSummary {
|
|
|
435
464
|
* console.log(categorized.fixable); // => true
|
|
436
465
|
* ```
|
|
437
466
|
*/
|
|
438
|
-
declare function categorizeDrift(drift:
|
|
467
|
+
declare function categorizeDrift(drift: SpecDocDrift): CategorizedDrift;
|
|
439
468
|
/**
|
|
440
469
|
* Group drifts by category.
|
|
441
470
|
*
|
|
@@ -450,7 +479,7 @@ declare function categorizeDrift(drift: SpecDocDrift2): CategorizedDrift;
|
|
|
450
479
|
* console.log(grouped.example.length); // Number of example issues
|
|
451
480
|
* ```
|
|
452
481
|
*/
|
|
453
|
-
declare function groupDriftsByCategory(drifts:
|
|
482
|
+
declare function groupDriftsByCategory(drifts: SpecDocDrift[]): Record<DriftCategory, CategorizedDrift[]>;
|
|
454
483
|
/**
|
|
455
484
|
* Get drift summary counts by category.
|
|
456
485
|
*
|
|
@@ -464,7 +493,7 @@ declare function groupDriftsByCategory(drifts: SpecDocDrift2[]): Record<DriftCat
|
|
|
464
493
|
* // => "5 issues: 3 fixable"
|
|
465
494
|
* ```
|
|
466
495
|
*/
|
|
467
|
-
declare function getDriftSummary(drifts:
|
|
496
|
+
declare function getDriftSummary(drifts: SpecDocDrift[]): DriftSummary;
|
|
468
497
|
/**
|
|
469
498
|
* Format drift summary for CLI output (single line).
|
|
470
499
|
*
|
|
@@ -479,7 +508,7 @@ declare function getDriftSummary(drifts: SpecDocDrift2[]): DriftSummary;
|
|
|
479
508
|
* ```
|
|
480
509
|
*/
|
|
481
510
|
declare function formatDriftSummaryLine(summary: DriftSummary): string;
|
|
482
|
-
import {
|
|
511
|
+
import { SpecExport } from "@openpkg-ts/spec";
|
|
483
512
|
/**
|
|
484
513
|
* Build a registry of all export/type names for cross-reference validation.
|
|
485
514
|
*/
|
|
@@ -497,7 +526,7 @@ declare function computeDrift(spec: OpenPkgSpec): DriftResult;
|
|
|
497
526
|
* @param registry - Registry of known exports and types for validation
|
|
498
527
|
* @returns Array of drift issues detected
|
|
499
528
|
*/
|
|
500
|
-
declare function computeExportDrift(entry: SpecExport, registry?: ExportRegistry):
|
|
529
|
+
declare function computeExportDrift(entry: SpecExport, registry?: ExportRegistry): SpecDocDrift[];
|
|
501
530
|
/**
|
|
502
531
|
* Calculate aggregate coverage score from a spec's exports.
|
|
503
532
|
*
|
|
@@ -546,7 +575,7 @@ declare function ensureSpecCoverage(spec: OpenPkgSpec): OpenPkgSpec & {
|
|
|
546
575
|
coverageScore: number;
|
|
547
576
|
};
|
|
548
577
|
};
|
|
549
|
-
import {
|
|
578
|
+
import { SpecExport as SpecExport2 } from "@openpkg-ts/spec";
|
|
550
579
|
interface ExampleRunResult {
|
|
551
580
|
success: boolean;
|
|
552
581
|
stdout: string;
|
|
@@ -597,7 +626,7 @@ declare function runExamplesWithPackage(examples: string[], options: RunExamples
|
|
|
597
626
|
* Detect runtime errors in @example blocks.
|
|
598
627
|
* Results are provided externally after running examples via runExamples().
|
|
599
628
|
*/
|
|
600
|
-
declare function detectExampleRuntimeErrors(entry: SpecExport2, runtimeResults: Map<number, ExampleRunResult>):
|
|
629
|
+
declare function detectExampleRuntimeErrors(entry: SpecExport2, runtimeResults: Map<number, ExampleRunResult>): SpecDocDrift[];
|
|
601
630
|
/**
|
|
602
631
|
* Parse assertion comments from example code.
|
|
603
632
|
* Matches: // => expected_value
|
|
@@ -614,7 +643,7 @@ declare function hasNonAssertionComments(code: string): boolean;
|
|
|
614
643
|
/**
|
|
615
644
|
* Detect assertion failures by comparing stdout to expected values.
|
|
616
645
|
*/
|
|
617
|
-
declare function detectExampleAssertionFailures(entry: SpecExport2, runtimeResults: Map<number, ExampleRunResult>):
|
|
646
|
+
declare function detectExampleAssertionFailures(entry: SpecExport2, runtimeResults: Map<number, ExampleRunResult>): SpecDocDrift[];
|
|
618
647
|
/**
|
|
619
648
|
* An enriched with computed documentation metadata.
|
|
620
649
|
* Extends SpecExport with the `docs` field for coverage analysis.
|
|
@@ -641,7 +670,7 @@ interface EnrichOptions {
|
|
|
641
670
|
* Per-drift issues to include in enrichment.
|
|
642
671
|
* Map from ID to drift issues.
|
|
643
672
|
*/
|
|
644
|
-
driftByExport?: Map<string,
|
|
673
|
+
driftByExport?: Map<string, SpecDocDrift[]>;
|
|
645
674
|
}
|
|
646
675
|
/**
|
|
647
676
|
* Enrich an OpenPkg spec with documentation coverage metadata.
|
|
@@ -664,8 +693,20 @@ interface EnrichOptions {
|
|
|
664
693
|
* ```
|
|
665
694
|
*/
|
|
666
695
|
declare function enrichSpec(spec: OpenPkg4, options?: EnrichOptions): EnrichedOpenPkg;
|
|
696
|
+
import { DocCovSpec } from "@doccov/spec";
|
|
697
|
+
interface BuildDocCovOptions {
|
|
698
|
+
openpkgPath: string;
|
|
699
|
+
openpkg: OpenPkgSpec;
|
|
700
|
+
packagePath?: string;
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Build a DocCov spec from an OpenPkg spec.
|
|
704
|
+
*
|
|
705
|
+
* @param options - Build options
|
|
706
|
+
* @returns DocCov specification with coverage analysis
|
|
707
|
+
*/
|
|
708
|
+
declare function buildDocCovSpec(options: BuildDocCovOptions): DocCovSpec;
|
|
667
709
|
import { OpenPkg as OpenPkg5 } from "@openpkg-ts/spec";
|
|
668
|
-
import { DriftCategory as DriftCategory3, SpecDocDrift as SpecDocDrift9 } from "@openpkg-ts/spec";
|
|
669
710
|
/**
|
|
670
711
|
* DocCov report schema version.
|
|
671
712
|
*/
|
|
@@ -725,7 +766,7 @@ interface DriftReportSummary {
|
|
|
725
766
|
/**
|
|
726
767
|
* Count of issues per category.
|
|
727
768
|
*/
|
|
728
|
-
byCategory: Record<
|
|
769
|
+
byCategory: Record<DriftCategory, number>;
|
|
729
770
|
/**
|
|
730
771
|
* Number of auto-fixable issues.
|
|
731
772
|
*/
|
|
@@ -747,7 +788,7 @@ interface DriftReport {
|
|
|
747
788
|
/**
|
|
748
789
|
* Issues grouped by category.
|
|
749
790
|
*/
|
|
750
|
-
byCategory: Record<
|
|
791
|
+
byCategory: Record<DriftCategory, CategorizedDrift[]>;
|
|
751
792
|
/**
|
|
752
793
|
* Flat list of all drift issues (backward compatible).
|
|
753
794
|
*/
|
|
@@ -805,7 +846,7 @@ interface ExportCoverageData {
|
|
|
805
846
|
/**
|
|
806
847
|
* Drift issues for this export.
|
|
807
848
|
*/
|
|
808
|
-
drift?:
|
|
849
|
+
drift?: SpecDocDrift[];
|
|
809
850
|
}
|
|
810
851
|
/**
|
|
811
852
|
* DocCov report - a persistable coverage analysis result.
|
|
@@ -885,6 +926,27 @@ declare function loadCachedReport(reportPath?: string): DocCovReport | null;
|
|
|
885
926
|
*/
|
|
886
927
|
declare function saveReport(report: DocCovReport, reportPath?: string): void;
|
|
887
928
|
/**
|
|
929
|
+
* Generate a git-trackable API surface markdown file from an OpenPkg spec.
|
|
930
|
+
*
|
|
931
|
+
* This produces a deterministic, sorted output suitable for version control.
|
|
932
|
+
* Changes to the API will show up as diffs in this file.
|
|
933
|
+
*
|
|
934
|
+
* @param spec - The OpenPkg spec to render
|
|
935
|
+
* @returns Markdown string representing the API surface
|
|
936
|
+
*
|
|
937
|
+
* @example
|
|
938
|
+
* ```ts
|
|
939
|
+
* import { DocCov, renderApiSurface } from '@doccov/sdk';
|
|
940
|
+
*
|
|
941
|
+
* const doccov = new DocCov();
|
|
942
|
+
* const { spec } = await doccov.analyzeFileWithDiagnostics('src/index.ts');
|
|
943
|
+
* const apiSurface = renderApiSurface(spec);
|
|
944
|
+
*
|
|
945
|
+
* fs.writeFileSync('api-surface.md', apiSurface);
|
|
946
|
+
* ```
|
|
947
|
+
*/
|
|
948
|
+
declare function renderApiSurface(spec: OpenPkg5): string;
|
|
949
|
+
/**
|
|
888
950
|
* Project detection types for I/O-agnostic project analysis.
|
|
889
951
|
* Used by both CLI (NodeFileSystem) and API (SandboxFileSystem).
|
|
890
952
|
*/
|
|
@@ -1350,7 +1412,7 @@ interface ExampleValidationResult {
|
|
|
1350
1412
|
* - `run`: executes examples (doesn't require presence or typecheck)
|
|
1351
1413
|
*/
|
|
1352
1414
|
declare function validateExamples(exports: SpecExport8[], options: ExampleValidationOptions): Promise<ExampleValidationResult>;
|
|
1353
|
-
import {
|
|
1415
|
+
import { SpecExport as SpecExport9 } from "@openpkg-ts/spec";
|
|
1354
1416
|
import * as TS2 from "typescript";
|
|
1355
1417
|
/**
|
|
1356
1418
|
* Represents a single parameter in a JSDoc patch
|
|
@@ -1457,7 +1519,7 @@ type FixType = "add-param" | "remove-param" | "update-param-type" | "update-para
|
|
|
1457
1519
|
*/
|
|
1458
1520
|
interface FixSuggestion {
|
|
1459
1521
|
type: FixType;
|
|
1460
|
-
driftType:
|
|
1522
|
+
driftType: SpecDocDrift["type"];
|
|
1461
1523
|
target: string;
|
|
1462
1524
|
description: string;
|
|
1463
1525
|
patch: Partial<JSDocPatch>;
|
|
@@ -1465,11 +1527,11 @@ interface FixSuggestion {
|
|
|
1465
1527
|
/**
|
|
1466
1528
|
* Check if a drift type can be fixed deterministically
|
|
1467
1529
|
*/
|
|
1468
|
-
declare function isFixableDrift(drift:
|
|
1530
|
+
declare function isFixableDrift(drift: SpecDocDrift): boolean;
|
|
1469
1531
|
/**
|
|
1470
1532
|
* Generate a fix for a single drift issue
|
|
1471
1533
|
*/
|
|
1472
|
-
declare function generateFix(drift:
|
|
1534
|
+
declare function generateFix(drift: SpecDocDrift, exportEntry: SpecExport9, existingPatch?: JSDocPatch): FixSuggestion | null;
|
|
1473
1535
|
/**
|
|
1474
1536
|
* Generate all fixes for an export's drift issues
|
|
1475
1537
|
*/
|
|
@@ -1481,9 +1543,9 @@ declare function mergeFixes(fixes: FixSuggestion[], basePatch?: JSDocPatch): JSD
|
|
|
1481
1543
|
/**
|
|
1482
1544
|
* Get a summary of fixable vs non-fixable drifts
|
|
1483
1545
|
*/
|
|
1484
|
-
declare function categorizeDrifts(drifts:
|
|
1485
|
-
fixable:
|
|
1486
|
-
nonFixable:
|
|
1546
|
+
declare function categorizeDrifts(drifts: SpecDocDrift[]): {
|
|
1547
|
+
fixable: SpecDocDrift[];
|
|
1548
|
+
nonFixable: SpecDocDrift[];
|
|
1487
1549
|
};
|
|
1488
1550
|
import { SpecDiff } from "@openpkg-ts/spec";
|
|
1489
1551
|
type MemberChangeType = "added" | "removed" | "signature-changed";
|
|
@@ -1899,6 +1961,14 @@ declare function formatDelta(delta: number): string;
|
|
|
1899
1961
|
*/
|
|
1900
1962
|
declare function pruneHistory(cwd: string, keepCount?: number): number;
|
|
1901
1963
|
/**
|
|
1964
|
+
* Prune snapshots based on tier retention policy.
|
|
1965
|
+
*
|
|
1966
|
+
* @param cwd - Working directory
|
|
1967
|
+
* @param tier - Retention tier (free: 7d, team: 30d, pro: 90d)
|
|
1968
|
+
* @returns Number of snapshots deleted
|
|
1969
|
+
*/
|
|
1970
|
+
declare function pruneByTier(cwd: string, tier: RetentionTier): number;
|
|
1971
|
+
/**
|
|
1902
1972
|
* Get extended trend analysis with velocity and projections.
|
|
1903
1973
|
*
|
|
1904
1974
|
* @param spec - Current OpenPkg spec
|
|
@@ -2576,4 +2646,4 @@ interface BuildPlanExecutionResult {
|
|
|
2576
2646
|
/** Overall error message if failed */
|
|
2577
2647
|
error?: string;
|
|
2578
2648
|
}
|
|
2579
|
-
export { validateSpecCache, validateExamples, typecheckExamples, typecheckExample, shouldValidate, serializeJSDoc, saveSpecCache, saveSnapshot, saveReport, safeParseJson, runExamplesWithPackage, runExamples, runExample, resolveTarget, resolveCompiledPath, renderSparkline, readPackageJson, pruneHistory, parseGitHubUrl2 as parseScanGitHubUrl, parseMarkdownFiles, parseMarkdownFile, parseListFlag, parseJSDocToPatch, parseGitHubUrl, parseExamplesFlag, parseAssertions, mergeFixes, mergeFilters, loadSpecCache, loadSnapshots, loadCachedReport, listWorkspacePackages, isStandardJSONSchema, isSchemaType, isFixableDrift, isExecutableLang, installDependencies, hashString, hashFiles, hashFile, hasNonAssertionComments, hasDocsImpact, hasDocsForExport, groupDriftsByCategory, getUndocumentedExports, getTrend, getSupportedLibraries, getSpecCachePath, getRunCommand, getReportPath, getRegisteredAdapters, getPrimaryBuildScript, getInstallCommand, getExtendedTrend, getDriftSummary, getDocumentedExports, getDocsImpactSummary, getDiffReportPath, generateReportFromEnriched, generateReport, generateFixesForExport, generateFix, formatPackageList, formatDriftSummaryLine, formatDelta, findRemovedReferences, findPackageByName, findJSDocLocation, findExportReferences, findDeprecatedReferences, findAdapter, fetchSpecFromGitHub, fetchSpec, fetchGitHubContext, extractStandardSchemasFromProject, extractStandardSchemas, extractSpecSummary, extractSchemaType, extractSchemaOutputType, extractPackageSpec, extractImports, extractFunctionCalls, ensureSpecCoverage, enrichSpec, diffSpecWithDocs, diffHashes, detectRuntimeSchemas, detectPackageManager, detectMonorepo, detectExampleRuntimeErrors, detectExampleAssertionFailures, detectEntryPoint, detectBuildInfo, defineConfig, createSourceFile, createNodeCommandRunner, computeSnapshot, computeExportDrift, computeDrift, clearSpecCache, categorizeDrifts, categorizeDrift, calculateAggregateCoverage, buildRawUrl, buildExportRegistry, buildDisplayUrl, buildCloneUrl, blockReferencesExport, applyPatchToJSDoc, applyEdits, analyzeProject2 as analyzeProject, analyzeFile, analyzeDocsImpact, analyze, WorkspacePackage, WorkspaceConfig, VALIDATION_INFO, TypecheckValidationResult, TypecheckResult, TypecheckOptions, SummaryDriftIssue, StandardSchemaExtractionResult, StandardSchemaExtractionOutput, StandardJSONSchemaV1, SpecSummary, SpecDiffWithDocs, SpecCacheConfig, SpecCache, SchemaExtractionResult, SchemaExtractionMode, SchemaDetectionResult, SchemaDetectionContext, SchemaAdapter, SandboxFileSystem, SPEC_CACHE_FILE, RuntimeDrift, RunValidationResult, RunExamplesWithPackageResult, RunExamplesWithPackageOptions, RunExampleOptions, ResolvedTarget, ResolvedFilters, ResolveTargetOptions, ReleaseTag, RETENTION_DAYS, REPORT_VERSION, REPORT_EXTENSIONS, ProjectInfo, PresenceResult, ParsedGitHubUrl, PackageManagerInfo, PackageManager, PackageJson, PackageExports, OpenPkgSpec, NodeFileSystem, MonorepoType, MonorepoInfo, MemberChange, MarkdownDocFile, MarkdownCodeBlock, LLMAssertion, JSDocTag, JSDocReturn, JSDocPatch, JSDocParam, JSDocEdit, InstallResult, InstallOptions, HISTORY_DIR, GitHubRepoMetadata, GitHubProjectContext, FixType, FixSuggestion, FilterSource, FilterOptions, FileSystem, FetchGitHubContextOptions, ExtractStandardSchemasOptions, ExtendedTrendAnalysis, ExportReference, ExportDriftResult, ExportCoverageData, ExampleValidationTypeError, ExampleValidationResult, ExampleValidationOptions, ExampleValidationMode, ExampleValidation, ExampleTypeError, ExampleRunResult, EntryPointSource, EntryPointInfo, EnrichedOpenPkg, EnrichedExport, EnrichedDocsMetadata, EnrichOptions, DriftSummary, DriftResult, DriftReportSummary, DriftReport, DocsImpactResult, DocsImpactReference, DocsImpact, DocsConfig, DocsChangeType, DocCovReport, DocCovOptions, DocCovConfig, DocCov, DiffWithDocsOptions, Diagnostic2 as Diagnostic, DetectedSchemaEntry, DetectedPackageManager, DEFAULT_REPORT_PATH, DEFAULT_REPORT_DIR, CoverageTrend, CoverageSummary, CoverageSnapshot, CommandRunner, CommandResult, CheckConfig, CategorizedDrift, CacheValidationResult, CacheContext, CACHE_VERSION, BuildPlanTarget, BuildPlanStepResult, BuildPlanStep, BuildPlanExecutionResult, BuildPlanEnvironment, BuildPlan, BuildInfo, BuildHints, ApplyEditsResult, AnalyzeProjectOptions, AnalyzeOptions, AnalysisResult, ALL_VALIDATIONS };
|
|
2649
|
+
export { validateSpecCache, validateExamples, typecheckExamples, typecheckExample, shouldValidate, serializeJSDoc, saveSpecCache, saveSnapshot, saveReport, safeParseJson, runExamplesWithPackage, runExamples, runExample, resolveTarget, resolveCompiledPath, renderSparkline, renderApiSurface, readPackageJson, pruneHistory, pruneByTier, parseGitHubUrl2 as parseScanGitHubUrl, parseMarkdownFiles, parseMarkdownFile, parseListFlag, parseJSDocToPatch, parseGitHubUrl, parseExamplesFlag, parseAssertions, mergeFixes, mergeFilters, loadSpecCache, loadSnapshots, loadCachedReport, listWorkspacePackages, isStandardJSONSchema, isSchemaType, isFixableDrift, isExecutableLang, installDependencies, hashString, hashFiles, hashFile, hasNonAssertionComments, hasDocsImpact, hasDocsForExport, groupDriftsByCategory, getUndocumentedExports, getTrend, getSupportedLibraries, getSpecCachePath, getRunCommand, getReportPath, getRegisteredAdapters, getPrimaryBuildScript, getInstallCommand, getExtendedTrend, getDriftSummary, getDocumentedExports, getDocsImpactSummary, getDiffReportPath, generateReportFromEnriched, generateReport, generateFixesForExport, generateFix, formatPackageList, formatDriftSummaryLine, formatDelta, findRemovedReferences, findPackageByName, findJSDocLocation, findExportReferences, findDeprecatedReferences, findAdapter, fetchSpecFromGitHub, fetchSpec, fetchGitHubContext, extractStandardSchemasFromProject, extractStandardSchemas, extractSpecSummary, extractSchemaType, extractSchemaOutputType, extractPackageSpec, extractImports, extractFunctionCalls, ensureSpecCoverage, enrichSpec, diffSpecWithDocs, diffHashes, detectRuntimeSchemas, detectPackageManager, detectMonorepo, detectExampleRuntimeErrors, detectExampleAssertionFailures, detectEntryPoint, detectBuildInfo, defineConfig, createSourceFile, createNodeCommandRunner, computeSnapshot, computeExportDrift, computeDrift, clearSpecCache, categorizeDrifts, categorizeDrift, calculateAggregateCoverage, buildRawUrl, buildExportRegistry, buildDocCovSpec, buildDisplayUrl, buildCloneUrl, blockReferencesExport, applyPatchToJSDoc, applyEdits, analyzeProject2 as analyzeProject, analyzeFile, analyzeDocsImpact, analyze, WorkspacePackage, WorkspaceConfig, VALIDATION_INFO, TypecheckValidationResult, TypecheckResult, TypecheckOptions, SummaryDriftIssue, StandardSchemaExtractionResult, StandardSchemaExtractionOutput, StandardJSONSchemaV1, SpecSummary, SpecDocDrift, SpecDiffWithDocs, SpecCacheConfig, SpecCache, SchemaExtractionResult, SchemaExtractionMode, SchemaDetectionResult, SchemaDetectionContext, SchemaAdapter, SandboxFileSystem, SPEC_CACHE_FILE, RuntimeDrift, RunValidationResult, RunExamplesWithPackageResult, RunExamplesWithPackageOptions, RunExampleOptions, RetentionTier, ResolvedTarget, ResolvedFilters, ResolveTargetOptions, ReleaseTag, RETENTION_DAYS, REPORT_VERSION, REPORT_EXTENSIONS, ProjectInfo, PresenceResult, ParsedGitHubUrl, PackageManagerInfo, PackageManager, PackageJson, PackageExports, OpenPkgSpec, NodeFileSystem, MonorepoType, MonorepoInfo, MemberChange, MarkdownDocFile, MarkdownCodeBlock, LLMAssertion, JSDocTag, JSDocReturn, JSDocPatch, JSDocParam, JSDocEdit, InstallResult, InstallOptions, HISTORY_DIR, GitHubRepoMetadata, GitHubProjectContext, FixType, FixSuggestion, FilterSource, FilterOptions, FileSystem, FetchGitHubContextOptions, ExtractStandardSchemasOptions, ExtendedTrendAnalysis, ExportReference, ExportDriftResult, ExportCoverageData, ExampleValidationTypeError, ExampleValidationResult, ExampleValidationOptions, ExampleValidationMode, ExampleValidation, ExampleTypeError, ExampleRunResult, EntryPointSource, EntryPointInfo, EnrichedOpenPkg, EnrichedExport, EnrichedDocsMetadata, EnrichOptions, DriftType, DriftSummary, DriftResult, DriftReportSummary, DriftReport, DriftCategory, DocsImpactResult, DocsImpactReference, DocsImpact, DocsConfig, DocsChangeType, DocCovReport, DocCovOptions, DocCovConfig, DocCov, DiffWithDocsOptions, Diagnostic2 as Diagnostic, DetectedSchemaEntry, DetectedPackageManager, DRIFT_CATEGORY_LABELS, DRIFT_CATEGORY_DESCRIPTIONS, DRIFT_CATEGORIES, DEFAULT_REPORT_PATH, DEFAULT_REPORT_DIR, CoverageTrend, CoverageSummary, CoverageSnapshot, CommandRunner, CommandResult, CheckConfig, CategorizedDrift, CacheValidationResult, CacheContext, CACHE_VERSION, BuildPlanTarget, BuildPlanStepResult, BuildPlanStep, BuildPlanExecutionResult, BuildPlanEnvironment, BuildPlan, BuildInfo, BuildHints, BuildDocCovOptions, ApplyEditsResult, AnalyzeProjectOptions, AnalyzeOptions, AnalysisResult, ALL_VALIDATIONS };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
+
DRIFT_CATEGORIES,
|
|
3
|
+
DRIFT_CATEGORY_DESCRIPTIONS,
|
|
4
|
+
DRIFT_CATEGORY_LABELS,
|
|
2
5
|
HISTORY_DIR,
|
|
3
6
|
RETENTION_DAYS,
|
|
4
7
|
applyEdits,
|
|
@@ -39,14 +42,16 @@ import {
|
|
|
39
42
|
mergeFixes,
|
|
40
43
|
parseAssertions,
|
|
41
44
|
parseJSDocToPatch,
|
|
45
|
+
pruneByTier,
|
|
42
46
|
pruneHistory,
|
|
47
|
+
renderApiSurface,
|
|
43
48
|
renderSparkline,
|
|
44
49
|
resolveCompiledPath,
|
|
45
50
|
saveReport,
|
|
46
51
|
saveSnapshot,
|
|
47
52
|
serializeJSDoc,
|
|
48
53
|
ts
|
|
49
|
-
} from "./shared/chunk-
|
|
54
|
+
} from "./shared/chunk-c1f9mytc.js";
|
|
50
55
|
import {
|
|
51
56
|
mergeFilters,
|
|
52
57
|
parseListFlag
|
|
@@ -4186,6 +4191,140 @@ function resolvePackageDir(entryFile) {
|
|
|
4186
4191
|
currentDir = parentDir;
|
|
4187
4192
|
}
|
|
4188
4193
|
}
|
|
4194
|
+
// src/analysis/doccov-builder.ts
|
|
4195
|
+
import { DRIFT_CATEGORIES as DRIFT_CATEGORIES2 } from "@doccov/spec";
|
|
4196
|
+
function buildDocCovSpec(options) {
|
|
4197
|
+
const { openpkg, openpkgPath } = options;
|
|
4198
|
+
const registry = buildExportRegistry(openpkg);
|
|
4199
|
+
const exports = {};
|
|
4200
|
+
let totalScore = 0;
|
|
4201
|
+
let documentedCount = 0;
|
|
4202
|
+
const missingByRule = {
|
|
4203
|
+
description: 0,
|
|
4204
|
+
params: 0,
|
|
4205
|
+
returns: 0,
|
|
4206
|
+
examples: 0,
|
|
4207
|
+
throws: 0
|
|
4208
|
+
};
|
|
4209
|
+
const driftByCategory = {
|
|
4210
|
+
structural: 0,
|
|
4211
|
+
semantic: 0,
|
|
4212
|
+
example: 0
|
|
4213
|
+
};
|
|
4214
|
+
let totalDrift = 0;
|
|
4215
|
+
let fixableDrift = 0;
|
|
4216
|
+
for (const exp of openpkg.exports ?? []) {
|
|
4217
|
+
const coverage = computeExportCoverage(exp);
|
|
4218
|
+
const rawDrifts = computeExportDrift(exp, registry);
|
|
4219
|
+
const categorizedDrifts = rawDrifts.map((d) => toCategorizedDrift(d));
|
|
4220
|
+
const exportId = exp.id ?? exp.name;
|
|
4221
|
+
exports[exportId] = {
|
|
4222
|
+
coverageScore: coverage.score,
|
|
4223
|
+
missing: coverage.missing.length > 0 ? coverage.missing : undefined,
|
|
4224
|
+
drift: categorizedDrifts.length > 0 ? categorizedDrifts : undefined
|
|
4225
|
+
};
|
|
4226
|
+
totalScore += coverage.score;
|
|
4227
|
+
if (coverage.score === 100)
|
|
4228
|
+
documentedCount++;
|
|
4229
|
+
for (const rule of coverage.missing) {
|
|
4230
|
+
missingByRule[rule]++;
|
|
4231
|
+
}
|
|
4232
|
+
for (const d of categorizedDrifts) {
|
|
4233
|
+
driftByCategory[d.category]++;
|
|
4234
|
+
totalDrift++;
|
|
4235
|
+
if (d.fixable)
|
|
4236
|
+
fixableDrift++;
|
|
4237
|
+
}
|
|
4238
|
+
}
|
|
4239
|
+
const exportCount = openpkg.exports?.length ?? 0;
|
|
4240
|
+
const summary = {
|
|
4241
|
+
score: exportCount > 0 ? Math.round(totalScore / exportCount) : 100,
|
|
4242
|
+
totalExports: exportCount,
|
|
4243
|
+
documentedExports: documentedCount,
|
|
4244
|
+
missingByRule,
|
|
4245
|
+
drift: {
|
|
4246
|
+
total: totalDrift,
|
|
4247
|
+
fixable: fixableDrift,
|
|
4248
|
+
byCategory: driftByCategory
|
|
4249
|
+
}
|
|
4250
|
+
};
|
|
4251
|
+
return {
|
|
4252
|
+
doccov: "1.0.0",
|
|
4253
|
+
source: {
|
|
4254
|
+
file: openpkgPath,
|
|
4255
|
+
specVersion: openpkg.openpkg,
|
|
4256
|
+
packageName: openpkg.meta.name,
|
|
4257
|
+
packageVersion: openpkg.meta.version
|
|
4258
|
+
},
|
|
4259
|
+
generatedAt: new Date().toISOString(),
|
|
4260
|
+
summary,
|
|
4261
|
+
exports
|
|
4262
|
+
};
|
|
4263
|
+
}
|
|
4264
|
+
function computeExportCoverage(exp) {
|
|
4265
|
+
const missing = [];
|
|
4266
|
+
let points = 0;
|
|
4267
|
+
let maxPoints = 0;
|
|
4268
|
+
maxPoints += 30;
|
|
4269
|
+
if (exp.description && exp.description.trim().length > 0) {
|
|
4270
|
+
points += 30;
|
|
4271
|
+
} else {
|
|
4272
|
+
missing.push("description");
|
|
4273
|
+
}
|
|
4274
|
+
const isCallable = exp.kind === "function" || exp.kind === "class";
|
|
4275
|
+
if (isCallable && exp.signatures?.length) {
|
|
4276
|
+
const sig = exp.signatures[0];
|
|
4277
|
+
const params = sig.parameters ?? [];
|
|
4278
|
+
if (params.length > 0) {
|
|
4279
|
+
maxPoints += 25;
|
|
4280
|
+
const documentedParams = params.filter((p) => p.description && p.description.trim().length > 0);
|
|
4281
|
+
if (documentedParams.length === params.length) {
|
|
4282
|
+
points += 25;
|
|
4283
|
+
} else if (documentedParams.length > 0) {
|
|
4284
|
+
points += Math.round(documentedParams.length / params.length * 25);
|
|
4285
|
+
missing.push("params");
|
|
4286
|
+
} else {
|
|
4287
|
+
missing.push("params");
|
|
4288
|
+
}
|
|
4289
|
+
}
|
|
4290
|
+
if (exp.kind === "function" && sig.returns) {
|
|
4291
|
+
maxPoints += 20;
|
|
4292
|
+
if (sig.returns.description && sig.returns.description.trim().length > 0) {
|
|
4293
|
+
points += 20;
|
|
4294
|
+
} else {
|
|
4295
|
+
missing.push("returns");
|
|
4296
|
+
}
|
|
4297
|
+
}
|
|
4298
|
+
if (sig.throws && sig.throws.length > 0) {
|
|
4299
|
+
maxPoints += 10;
|
|
4300
|
+
const documentedThrows = sig.throws.filter((t) => t.description);
|
|
4301
|
+
if (documentedThrows.length === sig.throws.length) {
|
|
4302
|
+
points += 10;
|
|
4303
|
+
} else {
|
|
4304
|
+
missing.push("throws");
|
|
4305
|
+
}
|
|
4306
|
+
}
|
|
4307
|
+
}
|
|
4308
|
+
maxPoints += 15;
|
|
4309
|
+
if (exp.examples && exp.examples.length > 0) {
|
|
4310
|
+
points += 15;
|
|
4311
|
+
} else {
|
|
4312
|
+
missing.push("examples");
|
|
4313
|
+
}
|
|
4314
|
+
const score = maxPoints > 0 ? Math.round(points / maxPoints * 100) : 100;
|
|
4315
|
+
return { score, missing };
|
|
4316
|
+
}
|
|
4317
|
+
function toCategorizedDrift(drift) {
|
|
4318
|
+
const driftType = drift.type;
|
|
4319
|
+
return {
|
|
4320
|
+
type: driftType,
|
|
4321
|
+
target: drift.target,
|
|
4322
|
+
issue: drift.issue,
|
|
4323
|
+
suggestion: drift.suggestion,
|
|
4324
|
+
category: DRIFT_CATEGORIES2[driftType],
|
|
4325
|
+
fixable: isFixableDrift(drift)
|
|
4326
|
+
};
|
|
4327
|
+
}
|
|
4189
4328
|
// src/config/types.ts
|
|
4190
4329
|
function defineConfig(config) {
|
|
4191
4330
|
return config;
|
|
@@ -6653,8 +6792,10 @@ export {
|
|
|
6653
6792
|
resolveTarget,
|
|
6654
6793
|
resolveCompiledPath,
|
|
6655
6794
|
renderSparkline,
|
|
6795
|
+
renderApiSurface,
|
|
6656
6796
|
readPackageJson,
|
|
6657
6797
|
pruneHistory,
|
|
6798
|
+
pruneByTier,
|
|
6658
6799
|
parseGitHubUrl2 as parseScanGitHubUrl,
|
|
6659
6800
|
parseMarkdownFiles,
|
|
6660
6801
|
parseMarkdownFile,
|
|
@@ -6742,6 +6883,7 @@ export {
|
|
|
6742
6883
|
calculateAggregateCoverage,
|
|
6743
6884
|
buildRawUrl,
|
|
6744
6885
|
buildExportRegistry,
|
|
6886
|
+
buildDocCovSpec,
|
|
6745
6887
|
buildDisplayUrl,
|
|
6746
6888
|
buildCloneUrl,
|
|
6747
6889
|
blockReferencesExport,
|
|
@@ -6760,6 +6902,9 @@ export {
|
|
|
6760
6902
|
NodeFileSystem,
|
|
6761
6903
|
HISTORY_DIR,
|
|
6762
6904
|
DocCov,
|
|
6905
|
+
DRIFT_CATEGORY_LABELS,
|
|
6906
|
+
DRIFT_CATEGORY_DESCRIPTIONS,
|
|
6907
|
+
DRIFT_CATEGORIES,
|
|
6763
6908
|
DEFAULT_REPORT_PATH,
|
|
6764
6909
|
DEFAULT_REPORT_DIR,
|
|
6765
6910
|
CACHE_VERSION,
|
|
@@ -219,6 +219,34 @@ async function detectRuntimeSchemas(context) {
|
|
|
219
219
|
};
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
+
// src/analysis/drift/types.ts
|
|
223
|
+
var DRIFT_CATEGORIES = {
|
|
224
|
+
"param-mismatch": "structural",
|
|
225
|
+
"param-type-mismatch": "structural",
|
|
226
|
+
"return-type-mismatch": "structural",
|
|
227
|
+
"optionality-mismatch": "structural",
|
|
228
|
+
"generic-constraint-mismatch": "structural",
|
|
229
|
+
"property-type-drift": "structural",
|
|
230
|
+
"async-mismatch": "structural",
|
|
231
|
+
"deprecated-mismatch": "semantic",
|
|
232
|
+
"visibility-mismatch": "semantic",
|
|
233
|
+
"broken-link": "semantic",
|
|
234
|
+
"example-drift": "example",
|
|
235
|
+
"example-syntax-error": "example",
|
|
236
|
+
"example-runtime-error": "example",
|
|
237
|
+
"example-assertion-failed": "example"
|
|
238
|
+
};
|
|
239
|
+
var DRIFT_CATEGORY_LABELS = {
|
|
240
|
+
structural: "Signature mismatches",
|
|
241
|
+
semantic: "Metadata issues",
|
|
242
|
+
example: "Example problems"
|
|
243
|
+
};
|
|
244
|
+
var DRIFT_CATEGORY_DESCRIPTIONS = {
|
|
245
|
+
structural: "JSDoc types or parameters don't match the actual code signature",
|
|
246
|
+
semantic: "Deprecation, visibility, or reference issues",
|
|
247
|
+
example: "@example code has errors or doesn't work correctly"
|
|
248
|
+
};
|
|
249
|
+
|
|
222
250
|
// src/fix/deterministic-fixes.ts
|
|
223
251
|
var FIXABLE_DRIFT_TYPES = new Set([
|
|
224
252
|
"param-mismatch",
|
|
@@ -1014,7 +1042,6 @@ function createSourceFile(filePath) {
|
|
|
1014
1042
|
return ts.createSourceFile(path2.basename(filePath), content, ts.ScriptTarget.Latest, true, filePath.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
|
|
1015
1043
|
}
|
|
1016
1044
|
// src/analysis/drift/categorize.ts
|
|
1017
|
-
import { DRIFT_CATEGORIES } from "@openpkg-ts/spec";
|
|
1018
1045
|
function categorizeDrift(drift) {
|
|
1019
1046
|
return {
|
|
1020
1047
|
...drift,
|
|
@@ -2884,4 +2911,4 @@ function getExtendedTrend(spec, cwd, options) {
|
|
|
2884
2911
|
};
|
|
2885
2912
|
}
|
|
2886
2913
|
|
|
2887
|
-
export { ts, isBuiltInTypeName, isBuiltInIdentifier, isStandardJSONSchema, resolveCompiledPath, extractStandardSchemas, extractStandardSchemasFromProject, detectRuntimeSchemas, isFixableDrift, generateFix, generateFixesForExport, mergeFixes, categorizeDrifts, parseJSDocToPatch, applyPatchToJSDoc, serializeJSDoc, findJSDocLocation, applyEdits, createSourceFile, categorizeDrift, groupDriftsByCategory, getDriftSummary, formatDriftSummaryLine, detectExampleRuntimeErrors, parseAssertions, hasNonAssertionComments, detectExampleAssertionFailures, buildExportRegistry, computeDrift, computeExportDrift, calculateAggregateCoverage, ensureSpecCoverage, enrichSpec, generateReport, generateReportFromEnriched, loadCachedReport, saveReport, isCachedReportValid, renderApiSurface, HISTORY_DIR, RETENTION_DAYS, computeSnapshot, saveSnapshot, loadSnapshots, getTrend, renderSparkline, formatDelta, pruneHistory, pruneByTier, loadSnapshotsForDays, generateWeeklySummaries, getExtendedTrend };
|
|
2914
|
+
export { ts, isBuiltInTypeName, isBuiltInIdentifier, isStandardJSONSchema, resolveCompiledPath, extractStandardSchemas, extractStandardSchemasFromProject, detectRuntimeSchemas, DRIFT_CATEGORIES, DRIFT_CATEGORY_LABELS, DRIFT_CATEGORY_DESCRIPTIONS, isFixableDrift, generateFix, generateFixesForExport, mergeFixes, categorizeDrifts, parseJSDocToPatch, applyPatchToJSDoc, serializeJSDoc, findJSDocLocation, applyEdits, createSourceFile, categorizeDrift, groupDriftsByCategory, getDriftSummary, formatDriftSummaryLine, detectExampleRuntimeErrors, parseAssertions, hasNonAssertionComments, detectExampleAssertionFailures, buildExportRegistry, computeDrift, computeExportDrift, calculateAggregateCoverage, ensureSpecCoverage, enrichSpec, generateReport, generateReportFromEnriched, loadCachedReport, saveReport, isCachedReportValid, renderApiSurface, HISTORY_DIR, RETENTION_DAYS, computeSnapshot, saveSnapshot, loadSnapshots, getTrend, renderSparkline, formatDelta, pruneHistory, pruneByTier, loadSnapshotsForDays, generateWeeklySummaries, getExtendedTrend };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* All possible drift type identifiers.
|
|
3
|
+
*/
|
|
4
|
+
type DriftType = "param-mismatch" | "param-type-mismatch" | "return-type-mismatch" | "generic-constraint-mismatch" | "optionality-mismatch" | "deprecated-mismatch" | "visibility-mismatch" | "async-mismatch" | "property-type-drift" | "example-drift" | "example-syntax-error" | "example-runtime-error" | "example-assertion-failed" | "broken-link";
|
|
5
|
+
type SpecDocDrift = {
|
|
6
|
+
type: DriftType;
|
|
7
|
+
target?: string;
|
|
8
|
+
issue: string;
|
|
9
|
+
suggestion?: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Drift categories group related drift types for progressive disclosure.
|
|
13
|
+
*/
|
|
14
|
+
type DriftCategory = "structural" | "semantic" | "example";
|
|
3
15
|
/**
|
|
4
16
|
* Extended drift with category and fixability metadata.
|
|
5
17
|
*/
|
|
@@ -66,7 +78,7 @@ interface DriftReportSummary {
|
|
|
66
78
|
/**
|
|
67
79
|
* Count of issues per category.
|
|
68
80
|
*/
|
|
69
|
-
byCategory: Record<
|
|
81
|
+
byCategory: Record<DriftCategory, number>;
|
|
70
82
|
/**
|
|
71
83
|
* Number of auto-fixable issues.
|
|
72
84
|
*/
|
|
@@ -88,7 +100,7 @@ interface DriftReport {
|
|
|
88
100
|
/**
|
|
89
101
|
* Issues grouped by category.
|
|
90
102
|
*/
|
|
91
|
-
byCategory: Record<
|
|
103
|
+
byCategory: Record<DriftCategory, CategorizedDrift[]>;
|
|
92
104
|
/**
|
|
93
105
|
* Flat list of all drift issues (backward compatible).
|
|
94
106
|
*/
|
|
@@ -146,7 +158,7 @@ interface ExportCoverageData {
|
|
|
146
158
|
/**
|
|
147
159
|
* Drift issues for this export.
|
|
148
160
|
*/
|
|
149
|
-
drift?:
|
|
161
|
+
drift?: SpecDocDrift[];
|
|
150
162
|
}
|
|
151
163
|
/**
|
|
152
164
|
* DocCov report - a persistable coverage analysis result.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@doccov/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "DocCov SDK - Documentation coverage and drift detection for TypeScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -47,7 +47,9 @@
|
|
|
47
47
|
"dist"
|
|
48
48
|
],
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@
|
|
50
|
+
"@doccov/spec": "workspace:*",
|
|
51
|
+
"@openpkg-ts/extract": "workspace:*",
|
|
52
|
+
"@openpkg-ts/spec": "workspace:*",
|
|
51
53
|
"@vercel/sandbox": "^1.0.3",
|
|
52
54
|
"mdast": "^3.0.0",
|
|
53
55
|
"minimatch": "^10.1.1",
|