@golemio/audit-logs 1.0.0 → 1.0.1-dev.1652858761

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.
@@ -2,9 +2,11 @@ import { ILogger } from "@golemio/core/dist/helpers";
2
2
  import { IDatabaseConnector } from "@golemio/core/dist/helpers/data-access/postgres/IDatabaseConnector";
3
3
  import { IAuditLog } from "../interfaces/IAuditLog";
4
4
  import { IAuditLogsConfig } from "../interfaces/IAuditLogsConfig";
5
+ import { Transaction } from "@golemio/core/dist/shared/sequelize";
5
6
  export declare class AuditLogger {
6
7
  private auditLogsRepository;
7
8
  private auditLogTransformation;
8
9
  constructor(databaseConnector: IDatabaseConnector, logger: ILogger, config: IAuditLogsConfig);
9
- log(auditLog: IAuditLog): Promise<void>;
10
+ log(auditLog: IAuditLog, transaction?: Transaction): Promise<void>;
11
+ batchLog(auditLogs: IAuditLog[], transaction?: Transaction): Promise<void>;
10
12
  }
@@ -17,10 +17,16 @@ class AuditLogger {
17
17
  this.auditLogsRepository = new AuditLogsRepository_1.AuditLogsRepository(databaseConnector, logger, config);
18
18
  this.auditLogTransformation = new AuditLogTransformation_1.AuditLogTransformation();
19
19
  }
20
- log(auditLog) {
20
+ log(auditLog, transaction) {
21
21
  return __awaiter(this, void 0, void 0, function* () {
22
22
  const transformedAuditLog = this.auditLogTransformation.transformElement(auditLog);
23
- yield this.auditLogsRepository.insert(transformedAuditLog);
23
+ yield this.auditLogsRepository.insert(transformedAuditLog, transaction);
24
+ });
25
+ }
26
+ batchLog(auditLogs, transaction) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ const transformedAuditLogs = this.auditLogTransformation.transformArray(auditLogs);
29
+ yield this.auditLogsRepository.bulkInsert(transformedAuditLogs, transaction);
24
30
  });
25
31
  }
26
32
  }
@@ -1 +1 @@
1
- {"version":3,"file":"AuditLogger.js","sourceRoot":"","sources":["../../src/helpers/AuditLogger.ts"],"names":[],"mappings":";;;;;;;;;;;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AmB,CAAC,UAAU,CAAC,oBAAoB,EAAE,WAAW,CAAC,CAAC;QACjF,CAAC;KAAA;CACJ;AAlBD,kCAkBC"}
@@ -2,7 +2,7 @@ import { ILogger } from "@golemio/core/dist/helpers";
2
2
  import { IDatabaseConnector } from "@golemio/core/dist/helpers/data-access/postgres/IDatabaseConnector";
3
3
  import { AbstractValidatableRepository } from "@golemio/core/dist/helpers/data-access/postgres/repositories/AbstractValidatableRepository";
4
4
  import { JSONSchemaValidator } from "@golemio/core/dist/shared/golemio-validator";
5
- import { ModelStatic } from "@golemio/core/dist/shared/sequelize";
5
+ import { ModelStatic, Transaction } from "@golemio/core/dist/shared/sequelize";
6
6
  import { IAuditLogsConfig } from "../interfaces/IAuditLogsConfig";
7
7
  import { AuditLogsModel } from "../models/AuditLogsModel";
8
8
  import { IAuditLog } from "../models/interfaces/IAuditLog";
@@ -14,5 +14,6 @@ export declare class AuditLogsRepository extends AbstractValidatableRepository {
14
14
  schema: string;
15
15
  private sequelizeModel;
16
16
  constructor(connector: IDatabaseConnector, logger: ILogger, config: IAuditLogsConfig);
17
- insert(data: IAuditLog): Promise<ReturnType<ModelStatic<AuditLogsModel>["create"]>>;
17
+ insert(data: IAuditLog, transaction?: Transaction): Promise<ReturnType<ModelStatic<AuditLogsModel>["create"]>>;
18
+ bulkInsert(data: IAuditLog[], transaction?: Transaction): Promise<ReturnType<ModelStatic<AuditLogsModel>["create"]>>;
18
19
  }
@@ -27,11 +27,11 @@ class AuditLogsRepository extends AbstractValidatableRepository_1.AbstractValida
27
27
  .getConnection()
28
28
  .define(this.tableName, AuditLogsModel_1.AuditLogsModel.attributeModel, { schema: this.schema, updatedAt: false });
29
29
  }
30
- insert(data) {
30
+ insert(data, transaction) {
31
31
  var _a;
32
32
  return __awaiter(this, void 0, void 0, function* () {
33
33
  try {
34
- return yield this.sequelizeModel.create(data);
34
+ return yield this.sequelizeModel.create(data, { transaction });
35
35
  }
36
36
  catch (err) {
37
37
  if (err instanceof sequelize_1.ValidationError && ((_a = err.errors) === null || _a === void 0 ? void 0 : _a.length) > 0) {
@@ -45,6 +45,24 @@ class AuditLogsRepository extends AbstractValidatableRepository_1.AbstractValida
45
45
  }
46
46
  });
47
47
  }
48
+ bulkInsert(data, transaction) {
49
+ var _a;
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ try {
52
+ return yield this.sequelizeModel.bulkCreate(data, { transaction });
53
+ }
54
+ catch (err) {
55
+ if (err instanceof sequelize_1.ValidationError && ((_a = err.errors) === null || _a === void 0 ? void 0 : _a.length) > 0) {
56
+ const mappedErrors = err.errors.map((e) => `${e.message} (${e.value})`).join(", ");
57
+ throw new golemio_errors_1.ValidationError(`Validation error in bulkInsert: ${mappedErrors}`, this.constructor.name, err);
58
+ }
59
+ if (err instanceof sequelize_1.DatabaseError) {
60
+ throw new golemio_errors_1.GeneralError(`Error in bulkInsert: ${err.parent}`, this.constructor.name, err);
61
+ }
62
+ throw new golemio_errors_1.GeneralError("Error in bulkInsert", this.constructor.name, err);
63
+ }
64
+ });
65
+ }
48
66
  }
49
67
  exports.AuditLogsRepository = AuditLogsRepository;
50
68
  //# sourceMappingURL=AuditLogsRepository.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AuditLogsRepository.js","sourceRoot":"","sources":["../../src/repositories/AuditLogsRepository.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,8IAA2I;AAC3I,6EAAyF;AACzF,mFAAkF;AAClF,mEAI6C;AAE7C,6DAA0D;AAG1D,MAAa,mBAAoB,SAAQ,6DAA6B;IAOlE,YAAY,SAA6B,EAAU,MAAe,EAAU,MAAwB;QAChG,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QADsB,WAAM,GAAN,MAAM,CAAS;QAAU,WAAM,GAAN,MAAM,CAAkB;QAL7F,cAAS,GAAG,+BAAc,CAAC,SAAS,CAAC;QAOxC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;QACjC,IAAI,C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;AAhDD,kDAgDC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@golemio/audit-logs",
3
- "version": "1.0.0",
3
+ "version": "1.0.1-dev.1652858761",
4
4
  "description": "Golemio Audit Logs Module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",