@cap-js-community/event-queue 1.8.1 → 1.8.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cap-js-community/event-queue",
3
- "version": "1.8.1",
3
+ "version": "1.8.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
  "types": "src/index.d.ts",
@@ -75,13 +75,19 @@
75
75
  "disableRedis": false
76
76
  },
77
77
  "[test]": {
78
- "isEventQueueActive": true,
78
+ "isEventQueueActive": false,
79
79
  "registerAsEventProcessor": false,
80
80
  "updatePeriodicEvents": false,
81
81
  "insertEventsBeforeCommit": false
82
82
  }
83
83
  },
84
84
  "requires": {
85
+ "redis-eventQueue": {
86
+ "options": {},
87
+ "vcap": {
88
+ "label": "redis-cache"
89
+ }
90
+ },
85
91
  "event-queue": {
86
92
  "model": "@cap-js-community/event-queue"
87
93
  }
package/src/config.js CHANGED
@@ -113,7 +113,7 @@ class Config {
113
113
  }
114
114
 
115
115
  _checkRedisIsBound() {
116
- return !!this.#env.redisCredentialsFromEnv;
116
+ return !!this.#env.redisRequires?.credentials;
117
117
  }
118
118
 
119
119
  shouldBeProcessedInThisApplication(type, subType) {
package/src/shared/env.js CHANGED
@@ -1,25 +1,24 @@
1
1
  "use strict";
2
2
 
3
+ const cds = require("@sap/cds");
4
+
3
5
  let instance;
4
6
 
5
7
  class Env {
6
- #vcapServices;
7
8
  #vcapApplication;
8
9
  #vcapApplicationInstance;
9
10
 
10
11
  constructor() {
11
12
  try {
12
- this.#vcapServices = JSON.parse(process.env.VCAP_SERVICES);
13
13
  this.#vcapApplication = JSON.parse(process.env.VCAP_APPLICATION);
14
14
  } catch {
15
- this.#vcapServices = {};
16
15
  this.#vcapApplication = {};
17
16
  }
18
17
  this.#vcapApplicationInstance = Number(process.env.CF_INSTANCE_INDEX);
19
18
  }
20
19
 
21
- get redisCredentialsFromEnv() {
22
- return this.#vcapServices["redis-cache"]?.[0]?.credentials;
20
+ get redisRequires() {
21
+ return cds.requires["redis-eventQueue"] ?? cds.requires["redis"];
23
22
  }
24
23
 
25
24
  get applicationName() {
@@ -30,14 +29,6 @@ class Env {
30
29
  return this.#vcapApplicationInstance;
31
30
  }
32
31
 
33
- set vcapServices(value) {
34
- this.#vcapServices = value;
35
- }
36
-
37
- get vcapServices() {
38
- return this.#vcapServices;
39
- }
40
-
41
32
  set applicationInstance(value) {
42
33
  this.#vcapApplicationInstance = value;
43
34
  }
@@ -27,24 +27,30 @@ const createMainClientAndConnect = (options) => {
27
27
  return mainClientPromise;
28
28
  };
29
29
 
30
- const _createClientBase = (redisOptions) => {
30
+ const _createClientBase = (redisOptions = {}) => {
31
31
  const env = getEnvInstance();
32
32
  try {
33
- const credentials = env.redisCredentialsFromEnv;
34
- const redisIsCluster = credentials.cluster_mode;
35
- const url = credentials.uri.replace(/(?<=rediss:\/\/)[\w-]+?(?=:)/, "");
36
- if (redisIsCluster) {
33
+ const { credentials, options } = env.redisRequires;
34
+ const socket = Object.assign(
35
+ {
36
+ host: credentials.hostname,
37
+ tls: !!credentials.tls,
38
+ port: credentials.port,
39
+ },
40
+ options?.socket,
41
+ redisOptions.socket
42
+ );
43
+ const socketOptions = Object.assign({}, options, redisOptions, {
44
+ password: redisOptions.password ?? options.password ?? credentials.password,
45
+ socket,
46
+ });
47
+ if (credentials.cluster_mode) {
37
48
  return redis.createCluster({
38
- rootNodes: [{ url }],
39
- // https://github.com/redis/node-redis/issues/1782
40
- defaults: {
41
- password: credentials.password,
42
- socket: { tls: credentials.tls },
43
- ...redisOptions,
44
- },
49
+ rootNodes: [socketOptions],
50
+ defaults: socketOptions,
45
51
  });
46
52
  }
47
- return redis.createClient({ url, ...redisOptions });
53
+ return redis.createClient(socketOptions);
48
54
  } catch (err) {
49
55
  throw EventQueueError.redisConnectionFailure(err);
50
56
  }