@armscye/hooks 0.5.0 → 0.7.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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @armscye/hooks
2
2
 
3
- > A collection of shared standard TypeScript definitions.
3
+ > A collection of shared standard TypeScript definitions (@hooks).
4
4
 
5
5
  ## Installation
6
6
 
@@ -15,3 +15,75 @@ or using yarn:
15
15
  ```sh
16
16
  yarn add @armscye/hooks --dev
17
17
  ```
18
+
19
+ ## Reference
20
+
21
+ ### ShutdownHook `Interface`
22
+
23
+ Interface defining method to respond to system signals (when application gets shutdown by, e.g., `SIGTERM`).
24
+
25
+ ```ts
26
+ interface ShutdownHook {
27
+ onShutdown(signal?: string): any;
28
+ }
29
+ ```
30
+
31
+ The `onShutdown` method is called when an application receives a system signal indicating it's time to gracefully shutdown. Common signals include `SIGTERM` (termination request) and `SIGINT` (interrupt).
32
+
33
+ The optional `signal` parameter might be provided, revealing the specific signal received.
34
+
35
+ **Usage notes**
36
+
37
+ Here's a basic example demonstrating how to use `ShutdownHook` to close a database connection:
38
+
39
+ ```ts
40
+ class MyShutdownHook implements ShutdownHook {
41
+ onShutdown(signal?: string) {
42
+ // Access and close database connection
43
+ const db = /* get database connection */;
44
+ db.close()
45
+ .then(() => console.log("Database connection closed"))
46
+ .catch(error => console.error("Error closing database:", error));
47
+ }
48
+ }
49
+ ```
50
+
51
+ ### StartupHook `Interface`
52
+
53
+ Interface defining method called during the application startup.
54
+
55
+ ```ts
56
+ interface StartupHook {
57
+ onStartup(): any;
58
+ }
59
+ ```
60
+
61
+ The `onStartup` method is called before the application begins listening for incoming connections.
62
+
63
+ **Usage notes**
64
+
65
+ Here's a basic example demonstrating how to use a `StartupHook` to connect to a database:
66
+
67
+ ```ts
68
+ class MyStartupHook implements StartupHook {
69
+ onStartup() {
70
+ // Connect to the database
71
+ database.connect();
72
+ console.log('Database connection established.');
73
+ }
74
+ }
75
+ ```
76
+
77
+ ### HookProvider `Type`
78
+
79
+ Describes type structure for hooks.
80
+
81
+ ```ts
82
+ type HookProvider = string | symbol | object | Type<any> | Function;
83
+ ```
84
+
85
+ ## License
86
+
87
+ This project is licensed under the **MIT license**.
88
+
89
+ See [LICENSE](LICENSE) for more information.
@@ -1,2 +1,2 @@
1
1
  import { Type } from '@armscye/core';
2
- export type HookProvider<T = any> = string | symbol | object | Type<T> | Function;
2
+ export type HookProvider = string | symbol | object | Type<any> | Function;
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Interface defining methods to respond to system signals (when application gets
3
- * shutdown by, e.g., SIGTERM)
2
+ * Interface defining method to respond to system signals (when application gets
3
+ * shutdown by, e.g., `SIGTERM`).
4
4
  */
5
5
  export interface ShutdownHook {
6
6
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@armscye/hooks",
3
- "version": "0.5.0",
4
- "description": "A collection of shared standard TypeScript definitions",
3
+ "version": "0.7.0",
4
+ "description": "A collection of shared standard TypeScript definitions (@hooks)",
5
5
  "author": "Augustus Kamau",
6
6
  "license": "MIT",
7
7
  "types": "./dist/index.d.ts",
@@ -11,10 +11,11 @@
11
11
  "keywords": [
12
12
  "armscye",
13
13
  "typescript",
14
- "types"
14
+ "types",
15
+ "hooks"
15
16
  ],
16
17
  "dependencies": {
17
- "@armscye/core": "^0.2.0"
18
+ "@armscye/core": "^0.4.0"
18
19
  },
19
20
  "homepage": "https://github.com/armscye/armscye#readme",
20
21
  "repository": {
@@ -27,5 +28,5 @@
27
28
  "publishConfig": {
28
29
  "access": "public"
29
30
  },
30
- "gitHead": "1cc4d3acff67f6754d443396835d2523284bdc3b"
31
+ "gitHead": "0709eb7276b853296ef820d0e5bd8c170e6d2ee3"
31
32
  }