Skip to content

Commit 9e28d8a

Browse files
committed
fix(packages): maintain singleton config object
1 parent 5f755a3 commit 9e28d8a

File tree

37 files changed

+306
-133
lines changed

37 files changed

+306
-133
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
});

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ import { describe, expect, test as it, vi } from "vitest";
44
import { resolveAwsSdkSigV4Config } from "./resolveAwsSdkSigV4Config";
55

66
describe(resolveAwsSdkSigV4Config.name, () => {
7+
it("maintains object custody", () => {
8+
const input = {
9+
region: "",
10+
sha256: vi.fn(),
11+
serviceId: "",
12+
useFipsEndpoint: async () => false,
13+
useDualstackEndpoint: async () => false,
14+
};
15+
expect(resolveAwsSdkSigV4Config(input)).toBe(input);
16+
});
17+
718
it("should allow one argument to be passed to the resolved credentials function", async () => {
819
const fn = vi.fn();
920

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: 19 additions & 9 deletions
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
});

0 commit comments

Comments
 (0)