@aws-sdk/util-endpoints 3.200.0 → 3.202.0

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,28 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.202.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.201.0...v3.202.0) (2022-11-02)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **util-endpoints:** evaluateTemplate implementation without RegExp/Function ([#4136](https://github.com/aws/aws-sdk-js-v3/issues/4136)) ([5c8a6fb](https://github.com/aws/aws-sdk-js-v3/commit/5c8a6fbe34267337b14774b8e47e9d584a29ecd4))
12
+
13
+
14
+
15
+
16
+
17
+ # [3.201.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.200.0...v3.201.0) (2022-11-01)
18
+
19
+
20
+ ### Features
21
+
22
+ * end support for Node.js 12.x ([#4123](https://github.com/aws/aws-sdk-js-v3/issues/4123)) ([83f913e](https://github.com/aws/aws-sdk-js-v3/commit/83f913ec2ac3878d8726c6964f585550dc5caf3e))
23
+
24
+
25
+
26
+
27
+
6
28
  # [3.200.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.199.0...v3.200.0) (2022-10-31)
7
29
 
8
30
  **Note:** Version bump only for package @aws-sdk/util-endpoints
@@ -2,27 +2,39 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.evaluateTemplate = void 0;
4
4
  const lib_1 = require("../lib");
5
- const ATTR_SHORTHAND_REGEX = new RegExp("\\${([\\w]+)#([\\w]+)}", "g");
6
5
  const evaluateTemplate = (template, options) => {
7
- const templateToEvaluate = template
8
- .replace(new RegExp(`\{([^{}]+)\}`, "g"), "${$1}")
9
- .replace(new RegExp(`\{\\$\{([^{}]+)\}\}`, "g"), "{$1}");
6
+ const evaluatedTemplateArr = [];
10
7
  const templateContext = {
11
8
  ...options.endpointParams,
12
9
  ...options.referenceRecord,
13
10
  };
14
- const attrShortHandList = templateToEvaluate.match(ATTR_SHORTHAND_REGEX) || [];
15
- const attrShortHandMap = attrShortHandList.reduce((acc, attrShortHand) => {
16
- const indexOfHash = attrShortHand.indexOf("#");
17
- const refName = attrShortHand.substring(2, indexOfHash);
18
- const attrName = attrShortHand.substring(indexOfHash + 1, attrShortHand.length - 1);
19
- acc[attrShortHand] = (0, lib_1.getAttr)(templateContext[refName], attrName);
20
- return acc;
21
- }, {});
22
- const templateWithAttr = Object.entries(attrShortHandMap).reduce((acc, [shortHand, value]) => acc.replace(shortHand, value), templateToEvaluate);
23
- const templateContextNames = Object.keys(templateContext);
24
- const templateContextValues = Object.values(templateContext);
25
- const templateWithTildeEscaped = templateWithAttr.replace(/\`/g, "\\`");
26
- return new Function(...templateContextNames, `return \`${templateWithTildeEscaped}\``)(...templateContextValues);
11
+ let currentIndex = 0;
12
+ while (currentIndex < template.length) {
13
+ const openingBraceIndex = template.indexOf("{", currentIndex);
14
+ if (openingBraceIndex === -1) {
15
+ evaluatedTemplateArr.push(template.slice(currentIndex));
16
+ break;
17
+ }
18
+ evaluatedTemplateArr.push(template.slice(currentIndex, openingBraceIndex));
19
+ const closingBraceIndex = template.indexOf("}", openingBraceIndex);
20
+ if (closingBraceIndex === -1) {
21
+ evaluatedTemplateArr.push(template.slice(openingBraceIndex));
22
+ break;
23
+ }
24
+ if (template[openingBraceIndex + 1] === "{" && template[closingBraceIndex + 1] === "}") {
25
+ evaluatedTemplateArr.push(template.slice(openingBraceIndex + 1, closingBraceIndex));
26
+ currentIndex = closingBraceIndex + 2;
27
+ }
28
+ const parameterName = template.substring(openingBraceIndex + 1, closingBraceIndex);
29
+ if (parameterName.includes("#")) {
30
+ const [refName, attrName] = parameterName.split("#");
31
+ evaluatedTemplateArr.push((0, lib_1.getAttr)(templateContext[refName], attrName));
32
+ }
33
+ else {
34
+ evaluatedTemplateArr.push(templateContext[parameterName]);
35
+ }
36
+ currentIndex = closingBraceIndex + 1;
37
+ }
38
+ return evaluatedTemplateArr.join("");
27
39
  };
28
40
  exports.evaluateTemplate = evaluateTemplate;
@@ -1,24 +1,36 @@
1
1
  import { getAttr } from "../lib";
2
- const ATTR_SHORTHAND_REGEX = new RegExp("\\${([\\w]+)#([\\w]+)}", "g");
3
2
  export const evaluateTemplate = (template, options) => {
4
- const templateToEvaluate = template
5
- .replace(new RegExp(`\{([^{}]+)\}`, "g"), "${$1}")
6
- .replace(new RegExp(`\{\\$\{([^{}]+)\}\}`, "g"), "{$1}");
3
+ const evaluatedTemplateArr = [];
7
4
  const templateContext = {
8
5
  ...options.endpointParams,
9
6
  ...options.referenceRecord,
10
7
  };
11
- const attrShortHandList = templateToEvaluate.match(ATTR_SHORTHAND_REGEX) || [];
12
- const attrShortHandMap = attrShortHandList.reduce((acc, attrShortHand) => {
13
- const indexOfHash = attrShortHand.indexOf("#");
14
- const refName = attrShortHand.substring(2, indexOfHash);
15
- const attrName = attrShortHand.substring(indexOfHash + 1, attrShortHand.length - 1);
16
- acc[attrShortHand] = getAttr(templateContext[refName], attrName);
17
- return acc;
18
- }, {});
19
- const templateWithAttr = Object.entries(attrShortHandMap).reduce((acc, [shortHand, value]) => acc.replace(shortHand, value), templateToEvaluate);
20
- const templateContextNames = Object.keys(templateContext);
21
- const templateContextValues = Object.values(templateContext);
22
- const templateWithTildeEscaped = templateWithAttr.replace(/\`/g, "\\`");
23
- return new Function(...templateContextNames, `return \`${templateWithTildeEscaped}\``)(...templateContextValues);
8
+ let currentIndex = 0;
9
+ while (currentIndex < template.length) {
10
+ const openingBraceIndex = template.indexOf("{", currentIndex);
11
+ if (openingBraceIndex === -1) {
12
+ evaluatedTemplateArr.push(template.slice(currentIndex));
13
+ break;
14
+ }
15
+ evaluatedTemplateArr.push(template.slice(currentIndex, openingBraceIndex));
16
+ const closingBraceIndex = template.indexOf("}", openingBraceIndex);
17
+ if (closingBraceIndex === -1) {
18
+ evaluatedTemplateArr.push(template.slice(openingBraceIndex));
19
+ break;
20
+ }
21
+ if (template[openingBraceIndex + 1] === "{" && template[closingBraceIndex + 1] === "}") {
22
+ evaluatedTemplateArr.push(template.slice(openingBraceIndex + 1, closingBraceIndex));
23
+ currentIndex = closingBraceIndex + 2;
24
+ }
25
+ const parameterName = template.substring(openingBraceIndex + 1, closingBraceIndex);
26
+ if (parameterName.includes("#")) {
27
+ const [refName, attrName] = parameterName.split("#");
28
+ evaluatedTemplateArr.push(getAttr(templateContext[refName], attrName));
29
+ }
30
+ else {
31
+ evaluatedTemplateArr.push(templateContext[parameterName]);
32
+ }
33
+ currentIndex = closingBraceIndex + 1;
34
+ }
35
+ return evaluatedTemplateArr.join("");
24
36
  };
@@ -3,4 +3,4 @@ export declare const evaluateExpression: (
3
3
  obj: Expression,
4
4
  keyName: string,
5
5
  options: EvaluateOptions
6
- ) => any;
6
+ ) => import("../types").FunctionReturn;
@@ -2,4 +2,4 @@ import { EvaluateOptions } from "../types";
2
2
  export declare const evaluateTemplate: (
3
3
  template: string,
4
4
  options: EvaluateOptions
5
- ) => any;
5
+ ) => string;
@@ -1,2 +1,2 @@
1
1
  import { EvaluateOptions, Expression } from "../types";
2
- export declare const evaluateExpression: (obj: Expression, keyName: string, options: EvaluateOptions) => any;
2
+ export declare const evaluateExpression: (obj: Expression, keyName: string, options: EvaluateOptions) => import("../types").FunctionReturn;
@@ -1,2 +1,2 @@
1
1
  import { EvaluateOptions } from "../types";
2
- export declare const evaluateTemplate: (template: string, options: EvaluateOptions) => any;
2
+ export declare const evaluateTemplate: (template: string, options: EvaluateOptions) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/util-endpoints",
3
- "version": "3.200.0",
3
+ "version": "3.202.0",
4
4
  "description": "Utilities to help with endpoint resolution",
5
5
  "main": "./dist-cjs/index.js",
6
6
  "module": "./dist-es/index.js",
@@ -21,11 +21,11 @@
21
21
  },
22
22
  "license": "Apache-2.0",
23
23
  "dependencies": {
24
- "@aws-sdk/types": "3.200.0",
24
+ "@aws-sdk/types": "3.201.0",
25
25
  "tslib": "^2.3.1"
26
26
  },
27
27
  "engines": {
28
- "node": ">= 12.0.0"
28
+ "node": ">=14.0.0"
29
29
  },
30
30
  "typesVersions": {
31
31
  "<4.0": {