Add undocumented/private API to hook into when a new frame is created.#701
Merged
mattbaileyuk merged 1 commit intojsonata-js:masterfrom Nov 28, 2024
Merged
Conversation
This is helpful in scenarios where you wish to debug the environment behavior, or modify the env for advanced scenarios. As the callback is set via a Symbol, it can not be manipulated or read inside a query. See jsonata-js/jsonata/jsonata-js#700.
andrew-coleman
approved these changes
Nov 26, 2024
Member
andrew-coleman
left a comment
There was a problem hiding this comment.
Looks good to me, I think. @mattbaileyuk are you happy with this?
shivanshu-netomi
approved these changes
Nov 28, 2024
Member
|
All looks good, including the protection around its use, so will merge this 👍 |
Member
|
Realised that didn't actually run through the checks; usually get an option on the merge to kick them off if they're initiated from a fork. Thankfully all looks good: https://github.com/jsonata-js/jsonata/actions/runs/12076711571/job/33678469127 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a small change to add a new hook, similar to
__evaluate_entryand__evaluate_exit, but for when a new frame is created from an old one. I am building an open-source pluggable framework around JSonata, and this small change will open up an enormous amount of awesome possibilities.It is beneficial for advanced cases like modifying env with additional metadata or mutating it so that you can analyse bind/lookup calls & provide diagnostics. I have actually patially achieved this already to significant effect by hooking into the env on
__evaluate_entry. However, in some cases inside the JSONata core, a new frame is created, which is then immediately bound to, and consequently that happens before it has yet to recurse throughevaluateand the entry callback. That means that callback is unable to capture everything for these advance pro-mode use cases. This new callback would enable that possibility.I accept this will be undocumented and could change in the future.
The callback is set via a
Symbol, so it can not be manipulated or read inside a query. See #700, which would need to be merged first, both as approval of the generalSymbolapproach and because the minor TS def changes are needed from there.Signed-off-by: Adam Thomas adam@adam-thomas.co.uk