@shopify/statsd
Advanced tools
Comparing version 2.1.4 to 3.0.0
@@ -1,51 +0,17 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.StatsDClient = void 0; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var _hotShots = require("hot-shots"); | ||
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js'); | ||
var hotShots = require('hot-shots'); | ||
var changeCase = require('change-case'); | ||
var _changeCase = require("change-case"); | ||
const UNKNOWN = 'Unknown'; | ||
class StatsDClient { | ||
constructor(_ref) { | ||
let { | ||
logger | ||
} = _ref, | ||
options = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, ["logger"]); | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } | ||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
var UNKNOWN = 'Unknown'; | ||
var StatsDClient = /*#__PURE__*/function () { | ||
function StatsDClient(_ref) { | ||
var _this = this; | ||
var logger = _ref.logger, | ||
options = _objectWithoutProperties(_ref, ["logger"]); | ||
_classCallCheck(this, StatsDClient); | ||
this.statsd = void 0; | ||
@@ -59,107 +25,78 @@ this.logger = console; | ||
this.options = _objectSpread(_objectSpread({}, options), {}, { | ||
errorHandler: options.errorHandler ? options.errorHandler : function (error) { | ||
_this.logger.log("Error occurred in the StatsD client:\n".concat(error.stack || error.message)); | ||
this.options = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, options), {}, { | ||
errorHandler: options.errorHandler ? options.errorHandler : error => { | ||
this.logger.log(`Error occurred in the StatsD client:\n${error.stack || error.message}`); | ||
} | ||
}); | ||
this.statsd = new _hotShots.StatsD(this.options); | ||
this.statsd = new hotShots.StatsD(this.options); | ||
} | ||
_createClass(StatsDClient, [{ | ||
key: "distribution", | ||
value: function distribution(stat, value, tags) { | ||
var _this2 = this; | ||
distribution(stat, value, tags) { | ||
return new Promise(resolve => { | ||
this.statsd.distribution(stat, value, this.normalizeTags(tags), this.createCallback(resolve)); | ||
}); | ||
} | ||
return new Promise(function (resolve) { | ||
_this2.statsd.distribution(stat, value, _this2.normalizeTags(tags), _this2.createCallback(resolve)); | ||
}); | ||
} | ||
}, { | ||
key: "timing", | ||
value: function timing(stat, value, tags) { | ||
var _this3 = this; | ||
timing(stat, value, tags) { | ||
return new Promise(resolve => { | ||
this.statsd.timing(stat, value, this.normalizeTags(tags), this.createCallback(resolve)); | ||
}); | ||
} | ||
return new Promise(function (resolve) { | ||
_this3.statsd.timing(stat, value, _this3.normalizeTags(tags), _this3.createCallback(resolve)); | ||
}); | ||
} | ||
}, { | ||
key: "gauge", | ||
value: function gauge(stat, value, tags) { | ||
var _this4 = this; | ||
gauge(stat, value, tags) { | ||
return new Promise(resolve => { | ||
this.statsd.gauge(stat, value, this.normalizeTags(tags), this.createCallback(resolve)); | ||
}); | ||
} | ||
return new Promise(function (resolve) { | ||
_this4.statsd.gauge(stat, value, _this4.normalizeTags(tags), _this4.createCallback(resolve)); | ||
}); | ||
} | ||
}, { | ||
key: "increment", | ||
value: function increment(stat, tags) { | ||
var _this5 = this; | ||
increment(stat, tags) { | ||
return new Promise(resolve => { | ||
this.statsd.increment(stat, 1, this.normalizeTags(tags), this.createCallback(resolve)); | ||
}); | ||
} | ||
return new Promise(function (resolve) { | ||
_this5.statsd.increment(stat, 1, _this5.normalizeTags(tags), _this5.createCallback(resolve)); | ||
}); | ||
} | ||
}, { | ||
key: "close", | ||
value: function close() { | ||
var _this6 = this; | ||
close() { | ||
return new Promise(resolve => { | ||
this.statsd.close(this.createCallback(resolve)); | ||
}); | ||
} | ||
return new Promise(function (resolve) { | ||
_this6.statsd.close(_this6.createCallback(resolve)); | ||
}); | ||
} | ||
}, { | ||
key: "addGlobalTags", | ||
value: function addGlobalTags(globalTags) { | ||
this.statsd = this.statsd.childClient({ | ||
globalTags: this.normalizeTags(globalTags) | ||
}); | ||
} | ||
}, { | ||
key: "createCallback", | ||
value: function createCallback(resolve) { | ||
var _this7 = this; | ||
addGlobalTags(globalTags) { | ||
this.statsd = this.statsd.childClient({ | ||
globalTags: this.normalizeTags(globalTags) | ||
}); | ||
} | ||
return function (error) { | ||
if (error && _this7.options.errorHandler) { | ||
_this7.options.errorHandler(error); | ||
} | ||
createCallback(resolve) { | ||
return error => { | ||
if (error && this.options.errorHandler) { | ||
this.options.errorHandler(error); | ||
} | ||
resolve(); | ||
}; | ||
resolve(); | ||
}; | ||
} | ||
normalizeTags(tags = []) { | ||
if (Array.isArray(tags)) { | ||
return tags; | ||
} | ||
}, { | ||
key: "normalizeTags", | ||
value: function normalizeTags() { | ||
var tags = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
if (Array.isArray(tags)) { | ||
return tags; | ||
} | ||
const output = {}; | ||
var output = {}; | ||
for (const [key, value] of Object.entries(tags)) { | ||
const newValue = value == null ? UNKNOWN : String(value); | ||
for (var _i = 0, _Object$entries = Object.entries(tags); _i < _Object$entries.length; _i++) { | ||
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), | ||
key = _Object$entries$_i[0], | ||
_value = _Object$entries$_i[1]; | ||
var newValue = _value == null ? UNKNOWN : String(_value); | ||
if (this.options.snakeCase) { | ||
output[(0, _changeCase.snakeCase)(key)] = newValue; | ||
} else { | ||
output[key] = newValue; | ||
} | ||
if (this.options.snakeCase) { | ||
output[changeCase.snakeCase(key)] = newValue; | ||
} else { | ||
output[key] = newValue; | ||
} | ||
return output; | ||
} | ||
}]); | ||
return StatsDClient; | ||
}(); | ||
return output; | ||
} | ||
exports.StatsDClient = StatsDClient; | ||
} | ||
exports.StatsDClient = StatsDClient; |
@@ -1,13 +0,9 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "StatsDClient", { | ||
enumerable: true, | ||
get: function get() { | ||
return _client.StatsDClient; | ||
} | ||
}); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var _client = require("./client.js"); | ||
var client = require('./client.js'); | ||
exports.StatsDClient = client.StatsDClient; |
@@ -10,2 +10,8 @@ # Changelog | ||
## 3.0.0 - 2021-05-21 | ||
### Breaking Change | ||
- Update minimum supported node version to 12.14.0. Add engines field to help enforce usage of this version. [#1906](https://github.com/Shopify/quilt/pull/1906) | ||
## 2.1.4 - 2021-04-13 | ||
@@ -12,0 +18,0 @@ |
{ | ||
"name": "@shopify/statsd", | ||
"version": "2.1.4", | ||
"version": "3.0.0", | ||
"license": "MIT", | ||
@@ -23,2 +23,5 @@ "description": "An opinionated StatsD client for Shopify Node.js servers and other StatsD utilities", | ||
"homepage": "https://github.com/Shopify/quilt/blob/main/packages/statsd/README.md", | ||
"engines": { | ||
"node": ">=12.14.0" | ||
}, | ||
"dependencies": { | ||
@@ -45,3 +48,4 @@ "change-case": "^4.1.1", | ||
} | ||
} | ||
}, | ||
"gitHead": "40de4af181104f298cbab42d2d3d68e228a9a31a" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22
22439
409
1