@diia-inhouse/db 12.4.12 → 12.5.0

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.
@@ -25,6 +25,10 @@ declare class DatabaseService implements OnInit, OnHealthCheck, OnDestroy {
25
25
  * https://www.mongodb.com/docs/manual/core/transactions/#read-concern-write-concern-read-preference
26
26
  */
27
27
  private readonly defaultTransactionOptions;
28
+ /**
29
+ * https://www.mongodb.com/docs/manual/core/read-preference-staleness/
30
+ */
31
+ private readonly secondaryPreferredMaxStalenessSeconds;
28
32
  constructor(databaseAdapter: DatabaseAdapterType, dbConfigs: Partial<Record<DbType, AppDbConfig>>, envService: EnvService, logger: Logger);
29
33
  onInit(): Promise<void>;
30
34
  onDestroy(): Promise<void>;
@@ -31,6 +31,10 @@ var DatabaseService = class {
31
31
  * https://www.mongodb.com/docs/manual/core/transactions/#read-concern-write-concern-read-preference
32
32
  */
33
33
  defaultTransactionOptions = { readPreference: "primary" };
34
+ /**
35
+ * https://www.mongodb.com/docs/manual/core/read-preference-staleness/
36
+ */
37
+ secondaryPreferredMaxStalenessSeconds = 90;
34
38
  constructor(databaseAdapter, dbConfigs, envService, logger) {
35
39
  this.databaseAdapter = databaseAdapter;
36
40
  this.dbConfigs = dbConfigs;
@@ -112,6 +116,7 @@ var DatabaseService = class {
112
116
  const query = [];
113
117
  if (authSource) query.push(`authSource=${authSource}`);
114
118
  if (readPreference) query.push(`readPreference=${readPreference}`);
119
+ if (readPreference === mongoose.mongo.ReadPreference.SECONDARY_PREFERRED) query.push(`maxStalenessSeconds=${this.secondaryPreferredMaxStalenessSeconds}`);
115
120
  if (authMechanism) query.push(`authMechanism=${authMechanism}`);
116
121
  if (query.length > 0) connectionString += `?${query.join("&")}`;
117
122
  const logOptions = cloneDeep(connectionOptions);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diia-inhouse/db",
3
- "version": "12.4.12",
3
+ "version": "12.5.0",
4
4
  "type": "module",
5
5
  "description": "Package with database connection",
6
6
  "main": "dist/index.js",
@@ -73,8 +73,8 @@
73
73
  "@types/pg": "8.20.0",
74
74
  "@types/recursive-readdir": "2.2.4",
75
75
  "@types/yargs": "17.0.35",
76
- "@vitest/coverage-v8": "4.1.5",
77
- "@vitest/ui": "4.1.5",
76
+ "@vitest/coverage-v8": "4.1.11",
77
+ "@vitest/ui": "4.1.11",
78
78
  "dotenv-flow": "4.1.0",
79
79
  "drizzle-kit": "0.31.10",
80
80
  "lockfile-lint": "5.0.0",
@@ -86,7 +86,7 @@
86
86
  "semantic-release": "25.0.3",
87
87
  "tsdown": "0.22.0",
88
88
  "typescript": "5.9.3",
89
- "vitest": "4.1.5",
89
+ "vitest": "4.1.11",
90
90
  "vitest-mock-extended": "4.0.0"
91
91
  },
92
92
  "release": {