-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathutils.js
More file actions
26 lines (24 loc) · 882 Bytes
/
Copy pathutils.js
File metadata and controls
26 lines (24 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import _ from 'lodash';
/**
* Given optional and polymorphic arguments, return an object with a raw
* 'gremlin' string and optional 'bindings' object.
* When supplying a query object as first parameter, any bindings supplied
* as the last parameter will be shallow-merged.
*
* @param {String|Object|Function} rawScript
* @param {Object} rawBindings
* @return {Object}: { gremlin<String>, bindings<Object> }
*/
export function buildQueryFromSignature(rawScript = '', rawBindings) {
const { gremlin = rawScript, bindings = rawBindings } = rawScript;
return {
gremlin,
// Remap 'undefined' bindings as 'null' values that would otherwise
// result in missing/unbound variables in the Gremlin script execution
// context.
bindings: _.mapValues(
{ ...bindings, ...rawBindings },
value => (_.isUndefined(value) ? null : value),
),
};
}