@8medusa/framework 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -0
- package/dist/build-tools/compiler.d.ts +64 -0
- package/dist/build-tools/compiler.d.ts.map +1 -0
- package/dist/build-tools/compiler.js +419 -0
- package/dist/build-tools/compiler.js.map +1 -0
- package/dist/build-tools/index.d.ts +2 -0
- package/dist/build-tools/index.d.ts.map +1 -0
- package/dist/build-tools/index.js +18 -0
- package/dist/build-tools/index.js.map +1 -0
- package/dist/config/config.d.ts +34 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +134 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/index.d.ts +5 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +21 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/loader.d.ts +11 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +35 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/types.d.ts +2 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +3 -0
- package/dist/config/types.js.map +1 -0
- package/dist/container.d.ts +3 -0
- package/dist/container.d.ts.map +1 -0
- package/dist/container.js +21 -0
- package/dist/container.js.map +1 -0
- package/dist/database/index.d.ts +3 -0
- package/dist/database/index.d.ts.map +1 -0
- package/dist/database/index.js +19 -0
- package/dist/database/index.js.map +1 -0
- package/dist/database/pg-connection-loader.d.ts +6 -0
- package/dist/database/pg-connection-loader.d.ts.map +1 -0
- package/dist/database/pg-connection-loader.js +43 -0
- package/dist/database/pg-connection-loader.js.map +1 -0
- package/dist/feature-flags/feature-flag-loader.d.ts +8 -0
- package/dist/feature-flags/feature-flag-loader.d.ts.map +1 -0
- package/dist/feature-flags/feature-flag-loader.js +81 -0
- package/dist/feature-flags/feature-flag-loader.js.map +1 -0
- package/dist/feature-flags/flag-router.d.ts +32 -0
- package/dist/feature-flags/flag-router.d.ts.map +1 -0
- package/dist/feature-flags/flag-router.js +67 -0
- package/dist/feature-flags/flag-router.js.map +1 -0
- package/dist/feature-flags/index.d.ts +5 -0
- package/dist/feature-flags/index.d.ts.map +1 -0
- package/dist/feature-flags/index.js +21 -0
- package/dist/feature-flags/index.js.map +1 -0
- package/dist/feature-flags/types.d.ts +31 -0
- package/dist/feature-flags/types.d.ts.map +1 -0
- package/dist/feature-flags/types.js +3 -0
- package/dist/feature-flags/types.js.map +1 -0
- package/dist/http/express-loader.d.ts +8 -0
- package/dist/http/express-loader.d.ts.map +1 -0
- package/dist/http/express-loader.js +128 -0
- package/dist/http/express-loader.js.map +1 -0
- package/dist/http/index.d.ts +15 -0
- package/dist/http/index.d.ts.map +1 -0
- package/dist/http/index.js +31 -0
- package/dist/http/index.js.map +1 -0
- package/dist/http/middleware-file-loader.d.ts +33 -0
- package/dist/http/middleware-file-loader.d.ts.map +1 -0
- package/dist/http/middleware-file-loader.js +173 -0
- package/dist/http/middleware-file-loader.js.map +1 -0
- package/dist/http/middlewares/apply-default-filters.d.ts +3 -0
- package/dist/http/middlewares/apply-default-filters.d.ts.map +1 -0
- package/dist/http/middlewares/apply-default-filters.js +32 -0
- package/dist/http/middlewares/apply-default-filters.js.map +1 -0
- package/dist/http/middlewares/apply-params-as-filters.d.ts +5 -0
- package/dist/http/middlewares/apply-params-as-filters.d.ts.map +1 -0
- package/dist/http/middlewares/apply-params-as-filters.js +14 -0
- package/dist/http/middlewares/apply-params-as-filters.js.map +1 -0
- package/dist/http/middlewares/authenticate-middleware.d.ts +13 -0
- package/dist/http/middlewares/authenticate-middleware.d.ts.map +1 -0
- package/dist/http/middlewares/authenticate-middleware.js +136 -0
- package/dist/http/middlewares/authenticate-middleware.js.map +1 -0
- package/dist/http/middlewares/bodyparser.d.ts +13 -0
- package/dist/http/middlewares/bodyparser.d.ts.map +1 -0
- package/dist/http/middlewares/bodyparser.js +62 -0
- package/dist/http/middlewares/bodyparser.js.map +1 -0
- package/dist/http/middlewares/clear-filters-by-key.d.ts +3 -0
- package/dist/http/middlewares/clear-filters-by-key.d.ts.map +1 -0
- package/dist/http/middlewares/clear-filters-by-key.js +12 -0
- package/dist/http/middlewares/clear-filters-by-key.js.map +1 -0
- package/dist/http/middlewares/ensure-publishable-api-key.d.ts +3 -0
- package/dist/http/middlewares/ensure-publishable-api-key.d.ts.map +1 -0
- package/dist/http/middlewares/ensure-publishable-api-key.js +45 -0
- package/dist/http/middlewares/ensure-publishable-api-key.js.map +1 -0
- package/dist/http/middlewares/error-handler.d.ts +21 -0
- package/dist/http/middlewares/error-handler.d.ts.map +1 -0
- package/dist/http/middlewares/error-handler.js +85 -0
- package/dist/http/middlewares/error-handler.js.map +1 -0
- package/dist/http/middlewares/exception-formatter.d.ts +9 -0
- package/dist/http/middlewares/exception-formatter.d.ts.map +1 -0
- package/dist/http/middlewares/exception-formatter.js +36 -0
- package/dist/http/middlewares/exception-formatter.js.map +1 -0
- package/dist/http/middlewares/index.d.ts +8 -0
- package/dist/http/middlewares/index.d.ts.map +1 -0
- package/dist/http/middlewares/index.js +24 -0
- package/dist/http/middlewares/index.js.map +1 -0
- package/dist/http/middlewares/set-context.d.ts +3 -0
- package/dist/http/middlewares/set-context.d.ts.map +1 -0
- package/dist/http/middlewares/set-context.js +18 -0
- package/dist/http/middlewares/set-context.js.map +1 -0
- package/dist/http/router.d.ts +28 -0
- package/dist/http/router.d.ts.map +1 -0
- package/dist/http/router.js +252 -0
- package/dist/http/router.js.map +1 -0
- package/dist/http/routes-finder.d.ts +22 -0
- package/dist/http/routes-finder.d.ts.map +1 -0
- package/dist/http/routes-finder.js +62 -0
- package/dist/http/routes-finder.js.map +1 -0
- package/dist/http/routes-loader.d.ts +30 -0
- package/dist/http/routes-loader.d.ts.map +1 -0
- package/dist/http/routes-loader.js +203 -0
- package/dist/http/routes-loader.js.map +1 -0
- package/dist/http/routes-sorter.d.ts +105 -0
- package/dist/http/routes-sorter.d.ts.map +1 -0
- package/dist/http/routes-sorter.js +146 -0
- package/dist/http/routes-sorter.js.map +1 -0
- package/dist/http/types.d.ts +164 -0
- package/dist/http/types.d.ts.map +1 -0
- package/dist/http/types.js +16 -0
- package/dist/http/types.js.map +1 -0
- package/dist/http/utils/define-middlewares.d.ts +22 -0
- package/dist/http/utils/define-middlewares.d.ts.map +1 -0
- package/dist/http/utils/define-middlewares.js +27 -0
- package/dist/http/utils/define-middlewares.js.map +1 -0
- package/dist/http/utils/get-query-config.d.ts +42 -0
- package/dist/http/utils/get-query-config.d.ts.map +1 -0
- package/dist/http/utils/get-query-config.js +183 -0
- package/dist/http/utils/get-query-config.js.map +1 -0
- package/dist/http/utils/http-compression.d.ts +5 -0
- package/dist/http/utils/http-compression.d.ts.map +1 -0
- package/dist/http/utils/http-compression.js +33 -0
- package/dist/http/utils/http-compression.js.map +1 -0
- package/dist/http/utils/maybe-apply-link-filter.d.ts +8 -0
- package/dist/http/utils/maybe-apply-link-filter.d.ts.map +1 -0
- package/dist/http/utils/maybe-apply-link-filter.js +68 -0
- package/dist/http/utils/maybe-apply-link-filter.js.map +1 -0
- package/dist/http/utils/refetch-entities.d.ts +5 -0
- package/dist/http/utils/refetch-entities.d.ts.map +1 -0
- package/dist/http/utils/refetch-entities.js +29 -0
- package/dist/http/utils/refetch-entities.js.map +1 -0
- package/dist/http/utils/restricted-fields.d.ts +6 -0
- package/dist/http/utils/restricted-fields.d.ts.map +1 -0
- package/dist/http/utils/restricted-fields.js +30 -0
- package/dist/http/utils/restricted-fields.js.map +1 -0
- package/dist/http/utils/unless-path.d.ts +9 -0
- package/dist/http/utils/unless-path.d.ts.map +1 -0
- package/dist/http/utils/unless-path.js +19 -0
- package/dist/http/utils/unless-path.js.map +1 -0
- package/dist/http/utils/validate-body.d.ts +5 -0
- package/dist/http/utils/validate-body.d.ts.map +1 -0
- package/dist/http/utils/validate-body.js +23 -0
- package/dist/http/utils/validate-body.js.map +1 -0
- package/dist/http/utils/validate-query.d.ts +6 -0
- package/dist/http/utils/validate-query.d.ts.map +1 -0
- package/dist/http/utils/validate-query.js +79 -0
- package/dist/http/utils/validate-query.js.map +1 -0
- package/dist/http/utils/wrap-handler.d.ts +3 -0
- package/dist/http/utils/wrap-handler.d.ts.map +1 -0
- package/dist/http/utils/wrap-handler.js +26 -0
- package/dist/http/utils/wrap-handler.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/jobs/index.d.ts +2 -0
- package/dist/jobs/index.d.ts.map +1 -0
- package/dist/jobs/index.js +18 -0
- package/dist/jobs/index.js.map +1 -0
- package/dist/jobs/job-loader.d.ts +42 -0
- package/dist/jobs/job-loader.d.ts.map +1 -0
- package/dist/jobs/job-loader.js +78 -0
- package/dist/jobs/job-loader.js.map +1 -0
- package/dist/links/index.d.ts +2 -0
- package/dist/links/index.d.ts.map +1 -0
- package/dist/links/index.js +18 -0
- package/dist/links/index.js.map +1 -0
- package/dist/links/link-loader.d.ts +10 -0
- package/dist/links/link-loader.d.ts.map +1 -0
- package/dist/links/link-loader.js +74 -0
- package/dist/links/link-loader.js.map +1 -0
- package/dist/logger/index.d.ts +3 -0
- package/dist/logger/index.d.ts.map +1 -0
- package/dist/logger/index.js +9 -0
- package/dist/logger/index.js.map +1 -0
- package/dist/medusa-app-loader.d.ts +51 -0
- package/dist/medusa-app-loader.d.ts.map +1 -0
- package/dist/medusa-app-loader.js +189 -0
- package/dist/medusa-app-loader.js.map +1 -0
- package/dist/migrations/index.d.ts +3 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/index.js +19 -0
- package/dist/migrations/index.js.map +1 -0
- package/dist/migrations/migrator.d.ts +38 -0
- package/dist/migrations/migrator.d.ts.map +1 -0
- package/dist/migrations/migrator.js +129 -0
- package/dist/migrations/migrator.js.map +1 -0
- package/dist/migrations/run-migration-scripts.d.ts +17 -0
- package/dist/migrations/run-migration-scripts.d.ts.map +1 -0
- package/dist/migrations/run-migration-scripts.js +94 -0
- package/dist/migrations/run-migration-scripts.js.map +1 -0
- package/dist/mikro-orm-cli/bin.d.ts +14 -0
- package/dist/mikro-orm-cli/bin.d.ts.map +1 -0
- package/dist/mikro-orm-cli/bin.js +54 -0
- package/dist/mikro-orm-cli/bin.js.map +1 -0
- package/dist/modules-sdk/index.d.ts +2 -0
- package/dist/modules-sdk/index.d.ts.map +1 -0
- package/dist/modules-sdk/index.js +18 -0
- package/dist/modules-sdk/index.js.map +1 -0
- package/dist/orchestration/index.d.ts +2 -0
- package/dist/orchestration/index.d.ts.map +1 -0
- package/dist/orchestration/index.js +18 -0
- package/dist/orchestration/index.js.map +1 -0
- package/dist/subscribers/index.d.ts +3 -0
- package/dist/subscribers/index.d.ts.map +1 -0
- package/dist/subscribers/index.js +19 -0
- package/dist/subscribers/index.js.map +1 -0
- package/dist/subscribers/subscriber-loader.d.ts +12 -0
- package/dist/subscribers/subscriber-loader.d.ts.map +1 -0
- package/dist/subscribers/subscriber-loader.js +147 -0
- package/dist/subscribers/subscriber-loader.js.map +1 -0
- package/dist/subscribers/types.d.ts +15 -0
- package/dist/subscribers/types.d.ts.map +1 -0
- package/dist/subscribers/types.js +3 -0
- package/dist/subscribers/types.js.map +1 -0
- package/dist/telemetry/index.d.ts +50 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +81 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/types/container.d.ts +62 -0
- package/dist/types/container.d.ts.map +1 -0
- package/dist/types/container.js +3 -0
- package/dist/types/container.js.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +18 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +19 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/resource-loader.d.ts +26 -0
- package/dist/utils/resource-loader.d.ts.map +1 -0
- package/dist/utils/resource-loader.js +78 -0
- package/dist/utils/resource-loader.js.map +1 -0
- package/dist/workflows/index.d.ts +3 -0
- package/dist/workflows/index.d.ts.map +1 -0
- package/dist/workflows/index.js +19 -0
- package/dist/workflows/index.js.map +1 -0
- package/dist/workflows/workflow-loader.d.ts +12 -0
- package/dist/workflows/workflow-loader.d.ts.map +1 -0
- package/dist/workflows/workflow-loader.js +24 -0
- package/dist/workflows/workflow-loader.js.map +1 -0
- package/dist/workflows-sdk/composer.d.ts +2 -0
- package/dist/workflows-sdk/composer.d.ts.map +1 -0
- package/dist/workflows-sdk/composer.js +18 -0
- package/dist/workflows-sdk/composer.js.map +1 -0
- package/dist/workflows-sdk/index.d.ts +3 -0
- package/dist/workflows-sdk/index.d.ts.map +1 -0
- package/dist/workflows-sdk/index.js +19 -0
- package/dist/workflows-sdk/index.js.map +1 -0
- package/dist/zod/index.d.ts +2 -0
- package/dist/zod/index.d.ts.map +1 -0
- package/dist/zod/index.js +18 -0
- package/dist/zod/index.js.map +1 -0
- package/dist/zod/zod-helpers.d.ts +3 -0
- package/dist/zod/zod-helpers.d.ts.map +1 -0
- package/dist/zod/zod-helpers.js +95 -0
- package/dist/zod/zod-helpers.js.map +1 -0
- package/package.json +133 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _MedusaAppLoader_container, _MedusaAppLoader_customLinksModules;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.MedusaAppLoader = void 0;
|
|
16
|
+
const modules_sdk_1 = require("@8medusa/modules-sdk");
|
|
17
|
+
const utils_1 = require("@8medusa/utils");
|
|
18
|
+
const awilix_1 = require("awilix");
|
|
19
|
+
const config_1 = require("./config");
|
|
20
|
+
const container_1 = require("./container");
|
|
21
|
+
class MedusaAppLoader {
|
|
22
|
+
// TODO: Adjust all loaders to accept an optional container such that in test env it is possible if needed to provide a specific container otherwise use the main container
|
|
23
|
+
// Maybe also adjust the different places to resolve the config from the container instead of the configManager for the same reason
|
|
24
|
+
// To be discussed
|
|
25
|
+
constructor({ container, customLinksModules, } = {}) {
|
|
26
|
+
/**
|
|
27
|
+
* Container from where to resolve resources
|
|
28
|
+
* @private
|
|
29
|
+
*/
|
|
30
|
+
_MedusaAppLoader_container.set(this, void 0);
|
|
31
|
+
/**
|
|
32
|
+
* Extra links modules config which should be added manually to the links to be loaded
|
|
33
|
+
* @private
|
|
34
|
+
*/
|
|
35
|
+
_MedusaAppLoader_customLinksModules.set(this, void 0);
|
|
36
|
+
__classPrivateFieldSet(this, _MedusaAppLoader_container, container ?? container_1.container, "f");
|
|
37
|
+
__classPrivateFieldSet(this, _MedusaAppLoader_customLinksModules, customLinksModules ?? [], "f");
|
|
38
|
+
}
|
|
39
|
+
mergeDefaultModules(modulesConfig) {
|
|
40
|
+
const defaultModules = Object.values(modules_sdk_1.ModulesDefinition).filter((definition) => {
|
|
41
|
+
return !!definition.defaultPackage;
|
|
42
|
+
});
|
|
43
|
+
const configModules = { ...modulesConfig };
|
|
44
|
+
for (const defaultModule of defaultModules) {
|
|
45
|
+
configModules[defaultModule.key] ??=
|
|
46
|
+
defaultModule.defaultModuleDeclaration;
|
|
47
|
+
}
|
|
48
|
+
for (const [key, value] of Object.entries(configModules)) {
|
|
49
|
+
const def = {};
|
|
50
|
+
def.key ??= key;
|
|
51
|
+
def.label ??= modules_sdk_1.ModulesDefinition[key]?.label ?? (0, utils_1.upperCaseFirst)(key);
|
|
52
|
+
def.isQueryable = modules_sdk_1.ModulesDefinition[key]?.isQueryable ?? true;
|
|
53
|
+
const orignalDef = value?.definition ?? modules_sdk_1.ModulesDefinition[key];
|
|
54
|
+
if (!(0, utils_1.isBoolean)(value) &&
|
|
55
|
+
((0, utils_1.isObject)(orignalDef) || !(0, utils_1.isPresent)(value.definition))) {
|
|
56
|
+
value.definition = {
|
|
57
|
+
...def,
|
|
58
|
+
...orignalDef,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return configModules;
|
|
63
|
+
}
|
|
64
|
+
prepareSharedResourcesAndDeps() {
|
|
65
|
+
const injectedDependencies = {
|
|
66
|
+
[utils_1.ContainerRegistrationKeys.PG_CONNECTION]: __classPrivateFieldGet(this, _MedusaAppLoader_container, "f").resolve(utils_1.ContainerRegistrationKeys.PG_CONNECTION),
|
|
67
|
+
[utils_1.ContainerRegistrationKeys.LOGGER]: __classPrivateFieldGet(this, _MedusaAppLoader_container, "f").resolve(utils_1.ContainerRegistrationKeys.LOGGER),
|
|
68
|
+
};
|
|
69
|
+
const driverOptions = {
|
|
70
|
+
...(config_1.configManager.config.projectConfig.databaseDriverOptions ?? {}),
|
|
71
|
+
};
|
|
72
|
+
const pool = driverOptions.pool ?? {};
|
|
73
|
+
delete driverOptions.pool;
|
|
74
|
+
const sharedResourcesConfig = {
|
|
75
|
+
database: {
|
|
76
|
+
clientUrl: injectedDependencies[utils_1.ContainerRegistrationKeys.PG_CONNECTION]?.client?.config?.connection?.connectionString ??
|
|
77
|
+
config_1.configManager.config.projectConfig.databaseUrl,
|
|
78
|
+
driverOptions: config_1.configManager.config.projectConfig.databaseDriverOptions,
|
|
79
|
+
pool: pool,
|
|
80
|
+
debug: config_1.configManager.config.projectConfig.databaseLogging ?? false,
|
|
81
|
+
schema: config_1.configManager.config.projectConfig.databaseSchema,
|
|
82
|
+
database: config_1.configManager.config.projectConfig.databaseName,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
return { sharedResourcesConfig, injectedDependencies };
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Run, Revert or Generate the migrations for the medusa app.
|
|
89
|
+
*
|
|
90
|
+
* @param moduleNames
|
|
91
|
+
* @param linkModules
|
|
92
|
+
* @param action
|
|
93
|
+
*/
|
|
94
|
+
async runModulesMigrations({ moduleNames, action = "run", } = {
|
|
95
|
+
action: "run",
|
|
96
|
+
}) {
|
|
97
|
+
const configModules = this.mergeDefaultModules(config_1.configManager.config.modules);
|
|
98
|
+
const { sharedResourcesConfig, injectedDependencies } = this.prepareSharedResourcesAndDeps();
|
|
99
|
+
const migrationOptions = {
|
|
100
|
+
modulesConfig: configModules,
|
|
101
|
+
sharedContainer: __classPrivateFieldGet(this, _MedusaAppLoader_container, "f"),
|
|
102
|
+
linkModules: __classPrivateFieldGet(this, _MedusaAppLoader_customLinksModules, "f"),
|
|
103
|
+
sharedResourcesConfig,
|
|
104
|
+
injectedDependencies,
|
|
105
|
+
};
|
|
106
|
+
if (action === "revert") {
|
|
107
|
+
await (0, modules_sdk_1.MedusaAppMigrateDown)(moduleNames, migrationOptions);
|
|
108
|
+
}
|
|
109
|
+
else if (action === "run") {
|
|
110
|
+
await (0, modules_sdk_1.MedusaAppMigrateUp)(migrationOptions);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
await (0, modules_sdk_1.MedusaAppMigrateGenerate)(moduleNames, migrationOptions);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Return an instance of the link module migration planner.
|
|
118
|
+
*/
|
|
119
|
+
async getLinksExecutionPlanner() {
|
|
120
|
+
const configModules = this.mergeDefaultModules(config_1.configManager.config.modules);
|
|
121
|
+
const { sharedResourcesConfig, injectedDependencies } = this.prepareSharedResourcesAndDeps();
|
|
122
|
+
const migrationOptions = {
|
|
123
|
+
modulesConfig: configModules,
|
|
124
|
+
sharedContainer: __classPrivateFieldGet(this, _MedusaAppLoader_container, "f"),
|
|
125
|
+
linkModules: __classPrivateFieldGet(this, _MedusaAppLoader_customLinksModules, "f"),
|
|
126
|
+
sharedResourcesConfig,
|
|
127
|
+
injectedDependencies,
|
|
128
|
+
};
|
|
129
|
+
return await (0, modules_sdk_1.MedusaAppGetLinksExecutionPlanner)(migrationOptions);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Run the modules loader without taking care of anything else. This is useful for running the loader as a separate action or to re run all modules loaders.
|
|
133
|
+
*/
|
|
134
|
+
async runModulesLoader() {
|
|
135
|
+
const { sharedResourcesConfig, injectedDependencies } = this.prepareSharedResourcesAndDeps();
|
|
136
|
+
const configModules = this.mergeDefaultModules(config_1.configManager.config.modules);
|
|
137
|
+
await (0, modules_sdk_1.MedusaApp)({
|
|
138
|
+
modulesConfig: configModules,
|
|
139
|
+
sharedContainer: __classPrivateFieldGet(this, _MedusaAppLoader_container, "f"),
|
|
140
|
+
linkModules: __classPrivateFieldGet(this, _MedusaAppLoader_customLinksModules, "f"),
|
|
141
|
+
sharedResourcesConfig,
|
|
142
|
+
injectedDependencies,
|
|
143
|
+
loaderOnly: true,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Load all modules and bootstrap all the modules and links to be ready to be consumed
|
|
148
|
+
* @param config
|
|
149
|
+
*/
|
|
150
|
+
async load(config = { registerInContainer: true }) {
|
|
151
|
+
const configModule = __classPrivateFieldGet(this, _MedusaAppLoader_container, "f").resolve(utils_1.ContainerRegistrationKeys.CONFIG_MODULE);
|
|
152
|
+
const { sharedResourcesConfig, injectedDependencies } = this.prepareSharedResourcesAndDeps();
|
|
153
|
+
__classPrivateFieldGet(this, _MedusaAppLoader_container, "f").register(utils_1.ContainerRegistrationKeys.REMOTE_QUERY, (0, awilix_1.asValue)(undefined));
|
|
154
|
+
__classPrivateFieldGet(this, _MedusaAppLoader_container, "f").register(utils_1.ContainerRegistrationKeys.QUERY, (0, awilix_1.asValue)(undefined));
|
|
155
|
+
__classPrivateFieldGet(this, _MedusaAppLoader_container, "f").register(utils_1.ContainerRegistrationKeys.LINK, (0, awilix_1.asValue)(undefined));
|
|
156
|
+
__classPrivateFieldGet(this, _MedusaAppLoader_container, "f").register(utils_1.ContainerRegistrationKeys.REMOTE_LINK, (0, awilix_1.aliasTo)(utils_1.ContainerRegistrationKeys.LINK));
|
|
157
|
+
const configModules = this.mergeDefaultModules(configModule.modules);
|
|
158
|
+
const medusaApp = await (0, modules_sdk_1.MedusaApp)({
|
|
159
|
+
workerMode: configModule.projectConfig.workerMode,
|
|
160
|
+
modulesConfig: configModules,
|
|
161
|
+
sharedContainer: __classPrivateFieldGet(this, _MedusaAppLoader_container, "f"),
|
|
162
|
+
linkModules: __classPrivateFieldGet(this, _MedusaAppLoader_customLinksModules, "f"),
|
|
163
|
+
sharedResourcesConfig,
|
|
164
|
+
injectedDependencies,
|
|
165
|
+
});
|
|
166
|
+
if (!config.registerInContainer) {
|
|
167
|
+
return medusaApp;
|
|
168
|
+
}
|
|
169
|
+
__classPrivateFieldGet(this, _MedusaAppLoader_container, "f").register(utils_1.ContainerRegistrationKeys.LINK, (0, awilix_1.asValue)(medusaApp.link));
|
|
170
|
+
__classPrivateFieldGet(this, _MedusaAppLoader_container, "f").register(utils_1.ContainerRegistrationKeys.REMOTE_LINK, (0, awilix_1.aliasTo)(utils_1.ContainerRegistrationKeys.LINK));
|
|
171
|
+
__classPrivateFieldGet(this, _MedusaAppLoader_container, "f").register(utils_1.ContainerRegistrationKeys.REMOTE_QUERY, (0, awilix_1.asValue)(medusaApp.query));
|
|
172
|
+
__classPrivateFieldGet(this, _MedusaAppLoader_container, "f").register(utils_1.ContainerRegistrationKeys.QUERY, (0, awilix_1.asValue)(medusaApp.query));
|
|
173
|
+
for (const moduleService of Object.values(medusaApp.modules)) {
|
|
174
|
+
const loadedModule = moduleService;
|
|
175
|
+
container_1.container.register(loadedModule.__definition.key, (0, awilix_1.asValue)(moduleService));
|
|
176
|
+
}
|
|
177
|
+
// Register all unresolved modules as undefined to be present in the container with undefined value by default
|
|
178
|
+
// but still resolvable
|
|
179
|
+
for (const moduleDefinition of Object.values(modules_sdk_1.ModulesDefinition)) {
|
|
180
|
+
if (!container_1.container.hasRegistration(moduleDefinition.key)) {
|
|
181
|
+
container_1.container.register(moduleDefinition.key, (0, awilix_1.asValue)(undefined));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return medusaApp;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
exports.MedusaAppLoader = MedusaAppLoader;
|
|
188
|
+
_MedusaAppLoader_container = new WeakMap(), _MedusaAppLoader_customLinksModules = new WeakMap();
|
|
189
|
+
//# sourceMappingURL=medusa-app-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"medusa-app-loader.js","sourceRoot":"","sources":["../src/medusa-app-loader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sDAS6B;AAU7B,0CAMuB;AAGvB,mCAAyC;AACzC,qCAAwC;AACxC,2CAIoB;AAGpB,MAAa,eAAe;IAe1B,2KAA2K;IAC3K,mIAAmI;IACnI,kBAAkB;IAClB,YAAY,EACV,SAAS,EACT,kBAAkB,MAMhB,EAAE;QAzBN;;;WAGG;QACM,6CAA2B;QAEpC;;;WAGG;QACM,sDAEuB;QAc9B,uBAAA,IAAI,8BAAc,SAAS,IAAI,qBAAa,MAAA,CAAA;QAC5C,uBAAA,IAAI,uCAAuB,kBAAkB,IAAI,EAAE,MAAA,CAAA;IACrD,CAAC;IA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,CAAC;QAED,OAAO,SAAS,CAAA;IAClB,CAAC;CACF;AArQD,0CAqQC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/migrations/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,yBAAyB,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./migrator"), exports);
|
|
18
|
+
__exportStar(require("./run-migration-scripts"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/migrations/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA0B;AAC1B,0DAAuC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { MedusaContainer } from "@8medusa/types";
|
|
2
|
+
import { Knex } from "@mikro-orm/knex";
|
|
3
|
+
export declare abstract class Migrator {
|
|
4
|
+
#private;
|
|
5
|
+
protected abstract migration_table_name: string;
|
|
6
|
+
protected container: MedusaContainer;
|
|
7
|
+
protected pgConnection: Knex<any>;
|
|
8
|
+
constructor({ container }: {
|
|
9
|
+
container: MedusaContainer;
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* Util to track duration using hrtime
|
|
13
|
+
*/
|
|
14
|
+
protected trackDuration(): {
|
|
15
|
+
getSeconds(): string;
|
|
16
|
+
};
|
|
17
|
+
ensureDatabase(): Promise<void>;
|
|
18
|
+
ensureMigrationsTable(): Promise<void>;
|
|
19
|
+
getExecutedMigrations(): Promise<{
|
|
20
|
+
script_name: string;
|
|
21
|
+
}[]>;
|
|
22
|
+
insertMigration(records: Record<string, any>[]): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Load migration files from the given paths
|
|
25
|
+
*
|
|
26
|
+
* @param paths - The paths to load migration files from
|
|
27
|
+
* @param options - The options for loading migration files
|
|
28
|
+
* @param options.force - Whether to force loading migration files even if they have already been loaded
|
|
29
|
+
* @returns The loaded migration file paths
|
|
30
|
+
*/
|
|
31
|
+
loadMigrationFiles(paths: string[], { force }?: {
|
|
32
|
+
force?: boolean;
|
|
33
|
+
}): Promise<string[]>;
|
|
34
|
+
protected abstract createMigrationTable(): Promise<void>;
|
|
35
|
+
abstract run(...args: any[]): Promise<any>;
|
|
36
|
+
abstract getPendingMigrations(migrationPaths: string[]): Promise<string[]>;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=migrator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrator.d.ts","sourceRoot":"","sources":["../../src/migrations/migrator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAMtC,8BAAsB,QAAQ;;IAC5B,SAAS,CAAC,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAA;IAE/C,SAAS,CAAC,SAAS,EAAE,eAAe,CAAA;IACpC,SAAS,CAAC,YAAY,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;gBAIrB,EAAE,SAAS,EAAE,EAAE;QAAE,SAAS,EAAE,eAAe,CAAA;KAAE;IAOzD;;OAEG;IACH,SAAS,CAAC,aAAa;;;IAUjB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAoB/B,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC;IAwBtC,qBAAqB,IAAI,OAAO,CAAC;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAY3D,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAyBpE;;;;;;;OAOG;IACG,kBAAkB,CACtB,KAAK,EAAE,MAAM,EAAE,EACf,EAAE,KAAK,EAAE,GAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAqB,GAChD,OAAO,CAAC,MAAM,EAAE,CAAC;IAgCpB,SAAS,CAAC,QAAQ,CAAC,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IACxD,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;IAC1C,QAAQ,CAAC,oBAAoB,CAAC,cAAc,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAC3E"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var _Migrator_alreadyLoadedPaths;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.Migrator = void 0;
|
|
10
|
+
const glob_1 = require("glob");
|
|
11
|
+
const path_1 = require("path");
|
|
12
|
+
const logger_1 = require("../logger");
|
|
13
|
+
const utils_1 = require("../utils");
|
|
14
|
+
class Migrator {
|
|
15
|
+
constructor({ container }) {
|
|
16
|
+
_Migrator_alreadyLoadedPaths.set(this, new Map());
|
|
17
|
+
this.container = container;
|
|
18
|
+
this.pgConnection = this.container.resolve(utils_1.ContainerRegistrationKeys.PG_CONNECTION);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Util to track duration using hrtime
|
|
22
|
+
*/
|
|
23
|
+
trackDuration() {
|
|
24
|
+
const startTime = process.hrtime();
|
|
25
|
+
return {
|
|
26
|
+
getSeconds() {
|
|
27
|
+
const duration = process.hrtime(startTime);
|
|
28
|
+
return (duration[0] + duration[1] / 1e9).toFixed(2);
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
async ensureDatabase() {
|
|
33
|
+
const pgConnection = this.container.resolve(utils_1.ContainerRegistrationKeys.PG_CONNECTION);
|
|
34
|
+
try {
|
|
35
|
+
await pgConnection.raw("SELECT 1 + 1;");
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (error.code === "3D000") {
|
|
39
|
+
logger_1.logger.error(`Cannot run migrations. ${error.message.replace("error: ", "")}`);
|
|
40
|
+
logger_1.logger.info(`Run command "db:create" to create the database`);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
logger_1.logger.error(error);
|
|
44
|
+
}
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async ensureMigrationsTable() {
|
|
49
|
+
try {
|
|
50
|
+
// Check if table exists
|
|
51
|
+
const tableExists = await this.pgConnection.raw(`
|
|
52
|
+
SELECT EXISTS (
|
|
53
|
+
SELECT FROM information_schema.tables
|
|
54
|
+
WHERE table_schema = 'public'
|
|
55
|
+
AND table_name = '${this.migration_table_name}'
|
|
56
|
+
);
|
|
57
|
+
`);
|
|
58
|
+
if (!tableExists.rows[0].exists) {
|
|
59
|
+
logger_1.logger.info(`Creating migrations table '${this.migration_table_name}'...`);
|
|
60
|
+
await this.createMigrationTable();
|
|
61
|
+
logger_1.logger.info("Migrations table created successfully");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
logger_1.logger.error("Failed to ensure migrations table exists:", error);
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async getExecutedMigrations() {
|
|
70
|
+
try {
|
|
71
|
+
const result = await this.pgConnection.raw(`SELECT * FROM ${this.migration_table_name}`);
|
|
72
|
+
return result.rows;
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
logger_1.logger.error("Failed to get executed migrations:", error);
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async insertMigration(records) {
|
|
80
|
+
try {
|
|
81
|
+
const values = records.map((record) => Object.values(record));
|
|
82
|
+
const columns = Object.keys(records[0]);
|
|
83
|
+
await this.pgConnection.raw(`INSERT INTO ${this.migration_table_name} (${columns.join(", ")}) VALUES ${values
|
|
84
|
+
.map((itemValues) => `(${new Array(itemValues.length).fill("?").join(",")})`)
|
|
85
|
+
.join(",")}`, values.flat());
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
logger_1.logger.error(`Failed to update migration table '${this.migration_table_name}':`, error);
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Load migration files from the given paths
|
|
94
|
+
*
|
|
95
|
+
* @param paths - The paths to load migration files from
|
|
96
|
+
* @param options - The options for loading migration files
|
|
97
|
+
* @param options.force - Whether to force loading migration files even if they have already been loaded
|
|
98
|
+
* @returns The loaded migration file paths
|
|
99
|
+
*/
|
|
100
|
+
async loadMigrationFiles(paths, { force } = { force: false }) {
|
|
101
|
+
const allScripts = [];
|
|
102
|
+
for (const basePath of paths) {
|
|
103
|
+
if (!force && __classPrivateFieldGet(this, _Migrator_alreadyLoadedPaths, "f").has(basePath)) {
|
|
104
|
+
allScripts.push(...__classPrivateFieldGet(this, _Migrator_alreadyLoadedPaths, "f").get(basePath));
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
const scriptFiles = glob_1.glob.sync("*.{js,ts}", {
|
|
109
|
+
cwd: basePath,
|
|
110
|
+
ignore: ["**/index.{js,ts}", "**/*.d.ts"],
|
|
111
|
+
});
|
|
112
|
+
if (!scriptFiles?.length) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
const filePaths = scriptFiles.map((script) => (0, path_1.join)(basePath, script));
|
|
116
|
+
__classPrivateFieldGet(this, _Migrator_alreadyLoadedPaths, "f").set(basePath, filePaths);
|
|
117
|
+
allScripts.push(...filePaths);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
logger_1.logger.error(`Failed to load migration files from ${basePath}:`, error);
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return allScripts;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.Migrator = Migrator;
|
|
128
|
+
_Migrator_alreadyLoadedPaths = new WeakMap();
|
|
129
|
+
//# sourceMappingURL=migrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrator.js","sourceRoot":"","sources":["../../src/migrations/migrator.ts"],"names":[],"mappings":";;;;;;;;;AAEA,+BAA2B;AAC3B,+BAA2B;AAC3B,sCAAkC;AAClC,oCAAoD;AAEpD,MAAsB,QAAQ;IAQ5B,YAAY,EAAE,SAAS,EAAkC;QAFzD,uCAAwC,IAAI,GAAG,EAAE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BAEjD,UAAU,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,CAAA;YAC/B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,eAAM,CAAC,KAAK,CAAC,uCAAuC,QAAQ,GAAG,EAAE,KAAK,CAAC,CAAA;gBACvE,MAAM,KAAK,CAAA;YACb,CAAC;QACH,CAAC;QAED,OAAO,UAAU,CAAA;IACnB,CAAC;CAKF;AA3JD,4BA2JC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MedusaContainer } from "@8medusa/types";
|
|
2
|
+
import { Migrator } from "./migrator";
|
|
3
|
+
export declare class MigrationScriptsMigrator extends Migrator {
|
|
4
|
+
#private;
|
|
5
|
+
protected migration_table_name: string;
|
|
6
|
+
constructor({ container }: {
|
|
7
|
+
container: MedusaContainer;
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* Run the migration scripts
|
|
11
|
+
* @param paths - The paths from which to load the scripts
|
|
12
|
+
*/
|
|
13
|
+
run(paths: string[]): Promise<void>;
|
|
14
|
+
getPendingMigrations(migrationPaths: string[]): Promise<string[]>;
|
|
15
|
+
protected createMigrationTable(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=run-migration-scripts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-migration-scripts.d.ts","sourceRoot":"","sources":["../../src/migrations/run-migration-scripts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAIhD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,qBAAa,wBAAyB,SAAQ,QAAQ;;IACpD,SAAS,CAAC,oBAAoB,SAAsB;gBAExC,EAAE,SAAS,EAAE,EAAE;QAAE,SAAS,EAAE,eAAe,CAAA;KAAE;IAIzD;;;OAGG;IACG,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA4DnC,oBAAoB,CAAC,cAAc,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;cASvD,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;CA0BtD"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var _MigrationScriptsMigrator_instances, _MigrationScriptsMigrator_updateMigrationFinishedAt, _MigrationScriptsMigrator_deleteMigration;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.MigrationScriptsMigrator = void 0;
|
|
10
|
+
const utils_1 = require("@8medusa/utils");
|
|
11
|
+
const path_1 = require("path");
|
|
12
|
+
const logger_1 = require("../logger");
|
|
13
|
+
const migrator_1 = require("./migrator");
|
|
14
|
+
class MigrationScriptsMigrator extends migrator_1.Migrator {
|
|
15
|
+
constructor({ container }) {
|
|
16
|
+
super({ container });
|
|
17
|
+
_MigrationScriptsMigrator_instances.add(this);
|
|
18
|
+
this.migration_table_name = "script_migrations";
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Run the migration scripts
|
|
22
|
+
* @param paths - The paths from which to load the scripts
|
|
23
|
+
*/
|
|
24
|
+
async run(paths) {
|
|
25
|
+
const lockService = this.container.resolve(utils_1.Modules.LOCKING);
|
|
26
|
+
const lockKey = "migration-scripts-running";
|
|
27
|
+
await lockService.acquire(lockKey, {
|
|
28
|
+
expire: 60 * 60,
|
|
29
|
+
});
|
|
30
|
+
try {
|
|
31
|
+
const scriptPaths = await this.getPendingMigrations(paths);
|
|
32
|
+
for (const script of scriptPaths) {
|
|
33
|
+
const scriptFn = await (0, utils_1.dynamicImport)(script);
|
|
34
|
+
if (!scriptFn.default) {
|
|
35
|
+
throw new Error(`Failed to load migration script ${script}. No default export found.`);
|
|
36
|
+
}
|
|
37
|
+
const scriptName = (0, path_1.basename)(script);
|
|
38
|
+
const err = await this.insertMigration([
|
|
39
|
+
{ script_name: scriptName },
|
|
40
|
+
]).catch((e) => e);
|
|
41
|
+
/**
|
|
42
|
+
* In case another processes is running in parallel, the migration might
|
|
43
|
+
* have already been executed and therefore the insert will fail because of the
|
|
44
|
+
* unique constraint.
|
|
45
|
+
*/
|
|
46
|
+
if (err) {
|
|
47
|
+
if (err.constraint === "idx_script_name_unique") {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
throw err;
|
|
51
|
+
}
|
|
52
|
+
logger_1.logger.info(`Running migration script ${script}`);
|
|
53
|
+
try {
|
|
54
|
+
const tracker = this.trackDuration();
|
|
55
|
+
await scriptFn.default({ container: this.container });
|
|
56
|
+
logger_1.logger.info(`Migration script ${script} completed (${tracker.getSeconds()}s)`);
|
|
57
|
+
await __classPrivateFieldGet(this, _MigrationScriptsMigrator_instances, "m", _MigrationScriptsMigrator_updateMigrationFinishedAt).call(this, scriptName);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
logger_1.logger.error(`Failed to run migration script ${script}:`, error);
|
|
61
|
+
await __classPrivateFieldGet(this, _MigrationScriptsMigrator_instances, "m", _MigrationScriptsMigrator_deleteMigration).call(this, scriptName);
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
await lockService.release(lockKey);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async getPendingMigrations(migrationPaths) {
|
|
71
|
+
const executedMigrations = new Set((await this.getExecutedMigrations()).map((item) => item.script_name));
|
|
72
|
+
const all = await this.loadMigrationFiles(migrationPaths);
|
|
73
|
+
return all.filter((item) => !executedMigrations.has((0, path_1.basename)(item)));
|
|
74
|
+
}
|
|
75
|
+
async createMigrationTable() {
|
|
76
|
+
await this.pgConnection.raw(`
|
|
77
|
+
CREATE TABLE IF NOT EXISTS ${this.migration_table_name} (
|
|
78
|
+
id SERIAL PRIMARY KEY,
|
|
79
|
+
script_name VARCHAR(255) NOT NULL,
|
|
80
|
+
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
|
81
|
+
finished_at TIMESTAMP WITH TIME ZONE
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_script_name_unique ON ${this.migration_table_name} (script_name);
|
|
85
|
+
`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.MigrationScriptsMigrator = MigrationScriptsMigrator;
|
|
89
|
+
_MigrationScriptsMigrator_instances = new WeakSet(), _MigrationScriptsMigrator_updateMigrationFinishedAt = function _MigrationScriptsMigrator_updateMigrationFinishedAt(scriptName) {
|
|
90
|
+
return this.pgConnection.raw(`UPDATE ${this.migration_table_name} SET finished_at = NOW() WHERE script_name = ?`, [scriptName]);
|
|
91
|
+
}, _MigrationScriptsMigrator_deleteMigration = function _MigrationScriptsMigrator_deleteMigration(scriptName) {
|
|
92
|
+
return this.pgConnection.raw(`DELETE FROM ${this.migration_table_name} WHERE script_name = ?`, [scriptName]);
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=run-migration-scripts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-migration-scripts.js","sourceRoot":"","sources":["../../src/migrations/run-migration-scripts.ts"],"names":[],"mappings":";;;;;;;;;AACA,0CAAuD;AACvD,+BAA+B;AAC/B,sCAAkC;AAClC,yCAAqC;AAErC,MAAa,wBAAyB,SAAQ,mBAAQ;IAGpD,YAAY,EAAE,SAAS,EAAkC;QACvD,KAAK,CAAC,EA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A0GC;wKAb4B,UAAkB;IAC3C,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAC1B,UAAU,IAAI,CAAC,oBAAoB,gDAAgD,EACnF,CAAC,UAAU,CAAC,CACb,CAAA;AACH,CAAC,iGAEgB,UAAkB;IACjC,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAC1B,eAAe,IAAI,CAAC,oBAAoB,wBAAwB,EAChE,CAAC,UAAU,CAAC,CACb,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom wrapper on top of MikroORM CLI to override the issue
|
|
3
|
+
* they have when importing TypeScript files.
|
|
4
|
+
*
|
|
5
|
+
* They have hardcoded the module system of TypeScript to CommonJS
|
|
6
|
+
* and that makes it impossible to use any other module system
|
|
7
|
+
* like Node16 or NodeNext and so on.
|
|
8
|
+
*
|
|
9
|
+
* With this wrapper, we monkey patch the code responsible for register
|
|
10
|
+
* ts-node and then boot their CLI. Since, the code footprint is
|
|
11
|
+
* small, we should be okay with managing this wrapper.
|
|
12
|
+
*/
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=bin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../../src/mikro-orm-cli/bin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Custom wrapper on top of MikroORM CLI to override the issue
|
|
4
|
+
* they have when importing TypeScript files.
|
|
5
|
+
*
|
|
6
|
+
* They have hardcoded the module system of TypeScript to CommonJS
|
|
7
|
+
* and that makes it impossible to use any other module system
|
|
8
|
+
* like Node16 or NodeNext and so on.
|
|
9
|
+
*
|
|
10
|
+
* With this wrapper, we monkey patch the code responsible for register
|
|
11
|
+
* ts-node and then boot their CLI. Since, the code footprint is
|
|
12
|
+
* small, we should be okay with managing this wrapper.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const cli_1 = require("@mikro-orm/cli");
|
|
16
|
+
const core_1 = require("@mikro-orm/core");
|
|
17
|
+
const path_1 = require("path");
|
|
18
|
+
/**
|
|
19
|
+
* Monkey patching the TSNode registration of Mikro ORM to not use
|
|
20
|
+
* hardcoded module system with TypeScript.
|
|
21
|
+
*/
|
|
22
|
+
core_1.ConfigurationLoader.registerTsNode = function (configPath = "tsconfig.json") {
|
|
23
|
+
const tsConfigPath = (0, path_1.isAbsolute)(configPath)
|
|
24
|
+
? configPath
|
|
25
|
+
: (0, path_1.join)(process.cwd(), configPath);
|
|
26
|
+
const tsNode = require(require.resolve("ts-node", { paths: [tsConfigPath] }));
|
|
27
|
+
if (!tsNode) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const { options } = tsNode.register({
|
|
31
|
+
project: tsConfigPath,
|
|
32
|
+
transpileOnly: true,
|
|
33
|
+
}).config;
|
|
34
|
+
if (Object.entries(options?.paths ?? {}).length > 0) {
|
|
35
|
+
require("tsconfig-paths").register({
|
|
36
|
+
baseUrl: options.baseUrl ?? ".",
|
|
37
|
+
paths: options.paths,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
};
|
|
42
|
+
require("@jercle/yargonaut")
|
|
43
|
+
.style("blue")
|
|
44
|
+
.style("yellow", "required")
|
|
45
|
+
.helpStyle("green")
|
|
46
|
+
.errorsStyle("red");
|
|
47
|
+
(async () => {
|
|
48
|
+
const argv = await cli_1.CLIConfigurator.configure();
|
|
49
|
+
const args = await argv.parse(process.argv.slice(2));
|
|
50
|
+
if (args._.length === 0) {
|
|
51
|
+
cli_1.CLIHelper.showHelp();
|
|
52
|
+
}
|
|
53
|
+
})();
|
|
54
|
+
//# sourceMappingURL=bin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.js","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