breaking: remove deprecated commands and code (#9521)

* breaking: remove deprecated commands

* feat: remove deprecated code and usages

* refactor: remove more logic around default relations

* fix tests

* remove log

* fix: remove defaultFields usage

* fix: add back accidentally removed code

* refactor: implement feedback

* feat: add --cluster flag to the start command

* refactor: assign limit to defaultLimit property

* fix: breaking code because of removed check

---------

Co-authored-by: adrien2p <adrien.deperetti@gmail.com>
This commit is contained in:
Harminder Virk
2024-10-14 20:11:34 +05:30
committed by GitHub
co-authored by adrien2p
parent cea4cdc8d7
commit ad322f2760
37 changed files with 162 additions and 679 deletions
@@ -256,15 +256,6 @@ export type ProjectConfigOptions = {
*/
databaseLogging?: boolean
/**
* @ignore
* @deprecated
*
* @privateRemarks
* only postgres is supported, so this config has no effect
*/
databaseType?: string
/**
* This configuration is used to pass additional options to the database connection. You can pass any configuration. For example, pass the
* `ssl` property that enables support for TLS/SSL connections.
@@ -391,19 +382,6 @@ export type ProjectConfigOptions = {
*/
sessionOptions?: SessionOptions
/**
* This property configures the HTTP compression from the application layer. If you have access to the HTTP server, the recommended approach would be to enable it there.
* However, some platforms don't offer access to the HTTP layer and in those cases, this is a good alternative.
*
* If you enable HTTP compression and you want to disable it for specific API Routes, you can pass in the request header `"x-no-compression": true`.
*
* @ignore
*
* @deprecated use {@link http }'s `compression` property instead.
*
*/
httpCompression?: HttpCompressionOptions
/**
* Configure the number of staged jobs that are polled from the database. Default is `1000`.
*
@@ -1,7 +1,7 @@
import z from "zod"
import { MedusaError } from "@medusajs/utils"
import { validateAndTransformQuery } from "../utils/validate-query"
import { MedusaRequest, MedusaResponse, MedusaNextFunction } from "../types"
import { MedusaNextFunction, MedusaRequest, MedusaResponse } from "../types"
export const createSelectParams = () => {
return z.object({
@@ -124,7 +124,7 @@ describe("validateAndTransformQuery", () => {
}
let queryConfig: any = {
defaultFields: [
defaults: [
"id",
"created_at",
"updated_at",
@@ -134,12 +134,6 @@ describe("validateAndTransformQuery", () => {
"metadata.children.id",
"metadata.product.id",
],
defaultRelations: [
"metadata",
"metadata.parent",
"metadata.children",
"metadata.product",
],
isList: true,
}
@@ -216,7 +210,7 @@ describe("validateAndTransformQuery", () => {
const nextFunction: MedusaNextFunction = jest.fn()
let queryConfig: any = {
defaultFields: [
defaults: [
"id",
"created_at",
"updated_at",
@@ -226,12 +220,6 @@ describe("validateAndTransformQuery", () => {
"metadata.children.id",
"metadata.product.id",
],
defaultRelations: [
"metadata",
"metadata.parent",
"metadata.children",
"metadata.product",
],
isList: true,
}
@@ -252,7 +240,7 @@ describe("validateAndTransformQuery", () => {
} as unknown as MedusaRequest
queryConfig = {
defaultFields: [
defaults: [
"id",
"prop-test-something",
"created_at",
@@ -263,12 +251,6 @@ describe("validateAndTransformQuery", () => {
"metadata.children.id",
"metadata.product.id",
],
defaultRelations: [
"metadata",
"metadata.parent",
"metadata.children",
"metadata.product",
],
isList: true,
}
@@ -415,7 +397,7 @@ describe("validateAndTransformQuery", () => {
} as unknown as MedusaRequest
queryConfig = {
defaultFields: [
defaults: [
"id",
"created_at",
"deleted_at",
@@ -467,7 +449,7 @@ describe("validateAndTransformQuery", () => {
const nextFunction: MedusaNextFunction = jest.fn()
let queryConfig: any = {
defaultFields: [
defaults: [
"id",
"created_at",
"updated_at",
@@ -514,7 +496,7 @@ describe("validateAndTransformQuery", () => {
} as unknown as MedusaRequest
queryConfig = {
defaultFields: [
defaults: [
"id",
"created_at",
"updated_at",
@@ -561,7 +543,7 @@ describe("validateAndTransformQuery", () => {
} as unknown as MedusaRequest
queryConfig = {
defaultFields: [
defaults: [
"id",
"created_at",
"deleted_at",
+2 -7
View File
@@ -123,15 +123,10 @@ export interface MedusaRequest<Body = unknown>
*/
filterableFields: Record<string, unknown>
includes?: Record<string, boolean>
/**
* An array of fields and relations that are allowed to be queried, this can be set by the
* consumer as part of a middleware and it will take precedence over the defaultAllowedFields
* @deprecated use `allowed` instead
*/
allowedFields?: string[]
/**
* An array of fields and relations that are allowed to be queried, this can be set by the
* consumer as part of a middleware and it will take precedence over the defaultAllowedFields set
* consumer as part of a middleware and it will take precedence over the req.allowed set
* by the api
*/
allowed?: string[]
@@ -4,7 +4,6 @@ import {
isDefined,
isPresent,
MedusaError,
getSetDifference,
stringToSelectRelationObject,
} from "@medusajs/utils"
@@ -28,28 +27,15 @@ export function prepareListQuery<T extends RequestQueryFields, TEntity>(
validated: T,
queryConfig: QueryConfig<TEntity> = {}
) {
// TODO: this function will be simplified a lot once we drop support for the old api
const { order, fields, limit = 50, expand, offset = 0 } = validated
let {
allowed = [],
defaults = [],
defaultFields = [],
defaultLimit,
allowedFields = [],
allowedRelations = [],
defaultRelations = [],
isList,
} = queryConfig
allowedFields = allowed.length ? allowed : allowedFields
defaultFields = defaults.length ? defaults : defaultFields
let { allowed = [], defaults = [], defaultLimit = 50, isList } = queryConfig
const { order, fields, limit = defaultLimit, offset = 0 } = validated
// e.g *product.variants meaning that we want all fields from the product.variants
// in that case it wont be part of the select but it will be part of the relations.
// For the remote query we will have to add the fields to the fields array as product.variants.*
const starFields: Set<string> = new Set()
let allFields = new Set(defaultFields) as Set<string>
let allFields = new Set(defaults) as Set<string>
if (isDefined(fields)) {
const customFields = fields.split(",").filter(Boolean)
@@ -90,9 +76,9 @@ export function prepareListQuery<T extends RequestQueryFields, TEntity>(
const notAllowedFields: string[] = []
if (allowedFields.length) {
if (allowed.length) {
;[...allFields, ...Array.from(starFields)].forEach((field) => {
const hasAllowedField = allowedFields.includes(field)
const hasAllowedField = allowed.includes(field)
if (hasAllowedField) {
return
@@ -108,7 +94,7 @@ export function prepareListQuery<T extends RequestQueryFields, TEntity>(
return
}
const fieldStartsWithAllowedField = allowedFields.some((allowedField) =>
const fieldStartsWithAllowedField = allowed.some((allowedField) =>
field.startsWith(allowedField)
)
@@ -133,33 +119,8 @@ export function prepareListQuery<T extends RequestQueryFields, TEntity>(
Array.from(allFields)
)
let allRelations = new Set([
...relations,
...defaultRelations,
...Array.from(starFields),
])
let allRelations = new Set([...relations, ...Array.from(starFields)])
if (isDefined(expand)) {
allRelations = new Set(expand.split(",").filter(Boolean))
}
if (allowedRelations.length && expand) {
const allAllowedRelations = new Set([...allowedRelations])
const notAllowedRelations = getSetDifference(
allRelations,
allAllowedRelations
)
if (allRelations.size && notAllowedRelations.size) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
`Requested fields [${Array.from(notAllowedRelations).join(
", "
)}] are not valid`
)
}
}
// End of expand compatibility
let orderBy: { [k: symbol]: "DESC" | "ASC" } | undefined = {}
@@ -173,10 +134,7 @@ export function prepareListQuery<T extends RequestQueryFields, TEntity>(
orderBy = { [order]: "ASC" }
}
if (
queryConfig?.allowedFields?.length &&
!queryConfig?.allowedFields.includes(orderField)
) {
if (allowed.length && !allowed.includes(orderField)) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
`Order field ${orderField} is not valid`
@@ -190,7 +148,7 @@ export function prepareListQuery<T extends RequestQueryFields, TEntity>(
select: select.length ? select : undefined,
relations: Array.from(allRelations),
skip: offset,
take: limit ?? defaultLimit,
take: limit,
order: finalOrder,
},
remoteQueryConfig: {
@@ -202,7 +160,7 @@ export function prepareListQuery<T extends RequestQueryFields, TEntity>(
pagination: isList
? {
skip: offset,
take: limit ?? defaultLimit,
take: limit,
order: finalOrder,
}
: {},
@@ -1,7 +1,7 @@
import { z } from "zod"
import { omit } from "lodash"
import { NextFunction } from "express"
import { removeUndefinedProperties, MedusaError } from "@medusajs/utils"
import { MedusaError, removeUndefinedProperties } from "@medusajs/utils"
import { BaseEntity, QueryConfig, RequestQueryFields } from "@medusajs/types"
import { zodValidator } from "../../zod/zod-helpers"