UNPKG

backendless

Version:

Backendless JavaScript SDK for Node.js and the browser

330 lines (329 loc) 12.4 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _counter = _interopRequireDefault(require("./counter")); var Counters = /*#__PURE__*/function () { function Counters(app) { (0, _classCallCheck2["default"])(this, Counters); this.app = app; } (0, _createClass2["default"])(Counters, [{ key: "of", value: function of(name) { return new _counter["default"](name, this); } }, { key: "list", value: function () { var _list = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(pattern) { return _regenerator["default"].wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: if (!(pattern !== null && pattern !== undefined && typeof pattern !== 'string')) { _context.next = 2; break; } throw new Error('Counters Pattern can be a string only'); case 2: return _context.abrupt("return", this.app.request.get({ url: this.app.urls.countersList(pattern) })); case 3: case "end": return _context.stop(); } }, _callee, this); })); function list(_x) { return _list.apply(this, arguments); } return list; }() }, { key: "incrementAndGet", value: function () { var _incrementAndGet = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(counterName) { return _regenerator["default"].wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: if (!(!counterName || typeof counterName !== 'string')) { _context2.next = 2; break; } throw new Error('Counter Name must be provided and must be a string.'); case 2: return _context2.abrupt("return", this.app.request.put({ url: this.app.urls.counterIncrementAndGet(counterName) })); case 3: case "end": return _context2.stop(); } }, _callee2, this); })); function incrementAndGet(_x2) { return _incrementAndGet.apply(this, arguments); } return incrementAndGet; }() }, { key: "getAndIncrement", value: function () { var _getAndIncrement = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(counterName) { return _regenerator["default"].wrap(function _callee3$(_context3) { while (1) switch (_context3.prev = _context3.next) { case 0: if (!(!counterName || typeof counterName !== 'string')) { _context3.next = 2; break; } throw new Error('Counter Name must be provided and must be a string.'); case 2: return _context3.abrupt("return", this.app.request.put({ url: this.app.urls.counterGetAndIncrement(counterName) })); case 3: case "end": return _context3.stop(); } }, _callee3, this); })); function getAndIncrement(_x3) { return _getAndIncrement.apply(this, arguments); } return getAndIncrement; }() }, { key: "decrementAndGet", value: function () { var _decrementAndGet = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(counterName) { return _regenerator["default"].wrap(function _callee4$(_context4) { while (1) switch (_context4.prev = _context4.next) { case 0: if (!(!counterName || typeof counterName !== 'string')) { _context4.next = 2; break; } throw new Error('Counter Name must be provided and must be a string.'); case 2: return _context4.abrupt("return", this.app.request.put({ url: this.app.urls.counterDecrementAndGet(counterName) })); case 3: case "end": return _context4.stop(); } }, _callee4, this); })); function decrementAndGet(_x4) { return _decrementAndGet.apply(this, arguments); } return decrementAndGet; }() }, { key: "getAndDecrement", value: function () { var _getAndDecrement = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(counterName) { return _regenerator["default"].wrap(function _callee5$(_context5) { while (1) switch (_context5.prev = _context5.next) { case 0: if (!(!counterName || typeof counterName !== 'string')) { _context5.next = 2; break; } throw new Error('Counter Name must be provided and must be a string.'); case 2: return _context5.abrupt("return", this.app.request.put({ url: this.app.urls.counterGetAndDecrement(counterName) })); case 3: case "end": return _context5.stop(); } }, _callee5, this); })); function getAndDecrement(_x5) { return _getAndDecrement.apply(this, arguments); } return getAndDecrement; }() }, { key: "reset", value: function () { var _reset = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(counterName) { return _regenerator["default"].wrap(function _callee6$(_context6) { while (1) switch (_context6.prev = _context6.next) { case 0: if (!(!counterName || typeof counterName !== 'string')) { _context6.next = 2; break; } throw new Error('Counter Name must be provided and must be a string.'); case 2: return _context6.abrupt("return", this.app.request.put({ url: this.app.urls.counterReset(counterName) })); case 3: case "end": return _context6.stop(); } }, _callee6, this); })); function reset(_x6) { return _reset.apply(this, arguments); } return reset; }() }, { key: "get", value: function () { var _get = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(counterName) { return _regenerator["default"].wrap(function _callee7$(_context7) { while (1) switch (_context7.prev = _context7.next) { case 0: if (!(!counterName || typeof counterName !== 'string')) { _context7.next = 2; break; } throw new Error('Counter Name must be provided and must be a string.'); case 2: return _context7.abrupt("return", this.app.request.get({ url: this.app.urls.counter(counterName) })); case 3: case "end": return _context7.stop(); } }, _callee7, this); })); function get(_x7) { return _get.apply(this, arguments); } return get; }() }, { key: "addAndGet", value: function () { var _addAndGet = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8(counterName, value) { return _regenerator["default"].wrap(function _callee8$(_context8) { while (1) switch (_context8.prev = _context8.next) { case 0: if (!(!counterName || typeof counterName !== 'string')) { _context8.next = 2; break; } throw new Error('Counter Name must be provided and must be a string.'); case 2: if (!(typeof value !== 'number')) { _context8.next = 4; break; } throw new Error('Counter Value must be a number.'); case 4: return _context8.abrupt("return", this.app.request.put({ url: this.app.urls.counterAddAndGet(counterName), query: { value: value } })); case 5: case "end": return _context8.stop(); } }, _callee8, this); })); function addAndGet(_x8, _x9) { return _addAndGet.apply(this, arguments); } return addAndGet; }() }, { key: "getAndAdd", value: function () { var _getAndAdd = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9(counterName, value) { return _regenerator["default"].wrap(function _callee9$(_context9) { while (1) switch (_context9.prev = _context9.next) { case 0: if (!(!counterName || typeof counterName !== 'string')) { _context9.next = 2; break; } throw new Error('Counter Name must be provided and must be a string.'); case 2: if (!(typeof value !== 'number')) { _context9.next = 4; break; } throw new Error('Counter Value must be a number.'); case 4: return _context9.abrupt("return", this.app.request.put({ url: this.app.urls.counterGetAndAdd(counterName), query: { value: value } })); case 5: case "end": return _context9.stop(); } }, _callee9, this); })); function getAndAdd(_x10, _x11) { return _getAndAdd.apply(this, arguments); } return getAndAdd; }() }, { key: "compareAndSet", value: function () { var _compareAndSet = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10(counterName, expected, updated) { return _regenerator["default"].wrap(function _callee10$(_context10) { while (1) switch (_context10.prev = _context10.next) { case 0: if (!(!counterName || typeof counterName !== 'string')) { _context10.next = 2; break; } throw new Error('Counter Name must be provided and must be a string.'); case 2: if (!(typeof expected !== 'number')) { _context10.next = 4; break; } throw new Error('Counter Expected Value must be a number.'); case 4: if (!(typeof updated !== 'number')) { _context10.next = 6; break; } throw new Error('Counter Updated Value must be a number.'); case 6: return _context10.abrupt("return", this.app.request.put({ url: this.app.urls.counterCompareAndSet(counterName), query: { expected: expected, updatedvalue: updated } })); case 7: case "end": return _context10.stop(); } }, _callee10, this); })); function compareAndSet(_x12, _x13, _x14) { return _compareAndSet.apply(this, arguments); } return compareAndSet; }() }]); return Counters; }(); exports["default"] = Counters;