@ai-sdk/provider-utils 3.0.5 → 3.0.7

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/index.mjs CHANGED
@@ -939,15 +939,1202 @@ var createStatusCodeErrorResponseHandler = () => async ({ response, url, request
939
939
 
940
940
  // src/zod-schema.ts
941
941
  import * as z4 from "zod/v4";
942
- import zodToJsonSchema from "zod-to-json-schema";
942
+
943
+ // src/zod-to-json-schema/get-relative-path.ts
944
+ var getRelativePath = (pathA, pathB) => {
945
+ let i = 0;
946
+ for (; i < pathA.length && i < pathB.length; i++) {
947
+ if (pathA[i] !== pathB[i])
948
+ break;
949
+ }
950
+ return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
951
+ };
952
+
953
+ // src/zod-to-json-schema/options.ts
954
+ var ignoreOverride = Symbol(
955
+ "Let zodToJsonSchema decide on which parser to use"
956
+ );
957
+ var defaultOptions = {
958
+ name: void 0,
959
+ $refStrategy: "root",
960
+ basePath: ["#"],
961
+ effectStrategy: "input",
962
+ pipeStrategy: "all",
963
+ dateStrategy: "format:date-time",
964
+ mapStrategy: "entries",
965
+ removeAdditionalStrategy: "passthrough",
966
+ allowedAdditionalProperties: true,
967
+ rejectedAdditionalProperties: false,
968
+ definitionPath: "definitions",
969
+ strictUnions: false,
970
+ definitions: {},
971
+ errorMessages: false,
972
+ patternStrategy: "escape",
973
+ applyRegexFlags: false,
974
+ emailStrategy: "format:email",
975
+ base64Strategy: "contentEncoding:base64",
976
+ nameStrategy: "ref"
977
+ };
978
+ var getDefaultOptions = (options) => typeof options === "string" ? {
979
+ ...defaultOptions,
980
+ name: options
981
+ } : {
982
+ ...defaultOptions,
983
+ ...options
984
+ };
985
+
986
+ // src/zod-to-json-schema/select-parser.ts
987
+ import { ZodFirstPartyTypeKind as ZodFirstPartyTypeKind3 } from "zod/v3";
988
+
989
+ // src/zod-to-json-schema/parsers/any.ts
990
+ function parseAnyDef() {
991
+ return {};
992
+ }
993
+
994
+ // src/zod-to-json-schema/parsers/array.ts
995
+ import { ZodFirstPartyTypeKind } from "zod/v3";
996
+ function parseArrayDef(def, refs) {
997
+ var _a, _b, _c;
998
+ const res = {
999
+ type: "array"
1000
+ };
1001
+ if (((_a = def.type) == null ? void 0 : _a._def) && ((_c = (_b = def.type) == null ? void 0 : _b._def) == null ? void 0 : _c.typeName) !== ZodFirstPartyTypeKind.ZodAny) {
1002
+ res.items = parseDef(def.type._def, {
1003
+ ...refs,
1004
+ currentPath: [...refs.currentPath, "items"]
1005
+ });
1006
+ }
1007
+ if (def.minLength) {
1008
+ res.minItems = def.minLength.value;
1009
+ }
1010
+ if (def.maxLength) {
1011
+ res.maxItems = def.maxLength.value;
1012
+ }
1013
+ if (def.exactLength) {
1014
+ res.minItems = def.exactLength.value;
1015
+ res.maxItems = def.exactLength.value;
1016
+ }
1017
+ return res;
1018
+ }
1019
+
1020
+ // src/zod-to-json-schema/parsers/bigint.ts
1021
+ function parseBigintDef(def) {
1022
+ const res = {
1023
+ type: "integer",
1024
+ format: "int64"
1025
+ };
1026
+ if (!def.checks)
1027
+ return res;
1028
+ for (const check of def.checks) {
1029
+ switch (check.kind) {
1030
+ case "min":
1031
+ if (check.inclusive) {
1032
+ res.minimum = check.value;
1033
+ } else {
1034
+ res.exclusiveMinimum = check.value;
1035
+ }
1036
+ break;
1037
+ case "max":
1038
+ if (check.inclusive) {
1039
+ res.maximum = check.value;
1040
+ } else {
1041
+ res.exclusiveMaximum = check.value;
1042
+ }
1043
+ break;
1044
+ case "multipleOf":
1045
+ res.multipleOf = check.value;
1046
+ break;
1047
+ }
1048
+ }
1049
+ return res;
1050
+ }
1051
+
1052
+ // src/zod-to-json-schema/parsers/boolean.ts
1053
+ function parseBooleanDef() {
1054
+ return { type: "boolean" };
1055
+ }
1056
+
1057
+ // src/zod-to-json-schema/parsers/branded.ts
1058
+ function parseBrandedDef(_def, refs) {
1059
+ return parseDef(_def.type._def, refs);
1060
+ }
1061
+
1062
+ // src/zod-to-json-schema/parsers/catch.ts
1063
+ var parseCatchDef = (def, refs) => {
1064
+ return parseDef(def.innerType._def, refs);
1065
+ };
1066
+
1067
+ // src/zod-to-json-schema/parsers/date.ts
1068
+ function parseDateDef(def, refs, overrideDateStrategy) {
1069
+ const strategy = overrideDateStrategy != null ? overrideDateStrategy : refs.dateStrategy;
1070
+ if (Array.isArray(strategy)) {
1071
+ return {
1072
+ anyOf: strategy.map((item, i) => parseDateDef(def, refs, item))
1073
+ };
1074
+ }
1075
+ switch (strategy) {
1076
+ case "string":
1077
+ case "format:date-time":
1078
+ return {
1079
+ type: "string",
1080
+ format: "date-time"
1081
+ };
1082
+ case "format:date":
1083
+ return {
1084
+ type: "string",
1085
+ format: "date"
1086
+ };
1087
+ case "integer":
1088
+ return integerDateParser(def);
1089
+ }
1090
+ }
1091
+ var integerDateParser = (def) => {
1092
+ const res = {
1093
+ type: "integer",
1094
+ format: "unix-time"
1095
+ };
1096
+ for (const check of def.checks) {
1097
+ switch (check.kind) {
1098
+ case "min":
1099
+ res.minimum = check.value;
1100
+ break;
1101
+ case "max":
1102
+ res.maximum = check.value;
1103
+ break;
1104
+ }
1105
+ }
1106
+ return res;
1107
+ };
1108
+
1109
+ // src/zod-to-json-schema/parsers/default.ts
1110
+ function parseDefaultDef(_def, refs) {
1111
+ return {
1112
+ ...parseDef(_def.innerType._def, refs),
1113
+ default: _def.defaultValue()
1114
+ };
1115
+ }
1116
+
1117
+ // src/zod-to-json-schema/parsers/effects.ts
1118
+ function parseEffectsDef(_def, refs) {
1119
+ return refs.effectStrategy === "input" ? parseDef(_def.schema._def, refs) : parseAnyDef();
1120
+ }
1121
+
1122
+ // src/zod-to-json-schema/parsers/enum.ts
1123
+ function parseEnumDef(def) {
1124
+ return {
1125
+ type: "string",
1126
+ enum: Array.from(def.values)
1127
+ };
1128
+ }
1129
+
1130
+ // src/zod-to-json-schema/parsers/intersection.ts
1131
+ var isJsonSchema7AllOfType = (type) => {
1132
+ if ("type" in type && type.type === "string")
1133
+ return false;
1134
+ return "allOf" in type;
1135
+ };
1136
+ function parseIntersectionDef(def, refs) {
1137
+ const allOf = [
1138
+ parseDef(def.left._def, {
1139
+ ...refs,
1140
+ currentPath: [...refs.currentPath, "allOf", "0"]
1141
+ }),
1142
+ parseDef(def.right._def, {
1143
+ ...refs,
1144
+ currentPath: [...refs.currentPath, "allOf", "1"]
1145
+ })
1146
+ ].filter((x) => !!x);
1147
+ const mergedAllOf = [];
1148
+ allOf.forEach((schema) => {
1149
+ if (isJsonSchema7AllOfType(schema)) {
1150
+ mergedAllOf.push(...schema.allOf);
1151
+ } else {
1152
+ let nestedSchema = schema;
1153
+ if ("additionalProperties" in schema && schema.additionalProperties === false) {
1154
+ const { additionalProperties, ...rest } = schema;
1155
+ nestedSchema = rest;
1156
+ }
1157
+ mergedAllOf.push(nestedSchema);
1158
+ }
1159
+ });
1160
+ return mergedAllOf.length ? { allOf: mergedAllOf } : void 0;
1161
+ }
1162
+
1163
+ // src/zod-to-json-schema/parsers/literal.ts
1164
+ function parseLiteralDef(def) {
1165
+ const parsedType = typeof def.value;
1166
+ if (parsedType !== "bigint" && parsedType !== "number" && parsedType !== "boolean" && parsedType !== "string") {
1167
+ return {
1168
+ type: Array.isArray(def.value) ? "array" : "object"
1169
+ };
1170
+ }
1171
+ return {
1172
+ type: parsedType === "bigint" ? "integer" : parsedType,
1173
+ const: def.value
1174
+ };
1175
+ }
1176
+
1177
+ // src/zod-to-json-schema/parsers/record.ts
1178
+ import {
1179
+ ZodFirstPartyTypeKind as ZodFirstPartyTypeKind2
1180
+ } from "zod/v3";
1181
+
1182
+ // src/zod-to-json-schema/parsers/string.ts
1183
+ var emojiRegex = void 0;
1184
+ var zodPatterns = {
1185
+ /**
1186
+ * `c` was changed to `[cC]` to replicate /i flag
1187
+ */
1188
+ cuid: /^[cC][^\s-]{8,}$/,
1189
+ cuid2: /^[0-9a-z]+$/,
1190
+ ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
1191
+ /**
1192
+ * `a-z` was added to replicate /i flag
1193
+ */
1194
+ email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
1195
+ /**
1196
+ * Constructed a valid Unicode RegExp
1197
+ *
1198
+ * Lazily instantiate since this type of regex isn't supported
1199
+ * in all envs (e.g. React Native).
1200
+ *
1201
+ * See:
1202
+ * https://github.com/colinhacks/zod/issues/2433
1203
+ * Fix in Zod:
1204
+ * https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
1205
+ */
1206
+ emoji: () => {
1207
+ if (emojiRegex === void 0) {
1208
+ emojiRegex = RegExp(
1209
+ "^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",
1210
+ "u"
1211
+ );
1212
+ }
1213
+ return emojiRegex;
1214
+ },
1215
+ /**
1216
+ * Unused
1217
+ */
1218
+ 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}$/,
1219
+ /**
1220
+ * Unused
1221
+ */
1222
+ 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])$/,
1223
+ ipv4Cidr: /^(?:(?: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])\/(3[0-2]|[12]?[0-9])$/,
1224
+ /**
1225
+ * Unused
1226
+ */
1227
+ 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})))$/,
1228
+ ipv6Cidr: /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,
1229
+ base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
1230
+ base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
1231
+ nanoid: /^[a-zA-Z0-9_-]{21}$/,
1232
+ jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
1233
+ };
1234
+ function parseStringDef(def, refs) {
1235
+ const res = {
1236
+ type: "string"
1237
+ };
1238
+ if (def.checks) {
1239
+ for (const check of def.checks) {
1240
+ switch (check.kind) {
1241
+ case "min":
1242
+ res.minLength = typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value;
1243
+ break;
1244
+ case "max":
1245
+ res.maxLength = typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value;
1246
+ break;
1247
+ case "email":
1248
+ switch (refs.emailStrategy) {
1249
+ case "format:email":
1250
+ addFormat(res, "email", check.message, refs);
1251
+ break;
1252
+ case "format:idn-email":
1253
+ addFormat(res, "idn-email", check.message, refs);
1254
+ break;
1255
+ case "pattern:zod":
1256
+ addPattern(res, zodPatterns.email, check.message, refs);
1257
+ break;
1258
+ }
1259
+ break;
1260
+ case "url":
1261
+ addFormat(res, "uri", check.message, refs);
1262
+ break;
1263
+ case "uuid":
1264
+ addFormat(res, "uuid", check.message, refs);
1265
+ break;
1266
+ case "regex":
1267
+ addPattern(res, check.regex, check.message, refs);
1268
+ break;
1269
+ case "cuid":
1270
+ addPattern(res, zodPatterns.cuid, check.message, refs);
1271
+ break;
1272
+ case "cuid2":
1273
+ addPattern(res, zodPatterns.cuid2, check.message, refs);
1274
+ break;
1275
+ case "startsWith":
1276
+ addPattern(
1277
+ res,
1278
+ RegExp(`^${escapeLiteralCheckValue(check.value, refs)}`),
1279
+ check.message,
1280
+ refs
1281
+ );
1282
+ break;
1283
+ case "endsWith":
1284
+ addPattern(
1285
+ res,
1286
+ RegExp(`${escapeLiteralCheckValue(check.value, refs)}$`),
1287
+ check.message,
1288
+ refs
1289
+ );
1290
+ break;
1291
+ case "datetime":
1292
+ addFormat(res, "date-time", check.message, refs);
1293
+ break;
1294
+ case "date":
1295
+ addFormat(res, "date", check.message, refs);
1296
+ break;
1297
+ case "time":
1298
+ addFormat(res, "time", check.message, refs);
1299
+ break;
1300
+ case "duration":
1301
+ addFormat(res, "duration", check.message, refs);
1302
+ break;
1303
+ case "length":
1304
+ res.minLength = typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value;
1305
+ res.maxLength = typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value;
1306
+ break;
1307
+ case "includes": {
1308
+ addPattern(
1309
+ res,
1310
+ RegExp(escapeLiteralCheckValue(check.value, refs)),
1311
+ check.message,
1312
+ refs
1313
+ );
1314
+ break;
1315
+ }
1316
+ case "ip": {
1317
+ if (check.version !== "v6") {
1318
+ addFormat(res, "ipv4", check.message, refs);
1319
+ }
1320
+ if (check.version !== "v4") {
1321
+ addFormat(res, "ipv6", check.message, refs);
1322
+ }
1323
+ break;
1324
+ }
1325
+ case "base64url":
1326
+ addPattern(res, zodPatterns.base64url, check.message, refs);
1327
+ break;
1328
+ case "jwt":
1329
+ addPattern(res, zodPatterns.jwt, check.message, refs);
1330
+ break;
1331
+ case "cidr": {
1332
+ if (check.version !== "v6") {
1333
+ addPattern(res, zodPatterns.ipv4Cidr, check.message, refs);
1334
+ }
1335
+ if (check.version !== "v4") {
1336
+ addPattern(res, zodPatterns.ipv6Cidr, check.message, refs);
1337
+ }
1338
+ break;
1339
+ }
1340
+ case "emoji":
1341
+ addPattern(res, zodPatterns.emoji(), check.message, refs);
1342
+ break;
1343
+ case "ulid": {
1344
+ addPattern(res, zodPatterns.ulid, check.message, refs);
1345
+ break;
1346
+ }
1347
+ case "base64": {
1348
+ switch (refs.base64Strategy) {
1349
+ case "format:binary": {
1350
+ addFormat(res, "binary", check.message, refs);
1351
+ break;
1352
+ }
1353
+ case "contentEncoding:base64": {
1354
+ res.contentEncoding = "base64";
1355
+ break;
1356
+ }
1357
+ case "pattern:zod": {
1358
+ addPattern(res, zodPatterns.base64, check.message, refs);
1359
+ break;
1360
+ }
1361
+ }
1362
+ break;
1363
+ }
1364
+ case "nanoid": {
1365
+ addPattern(res, zodPatterns.nanoid, check.message, refs);
1366
+ }
1367
+ case "toLowerCase":
1368
+ case "toUpperCase":
1369
+ case "trim":
1370
+ break;
1371
+ default:
1372
+ /* @__PURE__ */ ((_) => {
1373
+ })(check);
1374
+ }
1375
+ }
1376
+ }
1377
+ return res;
1378
+ }
1379
+ function escapeLiteralCheckValue(literal, refs) {
1380
+ return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(literal) : literal;
1381
+ }
1382
+ var ALPHA_NUMERIC = new Set(
1383
+ "ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789"
1384
+ );
1385
+ function escapeNonAlphaNumeric(source) {
1386
+ let result = "";
1387
+ for (let i = 0; i < source.length; i++) {
1388
+ if (!ALPHA_NUMERIC.has(source[i])) {
1389
+ result += "\\";
1390
+ }
1391
+ result += source[i];
1392
+ }
1393
+ return result;
1394
+ }
1395
+ function addFormat(schema, value, message, refs) {
1396
+ var _a;
1397
+ if (schema.format || ((_a = schema.anyOf) == null ? void 0 : _a.some((x) => x.format))) {
1398
+ if (!schema.anyOf) {
1399
+ schema.anyOf = [];
1400
+ }
1401
+ if (schema.format) {
1402
+ schema.anyOf.push({
1403
+ format: schema.format
1404
+ });
1405
+ delete schema.format;
1406
+ }
1407
+ schema.anyOf.push({
1408
+ format: value,
1409
+ ...message && refs.errorMessages && { errorMessage: { format: message } }
1410
+ });
1411
+ } else {
1412
+ schema.format = value;
1413
+ }
1414
+ }
1415
+ function addPattern(schema, regex, message, refs) {
1416
+ var _a;
1417
+ if (schema.pattern || ((_a = schema.allOf) == null ? void 0 : _a.some((x) => x.pattern))) {
1418
+ if (!schema.allOf) {
1419
+ schema.allOf = [];
1420
+ }
1421
+ if (schema.pattern) {
1422
+ schema.allOf.push({
1423
+ pattern: schema.pattern
1424
+ });
1425
+ delete schema.pattern;
1426
+ }
1427
+ schema.allOf.push({
1428
+ pattern: stringifyRegExpWithFlags(regex, refs),
1429
+ ...message && refs.errorMessages && { errorMessage: { pattern: message } }
1430
+ });
1431
+ } else {
1432
+ schema.pattern = stringifyRegExpWithFlags(regex, refs);
1433
+ }
1434
+ }
1435
+ function stringifyRegExpWithFlags(regex, refs) {
1436
+ var _a;
1437
+ if (!refs.applyRegexFlags || !regex.flags) {
1438
+ return regex.source;
1439
+ }
1440
+ const flags = {
1441
+ i: regex.flags.includes("i"),
1442
+ // Case-insensitive
1443
+ m: regex.flags.includes("m"),
1444
+ // `^` and `$` matches adjacent to newline characters
1445
+ s: regex.flags.includes("s")
1446
+ // `.` matches newlines
1447
+ };
1448
+ const source = flags.i ? regex.source.toLowerCase() : regex.source;
1449
+ let pattern = "";
1450
+ let isEscaped = false;
1451
+ let inCharGroup = false;
1452
+ let inCharRange = false;
1453
+ for (let i = 0; i < source.length; i++) {
1454
+ if (isEscaped) {
1455
+ pattern += source[i];
1456
+ isEscaped = false;
1457
+ continue;
1458
+ }
1459
+ if (flags.i) {
1460
+ if (inCharGroup) {
1461
+ if (source[i].match(/[a-z]/)) {
1462
+ if (inCharRange) {
1463
+ pattern += source[i];
1464
+ pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
1465
+ inCharRange = false;
1466
+ } else if (source[i + 1] === "-" && ((_a = source[i + 2]) == null ? void 0 : _a.match(/[a-z]/))) {
1467
+ pattern += source[i];
1468
+ inCharRange = true;
1469
+ } else {
1470
+ pattern += `${source[i]}${source[i].toUpperCase()}`;
1471
+ }
1472
+ continue;
1473
+ }
1474
+ } else if (source[i].match(/[a-z]/)) {
1475
+ pattern += `[${source[i]}${source[i].toUpperCase()}]`;
1476
+ continue;
1477
+ }
1478
+ }
1479
+ if (flags.m) {
1480
+ if (source[i] === "^") {
1481
+ pattern += `(^|(?<=[\r
1482
+ ]))`;
1483
+ continue;
1484
+ } else if (source[i] === "$") {
1485
+ pattern += `($|(?=[\r
1486
+ ]))`;
1487
+ continue;
1488
+ }
1489
+ }
1490
+ if (flags.s && source[i] === ".") {
1491
+ pattern += inCharGroup ? `${source[i]}\r
1492
+ ` : `[${source[i]}\r
1493
+ ]`;
1494
+ continue;
1495
+ }
1496
+ pattern += source[i];
1497
+ if (source[i] === "\\") {
1498
+ isEscaped = true;
1499
+ } else if (inCharGroup && source[i] === "]") {
1500
+ inCharGroup = false;
1501
+ } else if (!inCharGroup && source[i] === "[") {
1502
+ inCharGroup = true;
1503
+ }
1504
+ }
1505
+ try {
1506
+ new RegExp(pattern);
1507
+ } catch (e) {
1508
+ console.warn(
1509
+ `Could not convert regex pattern at ${refs.currentPath.join(
1510
+ "/"
1511
+ )} to a flag-independent form! Falling back to the flag-ignorant source`
1512
+ );
1513
+ return regex.source;
1514
+ }
1515
+ return pattern;
1516
+ }
1517
+
1518
+ // src/zod-to-json-schema/parsers/record.ts
1519
+ function parseRecordDef(def, refs) {
1520
+ var _a, _b, _c, _d, _e, _f;
1521
+ const schema = {
1522
+ type: "object",
1523
+ additionalProperties: (_a = parseDef(def.valueType._def, {
1524
+ ...refs,
1525
+ currentPath: [...refs.currentPath, "additionalProperties"]
1526
+ })) != null ? _a : refs.allowedAdditionalProperties
1527
+ };
1528
+ if (((_b = def.keyType) == null ? void 0 : _b._def.typeName) === ZodFirstPartyTypeKind2.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
1529
+ const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
1530
+ return {
1531
+ ...schema,
1532
+ propertyNames: keyType
1533
+ };
1534
+ } else if (((_d = def.keyType) == null ? void 0 : _d._def.typeName) === ZodFirstPartyTypeKind2.ZodEnum) {
1535
+ return {
1536
+ ...schema,
1537
+ propertyNames: {
1538
+ enum: def.keyType._def.values
1539
+ }
1540
+ };
1541
+ } else if (((_e = def.keyType) == null ? void 0 : _e._def.typeName) === ZodFirstPartyTypeKind2.ZodBranded && def.keyType._def.type._def.typeName === ZodFirstPartyTypeKind2.ZodString && ((_f = def.keyType._def.type._def.checks) == null ? void 0 : _f.length)) {
1542
+ const { type, ...keyType } = parseBrandedDef(
1543
+ def.keyType._def,
1544
+ refs
1545
+ );
1546
+ return {
1547
+ ...schema,
1548
+ propertyNames: keyType
1549
+ };
1550
+ }
1551
+ return schema;
1552
+ }
1553
+
1554
+ // src/zod-to-json-schema/parsers/map.ts
1555
+ function parseMapDef(def, refs) {
1556
+ if (refs.mapStrategy === "record") {
1557
+ return parseRecordDef(def, refs);
1558
+ }
1559
+ const keys = parseDef(def.keyType._def, {
1560
+ ...refs,
1561
+ currentPath: [...refs.currentPath, "items", "items", "0"]
1562
+ }) || parseAnyDef();
1563
+ const values = parseDef(def.valueType._def, {
1564
+ ...refs,
1565
+ currentPath: [...refs.currentPath, "items", "items", "1"]
1566
+ }) || parseAnyDef();
1567
+ return {
1568
+ type: "array",
1569
+ maxItems: 125,
1570
+ items: {
1571
+ type: "array",
1572
+ items: [keys, values],
1573
+ minItems: 2,
1574
+ maxItems: 2
1575
+ }
1576
+ };
1577
+ }
1578
+
1579
+ // src/zod-to-json-schema/parsers/native-enum.ts
1580
+ function parseNativeEnumDef(def) {
1581
+ const object = def.values;
1582
+ const actualKeys = Object.keys(def.values).filter((key) => {
1583
+ return typeof object[object[key]] !== "number";
1584
+ });
1585
+ const actualValues = actualKeys.map((key) => object[key]);
1586
+ const parsedTypes = Array.from(
1587
+ new Set(actualValues.map((values) => typeof values))
1588
+ );
1589
+ return {
1590
+ type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
1591
+ enum: actualValues
1592
+ };
1593
+ }
1594
+
1595
+ // src/zod-to-json-schema/parsers/never.ts
1596
+ function parseNeverDef() {
1597
+ return { not: parseAnyDef() };
1598
+ }
1599
+
1600
+ // src/zod-to-json-schema/parsers/null.ts
1601
+ function parseNullDef() {
1602
+ return {
1603
+ type: "null"
1604
+ };
1605
+ }
1606
+
1607
+ // src/zod-to-json-schema/parsers/union.ts
1608
+ var primitiveMappings = {
1609
+ ZodString: "string",
1610
+ ZodNumber: "number",
1611
+ ZodBigInt: "integer",
1612
+ ZodBoolean: "boolean",
1613
+ ZodNull: "null"
1614
+ };
1615
+ function parseUnionDef(def, refs) {
1616
+ const options = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
1617
+ if (options.every(
1618
+ (x) => x._def.typeName in primitiveMappings && (!x._def.checks || !x._def.checks.length)
1619
+ )) {
1620
+ const types = options.reduce((types2, x) => {
1621
+ const type = primitiveMappings[x._def.typeName];
1622
+ return type && !types2.includes(type) ? [...types2, type] : types2;
1623
+ }, []);
1624
+ return {
1625
+ type: types.length > 1 ? types : types[0]
1626
+ };
1627
+ } else if (options.every((x) => x._def.typeName === "ZodLiteral" && !x.description)) {
1628
+ const types = options.reduce(
1629
+ (acc, x) => {
1630
+ const type = typeof x._def.value;
1631
+ switch (type) {
1632
+ case "string":
1633
+ case "number":
1634
+ case "boolean":
1635
+ return [...acc, type];
1636
+ case "bigint":
1637
+ return [...acc, "integer"];
1638
+ case "object":
1639
+ if (x._def.value === null)
1640
+ return [...acc, "null"];
1641
+ case "symbol":
1642
+ case "undefined":
1643
+ case "function":
1644
+ default:
1645
+ return acc;
1646
+ }
1647
+ },
1648
+ []
1649
+ );
1650
+ if (types.length === options.length) {
1651
+ const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);
1652
+ return {
1653
+ type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
1654
+ enum: options.reduce(
1655
+ (acc, x) => {
1656
+ return acc.includes(x._def.value) ? acc : [...acc, x._def.value];
1657
+ },
1658
+ []
1659
+ )
1660
+ };
1661
+ }
1662
+ } else if (options.every((x) => x._def.typeName === "ZodEnum")) {
1663
+ return {
1664
+ type: "string",
1665
+ enum: options.reduce(
1666
+ (acc, x) => [
1667
+ ...acc,
1668
+ ...x._def.values.filter((x2) => !acc.includes(x2))
1669
+ ],
1670
+ []
1671
+ )
1672
+ };
1673
+ }
1674
+ return asAnyOf(def, refs);
1675
+ }
1676
+ var asAnyOf = (def, refs) => {
1677
+ const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map(
1678
+ (x, i) => parseDef(x._def, {
1679
+ ...refs,
1680
+ currentPath: [...refs.currentPath, "anyOf", `${i}`]
1681
+ })
1682
+ ).filter(
1683
+ (x) => !!x && (!refs.strictUnions || typeof x === "object" && Object.keys(x).length > 0)
1684
+ );
1685
+ return anyOf.length ? { anyOf } : void 0;
1686
+ };
1687
+
1688
+ // src/zod-to-json-schema/parsers/nullable.ts
1689
+ function parseNullableDef(def, refs) {
1690
+ if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(
1691
+ def.innerType._def.typeName
1692
+ ) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
1693
+ return {
1694
+ type: [
1695
+ primitiveMappings[def.innerType._def.typeName],
1696
+ "null"
1697
+ ]
1698
+ };
1699
+ }
1700
+ const base = parseDef(def.innerType._def, {
1701
+ ...refs,
1702
+ currentPath: [...refs.currentPath, "anyOf", "0"]
1703
+ });
1704
+ return base && { anyOf: [base, { type: "null" }] };
1705
+ }
1706
+
1707
+ // src/zod-to-json-schema/parsers/number.ts
1708
+ function parseNumberDef(def) {
1709
+ const res = {
1710
+ type: "number"
1711
+ };
1712
+ if (!def.checks)
1713
+ return res;
1714
+ for (const check of def.checks) {
1715
+ switch (check.kind) {
1716
+ case "int":
1717
+ res.type = "integer";
1718
+ break;
1719
+ case "min":
1720
+ if (check.inclusive) {
1721
+ res.minimum = check.value;
1722
+ } else {
1723
+ res.exclusiveMinimum = check.value;
1724
+ }
1725
+ break;
1726
+ case "max":
1727
+ if (check.inclusive) {
1728
+ res.maximum = check.value;
1729
+ } else {
1730
+ res.exclusiveMaximum = check.value;
1731
+ }
1732
+ break;
1733
+ case "multipleOf":
1734
+ res.multipleOf = check.value;
1735
+ break;
1736
+ }
1737
+ }
1738
+ return res;
1739
+ }
1740
+
1741
+ // src/zod-to-json-schema/parsers/object.ts
1742
+ function parseObjectDef(def, refs) {
1743
+ const result = {
1744
+ type: "object",
1745
+ properties: {}
1746
+ };
1747
+ const required = [];
1748
+ const shape = def.shape();
1749
+ for (const propName in shape) {
1750
+ let propDef = shape[propName];
1751
+ if (propDef === void 0 || propDef._def === void 0) {
1752
+ continue;
1753
+ }
1754
+ const propOptional = safeIsOptional(propDef);
1755
+ const parsedDef = parseDef(propDef._def, {
1756
+ ...refs,
1757
+ currentPath: [...refs.currentPath, "properties", propName],
1758
+ propertyPath: [...refs.currentPath, "properties", propName]
1759
+ });
1760
+ if (parsedDef === void 0) {
1761
+ continue;
1762
+ }
1763
+ result.properties[propName] = parsedDef;
1764
+ if (!propOptional) {
1765
+ required.push(propName);
1766
+ }
1767
+ }
1768
+ if (required.length) {
1769
+ result.required = required;
1770
+ }
1771
+ const additionalProperties = decideAdditionalProperties(def, refs);
1772
+ if (additionalProperties !== void 0) {
1773
+ result.additionalProperties = additionalProperties;
1774
+ }
1775
+ return result;
1776
+ }
1777
+ function decideAdditionalProperties(def, refs) {
1778
+ if (def.catchall._def.typeName !== "ZodNever") {
1779
+ return parseDef(def.catchall._def, {
1780
+ ...refs,
1781
+ currentPath: [...refs.currentPath, "additionalProperties"]
1782
+ });
1783
+ }
1784
+ switch (def.unknownKeys) {
1785
+ case "passthrough":
1786
+ return refs.allowedAdditionalProperties;
1787
+ case "strict":
1788
+ return refs.rejectedAdditionalProperties;
1789
+ case "strip":
1790
+ return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
1791
+ }
1792
+ }
1793
+ function safeIsOptional(schema) {
1794
+ try {
1795
+ return schema.isOptional();
1796
+ } catch (e) {
1797
+ return true;
1798
+ }
1799
+ }
1800
+
1801
+ // src/zod-to-json-schema/parsers/optional.ts
1802
+ var parseOptionalDef = (def, refs) => {
1803
+ var _a;
1804
+ if (refs.currentPath.toString() === ((_a = refs.propertyPath) == null ? void 0 : _a.toString())) {
1805
+ return parseDef(def.innerType._def, refs);
1806
+ }
1807
+ const innerSchema = parseDef(def.innerType._def, {
1808
+ ...refs,
1809
+ currentPath: [...refs.currentPath, "anyOf", "1"]
1810
+ });
1811
+ return innerSchema ? { anyOf: [{ not: parseAnyDef() }, innerSchema] } : parseAnyDef();
1812
+ };
1813
+
1814
+ // src/zod-to-json-schema/parsers/pipeline.ts
1815
+ var parsePipelineDef = (def, refs) => {
1816
+ if (refs.pipeStrategy === "input") {
1817
+ return parseDef(def.in._def, refs);
1818
+ } else if (refs.pipeStrategy === "output") {
1819
+ return parseDef(def.out._def, refs);
1820
+ }
1821
+ const a = parseDef(def.in._def, {
1822
+ ...refs,
1823
+ currentPath: [...refs.currentPath, "allOf", "0"]
1824
+ });
1825
+ const b = parseDef(def.out._def, {
1826
+ ...refs,
1827
+ currentPath: [...refs.currentPath, "allOf", a ? "1" : "0"]
1828
+ });
1829
+ return {
1830
+ allOf: [a, b].filter((x) => x !== void 0)
1831
+ };
1832
+ };
1833
+
1834
+ // src/zod-to-json-schema/parsers/promise.ts
1835
+ function parsePromiseDef(def, refs) {
1836
+ return parseDef(def.type._def, refs);
1837
+ }
1838
+
1839
+ // src/zod-to-json-schema/parsers/set.ts
1840
+ function parseSetDef(def, refs) {
1841
+ const items = parseDef(def.valueType._def, {
1842
+ ...refs,
1843
+ currentPath: [...refs.currentPath, "items"]
1844
+ });
1845
+ const schema = {
1846
+ type: "array",
1847
+ uniqueItems: true,
1848
+ items
1849
+ };
1850
+ if (def.minSize) {
1851
+ schema.minItems = def.minSize.value;
1852
+ }
1853
+ if (def.maxSize) {
1854
+ schema.maxItems = def.maxSize.value;
1855
+ }
1856
+ return schema;
1857
+ }
1858
+
1859
+ // src/zod-to-json-schema/parsers/tuple.ts
1860
+ function parseTupleDef(def, refs) {
1861
+ if (def.rest) {
1862
+ return {
1863
+ type: "array",
1864
+ minItems: def.items.length,
1865
+ items: def.items.map(
1866
+ (x, i) => parseDef(x._def, {
1867
+ ...refs,
1868
+ currentPath: [...refs.currentPath, "items", `${i}`]
1869
+ })
1870
+ ).reduce(
1871
+ (acc, x) => x === void 0 ? acc : [...acc, x],
1872
+ []
1873
+ ),
1874
+ additionalItems: parseDef(def.rest._def, {
1875
+ ...refs,
1876
+ currentPath: [...refs.currentPath, "additionalItems"]
1877
+ })
1878
+ };
1879
+ } else {
1880
+ return {
1881
+ type: "array",
1882
+ minItems: def.items.length,
1883
+ maxItems: def.items.length,
1884
+ items: def.items.map(
1885
+ (x, i) => parseDef(x._def, {
1886
+ ...refs,
1887
+ currentPath: [...refs.currentPath, "items", `${i}`]
1888
+ })
1889
+ ).reduce(
1890
+ (acc, x) => x === void 0 ? acc : [...acc, x],
1891
+ []
1892
+ )
1893
+ };
1894
+ }
1895
+ }
1896
+
1897
+ // src/zod-to-json-schema/parsers/undefined.ts
1898
+ function parseUndefinedDef() {
1899
+ return {
1900
+ not: parseAnyDef()
1901
+ };
1902
+ }
1903
+
1904
+ // src/zod-to-json-schema/parsers/unknown.ts
1905
+ function parseUnknownDef() {
1906
+ return parseAnyDef();
1907
+ }
1908
+
1909
+ // src/zod-to-json-schema/parsers/readonly.ts
1910
+ var parseReadonlyDef = (def, refs) => {
1911
+ return parseDef(def.innerType._def, refs);
1912
+ };
1913
+
1914
+ // src/zod-to-json-schema/select-parser.ts
1915
+ var selectParser = (def, typeName, refs) => {
1916
+ switch (typeName) {
1917
+ case ZodFirstPartyTypeKind3.ZodString:
1918
+ return parseStringDef(def, refs);
1919
+ case ZodFirstPartyTypeKind3.ZodNumber:
1920
+ return parseNumberDef(def);
1921
+ case ZodFirstPartyTypeKind3.ZodObject:
1922
+ return parseObjectDef(def, refs);
1923
+ case ZodFirstPartyTypeKind3.ZodBigInt:
1924
+ return parseBigintDef(def);
1925
+ case ZodFirstPartyTypeKind3.ZodBoolean:
1926
+ return parseBooleanDef();
1927
+ case ZodFirstPartyTypeKind3.ZodDate:
1928
+ return parseDateDef(def, refs);
1929
+ case ZodFirstPartyTypeKind3.ZodUndefined:
1930
+ return parseUndefinedDef();
1931
+ case ZodFirstPartyTypeKind3.ZodNull:
1932
+ return parseNullDef();
1933
+ case ZodFirstPartyTypeKind3.ZodArray:
1934
+ return parseArrayDef(def, refs);
1935
+ case ZodFirstPartyTypeKind3.ZodUnion:
1936
+ case ZodFirstPartyTypeKind3.ZodDiscriminatedUnion:
1937
+ return parseUnionDef(def, refs);
1938
+ case ZodFirstPartyTypeKind3.ZodIntersection:
1939
+ return parseIntersectionDef(def, refs);
1940
+ case ZodFirstPartyTypeKind3.ZodTuple:
1941
+ return parseTupleDef(def, refs);
1942
+ case ZodFirstPartyTypeKind3.ZodRecord:
1943
+ return parseRecordDef(def, refs);
1944
+ case ZodFirstPartyTypeKind3.ZodLiteral:
1945
+ return parseLiteralDef(def);
1946
+ case ZodFirstPartyTypeKind3.ZodEnum:
1947
+ return parseEnumDef(def);
1948
+ case ZodFirstPartyTypeKind3.ZodNativeEnum:
1949
+ return parseNativeEnumDef(def);
1950
+ case ZodFirstPartyTypeKind3.ZodNullable:
1951
+ return parseNullableDef(def, refs);
1952
+ case ZodFirstPartyTypeKind3.ZodOptional:
1953
+ return parseOptionalDef(def, refs);
1954
+ case ZodFirstPartyTypeKind3.ZodMap:
1955
+ return parseMapDef(def, refs);
1956
+ case ZodFirstPartyTypeKind3.ZodSet:
1957
+ return parseSetDef(def, refs);
1958
+ case ZodFirstPartyTypeKind3.ZodLazy:
1959
+ return () => def.getter()._def;
1960
+ case ZodFirstPartyTypeKind3.ZodPromise:
1961
+ return parsePromiseDef(def, refs);
1962
+ case ZodFirstPartyTypeKind3.ZodNaN:
1963
+ case ZodFirstPartyTypeKind3.ZodNever:
1964
+ return parseNeverDef();
1965
+ case ZodFirstPartyTypeKind3.ZodEffects:
1966
+ return parseEffectsDef(def, refs);
1967
+ case ZodFirstPartyTypeKind3.ZodAny:
1968
+ return parseAnyDef();
1969
+ case ZodFirstPartyTypeKind3.ZodUnknown:
1970
+ return parseUnknownDef();
1971
+ case ZodFirstPartyTypeKind3.ZodDefault:
1972
+ return parseDefaultDef(def, refs);
1973
+ case ZodFirstPartyTypeKind3.ZodBranded:
1974
+ return parseBrandedDef(def, refs);
1975
+ case ZodFirstPartyTypeKind3.ZodReadonly:
1976
+ return parseReadonlyDef(def, refs);
1977
+ case ZodFirstPartyTypeKind3.ZodCatch:
1978
+ return parseCatchDef(def, refs);
1979
+ case ZodFirstPartyTypeKind3.ZodPipeline:
1980
+ return parsePipelineDef(def, refs);
1981
+ case ZodFirstPartyTypeKind3.ZodFunction:
1982
+ case ZodFirstPartyTypeKind3.ZodVoid:
1983
+ case ZodFirstPartyTypeKind3.ZodSymbol:
1984
+ return void 0;
1985
+ default:
1986
+ return /* @__PURE__ */ ((_) => void 0)(typeName);
1987
+ }
1988
+ };
1989
+
1990
+ // src/zod-to-json-schema/parse-def.ts
1991
+ function parseDef(def, refs, forceResolution = false) {
1992
+ var _a;
1993
+ const seenItem = refs.seen.get(def);
1994
+ if (refs.override) {
1995
+ const overrideResult = (_a = refs.override) == null ? void 0 : _a.call(
1996
+ refs,
1997
+ def,
1998
+ refs,
1999
+ seenItem,
2000
+ forceResolution
2001
+ );
2002
+ if (overrideResult !== ignoreOverride) {
2003
+ return overrideResult;
2004
+ }
2005
+ }
2006
+ if (seenItem && !forceResolution) {
2007
+ const seenSchema = get$ref(seenItem, refs);
2008
+ if (seenSchema !== void 0) {
2009
+ return seenSchema;
2010
+ }
2011
+ }
2012
+ const newItem = { def, path: refs.currentPath, jsonSchema: void 0 };
2013
+ refs.seen.set(def, newItem);
2014
+ const jsonSchemaOrGetter = selectParser(def, def.typeName, refs);
2015
+ const jsonSchema2 = typeof jsonSchemaOrGetter === "function" ? parseDef(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
2016
+ if (jsonSchema2) {
2017
+ addMeta(def, refs, jsonSchema2);
2018
+ }
2019
+ if (refs.postProcess) {
2020
+ const postProcessResult = refs.postProcess(jsonSchema2, def, refs);
2021
+ newItem.jsonSchema = jsonSchema2;
2022
+ return postProcessResult;
2023
+ }
2024
+ newItem.jsonSchema = jsonSchema2;
2025
+ return jsonSchema2;
2026
+ }
2027
+ var get$ref = (item, refs) => {
2028
+ switch (refs.$refStrategy) {
2029
+ case "root":
2030
+ return { $ref: item.path.join("/") };
2031
+ case "relative":
2032
+ return { $ref: getRelativePath(refs.currentPath, item.path) };
2033
+ case "none":
2034
+ case "seen": {
2035
+ if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
2036
+ console.warn(
2037
+ `Recursive reference detected at ${refs.currentPath.join(
2038
+ "/"
2039
+ )}! Defaulting to any`
2040
+ );
2041
+ return parseAnyDef();
2042
+ }
2043
+ return refs.$refStrategy === "seen" ? parseAnyDef() : void 0;
2044
+ }
2045
+ }
2046
+ };
2047
+ var addMeta = (def, refs, jsonSchema2) => {
2048
+ if (def.description) {
2049
+ jsonSchema2.description = def.description;
2050
+ }
2051
+ return jsonSchema2;
2052
+ };
2053
+
2054
+ // src/zod-to-json-schema/refs.ts
2055
+ var getRefs = (options) => {
2056
+ const _options = getDefaultOptions(options);
2057
+ const currentPath = _options.name !== void 0 ? [..._options.basePath, _options.definitionPath, _options.name] : _options.basePath;
2058
+ return {
2059
+ ..._options,
2060
+ currentPath,
2061
+ propertyPath: void 0,
2062
+ seen: new Map(
2063
+ Object.entries(_options.definitions).map(([name, def]) => [
2064
+ def._def,
2065
+ {
2066
+ def: def._def,
2067
+ path: [..._options.basePath, _options.definitionPath, name],
2068
+ // Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
2069
+ jsonSchema: void 0
2070
+ }
2071
+ ])
2072
+ )
2073
+ };
2074
+ };
2075
+
2076
+ // src/zod-to-json-schema/zod-to-json-schema.ts
2077
+ var zodToJsonSchema = (schema, options) => {
2078
+ var _a;
2079
+ const refs = getRefs(options);
2080
+ let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce(
2081
+ (acc, [name2, schema2]) => {
2082
+ var _a2;
2083
+ return {
2084
+ ...acc,
2085
+ [name2]: (_a2 = parseDef(
2086
+ schema2._def,
2087
+ {
2088
+ ...refs,
2089
+ currentPath: [...refs.basePath, refs.definitionPath, name2]
2090
+ },
2091
+ true
2092
+ )) != null ? _a2 : parseAnyDef()
2093
+ };
2094
+ },
2095
+ {}
2096
+ ) : void 0;
2097
+ const name = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
2098
+ const main = (_a = parseDef(
2099
+ schema._def,
2100
+ name === void 0 ? refs : {
2101
+ ...refs,
2102
+ currentPath: [...refs.basePath, refs.definitionPath, name]
2103
+ },
2104
+ false
2105
+ )) != null ? _a : parseAnyDef();
2106
+ const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
2107
+ if (title !== void 0) {
2108
+ main.title = title;
2109
+ }
2110
+ const combined = name === void 0 ? definitions ? {
2111
+ ...main,
2112
+ [refs.definitionPath]: definitions
2113
+ } : main : {
2114
+ $ref: [
2115
+ ...refs.$refStrategy === "relative" ? [] : refs.basePath,
2116
+ refs.definitionPath,
2117
+ name
2118
+ ].join("/"),
2119
+ [refs.definitionPath]: {
2120
+ ...definitions,
2121
+ [name]: main
2122
+ }
2123
+ };
2124
+ combined.$schema = "http://json-schema.org/draft-07/schema#";
2125
+ return combined;
2126
+ };
2127
+
2128
+ // src/zod-to-json-schema/index.ts
2129
+ var zod_to_json_schema_default = zodToJsonSchema;
2130
+
2131
+ // src/zod-schema.ts
943
2132
  function zod3Schema(zodSchema2, options) {
944
2133
  var _a;
945
2134
  const useReferences = (_a = options == null ? void 0 : options.useReferences) != null ? _a : false;
946
2135
  return jsonSchema(
947
- zodToJsonSchema(zodSchema2, {
948
- $refStrategy: useReferences ? "root" : "none",
949
- target: "jsonSchema7"
950
- // note: openai mode breaks various gemini conversions
2136
+ zod_to_json_schema_default(zodSchema2, {
2137
+ $refStrategy: useReferences ? "root" : "none"
951
2138
  }),
952
2139
  {
953
2140
  validate: async (value) => {