@glue42/bbg-market-data
Version:
A high-level API that wraps existing Glue42 Bloomberg Bridge Market Data interop methods. The API is based on the jBloomberg open source wrapper.
84 lines • 3.85 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GenericRequestImpl = void 0;
const tslib_1 = require("tslib");
const base_request_1 = require("../../core/base-request");
const helpers_1 = require("../../core/helpers");
const event_types_1 = require("../../core/event-types");
const message_handlers_1 = require("../../core/message-handlers");
class GenericRequestImpl extends base_request_1.BaseRequest {
constructor(sessionManager, config, operationArgs) {
super(sessionManager, config, operationArgs);
this.sessionManager = sessionManager;
this.config = config;
this.operationArgs = operationArgs;
}
/**
* Public api.
*/
get api() {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const that = this;
return {
/**
* Dynamically set when the request is (re)opened.
*/
get id() {
return that.requestId;
},
get settings() {
return {
operation: that.config.operation,
service: that.config.service,
operationArgs: that.operationArgs,
};
},
get status() {
return that._status;
},
open: that.open.bind(that),
close: that.closeRequest.bind(that),
onRequestStatusChanged: that.onRequestStatusChanged.bind(that),
};
}
open(options) {
const _super = Object.create(null, {
openRequest: { get: () => super.openRequest }
});
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const _a = options !== null && options !== void 0 ? options : {}, { messageProcessor } = _a, otherOptions = tslib_1.__rest(_a, ["messageProcessor"]);
if (typeof messageProcessor !== "function") {
throw new Error("messageProcessor must be a function");
}
this.userMessageProcessor = messageProcessor;
yield _super.openRequest.call(this, Object.assign(Object.assign({}, otherOptions), { messageProcessor: this.messageProcessor.bind(this) }));
});
}
messageProcessor(eventMessage) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
// Check if the event is a known error type and handle it accordingly.
const error = [
message_handlers_1.sessionStartUpFailureHandler(eventMessage),
message_handlers_1.sessionTerminatedHandler(eventMessage),
message_handlers_1.serviceOpenedFailureHandler(eventMessage),
message_handlers_1.requestFailureHandler(eventMessage),
].find(({ match }) => match);
const processorResult = yield this.userMessageProcessor(eventMessage.eventType, eventMessage.message);
if (error) {
// If the event is a known error type, pass the message and ignore the user action - the request failed.
return { action: "fail", error: error.data };
}
if (helpers_1.isEventOfType(eventMessage, event_types_1.EventTypes.Response)) {
return { action: 'complete' };
}
return processorResult.continue ? { action: 'continue' } : { action: 'close' };
}
catch (error) {
return { action: 'fail', error: error instanceof Error ? error : new Error(String(error)) };
}
});
}
}
exports.GenericRequestImpl = GenericRequestImpl;
//# sourceMappingURL=generic-request.js.map