Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
39 lines
1.3 KiB
Plaintext
39 lines
1.3 KiB
Plaintext
import { InvalidConfiguration } from '../../errors/InvalidConfiguration.js';
|
|
import { getFieldByPath } from '../../utilities/getFieldByPath.js';
|
|
export const sanitizeCompoundIndexes = ({ fields, indexes })=>{
|
|
const sanitizedCompoundIndexes = [];
|
|
for (const index of indexes){
|
|
const sanitized = {
|
|
fields: [],
|
|
unique: index.unique ?? false
|
|
};
|
|
for (const path of index.fields){
|
|
const result = getFieldByPath({
|
|
fields,
|
|
path
|
|
});
|
|
if (!result) {
|
|
throw new InvalidConfiguration(`Field ${path} was not found`);
|
|
}
|
|
const { field, localizedPath, pathHasLocalized } = result;
|
|
if ([
|
|
'array',
|
|
'blocks',
|
|
'group',
|
|
'tab'
|
|
].includes(field.type)) {
|
|
throw new InvalidConfiguration(`Compound index on ${field.type} cannot be set. Path: ${localizedPath}`);
|
|
}
|
|
sanitized.fields.push({
|
|
field,
|
|
localizedPath,
|
|
path,
|
|
pathHasLocalized
|
|
});
|
|
}
|
|
sanitizedCompoundIndexes.push(sanitized);
|
|
}
|
|
return sanitizedCompoundIndexes;
|
|
};
|
|
|
|
//# sourceMappingURL=sanitizeCompoundIndexes.js.map |