Skip to content

Releases: discoveryjs/jora

1.0.0-beta.3

20 Sep 14:18
Compare
Choose a tag to compare
  • Improved sort() to be stable for mixed types (#17)
  • Added ascN and descN to define natural sorting functions
  • Added ascA and descA to define sorting functions with reverse order for numbers
  • Added ascAN and descAN 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 to ObjectEntry

1.0.0-beta.2

17 May 11:11
Compare
Choose a tag to compare
  • Fixed parse error handling

1.0.0-beta.1

14 May 13:11
Compare
Choose a tag to compare
  • Added [...expr] syntax
  • Added $$ root reference (arg1), which refers to second parameter of closest function or undefined 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 use Object.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 like pick() 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 key undefined
    • Cast boolean values to a number index when access to an array or string, i.e. false -> 0 and true -> 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, use entries().({ 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 and has no which was added (e.g. in query ["a", "b", 1, 2][$ in ["b", 2]] jora will suggest only "a" and 1 values in array after in operator)

1.0.0-alpha.13 Pipeline operator and build improvements

06 Jan 21:38
Compare
Choose a tag to compare

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

1.0.0-alpha.12

18 Dec 22:30
Compare
Choose a tag to compare
  • Included build prerequisite files (dist/parser.js & dist/version.json) in package

1.0.0-alpha.11

17 Dec 22:45
Compare
Choose a tag to compare
  • 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) and stringify(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 and desc keywords, e.g. sort(foo asc), $sorting: foo desc; sort($sorting) or sort(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

18 Jun 11:45
Compare
Choose a tag to compare
  • Fixed arguments context suggestion for chained methods with no arguments

1.0.0-alpha.9

05 Mar 09:36
Compare
Choose a tag to compare
  • 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 to map
  • Changed ~= operator to take any value as tester (not a regexp only); when value is a function it's behaves like filter(), when null or undefined 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

07 Feb 11:37
Compare
Choose a tag to compare
  • 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 and has no operators as inverse of in and not in
  • Fixed and and or operators to evaluate left expression only once (good for performance and eliminates duplicates in suggestions)

1.0.0-alpha.7

07 Feb 11:40
Compare
Choose a tag to compare
  • 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 or undefined otherwise
  • Changed semanthic jora(query, methods?, debug?) -> jora(query, options?) where options 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 with stat() and suggestion() 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