import { createLogger } from '@sap-cloud-sdk/util' ; import type { AllDestinations , DestinationsByType } from './destination-accessor-types' ; import type { Destination } from './destination-service-types' ; const logger = createLogger ( { package : 'connectivity' , messageContext : 'destination-selection-strategies' } ) ; internal export type DestinationSelectionStrategy = ( allDestinations : AllDestinations , destinationName : string ) => Destination | null ; param allDestinations param destinationName returns export function alwaysProvider ( allDestinations , destinationName ) { return findDestination ( allDestinations . provider , destinationName ) || null ; } param allDestinations param destinationName returns export function alwaysSubscriber ( allDestinations , destinationName ) { return findDestination ( allDestinations . subscriber , destinationName ) || null ; } param allDestinations param destinationName returns export function subscriberFirst ( allDestinations , destinationName ) { return ( findDestination ( allDestinations . subscriber , destinationName ) || findDestination ( allDestinations . provider , destinationName ) || null ) ; } internal export const DestinationSelectionStrategies = { alwaysProvider , alwaysSubscriber , subscriberFirst } ; function findDestination ( destinations , destinationName ) { const isRequestedDestination = ( destination ) => destination . name === destinationName ; const instanceDest = destinations . instance . find ( isRequestedDestination ) ; const subAccountDest = destinations . subaccount . find ( isRequestedDestination ) ; if ( instanceDest && subAccountDest ) { logger . warn ( `Found destinations named '${ destinationName }' for both, the destination service instance and subaccount. Using instance destination.` ) ; } return instanceDest || subAccountDest ; }