UNPKG

@deltares/fews-pi-requests

Version:

Library for making requests to the FEWS PI webservice

80 lines 3.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.convertToParameterGroups = void 0; /** * Checks if the provided value is of type Parameter. * * @param {Parameter | any} parameter - The value to be checked. * @returns {boolean} True if the value is of type Parameter, false otherwise. */ function isParameter(parameter) { return parameter.name !== undefined; } /** * Checks if the provided value is of type ParameterGroup. * * @param {ParameterGroup | any} parameter - The value to be checked. * @returns {boolean} True if the value is of type ParameterGroup, false otherwise. */ function isParameterGroup(parameter) { return parameter.parameters !== undefined; } /** * Converts the response from a TimeSeriesParameters API call to the ParameterGroupsOutput format. * * @param {TimeSeriesParametersResponse} response - The response from the TimeSeriesParameters API call. * @returns {ParameterGroupsOutput} The converted output in the ParameterGroupsOutput format. */ function convertToParameterGroups(response) { const groupIds = []; const result = { parameters: [] }; for (const tsParameter of response.timeSeriesParameters) { const parameterGroupId = tsParameter.parameterGroup; if (parameterGroupId !== undefined && groupIds.includes(parameterGroupId)) { const group = result.parameters.find(g => "parameters" in g && g.id === parameterGroupId); if (isParameterGroup(group) && isParameter(tsParameter)) { const parameter = { id: tsParameter.id, name: tsParameter.name, shortName: tsParameter.shortName }; group.parameters.push(parameter); } } else if (parameterGroupId !== undefined) { groupIds.push(parameterGroupId); const parameterGroup = { id: parameterGroupId, parameterType: tsParameter.parameterType === "instantaneous" ? "instantaneous" : "accumulative", unit: tsParameter.unit ?? '', parameters: [] }; if (tsParameter.displayUnit !== tsParameter.unit) parameterGroup.displayUnit = tsParameter.displayUnit; if (tsParameter.usesDatum === "true") parameterGroup.usesDatum = true; if (isParameter(tsParameter)) { const parameter = { id: tsParameter.id, name: tsParameter.name, shortName: tsParameter.shortName }; parameterGroup.parameters.push(parameter); } result.parameters.push(parameterGroup); } else if (isParameter(tsParameter)) { const parameter = { id: tsParameter.id, name: tsParameter.name, shortName: tsParameter.shortName }; result.parameters.push(parameter); } } return result; } exports.convertToParameterGroups = convertToParameterGroups; //# sourceMappingURL=convertToParameterGroups.js.map