@medusajs/utils 1.8.1 → 1.8.2-next-20230420102356
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/dist/decorators/inject-entity-manager.d.ts +1 -1
- package/dist/decorators/inject-entity-manager.js +5 -3
- package/dist/decorators/inject-entity-manager.js.map +1 -1
- package/dist/event-bus/index.d.ts +6 -0
- package/dist/event-bus/index.js +23 -12
- package/dist/event-bus/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function InjectEntityManager(managerProperty?: string): MethodDecorator;
|
|
1
|
+
export declare function InjectEntityManager(shouldForceTransaction?: (target: any) => boolean, managerProperty?: string): MethodDecorator;
|
|
@@ -37,7 +37,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.InjectEntityManager = void 0;
|
|
40
|
-
function InjectEntityManager(managerProperty) {
|
|
40
|
+
function InjectEntityManager(shouldForceTransaction, managerProperty) {
|
|
41
|
+
if (shouldForceTransaction === void 0) { shouldForceTransaction = function () { return false; }; }
|
|
41
42
|
if (managerProperty === void 0) { managerProperty = "manager_"; }
|
|
42
43
|
return function (target, propertyKey, descriptor) {
|
|
43
44
|
if (!target.MedusaContextIndex_) {
|
|
@@ -52,13 +53,14 @@ function InjectEntityManager(managerProperty) {
|
|
|
52
53
|
args[_i] = arguments[_i];
|
|
53
54
|
}
|
|
54
55
|
return __awaiter(this, void 0, void 0, function () {
|
|
55
|
-
var context;
|
|
56
|
+
var shouldForceTransactionRes, context;
|
|
56
57
|
var _this = this;
|
|
57
58
|
return __generator(this, function (_b) {
|
|
58
59
|
switch (_b.label) {
|
|
59
60
|
case 0:
|
|
61
|
+
shouldForceTransactionRes = shouldForceTransaction(target);
|
|
60
62
|
context = (_a = args[argIndex]) !== null && _a !== void 0 ? _a : {};
|
|
61
|
-
if (!(context === null || context === void 0 ? void 0 : context.transactionManager)) return [3 /*break*/, 2];
|
|
63
|
+
if (!(!shouldForceTransactionRes && (context === null || context === void 0 ? void 0 : context.transactionManager))) return [3 /*break*/, 2];
|
|
62
64
|
return [4 /*yield*/, originalMethod.apply(this, args)];
|
|
63
65
|
case 1: return [2 /*return*/, _b.sent()];
|
|
64
66
|
case 2: return [4 /*yield*/, this[managerProperty].transaction(function (transactionManager) { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject-entity-manager.js","sourceRoot":"","sources":["../../src/decorators/inject-entity-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAgB,mBAAmB,CACjC,
|
|
1
|
+
{"version":3,"file":"inject-entity-manager.js","sourceRoot":"","sources":["../../src/decorators/inject-entity-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAgB,mBAAmB,CACjC,sBAA8D,EAC9D,eAAoC;IADpC,uCAAA,EAAA,uCAAyD,OAAA,KAAK,EAAL,CAAK;IAC9D,gCAAA,EAAA,4BAAoC;IAEpC,OAAO,UACL,MAAW,EACX,WAA4B,EAC5B,UAAe;QAEf,IAAI,CAAC,MAAM,CAAC,mBAAmB,EAAE;YAC/B,MAAM,IAAI,KAAK,CACb,iFAAiF,CAClF,CAAA;SACF;QAED,IAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAA;QAEvC,IAAM,QAAQ,GAAG,MAAM,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAA;QACxD,UAAU,CAAC,KAAK,GAAG;;YAAgB,cAAc;iBAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;gBAAd,yBAAc;;;;;;;;4BACzC,yBAAyB,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAA;4BAC1D,OAAO,GAAkB,MAAA,IAAI,CAAC,QAAQ,CAAC,mCAAI,EAAE,CAAA;iCAE/C,CAAA,CAAC,yBAAyB,KAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,kBAAkB,CAAA,CAAA,EAAzD,wBAAyD;4BACpD,qBAAM,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,EAAA;gCAA7C,sBAAO,SAAsC,EAAA;gCAGxC,qBAAM,IAAI,CAAC,eAAe,CAAC,CAAC,WAAW,CAC5C,UAAO,kBAAkB;;;;;4CACvB,IAAI,CAAC,QAAQ,CAAC,GAAG,MAAA,IAAI,CAAC,QAAQ,CAAC,mCAAI,EAAE,CAAA;4CACrC,IAAI,CAAC,QAAQ,CAAC,CAAC,kBAAkB,GAAG,kBAAkB,CAAA;4CAE/C,qBAAM,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,EAAA;gDAA7C,sBAAO,SAAsC,EAAA;;;iCAC9C,CACF,EAAA;gCAPD,sBAAO,SAON,EAAA;;;;SACF,CAAA;IACH,CAAC,CAAA;AACH,CAAC;AApCD,kDAoCC"}
|
|
@@ -4,6 +4,12 @@ export declare abstract class AbstractEventBusModuleService implements EventBusT
|
|
|
4
4
|
get eventToSubscribersMap(): Map<string | symbol, EventBusTypes.SubscriberDescriptor[]>;
|
|
5
5
|
abstract emit<T>(eventName: string, data: T, options: Record<string, unknown>): Promise<void>;
|
|
6
6
|
abstract emit<T>(data: EventBusTypes.EmitData<T>[]): Promise<void>;
|
|
7
|
+
protected storeSubscribers({ event, subscriberId, subscriber, }: {
|
|
8
|
+
event: string | symbol;
|
|
9
|
+
subscriberId: string;
|
|
10
|
+
subscriber: EventBusTypes.Subscriber;
|
|
11
|
+
}): void;
|
|
12
|
+
retrieveSubscribers(event: string | symbol): EventBusTypes.SubscriberDescriptor[] | undefined;
|
|
7
13
|
subscribe(eventName: string | symbol, subscriber: EventBusTypes.Subscriber, context?: EventBusTypes.SubscriberContext): this;
|
|
8
14
|
unsubscribe(eventName: string | symbol, subscriber: EventBusTypes.Subscriber, context: EventBusTypes.SubscriberContext): this;
|
|
9
15
|
}
|
package/dist/event-bus/index.js
CHANGED
|
@@ -22,8 +22,24 @@ var AbstractEventBusModuleService = /** @class */ (function () {
|
|
|
22
22
|
enumerable: false,
|
|
23
23
|
configurable: true
|
|
24
24
|
});
|
|
25
|
+
AbstractEventBusModuleService.prototype.storeSubscribers = function (_a) {
|
|
26
|
+
var _b;
|
|
27
|
+
var event = _a.event, subscriberId = _a.subscriberId, subscriber = _a.subscriber;
|
|
28
|
+
var newSubscriberDescriptor = { subscriber: subscriber, id: subscriberId };
|
|
29
|
+
var existingSubscribers = (_b = this.eventToSubscribersMap_.get(event)) !== null && _b !== void 0 ? _b : [];
|
|
30
|
+
var subscriberAlreadyExists = existingSubscribers.find(function (sub) { return sub.id === subscriberId; });
|
|
31
|
+
if (subscriberAlreadyExists) {
|
|
32
|
+
throw Error("Subscriber with id ".concat(subscriberId, " already exists"));
|
|
33
|
+
}
|
|
34
|
+
this.eventToSubscribersMap_.set(event, __spreadArray(__spreadArray([], existingSubscribers, true), [
|
|
35
|
+
newSubscriberDescriptor,
|
|
36
|
+
], false));
|
|
37
|
+
};
|
|
38
|
+
AbstractEventBusModuleService.prototype.retrieveSubscribers = function (event) {
|
|
39
|
+
return this.eventToSubscribersMap_.get(event);
|
|
40
|
+
};
|
|
25
41
|
AbstractEventBusModuleService.prototype.subscribe = function (eventName, subscriber, context) {
|
|
26
|
-
var _a
|
|
42
|
+
var _a;
|
|
27
43
|
if (typeof subscriber !== "function") {
|
|
28
44
|
throw new Error("Subscriber must be a function");
|
|
29
45
|
}
|
|
@@ -33,16 +49,11 @@ var AbstractEventBusModuleService = /** @class */ (function () {
|
|
|
33
49
|
*/
|
|
34
50
|
var randId = (0, ulid_1.ulid)();
|
|
35
51
|
var event = eventName.toString();
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
throw Error("Subscriber with id ".concat(subscriberId, " already exists"));
|
|
42
|
-
}
|
|
43
|
-
this.eventToSubscribersMap_.set(event, __spreadArray(__spreadArray([], existingSubscribers, true), [
|
|
44
|
-
newSubscriberDescriptor,
|
|
45
|
-
], false));
|
|
52
|
+
this.storeSubscribers({
|
|
53
|
+
event: event,
|
|
54
|
+
subscriberId: (_a = context === null || context === void 0 ? void 0 : context.subscriberId) !== null && _a !== void 0 ? _a : "".concat(event, "-").concat(randId),
|
|
55
|
+
subscriber: subscriber,
|
|
56
|
+
});
|
|
46
57
|
return this;
|
|
47
58
|
};
|
|
48
59
|
AbstractEventBusModuleService.prototype.unsubscribe = function (eventName, subscriber, context) {
|
|
@@ -50,7 +61,7 @@ var AbstractEventBusModuleService = /** @class */ (function () {
|
|
|
50
61
|
if (typeof subscriber !== "function") {
|
|
51
62
|
throw new Error("Subscriber must be a function");
|
|
52
63
|
}
|
|
53
|
-
var existingSubscribers = this.
|
|
64
|
+
var existingSubscribers = this.retrieveSubscribers(eventName);
|
|
54
65
|
if (existingSubscribers === null || existingSubscribers === void 0 ? void 0 : existingSubscribers.length) {
|
|
55
66
|
var subIndex = existingSubscribers === null || existingSubscribers === void 0 ? void 0 : existingSubscribers.findIndex(function (sub) { return sub.id === (context === null || context === void 0 ? void 0 : context.subscriberId); });
|
|
56
67
|
if (subIndex !== -1) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/event-bus/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,6BAA2B;AAE3B;IAAA;QAGY,2BAAsB,GAG5B,IAAI,GAAG,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/event-bus/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,6BAA2B;AAE3B;IAAA;QAGY,2BAAsB,GAG5B,IAAI,GAAG,EAAE,CAAA;IAiGf,CAAC;IA/FC,sBAAW,gEAAqB;aAAhC;YAIE,OAAO,IAAI,CAAC,sBAAsB,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IAAI,CAAA;IACb,CAAC;IAED,mDAAW,GAAX,UACE,SAA0B,EAC1B,UAAoC,EACpC,OAAwC;;QAExC,IAAI,OAAO,UAAU,KAAK,UAAU,EAAE;YACpC,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAA;SACjD;QAED,IAAM,mBAAmB,GAAG,IAAI,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAA;QAE/D,IAAI,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,MAAM,EAAE;YAC/B,IAAM,QAAQ,GAAG,mBAAmB,aAAnB,mBAAmB,uBAAnB,mBAAmB,CAAE,SAAS,CAC7C,UAAC,GAAG,IAAK,OAAA,GAAG,CAAC,EAAE,MAAK,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,CAAA,EAAhC,CAAgC,CAC1C,CAAA;YAED,IAAI,QAAQ,KAAK,CAAC,CAAC,EAAE;gBACnB,MAAA,IAAI,CAAC,sBAAsB;qBACxB,GAAG,CAAC,SAAS,CAAC,0CACb,MAAM,CAAC,QAAkB,EAAE,CAAC,CAAC,CAAA;aAClC;SACF;QAED,OAAO,IAAI,CAAA;IACb,CAAC;IACH,oCAAC;AAAD,CAAC,AAvGD,IAuGC;AAvGqB,sEAA6B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medusajs/utils",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.2-next-20230420102356",
|
|
4
4
|
"description": "Medusa utilities functions shared by Medusa core and Modules",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"author": "Medusa",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@medusajs/types": "1.8.
|
|
20
|
+
"@medusajs/types": "1.8.3-next-20230420102356",
|
|
21
21
|
"@types/express": "^4.17.17",
|
|
22
22
|
"cross-env": "^5.2.1",
|
|
23
23
|
"jest": "^25.5.4",
|