@geekmidas/envkit 0.0.4 → 0.0.6

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.
Files changed (34) hide show
  1. package/dist/{EnvironmentParser-Bo2CCl_K.cjs → EnvironmentParser-BDPDLv6i.cjs} +7 -7
  2. package/dist/EnvironmentParser-C-arQEHQ.d.mts +108 -0
  3. package/dist/{EnvironmentParser-jKrGMBhP.mjs → EnvironmentParser-CQUOGqc0.mjs} +7 -7
  4. package/dist/EnvironmentParser-X4h2Vp4r.d.cts +108 -0
  5. package/dist/EnvironmentParser.cjs +1 -1
  6. package/dist/EnvironmentParser.d.cts +2 -0
  7. package/dist/EnvironmentParser.d.mts +2 -0
  8. package/dist/EnvironmentParser.mjs +1 -1
  9. package/dist/__tests__/ConfigParser.spec.cjs +1 -1
  10. package/dist/__tests__/ConfigParser.spec.d.cts +1 -0
  11. package/dist/__tests__/ConfigParser.spec.d.mts +1 -0
  12. package/dist/__tests__/ConfigParser.spec.mjs +1 -1
  13. package/dist/__tests__/EnvironmentParser.spec.cjs +1 -1
  14. package/dist/__tests__/EnvironmentParser.spec.d.cts +1 -0
  15. package/dist/__tests__/EnvironmentParser.spec.d.mts +1 -0
  16. package/dist/__tests__/EnvironmentParser.spec.mjs +1 -1
  17. package/dist/__tests__/sst.spec.cjs +305 -0
  18. package/dist/__tests__/sst.spec.d.cts +1 -0
  19. package/dist/__tests__/sst.spec.d.mts +1 -0
  20. package/dist/__tests__/sst.spec.mjs +304 -0
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.d.cts +2 -0
  23. package/dist/index.d.mts +2 -0
  24. package/dist/index.mjs +1 -1
  25. package/dist/sst-BSxwaAdz.cjs +146 -0
  26. package/dist/sst-CQhO0S6y.mjs +128 -0
  27. package/dist/sst.cjs +4 -130
  28. package/dist/sst.d.cts +107 -0
  29. package/dist/sst.d.mts +107 -0
  30. package/dist/sst.mjs +1 -126
  31. package/package.json +5 -5
  32. package/src/EnvironmentParser.ts +10 -10
  33. package/src/__tests__/sst.spec.ts +415 -0
  34. package/src/sst.ts +9 -9
@@ -7,13 +7,13 @@ const zod_v4 = require_chunk.__toESM(require("zod/v4"));
7
7
  /**
8
8
  * Parses and validates configuration objects against Zod schemas.
9
9
  * Handles nested configurations and aggregates validation errors.
10
- *
10
+ *
11
11
  * @template TResponse - The shape of the configuration object
12
12
  */
13
13
  var ConfigParser = class {
14
14
  /**
15
15
  * Creates a new ConfigParser instance.
16
- *
16
+ *
17
17
  * @param config - The configuration object to parse
18
18
  */
19
19
  constructor(config) {
@@ -51,9 +51,9 @@ var ConfigParser = class {
51
51
  * Parses environment variables with type-safe validation using Zod schemas.
52
52
  * Provides a fluent API for defining environment variable schemas with automatic
53
53
  * error context enrichment.
54
- *
54
+ *
55
55
  * @template T - The type of the configuration object (typically process.env)
56
- *
56
+ *
57
57
  * @example
58
58
  * ```typescript
59
59
  * const config = new EnvironmentParser(process.env)
@@ -69,7 +69,7 @@ var ConfigParser = class {
69
69
  var EnvironmentParser = class {
70
70
  /**
71
71
  * Creates a new EnvironmentParser instance.
72
- *
72
+ *
73
73
  * @param config - The configuration object to parse (typically process.env)
74
74
  */
75
75
  constructor(config) {
@@ -78,7 +78,7 @@ var EnvironmentParser = class {
78
78
  /**
79
79
  * Wraps a Zod schema to intercept parse/safeParse calls and enrich error messages
80
80
  * with environment variable context.
81
- *
81
+ *
82
82
  * @param schema - The Zod schema to wrap
83
83
  * @param name - The environment variable name for error context
84
84
  * @returns A wrapped Zod schema with enhanced error reporting
@@ -129,7 +129,7 @@ var EnvironmentParser = class {
129
129
  /**
130
130
  * Creates a proxied version of the Zod object that wraps all schema creators
131
131
  * to provide enhanced error messages with environment variable context.
132
- *
132
+ *
133
133
  * @param name - The environment variable name
134
134
  * @returns A proxied Zod object with wrapped schema creators
135
135
  */
@@ -0,0 +1,108 @@
1
+ import { z } from "zod/v4";
2
+
3
+ //#region src/EnvironmentParser.d.ts
4
+
5
+ /**
6
+ * Parses and validates configuration objects against Zod schemas.
7
+ * Handles nested configurations and aggregates validation errors.
8
+ *
9
+ * @template TResponse - The shape of the configuration object
10
+ */
11
+ declare class ConfigParser<TResponse extends EmptyObject> {
12
+ private readonly config;
13
+ /**
14
+ * Creates a new ConfigParser instance.
15
+ *
16
+ * @param config - The configuration object to parse
17
+ */
18
+ constructor(config: TResponse);
19
+ /**
20
+ * Parses the config object and validates it against the Zod schemas
21
+ * @returns The parsed config object
22
+ */
23
+ parse(): InferConfig<TResponse>;
24
+ }
25
+ /**
26
+ * Parses environment variables with type-safe validation using Zod schemas.
27
+ * Provides a fluent API for defining environment variable schemas with automatic
28
+ * error context enrichment.
29
+ *
30
+ * @template T - The type of the configuration object (typically process.env)
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const config = new EnvironmentParser(process.env)
35
+ * .create((get) => ({
36
+ * port: get('PORT').string().transform(Number).default(3000),
37
+ * database: {
38
+ * url: get('DATABASE_URL').string().url()
39
+ * }
40
+ * }))
41
+ * .parse();
42
+ * ```
43
+ */
44
+ declare class EnvironmentParser<T extends EmptyObject> {
45
+ private readonly config;
46
+ /**
47
+ * Creates a new EnvironmentParser instance.
48
+ *
49
+ * @param config - The configuration object to parse (typically process.env)
50
+ */
51
+ constructor(config: T);
52
+ /**
53
+ * Wraps a Zod schema to intercept parse/safeParse calls and enrich error messages
54
+ * with environment variable context.
55
+ *
56
+ * @param schema - The Zod schema to wrap
57
+ * @param name - The environment variable name for error context
58
+ * @returns A wrapped Zod schema with enhanced error reporting
59
+ */
60
+ private wrapSchema;
61
+ /**
62
+ * Creates a proxied version of the Zod object that wraps all schema creators
63
+ * to provide enhanced error messages with environment variable context.
64
+ *
65
+ * @param name - The environment variable name
66
+ * @returns A proxied Zod object with wrapped schema creators
67
+ */
68
+ private getZodGetter;
69
+ /**
70
+ * Creates a new ConfigParser object that can be used to parse the config object
71
+ *
72
+ * @param builder - A function that takes a getter function and returns a config object
73
+ * @returns A ConfigParser object that can be used to parse the config object
74
+ */
75
+ create<TReturn extends EmptyObject>(builder: (get: EnvFetcher) => TReturn): ConfigParser<TReturn>;
76
+ }
77
+ /**
78
+ * Infers the TypeScript type of a configuration object based on its Zod schemas.
79
+ * Recursively processes nested objects and extracts types from Zod schemas.
80
+ *
81
+ * @template T - The configuration object type
82
+ */
83
+ type InferConfig<T extends EmptyObject> = { [K in keyof T]: T[K] extends z.ZodSchema ? z.infer<T[K]> : T[K] extends Record<string, unknown> ? InferConfig<T[K]> : T[K] };
84
+ /**
85
+ * Function type for fetching environment variables with Zod validation.
86
+ * Returns a Zod object scoped to a specific environment variable.
87
+ *
88
+ * @template TPath - The environment variable path type
89
+ * @param name - The environment variable name
90
+ * @returns A Zod object for defining the schema
91
+ */
92
+ type EnvFetcher<TPath extends string = string> = (name: TPath) => typeof z;
93
+ /**
94
+ * Function type for building environment configuration objects.
95
+ * Takes an EnvFetcher and returns a configuration object with Zod schemas.
96
+ *
97
+ * @template TResponse - The response configuration object type
98
+ * @param get - The environment variable fetcher function
99
+ * @returns The configuration object with Zod schemas
100
+ */
101
+ type EnvironmentBuilder<TResponse extends EmptyObject> = (get: EnvFetcher) => TResponse;
102
+ /**
103
+ * Type alias for a generic object with unknown values.
104
+ * Used as a constraint for configuration objects.
105
+ */
106
+ type EmptyObject = Record<string | number | symbol, unknown>;
107
+ //#endregion
108
+ export { ConfigParser, EmptyObject, EnvFetcher, EnvironmentBuilder, EnvironmentParser, InferConfig };
@@ -6,13 +6,13 @@ import { z } from "zod/v4";
6
6
  /**
7
7
  * Parses and validates configuration objects against Zod schemas.
8
8
  * Handles nested configurations and aggregates validation errors.
9
- *
9
+ *
10
10
  * @template TResponse - The shape of the configuration object
11
11
  */
12
12
  var ConfigParser = class {
13
13
  /**
14
14
  * Creates a new ConfigParser instance.
15
- *
15
+ *
16
16
  * @param config - The configuration object to parse
17
17
  */
18
18
  constructor(config) {
@@ -50,9 +50,9 @@ var ConfigParser = class {
50
50
  * Parses environment variables with type-safe validation using Zod schemas.
51
51
  * Provides a fluent API for defining environment variable schemas with automatic
52
52
  * error context enrichment.
53
- *
53
+ *
54
54
  * @template T - The type of the configuration object (typically process.env)
55
- *
55
+ *
56
56
  * @example
57
57
  * ```typescript
58
58
  * const config = new EnvironmentParser(process.env)
@@ -68,7 +68,7 @@ var ConfigParser = class {
68
68
  var EnvironmentParser = class {
69
69
  /**
70
70
  * Creates a new EnvironmentParser instance.
71
- *
71
+ *
72
72
  * @param config - The configuration object to parse (typically process.env)
73
73
  */
74
74
  constructor(config) {
@@ -77,7 +77,7 @@ var EnvironmentParser = class {
77
77
  /**
78
78
  * Wraps a Zod schema to intercept parse/safeParse calls and enrich error messages
79
79
  * with environment variable context.
80
- *
80
+ *
81
81
  * @param schema - The Zod schema to wrap
82
82
  * @param name - The environment variable name for error context
83
83
  * @returns A wrapped Zod schema with enhanced error reporting
@@ -128,7 +128,7 @@ var EnvironmentParser = class {
128
128
  /**
129
129
  * Creates a proxied version of the Zod object that wraps all schema creators
130
130
  * to provide enhanced error messages with environment variable context.
131
- *
131
+ *
132
132
  * @param name - The environment variable name
133
133
  * @returns A proxied Zod object with wrapped schema creators
134
134
  */
@@ -0,0 +1,108 @@
1
+ import { z } from "zod/v4";
2
+
3
+ //#region src/EnvironmentParser.d.ts
4
+
5
+ /**
6
+ * Parses and validates configuration objects against Zod schemas.
7
+ * Handles nested configurations and aggregates validation errors.
8
+ *
9
+ * @template TResponse - The shape of the configuration object
10
+ */
11
+ declare class ConfigParser<TResponse extends EmptyObject> {
12
+ private readonly config;
13
+ /**
14
+ * Creates a new ConfigParser instance.
15
+ *
16
+ * @param config - The configuration object to parse
17
+ */
18
+ constructor(config: TResponse);
19
+ /**
20
+ * Parses the config object and validates it against the Zod schemas
21
+ * @returns The parsed config object
22
+ */
23
+ parse(): InferConfig<TResponse>;
24
+ }
25
+ /**
26
+ * Parses environment variables with type-safe validation using Zod schemas.
27
+ * Provides a fluent API for defining environment variable schemas with automatic
28
+ * error context enrichment.
29
+ *
30
+ * @template T - The type of the configuration object (typically process.env)
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const config = new EnvironmentParser(process.env)
35
+ * .create((get) => ({
36
+ * port: get('PORT').string().transform(Number).default(3000),
37
+ * database: {
38
+ * url: get('DATABASE_URL').string().url()
39
+ * }
40
+ * }))
41
+ * .parse();
42
+ * ```
43
+ */
44
+ declare class EnvironmentParser<T extends EmptyObject> {
45
+ private readonly config;
46
+ /**
47
+ * Creates a new EnvironmentParser instance.
48
+ *
49
+ * @param config - The configuration object to parse (typically process.env)
50
+ */
51
+ constructor(config: T);
52
+ /**
53
+ * Wraps a Zod schema to intercept parse/safeParse calls and enrich error messages
54
+ * with environment variable context.
55
+ *
56
+ * @param schema - The Zod schema to wrap
57
+ * @param name - The environment variable name for error context
58
+ * @returns A wrapped Zod schema with enhanced error reporting
59
+ */
60
+ private wrapSchema;
61
+ /**
62
+ * Creates a proxied version of the Zod object that wraps all schema creators
63
+ * to provide enhanced error messages with environment variable context.
64
+ *
65
+ * @param name - The environment variable name
66
+ * @returns A proxied Zod object with wrapped schema creators
67
+ */
68
+ private getZodGetter;
69
+ /**
70
+ * Creates a new ConfigParser object that can be used to parse the config object
71
+ *
72
+ * @param builder - A function that takes a getter function and returns a config object
73
+ * @returns A ConfigParser object that can be used to parse the config object
74
+ */
75
+ create<TReturn extends EmptyObject>(builder: (get: EnvFetcher) => TReturn): ConfigParser<TReturn>;
76
+ }
77
+ /**
78
+ * Infers the TypeScript type of a configuration object based on its Zod schemas.
79
+ * Recursively processes nested objects and extracts types from Zod schemas.
80
+ *
81
+ * @template T - The configuration object type
82
+ */
83
+ type InferConfig<T extends EmptyObject> = { [K in keyof T]: T[K] extends z.ZodSchema ? z.infer<T[K]> : T[K] extends Record<string, unknown> ? InferConfig<T[K]> : T[K] };
84
+ /**
85
+ * Function type for fetching environment variables with Zod validation.
86
+ * Returns a Zod object scoped to a specific environment variable.
87
+ *
88
+ * @template TPath - The environment variable path type
89
+ * @param name - The environment variable name
90
+ * @returns A Zod object for defining the schema
91
+ */
92
+ type EnvFetcher<TPath extends string = string> = (name: TPath) => typeof z;
93
+ /**
94
+ * Function type for building environment configuration objects.
95
+ * Takes an EnvFetcher and returns a configuration object with Zod schemas.
96
+ *
97
+ * @template TResponse - The response configuration object type
98
+ * @param get - The environment variable fetcher function
99
+ * @returns The configuration object with Zod schemas
100
+ */
101
+ type EnvironmentBuilder<TResponse extends EmptyObject> = (get: EnvFetcher) => TResponse;
102
+ /**
103
+ * Type alias for a generic object with unknown values.
104
+ * Used as a constraint for configuration objects.
105
+ */
106
+ type EmptyObject = Record<string | number | symbol, unknown>;
107
+ //#endregion
108
+ export { ConfigParser, EmptyObject, EnvFetcher, EnvironmentBuilder, EnvironmentParser, InferConfig };
@@ -1,4 +1,4 @@
1
- const require_EnvironmentParser = require('./EnvironmentParser-Bo2CCl_K.cjs');
1
+ const require_EnvironmentParser = require('./EnvironmentParser-BDPDLv6i.cjs');
2
2
 
3
3
  exports.ConfigParser = require_EnvironmentParser.ConfigParser;
4
4
  exports.EnvironmentParser = require_EnvironmentParser.EnvironmentParser;
@@ -0,0 +1,2 @@
1
+ import { ConfigParser, EmptyObject, EnvFetcher, EnvironmentBuilder, EnvironmentParser, InferConfig } from "./EnvironmentParser-X4h2Vp4r.cjs";
2
+ export { ConfigParser, EmptyObject, EnvFetcher, EnvironmentBuilder, EnvironmentParser, InferConfig };
@@ -0,0 +1,2 @@
1
+ import { ConfigParser, EmptyObject, EnvFetcher, EnvironmentBuilder, EnvironmentParser, InferConfig } from "./EnvironmentParser-C-arQEHQ.mjs";
2
+ export { ConfigParser, EmptyObject, EnvFetcher, EnvironmentBuilder, EnvironmentParser, InferConfig };
@@ -1,3 +1,3 @@
1
- import { ConfigParser, EnvironmentParser } from "./EnvironmentParser-jKrGMBhP.mjs";
1
+ import { ConfigParser, EnvironmentParser } from "./EnvironmentParser-CQUOGqc0.mjs";
2
2
 
3
3
  export { ConfigParser, EnvironmentParser };
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require('../chunk-CUT6urMc.cjs');
2
- const require_EnvironmentParser = require('../EnvironmentParser-Bo2CCl_K.cjs');
2
+ const require_EnvironmentParser = require('../EnvironmentParser-BDPDLv6i.cjs');
3
3
  const zod_v4 = require_chunk.__toESM(require("zod/v4"));
4
4
  const vitest = require_chunk.__toESM(require("vitest"));
5
5
 
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -1,4 +1,4 @@
1
- import { ConfigParser } from "../EnvironmentParser-jKrGMBhP.mjs";
1
+ import { ConfigParser } from "../EnvironmentParser-CQUOGqc0.mjs";
2
2
  import { z } from "zod/v4";
3
3
  import { describe, expect, it } from "vitest";
4
4
 
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require('../chunk-CUT6urMc.cjs');
2
- const require_EnvironmentParser = require('../EnvironmentParser-Bo2CCl_K.cjs');
2
+ const require_EnvironmentParser = require('../EnvironmentParser-BDPDLv6i.cjs');
3
3
  const zod_v4 = require_chunk.__toESM(require("zod/v4"));
4
4
  const vitest = require_chunk.__toESM(require("vitest"));
5
5
 
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -1,4 +1,4 @@
1
- import { EnvironmentParser } from "../EnvironmentParser-jKrGMBhP.mjs";
1
+ import { EnvironmentParser } from "../EnvironmentParser-CQUOGqc0.mjs";
2
2
  import { z } from "zod/v4";
3
3
  import { describe, expect, it } from "vitest";
4
4