@geekmidas/envkit 1.0.4 → 1.0.5

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 (79) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/{EnvironmentBuilder-BSuHZm0y.mjs → EnvironmentBuilder-CFen3oIg.mjs} +1 -1
  3. package/dist/{EnvironmentBuilder-BSuHZm0y.mjs.map → EnvironmentBuilder-CFen3oIg.mjs.map} +1 -1
  4. package/dist/{EnvironmentBuilder-Xuf2Dd9u.d.cts → EnvironmentBuilder-CNgcdzSR.d.cts} +1 -1
  5. package/dist/{EnvironmentBuilder-Xuf2Dd9u.d.cts.map → EnvironmentBuilder-CNgcdzSR.d.cts.map} +1 -1
  6. package/dist/{EnvironmentBuilder-Djr1VsWM.cjs → EnvironmentBuilder-DDgLJAAo.cjs} +1 -1
  7. package/dist/{EnvironmentBuilder-Djr1VsWM.cjs.map → EnvironmentBuilder-DDgLJAAo.cjs.map} +1 -1
  8. package/dist/{EnvironmentBuilder-jF-b7WQg.d.mts → EnvironmentBuilder-DHfDXJUm.d.mts} +1 -1
  9. package/dist/{EnvironmentBuilder-jF-b7WQg.d.mts.map → EnvironmentBuilder-DHfDXJUm.d.mts.map} +1 -1
  10. package/dist/{EnvironmentParser-DtOL86NU.d.cts → EnvironmentParser-BY1oCUsc.d.mts} +3 -3
  11. package/dist/EnvironmentParser-BY1oCUsc.d.mts.map +1 -0
  12. package/dist/{EnvironmentParser-DJdW7vOL.cjs → EnvironmentParser-Bzg5yXG2.cjs} +124 -4
  13. package/dist/EnvironmentParser-Bzg5yXG2.cjs.map +1 -0
  14. package/dist/{EnvironmentParser-CkLfmn4Y.d.mts → EnvironmentParser-DoooZm8n.d.cts} +3 -3
  15. package/dist/EnvironmentParser-DoooZm8n.d.cts.map +1 -0
  16. package/dist/{EnvironmentParser-zMblItla.mjs → EnvironmentParser-taAKfzT7.mjs} +112 -4
  17. package/dist/EnvironmentParser-taAKfzT7.mjs.map +1 -0
  18. package/dist/SnifferEnvironmentParser.cjs +19 -4
  19. package/dist/SnifferEnvironmentParser.cjs.map +1 -1
  20. package/dist/SnifferEnvironmentParser.d.cts +20 -3
  21. package/dist/SnifferEnvironmentParser.d.cts.map +1 -1
  22. package/dist/SnifferEnvironmentParser.d.mts +20 -3
  23. package/dist/SnifferEnvironmentParser.d.mts.map +1 -1
  24. package/dist/SnifferEnvironmentParser.mjs +19 -4
  25. package/dist/SnifferEnvironmentParser.mjs.map +1 -1
  26. package/dist/index.cjs +4 -5
  27. package/dist/index.d.cts +52 -4
  28. package/dist/index.d.cts.map +1 -0
  29. package/dist/index.d.mts +52 -4
  30. package/dist/index.d.mts.map +1 -0
  31. package/dist/index.mjs +2 -3
  32. package/dist/sst.cjs +114 -6
  33. package/dist/sst.cjs.map +1 -1
  34. package/dist/sst.d.cts +184 -3
  35. package/dist/sst.d.cts.map +1 -1
  36. package/dist/sst.d.mts +184 -3
  37. package/dist/sst.d.mts.map +1 -1
  38. package/dist/sst.mjs +110 -2
  39. package/dist/sst.mjs.map +1 -1
  40. package/package.json +4 -3
  41. package/src/SnifferEnvironmentParser.ts +31 -3
  42. package/src/__tests__/SnifferEnvironmentParser.spec.ts +158 -0
  43. package/tsdown.config.ts +16 -1
  44. package/dist/EnvironmentBuilder.cjs +0 -4
  45. package/dist/EnvironmentBuilder.d.cts +0 -2
  46. package/dist/EnvironmentBuilder.d.mts +0 -2
  47. package/dist/EnvironmentBuilder.mjs +0 -3
  48. package/dist/EnvironmentParser-CkLfmn4Y.d.mts.map +0 -1
  49. package/dist/EnvironmentParser-DJdW7vOL.cjs.map +0 -1
  50. package/dist/EnvironmentParser-DtOL86NU.d.cts.map +0 -1
  51. package/dist/EnvironmentParser-zMblItla.mjs.map +0 -1
  52. package/dist/EnvironmentParser.cjs +0 -5
  53. package/dist/EnvironmentParser.d.cts +0 -2
  54. package/dist/EnvironmentParser.d.mts +0 -2
  55. package/dist/EnvironmentParser.mjs +0 -4
  56. package/dist/SstEnvironmentBuilder-BRAcRQp2.d.mts +0 -186
  57. package/dist/SstEnvironmentBuilder-BRAcRQp2.d.mts.map +0 -1
  58. package/dist/SstEnvironmentBuilder-D-NGrp7U.cjs +0 -130
  59. package/dist/SstEnvironmentBuilder-D-NGrp7U.cjs.map +0 -1
  60. package/dist/SstEnvironmentBuilder-DOu4dVPL.mjs +0 -113
  61. package/dist/SstEnvironmentBuilder-DOu4dVPL.mjs.map +0 -1
  62. package/dist/SstEnvironmentBuilder-Dc9nOuuK.d.cts +0 -186
  63. package/dist/SstEnvironmentBuilder-Dc9nOuuK.d.cts.map +0 -1
  64. package/dist/SstEnvironmentBuilder.cjs +0 -7
  65. package/dist/SstEnvironmentBuilder.d.cts +0 -3
  66. package/dist/SstEnvironmentBuilder.d.mts +0 -3
  67. package/dist/SstEnvironmentBuilder.mjs +0 -4
  68. package/dist/formatter-BRRrxQi3.mjs +0 -111
  69. package/dist/formatter-BRRrxQi3.mjs.map +0 -1
  70. package/dist/formatter-Cox0NGxT.d.mts +0 -51
  71. package/dist/formatter-Cox0NGxT.d.mts.map +0 -1
  72. package/dist/formatter-D85aIkpd.d.cts +0 -51
  73. package/dist/formatter-D85aIkpd.d.cts.map +0 -1
  74. package/dist/formatter-HxePpSy2.cjs +0 -123
  75. package/dist/formatter-HxePpSy2.cjs.map +0 -1
  76. package/dist/formatter.cjs +0 -4
  77. package/dist/formatter.d.cts +0 -2
  78. package/dist/formatter.d.mts +0 -2
  79. package/dist/formatter.mjs +0 -3
@@ -343,6 +343,135 @@ describe('SnifferEnvironmentParser', () => {
343
343
  });
344
344
  });
345
345
 
346
+ describe('Optional variable tracking', () => {
347
+ it('should track variables accessed with .optional() as optional', () => {
348
+ const sniffer = new SnifferEnvironmentParser();
349
+
350
+ sniffer.create((get) => ({
351
+ required: get('REQUIRED_VAR').string(),
352
+ optional: get('OPTIONAL_VAR').string().optional(),
353
+ }));
354
+
355
+ expect(sniffer.getOptionalVariables()).toEqual(['OPTIONAL_VAR']);
356
+ });
357
+
358
+ it('should track variables accessed with .default() as optional', () => {
359
+ const sniffer = new SnifferEnvironmentParser();
360
+
361
+ sniffer.create((get) => ({
362
+ required: get('REQUIRED_VAR').string(),
363
+ withDefault: get('DEFAULT_VAR').string().default('fallback'),
364
+ }));
365
+
366
+ expect(sniffer.getOptionalVariables()).toEqual(['DEFAULT_VAR']);
367
+ });
368
+
369
+ it('should track variables with .default() after .transform() as optional', () => {
370
+ const sniffer = new SnifferEnvironmentParser();
371
+
372
+ sniffer.create((get) => ({
373
+ port: get('PORT').string().transform(Number).default(3000),
374
+ }));
375
+
376
+ expect(sniffer.getOptionalVariables()).toEqual(['PORT']);
377
+ });
378
+
379
+ it('should not include required variables in getOptionalVariables()', () => {
380
+ const sniffer = new SnifferEnvironmentParser();
381
+
382
+ sniffer.create((get) => ({
383
+ required: get('DATABASE_URL').string(),
384
+ optional: get('LOG_LEVEL').string().optional(),
385
+ }));
386
+
387
+ expect(sniffer.getOptionalVariables()).toEqual(['LOG_LEVEL']);
388
+ expect(sniffer.getOptionalVariables()).not.toContain('DATABASE_URL');
389
+ });
390
+
391
+ it('getEnvironmentVariables({ markOptional: true }) suffixes optional vars with ?', () => {
392
+ const sniffer = new SnifferEnvironmentParser();
393
+
394
+ sniffer.create((get) => ({
395
+ required: get('DATABASE_URL').string(),
396
+ apiKey: get('API_KEY').string(),
397
+ logLevel: get('LOG_LEVEL').string().optional(),
398
+ port: get('PORT').string().default('3000'),
399
+ }));
400
+
401
+ expect(sniffer.getEnvironmentVariables({ markOptional: true })).toEqual([
402
+ 'API_KEY',
403
+ 'DATABASE_URL',
404
+ 'LOG_LEVEL?',
405
+ 'PORT?',
406
+ ]);
407
+ });
408
+
409
+ it('getEnvironmentVariables() without option returns plain names', () => {
410
+ const sniffer = new SnifferEnvironmentParser();
411
+
412
+ sniffer.create((get) => ({
413
+ required: get('DATABASE_URL').string(),
414
+ optional: get('PORT').string().default('3000'),
415
+ }));
416
+
417
+ expect(sniffer.getEnvironmentVariables()).toEqual([
418
+ 'DATABASE_URL',
419
+ 'PORT',
420
+ ]);
421
+ });
422
+
423
+ it('getEnvironmentVariables({ markOptional: false }) returns plain names', () => {
424
+ const sniffer = new SnifferEnvironmentParser();
425
+
426
+ sniffer.create((get) => ({
427
+ required: get('DATABASE_URL').string(),
428
+ optional: get('PORT').string().default('3000'),
429
+ }));
430
+
431
+ expect(sniffer.getEnvironmentVariables({ markOptional: false })).toEqual([
432
+ 'DATABASE_URL',
433
+ 'PORT',
434
+ ]);
435
+ });
436
+
437
+ it('should return empty getOptionalVariables() when all vars are required', () => {
438
+ const sniffer = new SnifferEnvironmentParser();
439
+
440
+ sniffer.create((get) => ({
441
+ url: get('DATABASE_URL').string(),
442
+ key: get('API_KEY').string(),
443
+ }));
444
+
445
+ expect(sniffer.getOptionalVariables()).toEqual([]);
446
+ });
447
+
448
+ it('should handle mix of optional and default across nested config', () => {
449
+ const sniffer = new SnifferEnvironmentParser();
450
+
451
+ sniffer.create((get) => ({
452
+ database: {
453
+ url: get('DATABASE_URL').string(),
454
+ poolSize: get('DB_POOL_SIZE').string().transform(Number).default(10),
455
+ },
456
+ cache: {
457
+ url: get('REDIS_URL').string().optional(),
458
+ ttl: get('CACHE_TTL').string(),
459
+ },
460
+ }));
461
+
462
+ expect(sniffer.getOptionalVariables().sort()).toEqual([
463
+ 'DB_POOL_SIZE',
464
+ 'REDIS_URL',
465
+ ]);
466
+ expect(sniffer.getEnvironmentVariables({ markOptional: true })).toEqual([
467
+ 'CACHE_TTL',
468
+ 'DATABASE_URL',
469
+ 'DB_POOL_SIZE?',
470
+ 'REDIS_URL?',
471
+ ]);
472
+ });
473
+ });
474
+
346
475
  describe('Edge cases', () => {
347
476
  it('should return empty array when no variables accessed', () => {
348
477
  const sniffer = new SnifferEnvironmentParser();
@@ -483,4 +612,33 @@ describe('sniffWithFireAndForget', () => {
483
612
  expect(result.error).toBeUndefined();
484
613
  expect(result.unhandledRejections).toEqual([]);
485
614
  });
615
+
616
+ it('should include optionalEnvVars in result', async () => {
617
+ const sniffer = new SnifferEnvironmentParser();
618
+
619
+ const result = await sniffWithFireAndForget(sniffer, () => {
620
+ sniffer.create((get) => ({
621
+ required: get('DATABASE_URL').string(),
622
+ optional: get('PORT').string().default('3000'),
623
+ alsoOptional: get('LOG_LEVEL').string().optional(),
624
+ }));
625
+ });
626
+
627
+ expect(result.envVars).toEqual(['DATABASE_URL', 'LOG_LEVEL', 'PORT']);
628
+ expect(result.optionalEnvVars).toEqual(['LOG_LEVEL', 'PORT']);
629
+ expect(result.error).toBeUndefined();
630
+ });
631
+
632
+ it('should return empty optionalEnvVars when all vars are required', async () => {
633
+ const sniffer = new SnifferEnvironmentParser();
634
+
635
+ const result = await sniffWithFireAndForget(sniffer, () => {
636
+ sniffer.create((get) => ({
637
+ url: get('DATABASE_URL').string(),
638
+ key: get('API_KEY').string(),
639
+ }));
640
+ });
641
+
642
+ expect(result.optionalEnvVars).toEqual([]);
643
+ });
486
644
  });
package/tsdown.config.ts CHANGED
@@ -1,3 +1,18 @@
1
1
  import { defineConfig } from 'tsdown';
2
2
 
3
- export default defineConfig({});
3
+ export default defineConfig({
4
+ entry: [
5
+ 'src/index.ts',
6
+ 'src/sst.ts',
7
+ 'src/SnifferEnvironmentParser.ts',
8
+ 'src/credentials.ts',
9
+ ],
10
+ clean: true,
11
+ outDir: 'dist',
12
+ format: ['cjs', 'esm'],
13
+ sourcemap: true,
14
+ dts: true,
15
+ outExtensions: (ctx) => ({
16
+ js: ctx.format === 'es' ? '.mjs' : '.cjs',
17
+ }),
18
+ });
@@ -1,4 +0,0 @@
1
- const require_EnvironmentBuilder = require('./EnvironmentBuilder-Djr1VsWM.cjs');
2
-
3
- exports.EnvironmentBuilder = require_EnvironmentBuilder.EnvironmentBuilder;
4
- exports.environmentCase = require_EnvironmentBuilder.environmentCase;
@@ -1,2 +0,0 @@
1
- import { EnvRecord, EnvValue, EnvironmentBuilder, EnvironmentBuilderOptions, EnvironmentResolver, InputValue, Resolvers, TypedInputValue, TypedResolvers, environmentCase } from "./EnvironmentBuilder-Xuf2Dd9u.cjs";
2
- export { EnvRecord, EnvValue, EnvironmentBuilder, EnvironmentBuilderOptions, EnvironmentResolver, InputValue, Resolvers, TypedInputValue, TypedResolvers, environmentCase };
@@ -1,2 +0,0 @@
1
- import { EnvRecord, EnvValue, EnvironmentBuilder, EnvironmentBuilderOptions, EnvironmentResolver, InputValue, Resolvers, TypedInputValue, TypedResolvers, environmentCase } from "./EnvironmentBuilder-jF-b7WQg.mjs";
2
- export { EnvRecord, EnvValue, EnvironmentBuilder, EnvironmentBuilderOptions, EnvironmentResolver, InputValue, Resolvers, TypedInputValue, TypedResolvers, environmentCase };
@@ -1,3 +0,0 @@
1
- import { EnvironmentBuilder, environmentCase } from "./EnvironmentBuilder-BSuHZm0y.mjs";
2
-
3
- export { EnvironmentBuilder, environmentCase };
@@ -1 +0,0 @@
1
- {"version":3,"file":"EnvironmentParser-CkLfmn4Y.d.mts","names":[],"sources":["../src/EnvironmentParser.ts"],"sourcesContent":[],"mappings":";;;;;;AAWA;;;;AAS4B,cATf,YASe,CAAA,kBATgB,WAShB,CAAA,CAAA;EAAG,iBAMT,MAAA;EAAS,iBAArB,OAAA;EAAW;AA2FrB;;;;;EAiJmC,WAClB,CAAA,MAAA,EApPU,SAoPV,EAAA,OAAA,CAAA,EAnPW,GAmPX,CAAA,MAAA,CAAA;EAAU;;;AACX;EA6BJ,KAAA,CAAA,CAAA,EA3QF,WA2Qa,CA3QD,SA2QC,CAAA;EAAA;;;;;;;;;;;;;;;;EAKjB,uBAAC,CAAA,CAAA,EAAA,MAAA,EAAA;AAAC;AAWR;;;;AAEa;AAUb;;;;;AAEc;AAMd;;;;;;;;cApNa,4BAA4B;;;;;;;;;;;sBAWH;;;;;;;;;;;;;;;;;;;;;;;;yBAsId,4BACP,eAAe,UAC5B,aAAa;;;;;;;;;;;;;;;;;;;;;;KA6BL,sBAAsB,6BACrB,IAAI,EAAE,WAAW,CAAA,CAAE,YAC5B,CAAA,CAAE,MAAM,EAAE,MACV,EAAE,WAAW,0BACZ,YAAY,EAAE,MACd,EAAE;;;;;;;;;KAWK,mDACL,iBACK;;;;;;;;;KAUA,qCAAqC,qBAC3C,eACD;;;;;KAMO,WAAA,GAAc"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"EnvironmentParser-DJdW7vOL.cjs","names":["config: TResponse","envVars: Set<string>","errors: z.core.$ZodIssue[]","config: T","path: string[]","result: EmptyObject","z","schema: z.ZodType","name: string","issue: z.core.$ZodIssue","builder: (get: EnvFetcher) => TReturn"],"sources":["../src/EnvironmentParser.ts"],"sourcesContent":["import get from 'lodash.get';\nimport set from 'lodash.set';\nimport { z } from 'zod/v4';\nimport { formatParseError, isDevelopment } from './formatter.js';\n\n/**\n * Parses and validates configuration objects against Zod schemas.\n * Handles nested configurations and aggregates validation errors.\n *\n * @template TResponse - The shape of the configuration object\n */\nexport class ConfigParser<TResponse extends EmptyObject> {\n\t/**\n\t * Creates a new ConfigParser instance.\n\t *\n\t * @param config - The configuration object to parse\n\t * @param envVars - Set of environment variable names that were accessed\n\t */\n\tconstructor(\n\t\tprivate readonly config: TResponse,\n\t\tprivate readonly envVars: Set<string> = new Set(),\n\t) {}\n\t/**\n\t * Parses the config object and validates it against the Zod schemas\n\t * @returns The parsed config object\n\t */\n\tparse(): InferConfig<TResponse> {\n\t\tconst errors: z.core.$ZodIssue[] = [];\n\n\t\tconst parseDeep = <T>(config: T, path: string[] = []) => {\n\t\t\tconst result: EmptyObject = {};\n\n\t\t\tif (config && typeof config !== 'object') {\n\t\t\t\treturn config;\n\t\t\t}\n\n\t\t\tfor (const key in config) {\n\t\t\t\tconst schema = config[key];\n\t\t\t\tconst currentPath = [...path, key];\n\n\t\t\t\tif (schema instanceof z.ZodType) {\n\t\t\t\t\tconst parsed = schema.safeParse(undefined);\n\t\t\t\t\tif (parsed.success) {\n\t\t\t\t\t\tset(result, key, parsed.data);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If the schema is invalid, assign the error\n\t\t\t\t\t\terrors.push(\n\t\t\t\t\t\t\t...parsed.error.issues.map((issue) => ({\n\t\t\t\t\t\t\t\t...issue,\n\t\t\t\t\t\t\t\tpath: [...currentPath, ...(issue.path as string[])],\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else if (schema) {\n\t\t\t\t\tset(result, key, parseDeep(schema as EmptyObject, currentPath));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn result;\n\t\t};\n\n\t\tconst parsedConfig = parseDeep(\n\t\t\tthis.config,\n\t\t) as unknown as InferConfig<TResponse>;\n\n\t\tif (errors.length > 0) {\n\t\t\tconst zodError = new z.ZodError(errors);\n\t\t\t// In development, log a formatted error message before throwing\n\t\t\tif (isDevelopment()) {\n\t\t\t\tconsole.error(formatParseError(zodError));\n\t\t\t}\n\t\t\tthrow zodError;\n\t\t}\n\n\t\treturn parsedConfig;\n\t}\n\n\t/**\n\t * Returns an array of environment variable names that were accessed during config creation.\n\t * This is useful for deployment and configuration management to know which env vars are required.\n\t *\n\t * @returns Array of environment variable names, sorted alphabetically\n\t *\n\t * @example\n\t * ```typescript\n\t * const config = envParser.create((get) => ({\n\t * dbUrl: get('DATABASE_URL').string(),\n\t * port: get('PORT').number()\n\t * }));\n\t *\n\t * config.getEnvironmentVariables(); // ['DATABASE_URL', 'PORT']\n\t * ```\n\t */\n\tgetEnvironmentVariables(): string[] {\n\t\treturn Array.from(this.envVars).sort();\n\t}\n}\n\n/**\n * Parses environment variables with type-safe validation using Zod schemas.\n * Provides a fluent API for defining environment variable schemas with automatic\n * error context enrichment.\n *\n * @template T - The type of the configuration object (typically process.env)\n *\n * @example\n * ```typescript\n * const config = new EnvironmentParser(process.env)\n * .create((get) => ({\n * port: get('PORT').string().transform(Number).default(3000),\n * database: {\n * url: get('DATABASE_URL').string().url()\n * }\n * }))\n * .parse();\n * ```\n */\nexport class EnvironmentParser<T extends EmptyObject> {\n\t/**\n\t * Set to track which environment variable names have been accessed\n\t */\n\tprivate readonly accessedVars: Set<string> = new Set();\n\n\t/**\n\t * Creates a new EnvironmentParser instance.\n\t *\n\t * @param config - The configuration object to parse (typically process.env)\n\t */\n\tconstructor(private readonly config: T) {}\n\n\t/**\n\t * Wraps a Zod schema to intercept parse/safeParse calls and enrich error messages\n\t * with environment variable context.\n\t *\n\t * @param schema - The Zod schema to wrap\n\t * @param name - The environment variable name for error context\n\t * @returns A wrapped Zod schema with enhanced error reporting\n\t */\n\tprivate wrapSchema = (schema: z.ZodType, name: string): z.ZodType => {\n\t\t// Create a proxy that intercepts all method calls on the schema\n\t\treturn new Proxy(schema, {\n\t\t\tget: (target, prop) => {\n\t\t\t\tif (prop === 'parse') {\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tconst value = get(this.config, name);\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\treturn target.parse(value);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tif (error instanceof z.ZodError) {\n\t\t\t\t\t\t\t\t// Modify the error to include the environment variable name\n\t\t\t\t\t\t\t\tconst modifiedIssues = error.issues.map((issue) => ({\n\t\t\t\t\t\t\t\t\t...issue,\n\t\t\t\t\t\t\t\t\tmessage: `Environment variable \"${name}\": ${issue.message}`,\n\t\t\t\t\t\t\t\t\tpath: [name, ...issue.path],\n\t\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t\t\tthrow new z.ZodError(modifiedIssues);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tif (prop === 'safeParse') {\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tconst value = get(this.config, name);\n\t\t\t\t\t\tconst result = target.safeParse(value);\n\n\t\t\t\t\t\tif (!result.success) {\n\t\t\t\t\t\t\t// Modify the error to include the environment variable name\n\t\t\t\t\t\t\tconst modifiedIssues = result.error.issues.map(\n\t\t\t\t\t\t\t\t(issue: z.core.$ZodIssue) => ({\n\t\t\t\t\t\t\t\t\t...issue,\n\t\t\t\t\t\t\t\t\tmessage: `Environment variable \"${name}\": ${issue.message}`,\n\t\t\t\t\t\t\t\t\tpath: [name, ...issue.path],\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tsuccess: false as const,\n\t\t\t\t\t\t\t\terror: new z.ZodError(modifiedIssues),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\t// For any method that returns a new schema (like transform, optional, etc.),\n\t\t\t\t// wrap the result as well\n\t\t\t\tconst originalProp = target[prop as keyof typeof target];\n\t\t\t\tif (typeof originalProp === 'function') {\n\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\tconst result = originalProp.apply(target, args);\n\t\t\t\t\t\t// If the result is a ZodType, wrap it too\n\t\t\t\t\t\tif (result && typeof result === 'object' && 'parse' in result) {\n\t\t\t\t\t\t\treturn this.wrapSchema(result, name);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn originalProp;\n\t\t\t},\n\t\t});\n\t};\n\n\t/**\n\t * Creates a proxied version of the Zod object that wraps all schema creators\n\t * to provide enhanced error messages with environment variable context.\n\t *\n\t * @param name - The environment variable name\n\t * @returns A proxied Zod object with wrapped schema creators\n\t */\n\tprivate getZodGetter = (name: string) => {\n\t\t// Track that this environment variable was accessed\n\t\tthis.accessedVars.add(name);\n\n\t\t// Return an object that has all Zod schemas but with our wrapper\n\t\treturn new Proxy(\n\t\t\t{ ...z },\n\t\t\t{\n\t\t\t\tget: (target, prop) => {\n\t\t\t\t\t// deno-lint-ignore ban-ts-comment\n\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\tconst value = target[prop];\n\n\t\t\t\t\tif (typeof value === 'function') {\n\t\t\t\t\t\t// Return a wrapper around each Zod schema creator\n\t\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\t\tconst schema = value(...args);\n\t\t\t\t\t\t\treturn this.wrapSchema(schema, name);\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\t// Handle objects like z.coerce\n\t\t\t\t\tif (value && typeof value === 'object') {\n\t\t\t\t\t\treturn new Proxy(value, {\n\t\t\t\t\t\t\tget: (nestedTarget, nestedProp) => {\n\t\t\t\t\t\t\t\tconst nestedValue =\n\t\t\t\t\t\t\t\t\tnestedTarget[nestedProp as keyof typeof nestedTarget];\n\t\t\t\t\t\t\t\tif (typeof nestedValue === 'function') {\n\t\t\t\t\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\t\t\t\t\tconst schema = nestedValue(...args);\n\t\t\t\t\t\t\t\t\t\treturn this.wrapSchema(schema, name);\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn nestedValue;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\treturn value;\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t};\n\n\t/**\n\t * Creates a new ConfigParser object that can be used to parse the config object\n\t *\n\t * @param builder - A function that takes a getter function and returns a config object\n\t * @returns A ConfigParser object that can be used to parse the config object\n\t */\n\tcreate<TReturn extends EmptyObject>(\n\t\tbuilder: (get: EnvFetcher) => TReturn,\n\t): ConfigParser<TReturn> {\n\t\tconst config = builder(this.getZodGetter);\n\t\treturn new ConfigParser(config, this.accessedVars);\n\t}\n\n\t/**\n\t * Returns an array of environment variable names that were accessed via the getter.\n\t * This is useful for build-time analysis to determine which env vars a service needs.\n\t *\n\t * @returns Array of environment variable names, sorted alphabetically\n\t *\n\t * @example\n\t * ```typescript\n\t * const sniffer = new EnvironmentParser({});\n\t * service.register(sniffer);\n\t * const envVars = sniffer.getEnvironmentVariables(); // ['DATABASE_URL', 'PORT']\n\t * ```\n\t */\n\tgetEnvironmentVariables(): string[] {\n\t\treturn Array.from(this.accessedVars).sort();\n\t}\n}\n\n/**\n * Infers the TypeScript type of a configuration object based on its Zod schemas.\n * Recursively processes nested objects and extracts types from Zod schemas.\n *\n * @template T - The configuration object type\n */\nexport type InferConfig<T extends EmptyObject> = {\n\t[K in keyof T]: T[K] extends z.ZodSchema\n\t\t? z.infer<T[K]>\n\t\t: T[K] extends Record<string, unknown>\n\t\t\t? InferConfig<T[K]>\n\t\t\t: T[K];\n};\n\n/**\n * Function type for fetching environment variables with Zod validation.\n * Returns a Zod object scoped to a specific environment variable.\n *\n * @template TPath - The environment variable path type\n * @param name - The environment variable name\n * @returns A Zod object for defining the schema\n */\nexport type EnvFetcher<TPath extends string = string> = (\n\tname: TPath,\n) => typeof z;\n\n/**\n * Function type for building environment configuration objects.\n * Takes an EnvFetcher and returns a configuration object with Zod schemas.\n *\n * @template TResponse - The response configuration object type\n * @param get - The environment variable fetcher function\n * @returns The configuration object with Zod schemas\n */\nexport type EnvironmentBuilder<TResponse extends EmptyObject> = (\n\tget: EnvFetcher,\n) => TResponse;\n\n/**\n * Type alias for a generic object with unknown values.\n * Used as a constraint for configuration objects.\n */\nexport type EmptyObject = Record<string | number | symbol, unknown>;\n"],"mappings":";;;;;;;;;;;;;AAWA,IAAa,eAAb,MAAyD;;;;;;;CAOxD,YACkBA,QACAC,0BAAuB,IAAI,OAC3C;EAFgB;EACA;CACd;;;;;CAKJ,QAAgC;EAC/B,MAAMC,SAA6B,CAAE;EAErC,MAAM,YAAY,CAAIC,QAAWC,OAAiB,CAAE,MAAK;GACxD,MAAMC,SAAsB,CAAE;AAE9B,OAAI,iBAAiB,WAAW,SAC/B,QAAO;AAGR,QAAK,MAAM,OAAO,QAAQ;IACzB,MAAM,SAAS,OAAO;IACtB,MAAM,cAAc,CAAC,GAAG,MAAM,GAAI;AAElC,QAAI,kBAAk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F,UAAO;EACP,EACD;CAEF;;;;;;;CAQD,OACCI,SACwB;EACxB,MAAM,SAAS,QAAQ,KAAK,aAAa;AACzC,SAAO,IAAI,aAAa,QAAQ,KAAK;CACrC;;;;;;;;;;;;;;CAeD,0BAAoC;AACnC,SAAO,MAAM,KAAK,KAAK,aAAa,CAAC,MAAM;CAC3C;AACD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"EnvironmentParser-DtOL86NU.d.cts","names":[],"sources":["../src/EnvironmentParser.ts"],"sourcesContent":[],"mappings":";;;;;;AAWA;;;;AAS4B,cATf,YASe,CAAA,kBATgB,WAShB,CAAA,CAAA;EAAG,iBAMT,MAAA;EAAS,iBAArB,OAAA;EAAW;AA2FrB;;;;;EAiJmC,WAClB,CAAA,MAAA,EApPU,SAoPV,EAAA,OAAA,CAAA,EAnPW,GAmPX,CAAA,MAAA,CAAA;EAAU;;;AACX;EA6BJ,KAAA,CAAA,CAAA,EA3QF,WA2Qa,CA3QD,SA2QC,CAAA;EAAA;;;;;;;;;;;;;;;;EAKjB,uBAAC,CAAA,CAAA,EAAA,MAAA,EAAA;AAAC;AAWR;;;;AAEa;AAUb;;;;;AAEc;AAMd;;;;;;;;cApNa,4BAA4B;;;;;;;;;;;sBAWH;;;;;;;;;;;;;;;;;;;;;;;;yBAsId,4BACP,eAAe,UAC5B,aAAa;;;;;;;;;;;;;;;;;;;;;;KA6BL,sBAAsB,6BACrB,IAAI,EAAE,WAAW,CAAA,CAAE,YAC5B,CAAA,CAAE,MAAM,EAAE,MACV,EAAE,WAAW,0BACZ,YAAY,EAAE,MACd,EAAE;;;;;;;;;KAWK,mDACL,iBACK;;;;;;;;;KAUA,qCAAqC,qBAC3C,eACD;;;;;KAMO,WAAA,GAAc"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"EnvironmentParser-zMblItla.mjs","names":["config: TResponse","envVars: Set<string>","errors: z.core.$ZodIssue[]","config: T","path: string[]","result: EmptyObject","schema: z.ZodType","name: string","issue: z.core.$ZodIssue","builder: (get: EnvFetcher) => TReturn"],"sources":["../src/EnvironmentParser.ts"],"sourcesContent":["import get from 'lodash.get';\nimport set from 'lodash.set';\nimport { z } from 'zod/v4';\nimport { formatParseError, isDevelopment } from './formatter.js';\n\n/**\n * Parses and validates configuration objects against Zod schemas.\n * Handles nested configurations and aggregates validation errors.\n *\n * @template TResponse - The shape of the configuration object\n */\nexport class ConfigParser<TResponse extends EmptyObject> {\n\t/**\n\t * Creates a new ConfigParser instance.\n\t *\n\t * @param config - The configuration object to parse\n\t * @param envVars - Set of environment variable names that were accessed\n\t */\n\tconstructor(\n\t\tprivate readonly config: TResponse,\n\t\tprivate readonly envVars: Set<string> = new Set(),\n\t) {}\n\t/**\n\t * Parses the config object and validates it against the Zod schemas\n\t * @returns The parsed config object\n\t */\n\tparse(): InferConfig<TResponse> {\n\t\tconst errors: z.core.$ZodIssue[] = [];\n\n\t\tconst parseDeep = <T>(config: T, path: string[] = []) => {\n\t\t\tconst result: EmptyObject = {};\n\n\t\t\tif (config && typeof config !== 'object') {\n\t\t\t\treturn config;\n\t\t\t}\n\n\t\t\tfor (const key in config) {\n\t\t\t\tconst schema = config[key];\n\t\t\t\tconst currentPath = [...path, key];\n\n\t\t\t\tif (schema instanceof z.ZodType) {\n\t\t\t\t\tconst parsed = schema.safeParse(undefined);\n\t\t\t\t\tif (parsed.success) {\n\t\t\t\t\t\tset(result, key, parsed.data);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// If the schema is invalid, assign the error\n\t\t\t\t\t\terrors.push(\n\t\t\t\t\t\t\t...parsed.error.issues.map((issue) => ({\n\t\t\t\t\t\t\t\t...issue,\n\t\t\t\t\t\t\t\tpath: [...currentPath, ...(issue.path as string[])],\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else if (schema) {\n\t\t\t\t\tset(result, key, parseDeep(schema as EmptyObject, currentPath));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn result;\n\t\t};\n\n\t\tconst parsedConfig = parseDeep(\n\t\t\tthis.config,\n\t\t) as unknown as InferConfig<TResponse>;\n\n\t\tif (errors.length > 0) {\n\t\t\tconst zodError = new z.ZodError(errors);\n\t\t\t// In development, log a formatted error message before throwing\n\t\t\tif (isDevelopment()) {\n\t\t\t\tconsole.error(formatParseError(zodError));\n\t\t\t}\n\t\t\tthrow zodError;\n\t\t}\n\n\t\treturn parsedConfig;\n\t}\n\n\t/**\n\t * Returns an array of environment variable names that were accessed during config creation.\n\t * This is useful for deployment and configuration management to know which env vars are required.\n\t *\n\t * @returns Array of environment variable names, sorted alphabetically\n\t *\n\t * @example\n\t * ```typescript\n\t * const config = envParser.create((get) => ({\n\t * dbUrl: get('DATABASE_URL').string(),\n\t * port: get('PORT').number()\n\t * }));\n\t *\n\t * config.getEnvironmentVariables(); // ['DATABASE_URL', 'PORT']\n\t * ```\n\t */\n\tgetEnvironmentVariables(): string[] {\n\t\treturn Array.from(this.envVars).sort();\n\t}\n}\n\n/**\n * Parses environment variables with type-safe validation using Zod schemas.\n * Provides a fluent API for defining environment variable schemas with automatic\n * error context enrichment.\n *\n * @template T - The type of the configuration object (typically process.env)\n *\n * @example\n * ```typescript\n * const config = new EnvironmentParser(process.env)\n * .create((get) => ({\n * port: get('PORT').string().transform(Number).default(3000),\n * database: {\n * url: get('DATABASE_URL').string().url()\n * }\n * }))\n * .parse();\n * ```\n */\nexport class EnvironmentParser<T extends EmptyObject> {\n\t/**\n\t * Set to track which environment variable names have been accessed\n\t */\n\tprivate readonly accessedVars: Set<string> = new Set();\n\n\t/**\n\t * Creates a new EnvironmentParser instance.\n\t *\n\t * @param config - The configuration object to parse (typically process.env)\n\t */\n\tconstructor(private readonly config: T) {}\n\n\t/**\n\t * Wraps a Zod schema to intercept parse/safeParse calls and enrich error messages\n\t * with environment variable context.\n\t *\n\t * @param schema - The Zod schema to wrap\n\t * @param name - The environment variable name for error context\n\t * @returns A wrapped Zod schema with enhanced error reporting\n\t */\n\tprivate wrapSchema = (schema: z.ZodType, name: string): z.ZodType => {\n\t\t// Create a proxy that intercepts all method calls on the schema\n\t\treturn new Proxy(schema, {\n\t\t\tget: (target, prop) => {\n\t\t\t\tif (prop === 'parse') {\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tconst value = get(this.config, name);\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\treturn target.parse(value);\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tif (error instanceof z.ZodError) {\n\t\t\t\t\t\t\t\t// Modify the error to include the environment variable name\n\t\t\t\t\t\t\t\tconst modifiedIssues = error.issues.map((issue) => ({\n\t\t\t\t\t\t\t\t\t...issue,\n\t\t\t\t\t\t\t\t\tmessage: `Environment variable \"${name}\": ${issue.message}`,\n\t\t\t\t\t\t\t\t\tpath: [name, ...issue.path],\n\t\t\t\t\t\t\t\t}));\n\t\t\t\t\t\t\t\tthrow new z.ZodError(modifiedIssues);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tif (prop === 'safeParse') {\n\t\t\t\t\treturn () => {\n\t\t\t\t\t\tconst value = get(this.config, name);\n\t\t\t\t\t\tconst result = target.safeParse(value);\n\n\t\t\t\t\t\tif (!result.success) {\n\t\t\t\t\t\t\t// Modify the error to include the environment variable name\n\t\t\t\t\t\t\tconst modifiedIssues = result.error.issues.map(\n\t\t\t\t\t\t\t\t(issue: z.core.$ZodIssue) => ({\n\t\t\t\t\t\t\t\t\t...issue,\n\t\t\t\t\t\t\t\t\tmessage: `Environment variable \"${name}\": ${issue.message}`,\n\t\t\t\t\t\t\t\t\tpath: [name, ...issue.path],\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tsuccess: false as const,\n\t\t\t\t\t\t\t\terror: new z.ZodError(modifiedIssues),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\t// For any method that returns a new schema (like transform, optional, etc.),\n\t\t\t\t// wrap the result as well\n\t\t\t\tconst originalProp = target[prop as keyof typeof target];\n\t\t\t\tif (typeof originalProp === 'function') {\n\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\tconst result = originalProp.apply(target, args);\n\t\t\t\t\t\t// If the result is a ZodType, wrap it too\n\t\t\t\t\t\tif (result && typeof result === 'object' && 'parse' in result) {\n\t\t\t\t\t\t\treturn this.wrapSchema(result, name);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn originalProp;\n\t\t\t},\n\t\t});\n\t};\n\n\t/**\n\t * Creates a proxied version of the Zod object that wraps all schema creators\n\t * to provide enhanced error messages with environment variable context.\n\t *\n\t * @param name - The environment variable name\n\t * @returns A proxied Zod object with wrapped schema creators\n\t */\n\tprivate getZodGetter = (name: string) => {\n\t\t// Track that this environment variable was accessed\n\t\tthis.accessedVars.add(name);\n\n\t\t// Return an object that has all Zod schemas but with our wrapper\n\t\treturn new Proxy(\n\t\t\t{ ...z },\n\t\t\t{\n\t\t\t\tget: (target, prop) => {\n\t\t\t\t\t// deno-lint-ignore ban-ts-comment\n\t\t\t\t\t// @ts-expect-error\n\t\t\t\t\tconst value = target[prop];\n\n\t\t\t\t\tif (typeof value === 'function') {\n\t\t\t\t\t\t// Return a wrapper around each Zod schema creator\n\t\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\t\tconst schema = value(...args);\n\t\t\t\t\t\t\treturn this.wrapSchema(schema, name);\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\t// Handle objects like z.coerce\n\t\t\t\t\tif (value && typeof value === 'object') {\n\t\t\t\t\t\treturn new Proxy(value, {\n\t\t\t\t\t\t\tget: (nestedTarget, nestedProp) => {\n\t\t\t\t\t\t\t\tconst nestedValue =\n\t\t\t\t\t\t\t\t\tnestedTarget[nestedProp as keyof typeof nestedTarget];\n\t\t\t\t\t\t\t\tif (typeof nestedValue === 'function') {\n\t\t\t\t\t\t\t\t\treturn (...args: any[]) => {\n\t\t\t\t\t\t\t\t\t\tconst schema = nestedValue(...args);\n\t\t\t\t\t\t\t\t\t\treturn this.wrapSchema(schema, name);\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn nestedValue;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\treturn value;\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\t};\n\n\t/**\n\t * Creates a new ConfigParser object that can be used to parse the config object\n\t *\n\t * @param builder - A function that takes a getter function and returns a config object\n\t * @returns A ConfigParser object that can be used to parse the config object\n\t */\n\tcreate<TReturn extends EmptyObject>(\n\t\tbuilder: (get: EnvFetcher) => TReturn,\n\t): ConfigParser<TReturn> {\n\t\tconst config = builder(this.getZodGetter);\n\t\treturn new ConfigParser(config, this.accessedVars);\n\t}\n\n\t/**\n\t * Returns an array of environment variable names that were accessed via the getter.\n\t * This is useful for build-time analysis to determine which env vars a service needs.\n\t *\n\t * @returns Array of environment variable names, sorted alphabetically\n\t *\n\t * @example\n\t * ```typescript\n\t * const sniffer = new EnvironmentParser({});\n\t * service.register(sniffer);\n\t * const envVars = sniffer.getEnvironmentVariables(); // ['DATABASE_URL', 'PORT']\n\t * ```\n\t */\n\tgetEnvironmentVariables(): string[] {\n\t\treturn Array.from(this.accessedVars).sort();\n\t}\n}\n\n/**\n * Infers the TypeScript type of a configuration object based on its Zod schemas.\n * Recursively processes nested objects and extracts types from Zod schemas.\n *\n * @template T - The configuration object type\n */\nexport type InferConfig<T extends EmptyObject> = {\n\t[K in keyof T]: T[K] extends z.ZodSchema\n\t\t? z.infer<T[K]>\n\t\t: T[K] extends Record<string, unknown>\n\t\t\t? InferConfig<T[K]>\n\t\t\t: T[K];\n};\n\n/**\n * Function type for fetching environment variables with Zod validation.\n * Returns a Zod object scoped to a specific environment variable.\n *\n * @template TPath - The environment variable path type\n * @param name - The environment variable name\n * @returns A Zod object for defining the schema\n */\nexport type EnvFetcher<TPath extends string = string> = (\n\tname: TPath,\n) => typeof z;\n\n/**\n * Function type for building environment configuration objects.\n * Takes an EnvFetcher and returns a configuration object with Zod schemas.\n *\n * @template TResponse - The response configuration object type\n * @param get - The environment variable fetcher function\n * @returns The configuration object with Zod schemas\n */\nexport type EnvironmentBuilder<TResponse extends EmptyObject> = (\n\tget: EnvFetcher,\n) => TResponse;\n\n/**\n * Type alias for a generic object with unknown values.\n * Used as a constraint for configuration objects.\n */\nexport type EmptyObject = Record<string | number | symbol, unknown>;\n"],"mappings":";;;;;;;;;;;;AAWA,IAAa,eAAb,MAAyD;;;;;;;CAOxD,YACkBA,QACAC,0BAAuB,IAAI,OAC3C;EAFgB;EACA;CACd;;;;;CAKJ,QAAgC;EAC/B,MAAMC,SAA6B,CAAE;EAErC,MAAM,YAAY,CAAIC,QAAWC,OAAiB,CAAE,MAAK;GACxD,MAAMC,SAAsB,CAAE;AAE9B,OAAI,iBAAiB,WAAW,SAC/B,QAAO;AAGR,QAAK,MAAM,OAAO,QAAQ;IACzB,MAAM,SAAS,OAAO;IACtB,MAAM,cAAc,CAAC,GAAG,MAAM,GAAI;AAElC,QAAI,kBAAkB,EAAE,SAAS;KAChC,MAAM,SAAS,OAAO,iBAAoB;AAC1C,SAAI,OAAO,QACV,KAAI,QAAQ,KAAK,OAAO,KAAK;SAG7B,QAAO,KACN,GAAG,OAAO,MAAM,OAAO,IAAI,CAAC,WAAW;MACtC,GAAG;MACH,MAAM,CAAC,GAAG,aAAa,GAAI,MAAM,IAAkB;KACnD,GAAE,CACH;IAEF,WAAU,OACV,KAAI,QAAQ,KAAK,UAAU,QAAuB,YAAY,CAAC;GAEhE;AAED,UAAO;EACP;EAED,MAAM,eAAe,UACpB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;MACT,OAAO,IAAI,EAAE,SAAS;KACtB;IACD;AAED,WAAO;GACP;GAKF,MAAM,eAAe,OAAO;AAC5B,cAAW,iBAAiB,WAC3B,QAAO,CAAC,GAAG,SAAgB;IAC1B,MAAM,SAAS,aAAa,MAAM,QAAQ,KAAK;AAE/C,QAAI,iBAAiB,WAAW,YAAY,WAAW,OACtD,QAAO,KAAK,WAAW,QAAQ,KAAK;AAErC,WAAO;GACP;AAGF,UAAO;EACP,EACD;CACD;;;;;;;;CASD,AAAQ,eAAe,CAACD,SAAiB;AAExC,OAAK,aAAa,IAAI,KAAK;AAG3B,SAAO,IAAI,MACV,EAAE,GAAG,EAAG,GACR,EACC,KAAK,CAAC,QAAQ,SAAS;GAGtB,MAAM,QAAQ,OAAO;AAErB,cAAW,UAAU,WAEpB,QAAO,CAAC,GAAG,SAAgB;IAC1B,MAAM,SAAS,MAAM,GAAG,KAAK;AAC7B,WAAO,KAAK,WAAW,QAAQ,KAAK;GACpC;AAIF,OAAI,gBAAgB,UAAU,SAC7B,QAAO,IAAI,MAAM,OAAO,EACvB,KAAK,CAAC,cAAc,eAAe;IAClC,MAAM,cACL,aAAa;AACd,eAAW,gBAAgB,WAC1B,QAAO,CAAC,GAAG,SAAgB;KAC1B,MAAM,SAAS,YAAY,GAAG,KAAK;AACnC,YAAO,KAAK,WAAW,QAAQ,KAAK;IACpC;AAEF,WAAO;GACP,EACD;AAGF,UAAO;EACP,EACD;CAEF;;;;;;;CAQD,OACCE,SACwB;EACxB,MAAM,SAAS,QAAQ,KAAK,aAAa;AACzC,SAAO,IAAI,aAAa,QAAQ,KAAK;CACrC;;;;;;;;;;;;;;CAeD,0BAAoC;AACnC,SAAO,MAAM,KAAK,KAAK,aAAa,CAAC,MAAM;CAC3C;AACD"}
@@ -1,5 +0,0 @@
1
- require('./formatter-HxePpSy2.cjs');
2
- const require_EnvironmentParser = require('./EnvironmentParser-DJdW7vOL.cjs');
3
-
4
- exports.ConfigParser = require_EnvironmentParser.ConfigParser;
5
- exports.EnvironmentParser = require_EnvironmentParser.EnvironmentParser;
@@ -1,2 +0,0 @@
1
- import { ConfigParser, EmptyObject, EnvFetcher, EnvironmentBuilder, EnvironmentParser, InferConfig } from "./EnvironmentParser-DtOL86NU.cjs";
2
- export { ConfigParser, EmptyObject, EnvFetcher, EnvironmentBuilder, EnvironmentParser, InferConfig };
@@ -1,2 +0,0 @@
1
- import { ConfigParser, EmptyObject, EnvFetcher, EnvironmentBuilder, EnvironmentParser, InferConfig } from "./EnvironmentParser-CkLfmn4Y.mjs";
2
- export { ConfigParser, EmptyObject, EnvFetcher, EnvironmentBuilder, EnvironmentParser, InferConfig };
@@ -1,4 +0,0 @@
1
- import "./formatter-BRRrxQi3.mjs";
2
- import { ConfigParser, EnvironmentParser } from "./EnvironmentParser-zMblItla.mjs";
3
-
4
- export { ConfigParser, EnvironmentParser };
@@ -1,186 +0,0 @@
1
- import { EnvRecord, EnvironmentBuilderOptions, EnvironmentResolver, InputValue, Resolvers } from "./EnvironmentBuilder-jF-b7WQg.mjs";
2
-
3
- //#region src/SstEnvironmentBuilder.d.ts
4
-
5
- /**
6
- * Enumeration of supported SST (Serverless Stack Toolkit) resource types.
7
- * Used to identify and process different AWS and SST resources.
8
- */
9
- declare enum ResourceType {
10
- ApiGatewayV2 = "sst.aws.ApiGatewayV2",
11
- Postgres = "sst.aws.Postgres",
12
- Function = "sst.aws.Function",
13
- Bucket = "sst.aws.Bucket",
14
- Vpc = "sst.aws.Vpc",
15
- Secret = "sst.sst.Secret",
16
- Dynamo = "sst.aws.Dynamo",
17
- SSTSecret = "sst:sst:Secret",
18
- SSTFunction = "sst:sst:Function",
19
- SSTApiGatewayV2 = "sst:aws:ApiGatewayV2",
20
- SSTPostgres = "sst:aws:Postgres",
21
- SSTBucket = "sst:aws:Bucket",
22
- SnsTopic = "sst:aws:SnsTopic",
23
- SSTDynamo = "sst:aws:Dynamo",
24
- }
25
- /**
26
- * AWS API Gateway V2 resource type.
27
- * Represents an HTTP/WebSocket API.
28
- */
29
- type ApiGatewayV2 = {
30
- type: ResourceType.ApiGatewayV2 | ResourceType.SSTApiGatewayV2;
31
- url: string;
32
- };
33
- /**
34
- * PostgreSQL database resource type.
35
- * Contains all connection details needed to connect to the database.
36
- */
37
- type Postgres = {
38
- type: ResourceType.Postgres | ResourceType.SSTPostgres;
39
- database: string;
40
- host: string;
41
- password: string;
42
- port: number;
43
- username: string;
44
- };
45
- /**
46
- * AWS Lambda Function resource type.
47
- */
48
- type Function = {
49
- type: ResourceType.Function | ResourceType.SSTFunction;
50
- name: string;
51
- };
52
- /**
53
- * AWS S3 Bucket resource type.
54
- */
55
- type Bucket = {
56
- type: ResourceType.Bucket | ResourceType.SSTBucket;
57
- name: string;
58
- };
59
- /**
60
- * AWS VPC (Virtual Private Cloud) resource type.
61
- */
62
- type Vpc = {
63
- type: ResourceType.Vpc;
64
- bastion: string;
65
- };
66
- /**
67
- * Secret resource type for storing sensitive values.
68
- */
69
- type Secret = {
70
- type: ResourceType.Secret | ResourceType.SSTSecret;
71
- value: string;
72
- };
73
- /**
74
- * AWS SNS Topic resource type.
75
- */
76
- type SnsTopic = {
77
- type: ResourceType.SnsTopic;
78
- arn: string;
79
- };
80
- /**
81
- * AWS DynamoDB Table resource type.
82
- */
83
- type Dynamo = {
84
- type: ResourceType.Dynamo | ResourceType.SSTDynamo;
85
- name: string;
86
- };
87
- /**
88
- * Union type of all supported SST resource types.
89
- */
90
- type SstResource = ApiGatewayV2 | Postgres | Function | Bucket | Vpc | Secret | SnsTopic | Dynamo;
91
- /**
92
- * Function type for processing a specific resource type into environment variables.
93
- *
94
- * @template K - The specific resource type (without `type` key)
95
- * @param name - The resource name
96
- * @param value - The resource value (without `type` key)
97
- * @returns Object mapping environment variable names to values
98
- */
99
- type ResourceProcessor<K> = (name: string, value: K) => EnvRecord;
100
- /**
101
- * Pre-configured resolvers for all SST resource types.
102
- */
103
- declare const sstResolvers: Resolvers;
104
- /**
105
- * All known SST resource type strings.
106
- */
107
- type SstResourceTypeString = `${ResourceType}`;
108
- /**
109
- * Extracts the `type` string value from an input value.
110
- */
111
- type ExtractType<T> = T extends {
112
- type: infer U extends string;
113
- } ? U : never;
114
- /**
115
- * Removes the `type` key from an object type.
116
- */
117
- type OmitType<T> = T extends {
118
- type: string;
119
- } ? Omit<T, 'type'> : never;
120
- /**
121
- * Extracts all unique `type` values from a record (excluding plain strings).
122
- */
123
- type AllTypeValues<TRecord extends Record<string, InputValue>> = { [K in keyof TRecord]: ExtractType<TRecord[K]> }[keyof TRecord];
124
- /**
125
- * Extracts only the custom (non-SST) type values from a record.
126
- */
127
- type CustomTypeValues<TRecord extends Record<string, InputValue>> = Exclude<AllTypeValues<TRecord>, SstResourceTypeString>;
128
- /**
129
- * For a given type value, finds the corresponding value type (without `type` key).
130
- */
131
- type ValueForType<TRecord extends Record<string, InputValue>, TType extends string> = { [K in keyof TRecord]: TRecord[K] extends {
132
- type: TType;
133
- } ? OmitType<TRecord[K]> : never }[keyof TRecord];
134
- /**
135
- * Generates typed resolvers for custom (non-SST) types in the input record.
136
- */
137
- type CustomResolvers<TRecord extends Record<string, InputValue>> = CustomTypeValues<TRecord> extends never ? Resolvers | undefined : { [TType in CustomTypeValues<TRecord>]: EnvironmentResolver<ValueForType<TRecord, TType>> };
138
- /**
139
- * SST-specific environment builder with built-in resolvers for all known
140
- * SST resource types.
141
- *
142
- * Wraps the generic EnvironmentBuilder with pre-configured SST resolvers.
143
- *
144
- * @template TRecord - The input record type for type inference
145
- *
146
- * @example
147
- * ```typescript
148
- * const env = new SstEnvironmentBuilder({
149
- * database: { type: 'sst:aws:Postgres', host: '...', ... },
150
- * apiKey: { type: 'sst:sst:Secret', value: 'secret' },
151
- * appName: 'my-app',
152
- * }).build();
153
- *
154
- * // With custom resolvers (typed based on input)
155
- * const env = new SstEnvironmentBuilder(
156
- * {
157
- * database: postgresResource,
158
- * custom: { type: 'my-custom' as const, data: 'foo' },
159
- * },
160
- * {
161
- * // TypeScript requires 'my-custom' resolver with typed value
162
- * 'my-custom': (key, value) => ({ [`${key}Data`]: value.data }),
163
- * }
164
- * ).build();
165
- * ```
166
- */
167
- declare class SstEnvironmentBuilder<TRecord extends Record<string, SstResource | InputValue | string>> {
168
- private readonly builder;
169
- /**
170
- * Create a new SST environment builder.
171
- *
172
- * @param record - Object containing SST resources, custom resources, and/or string values
173
- * @param additionalResolvers - Optional custom resolvers (typed based on custom types in record)
174
- * @param options - Optional configuration options
175
- */
176
- constructor(record: TRecord, additionalResolvers?: CustomResolvers<TRecord>, options?: EnvironmentBuilderOptions);
177
- /**
178
- * Build environment variables from the input record.
179
- *
180
- * @returns A record of environment variables
181
- */
182
- build(): EnvRecord;
183
- }
184
- //#endregion
185
- export { ApiGatewayV2, Bucket, Dynamo, Function, Postgres, ResourceProcessor, ResourceType, Secret, SnsTopic, SstEnvironmentBuilder, SstResource, Vpc, sstResolvers };
186
- //# sourceMappingURL=SstEnvironmentBuilder-BRAcRQp2.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SstEnvironmentBuilder-BRAcRQp2.d.mts","names":[],"sources":["../src/SstEnvironmentBuilder.ts"],"sourcesContent":[],"mappings":";;;;;;AAaA;AAwBA;AAAwB,aAxBZ,YAAA;EAwBY,YACjB,GAAA,sBAAa;EAAY,QAAG,GAAA,kBAAa;EAAe,QAAA,GAAA,kBAAA;EAQnD,MAAA,GAAA,gBAAQ;EAAA,GAAA,GAAA,aAAA;EAAA,MACb,GAAA,gBAAa;EAAQ,MAAG,GAAA,gBAAa;EAAW,SAAA,GAAA,gBAAA;EAW3C,WAAQ,GAAA,kBAAA;EAAA,eAAA,GAAA,sBAAA;EAAA,WACb,GAAA,kBAAa;EAAQ,SAAG,GAAA,gBAAa;EAAW,QAAA,GAAA,kBAAA;EAO3C,SAAM,GAAA,gBAAA;;;;AACiC;AAOnD;AAQY,KA7CA,YAAA,GA6CM;EAAA,IAAA,EA5CX,YAAA,CAAa,YA4CF,GA5CiB,YAAA,CAAa,eA4C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,CAAA,CAAA,GAAA,CAAA,IAAA,EAAA,MAAA,EAAA,KAAA,EA7FiD,CA6FjD,EAAA,GA7FuD,SA6FvD;AAAO;AAAA;;AAKqC,cAjEvC,YAiEuC,EAjEzB,SAiEyB;;;;KA1C/C,qBAAA,GA4CD,GA5C4B,YA4C5B,EAAA;;;;KAvCC,WA0CsB,CAAA,CAAA,CAAA,GA1CL,CA0CK,SAAA;EAAK,IAA3B,EAAA,KAAA,WAAA,MAAA;CAAY,GA1CkD,CA0ClD,GADyB,KAAA;AAAmB;AAkC7D;;KAtEK,QAuE2B,CAAA,CAAA,CAAA,GAvEb,CAuEa,SAAA;EAAW,IAAG,EAAA,MAAA;CAAU,GAvER,IAuE/B,CAvEoC,CAuEpC,EAAA,MAAA,CAAA,GAAA,KAAA;;;;KAlEZ,aAmFO,CAAA,gBAnFuB,MAmFvB,CAAA,MAAA,EAnFsC,UAmFtC,CAAA,CAAA,GAAA,QAmBF,MArGG,OAqGH,GArGa,WAqGb,CArGyB,OAqGzB,CArGiC,CAqGjC,CAAA,CAAA,EAAS,CAAA,MApGX,OAoGW,CAAA;;;;KA/Fd,iCAAiC,eAAe,eAAe,QACnE,cAAc,UACd;;;;KAMI,6BACY,eAAe,mDAGnB,UAAU,QAAQ;QAAmB;IAC9C,SAAS,QAAQ,oBAEb;;;;KAKH,gCAAgC,eAAe,eACnD,iBAAiB,yBACd,oCAEU,iBAAiB,WAAW,oBACrC,aAAa,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAiCd,sCACI,eAAe,cAAc;;;;;;;;;sBAepC,+BACc,gBAAgB,oBAC5B;;;;;;WAmBF"}
@@ -1,130 +0,0 @@
1
- const require_EnvironmentBuilder = require('./EnvironmentBuilder-Djr1VsWM.cjs');
2
-
3
- //#region src/SstEnvironmentBuilder.ts
4
- /**
5
- * Enumeration of supported SST (Serverless Stack Toolkit) resource types.
6
- * Used to identify and process different AWS and SST resources.
7
- */
8
- let ResourceType = /* @__PURE__ */ function(ResourceType$1) {
9
- ResourceType$1["ApiGatewayV2"] = "sst.aws.ApiGatewayV2";
10
- ResourceType$1["Postgres"] = "sst.aws.Postgres";
11
- ResourceType$1["Function"] = "sst.aws.Function";
12
- ResourceType$1["Bucket"] = "sst.aws.Bucket";
13
- ResourceType$1["Vpc"] = "sst.aws.Vpc";
14
- ResourceType$1["Secret"] = "sst.sst.Secret";
15
- ResourceType$1["Dynamo"] = "sst.aws.Dynamo";
16
- ResourceType$1["SSTSecret"] = "sst:sst:Secret";
17
- ResourceType$1["SSTFunction"] = "sst:sst:Function";
18
- ResourceType$1["SSTApiGatewayV2"] = "sst:aws:ApiGatewayV2";
19
- ResourceType$1["SSTPostgres"] = "sst:aws:Postgres";
20
- ResourceType$1["SSTBucket"] = "sst:aws:Bucket";
21
- ResourceType$1["SnsTopic"] = "sst:aws:SnsTopic";
22
- ResourceType$1["SSTDynamo"] = "sst:aws:Dynamo";
23
- return ResourceType$1;
24
- }({});
25
- const secretResolver = (name, value) => ({ [name]: value.value });
26
- const postgresResolver = (key, value) => ({
27
- [`${key}Name`]: value.database,
28
- [`${key}Host`]: value.host,
29
- [`${key}Password`]: value.password,
30
- [`${key}Port`]: value.port,
31
- [`${key}Username`]: value.username
32
- });
33
- const bucketResolver = (name, value) => ({ [`${name}Name`]: value.name });
34
- const topicResolver = (name, value) => ({ [`${name}Arn`]: value.arn });
35
- const dynamoResolver = (name, value) => ({ [`${name}Name`]: value.name });
36
- const noopResolver = () => ({});
37
- /**
38
- * Pre-configured resolvers for all SST resource types.
39
- */
40
- const sstResolvers = {
41
- [ResourceType.ApiGatewayV2]: noopResolver,
42
- [ResourceType.Function]: noopResolver,
43
- [ResourceType.Vpc]: noopResolver,
44
- [ResourceType.Secret]: secretResolver,
45
- [ResourceType.Postgres]: postgresResolver,
46
- [ResourceType.Bucket]: bucketResolver,
47
- [ResourceType.Dynamo]: dynamoResolver,
48
- [ResourceType.SSTSecret]: secretResolver,
49
- [ResourceType.SSTBucket]: bucketResolver,
50
- [ResourceType.SSTFunction]: noopResolver,
51
- [ResourceType.SSTPostgres]: postgresResolver,
52
- [ResourceType.SSTApiGatewayV2]: noopResolver,
53
- [ResourceType.SnsTopic]: topicResolver,
54
- [ResourceType.SSTDynamo]: dynamoResolver
55
- };
56
- /**
57
- * SST-specific environment builder with built-in resolvers for all known
58
- * SST resource types.
59
- *
60
- * Wraps the generic EnvironmentBuilder with pre-configured SST resolvers.
61
- *
62
- * @template TRecord - The input record type for type inference
63
- *
64
- * @example
65
- * ```typescript
66
- * const env = new SstEnvironmentBuilder({
67
- * database: { type: 'sst:aws:Postgres', host: '...', ... },
68
- * apiKey: { type: 'sst:sst:Secret', value: 'secret' },
69
- * appName: 'my-app',
70
- * }).build();
71
- *
72
- * // With custom resolvers (typed based on input)
73
- * const env = new SstEnvironmentBuilder(
74
- * {
75
- * database: postgresResource,
76
- * custom: { type: 'my-custom' as const, data: 'foo' },
77
- * },
78
- * {
79
- * // TypeScript requires 'my-custom' resolver with typed value
80
- * 'my-custom': (key, value) => ({ [`${key}Data`]: value.data }),
81
- * }
82
- * ).build();
83
- * ```
84
- */
85
- var SstEnvironmentBuilder = class {
86
- builder;
87
- /**
88
- * Create a new SST environment builder.
89
- *
90
- * @param record - Object containing SST resources, custom resources, and/or string values
91
- * @param additionalResolvers - Optional custom resolvers (typed based on custom types in record)
92
- * @param options - Optional configuration options
93
- */
94
- constructor(record, additionalResolvers, options) {
95
- const mergedResolvers = additionalResolvers ? {
96
- ...sstResolvers,
97
- ...additionalResolvers
98
- } : sstResolvers;
99
- this.builder = new require_EnvironmentBuilder.EnvironmentBuilder(record, mergedResolvers, options);
100
- }
101
- /**
102
- * Build environment variables from the input record.
103
- *
104
- * @returns A record of environment variables
105
- */
106
- build() {
107
- return this.builder.build();
108
- }
109
- };
110
-
111
- //#endregion
112
- Object.defineProperty(exports, 'ResourceType', {
113
- enumerable: true,
114
- get: function () {
115
- return ResourceType;
116
- }
117
- });
118
- Object.defineProperty(exports, 'SstEnvironmentBuilder', {
119
- enumerable: true,
120
- get: function () {
121
- return SstEnvironmentBuilder;
122
- }
123
- });
124
- Object.defineProperty(exports, 'sstResolvers', {
125
- enumerable: true,
126
- get: function () {
127
- return sstResolvers;
128
- }
129
- });
130
- //# sourceMappingURL=SstEnvironmentBuilder-D-NGrp7U.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SstEnvironmentBuilder-D-NGrp7U.cjs","names":["name: string","value: SecretValue","key: string","value: PostgresValue","value: BucketValue","value: SnsTopicValue","value: DynamoValue","sstResolvers: Resolvers","record: TRecord","additionalResolvers?: CustomResolvers<TRecord>","options?: EnvironmentBuilderOptions","mergedResolvers: Resolvers","EnvironmentBuilder"],"sources":["../src/SstEnvironmentBuilder.ts"],"sourcesContent":["import {\n\tEnvironmentBuilder,\n\ttype EnvironmentBuilderOptions,\n\ttype EnvironmentResolver,\n\ttype EnvRecord,\n\ttype InputValue,\n\ttype Resolvers,\n} from './EnvironmentBuilder';\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\t// Legacy format (dot notation)\n\tApiGatewayV2 = 'sst.aws.ApiGatewayV2',\n\tPostgres = 'sst.aws.Postgres',\n\tFunction = 'sst.aws.Function',\n\tBucket = 'sst.aws.Bucket',\n\tVpc = 'sst.aws.Vpc',\n\tSecret = 'sst.sst.Secret',\n\tDynamo = 'sst.aws.Dynamo',\n\n\t// Modern format (colon notation)\n\tSSTSecret = 'sst:sst:Secret',\n\tSSTFunction = 'sst:sst:Function',\n\tSSTApiGatewayV2 = 'sst:aws:ApiGatewayV2',\n\tSSTPostgres = 'sst:aws:Postgres',\n\tSSTBucket = 'sst:aws:Bucket',\n\tSnsTopic = 'sst:aws:SnsTopic',\n\tSSTDynamo = 'sst:aws:Dynamo',\n}\n\n/**\n * AWS API Gateway V2 resource type.\n * Represents an HTTP/WebSocket API.\n */\nexport type ApiGatewayV2 = {\n\ttype: ResourceType.ApiGatewayV2 | ResourceType.SSTApiGatewayV2;\n\turl: 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\ttype: ResourceType.Postgres | ResourceType.SSTPostgres;\n\tdatabase: string;\n\thost: string;\n\tpassword: string;\n\tport: number;\n\tusername: string;\n};\n\n/**\n * AWS Lambda Function resource type.\n */\nexport type Function = {\n\ttype: ResourceType.Function | ResourceType.SSTFunction;\n\tname: string;\n};\n\n/**\n * AWS S3 Bucket resource type.\n */\nexport type Bucket = {\n\ttype: ResourceType.Bucket | ResourceType.SSTBucket;\n\tname: string;\n};\n\n/**\n * AWS VPC (Virtual Private Cloud) resource type.\n */\nexport type Vpc = {\n\ttype: ResourceType.Vpc;\n\tbastion: string;\n};\n\n/**\n * Secret resource type for storing sensitive values.\n */\nexport type Secret = {\n\ttype: ResourceType.Secret | ResourceType.SSTSecret;\n\tvalue: string;\n};\n\n/**\n * AWS SNS Topic resource type.\n */\nexport type SnsTopic = {\n\ttype: ResourceType.SnsTopic;\n\tarn: string;\n};\n\n/**\n * AWS DynamoDB Table resource type.\n */\nexport type Dynamo = {\n\ttype: ResourceType.Dynamo | ResourceType.SSTDynamo;\n\tname: string;\n};\n\n/**\n * Union type of all supported SST resource types.\n */\nexport type SstResource =\n\t| ApiGatewayV2\n\t| Postgres\n\t| Function\n\t| Bucket\n\t| Vpc\n\t| Secret\n\t| SnsTopic\n\t| Dynamo;\n\n// Value types without the `type` key (for resolver parameters)\ntype SecretValue = Omit<Secret, 'type'>;\ntype PostgresValue = Omit<Postgres, 'type'>;\ntype BucketValue = Omit<Bucket, 'type'>;\ntype SnsTopicValue = Omit<SnsTopic, 'type'>;\ntype DynamoValue = Omit<Dynamo, 'type'>;\n\n/**\n * Function type for processing a specific resource type into environment variables.\n *\n * @template K - The specific resource type (without `type` key)\n * @param name - The resource name\n * @param value - The resource value (without `type` key)\n * @returns Object mapping environment variable names to values\n */\nexport type ResourceProcessor<K> = (name: string, value: K) => EnvRecord;\n\n// SST Resource Resolvers (receive values without `type` key)\n\nconst secretResolver = (name: string, value: SecretValue) => ({\n\t[name]: value.value,\n});\n\nconst postgresResolver = (key: string, value: PostgresValue) => ({\n\t[`${key}Name`]: value.database,\n\t[`${key}Host`]: value.host,\n\t[`${key}Password`]: value.password,\n\t[`${key}Port`]: value.port,\n\t[`${key}Username`]: value.username,\n});\n\nconst bucketResolver = (name: string, value: BucketValue) => ({\n\t[`${name}Name`]: value.name,\n});\n\nconst topicResolver = (name: string, value: SnsTopicValue) => ({\n\t[`${name}Arn`]: value.arn,\n});\n\nconst dynamoResolver = (name: string, value: DynamoValue) => ({\n\t[`${name}Name`]: value.name,\n});\n\nconst noopResolver = () => ({});\n\n/**\n * Pre-configured resolvers for all SST resource types.\n */\nexport const sstResolvers: Resolvers = {\n\t// Legacy format\n\t[ResourceType.ApiGatewayV2]: noopResolver,\n\t[ResourceType.Function]: noopResolver,\n\t[ResourceType.Vpc]: noopResolver,\n\t[ResourceType.Secret]: secretResolver,\n\t[ResourceType.Postgres]: postgresResolver,\n\t[ResourceType.Bucket]: bucketResolver,\n\t[ResourceType.Dynamo]: dynamoResolver,\n\n\t// Modern format\n\t[ResourceType.SSTSecret]: secretResolver,\n\t[ResourceType.SSTBucket]: bucketResolver,\n\t[ResourceType.SSTFunction]: noopResolver,\n\t[ResourceType.SSTPostgres]: postgresResolver,\n\t[ResourceType.SSTApiGatewayV2]: noopResolver,\n\t[ResourceType.SnsTopic]: topicResolver,\n\t[ResourceType.SSTDynamo]: dynamoResolver,\n};\n\n/**\n * All known SST resource type strings.\n */\ntype SstResourceTypeString = `${ResourceType}`;\n\n/**\n * Extracts the `type` string value from an input value.\n */\ntype ExtractType<T> = T extends { type: infer U extends string } ? U : never;\n\n/**\n * Removes the `type` key from an object type.\n */\ntype OmitType<T> = T extends { type: string } ? Omit<T, 'type'> : never;\n\n/**\n * Extracts all unique `type` values from a record (excluding plain strings).\n */\ntype AllTypeValues<TRecord extends Record<string, InputValue>> = {\n\t[K in keyof TRecord]: ExtractType<TRecord[K]>;\n}[keyof TRecord];\n\n/**\n * Extracts only the custom (non-SST) type values from a record.\n */\ntype CustomTypeValues<TRecord extends Record<string, InputValue>> = Exclude<\n\tAllTypeValues<TRecord>,\n\tSstResourceTypeString\n>;\n\n/**\n * For a given type value, finds the corresponding value type (without `type` key).\n */\ntype ValueForType<\n\tTRecord extends Record<string, InputValue>,\n\tTType extends string,\n> = {\n\t[K in keyof TRecord]: TRecord[K] extends { type: TType }\n\t\t? OmitType<TRecord[K]>\n\t\t: never;\n}[keyof TRecord];\n\n/**\n * Generates typed resolvers for custom (non-SST) types in the input record.\n */\ntype CustomResolvers<TRecord extends Record<string, InputValue>> =\n\tCustomTypeValues<TRecord> extends never\n\t\t? Resolvers | undefined\n\t\t: {\n\t\t\t\t[TType in CustomTypeValues<TRecord>]: EnvironmentResolver<\n\t\t\t\t\tValueForType<TRecord, TType>\n\t\t\t\t>;\n\t\t\t};\n\n/**\n * SST-specific environment builder with built-in resolvers for all known\n * SST resource types.\n *\n * Wraps the generic EnvironmentBuilder with pre-configured SST resolvers.\n *\n * @template TRecord - The input record type for type inference\n *\n * @example\n * ```typescript\n * const env = new SstEnvironmentBuilder({\n * database: { type: 'sst:aws:Postgres', host: '...', ... },\n * apiKey: { type: 'sst:sst:Secret', value: 'secret' },\n * appName: 'my-app',\n * }).build();\n *\n * // With custom resolvers (typed based on input)\n * const env = new SstEnvironmentBuilder(\n * {\n * database: postgresResource,\n * custom: { type: 'my-custom' as const, data: 'foo' },\n * },\n * {\n * // TypeScript requires 'my-custom' resolver with typed value\n * 'my-custom': (key, value) => ({ [`${key}Data`]: value.data }),\n * }\n * ).build();\n * ```\n */\nexport class SstEnvironmentBuilder<\n\tTRecord extends Record<string, SstResource | InputValue | string>,\n> {\n\tprivate readonly builder: EnvironmentBuilder<\n\t\tRecord<string, InputValue>,\n\t\tResolvers\n\t>;\n\n\t/**\n\t * Create a new SST environment builder.\n\t *\n\t * @param record - Object containing SST resources, custom resources, and/or string values\n\t * @param additionalResolvers - Optional custom resolvers (typed based on custom types in record)\n\t * @param options - Optional configuration options\n\t */\n\tconstructor(\n\t\trecord: TRecord,\n\t\tadditionalResolvers?: CustomResolvers<TRecord>,\n\t\toptions?: EnvironmentBuilderOptions,\n\t) {\n\t\t// Merge resolvers with custom ones taking precedence\n\t\tconst mergedResolvers: Resolvers = additionalResolvers\n\t\t\t? { ...sstResolvers, ...additionalResolvers }\n\t\t\t: sstResolvers;\n\n\t\tthis.builder = new EnvironmentBuilder(\n\t\t\trecord as Record<string, InputValue>,\n\t\t\tmergedResolvers,\n\t\t\toptions,\n\t\t);\n\t}\n\n\t/**\n\t * Build environment variables from the input record.\n\t *\n\t * @returns A record of environment variables\n\t */\n\tbuild(): EnvRecord {\n\t\treturn this.builder.build();\n\t}\n}\n\nexport type {\n\tEnvironmentBuilderOptions,\n\tEnvRecord,\n\tEnvValue,\n} from './EnvironmentBuilder';\n// Re-export useful types\nexport { environmentCase } from './EnvironmentBuilder';\n"],"mappings":";;;;;;;AAaA,IAAY,wDAAL;AAEN;AACA;AACA;AACA;AACA;AACA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;AAwGD,MAAM,iBAAiB,CAACA,MAAcC,WAAwB,GAC5D,OAAO,MAAM,MACd;AAED,MAAM,mBAAmB,CAACC,KAAaC,WAA0B;GAC9D,EAAE,IAAI,QAAQ,MAAM;GACpB,EAAE,IAAI,QAAQ,MAAM;GACpB,EAAE,IAAI,YAAY,MAAM;GACxB,EAAE,IAAI,QAAQ,MAAM;GACpB,EAAE,IAAI,YAAY,MAAM;AAC1B;AAED,MAAM,iBAAiB,CAACH,MAAcI,WAAwB,IAC3D,EAAE,KAAK,QAAQ,MAAM,KACvB;AAED,MAAM,gBAAgB,CAACJ,MAAcK,WAA0B,IAC5D,EAAE,KAAK,OAAO,MAAM,IACtB;AAED,MAAM,iBAAiB,CAACL,MAAcM,WAAwB,IA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