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);

0 commit comments

Comments
 (0)