-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(medusa, utils): rename buildLegacyFieldsListFrom to objectToStringPath #3738
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@medusajs/medusa": patch | ||
--- | ||
|
||
chore(medusa): rename buildLegacyFieldsListFrom to objectToStringPath |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { flatten, groupBy, map, merge } from "lodash" | ||
import { FindManyOptions, FindOptionsRelations, In } from "typeorm" | ||
import { Order } from "../models" | ||
import { buildLegacyFieldsListFrom } from "../utils" | ||
import { objectToStringPath } from "../utils" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. todo: Import from |
||
import { dataSource } from "../loaders/database" | ||
|
||
const ITEMS_REL_NAME = "items" | ||
|
@@ -16,7 +16,7 @@ export const OrderRepository = dataSource.getRepository(Order).extend({ | |
const entitiesIds = entities.map(({ id }) => id) | ||
|
||
const groupedRelations: { [topLevel: string]: string[] } = {} | ||
for (const rel of buildLegacyFieldsListFrom(relations)) { | ||
for (const rel of objectToStringPath(relations)) { | ||
const [topLevel] = rel.split(".") | ||
if (groupedRelations[topLevel]) { | ||
groupedRelations[topLevel].push(rel) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ import { | |
import { ProductCategory } from "../models/product-category" | ||
import { ExtendedFindConfig, QuerySelector } from "../types/common" | ||
import { dataSource } from "../loaders/database" | ||
import { buildLegacyFieldsListFrom } from "../utils" | ||
import { objectToStringPath } from "../utils" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. todo: Import from |
||
import { isEmpty } from "lodash" | ||
|
||
export const ProductCategoryRepository = dataSource | ||
|
@@ -44,8 +44,8 @@ export const ProductCategoryRepository = dataSource | |
const options_ = { ...options } | ||
options_.where = options_.where as FindOptionsWhere<ProductCategory> | ||
|
||
const legacySelect = buildLegacyFieldsListFrom(options_.select) | ||
const legacyRelations = buildLegacyFieldsListFrom(options_.relations) | ||
const legacySelect = objectToStringPath(options_.select) | ||
const legacyRelations = objectToStringPath(options_.relations) | ||
|
||
const selectStatements = (relationName: string): string[] => { | ||
const modelColumns = this.metadata.ownColumns.map( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ import { ExtendedFindConfig } from "../types/common" | |
import { dataSource } from "../loaders/database" | ||
import { ProductFilterOptions } from "../types/product" | ||
import { | ||
buildLegacyFieldsListFrom, | ||
objectToStringPath, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. todo: Import from |
||
isObject, | ||
fetchCategoryDescendantsIds, | ||
} from "../utils" | ||
|
@@ -89,7 +89,7 @@ export const ProductRepository = dataSource.getRepository(Product).extend({ | |
// https://github.com/typeorm/typeorm/issues/6294 | ||
// Cleanup the repo and fix order/skip/take and relation load strategy when those issues are resolved | ||
|
||
const orderFieldsCollectionPointSeparated = buildLegacyFieldsListFrom( | ||
const orderFieldsCollectionPointSeparated = objectToStringPath( | ||
options.order ?? {} | ||
) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ import { | |
} from "../models" | ||
import { TaxRateListByConfig } from "../types/tax-rate" | ||
import { isDefined } from "medusa-core-utils" | ||
import { buildLegacyFieldsListFrom } from "../utils" | ||
import { objectToStringPath } from "../utils" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. todo: Import from |
||
import { dataSource } from "../loaders/database" | ||
|
||
const resolveableFields = [ | ||
|
@@ -33,7 +33,7 @@ export const TaxRateRepository = dataSource.getRepository(TaxRate).extend({ | |
const resolverFields: string[] = [] | ||
if (isDefined(findOptions.select)) { | ||
const selectableCols: (keyof TaxRate)[] = [] | ||
const legacySelect = buildLegacyFieldsListFrom( | ||
const legacySelect = objectToStringPath( | ||
findOptions.select as FindOptionsSelect<TaxRate> | ||
) | ||
for (const k of legacySelect) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,7 +153,7 @@ function buildWhere<TWhereKeys extends object, TEntity>( | |
* output: ['test.test1', 'test.test2', 'test.test3.test4', 'test2'] | ||
* @param input | ||
*/ | ||
export function buildLegacyFieldsListFrom<TEntity>( | ||
export function objectToStringPath<TEntity>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Keep this and deprecate it to stay backward compatible. And change all occurrences to import from |
||
input: | ||
| FindOptionsWhere<TEntity> | ||
| FindOptionsSelect<TEntity> | ||
|
@@ -168,7 +168,7 @@ export function buildLegacyFieldsListFrom<TEntity>( | |
|
||
for (const key of Object.keys(input)) { | ||
if (input[key] != undefined && typeof input[key] === "object") { | ||
const deepRes = buildLegacyFieldsListFrom(input[key]) | ||
const deepRes = objectToStringPath(input[key]) | ||
|
||
const items = deepRes.reduce((acc, val) => { | ||
acc.push(`${key}.${val}`) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo: Import from
@medusajs/utils