54 lines
998 B
JavaScript
54 lines
998 B
JavaScript
export function buildTraversal(path, value) {
|
|
const traversal = {
|
|
type: 'traversal',
|
|
steps: path.map((key) => {
|
|
return {
|
|
type: 'key',
|
|
key: key,
|
|
};
|
|
}),
|
|
};
|
|
if ('undefined' !== typeof value) {
|
|
traversal.value = buildValue(value);
|
|
}
|
|
return traversal;
|
|
}
|
|
|
|
export function buildInvoke (path, args = []) {
|
|
const traversal = buildTraversal(path);
|
|
traversal.steps.push({
|
|
type: 'invoke',
|
|
args: args.map((arg) => {
|
|
return buildValue(arg);
|
|
}),
|
|
});
|
|
return traversal;
|
|
}
|
|
|
|
export function buildValue(value) {
|
|
if (
|
|
'object' === typeof value
|
|
&& (
|
|
'traversal' === value.type
|
|
|| 'actions' === value.type
|
|
|| 'condition' === value.type
|
|
)
|
|
) {
|
|
return value;
|
|
}
|
|
return {
|
|
type: 'literal',
|
|
value,
|
|
};
|
|
}
|
|
|
|
export function buildCondition(operator, operands) {
|
|
return {
|
|
type: 'condition',
|
|
operator,
|
|
operands: operands.map((operand) => {
|
|
return buildValue(operand);
|
|
}),
|
|
};
|
|
}
|