@bgord/bun 1.4.14 → 1.4.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bgord/bun",
3
- "version": "1.4.14",
3
+ "version": "1.4.16",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "author": "Bartosz Gordon",
@@ -1,32 +1,18 @@
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
- type NodeEnvironmentEnumType = z.infer<typeof NodeEnvironment>;
5
- type AnyZodSchema = z.ZodSchema<any, any>;
6
- type EnvironmentValidatorConfig = { type: unknown; schema: AnyZodSchema };
4
+ export type EnvironmentResultType<Schema> = z.infer<Schema> & { type: NodeEnvironmentEnum };
7
5
 
8
- export type EnvironmentResultType<SchemaType> = SchemaType & { type: NodeEnvironmentEnumType };
6
+ export class EnvironmentValidator<Schema extends z.ZodObject<any>> {
7
+ private readonly type: NodeEnvironmentEnum;
8
+ private readonly schema: Schema;
9
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) {
10
+ constructor(config: { type: string | undefined; schema: Schema }) {
17
11
  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);
12
+ this.type = NodeEnvironment.parse(config.type);
27
13
  }
28
14
 
29
- load(): EnvironmentResultType<SchemaType> {
30
- return { ...this.schema.parse(process.env), type: this.type };
15
+ load(env: NodeJS.ProcessEnv): EnvironmentResultType<Schema> {
16
+ return { ...this.schema.parse(env), type: this.type };
31
17
  }
32
18
  }
@@ -7,4 +7,6 @@ export enum NodeEnvironmentEnum {
7
7
  production = "production",
8
8
  }
9
9
 
10
- export const NodeEnvironment = z.enum(NodeEnvironmentEnum);
10
+ export const NodeEnvironmentError = { Invalid: "node.environment.invalid" } as const;
11
+
12
+ export const NodeEnvironment = z.enum(NodeEnvironmentEnum, { error: NodeEnvironmentError.Invalid });