@doccov/sdk 0.20.0 → 0.22.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
@@ -125,6 +125,8 @@ interface DetectedSchema {
125
125
  interface SchemaDetectionResult {
126
126
  schemas: Map<string, DetectedSchema>;
127
127
  errors: string[];
128
+ /** Warning when runtime was requested but compiled JS not found */
129
+ noCompiledJsWarning?: boolean;
128
130
  }
129
131
  declare function detectRuntimeSchemas(context: SchemaDetectionContext): Promise<SchemaDetectionResult>;
130
132
  declare function clearSchemaCache(): void;
package/dist/index.js CHANGED
@@ -42,6 +42,22 @@ var WORKER_SCRIPT = `
42
42
  const path = require('path');
43
43
  const { pathToFileURL } = require('url');
44
44
 
45
+ // TypeBox detection: schemas have Symbol.for('TypeBox.Kind') and are JSON Schema
46
+ const TYPEBOX_KIND = Symbol.for('TypeBox.Kind');
47
+
48
+ function isTypeBoxSchema(obj) {
49
+ if (!obj || typeof obj !== 'object') return false;
50
+ // TypeBox schemas always have Kind symbol (Union, Object, String, etc.)
51
+ // Also check for common JSON Schema props to avoid false positives
52
+ if (!obj[TYPEBOX_KIND]) return false;
53
+ return typeof obj.type === 'string' || 'anyOf' in obj || 'oneOf' in obj || 'allOf' in obj;
54
+ }
55
+
56
+ function sanitizeTypeBoxSchema(schema) {
57
+ // JSON.stringify removes symbol keys, keeping only JSON Schema props
58
+ return JSON.parse(JSON.stringify(schema));
59
+ }
60
+
45
61
  async function extract() {
46
62
  // With node -e, argv is: [node, arg1, arg2, ...]
47
63
  // (the -e script is NOT in argv)
@@ -58,24 +74,36 @@ async function extract() {
58
74
  if (name.startsWith('_')) continue;
59
75
  if (typeof value !== 'object' || value === null) continue;
60
76
 
77
+ // Priority 1: Standard Schema (Zod 4.2+, ArkType, etc.)
61
78
  const std = value['~standard'];
62
- if (!std || typeof std !== 'object') continue;
63
- if (typeof std.version !== 'number') continue;
64
- if (typeof std.vendor !== 'string') continue;
65
- if (!std.jsonSchema || typeof std.jsonSchema.output !== 'function') continue;
66
-
67
- try {
68
- const outputSchema = std.jsonSchema.output(target);
69
- const inputSchema = std.jsonSchema.input ? std.jsonSchema.input(target) : undefined;
79
+ if (std && typeof std === 'object' && typeof std.version === 'number' && typeof std.vendor === 'string' && std.jsonSchema && typeof std.jsonSchema.output === 'function') {
80
+ try {
81
+ const outputSchema = std.jsonSchema.output(target);
82
+ const inputSchema = std.jsonSchema.input ? std.jsonSchema.input(target) : undefined;
83
+ results.push({
84
+ exportName: name,
85
+ vendor: std.vendor,
86
+ outputSchema,
87
+ inputSchema
88
+ });
89
+ } catch (e) {
90
+ // Skip schemas that fail to extract
91
+ }
92
+ continue;
93
+ }
70
94
 
71
- results.push({
72
- exportName: name,
73
- vendor: std.vendor,
74
- outputSchema,
75
- inputSchema
76
- });
77
- } catch (e) {
78
- // Skip schemas that fail to extract
95
+ // Priority 2: TypeBox (schema IS JSON Schema)
96
+ if (isTypeBoxSchema(value)) {
97
+ try {
98
+ results.push({
99
+ exportName: name,
100
+ vendor: 'typebox',
101
+ outputSchema: sanitizeTypeBoxSchema(value)
102
+ });
103
+ } catch (e) {
104
+ // Skip schemas that fail to extract
105
+ }
106
+ continue;
79
107
  }
80
108
  }
81
109
 
@@ -176,7 +204,8 @@ async function detectRuntimeSchemas(context) {
176
204
  if (!compiledPath) {
177
205
  return {
178
206
  schemas: new Map,
179
- errors: []
207
+ errors: [],
208
+ noCompiledJsWarning: true
180
209
  };
181
210
  }
182
211
  const extraction = await extractStandardSchemasFromProject(entryFile, baseDir);
@@ -618,7 +647,7 @@ function generateReturnTypeFix(drift, exportEntry, existingPatch) {
618
647
  const actualReturn = signature?.returns;
619
648
  if (!actualReturn)
620
649
  return null;
621
- const correctType = actualReturn.tsType ?? stringifySchema(actualReturn.schema);
650
+ const correctType = stringifySchema(actualReturn.schema);
622
651
  const updatedReturn = {
623
652
  ...existingPatch?.returns,
624
653
  type: correctType
@@ -1568,7 +1597,7 @@ function detectReturnTypeDrift(entry) {
1568
1597
  if (!signatureReturn) {
1569
1598
  return [];
1570
1599
  }
1571
- const declaredRaw = signatureReturn.tsType ?? extractTypeFromSchema(signatureReturn.schema);
1600
+ const declaredRaw = extractTypeFromSchema(signatureReturn.schema);
1572
1601
  const declaredType = normalizeType(declaredRaw) ?? undefined;
1573
1602
  if (!declaredType) {
1574
1603
  return [];
@@ -2170,7 +2199,7 @@ function detectAsyncMismatch(entry) {
2170
2199
  }
2171
2200
  const drifts = [];
2172
2201
  const returnsPromise = signatures.some((sig) => {
2173
- const returnType = sig.returns?.tsType ?? extractTypeFromSchema(sig.returns?.schema) ?? "";
2202
+ const returnType = extractTypeFromSchema(sig.returns?.schema) ?? "";
2174
2203
  return returnType.startsWith("Promise<") || returnType === "Promise";
2175
2204
  });
2176
2205
  const returnsTag = entry.tags?.find((tag) => tag.name === "returns" || tag.name === "return");
@@ -5133,11 +5162,11 @@ function formatTypeReference(type, typeChecker, typeRefs, referencedTypes, visit
5133
5162
  if (type.getFlags() & ts.TypeFlags.Object) {
5134
5163
  const objectType = type;
5135
5164
  if (objectType.objectFlags & ts.ObjectFlags.Mapped) {
5136
- return { type: "object", tsType: typeString };
5165
+ return { type: "object" };
5137
5166
  }
5138
5167
  }
5139
5168
  if (type.flags & ts.TypeFlags.Conditional) {
5140
- return { type: "object", tsType: typeString };
5169
+ return { type: "object" };
5141
5170
  }
5142
5171
  if (type.isUnion()) {
5143
5172
  const unionType = type;
@@ -6391,7 +6420,6 @@ function serializeCallSignatures(signatures, symbol, context, parsedDoc) {
6391
6420
  };
6392
6421
  });
6393
6422
  const returnType = signature.getReturnType();
6394
- const returnTypeText = returnType ? checker.typeToString(returnType) : undefined;
6395
6423
  if (returnType) {
6396
6424
  collectReferencedTypes(returnType, checker, referencedTypes);
6397
6425
  }
@@ -6417,7 +6445,6 @@ function serializeCallSignatures(signatures, symbol, context, parsedDoc) {
6417
6445
  returns: {
6418
6446
  schema: returnType ? formatTypeReference(returnType, checker, typeRefs, referencedTypes) : { type: "void" },
6419
6447
  description: functionDoc?.returns || "",
6420
- tsType: returnTypeText,
6421
6448
  ...typePredicateInfo ? { typePredicate: typePredicateInfo } : {}
6422
6449
  },
6423
6450
  description: functionDoc?.description || undefined,
@@ -7002,21 +7029,22 @@ function serializeVariable(declaration, symbol, context) {
7002
7029
  const typeRefs = typeRegistry.getTypeRefs();
7003
7030
  const referencedTypes = typeRegistry.getReferencedTypes();
7004
7031
  const symbolName = symbol.getName();
7005
- const standardSchema = context.detectedSchemas?.get(symbolName);
7006
- if (standardSchema) {
7032
+ const runtimeSchema = context.detectedSchemas?.get(symbolName);
7033
+ if (runtimeSchema) {
7034
+ const schemaSource = runtimeSchema.vendor === "typebox" ? "typebox-native" : "standard-schema";
7007
7035
  return {
7008
7036
  id: symbolName,
7009
7037
  name: symbolName,
7010
7038
  ...metadata,
7011
7039
  kind: "variable",
7012
7040
  deprecated: isSymbolDeprecated(symbol),
7013
- schema: standardSchema.schema,
7041
+ schema: runtimeSchema.schema,
7014
7042
  description,
7015
7043
  source: getSourceLocation(declaration),
7016
7044
  tags: [
7017
7045
  ...parsedDoc?.tags ?? [],
7018
- { name: "schemaLibrary", text: standardSchema.vendor },
7019
- { name: "schemaSource", text: "standard-schema" }
7046
+ { name: "schemaLibrary", text: runtimeSchema.vendor },
7047
+ { name: "schemaSource", text: schemaSource }
7020
7048
  ],
7021
7049
  examples: parsedDoc?.examples
7022
7050
  };
@@ -8461,13 +8489,6 @@ function extractTypeName(schema) {
8461
8489
  if (typeof s.type === "string") {
8462
8490
  return s.type;
8463
8491
  }
8464
- if (typeof s.tsType === "string") {
8465
- const tsType = s.tsType;
8466
- if (tsType.length > 30) {
8467
- return `${tsType.slice(0, 27)}...`;
8468
- }
8469
- return tsType;
8470
- }
8471
8492
  return;
8472
8493
  }
8473
8494
  function hasSignatureChanged(oldMember, newMember) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doccov/sdk",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
4
4
  "description": "DocCov SDK - Documentation coverage and drift detection for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",
@@ -39,7 +39,7 @@
39
39
  "dist"
40
40
  ],
41
41
  "dependencies": {
42
- "@openpkg-ts/spec": "^0.10.0",
42
+ "@openpkg-ts/spec": "^0.11.0",
43
43
  "@vercel/sandbox": "^1.0.3",
44
44
  "mdast": "^3.0.0",
45
45
  "minimatch": "^10.1.1",