rolldown 1.0.0-beta.1-commit.c170008 → 1.0.0-beta.1-commit.3484a68
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/cjs/cli.cjs +50 -1333
- package/dist/cjs/experimental-index.cjs +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/parallel-plugin-worker.cjs +1 -1
- package/dist/esm/cli.mjs +35 -1318
- package/dist/esm/experimental-index.mjs +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/parallel-plugin-worker.mjs +1 -1
- package/dist/shared/{consola_36c0034f-C_-uQ5ge.cjs → consola_36c0034f-BBnpcLZ5.cjs} +2 -2
- package/dist/shared/{consola_36c0034f-DnM2mwLf.mjs → consola_36c0034f-BwyQ494_.mjs} +2 -2
- package/dist/shared/{prompt-BNaEjAIz.cjs → prompt-BKuli-WV.cjs} +48 -48
- package/dist/shared/{prompt-DhKXGIIR.mjs → prompt-CqEsx-3v.mjs} +1 -1
- package/dist/shared/{src-CQK3Jfvf.mjs → src-CtFcwTp3.mjs} +341 -25
- package/dist/shared/{src-CKrS_jGA.cjs → src-D_KTGKvd.cjs} +369 -59
- package/dist/tsconfig.dts.tsbuildinfo +1 -1
- package/dist/types/cli/arguments/alias.d.ts +8 -1
- package/dist/types/cli/arguments/index.d.ts +1 -1
- package/dist/types/cli/arguments/normalize.d.ts +1 -1
- package/dist/types/cli/arguments/utils.d.ts +4 -2
- package/dist/types/log/logging.d.ts +0 -6
- package/dist/types/options/input-options.d.ts +4 -4
- package/dist/types/{treeshake → types}/module-side-effects.d.ts +0 -4
- package/dist/types/types/schema.d.ts +33 -0
- package/dist/types/utils/validator.d.ts +7 -1
- package/package.json +16 -18
- package/dist/types/cli/arguments/schema.d.ts +0 -12
- package/dist/types/options/input-options-schema.d.ts +0 -4
- package/dist/types/options/output-options-schema.d.ts +0 -3
- package/dist/types/treeshake/index.d.ts +0 -1
- package/dist/types/utils/zod-ext.d.ts +0 -16
package/dist/esm/cli.mjs
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createConsola } from "../shared/consola_36c0034f-
|
|
1
|
+
import { arraify, colors, description, getInputCliKeys, getJsonSchema, getOutputCliKeys, rolldown, validateCliOptions, version, watch } from "../shared/src-CtFcwTp3.mjs";
|
|
2
|
+
import { createConsola } from "../shared/consola_36c0034f-BwyQ494_.mjs";
|
|
3
3
|
import fs from "node:fs";
|
|
4
|
-
import { ZodFirstPartyTypeKind, z } from "zod";
|
|
5
4
|
import path from "node:path";
|
|
6
|
-
import process$1, { cwd
|
|
5
|
+
import process$1, { cwd } from "node:process";
|
|
7
6
|
import { performance } from "node:perf_hooks";
|
|
8
|
-
import * as tty from "tty";
|
|
9
7
|
import { parseArgs } from "node:util";
|
|
10
8
|
import { readdir } from "node:fs/promises";
|
|
11
9
|
import { pathToFileURL } from "node:url";
|
|
@@ -181,83 +179,6 @@ var SignalExit = class extends SignalExitBase {
|
|
|
181
179
|
const process$2 = globalThis.process;
|
|
182
180
|
const { onExit, load, unload } = signalExitWrap(processOk(process$2) ? new SignalExit(process$2) : new SignalExitFallback());
|
|
183
181
|
|
|
184
|
-
//#endregion
|
|
185
|
-
//#region ../../node_modules/.pnpm/colorette@2.0.20/node_modules/colorette/index.js
|
|
186
|
-
const { env: env$1 = {}, argv = [], platform = "" } = typeof process === "undefined" ? {} : process;
|
|
187
|
-
const isDisabled = "NO_COLOR" in env$1 || argv.includes("--no-color");
|
|
188
|
-
const isForced = "FORCE_COLOR" in env$1 || argv.includes("--color");
|
|
189
|
-
const isWindows = platform === "win32";
|
|
190
|
-
const isDumbTerminal = env$1.TERM === "dumb";
|
|
191
|
-
const isCompatibleTerminal = tty && tty.isatty && tty.isatty(1) && env$1.TERM && !isDumbTerminal;
|
|
192
|
-
const isCI = "CI" in env$1 && ("GITHUB_ACTIONS" in env$1 || "GITLAB_CI" in env$1 || "CIRCLECI" in env$1);
|
|
193
|
-
const isColorSupported = !isDisabled && (isForced || isWindows && !isDumbTerminal || isCompatibleTerminal || isCI);
|
|
194
|
-
const replaceClose = (index, string, close, replace, head = string.substring(0, index) + replace, tail = string.substring(index + close.length), next = tail.indexOf(close)) => head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
|
|
195
|
-
const clearBleed = (index, string, open, close, replace) => index < 0 ? open + string + close : open + replaceClose(index, string, close, replace) + close;
|
|
196
|
-
const filterEmpty = (open, close, replace = open, at = open.length + 1) => (string) => string || !(string === "" || string === undefined) ? clearBleed(("" + string).indexOf(close, at), string, open, close, replace) : "";
|
|
197
|
-
const init = (open, close, replace) => filterEmpty(`\x1b[${open}m`, `\x1b[${close}m`, replace);
|
|
198
|
-
const colors$1 = {
|
|
199
|
-
reset: init(0, 0),
|
|
200
|
-
bold: init(1, 22, "\x1B[22m\x1B[1m"),
|
|
201
|
-
dim: init(2, 22, "\x1B[22m\x1B[2m"),
|
|
202
|
-
italic: init(3, 23),
|
|
203
|
-
underline: init(4, 24),
|
|
204
|
-
inverse: init(7, 27),
|
|
205
|
-
hidden: init(8, 28),
|
|
206
|
-
strikethrough: init(9, 29),
|
|
207
|
-
black: init(30, 39),
|
|
208
|
-
red: init(31, 39),
|
|
209
|
-
green: init(32, 39),
|
|
210
|
-
yellow: init(33, 39),
|
|
211
|
-
blue: init(34, 39),
|
|
212
|
-
magenta: init(35, 39),
|
|
213
|
-
cyan: init(36, 39),
|
|
214
|
-
white: init(37, 39),
|
|
215
|
-
gray: init(90, 39),
|
|
216
|
-
bgBlack: init(40, 49),
|
|
217
|
-
bgRed: init(41, 49),
|
|
218
|
-
bgGreen: init(42, 49),
|
|
219
|
-
bgYellow: init(43, 49),
|
|
220
|
-
bgBlue: init(44, 49),
|
|
221
|
-
bgMagenta: init(45, 49),
|
|
222
|
-
bgCyan: init(46, 49),
|
|
223
|
-
bgWhite: init(47, 49),
|
|
224
|
-
blackBright: init(90, 39),
|
|
225
|
-
redBright: init(91, 39),
|
|
226
|
-
greenBright: init(92, 39),
|
|
227
|
-
yellowBright: init(93, 39),
|
|
228
|
-
blueBright: init(94, 39),
|
|
229
|
-
magentaBright: init(95, 39),
|
|
230
|
-
cyanBright: init(96, 39),
|
|
231
|
-
whiteBright: init(97, 39),
|
|
232
|
-
bgBlackBright: init(100, 49),
|
|
233
|
-
bgRedBright: init(101, 49),
|
|
234
|
-
bgGreenBright: init(102, 49),
|
|
235
|
-
bgYellowBright: init(103, 49),
|
|
236
|
-
bgBlueBright: init(104, 49),
|
|
237
|
-
bgMagentaBright: init(105, 49),
|
|
238
|
-
bgCyanBright: init(106, 49),
|
|
239
|
-
bgWhiteBright: init(107, 49)
|
|
240
|
-
};
|
|
241
|
-
const createColors = ({ useColor = isColorSupported } = {}) => useColor ? colors$1 : Object.keys(colors$1).reduce((colors$2, key) => ({
|
|
242
|
-
...colors$2,
|
|
243
|
-
[key]: String
|
|
244
|
-
}), {});
|
|
245
|
-
const { reset, bold: bold$1, dim: dim$1, italic, underline: underline$1, inverse, hidden, strikethrough, black, red: red$1, green: green$1, yellow: yellow$1, blue, magenta, cyan: cyan$1, white, gray: gray$1, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, blackBright, redBright, greenBright, yellowBright, blueBright, magentaBright, cyanBright, whiteBright, bgBlackBright, bgRedBright, bgGreenBright, bgYellowBright, bgBlueBright, bgMagentaBright, bgCyanBright, bgWhiteBright } = createColors();
|
|
246
|
-
|
|
247
|
-
//#endregion
|
|
248
|
-
//#region src/cli/colors.ts
|
|
249
|
-
const { bold, cyan, dim, gray, green, red, underline, yellow } = createColors({ useColor: env.FORCE_COLOR !== "0" && !env.NO_COLOR });
|
|
250
|
-
const colors = {
|
|
251
|
-
bold,
|
|
252
|
-
cyan,
|
|
253
|
-
dim,
|
|
254
|
-
gray,
|
|
255
|
-
green,
|
|
256
|
-
red,
|
|
257
|
-
underline,
|
|
258
|
-
yellow
|
|
259
|
-
};
|
|
260
|
-
|
|
261
182
|
//#endregion
|
|
262
183
|
//#region src/cli/logger.ts
|
|
263
184
|
const logger = process.env.ROLLDOWN_TEST ? createTestingLogger() : createConsola({ formatOptions: { date: false } });
|
|
@@ -515,7 +436,7 @@ function printOutputEntries(entries, sizeAdjustment, distPath) {
|
|
|
515
436
|
for (const group of CHUNK_GROUPS) {
|
|
516
437
|
const filtered = entries.filter((e) => e.type === group.type);
|
|
517
438
|
if (!filtered.length) continue;
|
|
518
|
-
for (const entry of filtered.sort((a, z
|
|
439
|
+
for (const entry of filtered.sort((a, z) => a.size - z.size)) {
|
|
519
440
|
let log = colors.dim(withTrailingSlash(distPath));
|
|
520
441
|
log += colors[group.color](entry.fileName.padEnd(sizeAdjustment.longest + 2));
|
|
521
442
|
log += colors.dim(entry.type);
|
|
@@ -536,1223 +457,12 @@ function relativeId(id) {
|
|
|
536
457
|
return path.relative(path.resolve(), id);
|
|
537
458
|
}
|
|
538
459
|
|
|
539
|
-
//#endregion
|
|
540
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/Options.js
|
|
541
|
-
const ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
542
|
-
const defaultOptions = {
|
|
543
|
-
name: undefined,
|
|
544
|
-
$refStrategy: "root",
|
|
545
|
-
basePath: ["#"],
|
|
546
|
-
effectStrategy: "input",
|
|
547
|
-
pipeStrategy: "all",
|
|
548
|
-
dateStrategy: "format:date-time",
|
|
549
|
-
mapStrategy: "entries",
|
|
550
|
-
removeAdditionalStrategy: "passthrough",
|
|
551
|
-
definitionPath: "definitions",
|
|
552
|
-
target: "jsonSchema7",
|
|
553
|
-
strictUnions: false,
|
|
554
|
-
definitions: {},
|
|
555
|
-
errorMessages: false,
|
|
556
|
-
markdownDescription: false,
|
|
557
|
-
patternStrategy: "escape",
|
|
558
|
-
applyRegexFlags: false,
|
|
559
|
-
emailStrategy: "format:email",
|
|
560
|
-
base64Strategy: "contentEncoding:base64",
|
|
561
|
-
nameStrategy: "ref"
|
|
562
|
-
};
|
|
563
|
-
const getDefaultOptions = (options$1) => typeof options$1 === "string" ? {
|
|
564
|
-
...defaultOptions,
|
|
565
|
-
name: options$1
|
|
566
|
-
} : {
|
|
567
|
-
...defaultOptions,
|
|
568
|
-
...options$1
|
|
569
|
-
};
|
|
570
|
-
|
|
571
|
-
//#endregion
|
|
572
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/Refs.js
|
|
573
|
-
const getRefs = (options$1) => {
|
|
574
|
-
const _options = getDefaultOptions(options$1);
|
|
575
|
-
const currentPath = _options.name !== undefined ? [
|
|
576
|
-
..._options.basePath,
|
|
577
|
-
_options.definitionPath,
|
|
578
|
-
_options.name
|
|
579
|
-
] : _options.basePath;
|
|
580
|
-
return {
|
|
581
|
-
..._options,
|
|
582
|
-
currentPath,
|
|
583
|
-
propertyPath: undefined,
|
|
584
|
-
seen: new Map(Object.entries(_options.definitions).map(([name, def]) => [def._def, {
|
|
585
|
-
def: def._def,
|
|
586
|
-
path: [
|
|
587
|
-
..._options.basePath,
|
|
588
|
-
_options.definitionPath,
|
|
589
|
-
name
|
|
590
|
-
],
|
|
591
|
-
jsonSchema: undefined
|
|
592
|
-
}]))
|
|
593
|
-
};
|
|
594
|
-
};
|
|
595
|
-
|
|
596
|
-
//#endregion
|
|
597
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/errorMessages.js
|
|
598
|
-
function addErrorMessage(res, key, errorMessage, refs) {
|
|
599
|
-
if (!refs?.errorMessages) return;
|
|
600
|
-
if (errorMessage) res.errorMessage = {
|
|
601
|
-
...res.errorMessage,
|
|
602
|
-
[key]: errorMessage
|
|
603
|
-
};
|
|
604
|
-
}
|
|
605
|
-
function setResponseValueAndErrors(res, key, value, errorMessage, refs) {
|
|
606
|
-
res[key] = value;
|
|
607
|
-
addErrorMessage(res, key, errorMessage, refs);
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
//#endregion
|
|
611
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/any.js
|
|
612
|
-
function parseAnyDef() {
|
|
613
|
-
return {};
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
//#endregion
|
|
617
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/array.js
|
|
618
|
-
function parseArrayDef(def, refs) {
|
|
619
|
-
const res = { type: "array" };
|
|
620
|
-
if (def.type?._def && def.type?._def?.typeName !== ZodFirstPartyTypeKind.ZodAny) res.items = parseDef(def.type._def, {
|
|
621
|
-
...refs,
|
|
622
|
-
currentPath: [...refs.currentPath, "items"]
|
|
623
|
-
});
|
|
624
|
-
if (def.minLength) setResponseValueAndErrors(res, "minItems", def.minLength.value, def.minLength.message, refs);
|
|
625
|
-
if (def.maxLength) setResponseValueAndErrors(res, "maxItems", def.maxLength.value, def.maxLength.message, refs);
|
|
626
|
-
if (def.exactLength) {
|
|
627
|
-
setResponseValueAndErrors(res, "minItems", def.exactLength.value, def.exactLength.message, refs);
|
|
628
|
-
setResponseValueAndErrors(res, "maxItems", def.exactLength.value, def.exactLength.message, refs);
|
|
629
|
-
}
|
|
630
|
-
return res;
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
//#endregion
|
|
634
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js
|
|
635
|
-
function parseBigintDef(def, refs) {
|
|
636
|
-
const res = {
|
|
637
|
-
type: "integer",
|
|
638
|
-
format: "int64"
|
|
639
|
-
};
|
|
640
|
-
if (!def.checks) return res;
|
|
641
|
-
for (const check of def.checks) switch (check.kind) {
|
|
642
|
-
case "min":
|
|
643
|
-
if (refs.target === "jsonSchema7") if (check.inclusive) setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
644
|
-
else setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
|
|
645
|
-
else {
|
|
646
|
-
if (!check.inclusive) res.exclusiveMinimum = true;
|
|
647
|
-
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
648
|
-
}
|
|
649
|
-
break;
|
|
650
|
-
case "max":
|
|
651
|
-
if (refs.target === "jsonSchema7") if (check.inclusive) setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
652
|
-
else setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
|
|
653
|
-
else {
|
|
654
|
-
if (!check.inclusive) res.exclusiveMaximum = true;
|
|
655
|
-
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
656
|
-
}
|
|
657
|
-
break;
|
|
658
|
-
case "multipleOf":
|
|
659
|
-
setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
660
|
-
break;
|
|
661
|
-
}
|
|
662
|
-
return res;
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
//#endregion
|
|
666
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js
|
|
667
|
-
function parseBooleanDef() {
|
|
668
|
-
return { type: "boolean" };
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
//#endregion
|
|
672
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/branded.js
|
|
673
|
-
function parseBrandedDef(_def, refs) {
|
|
674
|
-
return parseDef(_def.type._def, refs);
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
//#endregion
|
|
678
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/catch.js
|
|
679
|
-
const parseCatchDef = (def, refs) => {
|
|
680
|
-
return parseDef(def.innerType._def, refs);
|
|
681
|
-
};
|
|
682
|
-
|
|
683
|
-
//#endregion
|
|
684
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/date.js
|
|
685
|
-
function parseDateDef(def, refs, overrideDateStrategy) {
|
|
686
|
-
const strategy = overrideDateStrategy ?? refs.dateStrategy;
|
|
687
|
-
if (Array.isArray(strategy)) return { anyOf: strategy.map((item, i) => parseDateDef(def, refs, item)) };
|
|
688
|
-
switch (strategy) {
|
|
689
|
-
case "string":
|
|
690
|
-
case "format:date-time": return {
|
|
691
|
-
type: "string",
|
|
692
|
-
format: "date-time"
|
|
693
|
-
};
|
|
694
|
-
case "format:date": return {
|
|
695
|
-
type: "string",
|
|
696
|
-
format: "date"
|
|
697
|
-
};
|
|
698
|
-
case "integer": return integerDateParser(def, refs);
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
const integerDateParser = (def, refs) => {
|
|
702
|
-
const res = {
|
|
703
|
-
type: "integer",
|
|
704
|
-
format: "unix-time"
|
|
705
|
-
};
|
|
706
|
-
if (refs.target === "openApi3") return res;
|
|
707
|
-
for (const check of def.checks) switch (check.kind) {
|
|
708
|
-
case "min":
|
|
709
|
-
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
710
|
-
break;
|
|
711
|
-
case "max":
|
|
712
|
-
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
713
|
-
break;
|
|
714
|
-
}
|
|
715
|
-
return res;
|
|
716
|
-
};
|
|
717
|
-
|
|
718
|
-
//#endregion
|
|
719
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/default.js
|
|
720
|
-
function parseDefaultDef(_def, refs) {
|
|
721
|
-
return {
|
|
722
|
-
...parseDef(_def.innerType._def, refs),
|
|
723
|
-
default: _def.defaultValue()
|
|
724
|
-
};
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
//#endregion
|
|
728
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/effects.js
|
|
729
|
-
function parseEffectsDef(_def, refs) {
|
|
730
|
-
return refs.effectStrategy === "input" ? parseDef(_def.schema._def, refs) : {};
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
//#endregion
|
|
734
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/enum.js
|
|
735
|
-
function parseEnumDef(def) {
|
|
736
|
-
return {
|
|
737
|
-
type: "string",
|
|
738
|
-
enum: def.values
|
|
739
|
-
};
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
//#endregion
|
|
743
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js
|
|
744
|
-
const isJsonSchema7AllOfType = (type) => {
|
|
745
|
-
if ("type" in type && type.type === "string") return false;
|
|
746
|
-
return "allOf" in type;
|
|
747
|
-
};
|
|
748
|
-
function parseIntersectionDef(def, refs) {
|
|
749
|
-
const allOf = [parseDef(def.left._def, {
|
|
750
|
-
...refs,
|
|
751
|
-
currentPath: [
|
|
752
|
-
...refs.currentPath,
|
|
753
|
-
"allOf",
|
|
754
|
-
"0"
|
|
755
|
-
]
|
|
756
|
-
}), parseDef(def.right._def, {
|
|
757
|
-
...refs,
|
|
758
|
-
currentPath: [
|
|
759
|
-
...refs.currentPath,
|
|
760
|
-
"allOf",
|
|
761
|
-
"1"
|
|
762
|
-
]
|
|
763
|
-
})].filter((x) => !!x);
|
|
764
|
-
let unevaluatedProperties = refs.target === "jsonSchema2019-09" ? { unevaluatedProperties: false } : undefined;
|
|
765
|
-
const mergedAllOf = [];
|
|
766
|
-
allOf.forEach((schema$1) => {
|
|
767
|
-
if (isJsonSchema7AllOfType(schema$1)) {
|
|
768
|
-
mergedAllOf.push(...schema$1.allOf);
|
|
769
|
-
if (schema$1.unevaluatedProperties === undefined) unevaluatedProperties = undefined;
|
|
770
|
-
} else {
|
|
771
|
-
let nestedSchema = schema$1;
|
|
772
|
-
if ("additionalProperties" in schema$1 && schema$1.additionalProperties === false) {
|
|
773
|
-
const { additionalProperties,...rest } = schema$1;
|
|
774
|
-
nestedSchema = rest;
|
|
775
|
-
} else unevaluatedProperties = undefined;
|
|
776
|
-
mergedAllOf.push(nestedSchema);
|
|
777
|
-
}
|
|
778
|
-
});
|
|
779
|
-
return mergedAllOf.length ? {
|
|
780
|
-
allOf: mergedAllOf,
|
|
781
|
-
...unevaluatedProperties
|
|
782
|
-
} : undefined;
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
//#endregion
|
|
786
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/literal.js
|
|
787
|
-
function parseLiteralDef(def, refs) {
|
|
788
|
-
const parsedType = typeof def.value;
|
|
789
|
-
if (parsedType !== "bigint" && parsedType !== "number" && parsedType !== "boolean" && parsedType !== "string") return { type: Array.isArray(def.value) ? "array" : "object" };
|
|
790
|
-
if (refs.target === "openApi3") return {
|
|
791
|
-
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
792
|
-
enum: [def.value]
|
|
793
|
-
};
|
|
794
|
-
return {
|
|
795
|
-
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
796
|
-
const: def.value
|
|
797
|
-
};
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
//#endregion
|
|
801
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/string.js
|
|
802
|
-
let emojiRegex;
|
|
803
|
-
const zodPatterns = {
|
|
804
|
-
cuid: /^[cC][^\s-]{8,}$/,
|
|
805
|
-
cuid2: /^[0-9a-z]+$/,
|
|
806
|
-
ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
|
|
807
|
-
email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
|
|
808
|
-
emoji: () => {
|
|
809
|
-
if (emojiRegex === undefined) emojiRegex = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u");
|
|
810
|
-
return emojiRegex;
|
|
811
|
-
},
|
|
812
|
-
uuid: /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,
|
|
813
|
-
ipv4: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,
|
|
814
|
-
ipv6: /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,
|
|
815
|
-
base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
|
|
816
|
-
nanoid: /^[a-zA-Z0-9_-]{21}$/
|
|
817
|
-
};
|
|
818
|
-
function parseStringDef(def, refs) {
|
|
819
|
-
const res = { type: "string" };
|
|
820
|
-
function processPattern(value) {
|
|
821
|
-
return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(value) : value;
|
|
822
|
-
}
|
|
823
|
-
if (def.checks) for (const check of def.checks) switch (check.kind) {
|
|
824
|
-
case "min":
|
|
825
|
-
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
|
|
826
|
-
break;
|
|
827
|
-
case "max":
|
|
828
|
-
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
|
|
829
|
-
break;
|
|
830
|
-
case "email":
|
|
831
|
-
switch (refs.emailStrategy) {
|
|
832
|
-
case "format:email":
|
|
833
|
-
addFormat(res, "email", check.message, refs);
|
|
834
|
-
break;
|
|
835
|
-
case "format:idn-email":
|
|
836
|
-
addFormat(res, "idn-email", check.message, refs);
|
|
837
|
-
break;
|
|
838
|
-
case "pattern:zod":
|
|
839
|
-
addPattern(res, zodPatterns.email, check.message, refs);
|
|
840
|
-
break;
|
|
841
|
-
}
|
|
842
|
-
break;
|
|
843
|
-
case "url":
|
|
844
|
-
addFormat(res, "uri", check.message, refs);
|
|
845
|
-
break;
|
|
846
|
-
case "uuid":
|
|
847
|
-
addFormat(res, "uuid", check.message, refs);
|
|
848
|
-
break;
|
|
849
|
-
case "regex":
|
|
850
|
-
addPattern(res, check.regex, check.message, refs);
|
|
851
|
-
break;
|
|
852
|
-
case "cuid":
|
|
853
|
-
addPattern(res, zodPatterns.cuid, check.message, refs);
|
|
854
|
-
break;
|
|
855
|
-
case "cuid2":
|
|
856
|
-
addPattern(res, zodPatterns.cuid2, check.message, refs);
|
|
857
|
-
break;
|
|
858
|
-
case "startsWith":
|
|
859
|
-
addPattern(res, RegExp(`^${processPattern(check.value)}`), check.message, refs);
|
|
860
|
-
break;
|
|
861
|
-
case "endsWith":
|
|
862
|
-
addPattern(res, RegExp(`${processPattern(check.value)}$`), check.message, refs);
|
|
863
|
-
break;
|
|
864
|
-
case "datetime":
|
|
865
|
-
addFormat(res, "date-time", check.message, refs);
|
|
866
|
-
break;
|
|
867
|
-
case "date":
|
|
868
|
-
addFormat(res, "date", check.message, refs);
|
|
869
|
-
break;
|
|
870
|
-
case "time":
|
|
871
|
-
addFormat(res, "time", check.message, refs);
|
|
872
|
-
break;
|
|
873
|
-
case "duration":
|
|
874
|
-
addFormat(res, "duration", check.message, refs);
|
|
875
|
-
break;
|
|
876
|
-
case "length":
|
|
877
|
-
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
|
|
878
|
-
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
|
|
879
|
-
break;
|
|
880
|
-
case "includes": {
|
|
881
|
-
addPattern(res, RegExp(processPattern(check.value)), check.message, refs);
|
|
882
|
-
break;
|
|
883
|
-
}
|
|
884
|
-
case "ip": {
|
|
885
|
-
if (check.version !== "v6") addFormat(res, "ipv4", check.message, refs);
|
|
886
|
-
if (check.version !== "v4") addFormat(res, "ipv6", check.message, refs);
|
|
887
|
-
break;
|
|
888
|
-
}
|
|
889
|
-
case "emoji":
|
|
890
|
-
addPattern(res, zodPatterns.emoji, check.message, refs);
|
|
891
|
-
break;
|
|
892
|
-
case "ulid": {
|
|
893
|
-
addPattern(res, zodPatterns.ulid, check.message, refs);
|
|
894
|
-
break;
|
|
895
|
-
}
|
|
896
|
-
case "base64": {
|
|
897
|
-
switch (refs.base64Strategy) {
|
|
898
|
-
case "format:binary": {
|
|
899
|
-
addFormat(res, "binary", check.message, refs);
|
|
900
|
-
break;
|
|
901
|
-
}
|
|
902
|
-
case "contentEncoding:base64": {
|
|
903
|
-
setResponseValueAndErrors(res, "contentEncoding", "base64", check.message, refs);
|
|
904
|
-
break;
|
|
905
|
-
}
|
|
906
|
-
case "pattern:zod": {
|
|
907
|
-
addPattern(res, zodPatterns.base64, check.message, refs);
|
|
908
|
-
break;
|
|
909
|
-
}
|
|
910
|
-
}
|
|
911
|
-
break;
|
|
912
|
-
}
|
|
913
|
-
case "nanoid": addPattern(res, zodPatterns.nanoid, check.message, refs);
|
|
914
|
-
case "toLowerCase":
|
|
915
|
-
case "toUpperCase":
|
|
916
|
-
case "trim": break;
|
|
917
|
-
default: ((_) => {})(check);
|
|
918
|
-
}
|
|
919
|
-
return res;
|
|
920
|
-
}
|
|
921
|
-
const escapeNonAlphaNumeric = (value) => Array.from(value).map((c) => /[a-zA-Z0-9]/.test(c) ? c : `\\${c}`).join("");
|
|
922
|
-
const addFormat = (schema$1, value, message, refs) => {
|
|
923
|
-
if (schema$1.format || schema$1.anyOf?.some((x) => x.format)) {
|
|
924
|
-
if (!schema$1.anyOf) schema$1.anyOf = [];
|
|
925
|
-
if (schema$1.format) {
|
|
926
|
-
schema$1.anyOf.push({
|
|
927
|
-
format: schema$1.format,
|
|
928
|
-
...schema$1.errorMessage && refs.errorMessages && { errorMessage: { format: schema$1.errorMessage.format } }
|
|
929
|
-
});
|
|
930
|
-
delete schema$1.format;
|
|
931
|
-
if (schema$1.errorMessage) {
|
|
932
|
-
delete schema$1.errorMessage.format;
|
|
933
|
-
if (Object.keys(schema$1.errorMessage).length === 0) delete schema$1.errorMessage;
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
|
-
schema$1.anyOf.push({
|
|
937
|
-
format: value,
|
|
938
|
-
...message && refs.errorMessages && { errorMessage: { format: message } }
|
|
939
|
-
});
|
|
940
|
-
} else setResponseValueAndErrors(schema$1, "format", value, message, refs);
|
|
941
|
-
};
|
|
942
|
-
const addPattern = (schema$1, regex, message, refs) => {
|
|
943
|
-
if (schema$1.pattern || schema$1.allOf?.some((x) => x.pattern)) {
|
|
944
|
-
if (!schema$1.allOf) schema$1.allOf = [];
|
|
945
|
-
if (schema$1.pattern) {
|
|
946
|
-
schema$1.allOf.push({
|
|
947
|
-
pattern: schema$1.pattern,
|
|
948
|
-
...schema$1.errorMessage && refs.errorMessages && { errorMessage: { pattern: schema$1.errorMessage.pattern } }
|
|
949
|
-
});
|
|
950
|
-
delete schema$1.pattern;
|
|
951
|
-
if (schema$1.errorMessage) {
|
|
952
|
-
delete schema$1.errorMessage.pattern;
|
|
953
|
-
if (Object.keys(schema$1.errorMessage).length === 0) delete schema$1.errorMessage;
|
|
954
|
-
}
|
|
955
|
-
}
|
|
956
|
-
schema$1.allOf.push({
|
|
957
|
-
pattern: processRegExp(regex, refs),
|
|
958
|
-
...message && refs.errorMessages && { errorMessage: { pattern: message } }
|
|
959
|
-
});
|
|
960
|
-
} else setResponseValueAndErrors(schema$1, "pattern", processRegExp(regex, refs), message, refs);
|
|
961
|
-
};
|
|
962
|
-
const processRegExp = (regexOrFunction, refs) => {
|
|
963
|
-
const regex = typeof regexOrFunction === "function" ? regexOrFunction() : regexOrFunction;
|
|
964
|
-
if (!refs.applyRegexFlags || !regex.flags) return regex.source;
|
|
965
|
-
const flags = {
|
|
966
|
-
i: regex.flags.includes("i"),
|
|
967
|
-
m: regex.flags.includes("m"),
|
|
968
|
-
s: regex.flags.includes("s")
|
|
969
|
-
};
|
|
970
|
-
const source = flags.i ? regex.source.toLowerCase() : regex.source;
|
|
971
|
-
let pattern = "";
|
|
972
|
-
let isEscaped = false;
|
|
973
|
-
let inCharGroup = false;
|
|
974
|
-
let inCharRange = false;
|
|
975
|
-
for (let i = 0; i < source.length; i++) {
|
|
976
|
-
if (isEscaped) {
|
|
977
|
-
pattern += source[i];
|
|
978
|
-
isEscaped = false;
|
|
979
|
-
continue;
|
|
980
|
-
}
|
|
981
|
-
if (flags.i) {
|
|
982
|
-
if (inCharGroup) {
|
|
983
|
-
if (source[i].match(/[a-z]/)) {
|
|
984
|
-
if (inCharRange) {
|
|
985
|
-
pattern += source[i];
|
|
986
|
-
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
987
|
-
inCharRange = false;
|
|
988
|
-
} else if (source[i + 1] === "-" && source[i + 2]?.match(/[a-z]/)) {
|
|
989
|
-
pattern += source[i];
|
|
990
|
-
inCharRange = true;
|
|
991
|
-
} else pattern += `${source[i]}${source[i].toUpperCase()}`;
|
|
992
|
-
continue;
|
|
993
|
-
}
|
|
994
|
-
} else if (source[i].match(/[a-z]/)) {
|
|
995
|
-
pattern += `[${source[i]}${source[i].toUpperCase()}]`;
|
|
996
|
-
continue;
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
if (flags.m) {
|
|
1000
|
-
if (source[i] === "^") {
|
|
1001
|
-
pattern += `(^|(?<=[\r\n]))`;
|
|
1002
|
-
continue;
|
|
1003
|
-
} else if (source[i] === "$") {
|
|
1004
|
-
pattern += `($|(?=[\r\n]))`;
|
|
1005
|
-
continue;
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
if (flags.s && source[i] === ".") {
|
|
1009
|
-
pattern += inCharGroup ? `${source[i]}\r\n` : `[${source[i]}\r\n]`;
|
|
1010
|
-
continue;
|
|
1011
|
-
}
|
|
1012
|
-
pattern += source[i];
|
|
1013
|
-
if (source[i] === "\\") isEscaped = true;
|
|
1014
|
-
else if (inCharGroup && source[i] === "]") inCharGroup = false;
|
|
1015
|
-
else if (!inCharGroup && source[i] === "[") inCharGroup = true;
|
|
1016
|
-
}
|
|
1017
|
-
try {
|
|
1018
|
-
const regexTest = new RegExp(pattern);
|
|
1019
|
-
} catch {
|
|
1020
|
-
console.warn(`Could not convert regex pattern at ${refs.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`);
|
|
1021
|
-
return regex.source;
|
|
1022
|
-
}
|
|
1023
|
-
return pattern;
|
|
1024
|
-
};
|
|
1025
|
-
|
|
1026
|
-
//#endregion
|
|
1027
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/record.js
|
|
1028
|
-
function parseRecordDef(def, refs) {
|
|
1029
|
-
if (refs.target === "openApi3" && def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodEnum) return {
|
|
1030
|
-
type: "object",
|
|
1031
|
-
required: def.keyType._def.values,
|
|
1032
|
-
properties: def.keyType._def.values.reduce((acc, key) => ({
|
|
1033
|
-
...acc,
|
|
1034
|
-
[key]: parseDef(def.valueType._def, {
|
|
1035
|
-
...refs,
|
|
1036
|
-
currentPath: [
|
|
1037
|
-
...refs.currentPath,
|
|
1038
|
-
"properties",
|
|
1039
|
-
key
|
|
1040
|
-
]
|
|
1041
|
-
}) ?? {}
|
|
1042
|
-
}), {}),
|
|
1043
|
-
additionalProperties: false
|
|
1044
|
-
};
|
|
1045
|
-
const schema$1 = {
|
|
1046
|
-
type: "object",
|
|
1047
|
-
additionalProperties: parseDef(def.valueType._def, {
|
|
1048
|
-
...refs,
|
|
1049
|
-
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1050
|
-
}) ?? {}
|
|
1051
|
-
};
|
|
1052
|
-
if (refs.target === "openApi3") return schema$1;
|
|
1053
|
-
if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodString && def.keyType._def.checks?.length) {
|
|
1054
|
-
const { type,...keyType } = parseStringDef(def.keyType._def, refs);
|
|
1055
|
-
return {
|
|
1056
|
-
...schema$1,
|
|
1057
|
-
propertyNames: keyType
|
|
1058
|
-
};
|
|
1059
|
-
} else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodEnum) return {
|
|
1060
|
-
...schema$1,
|
|
1061
|
-
propertyNames: { enum: def.keyType._def.values }
|
|
1062
|
-
};
|
|
1063
|
-
else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodBranded && def.keyType._def.type._def.typeName === ZodFirstPartyTypeKind.ZodString && def.keyType._def.type._def.checks?.length) {
|
|
1064
|
-
const { type,...keyType } = parseBrandedDef(def.keyType._def, refs);
|
|
1065
|
-
return {
|
|
1066
|
-
...schema$1,
|
|
1067
|
-
propertyNames: keyType
|
|
1068
|
-
};
|
|
1069
|
-
}
|
|
1070
|
-
return schema$1;
|
|
1071
|
-
}
|
|
1072
|
-
|
|
1073
|
-
//#endregion
|
|
1074
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/map.js
|
|
1075
|
-
function parseMapDef(def, refs) {
|
|
1076
|
-
if (refs.mapStrategy === "record") return parseRecordDef(def, refs);
|
|
1077
|
-
const keys = parseDef(def.keyType._def, {
|
|
1078
|
-
...refs,
|
|
1079
|
-
currentPath: [
|
|
1080
|
-
...refs.currentPath,
|
|
1081
|
-
"items",
|
|
1082
|
-
"items",
|
|
1083
|
-
"0"
|
|
1084
|
-
]
|
|
1085
|
-
}) || {};
|
|
1086
|
-
const values = parseDef(def.valueType._def, {
|
|
1087
|
-
...refs,
|
|
1088
|
-
currentPath: [
|
|
1089
|
-
...refs.currentPath,
|
|
1090
|
-
"items",
|
|
1091
|
-
"items",
|
|
1092
|
-
"1"
|
|
1093
|
-
]
|
|
1094
|
-
}) || {};
|
|
1095
|
-
return {
|
|
1096
|
-
type: "array",
|
|
1097
|
-
maxItems: 125,
|
|
1098
|
-
items: {
|
|
1099
|
-
type: "array",
|
|
1100
|
-
items: [keys, values],
|
|
1101
|
-
minItems: 2,
|
|
1102
|
-
maxItems: 2
|
|
1103
|
-
}
|
|
1104
|
-
};
|
|
1105
|
-
}
|
|
1106
|
-
|
|
1107
|
-
//#endregion
|
|
1108
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js
|
|
1109
|
-
function parseNativeEnumDef(def) {
|
|
1110
|
-
const object = def.values;
|
|
1111
|
-
const actualKeys = Object.keys(def.values).filter((key) => {
|
|
1112
|
-
return typeof object[object[key]] !== "number";
|
|
1113
|
-
});
|
|
1114
|
-
const actualValues = actualKeys.map((key) => object[key]);
|
|
1115
|
-
const parsedTypes = Array.from(new Set(actualValues.map((values) => typeof values)));
|
|
1116
|
-
return {
|
|
1117
|
-
type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
|
|
1118
|
-
enum: actualValues
|
|
1119
|
-
};
|
|
1120
|
-
}
|
|
1121
|
-
|
|
1122
|
-
//#endregion
|
|
1123
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/never.js
|
|
1124
|
-
function parseNeverDef() {
|
|
1125
|
-
return { not: {} };
|
|
1126
|
-
}
|
|
1127
|
-
|
|
1128
|
-
//#endregion
|
|
1129
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/null.js
|
|
1130
|
-
function parseNullDef(refs) {
|
|
1131
|
-
return refs.target === "openApi3" ? {
|
|
1132
|
-
enum: ["null"],
|
|
1133
|
-
nullable: true
|
|
1134
|
-
} : { type: "null" };
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
|
-
//#endregion
|
|
1138
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/union.js
|
|
1139
|
-
const primitiveMappings = {
|
|
1140
|
-
ZodString: "string",
|
|
1141
|
-
ZodNumber: "number",
|
|
1142
|
-
ZodBigInt: "integer",
|
|
1143
|
-
ZodBoolean: "boolean",
|
|
1144
|
-
ZodNull: "null"
|
|
1145
|
-
};
|
|
1146
|
-
function parseUnionDef(def, refs) {
|
|
1147
|
-
if (refs.target === "openApi3") return asAnyOf(def, refs);
|
|
1148
|
-
const options$1 = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
|
|
1149
|
-
if (options$1.every((x) => x._def.typeName in primitiveMappings && (!x._def.checks || !x._def.checks.length))) {
|
|
1150
|
-
const types = options$1.reduce((types$1, x) => {
|
|
1151
|
-
const type = primitiveMappings[x._def.typeName];
|
|
1152
|
-
return type && !types$1.includes(type) ? [...types$1, type] : types$1;
|
|
1153
|
-
}, []);
|
|
1154
|
-
return { type: types.length > 1 ? types : types[0] };
|
|
1155
|
-
} else if (options$1.every((x) => x._def.typeName === "ZodLiteral" && !x.description)) {
|
|
1156
|
-
const types = options$1.reduce((acc, x) => {
|
|
1157
|
-
const type = typeof x._def.value;
|
|
1158
|
-
switch (type) {
|
|
1159
|
-
case "string":
|
|
1160
|
-
case "number":
|
|
1161
|
-
case "boolean": return [...acc, type];
|
|
1162
|
-
case "bigint": return [...acc, "integer"];
|
|
1163
|
-
case "object": if (x._def.value === null) return [...acc, "null"];
|
|
1164
|
-
case "symbol":
|
|
1165
|
-
case "undefined":
|
|
1166
|
-
case "function":
|
|
1167
|
-
default: return acc;
|
|
1168
|
-
}
|
|
1169
|
-
}, []);
|
|
1170
|
-
if (types.length === options$1.length) {
|
|
1171
|
-
const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);
|
|
1172
|
-
return {
|
|
1173
|
-
type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
|
|
1174
|
-
enum: options$1.reduce((acc, x) => {
|
|
1175
|
-
return acc.includes(x._def.value) ? acc : [...acc, x._def.value];
|
|
1176
|
-
}, [])
|
|
1177
|
-
};
|
|
1178
|
-
}
|
|
1179
|
-
} else if (options$1.every((x) => x._def.typeName === "ZodEnum")) return {
|
|
1180
|
-
type: "string",
|
|
1181
|
-
enum: options$1.reduce((acc, x) => [...acc, ...x._def.values.filter((x$1) => !acc.includes(x$1))], [])
|
|
1182
|
-
};
|
|
1183
|
-
return asAnyOf(def, refs);
|
|
1184
|
-
}
|
|
1185
|
-
const asAnyOf = (def, refs) => {
|
|
1186
|
-
const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map((x, i) => parseDef(x._def, {
|
|
1187
|
-
...refs,
|
|
1188
|
-
currentPath: [
|
|
1189
|
-
...refs.currentPath,
|
|
1190
|
-
"anyOf",
|
|
1191
|
-
`${i}`
|
|
1192
|
-
]
|
|
1193
|
-
})).filter((x) => !!x && (!refs.strictUnions || typeof x === "object" && Object.keys(x).length > 0));
|
|
1194
|
-
return anyOf.length ? { anyOf } : undefined;
|
|
1195
|
-
};
|
|
1196
|
-
|
|
1197
|
-
//#endregion
|
|
1198
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js
|
|
1199
|
-
function parseNullableDef(def, refs) {
|
|
1200
|
-
if ([
|
|
1201
|
-
"ZodString",
|
|
1202
|
-
"ZodNumber",
|
|
1203
|
-
"ZodBigInt",
|
|
1204
|
-
"ZodBoolean",
|
|
1205
|
-
"ZodNull"
|
|
1206
|
-
].includes(def.innerType._def.typeName) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
|
|
1207
|
-
if (refs.target === "openApi3") return {
|
|
1208
|
-
type: primitiveMappings[def.innerType._def.typeName],
|
|
1209
|
-
nullable: true
|
|
1210
|
-
};
|
|
1211
|
-
return { type: [primitiveMappings[def.innerType._def.typeName], "null"] };
|
|
1212
|
-
}
|
|
1213
|
-
if (refs.target === "openApi3") {
|
|
1214
|
-
const base$1 = parseDef(def.innerType._def, {
|
|
1215
|
-
...refs,
|
|
1216
|
-
currentPath: [...refs.currentPath]
|
|
1217
|
-
});
|
|
1218
|
-
if (base$1 && "$ref" in base$1) return {
|
|
1219
|
-
allOf: [base$1],
|
|
1220
|
-
nullable: true
|
|
1221
|
-
};
|
|
1222
|
-
return base$1 && {
|
|
1223
|
-
...base$1,
|
|
1224
|
-
nullable: true
|
|
1225
|
-
};
|
|
1226
|
-
}
|
|
1227
|
-
const base = parseDef(def.innerType._def, {
|
|
1228
|
-
...refs,
|
|
1229
|
-
currentPath: [
|
|
1230
|
-
...refs.currentPath,
|
|
1231
|
-
"anyOf",
|
|
1232
|
-
"0"
|
|
1233
|
-
]
|
|
1234
|
-
});
|
|
1235
|
-
return base && { anyOf: [base, { type: "null" }] };
|
|
1236
|
-
}
|
|
1237
|
-
|
|
1238
|
-
//#endregion
|
|
1239
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/number.js
|
|
1240
|
-
function parseNumberDef(def, refs) {
|
|
1241
|
-
const res = { type: "number" };
|
|
1242
|
-
if (!def.checks) return res;
|
|
1243
|
-
for (const check of def.checks) switch (check.kind) {
|
|
1244
|
-
case "int":
|
|
1245
|
-
res.type = "integer";
|
|
1246
|
-
addErrorMessage(res, "type", check.message, refs);
|
|
1247
|
-
break;
|
|
1248
|
-
case "min":
|
|
1249
|
-
if (refs.target === "jsonSchema7") if (check.inclusive) setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
1250
|
-
else setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
|
|
1251
|
-
else {
|
|
1252
|
-
if (!check.inclusive) res.exclusiveMinimum = true;
|
|
1253
|
-
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
1254
|
-
}
|
|
1255
|
-
break;
|
|
1256
|
-
case "max":
|
|
1257
|
-
if (refs.target === "jsonSchema7") if (check.inclusive) setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
1258
|
-
else setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
|
|
1259
|
-
else {
|
|
1260
|
-
if (!check.inclusive) res.exclusiveMaximum = true;
|
|
1261
|
-
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
1262
|
-
}
|
|
1263
|
-
break;
|
|
1264
|
-
case "multipleOf":
|
|
1265
|
-
setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
1266
|
-
break;
|
|
1267
|
-
}
|
|
1268
|
-
return res;
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
//#endregion
|
|
1272
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/object.js
|
|
1273
|
-
function decideAdditionalProperties(def, refs) {
|
|
1274
|
-
if (refs.removeAdditionalStrategy === "strict") return def.catchall._def.typeName === "ZodNever" ? def.unknownKeys !== "strict" : parseDef(def.catchall._def, {
|
|
1275
|
-
...refs,
|
|
1276
|
-
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1277
|
-
}) ?? true;
|
|
1278
|
-
else return def.catchall._def.typeName === "ZodNever" ? def.unknownKeys === "passthrough" : parseDef(def.catchall._def, {
|
|
1279
|
-
...refs,
|
|
1280
|
-
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1281
|
-
}) ?? true;
|
|
1282
|
-
}
|
|
1283
|
-
function parseObjectDef(def, refs) {
|
|
1284
|
-
const result = {
|
|
1285
|
-
type: "object",
|
|
1286
|
-
...Object.entries(def.shape()).reduce((acc, [propName, propDef]) => {
|
|
1287
|
-
if (propDef === undefined || propDef._def === undefined) return acc;
|
|
1288
|
-
const parsedDef = parseDef(propDef._def, {
|
|
1289
|
-
...refs,
|
|
1290
|
-
currentPath: [
|
|
1291
|
-
...refs.currentPath,
|
|
1292
|
-
"properties",
|
|
1293
|
-
propName
|
|
1294
|
-
],
|
|
1295
|
-
propertyPath: [
|
|
1296
|
-
...refs.currentPath,
|
|
1297
|
-
"properties",
|
|
1298
|
-
propName
|
|
1299
|
-
]
|
|
1300
|
-
});
|
|
1301
|
-
if (parsedDef === undefined) return acc;
|
|
1302
|
-
return {
|
|
1303
|
-
properties: {
|
|
1304
|
-
...acc.properties,
|
|
1305
|
-
[propName]: parsedDef
|
|
1306
|
-
},
|
|
1307
|
-
required: propDef.isOptional() ? acc.required : [...acc.required, propName]
|
|
1308
|
-
};
|
|
1309
|
-
}, {
|
|
1310
|
-
properties: {},
|
|
1311
|
-
required: []
|
|
1312
|
-
}),
|
|
1313
|
-
additionalProperties: decideAdditionalProperties(def, refs)
|
|
1314
|
-
};
|
|
1315
|
-
if (!result.required.length) delete result.required;
|
|
1316
|
-
return result;
|
|
1317
|
-
}
|
|
1318
|
-
|
|
1319
|
-
//#endregion
|
|
1320
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/optional.js
|
|
1321
|
-
const parseOptionalDef = (def, refs) => {
|
|
1322
|
-
if (refs.currentPath.toString() === refs.propertyPath?.toString()) return parseDef(def.innerType._def, refs);
|
|
1323
|
-
const innerSchema = parseDef(def.innerType._def, {
|
|
1324
|
-
...refs,
|
|
1325
|
-
currentPath: [
|
|
1326
|
-
...refs.currentPath,
|
|
1327
|
-
"anyOf",
|
|
1328
|
-
"1"
|
|
1329
|
-
]
|
|
1330
|
-
});
|
|
1331
|
-
return innerSchema ? { anyOf: [{ not: {} }, innerSchema] } : {};
|
|
1332
|
-
};
|
|
1333
|
-
|
|
1334
|
-
//#endregion
|
|
1335
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js
|
|
1336
|
-
const parsePipelineDef = (def, refs) => {
|
|
1337
|
-
if (refs.pipeStrategy === "input") return parseDef(def.in._def, refs);
|
|
1338
|
-
else if (refs.pipeStrategy === "output") return parseDef(def.out._def, refs);
|
|
1339
|
-
const a = parseDef(def.in._def, {
|
|
1340
|
-
...refs,
|
|
1341
|
-
currentPath: [
|
|
1342
|
-
...refs.currentPath,
|
|
1343
|
-
"allOf",
|
|
1344
|
-
"0"
|
|
1345
|
-
]
|
|
1346
|
-
});
|
|
1347
|
-
const b = parseDef(def.out._def, {
|
|
1348
|
-
...refs,
|
|
1349
|
-
currentPath: [
|
|
1350
|
-
...refs.currentPath,
|
|
1351
|
-
"allOf",
|
|
1352
|
-
a ? "1" : "0"
|
|
1353
|
-
]
|
|
1354
|
-
});
|
|
1355
|
-
return { allOf: [a, b].filter((x) => x !== undefined) };
|
|
1356
|
-
};
|
|
1357
|
-
|
|
1358
|
-
//#endregion
|
|
1359
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/promise.js
|
|
1360
|
-
function parsePromiseDef(def, refs) {
|
|
1361
|
-
return parseDef(def.type._def, refs);
|
|
1362
|
-
}
|
|
1363
|
-
|
|
1364
|
-
//#endregion
|
|
1365
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/set.js
|
|
1366
|
-
function parseSetDef(def, refs) {
|
|
1367
|
-
const items = parseDef(def.valueType._def, {
|
|
1368
|
-
...refs,
|
|
1369
|
-
currentPath: [...refs.currentPath, "items"]
|
|
1370
|
-
});
|
|
1371
|
-
const schema$1 = {
|
|
1372
|
-
type: "array",
|
|
1373
|
-
uniqueItems: true,
|
|
1374
|
-
items
|
|
1375
|
-
};
|
|
1376
|
-
if (def.minSize) setResponseValueAndErrors(schema$1, "minItems", def.minSize.value, def.minSize.message, refs);
|
|
1377
|
-
if (def.maxSize) setResponseValueAndErrors(schema$1, "maxItems", def.maxSize.value, def.maxSize.message, refs);
|
|
1378
|
-
return schema$1;
|
|
1379
|
-
}
|
|
1380
|
-
|
|
1381
|
-
//#endregion
|
|
1382
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js
|
|
1383
|
-
function parseTupleDef(def, refs) {
|
|
1384
|
-
if (def.rest) return {
|
|
1385
|
-
type: "array",
|
|
1386
|
-
minItems: def.items.length,
|
|
1387
|
-
items: def.items.map((x, i) => parseDef(x._def, {
|
|
1388
|
-
...refs,
|
|
1389
|
-
currentPath: [
|
|
1390
|
-
...refs.currentPath,
|
|
1391
|
-
"items",
|
|
1392
|
-
`${i}`
|
|
1393
|
-
]
|
|
1394
|
-
})).reduce((acc, x) => x === undefined ? acc : [...acc, x], []),
|
|
1395
|
-
additionalItems: parseDef(def.rest._def, {
|
|
1396
|
-
...refs,
|
|
1397
|
-
currentPath: [...refs.currentPath, "additionalItems"]
|
|
1398
|
-
})
|
|
1399
|
-
};
|
|
1400
|
-
else return {
|
|
1401
|
-
type: "array",
|
|
1402
|
-
minItems: def.items.length,
|
|
1403
|
-
maxItems: def.items.length,
|
|
1404
|
-
items: def.items.map((x, i) => parseDef(x._def, {
|
|
1405
|
-
...refs,
|
|
1406
|
-
currentPath: [
|
|
1407
|
-
...refs.currentPath,
|
|
1408
|
-
"items",
|
|
1409
|
-
`${i}`
|
|
1410
|
-
]
|
|
1411
|
-
})).reduce((acc, x) => x === undefined ? acc : [...acc, x], [])
|
|
1412
|
-
};
|
|
1413
|
-
}
|
|
1414
|
-
|
|
1415
|
-
//#endregion
|
|
1416
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js
|
|
1417
|
-
function parseUndefinedDef() {
|
|
1418
|
-
return { not: {} };
|
|
1419
|
-
}
|
|
1420
|
-
|
|
1421
|
-
//#endregion
|
|
1422
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js
|
|
1423
|
-
function parseUnknownDef() {
|
|
1424
|
-
return {};
|
|
1425
|
-
}
|
|
1426
|
-
|
|
1427
|
-
//#endregion
|
|
1428
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js
|
|
1429
|
-
const parseReadonlyDef = (def, refs) => {
|
|
1430
|
-
return parseDef(def.innerType._def, refs);
|
|
1431
|
-
};
|
|
1432
|
-
|
|
1433
|
-
//#endregion
|
|
1434
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parseDef.js
|
|
1435
|
-
function parseDef(def, refs, forceResolution = false) {
|
|
1436
|
-
const seenItem = refs.seen.get(def);
|
|
1437
|
-
if (refs.override) {
|
|
1438
|
-
const overrideResult = refs.override?.(def, refs, seenItem, forceResolution);
|
|
1439
|
-
if (overrideResult !== ignoreOverride) return overrideResult;
|
|
1440
|
-
}
|
|
1441
|
-
if (seenItem && !forceResolution) {
|
|
1442
|
-
const seenSchema = get$ref(seenItem, refs);
|
|
1443
|
-
if (seenSchema !== undefined) return seenSchema;
|
|
1444
|
-
}
|
|
1445
|
-
const newItem = {
|
|
1446
|
-
def,
|
|
1447
|
-
path: refs.currentPath,
|
|
1448
|
-
jsonSchema: undefined
|
|
1449
|
-
};
|
|
1450
|
-
refs.seen.set(def, newItem);
|
|
1451
|
-
const jsonSchema = selectParser(def, def.typeName, refs);
|
|
1452
|
-
if (jsonSchema) addMeta(def, refs, jsonSchema);
|
|
1453
|
-
newItem.jsonSchema = jsonSchema;
|
|
1454
|
-
return jsonSchema;
|
|
1455
|
-
}
|
|
1456
|
-
const get$ref = (item, refs) => {
|
|
1457
|
-
switch (refs.$refStrategy) {
|
|
1458
|
-
case "root": return { $ref: item.path.join("/") };
|
|
1459
|
-
case "relative": return { $ref: getRelativePath(refs.currentPath, item.path) };
|
|
1460
|
-
case "none":
|
|
1461
|
-
case "seen": {
|
|
1462
|
-
if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
|
|
1463
|
-
console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
|
|
1464
|
-
return {};
|
|
1465
|
-
}
|
|
1466
|
-
return refs.$refStrategy === "seen" ? {} : undefined;
|
|
1467
|
-
}
|
|
1468
|
-
}
|
|
1469
|
-
};
|
|
1470
|
-
const getRelativePath = (pathA, pathB) => {
|
|
1471
|
-
let i = 0;
|
|
1472
|
-
for (; i < pathA.length && i < pathB.length; i++) if (pathA[i] !== pathB[i]) break;
|
|
1473
|
-
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
1474
|
-
};
|
|
1475
|
-
const selectParser = (def, typeName, refs) => {
|
|
1476
|
-
switch (typeName) {
|
|
1477
|
-
case ZodFirstPartyTypeKind.ZodString: return parseStringDef(def, refs);
|
|
1478
|
-
case ZodFirstPartyTypeKind.ZodNumber: return parseNumberDef(def, refs);
|
|
1479
|
-
case ZodFirstPartyTypeKind.ZodObject: return parseObjectDef(def, refs);
|
|
1480
|
-
case ZodFirstPartyTypeKind.ZodBigInt: return parseBigintDef(def, refs);
|
|
1481
|
-
case ZodFirstPartyTypeKind.ZodBoolean: return parseBooleanDef();
|
|
1482
|
-
case ZodFirstPartyTypeKind.ZodDate: return parseDateDef(def, refs);
|
|
1483
|
-
case ZodFirstPartyTypeKind.ZodUndefined: return parseUndefinedDef();
|
|
1484
|
-
case ZodFirstPartyTypeKind.ZodNull: return parseNullDef(refs);
|
|
1485
|
-
case ZodFirstPartyTypeKind.ZodArray: return parseArrayDef(def, refs);
|
|
1486
|
-
case ZodFirstPartyTypeKind.ZodUnion:
|
|
1487
|
-
case ZodFirstPartyTypeKind.ZodDiscriminatedUnion: return parseUnionDef(def, refs);
|
|
1488
|
-
case ZodFirstPartyTypeKind.ZodIntersection: return parseIntersectionDef(def, refs);
|
|
1489
|
-
case ZodFirstPartyTypeKind.ZodTuple: return parseTupleDef(def, refs);
|
|
1490
|
-
case ZodFirstPartyTypeKind.ZodRecord: return parseRecordDef(def, refs);
|
|
1491
|
-
case ZodFirstPartyTypeKind.ZodLiteral: return parseLiteralDef(def, refs);
|
|
1492
|
-
case ZodFirstPartyTypeKind.ZodEnum: return parseEnumDef(def);
|
|
1493
|
-
case ZodFirstPartyTypeKind.ZodNativeEnum: return parseNativeEnumDef(def);
|
|
1494
|
-
case ZodFirstPartyTypeKind.ZodNullable: return parseNullableDef(def, refs);
|
|
1495
|
-
case ZodFirstPartyTypeKind.ZodOptional: return parseOptionalDef(def, refs);
|
|
1496
|
-
case ZodFirstPartyTypeKind.ZodMap: return parseMapDef(def, refs);
|
|
1497
|
-
case ZodFirstPartyTypeKind.ZodSet: return parseSetDef(def, refs);
|
|
1498
|
-
case ZodFirstPartyTypeKind.ZodLazy: return parseDef(def.getter()._def, refs);
|
|
1499
|
-
case ZodFirstPartyTypeKind.ZodPromise: return parsePromiseDef(def, refs);
|
|
1500
|
-
case ZodFirstPartyTypeKind.ZodNaN:
|
|
1501
|
-
case ZodFirstPartyTypeKind.ZodNever: return parseNeverDef();
|
|
1502
|
-
case ZodFirstPartyTypeKind.ZodEffects: return parseEffectsDef(def, refs);
|
|
1503
|
-
case ZodFirstPartyTypeKind.ZodAny: return parseAnyDef();
|
|
1504
|
-
case ZodFirstPartyTypeKind.ZodUnknown: return parseUnknownDef();
|
|
1505
|
-
case ZodFirstPartyTypeKind.ZodDefault: return parseDefaultDef(def, refs);
|
|
1506
|
-
case ZodFirstPartyTypeKind.ZodBranded: return parseBrandedDef(def, refs);
|
|
1507
|
-
case ZodFirstPartyTypeKind.ZodReadonly: return parseReadonlyDef(def, refs);
|
|
1508
|
-
case ZodFirstPartyTypeKind.ZodCatch: return parseCatchDef(def, refs);
|
|
1509
|
-
case ZodFirstPartyTypeKind.ZodPipeline: return parsePipelineDef(def, refs);
|
|
1510
|
-
case ZodFirstPartyTypeKind.ZodFunction:
|
|
1511
|
-
case ZodFirstPartyTypeKind.ZodVoid:
|
|
1512
|
-
case ZodFirstPartyTypeKind.ZodSymbol: return undefined;
|
|
1513
|
-
default: return ((_) => undefined)(typeName);
|
|
1514
|
-
}
|
|
1515
|
-
};
|
|
1516
|
-
const addMeta = (def, refs, jsonSchema) => {
|
|
1517
|
-
if (def.description) {
|
|
1518
|
-
jsonSchema.description = def.description;
|
|
1519
|
-
if (refs.markdownDescription) jsonSchema.markdownDescription = def.description;
|
|
1520
|
-
}
|
|
1521
|
-
return jsonSchema;
|
|
1522
|
-
};
|
|
1523
|
-
|
|
1524
|
-
//#endregion
|
|
1525
|
-
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js
|
|
1526
|
-
const zodToJsonSchema = (schema$1, options$1) => {
|
|
1527
|
-
const refs = getRefs(options$1);
|
|
1528
|
-
const definitions = typeof options$1 === "object" && options$1.definitions ? Object.entries(options$1.definitions).reduce((acc, [name$1, schema$2]) => ({
|
|
1529
|
-
...acc,
|
|
1530
|
-
[name$1]: parseDef(schema$2._def, {
|
|
1531
|
-
...refs,
|
|
1532
|
-
currentPath: [
|
|
1533
|
-
...refs.basePath,
|
|
1534
|
-
refs.definitionPath,
|
|
1535
|
-
name$1
|
|
1536
|
-
]
|
|
1537
|
-
}, true) ?? {}
|
|
1538
|
-
}), {}) : undefined;
|
|
1539
|
-
const name = typeof options$1 === "string" ? options$1 : options$1?.nameStrategy === "title" ? undefined : options$1?.name;
|
|
1540
|
-
const main$1 = parseDef(schema$1._def, name === undefined ? refs : {
|
|
1541
|
-
...refs,
|
|
1542
|
-
currentPath: [
|
|
1543
|
-
...refs.basePath,
|
|
1544
|
-
refs.definitionPath,
|
|
1545
|
-
name
|
|
1546
|
-
]
|
|
1547
|
-
}, false) ?? {};
|
|
1548
|
-
const title = typeof options$1 === "object" && options$1.name !== undefined && options$1.nameStrategy === "title" ? options$1.name : undefined;
|
|
1549
|
-
if (title !== undefined) main$1.title = title;
|
|
1550
|
-
const combined = name === undefined ? definitions ? {
|
|
1551
|
-
...main$1,
|
|
1552
|
-
[refs.definitionPath]: definitions
|
|
1553
|
-
} : main$1 : {
|
|
1554
|
-
$ref: [
|
|
1555
|
-
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
1556
|
-
refs.definitionPath,
|
|
1557
|
-
name
|
|
1558
|
-
].join("/"),
|
|
1559
|
-
[refs.definitionPath]: {
|
|
1560
|
-
...definitions,
|
|
1561
|
-
[name]: main$1
|
|
1562
|
-
}
|
|
1563
|
-
};
|
|
1564
|
-
if (refs.target === "jsonSchema7") combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
1565
|
-
else if (refs.target === "jsonSchema2019-09") combined.$schema = "https://json-schema.org/draft/2019-09/schema#";
|
|
1566
|
-
return combined;
|
|
1567
|
-
};
|
|
1568
|
-
|
|
1569
|
-
//#endregion
|
|
1570
|
-
//#region src/utils/zod-ext.ts
|
|
1571
|
-
const stringOrRegExp = () => z.string().or(z.instanceof(RegExp));
|
|
1572
|
-
const optionalStringArray = () => z.string().array().optional();
|
|
1573
|
-
const returnTrue = () => true;
|
|
1574
|
-
const phantom = () => z.custom(returnTrue);
|
|
1575
|
-
const voidNullableWith = (t) => {
|
|
1576
|
-
return voidNullable().or(t);
|
|
1577
|
-
};
|
|
1578
|
-
const voidNullable = () => {
|
|
1579
|
-
return z.void().or(z.null()).or(z.undefined());
|
|
1580
|
-
};
|
|
1581
|
-
|
|
1582
|
-
//#endregion
|
|
1583
|
-
//#region src/options/input-options-schema.ts
|
|
1584
|
-
const inputOptionSchema = z.string().or(z.string().array()).or(z.record(z.string()));
|
|
1585
|
-
const externalSchema = stringOrRegExp().or(stringOrRegExp().array()).or(z.function().args(z.string(), z.string().optional(), z.boolean()).returns(voidNullableWith(z.boolean())));
|
|
1586
|
-
const moduleTypesSchema = z.record(z.literal("js").or(z.literal("jsx")).or(z.literal("ts")).or(z.literal("tsx")).or(z.literal("json")).or(z.literal("text")).or(z.literal("base64")).or(z.literal("dataurl")).or(z.literal("binary")).or(z.literal("empty")).or(z.literal("css")));
|
|
1587
|
-
const jsxOptionsSchema = z.strictObject({
|
|
1588
|
-
mode: z.literal("classic").or(z.literal("automatic")).describe("Jsx transformation mode").optional(),
|
|
1589
|
-
factory: z.string().describe("Jsx element transformation").optional(),
|
|
1590
|
-
fragment: z.string().describe("Jsx fragment transformation").optional(),
|
|
1591
|
-
importSource: z.string().describe("Import the factory of element and fragment if mode is classic").optional(),
|
|
1592
|
-
jsxImportSource: z.string().describe("Import the factory of element and fragment if mode is automatic").optional(),
|
|
1593
|
-
refresh: z.boolean().describe("React refresh transformation").optional(),
|
|
1594
|
-
development: z.boolean().describe("Development specific information").optional()
|
|
1595
|
-
});
|
|
1596
|
-
const stringOrRegExpSchema = stringOrRegExp().or(stringOrRegExp().array());
|
|
1597
|
-
const watchOptionsSchema = z.strictObject({
|
|
1598
|
-
skipWrite: z.boolean().describe("Skip the bundle.write() step").optional(),
|
|
1599
|
-
notify: z.strictObject({
|
|
1600
|
-
pollInterval: z.number().optional(),
|
|
1601
|
-
compareContents: z.boolean().optional()
|
|
1602
|
-
}).describe("Notify options").optional(),
|
|
1603
|
-
include: stringOrRegExpSchema.optional(),
|
|
1604
|
-
exclude: stringOrRegExpSchema.optional(),
|
|
1605
|
-
chokidar: z.any().optional()
|
|
1606
|
-
});
|
|
1607
|
-
const checksOptionsSchema = z.strictObject({ circularDependency: z.boolean().describe("Wether to emit warnings when detecting circular dependencies").optional() });
|
|
1608
|
-
const inputOptionsSchema = z.strictObject({
|
|
1609
|
-
input: inputOptionSchema.optional(),
|
|
1610
|
-
plugins: phantom().optional(),
|
|
1611
|
-
external: externalSchema.optional(),
|
|
1612
|
-
resolve: z.strictObject({
|
|
1613
|
-
alias: z.record(z.array(z.string()).or(z.string())).optional(),
|
|
1614
|
-
aliasFields: z.array(z.array(z.string())).optional(),
|
|
1615
|
-
conditionNames: optionalStringArray(),
|
|
1616
|
-
extensionAlias: z.record(z.string(), z.array(z.string())).optional(),
|
|
1617
|
-
exportsFields: z.array(z.array(z.string())).optional(),
|
|
1618
|
-
extensions: optionalStringArray(),
|
|
1619
|
-
mainFields: optionalStringArray(),
|
|
1620
|
-
mainFiles: optionalStringArray(),
|
|
1621
|
-
modules: optionalStringArray(),
|
|
1622
|
-
symlinks: z.boolean().optional(),
|
|
1623
|
-
tsconfigFilename: z.string().optional()
|
|
1624
|
-
}).optional(),
|
|
1625
|
-
cwd: z.string().describe("Current working directory").optional(),
|
|
1626
|
-
platform: z.literal("node").or(z.literal("browser")).or(z.literal("neutral")).describe(`Platform for which the code should be generated (node, ${colors.underline("browser")}, neutral)`).optional(),
|
|
1627
|
-
shimMissingExports: z.boolean().describe(`Create shim variables for missing exports`).optional(),
|
|
1628
|
-
treeshake: TreeshakingOptionsSchema.optional(),
|
|
1629
|
-
logLevel: LogLevelOptionSchema.describe(`Log level (${colors.dim("silent")}, ${colors.underline(colors.gray("info"))}, debug, ${colors.yellow("warn")})`).optional(),
|
|
1630
|
-
onLog: z.function().args(LogLevelSchema, RollupLogSchema, z.function().args(LogLevelWithErrorSchema, RollupLogWithStringSchema)).optional(),
|
|
1631
|
-
onwarn: z.function().args(RollupLogSchema, z.function().args(RollupLogWithStringSchema.or(z.function().returns(RollupLogWithStringSchema)))).optional(),
|
|
1632
|
-
moduleTypes: moduleTypesSchema.describe("Module types for customized extensions").optional(),
|
|
1633
|
-
experimental: z.strictObject({
|
|
1634
|
-
enableComposingJsPlugins: z.boolean().optional(),
|
|
1635
|
-
strictExecutionOrder: z.boolean().optional(),
|
|
1636
|
-
disableLiveBindings: z.boolean().optional(),
|
|
1637
|
-
resolveNewUrlToAsset: z.boolean().optional()
|
|
1638
|
-
}).optional(),
|
|
1639
|
-
define: z.record(z.string()).describe("Define global variables").optional(),
|
|
1640
|
-
inject: z.record(z.string().or(z.tuple([z.string(), z.string()]))).optional(),
|
|
1641
|
-
profilerNames: z.boolean().optional(),
|
|
1642
|
-
jsx: jsxOptionsSchema.optional(),
|
|
1643
|
-
watch: watchOptionsSchema.or(z.literal(false)).optional(),
|
|
1644
|
-
dropLabels: z.array(z.string()).describe("Remove labeled statements with these label names").optional(),
|
|
1645
|
-
checks: checksOptionsSchema.optional()
|
|
1646
|
-
});
|
|
1647
|
-
const inputCliOptionsSchema = inputOptionsSchema.extend({
|
|
1648
|
-
external: z.array(z.string()).describe("Comma-separated list of module ids to exclude from the bundle `<module-id>,...`").optional(),
|
|
1649
|
-
inject: z.record(z.string()).describe("Inject import statements on demand").optional(),
|
|
1650
|
-
treeshake: z.boolean().describe("enable treeshaking").default(true).optional()
|
|
1651
|
-
}).omit({
|
|
1652
|
-
input: true,
|
|
1653
|
-
plugins: true,
|
|
1654
|
-
onwarn: true,
|
|
1655
|
-
onLog: true,
|
|
1656
|
-
resolve: true,
|
|
1657
|
-
experimental: true,
|
|
1658
|
-
profilerNames: true,
|
|
1659
|
-
watch: true
|
|
1660
|
-
});
|
|
1661
|
-
|
|
1662
|
-
//#endregion
|
|
1663
|
-
//#region src/options/output-options-schema.ts
|
|
1664
|
-
const ModuleFormatSchema = z.literal("es").or(z.literal("cjs")).or(z.literal("esm")).or(z.literal("module")).or(z.literal("commonjs")).or(z.literal("iife")).or(z.literal("umd")).describe(`Output format of the generated bundle (supports ${colors.underline("esm")}, cjs, and iife)`);
|
|
1665
|
-
const addonFunctionSchema = z.function().args(phantom()).returns(z.string().or(z.promise(z.string())));
|
|
1666
|
-
const chunkFileNamesFunctionSchema = z.function().args(phantom()).returns(z.string());
|
|
1667
|
-
const GlobalsFunctionSchema = z.function().args(z.string()).returns(z.string());
|
|
1668
|
-
const outputOptionsSchema = z.strictObject({
|
|
1669
|
-
dir: z.string().describe("Output directory, defaults to `dist` if `file` is not set").optional(),
|
|
1670
|
-
file: z.string().describe("Single output file").optional(),
|
|
1671
|
-
exports: z.literal("auto").or(z.literal("named")).or(z.literal("default")).or(z.literal("none")).describe(`Specify a export mode (${colors.underline("auto")}, named, default, none)`).optional(),
|
|
1672
|
-
hashCharacters: z.literal("base64").or(z.literal("base36")).or(z.literal("hex")).describe("Use the specified character set for file hashes").optional(),
|
|
1673
|
-
format: ModuleFormatSchema.optional(),
|
|
1674
|
-
sourcemap: z.boolean().or(z.literal("inline")).or(z.literal("hidden")).describe(`Generate sourcemap (\`-s inline\` for inline, or ${colors.bold("pass the `-s` on the last argument if you want to generate `.map` file")})`).optional(),
|
|
1675
|
-
sourcemapIgnoreList: z.boolean().or(phantom()).optional(),
|
|
1676
|
-
sourcemapPathTransform: phantom().optional(),
|
|
1677
|
-
banner: z.string().or(addonFunctionSchema).optional(),
|
|
1678
|
-
footer: z.string().or(addonFunctionSchema).optional(),
|
|
1679
|
-
intro: z.string().or(addonFunctionSchema).optional(),
|
|
1680
|
-
outro: z.string().or(addonFunctionSchema).optional(),
|
|
1681
|
-
extend: z.boolean().describe("Extend global variable defined by name in IIFE / UMD formats").optional(),
|
|
1682
|
-
esModule: z.literal("if-default-prop").or(z.boolean()).optional(),
|
|
1683
|
-
assetFileNames: z.string().describe("Name pattern for asset files").optional(),
|
|
1684
|
-
entryFileNames: z.string().or(chunkFileNamesFunctionSchema).describe("Name pattern for emitted entry chunks").optional(),
|
|
1685
|
-
chunkFileNames: z.string().or(chunkFileNamesFunctionSchema).describe("Name pattern for emitted secondary chunks").optional(),
|
|
1686
|
-
cssEntryFileNames: z.string().or(chunkFileNamesFunctionSchema).describe("Name pattern for emitted css entry chunks").optional(),
|
|
1687
|
-
cssChunkFileNames: z.string().or(chunkFileNamesFunctionSchema).describe("Name pattern for emitted css secondary chunks").optional(),
|
|
1688
|
-
minify: z.boolean().describe("Minify the bundled file.").optional(),
|
|
1689
|
-
name: z.string().describe("Name for UMD / IIFE format outputs").optional(),
|
|
1690
|
-
globals: z.record(z.string()).or(GlobalsFunctionSchema).describe("Global variable of UMD / IIFE dependencies (syntax: `key=value`)").optional(),
|
|
1691
|
-
externalLiveBindings: z.boolean().describe("external live bindings").default(true).optional(),
|
|
1692
|
-
inlineDynamicImports: z.boolean().describe("Inline dynamic imports").default(false).optional(),
|
|
1693
|
-
advancedChunks: z.strictObject({
|
|
1694
|
-
minSize: z.number().optional(),
|
|
1695
|
-
minShareCount: z.number().optional(),
|
|
1696
|
-
groups: z.array(z.strictObject({
|
|
1697
|
-
name: z.string(),
|
|
1698
|
-
test: z.string().or(z.instanceof(RegExp)).optional(),
|
|
1699
|
-
priority: z.number().optional(),
|
|
1700
|
-
minSize: z.number().optional(),
|
|
1701
|
-
minShareCount: z.number().optional()
|
|
1702
|
-
})).optional()
|
|
1703
|
-
}).optional(),
|
|
1704
|
-
comments: z.enum(["none", "preserve-legal"]).describe("Control comments in the output").optional(),
|
|
1705
|
-
target: z.enum([
|
|
1706
|
-
"es6",
|
|
1707
|
-
"es2015",
|
|
1708
|
-
"es2016",
|
|
1709
|
-
"es2017",
|
|
1710
|
-
"es2018",
|
|
1711
|
-
"es2019",
|
|
1712
|
-
"es2020",
|
|
1713
|
-
"es2021",
|
|
1714
|
-
"es2022",
|
|
1715
|
-
"es2023",
|
|
1716
|
-
"es2024",
|
|
1717
|
-
"esnext"
|
|
1718
|
-
]).describe("The JavaScript target environment.").optional()
|
|
1719
|
-
});
|
|
1720
|
-
const getAddonDescription = (placement, wrapper) => {
|
|
1721
|
-
return `Code to insert the ${colors.bold(placement)} of the bundled file (${colors.bold(wrapper)} the wrapper function)`;
|
|
1722
|
-
};
|
|
1723
|
-
const outputCliOptionsSchema = outputOptionsSchema.extend({
|
|
1724
|
-
banner: z.string().describe(getAddonDescription("top", "outside")).optional(),
|
|
1725
|
-
footer: z.string().describe(getAddonDescription("bottom", "outside")).optional(),
|
|
1726
|
-
intro: z.string().describe(getAddonDescription("top", "inside")).optional(),
|
|
1727
|
-
outro: z.string().describe(getAddonDescription("bottom", "inside")).optional(),
|
|
1728
|
-
esModule: z.boolean().describe("Always generate `__esModule` marks in non-ESM formats, defaults to `if-default-prop` (use `--no-esModule` to always disable)").optional(),
|
|
1729
|
-
globals: z.record(z.string()).describe("Global variable of UMD / IIFE dependencies (syntax: `key=value`)").optional(),
|
|
1730
|
-
advancedChunks: z.strictObject({
|
|
1731
|
-
minSize: z.number().describe("Minimum size of the chunk").optional(),
|
|
1732
|
-
minShareCount: z.number().describe("Minimum share count of the chunk").optional()
|
|
1733
|
-
}).optional()
|
|
1734
|
-
}).omit({
|
|
1735
|
-
sourcemapPathTransform: true,
|
|
1736
|
-
sourcemapIgnoreList: true
|
|
1737
|
-
});
|
|
1738
|
-
|
|
1739
|
-
//#endregion
|
|
1740
|
-
//#region src/cli/arguments/schema.ts
|
|
1741
|
-
const cliOptionsSchema = z.strictObject({
|
|
1742
|
-
config: z.string().or(z.boolean()).describe("Path to the config file (default: `rolldown.config.js`)").optional(),
|
|
1743
|
-
help: z.boolean().describe("Show help").optional(),
|
|
1744
|
-
version: z.boolean().describe("Show version number").optional(),
|
|
1745
|
-
watch: z.boolean().describe("Watch files in bundle and rebuild on changes").optional()
|
|
1746
|
-
}).merge(inputCliOptionsSchema).merge(outputCliOptionsSchema);
|
|
1747
|
-
const schema = zodToJsonSchema(cliOptionsSchema);
|
|
1748
|
-
|
|
1749
460
|
//#endregion
|
|
1750
461
|
//#region src/cli/arguments/alias.ts
|
|
1751
462
|
const alias = {
|
|
1752
463
|
config: {
|
|
1753
464
|
abbreviation: "c",
|
|
1754
|
-
hint: "filename"
|
|
1755
|
-
default: "rolldown.config.js"
|
|
465
|
+
hint: "filename"
|
|
1756
466
|
},
|
|
1757
467
|
help: { abbreviation: "h" },
|
|
1758
468
|
version: { abbreviation: "v" },
|
|
@@ -1785,20 +495,26 @@ const alias = {
|
|
|
1785
495
|
|
|
1786
496
|
//#endregion
|
|
1787
497
|
//#region src/cli/arguments/utils.ts
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
498
|
+
const priority = [
|
|
499
|
+
"object",
|
|
500
|
+
"array",
|
|
501
|
+
"string",
|
|
502
|
+
"number",
|
|
503
|
+
"boolean"
|
|
504
|
+
];
|
|
505
|
+
function getSchemaType(schema) {
|
|
506
|
+
if ("anyOf" in schema) {
|
|
507
|
+
const types = schema.anyOf.map(getSchemaType);
|
|
508
|
+
let result = priority.find((type) => types.includes(type));
|
|
509
|
+
if (result) return result;
|
|
510
|
+
}
|
|
511
|
+
if ("type" in schema) return schema.type;
|
|
512
|
+
if ("const" in schema) return typeof schema.const;
|
|
1798
513
|
return "object";
|
|
1799
514
|
}
|
|
1800
|
-
function flattenSchema(schema
|
|
1801
|
-
|
|
515
|
+
function flattenSchema(schema, base = {}, parent = "") {
|
|
516
|
+
if (schema === undefined) return base;
|
|
517
|
+
for (const [k, value] of Object.entries(schema)) {
|
|
1802
518
|
const key = parent ? `${parent}.${k}` : k;
|
|
1803
519
|
if (getSchemaType(value) === "object") if ("properties" in value) flattenSchema(value.properties, base, key);
|
|
1804
520
|
else base[key] = value;
|
|
@@ -1831,14 +547,14 @@ function kebabCaseToCamelCase(str) {
|
|
|
1831
547
|
//#endregion
|
|
1832
548
|
//#region src/cli/arguments/normalize.ts
|
|
1833
549
|
function normalizeCliOptions(cliOptions, positionals) {
|
|
1834
|
-
const
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
logger.error(`Invalid value for option ${error.path.join(", ")}. You can use \`rolldown -h\` to see the help.`);
|
|
550
|
+
const [data, errors] = validateCliOptions(cliOptions);
|
|
551
|
+
if (errors?.length) {
|
|
552
|
+
errors.forEach((error) => {
|
|
553
|
+
logger.error(`Invalid value for option ${error}. You can use \`rolldown -h\` to see the help.`);
|
|
1839
554
|
});
|
|
1840
555
|
process.exit(1);
|
|
1841
556
|
}
|
|
557
|
+
const options$1 = data ?? {};
|
|
1842
558
|
const result = {
|
|
1843
559
|
input: {},
|
|
1844
560
|
output: {},
|
|
@@ -1847,14 +563,14 @@ function normalizeCliOptions(cliOptions, positionals) {
|
|
|
1847
563
|
watch: options$1.watch ?? false
|
|
1848
564
|
};
|
|
1849
565
|
if (typeof options$1.config === "string") result.config = options$1.config;
|
|
566
|
+
const keysOfInput = getInputCliKeys();
|
|
567
|
+
const keysOfOutput = getOutputCliKeys();
|
|
1850
568
|
const reservedKeys = [
|
|
1851
569
|
"help",
|
|
1852
570
|
"version",
|
|
1853
571
|
"config",
|
|
1854
572
|
"watch"
|
|
1855
573
|
];
|
|
1856
|
-
const keysOfInput = inputCliOptionsSchema.keyof()._def.values;
|
|
1857
|
-
const keysOfOutput = outputCliOptionsSchema.keyof()._def.values;
|
|
1858
574
|
for (let [key, value] of Object.entries(options$1)) {
|
|
1859
575
|
const keys = key.split(".");
|
|
1860
576
|
const [primary] = keys;
|
|
@@ -1871,13 +587,14 @@ else if (!reservedKeys.includes(key)) {
|
|
|
1871
587
|
|
|
1872
588
|
//#endregion
|
|
1873
589
|
//#region src/cli/arguments/index.ts
|
|
1874
|
-
const
|
|
1875
|
-
const
|
|
590
|
+
const objectSchema = getJsonSchema();
|
|
591
|
+
const flattenedSchema = flattenSchema(objectSchema.properties);
|
|
592
|
+
const options = Object.fromEntries(Object.entries(flattenedSchema).map(([key, schema]) => {
|
|
1876
593
|
const config = Object.getOwnPropertyDescriptor(alias, key)?.value;
|
|
1877
|
-
const type = getSchemaType(schema
|
|
594
|
+
const type = getSchemaType(schema);
|
|
1878
595
|
const result = {
|
|
1879
596
|
type: type === "boolean" ? "boolean" : "string",
|
|
1880
|
-
description: schema
|
|
597
|
+
description: schema?.description ?? config?.description ?? "",
|
|
1881
598
|
hint: config?.hint
|
|
1882
599
|
};
|
|
1883
600
|
if (config && config?.abbreviation) result.short = config?.abbreviation;
|