airbyte-faros-destination 0.10.60 → 0.10.61
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.
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
import { AirbyteLogger } from 'faros-airbyte-cdk';
|
|
1
2
|
import { FarosClient } from 'faros-js-client';
|
|
2
3
|
import { DestinationRecord } from '../converter';
|
|
3
4
|
export declare class LocationCollector {
|
|
5
|
+
private readonly logger?;
|
|
4
6
|
private readonly farosClient?;
|
|
5
7
|
private readonly locationsCache;
|
|
6
|
-
constructor(resolveLocation: boolean, farosClient?: FarosClient);
|
|
8
|
+
constructor(resolveLocation: boolean, farosClient?: FarosClient, logger?: AirbyteLogger);
|
|
7
9
|
collect(location?: string): Promise<{
|
|
8
10
|
uid: string;
|
|
9
11
|
} | null>;
|
|
10
12
|
convertLocations(): DestinationRecord[];
|
|
13
|
+
private handleUncodedLocation;
|
|
11
14
|
}
|
|
@@ -1,33 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LocationCollector = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
4
5
|
class LocationCollector {
|
|
5
|
-
constructor(resolveLocation, farosClient) {
|
|
6
|
+
constructor(resolveLocation, farosClient, logger) {
|
|
7
|
+
this.logger = logger;
|
|
6
8
|
this.locationsCache = new Map();
|
|
7
9
|
if (resolveLocation && farosClient) {
|
|
8
10
|
this.farosClient = farosClient;
|
|
9
11
|
}
|
|
10
12
|
}
|
|
11
13
|
async collect(location) {
|
|
12
|
-
|
|
14
|
+
var _a, _b;
|
|
15
|
+
const normalizedLocation = location === null || location === void 0 ? void 0 : location.trim();
|
|
16
|
+
if (!normalizedLocation) {
|
|
13
17
|
return null;
|
|
14
18
|
}
|
|
15
|
-
if (this.locationsCache.has(
|
|
16
|
-
|
|
19
|
+
if (this.locationsCache.has(normalizedLocation)) {
|
|
20
|
+
const cached = this.locationsCache.get(normalizedLocation);
|
|
21
|
+
return { uid: cached.uid };
|
|
17
22
|
}
|
|
18
23
|
if (!this.farosClient) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return { uid: location };
|
|
24
|
+
return this.handleUncodedLocation(normalizedLocation);
|
|
25
|
+
}
|
|
26
|
+
const data = await this.farosClient.geocode(normalizedLocation);
|
|
27
|
+
if (!((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.uid)) {
|
|
28
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.warn(`Invalid geocoding response for location '${normalizedLocation}'. ` +
|
|
29
|
+
'Will use non-geocoded location.');
|
|
30
|
+
return this.handleUncodedLocation(normalizedLocation);
|
|
27
31
|
}
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
this.locationsCache.set(location, resolvedLocation);
|
|
32
|
+
const resolvedLocation = data[0];
|
|
33
|
+
this.locationsCache.set(normalizedLocation, resolvedLocation);
|
|
31
34
|
return { uid: resolvedLocation.uid };
|
|
32
35
|
}
|
|
33
36
|
convertLocations() {
|
|
@@ -35,37 +38,61 @@ class LocationCollector {
|
|
|
35
38
|
const seenCoordinates = new Set();
|
|
36
39
|
const records = [];
|
|
37
40
|
Array.from(this.locationsCache.values()).forEach((location) => {
|
|
41
|
+
var _a;
|
|
38
42
|
const address = location.address;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
const isValidAddress = address === null || address === void 0 ? void 0 : address.uid;
|
|
44
|
+
if (isValidAddress) {
|
|
45
|
+
if (!seenAddresses.has(address.uid)) {
|
|
46
|
+
records.push({
|
|
47
|
+
model: 'geo_Address',
|
|
48
|
+
record: address,
|
|
49
|
+
});
|
|
50
|
+
seenAddresses.add(address.uid);
|
|
51
|
+
}
|
|
45
52
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
const rawCoordinates = location.coordinates;
|
|
54
|
+
const lat = (rawCoordinates === null || rawCoordinates === void 0 ? void 0 : rawCoordinates.lat) ? (0, lodash_1.toNumber)(rawCoordinates.lat) : null;
|
|
55
|
+
const lon = (rawCoordinates === null || rawCoordinates === void 0 ? void 0 : rawCoordinates.lon) ? (0, lodash_1.toNumber)(rawCoordinates.lon) : null;
|
|
56
|
+
const coordinates = (0, lodash_1.isFinite)(lat) && (0, lodash_1.isFinite)(lon) ? { lat, lon } : null;
|
|
57
|
+
if (coordinates) {
|
|
58
|
+
const coordinatesKey = `${rawCoordinates.lat}:${rawCoordinates.lon}`;
|
|
49
59
|
if (!seenCoordinates.has(coordinatesKey)) {
|
|
50
60
|
records.push({
|
|
51
61
|
model: 'geo_Coordinates',
|
|
52
|
-
record:
|
|
62
|
+
record: coordinates,
|
|
53
63
|
});
|
|
54
64
|
seenCoordinates.add(coordinatesKey);
|
|
55
65
|
}
|
|
56
66
|
}
|
|
67
|
+
else {
|
|
68
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.warn(`Invalid coordinates lat: ${rawCoordinates.lat} and lon: ` +
|
|
69
|
+
`${rawCoordinates.lon} for location '${location.raw}'.`);
|
|
70
|
+
}
|
|
71
|
+
// Create location record with optional address and coordinates
|
|
57
72
|
records.push({
|
|
58
73
|
model: 'geo_Location',
|
|
59
74
|
record: {
|
|
60
75
|
uid: location.uid,
|
|
61
76
|
raw: location.raw,
|
|
62
|
-
address: { uid: address.uid },
|
|
63
|
-
coordinates:
|
|
77
|
+
address: isValidAddress ? { uid: address.uid } : null,
|
|
78
|
+
coordinates: coordinates ? { lat, lon } : null,
|
|
64
79
|
},
|
|
65
80
|
});
|
|
66
81
|
});
|
|
67
82
|
return records;
|
|
68
83
|
}
|
|
84
|
+
handleUncodedLocation(normalizedLocation) {
|
|
85
|
+
const address = {
|
|
86
|
+
uid: normalizedLocation,
|
|
87
|
+
fullAddress: normalizedLocation,
|
|
88
|
+
};
|
|
89
|
+
this.locationsCache.set(normalizedLocation, {
|
|
90
|
+
uid: normalizedLocation,
|
|
91
|
+
raw: normalizedLocation,
|
|
92
|
+
address,
|
|
93
|
+
});
|
|
94
|
+
return { uid: normalizedLocation };
|
|
95
|
+
}
|
|
69
96
|
}
|
|
70
97
|
exports.LocationCollector = LocationCollector;
|
|
71
98
|
//# sourceMappingURL=geo.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geo.js","sourceRoot":"","sources":["../../../src/converters/common/geo.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"geo.js","sourceRoot":"","sources":["../../../src/converters/common/geo.ts"],"names":[],"mappings":";;;AAEA,mCAA0C;AAI1C,MAAa,iBAAiB;IAI5B,YACE,eAAwB,EACxB,WAAyB,EACR,MAAsB;QAAtB,WAAM,GAAN,MAAM,CAAgB;QALxB,mBAAc,GAAG,IAAI,GAAG,EAAoB,CAAC;QAO5D,IAAI,eAAe,IAAI,WAAW,EAAE,CAAC;YACnC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QACjC,CAAC;IACH,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,QAAiB;;QAC7B,MAAM,kBAAkB,GAAG,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,EAAE,CAAC;QAC5C,IAAI,CAAC,kBAAkB,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,kBAAkB,CAAC,EAAE,CAAC;YAChD,MAAM,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;YAC3D,OAAO,EAAC,GAAG,EAAE,MAAM,CAAC,GAAG,EAAC,CAAC;QAC3B,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC,qBAAq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