Skip to content

Commit

Permalink
feat: support queries on nested array objects without the use of wild… (
Browse files Browse the repository at this point in the history
#24)

* feat: support queries on nested array objects without the use of wildcard
  • Loading branch information
oxdev03 authored Jul 27, 2024
1 parent e79e4af commit f1ac9c4
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 135 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ The following Lucene features are not currently supported but may be added in th

The following filters are not yet supported:

- Iterating over Array Object key without index like (e.g., `field.key_in_array`, working `field.*.key_in_array`)
- ~~Iterating over Array Object key without index like (e.g., `field.key_in_array`, working `field.*.key_in_array`)~~

## Contributing

Expand Down
236 changes: 120 additions & 116 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 29 additions & 3 deletions src/tests/utils/iterate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@ describe('iterate', () => {
`);
});

it.todo('should handle array elements as objects', () => {
it('should handle array elements as objects', () => {
const arrayObj = {
arr: [{ key: 'value1' }, { key: 'value2' }, { key2: 'value3' }],
};
const result = [...iterate(arrayObj, 'arr.*.key')];
const alternativeResult = [...iterate(arrayObj, 'arr.key')];
expect(result).toMatchInlineSnapshot(`
expect(alternativeResult).toMatchInlineSnapshot(`
[
[
"arr.0.key",
Expand All @@ -236,7 +236,33 @@ describe('iterate', () => {
],
]
`);
// FIXME: able to access array keys without *

expect(alternativeResult).toEqual(result);
});

it('should handle array elements as objects with nested array objects', () => {
const arrayObj = {
arr: [
{
key: [
{
foo: 'bar',
},
],
},
],
};
const alternativeResult = [...iterate(arrayObj, 'arr.key.foo')];
const result = [...iterate(arrayObj, 'arr.*.key.*.foo')];
expect(alternativeResult).toMatchInlineSnapshot(`
[
[
"arr.0.key.0.foo",
"bar",
],
]
`);

expect(alternativeResult).toEqual(result);
});

Expand Down
Loading

0 comments on commit f1ac9c4

Please sign in to comment.