Skip to content

Commit 93f7ae2

Browse files
committed
move utility function to util file
1 parent d806de9 commit 93f7ae2

File tree

4 files changed

+31
-25
lines changed

4 files changed

+31
-25
lines changed

packages/core/src/shared/awsClientBuilderV3.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { telemetry } from './telemetry'
2222
import { getRequestId } from './errors'
2323
import { extensionVersion } from '.'
2424
import { getLogger } from './logger'
25+
import { omitIfPresent } from './utilities/tsUtils'
2526

2627
export type AwsClient = IClient<any, any, any>
2728
interface AwsConfigOptions {
@@ -108,16 +109,6 @@ export function recordErrorTelemetry(err: Error, serviceName?: string) {
108109
} satisfies RequestData as any)
109110
}
110111

111-
export function omitIfPresent<T extends Record<string, unknown>>(obj: T, keys: string[]): T {
112-
const objCopy = { ...obj }
113-
for (const key of keys) {
114-
if (key in objCopy) {
115-
;(objCopy as any)[key] = '[omitted]'
116-
}
117-
}
118-
return objCopy
119-
}
120-
121112
function logAndThrow(e: any, serviceId: string, errorMessageAppend: string): never {
122113
if (e instanceof Error) {
123114
recordErrorTelemetry(e, serviceId)

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ export function stringOrProp(obj: any, prop: string): string {
1010
return obj[prop] ?? ''
1111
}
1212

13+
export function omitIfPresent<T extends Record<string, unknown>>(obj: T, keys: string[]): T {
14+
const objCopy = { ...obj }
15+
for (const key of keys) {
16+
if (key in objCopy) {
17+
;(objCopy as any)[key] = '[omitted]'
18+
}
19+
}
20+
return objCopy
21+
}
22+
1323
export function getMissingProps<T>(obj: T, ...props: (keyof T)[]): typeof props {
1424
return props.filter((prop) => obj[prop] === undefined)
1525
}

packages/core/src/test/shared/defaultAwsClientBuilderV3.test.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
AWSClientBuilderV3,
1414
DefaultAWSClientBuilderV3,
1515
getServiceId,
16-
omitIfPresent,
1716
recordErrorTelemetry,
1817
} from '../../shared/awsClientBuilderV3'
1918
import { Client } from '@aws-sdk/smithy-client'
@@ -83,17 +82,3 @@ describe('recordErrorTelemetry', function () {
8382
assertTelemetry('vscode_executeCommand', { requestServiceType: 'aws-service' })
8483
})
8584
})
86-
87-
describe('omitIfPresent', function () {
88-
it('returns a new object with value replace by [omitted]', function () {
89-
const obj = { a: 1, b: 2 }
90-
const result = omitIfPresent(obj, ['a'])
91-
assert.deepStrictEqual(result, { a: '[omitted]', b: 2 })
92-
})
93-
94-
it('returns the original object if the key is not present', function () {
95-
const obj = { a: 1, b: 2 }
96-
const result = omitIfPresent(obj, ['c'])
97-
assert.deepStrictEqual(result, obj)
98-
})
99-
})
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
import assert from 'assert'
6+
import { omitIfPresent } from '../../../shared/utilities/tsUtils'
7+
8+
describe('omitIfPresent', function () {
9+
it('returns a new object with value replace by [omitted]', function () {
10+
const obj = { a: 1, b: 2 }
11+
const result = omitIfPresent(obj, ['a'])
12+
assert.deepStrictEqual(result, { a: '[omitted]', b: 2 })
13+
})
14+
15+
it('returns the original object if the key is not present', function () {
16+
const obj = { a: 1, b: 2 }
17+
const result = omitIfPresent(obj, ['c'])
18+
assert.deepStrictEqual(result, obj)
19+
})
20+
})

0 commit comments

Comments
 (0)