@mastra/schema-compat 1.3.11-alpha.1 → 1.3.12-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { r as __toESM$1, t as require_json_schema_traverse } from "./json-schema-traverse-B35mHRM8.js";
2
2
  import { ensureAllPropertiesRequired, prepareJsonSchemaForOpenAIStrictMode, zodToJsonSchema as zodToJsonSchema$1 } from "./zod-to-json.js";
3
- import { a as standardSchemaToJSONSchema, i as isStandardSchemaWithJSON, n as isStandardJSONSchema, o as toStandardSchema, r as isStandardSchema, t as JSON_SCHEMA_LIBRARY_OPTIONS } from "./schema-BwlBcZRB.js";
3
+ import { a as standardSchemaToJSONSchema, i as isStandardSchemaWithJSON, n as isStandardJSONSchema, o as toStandardSchema, r as isStandardSchema, t as JSON_SCHEMA_LIBRARY_OPTIONS } from "./schema-e0VHpMt0.js";
4
4
  import { ZodArray, ZodDate, ZodDefault, ZodFirstPartyTypeKind, ZodIntersection, ZodNull, ZodNullable, ZodNumber, ZodObject, ZodOptional, ZodString, ZodUnion, z } from "zod/v3";
5
5
  import { z as z$1 } from "zod";
6
6
  import { convertJsonSchemaToZod } from "zod-from-json-schema";
@@ -5227,6 +5227,15 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer {
5227
5227
  "x-optional"
5228
5228
  ];
5229
5229
  const arrayKeywords = ["items"];
5230
+ const numericKeywords = [
5231
+ "format",
5232
+ "minimum",
5233
+ "maximum",
5234
+ "exclusiveMinimum",
5235
+ "exclusiveMaximum",
5236
+ "multipleOf"
5237
+ ];
5238
+ const isNumericType = (type) => type === "integer" || type === "number";
5230
5239
  const genericConstraintKeywords = [
5231
5240
  "const",
5232
5241
  "enum",
@@ -5276,10 +5285,26 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer {
5276
5285
  prop.anyOf = types.map((type) => {
5277
5286
  if (type === "null") return { type: "null" };
5278
5287
  const branch = { type };
5279
- for (const keyword of typeSpecificKeywords(type)) if (keyword in prop) branch[keyword] = prop[keyword];
5288
+ const numericFormat = typeof prop.format === "string" && [
5289
+ "int32",
5290
+ "int64",
5291
+ "float",
5292
+ "double"
5293
+ ].includes(prop.format);
5294
+ const formatOwner = types.includes("string") && !numericFormat ? type === "string" : isNumericType(type);
5295
+ for (const keyword of [
5296
+ ...typeSpecificKeywords(type),
5297
+ ...isNumericType(type) ? numericKeywords.filter((k) => k !== "format") : [],
5298
+ ...formatOwner ? ["format"] : []
5299
+ ]) if (keyword in prop) branch[keyword] = prop[keyword];
5280
5300
  return Object.assign(branch, branchConstraints);
5281
5301
  });
5282
- for (const keyword of [...objectKeywords, ...arrayKeywords]) delete prop[keyword];
5302
+ const numericBranchExists = types.some(isNumericType);
5303
+ for (const keyword of [
5304
+ ...objectKeywords,
5305
+ ...arrayKeywords,
5306
+ ...numericBranchExists ? numericKeywords : []
5307
+ ]) delete prop[keyword];
5283
5308
  } else if (prop.type && prop.type !== "null") {
5284
5309
  const originalType = prop.type;
5285
5310
  const keywords = typeSpecificKeywords(originalType);
@@ -5300,6 +5325,7 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer {
5300
5325
  };
5301
5326
  if (isRedundantNullableUnion(originalType)) delete propSchema.anyOf;
5302
5327
  for (const keyword of [...genericConstraintKeywords, "anyOf"]) delete prop[keyword];
5328
+ if (isNumericType(originalType)) for (const keyword of numericKeywords) delete prop[keyword];
5303
5329
  delete prop.type;
5304
5330
  prop.anyOf = [propSchema, { type: "null" }];
5305
5331
  }