UNPKG

@sphereon/ssi-sdk.data-store

Version:

71 lines 4.37 kB
"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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.EventLoggerStore = void 0; const ssi_types_1 = require("@sphereon/ssi-types"); const debug_1 = __importDefault(require("debug")); const AbstractEventLoggerStore_1 = require("./AbstractEventLoggerStore"); const AuditEventEntity_1 = require("../entities/eventLogger/AuditEventEntity"); const MappingUtils_1 = require("../utils/eventLogger/MappingUtils"); const debug = (0, debug_1.default)('sphereon:ssi-sdk:event-store'); class EventLoggerStore extends AbstractEventLoggerStore_1.AbstractEventLoggerStore { constructor(dbConnection) { super(); this.getAuditEvents = (args) => __awaiter(this, void 0, void 0, function* () { const { filter = [] } = args !== null && args !== void 0 ? args : {}; const auditEventsFilter = filter.map((item) => (Object.assign(Object.assign({}, item), { type: ssi_types_1.LoggingEventType.AUDIT }))); if (auditEventsFilter.length === 0) { auditEventsFilter.push({ type: ssi_types_1.LoggingEventType.AUDIT }); } const connection = yield this.dbConnection; debug('Getting audit events', args); const result = yield connection.getRepository(AuditEventEntity_1.AuditEventEntity).find({ where: auditEventsFilter, }); return result.map((event) => (0, MappingUtils_1.auditEventFrom)(event)); }); this.storeAuditEvent = (args) => __awaiter(this, void 0, void 0, function* () { const { event } = args; const auditEventEntity = (0, MappingUtils_1.auditEventEntityFrom)(event); const connection = yield this.dbConnection; debug('Storing audit event', auditEventEntity); const createdResult = yield connection.getRepository(AuditEventEntity_1.AuditEventEntity).save(auditEventEntity); return (0, MappingUtils_1.auditEventFrom)(createdResult); }); this.getActivityEvents = (args) => __awaiter(this, void 0, void 0, function* () { const { filter = [] } = args !== null && args !== void 0 ? args : {}; const activityEventsFilter = filter.map((item) => (Object.assign(Object.assign({}, item), { type: ssi_types_1.LoggingEventType.ACTIVITY }))); if (activityEventsFilter.length === 0) { activityEventsFilter.push({ type: ssi_types_1.LoggingEventType.ACTIVITY }); } const connection = yield this.dbConnection; debug('Getting activity events', args); const result = yield connection.getRepository(AuditEventEntity_1.AuditEventEntity).find({ where: activityEventsFilter, }); return result.map((event) => (0, MappingUtils_1.activityEventFrom)(event)); }); this.storeActivityEvent = (args) => __awaiter(this, void 0, void 0, function* () { const { event } = args; const activityEventEntity = (0, MappingUtils_1.activityEventEntityFrom)(event); const connection = yield this.dbConnection; debug('Storing activity event', activityEventEntity); const createdResult = yield connection.getRepository(AuditEventEntity_1.AuditEventEntity).save(activityEventEntity); return (0, MappingUtils_1.activityEventFrom)(createdResult); }); this.dbConnection = dbConnection; } } exports.EventLoggerStore = EventLoggerStore; //# sourceMappingURL=EventLoggerStore.js.map