contents.js wrapper for contents service

This is PR #6671, rebased because it's a blocker for the text editor components, and @fperez asked me to make that high priority. So far, I've just rebased, I intend to test it and fix things I see.
I think it's worth having a distinct method for listing directory contents, because it is conceptually different - other backends may want to handle these cases differently. However, I'll refactor it once we've added supported for 'get x, which should be a directory'.