atriusmaps-node-sdk 3.3.898 → 3.3.900

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 (62) hide show
  1. package/dist/cjs/nodesdk/nodeEntry.js +36 -58
  2. package/dist/cjs/package.json.js +8 -4
  3. package/dist/cjs/plugins/clientAPI/src/clientAPI.js +8 -6
  4. package/dist/cjs/plugins/dynamicPois/src/dynamicPois.js +50 -142
  5. package/dist/cjs/plugins/dynamicPois/src/processors.js +31 -53
  6. package/dist/cjs/plugins/flightStatus/src/flightDetailsMapper.js +47 -116
  7. package/dist/cjs/plugins/flightStatus/src/flightStatus.js +48 -82
  8. package/dist/cjs/plugins/flightStatus/src/utils.js +4 -14
  9. package/dist/cjs/plugins/poiDataManager/src/poiDataManager.js +77 -154
  10. package/dist/cjs/plugins/sdkServer/src/prepareSDKConfig.js +45 -76
  11. package/dist/cjs/plugins/sdkServer/src/sdkHeadless.js +70 -79
  12. package/dist/cjs/plugins/sdkServer/src/sdkServer.js +97 -147
  13. package/dist/cjs/plugins/searchService/src/flexsearchExports/lang.js +16 -190
  14. package/dist/cjs/plugins/searchService/src/flexsearchExports/simple.js +28 -35
  15. package/dist/cjs/plugins/searchService/src/poiSearch.js +10 -21
  16. package/dist/cjs/plugins/searchService/src/searchService.js +45 -147
  17. package/dist/cjs/plugins/searchService/src/searchTypeahead.js +17 -28
  18. package/dist/cjs/plugins/searchService/src/utils.js +9 -13
  19. package/dist/cjs/plugins/venueDataLoader/src/venueDataLoader.js +148 -304
  20. package/dist/cjs/plugins/venueDataLoader/src/venueLoadingUtils.js +47 -126
  21. package/dist/cjs/plugins/wayfinder/src/findRoute.js +6 -73
  22. package/dist/cjs/plugins/wayfinder/src/minPriorityQueue.js +7 -27
  23. package/dist/cjs/plugins/wayfinder/src/navGraph.js +78 -259
  24. package/dist/cjs/plugins/wayfinder/src/navGraphDebug.js +26 -57
  25. package/dist/cjs/plugins/wayfinder/src/segmentBadges.js +25 -25
  26. package/dist/cjs/plugins/wayfinder/src/segmentBuilder.js +50 -133
  27. package/dist/cjs/plugins/wayfinder/src/segmentCategories.js +29 -29
  28. package/dist/cjs/plugins/wayfinder/src/stepBuilder.js +53 -145
  29. package/dist/cjs/plugins/wayfinder/src/wayfinder.js +105 -349
  30. package/dist/cjs/src/app.js +53 -91
  31. package/dist/cjs/src/configs/postproc-mol-url-parms.js +34 -43
  32. package/dist/cjs/src/configs/postproc-stateTracking.js +1 -19
  33. package/dist/cjs/src/controller.js +4 -26
  34. package/dist/cjs/src/debugTools.js +55 -94
  35. package/dist/cjs/src/env.js +8 -19
  36. package/dist/cjs/src/extModules/bustle.js +15 -71
  37. package/dist/cjs/src/extModules/flexapi/src/help.js +7 -22
  38. package/dist/cjs/src/extModules/flexapi/src/index.js +15 -29
  39. package/dist/cjs/src/extModules/flexapi/src/validate.js +45 -93
  40. package/dist/cjs/src/extModules/geohasher.js +13 -31
  41. package/dist/cjs/src/extModules/log.js +18 -29
  42. package/dist/cjs/src/historyManager.js +4 -6
  43. package/dist/cjs/src/utils/bounds.js +2 -4
  44. package/dist/cjs/src/utils/buildStructureLookup.js +7 -7
  45. package/dist/cjs/src/utils/configUtils.js +7 -43
  46. package/dist/cjs/src/utils/date.js +5 -17
  47. package/dist/cjs/src/utils/distance.js +2 -2
  48. package/dist/cjs/src/utils/dom.js +9 -24
  49. package/dist/cjs/src/utils/funcs.js +15 -30
  50. package/dist/cjs/src/utils/geodesy.js +24 -39
  51. package/dist/cjs/src/utils/geom.js +32 -148
  52. package/dist/cjs/src/utils/i18n.js +39 -70
  53. package/dist/cjs/src/utils/isInitialState.js +7 -13
  54. package/dist/cjs/src/utils/location.js +10 -29
  55. package/dist/cjs/src/utils/observable.js +4 -29
  56. package/dist/cjs/src/utils/rand.js +9 -80
  57. package/dist/cjs/utils/constants.js +1 -1
  58. package/dist/package.json.js +1 -1
  59. package/dist/plugins/sdkServer/src/prepareSDKConfig.js +1 -1
  60. package/dist/src/utils/buildStructureLookup.js +1 -1
  61. package/dist/src/utils/date.js +1 -1
  62. package/package.json +1 -1
@@ -1,249 +1,75 @@
1
1
  'use strict';
2
2
 
3
- /* eslint-disable camelcase */
4
- /**
5
- * @param {!string} str
6
- * @param {boolean|Array<string|RegExp>=} normalize
7
- * @param {boolean|string|RegExp=} split
8
- * @param {boolean=} _collapse
9
- * @returns {string|Array<string>}
10
- * @this IndexInterface
11
- */
12
-
13
- function pipeline(str, normalize, split, _collapse) {
3
+ function pipeline(str, normalize2, split, _collapse) {
14
4
  if (str) {
15
- if (normalize) {
16
- str = replace(str, /** @type {Array<string|RegExp>} */ normalize);
5
+ if (normalize2) {
6
+ str = replace(
7
+ str,
8
+ /** @type {Array<string|RegExp>} */
9
+ normalize2
10
+ );
17
11
  }
18
-
19
12
  if (this.matcher) {
20
13
  str = replace(str, this.matcher);
21
14
  }
22
-
23
15
  if (this.stemmer && str.length > 1) {
24
16
  str = replace(str, this.stemmer);
25
17
  }
26
-
27
18
  if (_collapse && str.length > 1) {
28
19
  str = collapse(str);
29
20
  }
30
-
31
- if (split || split === '') {
32
- const words = str.split(/** @type {string|RegExp} */ split);
33
-
21
+ if (split || split === "") {
22
+ const words = str.split(
23
+ /** @type {string|RegExp} */
24
+ split
25
+ );
34
26
  return this.filter ? filter(words, this.filter) : words;
35
27
  }
36
28
  }
37
-
38
29
  return str;
39
30
  }
40
-
41
- // TODO improve normalize + remove non-delimited chars like in "I'm" + split on whitespace+
42
-
43
31
  const regex_whitespace = /[\p{Z}\p{S}\p{P}\p{C}]+/u;
44
- // https://github.com/nextapps-de/flexsearch/pull/414
45
- // export const regex_whitespace = /[\s\xA0\u2000-\u200B\u2028\u2029\u3000\ufeff!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~]/
46
32
  const regex_normalize = /[\u0300-\u036f'-]/gu;
47
-
48
33
  function normalize(str) {
49
34
  if (str.normalize) {
50
- str = str.normalize('NFD').replace(regex_normalize, '');
35
+ str = str.normalize("NFD").replace(regex_normalize, "");
51
36
  }
52
-
53
37
  return str;
54
38
  }
55
-
56
- /**
57
- * @param {!string} str
58
- * @param {boolean|Array<string|RegExp>=} normalize
59
- * @param {boolean|string|RegExp=} split
60
- * @param {boolean=} _collapse
61
- * @returns {string|Array<string>}
62
- */
63
-
64
- // FlexSearch.prototype.pipeline = function(str, normalize, split, _collapse){
65
- //
66
- // if(str){
67
- //
68
- // if(normalize && str){
69
- //
70
- // str = replace(str, /** @type {Array<string|RegExp>} */ (normalize));
71
- // }
72
- //
73
- // if(str && this.matcher){
74
- //
75
- // str = replace(str, this.matcher);
76
- // }
77
- //
78
- // if(this.stemmer && str.length > 1){
79
- //
80
- // str = replace(str, this.stemmer);
81
- // }
82
- //
83
- // if(_collapse && str.length > 1){
84
- //
85
- // str = collapse(str);
86
- // }
87
- //
88
- // if(str){
89
- //
90
- // if(split || (split === "")){
91
- //
92
- // const words = str.split(/** @type {string|RegExp} */ (split));
93
- //
94
- // return this.filter ? filter(words, this.filter) : words;
95
- // }
96
- // }
97
- // }
98
- //
99
- // return str;
100
- // };
101
-
102
- // export function pipeline(str, normalize, matcher, stemmer, split, _filter, _collapse){
103
- //
104
- // if(str){
105
- //
106
- // if(normalize && str){
107
- //
108
- // str = replace(str, normalize);
109
- // }
110
- //
111
- // if(matcher && str){
112
- //
113
- // str = replace(str, matcher);
114
- // }
115
- //
116
- // if(stemmer && str.length > 1){
117
- //
118
- // str = replace(str, stemmer);
119
- // }
120
- //
121
- // if(_collapse && str.length > 1){
122
- //
123
- // str = collapse(str);
124
- // }
125
- //
126
- // if(str){
127
- //
128
- // if(split !== false){
129
- //
130
- // str = str.split(split);
131
- //
132
- // if(_filter){
133
- //
134
- // str = filter(str, _filter);
135
- // }
136
- // }
137
- // }
138
- // }
139
- //
140
- // return str;
141
- // }
142
-
143
- /**
144
- * @param {!string} str
145
- * @param {Array} regexp
146
- * @returns {string}
147
- */
148
-
149
39
  function replace(str, regexp) {
150
40
  for (let i = 0, len = regexp.length; i < len; i += 2) {
151
41
  str = str.replace(regexp[i], regexp[i + 1]);
152
-
153
42
  if (!str) {
154
43
  break;
155
44
  }
156
45
  }
157
-
158
46
  return str;
159
47
  }
160
-
161
- /**
162
- * @param {!string} str
163
- * @returns {RegExp}
164
- */
165
-
166
48
  function regex(str) {
167
- return new RegExp(str, 'g');
49
+ return new RegExp(str, "g");
168
50
  }
169
-
170
- /**
171
- * Regex: replace(/(?:(\w)(?:\1)*)/g, "$1")
172
- * @param {!string} string
173
- * @returns {string}
174
- */
175
-
176
51
  function collapse(string) {
177
- let final = '';
178
- let prev = '';
179
-
52
+ let final = "";
53
+ let prev = "";
180
54
  for (let i = 0, len = string.length, char; i < len; i++) {
181
55
  if ((char = string[i]) !== prev) {
182
56
  final += prev = char;
183
57
  }
184
58
  }
185
-
186
59
  return final;
187
60
  }
188
-
189
- // TODO using fast-swap
190
61
  function filter(words, map) {
191
62
  const length = words.length;
192
63
  const filtered = [];
193
-
194
64
  for (let i = 0, count = 0; i < length; i++) {
195
65
  const word = words[i];
196
-
197
66
  if (word && !map[word]) {
198
67
  filtered[count++] = word;
199
68
  }
200
69
  }
201
-
202
70
  return filtered;
203
71
  }
204
72
 
205
- // const chars = {a:1, e:1, i:1, o:1, u:1, y:1};
206
- //
207
- // function collapse_repeating_chars(string){
208
- //
209
- // let collapsed_string = "",
210
- // char_prev = "",
211
- // char_next = "";
212
- //
213
- // for(let i = 0; i < string.length; i++){
214
- //
215
- // const char = string[i];
216
- //
217
- // if(char !== char_prev){
218
- //
219
- // if(i && (char === "h")){
220
- //
221
- // if((chars[char_prev] && chars[char_next]) || (char_prev === " ")){
222
- //
223
- // collapsed_string += char;
224
- // }
225
- // }
226
- // else{
227
- //
228
- // collapsed_string += char;
229
- // }
230
- // }
231
- //
232
- // char_next = (
233
- //
234
- // (i === (string.length - 1)) ?
235
- //
236
- // ""
237
- // :
238
- // string[i + 1]
239
- // );
240
- //
241
- // char_prev = char;
242
- // }
243
- //
244
- // return collapsed_string;
245
- // }
246
-
247
73
  exports.collapse = collapse;
248
74
  exports.filter = filter;
249
75
  exports.normalize = normalize;
@@ -2,58 +2,51 @@
2
2
 
3
3
  var lang = require('./lang.js');
4
4
 
5
- /* eslint-disable camelcase */
6
- const // regex_whitespace = /\W+/,
7
- // regex_strip = regex("[^a-z0-9 ]"),
8
- regex_a = lang.regex('[àáâãäå]');
9
- const regex_e = lang.regex('[èéêë]');
10
- const regex_i = lang.regex('[ìíîï]');
11
- const regex_o = lang.regex('[òóôõöő]');
12
- const regex_u = lang.regex('[ùúûüű]');
13
- const regex_y = lang.regex('[ýŷÿ]');
14
- const regex_n = lang.regex('ñ');
15
- const regex_c = lang.regex('[çc]');
16
- const regex_s = lang.regex('ß');
17
- const regex_and = lang.regex(' & ');
5
+ const regex_a = lang.regex("[\xE0\xE1\xE2\xE3\xE4\xE5]");
6
+ const regex_e = lang.regex("[\xE8\xE9\xEA\xEB]");
7
+ const regex_i = lang.regex("[\xEC\xED\xEE\xEF]");
8
+ const regex_o = lang.regex("[\xF2\xF3\xF4\xF5\xF6\u0151]");
9
+ const regex_u = lang.regex("[\xF9\xFA\xFB\xFC\u0171]");
10
+ const regex_y = lang.regex("[\xFD\u0177\xFF]");
11
+ const regex_n = lang.regex("\xF1");
12
+ const regex_c = lang.regex("[\xE7c]");
13
+ const regex_s = lang.regex("\xDF");
14
+ const regex_and = lang.regex(" & ");
18
15
  const pairs = [
19
16
  regex_a,
20
- 'a',
17
+ "a",
21
18
  regex_e,
22
- 'e',
19
+ "e",
23
20
  regex_i,
24
- 'i',
21
+ "i",
25
22
  regex_o,
26
- 'o',
23
+ "o",
27
24
  regex_u,
28
- 'u',
25
+ "u",
29
26
  regex_y,
30
- 'y',
27
+ "y",
31
28
  regex_n,
32
- 'n',
29
+ "n",
33
30
  regex_c,
34
- 'k',
31
+ "k",
35
32
  regex_s,
36
- 's',
33
+ "s",
37
34
  regex_and,
38
- ' and ',
35
+ " and "
39
36
  // regex_whitespace, " "
40
37
  // regex_strip, ""
41
38
  ];
42
-
43
- /**
44
- * @param {string|number} str
45
- * @this IndexInterface
46
- */
47
-
48
39
  function encode(str) {
49
- str = '' + str;
50
-
40
+ str = "" + str;
51
41
  return lang.pipeline.call(
52
42
  this,
53
- /* string: */ lang.normalize(str).toLowerCase(),
54
- /* normalize: */ !str.normalize && pairs,
55
- /* split: */ lang.regex_whitespace,
56
- false,
43
+ /* string: */
44
+ lang.normalize(str).toLowerCase(),
45
+ /* normalize: */
46
+ !str.normalize && pairs,
47
+ /* split: */
48
+ lang.regex_whitespace,
49
+ false
57
50
  );
58
51
  }
59
52
 
@@ -22,41 +22,30 @@ function _interopNamespaceDefault(e) {
22
22
 
23
23
  var R__namespace = /*#__PURE__*/_interopNamespaceDefault(R);
24
24
 
25
- const DEFAULT_RESULTS_LIMIT = 5000;
26
-
25
+ const DEFAULT_RESULTS_LIMIT = 5e3;
27
26
  function createPOISearch(pois, lang) {
28
27
  const index = utils.getFlexSearchInstance({ lang });
29
-
30
- // index.addMatcher({
31
- // '[\'.,]': ''
32
- // })
33
-
34
28
  prepareIndexEntries(pois).forEach(([id, content]) => index.add(id, content));
35
-
36
- function prepareIndexEntries(pois) {
37
- return Object.values(pois).map(poi => {
38
- const { poiId, category = '', name, keywords = [], roomId = '' } = poi;
39
- const grabTags = R__namespace.path(['dynamicData', 'grab', 'tags'], poi) || [];
40
- const searchKeywords = keywords.filter(R__namespace.prop('isUserSearchable')).map(R__namespace.prop('name'));
41
- const content = `${name} ${category.split('.').join(' ')} ${roomId} ${searchKeywords.join(' ')} ${grabTags.join(' ')}`;
29
+ function prepareIndexEntries(pois2) {
30
+ return Object.values(pois2).map((poi) => {
31
+ const { poiId, category = "", name, keywords = [], roomId = "" } = poi;
32
+ const grabTags = R__namespace.path(["dynamicData", "grab", "tags"], poi) || [];
33
+ const searchKeywords = keywords.filter(R__namespace.prop("isUserSearchable")).map(R__namespace.prop("name"));
34
+ const content = `${name} ${category.split(".").join(" ")} ${roomId} ${searchKeywords.join(" ")} ${grabTags.join(" ")}`;
42
35
  return [Number(poiId), content];
43
36
  });
44
37
  }
45
-
46
38
  function search(queryParams) {
47
39
  const options = { ...queryParams };
48
- if (!options.limit) // sometimes limit is NaN or undefined!
49
- {
40
+ if (!options.limit) {
50
41
  options.limit = DEFAULT_RESULTS_LIMIT;
51
42
  }
52
43
  const ids = index.search(options);
53
44
  return Object.values(R__namespace.pick(ids, pois));
54
45
  }
55
-
56
- function updateMultiple(pois) {
57
- prepareIndexEntries(pois).forEach(([id, content]) => index.update(id, content));
46
+ function updateMultiple(pois2) {
47
+ prepareIndexEntries(pois2).forEach(([id, content]) => index.update(id, content));
58
48
  }
59
-
60
49
  return { search, updateMultiple };
61
50
  }
62
51
 
@@ -30,154 +30,84 @@ function create(app, config) {
30
30
  const state = {
31
31
  poiSearch: null,
32
32
  typeahead: null,
33
- indexesCreated: new Zousan(), // re-initialize this when changing venues
33
+ indexesCreated: new Zousan(),
34
+ // re-initialize this when changing venues
34
35
  defaultSearchTerms: null,
35
- specialQueryTerms: {},
36
+ specialQueryTerms: {}
36
37
  };
37
-
38
38
  const init = async () => {
39
- const pois = await app.bus.get('poi/getAll');
39
+ const pois = await app.bus.get("poi/getAll");
40
40
  state.poiSearch = poiSearch(pois, app.i18n().language);
41
41
  state.typeahead = searchTypeahead(pois, state.poiSearch.search, app.i18n().language);
42
- state.defaultSearchTerms = configUtils.getLocalized(config, 'defaultSearchTerms', app.i18n().language);
42
+ state.defaultSearchTerms = configUtils.getLocalized(config, "defaultSearchTerms", app.i18n().language);
43
43
  state.indexesCreated.resolve();
44
44
  };
45
-
46
- /**
47
- * Prepares and send an event with up to 50 non-portal POIs sorted by distance to user location.
48
- */
49
- // todo check if async events (events which send a new event as a result) are still needed
50
- app.bus.on('search/queryNearby', async () => {
45
+ app.bus.on("search/queryNearby", async () => {
51
46
  const pois = await searchNearby();
52
- app.bus.send('search/showNearby', { pois, term: 'Nearby' });
47
+ app.bus.send("search/showNearby", { pois, term: "Nearby" });
53
48
  return pois;
54
49
  });
55
-
56
- /**
57
- * Returns max 50 non-portal POIs sorted by distance to user location.
58
- * @returns Array.<POI>
59
- */
60
- app.bus.on('search/queryNearbyAsync', searchNearby);
61
-
50
+ app.bus.on("search/queryNearbyAsync", searchNearby);
62
51
  async function searchNearby() {
63
- const startLocation = await app.bus.getFirst('user/getPhysicalLocation');
52
+ const startLocation = await app.bus.getFirst("user/getPhysicalLocation");
64
53
  if (!startLocation?.floorId) {
65
54
  return [];
66
55
  }
67
- const poisSameFloor = await app.bus.get('poi/getByFloorId', {
68
- floorId: startLocation?.floorId,
56
+ const poisSameFloor = await app.bus.get("poi/getByFloorId", {
57
+ floorId: startLocation?.floorId
69
58
  });
70
- const isNotPortal = poi => poi.category.indexOf('portal') === -1 && poi.category !== 'element.door';
59
+ const isNotPortal = (poi) => poi.category.indexOf("portal") === -1 && poi.category !== "element.door";
71
60
  const noPortalPois = Object.values(R__namespace.pickBy(isNotPortal, poisSameFloor));
72
- const poisWithDistance = await app.bus.get('wayfinder/addPathTimeMultiple', {
61
+ const poisWithDistance = await app.bus.get("wayfinder/addPathTimeMultiple", {
73
62
  pois: noPortalPois,
74
- startLocation,
63
+ startLocation
75
64
  });
76
- return R__namespace.sortBy(R__namespace.prop('distance'), Object.values(poisWithDistance)).slice(0, 50);
65
+ return R__namespace.sortBy(R__namespace.prop("distance"), Object.values(poisWithDistance)).slice(0, 50);
77
66
  }
78
-
79
- /**
80
- * Searches for POIs with search term or category name
81
- * and sends a new event 'search/showCategory' with search result POIs.
82
- *
83
- * @param {string} searchTerm - term to search POIs
84
- * @param {string} category - category name, fallback term to search POIs
85
- * @param {string} categoryName - label to display in search results input view
86
- */
87
- app.bus.on('search/queryCategory', async ({ category, categoryName, searchTerm }) => {
67
+ app.bus.on("search/queryCategory", async ({ category, categoryName, searchTerm }) => {
88
68
  const pois = await state.indexesCreated.then(() => state.poiSearch.search({ query: searchTerm || category }));
89
- app.bus.send('search/showCategory', { pois, category, categoryName });
69
+ app.bus.send("search/showCategory", { pois, category, categoryName });
90
70
  return pois;
91
71
  });
92
-
93
- /**
94
- * Searches for POIs with search term
95
- * and sends a new event 'search/showCategory' with search result POIs.
96
- *
97
- * @param {string} term - search term
98
- */
99
- // todo introduce consistent naming for parameters are return values (searchTem or term, pois or results, keywords or searchTerms)
100
- app.bus.on('search/query', ({ term }) => {
72
+ app.bus.on("search/query", ({ term }) => {
101
73
  return state.indexesCreated.then(() => {
102
74
  const pois = state.poiSearch.search({ query: term });
103
- app.bus.send('search/showSearchResults', { results: pois, term });
75
+ app.bus.send("search/showSearchResults", { results: pois, term });
104
76
  return pois;
105
77
  });
106
78
  });
107
-
108
- /**
109
- * Search for POIs with search term.
110
- *
111
- * @param {string} term - search term
112
- * @returns Array.<POI>
113
- */
114
- app.bus.on('search/queryAsync', ({ term }) =>
115
- state.indexesCreated.then(() => state.poiSearch.search({ query: term })),
79
+ app.bus.on(
80
+ "search/queryAsync",
81
+ ({ term }) => state.indexesCreated.then(() => state.poiSearch.search({ query: term }))
116
82
  );
117
-
118
- /**
119
- * If search term matches any registered special query term,
120
- * then send an event with params for this special query,
121
- * otherwise search for POIs with term and send the event 'search/query' with search result POIs
122
- *
123
- * @param {string} term - search term or special query
124
- */
125
- app.bus.on('search/queryWithSpecial', ({ term }) => {
83
+ app.bus.on("search/queryWithSpecial", ({ term }) => {
126
84
  if (state.specialQueryTerms[term]) {
127
85
  const { event, params } = state.specialQueryTerms[term];
128
- // use "send" as we can't gaurentee this event is a "get" or even returns POIs
129
86
  return app.bus.send(event, params);
130
87
  } else {
131
- return app.bus.get('search/query', { term });
88
+ return app.bus.get("search/query", { term });
132
89
  }
133
90
  });
134
-
135
- /**
136
- * Returns list of all localized default search terms declared in the configuration
137
- * or list of up to 'limit' random unique POI categories as a fallback.
138
- * Returns a list of keywords and sends an event 'search/showDefaultSearchKeywords' with same the list of keywords.
139
- *
140
- * @param {number} [limit=5] - Used to limit number of random unique categories list if default search terms are not defined in configuration.
141
- * @returns Array.<string> - list of keywords
142
- */
143
- app.bus.on('search/getDefaultSearchTerms', async ({ limit = 5 } = {}) => {
91
+ app.bus.on("search/getDefaultSearchTerms", async ({ limit = 5 } = {}) => {
144
92
  const defaultSearchTerms = state.defaultSearchTerms;
145
93
  const hasDefaultSearchTerms = defaultSearchTerms && defaultSearchTerms.length;
146
94
  const keywords = hasDefaultSearchTerms ? defaultSearchTerms : await getUniqueRandomCategories(limit);
147
- app.bus.send('search/showDefaultSearchKeywords', { keywords });
95
+ app.bus.send("search/showDefaultSearchKeywords", { keywords });
148
96
  return keywords;
149
97
  });
150
-
151
98
  async function getUniqueRandomCategories(limit) {
152
- const allCategories = (await app.bus.send('poi/getAllCategories'))[0];
99
+ const allCategories = (await app.bus.send("poi/getAllCategories"))[0];
153
100
  const uniqueCategories = Array.from(new Set(allCategories));
154
101
  const shuffledUniqueCategories = rand.randomizeArray(uniqueCategories);
155
102
  return shuffledUniqueCategories.slice(0, limit);
156
103
  }
157
-
158
- /**
159
- * Returns list of up to 'limit' unique random navigable POIs.
160
- *
161
- * @param {number} [limit=5]
162
- * @returns Array.<POI>
163
- */
164
- app.bus.on('search/getDefaultSearchPois', async ({ limit = 5 } = {}) => {
165
- const allPois = await app.bus.get('poi/getAll');
166
- const navigablePred = val => val.isNavigable;
104
+ app.bus.on("search/getDefaultSearchPois", async ({ limit = 5 } = {}) => {
105
+ const allPois = await app.bus.get("poi/getAll");
106
+ const navigablePred = (val) => val.isNavigable;
167
107
  const navigablePois = R__namespace.pickBy(navigablePred, allPois);
168
108
  return rand.arrayPick(Object.values(navigablePois), limit);
169
109
  });
170
-
171
- /**
172
- * Registers an event and event params for special query term.
173
- * Optionally adds passed special query term to keywords search index.
174
- *
175
- * @param {string} term - special query term
176
- * @param {string} event - name of associated event
177
- * @param {Object} params - parameters for associated event
178
- * @param {boolean} addKeyword - indicates if term has to be added to keywords search index
179
- */
180
- app.bus.on('search/registerSpecialQuery', ({ term, event, params, addKeyword = true }) => {
110
+ app.bus.on("search/registerSpecialQuery", ({ term, event, params, addKeyword = true }) => {
181
111
  state.indexesCreated.then(() => {
182
112
  if (addKeyword) {
183
113
  state.typeahead.addKeyword(term);
@@ -185,69 +115,37 @@ function create(app, config) {
185
115
  state.specialQueryTerms[term] = { event, params };
186
116
  });
187
117
  });
188
-
189
- /**
190
- * Adds list of keywords to keywords search index.
191
- *
192
- * @param {Array.<string>} keywords - list of new keywords
193
- */
194
- app.bus.on('search/addKeywords', ({ keywords }) =>
195
- state.indexesCreated.then(() => keywords.forEach(keyword => state.typeahead.addKeyword(keyword))),
118
+ app.bus.on(
119
+ "search/addKeywords",
120
+ ({ keywords }) => state.indexesCreated.then(() => keywords.forEach((keyword) => state.typeahead.addKeyword(keyword)))
196
121
  );
197
-
198
- /**
199
- * Returns lists of keywords and POIs matching search term.
200
- *
201
- * For term shorter than 3 characters only keywords index is queried.
202
- * If no keywords are found or when term is longer,
203
- * then POIs index is queried for the the remaining results.
204
- *
205
- * @param {string} term - search term
206
- * @param {number} limit - maximum number of results
207
- * @returns {{ pois: Array.<POI>, keywords: Array.<String>, term: string }} - list of keywords, list of POIs, search term
208
- */
209
- app.bus.on('search/typeahead', ({ term, limit }) =>
210
- state.indexesCreated.then(() => {
122
+ app.bus.on(
123
+ "search/typeahead",
124
+ ({ term, limit }) => state.indexesCreated.then(() => {
211
125
  const { keywords, pois } = state.typeahead.query(term, limit);
212
126
  return { keywords, pois, term };
213
- }),
127
+ })
214
128
  );
215
-
216
- /**
217
- * Resets plugin state.
218
- */
219
- app.bus.on('venueData/loadNewVenue', () => {
129
+ app.bus.on("venueData/loadNewVenue", () => {
220
130
  state.indexesCreated = new Zousan();
221
131
  init();
222
132
  });
223
-
224
- /**
225
- * Updates POIs search index with dynamic Grab POIs.
226
- *
227
- * @param {string} plugin - type of dynamic data
228
- * @param {Object<string, Object>} - dictionary of POI id to dynamic data object
229
- */
230
- app.bus.on('poi/setDynamicData', async ({ plugin, idValuesMap }) => {
231
- if (plugin !== 'grab') {
133
+ app.bus.on("poi/setDynamicData", async ({ plugin, idValuesMap }) => {
134
+ if (plugin !== "grab") {
232
135
  return;
233
136
  }
234
-
235
- const dynamicPoisPromises = Object.keys(idValuesMap).map(id => app.bus.get('poi/getById', { id }));
236
-
237
- return Promise.all(dynamicPoisPromises).then(pois =>
238
- state.indexesCreated.then(() => state.poiSearch.updateMultiple(pois)),
137
+ const dynamicPoisPromises = Object.keys(idValuesMap).map((id) => app.bus.get("poi/getById", { id }));
138
+ return Promise.all(dynamicPoisPromises).then(
139
+ (pois) => state.indexesCreated.then(() => state.poiSearch.updateMultiple(pois))
239
140
  );
240
141
  });
241
-
242
142
  const runTest = async (initialState, testRoutine) => {
243
- // state = { ...initialState }
244
143
  await testRoutine();
245
144
  return state;
246
145
  };
247
-
248
146
  return {
249
147
  init,
250
- runTest,
148
+ runTest
251
149
  };
252
150
  }
253
151