初始化环境文件
This commit is contained in:
64
node_modules/@smithy/middleware-endpoint/dist-es/adaptors/getEndpointFromInstructions.js
generated
vendored
Normal file
64
node_modules/@smithy/middleware-endpoint/dist-es/adaptors/getEndpointFromInstructions.js
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
import { resolveParamsForS3 } from "../service-customizations";
|
||||
import { createConfigValueProvider } from "./createConfigValueProvider";
|
||||
import { getEndpointFromConfig } from "./getEndpointFromConfig";
|
||||
import { toEndpointV1 } from "./toEndpointV1";
|
||||
export const getEndpointFromInstructions = async (commandInput, instructionsSupplier, clientConfig, context) => {
|
||||
if (!clientConfig.isCustomEndpoint) {
|
||||
let endpointFromConfig;
|
||||
if (clientConfig.serviceConfiguredEndpoint) {
|
||||
endpointFromConfig = await clientConfig.serviceConfiguredEndpoint();
|
||||
}
|
||||
else {
|
||||
endpointFromConfig = await getEndpointFromConfig(clientConfig.serviceId);
|
||||
}
|
||||
if (endpointFromConfig) {
|
||||
clientConfig.endpoint = () => Promise.resolve(toEndpointV1(endpointFromConfig));
|
||||
clientConfig.isCustomEndpoint = true;
|
||||
}
|
||||
}
|
||||
const endpointParams = await resolveParams(commandInput, instructionsSupplier, clientConfig);
|
||||
if (typeof clientConfig.endpointProvider !== "function") {
|
||||
throw new Error("config.endpointProvider is not set.");
|
||||
}
|
||||
const endpoint = clientConfig.endpointProvider(endpointParams, context);
|
||||
if (clientConfig.isCustomEndpoint && clientConfig.endpoint) {
|
||||
const customEndpoint = await clientConfig.endpoint();
|
||||
if (customEndpoint?.headers) {
|
||||
endpoint.headers ??= {};
|
||||
for (const [name, value] of Object.entries(customEndpoint.headers)) {
|
||||
endpoint.headers[name] = Array.isArray(value) ? value : [value];
|
||||
}
|
||||
}
|
||||
}
|
||||
return endpoint;
|
||||
};
|
||||
export const resolveParams = async (commandInput, instructionsSupplier, clientConfig) => {
|
||||
const endpointParams = {};
|
||||
const instructions = instructionsSupplier?.getEndpointParameterInstructions?.() || {};
|
||||
for (const [name, instruction] of Object.entries(instructions)) {
|
||||
switch (instruction.type) {
|
||||
case "staticContextParams":
|
||||
endpointParams[name] = instruction.value;
|
||||
break;
|
||||
case "contextParams":
|
||||
endpointParams[name] = commandInput[instruction.name];
|
||||
break;
|
||||
case "clientContextParams":
|
||||
case "builtInParams":
|
||||
endpointParams[name] = await createConfigValueProvider(instruction.name, name, clientConfig, instruction.type !== "builtInParams")();
|
||||
break;
|
||||
case "operationContextParams":
|
||||
endpointParams[name] = instruction.get(commandInput);
|
||||
break;
|
||||
default:
|
||||
throw new Error("Unrecognized endpoint parameter instruction: " + JSON.stringify(instruction));
|
||||
}
|
||||
}
|
||||
if (Object.keys(instructions).length === 0) {
|
||||
Object.assign(endpointParams, clientConfig);
|
||||
}
|
||||
if (String(clientConfig.serviceId).toLowerCase() === "s3") {
|
||||
await resolveParamsForS3(endpointParams);
|
||||
}
|
||||
return endpointParams;
|
||||
};
|
||||
Reference in New Issue
Block a user