exception-stream.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * exception-stream.js: TODO: add file header handler.
  3. *
  4. * (C) 2010 Charlie Robbins
  5. * MIT LICENCE
  6. */
  7. 'use strict';
  8. function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
  9. function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
  10. function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
  11. function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
  12. function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
  13. function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
  14. function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
  15. function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
  16. function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
  17. function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
  18. function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
  19. function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
  20. function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
  21. var _require = require('readable-stream'),
  22. Writable = _require.Writable;
  23. /**
  24. * TODO: add class description.
  25. * @type {ExceptionStream}
  26. * @extends {Writable}
  27. */
  28. module.exports = /*#__PURE__*/function (_Writable) {
  29. /**
  30. * Constructor function for the ExceptionStream responsible for wrapping a
  31. * TransportStream; only allowing writes of `info` objects with
  32. * `info.exception` set to true.
  33. * @param {!TransportStream} transport - Stream to filter to exceptions
  34. */
  35. function ExceptionStream(transport) {
  36. var _this;
  37. _classCallCheck(this, ExceptionStream);
  38. _this = _callSuper(this, ExceptionStream, [{
  39. objectMode: true
  40. }]);
  41. if (!transport) {
  42. throw new Error('ExceptionStream requires a TransportStream instance.');
  43. }
  44. // Remark (indexzero): we set `handleExceptions` here because it's the
  45. // predicate checked in ExceptionHandler.prototype.__getExceptionHandlers
  46. _this.handleExceptions = true;
  47. _this.transport = transport;
  48. return _this;
  49. }
  50. /**
  51. * Writes the info object to our transport instance if (and only if) the
  52. * `exception` property is set on the info.
  53. * @param {mixed} info - TODO: add param description.
  54. * @param {mixed} enc - TODO: add param description.
  55. * @param {mixed} callback - TODO: add param description.
  56. * @returns {mixed} - TODO: add return description.
  57. * @private
  58. */
  59. _inherits(ExceptionStream, _Writable);
  60. return _createClass(ExceptionStream, [{
  61. key: "_write",
  62. value: function _write(info, enc, callback) {
  63. if (info.exception) {
  64. return this.transport.log(info, callback);
  65. }
  66. callback();
  67. return true;
  68. }
  69. }]);
  70. }(Writable);