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

feat: support casting of nested properties #252

Merged
merged 19 commits into from
Jan 25, 2024

Conversation

ThisIsDemetrio
Copy link
Collaborator

@ThisIsDemetrio ThisIsDemetrio commented Jan 19, 2024

Pull Request Type

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Description

This feature extend the support for casting values also for properties included in nested fields.

E.g., the query { 'obj.numericValue': '5' } will be translated to { 'obj.numericValue': 5 } if the collection definition includes the field numericValue and defines it a as a string.

To achieve this, the method getFieldDefinition have been improved to be recursive and recursive an object where the key will be the path of the nested field (the value will be its type - as defined in the colleciton definition). This function has been to a separate file (QueryParser.utils.js) for readibility. Tests have been included in a separate file (queryParser.utils.test.js).

Also, the function QueryParser.js#traverse has been refactored to improve clarity and handle correctly the case of nested fields.

In case a field of type object/array does not define its children fields, casting will not be applied but the query will work nonetheless. This causes also to allow queries using the dot notation (e.g. { 'obj.numericValue': 5 }) to be valid even if the field might not exist because of the schema (this might be different related to the previous behavior of the application since it was more strict in this sense).

PR Checklist

  • The commit message follows our guidelines included in the CONTRIBUTING.md
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@ThisIsDemetrio ThisIsDemetrio force-pushed the fix/cast-of-nested-properties-from-v6x branch from 0604185 to dd36cf2 Compare January 24, 2024 15:51
@danibix95 danibix95 merged commit 0b70d36 into v6.x Jan 25, 2024
9 checks passed
@danibix95 danibix95 deleted the fix/cast-of-nested-properties-from-v6x branch January 25, 2024 15:22
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.

2 participants