@geekmidas/envkit 0.0.8 → 0.1.0

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 (57) hide show
  1. package/README.md +228 -174
  2. package/dist/EnvironmentBuilder-DHfDXJUm.d.mts +131 -0
  3. package/dist/EnvironmentBuilder-DfmYRBm-.mjs +83 -0
  4. package/dist/EnvironmentBuilder-DfmYRBm-.mjs.map +1 -0
  5. package/dist/EnvironmentBuilder-W2wku49g.cjs +95 -0
  6. package/dist/EnvironmentBuilder-W2wku49g.cjs.map +1 -0
  7. package/dist/EnvironmentBuilder-Xuf2Dd9u.d.cts +131 -0
  8. package/dist/EnvironmentBuilder.cjs +4 -0
  9. package/dist/EnvironmentBuilder.d.cts +2 -0
  10. package/dist/EnvironmentBuilder.d.mts +2 -0
  11. package/dist/EnvironmentBuilder.mjs +3 -0
  12. package/dist/{EnvironmentParser-cnxuy7lw.cjs → EnvironmentParser-Bt246UeP.cjs} +1 -1
  13. package/dist/{EnvironmentParser-cnxuy7lw.cjs.map → EnvironmentParser-Bt246UeP.cjs.map} +1 -1
  14. package/dist/{EnvironmentParser-B8--woiB.d.cts → EnvironmentParser-CVWU1ooT.d.mts} +1 -1
  15. package/dist/{EnvironmentParser-STvN_RCc.mjs → EnvironmentParser-c06agx31.mjs} +1 -1
  16. package/dist/{EnvironmentParser-STvN_RCc.mjs.map → EnvironmentParser-c06agx31.mjs.map} +1 -1
  17. package/dist/{EnvironmentParser-C_9v2BDw.d.mts → EnvironmentParser-tV-JjCg7.d.cts} +1 -1
  18. package/dist/EnvironmentParser.cjs +1 -1
  19. package/dist/EnvironmentParser.d.cts +1 -1
  20. package/dist/EnvironmentParser.d.mts +1 -1
  21. package/dist/EnvironmentParser.mjs +1 -1
  22. package/dist/SnifferEnvironmentParser.cjs +1 -1
  23. package/dist/SnifferEnvironmentParser.cjs.map +1 -1
  24. package/dist/SnifferEnvironmentParser.d.cts +1 -1
  25. package/dist/SnifferEnvironmentParser.d.mts +1 -1
  26. package/dist/SnifferEnvironmentParser.mjs +1 -1
  27. package/dist/SnifferEnvironmentParser.mjs.map +1 -1
  28. package/dist/SstEnvironmentBuilder-BuFw1hCe.cjs +125 -0
  29. package/dist/SstEnvironmentBuilder-BuFw1hCe.cjs.map +1 -0
  30. package/dist/SstEnvironmentBuilder-CjURMGjW.d.mts +177 -0
  31. package/dist/SstEnvironmentBuilder-D4oSo_KX.d.cts +177 -0
  32. package/dist/SstEnvironmentBuilder-DEa3lTUB.mjs +108 -0
  33. package/dist/SstEnvironmentBuilder-DEa3lTUB.mjs.map +1 -0
  34. package/dist/SstEnvironmentBuilder.cjs +7 -0
  35. package/dist/SstEnvironmentBuilder.d.cts +3 -0
  36. package/dist/SstEnvironmentBuilder.d.mts +3 -0
  37. package/dist/SstEnvironmentBuilder.mjs +4 -0
  38. package/dist/index.cjs +5 -2
  39. package/dist/index.d.cts +3 -2
  40. package/dist/index.d.mts +3 -2
  41. package/dist/index.mjs +3 -2
  42. package/dist/sst.cjs +13 -114
  43. package/dist/sst.cjs.map +1 -1
  44. package/dist/sst.d.cts +14 -93
  45. package/dist/sst.d.mts +14 -93
  46. package/dist/sst.mjs +10 -112
  47. package/dist/sst.mjs.map +1 -1
  48. package/docs/async-secrets-design.md +355 -0
  49. package/package.json +6 -2
  50. package/src/EnvironmentBuilder.ts +196 -0
  51. package/src/SnifferEnvironmentParser.ts +7 -5
  52. package/src/SstEnvironmentBuilder.ts +298 -0
  53. package/src/__tests__/EnvironmentBuilder.spec.ts +274 -0
  54. package/src/__tests__/SstEnvironmentBuilder.spec.ts +373 -0
  55. package/src/__tests__/sst.spec.ts +1 -1
  56. package/src/index.ts +12 -0
  57. package/src/sst.ts +45 -207
@@ -1,4 +1,4 @@
1
- import { ConfigParser } from "./EnvironmentParser-STvN_RCc.mjs";
1
+ import { ConfigParser } from "./EnvironmentParser-c06agx31.mjs";
2
2
  import { z } from "zod/v4";
3
3
 
4
4
  //#region src/SnifferEnvironmentParser.ts
@@ -1 +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":"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"}
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<T extends EmptyObject = EmptyObject> {\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<\n TResponse extends EmptyObject,\n> 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\n ? parsed.data\n : 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":"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"}
@@ -0,0 +1,125 @@
1
+ const require_EnvironmentBuilder = require('./EnvironmentBuilder-W2wku49g.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["SSTSecret"] = "sst:sst:Secret";
16
+ ResourceType$1["SSTFunction"] = "sst:sst:Function";
17
+ ResourceType$1["SSTApiGatewayV2"] = "sst:aws:ApiGatewayV2";
18
+ ResourceType$1["SSTPostgres"] = "sst:aws:Postgres";
19
+ ResourceType$1["SSTBucket"] = "sst:aws:Bucket";
20
+ ResourceType$1["SnsTopic"] = "sst:aws:SnsTopic";
21
+ return ResourceType$1;
22
+ }({});
23
+ const secretResolver = (name, value) => ({ [name]: value.value });
24
+ const postgresResolver = (key, value) => ({
25
+ [`${key}Name`]: value.database,
26
+ [`${key}Host`]: value.host,
27
+ [`${key}Password`]: value.password,
28
+ [`${key}Port`]: value.port,
29
+ [`${key}Username`]: value.username
30
+ });
31
+ const bucketResolver = (name, value) => ({ [`${name}Name`]: value.name });
32
+ const topicResolver = (name, value) => ({ [`${name}Arn`]: value.arn });
33
+ const noopResolver = () => ({});
34
+ /**
35
+ * Pre-configured resolvers for all SST resource types.
36
+ */
37
+ const sstResolvers = {
38
+ [ResourceType.ApiGatewayV2]: noopResolver,
39
+ [ResourceType.Function]: noopResolver,
40
+ [ResourceType.Vpc]: noopResolver,
41
+ [ResourceType.Secret]: secretResolver,
42
+ [ResourceType.Postgres]: postgresResolver,
43
+ [ResourceType.Bucket]: bucketResolver,
44
+ [ResourceType.SSTSecret]: secretResolver,
45
+ [ResourceType.SSTBucket]: bucketResolver,
46
+ [ResourceType.SSTFunction]: noopResolver,
47
+ [ResourceType.SSTPostgres]: postgresResolver,
48
+ [ResourceType.SSTApiGatewayV2]: noopResolver,
49
+ [ResourceType.SnsTopic]: topicResolver
50
+ };
51
+ /**
52
+ * SST-specific environment builder with built-in resolvers for all known
53
+ * SST resource types.
54
+ *
55
+ * Wraps the generic EnvironmentBuilder with pre-configured SST resolvers.
56
+ *
57
+ * @template TRecord - The input record type for type inference
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * const env = new SstEnvironmentBuilder({
62
+ * database: { type: 'sst:aws:Postgres', host: '...', ... },
63
+ * apiKey: { type: 'sst:sst:Secret', value: 'secret' },
64
+ * appName: 'my-app',
65
+ * }).build();
66
+ *
67
+ * // With custom resolvers (typed based on input)
68
+ * const env = new SstEnvironmentBuilder(
69
+ * {
70
+ * database: postgresResource,
71
+ * custom: { type: 'my-custom' as const, data: 'foo' },
72
+ * },
73
+ * {
74
+ * // TypeScript requires 'my-custom' resolver with typed value
75
+ * 'my-custom': (key, value) => ({ [`${key}Data`]: value.data }),
76
+ * }
77
+ * ).build();
78
+ * ```
79
+ */
80
+ var SstEnvironmentBuilder = class {
81
+ builder;
82
+ /**
83
+ * Create a new SST environment builder.
84
+ *
85
+ * @param record - Object containing SST resources, custom resources, and/or string values
86
+ * @param additionalResolvers - Optional custom resolvers (typed based on custom types in record)
87
+ * @param options - Optional configuration options
88
+ */
89
+ constructor(record, additionalResolvers, options) {
90
+ const mergedResolvers = additionalResolvers ? {
91
+ ...sstResolvers,
92
+ ...additionalResolvers
93
+ } : sstResolvers;
94
+ this.builder = new require_EnvironmentBuilder.EnvironmentBuilder(record, mergedResolvers, options);
95
+ }
96
+ /**
97
+ * Build environment variables from the input record.
98
+ *
99
+ * @returns A record of environment variables
100
+ */
101
+ build() {
102
+ return this.builder.build();
103
+ }
104
+ };
105
+
106
+ //#endregion
107
+ Object.defineProperty(exports, 'ResourceType', {
108
+ enumerable: true,
109
+ get: function () {
110
+ return ResourceType;
111
+ }
112
+ });
113
+ Object.defineProperty(exports, 'SstEnvironmentBuilder', {
114
+ enumerable: true,
115
+ get: function () {
116
+ return SstEnvironmentBuilder;
117
+ }
118
+ });
119
+ Object.defineProperty(exports, 'sstResolvers', {
120
+ enumerable: true,
121
+ get: function () {
122
+ return sstResolvers;
123
+ }
124
+ });
125
+ //# sourceMappingURL=SstEnvironmentBuilder-BuFw1hCe.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SstEnvironmentBuilder-BuFw1hCe.cjs","names":["name: string","value: SecretValue","key: string","value: PostgresValue","value: BucketValue","value: SnsTopicValue","sstResolvers: Resolvers","record: TRecord","additionalResolvers?: CustomResolvers<TRecord>","options?: EnvironmentBuilderOptions","mergedResolvers: Resolvers","EnvironmentBuilder"],"sources":["../src/SstEnvironmentBuilder.ts"],"sourcesContent":["import {\n type EnvRecord,\n EnvironmentBuilder,\n type EnvironmentBuilderOptions,\n type EnvironmentResolver,\n type InputValue,\n type 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 // Legacy format (dot notation)\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\n // Modern format (colon notation)\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 SnsTopic = 'sst:aws:SnsTopic',\n}\n\n/**\n * AWS API Gateway V2 resource type.\n * Represents an HTTP/WebSocket API.\n */\nexport type ApiGatewayV2 = {\n type: ResourceType.ApiGatewayV2 | ResourceType.SSTApiGatewayV2;\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 type: ResourceType.Postgres | ResourceType.SSTPostgres;\n database: string;\n host: string;\n password: string;\n port: number;\n username: string;\n};\n\n/**\n * AWS Lambda Function resource type.\n */\nexport type Function = {\n type: ResourceType.Function | ResourceType.SSTFunction;\n name: string;\n};\n\n/**\n * AWS S3 Bucket resource type.\n */\nexport type Bucket = {\n type: ResourceType.Bucket | ResourceType.SSTBucket;\n name: string;\n};\n\n/**\n * AWS VPC (Virtual Private Cloud) resource type.\n */\nexport type Vpc = {\n type: ResourceType.Vpc;\n bastion: string;\n};\n\n/**\n * Secret resource type for storing sensitive values.\n */\nexport type Secret = {\n type: ResourceType.Secret | ResourceType.SSTSecret;\n value: string;\n};\n\n/**\n * AWS SNS Topic resource type.\n */\nexport type SnsTopic = {\n type: ResourceType.SnsTopic;\n arn: string;\n};\n\n/**\n * Union type of all supported SST resource types.\n */\nexport type SstResource =\n | ApiGatewayV2\n | Postgres\n | Function\n | Bucket\n | Vpc\n | Secret\n | SnsTopic;\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'>;\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 [name]: value.value,\n});\n\nconst postgresResolver = (key: string, value: PostgresValue) => ({\n [`${key}Name`]: value.database,\n [`${key}Host`]: value.host,\n [`${key}Password`]: value.password,\n [`${key}Port`]: value.port,\n [`${key}Username`]: value.username,\n});\n\nconst bucketResolver = (name: string, value: BucketValue) => ({\n [`${name}Name`]: value.name,\n});\n\nconst topicResolver = (name: string, value: SnsTopicValue) => ({\n [`${name}Arn`]: value.arn,\n});\n\nconst noopResolver = () => ({});\n\n/**\n * Pre-configured resolvers for all SST resource types.\n */\nexport const sstResolvers: Resolvers = {\n // Legacy format\n [ResourceType.ApiGatewayV2]: noopResolver,\n [ResourceType.Function]: noopResolver,\n [ResourceType.Vpc]: noopResolver,\n [ResourceType.Secret]: secretResolver,\n [ResourceType.Postgres]: postgresResolver,\n [ResourceType.Bucket]: bucketResolver,\n\n // Modern format\n [ResourceType.SSTSecret]: secretResolver,\n [ResourceType.SSTBucket]: bucketResolver,\n [ResourceType.SSTFunction]: noopResolver,\n [ResourceType.SSTPostgres]: postgresResolver,\n [ResourceType.SSTApiGatewayV2]: noopResolver,\n [ResourceType.SnsTopic]: topicResolver,\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 [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 AllTypeValues<TRecord>,\n SstResourceTypeString\n>;\n\n/**\n * For a given type value, finds the corresponding value type (without `type` key).\n */\ntype ValueForType<\n TRecord extends Record<string, InputValue>,\n TType extends string,\n> = {\n [K in keyof TRecord]: TRecord[K] extends { type: TType }\n ? OmitType<TRecord[K]>\n : 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 CustomTypeValues<TRecord> extends never\n ? Resolvers | undefined\n : {\n [TType in CustomTypeValues<TRecord>]: EnvironmentResolver<\n ValueForType<TRecord, TType>\n >;\n };\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 TRecord extends Record<string, SstResource | InputValue | string>,\n> {\n private readonly builder: EnvironmentBuilder<\n Record<string, InputValue>,\n Resolvers\n >;\n\n /**\n * Create a new SST environment builder.\n *\n * @param record - Object containing SST resources, custom resources, and/or string values\n * @param additionalResolvers - Optional custom resolvers (typed based on custom types in record)\n * @param options - Optional configuration options\n */\n constructor(\n record: TRecord,\n additionalResolvers?: CustomResolvers<TRecord>,\n options?: EnvironmentBuilderOptions,\n ) {\n // Merge resolvers with custom ones taking precedence\n const mergedResolvers: Resolvers = additionalResolvers\n ? { ...sstResolvers, ...additionalResolvers }\n : sstResolvers;\n\n this.builder = new EnvironmentBuilder(\n record as Record<string, InputValue>,\n mergedResolvers,\n options,\n );\n }\n\n /**\n * Build environment variables from the input record.\n *\n * @returns A record of environment variables\n */\n build(): EnvRecord {\n return this.builder.build();\n }\n}\n\n// Re-export useful types\nexport { environmentCase } from './EnvironmentBuilder';\nexport type {\n EnvRecord,\n EnvValue,\n EnvironmentBuilderOptions,\n} from './EnvironmentBuilder';\n"],"mappings":";;;;;;;AAaA,IAAY,wDAAL;AAEL;AACA;AACA;AACA;AACA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;;AACD;AA8FD,MAAM,iBAAiB,CAACA,MAAcC,WAAwB,GAC3D,OAAO,MAAM,MACf;AAED,MAAM,mBAAmB,CAACC,KAAaC,WAA0B;GAC7D,EAAE,IAAI,QAAQ,MAAM;GACpB,EAAE,IAAI,QAAQ,MAAM;GACpB,EAAE,IAAI,YAAY,MAAM;GACxB,EAAE,IAAI,QAAQ,MAAM;GACpB,EAAE,IAAI,YAAY,MAAM;AAC3B;AAED,MAAM,iBAAiB,CAACH,MAAcI,WAAwB,IAC1D,EAAE,KAAK,QAAQ,MAAM,KACxB;AAED,MAAM,gBAAgB,CAACJ,MAAcK,WAA0B,IAC3D,EAAE,KAAK,OAAO,MAAM,IACvB;AAED,MAAM,eAAe,OAAO,CAAE;;;;AAK9B,MAAaC,eAA0B;EAEpC,aAAa,eAAe;EAC5B,aAAa,WAAW;EACxB,aAAa,MAAM;EACnB,aAAa,SAAS;EACtB,aAAa,WAAW;EACxB,aAAa,SAAS;EAGtB,aAAa,YAAY;EACzB,aAAa,YAAY;EACzB,aAAa,cAAc;EAC3B,aAAa,cAAc;EAC3B,aAAa,kBAAkB;EAC/B,aAAa,WAAW;AAC1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqFD,IAAa,wBAAb,MAEE;CACA,AAAiB;;;;;;;;CAYjB,YACEC,QACAC,qBACAC,SACA;EAEA,MAAMC,kBAA6B,sBAC/B;GAAE,GAAG;GAAc,GAAG;EAAqB,IAC3C;AAEJ,OAAK,UAAU,IAAIC,8CACjB,QACA,iBACA;CAEH;;;;;;CAOD,QAAmB;AACjB,SAAO,KAAK,QAAQ,OAAO;CAC5B;AACF"}
@@ -0,0 +1,177 @@
1
+ import { EnvRecord, EnvironmentBuilderOptions, EnvironmentResolver, InputValue, Resolvers } from "./EnvironmentBuilder-DHfDXJUm.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
+ SSTSecret = "sst:sst:Secret",
17
+ SSTFunction = "sst:sst:Function",
18
+ SSTApiGatewayV2 = "sst:aws:ApiGatewayV2",
19
+ SSTPostgres = "sst:aws:Postgres",
20
+ SSTBucket = "sst:aws:Bucket",
21
+ SnsTopic = "sst:aws:SnsTopic",
22
+ }
23
+ /**
24
+ * AWS API Gateway V2 resource type.
25
+ * Represents an HTTP/WebSocket API.
26
+ */
27
+ type ApiGatewayV2 = {
28
+ type: ResourceType.ApiGatewayV2 | ResourceType.SSTApiGatewayV2;
29
+ url: string;
30
+ };
31
+ /**
32
+ * PostgreSQL database resource type.
33
+ * Contains all connection details needed to connect to the database.
34
+ */
35
+ type Postgres = {
36
+ type: ResourceType.Postgres | ResourceType.SSTPostgres;
37
+ database: string;
38
+ host: string;
39
+ password: string;
40
+ port: number;
41
+ username: string;
42
+ };
43
+ /**
44
+ * AWS Lambda Function resource type.
45
+ */
46
+ type Function = {
47
+ type: ResourceType.Function | ResourceType.SSTFunction;
48
+ name: string;
49
+ };
50
+ /**
51
+ * AWS S3 Bucket resource type.
52
+ */
53
+ type Bucket = {
54
+ type: ResourceType.Bucket | ResourceType.SSTBucket;
55
+ name: string;
56
+ };
57
+ /**
58
+ * AWS VPC (Virtual Private Cloud) resource type.
59
+ */
60
+ type Vpc = {
61
+ type: ResourceType.Vpc;
62
+ bastion: string;
63
+ };
64
+ /**
65
+ * Secret resource type for storing sensitive values.
66
+ */
67
+ type Secret = {
68
+ type: ResourceType.Secret | ResourceType.SSTSecret;
69
+ value: string;
70
+ };
71
+ /**
72
+ * AWS SNS Topic resource type.
73
+ */
74
+ type SnsTopic = {
75
+ type: ResourceType.SnsTopic;
76
+ arn: string;
77
+ };
78
+ /**
79
+ * Union type of all supported SST resource types.
80
+ */
81
+ type SstResource = ApiGatewayV2 | Postgres | Function | Bucket | Vpc | Secret | SnsTopic;
82
+ /**
83
+ * Function type for processing a specific resource type into environment variables.
84
+ *
85
+ * @template K - The specific resource type (without `type` key)
86
+ * @param name - The resource name
87
+ * @param value - The resource value (without `type` key)
88
+ * @returns Object mapping environment variable names to values
89
+ */
90
+ type ResourceProcessor<K> = (name: string, value: K) => EnvRecord;
91
+ /**
92
+ * Pre-configured resolvers for all SST resource types.
93
+ */
94
+ declare const sstResolvers: Resolvers;
95
+ /**
96
+ * All known SST resource type strings.
97
+ */
98
+ type SstResourceTypeString = `${ResourceType}`;
99
+ /**
100
+ * Extracts the `type` string value from an input value.
101
+ */
102
+ type ExtractType<T> = T extends {
103
+ type: infer U extends string;
104
+ } ? U : never;
105
+ /**
106
+ * Removes the `type` key from an object type.
107
+ */
108
+ type OmitType<T> = T extends {
109
+ type: string;
110
+ } ? Omit<T, 'type'> : never;
111
+ /**
112
+ * Extracts all unique `type` values from a record (excluding plain strings).
113
+ */
114
+ type AllTypeValues<TRecord extends Record<string, InputValue>> = { [K in keyof TRecord]: ExtractType<TRecord[K]> }[keyof TRecord];
115
+ /**
116
+ * Extracts only the custom (non-SST) type values from a record.
117
+ */
118
+ type CustomTypeValues<TRecord extends Record<string, InputValue>> = Exclude<AllTypeValues<TRecord>, SstResourceTypeString>;
119
+ /**
120
+ * For a given type value, finds the corresponding value type (without `type` key).
121
+ */
122
+ type ValueForType<TRecord extends Record<string, InputValue>, TType extends string> = { [K in keyof TRecord]: TRecord[K] extends {
123
+ type: TType;
124
+ } ? OmitType<TRecord[K]> : never }[keyof TRecord];
125
+ /**
126
+ * Generates typed resolvers for custom (non-SST) types in the input record.
127
+ */
128
+ type CustomResolvers<TRecord extends Record<string, InputValue>> = CustomTypeValues<TRecord> extends never ? Resolvers | undefined : { [TType in CustomTypeValues<TRecord>]: EnvironmentResolver<ValueForType<TRecord, TType>> };
129
+ /**
130
+ * SST-specific environment builder with built-in resolvers for all known
131
+ * SST resource types.
132
+ *
133
+ * Wraps the generic EnvironmentBuilder with pre-configured SST resolvers.
134
+ *
135
+ * @template TRecord - The input record type for type inference
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * const env = new SstEnvironmentBuilder({
140
+ * database: { type: 'sst:aws:Postgres', host: '...', ... },
141
+ * apiKey: { type: 'sst:sst:Secret', value: 'secret' },
142
+ * appName: 'my-app',
143
+ * }).build();
144
+ *
145
+ * // With custom resolvers (typed based on input)
146
+ * const env = new SstEnvironmentBuilder(
147
+ * {
148
+ * database: postgresResource,
149
+ * custom: { type: 'my-custom' as const, data: 'foo' },
150
+ * },
151
+ * {
152
+ * // TypeScript requires 'my-custom' resolver with typed value
153
+ * 'my-custom': (key, value) => ({ [`${key}Data`]: value.data }),
154
+ * }
155
+ * ).build();
156
+ * ```
157
+ */
158
+ declare class SstEnvironmentBuilder<TRecord extends Record<string, SstResource | InputValue | string>> {
159
+ private readonly builder;
160
+ /**
161
+ * Create a new SST environment builder.
162
+ *
163
+ * @param record - Object containing SST resources, custom resources, and/or string values
164
+ * @param additionalResolvers - Optional custom resolvers (typed based on custom types in record)
165
+ * @param options - Optional configuration options
166
+ */
167
+ constructor(record: TRecord, additionalResolvers?: CustomResolvers<TRecord>, options?: EnvironmentBuilderOptions);
168
+ /**
169
+ * Build environment variables from the input record.
170
+ *
171
+ * @returns A record of environment variables
172
+ */
173
+ build(): EnvRecord;
174
+ }
175
+ //#endregion
176
+ export { ApiGatewayV2, Bucket, Function, Postgres, ResourceProcessor, ResourceType, Secret, SnsTopic, SstEnvironmentBuilder, SstResource, Vpc, sstResolvers };
177
+ //# sourceMappingURL=SstEnvironmentBuilder-CjURMGjW.d.mts.map
@@ -0,0 +1,177 @@
1
+ import { EnvRecord, EnvironmentBuilderOptions, EnvironmentResolver, InputValue, Resolvers } from "./EnvironmentBuilder-Xuf2Dd9u.cjs";
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
+ SSTSecret = "sst:sst:Secret",
17
+ SSTFunction = "sst:sst:Function",
18
+ SSTApiGatewayV2 = "sst:aws:ApiGatewayV2",
19
+ SSTPostgres = "sst:aws:Postgres",
20
+ SSTBucket = "sst:aws:Bucket",
21
+ SnsTopic = "sst:aws:SnsTopic",
22
+ }
23
+ /**
24
+ * AWS API Gateway V2 resource type.
25
+ * Represents an HTTP/WebSocket API.
26
+ */
27
+ type ApiGatewayV2 = {
28
+ type: ResourceType.ApiGatewayV2 | ResourceType.SSTApiGatewayV2;
29
+ url: string;
30
+ };
31
+ /**
32
+ * PostgreSQL database resource type.
33
+ * Contains all connection details needed to connect to the database.
34
+ */
35
+ type Postgres = {
36
+ type: ResourceType.Postgres | ResourceType.SSTPostgres;
37
+ database: string;
38
+ host: string;
39
+ password: string;
40
+ port: number;
41
+ username: string;
42
+ };
43
+ /**
44
+ * AWS Lambda Function resource type.
45
+ */
46
+ type Function = {
47
+ type: ResourceType.Function | ResourceType.SSTFunction;
48
+ name: string;
49
+ };
50
+ /**
51
+ * AWS S3 Bucket resource type.
52
+ */
53
+ type Bucket = {
54
+ type: ResourceType.Bucket | ResourceType.SSTBucket;
55
+ name: string;
56
+ };
57
+ /**
58
+ * AWS VPC (Virtual Private Cloud) resource type.
59
+ */
60
+ type Vpc = {
61
+ type: ResourceType.Vpc;
62
+ bastion: string;
63
+ };
64
+ /**
65
+ * Secret resource type for storing sensitive values.
66
+ */
67
+ type Secret = {
68
+ type: ResourceType.Secret | ResourceType.SSTSecret;
69
+ value: string;
70
+ };
71
+ /**
72
+ * AWS SNS Topic resource type.
73
+ */
74
+ type SnsTopic = {
75
+ type: ResourceType.SnsTopic;
76
+ arn: string;
77
+ };
78
+ /**
79
+ * Union type of all supported SST resource types.
80
+ */
81
+ type SstResource = ApiGatewayV2 | Postgres | Function | Bucket | Vpc | Secret | SnsTopic;
82
+ /**
83
+ * Function type for processing a specific resource type into environment variables.
84
+ *
85
+ * @template K - The specific resource type (without `type` key)
86
+ * @param name - The resource name
87
+ * @param value - The resource value (without `type` key)
88
+ * @returns Object mapping environment variable names to values
89
+ */
90
+ type ResourceProcessor<K> = (name: string, value: K) => EnvRecord;
91
+ /**
92
+ * Pre-configured resolvers for all SST resource types.
93
+ */
94
+ declare const sstResolvers: Resolvers;
95
+ /**
96
+ * All known SST resource type strings.
97
+ */
98
+ type SstResourceTypeString = `${ResourceType}`;
99
+ /**
100
+ * Extracts the `type` string value from an input value.
101
+ */
102
+ type ExtractType<T> = T extends {
103
+ type: infer U extends string;
104
+ } ? U : never;
105
+ /**
106
+ * Removes the `type` key from an object type.
107
+ */
108
+ type OmitType<T> = T extends {
109
+ type: string;
110
+ } ? Omit<T, 'type'> : never;
111
+ /**
112
+ * Extracts all unique `type` values from a record (excluding plain strings).
113
+ */
114
+ type AllTypeValues<TRecord extends Record<string, InputValue>> = { [K in keyof TRecord]: ExtractType<TRecord[K]> }[keyof TRecord];
115
+ /**
116
+ * Extracts only the custom (non-SST) type values from a record.
117
+ */
118
+ type CustomTypeValues<TRecord extends Record<string, InputValue>> = Exclude<AllTypeValues<TRecord>, SstResourceTypeString>;
119
+ /**
120
+ * For a given type value, finds the corresponding value type (without `type` key).
121
+ */
122
+ type ValueForType<TRecord extends Record<string, InputValue>, TType extends string> = { [K in keyof TRecord]: TRecord[K] extends {
123
+ type: TType;
124
+ } ? OmitType<TRecord[K]> : never }[keyof TRecord];
125
+ /**
126
+ * Generates typed resolvers for custom (non-SST) types in the input record.
127
+ */
128
+ type CustomResolvers<TRecord extends Record<string, InputValue>> = CustomTypeValues<TRecord> extends never ? Resolvers | undefined : { [TType in CustomTypeValues<TRecord>]: EnvironmentResolver<ValueForType<TRecord, TType>> };
129
+ /**
130
+ * SST-specific environment builder with built-in resolvers for all known
131
+ * SST resource types.
132
+ *
133
+ * Wraps the generic EnvironmentBuilder with pre-configured SST resolvers.
134
+ *
135
+ * @template TRecord - The input record type for type inference
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * const env = new SstEnvironmentBuilder({
140
+ * database: { type: 'sst:aws:Postgres', host: '...', ... },
141
+ * apiKey: { type: 'sst:sst:Secret', value: 'secret' },
142
+ * appName: 'my-app',
143
+ * }).build();
144
+ *
145
+ * // With custom resolvers (typed based on input)
146
+ * const env = new SstEnvironmentBuilder(
147
+ * {
148
+ * database: postgresResource,
149
+ * custom: { type: 'my-custom' as const, data: 'foo' },
150
+ * },
151
+ * {
152
+ * // TypeScript requires 'my-custom' resolver with typed value
153
+ * 'my-custom': (key, value) => ({ [`${key}Data`]: value.data }),
154
+ * }
155
+ * ).build();
156
+ * ```
157
+ */
158
+ declare class SstEnvironmentBuilder<TRecord extends Record<string, SstResource | InputValue | string>> {
159
+ private readonly builder;
160
+ /**
161
+ * Create a new SST environment builder.
162
+ *
163
+ * @param record - Object containing SST resources, custom resources, and/or string values
164
+ * @param additionalResolvers - Optional custom resolvers (typed based on custom types in record)
165
+ * @param options - Optional configuration options
166
+ */
167
+ constructor(record: TRecord, additionalResolvers?: CustomResolvers<TRecord>, options?: EnvironmentBuilderOptions);
168
+ /**
169
+ * Build environment variables from the input record.
170
+ *
171
+ * @returns A record of environment variables
172
+ */
173
+ build(): EnvRecord;
174
+ }
175
+ //#endregion
176
+ export { ApiGatewayV2, Bucket, Function, Postgres, ResourceProcessor, ResourceType, Secret, SnsTopic, SstEnvironmentBuilder, SstResource, Vpc, sstResolvers };
177
+ //# sourceMappingURL=SstEnvironmentBuilder-D4oSo_KX.d.cts.map
@@ -0,0 +1,108 @@
1
+ import { EnvironmentBuilder } from "./EnvironmentBuilder-DfmYRBm-.mjs";
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["SSTSecret"] = "sst:sst:Secret";
16
+ ResourceType$1["SSTFunction"] = "sst:sst:Function";
17
+ ResourceType$1["SSTApiGatewayV2"] = "sst:aws:ApiGatewayV2";
18
+ ResourceType$1["SSTPostgres"] = "sst:aws:Postgres";
19
+ ResourceType$1["SSTBucket"] = "sst:aws:Bucket";
20
+ ResourceType$1["SnsTopic"] = "sst:aws:SnsTopic";
21
+ return ResourceType$1;
22
+ }({});
23
+ const secretResolver = (name, value) => ({ [name]: value.value });
24
+ const postgresResolver = (key, value) => ({
25
+ [`${key}Name`]: value.database,
26
+ [`${key}Host`]: value.host,
27
+ [`${key}Password`]: value.password,
28
+ [`${key}Port`]: value.port,
29
+ [`${key}Username`]: value.username
30
+ });
31
+ const bucketResolver = (name, value) => ({ [`${name}Name`]: value.name });
32
+ const topicResolver = (name, value) => ({ [`${name}Arn`]: value.arn });
33
+ const noopResolver = () => ({});
34
+ /**
35
+ * Pre-configured resolvers for all SST resource types.
36
+ */
37
+ const sstResolvers = {
38
+ [ResourceType.ApiGatewayV2]: noopResolver,
39
+ [ResourceType.Function]: noopResolver,
40
+ [ResourceType.Vpc]: noopResolver,
41
+ [ResourceType.Secret]: secretResolver,
42
+ [ResourceType.Postgres]: postgresResolver,
43
+ [ResourceType.Bucket]: bucketResolver,
44
+ [ResourceType.SSTSecret]: secretResolver,
45
+ [ResourceType.SSTBucket]: bucketResolver,
46
+ [ResourceType.SSTFunction]: noopResolver,
47
+ [ResourceType.SSTPostgres]: postgresResolver,
48
+ [ResourceType.SSTApiGatewayV2]: noopResolver,
49
+ [ResourceType.SnsTopic]: topicResolver
50
+ };
51
+ /**
52
+ * SST-specific environment builder with built-in resolvers for all known
53
+ * SST resource types.
54
+ *
55
+ * Wraps the generic EnvironmentBuilder with pre-configured SST resolvers.
56
+ *
57
+ * @template TRecord - The input record type for type inference
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * const env = new SstEnvironmentBuilder({
62
+ * database: { type: 'sst:aws:Postgres', host: '...', ... },
63
+ * apiKey: { type: 'sst:sst:Secret', value: 'secret' },
64
+ * appName: 'my-app',
65
+ * }).build();
66
+ *
67
+ * // With custom resolvers (typed based on input)
68
+ * const env = new SstEnvironmentBuilder(
69
+ * {
70
+ * database: postgresResource,
71
+ * custom: { type: 'my-custom' as const, data: 'foo' },
72
+ * },
73
+ * {
74
+ * // TypeScript requires 'my-custom' resolver with typed value
75
+ * 'my-custom': (key, value) => ({ [`${key}Data`]: value.data }),
76
+ * }
77
+ * ).build();
78
+ * ```
79
+ */
80
+ var SstEnvironmentBuilder = class {
81
+ builder;
82
+ /**
83
+ * Create a new SST environment builder.
84
+ *
85
+ * @param record - Object containing SST resources, custom resources, and/or string values
86
+ * @param additionalResolvers - Optional custom resolvers (typed based on custom types in record)
87
+ * @param options - Optional configuration options
88
+ */
89
+ constructor(record, additionalResolvers, options) {
90
+ const mergedResolvers = additionalResolvers ? {
91
+ ...sstResolvers,
92
+ ...additionalResolvers
93
+ } : sstResolvers;
94
+ this.builder = new EnvironmentBuilder(record, mergedResolvers, options);
95
+ }
96
+ /**
97
+ * Build environment variables from the input record.
98
+ *
99
+ * @returns A record of environment variables
100
+ */
101
+ build() {
102
+ return this.builder.build();
103
+ }
104
+ };
105
+
106
+ //#endregion
107
+ export { ResourceType, SstEnvironmentBuilder, sstResolvers };
108
+ //# sourceMappingURL=SstEnvironmentBuilder-DEa3lTUB.mjs.map