UNPKG

pulse-ai-utils

Version:

Utility functions and helpers for AI-powered applications

34 lines 1.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.zodToJsonSchema = zodToJsonSchema; const zod_1 = require("zod"); function zodToJsonSchema(schema) { const def = schema._def; switch (def.typeName) { case zod_1.ZodFirstPartyTypeKind.ZodString: return { type: 'string' }; case zod_1.ZodFirstPartyTypeKind.ZodNumber: return { type: 'number' }; case zod_1.ZodFirstPartyTypeKind.ZodBoolean: return { type: 'boolean' }; case zod_1.ZodFirstPartyTypeKind.ZodArray: return { type: 'array', items: zodToJsonSchema(def.type) }; case zod_1.ZodFirstPartyTypeKind.ZodObject: { const shape = def.shape(); const properties = {}; for (const key of Object.keys(shape)) { properties[key] = zodToJsonSchema(shape[key]); } return { type: 'object', properties }; } case zod_1.ZodFirstPartyTypeKind.ZodNullable: { const inner = zodToJsonSchema(def.innerType); return { ...inner, nullable: true }; } case zod_1.ZodFirstPartyTypeKind.ZodOptional: return zodToJsonSchema(def.innerType); default: return {}; } } //# sourceMappingURL=zodToJsonSchema.js.map