@openpkg-ts/spec 0.2.2 → 0.3.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/README.md CHANGED
@@ -1,33 +1,43 @@
1
1
  # @openpkg-ts/spec
2
2
 
3
- Canonical schema, TypeScript types, validation, normalization, deref, diff, and migration helpers for OpenPkg specs.
3
+ OpenPkg schema, types, validation, and diffing utilities.
4
4
 
5
5
  ## Install
6
+
6
7
  ```bash
7
8
  npm install @openpkg-ts/spec
8
9
  ```
9
10
 
10
- ## Quick Helpers
11
- ```ts
12
- import { normalize, validateSpec } from '@openpkg-ts/spec';
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { validateSpec, normalize, diffSpec } from '@openpkg-ts/spec';
13
15
 
14
- const normalized = normalize(spec);
15
- const result = validateSpec(normalized);
16
+ // Validate
17
+ const result = validateSpec(normalize(spec));
16
18
  if (!result.ok) {
17
- throw new Error(result.errors.map((e) => `${e.instancePath || '/'} ${e.message}`).join('\n'));
19
+ console.error(result.errors);
18
20
  }
21
+
22
+ // Diff two specs
23
+ const diff = diffSpec(oldSpec, newSpec);
24
+ console.log(`Coverage delta: ${diff.coverageDelta}%`);
19
25
  ```
20
26
 
21
- ```ts
22
- import { dereference, diffSpec } from '@openpkg-ts/spec';
27
+ ## Exports
23
28
 
24
- const left = dereference(specA);
25
- const right = dereference(specB);
26
- const diff = diffSpec(left, right);
27
- ```
29
+ - `validateSpec` / `assertSpec` - Schema validation
30
+ - `normalize` - Ensure consistent structure
31
+ - `dereference` - Resolve `$ref` pointers
32
+ - `diffSpec` - Compare specs
33
+
34
+ ## Documentation
35
+
36
+ - [Spec Overview](../../docs/spec/overview.md)
37
+ - [Types Reference](../../docs/spec/types.md)
38
+ - [Drift Types](../../docs/spec/drift-types.md)
39
+ - [Diffing](../../docs/spec/diffing.md)
28
40
 
29
- ## See Also
30
- - [SDK generator](../sdk/README.md)
31
- - [CLI usage](../cli/README.md)
41
+ ## License
32
42
 
33
- MIT License
43
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpkg-ts/spec",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Shared schema, validation, and diff utilities for OpenPkg specs",
5
5
  "keywords": [
6
6
  "openpkg",
@@ -86,7 +86,12 @@
86
86
  "optionality-mismatch",
87
87
  "deprecated-mismatch",
88
88
  "visibility-mismatch",
89
+ "async-mismatch",
90
+ "property-type-drift",
89
91
  "example-drift",
92
+ "example-syntax-error",
93
+ "example-runtime-error",
94
+ "example-assertion-failed",
90
95
  "broken-link"
91
96
  ]
92
97
  },
@@ -153,6 +158,10 @@
153
158
  "type": "string",
154
159
  "description": "UI-friendly label"
155
160
  },
161
+ "alias": {
162
+ "type": "string",
163
+ "description": "Export alias if re-exported with a different name (id uses alias, name uses original)"
164
+ },
156
165
  "category": {
157
166
  "type": "string",
158
167
  "description": "Grouping hint for navigation"
@@ -164,7 +173,7 @@
164
173
  "kind": {
165
174
  "type": "string",
166
175
  "description": "Kind of export",
167
- "enum": ["function", "class", "variable", "interface", "type", "enum"]
176
+ "enum": ["function", "class", "variable", "interface", "type", "enum", "namespace", "external"]
168
177
  },
169
178
  "description": {
170
179
  "type": "string",
@@ -193,6 +202,15 @@
193
202
  "description": "Class/interface/enum members",
194
203
  "items": { "type": "object" }
195
204
  },
205
+ "extends": {
206
+ "type": "string",
207
+ "description": "Base class or interface that this class/interface extends"
208
+ },
209
+ "implements": {
210
+ "type": "array",
211
+ "description": "Interfaces implemented by this class",
212
+ "items": { "type": "string" }
213
+ },
196
214
  "tags": {
197
215
  "type": "array",
198
216
  "description": "JSDoc/TSDoc tags",
@@ -235,6 +253,10 @@
235
253
  "type": "string",
236
254
  "description": "UI-friendly label"
237
255
  },
256
+ "alias": {
257
+ "type": "string",
258
+ "description": "Export alias if re-exported with a different name (id uses alias, name uses original)"
259
+ },
238
260
  "category": {
239
261
  "type": "string",
240
262
  "description": "Grouping hint for navigation"
@@ -246,7 +268,7 @@
246
268
  "kind": {
247
269
  "type": "string",
248
270
  "description": "Kind of type definition",
249
- "enum": ["interface", "type", "enum", "class"]
271
+ "enum": ["interface", "type", "enum", "class", "external"]
250
272
  },
251
273
  "description": {
252
274
  "type": "string",
@@ -264,6 +286,15 @@
264
286
  "description": "Members for classes/interfaces/enums",
265
287
  "items": { "type": "object" }
266
288
  },
289
+ "extends": {
290
+ "type": "string",
291
+ "description": "Base class or interface that this class/interface extends"
292
+ },
293
+ "implements": {
294
+ "type": "array",
295
+ "description": "Interfaces implemented by this class",
296
+ "items": { "type": "string" }
297
+ },
267
298
  "tags": {
268
299
  "type": "array",
269
300
  "description": "JSDoc/TSDoc tags",
@@ -318,6 +349,13 @@
318
349
  "description": {
319
350
  "type": "string",
320
351
  "description": "Parameter description"
352
+ },
353
+ "default": {
354
+ "description": "Default value for the parameter"
355
+ },
356
+ "rest": {
357
+ "type": "boolean",
358
+ "description": "Whether this is a rest parameter (...args)"
321
359
  }
322
360
  }
323
361
  },
package/dist/index.d.ts DELETED
@@ -1,148 +0,0 @@
1
- declare const SCHEMA_VERSION = "0.2.0";
2
- declare const SCHEMA_URL = "https://unpkg.com/@openpkg-ts/spec/schemas/v0.2.0/openpkg.schema.json";
3
- declare const JSON_SCHEMA_DRAFT = "https://json-schema.org/draft/2020-12/schema";
4
- type SpecTag = {
5
- name: string;
6
- text: string;
7
- };
8
- type SpecSource = {
9
- file?: string;
10
- line?: number;
11
- url?: string;
12
- };
13
- type SpecSchema = unknown;
14
- type SpecExample = Record<string, unknown>;
15
- type SpecExtension = Record<string, unknown>;
16
- type SpecDocSignal = "description" | "params" | "returns" | "examples";
17
- type SpecDocDrift = {
18
- type: "param-mismatch" | "param-type-mismatch" | "return-type-mismatch" | "generic-constraint-mismatch" | "optionality-mismatch" | "deprecated-mismatch" | "visibility-mismatch" | "example-drift" | "broken-link";
19
- target?: string;
20
- issue: string;
21
- suggestion?: string;
22
- };
23
- type SpecVisibility = "public" | "protected" | "private";
24
- type SpecDocsMetadata = {
25
- coverageScore?: number;
26
- missing?: SpecDocSignal[];
27
- drift?: SpecDocDrift[];
28
- };
29
- type SpecTypeParameter = {
30
- name: string;
31
- constraint?: string;
32
- default?: string;
33
- };
34
- type SpecSignatureParameter = {
35
- name: string;
36
- required?: boolean;
37
- description?: string;
38
- schema: SpecSchema;
39
- };
40
- type SpecSignatureReturn = {
41
- schema: SpecSchema;
42
- description?: string;
43
- tsType?: string;
44
- };
45
- type SpecSignature = {
46
- parameters?: SpecSignatureParameter[];
47
- returns?: SpecSignatureReturn;
48
- description?: string;
49
- typeParameters?: SpecTypeParameter[];
50
- };
51
- type SpecMember = {
52
- id?: string;
53
- name?: string;
54
- kind?: string;
55
- description?: string;
56
- tags?: SpecTag[];
57
- visibility?: SpecVisibility;
58
- flags?: Record<string, unknown>;
59
- schema?: SpecSchema;
60
- signatures?: SpecSignature[];
61
- };
62
- type SpecExportKind = "function" | "class" | "variable" | "interface" | "type" | "enum" | "module" | "namespace" | "reference";
63
- type SpecTypeKind = "class" | "interface" | "type" | "enum";
64
- type SpecExport = {
65
- id: string;
66
- name: string;
67
- slug?: string;
68
- displayName?: string;
69
- category?: string;
70
- importPath?: string;
71
- kind: SpecExportKind;
72
- signatures?: SpecSignature[];
73
- typeParameters?: SpecTypeParameter[];
74
- members?: SpecMember[];
75
- type?: string | SpecSchema;
76
- schema?: SpecSchema;
77
- description?: string;
78
- examples?: string[];
79
- docs?: SpecDocsMetadata;
80
- source?: SpecSource;
81
- deprecated?: boolean;
82
- flags?: Record<string, unknown>;
83
- tags?: SpecTag[];
84
- };
85
- type SpecType = {
86
- id: string;
87
- name: string;
88
- slug?: string;
89
- displayName?: string;
90
- category?: string;
91
- importPath?: string;
92
- kind: SpecTypeKind;
93
- description?: string;
94
- schema?: SpecSchema;
95
- type?: string | SpecSchema;
96
- members?: SpecMember[];
97
- source?: SpecSource;
98
- tags?: SpecTag[];
99
- rawComments?: string;
100
- };
101
- type OpenPkgMeta = {
102
- name: string;
103
- version?: string;
104
- description?: string;
105
- license?: string;
106
- repository?: string;
107
- ecosystem?: string;
108
- };
109
- type OpenPkg = {
110
- $schema?: string;
111
- openpkg: "0.2.0";
112
- meta: OpenPkgMeta;
113
- exports: SpecExport[];
114
- types?: SpecType[];
115
- examples?: SpecExample[];
116
- docs?: SpecDocsMetadata;
117
- extensions?: SpecExtension;
118
- };
119
- declare function dereference(spec: OpenPkg): OpenPkg;
120
- type SpecDiff = {
121
- breaking: string[];
122
- nonBreaking: string[];
123
- docsOnly: string[];
124
- coverageDelta: number;
125
- oldCoverage: number;
126
- newCoverage: number;
127
- newUndocumented: string[];
128
- improvedExports: string[];
129
- regressedExports: string[];
130
- driftIntroduced: number;
131
- driftResolved: number;
132
- };
133
- declare function diffSpec(oldSpec: OpenPkg, newSpec: OpenPkg): SpecDiff;
134
- declare function normalize(spec: OpenPkg): OpenPkg;
135
- type SpecError = {
136
- instancePath: string;
137
- message: string;
138
- keyword: string;
139
- };
140
- declare function validateSpec(spec: unknown): {
141
- ok: true;
142
- } | {
143
- ok: false;
144
- errors: SpecError[];
145
- };
146
- declare function assertSpec(spec: unknown): asserts spec is OpenPkg;
147
- declare function getValidationErrors(spec: unknown): SpecError[];
148
- export { validateSpec, normalize, getValidationErrors, diffSpec, dereference, assertSpec, SpecVisibility, SpecTypeParameter, SpecTypeKind, SpecType, SpecTag, SpecSource, SpecSignatureReturn, SpecSignatureParameter, SpecSignature, SpecSchema, SpecMember, SpecExtension, SpecExportKind, SpecExport, SpecExample, SpecDocsMetadata, SpecDocSignal, SpecDocDrift, SCHEMA_VERSION, SCHEMA_URL, OpenPkgMeta, OpenPkg, JSON_SCHEMA_DRAFT };
package/dist/index.js DELETED
@@ -1,673 +0,0 @@
1
- // src/constants.ts
2
- var SCHEMA_VERSION = "0.2.0";
3
- var SCHEMA_URL = "https://unpkg.com/@openpkg-ts/spec/schemas/v0.2.0/openpkg.schema.json";
4
- var JSON_SCHEMA_DRAFT = "https://json-schema.org/draft/2020-12/schema";
5
- // src/deref.ts
6
- function dereference(spec) {
7
- const clone = JSON.parse(JSON.stringify(spec));
8
- const typeLookup = buildTypeLookup(clone.types);
9
- const visit = (value, seen) => {
10
- if (Array.isArray(value)) {
11
- return value.map((item) => visit(item, new Set(seen)));
12
- }
13
- if (value && typeof value === "object") {
14
- const record = value;
15
- const ref = readTypeRef(record);
16
- if (ref) {
17
- return resolveTypeRef(ref, typeLookup, seen);
18
- }
19
- const next = {};
20
- for (const [key, nested] of Object.entries(record)) {
21
- next[key] = visit(nested, seen);
22
- }
23
- return next;
24
- }
25
- return value;
26
- };
27
- clone.exports = clone.exports.map((item) => visit(item, new Set));
28
- if (clone.types) {
29
- clone.types = clone.types.map((item) => visit(item, new Set));
30
- }
31
- return clone;
32
- }
33
- function buildTypeLookup(types) {
34
- const map = new Map;
35
- if (!Array.isArray(types)) {
36
- return map;
37
- }
38
- for (const type of types) {
39
- if (type && typeof type.id === "string") {
40
- map.set(type.id, type);
41
- }
42
- }
43
- return map;
44
- }
45
- function readTypeRef(value) {
46
- const ref = value.$ref;
47
- if (typeof ref !== "string") {
48
- return null;
49
- }
50
- const prefix = "#/types/";
51
- if (!ref.startsWith(prefix)) {
52
- return null;
53
- }
54
- return ref.slice(prefix.length);
55
- }
56
- function resolveTypeRef(id, lookup, seen) {
57
- if (seen.has(id)) {
58
- return { $ref: `#/types/${id}` };
59
- }
60
- const target = lookup.get(id);
61
- if (!target) {
62
- return { $ref: `#/types/${id}` };
63
- }
64
- seen.add(id);
65
- if (target.schema) {
66
- return JSON.parse(JSON.stringify(target.schema));
67
- }
68
- return JSON.parse(JSON.stringify(target));
69
- }
70
- // src/diff.ts
71
- function diffSpec(oldSpec, newSpec) {
72
- const result = {
73
- breaking: [],
74
- nonBreaking: [],
75
- docsOnly: [],
76
- coverageDelta: 0,
77
- oldCoverage: 0,
78
- newCoverage: 0,
79
- newUndocumented: [],
80
- improvedExports: [],
81
- regressedExports: [],
82
- driftIntroduced: 0,
83
- driftResolved: 0
84
- };
85
- diffCollections(result, oldSpec.exports, newSpec.exports);
86
- diffCollections(result, oldSpec.types ?? [], newSpec.types ?? []);
87
- result.oldCoverage = oldSpec.docs?.coverageScore ?? 0;
88
- result.newCoverage = newSpec.docs?.coverageScore ?? 0;
89
- result.coverageDelta = Math.round((result.newCoverage - result.oldCoverage) * 10) / 10;
90
- const oldExportMap = toExportMap(oldSpec.exports);
91
- const newExportMap = toExportMap(newSpec.exports);
92
- for (const [id, newExport] of newExportMap.entries()) {
93
- const oldExport = oldExportMap.get(id);
94
- const newScore = newExport.docs?.coverageScore ?? 0;
95
- const newDriftCount = newExport.docs?.drift?.length ?? 0;
96
- if (!oldExport) {
97
- if (newScore < 100 || (newExport.docs?.missing?.length ?? 0) > 0) {
98
- result.newUndocumented.push(id);
99
- }
100
- result.driftIntroduced += newDriftCount;
101
- continue;
102
- }
103
- const oldScore = oldExport.docs?.coverageScore ?? 0;
104
- const oldDriftCount = oldExport.docs?.drift?.length ?? 0;
105
- if (newScore > oldScore) {
106
- result.improvedExports.push(id);
107
- } else if (newScore < oldScore) {
108
- result.regressedExports.push(id);
109
- }
110
- if (newDriftCount > oldDriftCount) {
111
- result.driftIntroduced += newDriftCount - oldDriftCount;
112
- } else if (oldDriftCount > newDriftCount) {
113
- result.driftResolved += oldDriftCount - newDriftCount;
114
- }
115
- }
116
- return result;
117
- }
118
- function toExportMap(exports) {
119
- const map = new Map;
120
- for (const exp of exports) {
121
- if (exp && typeof exp.id === "string") {
122
- map.set(exp.id, exp);
123
- }
124
- }
125
- return map;
126
- }
127
- function diffCollections(result, oldItems, newItems) {
128
- const oldMap = toMap(oldItems);
129
- const newMap = toMap(newItems);
130
- for (const [id, oldItem] of oldMap.entries()) {
131
- const newItem = newMap.get(id);
132
- if (!newItem) {
133
- result.breaking.push(id);
134
- continue;
135
- }
136
- const docOnly = isDocOnlyChange(oldItem, newItem);
137
- const identical = isDeepEqual(oldItem, newItem);
138
- if (identical) {
139
- continue;
140
- }
141
- if (docOnly) {
142
- result.docsOnly.push(id);
143
- continue;
144
- }
145
- result.breaking.push(id);
146
- }
147
- for (const id of newMap.keys()) {
148
- if (!oldMap.has(id)) {
149
- result.nonBreaking.push(id);
150
- }
151
- }
152
- }
153
- function toMap(items) {
154
- const map = new Map;
155
- for (const item of items) {
156
- if (item && typeof item.id === "string") {
157
- map.set(item.id, item);
158
- }
159
- }
160
- return map;
161
- }
162
- var DOC_KEYS = new Set(["description", "examples", "tags", "source", "rawComments"]);
163
- function isDocOnlyChange(a, b) {
164
- const structuralA = normalizeForComparison(removeDocFields(a));
165
- const structuralB = normalizeForComparison(removeDocFields(b));
166
- if (structuralA !== structuralB) {
167
- return false;
168
- }
169
- const fullA = normalizeForComparison(a);
170
- const fullB = normalizeForComparison(b);
171
- return fullA !== fullB;
172
- }
173
- function isDeepEqual(a, b) {
174
- return normalizeForComparison(a) === normalizeForComparison(b);
175
- }
176
- function removeDocFields(value) {
177
- if (Array.isArray(value)) {
178
- return value.map((item) => removeDocFields(item));
179
- }
180
- if (!value || typeof value !== "object") {
181
- return value;
182
- }
183
- const entries = Object.entries(value).filter(([key]) => !DOC_KEYS.has(key));
184
- const cleaned = {};
185
- for (const [key, val] of entries) {
186
- cleaned[key] = removeDocFields(val);
187
- }
188
- return cleaned;
189
- }
190
- function normalizeForComparison(value) {
191
- return JSON.stringify(sortKeys(value));
192
- }
193
- function sortKeys(value) {
194
- if (Array.isArray(value)) {
195
- return value.map((item) => sortKeys(item));
196
- }
197
- if (!value || typeof value !== "object") {
198
- return value;
199
- }
200
- const entries = Object.entries(value).sort(([a], [b]) => a.localeCompare(b));
201
- const result = {};
202
- for (const [key, val] of entries) {
203
- result[key] = sortKeys(val);
204
- }
205
- return result;
206
- }
207
- // src/normalize.ts
208
- var DEFAULT_ECOSYSTEM = "js/ts";
209
- var arrayFieldsByExport = ["signatures", "members", "examples", "tags"];
210
- var arrayFieldsByType = ["members", "tags"];
211
- function normalize(spec) {
212
- const normalized = JSON.parse(JSON.stringify(spec));
213
- normalized.meta = {
214
- ecosystem: normalized.meta?.ecosystem ?? DEFAULT_ECOSYSTEM,
215
- ...normalized.meta
216
- };
217
- normalized.exports = Array.isArray(normalized.exports) ? [...normalized.exports] : [];
218
- normalized.exports.sort((a, b) => (a.name || "").localeCompare(b.name || ""));
219
- normalized.exports = normalized.exports.map((item) => normalizeExport(item));
220
- const types = Array.isArray(normalized.types) ? [...normalized.types] : [];
221
- types.sort((a, b) => (a.name || "").localeCompare(b.name || ""));
222
- normalized.types = types.map((item) => normalizeType(item));
223
- return normalized;
224
- }
225
- function normalizeExport(item) {
226
- const clone = JSON.parse(JSON.stringify(item));
227
- for (const field of arrayFieldsByExport) {
228
- if (!Array.isArray(clone[field])) {
229
- clone[field] = [];
230
- }
231
- }
232
- return clone;
233
- }
234
- function normalizeType(item) {
235
- const clone = JSON.parse(JSON.stringify(item));
236
- for (const field of arrayFieldsByType) {
237
- if (!Array.isArray(clone[field])) {
238
- clone[field] = [];
239
- }
240
- }
241
- return clone;
242
- }
243
- // src/validate.ts
244
- import Ajv from "ajv/dist/2020.js";
245
- import addFormats from "ajv-formats";
246
- // schemas/v0.2.0/openpkg.schema.json
247
- var openpkg_schema_default = {
248
- $schema: "https://json-schema.org/draft/2020-12/schema",
249
- $id: "https://unpkg.com/@openpkg-ts/spec/schemas/v0.2.0/openpkg.schema.json",
250
- title: "OpenPkg Specification",
251
- description: "Schema for OpenPkg specification files",
252
- type: "object",
253
- required: ["openpkg", "meta", "exports"],
254
- properties: {
255
- $schema: {
256
- type: "string",
257
- description: "Reference to the OpenPkg schema version",
258
- pattern: "^(https://raw\\.githubusercontent\\.com/ryanwaits/openpkg/main/schemas/v[0-9]+\\.[0-9]+\\.[0-9]+/openpkg\\.schema\\.json|https://unpkg\\.com/@openpkg-ts/spec/schemas/v[0-9]+\\.[0-9]+\\.[0-9]+/openpkg\\.schema\\.json)$"
259
- },
260
- openpkg: {
261
- type: "string",
262
- description: "OpenPkg specification version",
263
- pattern: "^[0-9]+\\.[0-9]+\\.[0-9]+$",
264
- const: "0.2.0"
265
- },
266
- meta: {
267
- type: "object",
268
- description: "Package metadata",
269
- required: ["name"],
270
- properties: {
271
- name: {
272
- type: "string",
273
- description: "Package name"
274
- },
275
- version: {
276
- type: "string",
277
- description: "Package version"
278
- },
279
- description: {
280
- type: "string",
281
- description: "Package description"
282
- },
283
- license: {
284
- type: "string",
285
- description: "Package license"
286
- },
287
- repository: {
288
- type: "string",
289
- description: "Repository URL"
290
- },
291
- ecosystem: {
292
- type: "string",
293
- description: "Package ecosystem"
294
- }
295
- }
296
- },
297
- exports: {
298
- type: "array",
299
- description: "List of exported items",
300
- items: {
301
- $ref: "#/$defs/export"
302
- }
303
- },
304
- types: {
305
- type: "array",
306
- description: "List of type definitions",
307
- items: {
308
- $ref: "#/$defs/typeDef"
309
- }
310
- },
311
- docs: {
312
- $ref: "#/$defs/docsMetadata",
313
- description: "Aggregate documentation coverage metadata"
314
- }
315
- },
316
- $defs: {
317
- docSignal: {
318
- type: "string",
319
- enum: ["description", "params", "returns", "examples"]
320
- },
321
- docDrift: {
322
- type: "object",
323
- required: ["type", "issue"],
324
- properties: {
325
- type: {
326
- type: "string",
327
- enum: [
328
- "param-mismatch",
329
- "param-type-mismatch",
330
- "return-type-mismatch",
331
- "generic-constraint-mismatch",
332
- "optionality-mismatch",
333
- "deprecated-mismatch",
334
- "visibility-mismatch",
335
- "example-drift",
336
- "broken-link"
337
- ]
338
- },
339
- target: {
340
- type: "string",
341
- description: "Relevant identifier (e.g., parameter name)"
342
- },
343
- issue: {
344
- type: "string",
345
- description: "Human-friendly drift explanation"
346
- },
347
- suggestion: {
348
- type: "string",
349
- description: "Optional remediation hint"
350
- }
351
- },
352
- additionalProperties: false
353
- },
354
- docsMetadata: {
355
- type: "object",
356
- description: "Documentation coverage metadata",
357
- additionalProperties: false,
358
- properties: {
359
- coverageScore: {
360
- type: "number",
361
- minimum: 0,
362
- maximum: 100,
363
- description: "Documentation coverage value from 0-100."
364
- },
365
- missing: {
366
- type: "array",
367
- description: "Doc components missing for this entity",
368
- items: {
369
- $ref: "#/$defs/docSignal"
370
- },
371
- uniqueItems: true
372
- },
373
- drift: {
374
- type: "array",
375
- description: "Detected documentation drift signals",
376
- items: {
377
- $ref: "#/$defs/docDrift"
378
- }
379
- }
380
- }
381
- },
382
- export: {
383
- type: "object",
384
- required: ["id", "name", "kind"],
385
- properties: {
386
- id: {
387
- type: "string",
388
- description: "Unique identifier for the export"
389
- },
390
- name: {
391
- type: "string",
392
- description: "Export name"
393
- },
394
- slug: {
395
- type: "string",
396
- description: "Stable slug for linking"
397
- },
398
- displayName: {
399
- type: "string",
400
- description: "UI-friendly label"
401
- },
402
- category: {
403
- type: "string",
404
- description: "Grouping hint for navigation"
405
- },
406
- importPath: {
407
- type: "string",
408
- description: "Recommended import path"
409
- },
410
- kind: {
411
- type: "string",
412
- description: "Kind of export",
413
- enum: ["function", "class", "variable", "interface", "type", "enum"]
414
- },
415
- description: {
416
- type: "string",
417
- description: "JSDoc/TSDoc description"
418
- },
419
- examples: {
420
- type: "array",
421
- description: "Usage examples from documentation",
422
- items: {
423
- type: "string"
424
- }
425
- },
426
- signatures: {
427
- type: "array",
428
- description: "Function/method signatures",
429
- items: {
430
- $ref: "#/$defs/signature"
431
- }
432
- },
433
- type: {
434
- description: "Type reference or inline schema for variables",
435
- oneOf: [{ type: "string" }, { $ref: "#/$defs/schema" }]
436
- },
437
- members: {
438
- type: "array",
439
- description: "Class/interface/enum members",
440
- items: { type: "object" }
441
- },
442
- tags: {
443
- type: "array",
444
- description: "JSDoc/TSDoc tags",
445
- items: {
446
- type: "object",
447
- required: ["name", "text"],
448
- properties: {
449
- name: { type: "string" },
450
- text: { type: "string" }
451
- },
452
- additionalProperties: false
453
- }
454
- },
455
- source: {
456
- $ref: "#/$defs/sourceLocation"
457
- },
458
- docs: {
459
- $ref: "#/$defs/docsMetadata",
460
- description: "Documentation coverage metadata for this export"
461
- }
462
- }
463
- },
464
- typeDef: {
465
- type: "object",
466
- required: ["id", "name", "kind"],
467
- properties: {
468
- id: {
469
- type: "string",
470
- description: "Unique identifier for the type"
471
- },
472
- name: {
473
- type: "string",
474
- description: "Type name"
475
- },
476
- slug: {
477
- type: "string",
478
- description: "Stable slug for linking"
479
- },
480
- displayName: {
481
- type: "string",
482
- description: "UI-friendly label"
483
- },
484
- category: {
485
- type: "string",
486
- description: "Grouping hint for navigation"
487
- },
488
- importPath: {
489
- type: "string",
490
- description: "Recommended import path"
491
- },
492
- kind: {
493
- type: "string",
494
- description: "Kind of type definition",
495
- enum: ["interface", "type", "enum", "class"]
496
- },
497
- description: {
498
- type: "string",
499
- description: "JSDoc/TSDoc description"
500
- },
501
- schema: {
502
- $ref: "#/$defs/schema"
503
- },
504
- type: {
505
- type: "string",
506
- description: "Type expression for type aliases"
507
- },
508
- members: {
509
- type: "array",
510
- description: "Members for classes/interfaces/enums",
511
- items: { type: "object" }
512
- },
513
- tags: {
514
- type: "array",
515
- description: "JSDoc/TSDoc tags",
516
- items: {
517
- type: "object",
518
- required: ["name", "text"],
519
- properties: {
520
- name: { type: "string" },
521
- text: { type: "string" }
522
- },
523
- additionalProperties: false
524
- }
525
- },
526
- source: {
527
- $ref: "#/$defs/sourceLocation"
528
- }
529
- }
530
- },
531
- signature: {
532
- type: "object",
533
- properties: {
534
- parameters: {
535
- type: "array",
536
- items: {
537
- $ref: "#/$defs/parameter"
538
- }
539
- },
540
- returns: {
541
- $ref: "#/$defs/returns"
542
- },
543
- description: {
544
- type: "string",
545
- description: "Signature-level description"
546
- }
547
- }
548
- },
549
- parameter: {
550
- type: "object",
551
- required: ["name", "required"],
552
- properties: {
553
- name: {
554
- type: "string",
555
- description: "Parameter name"
556
- },
557
- required: {
558
- type: "boolean",
559
- description: "Whether the parameter is required"
560
- },
561
- schema: {
562
- $ref: "#/$defs/schema"
563
- },
564
- description: {
565
- type: "string",
566
- description: "Parameter description"
567
- }
568
- }
569
- },
570
- returns: {
571
- type: "object",
572
- properties: {
573
- schema: {
574
- $ref: "#/$defs/schema"
575
- },
576
- description: {
577
- type: "string",
578
- description: "Return value description"
579
- }
580
- }
581
- },
582
- schema: {
583
- anyOf: [
584
- {
585
- type: "boolean"
586
- },
587
- {
588
- type: "object",
589
- properties: {
590
- $ref: {
591
- type: "string",
592
- description: "Reference to another type",
593
- pattern: "^#/types/[A-Za-z0-9_.-]+$"
594
- }
595
- },
596
- required: ["$ref"],
597
- additionalProperties: false
598
- },
599
- {
600
- type: "object",
601
- not: {
602
- required: ["$ref"]
603
- },
604
- additionalProperties: true
605
- }
606
- ]
607
- },
608
- sourceLocation: {
609
- type: "object",
610
- required: ["file", "line"],
611
- properties: {
612
- file: {
613
- type: "string",
614
- description: "Source file path"
615
- },
616
- line: {
617
- type: "integer",
618
- description: "Line number in source file",
619
- minimum: 1
620
- }
621
- }
622
- }
623
- }
624
- };
625
-
626
- // src/validate.ts
627
- var ajv = new Ajv({
628
- strict: false,
629
- allErrors: true,
630
- allowUnionTypes: true,
631
- $data: true
632
- });
633
- addFormats(ajv);
634
- var validate = ajv.compile(openpkg_schema_default);
635
- function validateSpec(spec) {
636
- const ok = validate(spec);
637
- if (ok) {
638
- return { ok: true };
639
- }
640
- const errors = (validate.errors ?? []).map((error) => ({
641
- instancePath: error.instancePath ?? "",
642
- message: error.message ?? "invalid",
643
- keyword: error.keyword ?? "unknown"
644
- }));
645
- return {
646
- ok: false,
647
- errors
648
- };
649
- }
650
- function assertSpec(spec) {
651
- const result = validateSpec(spec);
652
- if (!result.ok) {
653
- const details = result.errors.map((error) => `- ${error.instancePath || "/"} ${error.message}`).join(`
654
- `);
655
- throw new Error(`Invalid OpenPkg spec:
656
- ${details}`);
657
- }
658
- }
659
- function getValidationErrors(spec) {
660
- const result = validateSpec(spec);
661
- return result.ok ? [] : result.errors;
662
- }
663
- export {
664
- validateSpec,
665
- normalize,
666
- getValidationErrors,
667
- diffSpec,
668
- dereference,
669
- assertSpec,
670
- SCHEMA_VERSION,
671
- SCHEMA_URL,
672
- JSON_SCHEMA_DRAFT
673
- };