@doccov/sdk 0.20.0 → 0.21.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.js +50 -21
- package/package.json +1 -1
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 (
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
|
|
@@ -7002,21 +7030,22 @@ function serializeVariable(declaration, symbol, context) {
|
|
|
7002
7030
|
const typeRefs = typeRegistry.getTypeRefs();
|
|
7003
7031
|
const referencedTypes = typeRegistry.getReferencedTypes();
|
|
7004
7032
|
const symbolName = symbol.getName();
|
|
7005
|
-
const
|
|
7006
|
-
if (
|
|
7033
|
+
const runtimeSchema = context.detectedSchemas?.get(symbolName);
|
|
7034
|
+
if (runtimeSchema) {
|
|
7035
|
+
const schemaSource = runtimeSchema.vendor === "typebox" ? "typebox-native" : "standard-schema";
|
|
7007
7036
|
return {
|
|
7008
7037
|
id: symbolName,
|
|
7009
7038
|
name: symbolName,
|
|
7010
7039
|
...metadata,
|
|
7011
7040
|
kind: "variable",
|
|
7012
7041
|
deprecated: isSymbolDeprecated(symbol),
|
|
7013
|
-
schema:
|
|
7042
|
+
schema: runtimeSchema.schema,
|
|
7014
7043
|
description,
|
|
7015
7044
|
source: getSourceLocation(declaration),
|
|
7016
7045
|
tags: [
|
|
7017
7046
|
...parsedDoc?.tags ?? [],
|
|
7018
|
-
{ name: "schemaLibrary", text:
|
|
7019
|
-
{ name: "schemaSource", text:
|
|
7047
|
+
{ name: "schemaLibrary", text: runtimeSchema.vendor },
|
|
7048
|
+
{ name: "schemaSource", text: schemaSource }
|
|
7020
7049
|
],
|
|
7021
7050
|
examples: parsedDoc?.examples
|
|
7022
7051
|
};
|