1602/jugglingdb — pull request #212 by NiKnight (2013-02-23 04:04:35+00:00)
Title: requirejs compat and fixes/improvements to http adapter

Nearly all files in the project are updated with this change, but it's only the beginning and ending of the files except for http.js.

I did this because I wanted to use jugglingdb in the browser without browserify. I use requirejs to allow me to share code between the client and server. So, these changes allow you to use jugglingdb using standard node require() calls, requirejs on the server, or requirejs in the browser.

This involves wrapping all files in a define() call, where the first parameter is an array of dependencies, and the second parameter is a function which takes as its arguments those dependencies. The 'amdefine' node module is used to allow these same files to to used by node's require. So everything behaves just as they did before - and the tests agree.

The primary difference is that dynamic require calls in the middle of the file no longer work. So using new Schema(, options) no longer works under requirejs - you'll have to pass the adapter after pulling it in yourself. Requiring adapters by name will still work if you're pulling jugglingdb in via standard node require calls.

The http and memory adapters have been converted. That leaves cradle, neo4j and riak to convert to requirejs compat. (I only converted the ones I could test on my machine)

This change also includes some fixes and updates to the http adapter, in three commits. Take a look.

Finally, I should note that a certain requirejs config is required to make this all work in the browser. fs and path have to be replaced with empty files, but they can't be the same file (due to requirejs demans) and they can't return null. util needs a shim - inspect and inherits need to be implemented. And finally, events needs a shim with EventEmitter implemented. I can provide my util/events shims if you're interested.