Files
medusa-store/packages/modules/index/src/utils/normalize-fields-selection.ts
Adrien de Peretti 3084008fc9 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",
                  },
                },
              },
            },
          },
        })
```
2024-09-20 10:02:42 +00:00

8 lines
280 B
TypeScript

import { objectFromStringPath } from "@medusajs/utils"
export function normalizeFieldsSelection(fields: string[]) {
const normalizedFields = fields.map((field) => field.replace(/\.\*/g, ""))
const fieldsObject = objectFromStringPath(normalizedFields)
return fieldsObject
}