In the case of more complex predicate functions, including abort/error messages would be helpful to help the consuming developers debug more easily.
e.g.
privileges: [{
resource: "Collection",
actions: {
write: `(originalDoc, newDoc) => {
if(originalDoc.owner != newDoc.owner) {
abort({
code: "insufficient_permission",
message: "Insufficient Permission. Only the Owner is allowed to change the owner."
})
}
if(originalDoc.access != newDoc.access) {
if(originalDoc.access.any(
(.entity == Query.identity() || .entity == Query.identity().activeOrganization)
&& .action == "UNRESTRICTED"
)
) {
true
} else {
abort({
code: "insufficient_permission",
message: "Insufficient Permission. Only the Owner is allowed to change the owner."
})
}
}
doc.access.any(
(.entity == Query.identity() || .entity == Query.identity().activeOrganization)
&& .action == "WRITE"
)
}
`
}
}
Somehow related to Detailed error message for “insufficient privileges” in dev mode, but more focused in the direction to print custom error codes/messages