atriusmaps-node-sdk 3.3.721 → 3.3.723
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.
- package/dist/cjs/deploy/prepareSDKConfig.js +40 -14
- package/dist/cjs/nodesdk/nodeEntry.js +14 -5
- package/dist/cjs/package.json.js +1 -1
- package/dist/cjs/plugins/dynamicPois/src/dynamicPois.js +14 -7
- package/dist/cjs/plugins/dynamicPois/src/processors.js +3 -1
- package/dist/cjs/plugins/poiDataManager/src/poiDataManager.js +55 -21
- package/dist/cjs/plugins/sdkServer/src/sdkHeadless.js +6 -2
- package/dist/cjs/plugins/sdkServer/src/sdkServer.js +19 -8
- package/dist/cjs/plugins/searchService/src/poiSearch.js +3 -2
- package/dist/cjs/plugins/searchService/src/searchService.js +6 -2
- package/dist/cjs/plugins/searchService/src/utils.js +3 -1
- package/dist/cjs/plugins/venueDataLoader/src/venueDataLoader.js +53 -21
- package/dist/cjs/plugins/venueDataLoader/src/venueLoadingUtils.js +17 -7
- package/dist/cjs/plugins/wayfinder/src/findRoute.js +21 -7
- package/dist/cjs/plugins/wayfinder/src/navGraph.js +56 -20
- package/dist/cjs/plugins/wayfinder/src/navGraphDebug.js +3 -1
- package/dist/cjs/plugins/wayfinder/src/segmentBuilder.js +75 -33
- package/dist/cjs/plugins/wayfinder/src/stepBuilder.js +15 -5
- package/dist/cjs/plugins/wayfinder/src/wayfinder.js +47 -18
- package/dist/cjs/src/app.js +21 -8
- package/dist/cjs/src/configs/postproc-mol-url-parms.js +15 -6
- package/dist/cjs/src/configs/postproc-stateTracking.js +8 -3
- package/dist/cjs/src/debugTools.js +8 -3
- package/dist/cjs/src/env.js +2 -1
- package/dist/cjs/src/extModules/bustle.js +40 -16
- package/dist/cjs/src/extModules/flexapi/src/validate.js +42 -18
- package/dist/cjs/src/extModules/log.js +16 -6
- package/dist/cjs/src/historyManager.js +3 -1
- package/dist/cjs/src/utils/configUtils.js +21 -8
- package/dist/cjs/src/utils/dom.js +19 -10
- package/dist/cjs/src/utils/funcs.js +8 -3
- package/dist/cjs/src/utils/geom.js +15 -5
- package/dist/cjs/src/utils/isInitialState.js +7 -3
- package/dist/cjs/src/utils/location.js +17 -8
- package/dist/cjs/src/utils/observable.js +17 -6
- package/dist/cjs/src/utils/rand.js +6 -2
- package/dist/package.json.js +1 -1
- package/dist/plugins/wayfinder/src/navGraph.js +1 -1
- package/dist/plugins/wayfinder/src/stepBuilder.js +1 -1
- package/package.json +1 -1
|
@@ -171,7 +171,9 @@ function create(app, config) {
|
|
|
171
171
|
const route = await getRoute({ fromEndpoint, toEndpoint, options });
|
|
172
172
|
if (route) {
|
|
173
173
|
const { segments } = route;
|
|
174
|
-
if (options.primary)
|
|
174
|
+
if (options.primary) {
|
|
175
|
+
app.bus.send('map/resetNavlineFeatures');
|
|
176
|
+
}
|
|
175
177
|
app.bus.send('map/showNavlineFeatures', {
|
|
176
178
|
segments,
|
|
177
179
|
category: options.primary ? 'primary' : 'alternative',
|
|
@@ -185,7 +187,9 @@ function create(app, config) {
|
|
|
185
187
|
app.bus.get('poi/getById', { id }).then(poi => {
|
|
186
188
|
if (poi && poi.position) {
|
|
187
189
|
return poiToNavigationEndpoint(poi, floorIdToOrdinal);
|
|
188
|
-
} else
|
|
190
|
+
} else {
|
|
191
|
+
throw Error('Unknown POI ID ' + id);
|
|
192
|
+
}
|
|
189
193
|
});
|
|
190
194
|
|
|
191
195
|
/**
|
|
@@ -199,20 +203,29 @@ function create(app, config) {
|
|
|
199
203
|
*/
|
|
200
204
|
async function getNavigationEndpoint(p) {
|
|
201
205
|
return graphLoadedProm.then(graph => {
|
|
202
|
-
if (!p)
|
|
206
|
+
if (!p) {
|
|
207
|
+
throw Error('wayfinder: Invalid endpoint definition', p);
|
|
208
|
+
}
|
|
203
209
|
|
|
204
|
-
if (typeof p === 'number')
|
|
210
|
+
if (typeof p === 'number') {
|
|
211
|
+
return poiIdToNavigationEndpoint(p, graph.floorIdToOrdinal);
|
|
212
|
+
}
|
|
205
213
|
|
|
206
214
|
if (typeof p === 'string') {
|
|
207
|
-
if (p.match(/^\d+$/))
|
|
208
|
-
|
|
215
|
+
if (p.match(/^\d+$/)) // single integer - assume its poi id
|
|
216
|
+
{
|
|
209
217
|
return poiIdToNavigationEndpoint(parseInt(p), graph.floorIdToOrdinal);
|
|
218
|
+
}
|
|
210
219
|
|
|
211
220
|
if (p.indexOf(',') > 0) {
|
|
212
221
|
// lat,lng,floorId,desc format
|
|
213
222
|
let [lat, lng, floorId, title] = p.split(',');
|
|
214
|
-
if (!graph.floorIdToStructureId(floorId))
|
|
215
|
-
|
|
223
|
+
if (!graph.floorIdToStructureId(floorId)) {
|
|
224
|
+
throw Error('Unknown floorId in endpoint: ' + floorId);
|
|
225
|
+
}
|
|
226
|
+
if (!title) {
|
|
227
|
+
title = 'Starting Point';
|
|
228
|
+
}
|
|
216
229
|
|
|
217
230
|
return {
|
|
218
231
|
lat: parseFloat(lat),
|
|
@@ -224,9 +237,11 @@ function create(app, config) {
|
|
|
224
237
|
}
|
|
225
238
|
}
|
|
226
239
|
|
|
227
|
-
if (isEndpoint(p))
|
|
240
|
+
if (isEndpoint(p)) {
|
|
241
|
+
return p;
|
|
242
|
+
}
|
|
228
243
|
|
|
229
|
-
if (p.latitude)
|
|
244
|
+
if (p.latitude) {
|
|
230
245
|
return {
|
|
231
246
|
lat: p.latitude,
|
|
232
247
|
lng: p.longitude,
|
|
@@ -234,10 +249,12 @@ function create(app, config) {
|
|
|
234
249
|
ordinal: graph.floorIdToOrdinal(p.floorId),
|
|
235
250
|
title: p.title,
|
|
236
251
|
};
|
|
252
|
+
}
|
|
237
253
|
|
|
238
|
-
if (p.position && p.name)
|
|
239
|
-
|
|
254
|
+
if (p.position && p.name) // looks like a POI or some other
|
|
255
|
+
{
|
|
240
256
|
return poiToNavigationEndpoint(p, graph.floorIdToOrdinal);
|
|
257
|
+
}
|
|
241
258
|
|
|
242
259
|
throw Error('Invalid start or end point: ' + p);
|
|
243
260
|
});
|
|
@@ -280,7 +297,9 @@ function create(app, config) {
|
|
|
280
297
|
options.compareFindPaths = config.compareFindPaths;
|
|
281
298
|
const route = findRoute.findRoute(graph, fromEndpoint, toEndpoint, options);
|
|
282
299
|
|
|
283
|
-
if (!route)
|
|
300
|
+
if (!route) {
|
|
301
|
+
return { routeExists: false };
|
|
302
|
+
}
|
|
284
303
|
|
|
285
304
|
const queues = route.waypoints.filter(
|
|
286
305
|
node =>
|
|
@@ -322,7 +341,9 @@ function create(app, config) {
|
|
|
322
341
|
return graphLoadedProm.then(async graph => {
|
|
323
342
|
options.compareFindPaths = config.compareFindPaths;
|
|
324
343
|
const route = findRoute.findRoute(graph, fromEndpoint, toEndpoint, options);
|
|
325
|
-
if (!route)
|
|
344
|
+
if (!route) {
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
326
347
|
const floorIdToNameMap = await app.bus.get('venueData/getFloorIdToNameMap');
|
|
327
348
|
const queueTypes = await app.bus.get('venueData/getQueueTypes');
|
|
328
349
|
const translate = app.gt();
|
|
@@ -357,7 +378,9 @@ function create(app, config) {
|
|
|
357
378
|
* @returns Array.<Object> - list of POIs
|
|
358
379
|
*/
|
|
359
380
|
app.bus.on('wayfinder/addPathTimeMultiple', async ({ pois, startLocation, options = {} }) => {
|
|
360
|
-
if (!startLocation)
|
|
381
|
+
if (!startLocation) {
|
|
382
|
+
return pois;
|
|
383
|
+
}
|
|
361
384
|
return graphLoadedProm.then(graph => addPathTimeMultiple(graph, options, pois, startLocation));
|
|
362
385
|
});
|
|
363
386
|
|
|
@@ -442,7 +465,9 @@ function create(app, config) {
|
|
|
442
465
|
app.bus.on(
|
|
443
466
|
'wayfinder/multipointAddPathTimeMultiple',
|
|
444
467
|
async ({ pois, startLocation, endLocation, currentLocation, options = {} }) => {
|
|
445
|
-
if (!startLocation && !endLocation && !currentLocation)
|
|
468
|
+
if (!startLocation && !endLocation && !currentLocation) {
|
|
469
|
+
return pois;
|
|
470
|
+
}
|
|
446
471
|
return graphLoadedProm.then(graph =>
|
|
447
472
|
multipointAddPathTimeMultiple(graph, options, pois, startLocation, endLocation, currentLocation),
|
|
448
473
|
);
|
|
@@ -491,7 +516,9 @@ function create(app, config) {
|
|
|
491
516
|
const distancePrimary = resolvePathDistance(pathPrimary, startLocation, poi);
|
|
492
517
|
const distanceSecondary = resolvePathDistance(pathSecondary, poi, endLocation);
|
|
493
518
|
|
|
494
|
-
if (!distancePrimary || !distanceSecondary)
|
|
519
|
+
if (!distancePrimary || !distanceSecondary) {
|
|
520
|
+
return null;
|
|
521
|
+
} // ensure poi is reachable from both locations
|
|
495
522
|
|
|
496
523
|
const timePrimary = resolvePathTime(pathPrimary, distancePrimary);
|
|
497
524
|
const timeSecondary = resolvePathTime(pathSecondary, distanceSecondary);
|
|
@@ -551,7 +578,9 @@ function create(app, config) {
|
|
|
551
578
|
* @param {Object<string, SecurityWaitTime|Object>} - dictionary of POI id to dynamic data object
|
|
552
579
|
*/
|
|
553
580
|
app.bus.on('poi/setDynamicData', ({ plugin, idValuesMap }) => {
|
|
554
|
-
if (plugin !== 'security')
|
|
581
|
+
if (plugin !== 'security') {
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
555
584
|
graphLoadedProm.then(graph => graph.updateWithSecurityWaitTime(idValuesMap));
|
|
556
585
|
});
|
|
557
586
|
|
package/dist/cjs/src/app.js
CHANGED
|
@@ -65,9 +65,13 @@ const getLang = config => {
|
|
|
65
65
|
const queryParms = new URLSearchParams(location.search);
|
|
66
66
|
// eslint-disable-next-line no-constant-condition
|
|
67
67
|
let lang = queryParms.get('lang') || (typeof navigator ? navigator.language : null);
|
|
68
|
-
while (lang)
|
|
69
|
-
if (lang && supportedLanguages.includes(lang))
|
|
70
|
-
|
|
68
|
+
while (lang) {
|
|
69
|
+
if (lang && supportedLanguages.includes(lang)) {
|
|
70
|
+
return lang;
|
|
71
|
+
} else {
|
|
72
|
+
lang = lang.substring(0, lang.lastIndexOf('-'));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
71
75
|
}
|
|
72
76
|
|
|
73
77
|
return config.defaultLanguage || 'en';
|
|
@@ -102,8 +106,9 @@ async function create(rawConfig) {
|
|
|
102
106
|
let config = rawConfig.extends ? await extendConfig(rawConfig, rawConfig.extends) : rawConfig;
|
|
103
107
|
|
|
104
108
|
// this handles error reporting, so we want it activated ASAP
|
|
105
|
-
if (config.plugins.monitoring)
|
|
109
|
+
if (config.plugins.monitoring) {
|
|
106
110
|
await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespaceDefaultOnly(require('../_virtual/_empty_module_placeholder.js')); }).then(mon => mon.activate(config.plugins.monitoring));
|
|
111
|
+
}
|
|
107
112
|
|
|
108
113
|
config = await handleConfigPostProcess(config);
|
|
109
114
|
|
|
@@ -137,10 +142,14 @@ async function create(rawConfig) {
|
|
|
137
142
|
if (config.debug) {
|
|
138
143
|
appInstance.debug = R.map(fn => fn.bind(appInstance), debugTools);
|
|
139
144
|
debugTools.dndGo.call(appInstance); // setup DnD by default...
|
|
140
|
-
} else
|
|
145
|
+
} else {
|
|
146
|
+
appInstance.debug = {};
|
|
147
|
+
} // no tools unless in debug mode.. (good idea?)
|
|
141
148
|
|
|
142
149
|
window._app = appInstance;
|
|
143
|
-
if (window.document && window.document.title && config.setWindowTitle)
|
|
150
|
+
if (window.document && window.document.title && config.setWindowTitle) {
|
|
151
|
+
document.title = config.name;
|
|
152
|
+
}
|
|
144
153
|
}
|
|
145
154
|
|
|
146
155
|
appInstance.env = env.buildEnv(appInstance);
|
|
@@ -161,7 +170,9 @@ async function create(rawConfig) {
|
|
|
161
170
|
|
|
162
171
|
appInstance.destroy = () => LayerManager.destroy(appInstance);
|
|
163
172
|
});
|
|
164
|
-
} else
|
|
173
|
+
} else {
|
|
174
|
+
appInstance.destroy = () => {};
|
|
175
|
+
} // noop
|
|
165
176
|
|
|
166
177
|
if (config.plugins) {
|
|
167
178
|
for (const id in config.plugins) {
|
|
@@ -171,7 +182,9 @@ async function create(rawConfig) {
|
|
|
171
182
|
throw Error(`Duplicate plugin name "${id}"`);
|
|
172
183
|
}
|
|
173
184
|
const plugin = await setupPlugin(appInstance, id, pluginConfig);
|
|
174
|
-
if (plugin)
|
|
185
|
+
if (plugin) {
|
|
186
|
+
appInstance.plugins[id] = plugin;
|
|
187
|
+
}
|
|
175
188
|
} catch (e) {
|
|
176
189
|
appLog.error('Error instantiating plugin ' + id);
|
|
177
190
|
appLog.error(e);
|
|
@@ -34,9 +34,10 @@ function setDeepLinksForParms(config, parms, forceCreate) {
|
|
|
34
34
|
if (parms.has('lldebug')) {
|
|
35
35
|
try {
|
|
36
36
|
config.debug = JSON.parse(parms.get('lldebug'));
|
|
37
|
-
if (config.debug === null)
|
|
38
|
-
|
|
37
|
+
if (config.debug === null) // allow for a URL parm of just `lldebug` (no value = null)
|
|
38
|
+
{
|
|
39
39
|
config.debug = {};
|
|
40
|
+
}
|
|
40
41
|
} catch (e) {
|
|
41
42
|
config.debug = true;
|
|
42
43
|
}
|
|
@@ -44,18 +45,26 @@ function setDeepLinksForParms(config, parms, forceCreate) {
|
|
|
44
45
|
Object.keys(parmToPlugin).forEach(key => {
|
|
45
46
|
if (parms.has(key)) {
|
|
46
47
|
let plugins = parmToPlugin[key];
|
|
47
|
-
if (!Array.isArray(plugins))
|
|
48
|
+
if (!Array.isArray(plugins)) {
|
|
49
|
+
plugins = [plugins];
|
|
50
|
+
}
|
|
48
51
|
plugins.forEach(plugin => {
|
|
49
52
|
let pc = config.plugins[plugin]; // config for this plugin
|
|
50
|
-
if (!pc && forceCreate)
|
|
53
|
+
if (!pc && forceCreate) {
|
|
54
|
+
pc = config.plugins[plugin] = {};
|
|
55
|
+
}
|
|
51
56
|
pc.deepLinkProps = { ...pc.deepLinkProps, [key]: parms.get(key) };
|
|
52
57
|
});
|
|
53
58
|
}
|
|
54
59
|
});
|
|
55
60
|
|
|
56
|
-
if (
|
|
57
|
-
|
|
61
|
+
if (
|
|
62
|
+
parms.has('poiId') &&
|
|
63
|
+
parms.has('showNav')
|
|
64
|
+
) // poiId doubles as a parm for both - if showNav is defined, it should target getDirectionsFromTo only
|
|
65
|
+
{
|
|
58
66
|
delete config.plugins['online/poiView'].deepLinkProps.poiId;
|
|
67
|
+
}
|
|
59
68
|
|
|
60
69
|
return config;
|
|
61
70
|
}
|
|
@@ -44,11 +44,16 @@ function setStateFromStateString(config, stateString, forceCreate) {
|
|
|
44
44
|
Object.keys(state).forEach(id => {
|
|
45
45
|
const so = state[id];
|
|
46
46
|
let pluginConf = config.plugins[id];
|
|
47
|
-
if (!pluginConf && forceCreate)
|
|
47
|
+
if (!pluginConf && forceCreate) {
|
|
48
|
+
pluginConf = config.plugins[id] = {};
|
|
49
|
+
}
|
|
48
50
|
if (pluginConf) {
|
|
49
51
|
const curDLP = pluginConf.deepLinkProps;
|
|
50
|
-
if (!curDLP)
|
|
51
|
-
|
|
52
|
+
if (!curDLP) {
|
|
53
|
+
pluginConf.deepLinkProps = so;
|
|
54
|
+
} else {
|
|
55
|
+
pluginConf.deepLinkProps = R__namespace.mergeDeepRight(curDLP, so);
|
|
56
|
+
}
|
|
52
57
|
}
|
|
53
58
|
});
|
|
54
59
|
|
|
@@ -24,7 +24,9 @@ function _interopNamespaceDefault(e) {
|
|
|
24
24
|
|
|
25
25
|
var R__namespace = /*#__PURE__*/_interopNamespaceDefault(R);
|
|
26
26
|
|
|
27
|
-
if (typeof window !== 'undefined')
|
|
27
|
+
if (typeof window !== 'undefined') {
|
|
28
|
+
window.R = R__namespace;
|
|
29
|
+
} // helps use Rambda in console... probably don't want to do this once we integrate with customer content
|
|
28
30
|
|
|
29
31
|
// NOTE:
|
|
30
32
|
// The exported functions from this module all get placed into the app.debug (accessable from console via _app.debug) and bound to
|
|
@@ -137,8 +139,11 @@ function dndGo() {
|
|
|
137
139
|
const bus = this.bus;
|
|
138
140
|
const toggleActive = (e, indicateDragVisual) => {
|
|
139
141
|
e.preventDefault();
|
|
140
|
-
if (indicateDragVisual)
|
|
141
|
-
|
|
142
|
+
if (indicateDragVisual) {
|
|
143
|
+
e.target.classList.add('dragover');
|
|
144
|
+
} else {
|
|
145
|
+
e.target.classList.remove('dragover');
|
|
146
|
+
}
|
|
142
147
|
};
|
|
143
148
|
|
|
144
149
|
const handlers = {
|
package/dist/cjs/src/env.js
CHANGED
|
@@ -29,7 +29,7 @@ function buildEnv(app) {
|
|
|
29
29
|
supportsTouch,
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
if (isBrowser)
|
|
32
|
+
if (isBrowser) {
|
|
33
33
|
window.addEventListener('resize', () => {
|
|
34
34
|
app.bus.send('env/resize', {
|
|
35
35
|
isMobile: env.isMobile(),
|
|
@@ -37,6 +37,7 @@ function buildEnv(app) {
|
|
|
37
37
|
isVeryNarrow: env.isVeryNarrow(),
|
|
38
38
|
});
|
|
39
39
|
});
|
|
40
|
+
}
|
|
40
41
|
|
|
41
42
|
return env;
|
|
42
43
|
}
|
|
@@ -8,10 +8,13 @@ var Zousan = require('zousan');
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
const bustleResponseComparitor = (r1, r2) => {
|
|
11
|
-
if (r1.responseOrder == null)
|
|
12
|
-
|
|
13
|
-
return r2.responseOrder == null ? 0 : 1;
|
|
14
|
-
|
|
11
|
+
if (r1.responseOrder == null) // null or undefined
|
|
12
|
+
{
|
|
13
|
+
return r2.responseOrder == null ? 0 : 1;
|
|
14
|
+
} // any order is higher pri than none
|
|
15
|
+
if (r2.responseOrder == null) {
|
|
16
|
+
return -1;
|
|
17
|
+
}
|
|
15
18
|
return r1.responseOrder - r2.responseOrder;
|
|
16
19
|
};
|
|
17
20
|
|
|
@@ -24,7 +27,9 @@ const arRm = (ar, value) => {
|
|
|
24
27
|
let i = 0;
|
|
25
28
|
do {
|
|
26
29
|
i = ar.indexOf(value, i);
|
|
27
|
-
if (i >= 0)
|
|
30
|
+
if (i >= 0) {
|
|
31
|
+
arRmAt(ar, i);
|
|
32
|
+
}
|
|
28
33
|
} while (i >= 0);
|
|
29
34
|
return ar;
|
|
30
35
|
};
|
|
@@ -44,7 +49,9 @@ function create(opts = {}) {
|
|
|
44
49
|
// to subscribe to events by observing an event and then
|
|
45
50
|
// subscribing to that observer.
|
|
46
51
|
function on(ev, fn) {
|
|
47
|
-
if (!ons[ev])
|
|
52
|
+
if (!ons[ev]) {
|
|
53
|
+
ons[ev] = [];
|
|
54
|
+
}
|
|
48
55
|
|
|
49
56
|
ons[ev].push(fn);
|
|
50
57
|
|
|
@@ -56,7 +63,9 @@ function create(opts = {}) {
|
|
|
56
63
|
// response). Also, any calls to monitor listeners contains both the message
|
|
57
64
|
// object AND a promise containing the response from the normal listeners.
|
|
58
65
|
function monitor(ev, fn) {
|
|
59
|
-
if (!mons[ev])
|
|
66
|
+
if (!mons[ev]) {
|
|
67
|
+
mons[ev] = [];
|
|
68
|
+
}
|
|
60
69
|
|
|
61
70
|
mons[ev].push(fn);
|
|
62
71
|
|
|
@@ -66,7 +75,9 @@ function create(opts = {}) {
|
|
|
66
75
|
function off(ev, fn) {
|
|
67
76
|
// run ASAP but not immediate, in case it removes in its own function
|
|
68
77
|
Zousan.soon(() => {
|
|
69
|
-
if (!ons[ev])
|
|
78
|
+
if (!ons[ev]) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
70
81
|
arRm(ons[ev], fn);
|
|
71
82
|
});
|
|
72
83
|
}
|
|
@@ -74,7 +85,9 @@ function create(opts = {}) {
|
|
|
74
85
|
function moff(ev, fn) {
|
|
75
86
|
// run ASAP but not immediate, in case it removes in its own function
|
|
76
87
|
Zousan.soon(() => {
|
|
77
|
-
if (!mons[ev])
|
|
88
|
+
if (!mons[ev]) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
78
91
|
arRm(mons[ev], fn);
|
|
79
92
|
});
|
|
80
93
|
}
|
|
@@ -89,10 +102,15 @@ function create(opts = {}) {
|
|
|
89
102
|
try {
|
|
90
103
|
res.push(listener(ob));
|
|
91
104
|
} catch (err) {
|
|
92
|
-
if (opts.reportAllErrors)
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
105
|
+
if (opts.reportAllErrors) {
|
|
106
|
+
log.error(err);
|
|
107
|
+
}
|
|
108
|
+
if (opts.rejectOnError) {
|
|
109
|
+
res.push(Zousan.reject(err));
|
|
110
|
+
} // will cause the Zousan.all to reject the send
|
|
111
|
+
else {
|
|
112
|
+
res.push(err);
|
|
113
|
+
}
|
|
96
114
|
}
|
|
97
115
|
}
|
|
98
116
|
}
|
|
@@ -104,7 +122,9 @@ function create(opts = {}) {
|
|
|
104
122
|
try {
|
|
105
123
|
listener(ob, results);
|
|
106
124
|
} catch (err) {
|
|
107
|
-
if (opts.reportAllErrors)
|
|
125
|
+
if (opts.reportAllErrors) {
|
|
126
|
+
log.error(err);
|
|
127
|
+
}
|
|
108
128
|
}
|
|
109
129
|
}
|
|
110
130
|
}
|
|
@@ -132,8 +152,12 @@ function create(opts = {}) {
|
|
|
132
152
|
function send(ev, ob) {
|
|
133
153
|
if (opts.showEvents) {
|
|
134
154
|
if (typeof opts.showEvents === 'function') {
|
|
135
|
-
if (opts.showEvents(ev, ob))
|
|
136
|
-
|
|
155
|
+
if (opts.showEvents(ev, ob)) {
|
|
156
|
+
log.info('send with', ev, ' and ', ob);
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
log.info('send with', ev, ' and ', ob);
|
|
160
|
+
}
|
|
137
161
|
}
|
|
138
162
|
return new Zousan(resolve => Zousan.soon(serve(ev, ob, resolve)));
|
|
139
163
|
}
|
|
@@ -7,7 +7,9 @@ const sqStr = function (str) {
|
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
function validate(library, sig, cob) {
|
|
10
|
-
if (sig.args)
|
|
10
|
+
if (sig.args) {
|
|
11
|
+
checkTypeList(library.customTypes, sig.args, cob);
|
|
12
|
+
}
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
function getSigMatch(library, cob) {
|
|
@@ -50,38 +52,50 @@ function checkMinMax(name, typeSpec, value) {
|
|
|
50
52
|
* @return {true|string} returns true if arg is valid, else a string description of the problem
|
|
51
53
|
*/
|
|
52
54
|
function checkType(customTypes, typeSpec, value) {
|
|
53
|
-
if (!typeSpec)
|
|
54
|
-
|
|
55
|
+
if (!typeSpec) // if there is no typespec to validate against, any value is ok
|
|
56
|
+
{
|
|
55
57
|
return true;
|
|
58
|
+
}
|
|
56
59
|
|
|
57
60
|
const name = typeSpec.name || '';
|
|
58
61
|
|
|
59
62
|
// if type is a reference/custom, grab that type def but allow "optional" override - TODO: consider other overrides (perhaps all but "type"?)
|
|
60
|
-
if (customTypes && customTypes[typeSpec.type])
|
|
63
|
+
if (customTypes && customTypes[typeSpec.type]) {
|
|
61
64
|
typeSpec = Object.assign({}, customTypes[typeSpec.type], typeSpec, {
|
|
62
65
|
type: customTypes[typeSpec.type].type,
|
|
63
66
|
});
|
|
67
|
+
}
|
|
64
68
|
|
|
65
69
|
if (typeSpec.type === 'integer') {
|
|
66
|
-
if (typeof value === 'string')
|
|
67
|
-
|
|
70
|
+
if (typeof value === 'string') {
|
|
71
|
+
value = parseInt(value, 10);
|
|
72
|
+
}
|
|
73
|
+
if (!Number.isInteger(value)) {
|
|
68
74
|
throw Error('expected integer argument for argument ' + sqStr(name) + ' but received ' + value);
|
|
75
|
+
}
|
|
69
76
|
checkMinMax(name, typeSpec, value);
|
|
70
77
|
} else if (typeSpec.type === 'float') {
|
|
71
|
-
if (typeof value === 'string')
|
|
72
|
-
|
|
78
|
+
if (typeof value === 'string') {
|
|
79
|
+
value = parseFloat(value);
|
|
80
|
+
}
|
|
81
|
+
if (!Number.isFinite(value)) {
|
|
73
82
|
throw Error('expected float argument for argument ' + sqStr(name) + " but received '" + value + "'");
|
|
83
|
+
}
|
|
74
84
|
checkMinMax(name, typeSpec, value);
|
|
75
85
|
} else if (typeSpec.type === 'string') {
|
|
76
|
-
if (typeof value !== 'string')
|
|
77
|
-
|
|
86
|
+
if (typeof value !== 'string') {
|
|
87
|
+
throw Error(`argument ${sqStr(name)} must be a string but is not (value: ${value})`);
|
|
88
|
+
}
|
|
89
|
+
if (typeSpec.minLength && value.length < typeSpec.minLength) {
|
|
78
90
|
throw Error(
|
|
79
91
|
`argument ${sqStr(name)} must be a at least ${typeSpec.minLength} characters but is '${value}' (${value.length} chars)`,
|
|
80
92
|
);
|
|
81
|
-
|
|
93
|
+
}
|
|
94
|
+
if (typeSpec.maxLength && value.length > typeSpec.maxLength) {
|
|
82
95
|
throw Error(
|
|
83
96
|
`argument ${sqStr(name)} must be a at most ${typeSpec.maxLength} characters but is '${value}' (${value.length} chars)`,
|
|
84
97
|
);
|
|
98
|
+
}
|
|
85
99
|
} else if (typeSpec.type === 'boolean') {
|
|
86
100
|
if (
|
|
87
101
|
value !== true &&
|
|
@@ -96,8 +110,10 @@ function checkType(customTypes, typeSpec, value) {
|
|
|
96
110
|
);
|
|
97
111
|
}
|
|
98
112
|
} else if (typeSpec.type === 'list') {
|
|
99
|
-
if (!Array.isArray(value))
|
|
100
|
-
|
|
113
|
+
if (!Array.isArray(value)) {
|
|
114
|
+
throw Error('argument ' + sqStr(name) + ' must be a list but is not. Value = ' + value);
|
|
115
|
+
}
|
|
116
|
+
if (typeSpec.minLength !== undefined && typeSpec.minLength > value.length) {
|
|
101
117
|
throw Error(
|
|
102
118
|
'argument ' +
|
|
103
119
|
sqStr(name) +
|
|
@@ -107,7 +123,8 @@ function checkType(customTypes, typeSpec, value) {
|
|
|
107
123
|
value.length +
|
|
108
124
|
' items',
|
|
109
125
|
);
|
|
110
|
-
|
|
126
|
+
}
|
|
127
|
+
if (typeSpec.maxLength !== undefined && typeSpec.maxLength < value.length) {
|
|
111
128
|
throw Error(
|
|
112
129
|
'argument ' +
|
|
113
130
|
sqStr(name) +
|
|
@@ -117,6 +134,7 @@ function checkType(customTypes, typeSpec, value) {
|
|
|
117
134
|
value.length +
|
|
118
135
|
' items',
|
|
119
136
|
);
|
|
137
|
+
}
|
|
120
138
|
if (typeSpec.itemType) {
|
|
121
139
|
const allItemsValid = value.reduce(function (isValid, curItem) {
|
|
122
140
|
try {
|
|
@@ -133,10 +151,13 @@ function checkType(customTypes, typeSpec, value) {
|
|
|
133
151
|
}
|
|
134
152
|
}
|
|
135
153
|
} else if (typeSpec.type === 'object') {
|
|
136
|
-
if (typeof value !== 'object' || Array.isArray(value))
|
|
154
|
+
if (typeof value !== 'object' || Array.isArray(value)) {
|
|
137
155
|
throw Error('argument ' + sqStr(name) + ' must be an object but is not. Value = ' + value);
|
|
156
|
+
}
|
|
138
157
|
try {
|
|
139
|
-
if (typeSpec.props)
|
|
158
|
+
if (typeSpec.props) {
|
|
159
|
+
checkTypeList(customTypes, typeSpec.props, value);
|
|
160
|
+
}
|
|
140
161
|
} catch (e) {
|
|
141
162
|
throw Error('Within ' + name + ', ' + e.message);
|
|
142
163
|
}
|
|
@@ -149,9 +170,12 @@ function checkType(customTypes, typeSpec, value) {
|
|
|
149
170
|
}
|
|
150
171
|
return true;
|
|
151
172
|
}, false);
|
|
152
|
-
if (!oneTypeValid)
|
|
173
|
+
if (!oneTypeValid) {
|
|
153
174
|
throw Error(`Argument ${sqStr(name)} can be of several types, but is not valid for any: ${value}`);
|
|
154
|
-
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
throw Error('type ' + typeSpec.type + ' is an unknown type');
|
|
178
|
+
}
|
|
155
179
|
|
|
156
180
|
return true;
|
|
157
181
|
}
|
|
@@ -16,14 +16,17 @@ function clog(name, options = {}) {
|
|
|
16
16
|
let prefix = name + ': ';
|
|
17
17
|
let style = null;
|
|
18
18
|
|
|
19
|
-
if (options.color)
|
|
19
|
+
if (options.color) {
|
|
20
20
|
if (options.isBrowser) {
|
|
21
21
|
prefix = '%c' + prefix;
|
|
22
22
|
style = `color: ${options.color}`;
|
|
23
23
|
} else {
|
|
24
24
|
const cstring = nodeColorsOb[options.color];
|
|
25
|
-
if (cstring)
|
|
25
|
+
if (cstring) {
|
|
26
|
+
prefix = cstring + prefix;
|
|
27
|
+
}
|
|
26
28
|
}
|
|
29
|
+
}
|
|
27
30
|
|
|
28
31
|
const trunc = (str, len) => (str && str.length > len ? str.substring(0, len) + '...' : str);
|
|
29
32
|
const checkPassesFilter = (args, filter) =>
|
|
@@ -34,15 +37,22 @@ function clog(name, options = {}) {
|
|
|
34
37
|
const isEnabled = options.enabled === undefined ? true : !!options.enabled;
|
|
35
38
|
if (isEnabled || cmethod === console.error) {
|
|
36
39
|
let args = Array.from(arguments);
|
|
37
|
-
if (style)
|
|
40
|
+
if (style) {
|
|
41
|
+
args.unshift(style);
|
|
42
|
+
}
|
|
38
43
|
args.unshift(prefix);
|
|
39
|
-
if (options.truncateObjects && cmethod !== console.error)
|
|
44
|
+
if (options.truncateObjects && cmethod !== console.error) {
|
|
40
45
|
args = args.map(arg => {
|
|
41
|
-
if (typeof arg === 'object')
|
|
46
|
+
if (typeof arg === 'object') {
|
|
47
|
+
return trunc(JSON.stringify(arg), parseInt(options.truncateObjects) || 100);
|
|
48
|
+
}
|
|
42
49
|
return arg;
|
|
43
50
|
});
|
|
51
|
+
}
|
|
44
52
|
const passesFilter = !options.logFilter || checkPassesFilter(args, options.logFilter);
|
|
45
|
-
if (passesFilter || cmethod === console.error)
|
|
53
|
+
if (passesFilter || cmethod === console.error) {
|
|
54
|
+
cmethod.apply(console, args);
|
|
55
|
+
}
|
|
46
56
|
}
|
|
47
57
|
};
|
|
48
58
|
}
|
|
@@ -9,7 +9,9 @@ const initHistoryManager = ({ bus }) => {
|
|
|
9
9
|
const layersToHide = [];
|
|
10
10
|
const current = stepStack.pop();
|
|
11
11
|
|
|
12
|
-
if (!current)
|
|
12
|
+
if (!current) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
13
15
|
|
|
14
16
|
layersToHide.push(current.viewId);
|
|
15
17
|
for (let i = stepStack.length - 1; i >= 0; --i) {
|