Skip to content

Commit e84ade3

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

File tree

37 files changed

+295
-121
lines changed

37 files changed

+295
-121
lines changed
Lines changed: 10 additions & 0 deletions
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

Lines changed: 4 additions & 6 deletions
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

Lines changed: 5 additions & 0 deletions
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
});
Lines changed: 16 additions & 0 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 4 additions & 4 deletions
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
};
Lines changed: 15 additions & 0 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 8 additions & 0 deletions
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);

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

Lines changed: 13 additions & 10 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 15 additions & 1 deletion
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 8 additions & 10 deletions
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

Lines changed: 8 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 8 additions & 0 deletions
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"),
Lines changed: 10 additions & 0 deletions
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

Lines changed: 2 additions & 3 deletions
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
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { describe, expect, test as it, vi } from "vitest";
2+
3+
import { resolveS3Config } from "./s3Configuration";
4+
5+
describe(resolveS3Config.name, () => {
6+
it("maintains object custody", () => {
7+
const input = {};
8+
expect(
9+
resolveS3Config(input, {
10+
session: [() => null, vi.fn()],
11+
})
12+
).toBe(input);
13+
});
14+
});

0 commit comments

Comments
 (0)