@@ -16,7 +16,14 @@ import { ServiceConfigurationOptions } from 'aws-sdk/lib/service'
16
16
import { CancellationError , Timeout , waitTimeout , waitUntil } from '../utilities/timeoutUtils'
17
17
import { isUserCancelledError } from '../../shared/errors'
18
18
import { showMessageWithCancel } from '../utilities/messages'
19
- import { assertHasProps , ClassToInterfaceType , hasProps , isNonNullable , RequiredProps } from '../utilities/tsUtils'
19
+ import {
20
+ assertHasProps ,
21
+ ClassToInterfaceType ,
22
+ hasProps ,
23
+ isDefined ,
24
+ isNonNullable ,
25
+ RequiredProps ,
26
+ } from '../utilities/tsUtils'
20
27
import { AsyncCollection , toCollection } from '../utilities/asyncCollection'
21
28
import { joinAll , pageableToCollection } from '../utilities/collectionUtils'
22
29
import { CodeCatalyst } from 'aws-sdk'
@@ -33,6 +40,7 @@ import {
33
40
CreateAccessTokenCommand ,
34
41
CreateAccessTokenRequest ,
35
42
CreateAccessTokenResponse ,
43
+ DevEnvironmentRepositorySummary ,
36
44
DevEnvironmentSummary ,
37
45
GetDevEnvironmentCommand ,
38
46
GetDevEnvironmentRequest ,
@@ -49,7 +57,6 @@ import {
49
57
GetUserDetailsCommandOutput ,
50
58
GetUserDetailsRequest ,
51
59
ListDevEnvironmentsCommand ,
52
- ListDevEnvironmentSessionsResponse ,
53
60
ListDevEnvironmentsRequest ,
54
61
ListDevEnvironmentsResponse ,
55
62
ListProjectsCommand ,
@@ -58,6 +65,8 @@ import {
58
65
ListSpacesCommand ,
59
66
ListSpacesRequest ,
60
67
ListSpacesResponse ,
68
+ PersistentStorage ,
69
+ ProjectSummary ,
61
70
SpaceSummary ,
62
71
} from '@aws-sdk/client-codecatalyst'
63
72
import { truncateProps } from '../utilities/textUtilities'
@@ -68,6 +77,16 @@ import { AwsCommand } from '../awsClientBuilderV3'
68
77
import { ClientWrapper } from './clientWrapper'
69
78
import { StandardRetryStrategy } from '@smithy/util-retry'
70
79
80
+ const requiredDevEnvProps = [
81
+ 'id' ,
82
+ 'status' ,
83
+ 'inactivityTimeoutMinutes' ,
84
+ 'repositories' ,
85
+ 'instanceType' ,
86
+ 'lastUpdatedTime' ,
87
+ ] as const
88
+ type RequiredDevEnvProps = ( typeof requiredDevEnvProps ) [ number ]
89
+
71
90
export interface CodeCatalystConfig {
72
91
readonly region : string
73
92
readonly endpoint : string
@@ -91,11 +110,17 @@ export function getCodeCatalystConfig(): CodeCatalystConfig {
91
110
}
92
111
}
93
112
94
- export interface DevEnvironment extends DevEnvironmentSummary {
113
+ interface CodeCatalystDevEnvironmentSummary extends RequiredProps < DevEnvironmentSummary , RequiredDevEnvProps > {
114
+ readonly persistentStorage : RequiredProps < PersistentStorage , 'sizeInGiB' >
115
+ readonly repositories : RequiredProps < DevEnvironmentRepositorySummary , 'repositoryName' > [ ]
116
+ }
117
+
118
+ export interface DevEnvironment extends CodeCatalystDevEnvironmentSummary {
95
119
readonly type : 'devEnvironment'
96
120
readonly id : string
97
121
readonly org : Pick < CodeCatalystOrg , 'name' >
98
122
readonly project : Pick < CodeCatalystProject , 'name' >
123
+ readonly repositories : RequiredProps < DevEnvironmentRepositorySummary , 'repositoryName' > [ ]
99
124
}
100
125
101
126
/** CodeCatalyst developer environment session. */
@@ -138,8 +163,8 @@ export type CodeCatalystResource =
138
163
function toDevEnv (
139
164
spaceName : string ,
140
165
projectName : string ,
141
- summary : RequiredProps < DevEnvironmentSummary , 'id' | 'status' >
142
- ) : RequiredProps < DevEnvironment , 'status' > {
166
+ summary : CodeCatalystDevEnvironmentSummary
167
+ ) : RequiredProps < DevEnvironment , RequiredDevEnvProps > {
143
168
return {
144
169
type : 'devEnvironment' ,
145
170
org : { name : spaceName } ,
@@ -525,11 +550,15 @@ class CodeCatalystClientInternal extends ClientWrapper<CodeCatalystSDKClient> {
525
550
public listSpaces ( request : ListSpacesRequest = { } ) : AsyncCollection < CodeCatalystOrg [ ] > {
526
551
const requester : ( request : ListSpacesRequest ) => Promise < ListSpacesResponse > = async ( request ) =>
527
552
this . callV3 ( ListSpacesCommand , request , true , { items : [ ] } )
528
- const collection = pageableToCollection ( requester , request , 'nextToken' , 'items' ) . filter (
529
- ( summaries ) => summaries !== undefined
530
- )
553
+ const collection = pageableToCollection ( requester , request , 'nextToken' , 'items' ) . filter ( isDefined )
554
+ // ts doesn't recognize nested assertion, so we add cast.This is safe because we assert it in the same line.
531
555
return collection . map ( ( summaries ) =>
532
- summaries . filter ( ( s ) => hasProps ( s , 'name' ) ) . map ( ( s ) => ( { type : 'org' , ...s } ) )
556
+ ( summaries . filter ( ( s ) => hasProps ( s , 'name' ) ) as Readonly < RequiredProps < SpaceSummary , 'name' > > [ ] ) . map (
557
+ ( s ) => ( {
558
+ type : 'org' ,
559
+ ...s ,
560
+ } )
561
+ )
533
562
)
534
563
}
535
564
@@ -551,34 +580,36 @@ class CodeCatalystClientInternal extends ClientWrapper<CodeCatalystSDKClient> {
551
580
const requester : ( request : ListProjectsRequest ) => Promise < ListProjectsResponse > = ( request ) =>
552
581
this . callV3 ( ListProjectsCommand , request , true , { items : [ ] } )
553
582
554
- const collection = pageableToCollection ( requester , request , 'nextToken' , 'items' ) . filter (
555
- ( summaries ) => summaries !== undefined
556
- )
557
-
583
+ const collection = pageableToCollection ( requester , request , 'nextToken' , 'items' ) . filter ( isDefined )
584
+ // ts doesn't recognize nested assertion, so we add cast. This is safe because we assert it in the same line.
558
585
return collection . map ( ( summaries ) =>
559
- summaries
560
- . filter ( ( s ) => hasProps ( s , 'name' ) )
561
- . map ( ( s ) => ( {
586
+ ( summaries . filter ( ( s ) => hasProps ( s , 'name' ) ) as Readonly < RequiredProps < ProjectSummary , 'name' > > [ ] ) . map (
587
+ ( s ) => ( {
562
588
type : 'project' ,
563
589
org : { name : request . spaceName } ,
564
590
...s ,
565
- } ) )
591
+ } )
592
+ )
566
593
)
567
594
}
568
595
569
596
/**
570
597
* Gets a flat list of all devenvs for the given CodeCatalyst project.
571
598
*/
572
- public listDevEnvironments ( proj : CodeCatalystProject ) : AsyncCollection < DevEnvironment [ ] > {
599
+ public listDevEnvironments (
600
+ proj : CodeCatalystProject
601
+ ) : AsyncCollection < RequiredProps < DevEnvironment , RequiredDevEnvProps > [ ] > {
573
602
const initRequest = { spaceName : proj . org . name , projectName : proj . name }
574
603
const requester : ( request : ListDevEnvironmentsRequest ) => Promise < ListDevEnvironmentsResponse > = ( request ) =>
575
604
this . callV3 ( ListDevEnvironmentsCommand , request , true , { items : [ ] } )
576
- const collection = pageableToCollection ( requester , initRequest , 'nextToken' , 'items' ) . filter (
577
- ( c ) => c !== undefined
578
- )
579
-
605
+ const collection = pageableToCollection ( requester , initRequest , 'nextToken' as never , 'items' ) . filter ( isDefined )
606
+ // ts unable to recognize nested assertion here, so we need to cast. This is safe because we assert it in the same line.
580
607
return collection . map ( ( envs ) =>
581
- envs . filter ( ( s ) => hasProps ( s , 'id' , 'status' ) ) . map ( ( s ) => toDevEnv ( proj . org . name , proj . name , s ) )
608
+ (
609
+ envs . filter (
610
+ ( s ) => hasProps ( s , ...requiredDevEnvProps ) && hasPersistentStorage ( s ) && hasRepositories ( s )
611
+ ) as CodeCatalystDevEnvironmentSummary [ ]
612
+ ) . map ( ( s ) => toDevEnv ( proj . org . name , proj . name , s ) )
582
613
)
583
614
}
584
615
@@ -730,14 +761,16 @@ class CodeCatalystClientInternal extends ClientWrapper<CodeCatalystSDKClient> {
730
761
731
762
public async getDevEnvironment (
732
763
args : RequiredProps < GetDevEnvironmentRequest , 'spaceName' | 'projectName' >
733
- ) : Promise < RequiredProps < DevEnvironment , 'status' > > {
764
+ ) : Promise < RequiredProps < DevEnvironment , RequiredDevEnvProps > > {
734
765
const a = { ...args }
735
766
delete ( a as any ) . ides
736
767
delete ( a as any ) . repositories
737
768
738
769
const r : GetDevEnvironmentResponse = await this . callV3 ( GetDevEnvironmentCommand , a , false )
739
770
const summary = { ...args , ...r }
740
- assertHasProps ( summary , 'id' , 'status' )
771
+ if ( ! hasProps ( summary , ...requiredDevEnvProps ) || ! hasPersistentStorage ( summary ) || ! hasRepositories ( summary ) ) {
772
+ throw new ToolkitError ( `GetDevEnvironment failed due to response missing required properties` )
773
+ }
741
774
742
775
return toDevEnv ( args . spaceName , args . projectName , summary )
743
776
}
@@ -974,3 +1007,15 @@ export async function isThirdPartyRepo(
974
1007
! Uri . parse ( url ) . authority . endsWith ( 'caws.dev-tools.aws.dev' )
975
1008
)
976
1009
}
1010
+
1011
+ function hasPersistentStorage < T extends DevEnvironmentSummary > (
1012
+ s : T
1013
+ ) : s is T & { persistentStorage : { sizeInGiB : number } } {
1014
+ return hasProps ( s , 'persistentStorage' ) && hasProps ( s . persistentStorage , 'sizeInGiB' )
1015
+ }
1016
+
1017
+ function hasRepositories < T extends DevEnvironmentSummary > (
1018
+ s : T
1019
+ ) : s is T & { repositories : RequiredProps < DevEnvironmentRepositorySummary , 'repositoryName' > [ ] } {
1020
+ return hasProps ( s , 'repositories' ) && s . repositories . every ( ( r ) => hasProps ( r , 'repositoryName' ) )
1021
+ }
0 commit comments