@power-plant/schema 0.0.33 → 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 CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_helpers = require('./helpers-sXsSapgI.cjs');
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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { E as isJsonSchemaLiteral, N as isJsonSchemaObject, a as getPropertiesList, c as isSchemaNullable, m as isJsonSchema, rt as getPrimarySchemaType, u as merge, z as isJsonSchemaString } from "./helpers-reqtcaa8.mjs";
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
- return isUntypedSchema(input) && !isJsonSchema(input);
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
- return isUntypedSchema(input) && !isJsonSchema(input);
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 { isUntypedSchema as $, isJsonSchemaNull as A, isJsonSchemaTuple as B, isJsonSchemaEnum as C, isJsonSchemaMap as D, isJsonSchemaLiteral as E, isJsonSchemaPrimitiveUnion as F, isNullOnlyJsonSchema as G, isJsonSchemaUndefined as H, isJsonSchemaRecord as I, isSchemaOf as J, isSchema as K, isJsonSchemaRef as L, isJsonSchemaNumber as M, isJsonSchemaObject as N, isJsonSchemaNativeEnum as O, isJsonSchemaPrimitiveType as P, isUntypedConfigStrict as Q, isJsonSchemaSet as R, isJsonSchemaDecimal as S, isJsonSchemaKeywords as T, isJsonSchemaUnion as U, isJsonSchemaType as V, isJsonSchemaUnknown as W, isStandardSchema as X, isSchemaWithSource as Y, isUntypedConfig as Z, isJsonSchemaAnyOf as _, getPropertiesList as a, isJsonSchemaBoolean as b, isSchemaNullable as c, mergeMetadata as d, isUntypedSchemaStrict as et, traverseSchema as f, isJsonSchemaAny as g, isJsonSchemaAllOf as h, getProperties as i, readSchemaTypes as it, isJsonSchemaNullable as j, isJsonSchemaNever as k, isValidSchemaConfigFile as l, isJsonSchema as m, getJsonSchema as n, applyJsonSchemaMetadata as nt, getProperty as o, isFileReference as p, isSchemaObject as q, getJsonSchemaObject as r, getPrimarySchemaType as rt, isPropertyOptional as s, addProperty as t, isValibotSchema as tt, merge as u, isJsonSchemaArray as v, isJsonSchemaInteger as w, isJsonSchemaDate as x, isJsonSchemaBigint as y, isJsonSchemaString as z };
921
- //# sourceMappingURL=helpers-reqtcaa8.mjs.map
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,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-sXsSapgI.cjs');
4
+ const require_helpers = require('./helpers-BQD6GZyX.cjs');
5
5
  const require_storage = require('./storage-B8aDmNpv.cjs');
6
6
  let _stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
7
7
  let _stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
@@ -14,12 +14,14 @@ let _stryke_json = require("@stryke/json");
14
14
  let _stryke_path_append = require("@stryke/path/append");
15
15
  let _stryke_path_find = require("@stryke/path/find");
16
16
  let _stryke_path_join = require("@stryke/path/join");
17
+ let _stryke_resolve_bundle = require("@stryke/resolve/bundle");
17
18
  let _stryke_resolve_constants = require("@stryke/resolve/constants");
18
19
  let _stryke_resolve_load = require("@stryke/resolve/load");
20
+ let _stryke_resolve_resolve = require("@stryke/resolve/resolve");
19
21
  let _stryke_string_format_list = require("@stryke/string-format/list");
20
22
  let _stryke_zod = require("@stryke/zod");
21
- require("@typescript/vfs");
22
23
  let _valibot_to_json_schema = require("@valibot/to-json-schema");
24
+ let esbuild = require("esbuild");
23
25
  let ts_json_schema_generator_dist_factory_generator_js = require("ts-json-schema-generator/dist/factory/generator.js");
24
26
  let ts_json_schema_generator_dist_src_Config_js = require("ts-json-schema-generator/dist/src/Config.js");
25
27
  let typescript = require("typescript");
@@ -130,7 +132,9 @@ function assertSchemasDoNotContradict(base, override, label = "schema") {
130
132
  //#endregion
131
133
  //#region src/extract.ts
132
134
  const SCHEMA_BUNDLE_BASE_URI = "https://power-plant.invalid/";
133
- typescript.default.ScriptTarget.ES2022, typescript.default.ModuleKind.ESNext;
135
+ function normalizePath(filePath) {
136
+ return filePath.replaceAll("\\", "/");
137
+ }
134
138
  function isWrappedSchemaConfig(input) {
135
139
  if (!(0, _stryke_type_checks_is_set_object.isSetObject)(input) || !("schema" in input)) return false;
136
140
  if ("hash" in input || "variant" in input || "source" in input) return false;
@@ -453,8 +457,148 @@ function extractSource(variant, input) {
453
457
  };
454
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.`);
455
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
+ }
456
596
  /**
457
- * Resolves a type definition to a JSON Schema. This function passes the provided file reference to ts-json-schema-generator, using the referenced export name as the target type when one is provided.
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.
458
602
  *
459
603
  * @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
460
604
  * @param options - Optional overrides reserved for API compatibility.
@@ -466,21 +610,30 @@ async function extractTSType(input, options = {}) {
466
610
  const exportName = fileReference.export ?? "*";
467
611
  const resolvedPath = await (0, _stryke_fs_resolve.resolveSafe)(fileReference.file, { fs: options.fs });
468
612
  const filePath = resolvedPath || fileReference.file;
469
- 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");
470
613
  try {
471
- const generatorConfig = {
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 = {
472
620
  ...ts_json_schema_generator_dist_src_Config_js.DEFAULT_CONFIG,
473
- path: filePath,
474
- type: exportName,
475
621
  expose: "all",
476
622
  jsDoc: "extended",
477
623
  markdownDescription: true,
478
624
  fullDescription: true,
479
625
  ...options,
480
- tsconfig
626
+ tsconfig,
627
+ path: entryFileName,
628
+ type: exportName,
629
+ skipTypeCheck: true
481
630
  };
482
- console.log(`Generating JSON schema for "${filePath}" using the type "${exportName}" with the following configuration: ${JSON.stringify(generatorConfig, null, 2)}`);
483
- return (0, ts_json_schema_generator_dist_factory_generator_js.createGenerator)(generatorConfig).createSchema(exportName);
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);
484
637
  } catch (error) {
485
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}`);
486
639
  }
@@ -683,10 +836,13 @@ exports.isSchemaWithSource = require_helpers.isSchemaWithSource;
683
836
  exports.isStandardSchema = require_helpers.isStandardSchema;
684
837
  exports.isUntypedConfig = require_helpers.isUntypedConfig;
685
838
  exports.isUntypedConfigStrict = require_helpers.isUntypedConfigStrict;
839
+ exports.isUntypedInput = require_helpers.isUntypedInput;
840
+ exports.isUntypedInputStrict = require_helpers.isUntypedInputStrict;
686
841
  exports.isUntypedSchema = require_helpers.isUntypedSchema;
687
842
  exports.isUntypedSchemaStrict = require_helpers.isUntypedSchemaStrict;
688
843
  exports.isValibotSchema = require_helpers.isValibotSchema;
689
844
  exports.isValidSchemaConfigFile = require_helpers.isValidSchemaConfigFile;
845
+ exports.isValidSchemaInputFile = require_helpers.isValidSchemaInputFile;
690
846
  exports.mapStorageToFileSystem = require_storage.mapStorageToFileSystem;
691
847
  exports.merge = require_helpers.merge;
692
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. This function passes the provided file reference to ts-json-schema-generator, using the referenced export name as the target type when one is provided.
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
@@ -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":"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"}
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":"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"}
package/dist/index.d.mts 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. This function passes the provided file reference to ts-json-schema-generator, using the referenced export name as the target type when one is provided.
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 isUntypedSchema, A as isJsonSchemaNull, B as isJsonSchemaTuple, C as isJsonSchemaEnum, D as isJsonSchemaMap, E as isJsonSchemaLiteral, F as isJsonSchemaPrimitiveUnion, G as isNullOnlyJsonSchema, H as isJsonSchemaUndefined, I as isJsonSchemaRecord, J as isSchemaOf, K as isSchema, L as isJsonSchemaRef, M as isJsonSchemaNumber, N as isJsonSchemaObject, O as isJsonSchemaNativeEnum, P as isJsonSchemaPrimitiveType, Q as isUntypedConfigStrict, R as isJsonSchemaSet, S as isJsonSchemaDecimal, T as isJsonSchemaKeywords, U as isJsonSchemaUnion, V as isJsonSchemaType, W as isJsonSchemaUnknown, X as isStandardSchema, Y as isSchemaWithSource, Z as isUntypedConfig, _ as isJsonSchemaAnyOf, a as getPropertiesList, b as isJsonSchemaBoolean, c as isSchemaNullable, d as mergeMetadata, et as isUntypedSchemaStrict, f as traverseSchema, g as isJsonSchemaAny, h as isJsonSchemaAllOf, i as getProperties, it as readSchemaTypes, j as isJsonSchemaNullable, k as isJsonSchemaNever, l as isValidSchemaConfigFile, m as isJsonSchema, n as getJsonSchema, nt as applyJsonSchemaMetadata, o as getProperty, p as isFileReference, q as isSchemaObject, r as getJsonSchemaObject, rt as getPrimarySchemaType, s as isPropertyOptional, t as addProperty, tt as isValibotSchema, u as merge, v as isJsonSchemaArray, w as isJsonSchemaInteger, x as isJsonSchemaDate, y as isJsonSchemaBigint, z as isJsonSchemaString } from "./helpers-reqtcaa8.mjs";
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,16 @@ 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
- import "@typescript/vfs";
20
21
  import { toJsonSchema } from "@valibot/to-json-schema";
22
+ import { build } from "esbuild";
21
23
  import { createGenerator } from "ts-json-schema-generator/dist/factory/generator.js";
22
24
  import { DEFAULT_CONFIG } from "ts-json-schema-generator/dist/src/Config.js";
23
25
  import ts from "typescript";
@@ -127,7 +129,9 @@ function assertSchemasDoNotContradict(base, override, label = "schema") {
127
129
  //#endregion
128
130
  //#region src/extract.ts
129
131
  const SCHEMA_BUNDLE_BASE_URI = "https://power-plant.invalid/";
130
- ts.ScriptTarget.ES2022, ts.ModuleKind.ESNext;
132
+ function normalizePath(filePath) {
133
+ return filePath.replaceAll("\\", "/");
134
+ }
131
135
  function isWrappedSchemaConfig(input) {
132
136
  if (!isSetObject(input) || !("schema" in input)) return false;
133
137
  if ("hash" in input || "variant" in input || "source" in input) return false;
@@ -450,8 +454,148 @@ function extractSource(variant, input) {
450
454
  };
451
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.`);
452
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
+ }
453
593
  /**
454
- * Resolves a type definition to a JSON Schema. This function passes the provided file reference to ts-json-schema-generator, using the referenced export name as the target type when one is provided.
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.
455
599
  *
456
600
  * @param input - The type definition to compile. This can be either a string or a {@link FileReference} object.
457
601
  * @param options - Optional overrides reserved for API compatibility.
@@ -463,21 +607,30 @@ async function extractTSType(input, options = {}) {
463
607
  const exportName = fileReference.export ?? "*";
464
608
  const resolvedPath = await resolveSafe(fileReference.file, { fs: options.fs });
465
609
  const filePath = resolvedPath || fileReference.file;
466
- const tsconfig = options.tsconfig ? appendPath(options.tsconfig, options.cwd || process.cwd()) : joinPaths(options.cwd || process.cwd(), "tsconfig.json");
467
610
  try {
468
- const generatorConfig = {
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 = {
469
617
  ...DEFAULT_CONFIG,
470
- path: filePath,
471
- type: exportName,
472
618
  expose: "all",
473
619
  jsDoc: "extended",
474
620
  markdownDescription: true,
475
621
  fullDescription: true,
476
622
  ...options,
477
- tsconfig
623
+ tsconfig,
624
+ path: entryFileName,
625
+ type: exportName,
626
+ skipTypeCheck: true
478
627
  };
479
- console.log(`Generating JSON schema for "${filePath}" using the type "${exportName}" with the following configuration: ${JSON.stringify(generatorConfig, null, 2)}`);
480
- return createGenerator(generatorConfig).createSchema(exportName);
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);
481
634
  } catch (error) {
482
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}`);
483
636
  }
@@ -610,5 +763,5 @@ async function extract(input, options = {}) {
610
763
  }
611
764
 
612
765
  //#endregion
613
- 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 };
614
767
  //# sourceMappingURL=index.mjs.map
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-sXsSapgI.cjs');
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.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { r as JSON_SCHEMA_TYPES } from "./constants-COGt3eeW.mjs";
2
- import { f as traverseSchema, g as isJsonSchemaAny, n as getJsonSchema } from "./helpers-reqtcaa8.mjs";
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.33",
3
+ "version": "0.0.35",
4
4
  "private": false,
5
5
  "description": "A Power Plant utility package to help managing schemas.",
6
6
  "keywords": [
@@ -121,11 +121,11 @@
121
121
  "@standard-schema/spec": "^1.1.0",
122
122
  "@stryke/convert": "^0.7.27",
123
123
  "@stryke/date": "^0.0.8",
124
+ "@stryke/fs": "^0.33.97",
124
125
  "@stryke/hash": "^0.13.50",
125
126
  "@stryke/helpers": "^0.10.36",
126
127
  "@stryke/json": "^0.15.20",
127
128
  "@stryke/path": "^0.29.23",
128
- "@stryke/fs": "^0.33.97",
129
129
  "@stryke/resolve": "^0.0.12",
130
130
  "@stryke/string-format": "^0.17.38",
131
131
  "@stryke/type-checks": "^0.6.29",
@@ -133,9 +133,10 @@
133
133
  "@stryke/unique-id": "^0.3.108",
134
134
  "@stryke/url": "^0.4.47",
135
135
  "@stryke/zod": "^0.3.42",
136
- "@typescript/vfs": "^1.6.4",
137
136
  "@valibot/to-json-schema": "^1.7.1",
138
137
  "defu": "^6.1.7",
138
+ "esbuild": "^0.28.1",
139
+ "normalize-path": "^3.0.0",
139
140
  "ts-json-schema-generator": "^2.9.0",
140
141
  "typescript": "^6.0.3",
141
142
  "unstorage": "^1.17.5",
@@ -157,5 +158,5 @@
157
158
  "zod": { "optional": true }
158
159
  },
159
160
  "publishConfig": { "access": "public" },
160
- "gitHead": "f4be99d1455bd72e5ae31a9dc55341a637b6cb43"
161
+ "gitHead": "aa08d1d0c91b8566d9fe9ebe8532fc1a001ccd9c"
161
162
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers-reqtcaa8.mjs","names":[],"sources":[],"mappings":""}