@openpkg-ts/extract 0.21.0 → 0.22.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-
|
|
4
|
+
} from "../shared/chunk-nymjpc96.js";
|
|
5
5
|
|
|
6
6
|
// src/cli/spec.ts
|
|
7
7
|
import * as fs from "node:fs";
|
|
@@ -452,8 +452,9 @@ function createProgram() {
|
|
|
452
452
|
fs.writeFileSync(options.output, JSON.stringify(normalized, null, 2));
|
|
453
453
|
spin.success(`Extracted to ${options.output}`);
|
|
454
454
|
if (result.runtimeSchemas) {
|
|
455
|
-
const { extracted, merged, vendors } = result.runtimeSchemas;
|
|
456
|
-
|
|
455
|
+
const { extracted, merged, vendors, method } = result.runtimeSchemas;
|
|
456
|
+
const via = method ? ` via ${method}` : "";
|
|
457
|
+
console.log(`ℹ Runtime schemas: ${merged}/${extracted} merged (${vendors.join(", ")})${via}`);
|
|
457
458
|
}
|
|
458
459
|
for (const diag of result.diagnostics) {
|
|
459
460
|
if (diag.severity === "info" && !options.verbose)
|
|
@@ -1523,8 +1523,9 @@ function serializeVariable(node, statement, ctx) {
|
|
|
1523
1523
|
}
|
|
1524
1524
|
|
|
1525
1525
|
// src/schema/standard-schema.ts
|
|
1526
|
-
import { spawn } from "node:child_process";
|
|
1526
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
1527
1527
|
import * as fs from "node:fs";
|
|
1528
|
+
import * as os from "node:os";
|
|
1528
1529
|
import * as path2 from "node:path";
|
|
1529
1530
|
function isStandardJSONSchema(obj) {
|
|
1530
1531
|
if (typeof obj !== "object" || obj === null)
|
|
@@ -1543,6 +1544,57 @@ function isStandardJSONSchema(obj) {
|
|
|
1543
1544
|
const jsObj = jsonSchema;
|
|
1544
1545
|
return typeof jsObj.output === "function" && typeof jsObj.input === "function";
|
|
1545
1546
|
}
|
|
1547
|
+
var cachedRuntime;
|
|
1548
|
+
function commandExists(cmd) {
|
|
1549
|
+
try {
|
|
1550
|
+
const result = spawnSync(process.platform === "win32" ? "where" : "which", [cmd], {
|
|
1551
|
+
stdio: "ignore"
|
|
1552
|
+
});
|
|
1553
|
+
return result.status === 0;
|
|
1554
|
+
} catch {
|
|
1555
|
+
return false;
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
function detectTsRuntime() {
|
|
1559
|
+
if (cachedRuntime !== undefined) {
|
|
1560
|
+
return cachedRuntime;
|
|
1561
|
+
}
|
|
1562
|
+
const nodeVersion = parseInt(process.versions.node.split(".")[0], 10);
|
|
1563
|
+
if (nodeVersion >= 22) {
|
|
1564
|
+
cachedRuntime = {
|
|
1565
|
+
cmd: "node",
|
|
1566
|
+
args: ["--experimental-strip-types", "--no-warnings"],
|
|
1567
|
+
name: "node (native)"
|
|
1568
|
+
};
|
|
1569
|
+
return cachedRuntime;
|
|
1570
|
+
}
|
|
1571
|
+
if (commandExists("bun")) {
|
|
1572
|
+
cachedRuntime = {
|
|
1573
|
+
cmd: "bun",
|
|
1574
|
+
args: ["run"],
|
|
1575
|
+
name: "bun"
|
|
1576
|
+
};
|
|
1577
|
+
return cachedRuntime;
|
|
1578
|
+
}
|
|
1579
|
+
if (commandExists("tsx")) {
|
|
1580
|
+
cachedRuntime = {
|
|
1581
|
+
cmd: "tsx",
|
|
1582
|
+
args: [],
|
|
1583
|
+
name: "tsx"
|
|
1584
|
+
};
|
|
1585
|
+
return cachedRuntime;
|
|
1586
|
+
}
|
|
1587
|
+
if (commandExists("ts-node")) {
|
|
1588
|
+
cachedRuntime = {
|
|
1589
|
+
cmd: "ts-node",
|
|
1590
|
+
args: ["--transpile-only"],
|
|
1591
|
+
name: "ts-node"
|
|
1592
|
+
};
|
|
1593
|
+
return cachedRuntime;
|
|
1594
|
+
}
|
|
1595
|
+
cachedRuntime = null;
|
|
1596
|
+
return null;
|
|
1597
|
+
}
|
|
1546
1598
|
var WORKER_SCRIPT = `
|
|
1547
1599
|
const path = require('path');
|
|
1548
1600
|
const { pathToFileURL } = require('url');
|
|
@@ -1634,6 +1686,161 @@ async function extract() {
|
|
|
1634
1686
|
|
|
1635
1687
|
extract();
|
|
1636
1688
|
`;
|
|
1689
|
+
var TS_WORKER_SCRIPT = `
|
|
1690
|
+
import * as path from 'path';
|
|
1691
|
+
import { pathToFileURL } from 'url';
|
|
1692
|
+
|
|
1693
|
+
// TypeBox detection
|
|
1694
|
+
const TYPEBOX_KIND = Symbol.for('TypeBox.Kind');
|
|
1695
|
+
|
|
1696
|
+
function isTypeBoxSchema(obj: unknown): boolean {
|
|
1697
|
+
if (!obj || typeof obj !== 'object') return false;
|
|
1698
|
+
const o = obj as Record<string | symbol, unknown>;
|
|
1699
|
+
if (!o[TYPEBOX_KIND]) return false;
|
|
1700
|
+
return typeof o.type === 'string' || 'anyOf' in o || 'oneOf' in o || 'allOf' in o;
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
function sanitizeTypeBoxSchema(schema: unknown): unknown {
|
|
1704
|
+
return JSON.parse(JSON.stringify(schema));
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
async function extract() {
|
|
1708
|
+
const [,, modulePath, optionsJson] = process.argv;
|
|
1709
|
+
const { target, libraryOptions } = JSON.parse(optionsJson || '{}');
|
|
1710
|
+
|
|
1711
|
+
try {
|
|
1712
|
+
const absPath = path.resolve(modulePath);
|
|
1713
|
+
const mod = await import(pathToFileURL(absPath).href);
|
|
1714
|
+
const results: Array<{exportName: string; vendor: string; outputSchema: unknown; inputSchema?: unknown}> = [];
|
|
1715
|
+
|
|
1716
|
+
// Build exports map
|
|
1717
|
+
const exports: Record<string, unknown> = {};
|
|
1718
|
+
for (const [name, value] of Object.entries(mod)) {
|
|
1719
|
+
if (name === 'default' && typeof value === 'object' && value !== null) {
|
|
1720
|
+
Object.assign(exports, value);
|
|
1721
|
+
} else if (name !== 'default') {
|
|
1722
|
+
exports[name] = value;
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
// Check each export
|
|
1727
|
+
for (const [name, value] of Object.entries(exports)) {
|
|
1728
|
+
if (name.startsWith('_')) continue;
|
|
1729
|
+
if (typeof value !== 'object' || value === null) continue;
|
|
1730
|
+
|
|
1731
|
+
const v = value as Record<string, unknown>;
|
|
1732
|
+
const std = v['~standard'] as Record<string, unknown> | undefined;
|
|
1733
|
+
|
|
1734
|
+
// Standard JSON Schema
|
|
1735
|
+
if (std && typeof std === 'object' && std.version === 1 && typeof std.vendor === 'string') {
|
|
1736
|
+
const jsonSchema = std.jsonSchema as Record<string, unknown> | undefined;
|
|
1737
|
+
if (jsonSchema && typeof jsonSchema.output === 'function') {
|
|
1738
|
+
try {
|
|
1739
|
+
const options = { target: target || 'draft-2020-12', ...(libraryOptions && { libraryOptions }) };
|
|
1740
|
+
const outputSchema = (jsonSchema.output as Function)(options);
|
|
1741
|
+
const inputSchema = typeof jsonSchema.input === 'function' ? (jsonSchema.input as Function)(options) : undefined;
|
|
1742
|
+
results.push({ exportName: name, vendor: std.vendor as string, outputSchema, inputSchema });
|
|
1743
|
+
} catch {}
|
|
1744
|
+
continue;
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
// TypeBox
|
|
1749
|
+
if (isTypeBoxSchema(value)) {
|
|
1750
|
+
try {
|
|
1751
|
+
results.push({ exportName: name, vendor: 'typebox', outputSchema: sanitizeTypeBoxSchema(value) });
|
|
1752
|
+
} catch {}
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
|
|
1756
|
+
console.log(JSON.stringify({ success: true, results }));
|
|
1757
|
+
} catch (e) {
|
|
1758
|
+
console.log(JSON.stringify({ success: false, error: (e as Error).message }));
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1762
|
+
extract();
|
|
1763
|
+
`;
|
|
1764
|
+
async function extractStandardSchemasFromTs(tsFilePath, options = {}) {
|
|
1765
|
+
const { timeout = 1e4, target = "draft-2020-12", libraryOptions } = options;
|
|
1766
|
+
const result = {
|
|
1767
|
+
schemas: new Map,
|
|
1768
|
+
errors: []
|
|
1769
|
+
};
|
|
1770
|
+
const runtime = detectTsRuntime();
|
|
1771
|
+
if (!runtime) {
|
|
1772
|
+
result.errors.push("No TypeScript runtime available. Install bun, tsx, or ts-node, or use Node 22+.");
|
|
1773
|
+
return result;
|
|
1774
|
+
}
|
|
1775
|
+
if (!fs.existsSync(tsFilePath)) {
|
|
1776
|
+
result.errors.push(`TypeScript file not found: ${tsFilePath}`);
|
|
1777
|
+
return result;
|
|
1778
|
+
}
|
|
1779
|
+
const tempDir = os.tmpdir();
|
|
1780
|
+
const workerPath = path2.join(tempDir, `openpkg-extract-worker-${Date.now()}.ts`);
|
|
1781
|
+
try {
|
|
1782
|
+
fs.writeFileSync(workerPath, TS_WORKER_SCRIPT);
|
|
1783
|
+
const optionsJson = JSON.stringify({ target, libraryOptions });
|
|
1784
|
+
const args = [...runtime.args, workerPath, tsFilePath, optionsJson];
|
|
1785
|
+
return await new Promise((resolve) => {
|
|
1786
|
+
const child = spawn(runtime.cmd, args, {
|
|
1787
|
+
timeout,
|
|
1788
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
1789
|
+
cwd: path2.dirname(tsFilePath)
|
|
1790
|
+
});
|
|
1791
|
+
let stdout = "";
|
|
1792
|
+
let stderr = "";
|
|
1793
|
+
child.stdout.on("data", (data) => {
|
|
1794
|
+
stdout += data.toString();
|
|
1795
|
+
});
|
|
1796
|
+
child.stderr.on("data", (data) => {
|
|
1797
|
+
stderr += data.toString();
|
|
1798
|
+
});
|
|
1799
|
+
child.on("close", (code) => {
|
|
1800
|
+
try {
|
|
1801
|
+
fs.unlinkSync(workerPath);
|
|
1802
|
+
} catch {}
|
|
1803
|
+
if (code !== 0) {
|
|
1804
|
+
result.errors.push(`Extraction failed (${runtime.name}): ${stderr || `exit code ${code}`}`);
|
|
1805
|
+
resolve(result);
|
|
1806
|
+
return;
|
|
1807
|
+
}
|
|
1808
|
+
try {
|
|
1809
|
+
const parsed = JSON.parse(stdout);
|
|
1810
|
+
if (!parsed.success) {
|
|
1811
|
+
result.errors.push(`Extraction failed: ${parsed.error}`);
|
|
1812
|
+
resolve(result);
|
|
1813
|
+
return;
|
|
1814
|
+
}
|
|
1815
|
+
for (const item of parsed.results) {
|
|
1816
|
+
result.schemas.set(item.exportName, {
|
|
1817
|
+
exportName: item.exportName,
|
|
1818
|
+
vendor: item.vendor,
|
|
1819
|
+
outputSchema: item.outputSchema,
|
|
1820
|
+
inputSchema: item.inputSchema
|
|
1821
|
+
});
|
|
1822
|
+
}
|
|
1823
|
+
} catch (e) {
|
|
1824
|
+
result.errors.push(`Failed to parse extraction output: ${e}`);
|
|
1825
|
+
}
|
|
1826
|
+
resolve(result);
|
|
1827
|
+
});
|
|
1828
|
+
child.on("error", (err) => {
|
|
1829
|
+
try {
|
|
1830
|
+
fs.unlinkSync(workerPath);
|
|
1831
|
+
} catch {}
|
|
1832
|
+
result.errors.push(`Subprocess error: ${err.message}`);
|
|
1833
|
+
resolve(result);
|
|
1834
|
+
});
|
|
1835
|
+
});
|
|
1836
|
+
} catch (e) {
|
|
1837
|
+
try {
|
|
1838
|
+
fs.unlinkSync(workerPath);
|
|
1839
|
+
} catch {}
|
|
1840
|
+
result.errors.push(`Failed to create worker script: ${e}`);
|
|
1841
|
+
return result;
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1637
1844
|
function readTsconfigOutDir(baseDir) {
|
|
1638
1845
|
const tsconfigPath = path2.join(baseDir, "tsconfig.json");
|
|
1639
1846
|
try {
|
|
@@ -1743,14 +1950,34 @@ async function extractStandardSchemas(compiledJsPath, options = {}) {
|
|
|
1743
1950
|
});
|
|
1744
1951
|
}
|
|
1745
1952
|
async function extractStandardSchemasFromProject(entryFile, baseDir, options = {}) {
|
|
1746
|
-
const
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1953
|
+
const { preferDirectTs, ...extractOptions } = options;
|
|
1954
|
+
const isTypeScript = /\.tsx?$/.test(entryFile);
|
|
1955
|
+
if (!preferDirectTs) {
|
|
1956
|
+
const compiledPath = resolveCompiledPath(entryFile, baseDir);
|
|
1957
|
+
if (compiledPath) {
|
|
1958
|
+
const result = await extractStandardSchemas(compiledPath, extractOptions);
|
|
1959
|
+
return {
|
|
1960
|
+
...result,
|
|
1961
|
+
info: { method: "compiled", path: compiledPath }
|
|
1962
|
+
};
|
|
1963
|
+
}
|
|
1752
1964
|
}
|
|
1753
|
-
|
|
1965
|
+
if (isTypeScript) {
|
|
1966
|
+
const runtime2 = detectTsRuntime();
|
|
1967
|
+
if (runtime2) {
|
|
1968
|
+
const result = await extractStandardSchemasFromTs(entryFile, extractOptions);
|
|
1969
|
+
return {
|
|
1970
|
+
...result,
|
|
1971
|
+
info: { method: "direct-ts", runtime: runtime2.name, path: entryFile }
|
|
1972
|
+
};
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
const runtime = detectTsRuntime();
|
|
1976
|
+
const hint = isTypeScript && !runtime ? " Install bun, tsx, or ts-node for direct TS execution." : "";
|
|
1977
|
+
return {
|
|
1978
|
+
schemas: new Map,
|
|
1979
|
+
errors: [`Could not find compiled JS for ${entryFile}.${hint}`]
|
|
1980
|
+
};
|
|
1754
1981
|
}
|
|
1755
1982
|
|
|
1756
1983
|
// src/builder/spec-builder.ts
|
|
@@ -1980,35 +2207,27 @@ async function extract(options) {
|
|
|
1980
2207
|
let runtimeMetadata;
|
|
1981
2208
|
if (options.schemaExtraction === "hybrid") {
|
|
1982
2209
|
const projectBaseDir = baseDir || path3.dirname(entryFile);
|
|
1983
|
-
const
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
diagnostics.push({
|
|
2001
|
-
message: `Runtime schema extraction: ${error}`,
|
|
2002
|
-
severity: "warning",
|
|
2003
|
-
code: "RUNTIME_SCHEMA_ERROR"
|
|
2004
|
-
});
|
|
2005
|
-
}
|
|
2006
|
-
} else {
|
|
2210
|
+
const runtimeResult = await extractStandardSchemasFromProject(entryFile, projectBaseDir, {
|
|
2211
|
+
target: options.schemaTarget || "draft-2020-12",
|
|
2212
|
+
timeout: 15000
|
|
2213
|
+
});
|
|
2214
|
+
if (runtimeResult.schemas.size > 0) {
|
|
2215
|
+
const mergeResult = mergeRuntimeSchemas(exports, runtimeResult.schemas);
|
|
2216
|
+
exports = mergeResult.exports;
|
|
2217
|
+
const method = runtimeResult.info?.method === "direct-ts" ? `direct-ts (${runtimeResult.info.runtime})` : "compiled";
|
|
2218
|
+
runtimeMetadata = {
|
|
2219
|
+
extracted: runtimeResult.schemas.size,
|
|
2220
|
+
merged: mergeResult.merged,
|
|
2221
|
+
vendors: [...new Set([...runtimeResult.schemas.values()].map((s) => s.vendor))],
|
|
2222
|
+
errors: runtimeResult.errors,
|
|
2223
|
+
method
|
|
2224
|
+
};
|
|
2225
|
+
}
|
|
2226
|
+
for (const error of runtimeResult.errors) {
|
|
2007
2227
|
diagnostics.push({
|
|
2008
|
-
message:
|
|
2228
|
+
message: `Runtime schema extraction: ${error}`,
|
|
2009
2229
|
severity: "warning",
|
|
2010
|
-
code: "
|
|
2011
|
-
suggestion: "Run `npm run build` or `tsc` before extraction"
|
|
2230
|
+
code: "RUNTIME_SCHEMA_ERROR"
|
|
2012
2231
|
});
|
|
2013
2232
|
}
|
|
2014
2233
|
}
|
|
@@ -2358,4 +2577,4 @@ async function getPackageMeta(entryFile, baseDir) {
|
|
|
2358
2577
|
} catch {}
|
|
2359
2578
|
return { name: path3.basename(searchDir) };
|
|
2360
2579
|
}
|
|
2361
|
-
export { BUILTIN_TYPE_SCHEMAS, isPrimitiveName, isBuiltinGeneric, isAnonymous, buildSchema, isPureRefSchema, withDescription, schemaIsAny, schemasAreEqual, deduplicateSchemas, findDiscriminatorProperty, TypeRegistry, getJSDocComment, getSourceLocation, getParamDescription, extractTypeParameters, isSymbolDeprecated, createProgram, extractParameters, registerReferencedTypes, serializeClass, serializeEnum, serializeFunctionExport, serializeInterface, serializeTypeAlias, serializeVariable, isStandardJSONSchema, resolveCompiledPath, extractStandardSchemas, extractStandardSchemasFromProject, extract };
|
|
2580
|
+
export { BUILTIN_TYPE_SCHEMAS, isPrimitiveName, isBuiltinGeneric, isAnonymous, buildSchema, isPureRefSchema, withDescription, schemaIsAny, schemasAreEqual, deduplicateSchemas, findDiscriminatorProperty, TypeRegistry, getJSDocComment, getSourceLocation, getParamDescription, extractTypeParameters, isSymbolDeprecated, createProgram, extractParameters, registerReferencedTypes, serializeClass, serializeEnum, serializeFunctionExport, serializeInterface, serializeTypeAlias, serializeVariable, isStandardJSONSchema, detectTsRuntime, extractStandardSchemasFromTs, resolveCompiledPath, extractStandardSchemas, extractStandardSchemasFromProject, extract };
|
package/dist/src/index.d.ts
CHANGED
|
@@ -96,6 +96,8 @@ interface ExtractResult {
|
|
|
96
96
|
vendors: string[];
|
|
97
97
|
/** Any errors encountered during runtime extraction */
|
|
98
98
|
errors: string[];
|
|
99
|
+
/** Extraction method used: 'compiled' or 'direct-ts (runtime)' */
|
|
100
|
+
method?: string;
|
|
99
101
|
};
|
|
100
102
|
}
|
|
101
103
|
interface Diagnostic {
|
|
@@ -199,6 +201,32 @@ interface StandardSchemaExtractionOutput {
|
|
|
199
201
|
*/
|
|
200
202
|
declare function isStandardJSONSchema(obj: unknown): obj is StandardJSONSchemaV1;
|
|
201
203
|
/**
|
|
204
|
+
* TypeScript runtime configuration.
|
|
205
|
+
*/
|
|
206
|
+
interface TsRuntime {
|
|
207
|
+
/** Command to execute */
|
|
208
|
+
cmd: string;
|
|
209
|
+
/** Arguments to pass before the script path */
|
|
210
|
+
args: string[];
|
|
211
|
+
/** Human-readable name */
|
|
212
|
+
name: string;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Detect available TypeScript runtime.
|
|
216
|
+
* Checks in order: Node 22+ native, bun, tsx, ts-node.
|
|
217
|
+
* Returns null if no TS runtime is available.
|
|
218
|
+
*/
|
|
219
|
+
declare function detectTsRuntime(): TsRuntime | null;
|
|
220
|
+
/**
|
|
221
|
+
* Extract Standard Schema from a TypeScript file directly.
|
|
222
|
+
* Uses detected TS runtime (bun, tsx, ts-node, or node 22+).
|
|
223
|
+
*
|
|
224
|
+
* @param tsFilePath - Path to TypeScript file
|
|
225
|
+
* @param options - Extraction options
|
|
226
|
+
* @returns Extraction results
|
|
227
|
+
*/
|
|
228
|
+
declare function extractStandardSchemasFromTs(tsFilePath: string, options?: ExtractStandardSchemasOptions): Promise<StandardSchemaExtractionOutput>;
|
|
229
|
+
/**
|
|
202
230
|
* Resolve compiled JS path from TypeScript source.
|
|
203
231
|
* Reads tsconfig.json for outDir and tries multiple output patterns.
|
|
204
232
|
* Supports .js, .mjs, and .cjs extensions.
|
|
@@ -216,15 +244,42 @@ declare function resolveCompiledPath(tsPath: string, baseDir: string): string |
|
|
|
216
244
|
*/
|
|
217
245
|
declare function extractStandardSchemas(compiledJsPath: string, options?: ExtractStandardSchemasOptions): Promise<StandardSchemaExtractionOutput>;
|
|
218
246
|
/**
|
|
247
|
+
* Result info from extractStandardSchemasFromProject
|
|
248
|
+
*/
|
|
249
|
+
interface ProjectExtractionInfo {
|
|
250
|
+
/** How schemas were extracted */
|
|
251
|
+
method: "compiled" | "direct-ts";
|
|
252
|
+
/** Runtime used (for direct-ts) */
|
|
253
|
+
runtime?: string;
|
|
254
|
+
/** Path that was used */
|
|
255
|
+
path: string;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Extended options for project extraction
|
|
259
|
+
*/
|
|
260
|
+
interface ExtractFromProjectOptions extends ExtractStandardSchemasOptions {
|
|
261
|
+
/** Prefer direct TS execution even if compiled JS exists */
|
|
262
|
+
preferDirectTs?: boolean;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Extended result for project extraction
|
|
266
|
+
*/
|
|
267
|
+
interface ProjectExtractionOutput extends StandardSchemaExtractionOutput {
|
|
268
|
+
/** Info about how extraction was performed */
|
|
269
|
+
info?: ProjectExtractionInfo;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
219
272
|
* Extract Standard Schema from a TypeScript project.
|
|
220
273
|
*
|
|
221
|
-
*
|
|
274
|
+
* Tries in order:
|
|
275
|
+
* 1. Compiled JS (if found)
|
|
276
|
+
* 2. Direct TypeScript execution (if TS runtime available)
|
|
222
277
|
*
|
|
223
278
|
* @param entryFile - TypeScript entry file path
|
|
224
279
|
* @param baseDir - Project base directory
|
|
225
280
|
* @param options - Extraction options
|
|
226
281
|
*/
|
|
227
|
-
declare function extractStandardSchemasFromProject(entryFile: string, baseDir: string, options?:
|
|
282
|
+
declare function extractStandardSchemasFromProject(entryFile: string, baseDir: string, options?: ExtractFromProjectOptions): Promise<ProjectExtractionOutput>;
|
|
228
283
|
import ts4 from "typescript";
|
|
229
284
|
interface ProgramOptions {
|
|
230
285
|
entryFile: string;
|
|
@@ -373,4 +428,4 @@ declare function findDiscriminatorProperty(unionTypes: ts12.Type[], checker: ts1
|
|
|
373
428
|
import ts13 from "typescript";
|
|
374
429
|
declare function isExported(node: ts13.Node): boolean;
|
|
375
430
|
declare function getNodeName(node: ts13.Node): string | undefined;
|
|
376
|
-
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 };
|
|
431
|
+
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, extractStandardSchemasFromTs, extractStandardSchemasFromProject, extractStandardSchemas, extractSchemaType, extractParameters, extract, detectTsRuntime, deduplicateSchemas, createProgram, buildSchema, arktypeAdapter, TypeRegistry, TypeReference2 as TypeReference, TsRuntime, StandardSchemaExtractionResult, StandardSchemaExtractionOutput, StandardJSONSchemaV1, StandardJSONSchemaTarget, StandardJSONSchemaOptions, SerializerContext, SchemaExtractionResult, SchemaAdapter, ProjectExtractionOutput, ProjectExtractionInfo, ProgramResult, ProgramOptions, ForgottenExport, ExtractStandardSchemasOptions, ExtractResult, ExtractOptions, ExtractFromProjectOptions, Diagnostic, BUILTIN_TYPE_SCHEMAS };
|
package/dist/src/index.js
CHANGED
|
@@ -4,10 +4,12 @@ import {
|
|
|
4
4
|
buildSchema,
|
|
5
5
|
createProgram,
|
|
6
6
|
deduplicateSchemas,
|
|
7
|
+
detectTsRuntime,
|
|
7
8
|
extract,
|
|
8
9
|
extractParameters,
|
|
9
10
|
extractStandardSchemas,
|
|
10
11
|
extractStandardSchemasFromProject,
|
|
12
|
+
extractStandardSchemasFromTs,
|
|
11
13
|
extractTypeParameters,
|
|
12
14
|
findDiscriminatorProperty,
|
|
13
15
|
getJSDocComment,
|
|
@@ -30,7 +32,7 @@ import {
|
|
|
30
32
|
serializeTypeAlias,
|
|
31
33
|
serializeVariable,
|
|
32
34
|
withDescription
|
|
33
|
-
} from "../shared/chunk-
|
|
35
|
+
} from "../shared/chunk-nymjpc96.js";
|
|
34
36
|
// src/schema/registry.ts
|
|
35
37
|
function isTypeReference(type) {
|
|
36
38
|
return !!(type.flags & 524288 && type.objectFlags && type.objectFlags & 4);
|
|
@@ -240,11 +242,13 @@ export {
|
|
|
240
242
|
findDiscriminatorProperty,
|
|
241
243
|
findAdapter,
|
|
242
244
|
extractTypeParameters,
|
|
245
|
+
extractStandardSchemasFromTs,
|
|
243
246
|
extractStandardSchemasFromProject,
|
|
244
247
|
extractStandardSchemas,
|
|
245
248
|
extractSchemaType,
|
|
246
249
|
extractParameters,
|
|
247
250
|
extract,
|
|
251
|
+
detectTsRuntime,
|
|
248
252
|
deduplicateSchemas,
|
|
249
253
|
createProgram,
|
|
250
254
|
buildSchema,
|