@autofleet/sequelize-utils 5.1.5 → 5.1.7

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
@@ -1,8 +1,7 @@
1
1
  import { Sequelize } from 'sequelize';
2
- import addModelEventHooks from './model-event-hooks';
3
2
  declare const _default: (sequelize: Sequelize) => {
4
3
  transactionWithRetry: any;
5
4
  httpBasedTransaction: any;
6
- addModelEventHooks: any;
5
+ registerModelEventHooks: any;
7
6
  };
8
7
  export default _default;
package/dist/index.js CHANGED
@@ -20,7 +20,7 @@ exports.default = (sequelize) => {
20
20
  return transValue;
21
21
  }
22
22
  catch (e) {
23
- if (e instanceof sequelize_1.DatabaseError) {
23
+ if (e instanceof sequelize_1.DatabaseError || e?.constructor?.name === 'DatabaseError') {
24
24
  if (retriesCount === 0) {
25
25
  log('error inside transactionWithRetry - will stop retry', e);
26
26
  throw e;
@@ -58,9 +58,10 @@ exports.default = (sequelize) => {
58
58
  }
59
59
  });
60
60
  };
61
+ const registerModelEventHooks = (modelTableMapping) => model_event_hooks_1.default(sequelize, modelTableMapping);
61
62
  return {
62
63
  httpBasedTransaction,
63
64
  transactionWithRetry,
64
- addModelEventHooks: model_event_hooks_1.default,
65
+ registerModelEventHooks,
65
66
  };
66
67
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/sequelize-utils",
3
- "version": "5.1.5",
3
+ "version": "5.1.7",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -11,7 +11,7 @@ const abortErrorText = 'Transaction cancelled due to request cancellation';
11
11
  export default (sequelize: Sequelize): {
12
12
  transactionWithRetry: any,
13
13
  httpBasedTransaction: any,
14
- addModelEventHooks: any
14
+ registerModelEventHooks: any
15
15
  } => {
16
16
  const transactionWithRetry = async (funcToRun: any, retriesCount = 2, options?: any): Promise<any> => {
17
17
  try {
@@ -22,7 +22,7 @@ export default (sequelize: Sequelize): {
22
22
  });
23
23
  return transValue;
24
24
  } catch (e) {
25
- if (e instanceof DatabaseError) {
25
+ if (e instanceof DatabaseError || e?.constructor?.name === 'DatabaseError') {
26
26
  if (retriesCount === 0) {
27
27
  log('error inside transactionWithRetry - will stop retry', e);
28
28
  throw e;
@@ -62,9 +62,11 @@ export default (sequelize: Sequelize): {
62
62
  });
63
63
  };
64
64
 
65
+ const registerModelEventHooks = (modelTableMapping) => addModelEventHooks(sequelize, modelTableMapping);
66
+
65
67
  return {
66
68
  httpBasedTransaction,
67
69
  transactionWithRetry,
68
- addModelEventHooks,
70
+ registerModelEventHooks,
69
71
  };
70
72
  };