feat(index): Provide a similar API to Query (#9193)
**What**
Align the index engine API to be similar to the Query API
## Example
```ts
// Benefit from the same level of typing like the remote query
const { data, metadata } = await indexEngine.query<'product'>({
fields: [
"product.*",
"product.variants.*",
"product.variants.prices.*",
],
filters: {
product: {
variants: {
prices: {
amount: { $gt: 50 },
},
},
},
},
pagination: {
order: {
product: {
variants: {
prices: {
amount: "DESC",
},
},
},
},
},
})
```
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { flattenObjectKeys } from "../flatten-object-keys"
|
||||
|
||||
describe("flattenWhereClauses", () => {
|
||||
it("should flatten where clauses", () => {
|
||||
const where = {
|
||||
a: 1,
|
||||
b: {
|
||||
c: 2,
|
||||
d: 3,
|
||||
z: {
|
||||
$ilike: "%test%",
|
||||
},
|
||||
y: null,
|
||||
},
|
||||
e: 4,
|
||||
}
|
||||
|
||||
const result = flattenObjectKeys(where)
|
||||
|
||||
expect(result).toEqual({
|
||||
a: 1,
|
||||
"b.c": 2,
|
||||
"b.d": 3,
|
||||
"b.z": { $ilike: "%test%" },
|
||||
"b.y": null,
|
||||
e: 4,
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,22 @@
|
||||
import { normalizeFieldsSelection } from "../normalize-fields-selection"
|
||||
|
||||
describe("normalizeFieldsSelection", () => {
|
||||
it("should normalize fields selection", () => {
|
||||
const fields = [
|
||||
"product.id",
|
||||
"product.title",
|
||||
"product.variants.*",
|
||||
"product.variants.prices.*",
|
||||
]
|
||||
const result = normalizeFieldsSelection(fields)
|
||||
expect(result).toEqual({
|
||||
product: {
|
||||
id: true,
|
||||
title: true,
|
||||
variants: {
|
||||
prices: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user