@any-routing/core 0.1.0 → 1.0.0-rc.2

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 (45) hide show
  1. package/README.md +5 -1
  2. package/eslint.config.mjs +24 -0
  3. package/package.json +7 -28
  4. package/project.json +21 -0
  5. package/src/index.ts +4 -0
  6. package/src/lib/core.model.ts +209 -0
  7. package/src/lib/core.ts +572 -0
  8. package/src/lib/data-providers/errors/unauthorized.ts +6 -0
  9. package/src/lib/data-providers/index.ts +39 -0
  10. package/src/lib/utils/dispatcher.ts +37 -0
  11. package/src/lib/utils/{random.js → random.ts} +0 -1
  12. package/src/lib/utils/requester.ts +41 -0
  13. package/tsconfig.json +23 -0
  14. package/tsconfig.lib.json +28 -0
  15. package/tsconfig.spec.json +28 -0
  16. package/vite.config.mts +59 -0
  17. package/src/index.d.ts +0 -4
  18. package/src/index.js +0 -5
  19. package/src/index.js.map +0 -1
  20. package/src/lib/data-providers/errors/index.js +0 -2
  21. package/src/lib/data-providers/errors/index.js.map +0 -1
  22. package/src/lib/data-providers/errors/unauthorized.d.ts +0 -6
  23. package/src/lib/data-providers/errors/unauthorized.js +0 -8
  24. package/src/lib/data-providers/errors/unauthorized.js.map +0 -1
  25. package/src/lib/data-providers/index.d.ts +0 -44
  26. package/src/lib/data-providers/index.js +0 -2
  27. package/src/lib/data-providers/index.js.map +0 -1
  28. package/src/lib/libre-routing.d.ts +0 -43
  29. package/src/lib/libre-routing.js +0 -235
  30. package/src/lib/libre-routing.js.map +0 -1
  31. package/src/lib/libre-routing.model.d.ts +0 -108
  32. package/src/lib/libre-routing.model.js +0 -15
  33. package/src/lib/libre-routing.model.js.map +0 -1
  34. package/src/lib/utils/dispatcher.d.ts +0 -7
  35. package/src/lib/utils/dispatcher.js +0 -25
  36. package/src/lib/utils/dispatcher.js.map +0 -1
  37. package/src/lib/utils/index.js +0 -4
  38. package/src/lib/utils/index.js.map +0 -1
  39. package/src/lib/utils/random.d.ts +0 -1
  40. package/src/lib/utils/random.js.map +0 -1
  41. package/src/lib/utils/requester.d.ts +0 -11
  42. package/src/lib/utils/requester.js +0 -44
  43. package/src/lib/utils/requester.js.map +0 -1
  44. /package/src/lib/data-providers/errors/{index.d.ts → index.ts} +0 -0
  45. /package/src/lib/utils/{index.d.ts → index.ts} +0 -0
package/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  This library was generated with [Nx](https://nx.dev).
4
4
 
5
+ ## Building
6
+
7
+ Run `nx build core` to build the library.
8
+
5
9
  ## Running unit tests
6
10
 
7
- Run `nx test core` to execute the unit tests via [Jest](https://jestjs.io).
11
+ Run `nx test core` to execute the unit tests via [Vitest](https://vitest.dev/).
@@ -0,0 +1,24 @@
1
+ import baseConfig from "../../eslint.config.mjs";
2
+
3
+ export default [
4
+ ...baseConfig,
5
+ {
6
+ files: [
7
+ "**/*.json"
8
+ ],
9
+ rules: {
10
+ "@nx/dependency-checks": [
11
+ "error",
12
+ {
13
+ "ignoredFiles": [
14
+ "{projectRoot}/eslint.config.{js,cjs,mjs,ts,cts,mts}",
15
+ "{projectRoot}/vite.config.{js,ts,mjs,mts}"
16
+ ]
17
+ }
18
+ ]
19
+ },
20
+ languageOptions: {
21
+ parser: await import("jsonc-eslint-parser")
22
+ }
23
+ }
24
+ ];
package/package.json CHANGED
@@ -1,31 +1,10 @@
1
1
  {
2
2
  "name": "@any-routing/core",
3
- "version": "0.1.0",
4
- "private": false,
5
- "license": "MIT",
6
- "author": "Marcin Lazar",
7
- "keywords": [
8
- "MapLibre GL",
9
- "Routing",
10
- "Directions",
11
- "Route",
12
- "OSMR",
13
- "Here",
14
- "Plugin",
15
- "Map",
16
- "js",
17
- "leaflet"
18
- ],
19
- "repository": {
20
- "type": "git",
21
- "url": "https://github.com/marucjmar/any-routing"
22
- },
3
+ "version": "1.0.0-rc.2",
4
+ "type": "module",
5
+ "main": "./index.js",
6
+ "types": "./index.d.ts",
23
7
  "dependencies": {
24
- "@turf/helpers": "6.5.0"
25
- },
26
- "peerDependencies": {
27
- "tslib": "2.5.0"
28
- },
29
- "main": "./src/index.js",
30
- "types": "./src/index.d.ts"
31
- }
8
+ "@types/geojson": "7946.0.16"
9
+ }
10
+ }
package/project.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "core",
3
+ "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
+ "sourceRoot": "libs/core/src",
5
+ "projectType": "library",
6
+ "release": {
7
+ "version": {
8
+ "manifestRootsToUpdate": ["dist/{projectRoot}"],
9
+ "currentVersionResolver": "git-tag",
10
+ "fallbackCurrentVersionResolver": "disk"
11
+ }
12
+ },
13
+ "tags": [],
14
+ "targets": {
15
+ "nx-release-publish": {
16
+ "options": {
17
+ "packageRoot": "dist/{projectRoot}"
18
+ }
19
+ }
20
+ }
21
+ }
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './lib/core';
2
+ export * from './lib/data-providers';
3
+ export * from './lib/core.model';
4
+ export * from './lib/utils';
@@ -0,0 +1,209 @@
1
+ import { AnyRoutingDataProvider, AnyRoutingDataResponse, RouteSummary } from './data-providers';
2
+ import type { AnyRouting } from './core';
3
+
4
+ export type LngLatPosition = number[];
5
+
6
+ export type WaypointPosition = { lat: number; lng: number };
7
+
8
+ export type RoutingEventPayloads<R extends AnyRoutingDataResponse> = {
9
+ calculationStarted: {
10
+ waypoints: InternalWaypoint[];
11
+ };
12
+
13
+ calculationError: {
14
+ error: Error;
15
+ };
16
+
17
+ routesFound: {
18
+ waypoints: InternalWaypoint[];
19
+ data: R;
20
+ };
21
+
22
+ routeSelected: {
23
+ routeId: number;
24
+ route: RouteSummary;
25
+ };
26
+
27
+ waypointsChanged: {
28
+ waypoints: InternalWaypoint[];
29
+ };
30
+
31
+ waypointGeocoded: {
32
+ waypoint: InternalWaypoint;
33
+ };
34
+
35
+ loadingChanged: {
36
+ loading: boolean;
37
+ };
38
+
39
+ stateUpdated: {
40
+ updatedProperties: Array<keyof AnyRoutingState<R>>;
41
+ };
42
+ };
43
+
44
+ export type RoutingEvent<
45
+ R extends AnyRoutingDataResponse,
46
+ E extends keyof RoutingEventPayloads<R>
47
+ > = RoutingEventPayloads<R>[E] & {
48
+ state: AnyRoutingState<R>;
49
+ eventName: E;
50
+ };
51
+
52
+ export type RoutingEvents<R extends AnyRoutingDataResponse> = {
53
+ calculationStarted: {
54
+ state: AnyRoutingState<R>;
55
+ waypoints: InternalWaypoint[];
56
+ };
57
+
58
+ calculationError: {
59
+ state: AnyRoutingState<R>;
60
+ error: Error;
61
+ };
62
+
63
+ routesFound: {
64
+ state: AnyRoutingState<R>;
65
+ waypoints: InternalWaypoint[];
66
+ data: R;
67
+ };
68
+
69
+ routeSelected: {
70
+ state: AnyRoutingState<R>;
71
+ routeId: number;
72
+ route: RouteSummary;
73
+ };
74
+
75
+ waypointsChanged: {
76
+ state: AnyRoutingState<R>;
77
+ waypoints: InternalWaypoint[];
78
+ };
79
+
80
+ waypointGeocoded: {
81
+ state: AnyRoutingState<R>;
82
+ waypoint: InternalWaypoint;
83
+ };
84
+
85
+ loadingChanged: {
86
+ state: AnyRoutingState<R>;
87
+ loading: boolean;
88
+ };
89
+
90
+ stateUpdated: {
91
+ state: AnyRoutingState<R>;
92
+ updatedProperties: Array<keyof AnyRoutingState<R>>;
93
+ };
94
+ };
95
+
96
+
97
+ export type InternalWaypointProperties = {
98
+ index: number;
99
+ isFirst: boolean;
100
+ isLast: boolean;
101
+ };
102
+
103
+ export type AnyRoutingState<DataType = AnyRoutingDataResponse> = {
104
+ data: DataType | undefined;
105
+ waypoints: InternalWaypoint[];
106
+ loading: boolean;
107
+ selectedRouteId: number | undefined | null;
108
+ routesShapeGeojson?: AnyRoutingDataResponse['routesShapeGeojson'];
109
+ };
110
+
111
+ export interface InternalWaypoint {
112
+ index: number;
113
+ position: WaypointPosition;
114
+ originalPosition: WaypointPosition;
115
+ properties: InternalWaypointProperties & Record<string, string | boolean | number>;
116
+ geocoded?: boolean;
117
+ }
118
+
119
+ export function isWaypointPositionEqual(posA: WaypointPosition, posB: WaypointPosition): boolean {
120
+ return posA.lat === posB.lat && posA.lng === posB.lng;
121
+ }
122
+
123
+ export class InternalWaypointC {
124
+ public static fromWaypoint(waypoint: Waypoint, props: InternalWaypointProperties): InternalWaypoint {
125
+ return {
126
+ index: props.index,
127
+ originalPosition: waypoint.position,
128
+ position: waypoint.position,
129
+ geocoded: waypoint.geocoded,
130
+ properties: { ...props, ...(waypoint.properties || {}) },
131
+ };
132
+ }
133
+ }
134
+
135
+ export interface Waypoint {
136
+ position: WaypointPosition;
137
+ originalPosition?: WaypointPosition;
138
+ properties?: Record<string, string | boolean | number>;
139
+ geocoded?: boolean;
140
+ }
141
+
142
+ export type PluginFactory = AnyRoutingPlugin | (new (...args: any[]) => AnyRoutingPlugin);
143
+
144
+ export interface AnyRoutingGeocoder {
145
+ geocode(waypoint: InternalWaypoint): Promise<InternalWaypoint>;
146
+ }
147
+
148
+ export type AnyRoutingProjectorEventMap = {
149
+ previewStarted: Record<string, never>;
150
+ previewFinished: { data: AnyRoutingDataResponse };
151
+ previewError: { error: Error };
152
+ waypointDrag: {
153
+ waypoint: InternalWaypoint;
154
+ };
155
+ waypointDragCommit: {
156
+ waypoint: InternalWaypoint;
157
+ };
158
+ waypointDragEnd: {
159
+ waypoint: InternalWaypoint;
160
+ };
161
+ waypointAdded: {
162
+ waypoint: InternalWaypoint;
163
+ };
164
+ routesProjected: {
165
+ routesShapeGeojson: AnyRoutingDataResponse['routesShapeGeojson'];
166
+ };
167
+ waypointsProjected: {
168
+ waypoints: InternalWaypoint[];
169
+ };
170
+ routeClick: {
171
+ routeId: number;
172
+ };
173
+ routeHighlight: {
174
+ routeId?: number;
175
+ };
176
+ viewStateChanged: {
177
+ state: AnyRoutingState;
178
+ reason: 'route' | 'waypoints' | 'interaction';
179
+ };
180
+ };
181
+
182
+ export interface AnyRoutingProjector {
183
+ waypoints: InternalWaypoint[];
184
+ onAdd(routing: AnyRouting<any>): void;
185
+ onRemove(routing: AnyRouting<any>): void;
186
+ highlightRoute?(routeId?: number): void;
187
+ on<E extends keyof AnyRoutingProjectorEventMap>(
188
+ event: E,
189
+ callback: (event: AnyRoutingProjectorEventMap[E]) => void,
190
+ ): void;
191
+ off<E extends keyof AnyRoutingProjectorEventMap>(
192
+ event: E,
193
+ callback: (event: AnyRoutingProjectorEventMap[E]) => void,
194
+ ): void;
195
+ }
196
+
197
+ export type AnyRoutingOptions<P extends AnyRoutingProjector = AnyRoutingProjector> = {
198
+ dataProvider: AnyRoutingDataProvider;
199
+ projector?: P;
200
+ geocoder?: AnyRoutingGeocoder | ((waypoint: InternalWaypoint) => Promise<InternalWaypoint>);
201
+ plugins?: PluginFactory[];
202
+ uniqueKey?: string;
203
+ waypointsSyncStrategy: 'none' | 'toPath' | 'geocodeFirst';
204
+ };
205
+
206
+ export interface AnyRoutingPlugin {
207
+ onAdd(AnyRouting: AnyRouting<any>): void;
208
+ onRemove(AnyRouting: AnyRouting<any>): void;
209
+ }