backendless
Version:
Backendless JavaScript SDK for Node.js and the browser
171 lines (170 loc) • 6.96 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SetStore = void 0;
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
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 _baseStore = require("./base-store");
var _constants = require("../constants");
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 SetStore = /*#__PURE__*/function (_HiveStore) {
(0, _inherits2["default"])(SetStore, _HiveStore);
var _super = _createSuper(SetStore);
function SetStore() {
(0, _classCallCheck2["default"])(this, SetStore);
return _super.apply(this, arguments);
}
(0, _createClass2["default"])(SetStore, [{
key: "get",
value: function get() {
return this.app.request.get({
url: this.getBaseURL()
});
}
}, {
key: "getRandom",
value: function getRandom(count) {
if (count !== undefined && (isNaN(count) || typeof count !== 'number')) {
throw new Error('Count must be a number.');
}
return this.app.request.get({
url: "".concat(this.getBaseURL(), "/random"),
query: {
count: count
}
});
}
}, {
key: "getRandomAndDelete",
value: function getRandomAndDelete(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(), "/random"),
query: {
count: count
}
});
}
}, {
key: "addValue",
value: function addValue(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"),
data: [value]
});
}
}, {
key: "addValues",
value: function addValues(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"),
data: values
});
}
}, {
key: "deleteValue",
value: function deleteValue(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["delete"]({
url: "".concat(this.getBaseURL(), "/values"),
data: [value]
});
}
}, {
key: "deleteValues",
value: function deleteValues(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["delete"]({
url: "".concat(this.getBaseURL(), "/values"),
data: values
});
}
}, {
key: "isValueMember",
value: function isValueMember(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.post({
url: "".concat(this.getBaseURL(), "/contains"),
data: [value]
});
}
}, {
key: "isValuesMembers",
value: function isValuesMembers(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.post({
url: "".concat(this.getBaseURL(), "/contains"),
data: values
});
}
}, {
key: "length",
value: function length() {
return this.app.request.get({
url: "".concat(this.getBaseURL(), "/length")
});
}
}], [{
key: "difference",
value: function difference(keyNames) {
if (!Array.isArray(keyNames)) {
throw new Error('Store keys must be provided and must be an array.');
}
return this.app.request.post({
url: "".concat(this.app.urls.hiveStore(this.hiveName, this.TYPE), "/action/difference"),
data: keyNames
});
}
}, {
key: "intersection",
value: function intersection(keyNames) {
if (!Array.isArray(keyNames)) {
throw new Error('Store keys must be provided and must be an array.');
}
return this.app.request.post({
url: "".concat(this.app.urls.hiveStore(this.hiveName, this.TYPE), "/action/intersection"),
data: keyNames
});
}
}, {
key: "union",
value: function union(keyNames) {
if (!Array.isArray(keyNames)) {
throw new Error('Store keys must be provided and must be an array.');
}
return this.app.request.post({
url: "".concat(this.app.urls.hiveStore(this.hiveName, this.TYPE), "/action/union"),
data: keyNames
});
}
}]);
return SetStore;
}(_baseStore.HiveStore);
exports.SetStore = SetStore;
(0, _defineProperty2["default"])(SetStore, "TYPE", _constants.HiveTypes.SET);
(0, _defineProperty2["default"])(SetStore, "STATIC_METHODS", [].concat((0, _toConsumableArray2["default"])(_baseStore.HiveStore.STATIC_METHODS), ['difference', 'intersection', 'union']));