@jitar-plugins/database 0.0.1

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 ADDED
@@ -0,0 +1,45 @@
1
+
2
+ # Database | Jitar Plugins
3
+
4
+ This package provides plugins for integrating the [The Shelf database package](https://github.com/MaskingTechnology/theshelf/tree/main/packages/database) in Jitar applications.
5
+
6
+ It contains a single health check for checking the database health.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install @theshelf/database @jitar-plugins/database
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ Follow the following steps to configure and use the provided health check.
17
+
18
+ ### Step 1 - Configure the health check
19
+
20
+ ```ts
21
+ // src/health/databaseHealthCheck.ts
22
+
23
+ import database from '@theshelf/database';
24
+ import { DatabaseHealthCheck } from '@jitar-plugins/database';
25
+
26
+ export default new DatabaseHealthCheck(database);
27
+ ```
28
+
29
+ ### Step 2 - Activate the health check
30
+
31
+ With the health check in place, it needs to be activated by registering it to the worker / standalone service.
32
+
33
+ ```json
34
+ /* services/some-worker.json */
35
+ {
36
+ "url": "http://example.com:3000",
37
+ "healthChecks": [ /* add health checks here */
38
+ "./health/databaseHealthCheck"
39
+ ],
40
+ "worker":
41
+ {
42
+ /* service configuration */
43
+ }
44
+ }
45
+ ```
@@ -0,0 +1,9 @@
1
+ import type { HealthCheck } from 'jitar';
2
+ import type { Database } from '@theshelf/database';
3
+ export default class DatabaseHealthCheck implements HealthCheck {
4
+ #private;
5
+ constructor(database: Database);
6
+ get name(): string;
7
+ get timeout(): number;
8
+ isHealthy(): Promise<boolean>;
9
+ }
@@ -0,0 +1,13 @@
1
+ export default class DatabaseHealthCheck {
2
+ #database;
3
+ #name = 'database';
4
+ #timeout = 5000;
5
+ constructor(database) {
6
+ this.#database = database;
7
+ }
8
+ get name() { return this.#name; }
9
+ get timeout() { return this.#timeout; }
10
+ async isHealthy() {
11
+ return this.#database.connected;
12
+ }
13
+ }
@@ -0,0 +1 @@
1
+ export { default as DatabaseHealthCheck } from './DatabaseHealthCheck';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { default as DatabaseHealthCheck } from './DatabaseHealthCheck';
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@jitar-plugins/database",
3
+ "private": false,
4
+ "version": "0.0.1",
5
+ "type": "module",
6
+ "scripts": {
7
+ "build": "tsc",
8
+ "clean": "rimraf dist",
9
+ "lint": "eslint",
10
+ "review": "npm run build && npm run lint",
11
+ "prepublishOnly": "npm run build"
12
+ },
13
+ "files": [
14
+ "README.md",
15
+ "dist"
16
+ ],
17
+ "types": "dist/index.d.ts",
18
+ "exports": "./dist/index.js",
19
+ "peerDependencies": {
20
+ "@theshelf/database": "^0.0.2",
21
+ "jitar": "^0.10.3"
22
+ }
23
+ }