@autofleet/sequelize-utils 5.1.7 → 5.1.9
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 +1 -0
- package/dist/index.js +9 -0
- package/dist/model-event-hooks.js +0 -2
- package/package.json +1 -1
- package/src/index.ts +17 -2
- package/src/model-event-hooks.ts +0 -2
package/dist/index.d.ts
CHANGED
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
|
};
|
|
@@ -23,7 +23,6 @@ const addModelEventHooks = async (sequelize, modelTableMapping) => {
|
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
25
|
sequelize.addHook('afterSave', async (savedObject, options) => {
|
|
26
|
-
logger_1.default.info('dimTables after save start', { savedObject });
|
|
27
26
|
if (options.transaction) {
|
|
28
27
|
options.transaction.afterCommit(() => updateEventToDimTable(savedObject));
|
|
29
28
|
}
|
|
@@ -32,7 +31,6 @@ const addModelEventHooks = async (sequelize, modelTableMapping) => {
|
|
|
32
31
|
}
|
|
33
32
|
});
|
|
34
33
|
sequelize.addHook('afterDestroy', async (savedObject, options) => {
|
|
35
|
-
logger_1.default.info('dimTables after save start', { savedObject });
|
|
36
34
|
if (options.transaction) {
|
|
37
35
|
options.transaction.afterCommit(() => updateEventToDimTable(savedObject, true));
|
|
38
36
|
}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
/* eslint-disable import/prefer-default-export */
|
|
2
|
-
import {
|
|
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
|
};
|
package/src/model-event-hooks.ts
CHANGED
|
@@ -31,7 +31,6 @@ const addModelEventHooks = async (sequelize: Sequelize, modelTableMapping: Model
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
sequelize.addHook('afterSave', async (savedObject, options) => {
|
|
34
|
-
logger.info('dimTables after save start', { savedObject });
|
|
35
34
|
if (options.transaction) {
|
|
36
35
|
options.transaction.afterCommit(() => updateEventToDimTable(savedObject));
|
|
37
36
|
} else {
|
|
@@ -39,7 +38,6 @@ const addModelEventHooks = async (sequelize: Sequelize, modelTableMapping: Model
|
|
|
39
38
|
}
|
|
40
39
|
});
|
|
41
40
|
sequelize.addHook('afterDestroy', async (savedObject, options) => {
|
|
42
|
-
logger.info('dimTables after save start', { savedObject });
|
|
43
41
|
if (options.transaction) {
|
|
44
42
|
options.transaction.afterCommit(() => updateEventToDimTable(savedObject, true));
|
|
45
43
|
} else {
|