From c71a06c87f1ff5949b601857a7bfdd6962c0c669 Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Wed, 8 May 2024 15:55:29 +0300 Subject: [PATCH] fix(medusa): import and use RequestQueryFields from types package (#7275) Noticed that `RequestQueryFields` is defined in both the `medusa` and `types` package. Within the `medusa` package sometimes it uses the local type definition or the definition in `types`. This PR removes the type definition of `RequestQueryFields` in `medusa` and uses that in `types` instead. --- .changeset/gorgeous-fireants-share.md | 5 +++ packages/core/types/src/common/common.ts | 5 ++- packages/medusa/src/types/common.ts | 31 ------------------- packages/medusa/src/types/global.ts | 4 +-- packages/medusa/src/utils/get-query-config.ts | 3 +- .../src/utils/middlewares/transform-query.ts | 3 +- 6 files changed, 15 insertions(+), 36 deletions(-) create mode 100644 .changeset/gorgeous-fireants-share.md diff --git a/.changeset/gorgeous-fireants-share.md b/.changeset/gorgeous-fireants-share.md new file mode 100644 index 0000000000..90fc9a4582 --- /dev/null +++ b/.changeset/gorgeous-fireants-share.md @@ -0,0 +1,5 @@ +--- +"@medusajs/medusa": patch +--- + +fix(medusa): import and use `RequestQueryFields` from types package diff --git a/packages/core/types/src/common/common.ts b/packages/core/types/src/common/common.ts index bc4b0b67ae..8d08135999 100644 --- a/packages/core/types/src/common/common.ts +++ b/packages/core/types/src/common/common.ts @@ -201,11 +201,14 @@ export type QueryConfig = { export type RequestQueryFields = { /** * Comma-separated relations that should be expanded in the returned data. + * @deprecated Use `fields` instead and the relations will be inferred */ expand?: string /** * Comma-separated fields that should be included in the returned data. + * if a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields. + * without prefix it will replace the entire default fields. */ fields?: string @@ -220,7 +223,7 @@ export type RequestQueryFields = { limit?: number /** - * Field to sort items in the list by. + * The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`. */ order?: string } diff --git a/packages/medusa/src/types/common.ts b/packages/medusa/src/types/common.ts index a6f859311c..ccab0a34c0 100644 --- a/packages/medusa/src/types/common.ts +++ b/packages/medusa/src/types/common.ts @@ -132,37 +132,6 @@ export type QueryConfig = { isList?: boolean } -/** - * @interface - * - * Request parameters used to configure and paginate retrieved data. - */ -export type RequestQueryFields = { - /** - * Comma-separated relations that should be expanded in the returned data. - * @deprecated Use `fields` instead and the relations will be inferred - */ - expand?: string - /** - * Comma-separated fields that should be included in the returned data. - * if a field is prefixed with `+` it will be added to the default fields, using `-` will remove it from the default fields. - * without prefix it will replace the entire default fields. - */ - fields?: string - /** - * The number of items to skip when retrieving a list. - */ - offset?: number - /** - * Limit the number of items returned in the list. - */ - limit?: number - /** - * The field to sort the data by. By default, the sort order is ascending. To change the order to descending, prefix the field name with `-`. - */ - order?: string -} - /** * @interface * diff --git a/packages/medusa/src/types/global.ts b/packages/medusa/src/types/global.ts index 45f5f83d93..659001a97e 100644 --- a/packages/medusa/src/types/global.ts +++ b/packages/medusa/src/types/global.ts @@ -1,7 +1,7 @@ -import { CommonTypes } from "@medusajs/types" +import { CommonTypes, RequestQueryFields } from "@medusajs/types" import { Request } from "express" import { MedusaContainer as coreMedusaContainer } from "medusa-core-utils" -import { FindConfig, RequestQueryFields } from "./common" +import { FindConfig } from "./common" declare global { // eslint-disable-next-line @typescript-eslint/no-namespace diff --git a/packages/medusa/src/utils/get-query-config.ts b/packages/medusa/src/utils/get-query-config.ts index 0258d23d77..a7b066e215 100644 --- a/packages/medusa/src/utils/get-query-config.ts +++ b/packages/medusa/src/utils/get-query-config.ts @@ -5,10 +5,11 @@ import { } from "@medusajs/utils" import { pick } from "lodash" import { MedusaError, isDefined } from "medusa-core-utils" +import { RequestQueryFields } from "@medusajs/types" import { BaseEntity } from "../interfaces" import { featureFlagRouter } from "../loaders/feature-flags" import MedusaV2 from "../loaders/feature-flags/medusa-v2" -import { FindConfig, QueryConfig, RequestQueryFields } from "../types/common" +import { FindConfig, QueryConfig } from "../types/common" export function pickByConfig( obj: TModel | TModel[], diff --git a/packages/medusa/src/utils/middlewares/transform-query.ts b/packages/medusa/src/utils/middlewares/transform-query.ts index ba5303a8c7..bf228a56fd 100644 --- a/packages/medusa/src/utils/middlewares/transform-query.ts +++ b/packages/medusa/src/utils/middlewares/transform-query.ts @@ -1,8 +1,9 @@ import { ValidatorOptions } from "class-validator" import { NextFunction, Request, Response } from "express" import { omit } from "lodash" +import { RequestQueryFields } from "@medusajs/types" import { BaseEntity } from "../../interfaces" -import { FindConfig, QueryConfig, RequestQueryFields } from "../../types/common" +import { FindConfig, QueryConfig } from "../../types/common" import { ClassConstructor } from "../../types/global" import { removeUndefinedProperties } from "../../utils" import {