Hey all,

I got nerd sniped by Joan this morning:

    <+Wohali> hmmmmm. https://github.com/denoland/deno
    <+Wohali> i know i know another runtime but it's focused on security

I wondered what it would take to make a couchjs variant based on deno. Turns 
out: about a day if you cut some corners ;)

One of the interesting aspects, as Joan notes, is its more-secure-by-default, 
so I have some hopes that this might work out better than our ill-fated nodejs 
query server experiment from a few years back.

I started by hacking up a readily generated main.js, then ran `make` again, and 
did it all again. Overall, it is ~30 LOC changes. Since there is no synchronous 
`readline()` available and JS code can either by sync or async, we can’t make 
it so one source could run in our couchjs or deno.

So I went ahead and ripped all the basics out of our main.js and modernised 
things a little bit along the way. The result is a main-deno.js that can run 
map/reduce/rereduce/filter/view_filter/validate_doc_update functions (as 
validated by the query server spec).

    https://gist.github.com/janl/c3139bc72efe663e35005d8864c4201f

I intentionally left out the couchappy functions, as at least lists with the 
`getRow()` function won’t be implementable without an API break. I also left 
out legacy compact with esprima/escodegen to keep things more manageable. Oh 
and no lib/modules, given today’s JS packaging tooling, it’s an easy choice to 
leave out.

I haven’t done any sort of benchmarking, but I’d love for someone here to give 
this a try. Here’s how to hack up `./dev/run` to add support for `deno` design 
docs:

   https://gist.github.com/janl/01559f8617ef44afd5ceec39ec8389e8

If you want to run this on a regular CouchDB setup, set up this env var before 
launching CouchDB:

    COUCHDB_QUERY_SERVER_DENO="deno run --allow-write /path/to/main-deno.js”

    `--allow-write` is only required for the debug log (/tmp/deno-qs.log), but 
won’t be required during operation, adding to the sandboxed nature of it all.

And some proof of operation:

   https://gist.github.com/janl/8636d469420a1fd2de481ae8f5780854

It’d be nice to see how stable this is in practice and if there are any 
meaningful performance / resource-usage differences. Any takers? I’ll answer 
any and all setup questions.

Now I’m passing the nerd-snipe torch to Paul:

    <+jan____> uh, and it is embeddable https://deno.land/manual/embedding_deno

Best
Jan
—

Reply via email to