@mastra/schema-compat 1.2.10-alpha.0 → 1.2.11-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.
Files changed (56) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/_types/@internal_ai-sdk-v4/dist/index.d.ts +2 -160
  3. package/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +13 -171
  4. package/dist/_types/@internal_ai-v6/dist/index.d.ts +28 -165
  5. package/dist/_types/@standard-schema_spec/dist/index.d.ts +119 -0
  6. package/dist/_types/@types_json-schema/index.d.ts +749 -0
  7. package/dist/{chunk-MARLM5PM.cjs → chunk-B6ZU4MU5.cjs} +508 -508
  8. package/dist/chunk-B6ZU4MU5.cjs.map +1 -0
  9. package/dist/{chunk-JO4RRSYO.cjs → chunk-BQ3VTMIR.cjs} +4 -4
  10. package/dist/{chunk-JO4RRSYO.cjs.map → chunk-BQ3VTMIR.cjs.map} +1 -1
  11. package/dist/{chunk-7ZCSAPV3.js → chunk-ECLNT3TQ.js} +3 -2
  12. package/dist/chunk-ECLNT3TQ.js.map +1 -0
  13. package/dist/{chunk-K73KZRCA.js → chunk-H72LBCXW.js} +4 -4
  14. package/dist/{chunk-K73KZRCA.js.map → chunk-H72LBCXW.js.map} +1 -1
  15. package/dist/{chunk-UFJG5KPA.cjs → chunk-LQOEEQF6.cjs} +3 -2
  16. package/dist/chunk-LQOEEQF6.cjs.map +1 -0
  17. package/dist/{chunk-KGSZKLQN.js → chunk-MXN3UURE.js} +506 -506
  18. package/dist/chunk-MXN3UURE.js.map +1 -0
  19. package/dist/{chunk-DLZFWLZ2.js → chunk-QFEMCRFS.js} +3 -3
  20. package/dist/{chunk-DLZFWLZ2.js.map → chunk-QFEMCRFS.js.map} +1 -1
  21. package/dist/{chunk-3MLZICLP.cjs → chunk-SKPYVQBT.cjs} +4 -4
  22. package/dist/chunk-SKPYVQBT.cjs.map +1 -0
  23. package/dist/{chunk-K7I3YXWP.js → chunk-Y4VRRNL5.js} +4 -4
  24. package/dist/chunk-Y4VRRNL5.js.map +1 -0
  25. package/dist/{chunk-Q6XZFGLX.cjs → chunk-ZRSV37SF.cjs} +6 -6
  26. package/dist/{chunk-Q6XZFGLX.cjs.map → chunk-ZRSV37SF.cjs.map} +1 -1
  27. package/dist/index.cjs +129 -36
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.js +101 -8
  30. package/dist/index.js.map +1 -1
  31. package/dist/json-schema.d.ts +2 -2
  32. package/dist/provider-compats/anthropic.d.ts +1 -1
  33. package/dist/provider-compats/deepseek.d.ts +1 -1
  34. package/dist/provider-compats/google.d.ts.map +1 -1
  35. package/dist/provider-compats/meta.d.ts +1 -1
  36. package/dist/schema.cjs +7 -7
  37. package/dist/schema.js +1 -1
  38. package/dist/schema.types.d.ts +3 -3
  39. package/dist/standard-schema/adapters/ai-sdk.d.ts +1 -1
  40. package/dist/standard-schema/adapters/json-schema.cjs +3 -3
  41. package/dist/standard-schema/adapters/json-schema.js +1 -1
  42. package/dist/standard-schema/adapters/zod-v3.cjs +2 -2
  43. package/dist/standard-schema/adapters/zod-v3.js +1 -1
  44. package/dist/standard-schema/adapters/zod-v4.d.ts +1 -1
  45. package/dist/standard-schema/standard-schema.d.ts +1 -1
  46. package/dist/standard-schema/standard-schema.types.d.ts +1 -1
  47. package/dist/zod-to-json.cjs +4 -4
  48. package/dist/zod-to-json.d.ts.map +1 -1
  49. package/dist/zod-to-json.js +1 -1
  50. package/package.json +12 -12
  51. package/dist/chunk-3MLZICLP.cjs.map +0 -1
  52. package/dist/chunk-7ZCSAPV3.js.map +0 -1
  53. package/dist/chunk-K7I3YXWP.js.map +0 -1
  54. package/dist/chunk-KGSZKLQN.js.map +0 -1
  55. package/dist/chunk-MARLM5PM.cjs.map +0 -1
  56. package/dist/chunk-UFJG5KPA.cjs.map +0 -1
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- import { toStandardSchema, standardSchemaToJSONSchema, isStandardSchemaWithJSON } from './chunk-K73KZRCA.js';
2
- export { JSON_SCHEMA_LIBRARY_OPTIONS, isStandardJSONSchema, isStandardSchema, isStandardSchemaWithJSON, standardSchemaToJSONSchema, toStandardSchema } from './chunk-K73KZRCA.js';
3
- import { zodToJsonSchema } from './chunk-7ZCSAPV3.js';
4
- export { ensureAllPropertiesRequired, prepareJsonSchemaForOpenAIStrictMode } from './chunk-7ZCSAPV3.js';
5
- import { require_json_schema_traverse } from './chunk-K7I3YXWP.js';
1
+ import { toStandardSchema, standardSchemaToJSONSchema, isStandardSchemaWithJSON } from './chunk-H72LBCXW.js';
2
+ export { JSON_SCHEMA_LIBRARY_OPTIONS, isStandardJSONSchema, isStandardSchema, isStandardSchemaWithJSON, standardSchemaToJSONSchema, toStandardSchema } from './chunk-H72LBCXW.js';
3
+ import { zodToJsonSchema } from './chunk-ECLNT3TQ.js';
4
+ export { ensureAllPropertiesRequired, prepareJsonSchemaForOpenAIStrictMode } from './chunk-ECLNT3TQ.js';
5
+ import { require_json_schema_traverse } from './chunk-Y4VRRNL5.js';
6
6
  import { __toESM } from './chunk-5WRI5ZAA.js';
7
7
  import { ZodOptional, ZodObject, ZodArray, ZodUnion, ZodString, ZodNumber, ZodNull, ZodNullable, ZodDate, ZodDefault, ZodIntersection, z as z$1, ZodFirstPartyTypeKind } from 'zod/v3';
8
8
  import { z } from 'zod';
@@ -10,7 +10,7 @@ import { convertJsonSchemaToZod } from 'zod-from-json-schema';
10
10
  import { convertJsonSchemaToZod as convertJsonSchemaToZod$1 } from 'zod-from-json-schema-v3';
11
11
  import { ZodOptional as ZodOptional$1, ZodObject as ZodObject$1, ZodNull as ZodNull$1, ZodNullable as ZodNullable$1, ZodArray as ZodArray$1, ZodUnion as ZodUnion$1, ZodString as ZodString$1, ZodNumber as ZodNumber$1, ZodDate as ZodDate$1, ZodDefault as ZodDefault$1, ZodIntersection as ZodIntersection$1, z as z$2 } from 'zod/v4';
12
12
 
13
- // ../_vendored/ai_v4/dist/chunk-HB6FLTHO.js
13
+ // ../_vendored/ai_v4/dist/chunk-J65CK2AI.js
14
14
  var __create = Object.create;
15
15
  var __defProp = Object.defineProperty;
16
16
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -37,7 +37,7 @@ var __toESM2 = (mod, isNodeMode, target) => (target = mod != null ? __create(__g
37
37
  mod
38
38
  ));
39
39
  var require_secure_json_parse = __commonJS({
40
- "../../../node_modules/.pnpm/secure-json-parse@2.7.0/node_modules/secure-json-parse/index.js"(exports$1, module) {
40
+ "../../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/secure-json-parse/2.7.0/1f65efb0c6ff2d0f745ac6dfe22202b559993ceecd896afead5fc2c075b2d349/node_modules/secure-json-parse/index.js"(exports, module) {
41
41
  var hasBuffer = typeof Buffer !== "undefined";
42
42
  var suspectProtoRx = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
43
43
  var suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
@@ -5974,6 +5974,51 @@ function fixAISDKNullableUnionTypes(schema) {
5974
5974
  }
5975
5975
  return result;
5976
5976
  }
5977
+ function inlineRefsAndDropDefinitions(schema) {
5978
+ const json = JSON.stringify(schema);
5979
+ if (!json.includes('"$ref"')) return;
5980
+ const defs = schema["definitions"] ?? schema["$defs"];
5981
+ const snapshot = JSON.parse(json);
5982
+ const snapshotDefs = snapshot["definitions"] ?? snapshot["$defs"];
5983
+ resolveRefs(schema, snapshot, snapshotDefs ?? defs ?? {}, /* @__PURE__ */ new Set());
5984
+ delete schema["definitions"];
5985
+ delete schema["$defs"];
5986
+ }
5987
+ function resolveRefs(node, rootSnapshot, defs, visiting) {
5988
+ if (typeof node !== "object" || node === null) return;
5989
+ for (const [key, value] of Object.entries(node)) {
5990
+ if (key === "$ref" && typeof value === "string") {
5991
+ const resolved = resolveRef(value, rootSnapshot, defs);
5992
+ if (!resolved || visiting.has(value)) {
5993
+ delete node["$ref"];
5994
+ node["type"] = "object";
5995
+ } else {
5996
+ delete node["$ref"];
5997
+ visiting.add(value);
5998
+ const clone = JSON.parse(JSON.stringify(resolved));
5999
+ resolveRefs(clone, rootSnapshot, defs, visiting);
6000
+ visiting.delete(value);
6001
+ Object.assign(node, clone);
6002
+ }
6003
+ } else if (Array.isArray(value)) {
6004
+ for (const item of value) {
6005
+ if (typeof item === "object" && item !== null) {
6006
+ resolveRefs(item, rootSnapshot, defs, visiting);
6007
+ }
6008
+ }
6009
+ } else if (typeof value === "object" && value !== null) {
6010
+ resolveRefs(value, rootSnapshot, defs, visiting);
6011
+ }
6012
+ }
6013
+ }
6014
+ function resolveRef(ref, rootSnapshot, defs) {
6015
+ if (ref === "#") return rootSnapshot;
6016
+ const match = ref.match(/^#\/(?:definitions|\$defs)\/(.+)$/);
6017
+ if (match) {
6018
+ return defs[match[1]];
6019
+ }
6020
+ return void 0;
6021
+ }
5977
6022
  var GoogleSchemaCompatLayer = class extends SchemaCompatLayer3 {
5978
6023
  constructor(model) {
5979
6024
  super(model);
@@ -6014,7 +6059,9 @@ var GoogleSchemaCompatLayer = class extends SchemaCompatLayer3 {
6014
6059
  return this.defaultUnsupportedZodTypeHandler(value);
6015
6060
  }
6016
6061
  processToJSONSchema(schema, io) {
6017
- return super.processToJSONSchema(schema, io);
6062
+ const result = super.processToJSONSchema(schema, io);
6063
+ inlineRefsAndDropDefinitions(result);
6064
+ return result;
6018
6065
  }
6019
6066
  processToAISDKSchema(zodSchema2) {
6020
6067
  const compat = this.processToCompatSchema(zodSchema2);
@@ -6068,6 +6115,52 @@ var GoogleSchemaCompatLayer = class extends SchemaCompatLayer3 {
6068
6115
  if (isUnionSchema(schema)) {
6069
6116
  this.defaultUnionHandler(schema);
6070
6117
  }
6118
+ const s = schema;
6119
+ delete s["$schema"];
6120
+ delete s["additionalProperties"];
6121
+ delete s["propertyNames"];
6122
+ if (Array.isArray(s["type"])) {
6123
+ const types = s["type"];
6124
+ const nonNull = types.filter((t) => t !== "null");
6125
+ const hasNull = types.includes("null");
6126
+ if (nonNull.length === 1) {
6127
+ s["type"] = nonNull[0];
6128
+ if (hasNull) s["nullable"] = true;
6129
+ } else if (nonNull.length === 0 && hasNull) {
6130
+ s["type"] = "object";
6131
+ s["nullable"] = true;
6132
+ } else {
6133
+ delete s["type"];
6134
+ delete s["nullable"];
6135
+ }
6136
+ }
6137
+ if (Array.isArray(s["oneOf"])) {
6138
+ s["anyOf"] = s["oneOf"];
6139
+ delete s["oneOf"];
6140
+ }
6141
+ if ("const" in s) {
6142
+ s["enum"] = [s["const"]];
6143
+ delete s["const"];
6144
+ }
6145
+ if (Array.isArray(s["items"])) {
6146
+ s["items"] = { anyOf: s["items"] };
6147
+ delete s["minItems"];
6148
+ delete s["maxItems"];
6149
+ }
6150
+ if (Array.isArray(s["anyOf"])) {
6151
+ const variants = s["anyOf"];
6152
+ const nonNull = variants.filter((v) => v && typeof v === "object" && v["type"] !== "null");
6153
+ const hasNull = variants.some((v) => v && typeof v === "object" && v["type"] === "null");
6154
+ if (hasNull && nonNull.length === 1) {
6155
+ const base = nonNull[0];
6156
+ delete s["anyOf"];
6157
+ Object.assign(s, base);
6158
+ s["nullable"] = true;
6159
+ } else if (hasNull && nonNull.length > 1) {
6160
+ s["anyOf"] = nonNull;
6161
+ s["nullable"] = true;
6162
+ }
6163
+ }
6071
6164
  }
6072
6165
  #traverse(value, schema) {
6073
6166
  const resolved = this.#resolveAnyOf(schema);