datastore: refactor transaction & datastore.

Hello again!

I rearranged a few things, hopefully for the better. I'll leave comments. :)
Note the reformat of `test/*.js` to `test/**/*.js`. The `test` directory + filename hierarchy is now 1:1 with the `lib/*` directory.