@ivfuture/ecomm-event-bus-local
Advanced tools
Comparing version 1.58.0 to 1.58.1
/// <reference types="node" /> | ||
import { MedusaContainer } from "@ivfuture/ecomm-modules-sdk"; | ||
import { EventEmitter } from "events"; | ||
import { EmitData, EventBusTypes, Logger, Subscriber } from "@ivfuture/ecomm-types"; | ||
import { AbstractEventBusModuleService } from "@ivfuture/ecomm-utils"; | ||
import { EventEmitter } from "events"; | ||
type InjectedDependencies = { | ||
logger: Logger; | ||
}; | ||
export default class LocalEventBusService extends AbstractEventBusModuleService { | ||
import { AbstractEventBusModuleService } from "@ivfuture/ecomm-core"; | ||
import { InjectedDependencies } from "../types"; | ||
declare class LocalEventBusService extends AbstractEventBusModuleService { | ||
isDefault: boolean; | ||
protected readonly logger_: Logger; | ||
protected readonly eventEmitter_: EventEmitter; | ||
constructor({ logger }: MedusaContainer & InjectedDependencies); | ||
emit<T>(eventName: string, data: T, options: Record<string, unknown>): Promise<void>; | ||
storeSubscribers: (args: { | ||
event: string | symbol; | ||
subscriberId: string; | ||
subscriber: Subscriber; | ||
}) => void; | ||
constructor({ logger }: InjectedDependencies); | ||
emit<T>(eventName: string, data: T, options?: Record<string, unknown>): Promise<void>; | ||
/** | ||
@@ -22,2 +25,2 @@ * Emit a number of events | ||
} | ||
export {}; | ||
export default LocalEventBusService; |
@@ -12,9 +12,6 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ecomm_utils_1 = require("@ivfuture/ecomm-utils"); | ||
const events_1 = require("events"); | ||
const ulid_1 = require("ulid"); | ||
const eventEmitter = new events_1.EventEmitter(); | ||
eventEmitter.setMaxListeners(Infinity); | ||
// eslint-disable-next-line max-len | ||
class LocalEventBusService extends ecomm_utils_1.AbstractEventBusModuleService { | ||
const ecomm_core_1 = require("@ivfuture/ecomm-core"); | ||
class LocalEventBusService extends ecomm_core_1.AbstractEventBusModuleService { | ||
constructor({ logger }) { | ||
@@ -24,4 +21,15 @@ // @ts-ignore | ||
super(...arguments); | ||
this.isDefault = false; | ||
this.logger_ = logger; | ||
this.eventEmitter_ = eventEmitter; | ||
this.eventEmitter_ = new events_1.EventEmitter(); | ||
this.eventEmitter_.setMaxListeners(Infinity); | ||
this.storeSubscribers = ({ event, subscriberId, subscriber }) => { | ||
var _a; | ||
if (!this.eventToSubscribersMap.has(event)) { | ||
this.eventToSubscribersMap.set(event, []); | ||
} | ||
(_a = this.eventToSubscribersMap | ||
.get(event)) === null || _a === void 0 ? void 0 : _a.push({ id: subscriberId, subscriber }); | ||
}; | ||
this.logger_.warn("Local Event Bus installed. This is not recommended for production. "); | ||
} | ||
@@ -59,8 +67,7 @@ emit(eventOrData, data, options = {}) { | ||
unsubscribe(event, subscriber, context) { | ||
var _a; | ||
const existingSubscribers = this.eventToSubscribersMap_.get(event); | ||
const existingSubscribers = this.eventToSubscribersMap.get(event); | ||
if (existingSubscribers === null || existingSubscribers === void 0 ? void 0 : existingSubscribers.length) { | ||
const subIndex = existingSubscribers === null || existingSubscribers === void 0 ? void 0 : existingSubscribers.findIndex((sub) => sub.id === (context === null || context === void 0 ? void 0 : context.subscriberId)); | ||
if (subIndex !== -1) { | ||
(_a = this.eventToSubscribersMap_.get(event)) === null || _a === void 0 ? void 0 : _a.splice(subIndex, 1); | ||
existingSubscribers === null || existingSubscribers === void 0 ? void 0 : existingSubscribers.splice(subIndex, 1); | ||
} | ||
@@ -67,0 +74,0 @@ } |
{ | ||
"name": "@ivfuture/ecomm-event-bus-local", | ||
"version": "1.58.0", | ||
"version": "1.58.1", | ||
"description": "Local Event Bus Module for Medusa", | ||
@@ -20,3 +20,3 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"@ivfuture/ecomm-types": "1.58.0", | ||
"@ivfuture/ecomm-types": "1.58.1", | ||
"cross-env": "^7.0.3", | ||
@@ -36,7 +36,7 @@ "jest": "^29.7.0", | ||
"dependencies": { | ||
"@ivfuture/ecomm-modules-sdk": "1.58.0", | ||
"@ivfuture/ecomm-utils": "1.58.0", | ||
"@ivfuture/ecomm-core": "2.70.1", | ||
"@ivfuture/ecomm-utils": "1.58.1", | ||
"ulid": "^2.3.0" | ||
}, | ||
"gitHead": "0316a5b6db8ac9d784488999e6b3a804ae62858e" | ||
"gitHead": "51656d6161670cd5fc2d90974cc5f2cf41fd097b" | ||
} |
Sorry, the diff of this file is not supported yet
12306
9
107
+ Added@ivfuture/ecomm-core@2.70.1
- Removed@ivfuture/ecomm-modules-sdk@1.58.0
Updated@ivfuture/ecomm-utils@1.58.1