@openpkg-ts/extract 0.19.0 → 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
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  extract
4
- } from "../shared/chunk-rgx6dspw.js";
4
+ } from "../shared/chunk-rej3ws8m.js";
5
5
 
6
6
  // src/cli/spec.ts
7
7
  import * as fs from "node:fs";
@@ -1686,7 +1686,7 @@ async function extract(options) {
1686
1686
  }
1687
1687
  const meta = await getPackageMeta(entryFile, baseDir);
1688
1688
  const types = ctx.typeRegistry.getAll();
1689
- const forgottenExports = collectForgottenExports(exports, types, program, sourceFile);
1689
+ const forgottenExports = collectForgottenExports(exports, types, program, sourceFile, exportedIds);
1690
1690
  for (const forgotten of forgottenExports) {
1691
1691
  const refSummary = forgotten.referencedBy.slice(0, 3).map((r) => `${r.exportName} (${r.location})`).join(", ");
1692
1692
  const moreRefs = forgotten.referencedBy.length > 3 ? ` +${forgotten.referencedBy.length - 3} more` : "";
@@ -1816,7 +1816,7 @@ function hasInternalTag(typeName, program, sourceFile) {
1816
1816
  const jsTags = symbol.getJsDocTags();
1817
1817
  return jsTags.some((tag) => tag.name === "internal");
1818
1818
  }
1819
- function collectForgottenExports(exports, types, program, sourceFile) {
1819
+ function collectForgottenExports(exports, types, program, sourceFile, exportedIds) {
1820
1820
  const definedTypes = new Set(types.map((t) => t.id));
1821
1821
  const referencedTypes = new Map;
1822
1822
  for (const exp of exports) {
@@ -1843,6 +1843,8 @@ function collectForgottenExports(exports, types, program, sourceFile) {
1843
1843
  continue;
1844
1844
  if (hasInternalTag(typeName, program, sourceFile))
1845
1845
  continue;
1846
+ if (exportedIds.has(typeName))
1847
+ continue;
1846
1848
  const definedIn = findTypeDefinition(typeName, program, sourceFile);
1847
1849
  const isExternal = isExternalType2(definedIn);
1848
1850
  forgottenExports.push({
@@ -180,15 +180,43 @@ declare const typeboxAdapter: SchemaAdapter;
180
180
  declare const valibotAdapter: SchemaAdapter;
181
181
  declare const zodAdapter: SchemaAdapter;
182
182
  /**
183
- * Standard JSON Schema v1 interface (minimal for detection).
183
+ * Target version for JSON Schema generation.
184
+ * @see https://standardschema.dev/json-schema
184
185
  */
185
- interface StandardJSONSchemaV1 {
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: number;
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
- jsonSchema?: {
190
- output: (target?: string) => Record<string, unknown>;
191
- input?: (target?: string) => Record<string, unknown>;
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?: "draft-2020-12" | "draft-07" | "openapi-3.0";
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-rgx6dspw.js";
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 (typeof stdObj.version !== "number")
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, target] = process.argv.slice(1);
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, etc.)
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' && typeof std.version === 'number' && typeof std.vendor === 'string' && std.jsonSchema && typeof std.jsonSchema.output === 'function') {
263
+ if (std && typeof std === 'object' && std.version === 1 && typeof std.vendor === 'string' && std.jsonSchema && typeof std.jsonSchema.output === 'function') {
263
264
  try {
264
- const outputSchema = std.jsonSchema.output(target);
265
- const inputSchema = std.jsonSchema.input ? std.jsonSchema.input(target) : undefined;
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, target], {
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.19.0",
3
+ "version": "0.20.0",
4
4
  "description": "TypeScript export extraction to OpenPkg spec",
5
5
  "keywords": [
6
6
  "openpkg",