How to undo/redo operations?

201 views
Skip to first unread message

Sergei Droganov

unread,
Mar 10, 2016, 6:59:30 PM3/10/16
to ShareJS
Hi,
I'm looking to write schema validation + access control library for sharedb backend.

I want the API to look like this:
harden( backend, schema );

It looks obvious to go this way:

backend.use [ "query", "submit", "after submit" ], (req, next) => validateAccessRights();
backend.use "after submit", (req, next) => validateSchema();

I'm able to validate the operation result against schema at "after submit" hook, but operation is applied despite of error I'm trowing, can I then roll it back somehow or prevent?

Sergei Droganov

unread,
Mar 10, 2016, 8:22:53 PM3/10/16
to ShareJS
Here is the problem:
https://github.com/share/sharedb/issues/67

no snapshot on submit or no rollback on after submit. As a result no way to validate the operation result.

Nate Smith

unread,
Mar 11, 2016, 1:19:35 PM3/11/16
to sha...@googlegroups.com
You should be using the "apply" and "commit" middleware hooks instead of "submit" and "after submit" for access control. Will write more docs on this later, but apply gives you the snapshot right before the op is applied and commit gives you the snapshot right after the op is applied but before it is committed to the database. You can prevent the submit from completing in any of "submit", "apply", or "commit" by passing an error to next.

An op cannot be rolled back after commit, so you cannot change anything in "after submit".

--
You received this message because you are subscribed to the Google Groups "ShareJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sharejs+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sergei Droganov

unread,
Mar 12, 2016, 5:10:12 PM3/12/16
to ShareJS, na...@nateps.com
Hello Nate, this helps, thank you!

Sivaganeshan B

unread,
Oct 14, 2022, 1:59:44 AM10/14/22
to ShareJS
Hello, 
interested to know how you have implemented it. could you please share the example?

Reply all
Reply to author
Forward
0 new messages