Documentation around the sync function often recommends to use properties of the document itself for authentication control purposes. The example sync function recommends, for example, using an owner property to prevent unauthorized access by other parties. However, this requires the owner property be known and set at the time the document is created. That in turn means the business logic (creation of the document data) and a cross-cutting technical concern (maintaining authorization meta-data) are interconnected.
If I want to have the authentication and access part of my client completely separated from the specific components creating a given document, I will still have to include a hook to access the username and insert it into the document. This only grows more complex the more meta-data I want to include.
It would be great to enforce these kind of invariants (newly created documents have an owner property) at the sync gateway. After a little digging it seems that making modifications to the document data as part of the sync function isn’t supported. That makes sense, as that isn’t the purpose of the sync function. Is there any other endorsed pattern I should be following to make these kind of transformations? Is there something I haven’t found in the CB Lite API that would allow me to make that kind of transformation on the client side before committing the document?