feat: arrête erreur quand un type n'existe plus dans Notion

This commit is contained in:
Sébastien Arod 2025-05-26 21:08:32 +02:00
parent 4fb83b8217
commit e6cbd790aa

View file

@ -7,7 +7,14 @@ import { richTextToPlainText } from "../../utils/text/richTextToPlainText";
export function checkDbPropertyOptionsMatchesType(
db: DatabaseObjectResponse,
propName: string,
typeOptions: readonly string[]
typeOptions: readonly string[],
options: {
failOnMissingFromDb: boolean;
failOnMissingFromType: boolean;
} = {
failOnMissingFromDb: true,
failOnMissingFromType: false
}
) {
const prop = db.properties[propName];
const dbTitle = richTextToPlainText(db.title);
@ -35,6 +42,12 @@ export function checkDbPropertyOptionsMatchesType(
notInDb.length
} options missing from db: [${notInDb.map((i) => `"${i}"`)}]`;
}
if (options.failOnMissingFromDb && notInDb.length > 0) {
throw new Error(message);
}
if (options.failOnMissingFromType && notInType.length > 0) {
throw new Error(message);
}
console.warn(message);
}
}