{"version":3,"sources":["../src/standard-schema/adapters/zod-v3.ts"],"names":["__toESM","require_json_schema_traverse","zodToJsonSchemaOriginal","ignoreOverride","traverse"],"mappings":";;;;;;;;;;;AACA,IAAA,2BAAA,GAAqBA,yBAAA,CAAAC,8CAAA,EAAA,EAAA,CAAA,CAAA;AAYrB,IAAM,UAAA,GAAoD;AAAA,EACxD,UAAA,EAAY,aAAA;AAAA,EACZ,UAAA,EAAY,aAAA;AAAA,EACZ,eAAA,EAAiB,mBAAA;AAAA,EACjB,aAAA,EAAe;AACjB,CAAA;AAYA,SAAS,mBAAA,CACP,WACA,OAAA,EACyB;AACzB,EAAA,MAAM,MAAA,GAAS,UAAA,CAAW,OAAA,CAAQ,MAAM,CAAA;AAExC,EAAA,IAAI,CAAC,MAAA,EAAQ;AAEX,IAAA,MAAM,gBAAA,GAAmB,MAAA,CAAO,IAAA,CAAK,UAAU,CAAA;AAC/C,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,oCAAoC,OAAA,CAAQ,MAAM,6BAAkC,gBAAA,CAAiB,IAAA,CAAK,IAAI,CAAC,CAAA;AAAA,KACjH;AAAA,EACF;AAEA,EAAA,MAAM,UAAA,GAAaC,yCAAwB,SAAA,EAAW;AAAA,IACpD,YAAA,EAAc,MAAA;AAAA,IACd,MAAA;AAAA,IACA,QAAA,EAAU,CAAC,GAAA,KAAa;AAGtB,MAAA,IAAI,GAAA,CAAI,aAAa,SAAA,EAAW;AAC9B,QAAA,OAAO,EAAE,IAAA,EAAM,QAAA,EAAU,MAAA,EAAQ,WAAA,EAAa,UAAU,IAAA,EAAK;AAAA,MAC/D;AACA,MAAA,OAAOC,sCAAA;AAAA,IACT;AAAA,GACD,CAAA;AAED,EAAA,IAAA,2BAAA,CAAAC,SAAS,UAAA,EAAY;AAAA,IACnB,EAAA,EAAI;AAAA,MACF,KAAK,CAAA,MAAA,KAAU;AACb,QAAA,IAAI,MAAA,CAAO,IAAA,KAAS,QAAA,IAAY,MAAA,CAAO,WAAW,OAAA,EAAS;AACzD,UAAA,MAAA,CAAO,OAAA,GAAU,CAAA,uGAAA,CAAA;AAAA,QACnB;AAAA,MACF;AAAA;AAAA;AAAA;AAAA;AAIF,GACD,CAAA;AAED,EAAA,OAAO,UAAA;AACT;AA8BO,SAAS,iBAAoB,SAAA,EAAwE;AAE1G,EAAA,MAAM,OAAA,GAAU,MAAA,CAAO,MAAA,CAAO,SAAS,CAAA;AAGvC,EAAA,MAAM,gBAAA,GAAmB,UAAU,WAAW,CAAA;AAG9C,EAAA,MAAM,mBAAA,GAAsD;AAAA,IAC1D,KAAA,EAAO,CAAC,OAAA,KAAmE;AACzE,MAAA,OAAO,mBAAA,CAAoB,WAAW,OAAO,CAAA;AAAA,IAC/C,CAAA;AAAA,IACA,MAAA,EAAQ,CAAC,OAAA,KAAmE;AAG1E,MAAA,OAAO,mBAAA,CAAoB,WAAW,OAAO,CAAA;AAAA,IAC/C;AAAA,GACF;AAGA,EAAA,MAAA,CAAO,cAAA,CAAe,SAAS,WAAA,EAAa;AAAA,IAC1C,KAAA,EAAO;AAAA,MACL,GAAG,gBAAA;AAAA,MACH,UAAA,EAAY;AAAA,KACd;AAAA,IACA,QAAA,EAAU,KAAA;AAAA,IACV,UAAA,EAAY,IAAA;AAAA,IACZ,YAAA,EAAc;AAAA,GACf,CAAA;AAED,EAAA,OAAO,OAAA;AACT","file":"chunk-BQ3VTMIR.cjs","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 = {\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>(\n zodSchema: T,\n options: StandardJSONSchemaV1.Options,\n): Record {\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;\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(zodSchema: ZodType): T & StandardSchemaWithJSON {\n // Create a wrapper object that includes the jsonSchema converter\n const wrapper = Object.create(zodSchema) as T & StandardSchemaWithJSON;\n\n // Get the existing ~standard property from Zod\n const existingStandard = zodSchema['~standard'] as StandardSchemaV1.Props;\n\n // Create the JSON Schema converter\n const jsonSchemaConverter: StandardJSONSchemaV1.Converter = {\n input: (options: StandardJSONSchemaV1.Options): Record => {\n return convertToJsonSchema(zodSchema, options);\n },\n output: (options: StandardJSONSchemaV1.Options): Record => {\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,\n writable: false,\n enumerable: true,\n configurable: false,\n });\n\n return wrapper;\n}\n"]}