Releases: discoveryjs/jora
1.0.0-beta.3
- Improved
sort()
to be stable for mixed types (#17) - Added
ascN
anddescN
to define natural sorting functions - Added
ascA
anddescA
to define sorting functions with reverse order for numbers - Added
ascAN
anddescAN
to define natural sorting functions with reverse order for numbers h - Improved suggestion for pipeline operator in malformed query (tolerant mode)
- Added suggestion for object keys in array-like notation property accessor
- Renamed node type
Property
toObjectEntry
1.0.0-beta.2
- Fixed parse error handling
1.0.0-beta.1
- Added
[...expr]
syntax - Added
$$
root reference (arg1
), which refers to second parameter of closest function orundefined
when no such - Added
reduce()
method - Added support for methods as a reference to definition's value, i.e.
$method: => 123; $method() or path.$method()
- Added
walk()
method to traverse AST - Allowed numbers without integer part, i.e.
.123
or.5e-4
- Allowed numbers and literals as property name in object literals, i.e.
{ 1: 'ok', null: 'ok' }
- Changed
=
and!=
operators to useObject.is()
instead of===
and!==
operators - Changed behaviour for references to undefined definitions, now an exception raises in default mode, but no exceptions in tolerant mode
- Changed array-like access notation (i.e.
foo[expr]
) to behave likepick()
method - Reworked
pick()
method:- Return first entry value when no argument gived
- String values are treat as an array
- Added support for negative indicies for array and strings
- Return a value for object and function as reference, instead of entry
- Pass index or key to function reference as second parameter (can be accessed by
$$
) - When no arguments given or reference is
undefined
for object, return first entry value instead of value with keyundefined
- Cast boolean values to a number index when access to an array or string, i.e.
false
->0
andtrue
->1
- Improved tolerant mode to not fail on methods that doesn't exists, such invocations silently returns
undefined
- Improved parse and some compile errors
- Fixed suggestion in empty function body for new syntax, i.e.
group(=>)
will suggest between=>
and)
- Fixed
~=
operator to produce a boolean result only - Removed
mapToArray()
method, useentries().({ nameProp: key, ...value })
instead - Grand internal refactoring around AST processing:
- Parser generates less virtual nodes, so parse->stringify is much closer to original code (white spaces and comments mostly lost)
- Suggestion subsystem moved aside from parser to a separate module which uses in stat mode only
- Various fixes and improvements in suggestions
- The new approach allows to implement more complex suggestion scenarios like suggestions in array values for operators
in
,not in
,has
andhas no
which was added (e.g. in query["a", "b", 1, 2][$ in ["b", 2]]
jora will suggest only"a"
and1
values in array afterin
operator)
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
1.0.0-alpha.12
- Included build prerequisite files (
dist/parser.js
&dist/version.json
) in package
1.0.0-alpha.11
- Reworked parsing to produce AST, other parts reworked to consume AST as well
- Exposed
syntax
interface with 3 methods:parse(source, tolerantMode)
,compile(ast, suggestRanges, statMode)
andstringify(ast)
- Added slice notation like proposed for adding to JavaScript, e.g.
$str: '<foo>'; str[1:-1]
('foo'
) or$ar:[1,2,3,4,5,6]; $ar[-3::-1]
([6,5,4]
) (#11) - Added
slice(from, to)
method - Added
split(pattern)
method - Added
join(separator)
method - Added
match(pattern, matchAll)
method - Fixed method invocation on recursive mapping, i.e.
..method()
doesn't raise an error now and works as expected without surrounding parentheses (#10) - Allowed definitions to use in parentheses, e.g.
($a: 1; $a + $a)
- Added a function definition via
=>
, i.e.=> body
- Added sorting function definition with
asc
anddesc
keywords, e.g.sort(foo asc)
,$sorting: foo desc; sort($sorting)
orsort(foo desc, bar asc)
- Changed
sort()
method to use a two argument function as a regular comparator - Removed
::self
syntax, recursion with a function defined by a variable should be used instead
1.0.0-alpha.10
- Fixed arguments context suggestion for chained methods with no arguments
1.0.0-alpha.9
- Added support for numbers with exponent
- Added support for strings as property name in object literals
- Fixed edge cases with suggestions around keywords and inside functions
- Allowed
-
and+
operators to be unary - Renamed
get
buildin method tomap
- Changed
~=
operator to take any value as tester (not a regexp only); when value is a function it's behaves likefilter()
, whennull
orundefined
it's always truthy otherwise falsy - Changed
group()
method to group by an element when key value is an array
1.0.0-alpha.8
- Reworked tolerant parsing mode, less failures and better suggestions
- Reworked lib building, lib size reduced from 71Kb to 39Kb
- Fixed a function parsing, now it's greedy and a parentheses needed only around expressions with
>
operator when used outside braces, since>
will end a function definition (i.e.<a > 20>
causes to a parse error, but<(a > 20)>
or<foo.[a > 20]>
is not) - Allowed a block inside a function, i.e. function can be empty (returns a
current
in this case) and definitions are allowed in function's body - Added
has
andhas no
operators as inverse ofin
andnot in
- Fixed
and
andor
operators to evaluate left expression only once (good for performance and eliminates duplicates in suggestions)
1.0.0-alpha.7
- Disallowed a whitespace between a dot and a bracket in
.[
,.(
and..(
tokens - Changed filter (i.e.
.[]
or.filter()
) behaviour for a non-array value to return a value itself when expression is truthy orundefined
otherwise - Changed semanthic
jora(query, methods?, debug?)
->jora(query, options?)
whereoptions
is{ methods?, debug? }
- Added stat mode (turns on by
stat
option, i.e.jora(query, { stat: true })
) to return a query stat interface (an object withstat()
andsuggestion()
methods) instead of resulting data - Added tolerant parse mode (turns on by
tolerant
option, i.e.jora(query, { tolerant: true })
) to supress parsing errors when possible - Added library
version
to export - Fixed parser edge cases for division (
/
) and regexp