Skip to content

Commit

Permalink
Rename transform request factory
Browse files Browse the repository at this point in the history
Clean-up return in transform request function
  • Loading branch information
amarkensteijn committed Oct 13, 2023
1 parent 3054523 commit c1ac145
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions src/components/map/MapComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ onBeforeMount(() => {
function transformRequest(url: string, resourceType: ResourceType) {
if (!configManager.authenticationIsEnabled)
return {
url: url,
url,
}
if (resourceType === 'Image' && url.indexOf('GetMap') > -1) {
const requestAuthHeaders = authenticationManager.getAuthorizationHeaders()
return {
url: url,
url,
headers: requestAuthHeaders,
}
}
return {
url: url,
url,
}
}
</script>
4 changes: 2 additions & 2 deletions src/components/ssd/SsdComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@load="onLoad"
@action="onAction"
style="width: 100%"
:transformRequestFn="transformRequestFn()"
:transformRequestFn="createTransformRequestFn()"
>
</schematic-status-display>
</div>
Expand All @@ -37,7 +37,7 @@
import { nextTick, onBeforeUnmount } from 'vue'
import { ref, onMounted, watch } from 'vue'
import { useDisplay } from 'vuetify'
import { transformRequestFn } from '@/lib/requests/transformRequest'
import { createTransformRequestFn } from '@/lib/requests/transformRequest'
interface Props {
src?: string
Expand Down
4 changes: 2 additions & 2 deletions src/components/systemmonitor/ImportStatusComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { ImportStatus, PiWebserviceProvider } from '@deltares/fews-pi-requests'
import { onMounted, onUnmounted, ref } from 'vue'
import { configManager } from '../../services/application-config'
import { VDataTable } from 'vuetify/labs/VDataTable'
import { transformRequestFn } from '@/lib/requests/transformRequest'
import { createTransformRequestFn } from '@/lib/requests/transformRequest'
type UnwrapReadonlyArrayType<A> = A extends Readonly<Array<infer I>>
? UnwrapReadonlyArrayType<I>
: A
Expand All @@ -49,7 +49,7 @@ let active: boolean = false
const baseUrl = configManager.get('VITE_FEWS_WEBSERVICES_URL')
const webServiceProvider = new PiWebserviceProvider(baseUrl, {
transformRequestFn: transformRequestFn(),
transformRequestFn: createTransformRequestFn(),
})
onUnmounted(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/systemmonitor/RunningTasks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
import { configManager } from '../../services/application-config'
import { onMounted, onUnmounted, ref } from 'vue'
import { VDataTable } from 'vuetify/labs/VDataTable'
import { transformRequestFn } from '@/lib/requests/transformRequest'
import { createTransformRequestFn } from '@/lib/requests/transformRequest'
type UnwrapReadonlyArrayType<A> = A extends Readonly<Array<infer I>>
? UnwrapReadonlyArrayType<I>
: A
Expand All @@ -39,7 +39,7 @@ const props = defineProps(['timeOut'])
let noDataText = ref('Loading data..')
const baseUrl = configManager.get('VITE_FEWS_WEBSERVICES_URL')
const webServiceProvider = new PiWebserviceProvider(baseUrl, {
transformRequestFn: transformRequestFn(),
transformRequestFn: createTransformRequestFn(),
})
onUnmounted(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/fews-config/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { configManager } from '../../services/application-config/index.ts'
import type { WebOcComponent, WebOcConfiguration } from './types.ts'
import { PiWebserviceProvider } from '@deltares/fews-pi-requests'
import { transformRequestFn } from '@/lib/requests/transformRequest'
import { createTransformRequestFn } from '@/lib/requests/transformRequest'

export async function getFewsConfig(): Promise<WebOcConfiguration> {
const baseUrl = configManager.get('VITE_FEWS_WEBSERVICES_URL')
const webServiceProvider = new PiWebserviceProvider(baseUrl, {
transformRequestFn: transformRequestFn(),
transformRequestFn: createTransformRequestFn(),
})
const fewsConfig = await webServiceProvider.getWebOcConfiguration()
const webOcComponents: WebOcComponent[] = []
Expand All @@ -22,7 +22,7 @@ export async function getFewsConfig(): Promise<WebOcConfiguration> {
export function getResourcesStaticUrl(resource: string) {
const baseUrl = configManager.get('VITE_FEWS_WEBSERVICES_URL')
const webServiceProvider = new PiWebserviceProvider(baseUrl, {
transformRequestFn: transformRequestFn(),
transformRequestFn: createTransformRequestFn(),
})
return webServiceProvider.resourcesStaticUrl(resource).toString()
}
2 changes: 1 addition & 1 deletion src/lib/requests/transformRequest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { authenticationManager } from '@/services/authentication/AuthenticationManager.ts'

export function transformRequestFn(controller?: AbortController) {
export function createTransformRequestFn(controller?: AbortController) {
return async (request: Request): Promise<Request> => {
return Promise.resolve(
authenticationManager.transformRequestAuth(request, controller?.signal),
Expand Down
4 changes: 2 additions & 2 deletions src/services/useSsd/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { ref, shallowRef, toValue, watchEffect } from 'vue'
import { absoluteUrl } from '../../lib/utils/absoluteUrl.ts'
import type { MaybeRefOrGetter, Ref } from 'vue'
import { transformRequestFn } from '@/lib/requests/transformRequest'
import { createTransformRequestFn } from '@/lib/requests/transformRequest'
export interface UseSsdReturn {
error: Ref<any>
capabilities: Ref<SsdGetCapabilitiesResponse | undefined>
Expand Down Expand Up @@ -45,7 +45,7 @@ export function useSsd(
time: MaybeRefOrGetter<string>,
): UseSsdReturn {
const ssdProvider = new SsdWebserviceProvider(baseUrl, {
transformRequestFn: transformRequestFn(),
transformRequestFn: createTransformRequestFn(),
})

const isReady = ref(false)
Expand Down
4 changes: 2 additions & 2 deletions src/services/useSsdPi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
toValue,
watchEffect,
} from 'vue'
import { transformRequestFn } from '@/lib/requests/transformRequest'
import { createTransformRequestFn } from '@/lib/requests/transformRequest'

export interface UseSsdPiReturn {
displayConfig: Ref<DisplayConfig | undefined>
Expand All @@ -31,7 +31,7 @@ export function useSsdPi(
plotId?: MaybeRefOrGetter<number>,
): UseSsdPiReturn {
const ssdProvider = new SsdWebserviceProvider(baseUrl, {
transformRequestFn: transformRequestFn(),
transformRequestFn: createTransformRequestFn(),
})

const isReady = ref(false)
Expand Down
4 changes: 2 additions & 2 deletions src/services/useTimeSeries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { absoluteUrl } from '../../lib/utils/absoluteUrl'
import { DateTime, Interval } from 'luxon'
import { Series } from '../../lib/timeseries/timeSeries'
import { SeriesUrlRequest } from '../../lib/timeseries/timeSeriesResource'
import { transformRequestFn } from '@/lib/requests/transformRequest'
import { createTransformRequestFn } from '@/lib/requests/transformRequest'

export interface UseTimeSeriesReturn {
error: Ref<any>
Expand Down Expand Up @@ -58,7 +58,7 @@ export function useTimeSeries(
controller.abort()
controller = new AbortController()
const piProvider = new PiWebserviceProvider(baseUrl, {
transformRequestFn: transformRequestFn(controller),
transformRequestFn: createTransformRequestFn(controller),
})
const _requests = toValue(requests)
for (const r in _requests) {
Expand Down
4 changes: 2 additions & 2 deletions src/services/useTopologyNodes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { MaybeRefOrGetter, Ref } from 'vue'
import { DisplayConfig } from '../../lib/display/DisplayConfig.js'
import { timeSeriesDisplayToChartConfig } from '../../lib/charts/timeSeriesDisplayToChartConfig'
import { ChartConfig } from '../../lib/charts/types/ChartConfig.js'
import { transformRequestFn } from '@/lib/requests/transformRequest.js'
import { createTransformRequestFn } from '@/lib/requests/transformRequest.js'

export interface UseTopologyNodesReturn {
error: Ref<any>
Expand Down Expand Up @@ -39,7 +39,7 @@ export function useTopologyNodes(
plotId: MaybeRefOrGetter<number>,
): UseTopologyNodesReturn {
const piProvider = new PiWebserviceProvider(baseUrl, {
transformRequestFn: transformRequestFn(),
transformRequestFn: createTransformRequestFn(),
})

const isReady = ref(false)
Expand Down
6 changes: 3 additions & 3 deletions src/services/useWms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { toWgs84 } from '@turf/projection'
import { point } from '@turf/helpers'
import { LngLatBounds } from 'mapbox-gl'
import { GetLegendGraphicResponse } from '@deltares/fews-wms-requests/src/response/getLegendGraphicResponse.ts'
import { transformRequestFn } from '@/lib/requests/transformRequest'
import { createTransformRequestFn } from '@/lib/requests/transformRequest'

export interface UseWmsReturn {
legendGraphic: Ref<GetLegendGraphicResponse | undefined>
Expand All @@ -25,7 +25,7 @@ export function useWmsLayer(
const legendGraphic = ref<GetLegendGraphicResponse>()
const wmsUrl = `${baseUrl}/wms`
const wmsProvider = new WMSProvider(wmsUrl, {
transformRequestFn: transformRequestFn(),
transformRequestFn: createTransformRequestFn(),
})
const times = ref<Date[]>()

Expand Down Expand Up @@ -99,7 +99,7 @@ export function useWmsCapilities(
const capabilities = ref<GetCapabilitiesResponse>()
const wmsUrl = `${baseUrl}/wms`
const wmsProvider = new WMSProvider(wmsUrl, {
transformRequestFn: transformRequestFn(),
transformRequestFn: createTransformRequestFn(),
})

async function loadCapabilities(): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions src/views/AboutView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import { PiWebserviceProvider, Version } from '@deltares/fews-pi-requests'
import { onMounted } from 'vue'
import { useConfigStore } from '../stores/config.ts'
import { configManager } from '@/services/application-config'
import { transformRequestFn } from '@/lib/requests/transformRequest'
import { createTransformRequestFn } from '@/lib/requests/transformRequest'
const webServiceUrl = configManager.get('VITE_FEWS_WEBSERVICES_URL')
const version = ref(packageConfig.version)
Expand All @@ -69,7 +69,7 @@ const configStore = useConfigStore()
onMounted(async () => {
const webServiceProvider = new PiWebserviceProvider(webServiceUrl, {
transformRequestFn: transformRequestFn(),
transformRequestFn: createTransformRequestFn(),
})
webServiceVersion.value = await (
await webServiceProvider.getVersion()
Expand Down

0 comments on commit c1ac145

Please sign in to comment.