@langchain/core
Version:
Core LangChain.js abstractions and schemas
1 lines • 1.83 kB
Source Map (JSON)
{"version":3,"file":"map.cjs","names":["parseRecordDef","parseDef","parseAnyDef"],"sources":["../../../../src/utils/zod-to-json-schema/parsers/map.ts"],"sourcesContent":["import { ZodMapDef } from \"zod/v3\";\nimport { parseDef } from \"../parseDef.js\";\nimport { JsonSchema7Type } from \"../parseTypes.js\";\nimport { Refs } from \"../Refs.js\";\nimport { JsonSchema7RecordType, parseRecordDef } from \"./record.js\";\nimport { parseAnyDef } from \"./any.js\";\n\nexport type JsonSchema7MapType = {\n type: \"array\";\n maxItems: 125;\n items: {\n type: \"array\";\n items: [JsonSchema7Type, JsonSchema7Type];\n minItems: 2;\n maxItems: 2;\n };\n};\n\nexport function parseMapDef(\n def: ZodMapDef,\n refs: Refs\n): JsonSchema7MapType | JsonSchema7RecordType {\n if (refs.mapStrategy === \"record\") {\n return parseRecordDef(def, refs);\n }\n\n const keys =\n parseDef(def.keyType._def, {\n ...refs,\n currentPath: [...refs.currentPath, \"items\", \"items\", \"0\"],\n }) || parseAnyDef(refs);\n const values =\n parseDef(def.valueType._def, {\n ...refs,\n currentPath: [...refs.currentPath, \"items\", \"items\", \"1\"],\n }) || parseAnyDef(refs);\n return {\n type: \"array\",\n maxItems: 125,\n items: {\n type: \"array\",\n items: [keys, values],\n minItems: 2,\n maxItems: 2,\n },\n };\n}\n"],"mappings":";;;;AAkBA,SAAgB,YACd,KACA,MAC4C;AAC5C,KAAI,KAAK,gBAAgB,SACvB,QAAOA,eAAAA,eAAe,KAAK,KAAK;AAalC,QAAO;EACL,MAAM;EACN,UAAU;EACV,OAAO;GACL,MAAM;GACN,OAAO,CAdTC,iBAAAA,SAAS,IAAI,QAAQ,MAAM;IACzB,GAAG;IACH,aAAa;KAAC,GAAG,KAAK;KAAa;KAAS;KAAS;KAAI;IAC1D,CAAC,IAAIC,YAAAA,YAAY,KAAK,EAEvBD,iBAAAA,SAAS,IAAI,UAAU,MAAM;IAC3B,GAAG;IACH,aAAa;KAAC,GAAG,KAAK;KAAa;KAAS;KAAS;KAAI;IAC1D,CAAC,IAAIC,YAAAA,YAAY,KAAK,CAMA;GACrB,UAAU;GACV,UAAU;GACX;EACF"}