@doccov/sdk 0.27.2 → 0.27.3
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/analysis/index.js +1 -1
- package/dist/index.d.ts +7 -129
- package/dist/index.js +7 -184
- package/dist/shared/{chunk-aemmktkm.js → chunk-v1vce2mg.js} +60 -208
- package/package.json +1 -1
package/dist/analysis/index.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -2139,143 +2139,21 @@ interface SchemaDetectionResult {
|
|
|
2139
2139
|
}
|
|
2140
2140
|
declare function detectRuntimeSchemas(context: SchemaDetectionContext): Promise<SchemaDetectionResult>;
|
|
2141
2141
|
import * as TS2 from "typescript";
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
* schema validation library.
|
|
2145
|
-
*/
|
|
2146
|
-
interface SchemaAdapter {
|
|
2147
|
-
/** Unique identifier for this adapter */
|
|
2148
|
-
readonly id: string;
|
|
2149
|
-
/** npm package name(s) this adapter handles */
|
|
2150
|
-
readonly packages: readonly string[];
|
|
2151
|
-
/**
|
|
2152
|
-
* Check if a type matches this adapter's schema library.
|
|
2153
|
-
* Should be fast - called for every export.
|
|
2154
|
-
*/
|
|
2155
|
-
matches(type: TS2.Type, checker: TS2.TypeChecker): boolean;
|
|
2156
|
-
/**
|
|
2157
|
-
* Extract the output type from a schema type.
|
|
2158
|
-
* Returns null if extraction fails.
|
|
2159
|
-
*/
|
|
2160
|
-
extractOutputType(type: TS2.Type, checker: TS2.TypeChecker): TS2.Type | null;
|
|
2161
|
-
/**
|
|
2162
|
-
* Extract the input type from a schema type (optional).
|
|
2163
|
-
* Useful for transforms where input differs from output.
|
|
2164
|
-
*/
|
|
2165
|
-
extractInputType?(type: TS2.Type, checker: TS2.TypeChecker): TS2.Type | null;
|
|
2166
|
-
}
|
|
2167
|
-
/**
|
|
2168
|
-
* Result of schema type extraction
|
|
2169
|
-
*/
|
|
2170
|
-
interface SchemaExtractionResult {
|
|
2171
|
-
/** The adapter that matched */
|
|
2172
|
-
adapter: SchemaAdapter;
|
|
2173
|
-
/** The extracted output type */
|
|
2174
|
-
outputType: TS2.Type;
|
|
2175
|
-
/** The extracted input type (if different from output) */
|
|
2176
|
-
inputType?: TS2.Type;
|
|
2177
|
-
}
|
|
2178
|
-
import * as TS3 from "typescript";
|
|
2179
|
-
/**
|
|
2180
|
-
* Find an adapter that matches the given type.
|
|
2181
|
-
* Returns null if no adapter matches.
|
|
2182
|
-
*/
|
|
2183
|
-
declare function findAdapter(type: TS3.Type, checker: TS3.TypeChecker): SchemaAdapter | null;
|
|
2184
|
-
/**
|
|
2185
|
-
* Check if a type is from a recognized schema library.
|
|
2186
|
-
*/
|
|
2187
|
-
declare function isSchemaType(type: TS3.Type, checker: TS3.TypeChecker): boolean;
|
|
2142
|
+
import { extractSchemaType, findAdapter, isSchemaType, extractStandardSchemas, extractStandardSchemasFromProject, isStandardJSONSchema, resolveCompiledPath, ExtractStandardSchemasOptions, SchemaAdapter, SchemaExtractionResult, StandardJSONSchemaV1, StandardSchemaExtractionOutput, StandardSchemaExtractionResult } from "@openpkg-ts/extract";
|
|
2143
|
+
import { SchemaAdapter as SchemaAdapter2 } from "@openpkg-ts/extract";
|
|
2188
2144
|
/**
|
|
2189
2145
|
* Extract the output type from a schema type.
|
|
2190
|
-
*
|
|
2191
|
-
* - The type is not from a recognized schema library
|
|
2192
|
-
* - The adapter fails to extract the output type
|
|
2193
|
-
*/
|
|
2194
|
-
declare function extractSchemaOutputType(type: TS3.Type, checker: TS3.TypeChecker): TS3.Type | null;
|
|
2195
|
-
/**
|
|
2196
|
-
* Full extraction with adapter info.
|
|
2197
|
-
* Useful when you need to know which library was detected.
|
|
2146
|
+
* Convenience wrapper that returns just the type.
|
|
2198
2147
|
*/
|
|
2199
|
-
declare function
|
|
2148
|
+
declare function extractSchemaOutputType(type: TS2.Type, checker: TS2.TypeChecker): TS2.Type | null;
|
|
2200
2149
|
/**
|
|
2201
2150
|
* Get all registered adapters.
|
|
2202
|
-
* Useful for logging/debugging.
|
|
2203
2151
|
*/
|
|
2204
|
-
declare function getRegisteredAdapters(): readonly
|
|
2152
|
+
declare function getRegisteredAdapters(): readonly SchemaAdapter2[];
|
|
2205
2153
|
/**
|
|
2206
2154
|
* Get supported library names.
|
|
2207
|
-
* Useful for documentation/help output.
|
|
2208
2155
|
*/
|
|
2209
2156
|
declare function getSupportedLibraries(): readonly string[];
|
|
2210
|
-
/**
|
|
2211
|
-
* Standard JSON Schema v1 interface (minimal for detection).
|
|
2212
|
-
*/
|
|
2213
|
-
interface StandardJSONSchemaV1 {
|
|
2214
|
-
"~standard": {
|
|
2215
|
-
version: number;
|
|
2216
|
-
vendor: string;
|
|
2217
|
-
jsonSchema?: {
|
|
2218
|
-
output: (target?: string) => Record<string, unknown>;
|
|
2219
|
-
input?: (target?: string) => Record<string, unknown>;
|
|
2220
|
-
};
|
|
2221
|
-
};
|
|
2222
|
-
}
|
|
2223
|
-
/**
|
|
2224
|
-
* Result of extracting Standard Schema from an export.
|
|
2225
|
-
*/
|
|
2226
|
-
interface StandardSchemaExtractionResult {
|
|
2227
|
-
exportName: string;
|
|
2228
|
-
vendor: string;
|
|
2229
|
-
outputSchema: Record<string, unknown>;
|
|
2230
|
-
inputSchema?: Record<string, unknown>;
|
|
2231
|
-
}
|
|
2232
|
-
/**
|
|
2233
|
-
* Options for runtime Standard Schema extraction.
|
|
2234
|
-
*/
|
|
2235
|
-
interface ExtractStandardSchemasOptions {
|
|
2236
|
-
/** Timeout in milliseconds (default: 10000) */
|
|
2237
|
-
timeout?: number;
|
|
2238
|
-
/** JSON Schema target version (default: 'draft-2020-12') */
|
|
2239
|
-
target?: "draft-2020-12" | "draft-07" | "openapi-3.0";
|
|
2240
|
-
}
|
|
2241
|
-
/**
|
|
2242
|
-
* Result of Standard Schema extraction.
|
|
2243
|
-
*/
|
|
2244
|
-
interface StandardSchemaExtractionOutput {
|
|
2245
|
-
schemas: Map<string, StandardSchemaExtractionResult>;
|
|
2246
|
-
errors: string[];
|
|
2247
|
-
}
|
|
2248
|
-
/**
|
|
2249
|
-
* Check if an object implements StandardJSONSchemaV1.
|
|
2250
|
-
* This is a static type guard - doesn't require runtime.
|
|
2251
|
-
*/
|
|
2252
|
-
declare function isStandardJSONSchema(obj: unknown): obj is StandardJSONSchemaV1;
|
|
2253
|
-
/**
|
|
2254
|
-
* Resolve compiled JS path from TypeScript source.
|
|
2255
|
-
* Tries common output locations: dist/, build/, lib/, same dir.
|
|
2256
|
-
*/
|
|
2257
|
-
declare function resolveCompiledPath(tsPath: string, baseDir: string): string | null;
|
|
2258
|
-
/**
|
|
2259
|
-
* Extract Standard Schema JSON Schemas from a compiled JS module.
|
|
2260
|
-
*
|
|
2261
|
-
* **Security Note**: This executes the module in a subprocess.
|
|
2262
|
-
* Only use with trusted code (user's own packages).
|
|
2263
|
-
*
|
|
2264
|
-
* @param compiledJsPath - Path to compiled .js file
|
|
2265
|
-
* @param options - Extraction options
|
|
2266
|
-
* @returns Extraction results with schemas and any errors
|
|
2267
|
-
*/
|
|
2268
|
-
declare function extractStandardSchemas(compiledJsPath: string, options?: ExtractStandardSchemasOptions): Promise<StandardSchemaExtractionOutput>;
|
|
2269
|
-
/**
|
|
2270
|
-
* Extract Standard Schema from a TypeScript project.
|
|
2271
|
-
*
|
|
2272
|
-
* Convenience function that resolves compiled JS and extracts schemas.
|
|
2273
|
-
*
|
|
2274
|
-
* @param entryFile - TypeScript entry file path
|
|
2275
|
-
* @param baseDir - Project base directory
|
|
2276
|
-
* @param options - Extraction options
|
|
2277
|
-
*/
|
|
2278
|
-
declare function extractStandardSchemasFromProject(entryFile: string, baseDir: string, options?: ExtractStandardSchemasOptions): Promise<StandardSchemaExtractionOutput>;
|
|
2279
2157
|
declare function extractPackageSpec(entryFile: string, packageDir?: string, content?: string, options?: DocCovOptions): Promise<OpenPkgSpec>;
|
|
2280
2158
|
/**
|
|
2281
2159
|
* Source of filter options.
|
|
@@ -2687,7 +2565,7 @@ interface SpecSummary {
|
|
|
2687
2565
|
* ```
|
|
2688
2566
|
*/
|
|
2689
2567
|
declare function extractSpecSummary(openpkg: OpenPkg8, doccov: DocCovSpec4): SpecSummary;
|
|
2690
|
-
import { OpenPkg as
|
|
2568
|
+
import { OpenPkg as OpenPkg_jkmegcwtaf } from "@openpkg-ts/spec";
|
|
2691
2569
|
/**
|
|
2692
2570
|
* Build Plan types for AI-powered repository scanning.
|
|
2693
2571
|
*/
|
|
@@ -2784,7 +2662,7 @@ interface BuildPlanExecutionResult {
|
|
|
2784
2662
|
/** Whether all required steps succeeded */
|
|
2785
2663
|
success: boolean;
|
|
2786
2664
|
/** Generated OpenPkg spec (if successful) */
|
|
2787
|
-
spec?:
|
|
2665
|
+
spec?: OpenPkg_jkmegcwtaf;
|
|
2788
2666
|
/** Results for each step */
|
|
2789
2667
|
stepResults: BuildPlanStepResult[];
|
|
2790
2668
|
/** Total execution time in milliseconds */
|
package/dist/index.js
CHANGED
|
@@ -21,8 +21,11 @@ import {
|
|
|
21
21
|
detectExampleRuntimeErrors,
|
|
22
22
|
detectRuntimeSchemas,
|
|
23
23
|
ensureSpecCoverage,
|
|
24
|
+
extractSchemaOutputType,
|
|
25
|
+
extractSchemaType,
|
|
24
26
|
extractStandardSchemas,
|
|
25
27
|
extractStandardSchemasFromProject,
|
|
28
|
+
findAdapter,
|
|
26
29
|
findJSDocLocation,
|
|
27
30
|
formatDelta,
|
|
28
31
|
formatDriftSummaryLine,
|
|
@@ -37,6 +40,8 @@ import {
|
|
|
37
40
|
getExportMissing,
|
|
38
41
|
getExportScore,
|
|
39
42
|
getExtendedTrend,
|
|
43
|
+
getRegisteredAdapters,
|
|
44
|
+
getSupportedLibraries,
|
|
40
45
|
getTrend,
|
|
41
46
|
groupDriftsByCategory,
|
|
42
47
|
groupFixesByFile,
|
|
@@ -44,6 +49,7 @@ import {
|
|
|
44
49
|
isBuiltInIdentifier,
|
|
45
50
|
isExportFullyDocumented,
|
|
46
51
|
isFixableDrift,
|
|
52
|
+
isSchemaType,
|
|
47
53
|
isStandardJSONSchema,
|
|
48
54
|
loadCachedReport,
|
|
49
55
|
loadSnapshots,
|
|
@@ -60,7 +66,7 @@ import {
|
|
|
60
66
|
saveSnapshot,
|
|
61
67
|
serializeJSDoc,
|
|
62
68
|
ts
|
|
63
|
-
} from "./shared/chunk-
|
|
69
|
+
} from "./shared/chunk-v1vce2mg.js";
|
|
64
70
|
import {
|
|
65
71
|
mergeFilters,
|
|
66
72
|
parseListFlag
|
|
@@ -419,189 +425,6 @@ function getSpecCachePath(cwd) {
|
|
|
419
425
|
}
|
|
420
426
|
// src/extractor.ts
|
|
421
427
|
import * as path6 from "node:path";
|
|
422
|
-
|
|
423
|
-
// src/extract/schema/types.ts
|
|
424
|
-
function isTypeReference(type) {
|
|
425
|
-
return !!(type.flags & 524288 && type.objectFlags && type.objectFlags & 4);
|
|
426
|
-
}
|
|
427
|
-
function getNonNullableType(type) {
|
|
428
|
-
if (type.isUnion()) {
|
|
429
|
-
const nonNullable = type.types.filter((t) => !(t.flags & 32768) && !(t.flags & 65536));
|
|
430
|
-
if (nonNullable.length === 1) {
|
|
431
|
-
return nonNullable[0];
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
return type;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
// src/extract/schema/adapters/arktype.ts
|
|
438
|
-
var ARKTYPE_TYPE_PATTERN = /^Type</;
|
|
439
|
-
var arktypeAdapter = {
|
|
440
|
-
id: "arktype",
|
|
441
|
-
packages: ["arktype"],
|
|
442
|
-
matches(type, checker) {
|
|
443
|
-
const typeName = checker.typeToString(type);
|
|
444
|
-
return ARKTYPE_TYPE_PATTERN.test(typeName);
|
|
445
|
-
},
|
|
446
|
-
extractOutputType(type, checker) {
|
|
447
|
-
if (!isTypeReference(type)) {
|
|
448
|
-
return null;
|
|
449
|
-
}
|
|
450
|
-
const args = checker.getTypeArguments(type);
|
|
451
|
-
if (args.length < 1) {
|
|
452
|
-
return null;
|
|
453
|
-
}
|
|
454
|
-
return args[0];
|
|
455
|
-
},
|
|
456
|
-
extractInputType(type, checker) {
|
|
457
|
-
if (!isTypeReference(type)) {
|
|
458
|
-
return null;
|
|
459
|
-
}
|
|
460
|
-
const args = checker.getTypeArguments(type);
|
|
461
|
-
if (args.length < 2) {
|
|
462
|
-
return null;
|
|
463
|
-
}
|
|
464
|
-
return args[1];
|
|
465
|
-
}
|
|
466
|
-
};
|
|
467
|
-
// src/extract/schema/adapters/typebox.ts
|
|
468
|
-
var TYPEBOX_TYPE_PATTERN = /^T[A-Z]/;
|
|
469
|
-
var typeboxAdapter = {
|
|
470
|
-
id: "typebox",
|
|
471
|
-
packages: ["@sinclair/typebox"],
|
|
472
|
-
matches(type, checker) {
|
|
473
|
-
const typeName = checker.typeToString(type);
|
|
474
|
-
if (!TYPEBOX_TYPE_PATTERN.test(typeName)) {
|
|
475
|
-
return false;
|
|
476
|
-
}
|
|
477
|
-
const typeProperty = type.getProperty("type");
|
|
478
|
-
return typeProperty !== undefined;
|
|
479
|
-
},
|
|
480
|
-
extractOutputType(type, checker) {
|
|
481
|
-
const staticSymbol = type.getProperty("static");
|
|
482
|
-
if (staticSymbol) {
|
|
483
|
-
return checker.getTypeOfSymbol(staticSymbol);
|
|
484
|
-
}
|
|
485
|
-
return null;
|
|
486
|
-
}
|
|
487
|
-
};
|
|
488
|
-
// src/extract/schema/adapters/valibot.ts
|
|
489
|
-
var VALIBOT_TYPE_PATTERN = /Schema(<|$)/;
|
|
490
|
-
var valibotAdapter = {
|
|
491
|
-
id: "valibot",
|
|
492
|
-
packages: ["valibot"],
|
|
493
|
-
matches(type, checker) {
|
|
494
|
-
const typeName = checker.typeToString(type);
|
|
495
|
-
return VALIBOT_TYPE_PATTERN.test(typeName) && !typeName.includes("Zod");
|
|
496
|
-
},
|
|
497
|
-
extractOutputType(type, checker) {
|
|
498
|
-
const typesSymbol = type.getProperty("~types");
|
|
499
|
-
if (!typesSymbol) {
|
|
500
|
-
return null;
|
|
501
|
-
}
|
|
502
|
-
let typesType = checker.getTypeOfSymbol(typesSymbol);
|
|
503
|
-
typesType = getNonNullableType(typesType);
|
|
504
|
-
const outputSymbol = typesType.getProperty("output");
|
|
505
|
-
if (!outputSymbol) {
|
|
506
|
-
return null;
|
|
507
|
-
}
|
|
508
|
-
return checker.getTypeOfSymbol(outputSymbol);
|
|
509
|
-
},
|
|
510
|
-
extractInputType(type, checker) {
|
|
511
|
-
const typesSymbol = type.getProperty("~types");
|
|
512
|
-
if (!typesSymbol) {
|
|
513
|
-
return null;
|
|
514
|
-
}
|
|
515
|
-
let typesType = checker.getTypeOfSymbol(typesSymbol);
|
|
516
|
-
typesType = getNonNullableType(typesType);
|
|
517
|
-
const inputSymbol = typesType.getProperty("input");
|
|
518
|
-
if (!inputSymbol) {
|
|
519
|
-
return null;
|
|
520
|
-
}
|
|
521
|
-
return checker.getTypeOfSymbol(inputSymbol);
|
|
522
|
-
}
|
|
523
|
-
};
|
|
524
|
-
// src/extract/schema/adapters/zod.ts
|
|
525
|
-
var ZOD_TYPE_PATTERN = /^Zod[A-Z]/;
|
|
526
|
-
var zodAdapter = {
|
|
527
|
-
id: "zod",
|
|
528
|
-
packages: ["zod"],
|
|
529
|
-
matches(type, checker) {
|
|
530
|
-
const typeName = checker.typeToString(type);
|
|
531
|
-
return ZOD_TYPE_PATTERN.test(typeName);
|
|
532
|
-
},
|
|
533
|
-
extractOutputType(type, checker) {
|
|
534
|
-
const outputSymbol = type.getProperty("_output");
|
|
535
|
-
if (outputSymbol) {
|
|
536
|
-
return checker.getTypeOfSymbol(outputSymbol);
|
|
537
|
-
}
|
|
538
|
-
const typeSymbol = type.getProperty("_type");
|
|
539
|
-
if (typeSymbol) {
|
|
540
|
-
return checker.getTypeOfSymbol(typeSymbol);
|
|
541
|
-
}
|
|
542
|
-
return null;
|
|
543
|
-
},
|
|
544
|
-
extractInputType(type, checker) {
|
|
545
|
-
const inputSymbol = type.getProperty("_input");
|
|
546
|
-
if (inputSymbol) {
|
|
547
|
-
return checker.getTypeOfSymbol(inputSymbol);
|
|
548
|
-
}
|
|
549
|
-
return null;
|
|
550
|
-
}
|
|
551
|
-
};
|
|
552
|
-
// src/extract/schema/registry.ts
|
|
553
|
-
var adapters = [
|
|
554
|
-
zodAdapter,
|
|
555
|
-
arktypeAdapter,
|
|
556
|
-
typeboxAdapter,
|
|
557
|
-
valibotAdapter
|
|
558
|
-
];
|
|
559
|
-
function findAdapter(type, checker) {
|
|
560
|
-
for (const adapter of adapters) {
|
|
561
|
-
if (adapter.matches(type, checker)) {
|
|
562
|
-
return adapter;
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
return null;
|
|
566
|
-
}
|
|
567
|
-
function isSchemaType(type, checker) {
|
|
568
|
-
return findAdapter(type, checker) !== null;
|
|
569
|
-
}
|
|
570
|
-
function extractSchemaOutputType(type, checker) {
|
|
571
|
-
const adapter = findAdapter(type, checker);
|
|
572
|
-
if (!adapter) {
|
|
573
|
-
return null;
|
|
574
|
-
}
|
|
575
|
-
return adapter.extractOutputType(type, checker);
|
|
576
|
-
}
|
|
577
|
-
function extractSchemaType(type, checker) {
|
|
578
|
-
const adapter = findAdapter(type, checker);
|
|
579
|
-
if (!adapter) {
|
|
580
|
-
return null;
|
|
581
|
-
}
|
|
582
|
-
const outputType = adapter.extractOutputType(type, checker);
|
|
583
|
-
if (!outputType) {
|
|
584
|
-
return null;
|
|
585
|
-
}
|
|
586
|
-
const result = {
|
|
587
|
-
adapter,
|
|
588
|
-
outputType
|
|
589
|
-
};
|
|
590
|
-
if (adapter.extractInputType) {
|
|
591
|
-
const inputType = adapter.extractInputType(type, checker);
|
|
592
|
-
if (inputType) {
|
|
593
|
-
result.inputType = inputType;
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
return result;
|
|
597
|
-
}
|
|
598
|
-
function getRegisteredAdapters() {
|
|
599
|
-
return adapters;
|
|
600
|
-
}
|
|
601
|
-
function getSupportedLibraries() {
|
|
602
|
-
return adapters.flatMap((a) => a.packages);
|
|
603
|
-
}
|
|
604
|
-
// src/extractor.ts
|
|
605
428
|
async function extractPackageSpec(entryFile, packageDir, content, options) {
|
|
606
429
|
const baseDir = packageDir ?? path6.dirname(entryFile);
|
|
607
430
|
const schemaMode = options?.schemaExtraction ?? "static";
|
|
@@ -2795,195 +2795,47 @@ function renderApiSurface(spec) {
|
|
|
2795
2795
|
`);
|
|
2796
2796
|
}
|
|
2797
2797
|
|
|
2798
|
-
// src/extract/schema/
|
|
2799
|
-
import {
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
return typeof obj.type === 'string' || 'anyOf' in obj || 'oneOf' in obj || 'allOf' in obj;
|
|
2832
|
-
}
|
|
2833
|
-
|
|
2834
|
-
function sanitizeTypeBoxSchema(schema) {
|
|
2835
|
-
// JSON.stringify removes symbol keys, keeping only JSON Schema props
|
|
2836
|
-
return JSON.parse(JSON.stringify(schema));
|
|
2837
|
-
}
|
|
2838
|
-
|
|
2839
|
-
async function extract() {
|
|
2840
|
-
// With node -e, argv is: [node, arg1, arg2, ...]
|
|
2841
|
-
// (the -e script is NOT in argv)
|
|
2842
|
-
const [modulePath, target] = process.argv.slice(1);
|
|
2843
|
-
|
|
2844
|
-
try {
|
|
2845
|
-
// Import the module using dynamic import (works with ESM and CJS)
|
|
2846
|
-
const absPath = path.resolve(modulePath);
|
|
2847
|
-
const mod = await import(pathToFileURL(absPath).href);
|
|
2848
|
-
const results = [];
|
|
2849
|
-
|
|
2850
|
-
// Build exports map - handle both ESM and CJS (where exports are in mod.default)
|
|
2851
|
-
const exports = {};
|
|
2852
|
-
for (const [name, value] of Object.entries(mod)) {
|
|
2853
|
-
if (name === 'default' && typeof value === 'object' && value !== null) {
|
|
2854
|
-
// CJS module: spread default exports
|
|
2855
|
-
Object.assign(exports, value);
|
|
2856
|
-
} else if (name !== 'default') {
|
|
2857
|
-
exports[name] = value;
|
|
2858
|
-
}
|
|
2859
|
-
}
|
|
2860
|
-
|
|
2861
|
-
// Check each export
|
|
2862
|
-
for (const [name, value] of Object.entries(exports)) {
|
|
2863
|
-
if (name.startsWith('_')) continue;
|
|
2864
|
-
if (typeof value !== 'object' || value === null) continue;
|
|
2865
|
-
|
|
2866
|
-
// Priority 1: Standard Schema (Zod 4.2+, ArkType, etc.)
|
|
2867
|
-
const std = value['~standard'];
|
|
2868
|
-
if (std && typeof std === 'object' && typeof std.version === 'number' && typeof std.vendor === 'string' && std.jsonSchema && typeof std.jsonSchema.output === 'function') {
|
|
2869
|
-
try {
|
|
2870
|
-
const outputSchema = std.jsonSchema.output(target);
|
|
2871
|
-
const inputSchema = std.jsonSchema.input ? std.jsonSchema.input(target) : undefined;
|
|
2872
|
-
results.push({
|
|
2873
|
-
exportName: name,
|
|
2874
|
-
vendor: std.vendor,
|
|
2875
|
-
outputSchema,
|
|
2876
|
-
inputSchema
|
|
2877
|
-
});
|
|
2878
|
-
} catch (e) {
|
|
2879
|
-
// Skip schemas that fail to extract
|
|
2880
|
-
}
|
|
2881
|
-
continue;
|
|
2882
|
-
}
|
|
2883
|
-
|
|
2884
|
-
// Priority 2: TypeBox (schema IS JSON Schema)
|
|
2885
|
-
if (isTypeBoxSchema(value)) {
|
|
2886
|
-
try {
|
|
2887
|
-
results.push({
|
|
2888
|
-
exportName: name,
|
|
2889
|
-
vendor: 'typebox',
|
|
2890
|
-
outputSchema: sanitizeTypeBoxSchema(value)
|
|
2891
|
-
});
|
|
2892
|
-
} catch (e) {
|
|
2893
|
-
// Skip schemas that fail to extract
|
|
2894
|
-
}
|
|
2895
|
-
continue;
|
|
2896
|
-
}
|
|
2897
|
-
}
|
|
2898
|
-
|
|
2899
|
-
console.log(JSON.stringify({ success: true, results }));
|
|
2900
|
-
} catch (e) {
|
|
2901
|
-
console.log(JSON.stringify({ success: false, error: e.message }));
|
|
2902
|
-
}
|
|
2903
|
-
}
|
|
2904
|
-
|
|
2905
|
-
extract();
|
|
2906
|
-
`;
|
|
2907
|
-
function resolveCompiledPath(tsPath, baseDir) {
|
|
2908
|
-
const relativePath = path4.relative(baseDir, tsPath);
|
|
2909
|
-
const withoutExt = relativePath.replace(/\.tsx?$/, "");
|
|
2910
|
-
const candidates = [
|
|
2911
|
-
path4.join(baseDir, `${withoutExt}.js`),
|
|
2912
|
-
path4.join(baseDir, "dist", `${withoutExt.replace(/^src\//, "")}.js`),
|
|
2913
|
-
path4.join(baseDir, "build", `${withoutExt.replace(/^src\//, "")}.js`),
|
|
2914
|
-
path4.join(baseDir, "lib", `${withoutExt.replace(/^src\//, "")}.js`)
|
|
2915
|
-
];
|
|
2916
|
-
for (const candidate of candidates) {
|
|
2917
|
-
if (fs4.existsSync(candidate)) {
|
|
2918
|
-
return candidate;
|
|
2919
|
-
}
|
|
2798
|
+
// src/extract/schema/index.ts
|
|
2799
|
+
import {
|
|
2800
|
+
arktypeAdapter,
|
|
2801
|
+
typeboxAdapter,
|
|
2802
|
+
valibotAdapter,
|
|
2803
|
+
zodAdapter,
|
|
2804
|
+
extractSchemaType,
|
|
2805
|
+
findAdapter,
|
|
2806
|
+
isSchemaType,
|
|
2807
|
+
extractStandardSchemas,
|
|
2808
|
+
extractStandardSchemasFromProject,
|
|
2809
|
+
isStandardJSONSchema,
|
|
2810
|
+
resolveCompiledPath,
|
|
2811
|
+
getNonNullableType,
|
|
2812
|
+
isTypeReference
|
|
2813
|
+
} from "@openpkg-ts/extract";
|
|
2814
|
+
import {
|
|
2815
|
+
arktypeAdapter as arktypeAdapter2,
|
|
2816
|
+
findAdapter as findAdapter2,
|
|
2817
|
+
typeboxAdapter as typeboxAdapter2,
|
|
2818
|
+
valibotAdapter as valibotAdapter2,
|
|
2819
|
+
zodAdapter as zodAdapter2
|
|
2820
|
+
} from "@openpkg-ts/extract";
|
|
2821
|
+
var adapters = [
|
|
2822
|
+
zodAdapter2,
|
|
2823
|
+
arktypeAdapter2,
|
|
2824
|
+
typeboxAdapter2,
|
|
2825
|
+
valibotAdapter2
|
|
2826
|
+
];
|
|
2827
|
+
function extractSchemaOutputType(type, checker) {
|
|
2828
|
+
const adapter = findAdapter2(type, checker);
|
|
2829
|
+
if (!adapter) {
|
|
2830
|
+
return null;
|
|
2920
2831
|
}
|
|
2921
|
-
return
|
|
2832
|
+
return adapter.extractOutputType(type, checker);
|
|
2922
2833
|
}
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
const result = {
|
|
2926
|
-
schemas: new Map,
|
|
2927
|
-
errors: []
|
|
2928
|
-
};
|
|
2929
|
-
if (!fs4.existsSync(compiledJsPath)) {
|
|
2930
|
-
result.errors.push(`Compiled JS not found: ${compiledJsPath}`);
|
|
2931
|
-
return result;
|
|
2932
|
-
}
|
|
2933
|
-
return new Promise((resolve3) => {
|
|
2934
|
-
const child = spawn("node", ["-e", WORKER_SCRIPT, compiledJsPath, target], {
|
|
2935
|
-
timeout,
|
|
2936
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
2937
|
-
});
|
|
2938
|
-
let stdout = "";
|
|
2939
|
-
let stderr = "";
|
|
2940
|
-
child.stdout.on("data", (data) => {
|
|
2941
|
-
stdout += data.toString();
|
|
2942
|
-
});
|
|
2943
|
-
child.stderr.on("data", (data) => {
|
|
2944
|
-
stderr += data.toString();
|
|
2945
|
-
});
|
|
2946
|
-
child.on("close", (code) => {
|
|
2947
|
-
if (code !== 0) {
|
|
2948
|
-
result.errors.push(`Extraction process failed: ${stderr || `exit code ${code}`}`);
|
|
2949
|
-
resolve3(result);
|
|
2950
|
-
return;
|
|
2951
|
-
}
|
|
2952
|
-
try {
|
|
2953
|
-
const parsed = JSON.parse(stdout);
|
|
2954
|
-
if (!parsed.success) {
|
|
2955
|
-
result.errors.push(`Extraction failed: ${parsed.error}`);
|
|
2956
|
-
resolve3(result);
|
|
2957
|
-
return;
|
|
2958
|
-
}
|
|
2959
|
-
for (const item of parsed.results) {
|
|
2960
|
-
result.schemas.set(item.exportName, {
|
|
2961
|
-
exportName: item.exportName,
|
|
2962
|
-
vendor: item.vendor,
|
|
2963
|
-
outputSchema: item.outputSchema,
|
|
2964
|
-
inputSchema: item.inputSchema
|
|
2965
|
-
});
|
|
2966
|
-
}
|
|
2967
|
-
} catch (e) {
|
|
2968
|
-
result.errors.push(`Failed to parse extraction output: ${e}`);
|
|
2969
|
-
}
|
|
2970
|
-
resolve3(result);
|
|
2971
|
-
});
|
|
2972
|
-
child.on("error", (err) => {
|
|
2973
|
-
result.errors.push(`Subprocess error: ${err.message}`);
|
|
2974
|
-
resolve3(result);
|
|
2975
|
-
});
|
|
2976
|
-
});
|
|
2834
|
+
function getRegisteredAdapters() {
|
|
2835
|
+
return adapters;
|
|
2977
2836
|
}
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
if (!compiledPath) {
|
|
2981
|
-
return {
|
|
2982
|
-
schemas: new Map,
|
|
2983
|
-
errors: [`Could not find compiled JS for ${entryFile}. Build the project first.`]
|
|
2984
|
-
};
|
|
2985
|
-
}
|
|
2986
|
-
return extractStandardSchemas(compiledPath, options);
|
|
2837
|
+
function getSupportedLibraries() {
|
|
2838
|
+
return adapters.flatMap((a) => a.packages);
|
|
2987
2839
|
}
|
|
2988
2840
|
|
|
2989
2841
|
// src/analysis/schema-detection.ts
|
|
@@ -3012,8 +2864,8 @@ async function detectRuntimeSchemas(context) {
|
|
|
3012
2864
|
}
|
|
3013
2865
|
|
|
3014
2866
|
// src/analysis/history.ts
|
|
3015
|
-
import * as
|
|
3016
|
-
import * as
|
|
2867
|
+
import * as fs4 from "node:fs";
|
|
2868
|
+
import * as path4 from "node:path";
|
|
3017
2869
|
var HISTORY_DIR = ".doccov/history";
|
|
3018
2870
|
var RETENTION_DAYS = {
|
|
3019
2871
|
free: 7,
|
|
@@ -3051,24 +2903,24 @@ function computeSnapshot(spec, options) {
|
|
|
3051
2903
|
};
|
|
3052
2904
|
}
|
|
3053
2905
|
function saveSnapshot(snapshot, cwd) {
|
|
3054
|
-
const historyDir =
|
|
3055
|
-
if (!
|
|
3056
|
-
|
|
2906
|
+
const historyDir = path4.resolve(cwd, HISTORY_DIR);
|
|
2907
|
+
if (!fs4.existsSync(historyDir)) {
|
|
2908
|
+
fs4.mkdirSync(historyDir, { recursive: true });
|
|
3057
2909
|
}
|
|
3058
2910
|
const filename = getSnapshotFilename(new Date(snapshot.timestamp));
|
|
3059
|
-
const filepath =
|
|
3060
|
-
|
|
2911
|
+
const filepath = path4.join(historyDir, filename);
|
|
2912
|
+
fs4.writeFileSync(filepath, JSON.stringify(snapshot, null, 2));
|
|
3061
2913
|
}
|
|
3062
2914
|
function loadSnapshots(cwd) {
|
|
3063
|
-
const historyDir =
|
|
3064
|
-
if (!
|
|
2915
|
+
const historyDir = path4.resolve(cwd, HISTORY_DIR);
|
|
2916
|
+
if (!fs4.existsSync(historyDir)) {
|
|
3065
2917
|
return [];
|
|
3066
2918
|
}
|
|
3067
|
-
const files =
|
|
2919
|
+
const files = fs4.readdirSync(historyDir).filter((f) => f.endsWith(".json")).sort().reverse();
|
|
3068
2920
|
const snapshots = [];
|
|
3069
2921
|
for (const file of files) {
|
|
3070
2922
|
try {
|
|
3071
|
-
const content =
|
|
2923
|
+
const content = fs4.readFileSync(path4.join(historyDir, file), "utf-8");
|
|
3072
2924
|
snapshots.push(JSON.parse(content));
|
|
3073
2925
|
} catch {}
|
|
3074
2926
|
}
|
|
@@ -3108,15 +2960,15 @@ function formatDelta(delta) {
|
|
|
3108
2960
|
return "→0%";
|
|
3109
2961
|
}
|
|
3110
2962
|
function pruneHistory(cwd, keepCount = 100) {
|
|
3111
|
-
const historyDir =
|
|
3112
|
-
if (!
|
|
2963
|
+
const historyDir = path4.resolve(cwd, HISTORY_DIR);
|
|
2964
|
+
if (!fs4.existsSync(historyDir)) {
|
|
3113
2965
|
return 0;
|
|
3114
2966
|
}
|
|
3115
|
-
const files =
|
|
2967
|
+
const files = fs4.readdirSync(historyDir).filter((f) => f.endsWith(".json")).sort().reverse();
|
|
3116
2968
|
const toDelete = files.slice(keepCount);
|
|
3117
2969
|
for (const file of toDelete) {
|
|
3118
2970
|
try {
|
|
3119
|
-
|
|
2971
|
+
fs4.unlinkSync(path4.join(historyDir, file));
|
|
3120
2972
|
} catch {}
|
|
3121
2973
|
}
|
|
3122
2974
|
return toDelete.length;
|
|
@@ -3125,20 +2977,20 @@ function pruneByTier(cwd, tier) {
|
|
|
3125
2977
|
const retentionDays = RETENTION_DAYS[tier];
|
|
3126
2978
|
const cutoffDate = new Date;
|
|
3127
2979
|
cutoffDate.setDate(cutoffDate.getDate() - retentionDays);
|
|
3128
|
-
const historyDir =
|
|
3129
|
-
if (!
|
|
2980
|
+
const historyDir = path4.resolve(cwd, HISTORY_DIR);
|
|
2981
|
+
if (!fs4.existsSync(historyDir)) {
|
|
3130
2982
|
return 0;
|
|
3131
2983
|
}
|
|
3132
|
-
const files =
|
|
2984
|
+
const files = fs4.readdirSync(historyDir).filter((f) => f.endsWith(".json"));
|
|
3133
2985
|
let deleted = 0;
|
|
3134
2986
|
for (const file of files) {
|
|
3135
2987
|
try {
|
|
3136
|
-
const filepath =
|
|
3137
|
-
const content =
|
|
2988
|
+
const filepath = path4.join(historyDir, file);
|
|
2989
|
+
const content = fs4.readFileSync(filepath, "utf-8");
|
|
3138
2990
|
const snapshot = JSON.parse(content);
|
|
3139
2991
|
const snapshotDate = new Date(snapshot.timestamp);
|
|
3140
2992
|
if (snapshotDate < cutoffDate) {
|
|
3141
|
-
|
|
2993
|
+
fs4.unlinkSync(filepath);
|
|
3142
2994
|
deleted++;
|
|
3143
2995
|
}
|
|
3144
2996
|
} catch {}
|
|
@@ -3238,4 +3090,4 @@ function getExtendedTrend(spec, cwd, options) {
|
|
|
3238
3090
|
};
|
|
3239
3091
|
}
|
|
3240
3092
|
|
|
3241
|
-
export { computeHealth, isFixableDrift, generateFix, generateFixesForExport, mergeFixes, categorizeDrifts, ts, parseJSDocToPatch, applyPatchToJSDoc, serializeJSDoc, findJSDocLocation, applyEdits, createSourceFile, generateForgottenExportFixes, groupFixesByFile, applyForgottenExportFixes, previewForgottenExportFixes, isBuiltInIdentifier, detectExampleRuntimeErrors, parseAssertions, hasNonAssertionComments, detectExampleAssertionFailures, buildExportRegistry, computeDrift, computeExportDrift, buildDocCovSpec, DRIFT_CATEGORIES2 as DRIFT_CATEGORIES, DRIFT_CATEGORY_LABELS, DRIFT_CATEGORY_DESCRIPTIONS, categorizeDrift, groupDriftsByCategory, getDriftSummary, formatDriftSummaryLine, calculateAggregateCoverage, ensureSpecCoverage, getExportAnalysis, getExportScore, getExportDrift, getExportMissing, isExportFullyDocumented, generateReport, generateReportFromDocCov, loadCachedReport, saveReport, isCachedReportValid, renderApiSurface,
|
|
3093
|
+
export { computeHealth, isFixableDrift, generateFix, generateFixesForExport, mergeFixes, categorizeDrifts, ts, parseJSDocToPatch, applyPatchToJSDoc, serializeJSDoc, findJSDocLocation, applyEdits, createSourceFile, generateForgottenExportFixes, groupFixesByFile, applyForgottenExportFixes, previewForgottenExportFixes, isBuiltInIdentifier, detectExampleRuntimeErrors, parseAssertions, hasNonAssertionComments, detectExampleAssertionFailures, buildExportRegistry, computeDrift, computeExportDrift, buildDocCovSpec, DRIFT_CATEGORIES2 as DRIFT_CATEGORIES, DRIFT_CATEGORY_LABELS, DRIFT_CATEGORY_DESCRIPTIONS, categorizeDrift, groupDriftsByCategory, getDriftSummary, formatDriftSummaryLine, calculateAggregateCoverage, ensureSpecCoverage, getExportAnalysis, getExportScore, getExportDrift, getExportMissing, isExportFullyDocumented, generateReport, generateReportFromDocCov, loadCachedReport, saveReport, isCachedReportValid, renderApiSurface, extractSchemaOutputType, getRegisteredAdapters, getSupportedLibraries, extractSchemaType, findAdapter, isSchemaType, extractStandardSchemas, extractStandardSchemasFromProject, isStandardJSONSchema, resolveCompiledPath, detectRuntimeSchemas, HISTORY_DIR, RETENTION_DAYS, computeSnapshot, saveSnapshot, loadSnapshots, getTrend, renderSparkline, formatDelta, pruneHistory, pruneByTier, loadSnapshotsForDays, generateWeeklySummaries, getExtendedTrend };
|