Skip to content

Commit 3dcd29f

Browse files
committed
fix(packages): maintain singleton config object
1 parent a727545 commit 3dcd29f

37 files changed

+308
-130
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { describe, expect, test as it } from "vitest";
2+
3+
import { resolveAccountIdEndpointModeConfig } from "./AccountIdEndpointModeConfigResolver";
4+
5+
describe(resolveAccountIdEndpointModeConfig.name, () => {
6+
it("maintains object custody", () => {
7+
const input = {};
8+
expect(resolveAccountIdEndpointModeConfig(input)).toBe(input);
9+
});
10+
});

packages/core/src/submodules/account-id-endpoint/AccountIdEndpointModeConfigResolver.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,9 @@ export interface AccountIdEndpointModeResolvedConfig {
3838
export const resolveAccountIdEndpointModeConfig = <T>(
3939
input: T & AccountIdEndpointModeInputConfig & PreviouslyResolved
4040
): T & AccountIdEndpointModeResolvedConfig => {
41-
const accountIdEndpointModeProvider = normalizeProvider(
42-
input.accountIdEndpointMode ?? DEFAULT_ACCOUNT_ID_ENDPOINT_MODE
43-
);
44-
return {
45-
...input,
41+
const { accountIdEndpointMode } = input;
42+
const accountIdEndpointModeProvider = normalizeProvider(accountIdEndpointMode ?? DEFAULT_ACCOUNT_ID_ENDPOINT_MODE);
43+
return Object.assign(input, {
4644
accountIdEndpointMode: async () => {
4745
const accIdMode = await accountIdEndpointModeProvider();
4846
if (!validateAccountIdEndpointMode(accIdMode)) {
@@ -52,5 +50,5 @@ export const resolveAccountIdEndpointModeConfig = <T>(
5250
}
5351
return accIdMode;
5452
},
55-
};
53+
});
5654
};

packages/core/src/submodules/httpAuthSchemes/aws_sdk/resolveAwsSdkSigV4AConfig.spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,9 @@ describe(resolveAwsSdkSigV4AConfig.name, () => {
99
expect(typeof config.sigv4aSigningRegionSet).toEqual("function");
1010
expect(await config.sigv4aSigningRegionSet()).toEqual(undefined);
1111
});
12+
13+
it("maintains object custody", () => {
14+
const input = {};
15+
expect(resolveAwsSdkSigV4AConfig(input)).toBe(input);
16+
});
1217
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { describe, expect, test as it, vi } from "vitest";
2+
3+
import { resolveAwsSdkSigV4Config } from "./resolveAwsSdkSigV4Config";
4+
5+
describe(resolveAwsSdkSigV4Config.name, () => {
6+
it("maintains object custody", () => {
7+
const input = {
8+
region: "",
9+
sha256: vi.fn(),
10+
serviceId: "",
11+
useFipsEndpoint: async () => false,
12+
useDualstackEndpoint: async () => false,
13+
};
14+
expect(resolveAwsSdkSigV4Config(input)).toBe(input);
15+
});
16+
});

packages/core/src/submodules/httpAuthSchemes/aws_sdk/resolveAwsSdkSigV4Config.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,7 @@ export const resolveAwsSdkSigV4Config = <T>(
220220
};
221221
}
222222

223-
return {
224-
...config,
223+
return Object.assign(config, {
225224
systemClockOffset,
226225
signingEscapePath,
227226
credentials: isUserSupplied
@@ -231,7 +230,7 @@ export const resolveAwsSdkSigV4Config = <T>(
231230
)
232231
: boundCredentialsProvider!,
233232
signer,
234-
};
233+
});
235234
};
236235

237236
/**

packages/middleware-api-key/src/apiKeyConfiguration.spec.ts

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import { describe, expect, test as it } from "vitest";
33
import { resolveApiKeyConfig } from "./index";
44

55
describe("ApiKeyConfig", () => {
6+
it("maintains object custody", () => {
7+
const config = {
8+
apiKey: () => Promise.resolve("example-api-key"),
9+
};
10+
expect(resolveApiKeyConfig(config)).toBe(config);
11+
});
612
it("should return the input unchanged", () => {
713
const config = {
814
apiKey: () => Promise.resolve("example-api-key"),

packages/middleware-api-key/src/apiKeyConfiguration.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export interface ApiKeyResolvedConfig {
3131
export const resolveApiKeyConfig = <T>(
3232
input: T & ApiKeyPreviouslyResolved & ApiKeyInputConfig
3333
): T & ApiKeyResolvedConfig => {
34-
return {
35-
...input,
36-
apiKey: input.apiKey ? normalizeProvider(input.apiKey) : undefined,
37-
};
34+
const { apiKey } = input;
35+
return Object.assign(input, {
36+
apiKey: apiKey ? normalizeProvider(apiKey) : undefined,
37+
});
3838
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { describe, expect, test as it, vi } from "vitest";
2+
3+
import { resolveBucketEndpointConfig } from "./configurations";
4+
5+
describe(resolveBucketEndpointConfig.name, () => {
6+
it("maintains object custody", () => {
7+
const input = {
8+
region: async () => "",
9+
regionInfoProvider: vi.fn(),
10+
useFipsEndpoint: async () => false,
11+
useDualstackEndpoint: async () => false,
12+
};
13+
expect(resolveBucketEndpointConfig(input)).toBe(input);
14+
});
15+
});

packages/middleware-bucket-endpoint/src/configurations.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ export function resolveBucketEndpointConfig<T>(
9393
useArnRegion = false,
9494
disableMultiregionAccessPoints = false,
9595
} = input;
96-
return {
97-
...input,
96+
return Object.assign(input, {
9897
bucketEndpoint,
9998
forcePathStyle,
10099
useAccelerateEndpoint,
@@ -103,5 +102,5 @@ export function resolveBucketEndpointConfig<T>(
103102
typeof disableMultiregionAccessPoints === "function"
104103
? disableMultiregionAccessPoints
105104
: () => Promise.resolve(disableMultiregionAccessPoints),
106-
};
105+
});
107106
}

packages/middleware-endpoint-discovery/src/resolveEndpointDiscoveryConfig.spec.ts

+19-9
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,26 @@ vi.mock("@aws-sdk/endpoint-cache");
77

88
describe(resolveEndpointDiscoveryConfig.name, () => {
99
const endpointDiscoveryCommandCtor = vi.fn();
10-
const mockInput = {
10+
const mockInput = () => ({
1111
isCustomEndpoint: false,
1212
credentials: vi.fn(),
1313
endpointDiscoveryEnabledProvider: vi.fn(),
14-
};
14+
});
1515

1616
afterEach(() => {
1717
vi.clearAllMocks();
1818
});
1919

20+
it("maintains object custody", () => {
21+
const input = {
22+
credentials: vi.fn(),
23+
endpointDiscoveryEnabledProvider: async () => false,
24+
};
25+
expect(resolveEndpointDiscoveryConfig(input, { endpointDiscoveryCommandCtor })).toBe(input);
26+
});
27+
2028
it("assigns endpointDiscoveryCommandCtor in resolvedConfig", () => {
21-
const resolvedConfig = resolveEndpointDiscoveryConfig(mockInput, { endpointDiscoveryCommandCtor });
29+
const resolvedConfig = resolveEndpointDiscoveryConfig(mockInput(), { endpointDiscoveryCommandCtor });
2230
expect(resolvedConfig.endpointDiscoveryCommandCtor).toStrictEqual(endpointDiscoveryCommandCtor);
2331
});
2432

@@ -27,7 +35,7 @@ describe(resolveEndpointDiscoveryConfig.name, () => {
2735
const endpointCacheSize = 100;
2836
resolveEndpointDiscoveryConfig(
2937
{
30-
...mockInput,
38+
...mockInput(),
3139
endpointCacheSize,
3240
},
3341
{ endpointDiscoveryCommandCtor }
@@ -36,28 +44,30 @@ describe(resolveEndpointDiscoveryConfig.name, () => {
3644
});
3745

3846
it("creates cache of size 1000 if endpointCacheSize not passed", () => {
39-
resolveEndpointDiscoveryConfig(mockInput, { endpointDiscoveryCommandCtor });
47+
resolveEndpointDiscoveryConfig(mockInput(), { endpointDiscoveryCommandCtor });
4048
expect(EndpointCache).toBeCalledWith(1000);
4149
});
4250
});
4351

4452
describe("endpointDiscoveryEnabled", () => {
4553
it.each<boolean>([false, true])(`sets to value passed in the config: %s`, async (endpointDiscoveryEnabled) => {
54+
const input = mockInput();
4655
const resolvedConfig = resolveEndpointDiscoveryConfig(
4756
{
48-
...mockInput,
57+
...input,
4958
endpointDiscoveryEnabled,
5059
},
5160
{ endpointDiscoveryCommandCtor }
5261
);
5362
await expect(resolvedConfig.endpointDiscoveryEnabled()).resolves.toBe(endpointDiscoveryEnabled);
54-
expect(mockInput.endpointDiscoveryEnabledProvider).not.toHaveBeenCalled();
63+
expect(input.endpointDiscoveryEnabledProvider).not.toHaveBeenCalled();
5564
expect(resolvedConfig.isClientEndpointDiscoveryEnabled).toStrictEqual(true);
5665
});
5766

5867
it(`sets to endpointDiscoveryEnabledProvider if value is not passed`, () => {
59-
const resolvedConfig = resolveEndpointDiscoveryConfig(mockInput, { endpointDiscoveryCommandCtor });
60-
expect(resolvedConfig.endpointDiscoveryEnabled).toBe(mockInput.endpointDiscoveryEnabledProvider);
68+
const input = mockInput();
69+
const resolvedConfig = resolveEndpointDiscoveryConfig(input, { endpointDiscoveryCommandCtor });
70+
expect(resolvedConfig.endpointDiscoveryEnabled).toBe(input.endpointDiscoveryEnabledProvider);
6171
expect(resolvedConfig.isClientEndpointDiscoveryEnabled).toStrictEqual(false);
6272
});
6373
});

packages/middleware-endpoint-discovery/src/resolveEndpointDiscoveryConfig.ts

+13-10
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,16 @@ export interface EndpointDiscoveryConfigOptions {
6262
export const resolveEndpointDiscoveryConfig = <T>(
6363
input: T & PreviouslyResolved & EndpointDiscoveryInputConfig,
6464
{ endpointDiscoveryCommandCtor }: EndpointDiscoveryConfigOptions
65-
): T & EndpointDiscoveryResolvedConfig => ({
66-
...input,
67-
endpointDiscoveryCommandCtor,
68-
endpointCache: new EndpointCache(input.endpointCacheSize ?? 1000),
69-
endpointDiscoveryEnabled:
70-
input.endpointDiscoveryEnabled !== undefined
71-
? () => Promise.resolve(input.endpointDiscoveryEnabled)
72-
: input.endpointDiscoveryEnabledProvider,
73-
isClientEndpointDiscoveryEnabled: input.endpointDiscoveryEnabled !== undefined,
74-
});
65+
): T & EndpointDiscoveryResolvedConfig => {
66+
const { endpointCacheSize, endpointDiscoveryEnabled, endpointDiscoveryEnabledProvider } = input;
67+
68+
return Object.assign(input, {
69+
endpointDiscoveryCommandCtor,
70+
endpointCache: new EndpointCache(endpointCacheSize ?? 1000),
71+
endpointDiscoveryEnabled:
72+
endpointDiscoveryEnabled !== undefined
73+
? () => Promise.resolve(endpointDiscoveryEnabled)
74+
: endpointDiscoveryEnabledProvider,
75+
isClientEndpointDiscoveryEnabled: endpointDiscoveryEnabled !== undefined,
76+
});
77+
};

packages/middleware-eventstream/src/eventStreamConfiguration.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ export function resolveEventStreamConfig<T>(
4040
...input,
4141
messageSigner,
4242
});
43-
return {
44-
...input,
43+
return Object.assign(input, {
4544
eventSigner,
4645
eventStreamPayloadHandler,
47-
};
46+
});
4847
}

packages/middleware-eventstream/src/middleware-eventstream.integ.spec.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { LexRuntimeV2 } from "@aws-sdk/client-lex-runtime-v2";
22
import { RekognitionStreaming } from "@aws-sdk/client-rekognitionstreaming";
33
import { TranscribeStreaming } from "@aws-sdk/client-transcribe-streaming";
4-
import { describe, expect, test as it } from "vitest";
4+
import { Decoder, Encoder, EventStreamPayloadHandlerProvider } from "@smithy/types";
5+
import { describe, expect, test as it, vi } from "vitest";
56

67
import { requireRequestsFrom } from "../../../private/aws-util-test/src";
8+
import { resolveEventStreamConfig } from "./eventStreamConfiguration";
79

810
describe("middleware-eventstream", () => {
911
const logger = {
@@ -14,6 +16,18 @@ describe("middleware-eventstream", () => {
1416
error() {},
1517
};
1618

19+
describe("config resolver", () => {
20+
it("maintains object custody", () => {
21+
const input = {
22+
utf8Encoder: vi.fn(),
23+
utf8Decoder: vi.fn(),
24+
signer: vi.fn(),
25+
eventStreamPayloadHandlerProvider: vi.fn(),
26+
};
27+
expect(resolveEventStreamConfig(input)).toBe(input);
28+
});
29+
});
30+
1731
// TODO: http2 in CI
1832
describe.skip(LexRuntimeV2.name, () => {
1933
it("should set streaming headers", async () => {

packages/middleware-flexible-checksums/src/resolveFlexibleChecksumsConfig.spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ describe(resolveFlexibleChecksumsConfig.name, () => {
2020
vi.clearAllMocks();
2121
});
2222

23+
it("maintains object custody", () => {
24+
const input = {};
25+
expect(resolveFlexibleChecksumsConfig(input)).toBe(input);
26+
});
27+
2328
it("returns default client checksums configuration, if not provided", () => {
2429
const resolvedConfig = resolveFlexibleChecksumsConfig({});
2530
expect(resolvedConfig).toEqual({

packages/middleware-flexible-checksums/src/resolveFlexibleChecksumsConfig.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,11 @@ export interface FlexibleChecksumsResolvedConfig {
4545

4646
export const resolveFlexibleChecksumsConfig = <T>(
4747
input: T & FlexibleChecksumsInputConfig
48-
): T & FlexibleChecksumsResolvedConfig => ({
49-
...input,
50-
requestChecksumCalculation: normalizeProvider(
51-
input.requestChecksumCalculation ?? DEFAULT_REQUEST_CHECKSUM_CALCULATION
52-
),
53-
responseChecksumValidation: normalizeProvider(
54-
input.responseChecksumValidation ?? DEFAULT_RESPONSE_CHECKSUM_VALIDATION
55-
),
56-
requestStreamBufferSize: Number(input.requestStreamBufferSize ?? 0),
57-
});
48+
): T & FlexibleChecksumsResolvedConfig => {
49+
const { requestChecksumCalculation, responseChecksumValidation, requestStreamBufferSize } = input;
50+
return Object.assign(input, {
51+
requestChecksumCalculation: normalizeProvider(requestChecksumCalculation ?? DEFAULT_REQUEST_CHECKSUM_CALCULATION),
52+
responseChecksumValidation: normalizeProvider(responseChecksumValidation ?? DEFAULT_RESPONSE_CHECKSUM_VALIDATION),
53+
requestStreamBufferSize: Number(requestStreamBufferSize ?? 0),
54+
});
55+
};

packages/middleware-host-header/src/index.spec.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import { HttpRequest } from "@smithy/protocol-http";
22
import { beforeEach, describe, expect, test as it, vi } from "vitest";
33

4-
import { hostHeaderMiddleware } from "./index";
4+
import { hostHeaderMiddleware, resolveHostHeaderConfig } from "./index";
55
describe("hostHeaderMiddleware", () => {
66
const mockNextHandler = vi.fn();
77

88
beforeEach(() => {
99
vi.clearAllMocks();
1010
});
1111

12+
it("maintains object custody", () => {
13+
const input = {
14+
requestHandler: vi.fn() as any,
15+
};
16+
expect(resolveHostHeaderConfig(input)).toBe(input);
17+
});
18+
1219
it("should set host header if not already set", async () => {
1320
expect.assertions(2);
1421
const middleware = hostHeaderMiddleware({ requestHandler: {} as any });

packages/middleware-location-constraint/src/configuration.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ export interface LocationConstraintResolvedConfig {
1818
export function resolveLocationConstraintConfig<T>(
1919
input: T & LocationConstraintInputConfig & PreviouslyResolved
2020
): T & LocationConstraintResolvedConfig {
21-
return { ...input };
21+
return input;
2222
}

packages/middleware-location-constraint/src/index.spec.ts

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { beforeEach, describe, expect, test as it, vi } from "vitest";
22

33
import { locationConstraintMiddleware } from "./";
4+
import { resolveLocationConstraintConfig } from "./configuration";
45

56
describe("locationConstrainMiddleware", () => {
67
const next = vi.fn();
@@ -12,6 +13,13 @@ describe("locationConstrainMiddleware", () => {
1213
vi.clearAllMocks();
1314
});
1415

16+
describe("config resolver", () => {
17+
it("maintains object custody", () => {
18+
const input = {} as any;
19+
expect(resolveLocationConstraintConfig(input)).toBe(input);
20+
});
21+
});
22+
1523
describe("for region us-east-1", () => {
1624
const handler = locationConstraintMiddleware({
1725
region: () => Promise.resolve("us-east-1"),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { describe, expect, test as it } from "vitest";
2+
3+
import { resolveS3ControlConfig } from "./configurations";
4+
5+
describe(resolveS3ControlConfig.name, () => {
6+
it("maintains object custody", () => {
7+
const input = {} as any;
8+
expect(resolveS3ControlConfig(input)).toBe(input);
9+
});
10+
});

packages/middleware-sdk-s3-control/src/configurations.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ export function resolveS3ControlConfig<T>(
5252
input: T & PreviouslyResolved & S3ControlInputConfig
5353
): T & S3ControlResolvedConfig {
5454
const { useArnRegion = false } = input;
55-
return {
56-
...input,
55+
return Object.assign(input, {
5756
useArnRegion: typeof useArnRegion === "function" ? useArnRegion : () => Promise.resolve(useArnRegion),
58-
};
57+
});
5958
}

0 commit comments

Comments
 (0)