Improve handling of collection names in generated JS

1. Generate correct mongo shell syntax for collections with names that aren't valid dot-separated JS identifiers.
2. Change generated names for temporary collections so that they are valid dot-separated JS identifiers, and to put them all under a `tmp` pseudo-namespace (so that they appear in the API as sharing a `tmp/` sub-directory.

This is another extract from my WIP branch for #140.
Yes. It's generating JS text that does the lookup. I couldn't come up with a succinct way of expressing that. I think toJsRef is an improvement, so I'll change it.