hazelcast-client
Version:
Hazelcast - open source In-Memory Data Grid - client for NodeJS
71 lines • 2.96 kB
JavaScript
"use strict";
var BaseProxy = (function () {
function BaseProxy(client, serviceName, name) {
this.client = client;
this.name = name;
this.serviceName = serviceName;
}
BaseProxy.prototype.createPromise = function (codec, promise) {
var toObject = this.toObject.bind(this);
return promise.then(function (clientMessage) {
if (codec.decodeResponse) {
var raw = codec.decodeResponse(clientMessage, toObject);
var response = raw.response;
if (typeof response === 'undefined') {
return raw;
}
else {
return response;
}
}
});
};
BaseProxy.prototype.encodeInvokeOnKey = function (codec, partitionKey) {
var codecArguments = [];
for (var _i = 2; _i < arguments.length; _i++) {
codecArguments[_i - 2] = arguments[_i];
}
var partitionId = this.client.getPartitionService().getPartitionId(partitionKey);
return this.encodeInvokeOnPartition.apply(this, [codec, partitionId].concat(codecArguments));
};
BaseProxy.prototype.encodeInvokeOnRandomTarget = function (codec) {
var codecArguments = [];
for (var _i = 1; _i < arguments.length; _i++) {
codecArguments[_i - 1] = arguments[_i];
}
var clientMessage = codec.encodeRequest.apply(codec, [this.name].concat(codecArguments));
var invocationResponse = this.client.getInvocationService().invokeOnRandomTarget(clientMessage);
return this.createPromise(codec, invocationResponse);
};
BaseProxy.prototype.encodeInvokeOnPartition = function (codec, partitionId) {
var codecArguments = [];
for (var _i = 2; _i < arguments.length; _i++) {
codecArguments[_i - 2] = arguments[_i];
}
var clientMessage = codec.encodeRequest.apply(codec, [this.name].concat(codecArguments));
var invocationResponse = this.client.getInvocationService()
.invokeOnPartition(clientMessage, partitionId);
return this.createPromise(codec, invocationResponse);
};
BaseProxy.prototype.toData = function (object) {
return this.client.getSerializationService().toData(object);
};
BaseProxy.prototype.toObject = function (data) {
return this.client.getSerializationService().toObject(data);
};
BaseProxy.prototype.getPartitionKey = function () {
return this.name;
};
BaseProxy.prototype.getName = function () {
return this.name;
};
BaseProxy.prototype.getServiceName = function () {
return this.serviceName;
};
BaseProxy.prototype.destroy = function () {
return this.client.getProxyManager().destroyProxy(this.name, this.serviceName);
};
return BaseProxy;
}());
exports.BaseProxy = BaseProxy;
//# sourceMappingURL=BaseProxy.js.map