atriusmaps-node-sdk 3.3.31 → 3.3.225
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/README.md +19 -1
- package/dist/cjs/_virtual/_empty_module_placeholder.js +2 -2
- package/dist/cjs/deploy/prepareSDKConfig.js +152 -2
- package/dist/cjs/nodesdk/nodeEntry.js +109 -0
- package/dist/cjs/package.json.js +190 -7
- package/dist/cjs/plugins/clientAPI/src/clientAPI.js +11 -2
- package/dist/cjs/plugins/dynamicPois/src/dynamicPois.js +218 -21
- package/dist/cjs/plugins/poiDataManager/src/poiDataManager.js +292 -21
- package/dist/cjs/plugins/sdkServer/src/sdkHeadless.js +99 -20
- package/dist/cjs/plugins/sdkServer/src/sdkServer.js +219 -2
- package/dist/cjs/plugins/sdkServer/src/util.js +16 -3
- package/dist/cjs/plugins/searchService/src/poiSearch.js +57 -19
- package/dist/cjs/plugins/searchService/src/searchService.js +246 -21
- package/dist/cjs/plugins/searchService/src/searchTypeahead.js +60 -3
- package/dist/cjs/plugins/searchService/src/utils.js +23 -4
- package/dist/cjs/plugins/venueDataLoader/src/venueDataLoader.js +472 -23
- package/dist/cjs/plugins/venueDataLoader/src/venueLoadingUtils.js +191 -23
- package/dist/cjs/plugins/wayfinder/src/findRoute.js +147 -19
- package/dist/cjs/plugins/wayfinder/src/minPriorityQueue.js +88 -2
- package/dist/cjs/plugins/wayfinder/src/navGraph.js +393 -5
- package/dist/cjs/plugins/wayfinder/src/navGraphDebug.js +110 -20
- package/dist/cjs/plugins/wayfinder/src/segmentBadges.js +28 -2
- package/dist/cjs/plugins/wayfinder/src/segmentBuilder.js +257 -19
- package/dist/cjs/plugins/wayfinder/src/segmentCategories.js +29 -2
- package/dist/cjs/plugins/wayfinder/src/stepBuilder.js +238 -3
- package/dist/cjs/plugins/wayfinder/src/wayfinder.js +597 -22
- package/dist/cjs/src/app.js +191 -25
- package/dist/cjs/src/configs/postproc-mol-url-parms.js +58 -2
- package/dist/cjs/src/configs/postproc-stateTracking.js +53 -19
- package/dist/cjs/src/controller.js +43 -4
- package/dist/cjs/src/debugTools.js +128 -23
- package/dist/cjs/src/env.js +17 -2
- package/dist/cjs/src/extModules/bustle.js +128 -4
- package/dist/cjs/src/extModules/flexapi/src/help.js +23 -4
- package/dist/cjs/src/extModules/flexapi/src/index.js +65 -4
- package/dist/cjs/src/extModules/flexapi/src/validate.js +133 -5
- package/dist/cjs/src/extModules/geohasher.js +90 -3
- package/dist/cjs/src/extModules/log.js +69 -2
- package/dist/cjs/src/historyManager.js +29 -2
- package/dist/cjs/src/utils/bounds.js +22 -4
- package/dist/cjs/src/utils/buildStructureLookup.js +31 -19
- package/dist/cjs/src/utils/configUtils.js +71 -3
- package/dist/cjs/src/utils/dom.js +48 -5
- package/dist/cjs/src/utils/funcs.js +30 -7
- package/dist/cjs/src/utils/geodesy.js +35 -3
- package/dist/cjs/src/utils/geom.js +212 -25
- package/dist/cjs/src/utils/i18n.js +69 -5
- package/dist/cjs/src/utils/observable.js +73 -2
- package/dist/cjs/src/utils/rand.js +82 -3
- package/dist/nodesdk/nodeEntry.js +1 -0
- package/dist/package.json.js +1 -0
- package/dist/plugins/dynamicPois/src/dynamicPois.js +1 -0
- package/dist/plugins/sdkServer/src/sdkHeadless.js +1 -0
- package/{lib → dist}/plugins/sdkServer/src/sdkServer.js +1 -1
- package/dist/plugins/searchService/src/poiSearch.js +1 -0
- package/dist/plugins/searchService/src/searchService.js +1 -0
- package/dist/plugins/venueDataLoader/src/venueDataLoader.js +1 -0
- package/dist/plugins/venueDataLoader/src/venueLoadingUtils.js +1 -0
- package/dist/plugins/wayfinder/src/navGraph.js +1 -0
- package/{lib → dist}/plugins/wayfinder/src/segmentBuilder.js +1 -1
- package/dist/plugins/wayfinder/src/stepBuilder.js +1 -0
- package/dist/plugins/wayfinder/src/wayfinder.js +1 -0
- package/dist/src/app.js +1 -0
- package/dist/src/configs/postproc-mol-url-parms.js +1 -0
- package/{lib → dist}/src/configs/sdkHeadless.json.js +1 -1
- package/dist/src/extModules/bustle.js +1 -0
- package/dist/src/extModules/log.js +1 -0
- package/dist/src/utils/funcs.js +1 -0
- package/dist/src/utils/geom.js +1 -0
- package/dist/src/utils/i18n.js +1 -0
- package/package.json +17 -9
- package/config/rollup.config.cjs.js +0 -31
- package/dist/cjs/deploy/nodeEntry.js +0 -15
- package/dist/cjs/src/auth/Auth.js +0 -23
- package/lib/deploy/nodeEntry.js +0 -1
- package/lib/package.json.js +0 -1
- package/lib/plugins/dynamicPois/src/dynamicPois.js +0 -1
- package/lib/plugins/sdkServer/src/sdkHeadless.js +0 -1
- package/lib/plugins/searchService/src/poiSearch.js +0 -1
- package/lib/plugins/searchService/src/searchService.js +0 -1
- package/lib/plugins/venueDataLoader/src/venueDataLoader.js +0 -1
- package/lib/plugins/venueDataLoader/src/venueLoadingUtils.js +0 -1
- package/lib/plugins/wayfinder/src/navGraph.js +0 -1
- package/lib/plugins/wayfinder/src/stepBuilder.js +0 -1
- package/lib/plugins/wayfinder/src/wayfinder.js +0 -1
- package/lib/src/app.js +0 -1
- package/lib/src/auth/Auth.js +0 -1
- package/lib/src/configs/postproc-mol-url-parms.js +0 -1
- package/lib/src/configs/sdkHeadless.json +0 -28
- package/lib/src/extModules/bustle.js +0 -1
- package/lib/src/extModules/log.js +0 -1
- package/lib/src/utils/funcs.js +0 -1
- package/lib/src/utils/geom.js +0 -1
- package/lib/src/utils/i18n.js +0 -1
- /package/{lib → dist}/_virtual/_empty_module_placeholder.js +0 -0
- /package/{lib → dist}/deploy/prepareSDKConfig.js +0 -0
- /package/{lib → dist}/plugins/clientAPI/src/clientAPI.js +0 -0
- /package/{lib → dist}/plugins/poiDataManager/src/poiDataManager.js +0 -0
- /package/{lib → dist}/plugins/sdkServer/src/util.js +0 -0
- /package/{lib → dist}/plugins/searchService/src/searchTypeahead.js +0 -0
- /package/{lib → dist}/plugins/searchService/src/utils.js +0 -0
- /package/{lib → dist}/plugins/wayfinder/src/findRoute.js +0 -0
- /package/{lib → dist}/plugins/wayfinder/src/minPriorityQueue.js +0 -0
- /package/{lib → dist}/plugins/wayfinder/src/navGraphDebug.js +0 -0
- /package/{lib → dist}/plugins/wayfinder/src/segmentBadges.js +0 -0
- /package/{lib → dist}/plugins/wayfinder/src/segmentCategories.js +0 -0
- /package/{lib → dist}/src/configs/postproc-stateTracking.js +0 -0
- /package/{lib → dist}/src/controller.js +0 -0
- /package/{lib → dist}/src/debugTools.js +0 -0
- /package/{lib → dist}/src/env.js +0 -0
- /package/{lib → dist}/src/extModules/flexapi/src/help.js +0 -0
- /package/{lib → dist}/src/extModules/flexapi/src/index.js +0 -0
- /package/{lib → dist}/src/extModules/flexapi/src/validate.js +0 -0
- /package/{lib → dist}/src/extModules/geohasher.js +0 -0
- /package/{lib → dist}/src/historyManager.js +0 -0
- /package/{lib → dist}/src/utils/bounds.js +0 -0
- /package/{lib → dist}/src/utils/buildStructureLookup.js +0 -0
- /package/{lib → dist}/src/utils/configUtils.js +0 -0
- /package/{lib → dist}/src/utils/dom.js +0 -0
- /package/{lib → dist}/src/utils/geodesy.js +0 -0
- /package/{lib → dist}/src/utils/observable.js +0 -0
- /package/{lib → dist}/src/utils/rand.js +0 -0
|
@@ -2,12 +2,136 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var Zousan = require('zousan');
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var Zousan__default = /*#__PURE__*/_interopDefaultLegacy(Zousan);
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Bustle is a highly performant event bus that offers event order guarantees.
|
|
13
|
+
*/
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
// Remove element from array at index specified and return the removed element.
|
|
16
|
+
// Source array will then have item removed.
|
|
17
|
+
const arRmAt = (ar, index) => ar.splice(index, 1)[0]; // oh yah, thats intuitive!
|
|
18
|
+
|
|
19
|
+
// Removes the value from the array if it exists. The array is then returned
|
|
20
|
+
const arRm = (ar, value) => {
|
|
21
|
+
let i = 0;
|
|
22
|
+
do {
|
|
23
|
+
i = ar.indexOf(value, i);
|
|
24
|
+
if (i >= 0)
|
|
25
|
+
arRmAt(ar, i);
|
|
26
|
+
} while (i >= 0)
|
|
27
|
+
return ar
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// This creates a bus instance. When used as a Singleton, you will only call this once
|
|
31
|
+
// for the life of your app. To isolate events (perhaps for performance or security
|
|
32
|
+
// reasons) you can create multple bus instances.
|
|
33
|
+
function create (opts = { }) {
|
|
34
|
+
// If a log option is defined, use it - and if it supports sublogs, instantiate that. If all else fails, use console
|
|
35
|
+
const log = opts.log ? (opts.log.sublog ? opts.log.sublog('bustle', { color: 'pink' }) : opts.log) : console;
|
|
36
|
+
|
|
37
|
+
const ons = { }; // holds your listeners
|
|
38
|
+
const mons = { }; // holds your monitors
|
|
39
|
+
|
|
40
|
+
// subscribes to an event. Your listener will always be called
|
|
41
|
+
// with a single argument. I am considering adding another way
|
|
42
|
+
// to subscribe to events by observing an event and then
|
|
43
|
+
// subscribing to that observer.
|
|
44
|
+
function on (ev, fn) {
|
|
45
|
+
if (!ons[ev])
|
|
46
|
+
ons[ev] = [];
|
|
47
|
+
|
|
48
|
+
ons[ev].push(fn);
|
|
49
|
+
|
|
50
|
+
return () => off(ev, fn)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Similar to "on" but is always called after all normal "on" listeners,
|
|
54
|
+
// and any values returned by a monitor call are ignored (not added to the
|
|
55
|
+
// response). Also, any calls to monitor listeners contains both the message
|
|
56
|
+
// object AND a promise containing the response from the normal listeners.
|
|
57
|
+
function monitor (ev, fn) {
|
|
58
|
+
if (!mons[ev])
|
|
59
|
+
mons[ev] = [];
|
|
60
|
+
|
|
61
|
+
mons[ev].push(fn);
|
|
62
|
+
|
|
63
|
+
return () => moff(ev, fn)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function off (ev, fn) {
|
|
67
|
+
if (!ons[ev])
|
|
68
|
+
return
|
|
69
|
+
arRm(ons[ev], fn);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function moff (ev, fn) {
|
|
73
|
+
if (!mons[ev])
|
|
74
|
+
return
|
|
75
|
+
arRm(mons[ev], fn);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const serve = (ev, ob, done) => () => {
|
|
79
|
+
// const myOns = (ons[ev] || []).concat(ons["*"] ? ons["*"] : [])
|
|
80
|
+
const myOns = ons[ev];
|
|
81
|
+
const myMons = mons[ev];
|
|
82
|
+
const res = [];
|
|
83
|
+
if (myOns) {
|
|
84
|
+
for (const listener of myOns) {
|
|
85
|
+
try {
|
|
86
|
+
res.push(listener(ob));
|
|
87
|
+
} catch (err) {
|
|
88
|
+
if (opts.reportAllErrors)
|
|
89
|
+
log.error(err);
|
|
90
|
+
if (opts.rejectOnError)
|
|
91
|
+
res.push(Zousan__default["default"].reject(err)); // will cause the Zousan.all to reject the send
|
|
92
|
+
else
|
|
93
|
+
res.push(err);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const results = Zousan__default["default"].all(res);
|
|
99
|
+
|
|
100
|
+
if (myMons) {
|
|
101
|
+
for (const listener of myMons) {
|
|
102
|
+
try {
|
|
103
|
+
listener(ob, results);
|
|
104
|
+
} catch (err) {
|
|
105
|
+
if (opts.reportAllErrors)
|
|
106
|
+
log.error(err);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
done(results);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// Used when there is a single listener that provides information or a service,
|
|
115
|
+
// a get sends a message to that listener, ensures it gets exactly 1 result,
|
|
116
|
+
// and returns that result.
|
|
117
|
+
const get = (ev, ob) =>
|
|
118
|
+
send(ev, ob).then(res => res.length !== 1
|
|
119
|
+
? Zousan__default["default"].reject(`${ev} event did not return a single result, but ${res.length} results.`)
|
|
120
|
+
: res[0]);
|
|
121
|
+
|
|
122
|
+
function send (ev, ob) {
|
|
123
|
+
if (opts.trace) { if (!ob) ob = { }; ob._stack = Error().stack; }
|
|
124
|
+
if (opts.showEvents) {
|
|
125
|
+
if (typeof opts.showEvents === 'function') {
|
|
126
|
+
if (opts.showEvents(ev, ob))
|
|
127
|
+
log.info('send with', ev, ' and ', ob);
|
|
128
|
+
} else
|
|
129
|
+
log.info('send with', ev, ' and ', ob);
|
|
130
|
+
}
|
|
131
|
+
return new Zousan__default["default"](resolve => Zousan__default["default"].soon(serve(ev, ob, resolve)))
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return { get, moff, monitor, off, on, send }
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
exports.create = create;
|
|
@@ -2,8 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
function
|
|
5
|
+
function pad (total, str) {
|
|
6
|
+
while (str.length < total) { str += ' '; }
|
|
7
|
+
return str
|
|
8
|
+
}
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
const getHelpHeader = () => pad(18, 'Command') + 'Arguments\n' + pad(18, '----------------') + '----------------\n';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Returns help on the passed command signature
|
|
14
|
+
*/
|
|
15
|
+
const getHelp = sig => pad(18, sig.command) +
|
|
16
|
+
(sig.args ? sig.args.map(argob => `${argob.name} {${argob.type}} ${argob.optional ? ' (optional)' : ' (required)'}`).join(', ') : '');
|
|
17
|
+
|
|
18
|
+
const sigsort = (s1, s2) => s1.command > s2.command ? 1 : -1;
|
|
19
|
+
/**
|
|
20
|
+
* Returns help on the passed command signatures
|
|
21
|
+
*/
|
|
22
|
+
const getHelpList = sigList => {
|
|
23
|
+
return sigList.sort(sigsort).reduce((ret, sig) => `${ret}${getHelp(sig)}\n`, getHelpHeader())
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
exports.getHelp = getHelp;
|
|
27
|
+
exports.getHelpHeader = getHelpHeader;
|
|
28
|
+
exports.getHelpList = getHelpList;
|
|
@@ -1,13 +1,74 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var Zousan = require('zousan');
|
|
4
4
|
var help = require('./help.js');
|
|
5
5
|
var validate = require('./validate.js');
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var Zousan__default = /*#__PURE__*/_interopDefaultLegacy(Zousan);
|
|
10
10
|
|
|
11
|
-
const
|
|
11
|
+
const COMMAND_VALIDATION_REGEX = /^[-_.0-9a-zA-Z]+$/;
|
|
12
|
+
const JS = JSON.stringify;
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
function create () {
|
|
15
|
+
const commandDefsList = [];
|
|
16
|
+
const commands = () => commandDefsList.map(cob => cob.sig);
|
|
17
|
+
const customTypes = { };
|
|
18
|
+
const library = { customTypes, commandDefsList };
|
|
19
|
+
const getCommandJSON = () => ({ commands: commands(), customTypes });
|
|
20
|
+
|
|
21
|
+
function registerCommand (sig, fn) {
|
|
22
|
+
const command = sig.command;
|
|
23
|
+
if (command === undefined) { throw Error(`Invalid command specification in registerCommand: ${JS(sig)}. No 'command' property specified.`) }
|
|
24
|
+
|
|
25
|
+
if (!COMMAND_VALIDATION_REGEX.test(command)) {
|
|
26
|
+
const er = Error(`Invalid command specification in registerCommand: ${JS(sig)}. Command name '${command}' not valid.`);
|
|
27
|
+
throw er
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
commandDefsList.push({ sig, fn });
|
|
31
|
+
|
|
32
|
+
return execute
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function registerCustomType (name, spec) {
|
|
36
|
+
customTypes[name] = spec;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function execute (cob) {
|
|
40
|
+
return new Zousan__default["default"]((resolve, reject) => {
|
|
41
|
+
if (!cob) { return reject(new Error(`No command specified in command object ${JS(cob)}`)) }
|
|
42
|
+
|
|
43
|
+
const commandMatches = library.commandDefsList
|
|
44
|
+
.filter(com => com.sig.command === cob.command);
|
|
45
|
+
|
|
46
|
+
if (commandMatches.length === 0) { return reject(new Error(`No API command '${cob.command}' found.\n${help.getHelpList(library.commandDefsList.map(o => o.sig))}`)) }
|
|
47
|
+
|
|
48
|
+
const sigMatch = validate.getSigMatch(library, cob);
|
|
49
|
+
|
|
50
|
+
if (!sigMatch) {
|
|
51
|
+
if (commandMatches.length === 1) { return reject(new Error(`Required fields not present in ${JS(cob)}\n${help.getHelpHeader()}${help.getHelp(commandMatches[0].sig)}`)) } else { return reject(new Error(`Command arguments did not match any required signatures: ${JS(cob)}\n${help.getHelpList(library.commandDefsList.map(o => o.sig))}`)) }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// console.log(`command ${JS(cob)} is ${JS(sigMatch.sig)}`)
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
validate.validate(library, sigMatch.sig, cob); // this will throw an error if invalid
|
|
58
|
+
} catch (e) { return reject(e) }
|
|
59
|
+
|
|
60
|
+
resolve(sigMatch.fn(cob));
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
registerCommand({ command: 'help', args: [] }, () => help.getHelpList(commands()));
|
|
65
|
+
registerCommand({ command: 'getCommandJSON', args: [] }, getCommandJSON);
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
registerCommand,
|
|
69
|
+
registerCustomType,
|
|
70
|
+
execute
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
module.exports = create;
|
|
@@ -2,9 +2,137 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// small helper for showing args
|
|
6
|
+
const SQ = '\''; // single quote
|
|
7
|
+
const sqStr = function (str) { return SQ + str + SQ };
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
function validate (library, sig, cob) {
|
|
10
|
+
if (sig.args)
|
|
11
|
+
checkTypeList(library.customTypes, sig.args, cob);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getSigMatch (library, cob) {
|
|
15
|
+
const matches = library.commandDefsList
|
|
16
|
+
.filter(cd => (cd.sig.command === cob.command) && matchesArgs(cd.sig, cob));
|
|
17
|
+
if (matches.length > 1) { throw Error('Command matches multiple signatures!') }
|
|
18
|
+
if (matches.length > 0) { return matches[0] }
|
|
19
|
+
return null // no matching signature found
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// returns true if each of the required arguments in the command
|
|
23
|
+
// spec (c) is defined within the command object (o) - else false
|
|
24
|
+
function matchesArgs (c, o) {
|
|
25
|
+
if (!c.args) { return true } // no args
|
|
26
|
+
return c.args.reduce(function (cs, argOb) {
|
|
27
|
+
return o[argOb.name] !== undefined || argOb.optional ? cs : false
|
|
28
|
+
}, true)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function checkMinMax (name, typeSpec, value) {
|
|
32
|
+
if (typeSpec.min !== undefined && value < typeSpec.min) { throw Error('argument ' + sqStr(name) + ' must be at least ' + typeSpec.min + ' but is ' + value) }
|
|
33
|
+
if (typeSpec.max !== undefined && value > typeSpec.max) { throw Error('argument ' + sqStr(name) + ' must be at most ' + typeSpec.max + ' but is ' + value) }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Checks an argument value against that arguments spec. If there are no violations of the argSpec, true is returned.
|
|
38
|
+
* If there is a violation, an error is thrown.
|
|
39
|
+
* @param {object} customTypes any defined custom types
|
|
40
|
+
* @param {object} typeSpec An type spec object which inclues a type and other constraints if applicable
|
|
41
|
+
* @param {*} value The JSON value to be checked against this spec
|
|
42
|
+
* @return {true|string} returns true if arg is valid, else a string description of the problem
|
|
43
|
+
*/
|
|
44
|
+
function checkType (customTypes, typeSpec, value) {
|
|
45
|
+
if (!typeSpec) // if there is no typespec to validate against, any value is ok
|
|
46
|
+
return true
|
|
47
|
+
|
|
48
|
+
const name = typeSpec.name || '';
|
|
49
|
+
|
|
50
|
+
// if type is a reference/custom, grab that type def but allow "optional" override - TODO: consider other overrides (perhaps all but "type"?)
|
|
51
|
+
if (customTypes && customTypes[typeSpec.type])
|
|
52
|
+
typeSpec = Object.assign({}, customTypes[typeSpec.type], typeSpec, { type: customTypes[typeSpec.type].type });
|
|
53
|
+
|
|
54
|
+
if (typeSpec.type === 'integer') {
|
|
55
|
+
if (typeof value === 'string')
|
|
56
|
+
value = parseInt(value, 10);
|
|
57
|
+
if (!Number.isInteger(value))
|
|
58
|
+
throw Error('expected integer argument for argument ' + sqStr(name) + ' but received ' + value)
|
|
59
|
+
checkMinMax(name, typeSpec, value);
|
|
60
|
+
} else
|
|
61
|
+
if (typeSpec.type === 'float') {
|
|
62
|
+
if (typeof value === 'string')
|
|
63
|
+
value = parseFloat(value);
|
|
64
|
+
if (!Number.isFinite(value))
|
|
65
|
+
throw Error('expected float argument for argument ' + sqStr(name) + ' but received \'' + value + '\'')
|
|
66
|
+
checkMinMax(name, typeSpec, value);
|
|
67
|
+
} else
|
|
68
|
+
if (typeSpec.type === 'string') {
|
|
69
|
+
if (typeof value !== 'string')
|
|
70
|
+
throw Error(`argument ${sqStr(name)} must be a string but is not (value: ${value})`)
|
|
71
|
+
if (typeSpec.minLength && value.length < typeSpec.minLength)
|
|
72
|
+
throw Error(`argument ${sqStr(name)} must be a at least ${typeSpec.minLength} characters but is '${value}' (${value.length} chars)`)
|
|
73
|
+
if (typeSpec.maxLength && value.length > typeSpec.maxLength)
|
|
74
|
+
throw Error(`argument ${sqStr(name)} must be a at most ${typeSpec.maxLength} characters but is '${value}' (${value.length} chars)`)
|
|
75
|
+
} else
|
|
76
|
+
if (typeSpec.type === 'boolean') {
|
|
77
|
+
if (value !== true && value !== false && value !== 'false' && value !== 'true' && value !== 'yes' && value !== 'no') { throw Error('argument ' + sqStr(name) + ' must be a boolean but is type ' + (typeof value) + ' with value of ' + value) }
|
|
78
|
+
} else
|
|
79
|
+
if (typeSpec.type === 'list') {
|
|
80
|
+
if (!Array.isArray(value))
|
|
81
|
+
throw Error('argument ' + sqStr(name) + ' must be a list but is not. Value = ' + value)
|
|
82
|
+
if (typeSpec.minLength !== undefined && typeSpec.minLength > value.length)
|
|
83
|
+
throw Error('argument ' + sqStr(name) + ' must contain at least ' + typeSpec.minLength + ' items but only contains ' + value.length + ' items')
|
|
84
|
+
if (typeSpec.maxLength !== undefined && typeSpec.maxLength < value.length)
|
|
85
|
+
throw Error('argument ' + sqStr(name) + ' must contain at most ' + typeSpec.maxLength + ' items but contains ' + value.length + ' items')
|
|
86
|
+
if (typeSpec.itemType) {
|
|
87
|
+
const allItemsValid = value.reduce(function (isValid, curItem) {
|
|
88
|
+
try {
|
|
89
|
+
checkType(customTypes, typeSpec.itemType, curItem);
|
|
90
|
+
} catch (e) { return false }
|
|
91
|
+
return isValid
|
|
92
|
+
}, true);
|
|
93
|
+
if (!allItemsValid) { throw Error(`argument ${sqStr(name)} contains an invalid item(s). All items in the list must be of type: ${JSON.stringify(typeSpec.itemType)} - list: ${JSON.stringify(value)}`) }
|
|
94
|
+
}
|
|
95
|
+
} else
|
|
96
|
+
if (typeSpec.type === 'object') {
|
|
97
|
+
if (typeof (value) !== 'object' || Array.isArray(value))
|
|
98
|
+
throw Error('argument ' + sqStr(name) + ' must be an object but is not. Value = ' + value)
|
|
99
|
+
try {
|
|
100
|
+
if (typeSpec.props)
|
|
101
|
+
checkTypeList(customTypes, typeSpec.props, value);
|
|
102
|
+
} catch (e) {
|
|
103
|
+
throw Error('Within ' + name + ', ' + e.message)
|
|
104
|
+
}
|
|
105
|
+
} else
|
|
106
|
+
if (typeSpec.type === 'multi') {
|
|
107
|
+
const oneTypeValid = typeSpec.types
|
|
108
|
+
.reduce((isValid, curType) => {
|
|
109
|
+
try {
|
|
110
|
+
checkType(customTypes, curType, value);
|
|
111
|
+
} catch (e) { return isValid }
|
|
112
|
+
return true
|
|
113
|
+
}, false);
|
|
114
|
+
if (!oneTypeValid)
|
|
115
|
+
throw Error(`Argument ${sqStr(name)} can be of several types, but is not valid for any: ${value}`)
|
|
116
|
+
} else
|
|
117
|
+
throw Error('type ' + typeSpec.type + ' is an unknown type')
|
|
118
|
+
|
|
119
|
+
return true
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Given a value and a typelist, ensure the value abides by the typelist
|
|
124
|
+
* @param types custom defined types
|
|
125
|
+
* @param typeList A list of types to check
|
|
126
|
+
* @param args The properties object to check against
|
|
127
|
+
*/
|
|
128
|
+
function checkTypeList (customTypes, typeList, args) {
|
|
129
|
+
typeList.forEach(nextType => {
|
|
130
|
+
if (args[nextType.name] !== undefined) { checkType(customTypes, nextType, args[nextType.name]); } else
|
|
131
|
+
if (!nextType.optional) { throw Error('you must include a value for ' + nextType.name) }
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
exports.checkType = checkType;
|
|
136
|
+
exports.checkTypeList = checkTypeList;
|
|
137
|
+
exports.getSigMatch = getSigMatch;
|
|
138
|
+
exports.validate = validate;
|
|
@@ -2,7 +2,94 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// Ported from https://github.com/JacksonTian/geohasher
|
|
6
|
+
// to ESM as it was not bundling properly via Rollup as a CJS
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
// Geohash library for Javascript
|
|
9
|
+
// (c) 2008 David Troy
|
|
10
|
+
// (c) 2010 Chris Williams
|
|
11
|
+
// (c) 2013 Jackson Tian
|
|
12
|
+
// Distributed under the MIT License
|
|
13
|
+
|
|
14
|
+
const BITS = [16, 8, 4, 2, 1];
|
|
15
|
+
|
|
16
|
+
const BASE32 = '0123456789bcdefghjkmnpqrstuvwxyz';
|
|
17
|
+
|
|
18
|
+
const NEIGHBORS = {
|
|
19
|
+
right: { even: 'bc01fg45238967deuvhjyznpkmstqrwx' },
|
|
20
|
+
left: { even: '238967debc01fg45kmstqrwxuvhjyznp' },
|
|
21
|
+
top: { even: 'p0r21436x8zb9dcf5h7kjnmqesgutwvy' },
|
|
22
|
+
bottom: { even: '14365h7k9dcfesgujnmqp0r2twvyx8zb' }
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const BORDERS = {
|
|
26
|
+
right: { even: 'bcfguvyz' },
|
|
27
|
+
left: { even: '0145hjnp' },
|
|
28
|
+
top: { even: 'prxz' },
|
|
29
|
+
bottom: { even: '028b' }
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
NEIGHBORS.bottom.odd = NEIGHBORS.left.even;
|
|
33
|
+
NEIGHBORS.top.odd = NEIGHBORS.right.even;
|
|
34
|
+
NEIGHBORS.left.odd = NEIGHBORS.bottom.even;
|
|
35
|
+
NEIGHBORS.right.odd = NEIGHBORS.top.even;
|
|
36
|
+
|
|
37
|
+
BORDERS.bottom.odd = BORDERS.left.even;
|
|
38
|
+
BORDERS.top.odd = BORDERS.right.even;
|
|
39
|
+
BORDERS.left.odd = BORDERS.bottom.even;
|
|
40
|
+
BORDERS.right.odd = BORDERS.top.even;
|
|
41
|
+
|
|
42
|
+
function calculateAdjacent (srcHash, dir) {
|
|
43
|
+
srcHash = srcHash.toLowerCase();
|
|
44
|
+
const lastChr = srcHash.charAt(srcHash.length - 1);
|
|
45
|
+
const type = (srcHash.length % 2) ? 'odd' : 'even';
|
|
46
|
+
let base = srcHash.substring(0, srcHash.length - 1);
|
|
47
|
+
if (BORDERS[dir][type].indexOf(lastChr) !== -1) {
|
|
48
|
+
base = calculateAdjacent(base, dir);
|
|
49
|
+
}
|
|
50
|
+
return base + BASE32[NEIGHBORS[dir][type].indexOf(lastChr)]
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function encode (latitude, longitude, precision) {
|
|
54
|
+
let isEven = 1;
|
|
55
|
+
const lat = [-90.0, 90.0];
|
|
56
|
+
const lng = [-180.0, 180.0];
|
|
57
|
+
let bit = 0;
|
|
58
|
+
let ch = 0;
|
|
59
|
+
precision = precision || 12;
|
|
60
|
+
|
|
61
|
+
let geohash = '';
|
|
62
|
+
while (geohash.length < precision) {
|
|
63
|
+
let mid;
|
|
64
|
+
if (isEven) {
|
|
65
|
+
mid = (lng[0] + lng[1]) / 2;
|
|
66
|
+
if (longitude > mid) {
|
|
67
|
+
ch |= BITS[bit];
|
|
68
|
+
lng[0] = mid;
|
|
69
|
+
} else {
|
|
70
|
+
lng[1] = mid;
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
mid = (lat[0] + lat[1]) / 2;
|
|
74
|
+
if (latitude > mid) {
|
|
75
|
+
ch |= BITS[bit];
|
|
76
|
+
lat[0] = mid;
|
|
77
|
+
} else {
|
|
78
|
+
lat[1] = mid;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
isEven = !isEven;
|
|
83
|
+
if (bit < 4) {
|
|
84
|
+
bit++;
|
|
85
|
+
} else {
|
|
86
|
+
geohash += BASE32[ch];
|
|
87
|
+
bit = 0;
|
|
88
|
+
ch = 0;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return geohash
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
exports.calculateAdjacent = calculateAdjacent;
|
|
95
|
+
exports.encode = encode;
|
|
@@ -2,6 +2,73 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
|
|
6
|
+
const nodeColorsOb = {
|
|
7
|
+
black: '\x1b[30m',
|
|
8
|
+
red: '\x1b[31m',
|
|
9
|
+
green: '\x1b[32m',
|
|
10
|
+
yellow: '\x1b[33m',
|
|
11
|
+
blue: '\x1b[34m',
|
|
12
|
+
magenta: '\x1b[35m',
|
|
13
|
+
cyan: '\x1b[36m',
|
|
14
|
+
white: '\x1b[37m'
|
|
15
|
+
};
|
|
6
16
|
|
|
7
|
-
|
|
17
|
+
function clog (name, options = { }) {
|
|
18
|
+
let prefix = name + ': ';
|
|
19
|
+
let style = null;
|
|
20
|
+
|
|
21
|
+
if (options.color)
|
|
22
|
+
if (options.isBrowser) {
|
|
23
|
+
prefix = '%c' + prefix;
|
|
24
|
+
style = `color: ${options.color}`;
|
|
25
|
+
} else {
|
|
26
|
+
const cstring = nodeColorsOb[options.color];
|
|
27
|
+
if (cstring)
|
|
28
|
+
prefix = cstring + prefix;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const trunc = (str, len) => str && str.length > len ? str.substring(0, len) + '...' : str;
|
|
32
|
+
const checkPassesFilter = (args, filter) => typeof filter === 'string'
|
|
33
|
+
? args[0].includes(filter)
|
|
34
|
+
: filter.test(args[0]);
|
|
35
|
+
|
|
36
|
+
function logGen (cmethod) {
|
|
37
|
+
return function () {
|
|
38
|
+
const isEnabled = options.enabled === undefined ? true : !!options.enabled;
|
|
39
|
+
if (isEnabled || cmethod === console.error) {
|
|
40
|
+
let args = Array.from(arguments);
|
|
41
|
+
if (style)
|
|
42
|
+
args.unshift(style);
|
|
43
|
+
args.unshift(prefix);
|
|
44
|
+
if (options.truncateObjects && cmethod !== console.error)
|
|
45
|
+
args = args.map(arg => {
|
|
46
|
+
if (typeof arg === 'object')
|
|
47
|
+
return trunc(JSON.stringify(arg), parseInt(options.truncateObjects) || 100)
|
|
48
|
+
return arg
|
|
49
|
+
});
|
|
50
|
+
const passesFilter = !options.logFilter || checkPassesFilter(args, options.logFilter);
|
|
51
|
+
if (passesFilter || cmethod === console.error)
|
|
52
|
+
cmethod.apply(console, args);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const log = logGen(console.log);
|
|
58
|
+
log.info = log;
|
|
59
|
+
log.warn = logGen(console.warn);
|
|
60
|
+
log.detailed = logGen(console.debug);
|
|
61
|
+
log.error = logGen(console.error);
|
|
62
|
+
|
|
63
|
+
log.setEnabled = e => { options.enabled = e; };
|
|
64
|
+
|
|
65
|
+
return log
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function initLog (name, options) {
|
|
69
|
+
const log = clog(name, options);
|
|
70
|
+
log.sublog = (sublogName, sublogOptions) => initLog(name + '.' + sublogName, Object.assign(Object.create(options), sublogOptions));
|
|
71
|
+
return log
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
exports.initLog = initLog;
|
|
@@ -2,6 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const initHistoryManager = ({ bus }) => {
|
|
6
|
+
const stepStack = [];
|
|
7
|
+
bus.on('history/register', ({ viewId, event, params = {} }) => {
|
|
8
|
+
stepStack.push({ viewId, event, params });
|
|
9
|
+
});
|
|
10
|
+
bus.on('history/stepBack', () => {
|
|
11
|
+
const layersToHide = [];
|
|
12
|
+
const current = stepStack.pop();
|
|
6
13
|
|
|
7
|
-
|
|
14
|
+
if (!current) return
|
|
15
|
+
|
|
16
|
+
layersToHide.push(current.viewId);
|
|
17
|
+
for (let i = stepStack.length - 1; i >= 0; --i) {
|
|
18
|
+
if (stepStack[i].event === current.event) {
|
|
19
|
+
const same = stepStack.pop();
|
|
20
|
+
layersToHide.push(same.viewId);
|
|
21
|
+
} else {
|
|
22
|
+
break
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
bus.send('layers/hideMultiple', layersToHide);
|
|
26
|
+
const { event, params } = stepStack.pop();
|
|
27
|
+
bus.send(event, params);
|
|
28
|
+
});
|
|
29
|
+
bus.on('history/clean', () => {
|
|
30
|
+
stepStack.length = 0;
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.initHistoryManager = initHistoryManager;
|
|
@@ -2,9 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var R = require('ramda');
|
|
6
6
|
|
|
7
|
-
function
|
|
7
|
+
function findBoundsOfWaypoints (waypoints) {
|
|
8
|
+
const latitudes = waypoints.map(R.path(['position', 'lat'])).filter(R.identity);
|
|
9
|
+
const longitudes = waypoints.map(R.path(['position', 'lng'])).filter(R.identity);
|
|
10
|
+
return findBounds(latitudes, longitudes)
|
|
11
|
+
}
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
function findBoundsOfCoordinates (coordinates) {
|
|
14
|
+
const latitudes = coordinates.map(R.prop(0)).filter(R.identity);
|
|
15
|
+
const longitudes = coordinates.map(R.prop(1)).filter(R.identity);
|
|
16
|
+
return findBounds(latitudes, longitudes)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function findBounds (latitudes, longitudes) {
|
|
20
|
+
const n = Math.max(...latitudes);
|
|
21
|
+
const s = Math.min(...latitudes);
|
|
22
|
+
const e = Math.max(...longitudes);
|
|
23
|
+
const w = Math.min(...longitudes);
|
|
24
|
+
return { n, s, e, w }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports.findBoundsOfCoordinates = findBoundsOfCoordinates;
|
|
28
|
+
exports.findBoundsOfWaypoints = findBoundsOfWaypoints;
|