@power-plant/schema 0.0.34 → 0.0.35
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/codegen.cjs +1 -1
- package/dist/codegen.d.mts +1 -1
- package/dist/codegen.mjs +1 -1
- package/dist/{helpers-sXsSapgI.cjs → helpers-BQD6GZyX.cjs} +27 -2
- package/dist/{helpers-reqtcaa8.mjs → helpers-dvxktFml.mjs} +11 -4
- package/dist/helpers-dvxktFml.mjs.map +1 -0
- package/dist/index.cjs +172 -9
- package/dist/index.d.cts +12 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +13 -3
- package/dist/index.mjs +169 -11
- package/dist/{types-CjF4wIDK.d.mts → types-CyvYSCHO.d.mts} +2 -2
- package/dist/types-CyvYSCHO.d.mts.map +1 -0
- package/dist/valibot.d.mts +1 -1
- package/dist/zod.cjs +1 -1
- package/dist/zod.d.mts +1 -1
- package/dist/zod.mjs +1 -1
- package/package.json +4 -2
- package/dist/helpers-reqtcaa8.mjs.map +0 -1
- package/dist/types-CjF4wIDK.d.mts.map +0 -1
package/dist/codegen.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_helpers = require('./helpers-
|
|
2
|
+
const require_helpers = require('./helpers-BQD6GZyX.cjs');
|
|
3
3
|
let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
|
|
4
4
|
let _stryke_type_checks = require("@stryke/type-checks");
|
|
5
5
|
let _stryke_string_format_list = require("@stryke/string-format/list");
|
package/dist/codegen.d.mts
CHANGED
package/dist/codegen.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { B as isJsonSchemaString, D as isJsonSchemaLiteral, P as isJsonSchemaObject, a as getPropertiesList, c as isSchemaNullable, d as merge, h as isJsonSchema, ot as getPrimarySchemaType } from "./helpers-dvxktFml.mjs";
|
|
2
2
|
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
3
3
|
import { isInteger, isObject, isSetArray, isString } from "@stryke/type-checks";
|
|
4
4
|
import { list } from "@stryke/string-format/list";
|
|
@@ -189,7 +189,7 @@ function isJsonSchemaKeywords(input) {
|
|
|
189
189
|
function isJsonSchemaAny(input) {
|
|
190
190
|
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
191
191
|
const schema = input;
|
|
192
|
-
return hasValidJsonSchemaKeywords(schema) && isOptionalString(schema.$ref) && (!schema.type || Array.isArray(schema.type) && schema.type.every((t) => require_constants.JSON_SCHEMA_PRIMITIVE_TYPES.includes(t)));
|
|
192
|
+
return hasValidJsonSchemaKeywords(schema) && isOptionalString(schema.$ref) && (!schema.type || (0, _stryke_type_checks.isSetString)(schema.type) && JSON_SCHEMA_PRIMITIVE_TYPE_SET.has(schema.type) || Array.isArray(schema.type) && schema.type.every((t) => require_constants.JSON_SCHEMA_PRIMITIVE_TYPES.includes(t)));
|
|
193
193
|
}
|
|
194
194
|
/**
|
|
195
195
|
* Type guard for JSON Schema array types.
|
|
@@ -590,7 +590,8 @@ function isUntypedSchema(input) {
|
|
|
590
590
|
* @returns True if the input is an untyped schema and not a JSON Schema.
|
|
591
591
|
*/
|
|
592
592
|
function isUntypedSchemaStrict(input) {
|
|
593
|
-
|
|
593
|
+
if (!isUntypedSchema(input) || isJsonSchema(input)) return false;
|
|
594
|
+
return !("type" in input);
|
|
594
595
|
}
|
|
595
596
|
/**
|
|
596
597
|
* Type guard for untyped input objects.
|
|
@@ -601,6 +602,8 @@ function isUntypedSchemaStrict(input) {
|
|
|
601
602
|
* @param input - The value to check.
|
|
602
603
|
* @returns True if the input is an untyped input object, false otherwise.
|
|
603
604
|
*/
|
|
605
|
+
/** @deprecated Use {@link isUntypedConfig} */
|
|
606
|
+
const isUntypedInput = isUntypedConfig;
|
|
604
607
|
function isUntypedConfig(input) {
|
|
605
608
|
if (!(0, _stryke_type_checks.isSetObject)(input)) return false;
|
|
606
609
|
const inputObject = input;
|
|
@@ -618,6 +621,8 @@ function isUntypedConfig(input) {
|
|
|
618
621
|
* @param input - The value to check.
|
|
619
622
|
* @returns True if the input is an untyped input object and not JSON Schema.
|
|
620
623
|
*/
|
|
624
|
+
/** @deprecated Use {@link isUntypedConfigStrict} */
|
|
625
|
+
const isUntypedInputStrict = isUntypedConfigStrict;
|
|
621
626
|
function isUntypedConfigStrict(input) {
|
|
622
627
|
if (!isUntypedConfig(input) || isJsonSchema(input)) return false;
|
|
623
628
|
const inputObject = input;
|
|
@@ -876,6 +881,8 @@ function isPropertyOptional(parent, propertyName) {
|
|
|
876
881
|
function isValidSchemaConfigFile(fileName) {
|
|
877
882
|
return _stryke_resolve_constants.VALID_OBJECT_SOURCE_EXTENSIONS.includes((0, _stryke_path_find.findFileExtensionSafe)(fileName));
|
|
878
883
|
}
|
|
884
|
+
/** @deprecated Use {@link isValidSchemaConfigFile} */
|
|
885
|
+
const isValidSchemaInputFile = isValidSchemaConfigFile;
|
|
879
886
|
/**
|
|
880
887
|
* Traverses a JSON Schema and applies a callback function to each schema fragment.
|
|
881
888
|
*
|
|
@@ -1219,6 +1226,18 @@ Object.defineProperty(exports, 'isUntypedConfigStrict', {
|
|
|
1219
1226
|
return isUntypedConfigStrict;
|
|
1220
1227
|
}
|
|
1221
1228
|
});
|
|
1229
|
+
Object.defineProperty(exports, 'isUntypedInput', {
|
|
1230
|
+
enumerable: true,
|
|
1231
|
+
get: function () {
|
|
1232
|
+
return isUntypedInput;
|
|
1233
|
+
}
|
|
1234
|
+
});
|
|
1235
|
+
Object.defineProperty(exports, 'isUntypedInputStrict', {
|
|
1236
|
+
enumerable: true,
|
|
1237
|
+
get: function () {
|
|
1238
|
+
return isUntypedInputStrict;
|
|
1239
|
+
}
|
|
1240
|
+
});
|
|
1222
1241
|
Object.defineProperty(exports, 'isUntypedSchema', {
|
|
1223
1242
|
enumerable: true,
|
|
1224
1243
|
get: function () {
|
|
@@ -1243,6 +1262,12 @@ Object.defineProperty(exports, 'isValidSchemaConfigFile', {
|
|
|
1243
1262
|
return isValidSchemaConfigFile;
|
|
1244
1263
|
}
|
|
1245
1264
|
});
|
|
1265
|
+
Object.defineProperty(exports, 'isValidSchemaInputFile', {
|
|
1266
|
+
enumerable: true,
|
|
1267
|
+
get: function () {
|
|
1268
|
+
return isValidSchemaInputFile;
|
|
1269
|
+
}
|
|
1270
|
+
});
|
|
1246
1271
|
Object.defineProperty(exports, 'merge', {
|
|
1247
1272
|
enumerable: true,
|
|
1248
1273
|
get: function () {
|
|
@@ -187,7 +187,7 @@ function isJsonSchemaKeywords(input) {
|
|
|
187
187
|
function isJsonSchemaAny(input) {
|
|
188
188
|
if (!isSetObject$1(input)) return false;
|
|
189
189
|
const schema = input;
|
|
190
|
-
return hasValidJsonSchemaKeywords(schema) && isOptionalString(schema.$ref) && (!schema.type || Array.isArray(schema.type) && schema.type.every((t) => JSON_SCHEMA_PRIMITIVE_TYPES.includes(t)));
|
|
190
|
+
return hasValidJsonSchemaKeywords(schema) && isOptionalString(schema.$ref) && (!schema.type || isSetString$1(schema.type) && JSON_SCHEMA_PRIMITIVE_TYPE_SET.has(schema.type) || Array.isArray(schema.type) && schema.type.every((t) => JSON_SCHEMA_PRIMITIVE_TYPES.includes(t)));
|
|
191
191
|
}
|
|
192
192
|
/**
|
|
193
193
|
* Type guard for JSON Schema array types.
|
|
@@ -588,7 +588,8 @@ function isUntypedSchema(input) {
|
|
|
588
588
|
* @returns True if the input is an untyped schema and not a JSON Schema.
|
|
589
589
|
*/
|
|
590
590
|
function isUntypedSchemaStrict(input) {
|
|
591
|
-
|
|
591
|
+
if (!isUntypedSchema(input) || isJsonSchema(input)) return false;
|
|
592
|
+
return !("type" in input);
|
|
592
593
|
}
|
|
593
594
|
/**
|
|
594
595
|
* Type guard for untyped input objects.
|
|
@@ -599,6 +600,8 @@ function isUntypedSchemaStrict(input) {
|
|
|
599
600
|
* @param input - The value to check.
|
|
600
601
|
* @returns True if the input is an untyped input object, false otherwise.
|
|
601
602
|
*/
|
|
603
|
+
/** @deprecated Use {@link isUntypedConfig} */
|
|
604
|
+
const isUntypedInput = isUntypedConfig;
|
|
602
605
|
function isUntypedConfig(input) {
|
|
603
606
|
if (!isSetObject$1(input)) return false;
|
|
604
607
|
const inputObject = input;
|
|
@@ -616,6 +619,8 @@ function isUntypedConfig(input) {
|
|
|
616
619
|
* @param input - The value to check.
|
|
617
620
|
* @returns True if the input is an untyped input object and not JSON Schema.
|
|
618
621
|
*/
|
|
622
|
+
/** @deprecated Use {@link isUntypedConfigStrict} */
|
|
623
|
+
const isUntypedInputStrict = isUntypedConfigStrict;
|
|
619
624
|
function isUntypedConfigStrict(input) {
|
|
620
625
|
if (!isUntypedConfig(input) || isJsonSchema(input)) return false;
|
|
621
626
|
const inputObject = input;
|
|
@@ -874,6 +879,8 @@ function isPropertyOptional(parent, propertyName) {
|
|
|
874
879
|
function isValidSchemaConfigFile(fileName) {
|
|
875
880
|
return VALID_OBJECT_SOURCE_EXTENSIONS.includes(findFileExtensionSafe(fileName));
|
|
876
881
|
}
|
|
882
|
+
/** @deprecated Use {@link isValidSchemaConfigFile} */
|
|
883
|
+
const isValidSchemaInputFile = isValidSchemaConfigFile;
|
|
877
884
|
/**
|
|
878
885
|
* Traverses a JSON Schema and applies a callback function to each schema fragment.
|
|
879
886
|
*
|
|
@@ -917,5 +924,5 @@ function traverseSchema(schema, callback) {
|
|
|
917
924
|
}
|
|
918
925
|
|
|
919
926
|
//#endregion
|
|
920
|
-
export {
|
|
921
|
-
//# sourceMappingURL=helpers-
|
|
927
|
+
export { isUntypedConfigStrict as $, isJsonSchemaNever as A, isJsonSchemaString as B, isJsonSchemaDecimal as C, isJsonSchemaLiteral as D, isJsonSchemaKeywords as E, isJsonSchemaPrimitiveType as F, isJsonSchemaUnknown as G, isJsonSchemaType as H, isJsonSchemaPrimitiveUnion as I, isSchemaObject as J, isNullOnlyJsonSchema as K, isJsonSchemaRecord as L, isJsonSchemaNullable as M, isJsonSchemaNumber as N, isJsonSchemaMap as O, isJsonSchemaObject as P, isUntypedConfig as Q, isJsonSchemaRef as R, isJsonSchemaDate as S, isJsonSchemaInteger as T, isJsonSchemaUndefined as U, isJsonSchemaTuple as V, isJsonSchemaUnion as W, isSchemaWithSource as X, isSchemaOf as Y, isStandardSchema as Z, isJsonSchemaAny as _, getPropertiesList as a, applyJsonSchemaMetadata as at, isJsonSchemaBigint as b, isSchemaNullable as c, merge as d, isUntypedInput as et, mergeMetadata as f, isJsonSchemaAllOf as g, isJsonSchema as h, getProperties as i, isValibotSchema as it, isJsonSchemaNull as j, isJsonSchemaNativeEnum as k, isValidSchemaConfigFile as l, isFileReference as m, getJsonSchema as n, isUntypedSchema as nt, getProperty as o, getPrimarySchemaType as ot, traverseSchema as p, isSchema as q, getJsonSchemaObject as r, isUntypedSchemaStrict as rt, isPropertyOptional as s, readSchemaTypes as st, addProperty as t, isUntypedInputStrict as tt, isValidSchemaInputFile as u, isJsonSchemaAnyOf as v, isJsonSchemaEnum as w, isJsonSchemaBoolean as x, isJsonSchemaArray as y, isJsonSchemaSet as z };
|
|
928
|
+
//# sourceMappingURL=helpers-dvxktFml.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers-dvxktFml.mjs","names":[],"sources":[],"mappings":""}
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_rolldown_runtime = require('./rolldown-runtime-C_NdSu1c.cjs');
|
|
2
3
|
const require_constants = require('./constants-B7xonHLD.cjs');
|
|
3
|
-
const require_helpers = require('./helpers-
|
|
4
|
+
const require_helpers = require('./helpers-BQD6GZyX.cjs');
|
|
4
5
|
const require_storage = require('./storage-B8aDmNpv.cjs');
|
|
5
6
|
let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
|
|
6
7
|
let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
|
|
@@ -13,12 +14,18 @@ let _stryke_json = require("@stryke/json");
|
|
|
13
14
|
let _stryke_path_append = require("@stryke/path/append");
|
|
14
15
|
let _stryke_path_find = require("@stryke/path/find");
|
|
15
16
|
let _stryke_path_join = require("@stryke/path/join");
|
|
17
|
+
let _stryke_resolve_bundle = require("@stryke/resolve/bundle");
|
|
16
18
|
let _stryke_resolve_constants = require("@stryke/resolve/constants");
|
|
17
19
|
let _stryke_resolve_load = require("@stryke/resolve/load");
|
|
20
|
+
let _stryke_resolve_resolve = require("@stryke/resolve/resolve");
|
|
18
21
|
let _stryke_string_format_list = require("@stryke/string-format/list");
|
|
19
22
|
let _stryke_zod = require("@stryke/zod");
|
|
20
23
|
let _valibot_to_json_schema = require("@valibot/to-json-schema");
|
|
24
|
+
let esbuild = require("esbuild");
|
|
21
25
|
let ts_json_schema_generator_dist_factory_generator_js = require("ts-json-schema-generator/dist/factory/generator.js");
|
|
26
|
+
let ts_json_schema_generator_dist_src_Config_js = require("ts-json-schema-generator/dist/src/Config.js");
|
|
27
|
+
let typescript = require("typescript");
|
|
28
|
+
typescript = require_rolldown_runtime.__toESM(typescript, 1);
|
|
22
29
|
|
|
23
30
|
//#region src/compatibility.ts
|
|
24
31
|
const METADATA_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -125,6 +132,9 @@ function assertSchemasDoNotContradict(base, override, label = "schema") {
|
|
|
125
132
|
//#endregion
|
|
126
133
|
//#region src/extract.ts
|
|
127
134
|
const SCHEMA_BUNDLE_BASE_URI = "https://power-plant.invalid/";
|
|
135
|
+
function normalizePath(filePath) {
|
|
136
|
+
return filePath.replaceAll("\\", "/");
|
|
137
|
+
}
|
|
128
138
|
function isWrappedSchemaConfig(input) {
|
|
129
139
|
if (!(0, _stryke_type_checks_is_set_object.isSetObject)(input) || !("schema" in input)) return false;
|
|
130
140
|
if ("hash" in input || "variant" in input || "source" in input) return false;
|
|
@@ -447,8 +457,148 @@ function extractSource(variant, input) {
|
|
|
447
457
|
};
|
|
448
458
|
throw new Error(`Failed to extract source information from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`);
|
|
449
459
|
}
|
|
460
|
+
function getTsCompilerOptions(config) {
|
|
461
|
+
if (config.tsconfig) {
|
|
462
|
+
const raw = typescript.default.sys.readFile(config.tsconfig);
|
|
463
|
+
if (!raw) throw new Error(`Cannot read config file "${config.tsconfig}"`);
|
|
464
|
+
const parsedConfig = typescript.default.parseConfigFileTextToJson(config.tsconfig, raw);
|
|
465
|
+
if (parsedConfig.error) throw new Error(parsedConfig.error.messageText.toString());
|
|
466
|
+
if (!parsedConfig.config) throw new Error(`Invalid parsed config file "${config.tsconfig}"`);
|
|
467
|
+
const parseResult = typescript.default.parseJsonConfigFileContent(parsedConfig.config, typescript.default.sys, (0, _stryke_path_find.findFilePath)(config.tsconfig), {}, config.tsconfig);
|
|
468
|
+
parseResult.options.noEmit = true;
|
|
469
|
+
delete parseResult.options.out;
|
|
470
|
+
delete parseResult.options.outDir;
|
|
471
|
+
delete parseResult.options.outFile;
|
|
472
|
+
delete parseResult.options.declaration;
|
|
473
|
+
delete parseResult.options.declarationDir;
|
|
474
|
+
delete parseResult.options.declarationMap;
|
|
475
|
+
return parseResult.options;
|
|
476
|
+
}
|
|
477
|
+
return {
|
|
478
|
+
noEmit: true,
|
|
479
|
+
emitDecoratorMetadata: true,
|
|
480
|
+
experimentalDecorators: true,
|
|
481
|
+
target: typescript.default.ScriptTarget.ES2022,
|
|
482
|
+
module: typescript.default.ModuleKind.ESNext,
|
|
483
|
+
moduleResolution: typescript.default.ModuleResolutionKind.Bundler,
|
|
484
|
+
strictNullChecks: false,
|
|
485
|
+
skipLibCheck: true,
|
|
486
|
+
skipDefaultLibCheck: true,
|
|
487
|
+
esModuleInterop: true,
|
|
488
|
+
types: ["node"]
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Rewrites type-only imports/exports so esbuild still walks them while
|
|
493
|
+
* collecting the original TypeScript sources for schema generation.
|
|
494
|
+
*/
|
|
495
|
+
function rewriteTypeOnlyImports(source) {
|
|
496
|
+
return source.replace(/\bimport\s+type\s+/g, "import ").replace(/\bexport\s+type\s+\*\s+from/g, "export * from").replace(/\bexport\s+type\s+\{/g, "export {");
|
|
497
|
+
}
|
|
498
|
+
function getScriptKind(fileName) {
|
|
499
|
+
switch ((0, _stryke_path_find.findFileExtensionSafe)(fileName)?.toLowerCase()) {
|
|
500
|
+
case "tsx": return typescript.default.ScriptKind.TSX;
|
|
501
|
+
case "jsx": return typescript.default.ScriptKind.JSX;
|
|
502
|
+
case "js":
|
|
503
|
+
case "cjs":
|
|
504
|
+
case "mjs": return typescript.default.ScriptKind.JS;
|
|
505
|
+
default: return typescript.default.ScriptKind.TS;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Uses esbuild (with `@stryke/resolve` path resolution) to walk the module
|
|
510
|
+
* graph, capturing original TypeScript sources before types are erased.
|
|
511
|
+
*/
|
|
512
|
+
async function bundleTypeScriptSources(filePath, options) {
|
|
513
|
+
const cwd = options.cwd || process.cwd();
|
|
514
|
+
const sources = /* @__PURE__ */ new Map();
|
|
515
|
+
const result = await (0, esbuild.build)({
|
|
516
|
+
absWorkingDir: cwd,
|
|
517
|
+
entryPoints: [filePath],
|
|
518
|
+
bundle: true,
|
|
519
|
+
write: false,
|
|
520
|
+
platform: "node",
|
|
521
|
+
format: "esm",
|
|
522
|
+
logLevel: "silent",
|
|
523
|
+
packages: "external",
|
|
524
|
+
plugins: [{
|
|
525
|
+
name: "power-plant-capture-ts-sources",
|
|
526
|
+
setup(buildApi) {
|
|
527
|
+
buildApi.onLoad({ filter: /.*/ }, async (args) => {
|
|
528
|
+
if (/[/\\]node_modules[/\\]/.test(args.path)) return null;
|
|
529
|
+
try {
|
|
530
|
+
const original = await (0, _stryke_resolve_resolve.resolve)(args.path, {
|
|
531
|
+
skipBundle: true,
|
|
532
|
+
cwd,
|
|
533
|
+
fs: options.fs
|
|
534
|
+
});
|
|
535
|
+
sources.set(normalizePath(args.path), original);
|
|
536
|
+
const extension = (0, _stryke_path_find.findFileExtensionSafe)(args.path);
|
|
537
|
+
const loader = extension === "tsx" || extension === "jsx" ? extension : extension === "js" || extension === "cjs" || extension === "mjs" ? "js" : "ts";
|
|
538
|
+
return {
|
|
539
|
+
contents: rewriteTypeOnlyImports(original),
|
|
540
|
+
loader
|
|
541
|
+
};
|
|
542
|
+
} catch {
|
|
543
|
+
return null;
|
|
544
|
+
}
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
}, (0, _stryke_resolve_bundle.plugin)({
|
|
548
|
+
originalInput: filePath,
|
|
549
|
+
cwd,
|
|
550
|
+
fs: options.fs ?? {}
|
|
551
|
+
})]
|
|
552
|
+
});
|
|
553
|
+
if (result.errors.length > 0) throw new Error(`Failed to bundle TypeScript sources for "${filePath}": ${result.errors.map((error) => error.text).join(", ")}`);
|
|
554
|
+
if (sources.size === 0) {
|
|
555
|
+
const fallback = await (0, _stryke_resolve_resolve.resolve)(filePath, {
|
|
556
|
+
skipBundle: true,
|
|
557
|
+
cwd,
|
|
558
|
+
fs: options.fs
|
|
559
|
+
});
|
|
560
|
+
sources.set(normalizePath(filePath), fallback);
|
|
561
|
+
}
|
|
562
|
+
return {
|
|
563
|
+
entryFileName: filePath,
|
|
564
|
+
sources
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Builds a TypeScript program from original sources collected during the
|
|
569
|
+
* esbuild graph walk so type information remains intact for schema generation.
|
|
570
|
+
*/
|
|
571
|
+
function createProgramFromSources(entryFileName, sources, config) {
|
|
572
|
+
const compilerOptions = getTsCompilerOptions(config);
|
|
573
|
+
const host = typescript.default.createCompilerHost(compilerOptions, true);
|
|
574
|
+
const normalizedSources = new Map([...sources.entries()].map(([key, value]) => [normalizePath(key), value]));
|
|
575
|
+
const getContent = (name) => normalizedSources.get(normalizePath(name)) ?? normalizedSources.get(name);
|
|
576
|
+
const baseFileExists = host.fileExists.bind(host);
|
|
577
|
+
const baseReadFile = host.readFile.bind(host);
|
|
578
|
+
const baseGetSourceFile = host.getSourceFile.bind(host);
|
|
579
|
+
host.fileExists = (name) => getContent(name) !== void 0 || baseFileExists(name);
|
|
580
|
+
host.readFile = (name) => getContent(name) ?? baseReadFile(name);
|
|
581
|
+
host.getSourceFile = (name, languageVersionOrOptions, onError, shouldCreateNewSourceFile) => {
|
|
582
|
+
const content = getContent(name);
|
|
583
|
+
if (content !== void 0) {
|
|
584
|
+
const scriptTarget = typeof languageVersionOrOptions === "object" ? languageVersionOrOptions.languageVersion : languageVersionOrOptions;
|
|
585
|
+
return typescript.default.createSourceFile(name, content, scriptTarget ?? compilerOptions.target ?? typescript.default.ScriptTarget.ES2022, true, getScriptKind(name));
|
|
586
|
+
}
|
|
587
|
+
return baseGetSourceFile(name, languageVersionOrOptions, onError, shouldCreateNewSourceFile);
|
|
588
|
+
};
|
|
589
|
+
const program = typescript.default.createProgram([entryFileName], compilerOptions, host);
|
|
590
|
+
if (!config.skipTypeCheck) {
|
|
591
|
+
const diagnostics = typescript.default.getPreEmitDiagnostics(program);
|
|
592
|
+
if (diagnostics.length) throw new Error(`Type check error: ${diagnostics.map((diagnostic) => diagnostic.messageText.toString()).join("\n")}`);
|
|
593
|
+
}
|
|
594
|
+
return program;
|
|
595
|
+
}
|
|
450
596
|
/**
|
|
451
|
-
* Resolves a type definition to a JSON Schema.
|
|
597
|
+
* Resolves a type definition to a JSON Schema. First bundles the TypeScript
|
|
598
|
+
* module graph for {@link FileReference.file} with esbuild (preserving original
|
|
599
|
+
* sources), then feeds that program to
|
|
600
|
+
* [ts-json-schema-generator](https://github.com/vega/ts-json-schema-generator)
|
|
601
|
+
* using the referenced export name as the target type when one is provided.
|
|
452
602
|
*
|
|
453
603
|
* @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
|
|
454
604
|
* @param options - Optional overrides reserved for API compatibility.
|
|
@@ -461,19 +611,29 @@ async function extractTSType(input, options = {}) {
|
|
|
461
611
|
const resolvedPath = await (0, _stryke_fs_resolve.resolveSafe)(fileReference.file, { fs: options.fs });
|
|
462
612
|
const filePath = resolvedPath || fileReference.file;
|
|
463
613
|
try {
|
|
464
|
-
const
|
|
465
|
-
|
|
466
|
-
|
|
614
|
+
const tsconfig = options.tsconfig ? (0, _stryke_path_append.appendPath)(options.tsconfig, options.cwd || process.cwd()) : (0, _stryke_path_join.joinPaths)(options.cwd || process.cwd(), "tsconfig.json");
|
|
615
|
+
const { entryFileName, sources } = await bundleTypeScriptSources(filePath, {
|
|
616
|
+
cwd: options.cwd || process.cwd(),
|
|
617
|
+
fs: options.fs
|
|
618
|
+
});
|
|
619
|
+
const config = {
|
|
620
|
+
...ts_json_schema_generator_dist_src_Config_js.DEFAULT_CONFIG,
|
|
467
621
|
expose: "all",
|
|
468
622
|
jsDoc: "extended",
|
|
469
623
|
markdownDescription: true,
|
|
470
624
|
fullDescription: true,
|
|
471
|
-
skipTypeCheck: true,
|
|
472
625
|
...options,
|
|
473
|
-
tsconfig
|
|
626
|
+
tsconfig,
|
|
627
|
+
path: entryFileName,
|
|
628
|
+
type: exportName,
|
|
629
|
+
skipTypeCheck: true
|
|
474
630
|
};
|
|
475
|
-
|
|
476
|
-
|
|
631
|
+
const tsProgram = createProgramFromSources(entryFileName, sources, config);
|
|
632
|
+
options.logger?.debug?.(`Generating JSON schema for bundled "${filePath}" using the type "${exportName}" (${sources.size} source file(s))`);
|
|
633
|
+
return (0, ts_json_schema_generator_dist_factory_generator_js.createGenerator)({
|
|
634
|
+
...config,
|
|
635
|
+
tsProgram
|
|
636
|
+
}).createSchema(exportName);
|
|
477
637
|
} catch (error) {
|
|
478
638
|
throw new Error(`Failed to generate a JSON schema for "${fileReference.file}"${resolvedPath && resolvedPath !== fileReference.file ? ` (resolved: ${resolvedPath})` : ""} using the type "${exportName}". Error: ${error.message}`);
|
|
479
639
|
}
|
|
@@ -676,10 +836,13 @@ exports.isSchemaWithSource = require_helpers.isSchemaWithSource;
|
|
|
676
836
|
exports.isStandardSchema = require_helpers.isStandardSchema;
|
|
677
837
|
exports.isUntypedConfig = require_helpers.isUntypedConfig;
|
|
678
838
|
exports.isUntypedConfigStrict = require_helpers.isUntypedConfigStrict;
|
|
839
|
+
exports.isUntypedInput = require_helpers.isUntypedInput;
|
|
840
|
+
exports.isUntypedInputStrict = require_helpers.isUntypedInputStrict;
|
|
679
841
|
exports.isUntypedSchema = require_helpers.isUntypedSchema;
|
|
680
842
|
exports.isUntypedSchemaStrict = require_helpers.isUntypedSchemaStrict;
|
|
681
843
|
exports.isValibotSchema = require_helpers.isValibotSchema;
|
|
682
844
|
exports.isValidSchemaConfigFile = require_helpers.isValidSchemaConfigFile;
|
|
845
|
+
exports.isValidSchemaInputFile = require_helpers.isValidSchemaInputFile;
|
|
683
846
|
exports.mapStorageToFileSystem = require_storage.mapStorageToFileSystem;
|
|
684
847
|
exports.merge = require_helpers.merge;
|
|
685
848
|
exports.mergeMetadata = require_helpers.mergeMetadata;
|
package/dist/index.d.cts
CHANGED
|
@@ -84,7 +84,11 @@ declare function extractSchema(input: SchemaSourceConfig, variant?: SchemaConfig
|
|
|
84
84
|
*/
|
|
85
85
|
declare function extractSource(variant: SchemaSourceVariant, input: SchemaSourceConfig): SchemaSource;
|
|
86
86
|
/**
|
|
87
|
-
* Resolves a type definition to a JSON Schema.
|
|
87
|
+
* Resolves a type definition to a JSON Schema. First bundles the TypeScript
|
|
88
|
+
* module graph for {@link FileReference.file} with esbuild (preserving original
|
|
89
|
+
* sources), then feeds that program to
|
|
90
|
+
* [ts-json-schema-generator](https://github.com/vega/ts-json-schema-generator)
|
|
91
|
+
* using the referenced export name as the target type when one is provided.
|
|
88
92
|
*
|
|
89
93
|
* @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
|
|
90
94
|
* @param options - Optional overrides reserved for API compatibility.
|
|
@@ -289,6 +293,8 @@ declare function isPropertyOptional(parent: JsonSchemaObject, propertyName: stri
|
|
|
289
293
|
* @returns `true` if the file name has a valid schema input extension, otherwise `false`.
|
|
290
294
|
*/
|
|
291
295
|
declare function isValidSchemaConfigFile(fileName: string): boolean;
|
|
296
|
+
/** @deprecated Use {@link isValidSchemaConfigFile} */
|
|
297
|
+
declare const isValidSchemaInputFile: typeof isValidSchemaConfigFile;
|
|
292
298
|
/**
|
|
293
299
|
* Traverses a JSON Schema and applies a callback function to each schema fragment.
|
|
294
300
|
*
|
|
@@ -610,6 +616,8 @@ declare function isUntypedSchemaStrict(input: unknown): input is Schema;
|
|
|
610
616
|
* @param input - The value to check.
|
|
611
617
|
* @returns True if the input is an untyped input object, false otherwise.
|
|
612
618
|
*/
|
|
619
|
+
/** @deprecated Use {@link isUntypedConfig} */
|
|
620
|
+
declare const isUntypedInput: typeof isUntypedConfig;
|
|
613
621
|
declare function isUntypedConfig(input: unknown): input is InputObject;
|
|
614
622
|
/**
|
|
615
623
|
* Strict type guard for untyped input objects.
|
|
@@ -621,6 +629,8 @@ declare function isUntypedConfig(input: unknown): input is InputObject;
|
|
|
621
629
|
* @param input - The value to check.
|
|
622
630
|
* @returns True if the input is an untyped input object and not JSON Schema.
|
|
623
631
|
*/
|
|
632
|
+
/** @deprecated Use {@link isUntypedConfigStrict} */
|
|
633
|
+
declare const isUntypedInputStrict: typeof isUntypedConfigStrict;
|
|
624
634
|
declare function isUntypedConfigStrict(input: unknown): input is InputObject;
|
|
625
635
|
/**
|
|
626
636
|
* Type guard for Powerlines Schema objects.
|
|
@@ -651,5 +661,5 @@ declare function isSchemaWithSource(input: unknown): input is ExtractedSchemaEnv
|
|
|
651
661
|
*/
|
|
652
662
|
declare function isSchemaObject(input: unknown): input is SchemaEnvelope<JsonSchemaObject>;
|
|
653
663
|
//#endregion
|
|
654
|
-
export { type BaseExtractOptions, type BaseSchemaSource, type ExtractedSchemaEnvelope, GetPropertyResult, type InferExtractOptions, JSON_SCHEMA_METADATA_KEYS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES, type JsonSchema, type JsonSchemaAllOf, type JsonSchemaAny, type JsonSchemaAnyOf, type JsonSchemaArray, type JsonSchemaBigint, type JsonSchemaBoolean, type JsonSchemaConditionalKeywords, type JsonSchemaDate, type JsonSchemaDecimal, type JsonSchemaDecimalFormat, type JsonSchemaEnum, type JsonSchemaInteger, type JsonSchemaIntegerFormat, type JsonSchemaKeywords, type JsonSchemaLike, type JsonSchemaLiteral, type JsonSchemaLogicKeywords, type JsonSchemaMap, type JsonSchemaMetadataKeywords, type JsonSchemaNativeEnum, type JsonSchemaNever, type JsonSchemaNull, type JsonSchemaNullable, type JsonSchemaNumber, type JsonSchemaNumberFormat, type JsonSchemaObject, type JsonSchemaOf, type JsonSchemaPrimitiveType, type JsonSchemaPrimitiveUnion, type JsonSchemaRecord, type JsonSchemaRecordPropertyNames, type JsonSchemaRef, type JsonSchemaSchemaSource, type JsonSchemaSet, type JsonSchemaString, type JsonSchemaStringFormat, type JsonSchemaTuple, type JsonSchemaType, JsonSchemaTypeNames, type JsonSchemaUndefined, type JsonSchemaUnion, type JsonSchemaUnknown, SCHEMA_ARRAY_CONCAT_KEYWORDS, SCHEMA_RECORD_KEYWORDS, SCHEMA_SINGLE_KEYWORDS, type SchemaConfig, type SchemaConfigVariant, type SchemaEnvelope, type SchemaEnvelopeOf, type SchemaSource, type SchemaSourceConfig, type SchemaSourceVariant, type SpecOf, type StandardSchemaSchemaSource, type UntypedConfigObject, type UntypedSchema, type UntypedSchemaSource, type ValibotSchema, type ValibotSchemaSource, type Zod3SchemaSource, addProperty, applyJsonSchemaMetadata, assertSchemasDoNotContradict, bundleReferences, createStoragePromises, extract, extractHash, extractJsonSchema, extractResolvedVariant, extractSchema, extractSchemaWithSource, extractSource, extractTSType, extractVariant, findSchemaContradictions, getJsonSchema, getJsonSchemaObject, getPrimarySchemaType, getProperties, getPropertiesList, getProperty, isFileReference, isJsonSchema, isJsonSchemaAllOf, isJsonSchemaAny, isJsonSchemaAnyOf, isJsonSchemaArray, isJsonSchemaBigint, isJsonSchemaBoolean, isJsonSchemaDate, isJsonSchemaDecimal, isJsonSchemaEnum, isJsonSchemaInteger, isJsonSchemaKeywords, isJsonSchemaLiteral, isJsonSchemaMap, isJsonSchemaNativeEnum, isJsonSchemaNever, isJsonSchemaNull, isJsonSchemaNullable, isJsonSchemaNumber, isJsonSchemaObject, isJsonSchemaPrimitiveType, isJsonSchemaPrimitiveUnion, isJsonSchemaRecord, isJsonSchemaRef, isJsonSchemaSet, isJsonSchemaString, isJsonSchemaTuple, isJsonSchemaType, isJsonSchemaUndefined, isJsonSchemaUnion, isJsonSchemaUnknown, isNullOnlyJsonSchema, isPropertyOptional, isSchema, isSchemaNullable, isSchemaObject, isSchemaOf, isSchemaWithSource, isStandardSchema, isUntypedConfig, isUntypedConfigStrict, isUntypedSchema, isUntypedSchemaStrict, isValibotSchema, isValidSchemaConfigFile, mapStorageToFileSystem, merge, mergeMetadata, normalizeKey, readSchemaTypes, traverseSchema };
|
|
664
|
+
export { type BaseExtractOptions, type BaseSchemaSource, type ExtractedSchemaEnvelope, GetPropertyResult, type InferExtractOptions, JSON_SCHEMA_METADATA_KEYS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES, type JsonSchema, type JsonSchemaAllOf, type JsonSchemaAny, type JsonSchemaAnyOf, type JsonSchemaArray, type JsonSchemaBigint, type JsonSchemaBoolean, type JsonSchemaConditionalKeywords, type JsonSchemaDate, type JsonSchemaDecimal, type JsonSchemaDecimalFormat, type JsonSchemaEnum, type JsonSchemaInteger, type JsonSchemaIntegerFormat, type JsonSchemaKeywords, type JsonSchemaLike, type JsonSchemaLiteral, type JsonSchemaLogicKeywords, type JsonSchemaMap, type JsonSchemaMetadataKeywords, type JsonSchemaNativeEnum, type JsonSchemaNever, type JsonSchemaNull, type JsonSchemaNullable, type JsonSchemaNumber, type JsonSchemaNumberFormat, type JsonSchemaObject, type JsonSchemaOf, type JsonSchemaPrimitiveType, type JsonSchemaPrimitiveUnion, type JsonSchemaRecord, type JsonSchemaRecordPropertyNames, type JsonSchemaRef, type JsonSchemaSchemaSource, type JsonSchemaSet, type JsonSchemaString, type JsonSchemaStringFormat, type JsonSchemaTuple, type JsonSchemaType, JsonSchemaTypeNames, type JsonSchemaUndefined, type JsonSchemaUnion, type JsonSchemaUnknown, SCHEMA_ARRAY_CONCAT_KEYWORDS, SCHEMA_RECORD_KEYWORDS, SCHEMA_SINGLE_KEYWORDS, type SchemaConfig, type SchemaConfigVariant, type SchemaEnvelope, type SchemaEnvelopeOf, type SchemaSource, type SchemaSourceConfig, type SchemaSourceVariant, type SpecOf, type StandardSchemaSchemaSource, type UntypedConfigObject, type UntypedSchema, type UntypedSchemaSource, type ValibotSchema, type ValibotSchemaSource, type Zod3SchemaSource, addProperty, applyJsonSchemaMetadata, assertSchemasDoNotContradict, bundleReferences, createStoragePromises, extract, extractHash, extractJsonSchema, extractResolvedVariant, extractSchema, extractSchemaWithSource, extractSource, extractTSType, extractVariant, findSchemaContradictions, getJsonSchema, getJsonSchemaObject, getPrimarySchemaType, getProperties, getPropertiesList, getProperty, isFileReference, isJsonSchema, isJsonSchemaAllOf, isJsonSchemaAny, isJsonSchemaAnyOf, isJsonSchemaArray, isJsonSchemaBigint, isJsonSchemaBoolean, isJsonSchemaDate, isJsonSchemaDecimal, isJsonSchemaEnum, isJsonSchemaInteger, isJsonSchemaKeywords, isJsonSchemaLiteral, isJsonSchemaMap, isJsonSchemaNativeEnum, isJsonSchemaNever, isJsonSchemaNull, isJsonSchemaNullable, isJsonSchemaNumber, isJsonSchemaObject, isJsonSchemaPrimitiveType, isJsonSchemaPrimitiveUnion, isJsonSchemaRecord, isJsonSchemaRef, isJsonSchemaSet, isJsonSchemaString, isJsonSchemaTuple, isJsonSchemaType, isJsonSchemaUndefined, isJsonSchemaUnion, isJsonSchemaUnknown, isNullOnlyJsonSchema, isPropertyOptional, isSchema, isSchemaNullable, isSchemaObject, isSchemaOf, isSchemaWithSource, isStandardSchema, isUntypedConfig, isUntypedConfigStrict, isUntypedInput, isUntypedInputStrict, isUntypedSchema, isUntypedSchemaStrict, isValibotSchema, isValidSchemaConfigFile, isValidSchemaInputFile, mapStorageToFileSystem, merge, mergeMetadata, normalizeKey, readSchemaTypes, traverseSchema };
|
|
655
665
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/compatibility.ts","../src/extract.ts","../src/helpers.ts","../src/metadata.ts","../src/type-checks.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;iBAwGgB,yBACd,MAAM,YACN,UAAU,YACV;;;;;;;;;iBAqHc,6BACd,MAAM,YACN,UAAU,YACV;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/compatibility.ts","../src/extract.ts","../src/helpers.ts","../src/metadata.ts","../src/type-checks.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;iBAwGgB,yBACd,MAAM,YACN,UAAU,YACV;;;;;;;;;iBAqHc,6BACd,MAAM,YACN,UAAU,YACV;;;;;;;;;iBC8Cc,iBAAiB,QAAQ,aAAa;;;;iBAgMtC,YACd,SAAS,qBACT,OAAO;;;;;;;iBAgDO,kBAAkB,kBAAkB;;;;;;;;iBAoCpC,uBACd,OAAO,qBACN;;;;;;;iBA0Ba,eAAe,OAAO,eAAe;;;;;;;;;iBAsB/B,cACpB,OAAO,oBACP,UAAU,sBACT,QAAQ;;;;;;;;;iBAmCK,cACd,SAAS,qBACT,OAAO,qBACN;;;;;;;;;;;;iBAkSmB,cACpB,OAAO,oBACP,UAAS,wBAAwB,SAAS,qBACzC,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+FW,wBAAwB,aAC5C,OAAO,cACP,UAAS,2BAA2B,SACnC,QAAQ,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0Ib,QAAQ,aAC5B,OAAO,aAAa,QACpB,UAAS,2BAA2B,SACnC,QAAQ,iBAAiB;;;KC9mChB,oBAAoB;EAC9B;EACA;EACA;;;;;;;;;;;;iBAac,cAAc,OAAO,iBAAiB,aAAa;;;;;;;;;;;iBAmBnD,oBACd,OAAO,iBAAiB,aACvB;;;;;;;;;;iBAkBa,cACd,KAAK,iBAAiB,mBACrB,eAAe;;;;;;;;;;iBA6BF,kBAAkB,KAAK,iBAAiB,mBAAgB;;;;;;;;;;iBAaxD,YAAY,gBAAgB,kBAC1C,KAAK,eAAe,WAAW,SAC/B,YAAY,iCACX;;;;;;;;;;;;iBAgCa,YACd,KAAK,iBAAiB,kBACtB,cACA,UAAU;;;;;;;;;;;;;;;;;;;;iBAyGI,SAAS,UAAU,aAAa,oBAAoB;;;;;;;;;;;iBA6BpD,cAAc,OAC5B,QAAQ,aAAa,QACrB,UAAU,6BACT,aAAa;;;;;;;;;;iBAoBA,iBAAiB,SAAS;;;;;;;;;;;iBAsB1B,mBACd,QAAQ,kBACR;;;;;;;iBAiBc,wBAAwB;;cAO3B,+BAAsB;;;;;;;;;;;iBAYnB,eAAe,GAC7B,QAAQ,YACR,WAAW,QAAQ,eAAe,WACjC;;;;;;;;;;iBCtWa,wBACd,QAAQ,YACR,UAAU,yCACT;;;;;;;;;;iBA0Ba,gBACd,SAAS,aACR;;;;;;;iBA6Ba,qBACd,SAAS,aACR;;;;;;;;;iBCvBa,gBAAgB,aAAa,SAAS;;;;;;;iBAsCtC,0BACd,iBACC,SAAS;;;;;;;iBAaI,iBAAiB,iBAAiB,SAAS;;;;;;;iBAiR3C,qBACd,iBACC,SAAS;;;;;;;iBAcI,gBAAgB,iBAAiB,SAAS;;;;;;;iBA0B1C,kBAAkB,iBAAiB,SAAS;;;;;;;iBA+B5C,mBAAmB,iBAAiB,SAAS;;;;;;;iBA+B7C,oBACd,iBACC,SAAS;;;;;;;iBAoBI,iBAAiB,iBAAiB,SAAS;;;;;;;iBAqC3C,iBAAiB,iBAAiB,SAAS;;;;;;;iBAuD3C,kBAAkB,iBAAiB,SAAS;;;;;;;iBA0B5C,oBACd,iBACC,SAAS;;;;;;;iBAuBI,gBAAgB,iBAAiB,SAAS;;;;;;;iBAgC1C,uBACd,iBACC,SAAS;;;;;;;iBA4BI,kBAAkB,iBAAiB,SAAS;;;;;;;iBAgB5C,iBAAiB,iBAAiB,SAAS;;;;;;;iBAuB3C,qBACd,iBACC,SAAS;;;;;;;iBAsCI,mBAAmB,iBAAiB,SAAS;;;;;;;iBA+B7C,oBACd,iBACC,SAAS;;;;;;;iBAUI,oBACd,iBACC,SAAS;;;;;;;iBAUI,mBAAmB,iBAAiB,SAAS;;;;;;;iBA2C7C,mBAAmB,iBAAiB,SAAS;;;;;;;iBA4B7C,gBAAgB,iBAAiB,SAAS;;;;;;;iBA8B1C,mBAAmB,iBAAiB,SAAS;;;;;;;iBAyB7C,kBAAkB,iBAAiB,SAAS;;;;;;;iBA8B5C,sBACd,iBACC,SAAS;;;;;;;iBAoBI,2BACd,iBACC,SAAS;;;;;;;iBAsEI,kBAAkB,iBAAiB,SAAS;;;;;;;iBAmB5C,oBACd,iBACC,SAAS;;;;;;;iBAUI,kBAAkB,iBAAiB,SAAS;;;;;;;iBAkB5C,gBAAgB,iBAAiB,SAAS;;;;;;;iBAgB1C,iBAAiB,iBAAiB,SAAS;;;;;;;iBAqB3C,gBACd,iBACC,SAAS;;;;;;;;;;iBA0BI,aAAa,iBAAiB,SAAS;;;;;;;;;;iBAsCvC,qBAAqB,iBAAiB,SAAS;;;;;;;;;;iBAa/C,gBAAgB,iBAAiB,SAAS;;;;;;;;;;;iBAyD1C,sBAAsB,iBAAiB,SAAS;;;;;;;;;;;cAmBnD,uBAAc;iBAEX,gBAAgB,iBAAiB,SAAS;;;;;;;;;;;;cA2B7C,6BAAoB;iBAEjB,sBACd,iBACC,SAAS;;;;;;;iBAuBI,SAAS,iBAAiB,SAAS;;;;;;;iBAkBnC,WAAW,OACzB,iBACC,SAAS,iBAAiB;;;;;;;iBAUb,mBAAmB,iBAAiB,SAAS;;;;;;;iBAiB7C,eACd,iBACC,SAAS,eAAe"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as SchemaSourceVariant, A as JsonSchemaNumberFormat, B as JsonSchemaString, C as JsonSchemaMap, D as JsonSchemaNull, E as JsonSchemaNever, F as JsonSchemaRecord, G as JsonSchemaUnion, H as JsonSchemaTuple, I as JsonSchemaRecordPropertyNames, J as SchemaConfigVariant, K as JsonSchemaUnknown, L as JsonSchemaRef, M as JsonSchemaOf, N as JsonSchemaPrimitiveType, O as JsonSchemaNullable, P as JsonSchemaPrimitiveUnion, Q as SchemaSourceConfig, R as JsonSchemaSchemaSource, S as JsonSchemaLogicKeywords, T as JsonSchemaNativeEnum, U as JsonSchemaType, V as JsonSchemaStringFormat, W as JsonSchemaUndefined, X as SchemaEnvelopeOf, Y as SchemaEnvelope, Z as SchemaSource, _ as JsonSchemaInteger, a as JsonSchema, at as ValibotSchema, b as JsonSchemaLike, c as JsonSchemaAnyOf, ct as JSON_SCHEMA_METADATA_KEYS, d as JsonSchemaBoolean, dt as JsonSchemaTypeNames, et as SpecOf, f as JsonSchemaConditionalKeywords, ft as SCHEMA_ARRAY_CONCAT_KEYWORDS, g as JsonSchemaEnum, h as JsonSchemaDecimalFormat, i as InferExtractOptions, it as UntypedSchemaSource, j as JsonSchemaObject, k as JsonSchemaNumber, l as JsonSchemaArray, lt as JSON_SCHEMA_PRIMITIVE_TYPES, m as JsonSchemaDecimal, mt as SCHEMA_SINGLE_KEYWORDS, n as BaseSchemaSource, nt as UntypedConfigObject, o as JsonSchemaAllOf, ot as ValibotSchemaSource, p as JsonSchemaDate, pt as SCHEMA_RECORD_KEYWORDS, q as SchemaConfig, r as ExtractedSchemaEnvelope, rt as UntypedSchema, s as JsonSchemaAny, st as Zod3SchemaSource, t as BaseExtractOptions, tt as StandardSchemaSchemaSource, u as JsonSchemaBigint, ut as JSON_SCHEMA_TYPES, v as JsonSchemaIntegerFormat, w as JsonSchemaMetadataKeywords, x as JsonSchemaLiteral, y as JsonSchemaKeywords, z as JsonSchemaSet } from "./types-
|
|
1
|
+
import { $ as SchemaSourceVariant, A as JsonSchemaNumberFormat, B as JsonSchemaString, C as JsonSchemaMap, D as JsonSchemaNull, E as JsonSchemaNever, F as JsonSchemaRecord, G as JsonSchemaUnion, H as JsonSchemaTuple, I as JsonSchemaRecordPropertyNames, J as SchemaConfigVariant, K as JsonSchemaUnknown, L as JsonSchemaRef, M as JsonSchemaOf, N as JsonSchemaPrimitiveType, O as JsonSchemaNullable, P as JsonSchemaPrimitiveUnion, Q as SchemaSourceConfig, R as JsonSchemaSchemaSource, S as JsonSchemaLogicKeywords, T as JsonSchemaNativeEnum, U as JsonSchemaType, V as JsonSchemaStringFormat, W as JsonSchemaUndefined, X as SchemaEnvelopeOf, Y as SchemaEnvelope, Z as SchemaSource, _ as JsonSchemaInteger, a as JsonSchema, at as ValibotSchema, b as JsonSchemaLike, c as JsonSchemaAnyOf, ct as JSON_SCHEMA_METADATA_KEYS, d as JsonSchemaBoolean, dt as JsonSchemaTypeNames, et as SpecOf, f as JsonSchemaConditionalKeywords, ft as SCHEMA_ARRAY_CONCAT_KEYWORDS, g as JsonSchemaEnum, h as JsonSchemaDecimalFormat, i as InferExtractOptions, it as UntypedSchemaSource, j as JsonSchemaObject, k as JsonSchemaNumber, l as JsonSchemaArray, lt as JSON_SCHEMA_PRIMITIVE_TYPES, m as JsonSchemaDecimal, mt as SCHEMA_SINGLE_KEYWORDS, n as BaseSchemaSource, nt as UntypedConfigObject, o as JsonSchemaAllOf, ot as ValibotSchemaSource, p as JsonSchemaDate, pt as SCHEMA_RECORD_KEYWORDS, q as SchemaConfig, r as ExtractedSchemaEnvelope, rt as UntypedSchema, s as JsonSchemaAny, st as Zod3SchemaSource, t as BaseExtractOptions, tt as StandardSchemaSchemaSource, u as JsonSchemaBigint, ut as JSON_SCHEMA_TYPES, v as JsonSchemaIntegerFormat, w as JsonSchemaMetadataKeywords, x as JsonSchemaLiteral, y as JsonSchemaKeywords, z as JsonSchemaSet } from "./types-CyvYSCHO.mjs";
|
|
2
2
|
import { n as createStoragePromises, r as normalizeKey, t as mapStorageToFileSystem } from "./index-C7q4X7Bo.mjs";
|
|
3
3
|
import { BaseSchema } from "valibot";
|
|
4
4
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
@@ -84,7 +84,11 @@ declare function extractSchema(input: SchemaSourceConfig, variant?: SchemaConfig
|
|
|
84
84
|
*/
|
|
85
85
|
declare function extractSource(variant: SchemaSourceVariant, input: SchemaSourceConfig): SchemaSource;
|
|
86
86
|
/**
|
|
87
|
-
* Resolves a type definition to a JSON Schema.
|
|
87
|
+
* Resolves a type definition to a JSON Schema. First bundles the TypeScript
|
|
88
|
+
* module graph for {@link FileReference.file} with esbuild (preserving original
|
|
89
|
+
* sources), then feeds that program to
|
|
90
|
+
* [ts-json-schema-generator](https://github.com/vega/ts-json-schema-generator)
|
|
91
|
+
* using the referenced export name as the target type when one is provided.
|
|
88
92
|
*
|
|
89
93
|
* @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
|
|
90
94
|
* @param options - Optional overrides reserved for API compatibility.
|
|
@@ -289,6 +293,8 @@ declare function isPropertyOptional(parent: JsonSchemaObject, propertyName: stri
|
|
|
289
293
|
* @returns `true` if the file name has a valid schema input extension, otherwise `false`.
|
|
290
294
|
*/
|
|
291
295
|
declare function isValidSchemaConfigFile(fileName: string): boolean;
|
|
296
|
+
/** @deprecated Use {@link isValidSchemaConfigFile} */
|
|
297
|
+
declare const isValidSchemaInputFile: typeof isValidSchemaConfigFile;
|
|
292
298
|
/**
|
|
293
299
|
* Traverses a JSON Schema and applies a callback function to each schema fragment.
|
|
294
300
|
*
|
|
@@ -610,6 +616,8 @@ declare function isUntypedSchemaStrict(input: unknown): input is Schema;
|
|
|
610
616
|
* @param input - The value to check.
|
|
611
617
|
* @returns True if the input is an untyped input object, false otherwise.
|
|
612
618
|
*/
|
|
619
|
+
/** @deprecated Use {@link isUntypedConfig} */
|
|
620
|
+
declare const isUntypedInput: typeof isUntypedConfig;
|
|
613
621
|
declare function isUntypedConfig(input: unknown): input is InputObject;
|
|
614
622
|
/**
|
|
615
623
|
* Strict type guard for untyped input objects.
|
|
@@ -621,6 +629,8 @@ declare function isUntypedConfig(input: unknown): input is InputObject;
|
|
|
621
629
|
* @param input - The value to check.
|
|
622
630
|
* @returns True if the input is an untyped input object and not JSON Schema.
|
|
623
631
|
*/
|
|
632
|
+
/** @deprecated Use {@link isUntypedConfigStrict} */
|
|
633
|
+
declare const isUntypedInputStrict: typeof isUntypedConfigStrict;
|
|
624
634
|
declare function isUntypedConfigStrict(input: unknown): input is InputObject;
|
|
625
635
|
/**
|
|
626
636
|
* Type guard for Powerlines Schema objects.
|
|
@@ -651,5 +661,5 @@ declare function isSchemaWithSource(input: unknown): input is ExtractedSchemaEnv
|
|
|
651
661
|
*/
|
|
652
662
|
declare function isSchemaObject(input: unknown): input is SchemaEnvelope<JsonSchemaObject>;
|
|
653
663
|
//#endregion
|
|
654
|
-
export { type BaseExtractOptions, type BaseSchemaSource, type ExtractedSchemaEnvelope, GetPropertyResult, type InferExtractOptions, JSON_SCHEMA_METADATA_KEYS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES, type JsonSchema, type JsonSchemaAllOf, type JsonSchemaAny, type JsonSchemaAnyOf, type JsonSchemaArray, type JsonSchemaBigint, type JsonSchemaBoolean, type JsonSchemaConditionalKeywords, type JsonSchemaDate, type JsonSchemaDecimal, type JsonSchemaDecimalFormat, type JsonSchemaEnum, type JsonSchemaInteger, type JsonSchemaIntegerFormat, type JsonSchemaKeywords, type JsonSchemaLike, type JsonSchemaLiteral, type JsonSchemaLogicKeywords, type JsonSchemaMap, type JsonSchemaMetadataKeywords, type JsonSchemaNativeEnum, type JsonSchemaNever, type JsonSchemaNull, type JsonSchemaNullable, type JsonSchemaNumber, type JsonSchemaNumberFormat, type JsonSchemaObject, type JsonSchemaOf, type JsonSchemaPrimitiveType, type JsonSchemaPrimitiveUnion, type JsonSchemaRecord, type JsonSchemaRecordPropertyNames, type JsonSchemaRef, type JsonSchemaSchemaSource, type JsonSchemaSet, type JsonSchemaString, type JsonSchemaStringFormat, type JsonSchemaTuple, type JsonSchemaType, JsonSchemaTypeNames, type JsonSchemaUndefined, type JsonSchemaUnion, type JsonSchemaUnknown, SCHEMA_ARRAY_CONCAT_KEYWORDS, SCHEMA_RECORD_KEYWORDS, SCHEMA_SINGLE_KEYWORDS, type SchemaConfig, type SchemaConfigVariant, type SchemaEnvelope, type SchemaEnvelopeOf, type SchemaSource, type SchemaSourceConfig, type SchemaSourceVariant, type SpecOf, type StandardSchemaSchemaSource, type UntypedConfigObject, type UntypedSchema, type UntypedSchemaSource, type ValibotSchema, type ValibotSchemaSource, type Zod3SchemaSource, addProperty, applyJsonSchemaMetadata, assertSchemasDoNotContradict, bundleReferences, createStoragePromises, extract, extractHash, extractJsonSchema, extractResolvedVariant, extractSchema, extractSchemaWithSource, extractSource, extractTSType, extractVariant, findSchemaContradictions, getJsonSchema, getJsonSchemaObject, getPrimarySchemaType, getProperties, getPropertiesList, getProperty, isFileReference, isJsonSchema, isJsonSchemaAllOf, isJsonSchemaAny, isJsonSchemaAnyOf, isJsonSchemaArray, isJsonSchemaBigint, isJsonSchemaBoolean, isJsonSchemaDate, isJsonSchemaDecimal, isJsonSchemaEnum, isJsonSchemaInteger, isJsonSchemaKeywords, isJsonSchemaLiteral, isJsonSchemaMap, isJsonSchemaNativeEnum, isJsonSchemaNever, isJsonSchemaNull, isJsonSchemaNullable, isJsonSchemaNumber, isJsonSchemaObject, isJsonSchemaPrimitiveType, isJsonSchemaPrimitiveUnion, isJsonSchemaRecord, isJsonSchemaRef, isJsonSchemaSet, isJsonSchemaString, isJsonSchemaTuple, isJsonSchemaType, isJsonSchemaUndefined, isJsonSchemaUnion, isJsonSchemaUnknown, isNullOnlyJsonSchema, isPropertyOptional, isSchema, isSchemaNullable, isSchemaObject, isSchemaOf, isSchemaWithSource, isStandardSchema, isUntypedConfig, isUntypedConfigStrict, isUntypedSchema, isUntypedSchemaStrict, isValibotSchema, isValidSchemaConfigFile, mapStorageToFileSystem, merge, mergeMetadata, normalizeKey, readSchemaTypes, traverseSchema };
|
|
664
|
+
export { type BaseExtractOptions, type BaseSchemaSource, type ExtractedSchemaEnvelope, GetPropertyResult, type InferExtractOptions, JSON_SCHEMA_METADATA_KEYS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES, type JsonSchema, type JsonSchemaAllOf, type JsonSchemaAny, type JsonSchemaAnyOf, type JsonSchemaArray, type JsonSchemaBigint, type JsonSchemaBoolean, type JsonSchemaConditionalKeywords, type JsonSchemaDate, type JsonSchemaDecimal, type JsonSchemaDecimalFormat, type JsonSchemaEnum, type JsonSchemaInteger, type JsonSchemaIntegerFormat, type JsonSchemaKeywords, type JsonSchemaLike, type JsonSchemaLiteral, type JsonSchemaLogicKeywords, type JsonSchemaMap, type JsonSchemaMetadataKeywords, type JsonSchemaNativeEnum, type JsonSchemaNever, type JsonSchemaNull, type JsonSchemaNullable, type JsonSchemaNumber, type JsonSchemaNumberFormat, type JsonSchemaObject, type JsonSchemaOf, type JsonSchemaPrimitiveType, type JsonSchemaPrimitiveUnion, type JsonSchemaRecord, type JsonSchemaRecordPropertyNames, type JsonSchemaRef, type JsonSchemaSchemaSource, type JsonSchemaSet, type JsonSchemaString, type JsonSchemaStringFormat, type JsonSchemaTuple, type JsonSchemaType, JsonSchemaTypeNames, type JsonSchemaUndefined, type JsonSchemaUnion, type JsonSchemaUnknown, SCHEMA_ARRAY_CONCAT_KEYWORDS, SCHEMA_RECORD_KEYWORDS, SCHEMA_SINGLE_KEYWORDS, type SchemaConfig, type SchemaConfigVariant, type SchemaEnvelope, type SchemaEnvelopeOf, type SchemaSource, type SchemaSourceConfig, type SchemaSourceVariant, type SpecOf, type StandardSchemaSchemaSource, type UntypedConfigObject, type UntypedSchema, type UntypedSchemaSource, type ValibotSchema, type ValibotSchemaSource, type Zod3SchemaSource, addProperty, applyJsonSchemaMetadata, assertSchemasDoNotContradict, bundleReferences, createStoragePromises, extract, extractHash, extractJsonSchema, extractResolvedVariant, extractSchema, extractSchemaWithSource, extractSource, extractTSType, extractVariant, findSchemaContradictions, getJsonSchema, getJsonSchemaObject, getPrimarySchemaType, getProperties, getPropertiesList, getProperty, isFileReference, isJsonSchema, isJsonSchemaAllOf, isJsonSchemaAny, isJsonSchemaAnyOf, isJsonSchemaArray, isJsonSchemaBigint, isJsonSchemaBoolean, isJsonSchemaDate, isJsonSchemaDecimal, isJsonSchemaEnum, isJsonSchemaInteger, isJsonSchemaKeywords, isJsonSchemaLiteral, isJsonSchemaMap, isJsonSchemaNativeEnum, isJsonSchemaNever, isJsonSchemaNull, isJsonSchemaNullable, isJsonSchemaNumber, isJsonSchemaObject, isJsonSchemaPrimitiveType, isJsonSchemaPrimitiveUnion, isJsonSchemaRecord, isJsonSchemaRef, isJsonSchemaSet, isJsonSchemaString, isJsonSchemaTuple, isJsonSchemaType, isJsonSchemaUndefined, isJsonSchemaUnion, isJsonSchemaUnknown, isNullOnlyJsonSchema, isPropertyOptional, isSchema, isSchemaNullable, isSchemaObject, isSchemaOf, isSchemaWithSource, isStandardSchema, isUntypedConfig, isUntypedConfigStrict, isUntypedInput, isUntypedInputStrict, isUntypedSchema, isUntypedSchemaStrict, isValibotSchema, isValidSchemaConfigFile, isValidSchemaInputFile, mapStorageToFileSystem, merge, mergeMetadata, normalizeKey, readSchemaTypes, traverseSchema };
|
|
655
665
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as SCHEMA_ARRAY_CONCAT_KEYWORDS, i as JsonSchemaTypeNames, n as JSON_SCHEMA_PRIMITIVE_TYPES, o as SCHEMA_RECORD_KEYWORDS, r as JSON_SCHEMA_TYPES, s as SCHEMA_SINGLE_KEYWORDS, t as JSON_SCHEMA_METADATA_KEYS } from "./constants-COGt3eeW.mjs";
|
|
2
|
-
import { $ as
|
|
2
|
+
import { $ as isUntypedConfigStrict, A as isJsonSchemaNever, B as isJsonSchemaString, C as isJsonSchemaDecimal, D as isJsonSchemaLiteral, E as isJsonSchemaKeywords, F as isJsonSchemaPrimitiveType, G as isJsonSchemaUnknown, H as isJsonSchemaType, I as isJsonSchemaPrimitiveUnion, J as isSchemaObject, K as isNullOnlyJsonSchema, L as isJsonSchemaRecord, M as isJsonSchemaNullable, N as isJsonSchemaNumber, O as isJsonSchemaMap, P as isJsonSchemaObject, Q as isUntypedConfig, R as isJsonSchemaRef, S as isJsonSchemaDate, T as isJsonSchemaInteger, U as isJsonSchemaUndefined, V as isJsonSchemaTuple, W as isJsonSchemaUnion, X as isSchemaWithSource, Y as isSchemaOf, Z as isStandardSchema, _ as isJsonSchemaAny, a as getPropertiesList, at as applyJsonSchemaMetadata, b as isJsonSchemaBigint, c as isSchemaNullable, d as merge, et as isUntypedInput, f as mergeMetadata, g as isJsonSchemaAllOf, h as isJsonSchema, i as getProperties, it as isValibotSchema, j as isJsonSchemaNull, k as isJsonSchemaNativeEnum, l as isValidSchemaConfigFile, m as isFileReference, n as getJsonSchema, nt as isUntypedSchema, o as getProperty, ot as getPrimarySchemaType, p as traverseSchema, q as isSchema, r as getJsonSchemaObject, rt as isUntypedSchemaStrict, s as isPropertyOptional, st as readSchemaTypes, t as addProperty, tt as isUntypedInputStrict, u as isValidSchemaInputFile, v as isJsonSchemaAnyOf, w as isJsonSchemaEnum, x as isJsonSchemaBoolean, y as isJsonSchemaArray, z as isJsonSchemaSet } from "./helpers-dvxktFml.mjs";
|
|
3
3
|
import { n as createStoragePromises, r as normalizeKey, t as mapStorageToFileSystem } from "./storage-C3BT2Xh-.mjs";
|
|
4
4
|
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
5
5
|
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
@@ -10,14 +10,19 @@ import { murmurhash } from "@stryke/hash";
|
|
|
10
10
|
import { deepClone } from "@stryke/helpers/deep-clone";
|
|
11
11
|
import { isStandardJsonSchema } from "@stryke/json";
|
|
12
12
|
import { appendPath } from "@stryke/path/append";
|
|
13
|
-
import { findFileExtensionSafe } from "@stryke/path/find";
|
|
13
|
+
import { findFileExtensionSafe, findFilePath } from "@stryke/path/find";
|
|
14
14
|
import { joinPaths } from "@stryke/path/join";
|
|
15
|
+
import { plugin } from "@stryke/resolve/bundle";
|
|
15
16
|
import { VALID_OBJECT_SOURCE_EXTENSIONS } from "@stryke/resolve/constants";
|
|
16
17
|
import { loadSafe } from "@stryke/resolve/load";
|
|
18
|
+
import { resolve } from "@stryke/resolve/resolve";
|
|
17
19
|
import { list } from "@stryke/string-format/list";
|
|
18
20
|
import { extractJsonSchema as extractJsonSchema$1, isZod3Type } from "@stryke/zod";
|
|
19
21
|
import { toJsonSchema } from "@valibot/to-json-schema";
|
|
22
|
+
import { build } from "esbuild";
|
|
20
23
|
import { createGenerator } from "ts-json-schema-generator/dist/factory/generator.js";
|
|
24
|
+
import { DEFAULT_CONFIG } from "ts-json-schema-generator/dist/src/Config.js";
|
|
25
|
+
import ts from "typescript";
|
|
21
26
|
|
|
22
27
|
//#region src/compatibility.ts
|
|
23
28
|
const METADATA_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -124,6 +129,9 @@ function assertSchemasDoNotContradict(base, override, label = "schema") {
|
|
|
124
129
|
//#endregion
|
|
125
130
|
//#region src/extract.ts
|
|
126
131
|
const SCHEMA_BUNDLE_BASE_URI = "https://power-plant.invalid/";
|
|
132
|
+
function normalizePath(filePath) {
|
|
133
|
+
return filePath.replaceAll("\\", "/");
|
|
134
|
+
}
|
|
127
135
|
function isWrappedSchemaConfig(input) {
|
|
128
136
|
if (!isSetObject(input) || !("schema" in input)) return false;
|
|
129
137
|
if ("hash" in input || "variant" in input || "source" in input) return false;
|
|
@@ -446,8 +454,148 @@ function extractSource(variant, input) {
|
|
|
446
454
|
};
|
|
447
455
|
throw new Error(`Failed to extract source information from the provided input. The input must be a Zod schema, a Standard JSON Schema, a JSON Schema object, an untyped schema, or a reflected Deepkit Type object.`);
|
|
448
456
|
}
|
|
457
|
+
function getTsCompilerOptions(config) {
|
|
458
|
+
if (config.tsconfig) {
|
|
459
|
+
const raw = ts.sys.readFile(config.tsconfig);
|
|
460
|
+
if (!raw) throw new Error(`Cannot read config file "${config.tsconfig}"`);
|
|
461
|
+
const parsedConfig = ts.parseConfigFileTextToJson(config.tsconfig, raw);
|
|
462
|
+
if (parsedConfig.error) throw new Error(parsedConfig.error.messageText.toString());
|
|
463
|
+
if (!parsedConfig.config) throw new Error(`Invalid parsed config file "${config.tsconfig}"`);
|
|
464
|
+
const parseResult = ts.parseJsonConfigFileContent(parsedConfig.config, ts.sys, findFilePath(config.tsconfig), {}, config.tsconfig);
|
|
465
|
+
parseResult.options.noEmit = true;
|
|
466
|
+
delete parseResult.options.out;
|
|
467
|
+
delete parseResult.options.outDir;
|
|
468
|
+
delete parseResult.options.outFile;
|
|
469
|
+
delete parseResult.options.declaration;
|
|
470
|
+
delete parseResult.options.declarationDir;
|
|
471
|
+
delete parseResult.options.declarationMap;
|
|
472
|
+
return parseResult.options;
|
|
473
|
+
}
|
|
474
|
+
return {
|
|
475
|
+
noEmit: true,
|
|
476
|
+
emitDecoratorMetadata: true,
|
|
477
|
+
experimentalDecorators: true,
|
|
478
|
+
target: ts.ScriptTarget.ES2022,
|
|
479
|
+
module: ts.ModuleKind.ESNext,
|
|
480
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
481
|
+
strictNullChecks: false,
|
|
482
|
+
skipLibCheck: true,
|
|
483
|
+
skipDefaultLibCheck: true,
|
|
484
|
+
esModuleInterop: true,
|
|
485
|
+
types: ["node"]
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Rewrites type-only imports/exports so esbuild still walks them while
|
|
490
|
+
* collecting the original TypeScript sources for schema generation.
|
|
491
|
+
*/
|
|
492
|
+
function rewriteTypeOnlyImports(source) {
|
|
493
|
+
return source.replace(/\bimport\s+type\s+/g, "import ").replace(/\bexport\s+type\s+\*\s+from/g, "export * from").replace(/\bexport\s+type\s+\{/g, "export {");
|
|
494
|
+
}
|
|
495
|
+
function getScriptKind(fileName) {
|
|
496
|
+
switch (findFileExtensionSafe(fileName)?.toLowerCase()) {
|
|
497
|
+
case "tsx": return ts.ScriptKind.TSX;
|
|
498
|
+
case "jsx": return ts.ScriptKind.JSX;
|
|
499
|
+
case "js":
|
|
500
|
+
case "cjs":
|
|
501
|
+
case "mjs": return ts.ScriptKind.JS;
|
|
502
|
+
default: return ts.ScriptKind.TS;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Uses esbuild (with `@stryke/resolve` path resolution) to walk the module
|
|
507
|
+
* graph, capturing original TypeScript sources before types are erased.
|
|
508
|
+
*/
|
|
509
|
+
async function bundleTypeScriptSources(filePath, options) {
|
|
510
|
+
const cwd = options.cwd || process.cwd();
|
|
511
|
+
const sources = /* @__PURE__ */ new Map();
|
|
512
|
+
const result = await build({
|
|
513
|
+
absWorkingDir: cwd,
|
|
514
|
+
entryPoints: [filePath],
|
|
515
|
+
bundle: true,
|
|
516
|
+
write: false,
|
|
517
|
+
platform: "node",
|
|
518
|
+
format: "esm",
|
|
519
|
+
logLevel: "silent",
|
|
520
|
+
packages: "external",
|
|
521
|
+
plugins: [{
|
|
522
|
+
name: "power-plant-capture-ts-sources",
|
|
523
|
+
setup(buildApi) {
|
|
524
|
+
buildApi.onLoad({ filter: /.*/ }, async (args) => {
|
|
525
|
+
if (/[/\\]node_modules[/\\]/.test(args.path)) return null;
|
|
526
|
+
try {
|
|
527
|
+
const original = await resolve(args.path, {
|
|
528
|
+
skipBundle: true,
|
|
529
|
+
cwd,
|
|
530
|
+
fs: options.fs
|
|
531
|
+
});
|
|
532
|
+
sources.set(normalizePath(args.path), original);
|
|
533
|
+
const extension = findFileExtensionSafe(args.path);
|
|
534
|
+
const loader = extension === "tsx" || extension === "jsx" ? extension : extension === "js" || extension === "cjs" || extension === "mjs" ? "js" : "ts";
|
|
535
|
+
return {
|
|
536
|
+
contents: rewriteTypeOnlyImports(original),
|
|
537
|
+
loader
|
|
538
|
+
};
|
|
539
|
+
} catch {
|
|
540
|
+
return null;
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
}, plugin({
|
|
545
|
+
originalInput: filePath,
|
|
546
|
+
cwd,
|
|
547
|
+
fs: options.fs ?? {}
|
|
548
|
+
})]
|
|
549
|
+
});
|
|
550
|
+
if (result.errors.length > 0) throw new Error(`Failed to bundle TypeScript sources for "${filePath}": ${result.errors.map((error) => error.text).join(", ")}`);
|
|
551
|
+
if (sources.size === 0) {
|
|
552
|
+
const fallback = await resolve(filePath, {
|
|
553
|
+
skipBundle: true,
|
|
554
|
+
cwd,
|
|
555
|
+
fs: options.fs
|
|
556
|
+
});
|
|
557
|
+
sources.set(normalizePath(filePath), fallback);
|
|
558
|
+
}
|
|
559
|
+
return {
|
|
560
|
+
entryFileName: filePath,
|
|
561
|
+
sources
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Builds a TypeScript program from original sources collected during the
|
|
566
|
+
* esbuild graph walk so type information remains intact for schema generation.
|
|
567
|
+
*/
|
|
568
|
+
function createProgramFromSources(entryFileName, sources, config) {
|
|
569
|
+
const compilerOptions = getTsCompilerOptions(config);
|
|
570
|
+
const host = ts.createCompilerHost(compilerOptions, true);
|
|
571
|
+
const normalizedSources = new Map([...sources.entries()].map(([key, value]) => [normalizePath(key), value]));
|
|
572
|
+
const getContent = (name) => normalizedSources.get(normalizePath(name)) ?? normalizedSources.get(name);
|
|
573
|
+
const baseFileExists = host.fileExists.bind(host);
|
|
574
|
+
const baseReadFile = host.readFile.bind(host);
|
|
575
|
+
const baseGetSourceFile = host.getSourceFile.bind(host);
|
|
576
|
+
host.fileExists = (name) => getContent(name) !== void 0 || baseFileExists(name);
|
|
577
|
+
host.readFile = (name) => getContent(name) ?? baseReadFile(name);
|
|
578
|
+
host.getSourceFile = (name, languageVersionOrOptions, onError, shouldCreateNewSourceFile) => {
|
|
579
|
+
const content = getContent(name);
|
|
580
|
+
if (content !== void 0) {
|
|
581
|
+
const scriptTarget = typeof languageVersionOrOptions === "object" ? languageVersionOrOptions.languageVersion : languageVersionOrOptions;
|
|
582
|
+
return ts.createSourceFile(name, content, scriptTarget ?? compilerOptions.target ?? ts.ScriptTarget.ES2022, true, getScriptKind(name));
|
|
583
|
+
}
|
|
584
|
+
return baseGetSourceFile(name, languageVersionOrOptions, onError, shouldCreateNewSourceFile);
|
|
585
|
+
};
|
|
586
|
+
const program = ts.createProgram([entryFileName], compilerOptions, host);
|
|
587
|
+
if (!config.skipTypeCheck) {
|
|
588
|
+
const diagnostics = ts.getPreEmitDiagnostics(program);
|
|
589
|
+
if (diagnostics.length) throw new Error(`Type check error: ${diagnostics.map((diagnostic) => diagnostic.messageText.toString()).join("\n")}`);
|
|
590
|
+
}
|
|
591
|
+
return program;
|
|
592
|
+
}
|
|
449
593
|
/**
|
|
450
|
-
* Resolves a type definition to a JSON Schema.
|
|
594
|
+
* Resolves a type definition to a JSON Schema. First bundles the TypeScript
|
|
595
|
+
* module graph for {@link FileReference.file} with esbuild (preserving original
|
|
596
|
+
* sources), then feeds that program to
|
|
597
|
+
* [ts-json-schema-generator](https://github.com/vega/ts-json-schema-generator)
|
|
598
|
+
* using the referenced export name as the target type when one is provided.
|
|
451
599
|
*
|
|
452
600
|
* @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
|
|
453
601
|
* @param options - Optional overrides reserved for API compatibility.
|
|
@@ -460,19 +608,29 @@ async function extractTSType(input, options = {}) {
|
|
|
460
608
|
const resolvedPath = await resolveSafe(fileReference.file, { fs: options.fs });
|
|
461
609
|
const filePath = resolvedPath || fileReference.file;
|
|
462
610
|
try {
|
|
463
|
-
const
|
|
464
|
-
|
|
465
|
-
|
|
611
|
+
const tsconfig = options.tsconfig ? appendPath(options.tsconfig, options.cwd || process.cwd()) : joinPaths(options.cwd || process.cwd(), "tsconfig.json");
|
|
612
|
+
const { entryFileName, sources } = await bundleTypeScriptSources(filePath, {
|
|
613
|
+
cwd: options.cwd || process.cwd(),
|
|
614
|
+
fs: options.fs
|
|
615
|
+
});
|
|
616
|
+
const config = {
|
|
617
|
+
...DEFAULT_CONFIG,
|
|
466
618
|
expose: "all",
|
|
467
619
|
jsDoc: "extended",
|
|
468
620
|
markdownDescription: true,
|
|
469
621
|
fullDescription: true,
|
|
470
|
-
skipTypeCheck: true,
|
|
471
622
|
...options,
|
|
472
|
-
tsconfig
|
|
623
|
+
tsconfig,
|
|
624
|
+
path: entryFileName,
|
|
625
|
+
type: exportName,
|
|
626
|
+
skipTypeCheck: true
|
|
473
627
|
};
|
|
474
|
-
|
|
475
|
-
|
|
628
|
+
const tsProgram = createProgramFromSources(entryFileName, sources, config);
|
|
629
|
+
options.logger?.debug?.(`Generating JSON schema for bundled "${filePath}" using the type "${exportName}" (${sources.size} source file(s))`);
|
|
630
|
+
return createGenerator({
|
|
631
|
+
...config,
|
|
632
|
+
tsProgram
|
|
633
|
+
}).createSchema(exportName);
|
|
476
634
|
} catch (error) {
|
|
477
635
|
throw new Error(`Failed to generate a JSON schema for "${fileReference.file}"${resolvedPath && resolvedPath !== fileReference.file ? ` (resolved: ${resolvedPath})` : ""} using the type "${exportName}". Error: ${error.message}`);
|
|
478
636
|
}
|
|
@@ -605,5 +763,5 @@ async function extract(input, options = {}) {
|
|
|
605
763
|
}
|
|
606
764
|
|
|
607
765
|
//#endregion
|
|
608
|
-
export { JSON_SCHEMA_METADATA_KEYS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES, JsonSchemaTypeNames, SCHEMA_ARRAY_CONCAT_KEYWORDS, SCHEMA_RECORD_KEYWORDS, SCHEMA_SINGLE_KEYWORDS, addProperty, applyJsonSchemaMetadata, assertSchemasDoNotContradict, bundleReferences, createStoragePromises, extract, extractHash, extractJsonSchema, extractResolvedVariant, extractSchema, extractSchemaWithSource, extractSource, extractTSType, extractVariant, findSchemaContradictions, getJsonSchema, getJsonSchemaObject, getPrimarySchemaType, getProperties, getPropertiesList, getProperty, isFileReference, isJsonSchema, isJsonSchemaAllOf, isJsonSchemaAny, isJsonSchemaAnyOf, isJsonSchemaArray, isJsonSchemaBigint, isJsonSchemaBoolean, isJsonSchemaDate, isJsonSchemaDecimal, isJsonSchemaEnum, isJsonSchemaInteger, isJsonSchemaKeywords, isJsonSchemaLiteral, isJsonSchemaMap, isJsonSchemaNativeEnum, isJsonSchemaNever, isJsonSchemaNull, isJsonSchemaNullable, isJsonSchemaNumber, isJsonSchemaObject, isJsonSchemaPrimitiveType, isJsonSchemaPrimitiveUnion, isJsonSchemaRecord, isJsonSchemaRef, isJsonSchemaSet, isJsonSchemaString, isJsonSchemaTuple, isJsonSchemaType, isJsonSchemaUndefined, isJsonSchemaUnion, isJsonSchemaUnknown, isNullOnlyJsonSchema, isPropertyOptional, isSchema, isSchemaNullable, isSchemaObject, isSchemaOf, isSchemaWithSource, isStandardSchema, isUntypedConfig, isUntypedConfigStrict, isUntypedSchema, isUntypedSchemaStrict, isValibotSchema, isValidSchemaConfigFile, mapStorageToFileSystem, merge, mergeMetadata, normalizeKey, readSchemaTypes, traverseSchema };
|
|
766
|
+
export { JSON_SCHEMA_METADATA_KEYS, JSON_SCHEMA_PRIMITIVE_TYPES, JSON_SCHEMA_TYPES, JsonSchemaTypeNames, SCHEMA_ARRAY_CONCAT_KEYWORDS, SCHEMA_RECORD_KEYWORDS, SCHEMA_SINGLE_KEYWORDS, addProperty, applyJsonSchemaMetadata, assertSchemasDoNotContradict, bundleReferences, createStoragePromises, extract, extractHash, extractJsonSchema, extractResolvedVariant, extractSchema, extractSchemaWithSource, extractSource, extractTSType, extractVariant, findSchemaContradictions, getJsonSchema, getJsonSchemaObject, getPrimarySchemaType, getProperties, getPropertiesList, getProperty, isFileReference, isJsonSchema, isJsonSchemaAllOf, isJsonSchemaAny, isJsonSchemaAnyOf, isJsonSchemaArray, isJsonSchemaBigint, isJsonSchemaBoolean, isJsonSchemaDate, isJsonSchemaDecimal, isJsonSchemaEnum, isJsonSchemaInteger, isJsonSchemaKeywords, isJsonSchemaLiteral, isJsonSchemaMap, isJsonSchemaNativeEnum, isJsonSchemaNever, isJsonSchemaNull, isJsonSchemaNullable, isJsonSchemaNumber, isJsonSchemaObject, isJsonSchemaPrimitiveType, isJsonSchemaPrimitiveUnion, isJsonSchemaRecord, isJsonSchemaRef, isJsonSchemaSet, isJsonSchemaString, isJsonSchemaTuple, isJsonSchemaType, isJsonSchemaUndefined, isJsonSchemaUnion, isJsonSchemaUnknown, isNullOnlyJsonSchema, isPropertyOptional, isSchema, isSchemaNullable, isSchemaObject, isSchemaOf, isSchemaWithSource, isStandardSchema, isUntypedConfig, isUntypedConfigStrict, isUntypedInput, isUntypedInputStrict, isUntypedSchema, isUntypedSchemaStrict, isValibotSchema, isValidSchemaConfigFile, isValidSchemaInputFile, mapStorageToFileSystem, merge, mergeMetadata, normalizeKey, readSchemaTypes, traverseSchema };
|
|
609
767
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { Config } from "ts-json-schema-generator/dist/src/Config.js";
|
|
1
2
|
import { BaseIssue, BaseSchema } from "valibot";
|
|
2
3
|
import { StandardJSONSchemaV1 } from "@standard-schema/spec";
|
|
3
4
|
import { InferLoadOptions, LoadReference } from "@stryke/resolve/types";
|
|
4
|
-
import { Config } from "ts-json-schema-generator/dist/src/Config.js";
|
|
5
5
|
import { Storage } from "unstorage";
|
|
6
6
|
import { InputObject, Schema } from "untyped";
|
|
7
7
|
import * as z3 from "zod/v3";
|
|
@@ -1347,4 +1347,4 @@ declare module "zod" {
|
|
|
1347
1347
|
}
|
|
1348
1348
|
//#endregion
|
|
1349
1349
|
export { SchemaSourceVariant as $, JsonSchemaNumberFormat as A, JsonSchemaString as B, JsonSchemaMap as C, JsonSchemaNull as D, JsonSchemaNever as E, JsonSchemaRecord as F, JsonSchemaUnion as G, JsonSchemaTuple as H, JsonSchemaRecordPropertyNames as I, SchemaConfigVariant as J, JsonSchemaUnknown as K, JsonSchemaRef as L, JsonSchemaOf as M, JsonSchemaPrimitiveType as N, JsonSchemaNullable as O, JsonSchemaPrimitiveUnion as P, SchemaSourceConfig as Q, JsonSchemaSchemaSource as R, JsonSchemaLogicKeywords as S, JsonSchemaNativeEnum as T, JsonSchemaType as U, JsonSchemaStringFormat as V, JsonSchemaUndefined as W, SchemaEnvelopeOf as X, SchemaEnvelope as Y, SchemaSource as Z, JsonSchemaInteger as _, JsonSchema as a, ValibotSchema as at, JsonSchemaLike as b, JsonSchemaAnyOf as c, JSON_SCHEMA_METADATA_KEYS as ct, JsonSchemaBoolean as d, JsonSchemaTypeNames as dt, SpecOf as et, JsonSchemaConditionalKeywords as f, SCHEMA_ARRAY_CONCAT_KEYWORDS as ft, JsonSchemaEnum as g, JsonSchemaDecimalFormat as h, InferExtractOptions as i, UntypedSchemaSource as it, JsonSchemaObject as j, JsonSchemaNumber as k, JsonSchemaArray as l, JSON_SCHEMA_PRIMITIVE_TYPES as lt, JsonSchemaDecimal as m, SCHEMA_SINGLE_KEYWORDS as mt, BaseSchemaSource as n, UntypedConfigObject as nt, JsonSchemaAllOf as o, ValibotSchemaSource as ot, JsonSchemaDate as p, SCHEMA_RECORD_KEYWORDS as pt, SchemaConfig as q, ExtractedSchemaEnvelope as r, UntypedSchema as rt, JsonSchemaAny as s, Zod3SchemaSource as st, BaseExtractOptions as t, StandardSchemaSchemaSource as tt, JsonSchemaBigint as u, JSON_SCHEMA_TYPES as ut, JsonSchemaIntegerFormat as v, JsonSchemaMetadataKeywords as w, JsonSchemaLiteral as x, JsonSchemaKeywords as y, JsonSchemaSet as z };
|
|
1350
|
-
//# sourceMappingURL=types-
|
|
1350
|
+
//# sourceMappingURL=types-CyvYSCHO.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-CyvYSCHO.d.mts","names":[],"sources":["../src/constants.ts","../src/types.ts"],"mappings":""}
|
package/dist/valibot.d.mts
CHANGED
package/dist/zod.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_rolldown_runtime = require('./rolldown-runtime-C_NdSu1c.cjs');
|
|
3
3
|
const require_constants = require('./constants-B7xonHLD.cjs');
|
|
4
|
-
const require_helpers = require('./helpers-
|
|
4
|
+
const require_helpers = require('./helpers-BQD6GZyX.cjs');
|
|
5
5
|
let _stryke_helpers_deep_clone = require("@stryke/helpers/deep-clone");
|
|
6
6
|
let zod_mini = require("zod/mini");
|
|
7
7
|
zod_mini = require_rolldown_runtime.__toESM(zod_mini, 1);
|
package/dist/zod.d.mts
CHANGED
package/dist/zod.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { r as JSON_SCHEMA_TYPES } from "./constants-COGt3eeW.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { _ as isJsonSchemaAny, n as getJsonSchema, p as traverseSchema } from "./helpers-dvxktFml.mjs";
|
|
3
3
|
import { deepClone } from "@stryke/helpers/deep-clone";
|
|
4
4
|
import * as z from "zod/mini";
|
|
5
5
|
import * as z4 from "zod/v4";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@power-plant/schema",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.35",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A Power Plant utility package to help managing schemas.",
|
|
6
6
|
"keywords": [
|
|
@@ -135,6 +135,8 @@
|
|
|
135
135
|
"@stryke/zod": "^0.3.42",
|
|
136
136
|
"@valibot/to-json-schema": "^1.7.1",
|
|
137
137
|
"defu": "^6.1.7",
|
|
138
|
+
"esbuild": "^0.28.1",
|
|
139
|
+
"normalize-path": "^3.0.0",
|
|
138
140
|
"ts-json-schema-generator": "^2.9.0",
|
|
139
141
|
"typescript": "^6.0.3",
|
|
140
142
|
"unstorage": "^1.17.5",
|
|
@@ -156,5 +158,5 @@
|
|
|
156
158
|
"zod": { "optional": true }
|
|
157
159
|
},
|
|
158
160
|
"publishConfig": { "access": "public" },
|
|
159
|
-
"gitHead": "
|
|
161
|
+
"gitHead": "aa08d1d0c91b8566d9fe9ebe8532fc1a001ccd9c"
|
|
160
162
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helpers-reqtcaa8.mjs","names":[],"sources":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types-CjF4wIDK.d.mts","names":[],"sources":["../src/constants.ts","../src/types.ts"],"mappings":""}
|