mobility-toolbox-js 2.0.1-beta.13 → 2.1.0

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 (259) hide show
  1. package/api/RealtimeAPI.d.ts +279 -0
  2. package/api/RealtimeAPI.d.ts.map +1 -0
  3. package/api/RealtimeAPI.js +466 -0
  4. package/api/RoutingAPI.d.ts +37 -0
  5. package/api/RoutingAPI.d.ts.map +1 -0
  6. package/api/RoutingAPI.js +32 -12
  7. package/api/StopsAPI.d.ts +38 -0
  8. package/api/StopsAPI.d.ts.map +1 -0
  9. package/api/StopsAPI.js +33 -9
  10. package/api/index.d.ts +4 -0
  11. package/api/index.d.ts.map +1 -0
  12. package/api/index.js +3 -3
  13. package/api/typedefs.d.ts +179 -0
  14. package/api/typedefs.d.ts.map +1 -0
  15. package/api/typedefs.js +75 -0
  16. package/common/api/HttpAPI.d.ts +31 -0
  17. package/common/api/HttpAPI.d.ts.map +1 -0
  18. package/common/api/HttpAPI.js +54 -27
  19. package/common/api/WebSocketAPI.d.ts +153 -0
  20. package/common/api/WebSocketAPI.d.ts.map +1 -0
  21. package/common/api/WebSocketAPI.js +330 -164
  22. package/common/controls/ControlCommon.d.ts +76 -0
  23. package/common/controls/ControlCommon.d.ts.map +1 -0
  24. package/common/controls/ControlCommon.js +150 -0
  25. package/common/controls/CopyrightControlCommon.d.ts +13 -0
  26. package/common/controls/CopyrightControlCommon.d.ts.map +1 -0
  27. package/common/controls/CopyrightControlCommon.js +34 -0
  28. package/common/controls/StopFinderControlCommon.d.ts +55 -0
  29. package/common/controls/StopFinderControlCommon.d.ts.map +1 -0
  30. package/common/controls/StopFinderControlCommon.js +144 -0
  31. package/common/index.d.ts +3 -0
  32. package/common/index.d.ts.map +1 -0
  33. package/common/index.js +2 -4
  34. package/common/layers/LayerCommon.d.ts +94 -0
  35. package/common/layers/LayerCommon.d.ts.map +1 -0
  36. package/common/layers/LayerCommon.js +244 -0
  37. package/common/mixins/RealtimeLayerMixin.d.ts +286 -0
  38. package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
  39. package/common/mixins/RealtimeLayerMixin.js +776 -0
  40. package/common/mixins/UserInteractionsLayerMixin.d.ts +60 -0
  41. package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
  42. package/common/mixins/UserInteractionsLayerMixin.js +241 -0
  43. package/common/styles/index.d.ts +5 -0
  44. package/common/styles/index.d.ts.map +1 -0
  45. package/common/styles/index.js +4 -4
  46. package/common/styles/realtimeDefaultStyle.d.ts +36 -0
  47. package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
  48. package/common/styles/realtimeDefaultStyle.js +275 -0
  49. package/common/styles/realtimeDelayStyle.d.ts +12 -0
  50. package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
  51. package/common/styles/realtimeDelayStyle.js +13 -0
  52. package/common/styles/realtimeHeadingStyle.d.ts +12 -0
  53. package/common/styles/realtimeHeadingStyle.d.ts.map +1 -0
  54. package/common/styles/realtimeHeadingStyle.js +85 -0
  55. package/common/styles/realtimeSimpleStyle.d.ts +4 -0
  56. package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
  57. package/common/styles/realtimeSimpleStyle.js +23 -0
  58. package/common/typedefs.d.ts +111 -0
  59. package/common/typedefs.d.ts.map +1 -0
  60. package/common/typedefs.js +52 -0
  61. package/common/utils/compareDepartures.d.ts +11 -0
  62. package/common/utils/compareDepartures.d.ts.map +1 -0
  63. package/common/utils/compareDepartures.js +35 -0
  64. package/common/utils/createCanvas.d.ts +10 -0
  65. package/common/utils/createCanvas.d.ts.map +1 -0
  66. package/common/utils/createCanvas.js +27 -0
  67. package/common/utils/createRealtimeFilters.d.ts +13 -0
  68. package/common/utils/createRealtimeFilters.d.ts.map +1 -0
  69. package/common/utils/createRealtimeFilters.js +74 -0
  70. package/common/utils/debounceDeparturesMessages.d.ts +12 -0
  71. package/common/utils/debounceDeparturesMessages.d.ts.map +1 -0
  72. package/common/utils/debounceDeparturesMessages.js +24 -0
  73. package/common/utils/debounceWebsocketMessages.d.ts +11 -0
  74. package/common/utils/debounceWebsocketMessages.d.ts.map +1 -0
  75. package/common/utils/debounceWebsocketMessages.js +29 -0
  76. package/common/utils/getLayersAsFlatArray.d.ts +3 -0
  77. package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
  78. package/common/utils/getLayersAsFlatArray.js +15 -0
  79. package/common/utils/getMapboxMapCopyrights.d.ts +18 -0
  80. package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
  81. package/common/utils/getMapboxMapCopyrights.js +26 -15
  82. package/common/utils/getMapboxRender.d.ts +7 -0
  83. package/common/utils/getMapboxRender.d.ts.map +1 -0
  84. package/common/utils/getMapboxRender.js +87 -0
  85. package/common/utils/getMaplibreRender.d.ts +7 -0
  86. package/common/utils/getMaplibreRender.d.ts.map +1 -0
  87. package/common/utils/getMaplibreRender.js +38 -0
  88. package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
  89. package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
  90. package/common/utils/getRealtimeModeSuffix.js +7 -0
  91. package/common/utils/getUrlWithParams.d.ts +9 -0
  92. package/common/utils/getUrlWithParams.d.ts.map +1 -0
  93. package/common/utils/getUrlWithParams.js +18 -0
  94. package/common/utils/getVehiclePosition.d.ts +16 -0
  95. package/common/utils/getVehiclePosition.d.ts.map +1 -0
  96. package/common/utils/getVehiclePosition.js +67 -37
  97. package/common/utils/index.d.ts +17 -0
  98. package/common/utils/index.d.ts.map +1 -0
  99. package/common/utils/index.js +17 -5
  100. package/common/utils/realtimeConfig.d.ts +49 -0
  101. package/common/utils/realtimeConfig.d.ts.map +1 -0
  102. package/common/utils/realtimeConfig.js +173 -0
  103. package/common/utils/removeDuplicate.d.ts +10 -0
  104. package/common/utils/removeDuplicate.d.ts.map +1 -0
  105. package/common/utils/removeDuplicate.js +12 -5
  106. package/common/utils/renderTrajectories.d.ts +17 -0
  107. package/common/utils/renderTrajectories.d.ts.map +1 -0
  108. package/common/utils/renderTrajectories.js +110 -0
  109. package/common/utils/sortAndFilterDepartures.d.ts +16 -0
  110. package/common/utils/sortAndFilterDepartures.d.ts.map +1 -0
  111. package/common/utils/sortAndFilterDepartures.js +58 -0
  112. package/common/utils/sortByDelay.d.ts +3 -0
  113. package/common/utils/sortByDelay.d.ts.map +1 -0
  114. package/common/utils/sortByDelay.js +17 -15
  115. package/common/utils/timeUtils.d.ts +24 -0
  116. package/common/utils/timeUtils.d.ts.map +1 -0
  117. package/common/utils/timeUtils.js +34 -15
  118. package/iife.d.ts +3 -0
  119. package/iife.d.ts.map +1 -0
  120. package/iife.js +5 -0
  121. package/index.d.ts +10 -0
  122. package/index.d.ts.map +1 -0
  123. package/index.js +8 -6
  124. package/mapbox/controls/CopyrightControl.d.ts +29 -0
  125. package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
  126. package/mapbox/controls/CopyrightControl.js +44 -25
  127. package/mapbox/controls/index.d.ts +2 -0
  128. package/mapbox/controls/index.d.ts.map +1 -0
  129. package/mapbox/controls/index.js +2 -1
  130. package/mapbox/index.d.ts +6 -0
  131. package/mapbox/index.d.ts.map +1 -0
  132. package/mapbox/index.js +5 -4
  133. package/mapbox/layers/Layer.d.ts +59 -0
  134. package/mapbox/layers/Layer.d.ts.map +1 -0
  135. package/mapbox/layers/Layer.js +99 -55
  136. package/mapbox/layers/RealtimeLayer.d.ts +181 -0
  137. package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
  138. package/mapbox/layers/RealtimeLayer.js +276 -0
  139. package/mapbox/layers/index.d.ts +3 -0
  140. package/mapbox/layers/index.d.ts.map +1 -0
  141. package/mapbox/layers/index.js +2 -2
  142. package/mapbox/utils/getMercatorResolution.d.ts +9 -0
  143. package/mapbox/utils/getMercatorResolution.d.ts.map +1 -0
  144. package/mapbox/utils/getMercatorResolution.js +18 -0
  145. package/mapbox/utils/getSourceCoordinates.d.ts +9 -0
  146. package/mapbox/utils/getSourceCoordinates.d.ts.map +1 -0
  147. package/mapbox/utils/getSourceCoordinates.js +27 -0
  148. package/mapbox/utils/index.d.ts +3 -0
  149. package/mapbox/utils/index.d.ts.map +1 -0
  150. package/mapbox/utils/index.js +2 -0
  151. package/mbt.js +26061 -16500
  152. package/mbt.js.map +4 -4
  153. package/mbt.min.js +205 -126
  154. package/mbt.min.js.map +4 -4
  155. package/ol/controls/CopyrightControl.d.ts +31 -0
  156. package/ol/controls/CopyrightControl.d.ts.map +1 -0
  157. package/ol/controls/CopyrightControl.js +62 -36
  158. package/ol/controls/RoutingControl.d.ts +193 -0
  159. package/ol/controls/RoutingControl.d.ts.map +1 -0
  160. package/ol/controls/RoutingControl.js +601 -357
  161. package/ol/controls/StopFinderControl.d.ts +30 -0
  162. package/ol/controls/StopFinderControl.d.ts.map +1 -0
  163. package/ol/controls/StopFinderControl.js +30 -8
  164. package/ol/controls/index.d.ts +4 -0
  165. package/ol/controls/index.d.ts.map +1 -0
  166. package/ol/controls/index.js +3 -3
  167. package/ol/index.d.ts +6 -0
  168. package/ol/index.d.ts.map +1 -0
  169. package/ol/index.js +5 -5
  170. package/ol/layers/Layer.d.ts +86 -0
  171. package/ol/layers/Layer.d.ts.map +1 -0
  172. package/ol/layers/Layer.js +163 -77
  173. package/ol/layers/MapGlLayer.d.ts +67 -0
  174. package/ol/layers/MapGlLayer.d.ts.map +1 -0
  175. package/ol/layers/MapGlLayer.js +218 -0
  176. package/ol/layers/MapboxLayer.d.ts +50 -0
  177. package/ol/layers/MapboxLayer.d.ts.map +1 -0
  178. package/ol/layers/MapboxLayer.js +99 -193
  179. package/ol/layers/MapboxStyleLayer.d.ts +129 -0
  180. package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
  181. package/ol/layers/MapboxStyleLayer.js +362 -171
  182. package/ol/layers/MaplibreLayer.d.ts +28 -0
  183. package/ol/layers/MaplibreLayer.d.ts.map +1 -0
  184. package/ol/layers/MaplibreLayer.js +30 -135
  185. package/ol/layers/RealtimeLayer.d.ts +202 -0
  186. package/ol/layers/RealtimeLayer.d.ts.map +1 -0
  187. package/ol/layers/RealtimeLayer.js +340 -0
  188. package/ol/layers/RoutingLayer.d.ts +34 -0
  189. package/ol/layers/RoutingLayer.d.ts.map +1 -0
  190. package/ol/layers/RoutingLayer.js +72 -48
  191. package/ol/layers/VectorLayer.d.ts +25 -0
  192. package/ol/layers/VectorLayer.d.ts.map +1 -0
  193. package/ol/layers/VectorLayer.js +34 -18
  194. package/ol/layers/WMSLayer.d.ts +42 -0
  195. package/ol/layers/WMSLayer.d.ts.map +1 -0
  196. package/ol/layers/WMSLayer.js +84 -34
  197. package/ol/layers/index.d.ts +9 -0
  198. package/ol/layers/index.d.ts.map +1 -0
  199. package/ol/layers/index.js +8 -8
  200. package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
  201. package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
  202. package/ol/styles/fullTrajectoryDelayStyle.js +26 -24
  203. package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
  204. package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
  205. package/ol/styles/fullTrajectoryStyle.js +40 -39
  206. package/ol/styles/index.d.ts +3 -0
  207. package/ol/styles/index.d.ts.map +1 -0
  208. package/ol/styles/index.js +2 -2
  209. package/package.json +81 -133
  210. package/setupTests.d.ts +2 -0
  211. package/setupTests.d.ts.map +1 -0
  212. package/setupTests.js +26 -0
  213. package/types/common.d.ts +122 -0
  214. package/types/index.d.ts +11 -0
  215. package/types/realtime.d.ts +320 -0
  216. package/types/routing.d.ts +206 -0
  217. package/types/stops.d.ts +143 -0
  218. package/README.md +0 -23
  219. package/api/RoutingAPI.test.js +0 -25
  220. package/api/StopsAPI.test.js +0 -22
  221. package/api/TralisAPI.js +0 -359
  222. package/api/TralisAPI.test.js +0 -67
  223. package/api/TralisAPIUtils.js +0 -43
  224. package/common/Tracker.js +0 -93
  225. package/common/api/HttpAPI.test.js +0 -50
  226. package/common/api/WebSocketAPI.test.js +0 -311
  227. package/common/controls/Control.js +0 -81
  228. package/common/controls/Control.test.js +0 -87
  229. package/common/layers/Layer.js +0 -213
  230. package/common/layers/Layer.test.js +0 -526
  231. package/common/mixins/CopyrightMixin.js +0 -24
  232. package/common/mixins/SearchMixin.js +0 -110
  233. package/common/mixins/TralisLayerMixin.js +0 -479
  234. package/common/styles/trackerDefaultStyle.js +0 -197
  235. package/common/styles/trackerDelayStyle.js +0 -8
  236. package/common/styles/trackerSimpleStyle.js +0 -18
  237. package/common/trackerConfig.js +0 -152
  238. package/common/trackerConfig.test.js +0 -23
  239. package/common/utils/createTrackerFilters.js +0 -56
  240. package/common/utils/createTrackerFilters.test.js +0 -79
  241. package/common/utils/getMapboxMapCopyrights.test.js +0 -40
  242. package/common/utils/getMapboxStyleUrl.js +0 -22
  243. package/common/utils/removeDuplicate.test.js +0 -19
  244. package/common/utils/timeUtils.test.js +0 -10
  245. package/mapbox/layers/Layer.test.js +0 -182
  246. package/mapbox/layers/TralisLayer.js +0 -182
  247. package/mapbox/layers/TralisLayer.test.js +0 -38
  248. package/mapbox/utils.js +0 -32
  249. package/ol/controls/CopyrightControl.test.js +0 -165
  250. package/ol/controls/RoutingControl.test.js +0 -151
  251. package/ol/controls/StopFinderControl.test.js +0 -48
  252. package/ol/layers/Layer.test.js +0 -174
  253. package/ol/layers/MapboxLayer.test.js +0 -160
  254. package/ol/layers/MapboxStyleLayer.test.js +0 -231
  255. package/ol/layers/RoutingLayer.test.js +0 -40
  256. package/ol/layers/TralisLayer.js +0 -185
  257. package/ol/layers/TralisLayer.test.js +0 -79
  258. package/ol/layers/VectorLayer.test.js +0 -87
  259. package/ol/layers/WMSLayer.test.js +0 -76
@@ -0,0 +1,179 @@
1
+ export default dummy;
2
+ export type Departure = {
3
+ /**
4
+ * Timestamp in ms.
5
+ */
6
+ time: number;
7
+ no_stop_between: boolean;
8
+ train_number: number;
9
+ to: string[];
10
+ /**
11
+ * Timestamp in ms.
12
+ */
13
+ ris_aimed_time: number;
14
+ /**
15
+ * Timestamp in ms.
16
+ */
17
+ updated_at: number;
18
+ new_to: boolean;
19
+ /**
20
+ * Timestamp in ms.
21
+ */
22
+ min_arrival_time: number;
23
+ /**
24
+ * List of next stops. Like value in at_station_ds100.
25
+ */
26
+ next_stoppoints: string[];
27
+ /**
28
+ * Timestamp in ms.
29
+ */
30
+ ris_estimated_time: number;
31
+ line: NetworkLine;
32
+ /**
33
+ * if true this departure has realtime data.
34
+ */
35
+ has_fzo: boolean;
36
+ train_id: number;
37
+ platform: string;
38
+ state: any | null;
39
+ /**
40
+ * Timestamp in ms.
41
+ */
42
+ fzo_estimated_time: number;
43
+ formation: any | null;
44
+ no_stop_till: any | null;
45
+ train_type: number;
46
+ call_id: number;
47
+ /**
48
+ * Timestamp in ms.
49
+ */
50
+ created_at: string;
51
+ at_station_ds100: string;
52
+ /**
53
+ * Timestamp in ms.
54
+ */
55
+ timediff: number;
56
+ };
57
+ export type Station = GeoJSONFeature;
58
+ export type StationProperties = {
59
+ transfers: Transfer[];
60
+ elevatorOutOfOrder: boolean;
61
+ uic: number;
62
+ name: string;
63
+ networkLines: NetworkLine[];
64
+ hasElevator: boolean;
65
+ hasZOB: boolean;
66
+ hasAccessibility: boolean;
67
+ type: string;
68
+ };
69
+ export type NetworkLine = {
70
+ /**
71
+ * Identifier of the line.
72
+ */
73
+ id: number;
74
+ /**
75
+ * Color of the line (CSS color string).
76
+ */
77
+ color: string;
78
+ /**
79
+ * Stroke color of the line (CSS color string).
80
+ */
81
+ stroke: string;
82
+ /**
83
+ * Name of the line.
84
+ */
85
+ name: string;
86
+ /**
87
+ * Text color of the line (CSS color string).
88
+ */
89
+ text_color: string;
90
+ };
91
+ export type Transfer = {
92
+ /**
93
+ * Mode of transportation (ex: U-Bahn).
94
+ */
95
+ mot: string;
96
+ /**
97
+ * Array of lines name (ex: ["U4", "U5"]).
98
+ */
99
+ lines: string[];
100
+ };
101
+ export type StopSequence = GeoJSONFeature;
102
+ export type RealtimeTrajectory = GeoJSONFeature;
103
+ export type FullTrajectory = GeoJSONFeature;
104
+ export type Vehicle = GeoJSONFeature;
105
+ export type ExtraGeom = GeoJSONFeature;
106
+ /**
107
+ * @typedef {Object} Departure
108
+ * @property {number} time Timestamp in ms.
109
+ * @property {boolean} no_stop_between
110
+ * @property {number} train_number
111
+ * @property {string[]} to
112
+ * @property {number} ris_aimed_time Timestamp in ms.
113
+ * @property {number} updated_at Timestamp in ms.
114
+ * @property {boolean} new_to
115
+ * @property {number} min_arrival_time Timestamp in ms.
116
+ * @property {string[]} next_stoppoints List of next stops. Like value in at_station_ds100.
117
+ * @property {number} ris_estimated_time Timestamp in ms.
118
+ * @property {NetworkLine} line
119
+ * @property {boolean} has_fzo if true this departure has realtime data.
120
+ * @property {number} train_id
121
+ * @property {string} platform
122
+ * @property {?*} state
123
+ * @property {number} fzo_estimated_time Timestamp in ms.
124
+ * @property {?*} formation
125
+ * @property {?*} no_stop_till
126
+ * @property {number} train_type
127
+ * @property {number} call_id
128
+ * @property {string} created_at Timestamp in ms.
129
+ * @property {string} at_station_ds100
130
+ * @property {number} timediff Timestamp in ms.
131
+ *
132
+ */
133
+ /**
134
+ * @typedef {GeoJSONFeature} Station
135
+ * @property {StationProperties} properties Returns the station's properties.
136
+ * @property {GeoJSONPoint} geometry Returns a point.
137
+ */
138
+ /**
139
+ * @typedef {Object} StationProperties
140
+ * @property {Transfer[]} transfers
141
+ * @property {boolean} elevatorOutOfOrder
142
+ * @property {number} uic
143
+ * @property {string} name
144
+ * @property {NetworkLine[]} networkLines
145
+ * @property {boolean} hasElevator
146
+ * @property {boolean} hasZOB
147
+ * @property {boolean} hasAccessibility
148
+ * @property {string} type
149
+ */
150
+ /**
151
+ * @typedef {Object} NetworkLine
152
+ * @property {number} id Identifier of the line.
153
+ * @property {string} color Color of the line (CSS color string).
154
+ * @property {string} stroke Stroke color of the line (CSS color string).
155
+ * @property {string} name Name of the line.
156
+ * @property {string} text_color Text color of the line (CSS color string).
157
+ */
158
+ /**
159
+ * @typedef {Object} Transfer
160
+ * @property {string} mot Mode of transportation (ex: U-Bahn).
161
+ * @property {string[]} lines Array of lines name (ex: ["U4", "U5"]).
162
+ */
163
+ /**
164
+ * @typedef {GeoJSONFeature} StopSequence
165
+ */
166
+ /**
167
+ * @typedef {GeoJSONFeature} RealtimeTrajectory
168
+ */
169
+ /**
170
+ * @typedef {GeoJSONFeature} FullTrajectory
171
+ */
172
+ /**
173
+ * @typedef {GeoJSONFeature} Vehicle
174
+ */
175
+ /**
176
+ * @typedef {GeoJSONFeature} ExtraGeom
177
+ */
178
+ declare function dummy(): void;
179
+ //# sourceMappingURL=typedefs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typedefs.d.ts","sourceRoot":"","sources":["../../src/api/typedefs.js"],"names":[],"mappings":";;;;;UAEc,MAAM;qBACN,OAAO;kBACP,MAAM;QACN,MAAM,EAAE;;;;oBACR,MAAM;;;;gBACN,MAAM;YACN,OAAO;;;;sBACP,MAAM;;;;qBACN,MAAM,EAAE;;;;wBACR,MAAM;UACN,WAAW;;;;aACX,OAAO;cACP,MAAM;cACN,MAAM;;;;;wBAEN,MAAM;;;gBAGN,MAAM;aACN,MAAM;;;;gBACN,MAAM;sBACN,MAAM;;;;cACN,MAAM;;;;eAYN,QAAQ,EAAE;wBACV,OAAO;SACP,MAAM;UACN,MAAM;kBACN,WAAW,EAAE;iBACb,OAAO;YACP,OAAO;sBACP,OAAO;UACP,MAAM;;;;;;QAKN,MAAM;;;;WACN,MAAM;;;;YACN,MAAM;;;;UACN,MAAM;;;;gBACN,MAAM;;;;;;SAKN,MAAM;;;;WACN,MAAM,EAAE;;;;;;;AA3DtB;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH;;;;GAIG;AAEH;;;;;;;;;;;GAWG;AAEH;;;;;;;GAOG;AAEH;;;;GAIG;AAEH;;GAEG;AAEH;;GAEG;AAEH;;GAEG;AAEH;;GAEG;AAEH;;GAEG;AAGH,+BAAsB"}
package/api/typedefs.js CHANGED
@@ -0,0 +1,75 @@
1
+ /**
2
+ * @typedef {Object} Departure
3
+ * @property {number} time Timestamp in ms.
4
+ * @property {boolean} no_stop_between
5
+ * @property {number} train_number
6
+ * @property {string[]} to
7
+ * @property {number} ris_aimed_time Timestamp in ms.
8
+ * @property {number} updated_at Timestamp in ms.
9
+ * @property {boolean} new_to
10
+ * @property {number} min_arrival_time Timestamp in ms.
11
+ * @property {string[]} next_stoppoints List of next stops. Like value in at_station_ds100.
12
+ * @property {number} ris_estimated_time Timestamp in ms.
13
+ * @property {NetworkLine} line
14
+ * @property {boolean} has_fzo if true this departure has realtime data.
15
+ * @property {number} train_id
16
+ * @property {string} platform
17
+ * @property {?*} state
18
+ * @property {number} fzo_estimated_time Timestamp in ms.
19
+ * @property {?*} formation
20
+ * @property {?*} no_stop_till
21
+ * @property {number} train_type
22
+ * @property {number} call_id
23
+ * @property {string} created_at Timestamp in ms.
24
+ * @property {string} at_station_ds100
25
+ * @property {number} timediff Timestamp in ms.
26
+ *
27
+ */
28
+ /**
29
+ * @typedef {GeoJSONFeature} Station
30
+ * @property {StationProperties} properties Returns the station's properties.
31
+ * @property {GeoJSONPoint} geometry Returns a point.
32
+ */
33
+ /**
34
+ * @typedef {Object} StationProperties
35
+ * @property {Transfer[]} transfers
36
+ * @property {boolean} elevatorOutOfOrder
37
+ * @property {number} uic
38
+ * @property {string} name
39
+ * @property {NetworkLine[]} networkLines
40
+ * @property {boolean} hasElevator
41
+ * @property {boolean} hasZOB
42
+ * @property {boolean} hasAccessibility
43
+ * @property {string} type
44
+ */
45
+ /**
46
+ * @typedef {Object} NetworkLine
47
+ * @property {number} id Identifier of the line.
48
+ * @property {string} color Color of the line (CSS color string).
49
+ * @property {string} stroke Stroke color of the line (CSS color string).
50
+ * @property {string} name Name of the line.
51
+ * @property {string} text_color Text color of the line (CSS color string).
52
+ */
53
+ /**
54
+ * @typedef {Object} Transfer
55
+ * @property {string} mot Mode of transportation (ex: U-Bahn).
56
+ * @property {string[]} lines Array of lines name (ex: ["U4", "U5"]).
57
+ */
58
+ /**
59
+ * @typedef {GeoJSONFeature} StopSequence
60
+ */
61
+ /**
62
+ * @typedef {GeoJSONFeature} RealtimeTrajectory
63
+ */
64
+ /**
65
+ * @typedef {GeoJSONFeature} FullTrajectory
66
+ */
67
+ /**
68
+ * @typedef {GeoJSONFeature} Vehicle
69
+ */
70
+ /**
71
+ * @typedef {GeoJSONFeature} ExtraGeom
72
+ */
73
+ // These lines is to block TypeScript to add "use strict;" in the outputed file.
74
+ const dummy = () => { };
75
+ export default dummy;
@@ -0,0 +1,31 @@
1
+ import BaseObject from 'ol/Object';
2
+ export type HttpAPIOptions = {
3
+ url: string;
4
+ apiKey?: string;
5
+ };
6
+ /**
7
+ * Common class to access to a geOps api using http.
8
+ *
9
+ * @example
10
+ * import { API } from 'mobility-toolbox-js/api';
11
+ *
12
+ * const api = new HttpApi({
13
+ * url: [yourUrl],
14
+ * apiKey: [yourApiKey]
15
+ * });
16
+ *
17
+ * @classproperty {string} url Url of the service.
18
+ * @classproperty {string} apiKey Api key to access the service.
19
+ */
20
+ declare class HttpAPI extends BaseObject {
21
+ url: string;
22
+ apiKey?: string;
23
+ constructor(options: HttpAPIOptions);
24
+ /**
25
+ * Append the apiKey before sending the request.
26
+ * @ignore
27
+ */
28
+ fetch(path: string, params: Object, config: RequestInit): Promise<any>;
29
+ }
30
+ export default HttpAPI;
31
+ //# sourceMappingURL=HttpAPI.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HttpAPI.d.ts","sourceRoot":"","sources":["../../../src/common/api/HttpAPI.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,WAAW,CAAC;AAGnC,MAAM,MAAM,cAAc,GAAG;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AACF;;;;;;;;;;;;;GAaG;AACH,cAAM,OAAQ,SAAQ,UAAU;IAC9B,GAAG,EAAE,MAAM,CAAC;IAEZ,MAAM,CAAC,EAAE,MAAM,CAAC;gBAEJ,OAAO,EAAE,cAAc;IASnC;;;OAGG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;CAmCvE;AAED,eAAe,OAAO,CAAC"}
@@ -1,30 +1,57 @@
1
- import qs from "query-string";
2
- import BaseObject from "ol/Object";
3
- class HttpApi extends BaseObject {
4
- constructor(options = {}) {
5
- super();
6
- this.url = options.url;
7
- this.apiKey = options.apiKey;
8
- }
9
- fetch(path, params, config) {
10
- const urlParams = { ...params || {}, key: this.apiKey };
11
- const clone = { ...urlParams };
12
- Object.keys(urlParams).forEach((key) => (clone[key] === void 0 || clone[key] === null) && delete clone[key]);
13
- if (!this.apiKey) {
14
- return Promise.reject(new Error(`No apiKey defined for request to ${this.url}`));
1
+ import BaseObject from 'ol/Object';
2
+ import getUrlWithParams from '../utils/getUrlWithParams';
3
+ /**
4
+ * Common class to access to a geOps api using http.
5
+ *
6
+ * @example
7
+ * import { API } from 'mobility-toolbox-js/api';
8
+ *
9
+ * const api = new HttpApi({
10
+ * url: [yourUrl],
11
+ * apiKey: [yourApiKey]
12
+ * });
13
+ *
14
+ * @classproperty {string} url Url of the service.
15
+ * @classproperty {string} apiKey Api key to access the service.
16
+ */
17
+ class HttpAPI extends BaseObject {
18
+ constructor(options) {
19
+ super();
20
+ /** @ignore */
21
+ this.url = options.url;
22
+ /** @ignore */
23
+ this.apiKey = options.apiKey;
15
24
  }
16
- return fetch(`${this.url}${path || ""}?${qs.stringify(clone)}`, config).then((response) => {
17
- try {
18
- return response.json().then((data) => {
19
- if (data.error) {
20
- throw new Error(data.error);
21
- }
22
- return data;
25
+ /**
26
+ * Append the apiKey before sending the request.
27
+ * @ignore
28
+ */
29
+ fetch(path, params, config) {
30
+ if (!this.url) {
31
+ // eslint-disable-next-line no-console
32
+ return Promise.reject(new Error(`No url defined for request to ${this.url}/${path}`));
33
+ }
34
+ if (!this.url && !this.apiKey && !/key=/.test(this.url)) {
35
+ // eslint-disable-next-line no-console
36
+ return Promise.reject(new Error(`No apiKey defined for request to ${this.url}`));
37
+ }
38
+ // Clean requets parameters, removing undefined and null values.
39
+ const searchParams = params || {};
40
+ const url = getUrlWithParams(`${this.url}${path || ''}`, Object.assign({ key: this.apiKey }, searchParams));
41
+ // We use toString because of TYpeScript bug that only accept a string in fetch method.
42
+ return fetch(url.toString(), config).then((response) => {
43
+ try {
44
+ return response.json().then((data) => {
45
+ if (data.error) {
46
+ throw new Error(data.error);
47
+ }
48
+ return data;
49
+ });
50
+ }
51
+ catch (err) {
52
+ return Promise.reject(new Error(err));
53
+ }
23
54
  });
24
- } catch (err) {
25
- return Promise.reject(new Error(err));
26
- }
27
- });
28
- }
55
+ }
29
56
  }
30
- export default HttpApi;
57
+ export default HttpAPI;
@@ -0,0 +1,153 @@
1
+ import { RealtimeTrajectoryResponse } from '../../types';
2
+ export declare type WebSocketAPIParameters = {
3
+ channel?: string;
4
+ args?: string | number;
5
+ id?: string | number;
6
+ };
7
+ export declare type WebSocketAPIMessageEventData<T> = {
8
+ timestamp: number;
9
+ source: string;
10
+ content: T;
11
+ client_reference: string | number | null;
12
+ };
13
+ export type WebSocketAPIBufferMessageEventData = WebSocketAPIMessageEventData<RealtimeTrajectoryResponse[]> & {
14
+ source: 'buffer';
15
+ };
16
+ export type WebSocketAPIMessageEvent = Event & {
17
+ data: string;
18
+ };
19
+ export interface WebSocketAPIMessageEventListener {
20
+ (evt: WebSocketAPIMessageEvent): void;
21
+ }
22
+ /**
23
+ * This type represents a function that has been call with each feature returned by the websocket.
24
+ */
25
+ export interface WebSocketAPIMessageCallback<T> {
26
+ (data: WebSocketAPIMessageEventData<T>): void;
27
+ }
28
+ export declare type WebSocketAPISubscription = {
29
+ params: WebSocketAPIParameters;
30
+ cb: WebSocketAPIMessageCallback<any>;
31
+ errorCb?: EventListener;
32
+ onMessageCb: WebSocketAPIMessageEventListener;
33
+ onErrorCb?: EventListener;
34
+ quiet: boolean;
35
+ };
36
+ export declare type WebSocketAPISubscribed = {
37
+ [index: string]: boolean;
38
+ };
39
+ export declare type WebSocketAPIRequest = {
40
+ params: WebSocketAPIParameters;
41
+ cb: WebSocketAPIMessageCallback<any>;
42
+ errorCb?: EventListener;
43
+ onMessageCb: WebSocketAPIMessageEventListener;
44
+ onErrorCb?: EventListener;
45
+ requestString: String;
46
+ };
47
+ /**
48
+ * Class used to facilitate connection to a WebSocketAPI and
49
+ * also to manage properly messages send to the WebSocketAPI.
50
+ * This class must not contain any specific implementation.
51
+ */
52
+ declare class WebSocketAPI {
53
+ websocket?: WebSocket;
54
+ closed?: boolean;
55
+ closing?: boolean;
56
+ connecting?: boolean;
57
+ open?: boolean;
58
+ messagesOnOpen: Array<string>;
59
+ subscriptions: Array<WebSocketAPISubscription>;
60
+ subscribed: WebSocketAPISubscribed;
61
+ requests: Array<WebSocketAPIRequest>;
62
+ constructor();
63
+ defineProperties(): void;
64
+ /**
65
+ * Get the websocket request string.
66
+ *
67
+ * @param {string} method Request mehtod {GET, SUB}.
68
+ * @param {WebSocketParameters} params Request parameters.
69
+ * @param {string} params.channel Channel name
70
+ * @param {string} [params.args] Request arguments
71
+ * @param {Number|string} [params.id] Request identifier
72
+ * @return {string} request string
73
+ * @private
74
+ */
75
+ static getRequestString(method: string, params?: WebSocketAPIParameters): string;
76
+ /**
77
+ * (Re)connect the websocket.
78
+ *
79
+ * @param {string} url Websocket url.
80
+ * @param {function} onOpen Callback called when the websocket connection is opened and before subscriptions of previous subscriptions.
81
+ * @private
82
+ */
83
+ connect(url: string, onOpen?: () => void): void;
84
+ /**
85
+ * Close the websocket definitively.
86
+ *
87
+ * @private
88
+ */
89
+ close(): void;
90
+ /**
91
+ * Sends a message to the websocket.
92
+ *
93
+ * @param {message} message Message to send.
94
+ * @private
95
+ */
96
+ send(message: string): void;
97
+ addEvents(onMessage: WebSocketAPIMessageEventListener, onError?: EventListener): void;
98
+ removeEvents(onMessage: WebSocketAPIMessageEventListener, onError?: EventListener): void;
99
+ /**
100
+ * Listen to websocket messages.
101
+ *
102
+ * @param {WebSocketParameters} params Parameters for the websocket get request
103
+ * @param {function} cb callback on listen
104
+ * @param {function} errorCb Callback on error
105
+ * @return {{onMessage: function, errorCb: function}} Object with onMessage and error callbacks
106
+ * @private
107
+ */
108
+ listen(params: WebSocketAPIParameters, cb: WebSocketAPIMessageCallback<any>, errorCb?: EventListener): {
109
+ onMessageCb: WebSocketAPIMessageEventListener;
110
+ onErrorCb?: EventListener;
111
+ };
112
+ /**
113
+ * Unlisten websocket messages.
114
+ *
115
+ * @param {Object} params Parameters for the websocket get request.
116
+ * @param {function} cb Callback used when listen.
117
+ * @private
118
+ */
119
+ unlisten(params: WebSocketAPIParameters, cb: WebSocketAPIMessageCallback<any>): void;
120
+ /**
121
+ * Sends a get request to the websocket.
122
+ * The callback is called only once, when the response is received or when the call returns an error.
123
+ *
124
+ * @param {Object} params Parameters for the websocket get request
125
+ * @param {function} onMessage callback on message event
126
+ * @param {function} onError Callback on error and close event
127
+ * @private
128
+ */
129
+ get(params: WebSocketAPIParameters, cb: WebSocketAPIMessageCallback<any>, errorCb?: EventListener): void;
130
+ /**
131
+ * Subscribe to a given channel.
132
+ *
133
+ * @param {Object} params Parameters for the websocket get request
134
+ * @param {function} cb callback on listen
135
+ * @param {function} errorCb Callback on error
136
+ * @param {boolean} quiet if false, no GET or SUB requests are send, only the callback is registered.
137
+ * @private
138
+ */
139
+ subscribe(params: WebSocketAPIParameters, cb: WebSocketAPIMessageCallback<any>, errorCb?: EventListener, quiet?: boolean): void;
140
+ /**
141
+ * Unsubscribe from a channel.
142
+ * @param {string} source source to unsubscribe from
143
+ * @param {function} cb Callback function to unsubscribe. If null all subscriptions for the channel will be unsubscribed.
144
+ * @private
145
+ */
146
+ unsubscribe(source: string, cb?: WebSocketAPIMessageCallback<any>): void;
147
+ /**
148
+ * After an auto reconnection we need to re-subscribe to the channels.
149
+ */
150
+ subscribePreviousSubscriptions(): void;
151
+ }
152
+ export default WebSocketAPI;
153
+ //# sourceMappingURL=WebSocketAPI.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebSocketAPI.d.ts","sourceRoot":"","sources":["../../../src/common/api/WebSocketAPI.ts"],"names":[],"mappings":"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"}