Skip to content

Commit

Permalink
v1.2.0 - renamed stuff and added proper bindings api
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhail-barg committed Jan 20, 2022
1 parent 886d75c commit e487321
Show file tree
Hide file tree
Showing 18 changed files with 3,420 additions and 3,354 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ Debug.Assert(result.ToString(Formatting.None) == "\"b\"");

* `JsonataQuery` objects are immutable and therefore reusable and thread-safe.
* It is possible to provide additional variable bindings via `bindings` arg of `Eval()` call.
* Additional functional bindings are work in progress (*TODO*: functionality is same as for built-in function implementations, but need to provide user API)
* It is possible to provide additional functional bindings via `Eval(JToken data, EvaluationEnvironment environment)` call. See [example](src/TestApp/Program.cs)
* Functionality is same as for [built-in function implementations](src/Jsonata.Net.Native/Eval/BuiltinFunctions.cs)
* You may use a number of [argument attributes](src/Jsonata.Net.Native/Eval/Attributes.cs) to get fancy behavior if needed. Also refer to [built-in function implementations](src/Jsonata.Net.Native/Eval/BuiltinFunctions.cs)
* Error codes are mostly in sync with the [JS implementation](https://github.com/jsonata-js/jsonata/blob/65e854d6bfee1d1413ebff7f1a185834c6c42265/src/jsonata.js#L1919), but some checkup is to be done later (*TODO*).

We also provide an [Exerciser app](https://github.com/mikhail-barg/jsonata.net.native/tree/master/src/JsonataExerciser) with same functionality as in original [JSONata Exerciser](https://try.jsonata.org/):
Expand Down
6,298 changes: 3,149 additions & 3,149 deletions src/Jsonata.Net.Native.TestSuite/TestReport/Jsonata.Net.Native.TestSuite.xml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Jsonata.Net.Native/Eval/Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public OptionalArgumentAttribute(object? defaultValue)
}
}

//provides support for builtin functions that require EvaluationEnvironment
//provides support for builtin functions that require EvaluationSupplement
[AttributeUsage(AttributeTargets.Parameter)]
internal sealed class EvalEnvironmentArgumentAttribute : Attribute
internal sealed class EvalSupplementArgumentAttribute : Attribute
{
}

Expand Down
10 changes: 5 additions & 5 deletions src/Jsonata.Net.Native/Eval/BuiltinFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ public static string replace([PropagateUndefined] string str, JToken pattern, JT
{
FunctionToken replacementFunction = (FunctionToken)replacement;
StringBuilder builder = new StringBuilder();
Environment env = Environment.CreateEvalEnvironment(); //TODO: think of providing proper env. Maybe via a func param?
EvaluationEnvironment env = EvaluationEnvironment.CreateEvalEnvironment(EvaluationEnvironment.DefaultEnvironment); //TODO: think of providing proper env. Maybe via a func param?
int replacesCount = 0;
int replaceStartAt = 0;
foreach (Match match in matches)
Expand Down Expand Up @@ -905,7 +905,7 @@ public static double sqrt([AllowContextAsValue][PropagateUndefined] double numbe
Signature: $random()
Returns a pseudo random number greater than or equal to zero and less than one (0 ≤ n < 1)
*/
public static double random([EvalEnvironmentArgument] EvaluationEnvironment evalEnv)
public static double random([EvalSupplementArgument] EvaluationSupplement evalEnv)
{
return evalEnv.Random.NextDouble();
}
Expand Down Expand Up @@ -1356,7 +1356,7 @@ public static JArray reverse([PropagateUndefined] JToken arrayToken)
Signature: $shuffle(array)
Returns an array containing all the values from the array parameter, but shuffled into random order.
*/
public static JArray shuffle([PropagateUndefined] JToken arrayToken, [EvalEnvironmentArgument] EvaluationEnvironment evalEnv)
public static JArray shuffle([PropagateUndefined] JToken arrayToken, [EvalSupplementArgument] EvaluationSupplement evalEnv)
{
if (arrayToken.Type != JTokenType.Array)
{
Expand Down Expand Up @@ -1788,7 +1788,7 @@ public static string @type([PropagateUndefined] JToken value)
Generates a UTC timestamp in ISO 8601 compatible format and returns it as a string. All invocations of $now() within an evaluation of an expression will all return the same timestamp value.
If the optional picture and timezone parameters are supplied, then the current timestamp is formatted as described by the $fromMillis() function.
*/
public static string now([OptionalArgument(UTC_FORMAT)] string picture, [OptionalArgument(null)] string? timezone, [EvalEnvironmentArgument] EvaluationEnvironment evalEnv)
public static string now([OptionalArgument(UTC_FORMAT)] string picture, [OptionalArgument(null)] string? timezone, [EvalSupplementArgument] EvaluationSupplement evalEnv)
{
return fromMillis(millis(evalEnv), picture, timezone);
}
Expand All @@ -1799,7 +1799,7 @@ public static string now([OptionalArgument(UTC_FORMAT)] string picture, [Optiona
Returns the number of milliseconds since the Unix Epoch (1 January, 1970 UTC) as a number.
All invocations of $millis() within an evaluation of an expression will all return the same value.
*/
public static long millis([EvalEnvironmentArgument] EvaluationEnvironment evalEnv)
public static long millis([EvalSupplementArgument] EvaluationSupplement evalEnv)
{
return evalEnv.Now.ToUnixTimeMilliseconds();
}
Expand Down
99 changes: 0 additions & 99 deletions src/Jsonata.Net.Native/Eval/Environment.cs

This file was deleted.

Loading

0 comments on commit e487321

Please sign in to comment.