1.0.0-alpha.13 Pipeline operator and build improvements
Pipeline operator
This release introduces pipeline operator |
(vertical bar), that can be used to chain queries:
foo.bar | size() + baz.smth() | qux
It needed to simplify making subquery for a query. For example, if we need to get a subquery size() + bar.smth()
from a foo.bar
, we may express it as foo.bar | size() + bar.smth()
which means the same as (foo.bar).(size() + bar.smth())
.
However, this operator is much useful when a query value needs to be converted to a scalar. For example, we need to produce an object from an array. We can't use mapping for that, i.e. [1,2,3].({ sum: sum(), size: size() })
, since it will map each element of array to an object. A single possible workaround is to use a variable:
$ar: [1,2,3]; { sum: $ar.sum(), size: $ar.size() }
It works, but using the pipeline operator we may avoid any variables:
[1,2,3] | { sum: sum(), size: size() }
It also can be used to simplify expressions avoiding mapping:
{ foo: ..., bar: ... }.(foo + bar)
// ->
{ foo: ..., bar: ... } | foo + bar
or reduce repetitions:
$a.bar + $a.baz
// ->
$a | bar + baz
Pipeline operator produces a regular query, so it may be used in any place where a query is applicable, e.g.
query.({
foo: $ | { ... },
baz: $baz | a + b
}) | foo * bar
Is't also possible to define variables on pipeline chunk (except first one), right after |
:
query | $a: expr1; $b: expr2; $a.foo + bar.[baz=$b]
All changes
- Added pipeline operator, i.e.
foo | bar | ...
- Added
fromEntries()
method - Allowed parent's scope variables overlapping, i.e.
$a;.($a; ...)
doesn't throw with an error now - Added support for a function as
debug
option value, i.e.query('...', { debug: (name, value) => /* ... */ })
- Disallowed whitespace between
$
and identifier, previously$foo
can be used as$ foo
, now it throws with a parse error - Reworked build setup:
- Added baking of
src/parser.js
before publishing, i.e. replace a runtime parser compilation with a pre-compiled version - Moved
jison
to dev dependencies, and package has no dependencies anymore (dev only) - Removed
dist/parser.js
&dist/version.json
from package
- Added baking of