@doccov/sdk 0.22.0 → 0.23.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 +650 -0
- package/dist/analysis/index.js +73 -0
- package/dist/index.d.ts +1173 -1209
- package/dist/index.js +5728 -8515
- package/dist/shared/chunk-esptwrfq.js +40 -0
- package/dist/shared/chunk-m6c6ffwr.js +44 -0
- package/dist/shared/chunk-nk2w5vws.js +2887 -0
- package/dist/types/index.d.ts +322 -0
- package/dist/types/index.js +22 -0
- package/package.json +9 -1
|
@@ -0,0 +1,650 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pre-detected Standard Schema for a variable export.
|
|
3
|
+
*/
|
|
4
|
+
interface DetectedSchemaEntry {
|
|
5
|
+
schema: Record<string, unknown>;
|
|
6
|
+
vendor: string;
|
|
7
|
+
}
|
|
8
|
+
import { DriftCategory as DriftCategory2, SpecDocDrift as SpecDocDrift2 } from "@openpkg-ts/spec";
|
|
9
|
+
import { DriftCategory, SpecDocDrift } from "@openpkg-ts/spec";
|
|
10
|
+
/**
|
|
11
|
+
* Result of computing drift for a single export.
|
|
12
|
+
*/
|
|
13
|
+
type ExportDriftResult = {
|
|
14
|
+
id: string;
|
|
15
|
+
drift: SpecDocDrift[];
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Result of computing drift for all exports.
|
|
19
|
+
*/
|
|
20
|
+
type DriftResult = {
|
|
21
|
+
exports: Map<string, SpecDocDrift[]>;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Information about an for context-aware suggestions.
|
|
25
|
+
*/
|
|
26
|
+
interface ExportInfo {
|
|
27
|
+
name: string;
|
|
28
|
+
kind: string;
|
|
29
|
+
isCallable: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Registry of exports and types for cross-reference validation.
|
|
33
|
+
*/
|
|
34
|
+
interface ExportRegistry {
|
|
35
|
+
/** Map of names to their info (for context-aware suggestions) */
|
|
36
|
+
exports: Map<string, ExportInfo>;
|
|
37
|
+
/** Set of type names (interfaces, type aliases, etc.) */
|
|
38
|
+
types: Set<string>;
|
|
39
|
+
/** Combined set of all names (for backward compatibility) */
|
|
40
|
+
all: Set<string>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Extended drift with category and fixability metadata.
|
|
44
|
+
*/
|
|
45
|
+
interface CategorizedDrift extends SpecDocDrift {
|
|
46
|
+
category: DriftCategory;
|
|
47
|
+
fixable: boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Summary of drift issues by category.
|
|
51
|
+
*/
|
|
52
|
+
interface DriftSummary {
|
|
53
|
+
total: number;
|
|
54
|
+
byCategory: Record<DriftCategory, number>;
|
|
55
|
+
fixable: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Categorize a single drift issue.
|
|
59
|
+
*
|
|
60
|
+
* @param drift - The drift to categorize
|
|
61
|
+
* @returns The drift with category and fixable metadata
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* const drift: SpecDocDrift = {
|
|
66
|
+
* type: 'param-type-mismatch',
|
|
67
|
+
* target: 'userId',
|
|
68
|
+
* issue: 'Type mismatch'
|
|
69
|
+
* };
|
|
70
|
+
* const categorized = categorizeDrift(drift);
|
|
71
|
+
* console.log(categorized.category); // => 'structural'
|
|
72
|
+
* console.log(categorized.fixable); // => true
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
declare function categorizeDrift(drift: SpecDocDrift2): CategorizedDrift;
|
|
76
|
+
/**
|
|
77
|
+
* Group drifts by category.
|
|
78
|
+
*
|
|
79
|
+
* @param drifts - Array of drift issues to group
|
|
80
|
+
* @returns Drifts organized by category
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* const grouped = groupDriftsByCategory(spec.docs.drift ?? []);
|
|
85
|
+
* console.log(grouped.structural.length); // Number of structural issues
|
|
86
|
+
* console.log(grouped.semantic.length); // Number of semantic issues
|
|
87
|
+
* console.log(grouped.example.length); // Number of example issues
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
declare function groupDriftsByCategory(drifts: SpecDocDrift2[]): Record<DriftCategory2, CategorizedDrift[]>;
|
|
91
|
+
/**
|
|
92
|
+
* Get drift summary counts by category.
|
|
93
|
+
*
|
|
94
|
+
* @param drifts - Array of drift issues
|
|
95
|
+
* @returns Summary with totals, category breakdown, and fixable count
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* const summary = getDriftSummary(exportEntry.docs?.drift ?? []);
|
|
100
|
+
* console.log(`${summary.total} issues: ${summary.fixable} fixable`);
|
|
101
|
+
* // => "5 issues: 3 fixable"
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
declare function getDriftSummary(drifts: SpecDocDrift2[]): DriftSummary;
|
|
105
|
+
/**
|
|
106
|
+
* Format drift summary for CLI output (single line).
|
|
107
|
+
*
|
|
108
|
+
* @param summary - Drift summary to format
|
|
109
|
+
* @returns Human-readable summary string
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* const summary = getDriftSummary(drifts);
|
|
114
|
+
* console.log(formatDriftSummaryLine(summary));
|
|
115
|
+
* // => "5 issues (3 structural, 1 semantic, 1 example)"
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
declare function formatDriftSummaryLine(summary: DriftSummary): string;
|
|
119
|
+
import { SpecDocDrift as SpecDocDrift3, SpecExport } from "@openpkg-ts/spec";
|
|
120
|
+
import { OpenPkg } from "@openpkg-ts/spec";
|
|
121
|
+
type OpenPkgSpec = OpenPkg;
|
|
122
|
+
/**
|
|
123
|
+
* Build a registry of all export/type names for cross-reference validation.
|
|
124
|
+
*/
|
|
125
|
+
declare function buildExportRegistry(spec: OpenPkgSpec): ExportRegistry;
|
|
126
|
+
/**
|
|
127
|
+
* Compute drift for all exports in a spec.
|
|
128
|
+
*
|
|
129
|
+
* @param spec - The OpenPkg spec to analyze
|
|
130
|
+
* @returns Drift results per */
|
|
131
|
+
declare function computeDrift(spec: OpenPkgSpec): DriftResult;
|
|
132
|
+
/**
|
|
133
|
+
* Compute drift for a single export.
|
|
134
|
+
*
|
|
135
|
+
* @param entry - The to analyze
|
|
136
|
+
* @param registry - Registry of known exports and types for validation
|
|
137
|
+
* @returns Array of drift issues detected
|
|
138
|
+
*/
|
|
139
|
+
declare function computeExportDrift(entry: SpecExport, registry?: ExportRegistry): SpecDocDrift3[];
|
|
140
|
+
/**
|
|
141
|
+
* Calculate aggregate coverage score from a spec's exports.
|
|
142
|
+
*
|
|
143
|
+
* This is a lightweight function that calculates coverage without
|
|
144
|
+
* requiring full quality evaluation. It handles three cases:
|
|
145
|
+
* 1. Exports with `docs.coverageScore` - uses that value
|
|
146
|
+
* 2. Exports without score but with description - counts as 100%
|
|
147
|
+
* 3. Exports without score and no description - counts as 0%
|
|
148
|
+
*
|
|
149
|
+
* @param spec - The OpenPkg spec to calculate coverage for
|
|
150
|
+
* @returns The aggregate coverage score (0-100)
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```ts
|
|
154
|
+
* import { calculateAggregateCoverage } from '@doccov/sdk';
|
|
155
|
+
*
|
|
156
|
+
* const coverage = calculateAggregateCoverage(spec);
|
|
157
|
+
* console.log(`Coverage: ${coverage}%`);
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
declare function calculateAggregateCoverage(spec: OpenPkgSpec): number;
|
|
161
|
+
/**
|
|
162
|
+
* Ensure a spec has a top-level docs.coverageScore.
|
|
163
|
+
*
|
|
164
|
+
* If the spec already has `docs.coverageScore`, returns the spec unchanged.
|
|
165
|
+
* Otherwise, calculates aggregate coverage from exports and returns a
|
|
166
|
+
* new spec with the coverage score added.
|
|
167
|
+
*
|
|
168
|
+
* This is useful for commands like `diff` that need coverage scores
|
|
169
|
+
* but may receive raw specs that haven't been enriched.
|
|
170
|
+
*
|
|
171
|
+
* @param spec - The OpenPkg spec to ensure coverage for
|
|
172
|
+
* @returns The spec with guaranteed top-level coverage score
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* import { ensureSpecCoverage } from '@doccov/sdk';
|
|
177
|
+
*
|
|
178
|
+
* // Works with raw or enriched specs
|
|
179
|
+
* const specWithCoverage = ensureSpecCoverage(rawSpec);
|
|
180
|
+
* console.log(specWithCoverage.docs?.coverageScore); // e.g., 85
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
declare function ensureSpecCoverage(spec: OpenPkgSpec): OpenPkgSpec & {
|
|
184
|
+
docs: {
|
|
185
|
+
coverageScore: number;
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
import { SpecDocDrift as SpecDocDrift4, SpecExport as SpecExport2 } from "@openpkg-ts/spec";
|
|
189
|
+
interface ExampleRunResult {
|
|
190
|
+
success: boolean;
|
|
191
|
+
stdout: string;
|
|
192
|
+
stderr: string;
|
|
193
|
+
exitCode: number;
|
|
194
|
+
duration: number;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Detect runtime errors in @example blocks.
|
|
198
|
+
* Results are provided externally after running examples via runExamples().
|
|
199
|
+
*/
|
|
200
|
+
declare function detectExampleRuntimeErrors(entry: SpecExport2, runtimeResults: Map<number, ExampleRunResult>): SpecDocDrift4[];
|
|
201
|
+
/**
|
|
202
|
+
* Parse assertion comments from example code.
|
|
203
|
+
* Matches: // => expected_value
|
|
204
|
+
*/
|
|
205
|
+
declare function parseAssertions(code: string): Array<{
|
|
206
|
+
lineNumber: number;
|
|
207
|
+
expected: string;
|
|
208
|
+
}>;
|
|
209
|
+
/**
|
|
210
|
+
* Check if code contains comments that are not assertion syntax.
|
|
211
|
+
* Used to determine if LLM fallback should be attempted.
|
|
212
|
+
*/
|
|
213
|
+
declare function hasNonAssertionComments(code: string): boolean;
|
|
214
|
+
/**
|
|
215
|
+
* Detect assertion failures by comparing stdout to expected values.
|
|
216
|
+
*/
|
|
217
|
+
declare function detectExampleAssertionFailures(entry: SpecExport2, runtimeResults: Map<number, ExampleRunResult>): SpecDocDrift4[];
|
|
218
|
+
import { OpenPkg as OpenPkg2, SpecDocDrift as SpecDocDrift8, SpecDocsMetadata, SpecExport as SpecExport7 } from "@openpkg-ts/spec";
|
|
219
|
+
/**
|
|
220
|
+
* An enriched with computed documentation metadata.
|
|
221
|
+
* Extends SpecExport with the `docs` field for coverage analysis.
|
|
222
|
+
*/
|
|
223
|
+
type EnrichedExport = SpecExport7 & {
|
|
224
|
+
docs?: EnrichedDocsMetadata;
|
|
225
|
+
};
|
|
226
|
+
/**
|
|
227
|
+
* Extended docs metadata.
|
|
228
|
+
*/
|
|
229
|
+
type EnrichedDocsMetadata = SpecDocsMetadata;
|
|
230
|
+
/**
|
|
231
|
+
* An enriched OpenPkg spec with computed documentation metadata.
|
|
232
|
+
* Extends OpenPkg with per-and aggregate coverage data.
|
|
233
|
+
*/
|
|
234
|
+
type EnrichedOpenPkg = Omit<OpenPkg2, "exports"> & {
|
|
235
|
+
exports: EnrichedExport[];
|
|
236
|
+
docs?: EnrichedDocsMetadata;
|
|
237
|
+
/** Drift summary with category breakdown (if drift exists) */
|
|
238
|
+
driftSummary?: DriftSummary;
|
|
239
|
+
};
|
|
240
|
+
interface EnrichOptions {
|
|
241
|
+
/**
|
|
242
|
+
* Per-drift issues to include in enrichment.
|
|
243
|
+
* Map from ID to drift issues.
|
|
244
|
+
*/
|
|
245
|
+
driftByExport?: Map<string, SpecDocDrift8[]>;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Enrich an OpenPkg spec with documentation coverage metadata.
|
|
249
|
+
*
|
|
250
|
+
* Computes coverage scores and detects drift issues.
|
|
251
|
+
*
|
|
252
|
+
* @param spec - The pure OpenPkg spec to enrich
|
|
253
|
+
* @param options - Optional enrichment configuration
|
|
254
|
+
* @returns An enriched spec with documentation metadata
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```ts
|
|
258
|
+
* import { DocCov, enrichSpec } from '@doccov/sdk';
|
|
259
|
+
*
|
|
260
|
+
* const doccov = new DocCov();
|
|
261
|
+
* const { spec } = await doccov.analyzeFileWithDiagnostics('src/index.ts');
|
|
262
|
+
*
|
|
263
|
+
* const enriched = enrichSpec(spec);
|
|
264
|
+
* console.log(enriched.docs?.coverageScore); // e.g., 85
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
declare function enrichSpec(spec: OpenPkg2, options?: EnrichOptions): EnrichedOpenPkg;
|
|
268
|
+
import { OpenPkg as OpenPkg3 } from "@openpkg-ts/spec";
|
|
269
|
+
/** Directory for storing history snapshots */
|
|
270
|
+
declare const HISTORY_DIR = ".doccov/history";
|
|
271
|
+
/**
|
|
272
|
+
* A historical coverage snapshot.
|
|
273
|
+
*/
|
|
274
|
+
interface CoverageSnapshot {
|
|
275
|
+
/** ISO 8601 timestamp */
|
|
276
|
+
timestamp: string;
|
|
277
|
+
/** Package name */
|
|
278
|
+
package: string;
|
|
279
|
+
/** Package version (if available) */
|
|
280
|
+
version?: string;
|
|
281
|
+
/** Coverage score (0-100) */
|
|
282
|
+
coverageScore: number;
|
|
283
|
+
/** Total number of exports */
|
|
284
|
+
totalExports: number;
|
|
285
|
+
/** Number of documented exports */
|
|
286
|
+
documentedExports: number;
|
|
287
|
+
/** Number of drift issues */
|
|
288
|
+
driftCount: number;
|
|
289
|
+
/** Git commit hash (if available) */
|
|
290
|
+
commit?: string;
|
|
291
|
+
/** Git branch (if available) */
|
|
292
|
+
branch?: string;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Coverage trend data.
|
|
296
|
+
*/
|
|
297
|
+
interface CoverageTrend {
|
|
298
|
+
/** Current snapshot */
|
|
299
|
+
current: CoverageSnapshot;
|
|
300
|
+
/** Previous snapshots (most recent first) */
|
|
301
|
+
history: CoverageSnapshot[];
|
|
302
|
+
/** Score delta from previous */
|
|
303
|
+
delta?: number;
|
|
304
|
+
/** Sparkline data (last N scores) */
|
|
305
|
+
sparkline: number[];
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Tier-based retention settings.
|
|
309
|
+
*/
|
|
310
|
+
type RetentionTier = "free" | "team" | "pro";
|
|
311
|
+
/**
|
|
312
|
+
* Retention days per tier.
|
|
313
|
+
*/
|
|
314
|
+
declare const RETENTION_DAYS: Record<RetentionTier, number>;
|
|
315
|
+
/**
|
|
316
|
+
* Weekly summary of coverage data.
|
|
317
|
+
*/
|
|
318
|
+
interface WeeklySummary {
|
|
319
|
+
/** Week start date (ISO string) */
|
|
320
|
+
weekStart: string;
|
|
321
|
+
/** Week end date (ISO string) */
|
|
322
|
+
weekEnd: string;
|
|
323
|
+
/** Average coverage for the week */
|
|
324
|
+
avgCoverage: number;
|
|
325
|
+
/** Coverage at start of week */
|
|
326
|
+
startCoverage: number;
|
|
327
|
+
/** Coverage at end of week */
|
|
328
|
+
endCoverage: number;
|
|
329
|
+
/** Change during the week */
|
|
330
|
+
delta: number;
|
|
331
|
+
/** Number of snapshots in the week */
|
|
332
|
+
snapshotCount: number;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Extended trend analysis result.
|
|
336
|
+
*/
|
|
337
|
+
interface ExtendedTrendAnalysis {
|
|
338
|
+
/** Current trend data */
|
|
339
|
+
trend: CoverageTrend;
|
|
340
|
+
/** Weekly summaries (most recent first) */
|
|
341
|
+
weeklySummaries: WeeklySummary[];
|
|
342
|
+
/** 7-day velocity (average daily change) */
|
|
343
|
+
velocity7d: number;
|
|
344
|
+
/** 30-day velocity */
|
|
345
|
+
velocity30d: number;
|
|
346
|
+
/** 90-day velocity (Pro only) */
|
|
347
|
+
velocity90d?: number;
|
|
348
|
+
/** Projected coverage in 30 days (based on velocity) */
|
|
349
|
+
projected30d: number;
|
|
350
|
+
/** Best coverage ever recorded */
|
|
351
|
+
allTimeHigh: number;
|
|
352
|
+
/** Worst coverage ever recorded */
|
|
353
|
+
allTimeLow: number;
|
|
354
|
+
/** Date range of available data */
|
|
355
|
+
dataRange: {
|
|
356
|
+
start: string;
|
|
357
|
+
end: string;
|
|
358
|
+
} | null;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Compute a coverage snapshot from an OpenPkg spec.
|
|
362
|
+
*/
|
|
363
|
+
declare function computeSnapshot(spec: OpenPkg3, options?: {
|
|
364
|
+
commit?: string;
|
|
365
|
+
branch?: string;
|
|
366
|
+
}): CoverageSnapshot;
|
|
367
|
+
/**
|
|
368
|
+
* Save a coverage snapshot to history.
|
|
369
|
+
*
|
|
370
|
+
* @param snapshot - The snapshot to save
|
|
371
|
+
* @param cwd - Working directory
|
|
372
|
+
*/
|
|
373
|
+
declare function saveSnapshot(snapshot: CoverageSnapshot, cwd: string): void;
|
|
374
|
+
/**
|
|
375
|
+
* Load all historical snapshots.
|
|
376
|
+
*
|
|
377
|
+
* @param cwd - Working directory
|
|
378
|
+
* @returns Array of snapshots sorted by timestamp (most recent first)
|
|
379
|
+
*/
|
|
380
|
+
declare function loadSnapshots(cwd: string): CoverageSnapshot[];
|
|
381
|
+
/**
|
|
382
|
+
* Get coverage trend data.
|
|
383
|
+
*
|
|
384
|
+
* @param spec - Current OpenPkg spec
|
|
385
|
+
* @param cwd - Working directory
|
|
386
|
+
* @param options - Optional git metadata
|
|
387
|
+
* @returns Trend data with history and delta
|
|
388
|
+
*/
|
|
389
|
+
declare function getTrend(spec: OpenPkg3, cwd: string, options?: {
|
|
390
|
+
commit?: string;
|
|
391
|
+
branch?: string;
|
|
392
|
+
}): CoverageTrend;
|
|
393
|
+
/**
|
|
394
|
+
* Generate a sparkline character representation.
|
|
395
|
+
*
|
|
396
|
+
* @param values - Array of values (0-100 for coverage)
|
|
397
|
+
* @returns Sparkline string using unicode characters
|
|
398
|
+
*/
|
|
399
|
+
declare function renderSparkline(values: number[]): string;
|
|
400
|
+
/**
|
|
401
|
+
* Format a delta value with arrow and color indicator.
|
|
402
|
+
*
|
|
403
|
+
* @param delta - Coverage delta (positive = improvement)
|
|
404
|
+
* @returns Formatted delta string
|
|
405
|
+
*/
|
|
406
|
+
declare function formatDelta(delta: number): string;
|
|
407
|
+
/**
|
|
408
|
+
* Prune old snapshots to keep history manageable.
|
|
409
|
+
*
|
|
410
|
+
* @param cwd - Working directory
|
|
411
|
+
* @param keepCount - Number of snapshots to keep (default: 100)
|
|
412
|
+
* @returns Number of snapshots deleted
|
|
413
|
+
*/
|
|
414
|
+
declare function pruneHistory(cwd: string, keepCount?: number): number;
|
|
415
|
+
/**
|
|
416
|
+
* Prune snapshots based on tier retention policy.
|
|
417
|
+
*
|
|
418
|
+
* @param cwd - Working directory
|
|
419
|
+
* @param tier - Retention tier (free: 7d, team: 30d, pro: 90d)
|
|
420
|
+
* @returns Number of snapshots deleted
|
|
421
|
+
*/
|
|
422
|
+
declare function pruneByTier(cwd: string, tier: RetentionTier): number;
|
|
423
|
+
/**
|
|
424
|
+
* Load snapshots within a date range.
|
|
425
|
+
*
|
|
426
|
+
* @param cwd - Working directory
|
|
427
|
+
* @param days - Number of days to include
|
|
428
|
+
* @returns Filtered snapshots
|
|
429
|
+
*/
|
|
430
|
+
declare function loadSnapshotsForDays(cwd: string, days: number): CoverageSnapshot[];
|
|
431
|
+
/**
|
|
432
|
+
* Generate weekly summaries from snapshots.
|
|
433
|
+
*
|
|
434
|
+
* @param snapshots - Snapshots to summarize (most recent first)
|
|
435
|
+
* @returns Weekly summaries (most recent first)
|
|
436
|
+
*/
|
|
437
|
+
declare function generateWeeklySummaries(snapshots: CoverageSnapshot[]): WeeklySummary[];
|
|
438
|
+
/**
|
|
439
|
+
* Get extended trend analysis with velocity and projections.
|
|
440
|
+
*
|
|
441
|
+
* @param spec - Current OpenPkg spec
|
|
442
|
+
* @param cwd - Working directory
|
|
443
|
+
* @param options - Analysis options
|
|
444
|
+
* @returns Extended trend analysis
|
|
445
|
+
*/
|
|
446
|
+
declare function getExtendedTrend(spec: OpenPkg3, cwd: string, options?: {
|
|
447
|
+
commit?: string;
|
|
448
|
+
branch?: string;
|
|
449
|
+
tier?: RetentionTier;
|
|
450
|
+
}): ExtendedTrendAnalysis;
|
|
451
|
+
import { OpenPkg as OpenPkg4 } from "@openpkg-ts/spec";
|
|
452
|
+
import { DriftCategory as DriftCategory3, SpecDocDrift as SpecDocDrift9 } from "@openpkg-ts/spec";
|
|
453
|
+
/**
|
|
454
|
+
* Drift summary with category breakdown.
|
|
455
|
+
*/
|
|
456
|
+
interface DriftReportSummary {
|
|
457
|
+
/**
|
|
458
|
+
* Total number of drift issues.
|
|
459
|
+
*/
|
|
460
|
+
total: number;
|
|
461
|
+
/**
|
|
462
|
+
* Count of issues per category.
|
|
463
|
+
*/
|
|
464
|
+
byCategory: Record<DriftCategory3, number>;
|
|
465
|
+
/**
|
|
466
|
+
* Number of auto-fixable issues.
|
|
467
|
+
*/
|
|
468
|
+
fixable: number;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Coverage summary for an entire package or project.
|
|
472
|
+
*/
|
|
473
|
+
interface CoverageSummary {
|
|
474
|
+
/**
|
|
475
|
+
* Overall coverage score (0-100).
|
|
476
|
+
*/
|
|
477
|
+
score: number;
|
|
478
|
+
/**
|
|
479
|
+
* Total number of exports analyzed.
|
|
480
|
+
*/
|
|
481
|
+
totalExports: number;
|
|
482
|
+
/**
|
|
483
|
+
* Number of fully documented exports.
|
|
484
|
+
*/
|
|
485
|
+
documentedExports: number;
|
|
486
|
+
/**
|
|
487
|
+
* Breakdown of missing documentation by rule ID.
|
|
488
|
+
*/
|
|
489
|
+
missingByRule: Record<string, number>;
|
|
490
|
+
/**
|
|
491
|
+
* Total number of drift issues detected.
|
|
492
|
+
*/
|
|
493
|
+
driftCount: number;
|
|
494
|
+
/**
|
|
495
|
+
* Drift summary with category breakdown.
|
|
496
|
+
*/
|
|
497
|
+
driftSummary?: DriftReportSummary;
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Coverage data for a single export.
|
|
501
|
+
*/
|
|
502
|
+
interface ExportCoverageData {
|
|
503
|
+
/**
|
|
504
|
+
* Export name.
|
|
505
|
+
*/
|
|
506
|
+
name: string;
|
|
507
|
+
/**
|
|
508
|
+
* Export kind (function, class, etc.).
|
|
509
|
+
*/
|
|
510
|
+
kind: string;
|
|
511
|
+
/**
|
|
512
|
+
* Coverage score for this (0-100).
|
|
513
|
+
*/
|
|
514
|
+
coverageScore: number;
|
|
515
|
+
/**
|
|
516
|
+
* Missing documentation rule IDs.
|
|
517
|
+
*/
|
|
518
|
+
missing?: string[];
|
|
519
|
+
/**
|
|
520
|
+
* Drift issues for this export.
|
|
521
|
+
*/
|
|
522
|
+
drift?: SpecDocDrift9[];
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* DocCov report - a persistable coverage analysis result.
|
|
526
|
+
*
|
|
527
|
+
* This is the format saved to `.doccov/report.json` and returned
|
|
528
|
+
* by the `check` command with `--format json`.
|
|
529
|
+
*/
|
|
530
|
+
interface DocCovReport {
|
|
531
|
+
/**
|
|
532
|
+
* JSON Schema reference for validation.
|
|
533
|
+
*/
|
|
534
|
+
$schema: string;
|
|
535
|
+
/**
|
|
536
|
+
* Report format version.
|
|
537
|
+
*/
|
|
538
|
+
version: string;
|
|
539
|
+
/**
|
|
540
|
+
* ISO 8601 timestamp when report was generated.
|
|
541
|
+
*/
|
|
542
|
+
generatedAt: string;
|
|
543
|
+
/**
|
|
544
|
+
* Package/project metadata.
|
|
545
|
+
*/
|
|
546
|
+
spec: {
|
|
547
|
+
name: string;
|
|
548
|
+
version?: string;
|
|
549
|
+
};
|
|
550
|
+
/**
|
|
551
|
+
* Aggregate coverage summary.
|
|
552
|
+
*/
|
|
553
|
+
coverage: CoverageSummary;
|
|
554
|
+
/**
|
|
555
|
+
* Per-coverage data, keyed by ID.
|
|
556
|
+
*/
|
|
557
|
+
exports: Record<string, ExportCoverageData>;
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* Generate a DocCov report from an OpenPkg spec.
|
|
561
|
+
*
|
|
562
|
+
* @param spec - The pure OpenPkg spec to analyze
|
|
563
|
+
* @returns A DocCov report with coverage analysis
|
|
564
|
+
*
|
|
565
|
+
* @example
|
|
566
|
+
* ```ts
|
|
567
|
+
* import { DocCov, generateReport } from '@doccov/sdk';
|
|
568
|
+
*
|
|
569
|
+
* const doccov = new DocCov();
|
|
570
|
+
* const { spec } = await doccov.analyzeFileWithDiagnostics('src/index.ts');
|
|
571
|
+
* const report = generateReport(spec);
|
|
572
|
+
*
|
|
573
|
+
* console.log(`Coverage: ${report.coverage.score}%`);
|
|
574
|
+
* ```
|
|
575
|
+
*/
|
|
576
|
+
declare function generateReport(spec: OpenPkg4): DocCovReport;
|
|
577
|
+
/**
|
|
578
|
+
* Generate a DocCov report from an already-enriched spec.
|
|
579
|
+
*
|
|
580
|
+
* Use this when you've already called enrichSpec() and want to avoid
|
|
581
|
+
* recomputing coverage data.
|
|
582
|
+
*
|
|
583
|
+
* @param enriched - The enriched OpenPkg spec
|
|
584
|
+
* @returns A DocCov report with coverage analysis
|
|
585
|
+
*/
|
|
586
|
+
declare function generateReportFromEnriched(enriched: EnrichedOpenPkg): DocCovReport;
|
|
587
|
+
/**
|
|
588
|
+
* Load a cached DocCov report from disk.
|
|
589
|
+
*
|
|
590
|
+
* @param reportPath - Path to the report file (defaults to .doccov/report.json)
|
|
591
|
+
* @returns The cached report, or null if not found
|
|
592
|
+
*/
|
|
593
|
+
declare function loadCachedReport(reportPath?: string): DocCovReport | null;
|
|
594
|
+
/**
|
|
595
|
+
* Save a DocCov report to disk.
|
|
596
|
+
*
|
|
597
|
+
* @param report - The report to save
|
|
598
|
+
* @param reportPath - Path to save the report (defaults to .doccov/report.json)
|
|
599
|
+
*/
|
|
600
|
+
declare function saveReport(report: DocCovReport, reportPath?: string): void;
|
|
601
|
+
/**
|
|
602
|
+
* Check if a cached report is still valid.
|
|
603
|
+
*
|
|
604
|
+
* A report is considered stale if:
|
|
605
|
+
* - It doesn't exist
|
|
606
|
+
* - The spec version has changed
|
|
607
|
+
* - Source files have been modified since generation
|
|
608
|
+
*
|
|
609
|
+
* @param reportPath - Path to the report file
|
|
610
|
+
* @param sourceFiles - Source files to check modification times against
|
|
611
|
+
* @returns True if the cached report is still valid
|
|
612
|
+
*/
|
|
613
|
+
declare function isCachedReportValid(reportPath?: string, sourceFiles?: string[]): boolean;
|
|
614
|
+
/**
|
|
615
|
+
* Generate a git-trackable API surface markdown file from an OpenPkg spec.
|
|
616
|
+
*
|
|
617
|
+
* This produces a deterministic, sorted output suitable for version control.
|
|
618
|
+
* Changes to the API will show up as diffs in this file.
|
|
619
|
+
*
|
|
620
|
+
* @param spec - The OpenPkg spec to render
|
|
621
|
+
* @returns Markdown string representing the API surface
|
|
622
|
+
*
|
|
623
|
+
* @example
|
|
624
|
+
* ```ts
|
|
625
|
+
* import { DocCov, renderApiSurface } from '@doccov/sdk';
|
|
626
|
+
*
|
|
627
|
+
* const doccov = new DocCov();
|
|
628
|
+
* const { spec } = await doccov.analyzeFileWithDiagnostics('src/index.ts');
|
|
629
|
+
* const apiSurface = renderApiSurface(spec);
|
|
630
|
+
*
|
|
631
|
+
* fs.writeFileSync('api-surface.md', apiSurface);
|
|
632
|
+
* ```
|
|
633
|
+
*/
|
|
634
|
+
declare function renderApiSurface(spec: OpenPkg4): string;
|
|
635
|
+
interface SchemaDetectionContext {
|
|
636
|
+
baseDir: string;
|
|
637
|
+
entryFile: string;
|
|
638
|
+
}
|
|
639
|
+
interface DetectedSchema {
|
|
640
|
+
schema: Record<string, unknown>;
|
|
641
|
+
vendor: string;
|
|
642
|
+
}
|
|
643
|
+
interface SchemaDetectionResult {
|
|
644
|
+
schemas: Map<string, DetectedSchema>;
|
|
645
|
+
errors: string[];
|
|
646
|
+
/** Warning when runtime was requested but compiled JS not found */
|
|
647
|
+
noCompiledJsWarning?: boolean;
|
|
648
|
+
}
|
|
649
|
+
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 };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HISTORY_DIR,
|
|
3
|
+
RETENTION_DAYS,
|
|
4
|
+
buildExportRegistry,
|
|
5
|
+
calculateAggregateCoverage,
|
|
6
|
+
categorizeDrift,
|
|
7
|
+
computeDrift,
|
|
8
|
+
computeExportDrift,
|
|
9
|
+
computeSnapshot,
|
|
10
|
+
detectExampleAssertionFailures,
|
|
11
|
+
detectExampleRuntimeErrors,
|
|
12
|
+
detectRuntimeSchemas,
|
|
13
|
+
enrichSpec,
|
|
14
|
+
ensureSpecCoverage,
|
|
15
|
+
formatDelta,
|
|
16
|
+
formatDriftSummaryLine,
|
|
17
|
+
generateReport,
|
|
18
|
+
generateReportFromEnriched,
|
|
19
|
+
generateWeeklySummaries,
|
|
20
|
+
getDriftSummary,
|
|
21
|
+
getExtendedTrend,
|
|
22
|
+
getTrend,
|
|
23
|
+
groupDriftsByCategory,
|
|
24
|
+
hasNonAssertionComments,
|
|
25
|
+
isCachedReportValid,
|
|
26
|
+
loadCachedReport,
|
|
27
|
+
loadSnapshots,
|
|
28
|
+
loadSnapshotsForDays,
|
|
29
|
+
parseAssertions,
|
|
30
|
+
pruneByTier,
|
|
31
|
+
pruneHistory,
|
|
32
|
+
renderApiSurface,
|
|
33
|
+
renderSparkline,
|
|
34
|
+
saveReport,
|
|
35
|
+
saveSnapshot
|
|
36
|
+
} from "../shared/chunk-nk2w5vws.js";
|
|
37
|
+
import"../shared/chunk-esptwrfq.js";
|
|
38
|
+
export {
|
|
39
|
+
saveSnapshot,
|
|
40
|
+
saveReport,
|
|
41
|
+
renderSparkline,
|
|
42
|
+
renderApiSurface,
|
|
43
|
+
pruneHistory,
|
|
44
|
+
pruneByTier,
|
|
45
|
+
parseAssertions,
|
|
46
|
+
loadSnapshotsForDays,
|
|
47
|
+
loadSnapshots,
|
|
48
|
+
loadCachedReport,
|
|
49
|
+
isCachedReportValid,
|
|
50
|
+
hasNonAssertionComments,
|
|
51
|
+
groupDriftsByCategory,
|
|
52
|
+
getTrend,
|
|
53
|
+
getExtendedTrend,
|
|
54
|
+
getDriftSummary,
|
|
55
|
+
generateWeeklySummaries,
|
|
56
|
+
generateReportFromEnriched,
|
|
57
|
+
generateReport,
|
|
58
|
+
formatDriftSummaryLine,
|
|
59
|
+
formatDelta,
|
|
60
|
+
ensureSpecCoverage,
|
|
61
|
+
enrichSpec,
|
|
62
|
+
detectRuntimeSchemas,
|
|
63
|
+
detectExampleRuntimeErrors,
|
|
64
|
+
detectExampleAssertionFailures,
|
|
65
|
+
computeSnapshot,
|
|
66
|
+
computeExportDrift,
|
|
67
|
+
computeDrift,
|
|
68
|
+
categorizeDrift,
|
|
69
|
+
calculateAggregateCoverage,
|
|
70
|
+
buildExportRegistry,
|
|
71
|
+
RETENTION_DAYS,
|
|
72
|
+
HISTORY_DIR
|
|
73
|
+
};
|