@openpkg-ts/spec 0.7.0 → 0.9.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/index.d.ts CHANGED
@@ -116,17 +116,41 @@ type SpecRelation = {
116
116
  description?: string;
117
117
  };
118
118
  type SpecExtension = Record<string, unknown>;
119
- type SpecDocSignal = "description" | "params" | "returns" | "examples";
119
+ /**
120
+ * All possible drift type identifiers.
121
+ */
122
+ 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";
120
123
  type SpecDocDrift = {
121
- type: "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";
124
+ type: DriftType;
122
125
  target?: string;
123
126
  issue: string;
124
127
  suggestion?: string;
125
128
  };
129
+ /**
130
+ * Drift categories group related drift types for progressive disclosure.
131
+ *
132
+ * - `structural`: Signature/type mismatches (mostly auto-fixable via JSDoc)
133
+ * - `semantic`: Metadata/visibility/reference issues
134
+ * - `example`: Code example problems
135
+ */
136
+ type DriftCategory = "structural" | "semantic" | "example";
137
+ /**
138
+ * Maps each drift type to its category.
139
+ */
140
+ declare const DRIFT_CATEGORIES: Record<DriftType, DriftCategory>;
141
+ /**
142
+ * Human-readable category labels.
143
+ */
144
+ declare const DRIFT_CATEGORY_LABELS: Record<DriftCategory, string>;
145
+ /**
146
+ * Category descriptions for help text.
147
+ */
148
+ declare const DRIFT_CATEGORY_DESCRIPTIONS: Record<DriftCategory, string>;
126
149
  type SpecVisibility = "public" | "protected" | "private";
127
150
  type SpecDocsMetadata = {
128
151
  coverageScore?: number;
129
- missing?: SpecDocSignal[];
152
+ /** Rule IDs that failed quality checks */
153
+ missing?: string[];
130
154
  drift?: SpecDocDrift[];
131
155
  };
132
156
  type SpecTypeParameter = {
@@ -187,7 +211,6 @@ type SpecExport = {
187
211
  schema?: SpecSchema;
188
212
  description?: string;
189
213
  examples?: (string | SpecExample)[];
190
- docs?: SpecDocsMetadata;
191
214
  source?: SpecSource;
192
215
  deprecated?: boolean;
193
216
  flags?: Record<string, unknown>;
@@ -233,6 +256,70 @@ type OpenPkgMeta = {
233
256
  repository?: string;
234
257
  ecosystem?: string;
235
258
  };
259
+ /**
260
+ * Method used to detect the entry point for analysis.
261
+ */
262
+ type EntryPointDetectionMethod = "types" | "exports" | "main" | "module" | "fallback" | "explicit" | "llm";
263
+ /**
264
+ * Severity level for issues encountered during spec generation.
265
+ */
266
+ type GenerationIssueSeverity = "error" | "warning" | "info";
267
+ /**
268
+ * An issue encountered during spec generation.
269
+ */
270
+ type GenerationIssue = {
271
+ /** Machine-readable issue code */
272
+ code: string;
273
+ /** Human-readable issue message */
274
+ message: string;
275
+ /** Severity level */
276
+ severity: GenerationIssueSeverity;
277
+ /** Suggested resolution */
278
+ suggestion?: string;
279
+ };
280
+ /**
281
+ * Metadata about how a spec was generated.
282
+ * Provides transparency about the analysis process and any limitations.
283
+ */
284
+ type SpecGenerationInfo = {
285
+ /** ISO 8601 timestamp of when the spec was generated */
286
+ timestamp: string;
287
+ /** Information about the tool that generated the spec */
288
+ generator: {
289
+ /** Tool name (e.g., '@doccov/cli', '@doccov/api') */
290
+ name: string;
291
+ /** Tool version */
292
+ version: string;
293
+ };
294
+ /** Details about the analysis process */
295
+ analysis: {
296
+ /** Entry point file that was analyzed (relative path) */
297
+ entryPoint: string;
298
+ /** How the entry point was detected */
299
+ entryPointSource: EntryPointDetectionMethod;
300
+ /** Whether this was a declaration-only analysis (.d.ts file) */
301
+ isDeclarationOnly: boolean;
302
+ /** Whether external types from node_modules were resolved */
303
+ resolvedExternalTypes: boolean;
304
+ /** Maximum type depth used for nested type resolution */
305
+ maxTypeDepth?: number;
306
+ };
307
+ /** Environment information during generation */
308
+ environment: {
309
+ /** Detected package manager */
310
+ packageManager?: string;
311
+ /** Whether node_modules was available for type resolution */
312
+ hasNodeModules: boolean;
313
+ /** Whether this is a monorepo */
314
+ isMonorepo?: boolean;
315
+ /** Target package name (for monorepos) */
316
+ targetPackage?: string;
317
+ };
318
+ /** Issues encountered during generation */
319
+ issues: GenerationIssue[];
320
+ /** Whether the result came from cache */
321
+ fromCache?: boolean;
322
+ };
236
323
  /** Supported OpenPkg spec versions */
237
324
  type OpenPkgVersion = "0.2.0" | "0.3.0";
238
325
  type OpenPkg = {
@@ -242,13 +329,25 @@ type OpenPkg = {
242
329
  exports: SpecExport[];
243
330
  types?: SpecType[];
244
331
  examples?: SpecExample[];
245
- docs?: SpecDocsMetadata;
246
332
  extensions?: SpecExtension;
333
+ /** Required metadata about how this spec was generated */
334
+ generation: SpecGenerationInfo;
247
335
  };
248
336
  declare const SCHEMA_VERSION: OpenPkgVersion;
249
337
  declare const SCHEMA_URL = "https://unpkg.com/@openpkg-ts/spec/schemas/v0.3.0/openpkg.schema.json";
250
338
  declare const JSON_SCHEMA_DRAFT = "https://json-schema.org/draft/2020-12/schema";
251
339
  declare function dereference(spec: OpenPkg): OpenPkg;
340
+ /**
341
+ * Export with optional docs metadata for diff comparison.
342
+ * Pure OpenPkg specs won't have docs; enriched specs will.
343
+ */
344
+ type ExportWithDocs = SpecExport & {
345
+ docs?: SpecDocsMetadata;
346
+ };
347
+ type SpecWithDocs = OpenPkg & {
348
+ docs?: SpecDocsMetadata;
349
+ exports: ExportWithDocs[];
350
+ };
252
351
  type BreakingSeverity = "high" | "medium" | "low";
253
352
  interface CategorizedBreaking {
254
353
  id: string;
@@ -277,7 +376,12 @@ type SpecDiff = {
277
376
  driftIntroduced: number;
278
377
  driftResolved: number;
279
378
  };
280
- declare function diffSpec(oldSpec: OpenPkg, newSpec: OpenPkg): SpecDiff;
379
+ /**
380
+ * Compare two OpenPkg specs and compute differences.
381
+ * If specs are enriched (have docs metadata), coverage changes are tracked.
382
+ * For pure structural specs, coverage fields will be 0.
383
+ */
384
+ declare function diffSpec(oldSpec: SpecWithDocs, newSpec: SpecWithDocs): SpecDiff;
281
385
  /**
282
386
  * Categorize breaking changes by severity
283
387
  *
@@ -287,7 +391,7 @@ declare function diffSpec(oldSpec: OpenPkg, newSpec: OpenPkg): SpecDiff;
287
391
  * @param memberChanges - Optional member-level changes for classes
288
392
  * @returns Categorized breaking changes sorted by severity (high first)
289
393
  */
290
- declare function categorizeBreakingChanges(breaking: string[], oldSpec: OpenPkg, newSpec: OpenPkg, memberChanges?: MemberChangeInfo[]): CategorizedBreaking[];
394
+ declare function categorizeBreakingChanges(breaking: string[], oldSpec: SpecWithDocs, newSpec: SpecWithDocs, memberChanges?: MemberChangeInfo[]): CategorizedBreaking[];
291
395
  declare function normalize(spec: OpenPkg): OpenPkg;
292
396
  /** Supported schema versions */
293
397
  type SchemaVersion = "0.1.0" | "0.2.0" | "0.3.0" | "latest";
@@ -325,4 +429,4 @@ declare function assertSpec(spec: unknown, version?: SchemaVersion): asserts spe
325
429
  * @returns Array of validation errors (empty if valid)
326
430
  */
327
431
  declare function getValidationErrors(spec: unknown, version?: SchemaVersion): SpecError[];
328
- export { validateSpec, normalize, getValidationErrors, diffSpec, dereference, categorizeBreakingChanges, assertSpec, SpecVisibility, SpecTypeParameter, SpecTypeKind, SpecTypeAliasKind, SpecType, SpecThrows, SpecTag, SpecSource, SpecSignatureReturn, SpecSignatureParameter, SpecSignature, SpecSchemaRef, SpecSchemaPrimitive, SpecSchemaGeneric, SpecSchemaFallback, SpecSchemaComposite, SpecSchemaCombinator, SpecSchema, SpecRelationType, SpecRelation, SpecMember, SpecMappedType, SpecExtension, SpecExportKind, SpecExport, SpecExampleLanguage, SpecExample, SpecDocsMetadata, SpecDocSignal, SpecDocDrift, SpecDiff, SpecDecorator, SpecConditionalType, SCHEMA_VERSION, SCHEMA_URL, OpenPkgVersion, OpenPkgMeta, OpenPkg, MemberChangeInfo, JSON_SCHEMA_DRAFT, CategorizedBreaking, BreakingSeverity };
432
+ export { validateSpec, normalize, getValidationErrors, diffSpec, dereference, categorizeBreakingChanges, assertSpec, SpecVisibility, SpecTypeParameter, SpecTypeKind, SpecTypeAliasKind, SpecType, SpecThrows, SpecTag, SpecSource, SpecSignatureReturn, SpecSignatureParameter, SpecSignature, SpecSchemaRef, SpecSchemaPrimitive, SpecSchemaGeneric, SpecSchemaFallback, SpecSchemaComposite, SpecSchemaCombinator, SpecSchema, SpecRelationType, SpecRelation, SpecMember, SpecMappedType, SpecGenerationInfo, SpecExtension, SpecExportKind, SpecExport, SpecExampleLanguage, SpecExample, SpecDocsMetadata, SpecDocDrift, SpecDiff, SpecDecorator, SpecConditionalType, SCHEMA_VERSION, SCHEMA_URL, OpenPkgVersion, OpenPkgMeta, OpenPkg, MemberChangeInfo, JSON_SCHEMA_DRAFT, GenerationIssueSeverity, GenerationIssue, EntryPointDetectionMethod, DriftType, DriftCategory, DRIFT_CATEGORY_LABELS, DRIFT_CATEGORY_DESCRIPTIONS, DRIFT_CATEGORIES, CategorizedBreaking, BreakingSeverity };
package/dist/index.js CHANGED
@@ -318,6 +318,33 @@ function normalizeType(item) {
318
318
  }
319
319
  return clone;
320
320
  }
321
+ // src/types.ts
322
+ var DRIFT_CATEGORIES = {
323
+ "param-mismatch": "structural",
324
+ "param-type-mismatch": "structural",
325
+ "return-type-mismatch": "structural",
326
+ "optionality-mismatch": "structural",
327
+ "generic-constraint-mismatch": "structural",
328
+ "property-type-drift": "structural",
329
+ "async-mismatch": "structural",
330
+ "deprecated-mismatch": "semantic",
331
+ "visibility-mismatch": "semantic",
332
+ "broken-link": "semantic",
333
+ "example-drift": "example",
334
+ "example-syntax-error": "example",
335
+ "example-runtime-error": "example",
336
+ "example-assertion-failed": "example"
337
+ };
338
+ var DRIFT_CATEGORY_LABELS = {
339
+ structural: "Signature mismatches",
340
+ semantic: "Metadata issues",
341
+ example: "Example problems"
342
+ };
343
+ var DRIFT_CATEGORY_DESCRIPTIONS = {
344
+ structural: "JSDoc types or parameters don't match the actual code signature",
345
+ semantic: "Deprecation, visibility, or reference issues",
346
+ example: "@example code has errors or doesn't work correctly"
347
+ };
321
348
  // src/validate.ts
322
349
  import Ajv from "ajv/dist/2020.js";
323
350
  import addFormats from "ajv-formats";
@@ -1056,7 +1083,7 @@ var openpkg_schema_default3 = {
1056
1083
  title: "OpenPkg Specification",
1057
1084
  description: "Schema for OpenPkg specification files",
1058
1085
  type: "object",
1059
- required: ["openpkg", "meta", "exports"],
1086
+ required: ["openpkg", "meta", "exports", "generation"],
1060
1087
  properties: {
1061
1088
  $schema: {
1062
1089
  type: "string",
@@ -1117,9 +1144,137 @@ var openpkg_schema_default3 = {
1117
1144
  docs: {
1118
1145
  $ref: "#/$defs/docsMetadata",
1119
1146
  description: "Aggregate documentation coverage metadata"
1147
+ },
1148
+ generation: {
1149
+ $ref: "#/$defs/generationInfo",
1150
+ description: "Required metadata about how this spec was generated"
1120
1151
  }
1121
1152
  },
1122
1153
  $defs: {
1154
+ entryPointDetectionMethod: {
1155
+ type: "string",
1156
+ description: "Method used to detect the entry point for analysis",
1157
+ enum: ["types", "exports", "main", "module", "fallback", "explicit", "llm"]
1158
+ },
1159
+ generationIssueSeverity: {
1160
+ type: "string",
1161
+ description: "Severity level for issues encountered during spec generation",
1162
+ enum: ["error", "warning", "info"]
1163
+ },
1164
+ generationIssue: {
1165
+ type: "object",
1166
+ description: "An issue encountered during spec generation",
1167
+ required: ["code", "message", "severity"],
1168
+ properties: {
1169
+ code: {
1170
+ type: "string",
1171
+ description: "Machine-readable issue code"
1172
+ },
1173
+ message: {
1174
+ type: "string",
1175
+ description: "Human-readable issue message"
1176
+ },
1177
+ severity: {
1178
+ $ref: "#/$defs/generationIssueSeverity"
1179
+ },
1180
+ suggestion: {
1181
+ type: "string",
1182
+ description: "Suggested resolution"
1183
+ }
1184
+ },
1185
+ additionalProperties: false
1186
+ },
1187
+ generationInfo: {
1188
+ type: "object",
1189
+ description: "Metadata about how the spec was generated",
1190
+ required: ["timestamp", "generator", "analysis", "environment", "issues"],
1191
+ properties: {
1192
+ timestamp: {
1193
+ type: "string",
1194
+ format: "date-time",
1195
+ description: "ISO 8601 timestamp of when the spec was generated"
1196
+ },
1197
+ generator: {
1198
+ type: "object",
1199
+ description: "Information about the tool that generated the spec",
1200
+ required: ["name", "version"],
1201
+ properties: {
1202
+ name: {
1203
+ type: "string",
1204
+ description: "Tool name (e.g., '@doccov/cli', '@doccov/api')"
1205
+ },
1206
+ version: {
1207
+ type: "string",
1208
+ description: "Tool version"
1209
+ }
1210
+ },
1211
+ additionalProperties: false
1212
+ },
1213
+ analysis: {
1214
+ type: "object",
1215
+ description: "Details about the analysis process",
1216
+ required: ["entryPoint", "entryPointSource", "isDeclarationOnly", "resolvedExternalTypes"],
1217
+ properties: {
1218
+ entryPoint: {
1219
+ type: "string",
1220
+ description: "Entry point file that was analyzed (relative path)"
1221
+ },
1222
+ entryPointSource: {
1223
+ $ref: "#/$defs/entryPointDetectionMethod"
1224
+ },
1225
+ isDeclarationOnly: {
1226
+ type: "boolean",
1227
+ description: "Whether this was a declaration-only analysis (.d.ts file)"
1228
+ },
1229
+ resolvedExternalTypes: {
1230
+ type: "boolean",
1231
+ description: "Whether external types from node_modules were resolved"
1232
+ },
1233
+ maxTypeDepth: {
1234
+ type: "integer",
1235
+ description: "Maximum type depth used for nested type resolution"
1236
+ }
1237
+ },
1238
+ additionalProperties: false
1239
+ },
1240
+ environment: {
1241
+ type: "object",
1242
+ description: "Environment information during generation",
1243
+ required: ["hasNodeModules"],
1244
+ properties: {
1245
+ packageManager: {
1246
+ type: "string",
1247
+ description: "Detected package manager"
1248
+ },
1249
+ hasNodeModules: {
1250
+ type: "boolean",
1251
+ description: "Whether node_modules was available for type resolution"
1252
+ },
1253
+ isMonorepo: {
1254
+ type: "boolean",
1255
+ description: "Whether this is a monorepo"
1256
+ },
1257
+ targetPackage: {
1258
+ type: "string",
1259
+ description: "Target package name (for monorepos)"
1260
+ }
1261
+ },
1262
+ additionalProperties: false
1263
+ },
1264
+ issues: {
1265
+ type: "array",
1266
+ description: "Issues encountered during generation",
1267
+ items: {
1268
+ $ref: "#/$defs/generationIssue"
1269
+ }
1270
+ },
1271
+ fromCache: {
1272
+ type: "boolean",
1273
+ description: "Whether the result came from cache"
1274
+ }
1275
+ },
1276
+ additionalProperties: false
1277
+ },
1123
1278
  docSignal: {
1124
1279
  type: "string",
1125
1280
  enum: ["description", "params", "returns", "examples"]
@@ -1841,5 +1996,8 @@ export {
1841
1996
  assertSpec,
1842
1997
  SCHEMA_VERSION,
1843
1998
  SCHEMA_URL,
1844
- JSON_SCHEMA_DRAFT
1999
+ JSON_SCHEMA_DRAFT,
2000
+ DRIFT_CATEGORY_LABELS,
2001
+ DRIFT_CATEGORY_DESCRIPTIONS,
2002
+ DRIFT_CATEGORIES
1845
2003
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpkg-ts/spec",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "Shared schema, validation, and diff utilities for OpenPkg specs",
5
5
  "keywords": [
6
6
  "openpkg",
@@ -4,7 +4,7 @@
4
4
  "title": "OpenPkg Specification",
5
5
  "description": "Schema for OpenPkg specification files",
6
6
  "type": "object",
7
- "required": ["openpkg", "meta", "exports"],
7
+ "required": ["openpkg", "meta", "exports", "generation"],
8
8
  "properties": {
9
9
  "$schema": {
10
10
  "type": "string",
@@ -65,9 +65,137 @@
65
65
  "docs": {
66
66
  "$ref": "#/$defs/docsMetadata",
67
67
  "description": "Aggregate documentation coverage metadata"
68
+ },
69
+ "generation": {
70
+ "$ref": "#/$defs/generationInfo",
71
+ "description": "Required metadata about how this spec was generated"
68
72
  }
69
73
  },
70
74
  "$defs": {
75
+ "entryPointDetectionMethod": {
76
+ "type": "string",
77
+ "description": "Method used to detect the entry point for analysis",
78
+ "enum": ["types", "exports", "main", "module", "fallback", "explicit", "llm"]
79
+ },
80
+ "generationIssueSeverity": {
81
+ "type": "string",
82
+ "description": "Severity level for issues encountered during spec generation",
83
+ "enum": ["error", "warning", "info"]
84
+ },
85
+ "generationIssue": {
86
+ "type": "object",
87
+ "description": "An issue encountered during spec generation",
88
+ "required": ["code", "message", "severity"],
89
+ "properties": {
90
+ "code": {
91
+ "type": "string",
92
+ "description": "Machine-readable issue code"
93
+ },
94
+ "message": {
95
+ "type": "string",
96
+ "description": "Human-readable issue message"
97
+ },
98
+ "severity": {
99
+ "$ref": "#/$defs/generationIssueSeverity"
100
+ },
101
+ "suggestion": {
102
+ "type": "string",
103
+ "description": "Suggested resolution"
104
+ }
105
+ },
106
+ "additionalProperties": false
107
+ },
108
+ "generationInfo": {
109
+ "type": "object",
110
+ "description": "Metadata about how the spec was generated",
111
+ "required": ["timestamp", "generator", "analysis", "environment", "issues"],
112
+ "properties": {
113
+ "timestamp": {
114
+ "type": "string",
115
+ "format": "date-time",
116
+ "description": "ISO 8601 timestamp of when the spec was generated"
117
+ },
118
+ "generator": {
119
+ "type": "object",
120
+ "description": "Information about the tool that generated the spec",
121
+ "required": ["name", "version"],
122
+ "properties": {
123
+ "name": {
124
+ "type": "string",
125
+ "description": "Tool name (e.g., '@doccov/cli', '@doccov/api')"
126
+ },
127
+ "version": {
128
+ "type": "string",
129
+ "description": "Tool version"
130
+ }
131
+ },
132
+ "additionalProperties": false
133
+ },
134
+ "analysis": {
135
+ "type": "object",
136
+ "description": "Details about the analysis process",
137
+ "required": ["entryPoint", "entryPointSource", "isDeclarationOnly", "resolvedExternalTypes"],
138
+ "properties": {
139
+ "entryPoint": {
140
+ "type": "string",
141
+ "description": "Entry point file that was analyzed (relative path)"
142
+ },
143
+ "entryPointSource": {
144
+ "$ref": "#/$defs/entryPointDetectionMethod"
145
+ },
146
+ "isDeclarationOnly": {
147
+ "type": "boolean",
148
+ "description": "Whether this was a declaration-only analysis (.d.ts file)"
149
+ },
150
+ "resolvedExternalTypes": {
151
+ "type": "boolean",
152
+ "description": "Whether external types from node_modules were resolved"
153
+ },
154
+ "maxTypeDepth": {
155
+ "type": "integer",
156
+ "description": "Maximum type depth used for nested type resolution"
157
+ }
158
+ },
159
+ "additionalProperties": false
160
+ },
161
+ "environment": {
162
+ "type": "object",
163
+ "description": "Environment information during generation",
164
+ "required": ["hasNodeModules"],
165
+ "properties": {
166
+ "packageManager": {
167
+ "type": "string",
168
+ "description": "Detected package manager"
169
+ },
170
+ "hasNodeModules": {
171
+ "type": "boolean",
172
+ "description": "Whether node_modules was available for type resolution"
173
+ },
174
+ "isMonorepo": {
175
+ "type": "boolean",
176
+ "description": "Whether this is a monorepo"
177
+ },
178
+ "targetPackage": {
179
+ "type": "string",
180
+ "description": "Target package name (for monorepos)"
181
+ }
182
+ },
183
+ "additionalProperties": false
184
+ },
185
+ "issues": {
186
+ "type": "array",
187
+ "description": "Issues encountered during generation",
188
+ "items": {
189
+ "$ref": "#/$defs/generationIssue"
190
+ }
191
+ },
192
+ "fromCache": {
193
+ "type": "boolean",
194
+ "description": "Whether the result came from cache"
195
+ }
196
+ },
197
+ "additionalProperties": false
198
+ },
71
199
  "docSignal": {
72
200
  "type": "string",
73
201
  "enum": ["description", "params", "returns", "examples"]