@autofleet/sequelize-utils 5.1.7 → 5.1.8

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.
package/dist/index.d.ts CHANGED
@@ -3,5 +3,6 @@ declare const _default: (sequelize: Sequelize) => {
3
3
  transactionWithRetry: any;
4
4
  httpBasedTransaction: any;
5
5
  registerModelEventHooks: any;
6
+ runAfterTransactionCommits: any;
6
7
  };
7
8
  export default _default;
package/dist/index.js CHANGED
@@ -59,9 +59,18 @@ exports.default = (sequelize) => {
59
59
  });
60
60
  };
61
61
  const registerModelEventHooks = (modelTableMapping) => model_event_hooks_1.default(sequelize, modelTableMapping);
62
+ const runAfterTransactionCommits = (cb, options) => {
63
+ if (options.transaction) {
64
+ options.transaction.afterCommit(() => cb());
65
+ }
66
+ else {
67
+ cb();
68
+ }
69
+ };
62
70
  return {
63
71
  httpBasedTransaction,
64
72
  transactionWithRetry,
65
73
  registerModelEventHooks,
74
+ runAfterTransactionCommits,
66
75
  };
67
76
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/sequelize-utils",
3
- "version": "5.1.7",
3
+ "version": "5.1.8",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  /* eslint-disable import/prefer-default-export */
2
- import { DatabaseError, Sequelize, Transaction } from 'sequelize';
2
+ import {
3
+ DatabaseError,
4
+ Sequelize,
5
+ Transaction,
6
+ Transactionable,
7
+ } from 'sequelize';
3
8
  import debug from 'debug';
4
9
  import addModelEventHooks from './model-event-hooks';
5
10
 
@@ -11,7 +16,8 @@ const abortErrorText = 'Transaction cancelled due to request cancellation';
11
16
  export default (sequelize: Sequelize): {
12
17
  transactionWithRetry: any,
13
18
  httpBasedTransaction: any,
14
- registerModelEventHooks: any
19
+ registerModelEventHooks: any,
20
+ runAfterTransactionCommits: any,
15
21
  } => {
16
22
  const transactionWithRetry = async (funcToRun: any, retriesCount = 2, options?: any): Promise<any> => {
17
23
  try {
@@ -64,9 +70,18 @@ export default (sequelize: Sequelize): {
64
70
 
65
71
  const registerModelEventHooks = (modelTableMapping) => addModelEventHooks(sequelize, modelTableMapping);
66
72
 
73
+ const runAfterTransactionCommits = (cb: () => any, options: Transactionable) => {
74
+ if (options.transaction) {
75
+ options.transaction.afterCommit(() => cb());
76
+ } else {
77
+ cb();
78
+ }
79
+ };
80
+
67
81
  return {
68
82
  httpBasedTransaction,
69
83
  transactionWithRetry,
70
84
  registerModelEventHooks,
85
+ runAfterTransactionCommits,
71
86
  };
72
87
  };