@openpkg-ts/extract 0.18.3 → 0.20.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/bin/tspec.js
CHANGED
|
@@ -680,13 +680,27 @@ function getJSDocComment(node) {
|
|
|
680
680
|
const jsDocTags = ts3.getJSDocTags(node);
|
|
681
681
|
const tags = jsDocTags.map((tag) => {
|
|
682
682
|
const rawText = typeof tag.comment === "string" ? tag.comment : ts3.getTextOfJSDocComment(tag.comment) ?? "";
|
|
683
|
-
let text = rawText;
|
|
684
683
|
if (tag.tagName.text === "param") {
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
684
|
+
const paramTag = tag;
|
|
685
|
+
const paramName = paramTag.name?.getText() ?? "";
|
|
686
|
+
const description2 = stripParamSeparator(rawText);
|
|
687
|
+
const text = description2 ? `${paramName} - ${description2}` : paramName;
|
|
688
|
+
const typeExpr = paramTag.typeExpression;
|
|
689
|
+
const type = typeExpr ? typeExpr.type.getText() : undefined;
|
|
690
|
+
const param = { name: paramName };
|
|
691
|
+
if (type)
|
|
692
|
+
param.type = type;
|
|
693
|
+
if (description2)
|
|
694
|
+
param.description = description2;
|
|
695
|
+
if (paramTag.isBracketed)
|
|
696
|
+
param.optional = true;
|
|
697
|
+
return { name: tag.tagName.text, text, param };
|
|
698
|
+
}
|
|
699
|
+
if (tag.tagName.text === "typeParam") {
|
|
700
|
+
const text = stripTypeParamSeparator(rawText) ?? "";
|
|
701
|
+
return { name: tag.tagName.text, text };
|
|
702
|
+
}
|
|
703
|
+
return { name: tag.tagName.text, text: rawText };
|
|
690
704
|
});
|
|
691
705
|
const jsDocComments = node.jsDoc;
|
|
692
706
|
let description;
|
|
@@ -1672,7 +1686,7 @@ async function extract(options) {
|
|
|
1672
1686
|
}
|
|
1673
1687
|
const meta = await getPackageMeta(entryFile, baseDir);
|
|
1674
1688
|
const types = ctx.typeRegistry.getAll();
|
|
1675
|
-
const forgottenExports = collectForgottenExports(exports, types, program, sourceFile);
|
|
1689
|
+
const forgottenExports = collectForgottenExports(exports, types, program, sourceFile, exportedIds);
|
|
1676
1690
|
for (const forgotten of forgottenExports) {
|
|
1677
1691
|
const refSummary = forgotten.referencedBy.slice(0, 3).map((r) => `${r.exportName} (${r.location})`).join(", ");
|
|
1678
1692
|
const moreRefs = forgotten.referencedBy.length > 3 ? ` +${forgotten.referencedBy.length - 3} more` : "";
|
|
@@ -1802,7 +1816,7 @@ function hasInternalTag(typeName, program, sourceFile) {
|
|
|
1802
1816
|
const jsTags = symbol.getJsDocTags();
|
|
1803
1817
|
return jsTags.some((tag) => tag.name === "internal");
|
|
1804
1818
|
}
|
|
1805
|
-
function collectForgottenExports(exports, types, program, sourceFile) {
|
|
1819
|
+
function collectForgottenExports(exports, types, program, sourceFile, exportedIds) {
|
|
1806
1820
|
const definedTypes = new Set(types.map((t) => t.id));
|
|
1807
1821
|
const referencedTypes = new Map;
|
|
1808
1822
|
for (const exp of exports) {
|
|
@@ -1829,6 +1843,8 @@ function collectForgottenExports(exports, types, program, sourceFile) {
|
|
|
1829
1843
|
continue;
|
|
1830
1844
|
if (hasInternalTag(typeName, program, sourceFile))
|
|
1831
1845
|
continue;
|
|
1846
|
+
if (exportedIds.has(typeName))
|
|
1847
|
+
continue;
|
|
1832
1848
|
const definedIn = findTypeDefinition(typeName, program, sourceFile);
|
|
1833
1849
|
const isExternal = isExternalType2(definedIn);
|
|
1834
1850
|
forgottenExports.push({
|
package/dist/src/index.d.ts
CHANGED
|
@@ -180,15 +180,43 @@ declare const typeboxAdapter: SchemaAdapter;
|
|
|
180
180
|
declare const valibotAdapter: SchemaAdapter;
|
|
181
181
|
declare const zodAdapter: SchemaAdapter;
|
|
182
182
|
/**
|
|
183
|
-
*
|
|
183
|
+
* Target version for JSON Schema generation.
|
|
184
|
+
* @see https://standardschema.dev/json-schema
|
|
184
185
|
*/
|
|
185
|
-
|
|
186
|
+
type StandardJSONSchemaTarget = "draft-2020-12" | "draft-07" | "openapi-3.0" | (string & {});
|
|
187
|
+
/**
|
|
188
|
+
* Options for JSON Schema generation methods.
|
|
189
|
+
*/
|
|
190
|
+
interface StandardJSONSchemaOptions {
|
|
191
|
+
/** Specifies the target version of the generated JSON Schema */
|
|
192
|
+
readonly target: StandardJSONSchemaTarget;
|
|
193
|
+
/** Vendor-specific parameters */
|
|
194
|
+
readonly libraryOptions?: Record<string, unknown>;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Standard JSON Schema v1 interface.
|
|
198
|
+
* @see https://standardschema.dev/json-schema
|
|
199
|
+
*/
|
|
200
|
+
interface StandardJSONSchemaV1<
|
|
201
|
+
Input = unknown,
|
|
202
|
+
Output = Input
|
|
203
|
+
> {
|
|
186
204
|
"~standard": {
|
|
187
|
-
version
|
|
205
|
+
/** The version number of the standard (always 1) */
|
|
206
|
+
version: 1;
|
|
207
|
+
/** The vendor name of the schema library */
|
|
188
208
|
vendor: string;
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
input
|
|
209
|
+
/** Inferred types (optional) */
|
|
210
|
+
types?: {
|
|
211
|
+
input: Input;
|
|
212
|
+
output: Output;
|
|
213
|
+
};
|
|
214
|
+
/** JSON Schema conversion methods */
|
|
215
|
+
jsonSchema: {
|
|
216
|
+
/** Converts input type to JSON Schema */
|
|
217
|
+
input: (options: StandardJSONSchemaOptions) => Record<string, unknown>;
|
|
218
|
+
/** Converts output type to JSON Schema */
|
|
219
|
+
output: (options: StandardJSONSchemaOptions) => Record<string, unknown>;
|
|
192
220
|
};
|
|
193
221
|
};
|
|
194
222
|
}
|
|
@@ -208,7 +236,9 @@ interface ExtractStandardSchemasOptions {
|
|
|
208
236
|
/** Timeout in milliseconds (default: 10000) */
|
|
209
237
|
timeout?: number;
|
|
210
238
|
/** JSON Schema target version (default: 'draft-2020-12') */
|
|
211
|
-
target?:
|
|
239
|
+
target?: StandardJSONSchemaTarget;
|
|
240
|
+
/** Vendor-specific options to pass through */
|
|
241
|
+
libraryOptions?: Record<string, unknown>;
|
|
212
242
|
}
|
|
213
243
|
/**
|
|
214
244
|
* Result of Standard Schema extraction.
|
|
@@ -329,4 +359,4 @@ declare function findDiscriminatorProperty(unionTypes: ts12.Type[], checker: ts1
|
|
|
329
359
|
import ts13 from "typescript";
|
|
330
360
|
declare function isExported(node: ts13.Node): boolean;
|
|
331
361
|
declare function getNodeName(node: ts13.Node): string | undefined;
|
|
332
|
-
export { zodAdapter, withDescription, valibotAdapter, typeboxAdapter, serializeVariable, serializeTypeAlias, serializeInterface, serializeFunctionExport, serializeEnum, serializeClass, schemasAreEqual, schemaIsAny, resolveCompiledPath, registerReferencedTypes, registerAdapter, isTypeReference, isSymbolDeprecated, isStandardJSONSchema, isSchemaType, isPureRefSchema, isPrimitiveName, isExported, isBuiltinGeneric, isAnonymous, getSourceLocation, getParamDescription, getNonNullableType, getNodeName, getJSDocComment, findDiscriminatorProperty, findAdapter, extractTypeParameters, extractStandardSchemasFromProject, extractStandardSchemas, extractSchemaType, extractParameters, extract, deduplicateSchemas, createProgram, buildSchema, arktypeAdapter, TypeRegistry, TypeReference2 as TypeReference, StandardSchemaExtractionResult, StandardSchemaExtractionOutput, StandardJSONSchemaV1, SerializerContext, SchemaExtractionResult, SchemaAdapter, ProgramResult, ProgramOptions, ForgottenExport, ExtractStandardSchemasOptions, ExtractResult, ExtractOptions, Diagnostic, BUILTIN_TYPE_SCHEMAS };
|
|
362
|
+
export { zodAdapter, withDescription, valibotAdapter, typeboxAdapter, serializeVariable, serializeTypeAlias, serializeInterface, serializeFunctionExport, serializeEnum, serializeClass, schemasAreEqual, schemaIsAny, resolveCompiledPath, registerReferencedTypes, registerAdapter, isTypeReference, isSymbolDeprecated, isStandardJSONSchema, isSchemaType, isPureRefSchema, isPrimitiveName, isExported, isBuiltinGeneric, isAnonymous, getSourceLocation, getParamDescription, getNonNullableType, getNodeName, getJSDocComment, findDiscriminatorProperty, findAdapter, extractTypeParameters, extractStandardSchemasFromProject, extractStandardSchemas, extractSchemaType, extractParameters, extract, deduplicateSchemas, createProgram, buildSchema, arktypeAdapter, TypeRegistry, TypeReference2 as TypeReference, StandardSchemaExtractionResult, StandardSchemaExtractionOutput, StandardJSONSchemaV1, StandardJSONSchemaTarget, StandardJSONSchemaOptions, SerializerContext, SchemaExtractionResult, SchemaAdapter, ProgramResult, ProgramOptions, ForgottenExport, ExtractStandardSchemasOptions, ExtractResult, ExtractOptions, Diagnostic, BUILTIN_TYPE_SCHEMAS };
|
package/dist/src/index.js
CHANGED
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
serializeTypeAlias,
|
|
27
27
|
serializeVariable,
|
|
28
28
|
withDescription
|
|
29
|
-
} from "../shared/chunk-
|
|
29
|
+
} from "../shared/chunk-rej3ws8m.js";
|
|
30
30
|
// src/schema/registry.ts
|
|
31
31
|
function isTypeReference(type) {
|
|
32
32
|
return !!(type.flags & 524288 && type.objectFlags && type.objectFlags & 4);
|
|
@@ -200,7 +200,7 @@ function isStandardJSONSchema(obj) {
|
|
|
200
200
|
if (typeof std !== "object" || std === null)
|
|
201
201
|
return false;
|
|
202
202
|
const stdObj = std;
|
|
203
|
-
if (
|
|
203
|
+
if (stdObj.version !== 1)
|
|
204
204
|
return false;
|
|
205
205
|
if (typeof stdObj.vendor !== "string")
|
|
206
206
|
return false;
|
|
@@ -208,7 +208,7 @@ function isStandardJSONSchema(obj) {
|
|
|
208
208
|
if (typeof jsonSchema !== "object" || jsonSchema === null)
|
|
209
209
|
return false;
|
|
210
210
|
const jsObj = jsonSchema;
|
|
211
|
-
return typeof jsObj.output === "function";
|
|
211
|
+
return typeof jsObj.output === "function" && typeof jsObj.input === "function";
|
|
212
212
|
}
|
|
213
213
|
var WORKER_SCRIPT = `
|
|
214
214
|
const path = require('path');
|
|
@@ -233,7 +233,8 @@ function sanitizeTypeBoxSchema(schema) {
|
|
|
233
233
|
async function extract() {
|
|
234
234
|
// With node -e, argv is: [node, arg1, arg2, ...]
|
|
235
235
|
// (the -e script is NOT in argv)
|
|
236
|
-
const [modulePath,
|
|
236
|
+
const [modulePath, optionsJson] = process.argv.slice(1);
|
|
237
|
+
const { target, libraryOptions } = JSON.parse(optionsJson || '{}');
|
|
237
238
|
|
|
238
239
|
try {
|
|
239
240
|
// Import the module using dynamic import (works with ESM and CJS)
|
|
@@ -257,12 +258,14 @@ async function extract() {
|
|
|
257
258
|
if (name.startsWith('_')) continue;
|
|
258
259
|
if (typeof value !== 'object' || value === null) continue;
|
|
259
260
|
|
|
260
|
-
// Priority 1: Standard Schema (Zod 4.2+, ArkType
|
|
261
|
+
// Priority 1: Standard JSON Schema (Zod 4.2+, ArkType 2.1.28+, Valibot 1.2+)
|
|
261
262
|
const std = value['~standard'];
|
|
262
|
-
if (std && typeof std === 'object' &&
|
|
263
|
+
if (std && typeof std === 'object' && std.version === 1 && typeof std.vendor === 'string' && std.jsonSchema && typeof std.jsonSchema.output === 'function') {
|
|
263
264
|
try {
|
|
264
|
-
|
|
265
|
-
const
|
|
265
|
+
// Per spec: pass options object with target and optional libraryOptions
|
|
266
|
+
const options = { target: target || 'draft-2020-12', ...(libraryOptions && { libraryOptions }) };
|
|
267
|
+
const outputSchema = std.jsonSchema.output(options);
|
|
268
|
+
const inputSchema = typeof std.jsonSchema.input === 'function' ? std.jsonSchema.input(options) : undefined;
|
|
266
269
|
results.push({
|
|
267
270
|
exportName: name,
|
|
268
271
|
vendor: std.vendor,
|
|
@@ -315,7 +318,7 @@ function resolveCompiledPath(tsPath, baseDir) {
|
|
|
315
318
|
return null;
|
|
316
319
|
}
|
|
317
320
|
async function extractStandardSchemas(compiledJsPath, options = {}) {
|
|
318
|
-
const { timeout = 1e4, target = "draft-2020-12" } = options;
|
|
321
|
+
const { timeout = 1e4, target = "draft-2020-12", libraryOptions } = options;
|
|
319
322
|
const result = {
|
|
320
323
|
schemas: new Map,
|
|
321
324
|
errors: []
|
|
@@ -324,8 +327,9 @@ async function extractStandardSchemas(compiledJsPath, options = {}) {
|
|
|
324
327
|
result.errors.push(`Compiled JS not found: ${compiledJsPath}`);
|
|
325
328
|
return result;
|
|
326
329
|
}
|
|
330
|
+
const optionsJson = JSON.stringify({ target, libraryOptions });
|
|
327
331
|
return new Promise((resolve) => {
|
|
328
|
-
const child = spawn("node", ["-e", WORKER_SCRIPT, compiledJsPath,
|
|
332
|
+
const child = spawn("node", ["-e", WORKER_SCRIPT, compiledJsPath, optionsJson], {
|
|
329
333
|
timeout,
|
|
330
334
|
stdio: ["ignore", "pipe", "pipe"]
|
|
331
335
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpkg-ts/extract",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "TypeScript export extraction to OpenPkg spec",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openpkg",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"format": "biome format --write src/"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@openpkg-ts/spec": "^0.
|
|
43
|
+
"@openpkg-ts/spec": "^0.19.0",
|
|
44
44
|
"chalk": "^5.4.1",
|
|
45
45
|
"commander": "^12.0.0",
|
|
46
46
|
"tree-sitter-wasms": "^0.1.13",
|