feat(medusa): Rollout index engine behind feature flag (#11431)
**What** - Add index engine feature flag - apply it to the `store/products` end point as well as `admin/products` - Query builder various fixes - search capabilities on full data of every entities. The `q` search will be applied to all involved joined table for selection/where clauses Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
3b69f5a105
commit
448dbcb596
@@ -0,0 +1,45 @@
|
||||
import { unflattenObjectKeys } from "../unflatten-object-keys"
|
||||
|
||||
describe("unflattenWhereClauses", () => {
|
||||
it("should unflatten where clauses", () => {
|
||||
const where = {
|
||||
"variants.sku": { $like: "%-1" },
|
||||
"variants.prices.amount": { $gt: 30 },
|
||||
"variants.prices.currency_code": "USD",
|
||||
variants: {
|
||||
prices: {
|
||||
something: "else",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const result = unflattenObjectKeys(where)
|
||||
|
||||
expect(result).toEqual({
|
||||
variants: {
|
||||
prices: {
|
||||
something: "else",
|
||||
amount: {
|
||||
$gt: 30,
|
||||
},
|
||||
currency_code: "USD",
|
||||
},
|
||||
sku: {
|
||||
$like: "%-1",
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it("should unflatten obj", () => {
|
||||
const where = {
|
||||
created_at: "ASC",
|
||||
}
|
||||
|
||||
const result = unflattenObjectKeys(where)
|
||||
|
||||
expect(result).toEqual({
|
||||
created_at: "ASC",
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -46,6 +46,8 @@ export * from "./load-env"
|
||||
export * from "./lower-case-first"
|
||||
export * from "./map-object-to"
|
||||
export * from "./medusa-container"
|
||||
export * from "./merge-metadata"
|
||||
export * from "./merge-plugin-modules"
|
||||
export * from "./normalize-import-path-with-source"
|
||||
export * from "./object-from-string-path"
|
||||
export * from "./object-to-string-path"
|
||||
@@ -76,10 +78,9 @@ export * from "./to-camel-case"
|
||||
export * from "./to-handle"
|
||||
export * from "./to-kebab-case"
|
||||
export * from "./to-pascal-case"
|
||||
export * from "./to-unix-slash"
|
||||
export * from "./trim-zeros"
|
||||
export * from "./unflatten-object-keys"
|
||||
export * from "./upper-case-first"
|
||||
export * from "./validate-handle"
|
||||
export * from "./wrap-handler"
|
||||
export * from "./merge-plugin-modules"
|
||||
export * from "./to-unix-slash"
|
||||
export * from "./merge-metadata"
|
||||
68
packages/core/utils/src/common/unflatten-object-keys.ts
Normal file
68
packages/core/utils/src/common/unflatten-object-keys.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { isObject } from "./is-object"
|
||||
|
||||
/**
|
||||
* unFlatten object keys
|
||||
* @example
|
||||
* input: {
|
||||
* "variants.sku": { $like: "%-1" },
|
||||
* "variants.prices.amount": { $gt: 30 },
|
||||
* "variants.prices.currency": "USD"
|
||||
* }
|
||||
*
|
||||
* output: {
|
||||
* {
|
||||
* "variants": {
|
||||
* "sku": {
|
||||
* "$like": "%-1"
|
||||
* },
|
||||
* "prices": {
|
||||
* "amount": {
|
||||
* "$gt": 30
|
||||
* },
|
||||
* "currency": "USD"
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* @param input
|
||||
*/
|
||||
export function unflattenObjectKeys(
|
||||
flattened: Record<string, any>
|
||||
): Record<string, any> {
|
||||
const result: Record<string, any> = {}
|
||||
|
||||
for (const key in flattened) {
|
||||
if (!key.includes(".")) {
|
||||
if (isObject(result[key])) {
|
||||
result[key] = { ...result[key], ...flattened[key] }
|
||||
} else {
|
||||
result[key] = flattened[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const key in flattened) {
|
||||
if (key.includes(".")) {
|
||||
const value = flattened[key]
|
||||
const keys = key.split(".")
|
||||
let current = result
|
||||
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const part = keys[i]
|
||||
|
||||
if (i === keys.length - 1) {
|
||||
if (isObject(value) && current[part]) {
|
||||
current[part] = { ...current[part], ...value }
|
||||
} else {
|
||||
current[part] = value
|
||||
}
|
||||
} else {
|
||||
current = current[part] = current[part] ?? {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user