@nimbus-cqrs/utils 2.1.2 → 2.3.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 +13 -48
- package/esm/_dnt.polyfills.d.ts +7 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -0
- package/esm/_dnt.polyfills.js +1 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -0
- package/esm/lib/getEnv.d.ts +2 -12
- package/esm/lib/getEnv.d.ts.map +1 -1
- package/esm/lib/getEnv.js +2 -32
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -5,11 +5,21 @@
|
|
|
5
5
|
|
|
6
6
|
# Nimbus Utils
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
> **Deprecated.** This package is deprecated. Import `getEnv` from [`@nimbus-cqrs/core`](https://www.npmjs.com/package/@nimbus-cqrs/core) instead. `@nimbus-cqrs/utils` remains available as a thin re-export for backwards compatibility.
|
|
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
|
-
##
|
|
12
|
+
## Migration
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
// Before
|
|
16
|
+
import { getEnv } from "@nimbus-cqrs/utils";
|
|
17
|
+
|
|
18
|
+
// After
|
|
19
|
+
import { getEnv } from "@nimbus-cqrs/core";
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Install (legacy)
|
|
13
23
|
|
|
14
24
|
```bash
|
|
15
25
|
# Deno
|
|
@@ -22,52 +32,7 @@ npm install @nimbus-cqrs/utils
|
|
|
22
32
|
bun add @nimbus-cqrs/utils
|
|
23
33
|
```
|
|
24
34
|
|
|
25
|
-
|
|
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
|
-
```
|
|
35
|
+
Prefer installing `@nimbus-cqrs/core` directly.
|
|
71
36
|
|
|
72
37
|
# License
|
|
73
38
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK;QACb,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CACF;AAED,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/index.d.ts
CHANGED
package/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAC7B,cAAc,iBAAiB,CAAC"}
|
package/esm/index.js
CHANGED
package/esm/lib/getEnv.d.ts
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
type GetEnvInput = {
|
|
2
|
-
variables: string[];
|
|
3
|
-
};
|
|
4
1
|
/**
|
|
5
|
-
*
|
|
6
|
-
* Throws an exception if any of the variables are not defined
|
|
7
|
-
* and logs the missing variable names.
|
|
8
|
-
*
|
|
9
|
-
* @param variables - The list of environment variables to get
|
|
10
|
-
* @returns {Record<string, string>} Object of the environment variables
|
|
11
|
-
* @throws {GenericException} Thrown if any of the requested variables are not defined
|
|
2
|
+
* @deprecated Import {@link getEnv} from `@nimbus-cqrs/core` instead.
|
|
12
3
|
*/
|
|
13
|
-
export
|
|
14
|
-
export {};
|
|
4
|
+
export { getEnv } from '@nimbus-cqrs/core';
|
|
15
5
|
//# sourceMappingURL=getEnv.d.ts.map
|
package/esm/lib/getEnv.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEnv.d.ts","sourceRoot":"","sources":["../../src/lib/getEnv.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getEnv.d.ts","sourceRoot":"","sources":["../../src/lib/getEnv.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,qDAAqD,CAAC"}
|
package/esm/lib/getEnv.js
CHANGED
|
@@ -1,34 +1,4 @@
|
|
|
1
|
-
import { GenericException, getLogger } from '@nimbus-cqrs/core';
|
|
2
|
-
import process from 'node:process';
|
|
3
1
|
/**
|
|
4
|
-
*
|
|
5
|
-
* Throws an exception if any of the variables are not defined
|
|
6
|
-
* and logs the missing variable names.
|
|
7
|
-
*
|
|
8
|
-
* @param variables - The list of environment variables to get
|
|
9
|
-
* @returns {Record<string, string>} Object of the environment variables
|
|
10
|
-
* @throws {GenericException} Thrown if any of the requested variables are not defined
|
|
2
|
+
* @deprecated Import {@link getEnv} from `@nimbus-cqrs/core` instead.
|
|
11
3
|
*/
|
|
12
|
-
export
|
|
13
|
-
const envVars = {};
|
|
14
|
-
const missingEnvVars = [];
|
|
15
|
-
for (const variable of variables) {
|
|
16
|
-
if (!process.env[variable]) {
|
|
17
|
-
missingEnvVars.push(variable);
|
|
18
|
-
}
|
|
19
|
-
envVars[variable] = process.env[variable];
|
|
20
|
-
}
|
|
21
|
-
if (missingEnvVars.length > 0) {
|
|
22
|
-
getLogger().error({
|
|
23
|
-
category: 'Nimbus',
|
|
24
|
-
message: 'Undefined environment variables',
|
|
25
|
-
data: {
|
|
26
|
-
undefinedVariables: missingEnvVars,
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
throw new GenericException('Undefined environment variables', {
|
|
30
|
-
undefinedVariables: missingEnvVars,
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
return envVars;
|
|
34
|
-
};
|
|
4
|
+
export { getEnv } from '@nimbus-cqrs/core';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nimbus-cqrs/utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Simplify Event-Driven Applications - Utility helpers shared across the Nimbus framework.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nimbus",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@opentelemetry/api": "^1.9.1",
|
|
35
|
-
"zod": "^4.3
|
|
36
|
-
"@nimbus-cqrs/core": "^2.
|
|
35
|
+
"zod": "^4.4.3",
|
|
36
|
+
"@nimbus-cqrs/core": "^2.3.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^22.0.0"
|