Skip to content
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

Improve Permissive Implementation; Allows Data Detection Override #29

Merged
merged 2 commits into from
Mar 19, 2024

Conversation

TotalTechGeek
Copy link
Owner

Based on the discussion in #28, I decided to improve how the Permissive implementation is handled to allow users to better customize how the data detection is implemented.

I do realize that as I add these capabilities, we might be making it slightly more difficult to maintain a fully compatible cross-language json-logic ecosystem, however, I'm comfortable supporting some of these extensions as long as it is clear to folks that these behaviors might not translate to other libraries by other authors.

Anyway:

I've changed the engine implementation to allow a user to specify how "data" is detected in one's logic.

class DataEngine extends LogicEngine {
  isData (logic, firstKey) {
    if (Object.keys(logic).length > 1) return true
    return !(firstKey in this.methods)
  }
}

You can extend logic engine and implement an isData method to specify if an object embedded in the logic should be treated as data, rather than treating it as a command.

This should give developers full flexibility in how they believe this should work, as there will be different opinions:

  • "Could it work via attaching a symbol to the object?"
  • "Could it treat it as data if it has more than 1 key?"
  • "Could it treat it as data if the function isn't recognized?"

Etc.

@TotalTechGeek TotalTechGeek merged commit 4fcbe2e into master Mar 19, 2024
3 checks passed
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.

None yet

1 participant