feat: prevent user from using doc id attribute

This commit is contained in:
Marc-Roig 2023-11-06 11:28:19 +01:00
parent 91d6b8ca44
commit 1dae937ea5
No known key found for this signature in database
GPG Key ID: FB4E2C43A0BEE249

View File

@ -33,6 +33,17 @@ export const transformContentTypesToModels = (
? { documentId: { type: 'string', default: createId } }
: {};
// Prevent user from creating a documentId attribute
const reservedAttributeNames = ['documentId', 'document_id'];
reservedAttributeNames.forEach((reservedAttributeName) => {
if (reservedAttributeName in contentType.attributes) {
throw new Error(
`The attribute "${reservedAttributeName}" is reserved and cannot be used in a model` +
`Please rename "${contentType.modelName}" attribute "${reservedAttributeName}" to something else.`
);
}
});
const model = {
...contentType,
// reuse new model def