Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tintinthong committed Nov 4, 2024
1 parent 148551a commit 7888d80
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/runtime-common/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,12 @@ function assertRangeFilter(
});
}

// This is a helper function to remove brackets from keys in a query object returned by qs.parse.
// For example, qs.parse consumes stringified search query and returns a query object with key '[author.firstName]; we should get 'author.firstName' instead
// Our search index doesn't account for path segments which are wrapped in brackets so we need to remove them.
const removeBrackets = (obj: any): any => {
if (!obj || typeof obj !== 'object') return obj;

// Handle arrays
if (Array.isArray(obj)) {
return obj.map((item) => removeBrackets(item));
}
Expand All @@ -432,14 +434,11 @@ const removeBrackets = (obj: any): any => {
// Remove surrounding brackets if they exist
const newKey = key.replace(/^\[(.*)\]$/, '$1');

// Handle arrays in values
if (Array.isArray(value)) {
acc[newKey] = value.map((item) => removeBrackets(item));
} else if (typeof value === 'object' && value !== null) {
// Recursively removeBrackets nested objects
acc[newKey] = removeBrackets(value);
} else {
// Handle primitive values
acc[newKey] = value;
}

Expand Down

0 comments on commit 7888d80

Please sign in to comment.