-
Notifications
You must be signed in to change notification settings - Fork 45
/
destination-selection-strategies.ts
83 lines (74 loc) · 2.73 KB
/
destination-selection-strategies.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved. */
import { AllDestinations } from './destination-accessor-types';
import { Destination } from './destination-service-types';
export type DestinationSelectionStrategy = (
allDestinations: AllDestinations,
destinationName: string
) => Destination | null;
/**
* Constraints the selection to provider destinations.
*
* @param allDestinations - Retrieved destinations
* @param destinationName - Name of the destination to retrieve
* @returns the destination to retrieve, returns null if no matched provider destination is found
*/
export function alwaysProvider(
allDestinations: AllDestinations,
destinationName: string
): Destination | null {
const isRequestedDestination = (destination: Destination) =>
destination.name === destinationName;
return (
allDestinations.provider.instance.find(isRequestedDestination) ||
allDestinations.provider.subaccount.find(isRequestedDestination) ||
null
);
}
/**
* Constraints the selection to subscriber destinations.
*
* @param allDestinations - Retrieved destinations
* @param destinationName - Name of the destination to retrieve
* @returns the destination to retrieve, returns null if no matched subscriber destination is found
*/
export function alwaysSubscriber(
allDestinations: AllDestinations,
destinationName: string
): Destination | null {
const isRequestedDestination = (destination: Destination) =>
destination.name === destinationName;
return (
allDestinations.subscriber.instance.find(isRequestedDestination) ||
allDestinations.subscriber.subaccount.find(isRequestedDestination) ||
null
);
}
/**
* Prioritizes the selection of subscriber destinations.
*
* @param allDestinations - Retrieved destinations
* @param destinationName - Name of the destination to retrieve
* @returns the destination to retrieve, returns null if no matched destination is found
*/
export function subscriberFirst(
allDestinations: AllDestinations,
destinationName: string
): Destination | null {
const isRequestedDestination = (destination: Destination) =>
destination.name === destinationName;
return (
allDestinations.subscriber.instance.find(isRequestedDestination) ||
allDestinations.subscriber.subaccount.find(isRequestedDestination) ||
allDestinations.provider.instance.find(isRequestedDestination) ||
allDestinations.provider.subaccount.find(isRequestedDestination) ||
null
);
}
/**
* Selector of destination selection strategies. See [[alwaysProvider]], [[alwaysSubscriber]] and [[subscriberFirst]] for more information available selection strategies.
*/
export const DestinationSelectionStrategies = {
alwaysProvider,
alwaysSubscriber,
subscriberFirst
};