@doccov/sdk 0.30.7 → 0.31.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.
@@ -1,11 +1,41 @@
1
1
  /**
2
+ * Documentation style presets.
3
+ *
4
+ * - 'minimal': Only description required (default)
5
+ * - 'verbose': Description, params, returns all required
6
+ * - 'types-only': No documentation required (rely on TypeScript types)
7
+ */
8
+ type StylePreset = "minimal" | "verbose" | "types-only";
9
+ /**
2
10
  * Pre-detected Standard Schema for a variable export.
3
11
  */
4
12
  interface DetectedSchemaEntry {
5
13
  schema: Record<string, unknown>;
6
14
  vendor: string;
7
15
  }
8
- import { DocCovSpec, TypeReferenceLocation } from "@doccov/spec";
16
+ import { DocCovSpec, ExportAnalysis, TypeReferenceLocation } from "@doccov/spec";
17
+ /**
18
+ * Documentation style presets for DocCov.
19
+ *
20
+ * Presets define expected documentation patterns that vary by project.
21
+ * Some projects require verbose docs with @param/@returns for every function,
22
+ * while others rely on TypeScript types and only need descriptions.
23
+ */
24
+ /**
25
+ * Documentation requirements - what must be present for an to be considered documented.
26
+ */
27
+ interface DocRequirements2 {
28
+ /** Require description/summary */
29
+ description: boolean;
30
+ /** Require @param tags for function parameters */
31
+ params: boolean;
32
+ /** Require @returns tag for functions */
33
+ returns: boolean;
34
+ /** Require @example blocks */
35
+ examples: boolean;
36
+ /** Require @since tag */
37
+ since: boolean;
38
+ }
9
39
  import { OpenPkg } from "@openpkg-ts/spec";
10
40
  type OpenPkgSpec = OpenPkg;
11
41
  /** Forgotten from extract package (different shape than spec type) */
@@ -29,6 +59,23 @@ interface BuildDocCovOptions {
29
59
  forgottenExports?: ExtractForgottenExport[];
30
60
  /** Type names to ignore in API surface calculation */
31
61
  apiSurfaceIgnore?: string[];
62
+ /**
63
+ * Export names from the package entry point.
64
+ * When analyzing a sub-file, provide this to filter out false positive
65
+ * "forgotten" exports that are actually exported from the main entry.
66
+ */
67
+ entryExportNames?: string[];
68
+ /** Progress callback for long-running analysis */
69
+ onProgress?: (current: number, total: number, item: string) => void;
70
+ /**
71
+ * Callback invoked after each is analyzed.
72
+ * Can be used for incremental persistence (crash recovery).
73
+ */
74
+ onExportAnalyzed?: (id: string, name: string, analysis: ExportAnalysis, index: number, total: number) => void | Promise<void>;
75
+ /** Documentation style preset */
76
+ style?: StylePreset;
77
+ /** Custom documentation requirements (overrides preset) */
78
+ require?: Partial<DocRequirements2>;
32
79
  }
33
80
  /**
34
81
  * Build a DocCov spec from an OpenPkg spec.
@@ -36,7 +83,7 @@ interface BuildDocCovOptions {
36
83
  * @param options - Build options
37
84
  * @returns DocCov specification with coverage analysis
38
85
  */
39
- declare function buildDocCovSpec(options: BuildDocCovOptions): DocCovSpec;
86
+ declare function buildDocCovSpec(options: BuildDocCovOptions): Promise<DocCovSpec>;
40
87
  /**
41
88
  * All possible drift type identifiers.
42
89
  */
@@ -45,6 +92,11 @@ type SpecDocDrift = {
45
92
  type: DriftType;
46
93
  target?: string;
47
94
  issue: string;
95
+ /** Expected value from JSDoc/documentation */
96
+ expected?: string;
97
+ /** Actual value from TypeScript signature/code */
98
+ actual?: string;
99
+ /** Actionable suggestion for fixing the drift */
48
100
  suggestion?: string;
49
101
  };
50
102
  /**
@@ -166,6 +218,93 @@ declare function getDriftSummary(drifts: SpecDocDrift[]): DriftSummary;
166
218
  */
167
219
  declare function formatDriftSummaryLine(summary: DriftSummary): string;
168
220
  import { SpecExport } from "@openpkg-ts/spec";
221
+ import { OpenPkg as OpenPkg2 } from "@openpkg-ts/spec";
222
+ /**
223
+ * Information about a module in the graph.
224
+ */
225
+ interface ModuleInfo {
226
+ /**
227
+ * Module name (package name).
228
+ */
229
+ name: string;
230
+ /**
231
+ * Set of exported symbol names from this module.
232
+ */
233
+ exports: Set<string>;
234
+ /**
235
+ * Set of type names exported from this module.
236
+ */
237
+ types: Set<string>;
238
+ }
239
+ /**
240
+ * Graph of modules and their exported symbols for cross-module validation.
241
+ */
242
+ interface ModuleGraph {
243
+ /**
244
+ * Map of module names to their info.
245
+ */
246
+ modules: Map<string, ModuleInfo>;
247
+ /**
248
+ * Map of symbol names to the module that exports them.
249
+ * For symbols exported from multiple modules, contains the first found.
250
+ */
251
+ exports: Map<string, string>;
252
+ /**
253
+ * Map of type names to the module that exports them.
254
+ */
255
+ types: Map<string, string>;
256
+ /**
257
+ * Combined set of all exported symbol and type names across all modules.
258
+ */
259
+ all: Set<string>;
260
+ }
261
+ /**
262
+ * Build a module graph from multiple OpenPkg specs.
263
+ *
264
+ * Used for cross-module @link validation in batch mode.
265
+ *
266
+ * @param specs - Array of OpenPkg specs to build graph from
267
+ * @returns ModuleGraph for cross-module symbol lookup
268
+ *
269
+ * @example
270
+ * ```ts
271
+ * import { buildModuleGraph } from '@doccov/sdk';
272
+ *
273
+ * const graph = buildModuleGraph([pkg1Spec, pkg2Spec]);
274
+ *
275
+ * // Check if symbol exists in any module
276
+ * if (graph.all.has('Schedule')) {
277
+ * console.log(`Schedule is exported from: ${graph.exports.get('Schedule')}`);
278
+ * }
279
+ * ```
280
+ */
281
+ declare function buildModuleGraph(specs: OpenPkg2[]): ModuleGraph;
282
+ /**
283
+ * Check if a symbol exists in the module graph.
284
+ *
285
+ * @param graph - Module graph to search
286
+ * @param symbol - Symbol name to find
287
+ * @returns Module name if found, undefined otherwise
288
+ */
289
+ declare function findSymbolModule(graph: ModuleGraph, symbol: string): string | undefined;
290
+ /**
291
+ * Check if a symbol exists anywhere in the module graph.
292
+ *
293
+ * @param graph - Module graph to search
294
+ * @param symbol - Symbol name to check
295
+ * @returns true if symbol exists in any module
296
+ */
297
+ declare function symbolExistsInGraph(graph: ModuleGraph, symbol: string): boolean;
298
+ /**
299
+ * Options for computing drift.
300
+ */
301
+ interface ComputeDriftOptions {
302
+ /**
303
+ * Module graph for cross-module @link validation.
304
+ * When provided, @link targets are validated across all modules.
305
+ */
306
+ moduleGraph?: ModuleGraph;
307
+ }
169
308
  /**
170
309
  * Build a registry of all export/type names for cross-reference validation.
171
310
  */
@@ -174,16 +313,18 @@ declare function buildExportRegistry(spec: OpenPkgSpec): ExportRegistry;
174
313
  * Compute drift for all exports in a spec.
175
314
  *
176
315
  * @param spec - The OpenPkg spec to analyze
316
+ * @param options - Optional config including moduleGraph for cross-module validation
177
317
  * @returns Drift results per */
178
- declare function computeDrift(spec: OpenPkgSpec): DriftResult;
318
+ declare function computeDrift(spec: OpenPkgSpec, options?: ComputeDriftOptions): DriftResult;
179
319
  /**
180
320
  * Compute drift for a single export.
181
321
  *
182
322
  * @param entry - The to analyze
183
323
  * @param registry - Registry of known exports and types for validation
324
+ * @param options - Optional config including moduleGraph for cross-module validation
184
325
  * @returns Array of drift issues detected
185
326
  */
186
- declare function computeExportDrift(entry: SpecExport, registry?: ExportRegistry): SpecDocDrift[];
327
+ declare function computeExportDrift(entry: SpecExport, registry?: ExportRegistry, options?: ComputeDriftOptions): SpecDocDrift[];
187
328
  /**
188
329
  * Calculate aggregate coverage score from a spec's exports.
189
330
  *
@@ -262,7 +403,7 @@ declare function hasNonAssertionComments(code: string): boolean;
262
403
  * Detect assertion failures by comparing stdout to expected values.
263
404
  */
264
405
  declare function detectExampleAssertionFailures(entry: SpecExport2, runtimeResults: Map<number, ExampleRunResult>): SpecDocDrift[];
265
- import { OpenPkg as OpenPkg2 } from "@openpkg-ts/spec";
406
+ import { OpenPkg as OpenPkg3 } from "@openpkg-ts/spec";
266
407
  /** Directory for storing history snapshots (relative to .doccov) */
267
408
  declare const HISTORY_DIR = ".doccov/history";
268
409
  /**
@@ -349,7 +490,7 @@ interface ExtendedTrendAnalysis {
349
490
  /**
350
491
  * Compute a coverage snapshot from an OpenPkg spec.
351
492
  */
352
- declare function computeSnapshot(spec: OpenPkg2, options?: {
493
+ declare function computeSnapshot(spec: OpenPkg3, options?: {
353
494
  commit?: string;
354
495
  branch?: string;
355
496
  }): CoverageSnapshot;
@@ -379,7 +520,7 @@ declare function loadSnapshots(cwd: string): CoverageSnapshot[];
379
520
  * @param options - Optional git metadata
380
521
  * @returns Trend data with history and delta
381
522
  */
382
- declare function getTrend(spec: OpenPkg2, cwd: string, options?: {
523
+ declare function getTrend(spec: OpenPkg3, cwd: string, options?: {
383
524
  commit?: string;
384
525
  branch?: string;
385
526
  }): CoverageTrend;
@@ -430,11 +571,11 @@ declare function generateWeeklySummaries(snapshots: CoverageSnapshot[]): WeeklyS
430
571
  * @param options - Optional git metadata
431
572
  * @returns Extended trend analysis
432
573
  */
433
- declare function getExtendedTrend(spec: OpenPkg2, cwd: string, options?: {
574
+ declare function getExtendedTrend(spec: OpenPkg3, cwd: string, options?: {
434
575
  commit?: string;
435
576
  branch?: string;
436
577
  }): ExtendedTrendAnalysis;
437
- import { DocCovDrift, DocCovSpec as DocCovSpec2, ExportAnalysis, MissingDocRule } from "@doccov/spec";
578
+ import { DocCovDrift, DocCovSpec as DocCovSpec2, ExportAnalysis as ExportAnalysis2, MissingDocRule } from "@doccov/spec";
438
579
  import { SpecExport as SpecExport7 } from "@openpkg-ts/spec";
439
580
  /**
440
581
  * Get the full analysis data for an export.
@@ -443,7 +584,7 @@ import { SpecExport as SpecExport7 } from "@openpkg-ts/spec";
443
584
  * @param doccov - The DocCov spec containing analysis data
444
585
  * @returns Export analysis or undefined if not found
445
586
  */
446
- declare function getExportAnalysis(exp: SpecExport7, doccov: DocCovSpec2): ExportAnalysis | undefined;
587
+ declare function getExportAnalysis(exp: SpecExport7, doccov: DocCovSpec2): ExportAnalysis2 | undefined;
447
588
  /**
448
589
  * Get the coverage score for an export.
449
590
  *
@@ -477,7 +618,7 @@ declare function getExportMissing(exp: SpecExport7, doccov: DocCovSpec2): Missin
477
618
  */
478
619
  declare function isExportFullyDocumented(exp: SpecExport7, doccov: DocCovSpec2): boolean;
479
620
  import { DocCovSpec as DocCovSpec3 } from "@doccov/spec";
480
- import { OpenPkg as OpenPkg3 } from "@openpkg-ts/spec";
621
+ import { OpenPkg as OpenPkg4 } from "@openpkg-ts/spec";
481
622
  import { ApiSurfaceResult, DocumentationHealth } from "@doccov/spec";
482
623
  /**
483
624
  * Drift summary with category breakdown.
@@ -549,6 +690,10 @@ interface ExportCoverageData {
549
690
  * Drift issues for this export.
550
691
  */
551
692
  drift?: SpecDocDrift[];
693
+ /**
694
+ * Number of overloads if > 1 (for overloaded functions).
695
+ */
696
+ overloadCount?: number;
552
697
  }
553
698
  /**
554
699
  * DocCov report - a persistable coverage analysis result.
@@ -611,7 +756,7 @@ interface DocCovReport {
611
756
  * console.log(`Coverage: ${report.coverage.score}%`);
612
757
  * ```
613
758
  */
614
- declare function generateReport(spec: OpenPkg3, openpkgPath?: string): DocCovReport;
759
+ declare function generateReport(spec: OpenPkg4, openpkgPath?: string): Promise<DocCovReport>;
615
760
  /**
616
761
  * Generate a DocCov report from OpenPkg spec + DocCov spec composition.
617
762
  *
@@ -622,7 +767,7 @@ declare function generateReport(spec: OpenPkg3, openpkgPath?: string): DocCovRep
622
767
  * @param doccov - The DocCov spec with analysis data
623
768
  * @returns A DocCov report with coverage analysis
624
769
  */
625
- declare function generateReportFromDocCov(openpkg: OpenPkg3, doccov: DocCovSpec3): DocCovReport;
770
+ declare function generateReportFromDocCov(openpkg: OpenPkg4, doccov: DocCovSpec3): DocCovReport;
626
771
  /**
627
772
  * Load a cached DocCov report from disk.
628
773
  *
@@ -670,7 +815,7 @@ declare function isCachedReportValid(reportPath?: string, sourceFiles?: string[]
670
815
  * fs.writeFileSync('api-surface.md', apiSurface);
671
816
  * ```
672
817
  */
673
- declare function renderApiSurface(spec: OpenPkg3): string;
818
+ declare function renderApiSurface(spec: OpenPkg4): string;
674
819
  interface SchemaDetectionContext {
675
820
  baseDir: string;
676
821
  entryFile: string;
@@ -686,4 +831,131 @@ interface SchemaDetectionResult {
686
831
  noCompiledJsWarning?: boolean;
687
832
  }
688
833
  declare function detectRuntimeSchemas(context: SchemaDetectionContext): Promise<SchemaDetectionResult>;
689
- export { saveSnapshot, saveReport, renderSparkline, renderApiSurface, pruneHistory, parseAssertions, loadSnapshotsForDays, loadSnapshots, loadCachedReport, isExportFullyDocumented, isCachedReportValid, hasNonAssertionComments, groupDriftsByCategory, getTrend, getExtendedTrend, getExportScore, getExportMissing, getExportDrift, getExportAnalysis, getDriftSummary, generateWeeklySummaries, generateReportFromDocCov, generateReport, formatDriftSummaryLine, formatDelta, ensureSpecCoverage, detectRuntimeSchemas, detectExampleRuntimeErrors, detectExampleAssertionFailures, computeSnapshot, computeExportDrift, computeDrift, categorizeDrift, calculateAggregateCoverage, buildExportRegistry, buildDocCovSpec, WeeklySummary, SchemaDetectionResult, SchemaDetectionContext, OpenPkgSpec, HISTORY_DIR, ExtractForgottenExport, ExtendedTrendAnalysis, ExportDriftResult, DriftSummary, DriftResult, DetectedSchemaEntry, CoverageTrend, CoverageSnapshot, CategorizedDrift, BuildDocCovOptions };
834
+ import { DocCovDrift as DocCovDrift2, ExportAnalysis as ExportAnalysis3, MissingDocRule as MissingDocRule2 } from "@doccov/spec";
835
+ /**
836
+ * Result from analyzing a single incrementally.
837
+ */
838
+ interface IncrementalExportResult {
839
+ /** Export ID (usually name) */
840
+ id: string;
841
+ /** Export name */
842
+ name: string;
843
+ /** Coverage score (0-100) */
844
+ coverageScore: number;
845
+ /** Missing documentation rules */
846
+ missing?: MissingDocRule2[];
847
+ /** Drift issues detected */
848
+ drift?: DocCovDrift2[];
849
+ /** Number of overloads (if > 1) */
850
+ overloadCount?: number;
851
+ /** Timestamp when this result was written */
852
+ timestamp: number;
853
+ }
854
+ /**
855
+ * Partial analysis state recovered from temp file.
856
+ */
857
+ interface PartialAnalysisState {
858
+ /** Results collected before interruption */
859
+ results: IncrementalExportResult[];
860
+ /** Total exports that were expected */
861
+ totalExpected?: number;
862
+ /** Whether analysis was interrupted */
863
+ interrupted: boolean;
864
+ }
865
+ /**
866
+ * Options for IncrementalAnalyzer.
867
+ */
868
+ interface IncrementalAnalyzerOptions {
869
+ /** Custom temp directory (defaults to os.tmpdir()) */
870
+ tempDir?: string;
871
+ /** Prefix for temp file name */
872
+ prefix?: string;
873
+ }
874
+ /**
875
+ * Analyzer that persists results incrementally for crash recovery.
876
+ *
877
+ * Usage:
878
+ * ```ts
879
+ * const analyzer = new IncrementalAnalyzer();
880
+ * analyzer.setTotal(exports.length);
881
+ *
882
+ * for (const exp of exports) {
883
+ * const result = analyzeExport(exp);
884
+ * await analyzer.writeResult(result);
885
+ * }
886
+ *
887
+ * // On success, clean up
888
+ * analyzer.cleanup();
889
+ *
890
+ * // On crash, recover partial results:
891
+ * const partial = await analyzer.getPartialResults();
892
+ * ```
893
+ */
894
+ declare class IncrementalAnalyzer {
895
+ private tempPath;
896
+ private totalExpected?;
897
+ private resultCount;
898
+ private fileHandle?;
899
+ constructor(options?: IncrementalAnalyzerOptions);
900
+ /**
901
+ * Get the temp file path (for debugging/logging).
902
+ */
903
+ get path(): string;
904
+ /**
905
+ * Get count of results written so far.
906
+ */
907
+ get count(): number;
908
+ /**
909
+ * Set total expected exports (for progress reporting).
910
+ */
911
+ setTotal(total: number): void;
912
+ /**
913
+ * Initialize the file handle for writing.
914
+ * Called automatically on first writeResult, but can be called
915
+ * explicitly for eager initialization.
916
+ */
917
+ init(): Promise<void>;
918
+ /**
919
+ * Write a single result to the temp file.
920
+ */
921
+ writeResult(result: IncrementalExportResult): Promise<void>;
922
+ /**
923
+ * Write an analysis result (converts from ExportAnalysis format).
924
+ */
925
+ writeExportAnalysis(id: string, name: string, analysis: ExportAnalysis3): Promise<void>;
926
+ /**
927
+ * Read partial results from the temp file.
928
+ * Returns empty array if file doesn't exist.
929
+ */
930
+ getPartialResults(): Promise<PartialAnalysisState>;
931
+ /**
932
+ * Clean up the temp file. Call this on successful completion.
933
+ */
934
+ cleanup(): Promise<void>;
935
+ /**
936
+ * Synchronous cleanup for use in signal handlers.
937
+ * Note: May lose last few writes that haven't been flushed.
938
+ */
939
+ cleanupSync(): void;
940
+ /**
941
+ * Check if temp file exists (for recovery detection).
942
+ */
943
+ exists(): boolean;
944
+ /**
945
+ * Get partial results synchronously (for signal handlers).
946
+ * May miss most recent writes.
947
+ */
948
+ getPartialResultsSync(): PartialAnalysisState;
949
+ }
950
+ /**
951
+ * Find any orphaned temp files from previous crashed runs.
952
+ * Returns paths to .ndjson files that match the doccov pattern.
953
+ */
954
+ declare function findOrphanedTempFiles(tempDir?: string, prefix?: string): string[];
955
+ /**
956
+ * Clean up orphaned temp files older than maxAge.
957
+ *
958
+ * @param maxAge - Maximum age in milliseconds (default: 1 hour)
959
+ */
960
+ declare function cleanupOrphanedTempFiles(tempDir?: string, prefix?: string, maxAge?: number): number;
961
+ export { symbolExistsInGraph, saveSnapshot, saveReport, renderSparkline, renderApiSurface, pruneHistory, parseAssertions, loadSnapshotsForDays, loadSnapshots, loadCachedReport, isExportFullyDocumented, isCachedReportValid, hasNonAssertionComments, groupDriftsByCategory, getTrend, getExtendedTrend, getExportScore, getExportMissing, getExportDrift, getExportAnalysis, getDriftSummary, generateWeeklySummaries, generateReportFromDocCov, generateReport, formatDriftSummaryLine, formatDelta, findSymbolModule, findOrphanedTempFiles, ensureSpecCoverage, detectRuntimeSchemas, detectExampleRuntimeErrors, detectExampleAssertionFailures, computeSnapshot, computeExportDrift, computeDrift, cleanupOrphanedTempFiles, categorizeDrift, calculateAggregateCoverage, buildModuleGraph, buildExportRegistry, buildDocCovSpec, WeeklySummary, SchemaDetectionResult, SchemaDetectionContext, PartialAnalysisState, OpenPkgSpec, ModuleInfo, ModuleGraph, IncrementalExportResult, IncrementalAnalyzerOptions, IncrementalAnalyzer, HISTORY_DIR, ExtractForgottenExport, ExtendedTrendAnalysis, ExportDriftResult, DriftSummary, DriftResult, DetectedSchemaEntry, CoverageTrend, CoverageSnapshot, CategorizedDrift, BuildDocCovOptions };
@@ -1,9 +1,12 @@
1
1
  import {
2
2
  HISTORY_DIR,
3
+ IncrementalAnalyzer,
3
4
  buildDocCovSpec,
4
5
  buildExportRegistry,
6
+ buildModuleGraph,
5
7
  calculateAggregateCoverage,
6
8
  categorizeDrift,
9
+ cleanupOrphanedTempFiles,
7
10
  computeDrift,
8
11
  computeExportDrift,
9
12
  computeSnapshot,
@@ -11,6 +14,8 @@ import {
11
14
  detectExampleRuntimeErrors,
12
15
  detectRuntimeSchemas,
13
16
  ensureSpecCoverage,
17
+ findOrphanedTempFiles,
18
+ findSymbolModule,
14
19
  formatDelta,
15
20
  formatDriftSummaryLine,
16
21
  generateReport,
@@ -35,10 +40,12 @@ import {
35
40
  renderApiSurface,
36
41
  renderSparkline,
37
42
  saveReport,
38
- saveSnapshot
39
- } from "../shared/chunk-ehne5cde.js";
43
+ saveSnapshot,
44
+ symbolExistsInGraph
45
+ } from "../shared/chunk-ee3ctqje.js";
40
46
  import"../shared/chunk-r4wa72ae.js";
41
47
  export {
48
+ symbolExistsInGraph,
42
49
  saveSnapshot,
43
50
  saveReport,
44
51
  renderSparkline,
@@ -64,6 +71,8 @@ export {
64
71
  generateReport,
65
72
  formatDriftSummaryLine,
66
73
  formatDelta,
74
+ findSymbolModule,
75
+ findOrphanedTempFiles,
67
76
  ensureSpecCoverage,
68
77
  detectRuntimeSchemas,
69
78
  detectExampleRuntimeErrors,
@@ -71,9 +80,12 @@ export {
71
80
  computeSnapshot,
72
81
  computeExportDrift,
73
82
  computeDrift,
83
+ cleanupOrphanedTempFiles,
74
84
  categorizeDrift,
75
85
  calculateAggregateCoverage,
86
+ buildModuleGraph,
76
87
  buildExportRegistry,
77
88
  buildDocCovSpec,
89
+ IncrementalAnalyzer,
78
90
  HISTORY_DIR
79
91
  };