/** * Module dependencies. */ var duplexer = require('duplexer2'); var Stream = require('stream'); /** * Slice reference. */ var slice = [].slice; /** * Duplexer options. */ var opts = { bubbleErrors: false }; /** * Expose `pipe`. */ module.exports = pipe; /** * Pipe. * * @param {Stream,...,[Function]} * @return {Stream} * @api public */ function pipe(){ if (arguments.length == 1) return arguments[0]; var streams = slice.call(arguments); var cb; if ('function' == typeof streams[streams.length - 1]) { cb = streams.splice(-1)[0]; } var first = streams[0]; var last = streams[streams.length - 1]; var ret; if (first.writable && last.readable) ret = duplexer(opts, first, last); else if (first.writable) ret = first; else if (last.readable) ret = last; else ret = new Stream; streams.forEach(function(stream, i){ var next = streams[i+1]; if (next) stream.pipe(next); if (stream != ret) stream.on('error', ret.emit.bind(ret, 'error')); }); if (cb) { var ended = false; ret.on('error', end); last.on('finish', end); function end(err){ if (ended) return; ended = true; cb(err); } } return ret; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 19553 | swellard | Move and rename clients | ||
//guest/perforce_software/helix-web-services/main/source/clients/2016.1.0/javascript/node_modules/multipipe/index.js | |||||
#1 | 18810 | tjuricek |
First-pass at JavaScript client SDK. JavaScript requires Node with Gulp to "browserfy" the library. It's the easiest way I found to use the swagger-js project; bundle up a wrapping method. There is no JavaScript reference guide. The swagger-js doesn't really document what they do very well, actually. Overall I'm not particularly impressed by swagger-js, it was hard to even figure out what the right method syntax was. We may want to invest time in doing it better. This required setting CORS response headers, which are currently defaulted to a fairly insecure setting. |