UNPKG

hazelcast-client

Version:

Hazelcast - open source In-Memory Data Grid - client for NodeJS

131 lines 6.14 kB
"use strict"; /* * Copyright (c) 2008-2018, Hazelcast, Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var SetAddCodec_1 = require("../codec/SetAddCodec"); var SetAddAllCodec_1 = require("../codec/SetAddAllCodec"); var SetGetAllCodec_1 = require("../codec/SetGetAllCodec"); var SetClearCodec_1 = require("../codec/SetClearCodec"); var SetContainsCodec_1 = require("../codec/SetContainsCodec"); var SetContainsAllCodec_1 = require("../codec/SetContainsAllCodec"); var SetIsEmptyCodec_1 = require("../codec/SetIsEmptyCodec"); var SetRemoveCodec_1 = require("../codec/SetRemoveCodec"); var SetCompareAndRemoveAllCodec_1 = require("../codec/SetCompareAndRemoveAllCodec"); var SetCompareAndRetainAllCodec_1 = require("../codec/SetCompareAndRetainAllCodec"); var SetSizeCodec_1 = require("../codec/SetSizeCodec"); var SetAddListenerCodec_1 = require("../codec/SetAddListenerCodec"); var SetRemoveListenerCodec_1 = require("../codec/SetRemoveListenerCodec"); var PartitionSpecificProxy_1 = require("./PartitionSpecificProxy"); var SetProxy = /** @class */ (function (_super) { __extends(SetProxy, _super); function SetProxy() { return _super !== null && _super.apply(this, arguments) || this; } SetProxy.prototype.add = function (entry) { return this.encodeInvoke(SetAddCodec_1.SetAddCodec, this.toData(entry)); }; SetProxy.prototype.addAll = function (items) { return this.encodeInvoke(SetAddAllCodec_1.SetAddAllCodec, this.serializeList(items)); }; SetProxy.prototype.toArray = function () { var _this = this; return this.encodeInvoke(SetGetAllCodec_1.SetGetAllCodec).then(function (items) { return items.map(function (item) { return _this.toObject(item); }); }); }; SetProxy.prototype.clear = function () { return this.encodeInvoke(SetClearCodec_1.SetClearCodec); }; SetProxy.prototype.contains = function (entry) { return this.encodeInvoke(SetContainsCodec_1.SetContainsCodec, this.toData(entry)); }; SetProxy.prototype.containsAll = function (items) { return this.encodeInvoke(SetContainsAllCodec_1.SetContainsAllCodec, this.serializeList(items)); }; SetProxy.prototype.isEmpty = function () { return this.encodeInvoke(SetIsEmptyCodec_1.SetIsEmptyCodec); }; SetProxy.prototype.remove = function (entry) { return this.encodeInvoke(SetRemoveCodec_1.SetRemoveCodec, this.toData(entry)); }; SetProxy.prototype.removeAll = function (items) { return this.encodeInvoke(SetCompareAndRemoveAllCodec_1.SetCompareAndRemoveAllCodec, this.serializeList(items)); }; SetProxy.prototype.retainAll = function (items) { return this.encodeInvoke(SetCompareAndRetainAllCodec_1.SetCompareAndRetainAllCodec, this.serializeList(items)); }; SetProxy.prototype.size = function () { return this.encodeInvoke(SetSizeCodec_1.SetSizeCodec); }; SetProxy.prototype.addItemListener = function (listener, includeValue) { var _this = this; if (includeValue === void 0) { includeValue = true; } var handler = function (message) { SetAddListenerCodec_1.SetAddListenerCodec.handle(message, function (item, uuid, eventType) { var responseObject = _this.toObject(item); var listenerFunction; if (eventType === 1) { listenerFunction = listener.itemAdded; } else if (eventType === 2) { listenerFunction = listener.itemRemoved; } if (listenerFunction) { listenerFunction.call(responseObject, responseObject); } }); }; var codec = this.createEntryListener(this.name, includeValue); return this.client.getListenerService().registerListener(codec, handler); }; SetProxy.prototype.removeItemListener = function (registrationId) { return this.client.getListenerService().deregisterListener(registrationId); }; SetProxy.prototype.serializeList = function (input) { var _this = this; return input.map(function (each) { return _this.toData(each); }); }; SetProxy.prototype.createEntryListener = function (name, includeValue) { return { encodeAddRequest: function (localOnly) { return SetAddListenerCodec_1.SetAddListenerCodec.encodeRequest(name, includeValue, localOnly); }, decodeAddResponse: function (msg) { return SetAddListenerCodec_1.SetAddListenerCodec.decodeResponse(msg).response; }, encodeRemoveRequest: function (listenerId) { return SetRemoveListenerCodec_1.SetRemoveListenerCodec.encodeRequest(name, listenerId); } }; }; return SetProxy; }(PartitionSpecificProxy_1.PartitionSpecificProxy)); exports.SetProxy = SetProxy; //# sourceMappingURL=SetProxy.js.map