@openpkg-ts/spec 0.7.0 → 0.8.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>;
@@ -242,13 +265,23 @@ type OpenPkg = {
242
265
  exports: SpecExport[];
243
266
  types?: SpecType[];
244
267
  examples?: SpecExample[];
245
- docs?: SpecDocsMetadata;
246
268
  extensions?: SpecExtension;
247
269
  };
248
270
  declare const SCHEMA_VERSION: OpenPkgVersion;
249
271
  declare const SCHEMA_URL = "https://unpkg.com/@openpkg-ts/spec/schemas/v0.3.0/openpkg.schema.json";
250
272
  declare const JSON_SCHEMA_DRAFT = "https://json-schema.org/draft/2020-12/schema";
251
273
  declare function dereference(spec: OpenPkg): OpenPkg;
274
+ /**
275
+ * Export with optional docs metadata for diff comparison.
276
+ * Pure OpenPkg specs won't have docs; enriched specs will.
277
+ */
278
+ type ExportWithDocs = SpecExport & {
279
+ docs?: SpecDocsMetadata;
280
+ };
281
+ type SpecWithDocs = OpenPkg & {
282
+ docs?: SpecDocsMetadata;
283
+ exports: ExportWithDocs[];
284
+ };
252
285
  type BreakingSeverity = "high" | "medium" | "low";
253
286
  interface CategorizedBreaking {
254
287
  id: string;
@@ -277,7 +310,12 @@ type SpecDiff = {
277
310
  driftIntroduced: number;
278
311
  driftResolved: number;
279
312
  };
280
- declare function diffSpec(oldSpec: OpenPkg, newSpec: OpenPkg): SpecDiff;
313
+ /**
314
+ * Compare two OpenPkg specs and compute differences.
315
+ * If specs are enriched (have docs metadata), coverage changes are tracked.
316
+ * For pure structural specs, coverage fields will be 0.
317
+ */
318
+ declare function diffSpec(oldSpec: SpecWithDocs, newSpec: SpecWithDocs): SpecDiff;
281
319
  /**
282
320
  * Categorize breaking changes by severity
283
321
  *
@@ -287,7 +325,7 @@ declare function diffSpec(oldSpec: OpenPkg, newSpec: OpenPkg): SpecDiff;
287
325
  * @param memberChanges - Optional member-level changes for classes
288
326
  * @returns Categorized breaking changes sorted by severity (high first)
289
327
  */
290
- declare function categorizeBreakingChanges(breaking: string[], oldSpec: OpenPkg, newSpec: OpenPkg, memberChanges?: MemberChangeInfo[]): CategorizedBreaking[];
328
+ declare function categorizeBreakingChanges(breaking: string[], oldSpec: SpecWithDocs, newSpec: SpecWithDocs, memberChanges?: MemberChangeInfo[]): CategorizedBreaking[];
291
329
  declare function normalize(spec: OpenPkg): OpenPkg;
292
330
  /** Supported schema versions */
293
331
  type SchemaVersion = "0.1.0" | "0.2.0" | "0.3.0" | "latest";
@@ -325,4 +363,4 @@ declare function assertSpec(spec: unknown, version?: SchemaVersion): asserts spe
325
363
  * @returns Array of validation errors (empty if valid)
326
364
  */
327
365
  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 };
366
+ 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, SpecDocDrift, SpecDiff, SpecDecorator, SpecConditionalType, SCHEMA_VERSION, SCHEMA_URL, OpenPkgVersion, OpenPkgMeta, OpenPkg, MemberChangeInfo, JSON_SCHEMA_DRAFT, 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";
@@ -1841,5 +1868,8 @@ export {
1841
1868
  assertSpec,
1842
1869
  SCHEMA_VERSION,
1843
1870
  SCHEMA_URL,
1844
- JSON_SCHEMA_DRAFT
1871
+ JSON_SCHEMA_DRAFT,
1872
+ DRIFT_CATEGORY_LABELS,
1873
+ DRIFT_CATEGORY_DESCRIPTIONS,
1874
+ DRIFT_CATEGORIES
1845
1875
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpkg-ts/spec",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Shared schema, validation, and diff utilities for OpenPkg specs",
5
5
  "keywords": [
6
6
  "openpkg",