backendless
Version:
Backendless JavaScript SDK for Node.js and the browser
181 lines (180 loc) • 7.15 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ListStore = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _constants = require("../constants");
var _baseStore = require("./base-store");
var _utils = require("../utils");
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
var ListStore = /*#__PURE__*/function (_HiveStore) {
(0, _inherits2["default"])(ListStore, _HiveStore);
var _super = _createSuper(ListStore);
function ListStore() {
(0, _classCallCheck2["default"])(this, ListStore);
return _super.apply(this, arguments);
}
(0, _createClass2["default"])(ListStore, [{
key: "get",
value: function get(from, to) {
if (to !== undefined) {
if (isNaN(to) || typeof to !== 'number') {
throw new Error('Index To must be a number.');
}
if (isNaN(from) || typeof from !== 'number') {
throw new Error('Index From must be a number.');
}
return this.app.request.get({
url: this.getBaseURL(),
query: {
from: from,
to: to
}
});
}
if (from !== undefined) {
if (isNaN(from) || typeof from !== 'number') {
throw new Error('Index must be a number.');
}
return this.app.request.get({
url: "".concat(this.getBaseURL(), "/").concat(from)
});
}
return this.app.request.get({
url: this.getBaseURL()
});
}
}, {
key: "length",
value: function length() {
return this.app.request.get({
url: "".concat(this.getBaseURL(), "/length")
});
}
}, {
key: "insertBefore",
value: function insertBefore(valueToInsert, anchorValue) {
return this.insert(valueToInsert, anchorValue, true);
}
}, {
key: "insertAfter",
value: function insertAfter(valueToInsert, anchorValue) {
return this.insert(valueToInsert, anchorValue, false);
}
}, {
key: "insert",
value: function insert(valueToInsert, anchorValue, before) {
if (!(0, _utils.isHiveValueValid)(valueToInsert)) {
throw new Error('ValueToInsert must be provided and must be one of types: string, number, boolean, object, array.');
}
if (!(0, _utils.isHiveValueValid)(anchorValue)) {
throw new Error('AnchorValue must be provided and must be one of types: string, number, boolean, object, array.');
}
return this.app.request.put({
url: "".concat(this.getBaseURL(), "/insert-").concat(before ? 'before' : 'after'),
data: {
valueToInsert: valueToInsert,
anchorValue: anchorValue
}
});
}
}, {
key: "deleteValue",
value: function deleteValue(value, count) {
if (!(0, _utils.isHiveValueValid)(value)) {
throw new Error('Value must be provided and must be one of types: string, number, boolean, object, array.');
}
if (count !== undefined && (isNaN(count) || typeof count !== 'number')) {
throw new Error('Count must be a number.');
}
return this.app.request.put({
url: "".concat(this.getBaseURL(), "/delete-value"),
data: {
value: value,
count: count
}
});
}
}, {
key: "addFirstValue",
value: function addFirstValue(value) {
if (!(0, _utils.isHiveValueValid)(value)) {
throw new Error('Value must be provided and must be one of types: string, number, boolean, object, array.');
}
return this.app.request.put({
url: "".concat(this.getBaseURL(), "/add-first"),
data: [value]
});
}
}, {
key: "addFirstValues",
value: function addFirstValues(values) {
if (!values || !Array.isArray(values) || !values.length || !(0, _utils.isHiveValueValid)(values)) {
throw new Error('Value must be provided and must be a list of valid JSON items.');
}
return this.app.request.put({
url: "".concat(this.getBaseURL(), "/add-first"),
data: values
});
}
}, {
key: "addLastValue",
value: function addLastValue(value) {
if (!(0, _utils.isHiveValueValid)(value)) {
throw new Error('Value must be provided and must be one of types: string, number, boolean, object, array.');
}
return this.app.request.put({
url: "".concat(this.getBaseURL(), "/add-last"),
data: [value]
});
}
}, {
key: "addLastValues",
value: function addLastValues(values) {
if (!values || !Array.isArray(values) || !values.length || !(0, _utils.isHiveValueValid)(values)) {
throw new Error('Value must be provided and must be a list of valid JSON items.');
}
return this.app.request.put({
url: "".concat(this.getBaseURL(), "/add-last"),
data: values
});
}
}, {
key: "deleteFirst",
value: function deleteFirst(count) {
if (count !== undefined && (isNaN(count) || typeof count !== 'number')) {
throw new Error('Count must be a number.');
}
return this.app.request.put({
url: "".concat(this.getBaseURL(), "/get-first-and-delete"),
query: {
count: count
}
});
}
}, {
key: "deleteLast",
value: function deleteLast(count) {
if (count !== undefined && (isNaN(count) || typeof count !== 'number')) {
throw new Error('Count must be a number.');
}
return this.app.request.put({
url: "".concat(this.getBaseURL(), "/get-last-and-delete"),
query: {
count: count
}
});
}
}]);
return ListStore;
}(_baseStore.HiveStore);
exports.ListStore = ListStore;
(0, _defineProperty2["default"])(ListStore, "TYPE", _constants.HiveTypes.LIST);