UNPKG

diffusion

Version:

Diffusion JavaScript client

94 lines (93 loc) 6.29 kB
"use strict"; /** * @module Services.GatewayControl */ var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.GatewayResponseSerialiser = exports.GatewayResponseSerialiserClass = void 0; var Codec = require("./../../io/codec"); var BEES = require("./../../serialisers/byte-encoded-enum-serialiser"); var serialiser_1 = require("./../../serialisers/serialiser"); var gateway_request_type_1 = require("./../../services/gateway-control/gateway-request-type"); var get_configuration_response_1 = require("./../../services/gateway-control/get-configuration-response"); var get_status_response_1 = require("./../../services/gateway-control/get-status-response"); var get_operation_detail_response_1 = require("./../../services/gateway-control/operations/get-operation-detail-response"); var get_operations_response_1 = require("./../../services/gateway-control/operations/get-operations-response"); var invoke_operation_response_1 = require("./../../services/gateway-control/operations/invoke-operation-response"); var operation_serialiser_1 = require("./../../services/gateway-control/operations/operation-serialiser"); var status_item_serialiser_1 = require("./../../services/gateway-control/status-item-serialiser"); var add_update_service_response_1 = require("./add-update-service-response"); var gateway_client_request_serialiser_1 = require("./gateway-client-request-serialiser"); var get_service_types_response_1 = require("./get-service-types-response"); var get_services_response_1 = require("./get-services-response"); var service_detail_serialiser_1 = require("./services/service-detail-serialiser"); var service_type_serialiser_1 = require("./services/service-type-serialiser"); /** * Serialiser for {@link GatewayResponse} */ var GatewayResponseSerialiserClass = /** @class */ (function (_super) { __extends(GatewayResponseSerialiserClass, _super); function GatewayResponseSerialiserClass() { return _super !== null && _super.apply(this, arguments) || this; } /** * Read a {@link GatewayResponse} from the stream * * @param bis the input stream * @return the {@link GatewayResponse} that was read */ // eslint-disable-next-line complexity GatewayResponseSerialiserClass.prototype.read = function (bis) { var type = BEES.read(bis, gateway_request_type_1.GatewayRequestType); switch (type) { case gateway_request_type_1.GatewayRequestType.GET_CONFIGURATION: case gateway_request_type_1.GatewayRequestType.GET_SERVICE_CONFIGURATION: return new get_configuration_response_1.GetConfigurationResponse(type, Codec.readByte(bis), Codec.readString(bis), Codec.readString(bis)); case gateway_request_type_1.GatewayRequestType.GET_STATUS: case gateway_request_type_1.GatewayRequestType.GET_SERVICE_STATUS: return new get_status_response_1.GetStatusResponse(type, Codec.readCollection(bis, status_item_serialiser_1.StatusItemSerialiser.read)); case gateway_request_type_1.GatewayRequestType.GET_OPERATIONS: case gateway_request_type_1.GatewayRequestType.GET_SERVICE_OPERATIONS: return new get_operations_response_1.GetOperationsResponse(type, Codec.readCollection(bis, operation_serialiser_1.GatewayOperationSerialiser.read)); case gateway_request_type_1.GatewayRequestType.GET_OPERATION_DETAIL: case gateway_request_type_1.GatewayRequestType.GET_SERVICE_OPERATION_DETAIL: return new get_operation_detail_response_1.GetOperationDetailResponse(type, Codec.readString(bis), Codec.readByte(bis) ? Codec.readString(bis) : undefined, Codec.readByte(bis) ? Codec.readString(bis) : undefined); case gateway_request_type_1.GatewayRequestType.INVOKE_OPERATION: case gateway_request_type_1.GatewayRequestType.INVOKE_SERVICE_OPERATION: return new invoke_operation_response_1.InvokeOperationResponse(type, Codec.readByte(bis) ? Codec.readString(bis) : undefined); case gateway_request_type_1.GatewayRequestType.ADD_SERVICE: case gateway_request_type_1.GatewayRequestType.UPDATE_SERVICE: return new add_update_service_response_1.AddUpdateServiceResponse(type, service_detail_serialiser_1.GatewayServiceSerialiser.read(bis)); case gateway_request_type_1.GatewayRequestType.GET_SERVICES: return new get_services_response_1.GetServicesResponse(Codec.readCollection(bis, service_detail_serialiser_1.GatewayServiceSerialiser.read)); case gateway_request_type_1.GatewayRequestType.GET_SERVICE_TYPES: return new get_service_types_response_1.GetServiceTypesResponse(Codec.readCollection(bis, service_type_serialiser_1.GatewayServiceTypeSerialiser.read)); case gateway_request_type_1.GatewayRequestType.REMOVE_SERVICE: // Requests which only return an acknoledgement return { type: type }; /* istanbul ignore next */ default: throw new gateway_client_request_serialiser_1.UnknownGatewayRequestTypeError(type); } }; return GatewayResponseSerialiserClass; }(serialiser_1.AbstractSerialiser)); exports.GatewayResponseSerialiserClass = GatewayResponseSerialiserClass; /** * The {@link GatewayResponseSerialiser} singleton */ // eslint-disable-next-line @typescript-eslint/naming-convention exports.GatewayResponseSerialiser = new GatewayResponseSerialiserClass();