@yxw007/translate 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- // translate v0.0.2 Copyright (c) 2024 Potter<aa4790139@gmail.com> and contributors
1
+ // translate v0.0.3 Copyright (c) 2024 Potter<aa4790139@gmail.com> and contributors
2
2
  'use strict';
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
@@ -727,16 +727,6 @@ const resolveEndpoint = (ruleSetObject, options) => {
727
727
  }
728
728
  }
729
729
  const endpoint = evaluateRules(rules, { endpointParams, logger, referenceRecord: {} });
730
- if (options.endpointParams?.Endpoint) {
731
- try {
732
- const givenEndpoint = new URL(options.endpointParams.Endpoint);
733
- const { protocol, port } = givenEndpoint;
734
- endpoint.url.protocol = protocol;
735
- endpoint.url.port = port;
736
- }
737
- catch (e) {
738
- }
739
- }
740
730
  options.logger?.debug?.(`${debugId} Resolved endpoint: ${toDebugString(endpoint)}`);
741
731
  return endpoint;
742
732
  };
@@ -1357,7 +1347,13 @@ const toEndpointV1 = (endpoint) => {
1357
1347
 
1358
1348
  const getEndpointFromInstructions = async (commandInput, instructionsSupplier, clientConfig, context) => {
1359
1349
  if (!clientConfig.endpoint) {
1360
- const endpointFromConfig = await getEndpointFromConfig(clientConfig.serviceId || "");
1350
+ let endpointFromConfig;
1351
+ if (clientConfig.serviceConfiguredEndpoint) {
1352
+ endpointFromConfig = await clientConfig.serviceConfiguredEndpoint();
1353
+ }
1354
+ else {
1355
+ endpointFromConfig = await getEndpointFromConfig(clientConfig.serviceId);
1356
+ }
1361
1357
  if (endpointFromConfig) {
1362
1358
  clientConfig.endpoint = () => Promise.resolve(toEndpointV1(endpointFromConfig));
1363
1359
  }
@@ -1511,7 +1507,7 @@ const resolveEndpointConfig = (input) => {
1511
1507
  const { endpoint } = input;
1512
1508
  const customEndpointProvider = endpoint != null ? async () => toEndpointV1(await normalizeProvider$1(endpoint)()) : undefined;
1513
1509
  const isCustomEndpoint = !!endpoint;
1514
- return {
1510
+ const resolvedConfig = {
1515
1511
  ...input,
1516
1512
  endpoint: customEndpointProvider,
1517
1513
  tls,
@@ -1519,6 +1515,14 @@ const resolveEndpointConfig = (input) => {
1519
1515
  useDualstackEndpoint: normalizeProvider$1(input.useDualstackEndpoint ?? false),
1520
1516
  useFipsEndpoint: normalizeProvider$1(input.useFipsEndpoint ?? false),
1521
1517
  };
1518
+ let configuredEndpointPromise = undefined;
1519
+ resolvedConfig.serviceConfiguredEndpoint = async () => {
1520
+ if (input.serviceId && !configuredEndpointPromise) {
1521
+ configuredEndpointPromise = getEndpointFromConfig(input.serviceId);
1522
+ }
1523
+ return configuredEndpointPromise;
1524
+ };
1525
+ return resolvedConfig;
1522
1526
  };
1523
1527
 
1524
1528
  const httpAuthSchemeEndpointRuleSetMiddlewareOptions = {
@@ -2210,13 +2214,31 @@ const priorityWeights = {
2210
2214
 
2211
2215
  class Client {
2212
2216
  constructor(config) {
2213
- this.middlewareStack = constructStack();
2214
2217
  this.config = config;
2218
+ this.middlewareStack = constructStack();
2215
2219
  }
2216
2220
  send(command, optionsOrCb, cb) {
2217
2221
  const options = typeof optionsOrCb !== "function" ? optionsOrCb : undefined;
2218
2222
  const callback = typeof optionsOrCb === "function" ? optionsOrCb : cb;
2219
- const handler = command.resolveMiddleware(this.middlewareStack, this.config, options);
2223
+ const useHandlerCache = options === undefined && this.config.cacheMiddleware === true;
2224
+ let handler;
2225
+ if (useHandlerCache) {
2226
+ if (!this.handlers) {
2227
+ this.handlers = new WeakMap();
2228
+ }
2229
+ const handlers = this.handlers;
2230
+ if (handlers.has(command.constructor)) {
2231
+ handler = handlers.get(command.constructor);
2232
+ }
2233
+ else {
2234
+ handler = command.resolveMiddleware(this.middlewareStack, this.config, options);
2235
+ handlers.set(command.constructor, handler);
2236
+ }
2237
+ }
2238
+ else {
2239
+ delete this.handlers;
2240
+ handler = command.resolveMiddleware(this.middlewareStack, this.config, options);
2241
+ }
2220
2242
  if (callback) {
2221
2243
  handler(command)
2222
2244
  .then((result) => callback(null, result.output), (err) => callback(err))
@@ -2227,8 +2249,8 @@ class Client {
2227
2249
  }
2228
2250
  }
2229
2251
  destroy() {
2230
- if (this.config.requestHandler.destroy)
2231
- this.config.requestHandler.destroy();
2252
+ this.config?.requestHandler?.destroy?.();
2253
+ delete this.handlers;
2232
2254
  }
2233
2255
  }
2234
2256