@mastra/schema-compat 1.1.3 → 1.2.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/CHANGELOG.md +68 -0
- package/LICENSE.md +15 -0
- package/dist/_types/@internal_ai-sdk-v4/dist/index.d.ts +7562 -0
- package/dist/_types/@internal_ai-v6/dist/index.d.ts +449 -343
- package/dist/chunk-23HDOZLF.js +105 -0
- package/dist/chunk-23HDOZLF.js.map +1 -0
- package/dist/chunk-3MLZICLP.cjs +94 -0
- package/dist/chunk-3MLZICLP.cjs.map +1 -0
- package/dist/chunk-3QMIGINL.cjs +123 -0
- package/dist/chunk-3QMIGINL.cjs.map +1 -0
- package/dist/{chunk-4EY4LZB2.js → chunk-7ZCSAPV3.js} +76 -3
- package/dist/chunk-7ZCSAPV3.js.map +1 -0
- package/dist/chunk-FKB2Z36H.cjs +68 -0
- package/dist/chunk-FKB2Z36H.cjs.map +1 -0
- package/dist/chunk-FS3P4V5M.cjs +108 -0
- package/dist/chunk-FS3P4V5M.cjs.map +1 -0
- package/dist/chunk-I2YUBGXM.js +112 -0
- package/dist/chunk-I2YUBGXM.js.map +1 -0
- package/dist/chunk-IKQO7EW7.js +62 -0
- package/dist/chunk-IKQO7EW7.js.map +1 -0
- package/dist/chunk-K7I3YXWP.js +92 -0
- package/dist/chunk-K7I3YXWP.js.map +1 -0
- package/dist/{chunk-DGOXVQNP.js → chunk-QDRBTCDV.js} +158 -479
- package/dist/chunk-QDRBTCDV.js.map +1 -0
- package/dist/{chunk-DAVEUCUM.cjs → chunk-ROFMEFEF.cjs} +160 -488
- package/dist/chunk-ROFMEFEF.cjs.map +1 -0
- package/dist/{chunk-BOGGUXB5.cjs → chunk-UFJG5KPA.cjs} +77 -2
- package/dist/chunk-UFJG5KPA.cjs.map +1 -0
- package/dist/index.cjs +626 -337
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +580 -325
- package/dist/index.js.map +1 -1
- package/dist/json-schema/utils.d.ts +8 -0
- package/dist/json-schema/utils.d.ts.map +1 -1
- package/dist/null-to-undefined.d.ts +24 -0
- package/dist/null-to-undefined.d.ts.map +1 -0
- package/dist/provider-compats/google.d.ts +3 -0
- package/dist/provider-compats/google.d.ts.map +1 -1
- package/dist/provider-compats/openai-reasoning.d.ts +5 -5
- package/dist/provider-compats/openai-reasoning.d.ts.map +1 -1
- package/dist/provider-compats/openai.d.ts +8 -0
- package/dist/provider-compats/openai.d.ts.map +1 -1
- package/dist/schema-compatibility-v3.d.ts +2 -2
- package/dist/schema-compatibility-v3.d.ts.map +1 -1
- package/dist/schema-compatibility.d.ts +2 -1
- package/dist/schema-compatibility.d.ts.map +1 -1
- package/dist/schema.cjs +16 -4
- package/dist/schema.d.ts +1 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +1 -1
- package/dist/schema.types.d.ts +4 -2
- package/dist/schema.types.d.ts.map +1 -1
- package/dist/standard-schema/adapters/ai-sdk.cjs +16 -0
- package/dist/standard-schema/adapters/ai-sdk.cjs.map +1 -0
- package/dist/standard-schema/adapters/ai-sdk.js +3 -0
- package/dist/standard-schema/adapters/ai-sdk.js.map +1 -0
- package/dist/standard-schema/adapters/json-schema.cjs +16 -0
- package/dist/standard-schema/adapters/json-schema.cjs.map +1 -0
- package/dist/standard-schema/adapters/json-schema.d.ts.map +1 -1
- package/dist/standard-schema/adapters/json-schema.js +3 -0
- package/dist/standard-schema/adapters/json-schema.js.map +1 -0
- package/dist/standard-schema/adapters/zod-v3.cjs +12 -0
- package/dist/standard-schema/adapters/zod-v3.cjs.map +1 -0
- package/dist/standard-schema/adapters/zod-v3.js +3 -0
- package/dist/standard-schema/adapters/zod-v3.js.map +1 -0
- package/dist/standard-schema/standard-schema.d.ts.map +1 -1
- package/dist/standard-schema-compat.d.ts +74 -0
- package/dist/standard-schema-compat.d.ts.map +1 -0
- package/dist/utils.d.ts +3 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/zod-to-json.cjs +10 -2
- package/dist/zod-to-json.d.ts +13 -0
- package/dist/zod-to-json.d.ts.map +1 -1
- package/dist/zod-to-json.js +1 -1
- package/package.json +41 -10
- package/dist/chunk-4EY4LZB2.js.map +0 -1
- package/dist/chunk-BOGGUXB5.cjs.map +0 -1
- package/dist/chunk-DAVEUCUM.cjs.map +0 -1
- package/dist/chunk-DGOXVQNP.js.map +0 -1
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// src/standard-schema/adapters/ai-sdk.ts
|
|
2
|
+
var VENDOR = "ai-sdk";
|
|
3
|
+
var AiSdkSchemaWrapper = class {
|
|
4
|
+
#schema;
|
|
5
|
+
"~standard";
|
|
6
|
+
constructor(schema) {
|
|
7
|
+
this.#schema = schema;
|
|
8
|
+
this["~standard"] = {
|
|
9
|
+
version: 1,
|
|
10
|
+
vendor: VENDOR,
|
|
11
|
+
validate: this.#validate.bind(this),
|
|
12
|
+
jsonSchema: {
|
|
13
|
+
input: this.#toJsonSchema.bind(this),
|
|
14
|
+
output: this.#toJsonSchema.bind(this)
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Validates a value against the AI SDK Schema.
|
|
20
|
+
*
|
|
21
|
+
* @param value - The value to validate
|
|
22
|
+
* @returns A result object with either the validated value or validation issues
|
|
23
|
+
*/
|
|
24
|
+
#validate(value) {
|
|
25
|
+
if (!this.#schema.validate) {
|
|
26
|
+
return { value };
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const result = this.#schema.validate(value);
|
|
30
|
+
if (result && typeof result === "object" && "then" in result && typeof result.then === "function") {
|
|
31
|
+
return Promise.resolve(
|
|
32
|
+
result
|
|
33
|
+
).then((res) => this.#convertValidationResult(res)).catch((error) => {
|
|
34
|
+
const message = error instanceof Error ? error.message : "Unknown validation error";
|
|
35
|
+
return {
|
|
36
|
+
issues: [{ message: `Schema validation error: ${message}` }]
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return this.#convertValidationResult(
|
|
41
|
+
result
|
|
42
|
+
);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
const message = error instanceof Error ? error.message : "Unknown validation error";
|
|
45
|
+
return {
|
|
46
|
+
issues: [{ message: `Schema validation error: ${message}` }]
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Converts an AI SDK ValidationResult to a StandardSchemaV1.Result.
|
|
52
|
+
*
|
|
53
|
+
* @param result - The AI SDK validation result
|
|
54
|
+
* @returns A StandardSchemaV1.Result
|
|
55
|
+
*/
|
|
56
|
+
#convertValidationResult(result) {
|
|
57
|
+
if (result.success) {
|
|
58
|
+
return { value: result.value };
|
|
59
|
+
}
|
|
60
|
+
const failureResult = result;
|
|
61
|
+
return {
|
|
62
|
+
issues: [{ message: failureResult.error.message }]
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Returns the JSON Schema in the requested target format.
|
|
67
|
+
*
|
|
68
|
+
* @param options - Options including the target format
|
|
69
|
+
* @returns The JSON Schema as a Record
|
|
70
|
+
*/
|
|
71
|
+
#toJsonSchema(options) {
|
|
72
|
+
const { target } = options;
|
|
73
|
+
const clonedSchema = JSON.parse(JSON.stringify(this.#schema.jsonSchema));
|
|
74
|
+
if (!clonedSchema.$schema) {
|
|
75
|
+
switch (target) {
|
|
76
|
+
case "draft-07":
|
|
77
|
+
clonedSchema.$schema = "http://json-schema.org/draft-07/schema#";
|
|
78
|
+
break;
|
|
79
|
+
case "draft-2020-12":
|
|
80
|
+
clonedSchema.$schema = "https://json-schema.org/draft/2020-12/schema";
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return clonedSchema;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Returns the original AI SDK Schema.
|
|
88
|
+
*/
|
|
89
|
+
getSchema() {
|
|
90
|
+
return this.#schema;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Returns the original JSON Schema from the AI SDK Schema.
|
|
94
|
+
*/
|
|
95
|
+
getJsonSchema() {
|
|
96
|
+
return this.#schema.jsonSchema;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
function toStandardSchema(schema) {
|
|
100
|
+
return new AiSdkSchemaWrapper(schema);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export { AiSdkSchemaWrapper, toStandardSchema };
|
|
104
|
+
//# sourceMappingURL=chunk-23HDOZLF.js.map
|
|
105
|
+
//# sourceMappingURL=chunk-23HDOZLF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/standard-schema/adapters/ai-sdk.ts"],"names":[],"mappings":";AAQA,IAAM,MAAA,GAAS,QAAA;AAoCR,IAAM,qBAAN,MAA2G;AAAA,EACvG,OAAA;AAAA,EACA,WAAA;AAAA,EAET,YAAY,MAAA,EAAwB;AAClC,IAAA,IAAA,CAAK,OAAA,GAAU,MAAA;AAGf,IAAA,IAAA,CAAK,WAAW,CAAA,GAAI;AAAA,MAClB,OAAA,EAAS,CAAA;AAAA,MACT,MAAA,EAAQ,MAAA;AAAA,MACR,QAAA,EAAU,IAAA,CAAK,SAAA,CAAU,IAAA,CAAK,IAAI,CAAA;AAAA,MAClC,UAAA,EAAY;AAAA,QACV,KAAA,EAAO,IAAA,CAAK,aAAA,CAAc,IAAA,CAAK,IAAI,CAAA;AAAA,QACnC,MAAA,EAAQ,IAAA,CAAK,aAAA,CAAc,IAAA,CAAK,IAAI;AAAA;AACtC,KACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,UAAU,KAAA,EAA4F;AAEpG,IAAA,IAAI,CAAC,IAAA,CAAK,OAAA,CAAQ,QAAA,EAAU;AAE1B,MAAA,OAAO,EAAE,KAAA,EAAuB;AAAA,IAClC;AAEA,IAAA,IAA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AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,cAAc,OAAA,EAAgE;AAC5E,IAAA,MAAM,EAAE,QAAO,GAAI,OAAA;AAGnB,IAAA,MAAM,YAAA,GAAe,KAAK,KAAA,CAAM,IAAA,CAAK,UAAU,IAAA,CAAK,OAAA,CAAQ,UAAU,CAAC,CAAA;AAGvE,IAAA,IAAI,CAAC,aAAa,OAAA,EAAS;AACzB,MAAA,QAAQ,MAAA;AAAQ,QACd,KAAK,UAAA;AACH,UAAA,YAAA,CAAa,OAAA,GAAU,yCAAA;AACvB,UAAA;AAAA,QACF,KAAK,eAAA;AACH,UAAA,YAAA,CAAa,OAAA,GAAU,8CAAA;AACvB,UAAA;AAMA;AACJ,IACF;AAEA,IAAA,OAAO,YAAA;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,SAAA,GAA4B;AAC1B,IAAA,OAAO,IAAA,CAAK,OAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,aAAA,GAA6B;AAC3B,IAAA,OAAO,KAAK,OAAA,CAAQ,UAAA;AAAA,EACtB;AACF;AAmCO,SAAS,iBAA8B,MAAA,EAA6C;AACzF,EAAA,OAAO,IAAI,mBAAyB,MAAM,CAAA;AAC5C","file":"chunk-23HDOZLF.js","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"]}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkDZUJEN5N_cjs = require('./chunk-DZUJEN5N.cjs');
|
|
4
|
+
|
|
5
|
+
// ../../node_modules/.pnpm/json-schema-traverse@1.0.0/node_modules/json-schema-traverse/index.js
|
|
6
|
+
var require_json_schema_traverse = chunkDZUJEN5N_cjs.__commonJS({
|
|
7
|
+
"../../node_modules/.pnpm/json-schema-traverse@1.0.0/node_modules/json-schema-traverse/index.js"(exports$1, module) {
|
|
8
|
+
var traverse = module.exports = function(schema, opts, cb) {
|
|
9
|
+
if (typeof opts == "function") {
|
|
10
|
+
cb = opts;
|
|
11
|
+
opts = {};
|
|
12
|
+
}
|
|
13
|
+
cb = opts.cb || cb;
|
|
14
|
+
var pre = typeof cb == "function" ? cb : cb.pre || function() {
|
|
15
|
+
};
|
|
16
|
+
var post = cb.post || function() {
|
|
17
|
+
};
|
|
18
|
+
_traverse(opts, pre, post, schema, "", schema);
|
|
19
|
+
};
|
|
20
|
+
traverse.keywords = {
|
|
21
|
+
additionalItems: true,
|
|
22
|
+
items: true,
|
|
23
|
+
contains: true,
|
|
24
|
+
additionalProperties: true,
|
|
25
|
+
propertyNames: true,
|
|
26
|
+
not: true,
|
|
27
|
+
if: true,
|
|
28
|
+
then: true,
|
|
29
|
+
else: true
|
|
30
|
+
};
|
|
31
|
+
traverse.arrayKeywords = {
|
|
32
|
+
items: true,
|
|
33
|
+
allOf: true,
|
|
34
|
+
anyOf: true,
|
|
35
|
+
oneOf: true
|
|
36
|
+
};
|
|
37
|
+
traverse.propsKeywords = {
|
|
38
|
+
$defs: true,
|
|
39
|
+
definitions: true,
|
|
40
|
+
properties: true,
|
|
41
|
+
patternProperties: true,
|
|
42
|
+
dependencies: true
|
|
43
|
+
};
|
|
44
|
+
traverse.skipKeywords = {
|
|
45
|
+
default: true,
|
|
46
|
+
enum: true,
|
|
47
|
+
const: true,
|
|
48
|
+
required: true,
|
|
49
|
+
maximum: true,
|
|
50
|
+
minimum: true,
|
|
51
|
+
exclusiveMaximum: true,
|
|
52
|
+
exclusiveMinimum: true,
|
|
53
|
+
multipleOf: true,
|
|
54
|
+
maxLength: true,
|
|
55
|
+
minLength: true,
|
|
56
|
+
pattern: true,
|
|
57
|
+
format: true,
|
|
58
|
+
maxItems: true,
|
|
59
|
+
minItems: true,
|
|
60
|
+
uniqueItems: true,
|
|
61
|
+
maxProperties: true,
|
|
62
|
+
minProperties: true
|
|
63
|
+
};
|
|
64
|
+
function _traverse(opts, pre, post, schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex) {
|
|
65
|
+
if (schema && typeof schema == "object" && !Array.isArray(schema)) {
|
|
66
|
+
pre(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex);
|
|
67
|
+
for (var key in schema) {
|
|
68
|
+
var sch = schema[key];
|
|
69
|
+
if (Array.isArray(sch)) {
|
|
70
|
+
if (key in traverse.arrayKeywords) {
|
|
71
|
+
for (var i = 0; i < sch.length; i++)
|
|
72
|
+
_traverse(opts, pre, post, sch[i], jsonPtr + "/" + key + "/" + i, rootSchema, jsonPtr, key, schema, i);
|
|
73
|
+
}
|
|
74
|
+
} else if (key in traverse.propsKeywords) {
|
|
75
|
+
if (sch && typeof sch == "object") {
|
|
76
|
+
for (var prop in sch)
|
|
77
|
+
_traverse(opts, pre, post, sch[prop], jsonPtr + "/" + key + "/" + escapeJsonPtr(prop), rootSchema, jsonPtr, key, schema, prop);
|
|
78
|
+
}
|
|
79
|
+
} else if (key in traverse.keywords || opts.allKeys && !(key in traverse.skipKeywords)) {
|
|
80
|
+
_traverse(opts, pre, post, sch, jsonPtr + "/" + key, rootSchema, jsonPtr, key, schema);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
post(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function escapeJsonPtr(str) {
|
|
87
|
+
return str.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
exports.require_json_schema_traverse = require_json_schema_traverse;
|
|
93
|
+
//# sourceMappingURL=chunk-3MLZICLP.cjs.map
|
|
94
|
+
//# sourceMappingURL=chunk-3MLZICLP.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../node_modules/.pnpm/json-schema-traverse@1.0.0/node_modules/json-schema-traverse/index.js"],"names":["__commonJS","exports"],"mappings":";;;;;AAAA,IAAA,4BAAA,GAAAA,4BAAA,CA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Content":["'use strict';\n\nvar traverse = module.exports = function (schema, opts, cb) {\n // Legacy support for v0.3.1 and earlier.\n if (typeof opts == 'function') {\n cb = opts;\n opts = {};\n }\n\n cb = opts.cb || cb;\n var pre = (typeof cb == 'function') ? cb : cb.pre || function() {};\n var post = cb.post || function() {};\n\n _traverse(opts, pre, post, schema, '', schema);\n};\n\n\ntraverse.keywords = {\n additionalItems: true,\n items: true,\n contains: true,\n additionalProperties: true,\n propertyNames: true,\n not: true,\n if: true,\n then: true,\n else: true\n};\n\ntraverse.arrayKeywords = {\n items: true,\n allOf: true,\n anyOf: true,\n oneOf: true\n};\n\ntraverse.propsKeywords = {\n $defs: true,\n definitions: true,\n properties: true,\n patternProperties: true,\n dependencies: true\n};\n\ntraverse.skipKeywords = {\n default: true,\n enum: true,\n const: true,\n required: true,\n maximum: true,\n minimum: true,\n exclusiveMaximum: true,\n exclusiveMinimum: true,\n multipleOf: true,\n maxLength: true,\n minLength: true,\n pattern: true,\n format: true,\n maxItems: true,\n minItems: true,\n uniqueItems: true,\n maxProperties: true,\n minProperties: true\n};\n\n\nfunction _traverse(opts, pre, post, schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex) {\n if (schema && typeof schema == 'object' && !Array.isArray(schema)) {\n pre(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex);\n for (var key in schema) {\n var sch = schema[key];\n if (Array.isArray(sch)) {\n if (key in traverse.arrayKeywords) {\n for (var i=0; i<sch.length; i++)\n _traverse(opts, pre, post, sch[i], jsonPtr + '/' + key + '/' + i, rootSchema, jsonPtr, key, schema, i);\n }\n } else if (key in traverse.propsKeywords) {\n if (sch && typeof sch == 'object') {\n for (var prop in sch)\n _traverse(opts, pre, post, sch[prop], jsonPtr + '/' + key + '/' + escapeJsonPtr(prop), rootSchema, jsonPtr, key, schema, prop);\n }\n } else if (key in traverse.keywords || (opts.allKeys && !(key in traverse.skipKeywords))) {\n _traverse(opts, pre, post, sch, jsonPtr + '/' + key, rootSchema, jsonPtr, key, schema);\n }\n }\n post(schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex);\n }\n}\n\n\nfunction escapeJsonPtr(str) {\n return str.replace(/~/g, '~0').replace(/\\//g, '~1');\n}\n"]}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkFS3P4V5M_cjs = require('./chunk-FS3P4V5M.cjs');
|
|
4
|
+
var chunkROFMEFEF_cjs = require('./chunk-ROFMEFEF.cjs');
|
|
5
|
+
var chunkFKB2Z36H_cjs = require('./chunk-FKB2Z36H.cjs');
|
|
6
|
+
var z3 = require('zod/v3');
|
|
7
|
+
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var z3__default = /*#__PURE__*/_interopDefault(z3);
|
|
11
|
+
|
|
12
|
+
function jsonSchemaOverride(ctx) {
|
|
13
|
+
const zodSchema = ctx.zodSchema;
|
|
14
|
+
if (ctx.jsonSchema.type === "object" && ctx.jsonSchema.properties !== void 0 && !ctx.jsonSchema.additionalProperties) {
|
|
15
|
+
ctx.jsonSchema.additionalProperties = false;
|
|
16
|
+
}
|
|
17
|
+
if (zodSchema) {
|
|
18
|
+
if (zodSchema?.type === "date") {
|
|
19
|
+
ctx.jsonSchema.type = "string";
|
|
20
|
+
ctx.jsonSchema.format = "date-time";
|
|
21
|
+
} else if (zodSchema?.type === "object" && zodSchema._zod?.def?.catchall?.type === "unknown") {
|
|
22
|
+
ctx.jsonSchema.additionalProperties = true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return void 0;
|
|
26
|
+
}
|
|
27
|
+
var JSON_SCHEMA_LIBRARY_OPTIONS = {
|
|
28
|
+
unrepresentable: "any",
|
|
29
|
+
override: jsonSchemaOverride
|
|
30
|
+
};
|
|
31
|
+
function isVercelSchema(schema) {
|
|
32
|
+
return typeof schema === "object" && schema !== null && "_type" in schema && "jsonSchema" in schema && typeof schema.jsonSchema === "object";
|
|
33
|
+
}
|
|
34
|
+
function isZodV4(schema) {
|
|
35
|
+
return typeof schema === "object" && schema !== null && "_zod" in schema;
|
|
36
|
+
}
|
|
37
|
+
function isZodV3(schema) {
|
|
38
|
+
if (schema === null || typeof schema !== "object") {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
if (isZodV4(schema)) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
if ("~standard" in schema) {
|
|
45
|
+
const std = schema["~standard"];
|
|
46
|
+
if (typeof std === "object" && std !== null && std.vendor === "zod" && !("jsonSchema" in std)) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return schema instanceof z3__default.default.ZodType;
|
|
51
|
+
}
|
|
52
|
+
function toStandardSchema4(schema) {
|
|
53
|
+
if (isStandardSchemaWithJSON(schema)) {
|
|
54
|
+
return schema;
|
|
55
|
+
}
|
|
56
|
+
if (isZodV3(schema)) {
|
|
57
|
+
return chunkFKB2Z36H_cjs.toStandardSchema(schema);
|
|
58
|
+
}
|
|
59
|
+
if (isVercelSchema(schema)) {
|
|
60
|
+
return chunkFS3P4V5M_cjs.toStandardSchema(schema);
|
|
61
|
+
}
|
|
62
|
+
if (schema === null || typeof schema !== "object" && typeof schema !== "function") {
|
|
63
|
+
throw new Error(`Unsupported schema type: ${typeof schema}`);
|
|
64
|
+
}
|
|
65
|
+
if (typeof schema === "function") {
|
|
66
|
+
throw new Error(`Unsupported schema type: function (schema libraries should implement StandardSchemaWithJSON)`);
|
|
67
|
+
}
|
|
68
|
+
return chunkROFMEFEF_cjs.toStandardSchema(schema);
|
|
69
|
+
}
|
|
70
|
+
function isStandardSchema(value) {
|
|
71
|
+
if (value === null || typeof value !== "object" && typeof value !== "function") {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
if (!("~standard" in value)) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
const std = value["~standard"];
|
|
78
|
+
return typeof std === "object" && std !== null && "version" in std && std.version === 1 && "vendor" in std && "validate" in std && typeof std.validate === "function";
|
|
79
|
+
}
|
|
80
|
+
function isStandardJSONSchema(value) {
|
|
81
|
+
if (value === null || typeof value !== "object" && typeof value !== "function") {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
if (!("~standard" in value)) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
const std = value["~standard"];
|
|
88
|
+
if (typeof std !== "object" || std === null) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
if (!("version" in std) || std.version !== 1 || !("vendor" in std)) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
if (!("jsonSchema" in std) || typeof std.jsonSchema !== "object") {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
return typeof std.jsonSchema.input === "function" && typeof std.jsonSchema.output === "function";
|
|
98
|
+
}
|
|
99
|
+
function isStandardSchemaWithJSON(value) {
|
|
100
|
+
return isStandardSchema(value) && isStandardJSONSchema(value);
|
|
101
|
+
}
|
|
102
|
+
function standardSchemaToJSONSchema(schema, options = {}) {
|
|
103
|
+
const { target = "draft-07", io = "output", override = JSON_SCHEMA_LIBRARY_OPTIONS.override } = options;
|
|
104
|
+
const jsonSchemaFn = schema["~standard"].jsonSchema[io];
|
|
105
|
+
let jsonSchema = jsonSchemaFn({
|
|
106
|
+
target,
|
|
107
|
+
libraryOptions: {
|
|
108
|
+
...JSON_SCHEMA_LIBRARY_OPTIONS,
|
|
109
|
+
override
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
jsonSchema = JSON.parse(JSON.stringify(jsonSchema));
|
|
113
|
+
return jsonSchema;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
exports.JSON_SCHEMA_LIBRARY_OPTIONS = JSON_SCHEMA_LIBRARY_OPTIONS;
|
|
117
|
+
exports.isStandardJSONSchema = isStandardJSONSchema;
|
|
118
|
+
exports.isStandardSchema = isStandardSchema;
|
|
119
|
+
exports.isStandardSchemaWithJSON = isStandardSchemaWithJSON;
|
|
120
|
+
exports.standardSchemaToJSONSchema = standardSchemaToJSONSchema;
|
|
121
|
+
exports.toStandardSchema = toStandardSchema4;
|
|
122
|
+
//# sourceMappingURL=chunk-3QMIGINL.cjs.map
|
|
123
|
+
//# sourceMappingURL=chunk-3QMIGINL.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/standard-schema/standard-schema.ts"],"names":["z3","toStandardSchema"],"mappings":";;;;;;;;;;;AAgBA,SAAS,mBAAmB,GAAA,EAA6E;AACvG,EAAA,MAAM,YAAY,GAAA,CAAI,SAAA;AAEtB,EAAA,IACE,GAAA,CAAI,UAAA,CAAW,IAAA,KAAS,QAAA,IACxB,GAAA,CAAI,UAAA,CAAW,UAAA,KAAe,MAAA,IAC9B,CAAC,GAAA,CAAI,UAAA,CAAW,oBAAA,EAChB;AACA,IAAA,GAAA,CAAI,WAAW,oBAAA,GAAuB,KAAA;AAAA,EACxC;AAEA,EAAA,IAAI,SAAA,EAAW;AAEb,IAAA,IAAI,SAAA,EAAW,SAAS,MAAA,EAAQ;AAC9B,MAAA,GAAA,CAAI,WAAW,IAAA,GAAO,QAAA;AACtB,MAAA,GAAA,CAAI,WAAW,MAAA,GAAS,WAAA;AAAA,IAE1B,CAAA,MAAA,IAAW,WAAW,IAAA,KAAS,QAAA,IAAY,UAAU,IAAA,EAAM,GAAA,EAAK,QAAA,EAAU,IAAA,KAAS,SAAA,EAAW;AAC5F,MAAA,GAAA,CAAI,WAAW,oBAAA,GAAuB,IAAA;AAAA,IACxC;AAAA,EACF;AAEA,EAAA,OAAO,MAAA;AACT;AAOO,IAAM,2BAAA,GAA8B;AAAA,EACzC,eAAA,EAAiB,KAAA;AAAA,EACjB,QAAA,EAAU;AACZ;AAUA,SAAS,eAAe,MAAA,EAAmC;AACzD,EAAA,OACE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AAY,GAAA,CAAA,EAAM;AAClE,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,IAAI,EAAE,YAAA,IAAgB,GAAA,CAAA,IAAQ,OAAO,GAAA,CAAI,eAAe,QAAA,EAAU;AAChE,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,OAAO,IAAI,UAAA,CAAW,KAAA,KAAU,cAAc,OAAO,GAAA,CAAI,WAAW,MAAA,KAAW,UAAA;AACxF;AAmBO,SAAS,yBAAyB,KAAA,EAAiD;AACxF,EAAA,OAAO,gBAAA,CAAiB,KAAK,CAAA,IAAK,oBAAA,CAAqB,KAAK,CAAA;AAC9D;AA4BO,SAAS,0BAAA,CACd,MAAA,EACA,OAAA,GAII,EAAC,EACQ;AACb,EAAA,MAAM,EAAE,SAAS,UAAA,EAAY,EAAA,GAAK,UAAU,QAAA,GAAW,2BAAA,CAA4B,UAAS,GAAI,OAAA;AAChG,EAAA,MAAM,YAAA,GAAe,MAAA,CAAO,WAAW,CAAA,CAAE,WAAW,EAAE,CAAA;AACtD,EAAA,IAAI,aAAa,YAAA,CAAa;AAAA,IAC5B,MAAA;AAAA,IACA,cAAA,EAAgB;AAAA,MACd,GAAG,2BAAA;AAAA,MACH;AAAA;AACF,GACD,CAAA;AAGD,EAAA,UAAA,GAAa,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,SAAA,CAAU,UAAU,CAAC,CAAA;AAElD,EAAA,OAAO,UAAA;AACT","file":"chunk-3QMIGINL.cjs","sourcesContent":["import type { Schema } from '@internal/ai-v6';\nimport type { StandardJSONSchemaV1, StandardSchemaV1 } from '@standard-schema/spec';\nimport type { JSONSchema7 } from 'json-schema';\nimport z3 from 'zod/v3';\nimport type { ZodType } from 'zod/v3';\nimport type { PublicSchema } from '../schema.types';\nimport { toStandardSchema as toStandardSchemaAiSdk } from './adapters/ai-sdk';\nimport { toStandardSchema as toStandardSchemaJsonSchema } from './adapters/json-schema';\nimport { toStandardSchema as toStandardSchemaZodV3 } from './adapters/zod-v3';\nimport type { StandardSchemaWithJSON } from './standard-schema.types';\n\n/**\n * Override function for JSON Schema conversion.\n * Handles types that Zod v4 cannot natively represent in JSON Schema:\n * - z.date() -> { type: 'string', format: 'date-time' }\n */\nfunction jsonSchemaOverride(ctx: { zodSchema: unknown; jsonSchema: Record<string, unknown> }): undefined {\n const zodSchema = ctx.zodSchema as { type?: string; _zod?: { def?: { type?: string } }; optional?: () => unknown };\n\n if (\n ctx.jsonSchema.type === 'object' &&\n ctx.jsonSchema.properties !== undefined &&\n !ctx.jsonSchema.additionalProperties\n ) {\n ctx.jsonSchema.additionalProperties = false;\n }\n\n if (zodSchema) {\n // Convert z.date() to JSON Schema string with date-time format\n if (zodSchema?.type === 'date') {\n ctx.jsonSchema.type = 'string';\n ctx.jsonSchema.format = 'date-time';\n // @ts-expect-error - catchall is a valid property for zod\n } else if (zodSchema?.type === 'object' && zodSchema._zod?.def?.catchall?.type === 'unknown') {\n ctx.jsonSchema.additionalProperties = true;\n }\n }\n\n return undefined;\n}\n/**\n * Library options for JSON Schema conversion.\n * - unrepresentable: 'any' allows z.custom() and other unrepresentable types to be converted to {}\n * instead of throwing \"Custom types cannot be represented in JSON Schema\"\n * - override: converts z.date() to { type: 'string', format: 'date-time' }\n */\nexport const JSON_SCHEMA_LIBRARY_OPTIONS = {\n unrepresentable: 'any' as const,\n override: jsonSchemaOverride,\n};\n\nexport type {\n StandardSchemaWithJSON,\n StandardSchemaWithJSONProps,\n InferInput,\n InferOutput,\n StandardSchemaIssue,\n} from './standard-schema.types';\n\nfunction isVercelSchema(schema: unknown): schema is Schema {\n return (\n typeof schema === 'object' &&\n schema !== null &&\n '_type' in schema &&\n 'jsonSchema' in schema &&\n typeof (schema as Schema).jsonSchema === 'object'\n );\n}\n\n/**\n * Check if a schema is Zod v4 (has _zod property which is v4-only)\n */\nfunction isZodV4(schema: unknown): boolean {\n return typeof schema === 'object' && schema !== null && '_zod' in schema;\n}\n\n/**\n * Check if a schema is Zod v3.\n *\n * Zod v3 can come from:\n * 1. The old standalone 'zod-v3' package\n * 2. The 'zod/v3' compat export from modern zod\n *\n * We detect Zod v3 by checking:\n * - Has ~standard.vendor === 'zod' (both v3 and v4 have this)\n * - Does NOT have ~standard.jsonSchema (only Zod v4 has native JSON Schema support)\n * - Does NOT have _zod property (only Zod v4 has this)\n *\n * Note: We can't use instanceof z3.ZodType because the old 'zod-v3' package\n * has a different prototype chain than 'zod/v3'.\n */\nfunction isZodV3(schema: unknown): schema is ZodType {\n if (schema === null || typeof schema !== 'object') {\n return false;\n }\n\n // Must not be Zod v4\n if (isZodV4(schema)) {\n return false;\n }\n\n // Check for ~standard with vendor 'zod' but no jsonSchema\n if ('~standard' in schema) {\n const std = (schema as any)['~standard'];\n if (typeof std === 'object' && std !== null && std.vendor === 'zod' && !('jsonSchema' in std)) {\n return true;\n }\n }\n\n // Fallback: check instanceof for zod/v3 compat export\n return schema instanceof z3.ZodType;\n}\n\nexport function toStandardSchema<T = unknown>(schema: PublicSchema<T>): StandardSchemaWithJSON<T> {\n // First check: if already StandardSchemaWithJSON, return as-is\n // This handles ArkType, Zod v4 (when it has jsonSchema), and pre-wrapped schemas\n if (isStandardSchemaWithJSON(schema)) {\n return schema;\n }\n\n // Check for Zod v3 schemas (need wrapping to add JSON Schema support)\n // Important: Must use isZodV3() not instanceof z3.ZodType because\n // Zod v4 schemas are also instanceof z3.ZodType due to prototype compatibility\n if (isZodV3(schema)) {\n return toStandardSchemaZodV3(schema as ZodType);\n }\n\n // Check for AI SDK Schema objects (Vercel's jsonSchema wrapper)\n if (isVercelSchema(schema)) {\n return toStandardSchemaAiSdk(schema as Schema<T>);\n }\n\n // At this point, assume it's a plain JSON Schema object\n // JSON Schema objects are plain objects with properties like 'type', 'properties', etc.\n if (schema === null || (typeof schema !== 'object' && typeof schema !== 'function')) {\n throw new Error(`Unsupported schema type: ${typeof schema}`);\n }\n\n // If it's a function that's not StandardSchemaWithJSON, it's not supported\n if (typeof schema === 'function') {\n throw new Error(`Unsupported schema type: function (schema libraries should implement StandardSchemaWithJSON)`);\n }\n\n return toStandardSchemaJsonSchema(schema as JSONSchema7);\n}\n\n/**\n * Type guard to check if a value implements the StandardSchemaV1 interface.\n *\n * @param value - The value to check\n * @returns True if the value implements StandardSchemaV1\n *\n * @example\n * ```typescript\n * import { isStandardSchema } from '@mastra/schema-compat';\n *\n * if (isStandardSchema(someValue)) {\n * const result = someValue['~standard'].validate(input);\n * }\n * ```\n */\nexport function isStandardSchema(value: unknown): value is StandardSchemaV1 {\n // Check for object or function (some libraries like ArkType use callable schemas)\n if (value === null || (typeof value !== 'object' && typeof value !== 'function')) {\n return false;\n }\n if (!('~standard' in value)) {\n return false;\n }\n const std = (value as any)['~standard'];\n return (\n typeof std === 'object' &&\n std !== null &&\n 'version' in std &&\n std.version === 1 &&\n 'vendor' in std &&\n 'validate' in std &&\n typeof std.validate === 'function'\n );\n}\n\n/**\n * Type guard to check if a value implements the StandardJSONSchemaV1 interface.\n *\n * @param value - The value to check\n * @returns True if the value implements StandardJSONSchemaV1\n *\n * @example\n * ```typescript\n * import { isStandardJSONSchema } from '@mastra/schema-compat';\n *\n * if (isStandardJSONSchema(someValue)) {\n * const jsonSchema = someValue['~standard'].jsonSchema.output({ target: 'draft-07' });\n * }\n * ```\n */\nexport function isStandardJSONSchema(value: unknown): value is StandardJSONSchemaV1 {\n // Check for object or function (some libraries like ArkType use callable schemas)\n if (value === null || (typeof value !== 'object' && typeof value !== 'function')) {\n return false;\n }\n if (!('~standard' in value)) {\n return false;\n }\n const std = (value as any)['~standard'];\n if (typeof std !== 'object' || std === null) {\n return false;\n }\n if (!('version' in std) || std.version !== 1 || !('vendor' in std)) {\n return false;\n }\n if (!('jsonSchema' in std) || typeof std.jsonSchema !== 'object') {\n return false;\n }\n return typeof std.jsonSchema.input === 'function' && typeof std.jsonSchema.output === 'function';\n}\n\n/**\n * Type guard to check if a value implements both StandardSchemaV1 and StandardJSONSchemaV1.\n *\n * @param value - The value to check\n * @returns True if the value implements both interfaces\n *\n * @example\n * ```typescript\n * import { isStandardSchemaWithJSON } from '@mastra/schema-compat';\n *\n * if (isStandardSchemaWithJSON(someValue)) {\n * // Can use both validation and JSON Schema conversion\n * const result = someValue['~standard'].validate(input);\n * const jsonSchema = someValue['~standard'].jsonSchema.output({ target: 'draft-07' });\n * }\n * ```\n */\nexport function isStandardSchemaWithJSON(value: unknown): value is StandardSchemaWithJSON {\n return isStandardSchema(value) && isStandardJSONSchema(value);\n}\n\n/**\n * Converts a StandardSchemaWithJSON to a JSON Schema.\n *\n * @param schema - The StandardSchemaWithJSON schema to convert\n * @param options - Conversion options\n * @param options.target - The JSON Schema target version (default: 'draft-07')\n * @param options.io - Whether to use input or output schema (default: 'output')\n * - 'input': Use for tool parameters, function arguments, request bodies\n * - 'output': Use for return types, response bodies\n * @returns The JSON Schema representation\n *\n * @example\n * ```typescript\n * import { standardSchemaToJSONSchema, toStandardSchema } from '@mastra/schema-compat';\n * import { z } from 'zod';\n *\n * const zodSchema = z.object({ name: z.string() });\n * const standardSchema = toStandardSchema(zodSchema);\n *\n * // For output types (default)\n * const outputSchema = standardSchemaToJSONSchema(standardSchema);\n *\n * // For input types (tool parameters)\n * const inputSchema = standardSchemaToJSONSchema(standardSchema, { io: 'input' });\n * ```\n */\nexport function standardSchemaToJSONSchema(\n schema: StandardSchemaWithJSON,\n options: {\n target?: StandardJSONSchemaV1.Target;\n io?: 'input' | 'output';\n override?: (typeof JSON_SCHEMA_LIBRARY_OPTIONS)['override'];\n } = {},\n): JSONSchema7 {\n const { target = 'draft-07', io = 'output', override = JSON_SCHEMA_LIBRARY_OPTIONS.override } = options;\n const jsonSchemaFn = schema['~standard'].jsonSchema[io];\n let jsonSchema = jsonSchemaFn({\n target,\n libraryOptions: {\n ...JSON_SCHEMA_LIBRARY_OPTIONS,\n override,\n },\n }) as JSONSchema7;\n\n // make sure only jsonSchema is left, no standard schema metadata\n jsonSchema = JSON.parse(JSON.stringify(jsonSchema));\n\n return jsonSchema;\n}\n"]}
|
|
@@ -98,6 +98,76 @@ function fixAnyOfNullable(schema) {
|
|
|
98
98
|
}
|
|
99
99
|
return result;
|
|
100
100
|
}
|
|
101
|
+
function ensureAllPropertiesRequired(schema) {
|
|
102
|
+
if (typeof schema !== "object" || schema === null) {
|
|
103
|
+
return schema;
|
|
104
|
+
}
|
|
105
|
+
const result = { ...schema };
|
|
106
|
+
if (result.type === "object" && result.properties) {
|
|
107
|
+
result.required = Object.keys(result.properties);
|
|
108
|
+
result.properties = Object.fromEntries(
|
|
109
|
+
Object.entries(result.properties).map(([key, value]) => [key, ensureAllPropertiesRequired(value)])
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
if (result.items) {
|
|
113
|
+
if (Array.isArray(result.items)) {
|
|
114
|
+
result.items = result.items.map((item) => ensureAllPropertiesRequired(item));
|
|
115
|
+
} else if (typeof result.items === "object") {
|
|
116
|
+
result.items = ensureAllPropertiesRequired(result.items);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (result.additionalProperties && typeof result.additionalProperties === "object") {
|
|
120
|
+
result.additionalProperties = ensureAllPropertiesRequired(result.additionalProperties);
|
|
121
|
+
}
|
|
122
|
+
if (result.anyOf && Array.isArray(result.anyOf)) {
|
|
123
|
+
result.anyOf = result.anyOf.map((s) => ensureAllPropertiesRequired(s));
|
|
124
|
+
}
|
|
125
|
+
if (result.oneOf && Array.isArray(result.oneOf)) {
|
|
126
|
+
result.oneOf = result.oneOf.map((s) => ensureAllPropertiesRequired(s));
|
|
127
|
+
}
|
|
128
|
+
if (result.allOf && Array.isArray(result.allOf)) {
|
|
129
|
+
result.allOf = result.allOf.map((s) => ensureAllPropertiesRequired(s));
|
|
130
|
+
}
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
function prepareJsonSchemaForOpenAIStrictMode(schema) {
|
|
134
|
+
const withRequired = ensureAllPropertiesRequired(schema);
|
|
135
|
+
return ensureAdditionalPropertiesFalse(withRequired);
|
|
136
|
+
}
|
|
137
|
+
function ensureAdditionalPropertiesFalse(schema) {
|
|
138
|
+
if (typeof schema !== "object" || schema === null) {
|
|
139
|
+
return schema;
|
|
140
|
+
}
|
|
141
|
+
const result = { ...schema };
|
|
142
|
+
if (result.type === "object" || result.properties) {
|
|
143
|
+
result.additionalProperties = false;
|
|
144
|
+
}
|
|
145
|
+
if (result.properties) {
|
|
146
|
+
result.properties = Object.fromEntries(
|
|
147
|
+
Object.entries(result.properties).map(([key, value]) => [
|
|
148
|
+
key,
|
|
149
|
+
ensureAdditionalPropertiesFalse(value)
|
|
150
|
+
])
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
if (result.items) {
|
|
154
|
+
if (Array.isArray(result.items)) {
|
|
155
|
+
result.items = result.items.map((item) => ensureAdditionalPropertiesFalse(item));
|
|
156
|
+
} else if (typeof result.items === "object") {
|
|
157
|
+
result.items = ensureAdditionalPropertiesFalse(result.items);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (result.anyOf && Array.isArray(result.anyOf)) {
|
|
161
|
+
result.anyOf = result.anyOf.map((s) => ensureAdditionalPropertiesFalse(s));
|
|
162
|
+
}
|
|
163
|
+
if (result.oneOf && Array.isArray(result.oneOf)) {
|
|
164
|
+
result.oneOf = result.oneOf.map((s) => ensureAdditionalPropertiesFalse(s));
|
|
165
|
+
}
|
|
166
|
+
if (result.allOf && Array.isArray(result.allOf)) {
|
|
167
|
+
result.allOf = result.allOf.map((s) => ensureAdditionalPropertiesFalse(s));
|
|
168
|
+
}
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
101
171
|
function zodToJsonSchema(zodSchema, target = "jsonSchema7", strategy = "relative") {
|
|
102
172
|
if (zodSchema?._zod) {
|
|
103
173
|
patchRecordSchemas(zodSchema);
|
|
@@ -109,6 +179,9 @@ function zodToJsonSchema(zodSchema, target = "jsonSchema7", strategy = "relative
|
|
|
109
179
|
ctx.jsonSchema.type = "string";
|
|
110
180
|
ctx.jsonSchema.format = "date-time";
|
|
111
181
|
}
|
|
182
|
+
if (def && (def.typeName === "ZodObject" || def.type === "object")) {
|
|
183
|
+
ctx.jsonSchema.additionalProperties = false;
|
|
184
|
+
}
|
|
112
185
|
}
|
|
113
186
|
});
|
|
114
187
|
return fixAnyOfNullable(jsonSchema);
|
|
@@ -120,6 +193,6 @@ function zodToJsonSchema(zodSchema, target = "jsonSchema7", strategy = "relative
|
|
|
120
193
|
}
|
|
121
194
|
}
|
|
122
195
|
|
|
123
|
-
export { zodToJsonSchema };
|
|
124
|
-
//# sourceMappingURL=chunk-
|
|
125
|
-
//# sourceMappingURL=chunk-
|
|
196
|
+
export { ensureAllPropertiesRequired, prepareJsonSchemaForOpenAIStrictMode, zodToJsonSchema };
|
|
197
|
+
//# sourceMappingURL=chunk-7ZCSAPV3.js.map
|
|
198
|
+
//# sourceMappingURL=chunk-7ZCSAPV3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/zod-to-json.ts"],"names":["zV4"],"mappings":";;;;AAOA,IAAM,OAAA,0BAAiB,oBAAoB,CAAA;AAO3C,SAAS,mBAAmB,MAAA,EAAkB;AAC5C,EAAA,IAAI,CAAC,MAAA,IAAU,OAAO,MAAA,KAAW,UAAU,OAAO,MAAA;AAGlD,EAAA,IAAK,MAAA,CAAe,OAAO,CAAA,EAAG,OAAO,MAAA;AACrC,EAAC,MAAA,CAAe,OAAO,CAAA,GAAI,IAAA;AAG3B,EAAA,MAAM,GAAA,GAAM,OAAO,IAAA,EAAM,GAAA;AAGzB,EAAA,IAAI,KAAK,IAAA,KAAS,QAAA,IAAY,IAAI,OAAA,IAAW,CAAC,IAAI,SAAA,EAAW;AAG3D,IAAA,GAAA,CAAI,YAAY,GAAA,CAAI,OAAA;AACpB,IAAA,GAAA,CAAI,OAAA,GAAUA,EAAI,MAAA,EAAO;AAAA,EAC3B;AAGA,EAAA,IAAI,CAAC,KAAK,OAAO,MAAA;AAEjB,EAAA,IAAI,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,GAAA,CAAI,QAAA,KAAa,SAAA,IAAa,GAAA,CAAI,SAAS,MAAA,CAAA,EAAS;AAC9D,UAAA,GAAA,CAAI,WAAW,IAAA,GAAO,QAAA;AACtB,UAAA,GAAA,CAAI,WAAW,MAAA,GAAS,WAAA;AAAA,QAC1B;AAGA,QAAA,IAAI,QAAQ,GAAA,CAAI,QAAA,KAAa,WAAA,IAAe,GAAA,CAAI,SAAS,QAAA,CAAA,EAAW;AAClE,UAAA,GAAA,CAAI,WAAW,oBAAA,GAAuB,KAAA;AAAA,QACxC;AAAA,MACF;AAAA,KACD,CAAA;AAGD,IAAA,OAAO,iBAAiB,UAAU,CAAA;AAAA,EACpC,CAAA,MAAO;AAEL,IAAA,OAAO,wBAAwB,SAAA,EAA0B;AAAA,MACvD,YAAA,EAAc,QAAA;AAAA,MACd;AAAA,KACD,CAAA;AAAA,EACH;AACF","file":"chunk-7ZCSAPV3.js","sourcesContent":["import type { JSONSchema7 } from 'json-schema';\nimport type { ZodSchema as ZodSchemaV3 } from 'zod/v3';\nimport { z as zV4 } from 'zod/v4';\nimport type { Targets } from 'zod-to-json-schema';\nimport zodToJsonSchemaOriginal from 'zod-to-json-schema';\n\n// Symbol to mark schemas as already patched (for idempotency)\nconst PATCHED = Symbol('__mastra_patched__');\n\n/**\n * Recursively patch Zod v4 record schemas that are missing valueType.\n * This fixes a bug in Zod v4 where z.record(valueSchema) doesn't set def.valueType.\n * The single-arg form should set valueType but instead only sets keyType.\n */\nfunction patchRecordSchemas(schema: any): any {\n if (!schema || typeof schema !== 'object') return schema;\n\n // Skip if already patched (idempotency check)\n if ((schema as any)[PATCHED]) return schema;\n (schema as any)[PATCHED] = true;\n\n // Check the _zod.def location (v4 structure)\n const def = schema._zod?.def;\n\n // Fix record schemas with missing valueType\n if (def?.type === 'record' && def.keyType && !def.valueType) {\n // The bug: z.record(valueSchema) puts the value in keyType instead of valueType\n // Fix: move it to valueType and set keyType to string (the default)\n def.valueType = def.keyType;\n def.keyType = zV4.string();\n }\n\n // Recursively patch nested schemas\n if (!def) return schema;\n\n if (def.type === 'object' && def.shape) {\n const shape = typeof def.shape === 'function' ? def.shape() : def.shape;\n for (const key of Object.keys(shape)) {\n patchRecordSchemas(shape[key]);\n }\n }\n\n if (def.type === 'array' && def.element) {\n patchRecordSchemas(def.element);\n }\n\n if (def.type === 'union' && def.options) {\n def.options.forEach(patchRecordSchemas);\n }\n\n if (def.type === 'record') {\n if (def.keyType) patchRecordSchemas(def.keyType);\n if (def.valueType) patchRecordSchemas(def.valueType);\n }\n\n // Handle intersection types\n if (def.type === 'intersection') {\n if (def.left) patchRecordSchemas(def.left);\n if (def.right) patchRecordSchemas(def.right);\n }\n\n // Handle lazy types - patch the schema returned by the getter\n if (def.type === 'lazy') {\n // For lazy schemas, we need to patch the schema when it's accessed\n // Store the original getter and wrap it\n if (def.getter && typeof def.getter === 'function') {\n const originalGetter = def.getter;\n def.getter = function () {\n const innerSchema = originalGetter();\n if (innerSchema) {\n patchRecordSchemas(innerSchema);\n }\n return innerSchema;\n };\n }\n }\n\n // Handle wrapper types that have innerType\n // This covers: optional, nullable, default, catch, nullish, and any other wrappers\n if (def.innerType) {\n patchRecordSchemas(def.innerType);\n }\n\n return schema;\n}\n\n/**\n * Recursively fixes anyOf patterns that some providers (like OpenAI) don't accept.\n * Converts anyOf: [{type: X}, {type: \"null\"}] to type: [X, \"null\"]\n * Also fixes empty {} property schemas by converting to a union of primitive types.\n */\nfunction fixAnyOfNullable(schema: JSONSchema7): JSONSchema7 {\n if (typeof schema !== 'object' || schema === null) {\n return schema;\n }\n\n const result = { ...schema };\n\n // Fix anyOf pattern: [{type: X}, {type: \"null\"}] or [{type: \"null\"}, {type: X}]\n if (result.anyOf && Array.isArray(result.anyOf) && result.anyOf.length === 2) {\n const nullSchema = result.anyOf.find((s: any) => typeof s === 'object' && s !== null && s.type === 'null');\n const otherSchema = result.anyOf.find((s: any) => typeof s === 'object' && s !== null && s.type !== 'null');\n\n if (nullSchema && otherSchema && typeof otherSchema === 'object' && otherSchema.type) {\n // Convert anyOf to type array format\n // Normalize sibling fields (like properties/items) before returning\n const { anyOf, ...rest } = result;\n const fixedRest = fixAnyOfNullable(rest as JSONSchema7);\n const fixedOther = fixAnyOfNullable(otherSchema as JSONSchema7);\n return {\n ...fixedRest,\n ...fixedOther,\n type: (Array.isArray(fixedOther.type)\n ? [...fixedOther.type, 'null']\n : [fixedOther.type, 'null']) as JSONSchema7['type'],\n };\n }\n }\n\n // Fix empty property schemas {} - OpenAI requires a type key\n if (result.properties && typeof result.properties === 'object' && !Array.isArray(result.properties)) {\n result.properties = Object.fromEntries(\n Object.entries(result.properties).map(([key, value]) => {\n const propSchema = value as JSONSchema7;\n\n // If property is an empty object {}, convert to allow primitive types\n // Note: We exclude 'object' (requires additionalProperties) and 'array' (requires items) for OpenAI\n if (\n typeof propSchema === 'object' &&\n propSchema !== null &&\n !Array.isArray(propSchema) &&\n Object.keys(propSchema).length === 0\n ) {\n return [key, { type: ['string', 'number', 'boolean', 'null'] as JSONSchema7['type'] }];\n }\n\n // Recursively fix nested schemas\n return [key, fixAnyOfNullable(propSchema)];\n }),\n );\n }\n\n // Recursively fix items in arrays\n if (result.items) {\n if (Array.isArray(result.items)) {\n result.items = result.items.map(item => fixAnyOfNullable(item as JSONSchema7));\n } else {\n result.items = fixAnyOfNullable(result.items as JSONSchema7);\n }\n }\n\n // Recursively fix anyOf/oneOf/allOf schemas\n if (result.anyOf && Array.isArray(result.anyOf)) {\n result.anyOf = result.anyOf.map(s => fixAnyOfNullable(s as JSONSchema7));\n }\n if (result.oneOf && Array.isArray(result.oneOf)) {\n result.oneOf = result.oneOf.map(s => fixAnyOfNullable(s as JSONSchema7));\n }\n if (result.allOf && Array.isArray(result.allOf)) {\n result.allOf = result.allOf.map(s => fixAnyOfNullable(s as JSONSchema7));\n }\n\n return result;\n}\n\n/**\n * Recursively ensures all properties in an object schema are included in the `required` array.\n * OpenAI's strict structured output mode requires every key in `properties` to also appear in `required`.\n *\n * @param schema - The JSON Schema to process\n * @returns A new schema with all properties marked as required\n */\nexport function ensureAllPropertiesRequired(schema: JSONSchema7): JSONSchema7 {\n if (typeof schema !== 'object' || schema === null) {\n return schema;\n }\n\n const result = { ...schema };\n\n if (result.type === 'object' && result.properties) {\n result.required = Object.keys(result.properties);\n result.properties = Object.fromEntries(\n Object.entries(result.properties).map(([key, value]) => [key, ensureAllPropertiesRequired(value as JSONSchema7)]),\n );\n }\n\n if (result.items) {\n if (Array.isArray(result.items)) {\n result.items = result.items.map(item => ensureAllPropertiesRequired(item as JSONSchema7));\n } else if (typeof result.items === 'object') {\n result.items = ensureAllPropertiesRequired(result.items as JSONSchema7);\n }\n }\n\n if (result.additionalProperties && typeof result.additionalProperties === 'object') {\n result.additionalProperties = ensureAllPropertiesRequired(result.additionalProperties as JSONSchema7);\n }\n\n if (result.anyOf && Array.isArray(result.anyOf)) {\n result.anyOf = result.anyOf.map(s => ensureAllPropertiesRequired(s as JSONSchema7));\n }\n if (result.oneOf && Array.isArray(result.oneOf)) {\n result.oneOf = result.oneOf.map(s => ensureAllPropertiesRequired(s as JSONSchema7));\n }\n if (result.allOf && Array.isArray(result.allOf)) {\n result.allOf = result.allOf.map(s => ensureAllPropertiesRequired(s as JSONSchema7));\n }\n\n return result;\n}\n\n/**\n * Prepare a JSON Schema for OpenAI strict mode by ensuring all object properties\n * are required and all objects have additionalProperties: false.\n */\nexport function prepareJsonSchemaForOpenAIStrictMode(schema: JSONSchema7): JSONSchema7 {\n const withRequired = ensureAllPropertiesRequired(schema);\n return ensureAdditionalPropertiesFalse(withRequired);\n}\n\nfunction ensureAdditionalPropertiesFalse(schema: JSONSchema7): JSONSchema7 {\n if (typeof schema !== 'object' || schema === null) {\n return schema;\n }\n\n const result = { ...schema };\n\n if (result.type === 'object' || result.properties) {\n result.additionalProperties = false;\n }\n\n if (result.properties) {\n result.properties = Object.fromEntries(\n Object.entries(result.properties).map(([key, value]) => [\n key,\n ensureAdditionalPropertiesFalse(value as JSONSchema7),\n ]),\n );\n }\n\n if (result.items) {\n if (Array.isArray(result.items)) {\n result.items = result.items.map(item => ensureAdditionalPropertiesFalse(item as JSONSchema7));\n } else if (typeof result.items === 'object') {\n result.items = ensureAdditionalPropertiesFalse(result.items as JSONSchema7);\n }\n }\n\n if (result.anyOf && Array.isArray(result.anyOf)) {\n result.anyOf = result.anyOf.map(s => ensureAdditionalPropertiesFalse(s as JSONSchema7));\n }\n if (result.oneOf && Array.isArray(result.oneOf)) {\n result.oneOf = result.oneOf.map(s => ensureAdditionalPropertiesFalse(s as JSONSchema7));\n }\n if (result.allOf && Array.isArray(result.allOf)) {\n result.allOf = result.allOf.map(s => ensureAdditionalPropertiesFalse(s as JSONSchema7));\n }\n\n return result;\n}\n\n// export function zotToJsonSchema(zodSchema: ZodSchemaV3 | ZodSchemaV4, target: Targets = 'jsonSchema7', strategy: 'none' | 'seen' | 'root' | 'relative' = 'relative'): JSONSchema7 {\n// const target = 'draft-07' as StandardJSONSchemaV1.Target;\n// const standardSchema = toStandardSchema(zodSchema);\n// const jsonSchema = standardSchemaToJSONSchema(standardSchema, {\n// target,\n// });\n\n// traverse(jsonSchema, {\n// cb: {\n// pre: (schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema) => {\n// this.preProcessJSONNode(schema, parentSchema);\n// },\n// post: (schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema) => {\n// this.postProcessJSONNode(schema, parentSchema);\n// },\n// },\n// });\n\n// }\n\nexport function zodToJsonSchema(\n zodSchema: any,\n target: Targets = 'jsonSchema7',\n strategy: 'none' | 'seen' | 'root' | 'relative' = 'relative',\n): JSONSchema7 {\n // Route based on whether the schema is v4 (has _zod) or v3 (only has _def).\n // We use zV4.toJSONSchema (imported from 'zod/v4') for v4 schemas, since the\n // default 'zod' import may resolve to v3 depending on the environment.\n // Without this check, v3 schemas passed to v4's toJSONSchema would throw\n // \"Cannot read properties of undefined (reading 'def')\".\n if (zodSchema?._zod) {\n // Zod v4 path - patch record schemas before converting\n patchRecordSchemas(zodSchema);\n\n const jsonSchema = zV4.toJSONSchema(zodSchema, {\n unrepresentable: 'any',\n override: (ctx: any) => {\n // Handle both Zod v4 structures: _def directly or nested in _zod\n const def = ctx.zodSchema?._def || ctx.zodSchema?._zod?.def;\n // Check for date type using both possible property names\n if (def && (def.typeName === 'ZodDate' || def.type === 'date')) {\n ctx.jsonSchema.type = 'string';\n ctx.jsonSchema.format = 'date-time';\n }\n // Add additionalProperties: false for object types to match Zod v3 behavior\n // This is required for OpenAI strict mode function calling\n if (def && (def.typeName === 'ZodObject' || def.type === 'object')) {\n ctx.jsonSchema.additionalProperties = false;\n }\n },\n }) as JSONSchema7;\n\n // Fix anyOf patterns for nullable fields - required for OpenAI compatibility\n return fixAnyOfNullable(jsonSchema);\n } else {\n // Zod v3 path - use the original converter\n return zodToJsonSchemaOriginal(zodSchema as ZodSchemaV3, {\n $refStrategy: strategy,\n target,\n }) as JSONSchema7;\n }\n}\n"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk3MLZICLP_cjs = require('./chunk-3MLZICLP.cjs');
|
|
4
|
+
var chunkDZUJEN5N_cjs = require('./chunk-DZUJEN5N.cjs');
|
|
5
|
+
var zodToJsonSchemaOriginal = require('zod-to-json-schema');
|
|
6
|
+
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var zodToJsonSchemaOriginal__default = /*#__PURE__*/_interopDefault(zodToJsonSchemaOriginal);
|
|
10
|
+
|
|
11
|
+
// src/standard-schema/adapters/zod-v3.ts
|
|
12
|
+
var import_json_schema_traverse = chunkDZUJEN5N_cjs.__toESM(chunk3MLZICLP_cjs.require_json_schema_traverse(), 1);
|
|
13
|
+
var TARGET_MAP = {
|
|
14
|
+
"draft-07": "jsonSchema7",
|
|
15
|
+
"openapi-3.0": "openApi3"
|
|
16
|
+
};
|
|
17
|
+
function convertToJsonSchema(zodSchema, options) {
|
|
18
|
+
const target = TARGET_MAP[options.target];
|
|
19
|
+
if (!target) {
|
|
20
|
+
const supportedTargets = Object.keys(TARGET_MAP);
|
|
21
|
+
throw new Error(
|
|
22
|
+
`Unsupported JSON Schema target: "${options.target}". Supported targets are: ${supportedTargets.join(", ")}`
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
const jsonSchema = zodToJsonSchemaOriginal__default.default(zodSchema, {
|
|
26
|
+
$refStrategy: "none",
|
|
27
|
+
target
|
|
28
|
+
});
|
|
29
|
+
(0, import_json_schema_traverse.default)(jsonSchema, {
|
|
30
|
+
cb: {
|
|
31
|
+
pre: (schema) => {
|
|
32
|
+
if (schema.type === "string" && schema.format === "email") {
|
|
33
|
+
schema.pattern = `^(?!\\.)(?!.*\\.\\.)([A-Za-z0-9_'+\\-\\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\\-]*\\.)+[A-Za-z]{2,}$`;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// post: (schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema) => {
|
|
37
|
+
// this.postProcessJSONNode(schema, parentSchema);
|
|
38
|
+
// },
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return jsonSchema;
|
|
42
|
+
}
|
|
43
|
+
function toStandardSchema(zodSchema) {
|
|
44
|
+
const wrapper = Object.create(zodSchema);
|
|
45
|
+
const existingStandard = zodSchema["~standard"];
|
|
46
|
+
const jsonSchemaConverter = {
|
|
47
|
+
input: (options) => {
|
|
48
|
+
return convertToJsonSchema(zodSchema, options);
|
|
49
|
+
},
|
|
50
|
+
output: (options) => {
|
|
51
|
+
return convertToJsonSchema(zodSchema, options);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
Object.defineProperty(wrapper, "~standard", {
|
|
55
|
+
value: {
|
|
56
|
+
...existingStandard,
|
|
57
|
+
jsonSchema: jsonSchemaConverter
|
|
58
|
+
},
|
|
59
|
+
writable: false,
|
|
60
|
+
enumerable: true,
|
|
61
|
+
configurable: false
|
|
62
|
+
});
|
|
63
|
+
return wrapper;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
exports.toStandardSchema = toStandardSchema;
|
|
67
|
+
//# sourceMappingURL=chunk-FKB2Z36H.cjs.map
|
|
68
|
+
//# sourceMappingURL=chunk-FKB2Z36H.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/standard-schema/adapters/zod-v3.ts"],"names":["__toESM","require_json_schema_traverse","zodToJsonSchemaOriginal","traverse"],"mappings":";;;;;;;;;;;AACA,IAAA,2BAAA,GAAqBA,yBAAA,CAAAC,8CAAA,EAAA,EAAA,CAAA,CAAA;AAYrB,IAAM,UAAA,GAAoD;AAAA,EACxD,UAAA,EAAY,aAAA;AAAA,EACZ,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;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-FKB2Z36H.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 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-07': 'jsonSchema7',\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 });\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"]}
|