@bgord/bun 1.4.14 → 1.4.15
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/dist/environment-validator.service.d.ts +11 -19
- package/dist/environment-validator.service.d.ts.map +1 -1
- package/dist/environment-validator.service.js +3 -9
- package/dist/environment-validator.service.js.map +1 -1
- package/dist/node-env.vo.d.ts +3 -0
- package/dist/node-env.vo.d.ts.map +1 -1
- package/dist/node-env.vo.js +2 -1
- package/dist/node-env.vo.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/environment-validator.service.ts +8 -24
- package/src/node-env.vo.ts +3 -1
package/package.json
CHANGED
|
@@ -1,32 +1,16 @@
|
|
|
1
1
|
import type { z } from "zod/v4";
|
|
2
|
-
import { NodeEnvironment } from "../src/node-env.vo";
|
|
2
|
+
import { NodeEnvironment, type NodeEnvironmentEnum } from "../src/node-env.vo";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export class EnvironmentValidator<Schema extends z.ZodObject<any>> {
|
|
5
|
+
private readonly type: NodeEnvironmentEnum;
|
|
6
|
+
private readonly schema: Schema;
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export const EnvironmentValidatorError = { Invalid: "environment.validator.invalid" } as const;
|
|
11
|
-
|
|
12
|
-
export class EnvironmentValidator<SchemaType> {
|
|
13
|
-
type: NodeEnvironmentEnumType;
|
|
14
|
-
schema: z.Schema<SchemaType>;
|
|
15
|
-
|
|
16
|
-
constructor(config: EnvironmentValidatorConfig) {
|
|
8
|
+
constructor(config: { type: string | undefined; schema: Schema }) {
|
|
17
9
|
this.schema = config.schema;
|
|
18
|
-
|
|
19
|
-
const result = NodeEnvironment.safeParse(config.type);
|
|
20
|
-
|
|
21
|
-
if (result.success) {
|
|
22
|
-
this.type = result.data;
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
throw new Error(EnvironmentValidatorError.Invalid);
|
|
10
|
+
this.type = NodeEnvironment.parse(config.type);
|
|
27
11
|
}
|
|
28
12
|
|
|
29
|
-
load():
|
|
30
|
-
return { ...this.schema.parse(
|
|
13
|
+
load(env: NodeJS.ProcessEnv): z.infer<Schema> & { type: NodeEnvironmentEnum } {
|
|
14
|
+
return { ...this.schema.parse(env), type: this.type };
|
|
31
15
|
}
|
|
32
16
|
}
|
package/src/node-env.vo.ts
CHANGED
|
@@ -7,4 +7,6 @@ export enum NodeEnvironmentEnum {
|
|
|
7
7
|
production = "production",
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export const
|
|
10
|
+
export const NodeEnvironmentError = { Invalid: "node.environment.invalid" } as const;
|
|
11
|
+
|
|
12
|
+
export const NodeEnvironment = z.enum(NodeEnvironmentEnum, { error: NodeEnvironmentError.Invalid });
|