@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.
- package/README.md +228 -174
- package/dist/EnvironmentBuilder-DHfDXJUm.d.mts +131 -0
- package/dist/EnvironmentBuilder-DfmYRBm-.mjs +83 -0
- package/dist/EnvironmentBuilder-DfmYRBm-.mjs.map +1 -0
- package/dist/EnvironmentBuilder-W2wku49g.cjs +95 -0
- package/dist/EnvironmentBuilder-W2wku49g.cjs.map +1 -0
- package/dist/EnvironmentBuilder-Xuf2Dd9u.d.cts +131 -0
- package/dist/EnvironmentBuilder.cjs +4 -0
- package/dist/EnvironmentBuilder.d.cts +2 -0
- package/dist/EnvironmentBuilder.d.mts +2 -0
- package/dist/EnvironmentBuilder.mjs +3 -0
- package/dist/{EnvironmentParser-cnxuy7lw.cjs → EnvironmentParser-Bt246UeP.cjs} +1 -1
- package/dist/{EnvironmentParser-cnxuy7lw.cjs.map → EnvironmentParser-Bt246UeP.cjs.map} +1 -1
- package/dist/{EnvironmentParser-B8--woiB.d.cts → EnvironmentParser-CVWU1ooT.d.mts} +1 -1
- package/dist/{EnvironmentParser-STvN_RCc.mjs → EnvironmentParser-c06agx31.mjs} +1 -1
- package/dist/{EnvironmentParser-STvN_RCc.mjs.map → EnvironmentParser-c06agx31.mjs.map} +1 -1
- package/dist/{EnvironmentParser-C_9v2BDw.d.mts → EnvironmentParser-tV-JjCg7.d.cts} +1 -1
- package/dist/EnvironmentParser.cjs +1 -1
- package/dist/EnvironmentParser.d.cts +1 -1
- package/dist/EnvironmentParser.d.mts +1 -1
- package/dist/EnvironmentParser.mjs +1 -1
- package/dist/SnifferEnvironmentParser.cjs +1 -1
- package/dist/SnifferEnvironmentParser.cjs.map +1 -1
- package/dist/SnifferEnvironmentParser.d.cts +1 -1
- package/dist/SnifferEnvironmentParser.d.mts +1 -1
- package/dist/SnifferEnvironmentParser.mjs +1 -1
- package/dist/SnifferEnvironmentParser.mjs.map +1 -1
- package/dist/SstEnvironmentBuilder-BuFw1hCe.cjs +125 -0
- package/dist/SstEnvironmentBuilder-BuFw1hCe.cjs.map +1 -0
- package/dist/SstEnvironmentBuilder-CjURMGjW.d.mts +177 -0
- package/dist/SstEnvironmentBuilder-D4oSo_KX.d.cts +177 -0
- package/dist/SstEnvironmentBuilder-DEa3lTUB.mjs +108 -0
- package/dist/SstEnvironmentBuilder-DEa3lTUB.mjs.map +1 -0
- package/dist/SstEnvironmentBuilder.cjs +7 -0
- package/dist/SstEnvironmentBuilder.d.cts +3 -0
- package/dist/SstEnvironmentBuilder.d.mts +3 -0
- package/dist/SstEnvironmentBuilder.mjs +4 -0
- package/dist/index.cjs +5 -2
- package/dist/index.d.cts +3 -2
- package/dist/index.d.mts +3 -2
- package/dist/index.mjs +3 -2
- package/dist/sst.cjs +13 -114
- package/dist/sst.cjs.map +1 -1
- package/dist/sst.d.cts +14 -93
- package/dist/sst.d.mts +14 -93
- package/dist/sst.mjs +10 -112
- package/dist/sst.mjs.map +1 -1
- package/docs/async-secrets-design.md +355 -0
- package/package.json +6 -2
- package/src/EnvironmentBuilder.ts +196 -0
- package/src/SnifferEnvironmentParser.ts +7 -5
- package/src/SstEnvironmentBuilder.ts +298 -0
- package/src/__tests__/EnvironmentBuilder.spec.ts +274 -0
- package/src/__tests__/SstEnvironmentBuilder.spec.ts +373 -0
- package/src/__tests__/sst.spec.ts +1 -1
- package/src/index.ts +12 -0
- package/src/sst.ts +45 -207
|
@@ -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 };
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_EnvironmentBuilder = require('./EnvironmentBuilder-W2wku49g.cjs');
|
|
2
|
+
const require_EnvironmentParser = require('./EnvironmentParser-Bt246UeP.cjs');
|
|
2
3
|
|
|
3
4
|
exports.ConfigParser = require_EnvironmentParser.ConfigParser;
|
|
4
|
-
exports.
|
|
5
|
+
exports.EnvironmentBuilder = require_EnvironmentBuilder.EnvironmentBuilder;
|
|
6
|
+
exports.EnvironmentParser = require_EnvironmentParser.EnvironmentParser;
|
|
7
|
+
exports.environmentCase = require_EnvironmentBuilder.environmentCase;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { EnvRecord, EnvValue, EnvironmentBuilder, EnvironmentBuilderOptions, EnvironmentResolver, InputValue, Resolvers, TypedInputValue, TypedResolvers, environmentCase } from "./EnvironmentBuilder-Xuf2Dd9u.cjs";
|
|
2
|
+
import { ConfigParser, EnvironmentParser } from "./EnvironmentParser-tV-JjCg7.cjs";
|
|
3
|
+
export { ConfigParser, EnvRecord, EnvValue, EnvironmentBuilder, EnvironmentBuilderOptions, EnvironmentParser, EnvironmentResolver, InputValue, Resolvers, TypedInputValue, TypedResolvers, environmentCase };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { EnvRecord, EnvValue, EnvironmentBuilder, EnvironmentBuilderOptions, EnvironmentResolver, InputValue, Resolvers, TypedInputValue, TypedResolvers, environmentCase } from "./EnvironmentBuilder-DHfDXJUm.mjs";
|
|
2
|
+
import { ConfigParser, EnvironmentParser } from "./EnvironmentParser-CVWU1ooT.mjs";
|
|
3
|
+
export { ConfigParser, EnvRecord, EnvValue, EnvironmentBuilder, EnvironmentBuilderOptions, EnvironmentParser, EnvironmentResolver, InputValue, Resolvers, TypedInputValue, TypedResolvers, environmentCase };
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EnvironmentBuilder, environmentCase } from "./EnvironmentBuilder-DfmYRBm-.mjs";
|
|
2
|
+
import { ConfigParser, EnvironmentParser } from "./EnvironmentParser-c06agx31.mjs";
|
|
2
3
|
|
|
3
|
-
export { ConfigParser, EnvironmentParser };
|
|
4
|
+
export { ConfigParser, EnvironmentBuilder, EnvironmentParser, environmentCase };
|
package/dist/sst.cjs
CHANGED
|
@@ -1,104 +1,10 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
1
|
+
const require_EnvironmentBuilder = require('./EnvironmentBuilder-W2wku49g.cjs');
|
|
2
|
+
const require_SstEnvironmentBuilder = require('./SstEnvironmentBuilder-BuFw1hCe.cjs');
|
|
3
3
|
|
|
4
4
|
//#region src/sst.ts
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* Numbers following underscores are preserved without the underscore.
|
|
6
|
+
* @deprecated Use `new SstEnvironmentBuilder(record).build()` instead.
|
|
8
7
|
*
|
|
9
|
-
* @param name - The string to convert
|
|
10
|
-
* @returns The converted string in environment variable format
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* environmentCase('myVariable') // 'MY_VARIABLE'
|
|
14
|
-
* environmentCase('api_v2') // 'APIV2'
|
|
15
|
-
*/
|
|
16
|
-
function environmentCase(name) {
|
|
17
|
-
return (0, lodash_snakecase.default)(name).toUpperCase().replace(/_\d+/g, (r) => {
|
|
18
|
-
return r.replace("_", "");
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Enumeration of supported SST (Serverless Stack Toolkit) resource types.
|
|
23
|
-
* Used to identify and process different AWS and SST resources.
|
|
24
|
-
*/
|
|
25
|
-
let ResourceType = /* @__PURE__ */ function(ResourceType$1) {
|
|
26
|
-
ResourceType$1["ApiGatewayV2"] = "sst.aws.ApiGatewayV2";
|
|
27
|
-
ResourceType$1["Postgres"] = "sst.aws.Postgres";
|
|
28
|
-
ResourceType$1["Function"] = "sst.aws.Function";
|
|
29
|
-
ResourceType$1["Bucket"] = "sst.aws.Bucket";
|
|
30
|
-
ResourceType$1["Vpc"] = "sst.aws.Vpc";
|
|
31
|
-
ResourceType$1["Secret"] = "sst.sst.Secret";
|
|
32
|
-
ResourceType$1["SSTSecret"] = "sst:sst:Secret";
|
|
33
|
-
ResourceType$1["SSTFunction"] = "sst:sst:Function";
|
|
34
|
-
ResourceType$1["SSTApiGatewayV2"] = "sst:aws:ApiGatewayV2";
|
|
35
|
-
ResourceType$1["SSTPostgres"] = "sst:aws:Postgres";
|
|
36
|
-
ResourceType$1["SSTBucket"] = "sst:aws:Bucket";
|
|
37
|
-
return ResourceType$1;
|
|
38
|
-
}({});
|
|
39
|
-
/**
|
|
40
|
-
* Processes a Secret resource into environment variables.
|
|
41
|
-
*
|
|
42
|
-
* @param name - The resource name
|
|
43
|
-
* @param value - The Secret resource
|
|
44
|
-
* @returns Object with environment variable mappings
|
|
45
|
-
*/
|
|
46
|
-
const secret = (name, value) => ({ [environmentCase(name)]: value.value });
|
|
47
|
-
/**
|
|
48
|
-
* Processes a Postgres database resource into environment variables.
|
|
49
|
-
* Creates multiple environment variables for database connection details.
|
|
50
|
-
*
|
|
51
|
-
* @param key - The resource key
|
|
52
|
-
* @param value - The Postgres resource
|
|
53
|
-
* @returns Object with database connection environment variables
|
|
54
|
-
*/
|
|
55
|
-
const postgres = (key, value) => {
|
|
56
|
-
const prefix = `${environmentCase(key)}`;
|
|
57
|
-
return {
|
|
58
|
-
[`${prefix}_NAME`]: value.database,
|
|
59
|
-
[`${prefix}_HOST`]: value.host,
|
|
60
|
-
[`${prefix}_PASSWORD`]: value.password,
|
|
61
|
-
[`${prefix}_PORT`]: value.port,
|
|
62
|
-
[`${prefix}_USERNAME`]: value.username
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* Processes a Bucket resource into environment variables.
|
|
67
|
-
*
|
|
68
|
-
* @param name - The resource name
|
|
69
|
-
* @param value - The Bucket resource
|
|
70
|
-
* @returns Object with bucket name environment variable
|
|
71
|
-
*/
|
|
72
|
-
const bucket = (name, value) => {
|
|
73
|
-
const prefix = `${environmentCase(name)}`;
|
|
74
|
-
return { [`${prefix}_NAME`]: value.name };
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* No-operation processor for resources that don't require environment variables.
|
|
78
|
-
*
|
|
79
|
-
* @param name - The resource name (unused)
|
|
80
|
-
* @param value - The resource value (unused)
|
|
81
|
-
* @returns Empty object
|
|
82
|
-
*/
|
|
83
|
-
const noop = (name, value) => ({});
|
|
84
|
-
/**
|
|
85
|
-
* Map of resource types to their corresponding processor functions.
|
|
86
|
-
* Each processor converts resource data into environment variables.
|
|
87
|
-
*/
|
|
88
|
-
const processors = {
|
|
89
|
-
[ResourceType.ApiGatewayV2]: noop,
|
|
90
|
-
[ResourceType.Function]: noop,
|
|
91
|
-
[ResourceType.Vpc]: noop,
|
|
92
|
-
[ResourceType.Secret]: secret,
|
|
93
|
-
[ResourceType.Postgres]: postgres,
|
|
94
|
-
[ResourceType.Bucket]: bucket,
|
|
95
|
-
[ResourceType.SSTSecret]: secret,
|
|
96
|
-
[ResourceType.SSTBucket]: bucket,
|
|
97
|
-
[ResourceType.SSTFunction]: noop,
|
|
98
|
-
[ResourceType.SSTPostgres]: postgres,
|
|
99
|
-
[ResourceType.SSTApiGatewayV2]: noop
|
|
100
|
-
};
|
|
101
|
-
/**
|
|
102
8
|
* Normalizes SST resources and plain strings into environment variables.
|
|
103
9
|
* Processes resources based on their type and converts names to environment case.
|
|
104
10
|
*
|
|
@@ -106,27 +12,20 @@ const processors = {
|
|
|
106
12
|
* @returns Normalized environment variables object
|
|
107
13
|
*
|
|
108
14
|
* @example
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
15
|
+
* // Old usage (deprecated):
|
|
16
|
+
* normalizeResourceEnv({ database: postgresResource })
|
|
17
|
+
*
|
|
18
|
+
* // New usage:
|
|
19
|
+
* new SstEnvironmentBuilder({ database: postgresResource }).build()
|
|
113
20
|
*/
|
|
114
21
|
function normalizeResourceEnv(record) {
|
|
115
|
-
|
|
116
|
-
for (const [k, value] of Object.entries(record)) {
|
|
117
|
-
if (typeof value === "string") {
|
|
118
|
-
env[environmentCase(k)] = value;
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
const processor = processors[value.type];
|
|
122
|
-
if (processor) Object.assign(env, processor(k, value));
|
|
123
|
-
else console.warn(`No processor found for resource type: `, { value });
|
|
124
|
-
}
|
|
125
|
-
return env;
|
|
22
|
+
return new require_SstEnvironmentBuilder.SstEnvironmentBuilder(record).build();
|
|
126
23
|
}
|
|
127
24
|
|
|
128
25
|
//#endregion
|
|
129
|
-
exports.ResourceType = ResourceType;
|
|
130
|
-
exports.
|
|
26
|
+
exports.ResourceType = require_SstEnvironmentBuilder.ResourceType;
|
|
27
|
+
exports.SstEnvironmentBuilder = require_SstEnvironmentBuilder.SstEnvironmentBuilder;
|
|
28
|
+
exports.environmentCase = require_EnvironmentBuilder.environmentCase;
|
|
131
29
|
exports.normalizeResourceEnv = normalizeResourceEnv;
|
|
30
|
+
exports.sstResolvers = require_SstEnvironmentBuilder.sstResolvers;
|
|
132
31
|
//# sourceMappingURL=sst.cjs.map
|
package/dist/sst.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sst.cjs","names":["
|
|
1
|
+
{"version":3,"file":"sst.cjs","names":["record: Record<string, SstResource | string>","SstEnvironmentBuilder"],"sources":["../src/sst.ts"],"sourcesContent":["// Re-export everything from SstEnvironmentBuilder\nexport {\n SstEnvironmentBuilder,\n sstResolvers,\n ResourceType,\n type ApiGatewayV2,\n type Postgres,\n type Function,\n type Bucket,\n type Vpc,\n type Secret,\n type SnsTopic,\n type SstResource,\n type ResourceProcessor,\n} from './SstEnvironmentBuilder';\n\n// Re-export environmentCase from EnvironmentBuilder\nexport { environmentCase } from './EnvironmentBuilder';\n\n// Re-export types from EnvironmentBuilder\nexport type {\n EnvRecord,\n EnvValue,\n EnvironmentBuilderOptions,\n} from './EnvironmentBuilder';\n\n// Import for deprecated function\nimport {\n SstEnvironmentBuilder,\n type SstResource,\n} from './SstEnvironmentBuilder';\n\n/**\n * @deprecated Use `new SstEnvironmentBuilder(record).build()` instead.\n *\n * Normalizes SST resources and plain strings into environment variables.\n * Processes resources based on their type and converts names to environment case.\n *\n * @param record - Object containing resources and/or string values\n * @returns Normalized environment variables object\n *\n * @example\n * // Old usage (deprecated):\n * normalizeResourceEnv({ database: postgresResource })\n *\n * // New usage:\n * new SstEnvironmentBuilder({ database: postgresResource }).build()\n */\nexport function normalizeResourceEnv(\n record: Record<string, SstResource | string>,\n): Record<string, string | number | boolean | Record<string, unknown>> {\n return new SstEnvironmentBuilder(record).build();\n}\n\n// Keep Resource type as deprecated alias for backwards compatibility\n/**\n * @deprecated Use `SstResource` instead.\n */\nexport type Resource = SstResource;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAgDA,SAAgB,qBACdA,QACqE;AACrE,QAAO,IAAIC,oDAAsB,QAAQ,OAAO;AACjD"}
|
package/dist/sst.d.cts
CHANGED
|
@@ -1,34 +1,11 @@
|
|
|
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
|
+
|
|
1
4
|
//#region src/sst.d.ts
|
|
5
|
+
|
|
2
6
|
/**
|
|
3
|
-
*
|
|
4
|
-
* Numbers following underscores are preserved without the underscore.
|
|
7
|
+
* @deprecated Use `new SstEnvironmentBuilder(record).build()` instead.
|
|
5
8
|
*
|
|
6
|
-
* @param name - The string to convert
|
|
7
|
-
* @returns The converted string in environment variable format
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* environmentCase('myVariable') // 'MY_VARIABLE'
|
|
11
|
-
* environmentCase('api_v2') // 'APIV2'
|
|
12
|
-
*/
|
|
13
|
-
declare function environmentCase(name: string): string;
|
|
14
|
-
/**
|
|
15
|
-
* Enumeration of supported SST (Serverless Stack Toolkit) resource types.
|
|
16
|
-
* Used to identify and process different AWS and SST resources.
|
|
17
|
-
*/
|
|
18
|
-
declare enum ResourceType {
|
|
19
|
-
ApiGatewayV2 = "sst.aws.ApiGatewayV2",
|
|
20
|
-
Postgres = "sst.aws.Postgres",
|
|
21
|
-
Function = "sst.aws.Function",
|
|
22
|
-
Bucket = "sst.aws.Bucket",
|
|
23
|
-
Vpc = "sst.aws.Vpc",
|
|
24
|
-
Secret = "sst.sst.Secret",
|
|
25
|
-
SSTSecret = "sst:sst:Secret",
|
|
26
|
-
SSTFunction = "sst:sst:Function",
|
|
27
|
-
SSTApiGatewayV2 = "sst:aws:ApiGatewayV2",
|
|
28
|
-
SSTPostgres = "sst:aws:Postgres",
|
|
29
|
-
SSTBucket = "sst:aws:Bucket",
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
9
|
* Normalizes SST resources and plain strings into environment variables.
|
|
33
10
|
* Processes resources based on their type and converts names to environment case.
|
|
34
11
|
*
|
|
@@ -36,73 +13,17 @@ declare enum ResourceType {
|
|
|
36
13
|
* @returns Normalized environment variables object
|
|
37
14
|
*
|
|
38
15
|
* @example
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
|
|
44
|
-
declare function normalizeResourceEnv(record: Record<string, Resource | string>): Record<string, string>;
|
|
45
|
-
/**
|
|
46
|
-
* AWS API Gateway V2 resource type.
|
|
47
|
-
* Represents an HTTP/WebSocket API.
|
|
48
|
-
*/
|
|
49
|
-
type ApiGatewayV2 = {
|
|
50
|
-
type: ResourceType.ApiGatewayV2;
|
|
51
|
-
url: string;
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* PostgreSQL database resource type.
|
|
55
|
-
* Contains all connection details needed to connect to the database.
|
|
56
|
-
*/
|
|
57
|
-
type Postgres = {
|
|
58
|
-
database: string;
|
|
59
|
-
host: string;
|
|
60
|
-
password: string;
|
|
61
|
-
port: number;
|
|
62
|
-
type: ResourceType.Postgres;
|
|
63
|
-
username: string;
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* AWS Lambda Function resource type.
|
|
67
|
-
*/
|
|
68
|
-
type Function = {
|
|
69
|
-
name: string;
|
|
70
|
-
type: ResourceType.Function;
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* AWS S3 Bucket resource type.
|
|
74
|
-
*/
|
|
75
|
-
type Bucket = {
|
|
76
|
-
name: string;
|
|
77
|
-
type: ResourceType.Bucket;
|
|
78
|
-
};
|
|
79
|
-
/**
|
|
80
|
-
* AWS VPC (Virtual Private Cloud) resource type.
|
|
81
|
-
*/
|
|
82
|
-
type Vpc = {
|
|
83
|
-
bastion: string;
|
|
84
|
-
type: ResourceType.Vpc;
|
|
85
|
-
};
|
|
86
|
-
/**
|
|
87
|
-
* Secret resource type for storing sensitive values.
|
|
88
|
-
*/
|
|
89
|
-
type Secret = {
|
|
90
|
-
type: ResourceType.Secret;
|
|
91
|
-
value: string;
|
|
92
|
-
};
|
|
93
|
-
/**
|
|
94
|
-
* Union type of all supported SST resource types.
|
|
16
|
+
* // Old usage (deprecated):
|
|
17
|
+
* normalizeResourceEnv({ database: postgresResource })
|
|
18
|
+
*
|
|
19
|
+
* // New usage:
|
|
20
|
+
* new SstEnvironmentBuilder({ database: postgresResource }).build()
|
|
95
21
|
*/
|
|
96
|
-
|
|
22
|
+
declare function normalizeResourceEnv(record: Record<string, SstResource | string>): Record<string, string | number | boolean | Record<string, unknown>>;
|
|
97
23
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* @template K - The specific resource type
|
|
101
|
-
* @param name - The resource name
|
|
102
|
-
* @param value - The resource value
|
|
103
|
-
* @returns Object mapping environment variable names to values
|
|
24
|
+
* @deprecated Use `SstResource` instead.
|
|
104
25
|
*/
|
|
105
|
-
type
|
|
26
|
+
type Resource = SstResource;
|
|
106
27
|
//#endregion
|
|
107
|
-
export { ApiGatewayV2, Bucket, Function, Postgres, Resource, ResourceProcessor, ResourceType, Secret, Vpc, environmentCase, normalizeResourceEnv };
|
|
28
|
+
export { ApiGatewayV2, Bucket, EnvRecord, EnvValue, EnvironmentBuilderOptions, Function, Postgres, Resource, ResourceProcessor, ResourceType, Secret, SnsTopic, SstEnvironmentBuilder, SstResource, Vpc, environmentCase, normalizeResourceEnv, sstResolvers };
|
|
108
29
|
//# sourceMappingURL=sst.d.cts.map
|
package/dist/sst.d.mts
CHANGED
|
@@ -1,34 +1,11 @@
|
|
|
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
|
+
|
|
1
4
|
//#region src/sst.d.ts
|
|
5
|
+
|
|
2
6
|
/**
|
|
3
|
-
*
|
|
4
|
-
* Numbers following underscores are preserved without the underscore.
|
|
7
|
+
* @deprecated Use `new SstEnvironmentBuilder(record).build()` instead.
|
|
5
8
|
*
|
|
6
|
-
* @param name - The string to convert
|
|
7
|
-
* @returns The converted string in environment variable format
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* environmentCase('myVariable') // 'MY_VARIABLE'
|
|
11
|
-
* environmentCase('api_v2') // 'APIV2'
|
|
12
|
-
*/
|
|
13
|
-
declare function environmentCase(name: string): string;
|
|
14
|
-
/**
|
|
15
|
-
* Enumeration of supported SST (Serverless Stack Toolkit) resource types.
|
|
16
|
-
* Used to identify and process different AWS and SST resources.
|
|
17
|
-
*/
|
|
18
|
-
declare enum ResourceType {
|
|
19
|
-
ApiGatewayV2 = "sst.aws.ApiGatewayV2",
|
|
20
|
-
Postgres = "sst.aws.Postgres",
|
|
21
|
-
Function = "sst.aws.Function",
|
|
22
|
-
Bucket = "sst.aws.Bucket",
|
|
23
|
-
Vpc = "sst.aws.Vpc",
|
|
24
|
-
Secret = "sst.sst.Secret",
|
|
25
|
-
SSTSecret = "sst:sst:Secret",
|
|
26
|
-
SSTFunction = "sst:sst:Function",
|
|
27
|
-
SSTApiGatewayV2 = "sst:aws:ApiGatewayV2",
|
|
28
|
-
SSTPostgres = "sst:aws:Postgres",
|
|
29
|
-
SSTBucket = "sst:aws:Bucket",
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
9
|
* Normalizes SST resources and plain strings into environment variables.
|
|
33
10
|
* Processes resources based on their type and converts names to environment case.
|
|
34
11
|
*
|
|
@@ -36,73 +13,17 @@ declare enum ResourceType {
|
|
|
36
13
|
* @returns Normalized environment variables object
|
|
37
14
|
*
|
|
38
15
|
* @example
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
|
|
44
|
-
declare function normalizeResourceEnv(record: Record<string, Resource | string>): Record<string, string>;
|
|
45
|
-
/**
|
|
46
|
-
* AWS API Gateway V2 resource type.
|
|
47
|
-
* Represents an HTTP/WebSocket API.
|
|
48
|
-
*/
|
|
49
|
-
type ApiGatewayV2 = {
|
|
50
|
-
type: ResourceType.ApiGatewayV2;
|
|
51
|
-
url: string;
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* PostgreSQL database resource type.
|
|
55
|
-
* Contains all connection details needed to connect to the database.
|
|
56
|
-
*/
|
|
57
|
-
type Postgres = {
|
|
58
|
-
database: string;
|
|
59
|
-
host: string;
|
|
60
|
-
password: string;
|
|
61
|
-
port: number;
|
|
62
|
-
type: ResourceType.Postgres;
|
|
63
|
-
username: string;
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* AWS Lambda Function resource type.
|
|
67
|
-
*/
|
|
68
|
-
type Function = {
|
|
69
|
-
name: string;
|
|
70
|
-
type: ResourceType.Function;
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* AWS S3 Bucket resource type.
|
|
74
|
-
*/
|
|
75
|
-
type Bucket = {
|
|
76
|
-
name: string;
|
|
77
|
-
type: ResourceType.Bucket;
|
|
78
|
-
};
|
|
79
|
-
/**
|
|
80
|
-
* AWS VPC (Virtual Private Cloud) resource type.
|
|
81
|
-
*/
|
|
82
|
-
type Vpc = {
|
|
83
|
-
bastion: string;
|
|
84
|
-
type: ResourceType.Vpc;
|
|
85
|
-
};
|
|
86
|
-
/**
|
|
87
|
-
* Secret resource type for storing sensitive values.
|
|
88
|
-
*/
|
|
89
|
-
type Secret = {
|
|
90
|
-
type: ResourceType.Secret;
|
|
91
|
-
value: string;
|
|
92
|
-
};
|
|
93
|
-
/**
|
|
94
|
-
* Union type of all supported SST resource types.
|
|
16
|
+
* // Old usage (deprecated):
|
|
17
|
+
* normalizeResourceEnv({ database: postgresResource })
|
|
18
|
+
*
|
|
19
|
+
* // New usage:
|
|
20
|
+
* new SstEnvironmentBuilder({ database: postgresResource }).build()
|
|
95
21
|
*/
|
|
96
|
-
|
|
22
|
+
declare function normalizeResourceEnv(record: Record<string, SstResource | string>): Record<string, string | number | boolean | Record<string, unknown>>;
|
|
97
23
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* @template K - The specific resource type
|
|
101
|
-
* @param name - The resource name
|
|
102
|
-
* @param value - The resource value
|
|
103
|
-
* @returns Object mapping environment variable names to values
|
|
24
|
+
* @deprecated Use `SstResource` instead.
|
|
104
25
|
*/
|
|
105
|
-
type
|
|
26
|
+
type Resource = SstResource;
|
|
106
27
|
//#endregion
|
|
107
|
-
export { ApiGatewayV2, Bucket, Function, Postgres, Resource, ResourceProcessor, ResourceType, Secret, Vpc, environmentCase, normalizeResourceEnv };
|
|
28
|
+
export { ApiGatewayV2, Bucket, EnvRecord, EnvValue, EnvironmentBuilderOptions, Function, Postgres, Resource, ResourceProcessor, ResourceType, Secret, SnsTopic, SstEnvironmentBuilder, SstResource, Vpc, environmentCase, normalizeResourceEnv, sstResolvers };
|
|
108
29
|
//# sourceMappingURL=sst.d.mts.map
|
package/dist/sst.mjs
CHANGED
|
@@ -1,103 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { environmentCase } from "./EnvironmentBuilder-DfmYRBm-.mjs";
|
|
2
|
+
import { ResourceType, SstEnvironmentBuilder, sstResolvers } from "./SstEnvironmentBuilder-DEa3lTUB.mjs";
|
|
2
3
|
|
|
3
4
|
//#region src/sst.ts
|
|
4
5
|
/**
|
|
5
|
-
*
|
|
6
|
-
* Numbers following underscores are preserved without the underscore.
|
|
6
|
+
* @deprecated Use `new SstEnvironmentBuilder(record).build()` instead.
|
|
7
7
|
*
|
|
8
|
-
* @param name - The string to convert
|
|
9
|
-
* @returns The converted string in environment variable format
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* environmentCase('myVariable') // 'MY_VARIABLE'
|
|
13
|
-
* environmentCase('api_v2') // 'APIV2'
|
|
14
|
-
*/
|
|
15
|
-
function environmentCase(name) {
|
|
16
|
-
return snakecase(name).toUpperCase().replace(/_\d+/g, (r) => {
|
|
17
|
-
return r.replace("_", "");
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Enumeration of supported SST (Serverless Stack Toolkit) resource types.
|
|
22
|
-
* Used to identify and process different AWS and SST resources.
|
|
23
|
-
*/
|
|
24
|
-
let ResourceType = /* @__PURE__ */ function(ResourceType$1) {
|
|
25
|
-
ResourceType$1["ApiGatewayV2"] = "sst.aws.ApiGatewayV2";
|
|
26
|
-
ResourceType$1["Postgres"] = "sst.aws.Postgres";
|
|
27
|
-
ResourceType$1["Function"] = "sst.aws.Function";
|
|
28
|
-
ResourceType$1["Bucket"] = "sst.aws.Bucket";
|
|
29
|
-
ResourceType$1["Vpc"] = "sst.aws.Vpc";
|
|
30
|
-
ResourceType$1["Secret"] = "sst.sst.Secret";
|
|
31
|
-
ResourceType$1["SSTSecret"] = "sst:sst:Secret";
|
|
32
|
-
ResourceType$1["SSTFunction"] = "sst:sst:Function";
|
|
33
|
-
ResourceType$1["SSTApiGatewayV2"] = "sst:aws:ApiGatewayV2";
|
|
34
|
-
ResourceType$1["SSTPostgres"] = "sst:aws:Postgres";
|
|
35
|
-
ResourceType$1["SSTBucket"] = "sst:aws:Bucket";
|
|
36
|
-
return ResourceType$1;
|
|
37
|
-
}({});
|
|
38
|
-
/**
|
|
39
|
-
* Processes a Secret resource into environment variables.
|
|
40
|
-
*
|
|
41
|
-
* @param name - The resource name
|
|
42
|
-
* @param value - The Secret resource
|
|
43
|
-
* @returns Object with environment variable mappings
|
|
44
|
-
*/
|
|
45
|
-
const secret = (name, value) => ({ [environmentCase(name)]: value.value });
|
|
46
|
-
/**
|
|
47
|
-
* Processes a Postgres database resource into environment variables.
|
|
48
|
-
* Creates multiple environment variables for database connection details.
|
|
49
|
-
*
|
|
50
|
-
* @param key - The resource key
|
|
51
|
-
* @param value - The Postgres resource
|
|
52
|
-
* @returns Object with database connection environment variables
|
|
53
|
-
*/
|
|
54
|
-
const postgres = (key, value) => {
|
|
55
|
-
const prefix = `${environmentCase(key)}`;
|
|
56
|
-
return {
|
|
57
|
-
[`${prefix}_NAME`]: value.database,
|
|
58
|
-
[`${prefix}_HOST`]: value.host,
|
|
59
|
-
[`${prefix}_PASSWORD`]: value.password,
|
|
60
|
-
[`${prefix}_PORT`]: value.port,
|
|
61
|
-
[`${prefix}_USERNAME`]: value.username
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* Processes a Bucket resource into environment variables.
|
|
66
|
-
*
|
|
67
|
-
* @param name - The resource name
|
|
68
|
-
* @param value - The Bucket resource
|
|
69
|
-
* @returns Object with bucket name environment variable
|
|
70
|
-
*/
|
|
71
|
-
const bucket = (name, value) => {
|
|
72
|
-
const prefix = `${environmentCase(name)}`;
|
|
73
|
-
return { [`${prefix}_NAME`]: value.name };
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* No-operation processor for resources that don't require environment variables.
|
|
77
|
-
*
|
|
78
|
-
* @param name - The resource name (unused)
|
|
79
|
-
* @param value - The resource value (unused)
|
|
80
|
-
* @returns Empty object
|
|
81
|
-
*/
|
|
82
|
-
const noop = (name, value) => ({});
|
|
83
|
-
/**
|
|
84
|
-
* Map of resource types to their corresponding processor functions.
|
|
85
|
-
* Each processor converts resource data into environment variables.
|
|
86
|
-
*/
|
|
87
|
-
const processors = {
|
|
88
|
-
[ResourceType.ApiGatewayV2]: noop,
|
|
89
|
-
[ResourceType.Function]: noop,
|
|
90
|
-
[ResourceType.Vpc]: noop,
|
|
91
|
-
[ResourceType.Secret]: secret,
|
|
92
|
-
[ResourceType.Postgres]: postgres,
|
|
93
|
-
[ResourceType.Bucket]: bucket,
|
|
94
|
-
[ResourceType.SSTSecret]: secret,
|
|
95
|
-
[ResourceType.SSTBucket]: bucket,
|
|
96
|
-
[ResourceType.SSTFunction]: noop,
|
|
97
|
-
[ResourceType.SSTPostgres]: postgres,
|
|
98
|
-
[ResourceType.SSTApiGatewayV2]: noop
|
|
99
|
-
};
|
|
100
|
-
/**
|
|
101
8
|
* Normalizes SST resources and plain strings into environment variables.
|
|
102
9
|
* Processes resources based on their type and converts names to environment case.
|
|
103
10
|
*
|
|
@@ -105,25 +12,16 @@ const processors = {
|
|
|
105
12
|
* @returns Normalized environment variables object
|
|
106
13
|
*
|
|
107
14
|
* @example
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
15
|
+
* // Old usage (deprecated):
|
|
16
|
+
* normalizeResourceEnv({ database: postgresResource })
|
|
17
|
+
*
|
|
18
|
+
* // New usage:
|
|
19
|
+
* new SstEnvironmentBuilder({ database: postgresResource }).build()
|
|
112
20
|
*/
|
|
113
21
|
function normalizeResourceEnv(record) {
|
|
114
|
-
|
|
115
|
-
for (const [k, value] of Object.entries(record)) {
|
|
116
|
-
if (typeof value === "string") {
|
|
117
|
-
env[environmentCase(k)] = value;
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
const processor = processors[value.type];
|
|
121
|
-
if (processor) Object.assign(env, processor(k, value));
|
|
122
|
-
else console.warn(`No processor found for resource type: `, { value });
|
|
123
|
-
}
|
|
124
|
-
return env;
|
|
22
|
+
return new SstEnvironmentBuilder(record).build();
|
|
125
23
|
}
|
|
126
24
|
|
|
127
25
|
//#endregion
|
|
128
|
-
export { ResourceType, environmentCase, normalizeResourceEnv };
|
|
26
|
+
export { ResourceType, SstEnvironmentBuilder, environmentCase, normalizeResourceEnv, sstResolvers };
|
|
129
27
|
//# sourceMappingURL=sst.mjs.map
|