@medusajs/utils
Advanced tools
Comparing version 1.9.5 to 1.9.6-next-20230814194612
@@ -25,1 +25,2 @@ export * from "./build-query"; | ||
export * from "./wrap-handler"; | ||
export * from "./container"; |
@@ -41,2 +41,3 @@ "use strict"; | ||
__exportStar(require("./wrap-handler"), exports); | ||
__exportStar(require("./container"), exports); | ||
//# sourceMappingURL=index.js.map |
import { ModuleServiceInitializeOptions } from "@medusajs/types"; | ||
export declare function mikroOrmCreateConnection(database: ModuleServiceInitializeOptions["database"], entities: any[]): Promise<import("@mikro-orm/core").MikroORM<import("@mikro-orm/postgresql").PostgreSqlDriver>>; | ||
export declare function mikroOrmCreateConnection(database: ModuleServiceInitializeOptions["database"] & { | ||
connection?: any; | ||
}, entities: any[]): Promise<import("@mikro-orm/core").MikroORM<import("@mikro-orm/postgresql").PostgreSqlDriver>>; |
@@ -66,19 +66,30 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var MikroORM, schema, orm; | ||
var schema, driverOptions, clientUrl, MikroORM; | ||
return __generator(this, function (_e) { | ||
switch (_e.label) { | ||
case 0: return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require("@mikro-orm/postgresql")); })]; | ||
case 0: | ||
schema = database.schema || "public"; | ||
driverOptions = (_a = database.driverOptions) !== null && _a !== void 0 ? _a : { | ||
connection: { ssl: true }, | ||
}; | ||
clientUrl = database.clientUrl; | ||
if (database.connection) { | ||
// Reuse already existing connection | ||
// It is important that the knex package version is the same as the one used by MikroORM knex package | ||
driverOptions = database.connection; | ||
clientUrl = | ||
database.connection.context.client.config.connection.connectionString; | ||
schema = database.connection.context.client.config.searchPath; | ||
} | ||
return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require("@mikro-orm/postgresql")); })]; | ||
case 1: | ||
MikroORM = (_e.sent()).MikroORM; | ||
schema = database.schema || "public"; | ||
return [4 /*yield*/, MikroORM.init({ | ||
discovery: { disableDynamicFileAccess: true }, | ||
entities: entities, | ||
debug: (_c = (_a = database.debug) !== null && _a !== void 0 ? _a : (_b = process.env.NODE_ENV) === null || _b === void 0 ? void 0 : _b.startsWith("dev")) !== null && _c !== void 0 ? _c : false, | ||
debug: (_d = (_b = database.debug) !== null && _b !== void 0 ? _b : (_c = process.env.NODE_ENV) === null || _c === void 0 ? void 0 : _c.startsWith("dev")) !== null && _d !== void 0 ? _d : false, | ||
baseDir: process.cwd(), | ||
clientUrl: database.clientUrl, | ||
clientUrl: clientUrl, | ||
schema: schema, | ||
driverOptions: (_d = database.driverOptions) !== null && _d !== void 0 ? _d : { | ||
connection: { ssl: true }, | ||
}, | ||
driverOptions: driverOptions, | ||
tsNode: process.env.APP_ENV === "development", | ||
@@ -90,5 +101,3 @@ type: "postgresql", | ||
})]; | ||
case 2: | ||
orm = _e.sent(); | ||
return [2 /*return*/, orm]; | ||
case 2: return [2 /*return*/, _e.sent()]; | ||
} | ||
@@ -95,0 +104,0 @@ }); |
@@ -5,1 +5,2 @@ export * from "./load-module-database-config"; | ||
export * from "./retrieve-entity"; | ||
export * from "./loaders/mikro-orm-connection-loader"; |
@@ -21,2 +21,3 @@ "use strict"; | ||
__exportStar(require("./retrieve-entity"), exports); | ||
__exportStar(require("./loaders/mikro-orm-connection-loader"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -8,2 +8,2 @@ import { ModulesSdkTypes } from "@medusajs/types"; | ||
*/ | ||
export declare function loadDatabaseConfig(moduleName: string, options?: ModulesSdkTypes.ModuleServiceInitializeOptions | ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions): ModulesSdkTypes.ModuleServiceInitializeOptions["database"]; | ||
export declare function loadDatabaseConfig(moduleName: string, options?: ModulesSdkTypes.ModuleServiceInitializeOptions, silent?: boolean): ModulesSdkTypes.ModuleServiceInitializeOptions["database"]; |
@@ -42,4 +42,5 @@ "use strict"; | ||
*/ | ||
function loadDatabaseConfig(moduleName, options) { | ||
function loadDatabaseConfig(moduleName, options, silent) { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
if (silent === void 0) { silent = false; } | ||
var clientUrl = getEnv("POSTGRES_URL", moduleName); | ||
@@ -60,3 +61,3 @@ var database = { | ||
} | ||
if (!database.clientUrl) { | ||
if (!database.clientUrl && !silent) { | ||
throw new common_1.MedusaError(common_1.MedusaError.Types.INVALID_ARGUMENT, "No database clientUrl provided. Please provide the clientUrl through the PRODUCT_POSTGRES_URL or POSTGRES_URL environment variable or the options object in the initialize function."); | ||
@@ -63,0 +64,0 @@ } |
{ | ||
"name": "@medusajs/utils", | ||
"version": "1.9.5", | ||
"version": "1.9.6-next-20230814194612", | ||
"description": "Medusa utilities functions shared by Medusa core and Modules", | ||
@@ -21,3 +21,3 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@medusajs/types": "^1.10.1", | ||
"@medusajs/types": "1.10.2-next-20230814194612", | ||
"@types/express": "^4.17.17", | ||
@@ -37,7 +37,7 @@ "cross-env": "^5.2.1", | ||
"scripts": { | ||
"prepare": "cross-env NODE_ENV=production yarn run build", | ||
"prepublishOnly": "cross-env NODE_ENV=production tsc --build", | ||
"build": "rimraf dist && tsc --build", | ||
"watch": "tsc --build --watch", | ||
"test": "jest" | ||
"test": "jest --runInBand --bail --forceExit" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
208439
205
3504
2