@armscye/hooks 0.4.1 → 0.6.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 +79 -1
- package/dist/index.d.ts +3 -3
- package/dist/{shutdown-hook.interface.d.ts → shutdown-hook.d.ts} +1 -7
- package/package.json +6 -5
- package/dist/hook.interface.d.ts +0 -2
- /package/dist/{hook-provider.interface.d.ts → hook-provider.d.ts} +0 -0
- /package/dist/{startup-hook.interface.d.ts → startup-hook.d.ts} +0 -0
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,81 @@ 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 methods 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
|
+
// Register the shutdown hook with the application
|
|
51
|
+
app.registerHook(new MyShutdownHook())
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### StartupHook `Interface`
|
|
55
|
+
|
|
56
|
+
Interface defining method called during the application startup.
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
interface StartupHook {
|
|
60
|
+
onStartup(): any;
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The `onStartup` method is called before the application begins listening for incoming connections.
|
|
65
|
+
|
|
66
|
+
**Usage notes**
|
|
67
|
+
|
|
68
|
+
Here's a basic example demonstrating how to use a `StartupHook` to connect to a database:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
class MyStartupHook implements StartupHook {
|
|
72
|
+
onStartup() {
|
|
73
|
+
// Connect to the database
|
|
74
|
+
database.connect();
|
|
75
|
+
console.log('Database connection established.');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Register the startup hook with the application
|
|
80
|
+
app.registerHook(new MyStartupHook());
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### HookProvider `Type`
|
|
84
|
+
|
|
85
|
+
Describes how hooks should be provided.
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
type HookProvider<T = any> = string | symbol | object | Type<T> | Function;
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
This project is licensed under the **MIT license**.
|
|
94
|
+
|
|
95
|
+
See [LICENSE](LICENSE) for more information.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './hook-provider
|
|
2
|
-
export * from './shutdown-hook
|
|
3
|
-
export * from './startup-hook
|
|
1
|
+
export * from './hook-provider';
|
|
2
|
+
export * from './shutdown-hook';
|
|
3
|
+
export * from './startup-hook';
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Interface defining methods to respond to system signals (when application gets
|
|
3
|
-
* shutdown by, e.g., SIGTERM)
|
|
3
|
+
* shutdown by, e.g., `SIGTERM`).
|
|
4
4
|
*/
|
|
5
5
|
export interface ShutdownHook {
|
|
6
|
-
/**
|
|
7
|
-
* Called before connections close.
|
|
8
|
-
*
|
|
9
|
-
* @param signal the system signal
|
|
10
|
-
*/
|
|
11
|
-
beforeShutdown(signal?: string): any;
|
|
12
6
|
/**
|
|
13
7
|
* Called after connections close.
|
|
14
8
|
*
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@armscye/hooks",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "A collection of shared standard TypeScript definitions",
|
|
3
|
+
"version": "0.6.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.
|
|
18
|
+
"@armscye/core": "^0.3.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": "
|
|
31
|
+
"gitHead": "a26e3829ccbd43eae0ab1a1dd165af7ae7b355c1"
|
|
31
32
|
}
|
package/dist/hook.interface.d.ts
DELETED
|
File without changes
|
|
File without changes
|