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
@@ -20,7 +20,7 @@ export const defaultAdminDetailsClaimFields = [
|
||||
]
|
||||
|
||||
export const retrieveTransformQueryConfig = {
|
||||
defaultFields: defaultAdminDetailsClaimFields,
|
||||
defaults: defaultAdminDetailsClaimFields,
|
||||
isList: false,
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ export const defaultAdminDetailsExchangeFields = [
|
||||
]
|
||||
|
||||
export const retrieveTransformQueryConfig = {
|
||||
defaultFields: defaultAdminDetailsExchangeFields,
|
||||
defaults: defaultAdminDetailsExchangeFields,
|
||||
isList: false,
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ export const defaultAdminDetailsOrderEditFields = [
|
||||
]
|
||||
|
||||
export const retrieveTransformQueryConfig = {
|
||||
defaultFields: defaultAdminDetailsOrderEditFields,
|
||||
defaults: defaultAdminDetailsOrderEditFields,
|
||||
isList: false,
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ export const defaultAdminRetrieveOrderChangesFields = [
|
||||
]
|
||||
|
||||
export const retrieveTransformQueryConfig = {
|
||||
defaultFields: defaultAdminRetrieveOrderFields,
|
||||
defaults: defaultAdminRetrieveOrderFields,
|
||||
isList: false,
|
||||
}
|
||||
|
||||
@@ -93,6 +93,6 @@ export const listTransformQueryConfig = {
|
||||
}
|
||||
|
||||
export const retrieveOrderChangesTransformQueryConfig = {
|
||||
defaultFields: defaultAdminRetrieveOrderChangesFields,
|
||||
defaults: defaultAdminRetrieveOrderChangesFields,
|
||||
isList: false,
|
||||
}
|
||||
@@ -12,7 +12,7 @@ export const defaultAdminRetrieveRefundReasonFields = [
|
||||
]
|
||||
|
||||
export const retrieveTransformQueryConfig = {
|
||||
defaultFields: defaultAdminRetrieveRefundReasonFields,
|
||||
defaults: defaultAdminRetrieveRefundReasonFields,
|
||||
isList: false,
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ export const defaultAdminRetrieveReturnReasonFields = [
|
||||
]
|
||||
|
||||
export const retrieveTransformQueryConfig = {
|
||||
defaultFields: defaultAdminRetrieveReturnReasonFields,
|
||||
defaults: defaultAdminRetrieveReturnReasonFields,
|
||||
isList: false,
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ export const defaultAdminDetailsReturnFields = [
|
||||
]
|
||||
|
||||
export const retrieveTransformQueryConfig = {
|
||||
defaultFields: defaultAdminDetailsReturnFields,
|
||||
defaults: defaultAdminDetailsReturnFields,
|
||||
isList: false,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export const defaultAdminUploadFields = ["id", "url"]
|
||||
|
||||
export const retrieveUploadConfig = {
|
||||
defaultFields: defaultAdminUploadFields,
|
||||
defaults: defaultAdminUploadFields,
|
||||
isList: false,
|
||||
}
|
||||
@@ -12,7 +12,7 @@ export const defaultStoreRetrieveReturnReasonFields = [
|
||||
]
|
||||
|
||||
export const retrieveTransformQueryConfig = {
|
||||
defaultFields: defaultStoreRetrieveReturnReasonFields,
|
||||
defaults: defaultStoreRetrieveReturnReasonFields,
|
||||
isList: false,
|
||||
}
|
||||
|
||||
|
||||
@@ -25,22 +25,6 @@ export const BigNumberInput = z.union([
|
||||
}),
|
||||
])
|
||||
|
||||
const optionalBooleanMapper = new Map([
|
||||
["undefined", undefined],
|
||||
["null", null],
|
||||
["true", true],
|
||||
["false", false],
|
||||
])
|
||||
|
||||
/**
|
||||
* @deprecated Use `booleanString` instead
|
||||
* It support the chainable API of zod. Please note it does not come with `.optional()` by default
|
||||
*/
|
||||
export const OptionalBooleanValidator = z.preprocess(
|
||||
(val: any) => optionalBooleanMapper.get(val?.toLowerCase()),
|
||||
z.boolean().optional()
|
||||
)
|
||||
|
||||
/**
|
||||
* Validates that a value is a boolean when it is passed as a string.
|
||||
*/
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
export { default as exec } from "./exec"
|
||||
export { default as user } from "./user"
|
||||
export { default as start } from "./start"
|
||||
export { default as build } from "./build"
|
||||
export { default as develop } from "./develop"
|
||||
export { default as exec } from "./exec"
|
||||
export { default as links } from "./links"
|
||||
export { default as migrate } from "./migrate"
|
||||
export { default as start } from "./start"
|
||||
export { default as startCluster } from "./start-cluster"
|
||||
export { default as user } from "./user"
|
||||
@@ -1,10 +0,0 @@
|
||||
import syncLinksCmd from "./db/sync-links"
|
||||
|
||||
const main = async function (argv) {
|
||||
if (argv.action !== "sync") {
|
||||
return process.exit()
|
||||
}
|
||||
await syncLinksCmd(argv)
|
||||
}
|
||||
|
||||
export default main
|
||||
@@ -1,117 +0,0 @@
|
||||
import { LinkLoader } from "@medusajs/framework/links"
|
||||
import { logger } from "@medusajs/framework/logger"
|
||||
import { MedusaAppLoader } from "@medusajs/framework"
|
||||
import { initializeContainer } from "../loaders"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
MedusaError,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { getResolvedPlugins } from "../loaders/helpers/resolve-plugins"
|
||||
import { join } from "path"
|
||||
|
||||
const TERMINAL_SIZE = process.stdout.columns
|
||||
|
||||
type Action = "run" | "revert" | "generate" | "show"
|
||||
|
||||
function validateInputArgs({
|
||||
action,
|
||||
modules,
|
||||
}: {
|
||||
action: Action
|
||||
modules: string[]
|
||||
}) {
|
||||
const actionsRequiringModules = ["revert", "generate"]
|
||||
|
||||
if (modules.length && !actionsRequiringModules.includes(action)) {
|
||||
logger.error(
|
||||
`<modules> cannot be specified with the "${action}" action. Please remove the <modules> argument and try again.`
|
||||
)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
if (!modules.length && actionsRequiringModules.includes(action)) {
|
||||
logger.error(
|
||||
"Please provide the modules for which you want to revert migrations"
|
||||
)
|
||||
logger.error(`For example: "npx medusa migration revert <moduleName>"`)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
const main = async function ({ directory }) {
|
||||
const args = process.argv
|
||||
args.shift()
|
||||
args.shift()
|
||||
args.shift()
|
||||
|
||||
const action = args[0] as Action
|
||||
const modules = args.splice(1)
|
||||
|
||||
validateInputArgs({ action, modules })
|
||||
|
||||
const container = await initializeContainer(directory)
|
||||
|
||||
const configModule = container.resolve(
|
||||
ContainerRegistrationKeys.CONFIG_MODULE
|
||||
)
|
||||
|
||||
const medusaAppLoader = new MedusaAppLoader()
|
||||
|
||||
const plugins = getResolvedPlugins(directory, configModule, true) || []
|
||||
const linksSourcePaths = plugins.map((plugin) =>
|
||||
join(plugin.resolve, "links")
|
||||
)
|
||||
await new LinkLoader(linksSourcePaths).load()
|
||||
|
||||
if (action === "run") {
|
||||
logger.info("Running migrations...")
|
||||
|
||||
await medusaAppLoader.runModulesMigrations({
|
||||
action: "run",
|
||||
})
|
||||
|
||||
console.log(new Array(TERMINAL_SIZE).join("-"))
|
||||
logger.info("Migrations completed")
|
||||
process.exit()
|
||||
} else if (action === "revert") {
|
||||
logger.info("Reverting migrations...")
|
||||
|
||||
try {
|
||||
await medusaAppLoader.runModulesMigrations({
|
||||
moduleNames: modules,
|
||||
action: "revert",
|
||||
})
|
||||
console.log(new Array(TERMINAL_SIZE).join("-"))
|
||||
logger.info("Migrations reverted")
|
||||
process.exit()
|
||||
} catch (error) {
|
||||
console.log(new Array(TERMINAL_SIZE).join("-"))
|
||||
if (error.code && error.code === MedusaError.Codes.UNKNOWN_MODULES) {
|
||||
logger.error(error.message)
|
||||
const modulesList = error.allModules.map(
|
||||
(name: string) => ` - ${name}`
|
||||
)
|
||||
logger.error(`Available modules:\n${modulesList.join("\n")}`)
|
||||
} else {
|
||||
logger.error(error.message, error)
|
||||
}
|
||||
process.exit(1)
|
||||
}
|
||||
} else if (action === "generate") {
|
||||
logger.info("Generating migrations...")
|
||||
|
||||
await medusaAppLoader.runModulesMigrations({
|
||||
moduleNames: modules,
|
||||
action: "generate",
|
||||
})
|
||||
|
||||
console.log(new Array(TERMINAL_SIZE).join("-"))
|
||||
logger.info("Migrations generated")
|
||||
process.exit()
|
||||
} else if (action === "show") {
|
||||
logger.info("Action not supported yet")
|
||||
process.exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
export default main
|
||||
@@ -1,92 +0,0 @@
|
||||
import cluster from "cluster"
|
||||
import express from "express"
|
||||
import { track } from "medusa-telemetry"
|
||||
import { scheduleJob } from "node-schedule"
|
||||
import os from "os"
|
||||
|
||||
import { logger } from "@medusajs/framework/logger"
|
||||
import { GracefulShutdownServer, isPresent } from "@medusajs/framework/utils"
|
||||
import loaders from "../loaders"
|
||||
|
||||
const EVERY_SIXTH_HOUR = "0 */6 * * *"
|
||||
const CRON_SCHEDULE = EVERY_SIXTH_HOUR
|
||||
|
||||
let isShuttingDown = false
|
||||
export default async function ({ port, cpus, directory }) {
|
||||
if (cluster.isPrimary) {
|
||||
const killMainProccess = () => process.exit(0)
|
||||
|
||||
cpus ??= os.cpus().length
|
||||
const numCPUs = Math.min(os.cpus().length, cpus)
|
||||
|
||||
for (let index = 0; index < numCPUs; index++) {
|
||||
const worker = cluster.fork()
|
||||
worker.send({ index })
|
||||
}
|
||||
|
||||
cluster.on("exit", (worker) => {
|
||||
if (!isShuttingDown) {
|
||||
cluster.fork()
|
||||
} else if (!isPresent(cluster.workers)) {
|
||||
setTimeout(killMainProccess, 100)
|
||||
}
|
||||
})
|
||||
|
||||
const gracefulShutDown = () => {
|
||||
isShuttingDown = true
|
||||
for (const id of Object.keys(cluster.workers ?? {})) {
|
||||
cluster.workers?.[id]?.kill("SIGTERM")
|
||||
}
|
||||
}
|
||||
|
||||
scheduleJob(CRON_SCHEDULE, () => {
|
||||
track("PING")
|
||||
})
|
||||
|
||||
process.on("SIGTERM", gracefulShutDown)
|
||||
process.on("SIGINT", gracefulShutDown)
|
||||
} else {
|
||||
const start = async () => {
|
||||
track("CLI_START")
|
||||
|
||||
const app = express()
|
||||
|
||||
const { shutdown } = await loaders({
|
||||
directory,
|
||||
expressApp: app,
|
||||
})
|
||||
const serverActivity = logger.activity(`Creating server`)
|
||||
const server = GracefulShutdownServer.create(
|
||||
app.listen(port).on("listening", () => {
|
||||
logger.success(serverActivity, `Server is ready on port: ${port}`)
|
||||
track("CLI_START_COMPLETED")
|
||||
})
|
||||
)
|
||||
|
||||
const gracefulShutDown = () => {
|
||||
server
|
||||
.shutdown()
|
||||
.then(async () => {
|
||||
await shutdown()
|
||||
process.exit(0)
|
||||
})
|
||||
.catch((e) => {
|
||||
process.exit(1)
|
||||
})
|
||||
}
|
||||
|
||||
process.on("SIGTERM", gracefulShutDown)
|
||||
process.on("SIGINT", gracefulShutDown)
|
||||
|
||||
return { server }
|
||||
}
|
||||
|
||||
process.on("message", async (msg: any) => {
|
||||
if (msg.index > 0) {
|
||||
process.env.PLUGIN_ADMIN_UI_SKIP_CACHE = "true"
|
||||
}
|
||||
|
||||
await start()
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,18 @@
|
||||
import os from "os"
|
||||
import path from "path"
|
||||
import http from "http"
|
||||
import express from "express"
|
||||
import cluster from "cluster"
|
||||
import { track } from "medusa-telemetry"
|
||||
import { scheduleJob } from "node-schedule"
|
||||
|
||||
import {
|
||||
dynamicImport,
|
||||
isPresent,
|
||||
FileSystem,
|
||||
gqlSchemaToTypes,
|
||||
GracefulShutdownServer,
|
||||
} from "@medusajs/framework/utils"
|
||||
import http from "http"
|
||||
import { logger } from "@medusajs/framework/logger"
|
||||
|
||||
import loaders from "../loaders"
|
||||
@@ -54,8 +57,14 @@ export async function registerInstrumentation(directory: string) {
|
||||
// eslint-disable-next-line no-var
|
||||
export var traceRequestHandler: (...args: any[]) => Promise<any> = void 0 as any
|
||||
|
||||
async function start({ port, directory, types }) {
|
||||
async function internalStart() {
|
||||
async function start(args: {
|
||||
directory: string
|
||||
port?: number
|
||||
types?: boolean
|
||||
cluster?: number
|
||||
}) {
|
||||
const { port, directory, types } = args
|
||||
async function internalStart(generateTypes: boolean) {
|
||||
track("CLI_START")
|
||||
await registerInstrumentation(directory)
|
||||
|
||||
@@ -84,7 +93,7 @@ async function start({ port, directory, types }) {
|
||||
expressApp: app,
|
||||
})
|
||||
|
||||
if (gqlSchema && types) {
|
||||
if (gqlSchema && generateTypes) {
|
||||
const outputDirGeneratedTypes = path.join(directory, ".medusa/types")
|
||||
await gqlSchemaToTypes({
|
||||
outputDir: outputDirGeneratedTypes,
|
||||
@@ -93,7 +102,7 @@ async function start({ port, directory, types }) {
|
||||
schema: gqlSchema,
|
||||
joinerConfigs: MedusaModule.getAllJoinerConfigs(),
|
||||
})
|
||||
logger.info("Geneated modules types")
|
||||
logger.info("Generated modules types")
|
||||
}
|
||||
|
||||
const serverActivity = logger.activity(`Creating server`)
|
||||
@@ -133,7 +142,54 @@ async function start({ port, directory, types }) {
|
||||
}
|
||||
}
|
||||
|
||||
await internalStart()
|
||||
/**
|
||||
* When the cluster flag is used we will start the process in
|
||||
* cluster mode
|
||||
*/
|
||||
if ("cluster" in args) {
|
||||
const maxCpus = os.cpus().length
|
||||
const cpus = args.cluster ?? maxCpus
|
||||
|
||||
if (cluster.isPrimary) {
|
||||
let isShuttingDown = false
|
||||
const numCPUs = Math.min(maxCpus, cpus)
|
||||
const killMainProccess = () => process.exit(0)
|
||||
const gracefulShutDown = () => {
|
||||
isShuttingDown = true
|
||||
for (const id of Object.keys(cluster.workers ?? {})) {
|
||||
cluster.workers?.[id]?.kill("SIGTERM")
|
||||
}
|
||||
}
|
||||
|
||||
for (let index = 0; index < numCPUs; index++) {
|
||||
cluster.fork().send({ index })
|
||||
}
|
||||
|
||||
cluster.on("exit", () => {
|
||||
if (!isShuttingDown) {
|
||||
cluster.fork()
|
||||
} else if (!isPresent(cluster.workers)) {
|
||||
setTimeout(killMainProccess, 100)
|
||||
}
|
||||
})
|
||||
|
||||
process.on("SIGTERM", gracefulShutDown)
|
||||
process.on("SIGINT", gracefulShutDown)
|
||||
} else {
|
||||
process.on("message", async (msg: any) => {
|
||||
if (msg.index > 0) {
|
||||
process.env.PLUGIN_ADMIN_UI_SKIP_CACHE = "true"
|
||||
}
|
||||
|
||||
await internalStart(!!types && msg.index === 0)
|
||||
})
|
||||
}
|
||||
} else {
|
||||
/**
|
||||
* Not in cluster mode
|
||||
*/
|
||||
await internalStart(!!types)
|
||||
}
|
||||
}
|
||||
|
||||
export default start
|
||||
@@ -40,12 +40,6 @@ declare global {
|
||||
*/
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user