1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.DestinationSelectionStrategies = exports.subscriberFirst = exports.alwaysSubscriber = exports.alwaysProvider = void 0;
|
4 | var util_1 = require("@sap-cloud-sdk/util");
|
5 | var logger = (0, util_1.createLogger)({
|
6 | package: 'core',
|
7 | messageContext: 'destination-selection-strategies'
|
8 | });
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | function alwaysProvider(allDestinations, destinationName) {
|
16 | return findDestination(allDestinations.provider, destinationName) || null;
|
17 | }
|
18 | exports.alwaysProvider = alwaysProvider;
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | function alwaysSubscriber(allDestinations, destinationName) {
|
26 | return findDestination(allDestinations.subscriber, destinationName) || null;
|
27 | }
|
28 | exports.alwaysSubscriber = alwaysSubscriber;
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | function subscriberFirst(allDestinations, destinationName) {
|
36 | return (findDestination(allDestinations.subscriber, destinationName) ||
|
37 | findDestination(allDestinations.provider, destinationName) ||
|
38 | null);
|
39 | }
|
40 | exports.subscriberFirst = subscriberFirst;
|
41 |
|
42 |
|
43 |
|
44 | exports.DestinationSelectionStrategies = {
|
45 | alwaysProvider: alwaysProvider,
|
46 | alwaysSubscriber: alwaysSubscriber,
|
47 | subscriberFirst: subscriberFirst
|
48 | };
|
49 | function findDestination(destinations, destinationName) {
|
50 | var isRequestedDestination = function (destination) {
|
51 | return destination.name === destinationName;
|
52 | };
|
53 | var instanceDest = destinations.instance.find(isRequestedDestination);
|
54 | var subAccountDest = destinations.subaccount.find(isRequestedDestination);
|
55 | if (instanceDest && subAccountDest) {
|
56 | logger.warn("Found destinations named '".concat(destinationName, "' for both, the destination service instance and subaccount. Using instance destination."));
|
57 | }
|
58 | return instanceDest || subAccountDest;
|
59 | }
|
60 |
|
\ | No newline at end of file |