Skip to content
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: Rename config properties to camelCase #7498

Merged
merged 5 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion integration-tests/api/__tests__/database/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("Database options", () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({
cwd,
database_extra: { idle_in_transaction_session_timeout: 1000 },
databaseExtra: { idle_in_transaction_session_timeout: 1000 },
})
medusaProcess = await setupServer({ cwd })
})
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/api/medusa-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ module.exports = {
disable: true,
},
projectConfig: {
redis_url: redisUrl,
database_url: DB_URL,
database_type: "postgres",
redisUrl: redisUrl,
databaseUrl: DB_URL,
databaseType: "postgres",
http: {
compression: {
enabled: enableResponseCompression,
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/environment-helpers/use-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const instance = DbTestUtil
module.exports = {
initDb: async function ({
cwd,
database_extra,
databaseExtra,
env,
force_modules_migration,
}) {
Expand Down Expand Up @@ -145,7 +145,7 @@ module.exports = {
url: DB_URL,
entities: enabledEntities.concat(moduleModels),
migrations: enabledMigrations.concat(moduleMigrations),
extra: database_extra ?? {},
extra: databaseExtra ?? {},
name: "integration-tests",
})

Expand Down
4 changes: 2 additions & 2 deletions integration-tests/modules/medusa-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ module.exports = {
},
plugins: [],
projectConfig: {
database_url: DB_URL,
database_type: "postgres",
databaseUrl: DB_URL,
databaseType: "postgres",
http: {
jwtSecret: "test",
cookieSecret: "test",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/medusa-test-utils/src/medusa-test-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ export function medusaIntegrationTestRunner({
rootDirectory: string
) => {
const config = originalConfigLoader(rootDirectory)
config.projectConfig.database_url = dbConfig.clientUrl
config.projectConfig.database_driver_options = dbConfig.clientUrl.includes(
config.projectConfig.databaseUrl = dbConfig.clientUrl
config.projectConfig.databaseDriverOptions = dbConfig.clientUrl.includes(
"localhost"
)
? {}
Expand Down
58 changes: 30 additions & 28 deletions packages/core/types/src/common/config-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export type HttpCompressionOptions = {
*/
export type ProjectConfigOptions = {
/**
* The name of the database to connect to. If specified in `database_url`, then it’s not required to include it.
* The name of the database to connect to. If specified in `databaseUrl`, then it’s not required to include it.
*
* Make sure to create the PostgreSQL database before using it. You can check how to create a database in
* [PostgreSQL's documentation](https://www.postgresql.org/docs/current/sql-createdatabase.html).
Expand All @@ -127,15 +127,15 @@ export type ProjectConfigOptions = {
* ```js title="medusa-config.js"
* module.exports = {
* projectConfig: {
* database_database: process.env.DATABASE_DATABASE ||
* databaseName: process.env.DATABASE_DATABASE ||
* "medusa-store",
* // ...
* },
* // ...
* }
* ```
*/
database_database?: string
databaseName?: string

/**
* The connection URL of the database. The format of the connection URL for PostgreSQL is:
Expand Down Expand Up @@ -166,29 +166,30 @@ export type ProjectConfigOptions = {
* ```js title="medusa-config.js"
* module.exports = {
* projectConfig: {
* database_url: process.env.DATABASE_URL,
* databaseUrl: process.env.DATABASE_URL,
* // ...
* },
* // ...
* }
* ```
*/
database_url?: string
databaseUrl?: string

/**
* The database schema to connect to. This is not required to provide if you’re using the default schema, which is `public`.
*
* ```js title="medusa-config.js"
* module.exports = {
* projectConfig: {
* database_schema: process.env.DATABASE_SCHEMA ||
* databaseSchema: process.env.DATABASE_SCHEMA ||
* "custom",
* // ...
* },
* // ...
* }
* ```
*/
database_schema?: string
databaseSchema?: string

/**
* This configuration specifies what database messages to log. Its value can be one of the following:
Expand All @@ -203,7 +204,7 @@ export type ProjectConfigOptions = {
* ```js title="medusa-config.js"
* module.exports = {
* projectConfig: {
* database_logging: [
* databaseLogging: [
* "query", "error",
* ],
* // ...
Expand All @@ -212,7 +213,7 @@ export type ProjectConfigOptions = {
* }
* ```
*/
database_logging: LoggerOptions
databaseLogging: LoggerOptions

/**
* @ignore
Expand All @@ -221,7 +222,7 @@ export type ProjectConfigOptions = {
* @privateRemarks
* only postgres is supported, so this config has no effect
*/
database_type?: string
databaseType?: string

/**
* An object that includes additional configurations to pass to the database connection. You can pass any configuration. One defined configuration to pass is
Expand All @@ -234,7 +235,7 @@ export type ProjectConfigOptions = {
* ```js title="medusa-config.js"
* module.exports = {
* projectConfig: {
* database_extra:
* databaseExtra:
* process.env.NODE_ENV !== "development"
* ? { ssl: { rejectUnauthorized: false } }
* : {},
Expand All @@ -244,7 +245,7 @@ export type ProjectConfigOptions = {
* }
* ```
*/
database_extra?: Record<string, unknown> & {
databaseExtra?: Record<string, unknown> & {
/**
* Configure support for TLS/SSL connection
*/
Expand All @@ -267,7 +268,7 @@ export type ProjectConfigOptions = {
* ```js title="medusa-config.js"
* module.exports = {
* projectConfig: {
* database_driver_options:
* databaseDriverOptions:
* process.env.NODE_ENV !== "development"
* ? { connection: { ssl: { rejectUnauthorized: false } } }
* : {},
Expand All @@ -277,7 +278,7 @@ export type ProjectConfigOptions = {
* }
* ```
*/
database_driver_options?: Record<string, unknown> & {
databaseDriverOptions?: Record<string, unknown> & {
connection?: {
/**
* Configure support for TLS/SSL connection
Expand Down Expand Up @@ -312,15 +313,15 @@ export type ProjectConfigOptions = {
* ```js title="medusa-config.js"
* module.exports = {
* projectConfig: {
* redis_url: process.env.REDIS_URL ||
* redisUrl: process.env.REDIS_URL ||
* "redis://localhost:6379",
* // ...
* },
* // ...
* }
* ```
*/
redis_url?: string
redisUrl?: string

/**
* The prefix set on all keys stored in Redis. The default value is `sess:`.
Expand All @@ -331,15 +332,15 @@ export type ProjectConfigOptions = {
* ```js title="medusa-config.js"
* module.exports = {
* projectConfig: {
* redis_prefix: process.env.REDIS_PREFIX ||
* redisPrefix: process.env.REDIS_PREFIX ||
* "medusa:",
* // ...
* },
* // ...
* }
* ```
*/
redis_prefix?: string
redisPrefix?: string

/**
* An object of options to pass ioredis. You can refer to [ioredis’s RedisOptions documentation](https://redis.github.io/ioredis/index.html#RedisOptions)
Expand All @@ -349,7 +350,7 @@ export type ProjectConfigOptions = {
* ```js title="medusa-config.js"
* module.exports = {
* projectConfig: {
* redis_options: {
* redisOptions: {
* connectionName: process.env.REDIS_CONNECTION_NAME ||
* "medusa",
* },
Expand All @@ -359,7 +360,7 @@ export type ProjectConfigOptions = {
* }
* ```
*/
redis_options?: RedisOptions
redisOptions?: RedisOptions

/**
* An object of options to pass to [express-session](https://www.npmjs.com/package/express-session).
Expand All @@ -368,7 +369,7 @@ export type ProjectConfigOptions = {
* ```js title="medusa-config.js"
* module.exports = {
* projectConfig: {
* session_options: {
* sessionOptions: {
* name: process.env.SESSION_NAME ||
* "custom",
* },
Expand All @@ -378,7 +379,7 @@ export type ProjectConfigOptions = {
* }
* ```
*/
session_options?: SessionOptions
sessionOptions?: SessionOptions

/**
* Configure HTTP compression from the application layer. If you have access to the HTTP server, the recommended approach would be to enable it there.
Expand All @@ -390,7 +391,7 @@ export type ProjectConfigOptions = {
* ```js title="medusa-config.js"
* module.exports = {
* projectConfig: {
* http_compression: {
* httpCompression: {
* enabled: true,
* level: 6,
* memLevel: 8,
Expand All @@ -405,7 +406,7 @@ export type ProjectConfigOptions = {
* @deprecated use {@link http }'s `compression` property instead.
*
*/
http_compression?: HttpCompressionOptions
httpCompression?: HttpCompressionOptions

/**
* Configure the number of staged jobs that are polled from the database. Default is `1000`.
Expand All @@ -414,14 +415,14 @@ export type ProjectConfigOptions = {
* ```js title="medusa-config.js"
* module.exports = {
* projectConfig: {
* jobs_batch_size: 100
* jobsBatchSize: 100
* // ...
* },
* // ...
* }
* ```
*/
jobs_batch_size?: number
jobsBatchSize?: number

/**
* Configure the application's worker mode. Default is `shared`.
Expand All @@ -436,14 +437,14 @@ export type ProjectConfigOptions = {
* ```js title="medusa-config.js"
* module.exports = {
* projectConfig: {
* worker_mode: "shared"
* workerMode: "shared"
* // ...
* },
* // ...
* }
* ```
*/
worker_mode?: "shared" | "worker" | "server"
workerMode?: "shared" | "worker" | "server"

/**
* Configure the application's http-specific settings
Expand Down Expand Up @@ -652,6 +653,7 @@ export type ProjectConfigOptions = {
* ```
*/
storeCors: string

/**
* The Medusa backend’s API Routes are protected by Cross-Origin Resource Sharing (CORS). So, only allowed URLs or URLs matching a specified pattern can send requests to the backend’s API Routes.
*
Expand Down
14 changes: 7 additions & 7 deletions packages/medusa/src/loaders/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,30 @@ const buildHttpConfig = (projectConfig: ConfigModule["projectConfig"]) => {
const normalizeProjectConfig = (
projectConfig: ConfigModule["projectConfig"]
) => {
if (!projectConfig?.redis_url) {
if (!projectConfig?.redisUrl) {
console.log(
`[medusa-config] ⚠️ redis_url not found. A fake redis instance will be used.`
`[medusa-config] ⚠️ redisUrl not found. A fake redis instance will be used.`
)
}

projectConfig.http = buildHttpConfig(projectConfig)

let worker_mode = projectConfig?.worker_mode
let workedMode = projectConfig?.workerMode

if (!isDefined(worker_mode)) {
if (!isDefined(workedMode)) {
const env = process.env.MEDUSA_WORKER_MODE
if (isDefined(env)) {
if (env === "shared" || env === "worker" || env === "server") {
worker_mode = env
workedMode = env
}
} else {
worker_mode = "shared"
workedMode = "shared"
}
}

return {
...projectConfig,
worker_mode,
workerMode: workedMode,
}
}

Expand Down
Loading
Loading