@geekmidas/envkit 0.0.7 → 0.0.8

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 (46) hide show
  1. package/dist/{EnvironmentParser-C-arQEHQ.d.mts → EnvironmentParser-B8--woiB.d.cts} +40 -2
  2. package/dist/{EnvironmentParser-X4h2Vp4r.d.cts → EnvironmentParser-C_9v2BDw.d.mts} +40 -2
  3. package/dist/{EnvironmentParser-CQUOGqc0.mjs → EnvironmentParser-STvN_RCc.mjs} +46 -3
  4. package/dist/EnvironmentParser-STvN_RCc.mjs.map +1 -0
  5. package/dist/{EnvironmentParser-BDPDLv6i.cjs → EnvironmentParser-cnxuy7lw.cjs} +46 -3
  6. package/dist/EnvironmentParser-cnxuy7lw.cjs.map +1 -0
  7. package/dist/EnvironmentParser.cjs +1 -1
  8. package/dist/EnvironmentParser.d.cts +1 -1
  9. package/dist/EnvironmentParser.d.mts +1 -1
  10. package/dist/EnvironmentParser.mjs +1 -1
  11. package/dist/SnifferEnvironmentParser.cjs +140 -0
  12. package/dist/SnifferEnvironmentParser.cjs.map +1 -0
  13. package/dist/SnifferEnvironmentParser.d.cts +50 -0
  14. package/dist/SnifferEnvironmentParser.d.mts +50 -0
  15. package/dist/SnifferEnvironmentParser.mjs +139 -0
  16. package/dist/SnifferEnvironmentParser.mjs.map +1 -0
  17. package/dist/index.cjs +2 -1
  18. package/dist/index.d.cts +2 -2
  19. package/dist/index.d.mts +2 -2
  20. package/dist/index.mjs +2 -2
  21. package/dist/sst.cjs +131 -4
  22. package/dist/sst.cjs.map +1 -0
  23. package/dist/sst.d.cts +2 -1
  24. package/dist/sst.d.mts +2 -1
  25. package/dist/sst.mjs +128 -2
  26. package/dist/sst.mjs.map +1 -0
  27. package/package.json +6 -1
  28. package/src/EnvironmentParser.ts +51 -2
  29. package/src/SnifferEnvironmentParser.ts +207 -0
  30. package/src/__tests__/EnvironmentParser.spec.ts +147 -0
  31. package/src/__tests__/SnifferEnvironmentParser.spec.ts +332 -0
  32. package/src/index.ts +1 -1
  33. package/dist/__tests__/ConfigParser.spec.cjs +0 -323
  34. package/dist/__tests__/ConfigParser.spec.d.cts +0 -1
  35. package/dist/__tests__/ConfigParser.spec.d.mts +0 -1
  36. package/dist/__tests__/ConfigParser.spec.mjs +0 -322
  37. package/dist/__tests__/EnvironmentParser.spec.cjs +0 -422
  38. package/dist/__tests__/EnvironmentParser.spec.d.cts +0 -1
  39. package/dist/__tests__/EnvironmentParser.spec.d.mts +0 -1
  40. package/dist/__tests__/EnvironmentParser.spec.mjs +0 -421
  41. package/dist/__tests__/sst.spec.cjs +0 -305
  42. package/dist/__tests__/sst.spec.d.cts +0 -1
  43. package/dist/__tests__/sst.spec.d.mts +0 -1
  44. package/dist/__tests__/sst.spec.mjs +0 -304
  45. package/dist/sst-BSxwaAdz.cjs +0 -146
  46. package/dist/sst-CQhO0S6y.mjs +0 -128
@@ -0,0 +1,50 @@
1
+ import { ConfigParser, EmptyObject, EnvFetcher } from "./EnvironmentParser-C_9v2BDw.mjs";
2
+
3
+ //#region src/SnifferEnvironmentParser.d.ts
4
+
5
+ /**
6
+ * A specialized EnvironmentParser for build-time analysis that tracks
7
+ * which environment variables are accessed without requiring actual values.
8
+ *
9
+ * Unlike the regular EnvironmentParser, the sniffer:
10
+ * - Always returns mock values from .parse() and .safeParse()
11
+ * - Never throws validation errors
12
+ * - Tracks all accessed environment variable names
13
+ *
14
+ * This allows service registration to succeed during build-time analysis
15
+ * even when environment variables are not set.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const sniffer = new SnifferEnvironmentParser();
20
+ * await service.register(sniffer); // Always succeeds
21
+ * const envVars = sniffer.getEnvironmentVariables(); // ['DATABASE_URL', 'API_KEY']
22
+ * ```
23
+ */
24
+ declare class SnifferEnvironmentParser<T extends EmptyObject = EmptyObject> {
25
+ private readonly accessedVars;
26
+ /**
27
+ * Wraps a Zod schema to always return mock values.
28
+ * This ensures .parse() and .safeParse() never fail.
29
+ */
30
+ private wrapSchema;
31
+ /**
32
+ * Returns a mock value based on the Zod schema type.
33
+ */
34
+ private getMockValue;
35
+ /**
36
+ * Creates a proxied Zod getter that tracks environment variable access.
37
+ */
38
+ private getZodGetter;
39
+ /**
40
+ * Creates a ConfigParser that will return mock values when parsed.
41
+ */
42
+ create<TReturn extends EmptyObject>(builder: (get: EnvFetcher) => TReturn): ConfigParser<TReturn>;
43
+ /**
44
+ * Returns all environment variable names that were accessed.
45
+ */
46
+ getEnvironmentVariables(): string[];
47
+ }
48
+ //#endregion
49
+ export { SnifferEnvironmentParser };
50
+ //# sourceMappingURL=SnifferEnvironmentParser.d.mts.map
@@ -0,0 +1,139 @@
1
+ import { ConfigParser } from "./EnvironmentParser-STvN_RCc.mjs";
2
+ import { z } from "zod/v4";
3
+
4
+ //#region src/SnifferEnvironmentParser.ts
5
+ /**
6
+ * A specialized EnvironmentParser for build-time analysis that tracks
7
+ * which environment variables are accessed without requiring actual values.
8
+ *
9
+ * Unlike the regular EnvironmentParser, the sniffer:
10
+ * - Always returns mock values from .parse() and .safeParse()
11
+ * - Never throws validation errors
12
+ * - Tracks all accessed environment variable names
13
+ *
14
+ * This allows service registration to succeed during build-time analysis
15
+ * even when environment variables are not set.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const sniffer = new SnifferEnvironmentParser();
20
+ * await service.register(sniffer); // Always succeeds
21
+ * const envVars = sniffer.getEnvironmentVariables(); // ['DATABASE_URL', 'API_KEY']
22
+ * ```
23
+ */
24
+ var SnifferEnvironmentParser = class {
25
+ accessedVars = /* @__PURE__ */ new Set();
26
+ /**
27
+ * Wraps a Zod schema to always return mock values.
28
+ * This ensures .parse() and .safeParse() never fail.
29
+ */
30
+ wrapSchema = (schema, name) => {
31
+ return new Proxy(schema, { get: (target, prop) => {
32
+ if (prop === "parse") return () => this.getMockValue(target);
33
+ if (prop === "safeParse") return () => ({
34
+ success: true,
35
+ data: this.getMockValue(target)
36
+ });
37
+ const originalProp = target[prop];
38
+ if (typeof originalProp === "function") return (...args) => {
39
+ const result = originalProp.apply(target, args);
40
+ if (result && typeof result === "object" && "parse" in result) return this.wrapSchema(result, name);
41
+ return result;
42
+ };
43
+ return originalProp;
44
+ } });
45
+ };
46
+ /**
47
+ * Returns a mock value based on the Zod schema type.
48
+ */
49
+ getMockValue(schema) {
50
+ if (schema instanceof z.ZodString) return "";
51
+ if (schema instanceof z.ZodNumber) return 0;
52
+ if (schema instanceof z.ZodBoolean) return false;
53
+ if (schema instanceof z.ZodArray) return [];
54
+ if (schema instanceof z.ZodOptional) return void 0;
55
+ if (schema instanceof z.ZodNullable) return null;
56
+ if (schema instanceof z.ZodObject && schema.shape) {
57
+ const result = {};
58
+ for (const [key, value] of Object.entries(schema.shape)) if (value instanceof z.ZodType) result[key] = this.getMockValue(value);
59
+ return result;
60
+ }
61
+ return "";
62
+ }
63
+ /**
64
+ * Creates a proxied Zod getter that tracks environment variable access.
65
+ */
66
+ getZodGetter = (name) => {
67
+ this.accessedVars.add(name);
68
+ return new Proxy({ ...z }, { get: (target, prop) => {
69
+ const value = target[prop];
70
+ if (typeof value === "function") return (...args) => {
71
+ const schema = value(...args);
72
+ return this.wrapSchema(schema, name);
73
+ };
74
+ if (value && typeof value === "object") return new Proxy(value, { get: (nestedTarget, nestedProp) => {
75
+ const nestedValue = nestedTarget[nestedProp];
76
+ if (typeof nestedValue === "function") return (...args) => {
77
+ const schema = nestedValue(...args);
78
+ return this.wrapSchema(schema, name);
79
+ };
80
+ return nestedValue;
81
+ } });
82
+ return value;
83
+ } });
84
+ };
85
+ /**
86
+ * Creates a ConfigParser that will return mock values when parsed.
87
+ */
88
+ create(builder) {
89
+ const config = builder(this.getZodGetter);
90
+ return new SnifferConfigParser(config, this.accessedVars);
91
+ }
92
+ /**
93
+ * Returns all environment variable names that were accessed.
94
+ */
95
+ getEnvironmentVariables() {
96
+ return Array.from(this.accessedVars).sort();
97
+ }
98
+ };
99
+ /**
100
+ * A ConfigParser that always succeeds with mock values.
101
+ */
102
+ var SnifferConfigParser = class extends ConfigParser {
103
+ parse() {
104
+ return this.parseWithMocks(this.getConfig());
105
+ }
106
+ getConfig() {
107
+ return this.config;
108
+ }
109
+ parseWithMocks(config) {
110
+ const result = {};
111
+ if (config && typeof config !== "object") return config;
112
+ for (const key in config) {
113
+ const schema = config[key];
114
+ if (schema instanceof z.ZodType) {
115
+ const parsed = schema.safeParse(void 0);
116
+ result[key] = parsed.success ? parsed.data : this.getDefaultForSchema(schema);
117
+ } else if (schema && typeof schema === "object") result[key] = this.parseWithMocks(schema);
118
+ }
119
+ return result;
120
+ }
121
+ getDefaultForSchema(schema) {
122
+ if (schema instanceof z.ZodString) return "";
123
+ if (schema instanceof z.ZodNumber) return 0;
124
+ if (schema instanceof z.ZodBoolean) return false;
125
+ if (schema instanceof z.ZodArray) return [];
126
+ if (schema instanceof z.ZodOptional) return void 0;
127
+ if (schema instanceof z.ZodNullable) return null;
128
+ if (schema instanceof z.ZodObject && schema.shape) {
129
+ const result = {};
130
+ for (const [key, value] of Object.entries(schema.shape)) if (value instanceof z.ZodType) result[key] = this.getDefaultForSchema(value);
131
+ return result;
132
+ }
133
+ return "";
134
+ }
135
+ };
136
+
137
+ //#endregion
138
+ export { SnifferEnvironmentParser };
139
+ //# sourceMappingURL=SnifferEnvironmentParser.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SnifferEnvironmentParser.mjs","names":["schema: z.ZodType","name: string","result: Record<string, unknown>","builder: (get: EnvFetcher) => TReturn","config: T","result: EmptyObject"],"sources":["../src/SnifferEnvironmentParser.ts"],"sourcesContent":["import { z } from 'zod/v4';\nimport {\n ConfigParser,\n type EmptyObject,\n type EnvFetcher,\n} from './EnvironmentParser';\n\n/**\n * A specialized EnvironmentParser for build-time analysis that tracks\n * which environment variables are accessed without requiring actual values.\n *\n * Unlike the regular EnvironmentParser, the sniffer:\n * - Always returns mock values from .parse() and .safeParse()\n * - Never throws validation errors\n * - Tracks all accessed environment variable names\n *\n * This allows service registration to succeed during build-time analysis\n * even when environment variables are not set.\n *\n * @example\n * ```typescript\n * const sniffer = new SnifferEnvironmentParser();\n * await service.register(sniffer); // Always succeeds\n * const envVars = sniffer.getEnvironmentVariables(); // ['DATABASE_URL', 'API_KEY']\n * ```\n */\nexport class SnifferEnvironmentParser<\n T extends EmptyObject = EmptyObject,\n> {\n private readonly accessedVars: Set<string> = new Set();\n\n /**\n * Wraps a Zod schema to always return mock values.\n * This ensures .parse() and .safeParse() never fail.\n */\n private wrapSchema = (schema: z.ZodType, name: string): z.ZodType => {\n return new Proxy(schema, {\n get: (target, prop) => {\n if (prop === 'parse') {\n return () => this.getMockValue(target);\n }\n\n if (prop === 'safeParse') {\n return () => ({\n success: true as const,\n data: this.getMockValue(target),\n });\n }\n\n const originalProp = target[prop as keyof typeof target];\n if (typeof originalProp === 'function') {\n return (...args: any[]) => {\n const result = originalProp.apply(target, args);\n if (result && typeof result === 'object' && 'parse' in result) {\n return this.wrapSchema(result, name);\n }\n return result;\n };\n }\n\n return originalProp;\n },\n });\n };\n\n /**\n * Returns a mock value based on the Zod schema type.\n */\n private getMockValue(schema: z.ZodType): unknown {\n // Return type-appropriate mock values\n if (schema instanceof z.ZodString) return '';\n if (schema instanceof z.ZodNumber) return 0;\n if (schema instanceof z.ZodBoolean) return false;\n if (schema instanceof z.ZodArray) return [];\n if (schema instanceof z.ZodOptional) return undefined;\n if (schema instanceof z.ZodNullable) return null;\n\n // For object schemas, build mock object from shape\n if (schema instanceof z.ZodObject && schema.shape) {\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(schema.shape)) {\n if (value instanceof z.ZodType) {\n result[key] = this.getMockValue(value);\n }\n }\n return result;\n }\n\n return '';\n }\n\n /**\n * Creates a proxied Zod getter that tracks environment variable access.\n */\n private getZodGetter = (name: string) => {\n this.accessedVars.add(name);\n\n return new Proxy(\n { ...z },\n {\n get: (target, prop) => {\n // @ts-ignore\n const value = target[prop];\n\n if (typeof value === 'function') {\n return (...args: any[]) => {\n const schema = value(...args);\n return this.wrapSchema(schema, name);\n };\n }\n\n if (value && typeof value === 'object') {\n return new Proxy(value, {\n get: (nestedTarget, nestedProp) => {\n const nestedValue =\n nestedTarget[nestedProp as keyof typeof nestedTarget];\n if (typeof nestedValue === 'function') {\n return (...args: any[]) => {\n const schema = nestedValue(...args);\n return this.wrapSchema(schema, name);\n };\n }\n return nestedValue;\n },\n });\n }\n\n return value;\n },\n },\n );\n };\n\n /**\n * Creates a ConfigParser that will return mock values when parsed.\n */\n create<TReturn extends EmptyObject>(\n builder: (get: EnvFetcher) => TReturn,\n ): ConfigParser<TReturn> {\n const config = builder(this.getZodGetter);\n return new SnifferConfigParser(config, this.accessedVars);\n }\n\n /**\n * Returns all environment variable names that were accessed.\n */\n getEnvironmentVariables(): string[] {\n return Array.from(this.accessedVars).sort();\n }\n}\n\n/**\n * A ConfigParser that always succeeds with mock values.\n */\nclass SnifferConfigParser<TResponse extends EmptyObject> extends ConfigParser<TResponse> {\n parse(): any {\n return this.parseWithMocks(this.getConfig());\n }\n\n private getConfig(): TResponse {\n // Access the private config via any cast\n return (this as any).config;\n }\n\n private parseWithMocks<T>(config: T): any {\n const result: EmptyObject = {};\n\n if (config && typeof config !== 'object') {\n return config;\n }\n\n for (const key in config) {\n const schema = config[key];\n\n if (schema instanceof z.ZodType) {\n // Use safeParse which will return mock values from our wrapped schema\n const parsed = schema.safeParse(undefined);\n result[key] = parsed.success ? parsed.data : this.getDefaultForSchema(schema);\n } else if (schema && typeof schema === 'object') {\n result[key] = this.parseWithMocks(schema as EmptyObject);\n }\n }\n\n return result;\n }\n\n private getDefaultForSchema(schema: z.ZodType): unknown {\n if (schema instanceof z.ZodString) return '';\n if (schema instanceof z.ZodNumber) return 0;\n if (schema instanceof z.ZodBoolean) return false;\n if (schema instanceof z.ZodArray) return [];\n if (schema instanceof z.ZodOptional) return undefined;\n if (schema instanceof z.ZodNullable) return null;\n\n if (schema instanceof z.ZodObject && schema.shape) {\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(schema.shape)) {\n if (value instanceof z.ZodType) {\n result[key] = this.getDefaultForSchema(value);\n }\n }\n return result;\n }\n\n return '';\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAa,2BAAb,MAEE;CACA,AAAiB,+BAA4B,IAAI;;;;;CAMjD,AAAQ,aAAa,CAACA,QAAmBC,SAA4B;AACnE,SAAO,IAAI,MAAM,QAAQ,EACvB,KAAK,CAAC,QAAQ,SAAS;AACrB,OAAI,SAAS,QACX,QAAO,MAAM,KAAK,aAAa,OAAO;AAGxC,OAAI,SAAS,YACX,QAAO,OAAO;IACZ,SAAS;IACT,MAAM,KAAK,aAAa,OAAO;GAChC;GAGH,MAAM,eAAe,OAAO;AAC5B,cAAW,iBAAiB,WAC1B,QAAO,CAAC,GAAG,SAAgB;IACzB,MAAM,SAAS,aAAa,MAAM,QAAQ,KAAK;AAC/C,QAAI,iBAAiB,WAAW,YAAY,WAAW,OACrD,QAAO,KAAK,WAAW,QAAQ,KAAK;AAEtC,WAAO;GACR;AAGH,UAAO;EACR,EACF;CACF;;;;CAKD,AAAQ,aAAaD,QAA4B;AAE/C,MAAI,kBAAkB,EAAE,UAAW,QAAO;AAC1C,MAAI,kBAAkB,EAAE,UAAW,QAAO;AAC1C,MAAI,kBAAkB,EAAE,WAAY,QAAO;AAC3C,MAAI,kBAAkB,EAAE,SAAU,QAAO,CAAE;AAC3C,MAAI,kBAAkB,EAAE,YAAa;AACrC,MAAI,kBAAkB,EAAE,YAAa,QAAO;AAG5C,MAAI,kBAAkB,EAAE,aAAa,OAAO,OAAO;GACjD,MAAME,SAAkC,CAAE;AAC1C,QAAK,MAAM,CAAC,KAAK,MAAM,IAAI,OAAO,QAAQ,OAAO,MAAM,CACrD,KAAI,iBAAiB,EAAE,QACrB,QAAO,OAAO,KAAK,aAAa,MAAM;AAG1C,UAAO;EACR;AAED,SAAO;CACR;;;;CAKD,AAAQ,eAAe,CAACD,SAAiB;AACvC,OAAK,aAAa,IAAI,KAAK;AAE3B,SAAO,IAAI,MACT,EAAE,GAAG,EAAG,GACR,EACE,KAAK,CAAC,QAAQ,SAAS;GAErB,MAAM,QAAQ,OAAO;AAErB,cAAW,UAAU,WACnB,QAAO,CAAC,GAAG,SAAgB;IACzB,MAAM,SAAS,MAAM,GAAG,KAAK;AAC7B,WAAO,KAAK,WAAW,QAAQ,KAAK;GACrC;AAGH,OAAI,gBAAgB,UAAU,SAC5B,QAAO,IAAI,MAAM,OAAO,EACtB,KAAK,CAAC,cAAc,eAAe;IACjC,MAAM,cACJ,aAAa;AACf,eAAW,gBAAgB,WACzB,QAAO,CAAC,GAAG,SAAgB;KACzB,MAAM,SAAS,YAAY,GAAG,KAAK;AACnC,YAAO,KAAK,WAAW,QAAQ,KAAK;IACrC;AAEH,WAAO;GACR,EACF;AAGH,UAAO;EACR,EACF;CAEJ;;;;CAKD,OACEE,SACuB;EACvB,MAAM,SAAS,QAAQ,KAAK,aAAa;AACzC,SAAO,IAAI,oBAAoB,QAAQ,KAAK;CAC7C;;;;CAKD,0BAAoC;AAClC,SAAO,MAAM,KAAK,KAAK,aAAa,CAAC,MAAM;CAC5C;AACF;;;;AAKD,IAAM,sBAAN,cAAiE,aAAwB;CACvF,QAAa;AACX,SAAO,KAAK,eAAe,KAAK,WAAW,CAAC;CAC7C;CAED,AAAQ,YAAuB;AAE7B,SAAQ,KAAa;CACtB;CAED,AAAQ,eAAkBC,QAAgB;EACxC,MAAMC,SAAsB,CAAE;AAE9B,MAAI,iBAAiB,WAAW,SAC9B,QAAO;AAGT,OAAK,MAAM,OAAO,QAAQ;GACxB,MAAM,SAAS,OAAO;AAEtB,OAAI,kBAAkB,EAAE,SAAS;IAE/B,MAAM,SAAS,OAAO,iBAAoB;AAC1C,WAAO,OAAO,OAAO,UAAU,OAAO,OAAO,KAAK,oBAAoB,OAAO;GAC9E,WAAU,iBAAiB,WAAW,SACrC,QAAO,OAAO,KAAK,eAAe,OAAsB;EAE3D;AAED,SAAO;CACR;CAED,AAAQ,oBAAoBL,QAA4B;AACtD,MAAI,kBAAkB,EAAE,UAAW,QAAO;AAC1C,MAAI,kBAAkB,EAAE,UAAW,QAAO;AAC1C,MAAI,kBAAkB,EAAE,WAAY,QAAO;AAC3C,MAAI,kBAAkB,EAAE,SAAU,QAAO,CAAE;AAC3C,MAAI,kBAAkB,EAAE,YAAa;AACrC,MAAI,kBAAkB,EAAE,YAAa,QAAO;AAE5C,MAAI,kBAAkB,EAAE,aAAa,OAAO,OAAO;GACjD,MAAME,SAAkC,CAAE;AAC1C,QAAK,MAAM,CAAC,KAAK,MAAM,IAAI,OAAO,QAAQ,OAAO,MAAM,CACrD,KAAI,iBAAiB,EAAE,QACrB,QAAO,OAAO,KAAK,oBAAoB,MAAM;AAGjD,UAAO;EACR;AAED,SAAO;CACR;AACF"}
package/dist/index.cjs CHANGED
@@ -1,3 +1,4 @@
1
- const require_EnvironmentParser = require('./EnvironmentParser-BDPDLv6i.cjs');
1
+ const require_EnvironmentParser = require('./EnvironmentParser-cnxuy7lw.cjs');
2
2
 
3
+ exports.ConfigParser = require_EnvironmentParser.ConfigParser;
3
4
  exports.EnvironmentParser = require_EnvironmentParser.EnvironmentParser;
package/dist/index.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- import { EnvironmentParser } from "./EnvironmentParser-X4h2Vp4r.cjs";
2
- export { EnvironmentParser };
1
+ import { ConfigParser, EnvironmentParser } from "./EnvironmentParser-B8--woiB.cjs";
2
+ export { ConfigParser, EnvironmentParser };
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { EnvironmentParser } from "./EnvironmentParser-C-arQEHQ.mjs";
2
- export { EnvironmentParser };
1
+ import { ConfigParser, EnvironmentParser } from "./EnvironmentParser-C_9v2BDw.mjs";
2
+ export { ConfigParser, EnvironmentParser };
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { EnvironmentParser } from "./EnvironmentParser-CQUOGqc0.mjs";
1
+ import { ConfigParser, EnvironmentParser } from "./EnvironmentParser-STvN_RCc.mjs";
2
2
 
3
- export { EnvironmentParser };
3
+ export { ConfigParser, EnvironmentParser };
package/dist/sst.cjs CHANGED
@@ -1,5 +1,132 @@
1
- const require_sst = require('./sst-BSxwaAdz.cjs');
1
+ const require_chunk = require('./chunk-CUT6urMc.cjs');
2
+ const lodash_snakecase = require_chunk.__toESM(require("lodash.snakecase"));
2
3
 
3
- exports.ResourceType = require_sst.ResourceType;
4
- exports.environmentCase = require_sst.environmentCase;
5
- exports.normalizeResourceEnv = require_sst.normalizeResourceEnv;
4
+ //#region src/sst.ts
5
+ /**
6
+ * Converts a string to environment variable case format (UPPER_SNAKE_CASE).
7
+ * Numbers following underscores are preserved without the underscore.
8
+ *
9
+ * @param name - The string to convert
10
+ * @returns The converted string in environment variable format
11
+ *
12
+ * @example
13
+ * environmentCase('myVariable') // 'MY_VARIABLE'
14
+ * environmentCase('api_v2') // 'APIV2'
15
+ */
16
+ function environmentCase(name) {
17
+ return (0, lodash_snakecase.default)(name).toUpperCase().replace(/_\d+/g, (r) => {
18
+ return r.replace("_", "");
19
+ });
20
+ }
21
+ /**
22
+ * Enumeration of supported SST (Serverless Stack Toolkit) resource types.
23
+ * Used to identify and process different AWS and SST resources.
24
+ */
25
+ let ResourceType = /* @__PURE__ */ function(ResourceType$1) {
26
+ ResourceType$1["ApiGatewayV2"] = "sst.aws.ApiGatewayV2";
27
+ ResourceType$1["Postgres"] = "sst.aws.Postgres";
28
+ ResourceType$1["Function"] = "sst.aws.Function";
29
+ ResourceType$1["Bucket"] = "sst.aws.Bucket";
30
+ ResourceType$1["Vpc"] = "sst.aws.Vpc";
31
+ ResourceType$1["Secret"] = "sst.sst.Secret";
32
+ ResourceType$1["SSTSecret"] = "sst:sst:Secret";
33
+ ResourceType$1["SSTFunction"] = "sst:sst:Function";
34
+ ResourceType$1["SSTApiGatewayV2"] = "sst:aws:ApiGatewayV2";
35
+ ResourceType$1["SSTPostgres"] = "sst:aws:Postgres";
36
+ ResourceType$1["SSTBucket"] = "sst:aws:Bucket";
37
+ return ResourceType$1;
38
+ }({});
39
+ /**
40
+ * Processes a Secret resource into environment variables.
41
+ *
42
+ * @param name - The resource name
43
+ * @param value - The Secret resource
44
+ * @returns Object with environment variable mappings
45
+ */
46
+ const secret = (name, value) => ({ [environmentCase(name)]: value.value });
47
+ /**
48
+ * Processes a Postgres database resource into environment variables.
49
+ * Creates multiple environment variables for database connection details.
50
+ *
51
+ * @param key - The resource key
52
+ * @param value - The Postgres resource
53
+ * @returns Object with database connection environment variables
54
+ */
55
+ const postgres = (key, value) => {
56
+ const prefix = `${environmentCase(key)}`;
57
+ return {
58
+ [`${prefix}_NAME`]: value.database,
59
+ [`${prefix}_HOST`]: value.host,
60
+ [`${prefix}_PASSWORD`]: value.password,
61
+ [`${prefix}_PORT`]: value.port,
62
+ [`${prefix}_USERNAME`]: value.username
63
+ };
64
+ };
65
+ /**
66
+ * Processes a Bucket resource into environment variables.
67
+ *
68
+ * @param name - The resource name
69
+ * @param value - The Bucket resource
70
+ * @returns Object with bucket name environment variable
71
+ */
72
+ const bucket = (name, value) => {
73
+ const prefix = `${environmentCase(name)}`;
74
+ return { [`${prefix}_NAME`]: value.name };
75
+ };
76
+ /**
77
+ * No-operation processor for resources that don't require environment variables.
78
+ *
79
+ * @param name - The resource name (unused)
80
+ * @param value - The resource value (unused)
81
+ * @returns Empty object
82
+ */
83
+ const noop = (name, value) => ({});
84
+ /**
85
+ * Map of resource types to their corresponding processor functions.
86
+ * Each processor converts resource data into environment variables.
87
+ */
88
+ const processors = {
89
+ [ResourceType.ApiGatewayV2]: noop,
90
+ [ResourceType.Function]: noop,
91
+ [ResourceType.Vpc]: noop,
92
+ [ResourceType.Secret]: secret,
93
+ [ResourceType.Postgres]: postgres,
94
+ [ResourceType.Bucket]: bucket,
95
+ [ResourceType.SSTSecret]: secret,
96
+ [ResourceType.SSTBucket]: bucket,
97
+ [ResourceType.SSTFunction]: noop,
98
+ [ResourceType.SSTPostgres]: postgres,
99
+ [ResourceType.SSTApiGatewayV2]: noop
100
+ };
101
+ /**
102
+ * Normalizes SST resources and plain strings into environment variables.
103
+ * Processes resources based on their type and converts names to environment case.
104
+ *
105
+ * @param record - Object containing resources and/or string values
106
+ * @returns Normalized environment variables object
107
+ *
108
+ * @example
109
+ * normalizeResourceEnv({
110
+ * apiUrl: 'https://api.example.com',
111
+ * database: { type: ResourceType.Postgres, ... }
112
+ * })
113
+ */
114
+ function normalizeResourceEnv(record) {
115
+ const env = {};
116
+ for (const [k, value] of Object.entries(record)) {
117
+ if (typeof value === "string") {
118
+ env[environmentCase(k)] = value;
119
+ continue;
120
+ }
121
+ const processor = processors[value.type];
122
+ if (processor) Object.assign(env, processor(k, value));
123
+ else console.warn(`No processor found for resource type: `, { value });
124
+ }
125
+ return env;
126
+ }
127
+
128
+ //#endregion
129
+ exports.ResourceType = ResourceType;
130
+ exports.environmentCase = environmentCase;
131
+ exports.normalizeResourceEnv = normalizeResourceEnv;
132
+ //# sourceMappingURL=sst.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sst.cjs","names":["name: string","value: Secret","key: string","value: Postgres","value: Bucket","value: any","processors: Record<ResourceType, ResourceProcessor<any>>","record: Record<string, Resource | string>","env: Record<string, string>"],"sources":["../src/sst.ts"],"sourcesContent":["import snakecase from 'lodash.snakecase';\n\n/**\n * Converts a string to environment variable case format (UPPER_SNAKE_CASE).\n * Numbers following underscores are preserved without the underscore.\n *\n * @param name - The string to convert\n * @returns The converted string in environment variable format\n *\n * @example\n * environmentCase('myVariable') // 'MY_VARIABLE'\n * environmentCase('api_v2') // 'APIV2'\n */\nexport function environmentCase(name: string) {\n return snakecase(name)\n .toUpperCase()\n .replace(/_\\d+/g, (r) => {\n return r.replace('_', '');\n });\n}\n\n/**\n * Enumeration of supported SST (Serverless Stack Toolkit) resource types.\n * Used to identify and process different AWS and SST resources.\n */\nexport enum ResourceType {\n ApiGatewayV2 = 'sst.aws.ApiGatewayV2',\n Postgres = 'sst.aws.Postgres',\n Function = 'sst.aws.Function',\n Bucket = 'sst.aws.Bucket',\n Vpc = 'sst.aws.Vpc',\n Secret = 'sst.sst.Secret',\n SSTSecret = 'sst:sst:Secret',\n SSTFunction = 'sst:sst:Function',\n SSTApiGatewayV2 = 'sst:aws:ApiGatewayV2',\n SSTPostgres = 'sst:aws:Postgres',\n SSTBucket = 'sst:aws:Bucket',\n}\n\n/**\n * Processes a Secret resource into environment variables.\n *\n * @param name - The resource name\n * @param value - The Secret resource\n * @returns Object with environment variable mappings\n */\nconst secret = (name: string, value: Secret) => ({\n [environmentCase(name)]: value.value,\n});\n/**\n * Processes a Postgres database resource into environment variables.\n * Creates multiple environment variables for database connection details.\n *\n * @param key - The resource key\n * @param value - The Postgres resource\n * @returns Object with database connection environment variables\n */\nconst postgres = (key: string, value: Postgres) => {\n const prefix = `${environmentCase(key)}`;\n return {\n [`${prefix}_NAME`]: value.database,\n [`${prefix}_HOST`]: value.host,\n [`${prefix}_PASSWORD`]: value.password,\n [`${prefix}_PORT`]: value.port,\n [`${prefix}_USERNAME`]: value.username,\n };\n};\n\n/**\n * Processes a Bucket resource into environment variables.\n *\n * @param name - The resource name\n * @param value - The Bucket resource\n * @returns Object with bucket name environment variable\n */\nconst bucket = (name: string, value: Bucket) => {\n const prefix = `${environmentCase(name)}`;\n return {\n [`${prefix}_NAME`]: value.name,\n };\n};\n\n/**\n * No-operation processor for resources that don't require environment variables.\n *\n * @param name - The resource name (unused)\n * @param value - The resource value (unused)\n * @returns Empty object\n */\nconst noop = (name: string, value: any) => ({});\n\n/**\n * Map of resource types to their corresponding processor functions.\n * Each processor converts resource data into environment variables.\n */\nconst processors: Record<ResourceType, ResourceProcessor<any>> = {\n [ResourceType.ApiGatewayV2]: noop,\n [ResourceType.Function]: noop,\n [ResourceType.Vpc]: noop,\n [ResourceType.Secret]: secret,\n [ResourceType.Postgres]: postgres,\n [ResourceType.Bucket]: bucket,\n\n [ResourceType.SSTSecret]: secret,\n [ResourceType.SSTBucket]: bucket,\n [ResourceType.SSTFunction]: noop,\n [ResourceType.SSTPostgres]: postgres,\n [ResourceType.SSTApiGatewayV2]: noop,\n};\n\n/**\n * Normalizes SST resources and plain strings into environment variables.\n * Processes resources based on their type and converts names to environment case.\n *\n * @param record - Object containing resources and/or string values\n * @returns Normalized environment variables object\n *\n * @example\n * normalizeResourceEnv({\n * apiUrl: 'https://api.example.com',\n * database: { type: ResourceType.Postgres, ... }\n * })\n */\nexport function normalizeResourceEnv(\n record: Record<string, Resource | string>,\n): Record<string, string> {\n const env: Record<string, string> = {};\n for (const [k, value] of Object.entries(record)) {\n if (typeof value === 'string') {\n env[environmentCase(k)] = value;\n continue;\n }\n\n const processor = processors[value.type];\n if (processor) {\n Object.assign(env, processor(k, value));\n } else {\n console.warn(`No processor found for resource type: `, { value });\n }\n }\n\n return env;\n}\n\n/**\n * AWS API Gateway V2 resource type.\n * Represents an HTTP/WebSocket API.\n */\nexport type ApiGatewayV2 = {\n type: ResourceType.ApiGatewayV2;\n url: string;\n};\n\n/**\n * PostgreSQL database resource type.\n * Contains all connection details needed to connect to the database.\n */\nexport type Postgres = {\n database: string;\n host: string;\n password: string;\n port: number;\n type: ResourceType.Postgres;\n username: string;\n};\n\n/**\n * AWS Lambda Function resource type.\n */\nexport type Function = {\n name: string;\n type: ResourceType.Function;\n};\n\n/**\n * AWS S3 Bucket resource type.\n */\nexport type Bucket = {\n name: string;\n type: ResourceType.Bucket;\n};\n\n/**\n * AWS VPC (Virtual Private Cloud) resource type.\n */\nexport type Vpc = {\n bastion: string;\n type: ResourceType.Vpc;\n};\n\n/**\n * Secret resource type for storing sensitive values.\n */\nexport type Secret = {\n type: ResourceType.Secret;\n value: string;\n};\n\n/**\n * Union type of all supported SST resource types.\n */\nexport type Resource =\n | ApiGatewayV2\n | Postgres\n | Function\n | Bucket\n | Vpc\n | Secret;\n\n/**\n * Function type for processing a specific resource type into environment variables.\n *\n * @template K - The specific resource type\n * @param name - The resource name\n * @param value - The resource value\n * @returns Object mapping environment variable names to values\n */\nexport type ResourceProcessor<K extends Resource> = (\n name: string,\n value: K,\n) => Record<string, string | number>;\n"],"mappings":";;;;;;;;;;;;;;;AAaA,SAAgB,gBAAgBA,MAAc;AAC5C,QAAO,8BAAU,KAAK,CACnB,aAAa,CACb,QAAQ,SAAS,CAAC,MAAM;AACvB,SAAO,EAAE,QAAQ,KAAK,GAAG;CAC1B,EAAC;AACL;;;;;AAMD,IAAY,wDAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACD;;;;;;;;AASD,MAAM,SAAS,CAACA,MAAcC,WAAmB,GAC9C,gBAAgB,KAAK,GAAG,MAAM,MAChC;;;;;;;;;AASD,MAAM,WAAW,CAACC,KAAaC,UAAoB;CACjD,MAAM,UAAU,EAAE,gBAAgB,IAAI,CAAC;AACvC,QAAO;IACH,EAAE,OAAO,SAAS,MAAM;IACxB,EAAE,OAAO,SAAS,MAAM;IACxB,EAAE,OAAO,aAAa,MAAM;IAC5B,EAAE,OAAO,SAAS,MAAM;IACxB,EAAE,OAAO,aAAa,MAAM;CAC/B;AACF;;;;;;;;AASD,MAAM,SAAS,CAACH,MAAcI,UAAkB;CAC9C,MAAM,UAAU,EAAE,gBAAgB,KAAK,CAAC;AACxC,QAAO,IACH,EAAE,OAAO,SAAS,MAAM,KAC3B;AACF;;;;;;;;AASD,MAAM,OAAO,CAACJ,MAAcK,WAAgB,CAAE;;;;;AAM9C,MAAMC,aAA2D;EAC9D,aAAa,eAAe;EAC5B,aAAa,WAAW;EACxB,aAAa,MAAM;EACnB,aAAa,SAAS;EACtB,aAAa,WAAW;EACxB,aAAa,SAAS;EAEtB,aAAa,YAAY;EACzB,aAAa,YAAY;EACzB,aAAa,cAAc;EAC3B,aAAa,cAAc;EAC3B,aAAa,kBAAkB;AACjC;;;;;;;;;;;;;;AAeD,SAAgB,qBACdC,QACwB;CACxB,MAAMC,MAA8B,CAAE;AACtC,MAAK,MAAM,CAAC,GAAG,MAAM,IAAI,OAAO,QAAQ,OAAO,EAAE;AAC/C,aAAW,UAAU,UAAU;AAC7B,OAAI,gBAAgB,EAAE,IAAI;AAC1B;EACD;EAED,MAAM,YAAY,WAAW,MAAM;AACnC,MAAI,UACF,QAAO,OAAO,KAAK,UAAU,GAAG,MAAM,CAAC;MAEvC,SAAQ,MAAM,yCAAyC,EAAE,MAAO,EAAC;CAEpE;AAED,QAAO;AACR"}
package/dist/sst.d.cts CHANGED
@@ -104,4 +104,5 @@ type Resource = ApiGatewayV2 | Postgres | Function | Bucket | Vpc | Secret;
104
104
  */
105
105
  type ResourceProcessor<K extends Resource> = (name: string, value: K) => Record<string, string | number>;
106
106
  //#endregion
107
- export { ApiGatewayV2, Bucket, Function, Postgres, Resource, ResourceProcessor, ResourceType, Secret, Vpc, environmentCase, normalizeResourceEnv };
107
+ export { ApiGatewayV2, Bucket, Function, Postgres, Resource, ResourceProcessor, ResourceType, Secret, Vpc, environmentCase, normalizeResourceEnv };
108
+ //# sourceMappingURL=sst.d.cts.map
package/dist/sst.d.mts CHANGED
@@ -104,4 +104,5 @@ type Resource = ApiGatewayV2 | Postgres | Function | Bucket | Vpc | Secret;
104
104
  */
105
105
  type ResourceProcessor<K extends Resource> = (name: string, value: K) => Record<string, string | number>;
106
106
  //#endregion
107
- export { ApiGatewayV2, Bucket, Function, Postgres, Resource, ResourceProcessor, ResourceType, Secret, Vpc, environmentCase, normalizeResourceEnv };
107
+ export { ApiGatewayV2, Bucket, Function, Postgres, Resource, ResourceProcessor, ResourceType, Secret, Vpc, environmentCase, normalizeResourceEnv };
108
+ //# sourceMappingURL=sst.d.mts.map
package/dist/sst.mjs CHANGED
@@ -1,3 +1,129 @@
1
- import { ResourceType, environmentCase, normalizeResourceEnv } from "./sst-CQhO0S6y.mjs";
1
+ import snakecase from "lodash.snakecase";
2
2
 
3
- export { ResourceType, environmentCase, normalizeResourceEnv };
3
+ //#region src/sst.ts
4
+ /**
5
+ * Converts a string to environment variable case format (UPPER_SNAKE_CASE).
6
+ * Numbers following underscores are preserved without the underscore.
7
+ *
8
+ * @param name - The string to convert
9
+ * @returns The converted string in environment variable format
10
+ *
11
+ * @example
12
+ * environmentCase('myVariable') // 'MY_VARIABLE'
13
+ * environmentCase('api_v2') // 'APIV2'
14
+ */
15
+ function environmentCase(name) {
16
+ return snakecase(name).toUpperCase().replace(/_\d+/g, (r) => {
17
+ return r.replace("_", "");
18
+ });
19
+ }
20
+ /**
21
+ * Enumeration of supported SST (Serverless Stack Toolkit) resource types.
22
+ * Used to identify and process different AWS and SST resources.
23
+ */
24
+ let ResourceType = /* @__PURE__ */ function(ResourceType$1) {
25
+ ResourceType$1["ApiGatewayV2"] = "sst.aws.ApiGatewayV2";
26
+ ResourceType$1["Postgres"] = "sst.aws.Postgres";
27
+ ResourceType$1["Function"] = "sst.aws.Function";
28
+ ResourceType$1["Bucket"] = "sst.aws.Bucket";
29
+ ResourceType$1["Vpc"] = "sst.aws.Vpc";
30
+ ResourceType$1["Secret"] = "sst.sst.Secret";
31
+ ResourceType$1["SSTSecret"] = "sst:sst:Secret";
32
+ ResourceType$1["SSTFunction"] = "sst:sst:Function";
33
+ ResourceType$1["SSTApiGatewayV2"] = "sst:aws:ApiGatewayV2";
34
+ ResourceType$1["SSTPostgres"] = "sst:aws:Postgres";
35
+ ResourceType$1["SSTBucket"] = "sst:aws:Bucket";
36
+ return ResourceType$1;
37
+ }({});
38
+ /**
39
+ * Processes a Secret resource into environment variables.
40
+ *
41
+ * @param name - The resource name
42
+ * @param value - The Secret resource
43
+ * @returns Object with environment variable mappings
44
+ */
45
+ const secret = (name, value) => ({ [environmentCase(name)]: value.value });
46
+ /**
47
+ * Processes a Postgres database resource into environment variables.
48
+ * Creates multiple environment variables for database connection details.
49
+ *
50
+ * @param key - The resource key
51
+ * @param value - The Postgres resource
52
+ * @returns Object with database connection environment variables
53
+ */
54
+ const postgres = (key, value) => {
55
+ const prefix = `${environmentCase(key)}`;
56
+ return {
57
+ [`${prefix}_NAME`]: value.database,
58
+ [`${prefix}_HOST`]: value.host,
59
+ [`${prefix}_PASSWORD`]: value.password,
60
+ [`${prefix}_PORT`]: value.port,
61
+ [`${prefix}_USERNAME`]: value.username
62
+ };
63
+ };
64
+ /**
65
+ * Processes a Bucket resource into environment variables.
66
+ *
67
+ * @param name - The resource name
68
+ * @param value - The Bucket resource
69
+ * @returns Object with bucket name environment variable
70
+ */
71
+ const bucket = (name, value) => {
72
+ const prefix = `${environmentCase(name)}`;
73
+ return { [`${prefix}_NAME`]: value.name };
74
+ };
75
+ /**
76
+ * No-operation processor for resources that don't require environment variables.
77
+ *
78
+ * @param name - The resource name (unused)
79
+ * @param value - The resource value (unused)
80
+ * @returns Empty object
81
+ */
82
+ const noop = (name, value) => ({});
83
+ /**
84
+ * Map of resource types to their corresponding processor functions.
85
+ * Each processor converts resource data into environment variables.
86
+ */
87
+ const processors = {
88
+ [ResourceType.ApiGatewayV2]: noop,
89
+ [ResourceType.Function]: noop,
90
+ [ResourceType.Vpc]: noop,
91
+ [ResourceType.Secret]: secret,
92
+ [ResourceType.Postgres]: postgres,
93
+ [ResourceType.Bucket]: bucket,
94
+ [ResourceType.SSTSecret]: secret,
95
+ [ResourceType.SSTBucket]: bucket,
96
+ [ResourceType.SSTFunction]: noop,
97
+ [ResourceType.SSTPostgres]: postgres,
98
+ [ResourceType.SSTApiGatewayV2]: noop
99
+ };
100
+ /**
101
+ * Normalizes SST resources and plain strings into environment variables.
102
+ * Processes resources based on their type and converts names to environment case.
103
+ *
104
+ * @param record - Object containing resources and/or string values
105
+ * @returns Normalized environment variables object
106
+ *
107
+ * @example
108
+ * normalizeResourceEnv({
109
+ * apiUrl: 'https://api.example.com',
110
+ * database: { type: ResourceType.Postgres, ... }
111
+ * })
112
+ */
113
+ function normalizeResourceEnv(record) {
114
+ const env = {};
115
+ for (const [k, value] of Object.entries(record)) {
116
+ if (typeof value === "string") {
117
+ env[environmentCase(k)] = value;
118
+ continue;
119
+ }
120
+ const processor = processors[value.type];
121
+ if (processor) Object.assign(env, processor(k, value));
122
+ else console.warn(`No processor found for resource type: `, { value });
123
+ }
124
+ return env;
125
+ }
126
+
127
+ //#endregion
128
+ export { ResourceType, environmentCase, normalizeResourceEnv };
129
+ //# sourceMappingURL=sst.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sst.mjs","names":["name: string","value: Secret","key: string","value: Postgres","value: Bucket","value: any","processors: Record<ResourceType, ResourceProcessor<any>>","record: Record<string, Resource | string>","env: Record<string, string>"],"sources":["../src/sst.ts"],"sourcesContent":["import snakecase from 'lodash.snakecase';\n\n/**\n * Converts a string to environment variable case format (UPPER_SNAKE_CASE).\n * Numbers following underscores are preserved without the underscore.\n *\n * @param name - The string to convert\n * @returns The converted string in environment variable format\n *\n * @example\n * environmentCase('myVariable') // 'MY_VARIABLE'\n * environmentCase('api_v2') // 'APIV2'\n */\nexport function environmentCase(name: string) {\n return snakecase(name)\n .toUpperCase()\n .replace(/_\\d+/g, (r) => {\n return r.replace('_', '');\n });\n}\n\n/**\n * Enumeration of supported SST (Serverless Stack Toolkit) resource types.\n * Used to identify and process different AWS and SST resources.\n */\nexport enum ResourceType {\n ApiGatewayV2 = 'sst.aws.ApiGatewayV2',\n Postgres = 'sst.aws.Postgres',\n Function = 'sst.aws.Function',\n Bucket = 'sst.aws.Bucket',\n Vpc = 'sst.aws.Vpc',\n Secret = 'sst.sst.Secret',\n SSTSecret = 'sst:sst:Secret',\n SSTFunction = 'sst:sst:Function',\n SSTApiGatewayV2 = 'sst:aws:ApiGatewayV2',\n SSTPostgres = 'sst:aws:Postgres',\n SSTBucket = 'sst:aws:Bucket',\n}\n\n/**\n * Processes a Secret resource into environment variables.\n *\n * @param name - The resource name\n * @param value - The Secret resource\n * @returns Object with environment variable mappings\n */\nconst secret = (name: string, value: Secret) => ({\n [environmentCase(name)]: value.value,\n});\n/**\n * Processes a Postgres database resource into environment variables.\n * Creates multiple environment variables for database connection details.\n *\n * @param key - The resource key\n * @param value - The Postgres resource\n * @returns Object with database connection environment variables\n */\nconst postgres = (key: string, value: Postgres) => {\n const prefix = `${environmentCase(key)}`;\n return {\n [`${prefix}_NAME`]: value.database,\n [`${prefix}_HOST`]: value.host,\n [`${prefix}_PASSWORD`]: value.password,\n [`${prefix}_PORT`]: value.port,\n [`${prefix}_USERNAME`]: value.username,\n };\n};\n\n/**\n * Processes a Bucket resource into environment variables.\n *\n * @param name - The resource name\n * @param value - The Bucket resource\n * @returns Object with bucket name environment variable\n */\nconst bucket = (name: string, value: Bucket) => {\n const prefix = `${environmentCase(name)}`;\n return {\n [`${prefix}_NAME`]: value.name,\n };\n};\n\n/**\n * No-operation processor for resources that don't require environment variables.\n *\n * @param name - The resource name (unused)\n * @param value - The resource value (unused)\n * @returns Empty object\n */\nconst noop = (name: string, value: any) => ({});\n\n/**\n * Map of resource types to their corresponding processor functions.\n * Each processor converts resource data into environment variables.\n */\nconst processors: Record<ResourceType, ResourceProcessor<any>> = {\n [ResourceType.ApiGatewayV2]: noop,\n [ResourceType.Function]: noop,\n [ResourceType.Vpc]: noop,\n [ResourceType.Secret]: secret,\n [ResourceType.Postgres]: postgres,\n [ResourceType.Bucket]: bucket,\n\n [ResourceType.SSTSecret]: secret,\n [ResourceType.SSTBucket]: bucket,\n [ResourceType.SSTFunction]: noop,\n [ResourceType.SSTPostgres]: postgres,\n [ResourceType.SSTApiGatewayV2]: noop,\n};\n\n/**\n * Normalizes SST resources and plain strings into environment variables.\n * Processes resources based on their type and converts names to environment case.\n *\n * @param record - Object containing resources and/or string values\n * @returns Normalized environment variables object\n *\n * @example\n * normalizeResourceEnv({\n * apiUrl: 'https://api.example.com',\n * database: { type: ResourceType.Postgres, ... }\n * })\n */\nexport function normalizeResourceEnv(\n record: Record<string, Resource | string>,\n): Record<string, string> {\n const env: Record<string, string> = {};\n for (const [k, value] of Object.entries(record)) {\n if (typeof value === 'string') {\n env[environmentCase(k)] = value;\n continue;\n }\n\n const processor = processors[value.type];\n if (processor) {\n Object.assign(env, processor(k, value));\n } else {\n console.warn(`No processor found for resource type: `, { value });\n }\n }\n\n return env;\n}\n\n/**\n * AWS API Gateway V2 resource type.\n * Represents an HTTP/WebSocket API.\n */\nexport type ApiGatewayV2 = {\n type: ResourceType.ApiGatewayV2;\n url: string;\n};\n\n/**\n * PostgreSQL database resource type.\n * Contains all connection details needed to connect to the database.\n */\nexport type Postgres = {\n database: string;\n host: string;\n password: string;\n port: number;\n type: ResourceType.Postgres;\n username: string;\n};\n\n/**\n * AWS Lambda Function resource type.\n */\nexport type Function = {\n name: string;\n type: ResourceType.Function;\n};\n\n/**\n * AWS S3 Bucket resource type.\n */\nexport type Bucket = {\n name: string;\n type: ResourceType.Bucket;\n};\n\n/**\n * AWS VPC (Virtual Private Cloud) resource type.\n */\nexport type Vpc = {\n bastion: string;\n type: ResourceType.Vpc;\n};\n\n/**\n * Secret resource type for storing sensitive values.\n */\nexport type Secret = {\n type: ResourceType.Secret;\n value: string;\n};\n\n/**\n * Union type of all supported SST resource types.\n */\nexport type Resource =\n | ApiGatewayV2\n | Postgres\n | Function\n | Bucket\n | Vpc\n | Secret;\n\n/**\n * Function type for processing a specific resource type into environment variables.\n *\n * @template K - The specific resource type\n * @param name - The resource name\n * @param value - The resource value\n * @returns Object mapping environment variable names to values\n */\nexport type ResourceProcessor<K extends Resource> = (\n name: string,\n value: K,\n) => Record<string, string | number>;\n"],"mappings":";;;;;;;;;;;;;;AAaA,SAAgB,gBAAgBA,MAAc;AAC5C,QAAO,UAAU,KAAK,CACnB,aAAa,CACb,QAAQ,SAAS,CAAC,MAAM;AACvB,SAAO,EAAE,QAAQ,KAAK,GAAG;CAC1B,EAAC;AACL;;;;;AAMD,IAAY,wDAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACD;;;;;;;;AASD,MAAM,SAAS,CAACA,MAAcC,WAAmB,GAC9C,gBAAgB,KAAK,GAAG,MAAM,MAChC;;;;;;;;;AASD,MAAM,WAAW,CAACC,KAAaC,UAAoB;CACjD,MAAM,UAAU,EAAE,gBAAgB,IAAI,CAAC;AACvC,QAAO;IACH,EAAE,OAAO,SAAS,MAAM;IACxB,EAAE,OAAO,SAAS,MAAM;IACxB,EAAE,OAAO,aAAa,MAAM;IAC5B,EAAE,OAAO,SAAS,MAAM;IACxB,EAAE,OAAO,aAAa,MAAM;CAC/B;AACF;;;;;;;;AASD,MAAM,SAAS,CAACH,MAAcI,UAAkB;CAC9C,MAAM,UAAU,EAAE,gBAAgB,KAAK,CAAC;AACxC,QAAO,IACH,EAAE,OAAO,SAAS,MAAM,KAC3B;AACF;;;;;;;;AASD,MAAM,OAAO,CAACJ,MAAcK,WAAgB,CAAE;;;;;AAM9C,MAAMC,aAA2D;EAC9D,aAAa,eAAe;EAC5B,aAAa,WAAW;EACxB,aAAa,MAAM;EACnB,aAAa,SAAS;EACtB,aAAa,WAAW;EACxB,aAAa,SAAS;EAEtB,aAAa,YAAY;EACzB,aAAa,YAAY;EACzB,aAAa,cAAc;EAC3B,aAAa,cAAc;EAC3B,aAAa,kBAAkB;AACjC;;;;;;;;;;;;;;AAeD,SAAgB,qBACdC,QACwB;CACxB,MAAMC,MAA8B,CAAE;AACtC,MAAK,MAAM,CAAC,GAAG,MAAM,IAAI,OAAO,QAAQ,OAAO,EAAE;AAC/C,aAAW,UAAU,UAAU;AAC7B,OAAI,gBAAgB,EAAE,IAAI;AAC1B;EACD;EAED,MAAM,YAAY,WAAW,MAAM;AACnC,MAAI,UACF,QAAO,OAAO,KAAK,UAAU,GAAG,MAAM,CAAC;MAEvC,SAAQ,MAAM,yCAAyC,EAAE,MAAO,EAAC;CAEpE;AAED,QAAO;AACR"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geekmidas/envkit",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
@@ -13,6 +13,11 @@
13
13
  "types": "./dist/sst.d.ts",
14
14
  "import": "./dist/sst.mjs",
15
15
  "require": "./dist/sst.cjs"
16
+ },
17
+ "./sniffer": {
18
+ "types": "./dist/SnifferEnvironmentParser.d.ts",
19
+ "import": "./dist/SnifferEnvironmentParser.mjs",
20
+ "require": "./dist/SnifferEnvironmentParser.cjs"
16
21
  }
17
22
  },
18
23
  "publishConfig": {
@@ -13,8 +13,12 @@ export class ConfigParser<TResponse extends EmptyObject> {
13
13
  * Creates a new ConfigParser instance.
14
14
  *
15
15
  * @param config - The configuration object to parse
16
+ * @param envVars - Set of environment variable names that were accessed
16
17
  */
17
- constructor(private readonly config: TResponse) {}
18
+ constructor(
19
+ private readonly config: TResponse,
20
+ private readonly envVars: Set<string> = new Set(),
21
+ ) {}
18
22
  /**
19
23
  * Parses the config object and validates it against the Zod schemas
20
24
  * @returns The parsed config object
@@ -65,6 +69,26 @@ export class ConfigParser<TResponse extends EmptyObject> {
65
69
 
66
70
  return parsedConfig;
67
71
  }
72
+
73
+ /**
74
+ * Returns an array of environment variable names that were accessed during config creation.
75
+ * This is useful for deployment and configuration management to know which env vars are required.
76
+ *
77
+ * @returns Array of environment variable names, sorted alphabetically
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * const config = envParser.create((get) => ({
82
+ * dbUrl: get('DATABASE_URL').string(),
83
+ * port: get('PORT').number()
84
+ * }));
85
+ *
86
+ * config.getEnvironmentVariables(); // ['DATABASE_URL', 'PORT']
87
+ * ```
88
+ */
89
+ getEnvironmentVariables(): string[] {
90
+ return Array.from(this.envVars).sort();
91
+ }
68
92
  }
69
93
 
70
94
  /**
@@ -87,6 +111,11 @@ export class ConfigParser<TResponse extends EmptyObject> {
87
111
  * ```
88
112
  */
89
113
  export class EnvironmentParser<T extends EmptyObject> {
114
+ /**
115
+ * Set to track which environment variable names have been accessed
116
+ */
117
+ private readonly accessedVars: Set<string> = new Set();
118
+
90
119
  /**
91
120
  * Creates a new EnvironmentParser instance.
92
121
  *
@@ -177,6 +206,9 @@ export class EnvironmentParser<T extends EmptyObject> {
177
206
  * @returns A proxied Zod object with wrapped schema creators
178
207
  */
179
208
  private getZodGetter = (name: string) => {
209
+ // Track that this environment variable was accessed
210
+ this.accessedVars.add(name);
211
+
180
212
  // Return an object that has all Zod schemas but with our wrapper
181
213
  return new Proxy(
182
214
  { ...z },
@@ -227,7 +259,24 @@ export class EnvironmentParser<T extends EmptyObject> {
227
259
  builder: (get: EnvFetcher) => TReturn,
228
260
  ): ConfigParser<TReturn> {
229
261
  const config = builder(this.getZodGetter);
230
- return new ConfigParser(config);
262
+ return new ConfigParser(config, this.accessedVars);
263
+ }
264
+
265
+ /**
266
+ * Returns an array of environment variable names that were accessed via the getter.
267
+ * This is useful for build-time analysis to determine which env vars a service needs.
268
+ *
269
+ * @returns Array of environment variable names, sorted alphabetically
270
+ *
271
+ * @example
272
+ * ```typescript
273
+ * const sniffer = new EnvironmentParser({});
274
+ * service.register(sniffer);
275
+ * const envVars = sniffer.getEnvironmentVariables(); // ['DATABASE_URL', 'PORT']
276
+ * ```
277
+ */
278
+ getEnvironmentVariables(): string[] {
279
+ return Array.from(this.accessedVars).sort();
231
280
  }
232
281
  }
233
282