@nimbus-cqrs/utils 2.0.0-beta.0 → 2.0.2
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 +61 -1
- package/esm/lib/getEnv.js +1 -1
- package/package.json +11 -3
package/README.md
CHANGED
|
@@ -5,10 +5,70 @@
|
|
|
5
5
|
|
|
6
6
|
# Nimbus Utils
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
A small collection of utility helpers used across the Nimbus framework — currently a single helper, `getEnv`, for reading required environment variables in a fail-fast way.
|
|
9
9
|
|
|
10
10
|
Refer to the [Nimbus main repository](https://github.com/overlap-dev/Nimbus) or the [Nimbus documentation](https://nimbus.overlap.at) for more information about the Nimbus framework.
|
|
11
11
|
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
# Deno
|
|
16
|
+
deno add jsr:@nimbus-cqrs/utils
|
|
17
|
+
|
|
18
|
+
# NPM
|
|
19
|
+
npm install @nimbus-cqrs/utils
|
|
20
|
+
|
|
21
|
+
# Bun
|
|
22
|
+
bun add @nimbus-cqrs/utils
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
# Examples
|
|
26
|
+
|
|
27
|
+
For detailed documentation, please refer to the [Nimbus documentation](https://nimbus.overlap.at).
|
|
28
|
+
|
|
29
|
+
## getEnv
|
|
30
|
+
|
|
31
|
+
`getEnv` reads a list of environment variables from `process.env` and returns them as a plain object. If any of the requested variables are missing it logs the missing names through the Nimbus logger and throws a `GenericException`, so misconfiguration fails loudly at startup instead of leaking through as `undefined` later.
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { getEnv } from '@nimbus-cqrs/utils';
|
|
35
|
+
|
|
36
|
+
const env = getEnv({
|
|
37
|
+
variables: ['MONGO_URI', 'MONGO_DB_NAME'],
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
console.log(env.MONGO_URI); // "mongodb://localhost:27017"
|
|
41
|
+
console.log(env.MONGO_DB_NAME); // "my-app"
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
If, for example, `MONGO_DB_NAME` is not set, the call throws a `GenericException` whose `data` carries the list of missing variables:
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"name": "GenericException",
|
|
49
|
+
"message": "Undefined environment variables",
|
|
50
|
+
"data": {
|
|
51
|
+
"undefinedVariables": ["MONGO_DB_NAME"]
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
A typical pattern is to call `getEnv` once at application startup, before any subsystem that needs those values is initialized:
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { getEnv } from '@nimbus-cqrs/utils';
|
|
60
|
+
import { MongoConnectionManager } from '@nimbus-cqrs/mongodb';
|
|
61
|
+
|
|
62
|
+
const env = getEnv({
|
|
63
|
+
variables: ['MONGO_URI', 'MONGO_DB_NAME'],
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const mongo = new MongoConnectionManager({
|
|
67
|
+
uri: env.MONGO_URI,
|
|
68
|
+
dbName: env.MONGO_DB_NAME,
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
12
72
|
# License
|
|
13
73
|
|
|
14
74
|
Copyright 2024-present Overlap GmbH & Co KG (https://overlap.at)
|
package/esm/lib/getEnv.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nimbus-cqrs/utils",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "Utility helpers shared across the Nimbus
|
|
3
|
+
"version": "2.0.2",
|
|
4
|
+
"description": "Simplify Event-Driven Applications - Utility helpers shared across the Nimbus framework.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"nimbus",
|
|
7
|
+
"cqrs",
|
|
8
|
+
"event-sourcing",
|
|
9
|
+
"event-driven",
|
|
10
|
+
"typescript",
|
|
11
|
+
"utils"
|
|
12
|
+
],
|
|
5
13
|
"author": "Daniel Gördes <d.goerdes@overlap.at> (https://overlap.at)",
|
|
6
14
|
"homepage": "https://nimbus.overlap.at",
|
|
7
15
|
"repository": {
|
|
@@ -25,7 +33,7 @@
|
|
|
25
33
|
"dependencies": {
|
|
26
34
|
"@opentelemetry/api": "^1.9.1",
|
|
27
35
|
"zod": "^4.3.6",
|
|
28
|
-
"@nimbus-cqrs/core": "^2.0.
|
|
36
|
+
"@nimbus-cqrs/core": "^2.0.2"
|
|
29
37
|
},
|
|
30
38
|
"devDependencies": {
|
|
31
39
|
"@types/node": "^22.0.0"
|