@reltio/components 1.4.1929 → 1.4.1931

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/cjs/hooks/useMarkers/helpers.d.ts +8 -0
  2. package/cjs/hooks/useMarkers/helpers.js +56 -0
  3. package/cjs/hooks/useMarkers/index.d.ts +2 -0
  4. package/cjs/hooks/useMarkers/index.js +7 -0
  5. package/cjs/hooks/useMarkers/nestedHelpers.d.ts +2 -0
  6. package/cjs/hooks/useMarkers/nestedHelpers.js +31 -0
  7. package/cjs/hooks/useMarkers/nestedHelpers.test.d.ts +1 -0
  8. package/cjs/hooks/useMarkers/nestedHelpers.test.js +235 -0
  9. package/cjs/hooks/useMarkers/referenceHelpers.d.ts +2 -0
  10. package/cjs/hooks/useMarkers/referenceHelpers.js +180 -0
  11. package/cjs/hooks/useMarkers/referenceHelpers.test.d.ts +1 -0
  12. package/cjs/hooks/useMarkers/referenceHelpers.test.js +490 -0
  13. package/cjs/hooks/useMarkers/resolveHelpers.d.ts +8 -0
  14. package/cjs/hooks/useMarkers/resolveHelpers.js +70 -0
  15. package/cjs/hooks/useMarkers/useMarkers.d.ts +5 -0
  16. package/cjs/hooks/useMarkers/useMarkers.js +30 -0
  17. package/cjs/index.d.ts +1 -0
  18. package/cjs/index.js +5 -2
  19. package/esm/hooks/useMarkers/helpers.d.ts +8 -0
  20. package/esm/hooks/useMarkers/helpers.js +49 -0
  21. package/esm/hooks/useMarkers/index.d.ts +2 -0
  22. package/esm/hooks/useMarkers/index.js +2 -0
  23. package/esm/hooks/useMarkers/nestedHelpers.d.ts +2 -0
  24. package/esm/hooks/useMarkers/nestedHelpers.js +27 -0
  25. package/esm/hooks/useMarkers/nestedHelpers.test.d.ts +1 -0
  26. package/esm/hooks/useMarkers/nestedHelpers.test.js +233 -0
  27. package/esm/hooks/useMarkers/referenceHelpers.d.ts +2 -0
  28. package/esm/hooks/useMarkers/referenceHelpers.js +176 -0
  29. package/esm/hooks/useMarkers/referenceHelpers.test.d.ts +1 -0
  30. package/esm/hooks/useMarkers/referenceHelpers.test.js +488 -0
  31. package/esm/hooks/useMarkers/resolveHelpers.d.ts +8 -0
  32. package/esm/hooks/useMarkers/resolveHelpers.js +66 -0
  33. package/esm/hooks/useMarkers/useMarkers.d.ts +5 -0
  34. package/esm/hooks/useMarkers/useMarkers.js +26 -0
  35. package/esm/index.d.ts +1 -0
  36. package/esm/index.js +1 -0
  37. package/package.json +15 -12
@@ -0,0 +1,8 @@
1
+ import { Entity, GeoPoint, Metadata, Point, PrimitiveValue, TEntityType } from '@reltio/mdm-sdk';
2
+ export declare const filterWrongLat: any;
3
+ export declare const isEqualGeoPoints: (aPoint: GeoPoint, bPoint: GeoPoint) => boolean;
4
+ export declare const isSet: (variable: Array<unknown>) => boolean;
5
+ export declare const getAttributeValuesByUri: (entity: Entity, attrTypeUri: string) => PrimitiveValue[];
6
+ type GeoAttribute = TEntityType['geoLocationAttributes'][0];
7
+ export declare const getPointsFromAttributes: (metadata: Metadata, entity: Entity, geoAttr: GeoAttribute) => Point[];
8
+ export {};
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPointsFromAttributes = exports.getAttributeValuesByUri = exports.isSet = exports.isEqualGeoPoints = exports.filterWrongLat = void 0;
4
+ var mdm_sdk_1 = require("@reltio/mdm-sdk");
5
+ var mdm_sdk_2 = require("@reltio/mdm-sdk");
6
+ var ramda_1 = require("ramda");
7
+ var getAttributeValue = function (attr) {
8
+ var value = attr.label || attr.value || '';
9
+ if (Array.isArray(value)) {
10
+ value = value.join(', ');
11
+ }
12
+ else if ((0, ramda_1.is)(Object, value)) {
13
+ value = '';
14
+ }
15
+ return value;
16
+ };
17
+ var parseAttributeValues = function (attributes, attrTypeUri) {
18
+ return Object.values(attributes)
19
+ .filter(Array.isArray)
20
+ .flat(Infinity)
21
+ .filter(mdm_sdk_1.isOv)
22
+ .flatMap(function (attribute) {
23
+ var result;
24
+ if (attribute.type == attrTypeUri) {
25
+ result = [getAttributeValue(attribute)];
26
+ }
27
+ if ((0, ramda_1.is)(Object, attribute.value)) {
28
+ result = (result || []).concat(parseAttributeValues(attribute.value, attrTypeUri));
29
+ }
30
+ return result;
31
+ });
32
+ };
33
+ exports.filterWrongLat = (0, ramda_1.pipe)((0, ramda_1.path)(['point', 'lat']), (0, ramda_1.both)((0, ramda_1.gt)(90), (0, ramda_1.lt)(-90)));
34
+ var isEqualGeoPoints = function (aPoint, bPoint) {
35
+ return (aPoint.entity === bPoint.entity &&
36
+ aPoint.point.lat === bPoint.point.lat &&
37
+ aPoint.point.lng === bPoint.point.lng);
38
+ };
39
+ exports.isEqualGeoPoints = isEqualGeoPoints;
40
+ var isSet = function (variable) { return variable && variable.length > 0; };
41
+ exports.isSet = isSet;
42
+ var getAttributeValuesByUri = function (entity, attrTypeUri) {
43
+ return [].concat((entity === null || entity === void 0 ? void 0 : entity.attributes) ? parseAttributeValues(entity.attributes, attrTypeUri) : []).filter(ramda_1.identity);
44
+ };
45
+ exports.getAttributeValuesByUri = getAttributeValuesByUri;
46
+ var getPointsFromAttributes = function (metadata, entity, geoAttr) {
47
+ if ((0, mdm_sdk_2.hasMaskingByUris)(metadata, [geoAttr.latitude, geoAttr.longitude]))
48
+ return null;
49
+ var lat = (0, exports.getAttributeValuesByUri)(entity, geoAttr.latitude);
50
+ var lng = (0, exports.getAttributeValuesByUri)(entity, geoAttr.longitude);
51
+ if ((0, exports.isSet)(lat) && (0, exports.isSet)(lng)) {
52
+ return (0, ramda_1.zipWith)(function (lat, lng) { return ({ lat: Number(lat), lng: Number(lng) }); }, lat, lng);
53
+ }
54
+ return null;
55
+ };
56
+ exports.getPointsFromAttributes = getPointsFromAttributes;
@@ -0,0 +1,2 @@
1
+ export { useMarkers } from './useMarkers';
2
+ export { resolveMarkers } from './resolveHelpers';
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveMarkers = exports.useMarkers = void 0;
4
+ var useMarkers_1 = require("./useMarkers");
5
+ Object.defineProperty(exports, "useMarkers", { enumerable: true, get: function () { return useMarkers_1.useMarkers; } });
6
+ var resolveHelpers_1 = require("./resolveHelpers");
7
+ Object.defineProperty(exports, "resolveMarkers", { enumerable: true, get: function () { return resolveHelpers_1.resolveMarkers; } });
@@ -0,0 +1,2 @@
1
+ import { Entity, GeoPoint, Metadata } from '@reltio/mdm-sdk';
2
+ export declare const getPointsFromNested: (metadata: Metadata, entities?: Entity[]) => GeoPoint[];
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPointsFromNested = void 0;
4
+ var mdm_sdk_1 = require("@reltio/mdm-sdk");
5
+ var ramda_1 = require("ramda");
6
+ var helpers_1 = require("./helpers");
7
+ var getPointsFromNested = function (metadata, entities) {
8
+ if (entities === void 0) { entities = []; }
9
+ return (0, ramda_1.pipe)((0, ramda_1.chain)(function (entity) {
10
+ var entityType = (0, mdm_sdk_1.getEntityType)(metadata, entity.type);
11
+ return ((entityType === null || entityType === void 0 ? void 0 : entityType.geoLocationAttributes) || []).flatMap(function (geoAttr) {
12
+ if ((0, mdm_sdk_1.findAttributeTypeByUri)(metadata, geoAttr.latitude, entity.type) &&
13
+ (0, mdm_sdk_1.findAttributeTypeByUri)(metadata, geoAttr.longitude, entity.type)) {
14
+ var points = (0, helpers_1.getPointsFromAttributes)(metadata, entity, geoAttr);
15
+ return points === null || points === void 0 ? void 0 : points.map(function (_a) {
16
+ var lat = _a.lat, lng = _a.lng;
17
+ return ({
18
+ id: "".concat(entity.uri, "_nested_").concat(lat, "_").concat(lng),
19
+ entity: entity,
20
+ label: entity.label,
21
+ point: {
22
+ lat: Number(lat),
23
+ lng: Number(lng)
24
+ }
25
+ });
26
+ });
27
+ }
28
+ });
29
+ }), (0, ramda_1.filter)(ramda_1.identity), (0, ramda_1.uniqBy)((0, ramda_1.prop)('id')))(entities);
30
+ };
31
+ exports.getPointsFromNested = getPointsFromNested;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,235 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
+ if (ar || !(i in from)) {
16
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
+ ar[i] = from[i];
18
+ }
19
+ }
20
+ return to.concat(ar || Array.prototype.slice.call(from));
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ var nestedHelpers_1 = require("./nestedHelpers");
24
+ describe('from nested strategy test', function () {
25
+ var metadata = {
26
+ entityTypes: [
27
+ {
28
+ uri: 'configuration/entityTypes/EntityWithNestedAddress',
29
+ geoLocationAttributes: [
30
+ {
31
+ latitude: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation/attributes/Latitude',
32
+ longitude: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation/attributes/Longitude'
33
+ }
34
+ ],
35
+ attributes: [
36
+ {
37
+ name: 'Location',
38
+ type: 'Nested',
39
+ uri: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location',
40
+ attributes: [
41
+ {
42
+ name: 'GeoLocation',
43
+ uri: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation',
44
+ type: 'Nested',
45
+ attributes: [
46
+ {
47
+ name: 'Latitude',
48
+ type: 'String',
49
+ uri: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation/attributes/Latitude'
50
+ },
51
+ {
52
+ name: 'Longitude',
53
+ type: 'String',
54
+ uri: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation/attributes/Longitude'
55
+ }
56
+ ]
57
+ }
58
+ ]
59
+ }
60
+ ]
61
+ }
62
+ ]
63
+ };
64
+ var entities = [
65
+ {
66
+ label: 'label',
67
+ uri: 'entities/1SfTJYdD',
68
+ ov: true,
69
+ type: 'configuration/entityTypes/EntityWithNestedAddress',
70
+ attributes: {
71
+ Location: [
72
+ {
73
+ type: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location',
74
+ ov: true,
75
+ uri: 'entities/1SfTJYdD/attributes/Location/3GXtYP63L',
76
+ value: {
77
+ GeoLocation: [
78
+ {
79
+ type: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation',
80
+ uri: 'entities/1SfTJYdD/attributes/Location/3GXtYP63L/GeoLocation/3GXtYPAJb',
81
+ ov: true,
82
+ value: {
83
+ Longitude: [
84
+ {
85
+ type: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation/attributes/Longitude',
86
+ value: '123',
87
+ ov: true,
88
+ uri: 'entities/1SfTJYdD/attributes/Location/3GXtYP63L/GeoLocation/3GXtYPAJb/Longitude/3GXtYPEZr'
89
+ }
90
+ ],
91
+ Latitude: [
92
+ {
93
+ type: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation/attributes/Latitude',
94
+ value: '321',
95
+ ov: true,
96
+ uri: 'entities/1SfTJYdD/attributes/Location/3GXtYP63L/GeoLocation/3GXtYPAJb/Latitude/3GXtYPIq7'
97
+ }
98
+ ]
99
+ }
100
+ }
101
+ ]
102
+ }
103
+ },
104
+ {
105
+ type: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location',
106
+ ov: true,
107
+ uri: 'entities/1SfTJYdD/attributes/Location/3GXtdfg3L',
108
+ value: {
109
+ GeoLocation: [
110
+ {
111
+ type: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation',
112
+ uri: 'entities/1SfTJYdD/attributes/Location/3GXtdfg3L/GeoLocation/3GXcvb1234',
113
+ ov: true,
114
+ value: {
115
+ Longitude: [
116
+ {
117
+ type: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation/attributes/Longitude',
118
+ value: '456',
119
+ ov: true,
120
+ uri: 'entities/1SfTJYdD/attributes/Location/3GXtdfg3L/GeoLocation/3GXcvb1234/Longitude/3GedY1235'
121
+ }
122
+ ],
123
+ Latitude: [
124
+ {
125
+ type: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation/attributes/Latitude',
126
+ value: '654',
127
+ ov: true,
128
+ uri: 'entities/1SfTJYdD/attributes/Location/3GXtdfg3L/GeoLocation/3GXcvb1234/Latitude/3GXt4ki77'
129
+ }
130
+ ]
131
+ }
132
+ }
133
+ ]
134
+ }
135
+ },
136
+ {
137
+ type: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location',
138
+ ov: false,
139
+ uri: 'entities/1SfTJYdD/attributes/Location/3GXektg3L',
140
+ value: {
141
+ GeoLocation: [
142
+ {
143
+ type: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation',
144
+ uri: 'entities/1SfTJYdD/attributes/Location/3GXektg3L/GeoLocation/3Goke1234',
145
+ ov: true,
146
+ value: {
147
+ Longitude: [
148
+ {
149
+ type: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation/attributes/Longitude',
150
+ value: '456',
151
+ ov: true,
152
+ uri: 'entities/1SfTJYdD/attributes/Location/3GXektg3L/GeoLocation/3Goke1234/Longitude/3hedY1235'
153
+ }
154
+ ],
155
+ Latitude: [
156
+ {
157
+ type: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation/attributes/Latitude',
158
+ value: '654',
159
+ ov: true,
160
+ uri: 'entities/1SfTJYdD/attributes/Location/3GXektg3L/GeoLocation/3Goke1234/Latitude/6GXt4ki77'
161
+ }
162
+ ]
163
+ }
164
+ }
165
+ ]
166
+ }
167
+ }
168
+ ]
169
+ }
170
+ }
171
+ ];
172
+ it('should get geo location attributes from nested address', function () {
173
+ var points = (0, nestedHelpers_1.getPointsFromNested)(metadata, entities);
174
+ expect(points.length).toBe(2);
175
+ expect(points[0].entity).toEqual(entities[0]);
176
+ expect(points[0].label).toBe('label');
177
+ expect(points[0].point).toEqual({ lat: 321, lng: 123 });
178
+ expect(points[1].entity).toEqual(entities[0]);
179
+ expect(points[1].label).toBe('label');
180
+ expect(points[1].point).toEqual({ lat: 654, lng: 456 });
181
+ expect(points[0].id).not.toBe(points[1].id);
182
+ });
183
+ it('should add only uniq points', function () {
184
+ var points = (0, nestedHelpers_1.getPointsFromNested)(metadata, [
185
+ __assign(__assign({}, entities[0]), { attributes: __assign(__assign({}, entities[0].attributes), { Location: __spreadArray(__spreadArray([], entities[0].attributes.Location, true), entities[0].attributes.Location, true) }) })
186
+ ]);
187
+ expect(points.length).toBe(2);
188
+ });
189
+ it('should not fail if entity type is not found', function () {
190
+ var points = (0, nestedHelpers_1.getPointsFromNested)(metadata, [{}]);
191
+ expect(points.length).toBe(0);
192
+ });
193
+ it('should return empty array if geoLocationAttributes is not exists', function () {
194
+ var points = (0, nestedHelpers_1.getPointsFromNested)({
195
+ entityTypes: [
196
+ {
197
+ uri: 'configuration/entityTypes/EntityWithNestedAddress',
198
+ attributes: [
199
+ {
200
+ name: 'Location',
201
+ type: 'Nested',
202
+ uri: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location',
203
+ attributes: [
204
+ {
205
+ name: 'GeoLocation',
206
+ uri: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation',
207
+ type: 'Nested',
208
+ attributes: [
209
+ {
210
+ name: 'Latitude',
211
+ type: 'String',
212
+ uri: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation/attributes/Latitude'
213
+ },
214
+ {
215
+ name: 'Longitude',
216
+ type: 'String',
217
+ uri: 'configuration/entityTypes/EntityWithNestedAddress/attributes/Location/attributes/GeoLocation/attributes/Longitude'
218
+ }
219
+ ]
220
+ }
221
+ ]
222
+ }
223
+ ]
224
+ }
225
+ ]
226
+ }, entities);
227
+ expect(points).toEqual([]);
228
+ });
229
+ it('should not consider attributes with masking while constructing point', function () {
230
+ var maskedMetadata = JSON.parse(JSON.stringify(metadata));
231
+ maskedMetadata.entityTypes[0].attributes[0].attributes[0].attributes[0].masking = { regex: '***' };
232
+ var points = (0, nestedHelpers_1.getPointsFromNested)(maskedMetadata, entities);
233
+ expect(points.length).toBe(0);
234
+ });
235
+ });
@@ -0,0 +1,2 @@
1
+ import { Entity, GeoPoint, Metadata } from '@reltio/mdm-sdk';
2
+ export declare const getPointsFromReference: (servicesPath: string, metadata: Metadata, entities?: Entity[]) => Promise<GeoPoint[]>;
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.getPointsFromReference = void 0;
51
+ var ramda_1 = require("ramda");
52
+ var mdm_sdk_1 = require("@reltio/mdm-sdk");
53
+ var masking_1 = require("@reltio/mdm-sdk/src/metadata/masking");
54
+ var helpers_1 = require("./helpers");
55
+ var getGeoLocation = function (servicesPath, entity, attributes, metadata, refAttribute, name) { return __awaiter(void 0, void 0, void 0, function () {
56
+ var entityType, results, geoLocation, results, response, _a;
57
+ var _b;
58
+ return __generator(this, function (_c) {
59
+ switch (_c.label) {
60
+ case 0:
61
+ if (entity && entity.type) {
62
+ entityType = (0, mdm_sdk_1.getEntityType)(metadata, entity.type);
63
+ if (refAttribute) {
64
+ entity = __assign(__assign({}, entity), { attributes: (_b = {}, _b[name] = [refAttribute], _b) });
65
+ }
66
+ results = (entityType.geoLocationAttributes || [])
67
+ .map(function (geoAttr) { return (0, helpers_1.getPointsFromAttributes)(metadata, entity, geoAttr); })
68
+ .filter(ramda_1.identity);
69
+ if (results.length > 0) {
70
+ return [2 /*return*/, Promise.resolve(results[0])];
71
+ }
72
+ }
73
+ geoLocation = attributes['GeoLocation'];
74
+ if (geoLocation) {
75
+ results = geoLocation
76
+ .map(function (loc) {
77
+ var lat = loc.value['Latitude'];
78
+ var lon = loc.value['Longitude'];
79
+ if ((0, helpers_1.isSet)(lat) && lat[0].value && (0, helpers_1.isSet)(lon) && lon[0].value) {
80
+ var hasMasking = (0, masking_1.hasMaskingByUris)(metadata, [lat[0].type, lon[0].type]);
81
+ return hasMasking ? null : { id: loc.uri, lat: Number(lat[0].value), lng: Number(lon[0].value) };
82
+ }
83
+ })
84
+ .filter(ramda_1.identity);
85
+ if (results.length > 0) {
86
+ return [2 /*return*/, Promise.resolve(results)];
87
+ }
88
+ }
89
+ if (!(refAttribute && refAttribute.label)) return [3 /*break*/, 4];
90
+ _c.label = 1;
91
+ case 1:
92
+ _c.trys.push([1, 3, , 4]);
93
+ return [4 /*yield*/, (0, mdm_sdk_1.decodeAddress)({ servicesPath: servicesPath, address: refAttribute.label })];
94
+ case 2:
95
+ response = _c.sent();
96
+ return [2 /*return*/, response.location];
97
+ case 3:
98
+ _a = _c.sent();
99
+ return [2 /*return*/, null];
100
+ case 4: return [2 /*return*/, Promise.resolve(null)];
101
+ }
102
+ });
103
+ }); };
104
+ var prepareData = function (metadata, entities) {
105
+ var map = {};
106
+ return (0, ramda_1.flatten)(entities.map(function (entity) {
107
+ var _a;
108
+ if (entity.type === 'configuration/entityTypes/Location') {
109
+ return { id: entity.uri, label: entity.label, entity: entity, pointSource: entity.attributes };
110
+ }
111
+ else {
112
+ map[entity.type] =
113
+ map[entity.type] ||
114
+ (((_a = (0, mdm_sdk_1.getEntityType)(metadata, entity.type)) === null || _a === void 0 ? void 0 : _a.attributes) || [])
115
+ .filter(function (attribute) { return attribute.referencedEntityTypeURI === 'configuration/entityTypes/Location'; })
116
+ .map(function (_a) {
117
+ var name = _a.name;
118
+ return name;
119
+ });
120
+ return map[entity.type]
121
+ .map(function (attrName) { return [attrName, entity.attributes[attrName]]; })
122
+ .filter(function (_a) {
123
+ var value = _a[1];
124
+ return value;
125
+ })
126
+ .flatMap(function (_a) {
127
+ var name = _a[0], attributes = _a[1];
128
+ return attributes.map(function (attribute) { return ({
129
+ id: attribute.uri,
130
+ label: attribute.label,
131
+ entity: entity,
132
+ pointSource: attribute.value,
133
+ refAttribute: attribute,
134
+ name: name
135
+ }); });
136
+ });
137
+ }
138
+ }));
139
+ };
140
+ var getPointsFromReference = function (servicesPath, metadata, entities) {
141
+ if (entities === void 0) { entities = []; }
142
+ return __awaiter(void 0, void 0, void 0, function () {
143
+ var data, results;
144
+ return __generator(this, function (_a) {
145
+ switch (_a.label) {
146
+ case 0:
147
+ data = prepareData(metadata, entities);
148
+ return [4 /*yield*/, Promise.all(data.map(function (_a) {
149
+ var id = _a.id, label = _a.label, entity = _a.entity, pointSource = _a.pointSource, refAttribute = _a.refAttribute, name = _a.name;
150
+ return getGeoLocation(servicesPath, entity, pointSource, metadata, refAttribute, name)
151
+ .then(function (points) {
152
+ if (!points && entity.label) {
153
+ return (0, mdm_sdk_1.decodeAddress)({ servicesPath: servicesPath, address: entity.label })
154
+ .then(function (response) { return response.location; })
155
+ .catch(function () { return null; });
156
+ }
157
+ else {
158
+ return points;
159
+ }
160
+ })
161
+ .then(function (points) {
162
+ return (0, mdm_sdk_1.wrapInArrayIfNeeded)(points)
163
+ .filter(ramda_1.identity)
164
+ .map(function (point) { return ({
165
+ id: point.id || id,
166
+ label: label,
167
+ entity: entity,
168
+ point: point
169
+ }); });
170
+ })
171
+ .catch(function () { return null; });
172
+ }))];
173
+ case 1:
174
+ results = _a.sent();
175
+ return [2 /*return*/, results.flat(Infinity).filter(ramda_1.identity)];
176
+ }
177
+ });
178
+ });
179
+ };
180
+ exports.getPointsFromReference = getPointsFromReference;
@@ -0,0 +1 @@
1
+ export {};