proteus-js-client
Version:
Proteus JavaScript Client
96 lines (79 loc) • 5.34 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 UnwrappingRSocket = function () {
function UnwrappingRSocket(source) {
_classCallCheck(this, UnwrappingRSocket);
this._source = source;
}
UnwrappingRSocket.prototype._unwrap = function _unwrap(payload) {
if (payload.metadata == null) {
throw new Error('metadata is empty');
}
var frame = (0, _frames.decodeFrame)(payload.metadata);
switch (frame.type) {
case _frames.FrameTypes.DESTINATION:
case _frames.FrameTypes.GROUP:
case _frames.FrameTypes.BROADCAST:
case _frames.FrameTypes.SHARD:
return {
metadata: frame.metadata,
data: payload.data
};
default:
throw new Error('unknown frame type ' + (0, _frames.getFrameTypeName)(frame.type));
}
};
UnwrappingRSocket.prototype.fireAndForget = function fireAndForget(payload) {
this._source.fireAndForget(this._unwrap(payload));
};
UnwrappingRSocket.prototype.requestResponse = function requestResponse(payload) {
try {
return this._source.requestResponse(this._unwrap(payload));
} catch (error) {
return _rsocketFlowable.Single.error(error);
}
};
UnwrappingRSocket.prototype.requestStream = function requestStream(payload) {
try {
return this._source.requestStream(this._unwrap(payload));
} catch (error) {
return _rsocketFlowable.Flowable.error(error);
}
};
UnwrappingRSocket.prototype.requestChannel = function requestChannel(payloads) {
var _this = this;
return this._source.requestChannel(payloads.map(function (payload) {
return _this._unwrap(payload);
}));
};
UnwrappingRSocket.prototype.metadataPush = function metadataPush(payload) {
try {
return this._source.metadataPush(this._unwrap(payload));
} catch (error) {
return _rsocketFlowable.Single.error(error);
}
};
return UnwrappingRSocket;
}();
exports.default = UnwrappingRSocket;