@doccov/spec 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.
@@ -0,0 +1,100 @@
1
+ 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";
2
+ type DriftCategory = "structural" | "semantic" | "example";
3
+ declare const DRIFT_CATEGORIES: Record<DriftType, DriftCategory>;
4
+ declare const DRIFT_CATEGORY_LABELS: Record<DriftCategory, string>;
5
+ declare const DRIFT_CATEGORY_DESCRIPTIONS: Record<DriftCategory, string>;
6
+ type DocCovDrift = {
7
+ type: DriftType;
8
+ target?: string;
9
+ issue: string;
10
+ suggestion?: string;
11
+ category: DriftCategory;
12
+ fixable: boolean;
13
+ };
14
+ type ExampleTypecheckError = {
15
+ exampleIndex: number;
16
+ line: number;
17
+ column: number;
18
+ message: string;
19
+ };
20
+ type ExampleRuntimeDrift = {
21
+ exampleIndex: number;
22
+ issue: string;
23
+ suggestion?: string;
24
+ };
25
+ type ExampleAnalysis = {
26
+ typecheckErrors?: ExampleTypecheckError[];
27
+ runtimeDrifts?: ExampleRuntimeDrift[];
28
+ };
29
+ type MissingDocRule = "description" | "params" | "returns" | "examples" | "throws";
30
+ type DocCovSpecVersion = "1.0.0";
31
+ type DocCovSpec = {
32
+ $schema?: string;
33
+ doccov: DocCovSpecVersion;
34
+ /** Reference to source openpkg spec */
35
+ source: {
36
+ file: string;
37
+ specVersion: string;
38
+ packageName: string;
39
+ packageVersion?: string;
40
+ };
41
+ generatedAt: string;
42
+ /** Aggregate coverage summary */
43
+ summary: DocCovSummary;
44
+ /** Per-analysis, keyed by openpkg ID */
45
+ exports: Record<string, ExportAnalysis>;
46
+ };
47
+ type DocCovSummary = {
48
+ /** Overall coverage score (0-100) */
49
+ score: number;
50
+ /** Total exports analyzed */
51
+ totalExports: number;
52
+ /** Exports with complete documentation */
53
+ documentedExports: number;
54
+ /** Missing documentation by rule */
55
+ missingByRule: Record<MissingDocRule, number>;
56
+ /** Drift summary */
57
+ drift: {
58
+ total: number;
59
+ fixable: number;
60
+ byCategory: Record<DriftCategory, number>;
61
+ };
62
+ /** Example validation summary (if run) */
63
+ examples?: {
64
+ total: number;
65
+ withExamples: number;
66
+ typecheckPassed?: number;
67
+ typecheckFailed?: number;
68
+ runtimePassed?: number;
69
+ runtimeFailed?: number;
70
+ };
71
+ };
72
+ type ExportAnalysis = {
73
+ /** Coverage score for this (0-100) */
74
+ coverageScore: number;
75
+ /** Missing documentation rules */
76
+ missing?: MissingDocRule[];
77
+ /** Drift issues */
78
+ drift?: DocCovDrift[];
79
+ /** Example validation results */
80
+ examples?: ExampleAnalysis;
81
+ };
82
+ declare const SCHEMA_VERSION = "1.0.0";
83
+ declare const SCHEMA_URL = "https://unpkg.com/@doccov/spec/schemas/v1.0.0/doccov.schema.json";
84
+ type DocCovSchemaVersion = "1.0.0" | "latest";
85
+ declare const LATEST_VERSION: DocCovSchemaVersion;
86
+ type DocCovSpecError = {
87
+ instancePath: string;
88
+ message: string;
89
+ keyword: string;
90
+ };
91
+ declare function validateDocCovSpec(spec: unknown, version?: DocCovSchemaVersion): {
92
+ ok: true;
93
+ } | {
94
+ ok: false;
95
+ errors: DocCovSpecError[];
96
+ };
97
+ declare function assertDocCovSpec(spec: unknown, version?: DocCovSchemaVersion): asserts spec is DocCovSpec;
98
+ declare function getDocCovValidationErrors(spec: unknown, version?: DocCovSchemaVersion): DocCovSpecError[];
99
+ declare function getAvailableDocCovVersions(): string[];
100
+ export { validateDocCovSpec, getDocCovValidationErrors, getAvailableDocCovVersions, assertDocCovSpec, SCHEMA_VERSION, SCHEMA_URL, MissingDocRule, LATEST_VERSION, ExportAnalysis, ExampleTypecheckError, ExampleRuntimeDrift, ExampleAnalysis, DriftType, DriftCategory, DocCovSummary, DocCovSpecVersion, DocCovSpecError, DocCovSpec, DocCovSchemaVersion, DocCovDrift, DRIFT_CATEGORY_LABELS, DRIFT_CATEGORY_DESCRIPTIONS, DRIFT_CATEGORIES };
package/dist/index.js ADDED
@@ -0,0 +1,259 @@
1
+ // src/types.ts
2
+ var DRIFT_CATEGORIES = {
3
+ "param-mismatch": "structural",
4
+ "param-type-mismatch": "structural",
5
+ "return-type-mismatch": "structural",
6
+ "optionality-mismatch": "structural",
7
+ "generic-constraint-mismatch": "structural",
8
+ "property-type-drift": "structural",
9
+ "async-mismatch": "structural",
10
+ "deprecated-mismatch": "semantic",
11
+ "visibility-mismatch": "semantic",
12
+ "broken-link": "semantic",
13
+ "example-drift": "example",
14
+ "example-syntax-error": "example",
15
+ "example-runtime-error": "example",
16
+ "example-assertion-failed": "example"
17
+ };
18
+ var DRIFT_CATEGORY_LABELS = {
19
+ structural: "Signature mismatches",
20
+ semantic: "Metadata issues",
21
+ example: "Example problems"
22
+ };
23
+ var DRIFT_CATEGORY_DESCRIPTIONS = {
24
+ structural: "JSDoc types or parameters don't match the actual code signature",
25
+ semantic: "Deprecation, visibility, or reference issues",
26
+ example: "@example code has errors or doesn't work correctly"
27
+ };
28
+ // src/constants.ts
29
+ var SCHEMA_VERSION = "1.0.0";
30
+ var SCHEMA_URL = "https://unpkg.com/@doccov/spec/schemas/v1.0.0/doccov.schema.json";
31
+ // src/validate.ts
32
+ import Ajv from "ajv/dist/2020.js";
33
+ import addFormats from "ajv-formats";
34
+ // schemas/v1.0.0/doccov.schema.json
35
+ var doccov_schema_default = {
36
+ $schema: "https://json-schema.org/draft/2020-12/schema",
37
+ $id: "https://unpkg.com/@doccov/spec/schemas/v1.0.0/doccov.schema.json",
38
+ title: "DocCov Specification",
39
+ description: "Documentation coverage analysis specification",
40
+ type: "object",
41
+ required: ["doccov", "source", "generatedAt", "summary", "exports"],
42
+ properties: {
43
+ $schema: { type: "string" },
44
+ doccov: { const: "1.0.0" },
45
+ source: { $ref: "#/$defs/source" },
46
+ generatedAt: { type: "string", format: "date-time" },
47
+ summary: { $ref: "#/$defs/summary" },
48
+ exports: {
49
+ type: "object",
50
+ additionalProperties: { $ref: "#/$defs/exportAnalysis" }
51
+ }
52
+ },
53
+ $defs: {
54
+ source: {
55
+ type: "object",
56
+ required: ["file", "specVersion", "packageName"],
57
+ properties: {
58
+ file: { type: "string" },
59
+ specVersion: { type: "string" },
60
+ packageName: { type: "string" },
61
+ packageVersion: { type: "string" }
62
+ }
63
+ },
64
+ driftType: {
65
+ type: "string",
66
+ enum: [
67
+ "param-mismatch",
68
+ "param-type-mismatch",
69
+ "return-type-mismatch",
70
+ "generic-constraint-mismatch",
71
+ "optionality-mismatch",
72
+ "deprecated-mismatch",
73
+ "visibility-mismatch",
74
+ "async-mismatch",
75
+ "property-type-drift",
76
+ "example-drift",
77
+ "example-syntax-error",
78
+ "example-runtime-error",
79
+ "example-assertion-failed",
80
+ "broken-link"
81
+ ]
82
+ },
83
+ driftCategory: {
84
+ type: "string",
85
+ enum: ["structural", "semantic", "example"]
86
+ },
87
+ missingDocRule: {
88
+ type: "string",
89
+ enum: ["description", "params", "returns", "examples", "throws"]
90
+ },
91
+ drift: {
92
+ type: "object",
93
+ required: ["type", "issue", "category", "fixable"],
94
+ properties: {
95
+ type: { $ref: "#/$defs/driftType" },
96
+ target: { type: "string" },
97
+ issue: { type: "string" },
98
+ suggestion: { type: "string" },
99
+ category: { $ref: "#/$defs/driftCategory" },
100
+ fixable: { type: "boolean" }
101
+ }
102
+ },
103
+ summary: {
104
+ type: "object",
105
+ required: ["score", "totalExports", "documentedExports", "missingByRule", "drift"],
106
+ properties: {
107
+ score: { type: "number", minimum: 0, maximum: 100 },
108
+ totalExports: { type: "integer", minimum: 0 },
109
+ documentedExports: { type: "integer", minimum: 0 },
110
+ missingByRule: {
111
+ type: "object",
112
+ additionalProperties: { type: "integer", minimum: 0 }
113
+ },
114
+ drift: {
115
+ type: "object",
116
+ required: ["total", "fixable", "byCategory"],
117
+ properties: {
118
+ total: { type: "integer", minimum: 0 },
119
+ fixable: { type: "integer", minimum: 0 },
120
+ byCategory: {
121
+ type: "object",
122
+ additionalProperties: { type: "integer", minimum: 0 }
123
+ }
124
+ }
125
+ },
126
+ examples: {
127
+ type: "object",
128
+ properties: {
129
+ total: { type: "integer", minimum: 0 },
130
+ withExamples: { type: "integer", minimum: 0 },
131
+ typecheckPassed: { type: "integer", minimum: 0 },
132
+ typecheckFailed: { type: "integer", minimum: 0 },
133
+ runtimePassed: { type: "integer", minimum: 0 },
134
+ runtimeFailed: { type: "integer", minimum: 0 }
135
+ }
136
+ }
137
+ }
138
+ },
139
+ exampleTypecheckError: {
140
+ type: "object",
141
+ required: ["exampleIndex", "line", "column", "message"],
142
+ properties: {
143
+ exampleIndex: { type: "integer", minimum: 0 },
144
+ line: { type: "integer", minimum: 0 },
145
+ column: { type: "integer", minimum: 0 },
146
+ message: { type: "string" }
147
+ }
148
+ },
149
+ exampleRuntimeDrift: {
150
+ type: "object",
151
+ required: ["exampleIndex", "issue"],
152
+ properties: {
153
+ exampleIndex: { type: "integer", minimum: 0 },
154
+ issue: { type: "string" },
155
+ suggestion: { type: "string" }
156
+ }
157
+ },
158
+ exampleAnalysis: {
159
+ type: "object",
160
+ properties: {
161
+ typecheckErrors: {
162
+ type: "array",
163
+ items: { $ref: "#/$defs/exampleTypecheckError" }
164
+ },
165
+ runtimeDrifts: {
166
+ type: "array",
167
+ items: { $ref: "#/$defs/exampleRuntimeDrift" }
168
+ }
169
+ }
170
+ },
171
+ exportAnalysis: {
172
+ type: "object",
173
+ required: ["coverageScore"],
174
+ properties: {
175
+ coverageScore: { type: "number", minimum: 0, maximum: 100 },
176
+ missing: {
177
+ type: "array",
178
+ items: { $ref: "#/$defs/missingDocRule" }
179
+ },
180
+ drift: {
181
+ type: "array",
182
+ items: { $ref: "#/$defs/drift" }
183
+ },
184
+ examples: { $ref: "#/$defs/exampleAnalysis" }
185
+ }
186
+ }
187
+ }
188
+ };
189
+
190
+ // src/validate.ts
191
+ var LATEST_VERSION = "1.0.0";
192
+ var schemas = {
193
+ "1.0.0": doccov_schema_default
194
+ };
195
+ var ajv = new Ajv({
196
+ strict: false,
197
+ allErrors: true,
198
+ allowUnionTypes: true
199
+ });
200
+ addFormats(ajv);
201
+ var validatorCache = new Map;
202
+ function getValidator(version = "latest") {
203
+ const resolvedVersion = version === "latest" ? LATEST_VERSION : version;
204
+ let validator = validatorCache.get(resolvedVersion);
205
+ if (validator) {
206
+ return validator;
207
+ }
208
+ const schema = schemas[resolvedVersion];
209
+ if (!schema) {
210
+ throw new Error(`Unknown schema version: ${resolvedVersion}. Available: ${Object.keys(schemas).join(", ")}`);
211
+ }
212
+ validator = ajv.compile(schema);
213
+ validatorCache.set(resolvedVersion, validator);
214
+ return validator;
215
+ }
216
+ function validateDocCovSpec(spec, version = "latest") {
217
+ const validate = getValidator(version);
218
+ const ok = validate(spec);
219
+ if (ok) {
220
+ return { ok: true };
221
+ }
222
+ const errors = (validate.errors ?? []).map((error) => ({
223
+ instancePath: error.instancePath ?? "",
224
+ message: error.message ?? "invalid",
225
+ keyword: error.keyword ?? "unknown"
226
+ }));
227
+ return {
228
+ ok: false,
229
+ errors
230
+ };
231
+ }
232
+ function assertDocCovSpec(spec, version = "latest") {
233
+ const result = validateDocCovSpec(spec, version);
234
+ if (!result.ok) {
235
+ const details = result.errors.map((error) => `- ${error.instancePath || "/"} ${error.message}`).join(`
236
+ `);
237
+ throw new Error(`Invalid DocCovSpec:
238
+ ${details}`);
239
+ }
240
+ }
241
+ function getDocCovValidationErrors(spec, version = "latest") {
242
+ const result = validateDocCovSpec(spec, version);
243
+ return result.ok ? [] : result.errors;
244
+ }
245
+ function getAvailableDocCovVersions() {
246
+ return Object.keys(schemas);
247
+ }
248
+ export {
249
+ validateDocCovSpec,
250
+ getDocCovValidationErrors,
251
+ getAvailableDocCovVersions,
252
+ assertDocCovSpec,
253
+ SCHEMA_VERSION,
254
+ SCHEMA_URL,
255
+ LATEST_VERSION,
256
+ DRIFT_CATEGORY_LABELS,
257
+ DRIFT_CATEGORY_DESCRIPTIONS,
258
+ DRIFT_CATEGORIES
259
+ };
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@doccov/spec",
3
+ "version": "0.24.0",
4
+ "description": "DocCov specification schema, types, and validation",
5
+ "keywords": [
6
+ "doccov",
7
+ "documentation",
8
+ "coverage",
9
+ "json-schema",
10
+ "validation",
11
+ "typescript"
12
+ ],
13
+ "homepage": "https://github.com/doccov/doccov#readme",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/doccov/doccov.git",
17
+ "directory": "packages/doccov-spec"
18
+ },
19
+ "license": "MIT",
20
+ "author": "Ryan Waits",
21
+ "type": "module",
22
+ "main": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "import": "./dist/index.js",
27
+ "types": "./dist/index.d.ts"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "schemas"
33
+ ],
34
+ "scripts": {
35
+ "build": "bunup",
36
+ "dev": "bunup --watch",
37
+ "lint": "biome check src/",
38
+ "lint:fix": "biome check --write src/",
39
+ "format": "biome format --write src/"
40
+ },
41
+ "dependencies": {
42
+ "ajv": "^8.17.1",
43
+ "ajv-formats": "^3.0.1"
44
+ },
45
+ "devDependencies": {
46
+ "@types/bun": "latest",
47
+ "@types/node": "^20.0.0",
48
+ "bunup": "latest",
49
+ "typescript": "^5.0.0"
50
+ },
51
+ "publishConfig": {
52
+ "access": "public"
53
+ }
54
+ }
@@ -0,0 +1,154 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://unpkg.com/@doccov/spec/schemas/v1.0.0/doccov.schema.json",
4
+ "title": "DocCov Specification",
5
+ "description": "Documentation coverage analysis specification",
6
+ "type": "object",
7
+ "required": ["doccov", "source", "generatedAt", "summary", "exports"],
8
+ "properties": {
9
+ "$schema": { "type": "string" },
10
+ "doccov": { "const": "1.0.0" },
11
+ "source": { "$ref": "#/$defs/source" },
12
+ "generatedAt": { "type": "string", "format": "date-time" },
13
+ "summary": { "$ref": "#/$defs/summary" },
14
+ "exports": {
15
+ "type": "object",
16
+ "additionalProperties": { "$ref": "#/$defs/exportAnalysis" }
17
+ }
18
+ },
19
+ "$defs": {
20
+ "source": {
21
+ "type": "object",
22
+ "required": ["file", "specVersion", "packageName"],
23
+ "properties": {
24
+ "file": { "type": "string" },
25
+ "specVersion": { "type": "string" },
26
+ "packageName": { "type": "string" },
27
+ "packageVersion": { "type": "string" }
28
+ }
29
+ },
30
+ "driftType": {
31
+ "type": "string",
32
+ "enum": [
33
+ "param-mismatch",
34
+ "param-type-mismatch",
35
+ "return-type-mismatch",
36
+ "generic-constraint-mismatch",
37
+ "optionality-mismatch",
38
+ "deprecated-mismatch",
39
+ "visibility-mismatch",
40
+ "async-mismatch",
41
+ "property-type-drift",
42
+ "example-drift",
43
+ "example-syntax-error",
44
+ "example-runtime-error",
45
+ "example-assertion-failed",
46
+ "broken-link"
47
+ ]
48
+ },
49
+ "driftCategory": {
50
+ "type": "string",
51
+ "enum": ["structural", "semantic", "example"]
52
+ },
53
+ "missingDocRule": {
54
+ "type": "string",
55
+ "enum": ["description", "params", "returns", "examples", "throws"]
56
+ },
57
+ "drift": {
58
+ "type": "object",
59
+ "required": ["type", "issue", "category", "fixable"],
60
+ "properties": {
61
+ "type": { "$ref": "#/$defs/driftType" },
62
+ "target": { "type": "string" },
63
+ "issue": { "type": "string" },
64
+ "suggestion": { "type": "string" },
65
+ "category": { "$ref": "#/$defs/driftCategory" },
66
+ "fixable": { "type": "boolean" }
67
+ }
68
+ },
69
+ "summary": {
70
+ "type": "object",
71
+ "required": ["score", "totalExports", "documentedExports", "missingByRule", "drift"],
72
+ "properties": {
73
+ "score": { "type": "number", "minimum": 0, "maximum": 100 },
74
+ "totalExports": { "type": "integer", "minimum": 0 },
75
+ "documentedExports": { "type": "integer", "minimum": 0 },
76
+ "missingByRule": {
77
+ "type": "object",
78
+ "additionalProperties": { "type": "integer", "minimum": 0 }
79
+ },
80
+ "drift": {
81
+ "type": "object",
82
+ "required": ["total", "fixable", "byCategory"],
83
+ "properties": {
84
+ "total": { "type": "integer", "minimum": 0 },
85
+ "fixable": { "type": "integer", "minimum": 0 },
86
+ "byCategory": {
87
+ "type": "object",
88
+ "additionalProperties": { "type": "integer", "minimum": 0 }
89
+ }
90
+ }
91
+ },
92
+ "examples": {
93
+ "type": "object",
94
+ "properties": {
95
+ "total": { "type": "integer", "minimum": 0 },
96
+ "withExamples": { "type": "integer", "minimum": 0 },
97
+ "typecheckPassed": { "type": "integer", "minimum": 0 },
98
+ "typecheckFailed": { "type": "integer", "minimum": 0 },
99
+ "runtimePassed": { "type": "integer", "minimum": 0 },
100
+ "runtimeFailed": { "type": "integer", "minimum": 0 }
101
+ }
102
+ }
103
+ }
104
+ },
105
+ "exampleTypecheckError": {
106
+ "type": "object",
107
+ "required": ["exampleIndex", "line", "column", "message"],
108
+ "properties": {
109
+ "exampleIndex": { "type": "integer", "minimum": 0 },
110
+ "line": { "type": "integer", "minimum": 0 },
111
+ "column": { "type": "integer", "minimum": 0 },
112
+ "message": { "type": "string" }
113
+ }
114
+ },
115
+ "exampleRuntimeDrift": {
116
+ "type": "object",
117
+ "required": ["exampleIndex", "issue"],
118
+ "properties": {
119
+ "exampleIndex": { "type": "integer", "minimum": 0 },
120
+ "issue": { "type": "string" },
121
+ "suggestion": { "type": "string" }
122
+ }
123
+ },
124
+ "exampleAnalysis": {
125
+ "type": "object",
126
+ "properties": {
127
+ "typecheckErrors": {
128
+ "type": "array",
129
+ "items": { "$ref": "#/$defs/exampleTypecheckError" }
130
+ },
131
+ "runtimeDrifts": {
132
+ "type": "array",
133
+ "items": { "$ref": "#/$defs/exampleRuntimeDrift" }
134
+ }
135
+ }
136
+ },
137
+ "exportAnalysis": {
138
+ "type": "object",
139
+ "required": ["coverageScore"],
140
+ "properties": {
141
+ "coverageScore": { "type": "number", "minimum": 0, "maximum": 100 },
142
+ "missing": {
143
+ "type": "array",
144
+ "items": { "$ref": "#/$defs/missingDocRule" }
145
+ },
146
+ "drift": {
147
+ "type": "array",
148
+ "items": { "$ref": "#/$defs/drift" }
149
+ },
150
+ "examples": { "$ref": "#/$defs/exampleAnalysis" }
151
+ }
152
+ }
153
+ }
154
+ }