@geekmidas/envkit 0.0.4 → 0.0.6
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/dist/{EnvironmentParser-Bo2CCl_K.cjs → EnvironmentParser-BDPDLv6i.cjs} +7 -7
- package/dist/EnvironmentParser-C-arQEHQ.d.mts +108 -0
- package/dist/{EnvironmentParser-jKrGMBhP.mjs → EnvironmentParser-CQUOGqc0.mjs} +7 -7
- package/dist/EnvironmentParser-X4h2Vp4r.d.cts +108 -0
- package/dist/EnvironmentParser.cjs +1 -1
- package/dist/EnvironmentParser.d.cts +2 -0
- package/dist/EnvironmentParser.d.mts +2 -0
- package/dist/EnvironmentParser.mjs +1 -1
- package/dist/__tests__/ConfigParser.spec.cjs +1 -1
- package/dist/__tests__/ConfigParser.spec.d.cts +1 -0
- package/dist/__tests__/ConfigParser.spec.d.mts +1 -0
- package/dist/__tests__/ConfigParser.spec.mjs +1 -1
- package/dist/__tests__/EnvironmentParser.spec.cjs +1 -1
- package/dist/__tests__/EnvironmentParser.spec.d.cts +1 -0
- package/dist/__tests__/EnvironmentParser.spec.d.mts +1 -0
- package/dist/__tests__/EnvironmentParser.spec.mjs +1 -1
- package/dist/__tests__/sst.spec.cjs +305 -0
- package/dist/__tests__/sst.spec.d.cts +1 -0
- package/dist/__tests__/sst.spec.d.mts +1 -0
- package/dist/__tests__/sst.spec.mjs +304 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +1 -1
- package/dist/sst-BSxwaAdz.cjs +146 -0
- package/dist/sst-CQhO0S6y.mjs +128 -0
- package/dist/sst.cjs +4 -130
- package/dist/sst.d.cts +107 -0
- package/dist/sst.d.mts +107 -0
- package/dist/sst.mjs +1 -126
- package/package.json +5 -5
- package/src/EnvironmentParser.ts +10 -10
- package/src/__tests__/sst.spec.ts +415 -0
- package/src/sst.ts +9 -9
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const lodash_snakecase = require_chunk.__toESM(require("lodash.snakecase"));
|
|
3
|
+
|
|
4
|
+
//#region src/sst.ts
|
|
5
|
+
/**
|
|
6
|
+
* Converts a string to environment variable case format (UPPER_SNAKE_CASE).
|
|
7
|
+
* Numbers following underscores are preserved without the underscore.
|
|
8
|
+
*
|
|
9
|
+
* @param name - The string to convert
|
|
10
|
+
* @returns The converted string in environment variable format
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* environmentCase('myVariable') // 'MY_VARIABLE'
|
|
14
|
+
* environmentCase('api_v2') // 'APIV2'
|
|
15
|
+
*/
|
|
16
|
+
function environmentCase(name) {
|
|
17
|
+
return (0, lodash_snakecase.default)(name).toUpperCase().replace(/_\d+/g, (r) => {
|
|
18
|
+
return r.replace("_", "");
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Enumeration of supported SST (Serverless Stack Toolkit) resource types.
|
|
23
|
+
* Used to identify and process different AWS and SST resources.
|
|
24
|
+
*/
|
|
25
|
+
let ResourceType = /* @__PURE__ */ function(ResourceType$1) {
|
|
26
|
+
ResourceType$1["ApiGatewayV2"] = "sst.aws.ApiGatewayV2";
|
|
27
|
+
ResourceType$1["Postgres"] = "sst.aws.Postgres";
|
|
28
|
+
ResourceType$1["Function"] = "sst.aws.Function";
|
|
29
|
+
ResourceType$1["Bucket"] = "sst.aws.Bucket";
|
|
30
|
+
ResourceType$1["Vpc"] = "sst.aws.Vpc";
|
|
31
|
+
ResourceType$1["Secret"] = "sst.sst.Secret";
|
|
32
|
+
ResourceType$1["SSTSecret"] = "sst:sst:Secret";
|
|
33
|
+
ResourceType$1["SSTFunction"] = "sst:sst:Function";
|
|
34
|
+
ResourceType$1["SSTApiGatewayV2"] = "sst:aws:ApiGatewayV2";
|
|
35
|
+
ResourceType$1["SSTPostgres"] = "sst:aws:Postgres";
|
|
36
|
+
ResourceType$1["SSTBucket"] = "sst:aws:Bucket";
|
|
37
|
+
return ResourceType$1;
|
|
38
|
+
}({});
|
|
39
|
+
/**
|
|
40
|
+
* Processes a Secret resource into environment variables.
|
|
41
|
+
*
|
|
42
|
+
* @param name - The resource name
|
|
43
|
+
* @param value - The Secret resource
|
|
44
|
+
* @returns Object with environment variable mappings
|
|
45
|
+
*/
|
|
46
|
+
const secret = (name, value) => ({ [environmentCase(name)]: value.value });
|
|
47
|
+
/**
|
|
48
|
+
* Processes a Postgres database resource into environment variables.
|
|
49
|
+
* Creates multiple environment variables for database connection details.
|
|
50
|
+
*
|
|
51
|
+
* @param key - The resource key
|
|
52
|
+
* @param value - The Postgres resource
|
|
53
|
+
* @returns Object with database connection environment variables
|
|
54
|
+
*/
|
|
55
|
+
const postgres = (key, value) => {
|
|
56
|
+
const prefix = `${environmentCase(key)}`;
|
|
57
|
+
return {
|
|
58
|
+
[`${prefix}_NAME`]: value.database,
|
|
59
|
+
[`${prefix}_HOST`]: value.host,
|
|
60
|
+
[`${prefix}_PASSWORD`]: value.password,
|
|
61
|
+
[`${prefix}_PORT`]: value.port,
|
|
62
|
+
[`${prefix}_USERNAME`]: value.username
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Processes a Bucket resource into environment variables.
|
|
67
|
+
*
|
|
68
|
+
* @param name - The resource name
|
|
69
|
+
* @param value - The Bucket resource
|
|
70
|
+
* @returns Object with bucket name environment variable
|
|
71
|
+
*/
|
|
72
|
+
const bucket = (name, value) => {
|
|
73
|
+
const prefix = `${environmentCase(name)}`;
|
|
74
|
+
return { [`${prefix}_NAME`]: value.name };
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* No-operation processor for resources that don't require environment variables.
|
|
78
|
+
*
|
|
79
|
+
* @param name - The resource name (unused)
|
|
80
|
+
* @param value - The resource value (unused)
|
|
81
|
+
* @returns Empty object
|
|
82
|
+
*/
|
|
83
|
+
const noop = (name, value) => ({});
|
|
84
|
+
/**
|
|
85
|
+
* Map of resource types to their corresponding processor functions.
|
|
86
|
+
* Each processor converts resource data into environment variables.
|
|
87
|
+
*/
|
|
88
|
+
const processors = {
|
|
89
|
+
[ResourceType.ApiGatewayV2]: noop,
|
|
90
|
+
[ResourceType.Function]: noop,
|
|
91
|
+
[ResourceType.Vpc]: noop,
|
|
92
|
+
[ResourceType.Secret]: secret,
|
|
93
|
+
[ResourceType.Postgres]: postgres,
|
|
94
|
+
[ResourceType.Bucket]: bucket,
|
|
95
|
+
[ResourceType.SSTSecret]: secret,
|
|
96
|
+
[ResourceType.SSTBucket]: bucket,
|
|
97
|
+
[ResourceType.SSTFunction]: noop,
|
|
98
|
+
[ResourceType.SSTPostgres]: postgres,
|
|
99
|
+
[ResourceType.SSTApiGatewayV2]: noop
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Normalizes SST resources and plain strings into environment variables.
|
|
103
|
+
* Processes resources based on their type and converts names to environment case.
|
|
104
|
+
*
|
|
105
|
+
* @param record - Object containing resources and/or string values
|
|
106
|
+
* @returns Normalized environment variables object
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* normalizeResourceEnv({
|
|
110
|
+
* apiUrl: 'https://api.example.com',
|
|
111
|
+
* database: { type: ResourceType.Postgres, ... }
|
|
112
|
+
* })
|
|
113
|
+
*/
|
|
114
|
+
function normalizeResourceEnv(record) {
|
|
115
|
+
const env = {};
|
|
116
|
+
for (const [k, value] of Object.entries(record)) {
|
|
117
|
+
if (typeof value === "string") {
|
|
118
|
+
env[environmentCase(k)] = value;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const processor = processors[value.type];
|
|
122
|
+
if (processor) Object.assign(env, processor(k, value));
|
|
123
|
+
else console.warn(`No processor found for resource type: `, { value });
|
|
124
|
+
}
|
|
125
|
+
return env;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
//#endregion
|
|
129
|
+
Object.defineProperty(exports, 'ResourceType', {
|
|
130
|
+
enumerable: true,
|
|
131
|
+
get: function () {
|
|
132
|
+
return ResourceType;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
Object.defineProperty(exports, 'environmentCase', {
|
|
136
|
+
enumerable: true,
|
|
137
|
+
get: function () {
|
|
138
|
+
return environmentCase;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
Object.defineProperty(exports, 'normalizeResourceEnv', {
|
|
142
|
+
enumerable: true,
|
|
143
|
+
get: function () {
|
|
144
|
+
return normalizeResourceEnv;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import snakecase from "lodash.snakecase";
|
|
2
|
+
|
|
3
|
+
//#region src/sst.ts
|
|
4
|
+
/**
|
|
5
|
+
* Converts a string to environment variable case format (UPPER_SNAKE_CASE).
|
|
6
|
+
* Numbers following underscores are preserved without the underscore.
|
|
7
|
+
*
|
|
8
|
+
* @param name - The string to convert
|
|
9
|
+
* @returns The converted string in environment variable format
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* environmentCase('myVariable') // 'MY_VARIABLE'
|
|
13
|
+
* environmentCase('api_v2') // 'APIV2'
|
|
14
|
+
*/
|
|
15
|
+
function environmentCase(name) {
|
|
16
|
+
return snakecase(name).toUpperCase().replace(/_\d+/g, (r) => {
|
|
17
|
+
return r.replace("_", "");
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Enumeration of supported SST (Serverless Stack Toolkit) resource types.
|
|
22
|
+
* Used to identify and process different AWS and SST resources.
|
|
23
|
+
*/
|
|
24
|
+
let ResourceType = /* @__PURE__ */ function(ResourceType$1) {
|
|
25
|
+
ResourceType$1["ApiGatewayV2"] = "sst.aws.ApiGatewayV2";
|
|
26
|
+
ResourceType$1["Postgres"] = "sst.aws.Postgres";
|
|
27
|
+
ResourceType$1["Function"] = "sst.aws.Function";
|
|
28
|
+
ResourceType$1["Bucket"] = "sst.aws.Bucket";
|
|
29
|
+
ResourceType$1["Vpc"] = "sst.aws.Vpc";
|
|
30
|
+
ResourceType$1["Secret"] = "sst.sst.Secret";
|
|
31
|
+
ResourceType$1["SSTSecret"] = "sst:sst:Secret";
|
|
32
|
+
ResourceType$1["SSTFunction"] = "sst:sst:Function";
|
|
33
|
+
ResourceType$1["SSTApiGatewayV2"] = "sst:aws:ApiGatewayV2";
|
|
34
|
+
ResourceType$1["SSTPostgres"] = "sst:aws:Postgres";
|
|
35
|
+
ResourceType$1["SSTBucket"] = "sst:aws:Bucket";
|
|
36
|
+
return ResourceType$1;
|
|
37
|
+
}({});
|
|
38
|
+
/**
|
|
39
|
+
* Processes a Secret resource into environment variables.
|
|
40
|
+
*
|
|
41
|
+
* @param name - The resource name
|
|
42
|
+
* @param value - The Secret resource
|
|
43
|
+
* @returns Object with environment variable mappings
|
|
44
|
+
*/
|
|
45
|
+
const secret = (name, value) => ({ [environmentCase(name)]: value.value });
|
|
46
|
+
/**
|
|
47
|
+
* Processes a Postgres database resource into environment variables.
|
|
48
|
+
* Creates multiple environment variables for database connection details.
|
|
49
|
+
*
|
|
50
|
+
* @param key - The resource key
|
|
51
|
+
* @param value - The Postgres resource
|
|
52
|
+
* @returns Object with database connection environment variables
|
|
53
|
+
*/
|
|
54
|
+
const postgres = (key, value) => {
|
|
55
|
+
const prefix = `${environmentCase(key)}`;
|
|
56
|
+
return {
|
|
57
|
+
[`${prefix}_NAME`]: value.database,
|
|
58
|
+
[`${prefix}_HOST`]: value.host,
|
|
59
|
+
[`${prefix}_PASSWORD`]: value.password,
|
|
60
|
+
[`${prefix}_PORT`]: value.port,
|
|
61
|
+
[`${prefix}_USERNAME`]: value.username
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Processes a Bucket resource into environment variables.
|
|
66
|
+
*
|
|
67
|
+
* @param name - The resource name
|
|
68
|
+
* @param value - The Bucket resource
|
|
69
|
+
* @returns Object with bucket name environment variable
|
|
70
|
+
*/
|
|
71
|
+
const bucket = (name, value) => {
|
|
72
|
+
const prefix = `${environmentCase(name)}`;
|
|
73
|
+
return { [`${prefix}_NAME`]: value.name };
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* No-operation processor for resources that don't require environment variables.
|
|
77
|
+
*
|
|
78
|
+
* @param name - The resource name (unused)
|
|
79
|
+
* @param value - The resource value (unused)
|
|
80
|
+
* @returns Empty object
|
|
81
|
+
*/
|
|
82
|
+
const noop = (name, value) => ({});
|
|
83
|
+
/**
|
|
84
|
+
* Map of resource types to their corresponding processor functions.
|
|
85
|
+
* Each processor converts resource data into environment variables.
|
|
86
|
+
*/
|
|
87
|
+
const processors = {
|
|
88
|
+
[ResourceType.ApiGatewayV2]: noop,
|
|
89
|
+
[ResourceType.Function]: noop,
|
|
90
|
+
[ResourceType.Vpc]: noop,
|
|
91
|
+
[ResourceType.Secret]: secret,
|
|
92
|
+
[ResourceType.Postgres]: postgres,
|
|
93
|
+
[ResourceType.Bucket]: bucket,
|
|
94
|
+
[ResourceType.SSTSecret]: secret,
|
|
95
|
+
[ResourceType.SSTBucket]: bucket,
|
|
96
|
+
[ResourceType.SSTFunction]: noop,
|
|
97
|
+
[ResourceType.SSTPostgres]: postgres,
|
|
98
|
+
[ResourceType.SSTApiGatewayV2]: noop
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Normalizes SST resources and plain strings into environment variables.
|
|
102
|
+
* Processes resources based on their type and converts names to environment case.
|
|
103
|
+
*
|
|
104
|
+
* @param record - Object containing resources and/or string values
|
|
105
|
+
* @returns Normalized environment variables object
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* normalizeResourceEnv({
|
|
109
|
+
* apiUrl: 'https://api.example.com',
|
|
110
|
+
* database: { type: ResourceType.Postgres, ... }
|
|
111
|
+
* })
|
|
112
|
+
*/
|
|
113
|
+
function normalizeResourceEnv(record) {
|
|
114
|
+
const env = {};
|
|
115
|
+
for (const [k, value] of Object.entries(record)) {
|
|
116
|
+
if (typeof value === "string") {
|
|
117
|
+
env[environmentCase(k)] = value;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const processor = processors[value.type];
|
|
121
|
+
if (processor) Object.assign(env, processor(k, value));
|
|
122
|
+
else console.warn(`No processor found for resource type: `, { value });
|
|
123
|
+
}
|
|
124
|
+
return env;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
//#endregion
|
|
128
|
+
export { ResourceType, environmentCase, normalizeResourceEnv };
|
package/dist/sst.cjs
CHANGED
|
@@ -1,131 +1,5 @@
|
|
|
1
|
-
const
|
|
2
|
-
const lodash_snakecase = require_chunk.__toESM(require("lodash.snakecase"));
|
|
1
|
+
const require_sst = require('./sst-BSxwaAdz.cjs');
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* Numbers following underscores are preserved without the underscore.
|
|
8
|
-
*
|
|
9
|
-
* @param name - The string to convert
|
|
10
|
-
* @returns The converted string in environment variable format
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* environmentCase('myVariable') // 'MY_VARIABLE'
|
|
14
|
-
* environmentCase('api_v2') // 'APIV2'
|
|
15
|
-
*/
|
|
16
|
-
function environmentCase(name) {
|
|
17
|
-
return (0, lodash_snakecase.default)(name).toUpperCase().replace(/_\d+/g, (r) => {
|
|
18
|
-
return r.replace("_", "");
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Enumeration of supported SST (Serverless Stack Toolkit) resource types.
|
|
23
|
-
* Used to identify and process different AWS and SST resources.
|
|
24
|
-
*/
|
|
25
|
-
let ResourceType = /* @__PURE__ */ function(ResourceType$1) {
|
|
26
|
-
ResourceType$1["ApiGatewayV2"] = "sst.aws.ApiGatewayV2";
|
|
27
|
-
ResourceType$1["Postgres"] = "sst.aws.Postgres";
|
|
28
|
-
ResourceType$1["Function"] = "sst.aws.Function";
|
|
29
|
-
ResourceType$1["Bucket"] = "sst.aws.Bucket";
|
|
30
|
-
ResourceType$1["Vpc"] = "sst.aws.Vpc";
|
|
31
|
-
ResourceType$1["Secret"] = "sst.sst.Secret";
|
|
32
|
-
ResourceType$1["SSTSecret"] = "sst:sst:Secret";
|
|
33
|
-
ResourceType$1["SSTFunction"] = "sst:sst:Function";
|
|
34
|
-
ResourceType$1["SSTApiGatewayV2"] = "sst:aws:ApiGatewayV2";
|
|
35
|
-
ResourceType$1["SSTPostgres"] = "sst:aws:Postgres";
|
|
36
|
-
ResourceType$1["SSTBucket"] = "sst:aws:Bucket";
|
|
37
|
-
return ResourceType$1;
|
|
38
|
-
}({});
|
|
39
|
-
/**
|
|
40
|
-
* Processes a Secret resource into environment variables.
|
|
41
|
-
*
|
|
42
|
-
* @param name - The resource name
|
|
43
|
-
* @param value - The Secret resource
|
|
44
|
-
* @returns Object with environment variable mappings
|
|
45
|
-
*/
|
|
46
|
-
const secret = (name, value) => ({ [environmentCase(name)]: value.value });
|
|
47
|
-
/**
|
|
48
|
-
* Processes a Postgres database resource into environment variables.
|
|
49
|
-
* Creates multiple environment variables for database connection details.
|
|
50
|
-
*
|
|
51
|
-
* @param key - The resource key
|
|
52
|
-
* @param value - The Postgres resource
|
|
53
|
-
* @returns Object with database connection environment variables
|
|
54
|
-
*/
|
|
55
|
-
const postgres = (key, value) => {
|
|
56
|
-
const prefix = `${environmentCase(key)}`;
|
|
57
|
-
return {
|
|
58
|
-
[`${prefix}_NAME`]: value.database,
|
|
59
|
-
[`${prefix}_HOST`]: value.host,
|
|
60
|
-
[`${prefix}_PASSWORD`]: value.password,
|
|
61
|
-
[`${prefix}_PORT`]: value.port,
|
|
62
|
-
[`${prefix}_USERNAME`]: value.username
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* Processes a Bucket resource into environment variables.
|
|
67
|
-
*
|
|
68
|
-
* @param name - The resource name
|
|
69
|
-
* @param value - The Bucket resource
|
|
70
|
-
* @returns Object with bucket name environment variable
|
|
71
|
-
*/
|
|
72
|
-
const bucket = (name, value) => {
|
|
73
|
-
const prefix = `${environmentCase(name)}`;
|
|
74
|
-
return { [`${prefix}_NAME`]: value.name };
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* No-operation processor for resources that don't require environment variables.
|
|
78
|
-
*
|
|
79
|
-
* @param name - The resource name (unused)
|
|
80
|
-
* @param value - The resource value (unused)
|
|
81
|
-
* @returns Empty object
|
|
82
|
-
*/
|
|
83
|
-
const noop = (name, value) => ({});
|
|
84
|
-
/**
|
|
85
|
-
* Map of resource types to their corresponding processor functions.
|
|
86
|
-
* Each processor converts resource data into environment variables.
|
|
87
|
-
*/
|
|
88
|
-
const processors = {
|
|
89
|
-
[ResourceType.ApiGatewayV2]: noop,
|
|
90
|
-
[ResourceType.Function]: noop,
|
|
91
|
-
[ResourceType.Vpc]: noop,
|
|
92
|
-
[ResourceType.Secret]: secret,
|
|
93
|
-
[ResourceType.Postgres]: postgres,
|
|
94
|
-
[ResourceType.Bucket]: bucket,
|
|
95
|
-
[ResourceType.SSTSecret]: secret,
|
|
96
|
-
[ResourceType.SSTBucket]: bucket,
|
|
97
|
-
[ResourceType.SSTFunction]: noop,
|
|
98
|
-
[ResourceType.SSTPostgres]: postgres,
|
|
99
|
-
[ResourceType.SSTApiGatewayV2]: noop
|
|
100
|
-
};
|
|
101
|
-
/**
|
|
102
|
-
* Normalizes SST resources and plain strings into environment variables.
|
|
103
|
-
* Processes resources based on their type and converts names to environment case.
|
|
104
|
-
*
|
|
105
|
-
* @param record - Object containing resources and/or string values
|
|
106
|
-
* @returns Normalized environment variables object
|
|
107
|
-
*
|
|
108
|
-
* @example
|
|
109
|
-
* normalizeResourceEnv({
|
|
110
|
-
* apiUrl: 'https://api.example.com',
|
|
111
|
-
* database: { type: ResourceType.Postgres, ... }
|
|
112
|
-
* })
|
|
113
|
-
*/
|
|
114
|
-
function normalizeResourceEnv(record) {
|
|
115
|
-
const env = {};
|
|
116
|
-
for (const [k, value] of Object.entries(record)) {
|
|
117
|
-
if (typeof value === "string") {
|
|
118
|
-
env[environmentCase(k)] = value;
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
const processor = processors[value.type];
|
|
122
|
-
if (processor) Object.assign(env, processor(k, value));
|
|
123
|
-
else console.warn(`No processor found for resource type: `, { value });
|
|
124
|
-
}
|
|
125
|
-
return env;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
//#endregion
|
|
129
|
-
exports.ResourceType = ResourceType;
|
|
130
|
-
exports.environmentCase = environmentCase;
|
|
131
|
-
exports.normalizeResourceEnv = normalizeResourceEnv;
|
|
3
|
+
exports.ResourceType = require_sst.ResourceType;
|
|
4
|
+
exports.environmentCase = require_sst.environmentCase;
|
|
5
|
+
exports.normalizeResourceEnv = require_sst.normalizeResourceEnv;
|
package/dist/sst.d.cts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
//#region src/sst.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Converts a string to environment variable case format (UPPER_SNAKE_CASE).
|
|
4
|
+
* Numbers following underscores are preserved without the underscore.
|
|
5
|
+
*
|
|
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
|
+
* Normalizes SST resources and plain strings into environment variables.
|
|
33
|
+
* Processes resources based on their type and converts names to environment case.
|
|
34
|
+
*
|
|
35
|
+
* @param record - Object containing resources and/or string values
|
|
36
|
+
* @returns Normalized environment variables object
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* normalizeResourceEnv({
|
|
40
|
+
* apiUrl: 'https://api.example.com',
|
|
41
|
+
* database: { type: ResourceType.Postgres, ... }
|
|
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.
|
|
95
|
+
*/
|
|
96
|
+
type Resource = ApiGatewayV2 | Postgres | Function | Bucket | Vpc | Secret;
|
|
97
|
+
/**
|
|
98
|
+
* Function type for processing a specific resource type into environment variables.
|
|
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
|
|
104
|
+
*/
|
|
105
|
+
type ResourceProcessor<K extends Resource> = (name: string, value: K) => Record<string, string | number>;
|
|
106
|
+
//#endregion
|
|
107
|
+
export { ApiGatewayV2, Bucket, Function, Postgres, Resource, ResourceProcessor, ResourceType, Secret, Vpc, environmentCase, normalizeResourceEnv };
|
package/dist/sst.d.mts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
//#region src/sst.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Converts a string to environment variable case format (UPPER_SNAKE_CASE).
|
|
4
|
+
* Numbers following underscores are preserved without the underscore.
|
|
5
|
+
*
|
|
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
|
+
* Normalizes SST resources and plain strings into environment variables.
|
|
33
|
+
* Processes resources based on their type and converts names to environment case.
|
|
34
|
+
*
|
|
35
|
+
* @param record - Object containing resources and/or string values
|
|
36
|
+
* @returns Normalized environment variables object
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* normalizeResourceEnv({
|
|
40
|
+
* apiUrl: 'https://api.example.com',
|
|
41
|
+
* database: { type: ResourceType.Postgres, ... }
|
|
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.
|
|
95
|
+
*/
|
|
96
|
+
type Resource = ApiGatewayV2 | Postgres | Function | Bucket | Vpc | Secret;
|
|
97
|
+
/**
|
|
98
|
+
* Function type for processing a specific resource type into environment variables.
|
|
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
|
|
104
|
+
*/
|
|
105
|
+
type ResourceProcessor<K extends Resource> = (name: string, value: K) => Record<string, string | number>;
|
|
106
|
+
//#endregion
|
|
107
|
+
export { ApiGatewayV2, Bucket, Function, Postgres, Resource, ResourceProcessor, ResourceType, Secret, Vpc, environmentCase, normalizeResourceEnv };
|