Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@medusajs/utils

Package Overview
Dependencies
Maintainers
2
Versions
2680
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@medusajs/utils - npm Package Compare versions

Comparing version 0.0.2-next-20230322094312 to 0.0.2-next-20230322120058

dist/search/abstract-service.d.ts

1

dist/bundles.d.ts
export * as DecoratorUtils from "./decorators";
export * as EventBusUtils from "./event-bus";
export * as SearchUtils from "./search";

3

dist/bundles.js

@@ -26,5 +26,6 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.EventBusUtils = exports.DecoratorUtils = void 0;
exports.SearchUtils = exports.EventBusUtils = exports.DecoratorUtils = void 0;
exports.DecoratorUtils = __importStar(require("./decorators"));
exports.EventBusUtils = __importStar(require("./event-bus"));
exports.SearchUtils = __importStar(require("./search"));
//# sourceMappingURL=bundles.js.map

@@ -10,3 +10,3 @@ "use strict";

if (propertyKey in target.MedusaContextIndex_) {
throw new Error(`Only one MedusaContext is allowed on method "${String(propertyKey)}".`);
throw new Error("Only one MedusaContext is allowed on method \"".concat(String(propertyKey), "\"."));
}

@@ -13,0 +13,0 @@ target.MedusaContextIndex_[propertyKey] = parameterIndex;

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
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;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.InjectEntityManager = void 0;
function InjectEntityManager(managerProperty = "manager_") {
function InjectEntityManager(managerProperty) {
if (managerProperty === void 0) { managerProperty = "manager_"; }
return function (target, propertyKey, descriptor) {
if (!target.MedusaContextIndex_) {
throw new Error(`To apply @InjectEntityManager you have to flag a parameter using @MedusaContext`);
throw new Error("To apply @InjectEntityManager you have to flag a parameter using @MedusaContext");
}
const originalMethod = descriptor.value;
const argIndex = target.MedusaContextIndex_[propertyKey];
descriptor.value = async function (...args) {
const context = args[argIndex] ?? {};
if (context?.transactionManager) {
return await originalMethod.apply(this, args);
var originalMethod = descriptor.value;
var argIndex = target.MedusaContextIndex_[propertyKey];
descriptor.value = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return await this[managerProperty].transaction(async (transactionManager) => {
args[argIndex] = args[argIndex] ?? {};
args[argIndex].transactionManager = transactionManager;
return await originalMethod.apply(this, args);
return __awaiter(this, void 0, void 0, function () {
var context;
var _this = this;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
context = (_a = args[argIndex]) !== null && _a !== void 0 ? _a : {};
if (!(context === null || context === void 0 ? void 0 : context.transactionManager)) return [3 /*break*/, 2];
return [4 /*yield*/, originalMethod.apply(this, args)];
case 1: return [2 /*return*/, _b.sent()];
case 2: return [4 /*yield*/, this[managerProperty].transaction(function (transactionManager) { return __awaiter(_this, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
args[argIndex] = (_a = args[argIndex]) !== null && _a !== void 0 ? _a : {};
args[argIndex].transactionManager = transactionManager;
return [4 /*yield*/, originalMethod.apply(this, args)];
case 1: return [2 /*return*/, _b.sent()];
}
});
}); })];
case 3: return [2 /*return*/, _b.sent()];
}
});
});

@@ -21,0 +80,0 @@ };

"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AbstractEventBusModuleService = void 0;
const ulid_1 = require("ulid");
class AbstractEventBusModuleService {
constructor() {
var ulid_1 = require("ulid");
var AbstractEventBusModuleService = /** @class */ (function () {
function AbstractEventBusModuleService() {
this.eventToSubscribersMap_ = new Map();
}
get eventToSubscribersMap() {
return this.eventToSubscribersMap_;
}
subscribe(eventName, subscriber, context) {
if (typeof subscriber !== `function`) {
Object.defineProperty(AbstractEventBusModuleService.prototype, "eventToSubscribersMap", {
get: function () {
return this.eventToSubscribersMap_;
},
enumerable: false,
configurable: true
});
AbstractEventBusModuleService.prototype.subscribe = function (eventName, subscriber, context) {
var _a, _b;
if (typeof subscriber !== "function") {
throw new Error("Subscriber must be a function");

@@ -20,34 +34,34 @@ }

*/
const randId = (0, ulid_1.ulid)();
const event = eventName.toString();
const subscriberId = context?.subscriberId ?? `${event}-${randId}`;
const newSubscriberDescriptor = { subscriber, id: subscriberId };
const existingSubscribers = this.eventToSubscribersMap_.get(event) ?? [];
const subscriberAlreadyExists = existingSubscribers.find((sub) => sub.id === subscriberId);
var randId = (0, ulid_1.ulid)();
var event = eventName.toString();
var subscriberId = (_a = context === null || context === void 0 ? void 0 : context.subscriberId) !== null && _a !== void 0 ? _a : "".concat(event, "-").concat(randId);
var newSubscriberDescriptor = { subscriber: subscriber, id: subscriberId };
var existingSubscribers = (_b = this.eventToSubscribersMap_.get(event)) !== null && _b !== void 0 ? _b : [];
var subscriberAlreadyExists = existingSubscribers.find(function (sub) { return sub.id === subscriberId; });
if (subscriberAlreadyExists) {
throw Error(`Subscriber with id ${subscriberId} already exists`);
throw Error("Subscriber with id ".concat(subscriberId, " already exists"));
}
this.eventToSubscribersMap_.set(event, [
...existingSubscribers,
this.eventToSubscribersMap_.set(event, __spreadArray(__spreadArray([], existingSubscribers, true), [
newSubscriberDescriptor,
]);
], false));
return this;
}
unsubscribe(eventName, subscriber, context) {
if (typeof subscriber !== `function`) {
};
AbstractEventBusModuleService.prototype.unsubscribe = function (eventName, subscriber, context) {
var _a;
if (typeof subscriber !== "function") {
throw new Error("Subscriber must be a function");
}
const existingSubscribers = this.eventToSubscribersMap_.get(eventName);
if (existingSubscribers?.length) {
const subIndex = existingSubscribers?.findIndex((sub) => sub.id === context?.subscriberId);
var existingSubscribers = this.eventToSubscribersMap_.get(eventName);
if (existingSubscribers === null || existingSubscribers === void 0 ? void 0 : existingSubscribers.length) {
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); });
if (subIndex !== -1) {
this.eventToSubscribersMap_
.get(eventName)
?.splice(subIndex, 1);
(_a = this.eventToSubscribersMap_
.get(eventName)) === null || _a === void 0 ? void 0 : _a.splice(subIndex, 1);
}
}
return this;
}
}
};
return AbstractEventBusModuleService;
}());
exports.AbstractEventBusModuleService = AbstractEventBusModuleService;
//# sourceMappingURL=index.js.map
export * from "./bundles";
export * from "./decorators";
export * from "./event-bus";
export * from "./search";

@@ -20,2 +20,3 @@ "use strict";

__exportStar(require("./event-bus"), exports);
__exportStar(require("./search"), exports);
//# sourceMappingURL=index.js.map
{
"name": "@medusajs/utils",
"version": "0.0.2-next-20230322094312",
"version": "0.0.2-next-20230322120058",
"description": "Medusa utilities functions shared by Medusa core and Modules",

@@ -20,3 +20,3 @@ "main": "dist/index.js",

"devDependencies": {
"@medusajs/types": "0.0.2-next-20230322094312",
"@medusajs/types": "0.0.2-next-20230322120058",
"cross-env": "^5.2.1",

@@ -29,3 +29,3 @@ "jest": "^25.5.4",

"peerDependencies": {
"@medusajs/types": "0.0.2-next-20230322094312"
"@medusajs/types": "0.0.2-next-20230322120058"
},

@@ -32,0 +32,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc