UNPKG

@langchain/core

Version:
1 lines 2.51 kB
{"version":3,"file":"tuple.cjs","names":["def: ZodTupleDef<ZodTupleItems | [], ZodTypeAny | null>","refs: Refs","parseDef","acc: JsonSchema7Type[]"],"sources":["../../../../src/utils/zod-to-json-schema/parsers/tuple.ts"],"sourcesContent":["import { ZodTupleDef, ZodTupleItems, ZodTypeAny } from \"zod/v3\";\nimport { parseDef } from \"../parseDef.js\";\nimport { JsonSchema7Type } from \"../parseTypes.js\";\nimport { Refs } from \"../Refs.js\";\n\nexport type JsonSchema7TupleType = {\n type: \"array\";\n minItems: number;\n items: JsonSchema7Type[];\n} & (\n | {\n maxItems: number;\n }\n | {\n additionalItems?: JsonSchema7Type;\n }\n);\n\nexport function parseTupleDef(\n def: ZodTupleDef<ZodTupleItems | [], ZodTypeAny | null>,\n refs: Refs\n): JsonSchema7TupleType {\n if (def.rest) {\n return {\n type: \"array\",\n minItems: def.items.length,\n items: def.items\n .map((x, i) =>\n parseDef(x._def, {\n ...refs,\n currentPath: [...refs.currentPath, \"items\", `${i}`],\n })\n )\n .reduce(\n (acc: JsonSchema7Type[], x) => (x === undefined ? acc : [...acc, x]),\n []\n ),\n additionalItems: parseDef(def.rest._def, {\n ...refs,\n currentPath: [...refs.currentPath, \"additionalItems\"],\n }),\n };\n } else {\n return {\n type: \"array\",\n minItems: def.items.length,\n maxItems: def.items.length,\n items: def.items\n .map((x, i) =>\n parseDef(x._def, {\n ...refs,\n currentPath: [...refs.currentPath, \"items\", `${i}`],\n })\n )\n .reduce(\n (acc: JsonSchema7Type[], x) => (x === undefined ? acc : [...acc, x]),\n []\n ),\n };\n }\n}\n"],"mappings":";;;AAkBA,SAAgB,cACdA,KACAC,MACsB;AACtB,KAAI,IAAI,KACN,QAAO;EACL,MAAM;EACN,UAAU,IAAI,MAAM;EACpB,OAAO,IAAI,MACR,IAAI,CAAC,GAAG,MACPC,0BAAS,EAAE,MAAM;GACf,GAAG;GACH,aAAa;IAAC,GAAG,KAAK;IAAa;IAAS,GAAG,GAAG;GAAC;EACpD,EAAC,CACH,CACA,OACC,CAACC,KAAwB,MAAO,MAAM,SAAY,MAAM,CAAC,GAAG,KAAK,CAAE,GACnE,CAAE,EACH;EACH,iBAAiBD,0BAAS,IAAI,KAAK,MAAM;GACvC,GAAG;GACH,aAAa,CAAC,GAAG,KAAK,aAAa,iBAAkB;EACtD,EAAC;CACH;KAED,QAAO;EACL,MAAM;EACN,UAAU,IAAI,MAAM;EACpB,UAAU,IAAI,MAAM;EACpB,OAAO,IAAI,MACR,IAAI,CAAC,GAAG,MACPA,0BAAS,EAAE,MAAM;GACf,GAAG;GACH,aAAa;IAAC,GAAG,KAAK;IAAa;IAAS,GAAG,GAAG;GAAC;EACpD,EAAC,CACH,CACA,OACC,CAACC,KAAwB,MAAO,MAAM,SAAY,MAAM,CAAC,GAAG,KAAK,CAAE,GACnE,CAAE,EACH;CACJ;AAEJ"}