@asyncapi/react-component
Version:
A React component for AsyncAPI specification.
82 lines • 3.75 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommonHelpers = void 0;
var types_1 = require("../types");
var constants_1 = require("../constants");
var CommonHelpers = (function () {
function CommonHelpers() {
}
CommonHelpers.getIdentifier = function (id, config) {
var schemaID = config === null || config === void 0 ? void 0 : config.schemaID;
if (schemaID) {
return "".concat(schemaID, "-").concat(id);
}
return id;
};
CommonHelpers.getOperationType = function (operation) {
if (operation.isSend()) {
if (operation.reply() !== undefined) {
return types_1.PayloadType.REQUEST;
}
else {
return types_1.PayloadType.SEND;
}
}
if (operation.isReceive() && operation.reply() !== undefined) {
return types_1.PayloadType.REPLY;
}
return types_1.PayloadType.RECEIVE;
};
CommonHelpers.getOperationIdentifier = function (_a) {
var operation = _a.operation, config = _a.config;
if (operation.isSend()) {
if (operation.reply() !== undefined) {
return CommonHelpers.getIdentifier("operation-".concat(types_1.PayloadType.REQUEST, "-").concat(operation.id()), config);
}
else {
return CommonHelpers.getIdentifier("operation-".concat(types_1.PayloadType.SEND, "-").concat(operation.id()), config);
}
}
if (operation.isReceive() && operation.reply() !== undefined) {
return CommonHelpers.getIdentifier("operation-".concat(types_1.PayloadType.REPLY, "-").concat(operation.id()), config);
}
return CommonHelpers.getIdentifier("operation-".concat(types_1.PayloadType.RECEIVE, "-").concat(operation.id()), config);
};
CommonHelpers.getOperationDesignInformation = function (_a) {
var _b, _c, _d, _e, _f, _g;
var type = _a.type, config = _a.config, isAsyncAPIv2 = _a.isAsyncAPIv2;
if (type === types_1.PayloadType.RECEIVE) {
return {
borderColor: 'border-green-600 text-green-600',
backgroundColor: 'bg-green-600',
typeLabel: !isAsyncAPIv2
? (_b = config.receiveLabel) !== null && _b !== void 0 ? _b : constants_1.RECEIVE_TEXT_LABEL_DEFAULT_TEXT
: (_c = config.publishLabel) !== null && _c !== void 0 ? _c : constants_1.PUBLISH_LABEL_DEFAULT_TEXT,
};
}
if (type === types_1.PayloadType.REPLY) {
return {
borderColor: 'border-orange-600 text-orange-600',
backgroundColor: 'bg-orange-600',
typeLabel: (_d = config.replyLabel) !== null && _d !== void 0 ? _d : constants_1.REPLIER_LABEL_DEFAULT_TEXT,
};
}
if (type === types_1.PayloadType.REQUEST) {
return {
borderColor: 'border-red-600 text-red-600',
backgroundColor: 'bg-red-600',
typeLabel: (_e = config.requestLabel) !== null && _e !== void 0 ? _e : constants_1.REQUEST_LABEL_DEFAULT_TEXT,
};
}
return {
borderColor: 'border-blue-600 text-blue-500',
backgroundColor: 'bg-blue-600',
typeLabel: !isAsyncAPIv2
? (_f = config.sendLabel) !== null && _f !== void 0 ? _f : constants_1.SEND_LABEL_DEFAULT_TEXT
: (_g = config.subscribeLabel) !== null && _g !== void 0 ? _g : constants_1.SUBSCRIBE_LABEL_DEFAULT_TEXT,
};
};
return CommonHelpers;
}());
exports.CommonHelpers = CommonHelpers;
//# sourceMappingURL=common.js.map
;