@lyxa.ai/core 1.2.67 → 1.2.68

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,6 +1,6 @@
1
1
  import { GoogleMapsService } from './providers/google-maps';
2
2
  import { OsrmMapService } from './providers/osrm';
3
- import { ICoordinate, IDistanceInfo, IWaypointDistanceInfo, IRouteMatrixDTO } from './interfaces/IMapService';
3
+ import { ICoordinate, IDistanceInfo, IRouteMatrixDTO, IWaypointDistanceInfo } from './interfaces/IMapService';
4
4
  export declare enum MapProvider {
5
5
  GOOGLE = "google",
6
6
  OSRM = "osrm"
@@ -39,8 +39,8 @@ class MapService {
39
39
  }
40
40
  }
41
41
  async calculateDistanceBetweenCoordinates(coord1, coord2, options) {
42
- const [lat1, lon1] = coord1;
43
- const [lat2, lon2] = coord2;
42
+ const [lon1, lat1] = coord1;
43
+ const [lon2, lat2] = coord2;
44
44
  try {
45
45
  const distanceInfo = await this.getProvider(options).getDistanceInfo({ latitude: lat1, longitude: lon1 }, { latitude: lat2, longitude: lon2 });
46
46
  if (distanceInfo && distanceInfo.distance) {
@@ -1 +1 @@
1
- {"version":3,"file":"mapService.js","sourceRoot":"/","sources":["libraries/map/mapService.ts"],"names":[],"mappings":";;;AAUA,IAAY,WAGX;AAHD,WAAY,WAAW;IACtB,gCAAiB,CAAA;IACjB,4BAAa,CAAA;AACd,CAAC,EAHW,WAAW,2BAAX,WAAW,QAGtB;AAOD,MAAa,UAAU;IACd,MAAM,CAAoB;IAC1B,IAAI,CAAiB;IAE7B,YAAY,MAAyB,EAAE,IAAoB;QAC1D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;IAEM,0BAA0B,CAAC,MAAwB,EAAE,MAAwB;QACnF,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,MAAM,CAAC;QAC5B,MAAM,CAAC,IAAI,EAAE,IAAI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AAC,iBAAiB,CACtB,OAA2B,EAC3B,YAAgC,EAChC,OAAoB;QAEpB,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,iBAAiB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACjF,CAAC;CACD;AApFD,gCAoFC","sourcesContent":["import { GoogleMapsService } from './providers/google-maps';\nimport { OsrmMapService } from './providers/osrm';\nimport {\n\tIMapService,\n\tICoordinate,\n\tIDistanceInfo,\n\tIWaypointDistanceInfo,\n\tIRouteMatrixDTO,\n} from './interfaces/IMapService';\n\nexport enum MapProvider {\n\tGOOGLE = 'google',\n\tOSRM = 'osrm',\n}\n\nexport interface MapOptions {\n\tprovider: MapProvider;\n\t// Add other options if needed\n}\n\nexport class MapService {\n\tprivate google: GoogleMapsService;\n\tprivate osrm: OsrmMapService;\n\n\tconstructor(google: GoogleMapsService, osrm: OsrmMapService) {\n\t\tthis.google = google;\n\t\tthis.osrm = osrm;\n\t}\n\n\tpublic calculateHaversineDistance(coord1: [number, number], coord2: [number, number]): number {\n\t\tconst [lat1, lon1] = coord1;\n\t\tconst [lat2, lon2] = coord2;\n\t\tconst R = 6371;\n\t\tconst dLat = ((lat2 - lat1) * Math.PI) / 180;\n\t\tconst dLon = ((lon2 - lon1) * Math.PI) / 180;\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\t\tconst c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));\n\t\treturn R * c;\n\t}\n\tprivate getProvider(options?: MapOptions): IMapService {\n\t\t// Default to OSRM if options not provided\n\t\tconst provider = options?.provider ?? MapProvider.OSRM;\n\n\t\tswitch (provider) {\n\t\t\tcase MapProvider.GOOGLE:\n\t\t\t\treturn this.google;\n\t\t\tcase MapProvider.OSRM:\n\t\t\t\treturn this.osrm;\n\t\t\tdefault:\n\t\t\t\tthrow new Error('Unknown map provider');\n\t\t}\n\t}\n\n\tpublic async calculateDistanceBetweenCoordinates(\n\t\tcoord1: [number, number],\n\t\tcoord2: [number, number],\n\t\toptions?: MapOptions // optional\n\t): Promise<number> {\n\t\tconst [lat1, lon1] = coord1;\n\t\tconst [lat2, lon2] = coord2;\n\t\ttry {\n\t\t\tconst distanceInfo = await this.getProvider(options).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;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error(`Error fetching distance info: ${error}`);\n\t\t}\n\t\tconsole.log('Maps API failed. Falling back to Haversine calculation.');\n\t\treturn this.calculateHaversineDistance(coord1, coord2);\n\t}\n\n\tasync getDistanceInfo(\n\t\torigin: ICoordinate,\n\t\tdestination: ICoordinate,\n\t\toptions?: MapOptions\n\t): Promise<IDistanceInfo> {\n\t\treturn await this.getProvider(options).getDistanceInfo(origin, destination);\n\t}\n\n\tasync getWaypointsDistanceInfo(\n\t\torigin: ICoordinate,\n\t\tdestination: ICoordinate,\n\t\twaypoints: Array<ICoordinate>,\n\t\toptions?: MapOptions\n\t): Promise<IWaypointDistanceInfo> {\n\t\treturn await this.getProvider(options).getWaypointsDistanceInfo(origin, destination, waypoints);\n\t}\n\n\tasync getDistanceMatrix(\n\t\torigins: Array<ICoordinate>,\n\t\tdestinations: Array<ICoordinate>,\n\t\toptions?: MapOptions\n\t): Promise<IRouteMatrixDTO[]> {\n\t\treturn await this.getProvider(options).getDistanceMatrix(origins, destinations);\n\t}\n}\n"]}
1
+ {"version":3,"file":"mapService.js","sourceRoot":"/","sources":["libraries/map/mapService.ts"],"names":[],"mappings":";;;AAUA,IAAY,WAGX;AAHD,WAA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C;IACxD,CAAC;IAED,KAAK,CAAC,eAAe,CACpB,MAAmB,EACnB,WAAwB,EACxB,OAAoB;QAEpB,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,eAAe,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAC7E,CAAC;IAED,KAAK,CAAC,wBAAwB,CAC7B,MAAmB,EACnB,WAAwB,EACxB,SAA6B,EAC7B,OAAoB;QAEpB,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,wBAAwB,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;IACjG,CAAC;IAED,KAAK,CAAC,iBAAiB,CACtB,OAA2B,EAC3B,YAAgC,EAChC,OAAoB;QAEpB,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,iBAAiB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACjF,CAAC;CACD;AArFD,gCAqFC","sourcesContent":["import { GoogleMapsService } from './providers/google-maps';\nimport { OsrmMapService } from './providers/osrm';\nimport {\n\tICoordinate,\n\tIDistanceInfo,\n\tIMapService,\n\tIRouteMatrixDTO,\n\tIWaypointDistanceInfo,\n} from './interfaces/IMapService';\n\nexport enum MapProvider {\n\tGOOGLE = 'google',\n\tOSRM = 'osrm',\n}\n\nexport interface MapOptions {\n\tprovider: MapProvider;\n\t// Add other options if needed\n}\n\nexport class MapService {\n\tprivate google: GoogleMapsService;\n\tprivate osrm: OsrmMapService;\n\n\tconstructor(google: GoogleMapsService, osrm: OsrmMapService) {\n\t\tthis.google = google;\n\t\tthis.osrm = osrm;\n\t}\n\n\tpublic calculateHaversineDistance(coord1: [number, number], coord2: [number, number]): number {\n\t\tconst [lat1, lon1] = coord1;\n\t\tconst [lat2, lon2] = coord2;\n\t\tconst R = 6371;\n\t\tconst dLat = ((lat2 - lat1) * Math.PI) / 180;\n\t\tconst dLon = ((lon2 - lon1) * Math.PI) / 180;\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\t\tconst c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));\n\t\treturn R * c;\n\t}\n\tprivate getProvider(options?: MapOptions): IMapService {\n\t\t// Default to OSRM if options not provided\n\t\tconst provider = options?.provider ?? MapProvider.OSRM;\n\n\t\tswitch (provider) {\n\t\t\tcase MapProvider.GOOGLE:\n\t\t\t\treturn this.google;\n\t\t\tcase MapProvider.OSRM:\n\t\t\t\treturn this.osrm;\n\t\t\tdefault:\n\t\t\t\tthrow new Error('Unknown map provider');\n\t\t}\n\t}\n\n\tpublic async calculateDistanceBetweenCoordinates(\n\t\tcoord1: [number, number],\n\t\tcoord2: [number, number],\n\t\toptions?: MapOptions // optional\n\t): Promise<number> {\n\t\tconst [lon1, lat1] = coord1;\n\t\tconst [lon2, lat2] = coord2;\n\n\t\ttry {\n\t\t\tconst distanceInfo = await this.getProvider(options).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;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error(`Error fetching distance info: ${error}`);\n\t\t}\n\t\tconsole.log('Maps API failed. Falling back to Haversine calculation.');\n\t\treturn this.calculateHaversineDistance(coord1, coord2);\n\t}\n\n\tasync getDistanceInfo(\n\t\torigin: ICoordinate,\n\t\tdestination: ICoordinate,\n\t\toptions?: MapOptions\n\t): Promise<IDistanceInfo> {\n\t\treturn await this.getProvider(options).getDistanceInfo(origin, destination);\n\t}\n\n\tasync getWaypointsDistanceInfo(\n\t\torigin: ICoordinate,\n\t\tdestination: ICoordinate,\n\t\twaypoints: Array<ICoordinate>,\n\t\toptions?: MapOptions\n\t): Promise<IWaypointDistanceInfo> {\n\t\treturn await this.getProvider(options).getWaypointsDistanceInfo(origin, destination, waypoints);\n\t}\n\n\tasync getDistanceMatrix(\n\t\torigins: Array<ICoordinate>,\n\t\tdestinations: Array<ICoordinate>,\n\t\toptions?: MapOptions\n\t): Promise<IRouteMatrixDTO[]> {\n\t\treturn await this.getProvider(options).getDistanceMatrix(origins, destinations);\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.2.67
25
+ Version: 1.2.68
26
26
 
27
27
  ## Dependencies
28
28
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/types",
3
- "version": "1.2.67",
3
+ "version": "1.2.68",
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.2.67",
3
+ "version": "1.2.68",
4
4
  "description": "The Core system of the Lyxa services.",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",