@geekmidas/envkit 0.0.7 → 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 (74) 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-BDPDLv6i.cjs → EnvironmentParser-Bt246UeP.cjs} +46 -3
  13. package/dist/EnvironmentParser-Bt246UeP.cjs.map +1 -0
  14. package/dist/{EnvironmentParser-C-arQEHQ.d.mts → EnvironmentParser-CVWU1ooT.d.mts} +40 -2
  15. package/dist/{EnvironmentParser-CQUOGqc0.mjs → EnvironmentParser-c06agx31.mjs} +46 -3
  16. package/dist/EnvironmentParser-c06agx31.mjs.map +1 -0
  17. package/dist/{EnvironmentParser-X4h2Vp4r.d.cts → EnvironmentParser-tV-JjCg7.d.cts} +40 -2
  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 +140 -0
  23. package/dist/SnifferEnvironmentParser.cjs.map +1 -0
  24. package/dist/SnifferEnvironmentParser.d.cts +50 -0
  25. package/dist/SnifferEnvironmentParser.d.mts +50 -0
  26. package/dist/SnifferEnvironmentParser.mjs +139 -0
  27. package/dist/SnifferEnvironmentParser.mjs.map +1 -0
  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 +6 -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 +30 -4
  43. package/dist/sst.cjs.map +1 -0
  44. package/dist/sst.d.cts +15 -93
  45. package/dist/sst.d.mts +15 -93
  46. package/dist/sst.mjs +26 -2
  47. package/dist/sst.mjs.map +1 -0
  48. package/docs/async-secrets-design.md +355 -0
  49. package/package.json +11 -2
  50. package/src/EnvironmentBuilder.ts +196 -0
  51. package/src/EnvironmentParser.ts +51 -2
  52. package/src/SnifferEnvironmentParser.ts +209 -0
  53. package/src/SstEnvironmentBuilder.ts +298 -0
  54. package/src/__tests__/EnvironmentBuilder.spec.ts +274 -0
  55. package/src/__tests__/EnvironmentParser.spec.ts +147 -0
  56. package/src/__tests__/SnifferEnvironmentParser.spec.ts +332 -0
  57. package/src/__tests__/SstEnvironmentBuilder.spec.ts +373 -0
  58. package/src/__tests__/sst.spec.ts +1 -1
  59. package/src/index.ts +13 -1
  60. package/src/sst.ts +45 -207
  61. package/dist/__tests__/ConfigParser.spec.cjs +0 -323
  62. package/dist/__tests__/ConfigParser.spec.d.cts +0 -1
  63. package/dist/__tests__/ConfigParser.spec.d.mts +0 -1
  64. package/dist/__tests__/ConfigParser.spec.mjs +0 -322
  65. package/dist/__tests__/EnvironmentParser.spec.cjs +0 -422
  66. package/dist/__tests__/EnvironmentParser.spec.d.cts +0 -1
  67. package/dist/__tests__/EnvironmentParser.spec.d.mts +0 -1
  68. package/dist/__tests__/EnvironmentParser.spec.mjs +0 -421
  69. package/dist/__tests__/sst.spec.cjs +0 -305
  70. package/dist/__tests__/sst.spec.d.cts +0 -1
  71. package/dist/__tests__/sst.spec.d.mts +0 -1
  72. package/dist/__tests__/sst.spec.mjs +0 -304
  73. package/dist/sst-BSxwaAdz.cjs +0 -146
  74. package/dist/sst-CQhO0S6y.mjs +0 -128
@@ -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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SstEnvironmentBuilder-DEa3lTUB.mjs","names":["name: string","value: SecretValue","key: string","value: PostgresValue","value: BucketValue","value: SnsTopicValue","sstResolvers: Resolvers","record: TRecord","additionalResolvers?: CustomResolvers<TRecord>","options?: EnvironmentBuilderOptions","mergedResolvers: Resolvers"],"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,IAAI,mBACjB,QACA,iBACA;CAEH;;;;;;CAOD,QAAmB;AACjB,SAAO,KAAK,QAAQ,OAAO;CAC5B;AACF"}
@@ -0,0 +1,7 @@
1
+ const require_EnvironmentBuilder = require('./EnvironmentBuilder-W2wku49g.cjs');
2
+ const require_SstEnvironmentBuilder = require('./SstEnvironmentBuilder-BuFw1hCe.cjs');
3
+
4
+ exports.ResourceType = require_SstEnvironmentBuilder.ResourceType;
5
+ exports.SstEnvironmentBuilder = require_SstEnvironmentBuilder.SstEnvironmentBuilder;
6
+ exports.environmentCase = require_EnvironmentBuilder.environmentCase;
7
+ exports.sstResolvers = require_SstEnvironmentBuilder.sstResolvers;
@@ -0,0 +1,3 @@
1
+ import { EnvRecord, EnvValue, EnvironmentBuilderOptions, environmentCase } from "./EnvironmentBuilder-Xuf2Dd9u.cjs";
2
+ import { ApiGatewayV2, Bucket, Function, Postgres, ResourceProcessor, ResourceType, Secret, SnsTopic, SstEnvironmentBuilder, SstResource, Vpc, sstResolvers } from "./SstEnvironmentBuilder-D4oSo_KX.cjs";
3
+ export { ApiGatewayV2, Bucket, EnvRecord, EnvValue, EnvironmentBuilderOptions, Function, Postgres, ResourceProcessor, ResourceType, Secret, SnsTopic, SstEnvironmentBuilder, SstResource, Vpc, environmentCase, sstResolvers };
@@ -0,0 +1,3 @@
1
+ import { EnvRecord, EnvValue, EnvironmentBuilderOptions, environmentCase } from "./EnvironmentBuilder-DHfDXJUm.mjs";
2
+ import { ApiGatewayV2, Bucket, Function, Postgres, ResourceProcessor, ResourceType, Secret, SnsTopic, SstEnvironmentBuilder, SstResource, Vpc, sstResolvers } from "./SstEnvironmentBuilder-CjURMGjW.mjs";
3
+ export { ApiGatewayV2, Bucket, EnvRecord, EnvValue, EnvironmentBuilderOptions, Function, Postgres, ResourceProcessor, ResourceType, Secret, SnsTopic, SstEnvironmentBuilder, SstResource, Vpc, environmentCase, sstResolvers };
@@ -0,0 +1,4 @@
1
+ import { environmentCase } from "./EnvironmentBuilder-DfmYRBm-.mjs";
2
+ import { ResourceType, SstEnvironmentBuilder, sstResolvers } from "./SstEnvironmentBuilder-DEa3lTUB.mjs";
3
+
4
+ export { ResourceType, SstEnvironmentBuilder, environmentCase, sstResolvers };
package/dist/index.cjs CHANGED
@@ -1,3 +1,7 @@
1
- const require_EnvironmentParser = require('./EnvironmentParser-BDPDLv6i.cjs');
1
+ const require_EnvironmentBuilder = require('./EnvironmentBuilder-W2wku49g.cjs');
2
+ const require_EnvironmentParser = require('./EnvironmentParser-Bt246UeP.cjs');
2
3
 
3
- exports.EnvironmentParser = require_EnvironmentParser.EnvironmentParser;
4
+ exports.ConfigParser = require_EnvironmentParser.ConfigParser;
5
+ exports.EnvironmentBuilder = require_EnvironmentBuilder.EnvironmentBuilder;
6
+ exports.EnvironmentParser = require_EnvironmentParser.EnvironmentParser;
7
+ exports.environmentCase = require_EnvironmentBuilder.environmentCase;