nestjs-transaction
Version:
A library that extracts and provides only some of the functions of the 'typeorm-transactional' npm module that are needed to operate in the Nestjs + TypeORM environment
37 lines • 1.53 kB
JavaScript
;
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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.storage = exports.ALSStroage = void 0;
const async_hooks_1 = require("async_hooks");
class ALSStroage {
constructor() {
this.storage = new async_hooks_1.AsyncLocalStorage();
}
get store() {
return this.storage.getStore() || new Map();
}
get(key) {
var _a;
return (_a = this.store) === null || _a === void 0 ? void 0 : _a.get(key);
}
set(key, value) {
var _a;
(_a = this.store) === null || _a === void 0 ? void 0 : _a.set(key, value);
}
run(cb) {
return __awaiter(this, void 0, void 0, function* () {
return this.storage.run(this.store, cb);
});
}
}
exports.ALSStroage = ALSStroage;
exports.storage = new ALSStroage();
//# sourceMappingURL=index.js.map