@lyxa.ai/core 1.1.49 → 1.1.50

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.
@@ -2,7 +2,8 @@ import { IMapService, ICoordinate, IDistanceInfo, IWaypointDistanceInfo } from '
2
2
  export declare class MapService {
3
3
  private service;
4
4
  constructor(service: IMapService);
5
- calculateDistanceBetweenCoordinates(coord1: [number, number], coord2: [number, number]): number;
5
+ calculateHaversineDistance(coord1: [number, number], coord2: [number, number]): number;
6
+ calculateDistanceBetweenCoordinates(coord1: [number, number], coord2: [number, number]): Promise<number>;
6
7
  getDistanceInfo(origin: ICoordinate, destination: ICoordinate): Promise<IDistanceInfo>;
7
8
  getWaypointsDistanceInfo(origin: ICoordinate, destination: ICoordinate, waypoints: Array<ICoordinate>): Promise<IWaypointDistanceInfo>;
8
9
  }
@@ -16,7 +16,7 @@ let MapService = class MapService {
16
16
  constructor(service) {
17
17
  this.service = service;
18
18
  }
19
- calculateDistanceBetweenCoordinates(coord1, coord2) {
19
+ calculateHaversineDistance(coord1, coord2) {
20
20
  const [lat1, lon1] = coord1;
21
21
  const [lat2, lon2] = coord2;
22
22
  const R = 6371;
@@ -30,6 +30,21 @@ let MapService = class MapService {
30
30
  const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
31
31
  return R * c;
32
32
  }
33
+ async calculateDistanceBetweenCoordinates(coord1, coord2) {
34
+ const [lat1, lon1] = coord1;
35
+ const [lat2, lon2] = coord2;
36
+ try {
37
+ const distanceInfo = await this.service.getDistanceInfo({ latitude: lat1, longitude: lon1 }, { latitude: lat2, longitude: lon2 });
38
+ if (distanceInfo && distanceInfo.distance) {
39
+ return distanceInfo.distance.value / 1000;
40
+ }
41
+ }
42
+ catch (error) {
43
+ console.error(`Error fetching distance info: ${error}`);
44
+ }
45
+ console.log('Maps API failed. Falling back to Haversine calculation.');
46
+ return this.calculateHaversineDistance(coord1, coord2);
47
+ }
33
48
  async getDistanceInfo(origin, destination) {
34
49
  return await this.service.getDistanceInfo(origin, destination);
35
50
  }
@@ -1 +1 @@
1
- {"version":3,"file":"mapService.js","sourceRoot":"/","sources":["libraries/map/mapService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAAiC;AAI1B,IAAM,UAAU,GAAhB,MAAM,UAAU;IACF;IAApB,YAAoB,OAAoB;QAApB,YAAO,GAAP,OAAO,CAAa;IAAG,CAAC;IAUrC,mCAAmC,CAAC,MAAwB,EAAE,MAAwB;QAC5F,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,MAAM,CAAC;QAC5B,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,MAAM,CAAC;QAG5B,MAAM,CAAC,GAAG,IAAI,CAAC;QAGf,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;QAC7C,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;QAE7C,MAAM,CAAC,GACN,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC;YACvC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;gBAC/B,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;gBAChC,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC;gBAClB,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;QAErB,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAEzD,OAAO,CAAC,GAAG,CAAC,CAAC;IACd,CAAC;IASD,KAAK,CAAC,eAAe,CAAC,MAAmB,EAAE,WAAwB;QAClE,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAChE,CAAC;IAUD,KAAK,CAAC,wBAAwB,CAC7B,MAAmB,EACnB,WAAwB,EACxB,SAA6B;QAE7B,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,wBAAwB,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;IACpF,CAAC;CACD,CAAA;AA5DY,gCAAU;qBAAV,UAAU;IADtB,IAAA,gBAAO,GAAE;;GACG,UAAU,CA4DtB","sourcesContent":["import { Service } from 'typedi';\nimport { IMapService, ICoordinate, IDistanceInfo, IWaypointDistanceInfo } from './interfaces/IMapService';\n\n@Service()\nexport class MapService {\n\tconstructor(private service: IMapService) {}\n\n\t/**\n\t * Calculates the distance between two coordinates in kilometers\n\t * using the Haversine formula\n\t *\n\t * @param coord1 - First coordinate [latitude, longitude]\n\t * @param coord2 - Second coordinate [latitude, longitude]\n\t * @returns Distance in kilometers\n\t */\n\tpublic calculateDistanceBetweenCoordinates(coord1: [number, number], coord2: [number, number]): number {\n\t\tconst [lat1, lon1] = coord1;\n\t\tconst [lat2, lon2] = coord2;\n\n\t\t// Earth radius in kilometers\n\t\tconst R = 6371;\n\n\t\t// Convert degrees to radians\n\t\tconst dLat = ((lat2 - lat1) * Math.PI) / 180;\n\t\tconst dLon = ((lon2 - lon1) * Math.PI) / 180;\n\n\t\tconst a =\n\t\t\tMath.sin(dLat / 2) * Math.sin(dLat / 2) +\n\t\t\tMath.cos((lat1 * Math.PI) / 180) *\n\t\t\t\tMath.cos((lat2 * Math.PI) / 180) *\n\t\t\t\tMath.sin(dLon / 2) *\n\t\t\t\tMath.sin(dLon / 2);\n\n\t\tconst c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));\n\n\t\treturn R * c;\n\t}\n\n\t/**\n\t * Get the distance and driving duration between two locations\n\t *\n\t * @param origin - Origin coordinate\n\t * @param destination - Destination coordinate\n\t * @returns Distance and duration\n\t */\n\tasync getDistanceInfo(origin: ICoordinate, destination: ICoordinate): Promise<IDistanceInfo> {\n\t\treturn await this.service.getDistanceInfo(origin, destination);\n\t}\n\n\t/**\n\t * Get the distance and driving duration between two locations\n\t *\n\t * @param origin - Origin coordinate\n\t * @param destination - Destination coordinate\n\t * @param waypoints - Coordinates of intermediary waypoints\n\t * @returns Distance, duration, and polyline of each leg and the whole journey\n\t */\n\tasync getWaypointsDistanceInfo(\n\t\torigin: ICoordinate,\n\t\tdestination: ICoordinate,\n\t\twaypoints: Array<ICoordinate>\n\t): Promise<IWaypointDistanceInfo> {\n\t\treturn await this.service.getWaypointsDistanceInfo(origin, destination, waypoints);\n\t}\n}\n"]}
1
+ {"version":3,"file":"mapService.js","sourceRoot":"/","sources":["libraries/map/mapService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAAiC;AAI1B,IAAM,UAAU,GAAhB,MAAM,UAAU;IACF;IAApB,YAAoB,OAAoB;QAApB,YAAO,GAAP,OAAO,CAAa;IAAG,CAAC;IAUrC,0BAA0B,CAAC,MAAwB,EAAE,MAAwB;QACnF,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,MAAM,CAAC;QAC5B,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,MAAM,CAAC;QAG5B,MAAM,CAAC,GAAG,IAAI,CAAC;QAGf,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;QAC7C,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;QAE7C,MAAM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AAE,CAAC,CAAC;QACzD,CAAC;QAGD,OAAO,CAAC,GAAG,CAAC,yDAAyD,CAAC,CAAC;QACvE,OAAO,IAAI,CAAC,0BAA0B,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxD,CAAC;IASD,KAAK,CAAC,eAAe,CAAC,MAAmB,EAAE,WAAwB;QAClE,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAChE,CAAC;IAUD,KAAK,CAAC,wBAAwB,CAC7B,MAAmB,EACnB,WAAwB,EACxB,SAA6B;QAE7B,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,wBAAwB,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;IACpF,CAAC;CACD,CAAA;AA5FY,gCAAU;qBAAV,UAAU;IADtB,IAAA,gBAAO,GAAE;;GACG,UAAU,CA4FtB","sourcesContent":["import { Service } from 'typedi';\nimport { IMapService, ICoordinate, IDistanceInfo, IWaypointDistanceInfo } from './interfaces/IMapService';\n\n@Service()\nexport class MapService {\n\tconstructor(private service: IMapService) {}\n\n\t/**\n\t * Calculates the distance between two coordinates in kilometers\n\t * using the Haversine formula\n\t *\n\t * @param coord1 - First coordinate [latitude, longitude]\n\t * @param coord2 - Second coordinate [latitude, longitude]\n\t * @returns Distance in kilometers\n\t */\n\tpublic calculateHaversineDistance(coord1: [number, number], coord2: [number, number]): number {\n\t\tconst [lat1, lon1] = coord1;\n\t\tconst [lat2, lon2] = coord2;\n\n\t\t// Earth radius in kilometers\n\t\tconst R = 6371;\n\n\t\t// Convert degrees to radians\n\t\tconst dLat = ((lat2 - lat1) * Math.PI) / 180;\n\t\tconst dLon = ((lon2 - lon1) * Math.PI) / 180;\n\n\t\tconst a =\n\t\t\tMath.sin(dLat / 2) * Math.sin(dLat / 2) +\n\t\t\tMath.cos((lat1 * Math.PI) / 180) *\n\t\t\t\tMath.cos((lat2 * Math.PI) / 180) *\n\t\t\t\tMath.sin(dLon / 2) *\n\t\t\t\tMath.sin(dLon / 2);\n\n\t\tconst c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));\n\n\t\treturn R * c;\n\t}\n\n\t/**\n\t * Calculates the distance between two coordinates in kilometers\n\t * using the Haversine formula\n\t *\n\t * @param coord1 - First coordinate [latitude, longitude]\n\t * @param coord2 - Second coordinate [latitude, longitude]\n\t * @returns Distance in kilometers\n\t */\n\tpublic async calculateDistanceBetweenCoordinates(\n\t\tcoord1: [number, number],\n\t\tcoord2: [number, number]\n\t): Promise<number> {\n\t\tconst [lat1, lon1] = coord1;\n\t\tconst [lat2, lon2] = coord2;\n\n\t\ttry {\n\t\t\tconst distanceInfo = await this.service.getDistanceInfo(\n\t\t\t\t{ latitude: lat1, longitude: lon1 },\n\t\t\t\t{ latitude: lat2, longitude: lon2 }\n\t\t\t);\n\t\t\tif (distanceInfo && distanceInfo.distance) {\n\t\t\t\treturn distanceInfo.distance.value / 1000; // Convert meters to kilometers\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error(`Error fetching distance info: ${error}`);\n\t\t}\n\n\t\t// Fallback to Haversine formula if API call fails\n\t\tconsole.log('Maps API failed. Falling back to Haversine calculation.');\n\t\treturn this.calculateHaversineDistance(coord1, coord2);\n\t}\n\n\t/**\n\t * Get the distance and driving duration between two locations\n\t *\n\t * @param origin - Origin coordinate\n\t * @param destination - Destination coordinate\n\t * @returns Distance and duration\n\t */\n\tasync getDistanceInfo(origin: ICoordinate, destination: ICoordinate): Promise<IDistanceInfo> {\n\t\treturn await this.service.getDistanceInfo(origin, destination);\n\t}\n\n\t/**\n\t * Get the distance and driving duration between two locations\n\t *\n\t * @param origin - Origin coordinate\n\t * @param destination - Destination coordinate\n\t * @param waypoints - Coordinates of intermediary waypoints\n\t * @returns Distance, duration, and polyline of each leg and the whole journey\n\t */\n\tasync getWaypointsDistanceInfo(\n\t\torigin: ICoordinate,\n\t\tdestination: ICoordinate,\n\t\twaypoints: Array<ICoordinate>\n\t): Promise<IWaypointDistanceInfo> {\n\t\treturn await this.service.getWaypointsDistanceInfo(origin, destination, waypoints);\n\t}\n}\n"]}
@@ -22,7 +22,7 @@ Perfect for sharing types between frontend and backend applications.
22
22
 
23
23
  ## Version
24
24
 
25
- Version: 1.1.49
25
+ Version: 1.1.50
26
26
 
27
27
  ## Dependencies
28
28
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/types",
3
- "version": "1.1.49",
3
+ "version": "1.1.50",
4
4
  "description": "Lyxa type definitions and validation schemas for both frontend and backend",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/core",
3
- "version": "1.1.49",
3
+ "version": "1.1.50",
4
4
  "description": "The Core system of the Lyxa services.",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",