medusa-test-utils 1.1.45-snapshot-20240607093839 → 1.1.45-snapshot-20240703074611

Sign up to get free protection for your applications and to get access to all the features.
package/dist/database.js CHANGED
@@ -1,60 +1,22 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  exports.getMikroOrmWrapper = exports.getMikroOrmConfig = exports.getDatabaseURL = void 0;
40
- var postgresql_1 = require("@mikro-orm/postgresql");
4
+ const postgresql_1 = require("@mikro-orm/postgresql");
41
5
  function getDatabaseURL(dbName) {
42
- var _a, _b;
43
- var DB_HOST = (_a = process.env.DB_HOST) !== null && _a !== void 0 ? _a : "localhost";
44
- var DB_USERNAME = (_b = process.env.DB_USERNAME) !== null && _b !== void 0 ? _b : "";
45
- var DB_PASSWORD = process.env.DB_PASSWORD;
46
- var DB_NAME = dbName !== null && dbName !== void 0 ? dbName : process.env.DB_TEMP_NAME;
47
- return "postgres://".concat(DB_USERNAME).concat(DB_PASSWORD ? ":".concat(DB_PASSWORD) : "", "@").concat(DB_HOST, "/").concat(DB_NAME);
6
+ const DB_HOST = process.env.DB_HOST ?? "localhost";
7
+ const DB_USERNAME = process.env.DB_USERNAME ?? "";
8
+ const DB_PASSWORD = process.env.DB_PASSWORD;
9
+ const DB_NAME = dbName ?? process.env.DB_TEMP_NAME;
10
+ return `postgres://${DB_USERNAME}${DB_PASSWORD ? `:${DB_PASSWORD}` : ""}@${DB_HOST}/${DB_NAME}`;
48
11
  }
49
12
  exports.getDatabaseURL = getDatabaseURL;
50
- function getMikroOrmConfig(_a) {
51
- var mikroOrmEntities = _a.mikroOrmEntities, pathToMigrations = _a.pathToMigrations, clientUrl = _a.clientUrl, schema = _a.schema;
52
- var DB_URL = clientUrl !== null && clientUrl !== void 0 ? clientUrl : getDatabaseURL();
13
+ function getMikroOrmConfig({ mikroOrmEntities, pathToMigrations, clientUrl, schema, }) {
14
+ const DB_URL = clientUrl ?? getDatabaseURL();
53
15
  return {
54
16
  type: "postgresql",
55
17
  clientUrl: DB_URL,
56
18
  entities: Object.values(mikroOrmEntities),
57
- schema: schema !== null && schema !== void 0 ? schema : process.env.MEDUSA_DB_SCHEMA,
19
+ schema: schema ?? process.env.MEDUSA_DB_SCHEMA,
58
20
  debug: false,
59
21
  migrations: {
60
22
  pathTs: pathToMigrations,
@@ -63,121 +25,73 @@ function getMikroOrmConfig(_a) {
63
25
  };
64
26
  }
65
27
  exports.getMikroOrmConfig = getMikroOrmConfig;
66
- function getMikroOrmWrapper(_a) {
67
- var mikroOrmEntities = _a.mikroOrmEntities, pathToMigrations = _a.pathToMigrations, clientUrl = _a.clientUrl, schema = _a.schema;
28
+ function getMikroOrmWrapper({ mikroOrmEntities, pathToMigrations, clientUrl, schema, }) {
68
29
  return {
69
- mikroOrmEntities: mikroOrmEntities,
70
- pathToMigrations: pathToMigrations,
71
- clientUrl: clientUrl !== null && clientUrl !== void 0 ? clientUrl : getDatabaseURL(),
72
- schema: schema !== null && schema !== void 0 ? schema : process.env.MEDUSA_DB_SCHEMA,
30
+ mikroOrmEntities,
31
+ pathToMigrations,
32
+ clientUrl: clientUrl ?? getDatabaseURL(),
33
+ schema: schema ?? process.env.MEDUSA_DB_SCHEMA,
73
34
  orm: null,
74
35
  manager: null,
75
- getManager: function () {
36
+ getManager() {
76
37
  if (this.manager === null) {
77
38
  throw new Error("manager entity not available");
78
39
  }
79
40
  return this.manager;
80
41
  },
81
- forkManager: function () {
42
+ forkManager() {
82
43
  if (this.manager === null) {
83
44
  throw new Error("manager entity not available");
84
45
  }
85
46
  return this.manager.fork();
86
47
  },
87
- getOrm: function () {
48
+ getOrm() {
88
49
  if (this.orm === null) {
89
50
  throw new Error("orm entity not available");
90
51
  }
91
52
  return this.orm;
92
53
  },
93
- setupDatabase: function () {
94
- return __awaiter(this, void 0, void 0, function () {
95
- var OrmConfig, _a, err_1, pendingMigrations;
96
- var _b, _c;
97
- return __generator(this, function (_d) {
98
- switch (_d.label) {
99
- case 0:
100
- OrmConfig = getMikroOrmConfig({
101
- mikroOrmEntities: this.mikroOrmEntities,
102
- pathToMigrations: this.pathToMigrations,
103
- clientUrl: this.clientUrl,
104
- schema: this.schema,
105
- });
106
- // Initializing the ORM
107
- _a = this;
108
- return [4 /*yield*/, postgresql_1.MikroORM.init(OrmConfig)];
109
- case 1:
110
- // Initializing the ORM
111
- _a.orm = _d.sent();
112
- this.manager = this.orm.em;
113
- _d.label = 2;
114
- case 2:
115
- _d.trys.push([2, 4, , 5]);
116
- return [4 /*yield*/, this.orm.getSchemaGenerator().ensureDatabase()];
117
- case 3:
118
- _d.sent();
119
- return [3 /*break*/, 5];
120
- case 4:
121
- err_1 = _d.sent();
122
- console.log(err_1);
123
- return [3 /*break*/, 5];
124
- case 5: return [4 /*yield*/, ((_b = this.manager) === null || _b === void 0 ? void 0 : _b.execute("CREATE SCHEMA IF NOT EXISTS \"".concat((_c = this.schema) !== null && _c !== void 0 ? _c : "public", "\";")))];
125
- case 6:
126
- _d.sent();
127
- return [4 /*yield*/, this.orm
128
- .getMigrator()
129
- .getPendingMigrations()];
130
- case 7:
131
- pendingMigrations = _d.sent();
132
- if (!(pendingMigrations && pendingMigrations.length > 0)) return [3 /*break*/, 9];
133
- return [4 /*yield*/, this.orm
134
- .getMigrator()
135
- .up({ migrations: pendingMigrations.map(function (m) { return m.name; }) })];
136
- case 8:
137
- _d.sent();
138
- return [3 /*break*/, 11];
139
- case 9: return [4 /*yield*/, this.orm.schema.refreshDatabase()]; // ensure db exists and is fresh
140
- case 10:
141
- _d.sent(); // ensure db exists and is fresh
142
- _d.label = 11;
143
- case 11: return [2 /*return*/];
144
- }
145
- });
54
+ async setupDatabase() {
55
+ const OrmConfig = getMikroOrmConfig({
56
+ mikroOrmEntities: this.mikroOrmEntities,
57
+ pathToMigrations: this.pathToMigrations,
58
+ clientUrl: this.clientUrl,
59
+ schema: this.schema,
146
60
  });
61
+ // Initializing the ORM
62
+ this.orm = await postgresql_1.MikroORM.init(OrmConfig);
63
+ this.manager = this.orm.em;
64
+ try {
65
+ await this.orm.getSchemaGenerator().ensureDatabase();
66
+ }
67
+ catch (err) {
68
+ console.log(err);
69
+ }
70
+ await this.manager?.execute(`CREATE SCHEMA IF NOT EXISTS "${this.schema ?? "public"}";`);
71
+ const pendingMigrations = await this.orm
72
+ .getMigrator()
73
+ .getPendingMigrations();
74
+ if (pendingMigrations && pendingMigrations.length > 0) {
75
+ await this.orm
76
+ .getMigrator()
77
+ .up({ migrations: pendingMigrations.map((m) => m.name) });
78
+ }
79
+ else {
80
+ await this.orm.schema.refreshDatabase(); // ensure db exists and is fresh
81
+ }
147
82
  },
148
- clearDatabase: function () {
149
- return __awaiter(this, void 0, void 0, function () {
150
- var _a;
151
- var _b, _c, _d, _e;
152
- return __generator(this, function (_f) {
153
- switch (_f.label) {
154
- case 0:
155
- if (this.orm === null) {
156
- throw new Error("ORM not configured");
157
- }
158
- return [4 /*yield*/, ((_b = this.manager) === null || _b === void 0 ? void 0 : _b.execute("DROP SCHEMA IF EXISTS \"".concat((_c = this.schema) !== null && _c !== void 0 ? _c : "public", "\" CASCADE;")))];
159
- case 1:
160
- _f.sent();
161
- return [4 /*yield*/, ((_d = this.manager) === null || _d === void 0 ? void 0 : _d.execute("CREATE SCHEMA IF NOT EXISTS \"".concat((_e = this.schema) !== null && _e !== void 0 ? _e : "public", "\";")))];
162
- case 2:
163
- _f.sent();
164
- _f.label = 3;
165
- case 3:
166
- _f.trys.push([3, 5, , 6]);
167
- return [4 /*yield*/, this.orm.close()];
168
- case 4:
169
- _f.sent();
170
- return [3 /*break*/, 6];
171
- case 5:
172
- _a = _f.sent();
173
- return [3 /*break*/, 6];
174
- case 6:
175
- this.orm = null;
176
- this.manager = null;
177
- return [2 /*return*/];
178
- }
179
- });
180
- });
83
+ async clearDatabase() {
84
+ if (this.orm === null) {
85
+ throw new Error("ORM not configured");
86
+ }
87
+ await this.manager?.execute(`DROP SCHEMA IF EXISTS "${this.schema ?? "public"}" CASCADE;`);
88
+ await this.manager?.execute(`CREATE SCHEMA IF NOT EXISTS "${this.schema ?? "public"}";`);
89
+ try {
90
+ await this.orm.close();
91
+ }
92
+ catch { }
93
+ this.orm = null;
94
+ this.manager = null;
181
95
  },
182
96
  };
183
97
  }
@@ -1 +1 @@
1
- {"version":3,"file":"database.js","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA2E;AAE3E,SAAgB,cAAc,CAAC,MAAe;;IAC5C,IAAM,OAAO,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,OAAO,mCAAI,WAAW,CAAA;IAClD,IAAM,WAAW,GAAG,MAAA,OAAO,CAAC,GAAG,CAAC,WAAW,mCAAI,EAAE,CAAA;IACjD,IAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAA;IAC3C,IAAM,OAAO,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,OAAO,CAAC,GAAG,CAAC,YAAY,CAAA;IAElD,OAAO,qBAAc,WAAW,SAC9B,WAAW,CAAC,CAAC,CAAC,WAAI,WAAW,CAAE,CAAC,CAAC,CAAC,EAAE,cAClC,OAAO,cAAI,OAAO,CAAE,CAAA;AAC1B,CAAC;AATD,wCASC;AAED,SAAgB,iBAAiB,CAAC,EAUjC;QATC,gBAAgB,sBAAA,EAChB,gBAAgB,sBAAA,EAChB,SAAS,eAAA,EACT,MAAM,YAAA;IAON,IAAM,MAAM,GAAG,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,cAAc,EAAE,CAAA;IAE5C,OAAO;QACL,IAAI,EAAE,YAAY;QAClB,SAAS,EAAE,MAAM;QACjB,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC;QACzC,MAAM,EAAE,MAAM,aAAN,MAAM,cAAN,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AE,CAAC;gBACtB,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAA;YACvC,CAAC;YAED,MAAM,IAAI,CAAC,OAAO,EAAE,OAAO,CACzB,0BAA0B,IAAI,CAAC,MAAM,IAAI,QAAQ,YAAY,CAC9D,CAAA;YAED,MAAM,IAAI,CAAC,OAAO,EAAE,OAAO,CACzB,gCAAgC,IAAI,CAAC,MAAM,IAAI,QAAQ,IAAI,CAC5D,CAAA;YAED,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAA;YACxB,CAAC;YAAC,MAAM,CAAC,CAAA,CAAC;YAEV,IAAI,CAAC,GAAG,GAAG,IAAI,CAAA;YACf,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QACrB,CAAC;KACF,CAAA;AACH,CAAC;AArGD,gDAqGC"}
package/dist/events.js CHANGED
@@ -1,67 +1,20 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  exports.waitSubscribersExecution = void 0;
40
4
  // Allows you to wait for all subscribers to execute for a given event. Only works with the local event bus.
41
- var waitSubscribersExecution = function (eventName, eventBus) {
42
- var subscriberPromises = [];
43
- eventBus.eventEmitter_.listeners(eventName).forEach(function (listener) {
5
+ const waitSubscribersExecution = (eventName, eventBus) => {
6
+ const subscriberPromises = [];
7
+ eventBus.eventEmitter_.listeners(eventName).forEach((listener) => {
44
8
  ;
45
9
  eventBus.eventEmitter_.removeListener("order.created", listener);
46
- var ok, nok;
47
- var promise = new Promise(function (resolve, reject) {
10
+ let ok, nok;
11
+ const promise = new Promise((resolve, reject) => {
48
12
  ok = resolve;
49
13
  nok = reject;
50
14
  });
51
15
  subscriberPromises.push(promise);
52
- var newListener = function () {
53
- var args2 = [];
54
- for (var _i = 0; _i < arguments.length; _i++) {
55
- args2[_i] = arguments[_i];
56
- }
57
- return __awaiter(void 0, void 0, void 0, function () {
58
- return __generator(this, function (_a) {
59
- switch (_a.label) {
60
- case 0: return [4 /*yield*/, listener.apply(eventBus, args2).then(ok).catch(nok)];
61
- case 1: return [2 /*return*/, _a.sent()];
62
- }
63
- });
64
- });
16
+ const newListener = async (...args2) => {
17
+ return await listener.apply(eventBus, args2).then(ok).catch(nok);
65
18
  };
66
19
  eventBus.eventEmitter_.on("order.created", newListener);
67
20
  });
@@ -1 +1 @@
1
- {"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,4GAA4G;AACrG,IAAM,wBAAwB,GAAG,UACtC,SAAiB,EACjB,QAAgC;IAEhC,IAAM,kBAAkB,GAAmB,EAAE,CAE5C;IAAC,QAAgB,CAAC,aAAa,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,UAAC,QAAQ;QACrE,CAAC;QAAC,QAAgB,CAAC,aAAa,CAAC,cAAc,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAA;QAE1E,IAAI,EAAE,EAAE,GAAG,CAAA;QACX,IAAM,OAAO,GAAG,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;YAC1C,EAAE,GAAG,OAAO,CAAA;YACZ,GAAG,GAAG,MAAM,CAAA;QACd,CAAC,CAAC,CAAA;QACF,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAEhC,IAAM,WAAW,GAAG;YAAO,eAAQ;iBAAR,UAAQ,EAAR,qBAAQ,EAAR,IAAQ;gBAAR,0BAAQ;;;;;gCAC1B,qBAAM,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAA;gCAAhE,sBAAO,SAAyD,EAAA;;;;SAC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BAAwB,4BAwBpC"}
package/dist/id-map.js CHANGED
@@ -3,23 +3,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- var randomatic_1 = __importDefault(require("randomatic"));
7
- var IdMap = /** @class */ (function () {
8
- function IdMap() {
9
- this.ids = {};
10
- }
11
- IdMap.prototype.getId = function (key, prefix, length) {
12
- if (prefix === void 0) { prefix = ""; }
13
- if (length === void 0) { length = 10; }
6
+ const randomatic_1 = __importDefault(require("randomatic"));
7
+ class IdMap {
8
+ ids = {};
9
+ getId(key, prefix = "", length = 10) {
14
10
  if (this.ids[key]) {
15
11
  return this.ids[key];
16
12
  }
17
- var id = "".concat(prefix && prefix + "_").concat((0, randomatic_1.default)("Aa0", length));
13
+ const id = `${prefix && prefix + "_"}${(0, randomatic_1.default)("Aa0", length)}`;
18
14
  this.ids[key] = id;
19
15
  return id;
20
- };
21
- return IdMap;
22
- }());
23
- var instance = new IdMap();
16
+ }
17
+ }
18
+ const instance = new IdMap();
24
19
  exports.default = instance;
25
20
  //# sourceMappingURL=id-map.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"id-map.js","sourceRoot":"","sources":["../src/id-map.ts"],"names":[],"mappings":";;;;;AAAA,0DAAkC;AAElC;IAAA;QACE,QAAG,GAAG,EAAE,CAAA;IAYV,CAAC;IAVC,qBAAK,GAAL,UAAM,GAAG,EAAE,MAAW,EAAE,MAAW;QAAxB,uBAAA,EAAA,WAAW;QAAE,uBAAA,EAAA,WAAW;QACjC,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAClB,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QACtB,CAAC;QAED,IAAM,EAAE,GAAG,UAAG,MAAM,IAAI,MAAM,GAAG,GAAG,SAAG,IAAA,oBAAS,EAAC,KAAK,EAAE,MAAM,CAAC,CAAE,CAAA;QACjE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAA;QAElB,OAAO,EAAE,CAAA;IACX,CAAC;IACH,YAAC;AAAD,CAAC,AAbD,IAaC;AAED,IAAM,QAAQ,GAAG,IAAI,KAAK,EAAE,CAAA;AAC5B,kBAAe,QAAQ,CAAA"}
1
+ {"version":3,"file":"id-map.js","sourceRoot":"","sources":["../src/id-map.ts"],"names":[],"mappings":";;;;;AAAA,4DAAkC;AAElC,MAAM,KAAK;IACT,GAAG,GAAG,EAAE,CAAA;IAER,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,EAAE,EAAE,MAAM,GAAG,EAAE;QACjC,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAClB,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QACtB,CAAC;QAED,MAAM,EAAE,GAAG,GAAG,MAAM,IAAI,MAAM,GAAG,GAAG,GAAG,IAAA,oBAAS,EAAC,KAAK,EAAE,MAAM,CAAC,EAAE,CAAA;QACjE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAA;QAElB,OAAO,EAAE,CAAA;IACX,CAAC;CACF;AAED,MAAM,QAAQ,GAAG,IAAI,KAAK,EAAE,CAAA;AAC5B,kBAAe,QAAQ,CAAA"}
@@ -1,106 +1,45 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  exports.initModules = void 0;
40
- var utils_1 = require("@medusajs/utils");
41
- function initModules(_a) {
42
- return __awaiter(this, arguments, void 0, function (_b) {
43
- function shutdown() {
44
- return __awaiter(this, void 0, void 0, function () {
45
- var _a;
46
- return __generator(this, function (_b) {
47
- switch (_b.label) {
48
- case 0:
49
- if (!shouldDestroyConnectionAutomatically) return [3 /*break*/, 3];
50
- return [4 /*yield*/, medusaApp.onApplicationPrepareShutdown()];
51
- case 1:
52
- _b.sent();
53
- return [4 /*yield*/, (0, utils_1.promiseAll)([
54
- (_a = sharedPgConnection.context) === null || _a === void 0 ? void 0 : _a.destroy(),
55
- sharedPgConnection.destroy(),
56
- medusaApp.onApplicationShutdown(),
57
- ])];
58
- case 2:
59
- _b.sent();
60
- return [3 /*break*/, 4];
61
- case 3:
62
- if (!preventConnectionDestroyWarning) {
63
- console.info("You are using a custom shared connection. The connection won't be destroyed automatically.");
64
- }
65
- _b.label = 4;
66
- case 4:
67
- moduleSdkImports.MedusaModule.clearInstances();
68
- return [2 /*return*/];
69
- }
70
- });
71
- });
72
- }
73
- var moduleSdkImports, sharedPgConnection, shouldDestroyConnectionAutomatically, medusaApp;
74
- var injectedDependencies = _b.injectedDependencies, databaseConfig = _b.databaseConfig, modulesConfig = _b.modulesConfig, joinerConfig = _b.joinerConfig, _c = _b.preventConnectionDestroyWarning, preventConnectionDestroyWarning = _c === void 0 ? false : _c;
75
- return __generator(this, function (_d) {
76
- switch (_d.label) {
77
- case 0:
78
- moduleSdkImports = require("@medusajs/modules-sdk");
79
- injectedDependencies !== null && injectedDependencies !== void 0 ? injectedDependencies : (injectedDependencies = {});
80
- sharedPgConnection = injectedDependencies === null || injectedDependencies === void 0 ? void 0 : injectedDependencies[utils_1.ContainerRegistrationKeys.PG_CONNECTION];
81
- shouldDestroyConnectionAutomatically = !sharedPgConnection;
82
- if (!sharedPgConnection) {
83
- sharedPgConnection = utils_1.ModulesSdkUtils.createPgConnection({
84
- clientUrl: databaseConfig.clientUrl,
85
- schema: databaseConfig.schema,
86
- });
87
- injectedDependencies[utils_1.ContainerRegistrationKeys.PG_CONNECTION] =
88
- sharedPgConnection;
89
- }
90
- return [4 /*yield*/, moduleSdkImports.MedusaApp({
91
- modulesConfig: modulesConfig,
92
- servicesConfig: joinerConfig,
93
- injectedDependencies: injectedDependencies,
94
- })];
95
- case 1:
96
- medusaApp = _d.sent();
97
- return [2 /*return*/, {
98
- medusaApp: medusaApp,
99
- shutdown: shutdown,
100
- }];
101
- }
4
+ const utils_1 = require("@medusajs/utils");
5
+ async function initModules({ injectedDependencies, databaseConfig, modulesConfig, joinerConfig, preventConnectionDestroyWarning = false, }) {
6
+ const moduleSdkImports = require("@medusajs/modules-sdk");
7
+ injectedDependencies ??= {};
8
+ let sharedPgConnection = injectedDependencies?.[utils_1.ContainerRegistrationKeys.PG_CONNECTION];
9
+ let shouldDestroyConnectionAutomatically = !sharedPgConnection;
10
+ if (!sharedPgConnection) {
11
+ sharedPgConnection = utils_1.ModulesSdkUtils.createPgConnection({
12
+ clientUrl: databaseConfig.clientUrl,
13
+ schema: databaseConfig.schema,
102
14
  });
15
+ injectedDependencies[utils_1.ContainerRegistrationKeys.PG_CONNECTION] =
16
+ sharedPgConnection;
17
+ }
18
+ const medusaApp = await moduleSdkImports.MedusaApp({
19
+ modulesConfig,
20
+ servicesConfig: joinerConfig,
21
+ injectedDependencies,
103
22
  });
23
+ async function shutdown() {
24
+ if (shouldDestroyConnectionAutomatically) {
25
+ await medusaApp.onApplicationPrepareShutdown();
26
+ await (0, utils_1.promiseAll)([
27
+ sharedPgConnection.context?.destroy(),
28
+ sharedPgConnection.destroy(),
29
+ medusaApp.onApplicationShutdown(),
30
+ ]);
31
+ }
32
+ else {
33
+ if (!preventConnectionDestroyWarning) {
34
+ console.info(`You are using a custom shared connection. The connection won't be destroyed automatically.`);
35
+ }
36
+ }
37
+ moduleSdkImports.MedusaModule.clearInstances();
38
+ }
39
+ return {
40
+ medusaApp,
41
+ shutdown,
42
+ };
104
43
  }
105
44
  exports.initModules = initModules;
106
45
  //# sourceMappingURL=init-modules.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"init-modules.js","sourceRoot":"","sources":["../src/init-modules.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,yCAIwB;AAkBx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AE;gBACrC,SAAS,CAAC,qBAAqB,EAAE;aAClC,CAAC,CAAA;QACJ,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,+BAA+B,EAAE,CAAC;gBACrC,OAAO,CAAC,IAAI,CACV,4FAA4F,CAC7F,CAAA;YACH,CAAC;QACH,CAAC;QACD,gBAAgB,CAAC,YAAY,CAAC,cAAc,EAAE,CAAA;IAChD,CAAC;IAED,OAAO;QACL,SAAS;QACT,QAAQ;KACT,CAAA;AACH,CAAC;AAtDD,kCAsDC"}
package/dist/jest.js CHANGED
@@ -1,73 +1,25 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  exports.afterAllHookDropDatabase = void 0;
40
- var pg_god_1 = require("pg-god");
4
+ const pg_god_1 = require("pg-god");
41
5
  function afterAllHookDropDatabase() {
42
- var _this = this;
43
- var _a, _b, _c;
44
- var DB_HOST = (_a = process.env.DB_HOST) !== null && _a !== void 0 ? _a : "localhost";
45
- var DB_USERNAME = (_b = process.env.DB_USERNAME) !== null && _b !== void 0 ? _b : "postgres";
46
- var DB_PASSWORD = (_c = process.env.DB_PASSWORD) !== null && _c !== void 0 ? _c : "";
47
- var DB_NAME = process.env.DB_TEMP_NAME || "";
48
- var pgGodCredentials = {
6
+ const DB_HOST = process.env.DB_HOST ?? "localhost";
7
+ const DB_USERNAME = process.env.DB_USERNAME ?? "postgres";
8
+ const DB_PASSWORD = process.env.DB_PASSWORD ?? "";
9
+ const DB_NAME = process.env.DB_TEMP_NAME || "";
10
+ const pgGodCredentials = {
49
11
  user: DB_USERNAME,
50
12
  password: DB_PASSWORD,
51
13
  host: DB_HOST,
52
14
  };
53
- afterAll(function () { return __awaiter(_this, void 0, void 0, function () {
54
- var e_1;
55
- return __generator(this, function (_a) {
56
- switch (_a.label) {
57
- case 0:
58
- _a.trys.push([0, 2, , 3]);
59
- return [4 /*yield*/, (0, pg_god_1.dropDatabase)({ databaseName: DB_NAME }, pgGodCredentials)];
60
- case 1:
61
- _a.sent();
62
- return [3 /*break*/, 3];
63
- case 2:
64
- e_1 = _a.sent();
65
- console.error("This might fail if it is run during the unit tests since there is no database to drop. Otherwise, please check what is the issue. ".concat(e_1.message));
66
- return [3 /*break*/, 3];
67
- case 3: return [2 /*return*/];
68
- }
69
- });
70
- }); });
15
+ afterAll(async () => {
16
+ try {
17
+ await (0, pg_god_1.dropDatabase)({ databaseName: DB_NAME }, pgGodCredentials);
18
+ }
19
+ catch (e) {
20
+ console.error(`This might fail if it is run during the unit tests since there is no database to drop. Otherwise, please check what is the issue. ${e.message}`);
21
+ }
22
+ });
71
23
  }
72
24
  exports.afterAllHookDropDatabase = afterAllHookDropDatabase;
73
25
  //# sourceMappingURL=jest.js.map