var Splicer = require('stream-splicer'); var inherits = require('inherits'); var isarray = require('isarray'); module.exports = Labeled; inherits(Labeled, Splicer); module.exports.obj = function (streams, opts) { if (!opts) opts = {}; opts.objectMode = true; return new Labeled(streams, opts); }; function Labeled (streams, opts) { if (!(this instanceof Labeled)) return new Labeled(streams, opts); Splicer.call(this, [], opts); var reps = []; for (var i = 0; i < streams.length; i++) { var s = streams[i]; if (typeof s === 'string') continue; if (isarray(s)) { s = new Labeled(s, opts); } if (i >= 0 && typeof streams[i-1] === 'string') { s.label = streams[i-1]; } reps.push(s); } if (typeof streams[i-1] === 'string') { reps.push(new Labeled([], opts)); } this.splice.apply(this, [0,0].concat(reps)); } Labeled.prototype.indexOf = function (stream) { if (typeof stream === 'string') { for (var i = 0; i < this._streams.length; i++) { if (this._streams[i].label === stream) return i; } return -1; } else { return Splicer.prototype.indexOf.call(this, stream); } }; Labeled.prototype.get = function (key) { if (typeof key === 'string') { var ix = this.indexOf(key); if (ix < 0) return undefined; return this._streams[ix]; } else return Splicer.prototype.get.call(this, key); }; Labeled.prototype.splice = function (key) { var ix; if (typeof key === 'string') { ix = this.indexOf(key); } else ix = key; var args = [ ix ].concat([].slice.call(arguments, 1)); return Splicer.prototype.splice.apply(this, args); };
# | 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/labeled-stream-splicer/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. |