@mastra/schema-compat 1.3.4-alpha.2 → 1.3.5-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 (75) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +4 -4
  3. package/dist/_types/@internal_ai-v6/dist/index.d.ts +10 -6
  4. package/dist/index.cjs +5455 -5998
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.js +5467 -5988
  7. package/dist/index.js.map +1 -1
  8. package/dist/json-schema-BstKYbJi.js +6797 -0
  9. package/dist/json-schema-BstKYbJi.js.map +1 -0
  10. package/dist/json-schema-pcL1TeZs.cjs +6809 -0
  11. package/dist/json-schema-pcL1TeZs.cjs.map +1 -0
  12. package/dist/json-schema-traverse-B35mHRM8.js +101 -0
  13. package/dist/json-schema-traverse-B35mHRM8.js.map +1 -0
  14. package/dist/json-schema-traverse-CSNSaf0y.cjs +83 -0
  15. package/dist/json-schema-traverse-CSNSaf0y.cjs.map +1 -0
  16. package/dist/json-to-zod.cjs +185 -245
  17. package/dist/json-to-zod.cjs.map +1 -1
  18. package/dist/json-to-zod.js +176 -235
  19. package/dist/json-to-zod.js.map +1 -1
  20. package/dist/provider-compats/anthropic.d.ts +1 -0
  21. package/dist/provider-compats/anthropic.d.ts.map +1 -1
  22. package/dist/rolldown-runtime-emK7D4bc.cjs +35 -0
  23. package/dist/schema-Bv9OdW1f.js +258 -0
  24. package/dist/schema-Bv9OdW1f.js.map +1 -0
  25. package/dist/schema-Cjk6OMG9.cjs +295 -0
  26. package/dist/schema-Cjk6OMG9.cjs.map +1 -0
  27. package/dist/schema.cjs +8 -32
  28. package/dist/schema.js +2 -3
  29. package/dist/standard-schema/adapters/ai-sdk.cjs +156 -14
  30. package/dist/standard-schema/adapters/ai-sdk.cjs.map +1 -1
  31. package/dist/standard-schema/adapters/ai-sdk.js +155 -2
  32. package/dist/standard-schema/adapters/ai-sdk.js.map +1 -1
  33. package/dist/standard-schema/adapters/json-schema.cjs +4 -16
  34. package/dist/standard-schema/adapters/json-schema.js +2 -3
  35. package/dist/standard-schema/adapters/zod-v3.cjs +101 -10
  36. package/dist/standard-schema/adapters/zod-v3.cjs.map +1 -1
  37. package/dist/standard-schema/adapters/zod-v3.js +99 -2
  38. package/dist/standard-schema/adapters/zod-v3.js.map +1 -1
  39. package/dist/zod-to-json.cjs +165 -22
  40. package/dist/zod-to-json.cjs.map +1 -1
  41. package/dist/zod-to-json.js +160 -2
  42. package/dist/zod-to-json.js.map +1 -1
  43. package/package.json +18 -17
  44. package/dist/chunk-23HDOZLF.js +0 -105
  45. package/dist/chunk-23HDOZLF.js.map +0 -1
  46. package/dist/chunk-5WRI5ZAA.js +0 -29
  47. package/dist/chunk-5WRI5ZAA.js.map +0 -1
  48. package/dist/chunk-77T2HV4Q.cjs +0 -7352
  49. package/dist/chunk-77T2HV4Q.cjs.map +0 -1
  50. package/dist/chunk-BQ3VTMIR.cjs +0 -76
  51. package/dist/chunk-BQ3VTMIR.cjs.map +0 -1
  52. package/dist/chunk-DZUJEN5N.cjs +0 -32
  53. package/dist/chunk-DZUJEN5N.cjs.map +0 -1
  54. package/dist/chunk-FJGZKUBH.cjs +0 -208
  55. package/dist/chunk-FJGZKUBH.cjs.map +0 -1
  56. package/dist/chunk-FS3P4V5M.cjs +0 -108
  57. package/dist/chunk-FS3P4V5M.cjs.map +0 -1
  58. package/dist/chunk-QEM5W7OR.js +0 -199
  59. package/dist/chunk-QEM5W7OR.js.map +0 -1
  60. package/dist/chunk-QFEMCRFS.js +0 -70
  61. package/dist/chunk-QFEMCRFS.js.map +0 -1
  62. package/dist/chunk-RMMKMUYK.js +0 -7349
  63. package/dist/chunk-RMMKMUYK.js.map +0 -1
  64. package/dist/chunk-SKPYVQBT.cjs +0 -94
  65. package/dist/chunk-SKPYVQBT.cjs.map +0 -1
  66. package/dist/chunk-VNIPWNNH.js +0 -170
  67. package/dist/chunk-VNIPWNNH.js.map +0 -1
  68. package/dist/chunk-Y4VRRNL5.js +0 -92
  69. package/dist/chunk-Y4VRRNL5.js.map +0 -1
  70. package/dist/chunk-ZTO66ALH.cjs +0 -181
  71. package/dist/chunk-ZTO66ALH.cjs.map +0 -1
  72. package/dist/schema.cjs.map +0 -1
  73. package/dist/schema.js.map +0 -1
  74. package/dist/standard-schema/adapters/json-schema.cjs.map +0 -1
  75. package/dist/standard-schema/adapters/json-schema.js.map +0 -1
package/dist/schema.cjs CHANGED
@@ -1,32 +1,8 @@
1
- 'use strict';
2
-
3
- var chunkZTO66ALH_cjs = require('./chunk-ZTO66ALH.cjs');
4
-
5
-
6
-
7
- Object.defineProperty(exports, "JSON_SCHEMA_LIBRARY_OPTIONS", {
8
- enumerable: true,
9
- get: function () { return chunkZTO66ALH_cjs.JSON_SCHEMA_LIBRARY_OPTIONS; }
10
- });
11
- Object.defineProperty(exports, "isStandardJSONSchema", {
12
- enumerable: true,
13
- get: function () { return chunkZTO66ALH_cjs.isStandardJSONSchema; }
14
- });
15
- Object.defineProperty(exports, "isStandardSchema", {
16
- enumerable: true,
17
- get: function () { return chunkZTO66ALH_cjs.isStandardSchema; }
18
- });
19
- Object.defineProperty(exports, "isStandardSchemaWithJSON", {
20
- enumerable: true,
21
- get: function () { return chunkZTO66ALH_cjs.isStandardSchemaWithJSON; }
22
- });
23
- Object.defineProperty(exports, "standardSchemaToJSONSchema", {
24
- enumerable: true,
25
- get: function () { return chunkZTO66ALH_cjs.standardSchemaToJSONSchema; }
26
- });
27
- Object.defineProperty(exports, "toStandardSchema", {
28
- enumerable: true,
29
- get: function () { return chunkZTO66ALH_cjs.toStandardSchema; }
30
- });
31
- //# sourceMappingURL=schema.cjs.map
32
- //# sourceMappingURL=schema.cjs.map
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_schema = require("./schema-Cjk6OMG9.cjs");
3
+ exports.JSON_SCHEMA_LIBRARY_OPTIONS = require_schema.JSON_SCHEMA_LIBRARY_OPTIONS;
4
+ exports.isStandardJSONSchema = require_schema.isStandardJSONSchema;
5
+ exports.isStandardSchema = require_schema.isStandardSchema;
6
+ exports.isStandardSchemaWithJSON = require_schema.isStandardSchemaWithJSON;
7
+ exports.standardSchemaToJSONSchema = require_schema.standardSchemaToJSONSchema;
8
+ exports.toStandardSchema = require_schema.toStandardSchema;
package/dist/schema.js CHANGED
@@ -1,3 +1,2 @@
1
- export { JSON_SCHEMA_LIBRARY_OPTIONS, isStandardJSONSchema, isStandardSchema, isStandardSchemaWithJSON, standardSchemaToJSONSchema, toStandardSchema } from './chunk-VNIPWNNH.js';
2
- //# sourceMappingURL=schema.js.map
3
- //# sourceMappingURL=schema.js.map
1
+ import { a as standardSchemaToJSONSchema, i as isStandardSchemaWithJSON, n as isStandardJSONSchema, o as toStandardSchema, r as isStandardSchema, t as JSON_SCHEMA_LIBRARY_OPTIONS } from "./schema-Bv9OdW1f.js";
2
+ export { JSON_SCHEMA_LIBRARY_OPTIONS, isStandardJSONSchema, isStandardSchema, isStandardSchemaWithJSON, standardSchemaToJSONSchema, toStandardSchema };
@@ -1,16 +1,158 @@
1
- 'use strict';
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region src/standard-schema/adapters/ai-sdk.ts
3
+ /**
4
+ * Vendor name for AI SDK wrapped schemas.
5
+ */
6
+ const VENDOR = "ai-sdk";
7
+ /**
8
+ * A wrapper class that makes AI SDK Schema compatible with @standard-schema/spec.
9
+ *
10
+ * This class implements both `StandardSchemaV1` (validation) and `StandardJSONSchemaV1`
11
+ * (JSON Schema conversion) interfaces. It wraps an AI SDK Schema and adapts its
12
+ * validation method and jsonSchema property to the standard-schema interface.
13
+ *
14
+ * @typeParam T - The TypeScript type that the AI SDK Schema represents
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { jsonSchema } from '@internal/ai-v6';
19
+ * import { toStandardSchema } from '@mastra/schema-compat/adapters/ai-sdk';
20
+ *
21
+ * // Create an AI SDK schema
22
+ * const aiSdkSchema = jsonSchema<{ name: string; age: number }>({
23
+ * type: 'object',
24
+ * properties: {
25
+ * name: { type: 'string' },
26
+ * age: { type: 'number' },
27
+ * },
28
+ * required: ['name', 'age'],
29
+ * });
30
+ *
31
+ * // Convert to standard-schema
32
+ * const standardSchema = toStandardSchema(aiSdkSchema);
33
+ *
34
+ * // Use validation (from StandardSchemaV1)
35
+ * const result = standardSchema['~standard'].validate({ name: 'John', age: 30 });
36
+ *
37
+ * // Get JSON Schema (from StandardJSONSchemaV1)
38
+ * const jsonSchema = standardSchema['~standard'].jsonSchema.output({ target: 'draft-07' });
39
+ * ```
40
+ */
41
+ var AiSdkSchemaWrapper = class {
42
+ #schema;
43
+ "~standard";
44
+ constructor(schema) {
45
+ this.#schema = schema;
46
+ this["~standard"] = {
47
+ version: 1,
48
+ vendor: VENDOR,
49
+ validate: this.#validate.bind(this),
50
+ jsonSchema: {
51
+ input: this.#toJsonSchema.bind(this),
52
+ output: this.#toJsonSchema.bind(this)
53
+ }
54
+ };
55
+ }
56
+ /**
57
+ * Validates a value against the AI SDK Schema.
58
+ *
59
+ * @param value - The value to validate
60
+ * @returns A result object with either the validated value or validation issues
61
+ */
62
+ #validate(value) {
63
+ if (!this.#schema.validate) return { value };
64
+ try {
65
+ const result = this.#schema.validate(value);
66
+ if (result && typeof result === "object" && "then" in result && typeof result.then === "function") return Promise.resolve(result).then((res) => this.#convertValidationResult(res)).catch((error) => {
67
+ return { issues: [{ message: `Schema validation error: ${error instanceof Error ? error.message : "Unknown validation error"}` }] };
68
+ });
69
+ return this.#convertValidationResult(result);
70
+ } catch (error) {
71
+ return { issues: [{ message: `Schema validation error: ${error instanceof Error ? error.message : "Unknown validation error"}` }] };
72
+ }
73
+ }
74
+ /**
75
+ * Converts an AI SDK ValidationResult to a StandardSchemaV1.Result.
76
+ *
77
+ * @param result - The AI SDK validation result
78
+ * @returns A StandardSchemaV1.Result
79
+ */
80
+ #convertValidationResult(result) {
81
+ if (result.success) return { value: result.value };
82
+ return { issues: [{ message: result.error.message }] };
83
+ }
84
+ /**
85
+ * Returns the JSON Schema in the requested target format.
86
+ *
87
+ * @param options - Options including the target format
88
+ * @returns The JSON Schema as a Record
89
+ */
90
+ #toJsonSchema(options) {
91
+ const { target } = options;
92
+ const clonedSchema = JSON.parse(JSON.stringify(this.#schema.jsonSchema));
93
+ if (!clonedSchema.$schema) switch (target) {
94
+ case "draft-07":
95
+ clonedSchema.$schema = "http://json-schema.org/draft-07/schema#";
96
+ break;
97
+ case "draft-2020-12":
98
+ clonedSchema.$schema = "https://json-schema.org/draft/2020-12/schema";
99
+ break;
100
+ case "openapi-3.0": break;
101
+ default: break;
102
+ }
103
+ return clonedSchema;
104
+ }
105
+ /**
106
+ * Returns the original AI SDK Schema.
107
+ */
108
+ getSchema() {
109
+ return this.#schema;
110
+ }
111
+ /**
112
+ * Returns the original JSON Schema from the AI SDK Schema.
113
+ */
114
+ getJsonSchema() {
115
+ return this.#schema.jsonSchema;
116
+ }
117
+ };
118
+ /**
119
+ * Wraps an AI SDK Schema to implement the full @standard-schema/spec interface.
120
+ *
121
+ * This function creates a wrapper that implements both `StandardSchemaV1` (validation)
122
+ * and `StandardJSONSchemaV1` (JSON Schema conversion) interfaces.
123
+ *
124
+ * @typeParam T - The TypeScript type that the AI SDK Schema represents
125
+ * @param schema - The AI SDK Schema to wrap
126
+ * @returns A wrapper implementing StandardSchemaWithJSON
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * import { jsonSchema } from '@internal/ai-v6';
131
+ * import { toStandardSchema } from '@mastra/schema-compat/adapters/ai-sdk';
132
+ *
133
+ * const aiSdkSchema = jsonSchema<{ name: string; age: number }>({
134
+ * type: 'object',
135
+ * properties: {
136
+ * name: { type: 'string' },
137
+ * age: { type: 'number' },
138
+ * },
139
+ * required: ['name', 'age'],
140
+ * });
141
+ *
142
+ * const standardSchema = toStandardSchema(aiSdkSchema);
143
+ *
144
+ * // Validate data
145
+ * const result = standardSchema['~standard'].validate({ name: 'John', age: 30 });
146
+ *
147
+ * // Get JSON Schema
148
+ * const jsonSchema = standardSchema['~standard'].jsonSchema.output({ target: 'draft-07' });
149
+ * ```
150
+ */
151
+ function toStandardSchema(schema) {
152
+ return new AiSdkSchemaWrapper(schema);
153
+ }
154
+ //#endregion
155
+ exports.AiSdkSchemaWrapper = AiSdkSchemaWrapper;
156
+ exports.toStandardSchema = toStandardSchema;
2
157
 
3
- var chunkFS3P4V5M_cjs = require('../../chunk-FS3P4V5M.cjs');
4
-
5
-
6
-
7
- Object.defineProperty(exports, "AiSdkSchemaWrapper", {
8
- enumerable: true,
9
- get: function () { return chunkFS3P4V5M_cjs.AiSdkSchemaWrapper; }
10
- });
11
- Object.defineProperty(exports, "toStandardSchema", {
12
- enumerable: true,
13
- get: function () { return chunkFS3P4V5M_cjs.toStandardSchema; }
14
- });
15
- //# sourceMappingURL=ai-sdk.cjs.map
16
158
  //# sourceMappingURL=ai-sdk.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"ai-sdk.cjs"}
1
+ {"version":3,"file":"ai-sdk.cjs","names":["#schema","#validate","#toJsonSchema","#convertValidationResult","failureResult"],"sources":["../../../src/standard-schema/adapters/ai-sdk.ts"],"sourcesContent":["import type { Schema } from '@internal/ai-v6';\nimport type { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';\nimport type { JSONSchema7 } from 'json-schema';\nimport type { StandardSchemaWithJSON, StandardSchemaWithJSONProps } from '../standard-schema.types';\n\n/**\n * Vendor name for AI SDK wrapped schemas.\n */\nconst VENDOR = 'ai-sdk';\n\n/**\n * A wrapper class that makes AI SDK Schema compatible with @standard-schema/spec.\n *\n * This class implements both `StandardSchemaV1` (validation) and `StandardJSONSchemaV1`\n * (JSON Schema conversion) interfaces. It wraps an AI SDK Schema and adapts its\n * validation method and jsonSchema property to the standard-schema interface.\n *\n * @typeParam T - The TypeScript type that the AI SDK Schema represents\n *\n * @example\n * ```typescript\n * import { jsonSchema } from '@internal/ai-v6';\n * import { toStandardSchema } from '@mastra/schema-compat/adapters/ai-sdk';\n *\n * // Create an AI SDK schema\n * const aiSdkSchema = jsonSchema<{ name: string; age: number }>({\n * type: 'object',\n * properties: {\n * name: { type: 'string' },\n * age: { type: 'number' },\n * },\n * required: ['name', 'age'],\n * });\n *\n * // Convert to standard-schema\n * const standardSchema = toStandardSchema(aiSdkSchema);\n *\n * // Use validation (from StandardSchemaV1)\n * const result = standardSchema['~standard'].validate({ name: 'John', age: 30 });\n *\n * // Get JSON Schema (from StandardJSONSchemaV1)\n * const jsonSchema = standardSchema['~standard'].jsonSchema.output({ target: 'draft-07' });\n * ```\n */\nexport class AiSdkSchemaWrapper<Input = unknown, Output = Input> implements StandardSchemaWithJSON<Input, Output> {\n readonly #schema: Schema<Output>;\n readonly '~standard': StandardSchemaWithJSONProps<Input, Output>;\n\n constructor(schema: Schema<Output>) {\n this.#schema = schema;\n\n // Create the ~standard property\n this['~standard'] = {\n version: 1,\n vendor: VENDOR,\n validate: this.#validate.bind(this),\n jsonSchema: {\n input: this.#toJsonSchema.bind(this),\n output: this.#toJsonSchema.bind(this),\n },\n };\n }\n\n /**\n * Validates a value against the AI SDK Schema.\n *\n * @param value - The value to validate\n * @returns A result object with either the validated value or validation issues\n */\n #validate(value: unknown): StandardSchemaV1.Result<Output> | Promise<StandardSchemaV1.Result<Output>> {\n // Check if the schema has a validate method (it's optional on AI SDK Schema)\n if (!this.#schema.validate) {\n // If no validate method, we can't validate - just pass through\n return { value: value as Output };\n }\n\n try {\n const result = this.#schema.validate(value);\n\n // Handle both sync and async validation results\n // The AI SDK Schema.validate returns ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>\n // We need to check if it's a thenable (promise-like)\n if (result && typeof result === 'object' && 'then' in result && typeof result.then === 'function') {\n // Wrap PromiseLike in a proper Promise to satisfy the StandardSchemaV1 interface\n return Promise.resolve(\n result as PromiseLike<{ success: true; value: Output } | { success: false; error: Error }>,\n )\n .then(res => this.#convertValidationResult(res))\n .catch((error: unknown) => {\n // Convert rejected promises to the expected { issues: [...] } shape\n const message = error instanceof Error ? error.message : 'Unknown validation error';\n return {\n issues: [{ message: `Schema validation error: ${message}` }],\n } as StandardSchemaV1.Result<Output>;\n });\n }\n\n // It's a sync result\n return this.#convertValidationResult(\n result as { success: true; value: Output } | { success: false; error: Error },\n );\n } catch (error) {\n // If validation fails unexpectedly, return a validation error\n const message = error instanceof Error ? error.message : 'Unknown validation error';\n return {\n issues: [{ message: `Schema validation error: ${message}` }],\n };\n }\n }\n\n /**\n * Converts an AI SDK ValidationResult to a StandardSchemaV1.Result.\n *\n * @param result - The AI SDK validation result\n * @returns A StandardSchemaV1.Result\n */\n #convertValidationResult(\n result: { success: true; value: Output } | { success: false; error: Error },\n ): StandardSchemaV1.Result<Output> {\n if (result.success) {\n return { value: result.value };\n }\n\n // Convert the AI SDK error to a Standard Schema issue\n // Cast to the failure type since TypeScript can't narrow discriminated unions with private field access\n const failureResult = result as { success: false; error: Error };\n return {\n issues: [{ message: failureResult.error.message }],\n };\n }\n\n /**\n * Returns the JSON Schema in the requested target format.\n *\n * @param options - Options including the target format\n * @returns The JSON Schema as a Record\n */\n #toJsonSchema(options: StandardJSONSchemaV1.Options): Record<string, unknown> {\n const { target } = options;\n\n // Clone the schema to avoid mutations\n const clonedSchema = JSON.parse(JSON.stringify(this.#schema.jsonSchema)) as Record<string, unknown>;\n\n // Add $schema if not present, based on target\n if (!clonedSchema.$schema) {\n switch (target) {\n case 'draft-07':\n clonedSchema.$schema = 'http://json-schema.org/draft-07/schema#';\n break;\n case 'draft-2020-12':\n clonedSchema.$schema = 'https://json-schema.org/draft/2020-12/schema';\n break;\n case 'openapi-3.0':\n // OpenAPI 3.0 doesn't use $schema\n break;\n default:\n // For unknown targets, don't add $schema\n break;\n }\n }\n\n return clonedSchema;\n }\n\n /**\n * Returns the original AI SDK Schema.\n */\n getSchema(): Schema<Output> {\n return this.#schema;\n }\n\n /**\n * Returns the original JSON Schema from the AI SDK Schema.\n */\n getJsonSchema(): JSONSchema7 {\n return this.#schema.jsonSchema as JSONSchema7;\n }\n}\n\n/**\n * Wraps an AI SDK Schema to implement the full @standard-schema/spec interface.\n *\n * This function creates a wrapper that implements both `StandardSchemaV1` (validation)\n * and `StandardJSONSchemaV1` (JSON Schema conversion) interfaces.\n *\n * @typeParam T - The TypeScript type that the AI SDK Schema represents\n * @param schema - The AI SDK Schema to wrap\n * @returns A wrapper implementing StandardSchemaWithJSON\n *\n * @example\n * ```typescript\n * import { jsonSchema } from '@internal/ai-v6';\n * import { toStandardSchema } from '@mastra/schema-compat/adapters/ai-sdk';\n *\n * const aiSdkSchema = jsonSchema<{ name: string; age: number }>({\n * type: 'object',\n * properties: {\n * name: { type: 'string' },\n * age: { type: 'number' },\n * },\n * required: ['name', 'age'],\n * });\n *\n * const standardSchema = toStandardSchema(aiSdkSchema);\n *\n * // Validate data\n * const result = standardSchema['~standard'].validate({ name: 'John', age: 30 });\n *\n * // Get JSON Schema\n * const jsonSchema = standardSchema['~standard'].jsonSchema.output({ target: 'draft-07' });\n * ```\n */\nexport function toStandardSchema<T = unknown>(schema: Schema<T>): AiSdkSchemaWrapper<T, T> {\n return new AiSdkSchemaWrapper<T, T>(schema);\n}\n"],"mappings":";;;;;AAQA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCf,IAAa,qBAAb,MAAkH;CAChH;CACA;CAEA,YAAY,QAAwB;EAClC,KAAKA,UAAU;EAGf,KAAK,eAAe;GAClB,SAAS;GACT,QAAQ;GACR,UAAU,KAAKC,UAAU,KAAK,IAAI;GAClC,YAAY;IACV,OAAO,KAAKC,cAAc,KAAK,IAAI;IACnC,QAAQ,KAAKA,cAAc,KAAK,IAAI;GACtC;EACF;CACF;;;;;;;CAQA,UAAU,OAA4F;EAEpG,IAAI,CAAC,KAAKF,QAAQ,UAEhB,OAAO,EAAS,MAAgB;EAGlC,IAAI;GACF,MAAM,SAAS,KAAKA,QAAQ,SAAS,KAAK;GAK1C,IAAI,UAAU,OAAO,WAAW,YAAY,UAAU,UAAU,OAAO,OAAO,SAAS,YAErF,OAAO,QAAQ,QACb,MACF,CAAC,CACE,MAAK,QAAO,KAAKG,yBAAyB,GAAG,CAAC,CAAC,CAC/C,OAAO,UAAmB;IAGzB,OAAO,EACL,QAAQ,CAAC,EAAE,SAAS,4BAFN,iBAAiB,QAAQ,MAAM,UAAU,6BAEG,CAAC,EAC7D;GACF,CAAC;GAIL,OAAO,KAAKA,yBACV,MACF;EACF,SAAS,OAAO;GAGd,OAAO,EACL,QAAQ,CAAC,EAAE,SAAS,4BAFN,iBAAiB,QAAQ,MAAM,UAAU,6BAEG,CAAC,EAC7D;EACF;CACF;;;;;;;CAQA,yBACE,QACiC;EACjC,IAAI,OAAO,SACT,OAAO,EAAE,OAAO,OAAO,MAAM;EAM/B,OAAO,EACL,QAAQ,CAAC,EAAE,SAASC,OAAc,MAAM,QAAQ,CAAC,EACnD;CACF;;;;;;;CAQA,cAAc,SAAgE;EAC5E,MAAM,EAAE,WAAW;EAGnB,MAAM,eAAe,KAAK,MAAM,KAAK,UAAU,KAAKJ,QAAQ,UAAU,CAAC;EAGvE,IAAI,CAAC,aAAa,SAChB,QAAQ,QAAR;GACE,KAAK;IACH,aAAa,UAAU;IACvB;GACF,KAAK;IACH,aAAa,UAAU;IACvB;GACF,KAAK,eAEH;GACF,SAEE;EACJ;EAGF,OAAO;CACT;;;;CAKA,YAA4B;EAC1B,OAAO,KAAKA;CACd;;;;CAKA,gBAA6B;EAC3B,OAAO,KAAKA,QAAQ;CACtB;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,SAAgB,iBAA8B,QAA6C;CACzF,OAAO,IAAI,mBAAyB,MAAM;AAC5C"}
@@ -1,3 +1,156 @@
1
- export { AiSdkSchemaWrapper, toStandardSchema } from '../../chunk-23HDOZLF.js';
2
- //# sourceMappingURL=ai-sdk.js.map
1
+ //#region src/standard-schema/adapters/ai-sdk.ts
2
+ /**
3
+ * Vendor name for AI SDK wrapped schemas.
4
+ */
5
+ const VENDOR = "ai-sdk";
6
+ /**
7
+ * A wrapper class that makes AI SDK Schema compatible with @standard-schema/spec.
8
+ *
9
+ * This class implements both `StandardSchemaV1` (validation) and `StandardJSONSchemaV1`
10
+ * (JSON Schema conversion) interfaces. It wraps an AI SDK Schema and adapts its
11
+ * validation method and jsonSchema property to the standard-schema interface.
12
+ *
13
+ * @typeParam T - The TypeScript type that the AI SDK Schema represents
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { jsonSchema } from '@internal/ai-v6';
18
+ * import { toStandardSchema } from '@mastra/schema-compat/adapters/ai-sdk';
19
+ *
20
+ * // Create an AI SDK schema
21
+ * const aiSdkSchema = jsonSchema<{ name: string; age: number }>({
22
+ * type: 'object',
23
+ * properties: {
24
+ * name: { type: 'string' },
25
+ * age: { type: 'number' },
26
+ * },
27
+ * required: ['name', 'age'],
28
+ * });
29
+ *
30
+ * // Convert to standard-schema
31
+ * const standardSchema = toStandardSchema(aiSdkSchema);
32
+ *
33
+ * // Use validation (from StandardSchemaV1)
34
+ * const result = standardSchema['~standard'].validate({ name: 'John', age: 30 });
35
+ *
36
+ * // Get JSON Schema (from StandardJSONSchemaV1)
37
+ * const jsonSchema = standardSchema['~standard'].jsonSchema.output({ target: 'draft-07' });
38
+ * ```
39
+ */
40
+ var AiSdkSchemaWrapper = class {
41
+ #schema;
42
+ "~standard";
43
+ constructor(schema) {
44
+ this.#schema = schema;
45
+ this["~standard"] = {
46
+ version: 1,
47
+ vendor: VENDOR,
48
+ validate: this.#validate.bind(this),
49
+ jsonSchema: {
50
+ input: this.#toJsonSchema.bind(this),
51
+ output: this.#toJsonSchema.bind(this)
52
+ }
53
+ };
54
+ }
55
+ /**
56
+ * Validates a value against the AI SDK Schema.
57
+ *
58
+ * @param value - The value to validate
59
+ * @returns A result object with either the validated value or validation issues
60
+ */
61
+ #validate(value) {
62
+ if (!this.#schema.validate) return { value };
63
+ try {
64
+ const result = this.#schema.validate(value);
65
+ if (result && typeof result === "object" && "then" in result && typeof result.then === "function") return Promise.resolve(result).then((res) => this.#convertValidationResult(res)).catch((error) => {
66
+ return { issues: [{ message: `Schema validation error: ${error instanceof Error ? error.message : "Unknown validation error"}` }] };
67
+ });
68
+ return this.#convertValidationResult(result);
69
+ } catch (error) {
70
+ return { issues: [{ message: `Schema validation error: ${error instanceof Error ? error.message : "Unknown validation error"}` }] };
71
+ }
72
+ }
73
+ /**
74
+ * Converts an AI SDK ValidationResult to a StandardSchemaV1.Result.
75
+ *
76
+ * @param result - The AI SDK validation result
77
+ * @returns A StandardSchemaV1.Result
78
+ */
79
+ #convertValidationResult(result) {
80
+ if (result.success) return { value: result.value };
81
+ return { issues: [{ message: result.error.message }] };
82
+ }
83
+ /**
84
+ * Returns the JSON Schema in the requested target format.
85
+ *
86
+ * @param options - Options including the target format
87
+ * @returns The JSON Schema as a Record
88
+ */
89
+ #toJsonSchema(options) {
90
+ const { target } = options;
91
+ const clonedSchema = JSON.parse(JSON.stringify(this.#schema.jsonSchema));
92
+ if (!clonedSchema.$schema) switch (target) {
93
+ case "draft-07":
94
+ clonedSchema.$schema = "http://json-schema.org/draft-07/schema#";
95
+ break;
96
+ case "draft-2020-12":
97
+ clonedSchema.$schema = "https://json-schema.org/draft/2020-12/schema";
98
+ break;
99
+ case "openapi-3.0": break;
100
+ default: break;
101
+ }
102
+ return clonedSchema;
103
+ }
104
+ /**
105
+ * Returns the original AI SDK Schema.
106
+ */
107
+ getSchema() {
108
+ return this.#schema;
109
+ }
110
+ /**
111
+ * Returns the original JSON Schema from the AI SDK Schema.
112
+ */
113
+ getJsonSchema() {
114
+ return this.#schema.jsonSchema;
115
+ }
116
+ };
117
+ /**
118
+ * Wraps an AI SDK Schema to implement the full @standard-schema/spec interface.
119
+ *
120
+ * This function creates a wrapper that implements both `StandardSchemaV1` (validation)
121
+ * and `StandardJSONSchemaV1` (JSON Schema conversion) interfaces.
122
+ *
123
+ * @typeParam T - The TypeScript type that the AI SDK Schema represents
124
+ * @param schema - The AI SDK Schema to wrap
125
+ * @returns A wrapper implementing StandardSchemaWithJSON
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * import { jsonSchema } from '@internal/ai-v6';
130
+ * import { toStandardSchema } from '@mastra/schema-compat/adapters/ai-sdk';
131
+ *
132
+ * const aiSdkSchema = jsonSchema<{ name: string; age: number }>({
133
+ * type: 'object',
134
+ * properties: {
135
+ * name: { type: 'string' },
136
+ * age: { type: 'number' },
137
+ * },
138
+ * required: ['name', 'age'],
139
+ * });
140
+ *
141
+ * const standardSchema = toStandardSchema(aiSdkSchema);
142
+ *
143
+ * // Validate data
144
+ * const result = standardSchema['~standard'].validate({ name: 'John', age: 30 });
145
+ *
146
+ * // Get JSON Schema
147
+ * const jsonSchema = standardSchema['~standard'].jsonSchema.output({ target: 'draft-07' });
148
+ * ```
149
+ */
150
+ function toStandardSchema(schema) {
151
+ return new AiSdkSchemaWrapper(schema);
152
+ }
153
+ //#endregion
154
+ export { AiSdkSchemaWrapper, toStandardSchema };
155
+
3
156
  //# sourceMappingURL=ai-sdk.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"ai-sdk.js"}
1
+ {"version":3,"file":"ai-sdk.js","names":["#schema","#validate","#toJsonSchema","#convertValidationResult","failureResult"],"sources":["../../../src/standard-schema/adapters/ai-sdk.ts"],"sourcesContent":["import type { Schema } from '@internal/ai-v6';\nimport type { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';\nimport type { JSONSchema7 } from 'json-schema';\nimport type { StandardSchemaWithJSON, StandardSchemaWithJSONProps } from '../standard-schema.types';\n\n/**\n * Vendor name for AI SDK wrapped schemas.\n */\nconst VENDOR = 'ai-sdk';\n\n/**\n * A wrapper class that makes AI SDK Schema compatible with @standard-schema/spec.\n *\n * This class implements both `StandardSchemaV1` (validation) and `StandardJSONSchemaV1`\n * (JSON Schema conversion) interfaces. It wraps an AI SDK Schema and adapts its\n * validation method and jsonSchema property to the standard-schema interface.\n *\n * @typeParam T - The TypeScript type that the AI SDK Schema represents\n *\n * @example\n * ```typescript\n * import { jsonSchema } from '@internal/ai-v6';\n * import { toStandardSchema } from '@mastra/schema-compat/adapters/ai-sdk';\n *\n * // Create an AI SDK schema\n * const aiSdkSchema = jsonSchema<{ name: string; age: number }>({\n * type: 'object',\n * properties: {\n * name: { type: 'string' },\n * age: { type: 'number' },\n * },\n * required: ['name', 'age'],\n * });\n *\n * // Convert to standard-schema\n * const standardSchema = toStandardSchema(aiSdkSchema);\n *\n * // Use validation (from StandardSchemaV1)\n * const result = standardSchema['~standard'].validate({ name: 'John', age: 30 });\n *\n * // Get JSON Schema (from StandardJSONSchemaV1)\n * const jsonSchema = standardSchema['~standard'].jsonSchema.output({ target: 'draft-07' });\n * ```\n */\nexport class AiSdkSchemaWrapper<Input = unknown, Output = Input> implements StandardSchemaWithJSON<Input, Output> {\n readonly #schema: Schema<Output>;\n readonly '~standard': StandardSchemaWithJSONProps<Input, Output>;\n\n constructor(schema: Schema<Output>) {\n this.#schema = schema;\n\n // Create the ~standard property\n this['~standard'] = {\n version: 1,\n vendor: VENDOR,\n validate: this.#validate.bind(this),\n jsonSchema: {\n input: this.#toJsonSchema.bind(this),\n output: this.#toJsonSchema.bind(this),\n },\n };\n }\n\n /**\n * Validates a value against the AI SDK Schema.\n *\n * @param value - The value to validate\n * @returns A result object with either the validated value or validation issues\n */\n #validate(value: unknown): StandardSchemaV1.Result<Output> | Promise<StandardSchemaV1.Result<Output>> {\n // Check if the schema has a validate method (it's optional on AI SDK Schema)\n if (!this.#schema.validate) {\n // If no validate method, we can't validate - just pass through\n return { value: value as Output };\n }\n\n try {\n const result = this.#schema.validate(value);\n\n // Handle both sync and async validation results\n // The AI SDK Schema.validate returns ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>\n // We need to check if it's a thenable (promise-like)\n if (result && typeof result === 'object' && 'then' in result && typeof result.then === 'function') {\n // Wrap PromiseLike in a proper Promise to satisfy the StandardSchemaV1 interface\n return Promise.resolve(\n result as PromiseLike<{ success: true; value: Output } | { success: false; error: Error }>,\n )\n .then(res => this.#convertValidationResult(res))\n .catch((error: unknown) => {\n // Convert rejected promises to the expected { issues: [...] } shape\n const message = error instanceof Error ? error.message : 'Unknown validation error';\n return {\n issues: [{ message: `Schema validation error: ${message}` }],\n } as StandardSchemaV1.Result<Output>;\n });\n }\n\n // It's a sync result\n return this.#convertValidationResult(\n result as { success: true; value: Output } | { success: false; error: Error },\n );\n } catch (error) {\n // If validation fails unexpectedly, return a validation error\n const message = error instanceof Error ? error.message : 'Unknown validation error';\n return {\n issues: [{ message: `Schema validation error: ${message}` }],\n };\n }\n }\n\n /**\n * Converts an AI SDK ValidationResult to a StandardSchemaV1.Result.\n *\n * @param result - The AI SDK validation result\n * @returns A StandardSchemaV1.Result\n */\n #convertValidationResult(\n result: { success: true; value: Output } | { success: false; error: Error },\n ): StandardSchemaV1.Result<Output> {\n if (result.success) {\n return { value: result.value };\n }\n\n // Convert the AI SDK error to a Standard Schema issue\n // Cast to the failure type since TypeScript can't narrow discriminated unions with private field access\n const failureResult = result as { success: false; error: Error };\n return {\n issues: [{ message: failureResult.error.message }],\n };\n }\n\n /**\n * Returns the JSON Schema in the requested target format.\n *\n * @param options - Options including the target format\n * @returns The JSON Schema as a Record\n */\n #toJsonSchema(options: StandardJSONSchemaV1.Options): Record<string, unknown> {\n const { target } = options;\n\n // Clone the schema to avoid mutations\n const clonedSchema = JSON.parse(JSON.stringify(this.#schema.jsonSchema)) as Record<string, unknown>;\n\n // Add $schema if not present, based on target\n if (!clonedSchema.$schema) {\n switch (target) {\n case 'draft-07':\n clonedSchema.$schema = 'http://json-schema.org/draft-07/schema#';\n break;\n case 'draft-2020-12':\n clonedSchema.$schema = 'https://json-schema.org/draft/2020-12/schema';\n break;\n case 'openapi-3.0':\n // OpenAPI 3.0 doesn't use $schema\n break;\n default:\n // For unknown targets, don't add $schema\n break;\n }\n }\n\n return clonedSchema;\n }\n\n /**\n * Returns the original AI SDK Schema.\n */\n getSchema(): Schema<Output> {\n return this.#schema;\n }\n\n /**\n * Returns the original JSON Schema from the AI SDK Schema.\n */\n getJsonSchema(): JSONSchema7 {\n return this.#schema.jsonSchema as JSONSchema7;\n }\n}\n\n/**\n * Wraps an AI SDK Schema to implement the full @standard-schema/spec interface.\n *\n * This function creates a wrapper that implements both `StandardSchemaV1` (validation)\n * and `StandardJSONSchemaV1` (JSON Schema conversion) interfaces.\n *\n * @typeParam T - The TypeScript type that the AI SDK Schema represents\n * @param schema - The AI SDK Schema to wrap\n * @returns A wrapper implementing StandardSchemaWithJSON\n *\n * @example\n * ```typescript\n * import { jsonSchema } from '@internal/ai-v6';\n * import { toStandardSchema } from '@mastra/schema-compat/adapters/ai-sdk';\n *\n * const aiSdkSchema = jsonSchema<{ name: string; age: number }>({\n * type: 'object',\n * properties: {\n * name: { type: 'string' },\n * age: { type: 'number' },\n * },\n * required: ['name', 'age'],\n * });\n *\n * const standardSchema = toStandardSchema(aiSdkSchema);\n *\n * // Validate data\n * const result = standardSchema['~standard'].validate({ name: 'John', age: 30 });\n *\n * // Get JSON Schema\n * const jsonSchema = standardSchema['~standard'].jsonSchema.output({ target: 'draft-07' });\n * ```\n */\nexport function toStandardSchema<T = unknown>(schema: Schema<T>): AiSdkSchemaWrapper<T, T> {\n return new AiSdkSchemaWrapper<T, T>(schema);\n}\n"],"mappings":";;;;AAQA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCf,IAAa,qBAAb,MAAkH;CAChH;CACA;CAEA,YAAY,QAAwB;EAClC,KAAKA,UAAU;EAGf,KAAK,eAAe;GAClB,SAAS;GACT,QAAQ;GACR,UAAU,KAAKC,UAAU,KAAK,IAAI;GAClC,YAAY;IACV,OAAO,KAAKC,cAAc,KAAK,IAAI;IACnC,QAAQ,KAAKA,cAAc,KAAK,IAAI;GACtC;EACF;CACF;;;;;;;CAQA,UAAU,OAA4F;EAEpG,IAAI,CAAC,KAAKF,QAAQ,UAEhB,OAAO,EAAS,MAAgB;EAGlC,IAAI;GACF,MAAM,SAAS,KAAKA,QAAQ,SAAS,KAAK;GAK1C,IAAI,UAAU,OAAO,WAAW,YAAY,UAAU,UAAU,OAAO,OAAO,SAAS,YAErF,OAAO,QAAQ,QACb,MACF,CAAC,CACE,MAAK,QAAO,KAAKG,yBAAyB,GAAG,CAAC,CAAC,CAC/C,OAAO,UAAmB;IAGzB,OAAO,EACL,QAAQ,CAAC,EAAE,SAAS,4BAFN,iBAAiB,QAAQ,MAAM,UAAU,6BAEG,CAAC,EAC7D;GACF,CAAC;GAIL,OAAO,KAAKA,yBACV,MACF;EACF,SAAS,OAAO;GAGd,OAAO,EACL,QAAQ,CAAC,EAAE,SAAS,4BAFN,iBAAiB,QAAQ,MAAM,UAAU,6BAEG,CAAC,EAC7D;EACF;CACF;;;;;;;CAQA,yBACE,QACiC;EACjC,IAAI,OAAO,SACT,OAAO,EAAE,OAAO,OAAO,MAAM;EAM/B,OAAO,EACL,QAAQ,CAAC,EAAE,SAASC,OAAc,MAAM,QAAQ,CAAC,EACnD;CACF;;;;;;;CAQA,cAAc,SAAgE;EAC5E,MAAM,EAAE,WAAW;EAGnB,MAAM,eAAe,KAAK,MAAM,KAAK,UAAU,KAAKJ,QAAQ,UAAU,CAAC;EAGvE,IAAI,CAAC,aAAa,SAChB,QAAQ,QAAR;GACE,KAAK;IACH,aAAa,UAAU;IACvB;GACF,KAAK;IACH,aAAa,UAAU;IACvB;GACF,KAAK,eAEH;GACF,SAEE;EACJ;EAGF,OAAO;CACT;;;;CAKA,YAA4B;EAC1B,OAAO,KAAKA;CACd;;;;CAKA,gBAA6B;EAC3B,OAAO,KAAKA,QAAQ;CACtB;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,SAAgB,iBAA8B,QAA6C;CACzF,OAAO,IAAI,mBAAyB,MAAM;AAC5C"}
@@ -1,16 +1,4 @@
1
- 'use strict';
2
-
3
- var chunk77T2HV4Q_cjs = require('../../chunk-77T2HV4Q.cjs');
4
-
5
-
6
-
7
- Object.defineProperty(exports, "JsonSchemaWrapper", {
8
- enumerable: true,
9
- get: function () { return chunk77T2HV4Q_cjs.JsonSchemaWrapper; }
10
- });
11
- Object.defineProperty(exports, "toStandardSchema", {
12
- enumerable: true,
13
- get: function () { return chunk77T2HV4Q_cjs.toStandardSchema; }
14
- });
15
- //# sourceMappingURL=json-schema.cjs.map
16
- //# sourceMappingURL=json-schema.cjs.map
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_json_schema = require("../../json-schema-pcL1TeZs.cjs");
3
+ exports.JsonSchemaWrapper = require_json_schema.JsonSchemaWrapper;
4
+ exports.toStandardSchema = require_json_schema.toStandardSchema;
@@ -1,3 +1,2 @@
1
- export { JsonSchemaWrapper, toStandardSchema } from '../../chunk-RMMKMUYK.js';
2
- //# sourceMappingURL=json-schema.js.map
3
- //# sourceMappingURL=json-schema.js.map
1
+ import { n as toStandardSchema, t as JsonSchemaWrapper } from "../../json-schema-BstKYbJi.js";
2
+ export { JsonSchemaWrapper, toStandardSchema };
@@ -1,12 +1,103 @@
1
- 'use strict';
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_rolldown_runtime = require("../../rolldown-runtime-emK7D4bc.cjs");
3
+ const require_json_schema_traverse$1 = require("../../json-schema-traverse-CSNSaf0y.cjs");
4
+ let zod_to_json_schema = require("zod-to-json-schema");
5
+ zod_to_json_schema = require_rolldown_runtime.__toESM(zod_to_json_schema, 1);
6
+ //#region src/standard-schema/adapters/zod-v3.ts
7
+ var import_json_schema_traverse = /* @__PURE__ */ require_rolldown_runtime.__toESM(require_json_schema_traverse$1.require_json_schema_traverse(), 1);
8
+ /**
9
+ * Target mapping from Standard Schema targets to zod-to-json-schema targets.
10
+ */
11
+ const TARGET_MAP = {
12
+ "draft-04": "jsonSchema7",
13
+ "draft-07": "jsonSchema7",
14
+ "draft-2020-12": "jsonSchema2019-09",
15
+ "openapi-3.0": "openApi3"
16
+ };
17
+ /**
18
+ * Converts a Zod schema to JSON Schema using the specified target format.
19
+ *
20
+ * @param zodSchema - The Zod schema to convert
21
+ * @param options - Standard Schema JSON options including the target format
22
+ * @returns The JSON Schema representation
23
+ * @throws Error if the target format is not supported
24
+ *
25
+ * @internal
26
+ */
27
+ function convertToJsonSchema(zodSchema, options) {
28
+ const target = TARGET_MAP[options.target];
29
+ if (!target) {
30
+ const supportedTargets = Object.keys(TARGET_MAP);
31
+ throw new Error(`Unsupported JSON Schema target: "${options.target}". Supported targets are: ${supportedTargets.join(", ")}`);
32
+ }
33
+ const jsonSchema = (0, zod_to_json_schema.default)(zodSchema, {
34
+ $refStrategy: "none",
35
+ target,
36
+ override: (def) => {
37
+ if (def.typeName === "ZodDate") return {
38
+ type: "string",
39
+ format: "date-time",
40
+ "x-date": true
41
+ };
42
+ return zod_to_json_schema.ignoreOverride;
43
+ }
44
+ });
45
+ (0, import_json_schema_traverse.default)(jsonSchema, { cb: { pre: (schema) => {
46
+ if (schema.type === "string" && schema.format === "email") schema.pattern = `^(?!\\.)(?!.*\\.\\.)([A-Za-z0-9_'+\\-\\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$`;
47
+ } } });
48
+ return jsonSchema;
49
+ }
50
+ /**
51
+ * Wraps a Zod v3 schema to implement the full @standard-schema/spec interface.
52
+ *
53
+ * While Zod v3 natively implements `StandardSchemaV1` (validation), it does not
54
+ * implement `StandardJSONSchemaV1` (JSON Schema conversion). This adapter adds
55
+ * the `jsonSchema` property to provide JSON Schema conversion capabilities.
56
+ *
57
+ * @typeParam T - The Zod schema type
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * import { z } from 'zod';
62
+ * import { toStandardSchema } from '@mastra/schema-compat/adapters/zod-v3';
63
+ *
64
+ * const userSchema = z.object({
65
+ * name: z.string(),
66
+ * age: z.number().min(0),
67
+ * });
68
+ *
69
+ * const standardSchema = toStandardSchema(userSchema);
70
+ *
71
+ * // Use validation (from StandardSchemaV1)
72
+ * const result = standardSchema['~standard'].validate({ name: 'John', age: 30 });
73
+ *
74
+ * // Get JSON Schema (from StandardJSONSchemaV1)
75
+ * const jsonSchema = standardSchema['~standard'].jsonSchema.output({ target: 'draft-07' });
76
+ * ```
77
+ */
78
+ function toStandardSchema(zodSchema) {
79
+ const wrapper = Object.create(zodSchema);
80
+ const existingStandard = zodSchema["~standard"];
81
+ const jsonSchemaConverter = {
82
+ input: (options) => {
83
+ return convertToJsonSchema(zodSchema, options);
84
+ },
85
+ output: (options) => {
86
+ return convertToJsonSchema(zodSchema, options);
87
+ }
88
+ };
89
+ Object.defineProperty(wrapper, "~standard", {
90
+ value: {
91
+ ...existingStandard,
92
+ jsonSchema: jsonSchemaConverter
93
+ },
94
+ writable: false,
95
+ enumerable: true,
96
+ configurable: false
97
+ });
98
+ return wrapper;
99
+ }
100
+ //#endregion
101
+ exports.toStandardSchema = toStandardSchema;
2
102
 
3
- var chunkBQ3VTMIR_cjs = require('../../chunk-BQ3VTMIR.cjs');
4
-
5
-
6
-
7
- Object.defineProperty(exports, "toStandardSchema", {
8
- enumerable: true,
9
- get: function () { return chunkBQ3VTMIR_cjs.toStandardSchema; }
10
- });
11
- //# sourceMappingURL=zod-v3.cjs.map
12
103
  //# sourceMappingURL=zod-v3.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"zod-v3.cjs"}
1
+ {"version":3,"file":"zod-v3.cjs","names":["ignoreOverride"],"sources":["../../../src/standard-schema/adapters/zod-v3.ts"],"sourcesContent":["import type { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';\nimport traverse from 'json-schema-traverse';\n// Use zod/v3 types for v3 compatibility (v4's v3-compat layer)\nimport type { ZodType, ZodTypeDef } from 'zod/v3';\nimport zodToJsonSchemaOriginal, { ignoreOverride } from 'zod-to-json-schema';\nimport type {\n StandardSchemaWithJSON,\n StandardSchemaWithJSONProps,\n ZodToJsonSchemaTarget,\n} from '../standard-schema.types';\n/**\n * Target mapping from Standard Schema targets to zod-to-json-schema targets.\n */\nconst TARGET_MAP: Record<string, ZodToJsonSchemaTarget> = {\n 'draft-04': 'jsonSchema7',\n 'draft-07': 'jsonSchema7',\n 'draft-2020-12': 'jsonSchema2019-09',\n 'openapi-3.0': 'openApi3',\n};\n\n/**\n * Converts a Zod schema to JSON Schema using the specified target format.\n *\n * @param zodSchema - The Zod schema to convert\n * @param options - Standard Schema JSON options including the target format\n * @returns The JSON Schema representation\n * @throws Error if the target format is not supported\n *\n * @internal\n */\nfunction convertToJsonSchema<T extends ZodType<any, ZodTypeDef, any>>(\n zodSchema: T,\n options: StandardJSONSchemaV1.Options,\n): Record<string, unknown> {\n const target = TARGET_MAP[options.target];\n\n if (!target) {\n // For unknown targets, try to use jsonSchema7 as fallback or throw\n const supportedTargets = Object.keys(TARGET_MAP);\n throw new Error(\n `Unsupported JSON Schema target: \"${options.target}\". ` + `Supported targets are: ${supportedTargets.join(', ')}`,\n );\n }\n\n const jsonSchema = zodToJsonSchemaOriginal(zodSchema, {\n $refStrategy: 'none',\n target,\n override: (def: any) => {\n // Mark z.date() with x-date for downstream string→Date conversion.\n // Zod v3 has no z.coerce.date(), so all dates are strict.\n if (def.typeName === 'ZodDate') {\n return { type: 'string', format: 'date-time', 'x-date': true };\n }\n return ignoreOverride;\n },\n });\n\n traverse(jsonSchema, {\n cb: {\n pre: schema => {\n if (schema.type === 'string' && schema.format === 'email') {\n schema.pattern = `^(?!\\\\.)(?!.*\\\\.\\\\.)([A-Za-z0-9_'+\\\\-\\\\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\\\\-]*\\\\.)+[A-Za-z]{2,}$`;\n }\n },\n // post: (schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema) => {\n // this.postProcessJSONNode(schema, parentSchema);\n // },\n },\n });\n\n return jsonSchema as Record<string, unknown>;\n}\n\n/**\n * Wraps a Zod v3 schema to implement the full @standard-schema/spec interface.\n *\n * While Zod v3 natively implements `StandardSchemaV1` (validation), it does not\n * implement `StandardJSONSchemaV1` (JSON Schema conversion). This adapter adds\n * the `jsonSchema` property to provide JSON Schema conversion capabilities.\n *\n * @typeParam T - The Zod schema type\n *\n * @example\n * ```typescript\n * import { z } from 'zod';\n * import { toStandardSchema } from '@mastra/schema-compat/adapters/zod-v3';\n *\n * const userSchema = z.object({\n * name: z.string(),\n * age: z.number().min(0),\n * });\n *\n * const standardSchema = toStandardSchema(userSchema);\n *\n * // Use validation (from StandardSchemaV1)\n * const result = standardSchema['~standard'].validate({ name: 'John', age: 30 });\n *\n * // Get JSON Schema (from StandardJSONSchemaV1)\n * const jsonSchema = standardSchema['~standard'].jsonSchema.output({ target: 'draft-07' });\n * ```\n */\nexport function toStandardSchema<T>(zodSchema: ZodType<T, ZodTypeDef, T>): T & StandardSchemaWithJSON<T, T> {\n // Create a wrapper object that includes the jsonSchema converter\n const wrapper = Object.create(zodSchema) as T & StandardSchemaWithJSON<T, T>;\n\n // Get the existing ~standard property from Zod\n const existingStandard = zodSchema['~standard'] as StandardSchemaV1.Props<T, T>;\n\n // Create the JSON Schema converter\n const jsonSchemaConverter: StandardJSONSchemaV1.Converter = {\n input: (options: StandardJSONSchemaV1.Options): Record<string, unknown> => {\n return convertToJsonSchema(zodSchema, options);\n },\n output: (options: StandardJSONSchemaV1.Options): Record<string, unknown> => {\n // For Zod schemas, input and output JSON Schema are typically the same\n // unless using transforms, which would need special handling\n return convertToJsonSchema(zodSchema, options);\n },\n };\n\n // Define the enhanced ~standard property\n Object.defineProperty(wrapper, '~standard', {\n value: {\n ...existingStandard,\n jsonSchema: jsonSchemaConverter,\n } satisfies StandardSchemaWithJSONProps<T, T>,\n writable: false,\n enumerable: true,\n configurable: false,\n });\n\n return wrapper;\n}\n"],"mappings":";;;;;;;;;;AAaA,MAAM,aAAoD;CACxD,YAAY;CACZ,YAAY;CACZ,iBAAiB;CACjB,eAAe;AACjB;;;;;;;;;;;AAYA,SAAS,oBACP,WACA,SACyB;CACzB,MAAM,SAAS,WAAW,QAAQ;CAElC,IAAI,CAAC,QAAQ;EAEX,MAAM,mBAAmB,OAAO,KAAK,UAAU;EAC/C,MAAM,IAAI,MACR,oCAAoC,QAAQ,OAAO,4BAAiC,iBAAiB,KAAK,IAAI,GAChH;CACF;CAEA,MAAM,cAAA,GAAA,mBAAA,QAAA,CAAqC,WAAW;EACpD,cAAc;EACd;EACA,WAAW,QAAa;GAGtB,IAAI,IAAI,aAAa,WACnB,OAAO;IAAE,MAAM;IAAU,QAAQ;IAAa,UAAU;GAAK;GAE/D,OAAOA,mBAAAA;EACT;CACF,CAAC;CAED,CAAA,GAAA,4BAAA,QAAA,CAAS,YAAY,EACnB,IAAI,EACF,MAAK,WAAU;EACb,IAAI,OAAO,SAAS,YAAY,OAAO,WAAW,SAChD,OAAO,UAAU;CAErB,EAIF,EACF,CAAC;CAED,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,SAAgB,iBAAoB,WAAwE;CAE1G,MAAM,UAAU,OAAO,OAAO,SAAS;CAGvC,MAAM,mBAAmB,UAAU;CAGnC,MAAM,sBAAsD;EAC1D,QAAQ,YAAmE;GACzE,OAAO,oBAAoB,WAAW,OAAO;EAC/C;EACA,SAAS,YAAmE;GAG1E,OAAO,oBAAoB,WAAW,OAAO;EAC/C;CACF;CAGA,OAAO,eAAe,SAAS,aAAa;EAC1C,OAAO;GACL,GAAG;GACH,YAAY;EACd;EACA,UAAU;EACV,YAAY;EACZ,cAAc;CAChB,CAAC;CAED,OAAO;AACT"}