Skip to content

Commit 7c7bac3

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

File tree

42 files changed

+294
-132
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+294
-132
lines changed

Diff for: clients/client-s3/src/S3Client.ts

+3
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,9 @@ export class S3Client extends __Client<
862862
this.middlewareStack.use(getRegionRedirectMiddlewarePlugin(this.config));
863863
this.middlewareStack.use(getS3ExpressPlugin(this.config));
864864
this.middlewareStack.use(getS3ExpressHttpSigningPlugin(this.config));
865+
if ((_config_0 as unknown) !== this.config) {
866+
throw new Error(`${this.constructor.name} - ConfigCustodyError`);
867+
}
865868
}
866869

867870
/**

Diff for: clients/client-s3/src/auth/httpAuthSchemeProvider.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,5 @@ export const resolveHttpAuthSchemeConfig = <T>(
324324
): T & HttpAuthSchemeResolvedConfig => {
325325
const config_0 = resolveAwsSdkSigV4Config(config);
326326
const config_1 = resolveAwsSdkSigV4AConfig(config_0);
327-
return {
328-
...config_1,
329-
} as T & HttpAuthSchemeResolvedConfig;
327+
return Object.assign(config_1, {}) as T & HttpAuthSchemeResolvedConfig;
330328
};

Diff for: clients/client-s3/src/endpoint/EndpointParameters.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,15 @@ export type ClientResolvedEndpointParameters = ClientInputEndpointParameters & {
2424
export const resolveClientEndpointParameters = <T>(
2525
options: T & ClientInputEndpointParameters
2626
): T & ClientResolvedEndpointParameters => {
27-
return {
28-
...options,
27+
return Object.assign(options, {
2928
useFipsEndpoint: options.useFipsEndpoint ?? false,
3029
useDualstackEndpoint: options.useDualstackEndpoint ?? false,
3130
forcePathStyle: options.forcePathStyle ?? false,
3231
useAccelerateEndpoint: options.useAccelerateEndpoint ?? false,
3332
useGlobalEndpoint: options.useGlobalEndpoint ?? false,
3433
disableMultiregionAccessPoints: options.disableMultiregionAccessPoints ?? false,
3534
defaultSigningName: "s3",
36-
};
35+
});
3736
};
3837

3938
export const commonParams = {

Diff for: clients/client-s3/src/models/models_0.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// smithy-typescript generated code
22
import { ExceptionOptionType as __ExceptionOptionType, SENSITIVE_STRING } from "@smithy/smithy-client";
3-
43
import { StreamingBlobTypes } from "@smithy/types";
54

65
import { S3ServiceException as __BaseException } from "./S3ServiceException";

Diff for: clients/client-s3/src/models/models_1.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// smithy-typescript generated code
22
import { ExceptionOptionType as __ExceptionOptionType, SENSITIVE_STRING } from "@smithy/smithy-client";
3-
43
import { StreamingBlobTypes } from "@smithy/types";
54

65
import {
@@ -41,7 +40,6 @@ import {
4140
Tag,
4241
TransitionDefaultMinimumObjectSize,
4342
} from "./models_0";
44-
4543
import { S3ServiceException as __BaseException } from "./S3ServiceException";
4644

4745
/**

Diff for: clients/client-s3/src/runtimeExtensions.ts

+13-15
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,24 @@ export interface RuntimeExtensionsConfig {
2323
extensions: RuntimeExtension[];
2424
}
2525

26-
const asPartial = <T extends Partial<S3ExtensionConfiguration>>(t: T) => t;
27-
2826
/**
2927
* @internal
3028
*/
3129
export const resolveRuntimeExtensions = (runtimeConfig: any, extensions: RuntimeExtension[]) => {
32-
const extensionConfiguration: S3ExtensionConfiguration = {
33-
...asPartial(getAwsRegionExtensionConfiguration(runtimeConfig)),
34-
...asPartial(getDefaultExtensionConfiguration(runtimeConfig)),
35-
...asPartial(getHttpHandlerExtensionConfiguration(runtimeConfig)),
36-
...asPartial(getHttpAuthExtensionConfiguration(runtimeConfig)),
37-
};
30+
const extensionConfiguration: S3ExtensionConfiguration = Object.assign(
31+
getAwsRegionExtensionConfiguration(runtimeConfig),
32+
getDefaultExtensionConfiguration(runtimeConfig),
33+
getHttpHandlerExtensionConfiguration(runtimeConfig),
34+
getHttpAuthExtensionConfiguration(runtimeConfig)
35+
);
3836

3937
extensions.forEach((extension) => extension.configure(extensionConfiguration));
4038

41-
return {
42-
...runtimeConfig,
43-
...resolveAwsRegionExtensionConfiguration(extensionConfiguration),
44-
...resolveDefaultRuntimeConfig(extensionConfiguration),
45-
...resolveHttpHandlerRuntimeConfig(extensionConfiguration),
46-
...resolveHttpAuthRuntimeConfig(extensionConfiguration),
47-
};
39+
return Object.assign(
40+
runtimeConfig,
41+
resolveAwsRegionExtensionConfiguration(extensionConfiguration),
42+
resolveDefaultRuntimeConfig(extensionConfiguration),
43+
resolveHttpHandlerRuntimeConfig(extensionConfiguration),
44+
resolveHttpAuthRuntimeConfig(extensionConfiguration)
45+
);
4846
};
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+
});

Diff for: 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
};

Diff for: 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+
});

Diff for: 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
/**

Diff for: 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"),

Diff for: 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+
});

Diff for: 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
}

Diff for: packages/middleware-endpoint-discovery/src/resolveEndpointDiscoveryConfig.spec.ts

+8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ describe(resolveEndpointDiscoveryConfig.name, () => {
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", () => {
2129
const resolvedConfig = resolveEndpointDiscoveryConfig(mockInput, { endpointDiscoveryCommandCtor });
2230
expect(resolvedConfig.endpointDiscoveryCommandCtor).toStrictEqual(endpointDiscoveryCommandCtor);

Diff for: 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+
};

Diff for: 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
}

Diff for: 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 () => {

Diff for: 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({

Diff for: 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+
};

Diff for: 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 });

Diff for: 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
}

0 commit comments

Comments
 (0)