{"version":3,"sources":["../../../src/collections/config/sanitizeCompoundIndexes.ts"],"sourcesContent":["import type { FlattenedField } from '../../fields/config/types.js'\nimport type { CompoundIndex, SanitizedCompoundIndex } from './types.js'\n\nimport { InvalidConfiguration } from '../../errors/InvalidConfiguration.js'\nimport { getFieldByPath } from '../../utilities/getFieldByPath.js'\n\nexport const sanitizeCompoundIndexes = ({\n fields,\n indexes,\n}: {\n fields: FlattenedField[]\n indexes: CompoundIndex[]\n}): SanitizedCompoundIndex[] => {\n const sanitizedCompoundIndexes: SanitizedCompoundIndex[] = []\n\n for (const index of indexes) {\n const sanitized: SanitizedCompoundIndex = { fields: [], unique: index.unique ?? false }\n for (const path of index.fields) {\n const result = getFieldByPath({ fields, path })\n\n if (!result) {\n throw new InvalidConfiguration(`Field ${path} was not found`)\n }\n\n const { field, localizedPath, pathHasLocalized } = result\n\n if (['array', 'blocks', 'group', 'tab'].includes(field.type)) {\n throw new InvalidConfiguration(\n `Compound index on ${field.type} cannot be set. Path: ${localizedPath}`,\n )\n }\n\n sanitized.fields.push({ field, localizedPath, path, pathHasLocalized })\n }\n\n sanitizedCompoundIndexes.push(sanitized)\n }\n\n return sanitizedCompoundIndexes\n}\n"],"names":["InvalidConfiguration","getFieldByPath","sanitizeCompoundIndexes","fields","indexes","sanitizedCompoundIndexes","index","sanitized","unique","path","result","field","localizedPath","pathHasLocalized","includes","type","push"],"mappings":"AAGA,SAASA,oBAAoB,QAAQ,uCAAsC;AAC3E,SAASC,cAAc,QAAQ,oCAAmC;AAElE,OAAO,MAAMC,0BAA0B,CAAC,EACtCC,MAAM,EACNC,OAAO,EAIR;IACC,MAAMC,2BAAqD,EAAE;IAE7D,KAAK,MAAMC,SAASF,QAAS;QAC3B,MAAMG,YAAoC;YAAEJ,QAAQ,EAAE;YAAEK,QAAQF,MAAME,MAAM,IAAI;QAAM;QACtF,KAAK,MAAMC,QAAQH,MAAMH,MAAM,CAAE;YAC/B,MAAMO,SAAST,eAAe;gBAAEE;gBAAQM;YAAK;YAE7C,IAAI,CAACC,QAAQ;gBACX,MAAM,IAAIV,qBAAqB,CAAC,MAAM,EAAES,KAAK,cAAc,CAAC;YAC9D;YAEA,MAAM,EAAEE,KAAK,EAAEC,aAAa,EAAEC,gBAAgB,EAAE,GAAGH;YAEnD,IAAI;gBAAC;gBAAS;gBAAU;gBAAS;aAAM,CAACI,QAAQ,CAACH,MAAMI,IAAI,GAAG;gBAC5D,MAAM,IAAIf,qBACR,CAAC,kBAAkB,EAAEW,MAAMI,IAAI,CAAC,sBAAsB,EAAEH,eAAe;YAE3E;YAEAL,UAAUJ,MAAM,CAACa,IAAI,CAAC;gBAAEL;gBAAOC;gBAAeH;gBAAMI;YAAiB;QACvE;QAEAR,yBAAyBW,IAAI,CAACT;IAChC;IAEA,OAAOF;AACT,EAAC"}