@cap-js-community/common 0.1.2 → 0.1.4

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/README.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # CAP Node.js Community Common
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/@cap-js-community/common)](https://www.npmjs.com/package/@cap-js-community/common)
4
+ [![monthly downloads](https://img.shields.io/npm/dm/@cap-js-community/common)](https://www.npmjs.com/package/@cap-js-community/common)
5
+ [![REUSE status](https://api.reuse.software/badge/github.com/cap-js-community/common)](https://api.reuse.software/info/github.com/cap-js-community/common)
6
+ [![Main CI](https://github.com/cap-js-community/common/actions/workflows/main-ci.yml/badge.svg)](https://github.com/cap-js-community/common/commits/main)
7
+
3
8
  ## Getting Started
4
9
 
5
10
  - Run `npm add @cap-js-community/common` in `@sap/cds` project
@@ -72,6 +77,22 @@ Options can be passed to replication cache via CDS environment via `cds.replicat
72
77
  - `tmpDir: Boolean`: Store replication cache file in temporary directory. Default is `false`
73
78
  - `baseDir: String`: Base directory for replication cache files. Default is `"temp"`
74
79
 
80
+ ### Test
81
+
82
+ Replication cache is inactive per default for tests (`test` profile). It can be enabled via CDS env:
83
+
84
+ ```json
85
+ {
86
+ "cds": {
87
+ "replicationCache": {
88
+ "[test]": {
89
+ "plugin": true
90
+ }
91
+ }
92
+ }
93
+ }
94
+ ```
95
+
75
96
  ## Migration Check
76
97
 
77
98
  ### Options
@@ -196,6 +217,22 @@ For shared redis configuration Redis service name can be provided in CDS env as
196
217
  }
197
218
  ```
198
219
 
220
+ ### Test
221
+
222
+ Rate limiting is inactive per default for tests (`test` profile). It can be enabled via CDS env:
223
+
224
+ ```json
225
+ {
226
+ "cds": {
227
+ "rateLimiting": {
228
+ "[test]": {
229
+ "plugin": true
230
+ }
231
+ }
232
+ }
233
+ }
234
+ ```
235
+
199
236
  ## Redis Client
200
237
 
201
238
  A Redis Client broker is provided to connect to Redis service.
@@ -220,7 +257,7 @@ const mainClient = await RedisClient.default("name").createMainClientAndConnect(
220
257
 
221
258
  ```js
222
259
  const { RedisClient } = require("@cap-js-community/common");
223
- const client = await new RedisClient(name).createClientAndConnect(options);
260
+ const client = await new RedisClient("name").createClientAndConnect(options);
224
261
  ```
225
262
 
226
263
  ### Options
@@ -243,6 +280,28 @@ Redis options can be provided in CDS env as follows:
243
280
  }
244
281
  ```
245
282
 
283
+ Specific Redis options for a custom name can be established as follows:
284
+
285
+ ```json
286
+ {
287
+ "cds": {
288
+ "requires": {
289
+ "redis-customName": {
290
+ "vcap": {
291
+ "tag": "redis-cache"
292
+ },
293
+ "options": {}
294
+ }
295
+ }
296
+ }
297
+ }
298
+ ```
299
+
300
+ ```js
301
+ const { RedisClient } = require("@cap-js-community/common");
302
+ const mainClient = await RedisClient.default("customName").createMainClientAndConnect(options);
303
+ ```
304
+
246
305
  In addition, options can be passed to Redis client during creation via `options` parameter:
247
306
 
248
307
  ```js
@@ -262,4 +321,4 @@ We as members, contributors, and leaders pledge to make participation in our com
262
321
 
263
322
  ## Licensing
264
323
 
265
- Copyright 2025 SAP SE or an SAP affiliate company and sap-afc-sdk contributors. Please see our [LICENSE](LICENSE) for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available [via the REUSE tool](https://api.reuse.software/info/github.com/cap-js-community/common).
324
+ Copyright 2025 SAP SE or an SAP affiliate company and common contributors. Please see our [LICENSE](LICENSE) for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available [via the REUSE tool](https://api.reuse.software/info/github.com/cap-js-community/common).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cap-js-community/common",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "CAP Node.js Community Common",
5
5
  "homepage": "https://cap.cloud.sap/",
6
6
  "engines": {
@@ -56,7 +56,7 @@
56
56
  "@sap/cds-common-content": "^2.1.0",
57
57
  "@sap/cds-dk": "^8.9.1",
58
58
  "eslint": "9.24.0",
59
- "eslint-config-prettier": "10.1.1",
59
+ "eslint-config-prettier": "10.1.2",
60
60
  "eslint-plugin-jest": "28.11.0",
61
61
  "eslint-plugin-n": "^17.17.0",
62
62
  "jest": "29.7.0",
@@ -103,7 +103,7 @@ class RedisClient {
103
103
 
104
104
  createClientBase(redisOptions = {}) {
105
105
  const { credentials, options } =
106
- (this.name ? cds.requires[`redis-${this.name}`] : undefined) || cds.requires["redis"] || {};
106
+ (this.name ? cds.env.requires[`redis-${this.name}`] : undefined) || cds.env.requires["redis"] || {};
107
107
  const socket = {
108
108
  host: credentials?.hostname ?? "127.0.0.1",
109
109
  tls: !!credentials?.tls,
@@ -114,7 +114,7 @@ class RedisClient {
114
114
  const socketOptions = {
115
115
  ...options,
116
116
  ...redisOptions,
117
- password: options?.password ?? options?.password ?? credentials?.password,
117
+ password: redisOptions?.password ?? options?.password ?? credentials?.password,
118
118
  socket,
119
119
  };
120
120
  try {
@@ -184,6 +184,9 @@ class RedisClient {
184
184
  }
185
185
 
186
186
  async closeMainClient() {
187
+ if (!this.mainClientPromise) {
188
+ return;
189
+ }
187
190
  const client = this.mainClientPromise;
188
191
  this.mainClientPromise = null;
189
192
  await this.resilientClientClose(await client);
@@ -191,6 +194,9 @@ class RedisClient {
191
194
  }
192
195
 
193
196
  async closeAdditionalClient() {
197
+ if (!this.additionalClientPromise) {
198
+ return;
199
+ }
194
200
  const client = this.additionalClientPromise;
195
201
  this.additionalClientPromise = null;
196
202
  await this.resilientClientClose(await client);
@@ -198,6 +204,9 @@ class RedisClient {
198
204
  }
199
205
 
200
206
  async closeSubscribeClient() {
207
+ if (!this.subscriberClientPromise) {
208
+ return;
209
+ }
201
210
  const client = this.subscriberClientPromise;
202
211
  this.subscriberClientPromise = null;
203
212
  await this.resilientClientClose(await client);