@openpkg-ts/sdk 0.34.1 → 0.35.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 +38 -1
- package/dist/index.js +149 -30
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -33,6 +33,10 @@ interface ExtractOptions {
|
|
|
33
33
|
includePrivate?: boolean;
|
|
34
34
|
/** Configuration for resolving external package re-exports */
|
|
35
35
|
externals?: ExternalsConfig;
|
|
36
|
+
/** Max properties to serialize per object type (default: 20) */
|
|
37
|
+
maxProperties?: number;
|
|
38
|
+
/** Callback when properties are truncated */
|
|
39
|
+
onTruncation?: (typeName: string, actual: number, limit: number) => void;
|
|
36
40
|
}
|
|
37
41
|
interface ExtractResult {
|
|
38
42
|
spec: OpenPkg;
|
|
@@ -48,6 +52,12 @@ interface ExtractResult {
|
|
|
48
52
|
vendors: string[];
|
|
49
53
|
/** Any errors encountered during runtime extraction */
|
|
50
54
|
errors: string[];
|
|
55
|
+
/** Non-fatal warnings from extraction (e.g., individual schema failures) */
|
|
56
|
+
warnings: Array<{
|
|
57
|
+
code: string;
|
|
58
|
+
message: string;
|
|
59
|
+
exportName?: string;
|
|
60
|
+
}>;
|
|
51
61
|
/** Extraction method used: 'compiled' or 'direct-ts (runtime)' */
|
|
52
62
|
method?: string;
|
|
53
63
|
};
|
|
@@ -1165,6 +1175,10 @@ interface SerializerContext {
|
|
|
1165
1175
|
inTupleElement?: boolean;
|
|
1166
1176
|
/** Include private/protected class members (default: false) */
|
|
1167
1177
|
includePrivate?: boolean;
|
|
1178
|
+
/** Max properties to serialize per object type (default: 20) */
|
|
1179
|
+
maxProperties: number;
|
|
1180
|
+
/** Callback when properties are truncated */
|
|
1181
|
+
onTruncation?: (typeName: string, actual: number, limit: number) => void;
|
|
1168
1182
|
}
|
|
1169
1183
|
declare class TypeRegistry {
|
|
1170
1184
|
private types;
|
|
@@ -1296,11 +1310,34 @@ interface ExtractStandardSchemasOptions {
|
|
|
1296
1310
|
libraryOptions?: Record<string, unknown>;
|
|
1297
1311
|
}
|
|
1298
1312
|
/**
|
|
1313
|
+
* Warning codes for extraction diagnostics.
|
|
1314
|
+
*
|
|
1315
|
+
* - `SCHEMA_FAILED`: Standard Schema extraction failed (e.g., ~standard.jsonSchema.output() threw)
|
|
1316
|
+
* - `TYPEBOX_FAILED`: TypeBox schema sanitization failed
|
|
1317
|
+
* - `PARSE_FAILED`: Failed to parse subprocess JSON output
|
|
1318
|
+
* - `CLEANUP_FAILED`: Failed to delete temp worker script file
|
|
1319
|
+
* - `TSCONFIG_INVALID`: Could not parse tsconfig.json (uses defaults)
|
|
1320
|
+
*/
|
|
1321
|
+
type ExtractionWarningCode = "SCHEMA_FAILED" | "TYPEBOX_FAILED" | "PARSE_FAILED" | "CLEANUP_FAILED" | "TSCONFIG_INVALID" | "OUTPUT_TRUNCATED";
|
|
1322
|
+
/**
|
|
1323
|
+
* Warning from extraction process.
|
|
1324
|
+
* Captures non-fatal issues during schema extraction.
|
|
1325
|
+
*/
|
|
1326
|
+
interface ExtractionWarning {
|
|
1327
|
+
/** Warning type identifier */
|
|
1328
|
+
code: ExtractionWarningCode;
|
|
1329
|
+
/** Human-readable description */
|
|
1330
|
+
message: string;
|
|
1331
|
+
/** Export name if applicable */
|
|
1332
|
+
exportName?: string;
|
|
1333
|
+
}
|
|
1334
|
+
/**
|
|
1299
1335
|
* Result of Standard Schema extraction.
|
|
1300
1336
|
*/
|
|
1301
1337
|
interface StandardSchemaExtractionOutput {
|
|
1302
1338
|
schemas: Map<string, StandardSchemaExtractionResult>;
|
|
1303
1339
|
errors: string[];
|
|
1340
|
+
warnings: ExtractionWarning[];
|
|
1304
1341
|
}
|
|
1305
1342
|
/**
|
|
1306
1343
|
* Check if an object implements StandardJSONSchemaV1.
|
|
@@ -1719,4 +1756,4 @@ declare function normalizeMembers(members: SpecMember3[], options?: NormalizeOpt
|
|
|
1719
1756
|
import ts16 from "typescript";
|
|
1720
1757
|
declare function isExported(node: ts16.Node): boolean;
|
|
1721
1758
|
declare function getNodeName(node: ts16.Node): string | undefined;
|
|
1722
|
-
export { zodAdapter, withDescription2 as withDescription, valibotAdapter, typeboxAdapter, toSearchIndexJSON, toSearchIndex2 as toSearchIndex, toReactString, toReact, toPagefindRecords2 as toPagefindRecords, toNavigation2 as toNavigation, toMarkdown2 as toMarkdown, toJSONString, toJSON2 as toJSON, toHTML2 as toHTML, toFumadocsMetaJSON, toDocusaurusSidebarJS, toAlgoliaRecords2 as toAlgoliaRecords, sortByName, serializeVariable, serializeTypeAlias, serializeInterface, serializeFunctionExport, serializeEnum, serializeClass, schemasAreEqual, schemaIsAny, resolveTypeRef, resolveExportTarget, resolveCompiledPath, registerReferencedTypes, registerAdapter, recommendSemverBump, query, normalizeType, normalizeSchema, normalizeMembers, normalizeExport, mergeConfig, loadSpec, loadConfig, listExports, isTypeReference, isTypeOnlyExport, isSymbolDeprecated, isStandardJSONSchema, isSchemaType, isPureRefSchema, isProperty, isPrimitiveName, isMethod, isExported, isBuiltinGeneric, isAnonymous, hasDeprecatedTag, groupByVisibility, getTypeOrigin, getSourceLocation, getProperties, getParamDescription, getNonNullableType, getNodeName, getMethods, getMemberBadges, getJSDocComment, getExport2 as getExport, getDeprecationMessage, toMarkdown2 as generateDocs, formatTypeParameters, formatSchema, formatReturnType, formatParameters, formatMappedType, formatConditionalType, formatBadges, findMissingParamDocs, findDiscriminatorProperty, findAdapter, filterSpec, extractTypeParameters, extractStandardSchemasFromTs, extractStandardSchemasFromProject, extractStandardSchemas, extractSpec, extractSchemaType, extractParameters, extract, exportToMarkdown, ensureNonEmptySchema, diffSpec2 as diffSpecs, diffSpec, detectTsRuntime, deduplicateSchemas, createProgram, createDocs, categorizeBreakingChanges, calculateNextVersion, buildSignatureString, buildSchema, arktypeAdapter, analyzeSpec, TypeRegistry, TypeReference2 as TypeReference, TsRuntime, StandardSchemaExtractionResult, StandardSchemaExtractionOutput, StandardJSONSchemaV1, StandardJSONSchemaTarget, StandardJSONSchemaOptions, SpecMappedType, SpecDiff, SpecDiagnostics, SpecConditionalType, SkippedExportDetail, SimplifiedSpec, SimplifiedSignature, SimplifiedReturn, SimplifiedParameter, SimplifiedMember, SimplifiedExport, SimplifiedExample, SerializerContext, SemverRecommendation, SemverBump, SearchRecord, SearchOptions, SearchIndex, SchemaExtractionResult, SchemaAdapter, ReactLayoutOptions, QueryBuilder, ProjectExtractionOutput, ProjectExtractionInfo, ProgramResult, ProgramOptions, PagefindRecord, OpenpkgConfig, NormalizeOptions, NavOptions, NavItem, NavGroup, NavFormat, MemberChangeInfo, MarkdownOptions, LoadOptions, ListExportsResult, ListExportsOptions, JSONSchema, JSONOptions, HTMLOptions, GroupBy, GetExportResult, GetExportOptions, GenericNav, FumadocsMetaItem, FumadocsMeta, FormatSchemaOptions, ForgottenExport, FilterResult, FilterCriteria, ExtractStandardSchemasOptions, ExtractResult, ExtractOptions, ExtractFromProjectOptions, ExternalsConfig, ExportVerification, ExportTracker, ExportMarkdownOptions, ExportItem, DocusaurusSidebarItem, DocusaurusSidebar, DocsInstance, DiagnosticItem, Diagnostic, CategorizedBreaking, CacheManagerOptions, CacheManager, CONFIG_FILENAME, BreakingSeverity, BUILTIN_TYPE_SCHEMAS, AlgoliaRecord, ARRAY_PROTOTYPE_METHODS };
|
|
1759
|
+
export { zodAdapter, withDescription2 as withDescription, valibotAdapter, typeboxAdapter, toSearchIndexJSON, toSearchIndex2 as toSearchIndex, toReactString, toReact, toPagefindRecords2 as toPagefindRecords, toNavigation2 as toNavigation, toMarkdown2 as toMarkdown, toJSONString, toJSON2 as toJSON, toHTML2 as toHTML, toFumadocsMetaJSON, toDocusaurusSidebarJS, toAlgoliaRecords2 as toAlgoliaRecords, sortByName, serializeVariable, serializeTypeAlias, serializeInterface, serializeFunctionExport, serializeEnum, serializeClass, schemasAreEqual, schemaIsAny, resolveTypeRef, resolveExportTarget, resolveCompiledPath, registerReferencedTypes, registerAdapter, recommendSemverBump, query, normalizeType, normalizeSchema, normalizeMembers, normalizeExport, mergeConfig, loadSpec, loadConfig, listExports, isTypeReference, isTypeOnlyExport, isSymbolDeprecated, isStandardJSONSchema, isSchemaType, isPureRefSchema, isProperty, isPrimitiveName, isMethod, isExported, isBuiltinGeneric, isAnonymous, hasDeprecatedTag, groupByVisibility, getTypeOrigin, getSourceLocation, getProperties, getParamDescription, getNonNullableType, getNodeName, getMethods, getMemberBadges, getJSDocComment, getExport2 as getExport, getDeprecationMessage, toMarkdown2 as generateDocs, formatTypeParameters, formatSchema, formatReturnType, formatParameters, formatMappedType, formatConditionalType, formatBadges, findMissingParamDocs, findDiscriminatorProperty, findAdapter, filterSpec, extractTypeParameters, extractStandardSchemasFromTs, extractStandardSchemasFromProject, extractStandardSchemas, extractSpec, extractSchemaType, extractParameters, extract, exportToMarkdown, ensureNonEmptySchema, diffSpec2 as diffSpecs, diffSpec, detectTsRuntime, deduplicateSchemas, createProgram, createDocs, categorizeBreakingChanges, calculateNextVersion, buildSignatureString, buildSchema, arktypeAdapter, analyzeSpec, TypeRegistry, TypeReference2 as TypeReference, TsRuntime, StandardSchemaExtractionResult, StandardSchemaExtractionOutput, StandardJSONSchemaV1, StandardJSONSchemaTarget, StandardJSONSchemaOptions, SpecMappedType, SpecDiff, SpecDiagnostics, SpecConditionalType, SkippedExportDetail, SimplifiedSpec, SimplifiedSignature, SimplifiedReturn, SimplifiedParameter, SimplifiedMember, SimplifiedExport, SimplifiedExample, SerializerContext, SemverRecommendation, SemverBump, SearchRecord, SearchOptions, SearchIndex, SchemaExtractionResult, SchemaAdapter, ReactLayoutOptions, QueryBuilder, ProjectExtractionOutput, ProjectExtractionInfo, ProgramResult, ProgramOptions, PagefindRecord, OpenpkgConfig, NormalizeOptions, NavOptions, NavItem, NavGroup, NavFormat, MemberChangeInfo, MarkdownOptions, LoadOptions, ListExportsResult, ListExportsOptions, JSONSchema, JSONOptions, HTMLOptions, GroupBy, GetExportResult, GetExportOptions, GenericNav, FumadocsMetaItem, FumadocsMeta, FormatSchemaOptions, ForgottenExport, FilterResult, FilterCriteria, ExtractionWarningCode, ExtractionWarning, ExtractStandardSchemasOptions, ExtractResult, ExtractOptions, ExtractFromProjectOptions, ExternalsConfig, ExportVerification, ExportTracker, ExportMarkdownOptions, ExportItem, DocusaurusSidebarItem, DocusaurusSidebar, DocsInstance, DiagnosticItem, Diagnostic, CategorizedBreaking, CacheManagerOptions, CacheManager, CONFIG_FILENAME, BreakingSeverity, BUILTIN_TYPE_SCHEMAS, AlgoliaRecord, ARRAY_PROTOTYPE_METHODS };
|
package/dist/index.js
CHANGED
|
@@ -45,7 +45,10 @@ function loadConfig(cwd) {
|
|
|
45
45
|
try {
|
|
46
46
|
const content = fs.readFileSync(configPath, "utf-8");
|
|
47
47
|
return JSON.parse(content);
|
|
48
|
-
} catch {
|
|
48
|
+
} catch (err) {
|
|
49
|
+
const msg = err instanceof SyntaxError ? err.message : String(err);
|
|
50
|
+
console.warn(`Warning: Invalid JSON in ${CONFIG_FILENAME}: ${msg}`);
|
|
51
|
+
}
|
|
49
52
|
}
|
|
50
53
|
const pkgPath = path.join(cwd, "package.json");
|
|
51
54
|
if (fs.existsSync(pkgPath)) {
|
|
@@ -55,7 +58,10 @@ function loadConfig(cwd) {
|
|
|
55
58
|
if (pkg.openpkg) {
|
|
56
59
|
return pkg.openpkg;
|
|
57
60
|
}
|
|
58
|
-
} catch {
|
|
61
|
+
} catch (err) {
|
|
62
|
+
const msg = err instanceof SyntaxError ? err.message : String(err);
|
|
63
|
+
console.warn(`Warning: Invalid JSON in package.json: ${msg}`);
|
|
64
|
+
}
|
|
59
65
|
}
|
|
60
66
|
return null;
|
|
61
67
|
}
|
|
@@ -2529,9 +2535,11 @@ function buildSchemaInternal(type, checker, ctx) {
|
|
|
2529
2535
|
function buildFunctionSchema(callSignatures, checker, ctx) {
|
|
2530
2536
|
const buildSignatures = () => {
|
|
2531
2537
|
const signatures = callSignatures.map((sig) => {
|
|
2532
|
-
const params = sig.getParameters().
|
|
2533
|
-
const paramType = checker.getTypeOfSymbolAtLocation(param, param.valueDeclaration);
|
|
2538
|
+
const params = sig.getParameters().flatMap((param) => {
|
|
2534
2539
|
const decl = param.valueDeclaration;
|
|
2540
|
+
if (!decl)
|
|
2541
|
+
return [];
|
|
2542
|
+
const paramType = checker.getTypeOfSymbolAtLocation(param, decl);
|
|
2535
2543
|
const isOptional = !!decl?.questionToken || !!decl?.initializer;
|
|
2536
2544
|
return {
|
|
2537
2545
|
name: param.getName(),
|
|
@@ -2712,7 +2720,9 @@ function extractParameters(signature, ctx) {
|
|
|
2712
2720
|
const jsdocTags = signatureDecl ? ts4.getJSDocTags(signatureDecl) : [];
|
|
2713
2721
|
for (const param of signature.getParameters()) {
|
|
2714
2722
|
const decl = param.valueDeclaration;
|
|
2715
|
-
|
|
2723
|
+
if (!decl)
|
|
2724
|
+
continue;
|
|
2725
|
+
const type = checker.getTypeOfSymbolAtLocation(param, decl);
|
|
2716
2726
|
if (decl && ts4.isObjectBindingPattern(decl.name)) {
|
|
2717
2727
|
const expandedParams = expandBindingPattern(decl, type, jsdocTags, ctx);
|
|
2718
2728
|
result.push(...expandedParams);
|
|
@@ -2857,7 +2867,12 @@ function registerReferencedTypes(type, ctx, depth = 0) {
|
|
|
2857
2867
|
}
|
|
2858
2868
|
if (type.flags & ts4.TypeFlags.Object) {
|
|
2859
2869
|
const props = type.getProperties();
|
|
2860
|
-
|
|
2870
|
+
const limit = ctx.maxProperties;
|
|
2871
|
+
if (props.length > limit && ctx.onTruncation) {
|
|
2872
|
+
const typeName = type.getSymbol()?.getName() ?? "anonymous";
|
|
2873
|
+
ctx.onTruncation(typeName, props.length, limit);
|
|
2874
|
+
}
|
|
2875
|
+
for (const prop of props.slice(0, limit)) {
|
|
2861
2876
|
const propType = checker.getTypeOfSymbol(prop);
|
|
2862
2877
|
registerReferencedTypes(propType, ctx, depth + 1);
|
|
2863
2878
|
}
|
|
@@ -3056,7 +3071,12 @@ class TypeRegistry {
|
|
|
3056
3071
|
}
|
|
3057
3072
|
const props = {};
|
|
3058
3073
|
const required = [];
|
|
3059
|
-
|
|
3074
|
+
const limit = ctx.maxProperties;
|
|
3075
|
+
if (properties.length > limit && ctx.onTruncation) {
|
|
3076
|
+
const typeName = type.getSymbol()?.getName() ?? "anonymous";
|
|
3077
|
+
ctx.onTruncation(typeName, properties.length, limit);
|
|
3078
|
+
}
|
|
3079
|
+
for (const prop of properties.slice(0, limit)) {
|
|
3060
3080
|
const propName = prop.getName();
|
|
3061
3081
|
if (propName.startsWith("_"))
|
|
3062
3082
|
continue;
|
|
@@ -3090,7 +3110,9 @@ function createContext(program, sourceFile, options = {}) {
|
|
|
3090
3110
|
typeRegistry: new TypeRegistry,
|
|
3091
3111
|
exportedIds: new Set,
|
|
3092
3112
|
visitedTypes: new Set,
|
|
3093
|
-
includePrivate: options.includePrivate ?? false
|
|
3113
|
+
includePrivate: options.includePrivate ?? false,
|
|
3114
|
+
maxProperties: options.maxProperties ?? 20,
|
|
3115
|
+
onTruncation: options.onTruncation
|
|
3094
3116
|
};
|
|
3095
3117
|
}
|
|
3096
3118
|
function getInheritedMembers(classType, ownMemberNames, ctx, isStatic = false) {
|
|
@@ -3098,7 +3120,12 @@ function getInheritedMembers(classType, ownMemberNames, ctx, isStatic = false) {
|
|
|
3098
3120
|
const inherited = [];
|
|
3099
3121
|
const visited = new Set;
|
|
3100
3122
|
const inheritedNames = new Set;
|
|
3101
|
-
|
|
3123
|
+
let typeToWalk = classType;
|
|
3124
|
+
if (isStatic) {
|
|
3125
|
+
const symbol = classType.getSymbol();
|
|
3126
|
+
const valueDecl = symbol?.valueDeclaration;
|
|
3127
|
+
typeToWalk = symbol && valueDecl ? checker.getTypeOfSymbolAtLocation(symbol, valueDecl) : undefined;
|
|
3128
|
+
}
|
|
3102
3129
|
if (!typeToWalk)
|
|
3103
3130
|
return inherited;
|
|
3104
3131
|
walkBaseTypes(typeToWalk, ownMemberNames, inherited, inheritedNames, visited, ctx, isStatic);
|
|
@@ -3249,6 +3276,8 @@ function serializeClass(node, ctx) {
|
|
|
3249
3276
|
methodsByName.set(methodMember.name, methodMember);
|
|
3250
3277
|
} else {
|
|
3251
3278
|
const existing = methodsByName.get(methodMember.name);
|
|
3279
|
+
if (!existing)
|
|
3280
|
+
continue;
|
|
3252
3281
|
if (!existing.description && methodMember.description) {
|
|
3253
3282
|
existing.description = methodMember.description;
|
|
3254
3283
|
}
|
|
@@ -4761,6 +4790,7 @@ import { spawn, spawnSync } from "node:child_process";
|
|
|
4761
4790
|
import * as fs5 from "node:fs";
|
|
4762
4791
|
import * as os from "node:os";
|
|
4763
4792
|
import * as path5 from "node:path";
|
|
4793
|
+
var MAX_BUFFER_SIZE = 10 * 1024 * 1024;
|
|
4764
4794
|
function isStandardJSONSchema(obj) {
|
|
4765
4795
|
if (typeof obj !== "object" || obj === null)
|
|
4766
4796
|
return false;
|
|
@@ -4860,6 +4890,7 @@ async function extract() {
|
|
|
4860
4890
|
const absPath = path.resolve(modulePath);
|
|
4861
4891
|
const mod = await import(pathToFileURL(absPath).href);
|
|
4862
4892
|
const results = [];
|
|
4893
|
+
const warnings = [];
|
|
4863
4894
|
|
|
4864
4895
|
// Build exports map - handle both ESM and CJS (where exports are in mod.default)
|
|
4865
4896
|
const exports = {};
|
|
@@ -4892,7 +4923,7 @@ async function extract() {
|
|
|
4892
4923
|
inputSchema
|
|
4893
4924
|
});
|
|
4894
4925
|
} catch (e) {
|
|
4895
|
-
|
|
4926
|
+
warnings.push({ code: 'SCHEMA_FAILED', message: String(e), exportName: name });
|
|
4896
4927
|
}
|
|
4897
4928
|
continue;
|
|
4898
4929
|
}
|
|
@@ -4906,15 +4937,15 @@ async function extract() {
|
|
|
4906
4937
|
outputSchema: sanitizeTypeBoxSchema(value)
|
|
4907
4938
|
});
|
|
4908
4939
|
} catch (e) {
|
|
4909
|
-
|
|
4940
|
+
warnings.push({ code: 'TYPEBOX_FAILED', message: String(e), exportName: name });
|
|
4910
4941
|
}
|
|
4911
4942
|
continue;
|
|
4912
4943
|
}
|
|
4913
4944
|
}
|
|
4914
4945
|
|
|
4915
|
-
console.log(JSON.stringify({ success: true, results }));
|
|
4946
|
+
console.log(JSON.stringify({ success: true, results, warnings }));
|
|
4916
4947
|
} catch (e) {
|
|
4917
|
-
console.log(JSON.stringify({ success: false, error: e.message }));
|
|
4948
|
+
console.log(JSON.stringify({ success: false, error: e.message, warnings: [] }));
|
|
4918
4949
|
}
|
|
4919
4950
|
}
|
|
4920
4951
|
|
|
@@ -4946,6 +4977,7 @@ async function extract() {
|
|
|
4946
4977
|
const absPath = path.resolve(modulePath);
|
|
4947
4978
|
const mod = await import(pathToFileURL(absPath).href);
|
|
4948
4979
|
const results: Array<{exportName: string; vendor: string; outputSchema: unknown; inputSchema?: unknown}> = [];
|
|
4980
|
+
const warnings: Array<{code: string; message: string; exportName?: string}> = [];
|
|
4949
4981
|
|
|
4950
4982
|
// Build exports map
|
|
4951
4983
|
const exports: Record<string, unknown> = {};
|
|
@@ -4974,7 +5006,9 @@ async function extract() {
|
|
|
4974
5006
|
const outputSchema = (jsonSchema.output as Function)(options);
|
|
4975
5007
|
const inputSchema = typeof jsonSchema.input === 'function' ? (jsonSchema.input as Function)(options) : undefined;
|
|
4976
5008
|
results.push({ exportName: name, vendor: std.vendor as string, outputSchema, inputSchema });
|
|
4977
|
-
} catch {
|
|
5009
|
+
} catch (e) {
|
|
5010
|
+
warnings.push({ code: 'SCHEMA_FAILED', message: String(e), exportName: name });
|
|
5011
|
+
}
|
|
4978
5012
|
continue;
|
|
4979
5013
|
}
|
|
4980
5014
|
}
|
|
@@ -4983,13 +5017,15 @@ async function extract() {
|
|
|
4983
5017
|
if (isTypeBoxSchema(value)) {
|
|
4984
5018
|
try {
|
|
4985
5019
|
results.push({ exportName: name, vendor: 'typebox', outputSchema: sanitizeTypeBoxSchema(value) });
|
|
4986
|
-
} catch {
|
|
5020
|
+
} catch (e) {
|
|
5021
|
+
warnings.push({ code: 'TYPEBOX_FAILED', message: String(e), exportName: name });
|
|
5022
|
+
}
|
|
4987
5023
|
}
|
|
4988
5024
|
}
|
|
4989
5025
|
|
|
4990
|
-
console.log(JSON.stringify({ success: true, results }));
|
|
5026
|
+
console.log(JSON.stringify({ success: true, results, warnings }));
|
|
4991
5027
|
} catch (e) {
|
|
4992
|
-
console.log(JSON.stringify({ success: false, error: (e as Error).message }));
|
|
5028
|
+
console.log(JSON.stringify({ success: false, error: (e as Error).message, warnings: [] }));
|
|
4993
5029
|
}
|
|
4994
5030
|
}
|
|
4995
5031
|
|
|
@@ -4999,7 +5035,8 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
|
|
|
4999
5035
|
const { timeout = 1e4, target = "draft-2020-12", libraryOptions } = options;
|
|
5000
5036
|
const result = {
|
|
5001
5037
|
schemas: new Map,
|
|
5002
|
-
errors: []
|
|
5038
|
+
errors: [],
|
|
5039
|
+
warnings: []
|
|
5003
5040
|
};
|
|
5004
5041
|
const runtime = detectTsRuntime();
|
|
5005
5042
|
if (!runtime) {
|
|
@@ -5024,16 +5061,32 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
|
|
|
5024
5061
|
});
|
|
5025
5062
|
let stdout = "";
|
|
5026
5063
|
let stderr = "";
|
|
5064
|
+
let stdoutTruncated = false;
|
|
5065
|
+
let stderrTruncated = false;
|
|
5027
5066
|
child.stdout.on("data", (data) => {
|
|
5028
|
-
stdout
|
|
5067
|
+
if (stdout.length < MAX_BUFFER_SIZE) {
|
|
5068
|
+
const chunk = data.toString();
|
|
5069
|
+
stdout += chunk.slice(0, MAX_BUFFER_SIZE - stdout.length);
|
|
5070
|
+
if (stdout.length >= MAX_BUFFER_SIZE)
|
|
5071
|
+
stdoutTruncated = true;
|
|
5072
|
+
}
|
|
5029
5073
|
});
|
|
5030
5074
|
child.stderr.on("data", (data) => {
|
|
5031
|
-
stderr
|
|
5075
|
+
if (stderr.length < MAX_BUFFER_SIZE) {
|
|
5076
|
+
const chunk = data.toString();
|
|
5077
|
+
stderr += chunk.slice(0, MAX_BUFFER_SIZE - stderr.length);
|
|
5078
|
+
if (stderr.length >= MAX_BUFFER_SIZE)
|
|
5079
|
+
stderrTruncated = true;
|
|
5080
|
+
}
|
|
5032
5081
|
});
|
|
5033
5082
|
child.on("close", (code) => {
|
|
5034
5083
|
try {
|
|
5035
5084
|
fs5.unlinkSync(workerPath);
|
|
5036
|
-
} catch {
|
|
5085
|
+
} catch (cleanupErr) {
|
|
5086
|
+
if (cleanupErr?.code !== "ENOENT") {
|
|
5087
|
+
result.warnings.push({ code: "CLEANUP_FAILED", message: String(cleanupErr) });
|
|
5088
|
+
}
|
|
5089
|
+
}
|
|
5037
5090
|
if (code !== 0) {
|
|
5038
5091
|
result.errors.push(`Extraction failed (${runtime.name}): ${stderr || `exit code ${code}`}`);
|
|
5039
5092
|
resolve2(result);
|
|
@@ -5054,15 +5107,34 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
|
|
|
5054
5107
|
inputSchema: item.inputSchema
|
|
5055
5108
|
});
|
|
5056
5109
|
}
|
|
5110
|
+
if (Array.isArray(parsed.warnings)) {
|
|
5111
|
+
for (const w of parsed.warnings) {
|
|
5112
|
+
result.warnings.push({
|
|
5113
|
+
code: w.code,
|
|
5114
|
+
message: w.message,
|
|
5115
|
+
exportName: w.exportName
|
|
5116
|
+
});
|
|
5117
|
+
}
|
|
5118
|
+
}
|
|
5057
5119
|
} catch (e) {
|
|
5058
5120
|
result.errors.push(`Failed to parse extraction output: ${e}`);
|
|
5059
5121
|
}
|
|
5122
|
+
if (stdoutTruncated) {
|
|
5123
|
+
result.warnings.push({ code: "OUTPUT_TRUNCATED", message: "stdout exceeded 10MB buffer limit" });
|
|
5124
|
+
}
|
|
5125
|
+
if (stderrTruncated) {
|
|
5126
|
+
result.warnings.push({ code: "OUTPUT_TRUNCATED", message: "stderr exceeded 10MB buffer limit" });
|
|
5127
|
+
}
|
|
5060
5128
|
resolve2(result);
|
|
5061
5129
|
});
|
|
5062
5130
|
child.on("error", (err) => {
|
|
5063
5131
|
try {
|
|
5064
5132
|
fs5.unlinkSync(workerPath);
|
|
5065
|
-
} catch {
|
|
5133
|
+
} catch (cleanupErr) {
|
|
5134
|
+
if (cleanupErr?.code !== "ENOENT") {
|
|
5135
|
+
result.warnings.push({ code: "CLEANUP_FAILED", message: String(cleanupErr) });
|
|
5136
|
+
}
|
|
5137
|
+
}
|
|
5066
5138
|
result.errors.push(`Subprocess error: ${err.message}`);
|
|
5067
5139
|
resolve2(result);
|
|
5068
5140
|
});
|
|
@@ -5070,7 +5142,11 @@ async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
|
|
|
5070
5142
|
} catch (e) {
|
|
5071
5143
|
try {
|
|
5072
5144
|
fs5.unlinkSync(workerPath);
|
|
5073
|
-
} catch {
|
|
5145
|
+
} catch (cleanupErr) {
|
|
5146
|
+
if (cleanupErr?.code !== "ENOENT") {
|
|
5147
|
+
result.warnings.push({ code: "CLEANUP_FAILED", message: String(cleanupErr) });
|
|
5148
|
+
}
|
|
5149
|
+
}
|
|
5074
5150
|
result.errors.push(`Failed to create worker script: ${e}`);
|
|
5075
5151
|
return result;
|
|
5076
5152
|
}
|
|
@@ -5087,7 +5163,7 @@ function readTsconfigOutDir(baseDir) {
|
|
|
5087
5163
|
if (tsconfig.compilerOptions?.outDir) {
|
|
5088
5164
|
return tsconfig.compilerOptions.outDir.replace(/^\.\//, "");
|
|
5089
5165
|
}
|
|
5090
|
-
} catch {}
|
|
5166
|
+
} catch (_e) {}
|
|
5091
5167
|
return null;
|
|
5092
5168
|
}
|
|
5093
5169
|
function resolveCompiledPath(tsPath, baseDir) {
|
|
@@ -5131,7 +5207,8 @@ async function extractStandardSchemas(compiledJsPath, options = {}) {
|
|
|
5131
5207
|
const { timeout = 1e4, target = "draft-2020-12", libraryOptions } = options;
|
|
5132
5208
|
const result = {
|
|
5133
5209
|
schemas: new Map,
|
|
5134
|
-
errors: []
|
|
5210
|
+
errors: [],
|
|
5211
|
+
warnings: []
|
|
5135
5212
|
};
|
|
5136
5213
|
if (!fs5.existsSync(compiledJsPath)) {
|
|
5137
5214
|
result.errors.push(`Compiled JS not found: ${compiledJsPath}`);
|
|
@@ -5145,11 +5222,23 @@ async function extractStandardSchemas(compiledJsPath, options = {}) {
|
|
|
5145
5222
|
});
|
|
5146
5223
|
let stdout = "";
|
|
5147
5224
|
let stderr = "";
|
|
5225
|
+
let stdoutTruncated = false;
|
|
5226
|
+
let stderrTruncated = false;
|
|
5148
5227
|
child.stdout.on("data", (data) => {
|
|
5149
|
-
stdout
|
|
5228
|
+
if (stdout.length < MAX_BUFFER_SIZE) {
|
|
5229
|
+
const chunk = data.toString();
|
|
5230
|
+
stdout += chunk.slice(0, MAX_BUFFER_SIZE - stdout.length);
|
|
5231
|
+
if (stdout.length >= MAX_BUFFER_SIZE)
|
|
5232
|
+
stdoutTruncated = true;
|
|
5233
|
+
}
|
|
5150
5234
|
});
|
|
5151
5235
|
child.stderr.on("data", (data) => {
|
|
5152
|
-
stderr
|
|
5236
|
+
if (stderr.length < MAX_BUFFER_SIZE) {
|
|
5237
|
+
const chunk = data.toString();
|
|
5238
|
+
stderr += chunk.slice(0, MAX_BUFFER_SIZE - stderr.length);
|
|
5239
|
+
if (stderr.length >= MAX_BUFFER_SIZE)
|
|
5240
|
+
stderrTruncated = true;
|
|
5241
|
+
}
|
|
5153
5242
|
});
|
|
5154
5243
|
child.on("close", (code) => {
|
|
5155
5244
|
if (code !== 0) {
|
|
@@ -5172,9 +5261,24 @@ async function extractStandardSchemas(compiledJsPath, options = {}) {
|
|
|
5172
5261
|
inputSchema: item.inputSchema
|
|
5173
5262
|
});
|
|
5174
5263
|
}
|
|
5264
|
+
if (Array.isArray(parsed.warnings)) {
|
|
5265
|
+
for (const w of parsed.warnings) {
|
|
5266
|
+
result.warnings.push({
|
|
5267
|
+
code: w.code,
|
|
5268
|
+
message: w.message,
|
|
5269
|
+
exportName: w.exportName
|
|
5270
|
+
});
|
|
5271
|
+
}
|
|
5272
|
+
}
|
|
5175
5273
|
} catch (e) {
|
|
5176
5274
|
result.errors.push(`Failed to parse extraction output: ${e}`);
|
|
5177
5275
|
}
|
|
5276
|
+
if (stdoutTruncated) {
|
|
5277
|
+
result.warnings.push({ code: "OUTPUT_TRUNCATED", message: "stdout exceeded 10MB buffer limit" });
|
|
5278
|
+
}
|
|
5279
|
+
if (stderrTruncated) {
|
|
5280
|
+
result.warnings.push({ code: "OUTPUT_TRUNCATED", message: "stderr exceeded 10MB buffer limit" });
|
|
5281
|
+
}
|
|
5178
5282
|
resolve2(result);
|
|
5179
5283
|
});
|
|
5180
5284
|
child.on("error", (err) => {
|
|
@@ -5210,7 +5314,8 @@ async function extractStandardSchemasFromProject(entryFile, baseDir, options = {
|
|
|
5210
5314
|
const hint = isTypeScript && !runtime ? " Install bun, tsx, or ts-node for direct TS execution." : "";
|
|
5211
5315
|
return {
|
|
5212
5316
|
schemas: new Map,
|
|
5213
|
-
errors: [`Could not find compiled JS for ${entryFile}.${hint}`]
|
|
5317
|
+
errors: [`Could not find compiled JS for ${entryFile}.${hint}`],
|
|
5318
|
+
warnings: []
|
|
5214
5319
|
};
|
|
5215
5320
|
}
|
|
5216
5321
|
|
|
@@ -5796,7 +5901,9 @@ async function extract(options) {
|
|
|
5796
5901
|
ignore,
|
|
5797
5902
|
onProgress,
|
|
5798
5903
|
isDtsSource,
|
|
5799
|
-
includePrivate
|
|
5904
|
+
includePrivate,
|
|
5905
|
+
maxProperties,
|
|
5906
|
+
onTruncation
|
|
5800
5907
|
} = options;
|
|
5801
5908
|
const diagnostics = [];
|
|
5802
5909
|
let exports = [];
|
|
@@ -5836,7 +5943,9 @@ async function extract(options) {
|
|
|
5836
5943
|
maxTypeDepth,
|
|
5837
5944
|
maxExternalTypeDepth,
|
|
5838
5945
|
resolveExternalTypes,
|
|
5839
|
-
includePrivate
|
|
5946
|
+
includePrivate,
|
|
5947
|
+
maxProperties,
|
|
5948
|
+
onTruncation
|
|
5840
5949
|
});
|
|
5841
5950
|
ctx.exportedIds = exportedIds;
|
|
5842
5951
|
const filteredSymbols = exportedSymbols.filter((s) => shouldIncludeExport(s.getName(), only, ignore));
|
|
@@ -5845,6 +5954,8 @@ async function extract(options) {
|
|
|
5845
5954
|
const symbol = filteredSymbols[i];
|
|
5846
5955
|
const exportName = symbol.getName();
|
|
5847
5956
|
const tracker = exportTracker.get(exportName);
|
|
5957
|
+
if (!tracker)
|
|
5958
|
+
continue;
|
|
5848
5959
|
onProgress?.(i + 1, total, exportName);
|
|
5849
5960
|
if (i > 0 && i % YIELD_BATCH_SIZE === 0) {
|
|
5850
5961
|
await new Promise((r) => setImmediate(r));
|
|
@@ -5976,6 +6087,7 @@ async function extract(options) {
|
|
|
5976
6087
|
merged: mergeResult.merged,
|
|
5977
6088
|
vendors: [...new Set([...runtimeResult.schemas.values()].map((s) => s.vendor))],
|
|
5978
6089
|
errors: runtimeResult.errors,
|
|
6090
|
+
warnings: runtimeResult.warnings,
|
|
5979
6091
|
method
|
|
5980
6092
|
};
|
|
5981
6093
|
}
|
|
@@ -5986,6 +6098,13 @@ async function extract(options) {
|
|
|
5986
6098
|
code: "RUNTIME_SCHEMA_ERROR"
|
|
5987
6099
|
});
|
|
5988
6100
|
}
|
|
6101
|
+
for (const warning of runtimeResult.warnings) {
|
|
6102
|
+
diagnostics.push({
|
|
6103
|
+
message: `Schema extraction skipped${warning.exportName ? ` (${warning.exportName})` : ""}: ${warning.message}`,
|
|
6104
|
+
severity: "warning",
|
|
6105
|
+
code: warning.code
|
|
6106
|
+
});
|
|
6107
|
+
}
|
|
5989
6108
|
}
|
|
5990
6109
|
const normalizedExports = exports.map((exp) => normalizeExport(exp, { dialect: "draft-2020-12" }));
|
|
5991
6110
|
const normalizedTypes = types.map((t) => normalizeType(t, { dialect: "draft-2020-12" }));
|