Skip to content

This set of changes allows JSON Logic engine to more strictly honor s… #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 5, 2024

Conversation

TotalTechGeek
Copy link
Member

While the operators I implemented were compatible with the base spec, the interpreter was not implemented to actually sugar / desugar single arguments. In terms of compatibility, this has not created issues for anyone, but it was possible to add new operators that would not receive arrays as arguments.

I considered this to be a good thing / an option to be flexible, but with https://github.com/json-logic, I'd like to try to be more rigid with what I allow.

However, I've compromised by allowing users to add a flag to enable them to say optimizeUnary on an operator. This argument is used to signify "Hey, I support arrays, but I also support direct input if you want to invoke me with that". This allows my compiler & optimizer to avoid array destructuring overhead, which can actually have semi-significant impact (it did in the Handlebars JLE Library)

Because this change makes adding operators a bit more rigid, and semi-ensures that args will always be an array, I'm bumping the major version flag once more.

I've also changed the layout for some of my tests. Over time, I'm going to move more JSON files into the suites directory.

…ugaring in most methods.

While the operators I implemented were compatible with the base spec, the interpreter was not implemented to actually sugar / desugar single arguments. In terms of compatibility, this has not created issues for anyone, but it was possible to add new operators that would not receive arrays as arguments.

I considered this to be a good thing / an option to be flexible, but with https://github.com/json-logic, I'd like to try to be more rigid with what I allow.

However, I've compromised by allowing users to add a flag to enable them to say `optimizeUnary` on an operator. This argument is used to signify "Hey, I support arrays, but I also support direct input if you want to invoke me with that". This allows my compiler & optimizer to avoid array destructuring overhead, which can actually have semi-significant impact (it did in the Handlebars JLE Library)

Because this change makes adding operators a bit more rigid, and semi-ensures that args will always be an array, I'm bumping the major version flag once more.

I've also changed the layout for some of my tests. Over time, I'm going to move more JSON files into the `suites` directory.
@TotalTechGeek
Copy link
Member Author

Actually, to be clear, this does fix an issue w/r/t https://github.com/orgs/json-logic/discussions/2

So prior to this, { "max": 1 } would not be handled correctly, since it expected an array.

I could have tweaked the remaining operators, but it seemed smarter to aim for more rigid compliance.

@TotalTechGeek TotalTechGeek merged commit 06d0af9 into master Dec 5, 2024
6 of 7 checks passed
@TotalTechGeek TotalTechGeek deleted the fix/strictly-honor-sugaring branch December 5, 2024 02:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant