@@ -11,10 +11,19 @@ type ServiceEnvCommand = {
1111 environmentValueSources ?: Record < string , GatewayServiceEnvironmentValueSource | undefined > ;
1212} | null ;
1313
14- function normalizeServiceEnvKey ( key : string ) : string | null {
14+ export function normalizeServiceEnvKey ( key : string ) : string | null {
1515 return normalizeEnvVarKey ( key , { portable : true } ) ?. toUpperCase ( ) ?? null ;
1616}
1717
18+ export function normalizeServiceEnvKeys ( keys : Iterable < string > ) : Set < string > {
19+ return new Set (
20+ [ ...keys ] . flatMap ( ( key ) => {
21+ const normalized = normalizeServiceEnvKey ( key ) ;
22+ return normalized ? [ normalized ] : [ ] ;
23+ } ) ,
24+ ) ;
25+ }
26+
1827export function hasInlineEnvironmentSource (
1928 source : GatewayServiceEnvironmentValueSource | undefined ,
2029) : boolean {
@@ -34,34 +43,17 @@ export function hasEnvironmentFileSource(
3443}
3544
3645function parseManagedServiceEnvKeys ( value : string | undefined ) : Set < string > {
37- const keys = new Set < string > ( ) ;
38- for ( const entry of value ?. split ( "," ) ?? [ ] ) {
39- const key = normalizeServiceEnvKey ( entry . trim ( ) ) ;
40- if ( key ) {
41- keys . add ( key ) ;
42- }
43- }
44- return keys ;
46+ return normalizeServiceEnvKeys ( value ?. split ( "," ) ?? [ ] ) ;
4547}
4648
4749export function formatManagedServiceEnvKeys (
4850 managedEnvironment : Record < string , string | undefined > ,
4951 options ?: { omitKeys ?: Iterable < string > } ,
5052) : string | undefined {
51- const omitKeys = new Set (
52- [ ...( options ?. omitKeys ?? [ ] ) ] . flatMap ( ( key ) => {
53- const normalized = normalizeServiceEnvKey ( key ) ;
54- return normalized ? [ normalized ] : [ ] ;
55- } ) ,
56- ) ;
53+ const omitKeys = normalizeServiceEnvKeys ( options ?. omitKeys ?? [ ] ) ;
5754 const keys = Object . keys ( managedEnvironment )
58- . flatMap ( ( key ) => {
59- const normalized = normalizeServiceEnvKey ( key ) ;
60- if ( ! normalized || omitKeys . has ( normalized ) ) {
61- return [ ] ;
62- }
63- return [ normalized ] ;
64- } )
55+ . map ( normalizeServiceEnvKey )
56+ . filter ( ( key ) : key is string => Boolean ( key && ! omitKeys . has ( key ) ) )
6557 . toSorted ( ) ;
6658 return keys . length > 0 ? keys . join ( "," ) : undefined ;
6759}
@@ -84,12 +76,7 @@ function deleteManagedServiceEnvKeys(
8476 environment : Record < string , string | undefined > ,
8577 keys : Iterable < string > ,
8678) : void {
87- const normalizedKeys = new Set (
88- [ ...keys ] . flatMap ( ( key ) => {
89- const normalized = normalizeServiceEnvKey ( key ) ;
90- return normalized ? [ normalized ] : [ ] ;
91- } ) ,
92- ) ;
79+ const normalizedKeys = normalizeServiceEnvKeys ( keys ) ;
9380 if ( normalizedKeys . size === 0 ) {
9481 return ;
9582 }
@@ -140,13 +127,21 @@ export function collectInlineManagedServiceEnvKeys(
140127 return [ ] ;
141128 }
142129 const managedKeys = parseManagedServiceEnvKeys ( command . environment [ MANAGED_SERVICE_ENV_KEYS_VAR ] ) ;
143- for ( const key of expectedManagedKeys ?? [ ] ) {
144- const normalized = normalizeServiceEnvKey ( key ) ;
145- if ( normalized ) {
146- managedKeys . add ( normalized ) ;
147- }
130+ for ( const key of normalizeServiceEnvKeys ( expectedManagedKeys ?? [ ] ) ) {
131+ managedKeys . add ( key ) ;
132+ }
133+ return collectInlineServiceEnvKeys ( command , managedKeys ) ;
134+ }
135+
136+ export function collectInlineServiceEnvKeys (
137+ command : ServiceEnvCommand ,
138+ expectedKeys : Iterable < string > ,
139+ ) : string [ ] {
140+ if ( ! command ?. environment ) {
141+ return [ ] ;
148142 }
149- if ( managedKeys . size === 0 ) {
143+ const normalizedKeys = normalizeServiceEnvKeys ( expectedKeys ) ;
144+ if ( normalizedKeys . size === 0 ) {
150145 return [ ] ;
151146 }
152147 const inlineKeys : string [ ] = [ ] ;
@@ -155,7 +150,7 @@ export function collectInlineManagedServiceEnvKeys(
155150 continue ;
156151 }
157152 const normalized = normalizeServiceEnvKey ( rawKey ) ;
158- if ( ! normalized || ! managedKeys . has ( normalized ) ) {
153+ if ( ! normalized || ! normalizedKeys . has ( normalized ) ) {
159154 continue ;
160155 }
161156 if ( normalized === MANAGED_SERVICE_ENV_KEYS_VAR ) {
0 commit comments