dt-common-device 1.0.17 → 1.0.18
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/config/config.d.ts +1 -5
- package/dist/config/config.js +3 -7
- package/dist/db/db.js +2 -2
- package/package.json +1 -1
- package/src/config/config.ts +4 -14
- package/src/db/db.ts +2 -2
package/dist/config/config.d.ts
CHANGED
|
@@ -7,11 +7,7 @@ export declare function ensureAuditInitialized(): void;
|
|
|
7
7
|
* Returns the PostgreSQL DB URI from environment variables.
|
|
8
8
|
* Throws an error if not set.
|
|
9
9
|
*/
|
|
10
|
-
export declare function getPostgresDbUri():
|
|
11
|
-
baseUri: string;
|
|
12
|
-
dbName: string;
|
|
13
|
-
params: string;
|
|
14
|
-
};
|
|
10
|
+
export declare function getPostgresDbUri(): string;
|
|
15
11
|
/**
|
|
16
12
|
* Returns the Redis DB Host and port from environment variables.
|
|
17
13
|
* Throws an error if not set.
|
package/dist/config/config.js
CHANGED
|
@@ -62,15 +62,11 @@ function ensureAuditInitialized() {
|
|
|
62
62
|
* Throws an error if not set.
|
|
63
63
|
*/
|
|
64
64
|
function getPostgresDbUri() {
|
|
65
|
-
const fullUri = process.env.
|
|
65
|
+
const fullUri = process.env.ADMIN_DB_URI;
|
|
66
66
|
if (!fullUri) {
|
|
67
|
-
throw new Error("dt-common-device:
|
|
67
|
+
throw new Error("dt-common-device: ADMIN_DB_URI must be set in environment variables or .env file");
|
|
68
68
|
}
|
|
69
|
-
|
|
70
|
-
const baseUri = `${url.protocol}//${url.username}:${url.password}@${url.hostname}${url.port ? `:${url.port}` : ""}/`;
|
|
71
|
-
const dbName = url.pathname.replace(/^\//, "").split("?")[0];
|
|
72
|
-
const params = url.search || "";
|
|
73
|
-
return { baseUri, dbName, params };
|
|
69
|
+
return fullUri;
|
|
74
70
|
}
|
|
75
71
|
/**
|
|
76
72
|
* Returns the Redis DB Host and port from environment variables.
|
package/dist/db/db.js
CHANGED
|
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getPostgresClient = getPostgresClient;
|
|
4
4
|
const pg_1 = require("pg");
|
|
5
5
|
const config_1 = require("../config/config");
|
|
6
|
-
const
|
|
6
|
+
const URI = (0, config_1.getPostgresDbUri)();
|
|
7
7
|
let pool = null;
|
|
8
8
|
function getPostgresClient() {
|
|
9
9
|
if (!pool) {
|
|
10
10
|
pool = new pg_1.Pool({
|
|
11
|
-
connectionString:
|
|
11
|
+
connectionString: URI,
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
14
|
return pool;
|
package/package.json
CHANGED
package/src/config/config.ts
CHANGED
|
@@ -68,24 +68,14 @@ export function ensureAuditInitialized() {
|
|
|
68
68
|
* Returns the PostgreSQL DB URI from environment variables.
|
|
69
69
|
* Throws an error if not set.
|
|
70
70
|
*/
|
|
71
|
-
export function getPostgresDbUri(): {
|
|
72
|
-
|
|
73
|
-
dbName: string;
|
|
74
|
-
params: string;
|
|
75
|
-
} {
|
|
76
|
-
const fullUri = process.env.DATABASE_URL;
|
|
71
|
+
export function getPostgresDbUri(): string {
|
|
72
|
+
const fullUri = process.env.ADMIN_DB_URI;
|
|
77
73
|
if (!fullUri) {
|
|
78
74
|
throw new Error(
|
|
79
|
-
"dt-common-device:
|
|
75
|
+
"dt-common-device: ADMIN_DB_URI must be set in environment variables or .env file"
|
|
80
76
|
);
|
|
81
77
|
}
|
|
82
|
-
|
|
83
|
-
const baseUri = `${url.protocol}//${url.username}:${url.password}@${
|
|
84
|
-
url.hostname
|
|
85
|
-
}${url.port ? `:${url.port}` : ""}/`;
|
|
86
|
-
const dbName = url.pathname.replace(/^\//, "").split("?")[0];
|
|
87
|
-
const params = url.search || "";
|
|
88
|
-
return { baseUri, dbName, params };
|
|
78
|
+
return fullUri;
|
|
89
79
|
}
|
|
90
80
|
|
|
91
81
|
/**
|
package/src/db/db.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Pool } from "pg";
|
|
2
2
|
import { getPostgresDbUri } from "../config/config";
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const URI = getPostgresDbUri();
|
|
5
5
|
|
|
6
6
|
let pool: Pool | null = null;
|
|
7
7
|
|
|
8
8
|
export function getPostgresClient() {
|
|
9
9
|
if (!pool) {
|
|
10
10
|
pool = new Pool({
|
|
11
|
-
connectionString:
|
|
11
|
+
connectionString: URI,
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
14
|
return pool;
|