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:
1 parent
cea4cdc8d7
commit
ad322f2760
37 files changed
+162
-679
No files matched your search
@@ -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",
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -119,12 +119,6 @@ export type TotalField =
|
||||
* Fields that can be passed in the query parameters of a request.
|
||||
*/
|
||||
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.
|
||||
@@ -309,26 +303,10 @@ export type QueryConfig<TEntity> = {
|
||||
* Default fields and relations to return
|
||||
*/
|
||||
defaults?: (keyof TEntity | string)[]
|
||||
/**
|
||||
* @deprecated Use `defaults` instead
|
||||
*/
|
||||
defaultFields?: (keyof TEntity | string)[]
|
||||
/**
|
||||
* @deprecated Use `defaultFields` instead and the relations will be inferred
|
||||
*/
|
||||
defaultRelations?: string[]
|
||||
/**
|
||||
* Fields and relations that are allowed to be requested
|
||||
*/
|
||||
allowed?: string[]
|
||||
/**
|
||||
* @deprecated Use `allowed` instead
|
||||
*/
|
||||
allowedFields?: string[]
|
||||
/**
|
||||
* @deprecated Use `allowedFields` instead and the relations will be inferred
|
||||
*/
|
||||
allowedRelations?: string[]
|
||||
defaultLimit?: number
|
||||
isList?: boolean
|
||||
}
|
||||
|
||||
@@ -265,15 +265,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.
|
||||
@@ -400,19 +391,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,23 +1,6 @@
|
||||
import { EventBusTypes } from "./bundles"
|
||||
import { Message } from "./event-bus"
|
||||
|
||||
/**
|
||||
* @deprecated use `Context` instead
|
||||
* @interface
|
||||
*
|
||||
* A context used to share resources, such as transaction manager, between the application and the module.
|
||||
*/
|
||||
export type SharedContext = {
|
||||
/**
|
||||
* An instance of a transaction manager.
|
||||
*/
|
||||
transactionManager?: any
|
||||
/**
|
||||
* An instance of an entity manager.
|
||||
*/
|
||||
manager?: any
|
||||
}
|
||||
|
||||
export interface MessageAggregatorFormat {
|
||||
groupBy?: string[]
|
||||
sortBy?: { [key: string]: string[] | string | number }
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
export * as ApiKeyUtils from "./api-key"
|
||||
export * as CoreFlowsUitls from "./core-flows"
|
||||
export * as DALUtils from "./dal"
|
||||
export * as DecoratorUtils from "./decorators"
|
||||
export * as DefaultsUtils from "./defaults"
|
||||
export * as DMLUtils from "./dml"
|
||||
export * as EventBusUtils from "./event-bus"
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export * from "./inject-entity-manager"
|
||||
@@ -1,50 +0,0 @@
|
||||
import { Context, SharedContext } from "@medusajs/types"
|
||||
import { MedusaContextType } from "../modules-sdk/decorators"
|
||||
|
||||
// @deprecated Use InjectManager instead
|
||||
export function InjectEntityManager(
|
||||
shouldForceTransaction: (target: any) => boolean = () => false,
|
||||
managerProperty: string | false = "manager_"
|
||||
): MethodDecorator {
|
||||
return function (
|
||||
target: any,
|
||||
propertyKey: string | symbol,
|
||||
descriptor: any
|
||||
): void {
|
||||
if (!target.MedusaContextIndex_) {
|
||||
throw new Error(
|
||||
`To apply @InjectEntityManager you have to flag a parameter using @MedusaContext`
|
||||
)
|
||||
}
|
||||
|
||||
const originalMethod = descriptor.value
|
||||
|
||||
const argIndex = target.MedusaContextIndex_[propertyKey]
|
||||
descriptor.value = async function (...args: any[]) {
|
||||
const shouldForceTransactionRes = shouldForceTransaction(target)
|
||||
const context: SharedContext | Context = args[argIndex] ?? {}
|
||||
|
||||
if (!shouldForceTransactionRes && context?.transactionManager) {
|
||||
return await originalMethod.apply(this, args)
|
||||
}
|
||||
|
||||
return await (managerProperty === false
|
||||
? this
|
||||
: this[managerProperty]
|
||||
).transaction(
|
||||
async (transactionManager) => {
|
||||
args[argIndex] = args[argIndex] ?? { __type: MedusaContextType }
|
||||
args[argIndex].transactionManager = transactionManager
|
||||
|
||||
return await originalMethod.apply(this, args)
|
||||
},
|
||||
{
|
||||
transaction: context?.transactionManager,
|
||||
isolationLevel: (context as Context)?.isolationLevel,
|
||||
enableNestedTransactions:
|
||||
(context as Context).enableNestedTransactions ?? false,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ export * from "./bundles"
|
||||
export * from "./common"
|
||||
export * from "./core-flows"
|
||||
export * from "./dal"
|
||||
export * from "./decorators"
|
||||
export * from "./defaults"
|
||||
export * from "./dml"
|
||||
export * from "./event-bus"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Context, SharedContext } from "@medusajs/types"
|
||||
import { Context } from "@medusajs/types"
|
||||
import { MedusaContextType } from "./context-parameter"
|
||||
|
||||
export function InjectSharedContext(): MethodDecorator {
|
||||
@@ -17,7 +17,7 @@ export function InjectSharedContext(): MethodDecorator {
|
||||
const argIndex = target.MedusaContextIndex_[propertyKey]
|
||||
|
||||
descriptor.value = function (...args: any[]) {
|
||||
const context: SharedContext | Context = {
|
||||
const context: Context = {
|
||||
...(args[argIndex] ?? { __type: MedusaContextType }),
|
||||
}
|
||||
args[argIndex] = context
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Context, EventBusTypes } from "@medusajs/types"
|
||||
import { buildModuleResourceEventName } from "../event-bus"
|
||||
import { buildModuleResourceEventName } from "../event-bus/utils"
|
||||
|
||||
// TODO should that move closer to the event bus? and maybe be rename to modulemoduleEventBuilderFactory
|
||||
|
||||
@@ -28,16 +28,11 @@ import { buildModuleResourceEventName } from "../event-bus"
|
||||
export function moduleEventBuilderFactory({
|
||||
action,
|
||||
object,
|
||||
eventsEnum,
|
||||
eventName,
|
||||
source,
|
||||
}: {
|
||||
action: string
|
||||
object: string
|
||||
/**
|
||||
* @deprecated use eventName instead
|
||||
*/
|
||||
eventsEnum?: Record<string, string>
|
||||
eventName?: string
|
||||
source: string
|
||||
}) {
|
||||
@@ -57,14 +52,8 @@ export function moduleEventBuilderFactory({
|
||||
const aggregator = sharedContext.messageAggregator!
|
||||
const messages: EventBusTypes.RawMessageFormat[] = []
|
||||
|
||||
// The event enums contains event formatted like so [object]_[action] e.g. PRODUCT_CREATED
|
||||
// We expect the keys of events to be fully uppercased
|
||||
let eventName_ = eventsEnum
|
||||
? eventsEnum[`${object.toUpperCase()}_${action.toUpperCase()}`]
|
||||
: eventName
|
||||
|
||||
if (!eventName_) {
|
||||
eventName_ = buildModuleResourceEventName({
|
||||
if (!eventName) {
|
||||
eventName = buildModuleResourceEventName({
|
||||
prefix: source,
|
||||
objectName: object,
|
||||
action,
|
||||
@@ -77,7 +66,7 @@ export function moduleEventBuilderFactory({
|
||||
action,
|
||||
context: sharedContext,
|
||||
data: { id: dataItem.id },
|
||||
eventName: eventName_,
|
||||
eventName: eventName!,
|
||||
object,
|
||||
})
|
||||
})
|
||||
|
||||
@@ -25,16 +25,6 @@ export type ModelDTOConfig = {
|
||||
model?: DmlEntity<any, any>
|
||||
create?: any
|
||||
update?: any
|
||||
/**
|
||||
* @internal
|
||||
* @deprecated
|
||||
*/
|
||||
singular?: string
|
||||
/**
|
||||
* @internal
|
||||
* @deprecated
|
||||
*/
|
||||
plural?: string
|
||||
}
|
||||
|
||||
export type ModelsConfigTemplate = { [key: string]: ModelDTOConfig }
|
||||
@@ -51,21 +41,6 @@ export type ModelConfigurationsToConfigTemplate<T extends ModelEntries> = {
|
||||
: T[Key] extends IDmlEntity<any, any>
|
||||
? T[Key]
|
||||
: never
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
create: any
|
||||
update: any
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
singular: T[Key] extends { singular: string } ? T[Key]["singular"] : Key
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
plural: T[Key] extends { plural: string }
|
||||
? T[Key]["plural"]
|
||||
: Pluralize<Key & string>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user