proteus-js-client
Version:
Proteus JavaScript Client
118 lines (100 loc) • 5.95 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _rsocketFlowable = require('rsocket-flowable');
var _frames = require('../frames');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /**
* Copyright (c) 2017-present, Netifi Inc.
*
* 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 WrappingRSocket = function () {
function WrappingRSocket(transformer, source) {
_classCallCheck(this, WrappingRSocket);
this._transformer = transformer;
this._source = source;
}
WrappingRSocket.group = function group(_group, tags, source) {
return new WrappingRSocket(function (payload) {
var metadata = (0, _frames.encodeFrame)({
type: _frames.FrameTypes.GROUP,
majorVersion: null,
minorVersion: null,
group: _group,
tags: tags,
metadata: payload.metadata || Buffer.alloc(0)
});
return {
data: payload.data,
metadata: metadata
};
}, source);
};
WrappingRSocket.broadcast = function broadcast(group, tags, source) {
return new WrappingRSocket(function (payload) {
var metadata = (0, _frames.encodeFrame)({
type: _frames.FrameTypes.BROADCAST,
majorVersion: null,
minorVersion: null,
group: group,
tags: tags,
metadata: payload.metadata || Buffer.alloc(0)
});
return {
data: payload.data,
metadata: metadata
};
}, source);
};
WrappingRSocket.prototype.fireAndForget = function fireAndForget(payload) {
this._source.fireAndForget(this._transformer(payload));
};
WrappingRSocket.prototype.requestResponse = function requestResponse(payload) {
try {
return this._source.requestResponse(this._transformer(payload));
} catch (error) {
return _rsocketFlowable.Single.error(error);
}
};
WrappingRSocket.prototype.requestStream = function requestStream(payload) {
try {
return this._source.requestStream(this._transformer(payload));
} catch (error) {
return _rsocketFlowable.Flowable.error(error);
}
};
WrappingRSocket.prototype.requestChannel = function requestChannel(payloads) {
var _this = this;
return this._source.requestChannel(payloads.map(function (payload) {
return _this._transformer(payload);
}));
};
WrappingRSocket.prototype.metadataPush = function metadataPush(payload) {
try {
return this._source.metadataPush(this._transformer(payload));
} catch (error) {
return _rsocketFlowable.Single.error(error);
}
};
WrappingRSocket.prototype.close = function close() {
this._source.close();
};
WrappingRSocket.prototype.connectionStatus = function connectionStatus() {
return this._source.connectionStatus();
};
return WrappingRSocket;
}();
exports.default = WrappingRSocket;