UNPKG

@deltares/fews-pi-requests

Version:

Library for making requests to the FEWS PI webservice

1 lines 23.8 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["fews-pi-requests"]=e():t["fews-pi-requests"]=e()}(self,(()=>(()=>{"use strict";var t,e,s={d:(t,e)=>{for(var r in e)s.o(e,r)&&!s.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},r={};function a(t){return void 0!==t.name}function i(t){const e=[],s={parameters:[]};for(const r of t.timeSeriesParameters){const t=r.parameterGroup;if(void 0!==t&&e.includes(t)){const e=s.parameters.find((e=>"parameters"in e&&e.id===t));if(void 0!==e.parameters&&a(r)){const t={id:r.id,name:r.name,shortName:r.shortName};e.parameters.push(t)}}else if(void 0!==t){e.push(t);const i={id:t,parameterType:"instantaneous"===r.parameterType?"instantaneous":"accumulative",unit:r.unit??"",parameters:[]};if(r.displayUnit!==r.unit&&(i.displayUnit=r.displayUnit),"true"===r.usesDatum&&(i.usesDatum=!0),a(r)){const t={id:r.id,name:r.name,shortName:r.shortName};i.parameters.push(t)}s.parameters.push(i)}else if(a(r)){const t={id:r.id,name:r.name,shortName:r.shortName};s.parameters.push(t)}}return s}function n(t){let e;try{e=new URL(t)}catch(s){s instanceof TypeError&&(e=new URL(t,document.baseURI))}return e}function o(t,e=2e3,s){if(t.toString().length<=e)return[t];const r=new URL(t.toString()),a=void 0!==s?s:function(t){const e=function(t){const e=new Map;return t.forEach((t=>{const s=e.get(t)??0;e.set(t,s+1)})),e}(Array.from(t.searchParams.keys()));let s=0,r=Array.from(e.keys())[0];for(const[t,a]of e)a>s&&(s=a,r=t);return r}(t);r.searchParams.delete(a);const i=[];let n=new URL(r.toString());for(const s of t.searchParams.getAll(a))if(n.toString().length+a.length+s.length+2>e&&(i.push(new URL(n.toString())),n=new URL(r.toString())),n.searchParams.append(a,s),n.toString().length>e)throw new Error(`Cannot split url by query parameter '${a}' to be shorter than ${e} <= ${n.toString()}.`);return i.push(n),i}function h(t,e){const s=[];if(e instanceof Array)for(const r of e)s.push(`${encodeURIComponent(t)}=${encodeURIComponent(r)}`);else s.push(`${encodeURIComponent(t)}=${encodeURIComponent(e)}`);return s}function c(t){const e=[];for(const[s,r]of Object.entries(t))if(void 0!==r)if("attribute"===s||"properties"===s){const t={attribute:"attribute",properties:"property"}[s];for(const[s,a]of Object.entries(r)){const r=h(`${t}(${s})`,a);e.push(...r)}}else if("qualifierIds"!==s||"object"!=typeof r||Array.isArray(r))if("bbox"===s){const t=h(s,`${encodeURIComponent(r[0])},${encodeURIComponent(r[1])},${encodeURIComponent(r[2])},${encodeURIComponent(r[3])}`);e.push(...t)}else{const t=h(s,r);e.push(...t)}else for(const[t,a]of Object.entries(r)){const r=h(`${s}`,`${t}=`+a);e.push(...r)}return e.length?"?"+e.join("&"):""}s.r(r),s.d(r,{DocumentFormat:()=>t,FailoverPolicy:()=>b,PiArchiveWebserviceProvider:()=>m,PiWebserviceProvider:()=>g,TaskStatus:()=>d,TimeSeriesType:()=>e,WhatifID:()=>_,convertToParameterGroups:()=>i,isDimensionWithPeriod:()=>I}),function(t){t.PI_XML="PI_XML",t.PI_JSON="PI_JSON",t.PI_CSV="PI_CSV",t.GEO_JSON="GEO_JSON"}(t||(t={})),function(t){t.EXTERNAL_HISTORICAL="EXTERNAL_HISTORICAL",t.EXTERNAL_FORECASTING="EXTERNAL_FORECASTING",t.SIMULATED_HISTORICAL="SIMULATED_HISTORICAL",t.SIMULATED_FORECASTING="SIMULATED_FORECASTING"}(e||(e={}));class l{_mode="cors";_relativeUrl=!0;get relativeUrl(){return this._relativeUrl}set relativeUrl(t){this._relativeUrl=t}get mode(){return this._mode}set mode(t){this._mode=t}}class U{async parse(t){return await t.json()}}class u{webserviceUrl;transformRequest;constructor(t,e){if(this.webserviceUrl=t,void 0!==e)this.transformRequest=e;else{async function s(t){return t}this.transformRequest=s}}async getDataWithParser(t,e,s){const r=e.relativeUrl?this.webserviceUrl+t:t,a=new Request(r,{method:"GET"}),i=await fetch(await this.transformRequest(a));if(!i.ok)throw new Error("Fetch Error",{cause:i});return await this.processResponse({},i,r,s)}async postDataWithParser(t,e,s,r,a){const i=e.relativeUrl?this.webserviceUrl+t:t,n={method:"POST"};n.body=r,n.headers=a;const o=new Request(i,n),h=await fetch(await this.transformRequest(o));if(!h.ok)throw new Error("Fetch Error",{cause:h});return await this.processResponse({},h,i,s)}async getData(t){const e=new l;return e.relativeUrl=!t.startsWith("http"),this.getDataWithParser(t,e,new U)}async postData(t,e,s={"Content-Type":"application/json"}){const r=new l;return r.relativeUrl=!t.startsWith("http"),this.postDataWithParser(t,r,new U,e,s)}async processResponse(t,e,s,r){t.responseCode=e.status,t.contentType=e.headers.get("content-type");try{t.data=await r.parse(e)}catch(t){throw new Error(`Parse Error for response ${s}.`,{cause:t})}return t}}class p{async parse(t){return await t.text()}}class g{_baseUrl;maxUrlLength;API_ENDPOINT="rest/fewspiservice/v1";webservice;constructor(t,e={}){t.endsWith("/")||(t+="/"),this._baseUrl=n(t),this.maxUrlLength=e.maxUrlLength??1/0,this.webservice=new u(t,e.transformRequestFn)}async getLocations(t){const e=this.locationsUrl(t);return(await this.webservice.getData(e.toString())).data}async getLogDisplays(t){const e=this.logDisplaysUrl(t);return(await this.webservice.getData(e.toString())).data}async getLocationsTooltip(t){const e=this.locationsTooltipUrl(t).toString(),s=new p,r=new l;return r.relativeUrl=!e.startsWith("http"),(await this.webservice.getDataWithParser(e,r,s)).data}async getHistoryEdits(t){let e=t.editUrl;for(const s in t.times)e=e+"&times="+t.times[s];return(await this.webservice.getData(e)).data}async getParameters(t,e){const s=this.parametersUrl(t),r=await this.webservice.getData(s.toString());return"parameterGroups"===e?.type?i(r.data):r.data}async getTimeSeriesWithRelativeUrl(t){const e=new URL(t,this._baseUrl);return(await this.webservice.getData(e.toString())).data}async getTimeSeriesTopologyActions(e){const s={documentFormat:t.PI_JSON,...e},r=this.timeSeriesTopologyActionsUrl(s);return await this.getTimeSeriesResponse(r)}async getTimeSeries(e){const s={documentFormat:t.PI_JSON,...e},r=this.timeSeriesUrl(s);return await this.getTimeSeriesResponse(r)}async getTimeSeriesResponse(t){if(t.toString().length<=this.maxUrlLength)return(await this.webservice.getData(t.toString())).data;{const e=o(t,this.maxUrlLength).map((t=>this.webservice.getData(t.toString())));return Promise.all(e).then((t=>{const e=t[0].data;if(void 0!==e.timeSeries)for(let s=1;s<t.length;s++)void 0!==t[s].data.timeSeries&&e.timeSeries.push(...t[s].data.timeSeries||[]);return e}))}}async getTimeSeriesGrid(e){const s={documentFormat:t.PI_JSON,...e},r=this.timeSeriesGridUrl(s);return(await this.webservice.getData(r.toString())).data}async getTimeSeriesGridActions(t){const e=this.timeSeriesGridActionsUrl(t);return(await this.webservice.getData(e.toString())).data}async getTimeSeriesGridMaxValues(t){const e=this.timeSeriesGridMaxValuesUrl(t);return(await this.webservice.getData(e.toString())).data}async getTaskRuns(t){const e={...t},s=this.taskRunsUrl(e);return await this.getTaskRunsResponse(s)}async getTaskRunsResponse(t){if(t.toString().length<=this.maxUrlLength)return(await this.webservice.getData(t.toString())).data;const e=o(t,this.maxUrlLength).map((t=>t.toString())).map((t=>this.webservice.getData(t))),s=await Promise.all(e),r=s.flatMap((t=>t.data.taskRuns??[])),a=s[0].data;return r.length&&(a.taskRuns=r),a}async getTopologyNodes(){const t=this.topologyNodesUrl();return(await this.webservice.getData(t.toString())).data}async getTopologyThresholds(t){const e=this.topologyThresholdsUrl(t);return(await this.webservice.getData(e.toString())).data}async getImportStatus(){const t=this.importStatusUrl();return(await this.webservice.getData(t.toString())).data}async getVersion(){const t=this.versionUrl("documentFormat=PI_JSON");return(await this.webservice.getData(t.toString())).data}async getTimeZoneId(){const t=this.timeZoneIdUrl().toString(),e=new p,s=new l;return s.relativeUrl=!t.startsWith("http"),(await this.webservice.getDataWithParser(t.toString(),s,e)).data}async getWebOcConfiguration(){const e={documentFormat:t.PI_JSON},s=this.webOcConfigurationUrl(e);return(await this.webservice.getData(s.toString())).data}async getWebOcPublicConfiguration(){const e={documentFormat:t.PI_JSON},s=this.webOcPublicConfigurationUrl(e);return(await this.webservice.getData(s.toString())).data}async getColors(){const t=new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/colors/default`,this._baseUrl);return(await this.webservice.getData(t.toString())).data}async getTopologyActions(t){const e=this.topologyActionsUrl(t);return(await this.webservice.getData(e.toString())).data}async getDisplayGroupsNodes(){const t=this.displayGroupsNodesUrl();return(await this.webservice.getData(t.toString())).data}async getFlags(){const t=this.flagsUrl();return(await this.webservice.getData(t.toString())).data}async getFlagSources(){const t=this.flagSourcesUrl();return(await this.webservice.getData(t.toString())).data}async getFilterActions(t){const e=this.filterActionsUrl(t);return(await this.webservice.getData(e.toString())).data}async getWorkflows(t){const e=this.workflowsUrl(t);return(await this.webservice.getData(e.toString())).data}async getModuleRunTimes(t){const e=this.moduleRunTimesUrl(t);return(await this.webservice.getData(e.toString())).data}async getDashboards(t){const e=this.dashboardsUrl(t);return(await this.webservice.getData(e.toString())).data}async getLogDisplayLogs(t){const e=this.logDisplayLogsUrl(t);return(await this.webservice.getData(e.toString())).data}async postLogDisplaysAction(t){const{logDisplayId:e,...s}=t,r=this.logDisplayActionUrl(e),a=new p,i=new l;return i.relativeUrl=!r.toString().startsWith("http"),(await this.webservice.postDataWithParser(r.toString(),i,a,JSON.stringify(s),{"Content-Type":"application/json"})).data}async getWhatIfTemplates(t){const e=this.whatIfTemplatesUrl(t);return(await this.webservice.getData(e.toString())).data}async getComponentSettings(t){const e=this.componentSettingsUrl(t);return(await this.webservice.getData(e.toString())).data}async getForecasterNotes(t){const e=this.forecasterNotesUrl(t);return(await this.webservice.getData(e.toString())).data}async getFssInfo(t){const e=this.fssInfoUrl(t);return(await this.webservice.getData(e.toString())).data}async getForecastTimes(t){const e=this.forecastTimesUrl(t);return(await this.webservice.getData(e.toString())).data}async postForecasterNoteHelper(t,e){const s=new p,r=new l;return r.relativeUrl=!e.toString().startsWith("http"),(await this.webservice.postDataWithParser(e.toString(),r,s,JSON.stringify(t),{"Content-Type":"application/json"})).data}async postForecasterNote(t){const e=this.forecasterNotesUrl({});return await this.postForecasterNoteHelper(t,e)}async deleteForecasterNote(t){const e=this.forecasterNotesUrl({},"delete");return await this.postForecasterNoteHelper(t,e)}async acknowledgeForecasterNote(t){const e=this.forecasterNotesUrl({},"acknowledge");return await this.postForecasterNoteHelper(t,e)}async unacknowledgeForecasterNote(t){const e=this.forecasterNotesUrl({},"unacknowledge");return await this.postForecasterNoteHelper(t,e)}async getWhatIfScenarios(t){const e=this.whatIfScenariosUrl(t);return(await this.webservice.getData(e.toString())).data}async postTimeSeriesEdit(t,e){const s=new l;return s.relativeUrl=!t.toString().startsWith("http"),(await this.webservice.postDataWithParser(t,s,new p,JSON.stringify(e),{"Content-Type":"application/json"})).data}async postRunTask(t,e){const s=this.runTaskUrl(t),r=new l;return r.relativeUrl=!s.toString().startsWith("http"),(await this.webservice.postDataWithParser(s.toString(),r,new p,e,{"Content-Type":"application/x-www-form-urlencoded"})).data}async postWhatIfScenario(t,e){const s=this.postWhatIfScenarioUrl(t),r=new l;return r.relativeUrl=!s.toString().startsWith("http"),(await this.webservice.postDataWithParser(s.toString(),r,new U,e,{"Content-Type":"application/x-www-form-urlencoded"})).data}async getReports(t){const e=this.reportsUrl(t);return(await this.webservice.getData(e.toString())).data}async getReport(t){const e=this.reportUrl(t).toString(),s=new p,r=new l;return r.relativeUrl=!e.startsWith("http"),(await this.webservice.getDataWithParser(e,r,s)).data}async getDynamicReportDisplay(t){const e=this.dynamicReportDisplayUrl(t).toString(),s=new p,r=new l;return r.relativeUrl=!e.startsWith("http"),(await this.webservice.getDataWithParser(e,r,s)).data}async getDynamicReportDisplayCapabilities(t){const e=this.dynamicReportDisplayUrl(t,"capabilities").toString();return(await this.webservice.getData(e)).data}async getDynamicReportDisplayData(t){const e=this.dynamicReportDisplayUrl(t,"data").toString();return(await this.webservice.getData(e)).data}async getTimeSteps(t){const e=this.timeStepsUrl(t);return(await this.webservice.getData(e.toString())).data}async getCorrelation(t){const e=this.correlationUrl(t);return(await this.webservice.getData(e.toString())).data}async getDataAnalysisDisplays(t){const e=this.dataAnalysisDisplaysUrl(t);return(await this.webservice.getData(e.toString())).data}async getTaskRunStatus(t){const e=this.taskRunStatusUrl(t);return(await this.webservice.getData(e.toString())).data}async getUserSettings(t,e){const s=this.userSettingsUrl(t),r=new l;return r.relativeUrl=!s.toString().startsWith("http"),(await this.webservice.getDataWithParser(s.toString(),r,e??new U)).data}async postUserSettings(t,e){const s=this.userSettingsUrl(t),r=new p,a=new l;return a.relativeUrl=!s.toString().startsWith("http"),(await this.webservice.postDataWithParser(s.toString(),a,r,e,{"Content-Type":"application/json"})).data}async getUserSettingsUsers(t){const e=this.userSettingsUsersUrl(t);return(await this.webservice.getData(e.toString())).data}locationsUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/locations${e}`,this._baseUrl)}logDisplaysUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/logdisplays${e}`,this._baseUrl)}locationsTooltipUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/locations/tooltip${e}`,this._baseUrl)}historyEditsUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/timeseries/history/${e}`,this._baseUrl)}parametersUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/parameters${e}`,this._baseUrl)}timeSeriesUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/timeseries${e}`,this._baseUrl)}timeSeriesGridUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/timeseries/grid${e}`,this._baseUrl)}timeSeriesGridMaxValuesUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/timeseries/grid/maxvalues${e}`,this._baseUrl)}topologyActionsUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/topology/actions${e}`,this._baseUrl)}timeSeriesGridActionsUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/timeseries/grid/actions${e}`,this._baseUrl)}filterActionsUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/filters/actions${e}`,this._baseUrl)}displayGroupsNodesUrl(){return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/displaygroups/nodes`,this._baseUrl)}taskRunsUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/taskruns${e}`,this._baseUrl)}importStatusUrl(){return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/import/status?documentFormat=PI_JSON`,this._baseUrl)}versionUrl(t){return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/version?${t}`,this._baseUrl)}timeZoneIdUrl(){return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/timezoneid`,this._baseUrl)}webOcConfigurationUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/weboc/config${e}`,this._baseUrl)}webOcPublicConfigurationUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/weboc/config/public${e}`,this._baseUrl)}resourcesStaticUrl(t){return t.startsWith("http://")||t.startsWith("https://")?new URL(t):new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/resources/static/${t}`,this._baseUrl)}resourcesIconsUrl(t){return t.startsWith("http://")||t.startsWith("https://")?new URL(t):new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/resources/icons/${t}`,this._baseUrl)}topologyNodesUrl(){return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/topology/nodes`,this._baseUrl)}topologyThresholdsUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/topology/thresholds${e}`,this._baseUrl)}timeSeriesTopologyActionsUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/timeseries/topology/actions${e}`,this._baseUrl)}flagsUrl(){return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/flags`,this._baseUrl)}flagSourcesUrl(){return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/flagsources`,this._baseUrl)}processDataUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/processdata${e}`,this._baseUrl)}runTaskUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/runtask${e}`,this._baseUrl)}reportsUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/reports${e}`,this._baseUrl)}reportUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/report${e}`,this._baseUrl)}dynamicReportDisplayUrl(t,e){const s=c(t);return e?new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/dynamicreportdisplays/${e}${s}`,this._baseUrl):new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/dynamicreportdisplays${s}`,this._baseUrl)}workflowsUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/workflows${e}`,this._baseUrl)}moduleRunTimesUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/moduleruntimes${e}`,this._baseUrl)}dashboardsUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/dashboards${e}`,this._baseUrl)}logDisplayLogsUrl(t){const{logDisplayId:e,...s}=t,r=c(s);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/logdisplays/${e}/logs${r}`,this._baseUrl)}logDisplayActionUrl(t){return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/logdisplays/${t}/action`,this._baseUrl)}whatIfScenariosUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/whatifscenarios${e}`,this._baseUrl)}whatIfTemplatesUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/whatiftemplates${e}`,this._baseUrl)}postWhatIfScenarioUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/whatifscenarios${e}`,this._baseUrl)}componentSettingsUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/weboc/config/componentsettings${e}`,this._baseUrl)}forecasterNotesUrl(t,e){const s=c(t);return e?new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/forecasternotes/${e}/${s}`,this._baseUrl):new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/forecasternotes${s}`,this._baseUrl)}fssInfoUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/workflows/fssinfo${e}`,this._baseUrl)}forecastTimesUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/workflows/forecasttimes${e}`,this._baseUrl)}timeSeriesFilterActionsUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/timeseries/filters/actions${e}`,this._baseUrl)}timeStepsUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/timesteps${e}`,this._baseUrl)}correlationUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/statistics/correlation${e}`,this._baseUrl)}dataAnalysisDisplaysUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/dataanalysisdisplays${e}`,this._baseUrl)}taskRunStatusUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/taskrunstatus${e}`,this._baseUrl)}userSettingsUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/usersettings${e}`,this._baseUrl)}postUserSettingsUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/usersettings${e}`,this._baseUrl)}userSettingsUsersUrl(t){const e=c(t);return new URL(`${this._baseUrl.pathname}${this.API_ENDPOINT}/usersettings/users${e}`,this._baseUrl)}}const w={parameterIds:"long_name"};class m{baseUrl;maxUrlLength;API_ENDPOINT="rest/fewspiservice/v1";webservice;addPiJsonFormat(e){return e+(0==e.length?"?":"&")+"documentFormat="+t.PI_JSON}constructor(t,e={}){t.endsWith("/")||(t+="/"),this.baseUrl=n(t),this.maxUrlLength=e.maxUrlLength??1/0,this.webservice=new u(t,e.transformRequestFn)}async getParameters(t){const e=this.parametersUrl(t);return(await this.webservice.getData(e.toString())).data}parametersUrl(t){const e=c(t);return new URL(`${this.baseUrl.pathname}${this.API_ENDPOINT}/archive/parameters${e}`,this.baseUrl)}async getLocations(t){const e=this.locationsUrl(t);return(await this.webservice.getData(e.toString())).data}locationsUrl(t){const e=c(t);return new URL(`${this.baseUrl.pathname}${this.API_ENDPOINT}/archive/locations${e}`,this.baseUrl)}async getAreas(t){const e=this.areasUrl(t);return(await this.webservice.getData(e.toString())).data}areasUrl(t){const e=c(t);return new URL(`${this.baseUrl.pathname}${this.API_ENDPOINT}/archive/areas${e}`,this.baseUrl)}async getSources(t){const e=this.sourcesUrl(t);return(await this.webservice.getData(e.toString())).data}sourcesUrl(t){const e=c(t);return new URL(`${this.baseUrl.pathname}${this.API_ENDPOINT}/archive/sources${e}`,this.baseUrl)}async getAttributes(t){const e=this.attributesUrl(t);return(await this.webservice.getData(e.toString())).data}attributesUrl(t){const e=c(t);return new URL(`${this.baseUrl.pathname}${this.API_ENDPOINT}/archive/attributes${e}`,this.baseUrl)}async getExternalForecasts(e){const s={};for(const[t,r]of Object.entries(e))t in Object.keys(w)?s[w[t]]=r:s[t]=r;const r={documentFormat:t.PI_JSON},a={...s,...r},i=this.externalForecastsUrl(a);return(await this.webservice.getData(i.toString())).data}externalForecastsUrl(t){const e=c(t);return new URL(`${this.baseUrl.pathname}${this.API_ENDPOINT}/archive/netcdfstorageforecasts${e}`,this.baseUrl)}async getProductsMetaData(t){const e=c(t),s=this.productsMetaDataUrl(e);return(await this.webservice.getData(s.toString())).data}productsMetaDataUrl(t){return new URL(`${this.baseUrl.pathname}${this.API_ENDPOINT}/archive/productsmetadata${t}`,this.baseUrl)}async getTimeSeries(e){const s={documentFormat:t.PI_JSON,...e},r=this.timeSeriesUrl(s);if(r.toString().length<=this.maxUrlLength)return(await this.webservice.getData(r.toString())).data;{const t=o(r,this.maxUrlLength).map((t=>this.webservice.getData(t.toString())));return Promise.all(t).then((t=>{const e=t[0].data;if(void 0!==e.timeSeries)for(let s=1;s<t.length;s++)void 0!==t[s].data.timeSeries&&e.timeSeries.push(...t[s].data.timeSeries||[]);return e}))}}timeSeriesUrl(t){const e=c(t);return new URL(`${this.baseUrl.pathname}${this.API_ENDPOINT}/timeseries${e}`,this.baseUrl)}}var b,d,_;function I(t){return void 0!==t.period}return function(t){t.RunDuty="RUN_DUTY",t.RunDutyAndFailover="RUN_DUTY_AND_FAILOVER",t.SuspendDutyInFailover="SUSPEND_DUTY_IN_FAILOVER"}(b||(b={})),function(t){t.A="A",t.B="B",t.C="C",t.D="D",t.F="F",t.I="I",t.P="P",t.R="R",t.S="S",t.T="T"}(d||(d={})),function(t){t.None="None"}(_||(_={})),r})()));