Skip to content

Commit c2b6543

Browse files
committed
refactor: tighten typing constraints
1 parent 8abdea8 commit c2b6543

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

packages/core/src/shared/clients/clientWrapper.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import globals from '../extensionGlobals'
77
import { AwsClient, AwsClientConstructor, AwsCommand, AwsCommandConstructor } from '../awsClientBuilderV3'
88
import { PaginationConfiguration, Paginator } from '@aws-sdk/types'
99
import { AsyncCollection, toCollection } from '../utilities/asyncCollection'
10+
import { isDefined } from '../utilities/tsUtils'
1011

1112
type SDKPaginator<C, CommandInput extends object, CommandOutput extends object> = (
1213
config: Omit<PaginationConfiguration, 'client'> & { client: C },
@@ -49,10 +50,6 @@ export abstract class ClientWrapper<C extends AwsClient> implements vscode.Dispo
4950
.map((o) => o.filter(isDefined))
5051

5152
return collection
52-
53-
function isDefined<T>(i: T | undefined): i is T {
54-
return i !== undefined
55-
}
5653
}
5754

5855
protected async getFirst<CommandInput extends object, CommandOutput extends object, Output extends object>(

packages/core/src/shared/clients/codecatalystClient.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ import { ServiceConfigurationOptions } from 'aws-sdk/lib/service'
1616
import { CancellationError, Timeout, waitTimeout, waitUntil } from '../utilities/timeoutUtils'
1717
import { isUserCancelledError } from '../../shared/errors'
1818
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'
2027
import { AsyncCollection, toCollection } from '../utilities/asyncCollection'
2128
import { joinAll, pageableToCollection } from '../utilities/collectionUtils'
2229
import { CodeCatalyst } from 'aws-sdk'
@@ -58,6 +65,7 @@ import {
5865
ListSpacesCommand,
5966
ListSpacesRequest,
6067
ListSpacesResponse,
68+
ProjectSummary,
6169
SpaceSummary,
6270
} from '@aws-sdk/client-codecatalyst'
6371
import { truncateProps } from '../utilities/textUtilities'
@@ -525,9 +533,7 @@ class CodeCatalystClientInternal extends ClientWrapper<CodeCatalystSDKClient> {
525533
public listSpaces(request: ListSpacesRequest = {}): AsyncCollection<CodeCatalystOrg[]> {
526534
const requester: (request: ListSpacesRequest) => Promise<ListSpacesResponse> = async (request) =>
527535
this.callV3(ListSpacesCommand, request, true, { items: [] })
528-
const collection = pageableToCollection(requester, request, 'nextToken', 'items').filter(
529-
(summaries) => summaries !== undefined
530-
)
536+
const collection = pageableToCollection(requester, request, 'nextToken', 'items').filter(isDefined)
531537
return collection.map((summaries) =>
532538
summaries.filter((s) => hasProps(s, 'name')).map((s) => ({ type: 'org', ...s }))
533539
)
@@ -551,9 +557,7 @@ class CodeCatalystClientInternal extends ClientWrapper<CodeCatalystSDKClient> {
551557
const requester: (request: ListProjectsRequest) => Promise<ListProjectsResponse> = (request) =>
552558
this.callV3(ListProjectsCommand, request, true, { items: [] })
553559

554-
const collection = pageableToCollection(requester, request, 'nextToken', 'items').filter(
555-
(summaries) => summaries !== undefined
556-
)
560+
const collection = pageableToCollection(requester, request, 'nextToken', 'items').filter(isDefined)
557561

558562
return collection.map((summaries) =>
559563
summaries
@@ -569,16 +573,18 @@ class CodeCatalystClientInternal extends ClientWrapper<CodeCatalystSDKClient> {
569573
/**
570574
* Gets a flat list of all devenvs for the given CodeCatalyst project.
571575
*/
572-
public listDevEnvironments(proj: CodeCatalystProject): AsyncCollection<DevEnvironment[]> {
576+
public listDevEnvironments(
577+
proj: CodeCatalystProject
578+
): AsyncCollection<RequiredProps<DevEnvironment, 'id' | 'status' | 'lastUpdatedTime'>[]> {
573579
const initRequest = { spaceName: proj.org.name, projectName: proj.name }
574580
const requester: (request: ListDevEnvironmentsRequest) => Promise<ListDevEnvironmentsResponse> = (request) =>
575581
this.callV3(ListDevEnvironmentsCommand, request, true, { items: [] })
576-
const collection = pageableToCollection(requester, initRequest, 'nextToken', 'items').filter(
577-
(c) => c !== undefined
578-
)
582+
const collection = pageableToCollection(requester, initRequest, 'nextToken', 'items').filter(isDefined)
579583

580584
return collection.map((envs) =>
581-
envs.filter((s) => hasProps(s, 'id', 'status')).map((s) => toDevEnv(proj.org.name, proj.name, s))
585+
envs
586+
.filter((s) => hasProps(s, 'id', 'status', 'lastUpdatedTime'))
587+
.map((s) => toDevEnv(proj.org.name, proj.name, s))
582588
)
583589
}
584590

packages/core/src/shared/utilities/tsUtils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,7 @@ export function omitIfPresent<T extends Record<string, unknown>>(obj: T, keys: s
161161
}
162162
return objCopy
163163
}
164+
165+
export function isDefined<T>(i: T | undefined): i is T {
166+
return i !== undefined
167+
}

packages/core/src/testE2E/codecatalyst/client.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ describe.only('Test how this codebase uses the CodeCatalyst API', function () {
191191
assert.strictEqual(actualDevEnv.org.name, spaceName)
192192
assert.strictEqual(actualDevEnv.alias, differentDevEnvSettings.alias)
193193
assert.strictEqual(actualDevEnv.instanceType, 'dev.standard1.medium')
194-
assert.strictEqual(actualDevEnv.persistentStorage.sizeInGiB, 32)
194+
assert.strictEqual(actualDevEnv.persistentStorage && actualDevEnv.persistentStorage.sizeInGiB, 32)
195195
})
196196

197197
it.skip('creates a Dev Environment using an existing branch', async function () {
@@ -533,7 +533,7 @@ describe.only('Test how this codebase uses the CodeCatalyst API', function () {
533533
)
534534
}
535535

536-
async function getAllDevEnvs(projectName: CodeCatalystProject['name']): Promise<DevEnvironment[]> {
536+
async function getAllDevEnvs(projectName: CodeCatalystProject['name']) {
537537
const currentDevEnvs = await client
538538
.listDevEnvironments({ name: projectName, org: { name: spaceName }, type: 'project' })
539539
.flatten()

0 commit comments

Comments
 (0)