@cap-js-community/event-queue 1.3.1 → 1.3.2
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/package.json +2 -2
- package/src/initialize.js +8 -10
- package/src/outbox/eventQueueAsOutbox.js +16 -7
- package/src/shared/cdsHelper.js +7 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cap-js-community/event-queue",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "An event queue that enables secure transactional processing of asynchronous and periodic events, featuring instant event processing with Redis Pub/Sub and load distribution across all application instances.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"redis": "4.6.13",
|
|
46
46
|
"verror": "1.10.1",
|
|
47
|
-
"yaml": "2.
|
|
47
|
+
"yaml": "2.4.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@cap-js/hana": "^0.0.5",
|
package/src/initialize.js
CHANGED
|
@@ -84,21 +84,19 @@ const initialize = async ({
|
|
|
84
84
|
);
|
|
85
85
|
|
|
86
86
|
const logger = cds.log(COMPONENT);
|
|
87
|
-
config.fileContent = await readConfigFromFile(config.configFilePath);
|
|
88
87
|
config.checkRedisEnabled();
|
|
88
|
+
cds.on("connect", (service) => {
|
|
89
|
+
if (service.name === "db") {
|
|
90
|
+
config.processEventsAfterPublish && dbHandler.registerEventQueueDbHandler(service);
|
|
91
|
+
config.cleanupLocksAndEventsForDev && registerCleanupForDevDb().catch(() => {});
|
|
92
|
+
registerEventProcessors();
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
config.fileContent = await readConfigFromFile(config.configFilePath);
|
|
89
96
|
|
|
90
|
-
if (config.processEventsAfterPublish) {
|
|
91
|
-
cds.on("connect", (service) => {
|
|
92
|
-
if (service.name === "db") {
|
|
93
|
-
dbHandler.registerEventQueueDbHandler(service);
|
|
94
|
-
config.cleanupLocksAndEventsForDev && registerCleanupForDevDb().catch(() => {});
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
97
|
!config.skipCsnCheck && (await csnCheck());
|
|
99
98
|
|
|
100
99
|
monkeyPatchCAPOutbox();
|
|
101
|
-
registerEventProcessors();
|
|
102
100
|
registerCdsShutdown();
|
|
103
101
|
logger.info("event queue initialized", {
|
|
104
102
|
registerAsEventProcessor: config.registerAsEventProcessor,
|
|
@@ -68,21 +68,30 @@ function unboxed(srv) {
|
|
|
68
68
|
return srv[UNBOXED] || srv;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
const _mapToEventAndPublish = async (context, name,
|
|
71
|
+
const _mapToEventAndPublish = async (context, name, req) => {
|
|
72
|
+
let startAfter;
|
|
73
|
+
for (const header in req.headers ?? {}) {
|
|
74
|
+
if (header.toLocaleLowerCase() === "x-eventqueue-startafter") {
|
|
75
|
+
startAfter = req.headers[header];
|
|
76
|
+
delete req.headers[header];
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
72
80
|
const event = {
|
|
73
81
|
contextUser: context.user.id,
|
|
74
|
-
...(
|
|
75
|
-
...(
|
|
76
|
-
...(
|
|
77
|
-
...(
|
|
78
|
-
...(
|
|
79
|
-
...(
|
|
82
|
+
...(req._fromSend || (req.reply && { _fromSend: true })), // send or emit
|
|
83
|
+
...(req.inbound && { inbound: req.inbound }),
|
|
84
|
+
...(req.event && { event: req.event }),
|
|
85
|
+
...(req.data && { data: req.data }),
|
|
86
|
+
...(req.headers && { headers: req.headers }),
|
|
87
|
+
...(req.query && { query: req.query }),
|
|
80
88
|
};
|
|
81
89
|
|
|
82
90
|
await publishEvent(cds.tx(context), {
|
|
83
91
|
type: CDS_EVENT_TYPE,
|
|
84
92
|
subType: name,
|
|
85
93
|
payload: JSON.stringify(event),
|
|
94
|
+
...(startAfter && { startAfter }),
|
|
86
95
|
});
|
|
87
96
|
};
|
|
88
97
|
|
package/src/shared/cdsHelper.js
CHANGED
|
@@ -57,6 +57,13 @@ async function executeInNewTransaction(context = {}, transactionTag, fn, args, {
|
|
|
57
57
|
);
|
|
58
58
|
} else {
|
|
59
59
|
contextTx.context.user = user;
|
|
60
|
+
try {
|
|
61
|
+
contextTx.set?.({
|
|
62
|
+
"$user.id": user.id,
|
|
63
|
+
});
|
|
64
|
+
} catch {
|
|
65
|
+
/* empty */
|
|
66
|
+
}
|
|
60
67
|
await fn(contextTx, ...parameters);
|
|
61
68
|
}
|
|
62
69
|
}
|