2021-08-19 19:11:37 +03:00
|
|
|
# []
|
|
|
|
def _query_array:
|
|
|
|
{
|
|
|
|
term: {
|
|
|
|
type: "TermTypeArray",
|
|
|
|
array: {
|
|
|
|
query: .
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
# a() -> b()
|
2021-09-04 01:54:51 +03:00
|
|
|
def _query_func_rename(name):
|
|
|
|
.term.func.name = name;
|
2021-08-19 19:11:37 +03:00
|
|
|
|
|
|
|
# . | r
|
|
|
|
def _query_pipe(r):
|
|
|
|
{ op: "|",
|
|
|
|
left: .,
|
|
|
|
right: r
|
|
|
|
};
|
|
|
|
|
|
|
|
def _query_ident: {term: {type: "TermTypeIdentity"}};
|
|
|
|
|
|
|
|
# .[]
|
|
|
|
def _query_iter:
|
|
|
|
{ "term": {
|
|
|
|
"suffix_list": [{
|
|
|
|
"iter": true
|
|
|
|
}],
|
|
|
|
"type": "TermTypeIdentity"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-09-05 14:04:58 +03:00
|
|
|
def _query_func($name; $args):
|
|
|
|
{
|
|
|
|
"term": {
|
|
|
|
"func": {
|
|
|
|
"args": $args,
|
|
|
|
"name": $name
|
|
|
|
},
|
|
|
|
"type": "TermTypeFunc"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
def _query_func($name):
|
|
|
|
_query_func($name; null);
|
|
|
|
|
2021-09-04 01:54:51 +03:00
|
|
|
def _query_is_func(name):
|
|
|
|
.term.func.name == name;
|
|
|
|
|
2021-08-19 19:11:37 +03:00
|
|
|
# last query in pipeline
|
|
|
|
def _query_pipe_last:
|
2021-09-04 01:54:51 +03:00
|
|
|
if .term.suffix_list then
|
|
|
|
( .term.suffix_list[-1]
|
|
|
|
| if .bind.body then
|
|
|
|
( .bind.body
|
|
|
|
| _query_pipe_last
|
2021-08-19 19:11:37 +03:00
|
|
|
)
|
|
|
|
end
|
|
|
|
)
|
2021-09-04 01:54:51 +03:00
|
|
|
elif .op == "|" then
|
|
|
|
( .right
|
|
|
|
| _query_pipe_last
|
|
|
|
)
|
2021-08-19 19:11:37 +03:00
|
|
|
end;
|
|
|
|
|
2021-09-04 01:54:51 +03:00
|
|
|
def _query_transform_last(f):
|
2021-08-19 19:11:37 +03:00
|
|
|
def _f:
|
|
|
|
if .term.suffix_list then
|
|
|
|
.term.suffix_list[-1] |=
|
2021-09-04 01:54:51 +03:00
|
|
|
if .bind.body then
|
|
|
|
.bind.body |= _f
|
2021-08-19 19:11:37 +03:00
|
|
|
else f
|
|
|
|
end
|
2021-09-04 01:54:51 +03:00
|
|
|
elif .op == "|" then
|
|
|
|
.right |= _f
|
2021-08-19 19:11:37 +03:00
|
|
|
else f
|
|
|
|
end;
|
|
|
|
_f;
|
|
|
|
|
2021-09-05 14:04:58 +03:00
|
|
|
# <filter...> | <slurp_func> -> map(<filter...> | .) | (<slurp_func> | f)
|
2021-08-19 19:11:37 +03:00
|
|
|
def _query_slurp_wrap(f):
|
2021-09-05 14:04:58 +03:00
|
|
|
# save and move directives to new root query
|
2021-09-04 01:54:51 +03:00
|
|
|
( . as {$meta, $imports}
|
|
|
|
| del(.meta)
|
|
|
|
| del(.imports)
|
|
|
|
| _query_pipe_last as $lq
|
|
|
|
| _query_transform_last(_query_ident) as $pipe
|
2021-09-05 14:04:58 +03:00
|
|
|
| _query_func("map"; [$pipe])
|
2021-08-19 19:11:37 +03:00
|
|
|
| _query_pipe($lq | f)
|
2021-09-04 01:54:51 +03:00
|
|
|
| .meta = $meta
|
|
|
|
| .imports = $imports
|
2021-08-19 19:11:37 +03:00
|
|
|
);
|