@medusajs/event-bus-local 0.0.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.
@@ -0,0 +1,6 @@
1
+ import { ModuleExports } from "@medusajs/medusa";
2
+ import LocalEventBus from "./services/event-bus-local";
3
+ export declare const service: typeof LocalEventBus;
4
+ export declare const loaders: (({ logger }: import("@medusajs/medusa").LoaderOptions) => Promise<void>)[];
5
+ declare const _default: ModuleExports;
6
+ export default _default;
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.loaders = exports.service = void 0;
7
+ var loaders_1 = __importDefault(require("./loaders"));
8
+ var event_bus_local_1 = __importDefault(require("./services/event-bus-local"));
9
+ exports.service = event_bus_local_1.default;
10
+ exports.loaders = [loaders_1.default];
11
+ exports.default = {
12
+ service: exports.service,
13
+ loaders: exports.loaders,
14
+ };
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AACA,sDAA8B;AAC9B,+EAAsD;AAEzC,QAAA,OAAO,GAAG,yBAAa,CAAA;AACvB,QAAA,OAAO,GAAG,CAAC,iBAAM,CAAC,CAAA;AAE/B,kBAAe;IACb,OAAO,iBAAA;IACP,OAAO,iBAAA;CACS,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { LoaderOptions } from "@medusajs/medusa";
2
+ declare const _default: ({ logger }: LoaderOptions) => Promise<void>;
3
+ export default _default;
@@ -0,0 +1,48 @@
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 (_) 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
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.default = (function (_a) {
40
+ var logger = _a.logger;
41
+ return __awaiter(void 0, void 0, void 0, function () {
42
+ return __generator(this, function (_b) {
43
+ logger === null || logger === void 0 ? void 0 : logger.warn("Local event bus module installed. Event bus will not be available.");
44
+ return [2 /*return*/];
45
+ });
46
+ });
47
+ });
48
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/loaders/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,mBAAe,UAAO,EAAyB;QAAvB,MAAM,YAAA;;;YAC5B,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,CACV,oEAAoE,CACrE,CAAA;;;;CACF,EAAA"}
@@ -0,0 +1,27 @@
1
+ import { EventHandler, IEventBusService, Logger, MedusaContainer, TransactionBaseService } from "@medusajs/medusa";
2
+ import { EntityManager } from "typeorm";
3
+ declare type InjectedDependencies = {
4
+ logger: Logger;
5
+ };
6
+ export default class LocalEventBus extends TransactionBaseService implements IEventBusService {
7
+ protected readonly container_: MedusaContainer & InjectedDependencies;
8
+ protected readonly logger_: Logger;
9
+ protected readonly manager_: EntityManager;
10
+ protected readonly transactionManager_: EntityManager | undefined;
11
+ constructor({ logger }: MedusaContainer & InjectedDependencies);
12
+ /**
13
+ * @return this
14
+ */
15
+ subscribe(event: string | symbol, handler: EventHandler): this;
16
+ /**
17
+ * @return this
18
+ */
19
+ unsubscribe(event: string | symbol, subscriber: EventHandler): this;
20
+ /**
21
+ * @return void
22
+ */
23
+ emit<T>(eventName: string, data: T, options?: {
24
+ delay?: number;
25
+ }): Promise<void>;
26
+ }
27
+ export {};
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ 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;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ var medusa_1 = require("@medusajs/medusa");
55
+ var LocalEventBus = /** @class */ (function (_super) {
56
+ __extends(LocalEventBus, _super);
57
+ function LocalEventBus(_a) {
58
+ var logger = _a.logger;
59
+ var _this =
60
+ // eslint-disable-next-line prefer-rest-params
61
+ _super.call(this, arguments[0]) || this;
62
+ _this.logger_ = logger;
63
+ return _this;
64
+ }
65
+ /**
66
+ * @return this
67
+ */
68
+ LocalEventBus.prototype.subscribe = function (event, handler) {
69
+ this.logger_.info("[".concat(event.toString(), "] Local Event Bus installed. Subscribe is unavailable."));
70
+ return this;
71
+ };
72
+ /**
73
+ * @return this
74
+ */
75
+ LocalEventBus.prototype.unsubscribe = function (event, subscriber) {
76
+ this.logger_.info("[".concat(event.toString(), "] Local Event Bus installed. Unsubscribe is unavailable."));
77
+ return this;
78
+ };
79
+ /**
80
+ * @return void
81
+ */
82
+ LocalEventBus.prototype.emit = function (eventName, data, options) {
83
+ if (options === void 0) { options = {}; }
84
+ return __awaiter(this, void 0, void 0, function () {
85
+ return __generator(this, function (_a) {
86
+ this.logger_.info("[".concat(eventName, "] Local Event Bus installed. Emitting events has no effect."));
87
+ return [2 /*return*/];
88
+ });
89
+ });
90
+ };
91
+ return LocalEventBus;
92
+ }(medusa_1.TransactionBaseService));
93
+ exports.default = LocalEventBus;
94
+ //# sourceMappingURL=event-bus-local.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event-bus-local.js","sourceRoot":"","sources":["../../src/services/event-bus-local.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAMyB;AAOzB;IACU,iCAAsB;IAQ9B,uBAAY,EAAkD;YAAhD,MAAM,YAAA;QAApB;QACE,8CAA8C;QAC9C,kBAAM,SAAS,CAAC,CAAC,CAAC,CAAC,SAGpB;QADC,KAAI,CAAC,OAAO,GAAG,MAAM,CAAA;;IACvB,CAAC;IAED;;OAEG;IACH,iCAAS,GAAT,UAAU,KAAsB,EAAE,OAAqB;QACrD,IAAI,CAAC,OAAO,CAAC,IAAI,CACf,WAAI,KAAK,CAAC,QAAQ,EAAE,2DAAwD,CAC7E,CAAA;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;OAEG;IACH,mCAAW,GAAX,UAAY,KAAsB,EAAE,UAAwB;QAC1D,IAAI,CAAC,OAAO,CAAC,IAAI,CACf,WAAI,KAAK,CAAC,QAAQ,EAAE,6DAA0D,CAC/E,CAAA;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;OAEG;IACG,4BAAI,GAAV,UACE,SAAiB,EACjB,IAAO,EACP,OAAgC;QAAhC,wBAAA,EAAA,YAAgC;;;gBAEhC,IAAI,CAAC,OAAO,CAAC,IAAI,CACf,WAAI,SAAS,gEAA6D,CAC3E,CAAA;;;;KACF;IACH,oBAAC;AAAD,CAAC,AAhDD,CACU,+BAAsB,GA+C/B"}
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@medusajs/event-bus-local",
3
+ "version": "0.0.0",
4
+ "description": "Local Event Bus Module for Medusa",
5
+ "main": "dist/index.js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/medusajs/medusa",
9
+ "directory": "packages/event-bus-local"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "author": "Medusa",
15
+ "license": "MIT",
16
+ "devDependencies": {
17
+ "@medusajs/medusa": "^1.6.5",
18
+ "cross-env": "^5.2.1",
19
+ "typescript": "^4.4.4"
20
+ },
21
+ "scripts": {
22
+ "watch": "tsc --build --watch",
23
+ "prepare": "cross-env NODE_ENV=production yarn run build",
24
+ "build": "tsc --build"
25
+ },
26
+ "peerDependencies": {
27
+ "@medusajs/medusa": "1.x.x",
28
+ "medusa-interfaces": "1.x.x"
29
+ },
30
+ "dependencies": {
31
+ "typeorm": "^0.2.45"
32
+ }
33
+ }