UNPKG

@langchain/core

Version:
1 lines 1.63 kB
{"version":3,"file":"set.cjs","names":["parseDef"],"sources":["../../../../src/utils/zod-to-json-schema/parsers/set.ts"],"sourcesContent":["import { ZodSetDef } from \"zod/v3\";\nimport { ErrorMessages, setResponseValueAndErrors } from \"../errorMessages.js\";\nimport { parseDef } from \"../parseDef.js\";\nimport { JsonSchema7Type } from \"../parseTypes.js\";\nimport { Refs } from \"../Refs.js\";\n\nexport type JsonSchema7SetType = {\n type: \"array\";\n uniqueItems: true;\n items?: JsonSchema7Type;\n minItems?: number;\n maxItems?: number;\n errorMessage?: ErrorMessages<JsonSchema7SetType>;\n};\n\nexport function parseSetDef(def: ZodSetDef, refs: Refs): JsonSchema7SetType {\n const items = parseDef(def.valueType._def, {\n ...refs,\n currentPath: [...refs.currentPath, \"items\"],\n });\n\n const schema: JsonSchema7SetType = {\n type: \"array\",\n uniqueItems: true,\n items,\n };\n\n if (def.minSize) {\n setResponseValueAndErrors(\n schema,\n \"minItems\",\n def.minSize.value,\n def.minSize.message,\n refs\n );\n }\n\n if (def.maxSize) {\n setResponseValueAndErrors(\n schema,\n \"maxItems\",\n def.maxSize.value,\n def.maxSize.message,\n refs\n );\n }\n\n return schema;\n}\n"],"mappings":";;;AAeA,SAAgB,YAAY,KAAgB,MAAgC;CAM1E,MAAM,SAA6B;EACjC,MAAM;EACN,aAAa;EACb,OARYA,iBAAAA,SAAS,IAAI,UAAU,MAAM;GACzC,GAAG;GACH,aAAa,CAAC,GAAG,KAAK,aAAa,QAAQ;GAC5C,CAAC;EAMD;AAED,KAAI,IAAI,QACN,uBAAA,0BACE,QACA,YACA,IAAI,QAAQ,OACZ,IAAI,QAAQ,SACZ,KACD;AAGH,KAAI,IAAI,QACN,uBAAA,0BACE,QACA,YACA,IAAI,QAAQ,OACZ,IAAI,QAAQ,SACZ,KACD;AAGH,QAAO"}