@aws-sdk/util-endpoints 3.201.0 → 3.208.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.
@@ -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.201.0",
3
+ "version": "3.208.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,7 +21,7 @@
21
21
  },
22
22
  "license": "Apache-2.0",
23
23
  "dependencies": {
24
- "@aws-sdk/types": "3.201.0",
24
+ "@aws-sdk/types": "3.208.0",
25
25
  "tslib": "^2.3.1"
26
26
  },
27
27
  "engines": {
package/CHANGELOG.md DELETED
@@ -1,220 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- # [3.201.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.200.0...v3.201.0) (2022-11-01)
7
-
8
-
9
- ### Features
10
-
11
- * 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))
12
-
13
-
14
-
15
-
16
-
17
- # [3.200.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.199.0...v3.200.0) (2022-10-31)
18
-
19
- **Note:** Version bump only for package @aws-sdk/util-endpoints
20
-
21
-
22
-
23
-
24
-
25
- # [3.198.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.197.0...v3.198.0) (2022-10-27)
26
-
27
-
28
- ### Features
29
-
30
- * **endpoint:** log endpoint decisions at debug level ([#4106](https://github.com/aws/aws-sdk-js-v3/issues/4106)) ([d600213](https://github.com/aws/aws-sdk-js-v3/commit/d600213292eb1bea870c43420367f78406db1c82))
31
-
32
-
33
-
34
-
35
-
36
- # [3.197.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.196.0...v3.197.0) (2022-10-26)
37
-
38
- **Note:** Version bump only for package @aws-sdk/util-endpoints
39
-
40
-
41
-
42
-
43
-
44
- # [3.196.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.195.0...v3.196.0) (2022-10-25)
45
-
46
-
47
- ### Features
48
-
49
- * **endpoint:** add remaining restJson1 services endpoint models ([#4090](https://github.com/aws/aws-sdk-js-v3/issues/4090)) ([998113b](https://github.com/aws/aws-sdk-js-v3/commit/998113bd0a70a7de4bf5d975cb5f7524098866a0))
50
-
51
-
52
-
53
-
54
-
55
- # [3.194.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.193.0...v3.194.0) (2022-10-21)
56
-
57
-
58
- ### Bug Fixes
59
-
60
- * **util-endpoints:** use default import for partitions.json ([#4072](https://github.com/aws/aws-sdk-js-v3/issues/4072)) ([f9bc7af](https://github.com/aws/aws-sdk-js-v3/commit/f9bc7afd7af7535c0de8123d0820faa8ebec7e16))
61
-
62
-
63
-
64
-
65
-
66
- # [3.193.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.192.0...v3.193.0) (2022-10-20)
67
-
68
- **Note:** Version bump only for package @aws-sdk/util-endpoints
69
-
70
-
71
-
72
-
73
-
74
- # [3.192.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.191.0...v3.192.0) (2022-10-19)
75
-
76
-
77
- ### Bug Fixes
78
-
79
- * **endpoint:** dedupe clientContext/builtIn params, fix s3 unit test ([#4051](https://github.com/aws/aws-sdk-js-v3/issues/4051)) ([947c8bc](https://github.com/aws/aws-sdk-js-v3/commit/947c8bce2798ae5ddc022d34f62aeeb60b4e6fde))
80
-
81
-
82
-
83
-
84
-
85
- # [3.190.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.189.0...v3.190.0) (2022-10-17)
86
-
87
-
88
- ### Bug Fixes
89
-
90
- * **endpoint:** endpoints 2.0 all-service TS compilation fixes ([#4043](https://github.com/aws/aws-sdk-js-v3/issues/4043)) ([f2da618](https://github.com/aws/aws-sdk-js-v3/commit/f2da6182298d4d6b02e84fb723492c07c27469a8))
91
-
92
-
93
-
94
-
95
-
96
- # [3.188.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.187.0...v3.188.0) (2022-10-13)
97
-
98
-
99
- ### Bug Fixes
100
-
101
- * **endpoint:** misc endpoints 2.0 fixes for s3 ([#4031](https://github.com/aws/aws-sdk-js-v3/issues/4031)) ([f8926a5](https://github.com/aws/aws-sdk-js-v3/commit/f8926a56cf9a25c2e6a5c91089543094e32d5c4b))
102
-
103
-
104
-
105
-
106
-
107
- # [3.186.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.185.0...v3.186.0) (2022-10-06)
108
-
109
- **Note:** Version bump only for package @aws-sdk/util-endpoints
110
-
111
-
112
-
113
-
114
-
115
- # [3.183.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.182.0...v3.183.0) (2022-10-03)
116
-
117
- **Note:** Version bump only for package @aws-sdk/util-endpoints
118
-
119
-
120
-
121
-
122
-
123
- # [3.182.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.181.0...v3.182.0) (2022-09-30)
124
-
125
-
126
- ### Bug Fixes
127
-
128
- * **endpoint:** misc fixes for endpoints 2.0 based on service unit tests ([#4002](https://github.com/aws/aws-sdk-js-v3/issues/4002)) ([77788f9](https://github.com/aws/aws-sdk-js-v3/commit/77788f9a9c7274d0cdec7832b6ed72325c9262e6))
129
-
130
-
131
-
132
-
133
-
134
- # [3.178.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.177.0...v3.178.0) (2022-09-23)
135
-
136
-
137
- ### Features
138
-
139
- * **endpoint:** endpoints 2.0 existing package changes ([#3947](https://github.com/aws/aws-sdk-js-v3/issues/3947)) ([df99fc3](https://github.com/aws/aws-sdk-js-v3/commit/df99fc33a43982e1c59000721a535f6fe77a3c23))
140
-
141
-
142
-
143
-
144
-
145
- # [3.174.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.173.0...v3.174.0) (2022-09-19)
146
-
147
-
148
- ### Features
149
-
150
- * **util-endpoints:** add aws.isVirtualHostableS3Bucket ([#3967](https://github.com/aws/aws-sdk-js-v3/issues/3967)) ([2fbe419](https://github.com/aws/aws-sdk-js-v3/commit/2fbe4199b971b0da966369c36a28521ba389a466))
151
-
152
-
153
-
154
-
155
-
156
- # [3.171.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.170.0...v3.171.0) (2022-09-14)
157
-
158
-
159
- ### Features
160
-
161
- * **endpoint:** util-endpoints and middleware-endpoint for endpoints 2.0 ([#3932](https://github.com/aws/aws-sdk-js-v3/issues/3932)) ([e81b7d0](https://github.com/aws/aws-sdk-js-v3/commit/e81b7d0920a74843a2a34857f41b0d6d93abc465))
162
-
163
-
164
-
165
-
166
-
167
- # [3.170.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.169.0...v3.170.0) (2022-09-13)
168
-
169
-
170
- ### Bug Fixes
171
-
172
- * **util-endpoints:** call multi-level functions from callFunction ([#3929](https://github.com/aws/aws-sdk-js-v3/issues/3929)) ([1209cb1](https://github.com/aws/aws-sdk-js-v3/commit/1209cb1613891496b3e03e6a61ff87fc721d1ccf))
173
- * **util-endpoints:** escape tilde when evaluating template ([#3934](https://github.com/aws/aws-sdk-js-v3/issues/3934)) ([5d7ef10](https://github.com/aws/aws-sdk-js-v3/commit/5d7ef10160456b7b872a1e7818dde7d73b4fb714))
174
- * **util-endpoints:** export parseArn from lib/aws ([#3931](https://github.com/aws/aws-sdk-js-v3/issues/3931)) ([1cee1f4](https://github.com/aws/aws-sdk-js-v3/commit/1cee1f4e41d1a660b4fbb7e06eecc22f2a9a82db))
175
- * **util-endpoints:** populate default params before checking for required values ([#3928](https://github.com/aws/aws-sdk-js-v3/issues/3928)) ([2561f60](https://github.com/aws/aws-sdk-js-v3/commit/2561f609f76b006bb39794a6cecfb6c0d68f9ef1))
176
- * **util-endpoints:** return null in parseArn for some empty elements ([#3935](https://github.com/aws/aws-sdk-js-v3/issues/3935)) ([f8bc8b3](https://github.com/aws/aws-sdk-js-v3/commit/f8bc8b3da798cb0c4c4d6fb21e8e88c9109e649b))
177
- * **util-endpoints:** skip evaluation for arg of type number ([#3936](https://github.com/aws/aws-sdk-js-v3/issues/3936)) ([aecd894](https://github.com/aws/aws-sdk-js-v3/commit/aecd89441ec92fc2be8cb4a3914ca7559e136d7d))
178
-
179
-
180
-
181
-
182
-
183
- # [3.168.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.167.0...v3.168.0) (2022-09-09)
184
-
185
- **Note:** Version bump only for package @aws-sdk/util-endpoints
186
-
187
-
188
-
189
-
190
-
191
- # [3.167.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.166.0...v3.167.0) (2022-09-08)
192
-
193
- **Note:** Version bump only for package @aws-sdk/util-endpoints
194
-
195
-
196
-
197
-
198
-
199
- # [3.162.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.161.0...v3.162.0) (2022-08-31)
200
-
201
- **Note:** Version bump only for package @aws-sdk/util-endpoints
202
-
203
-
204
-
205
-
206
-
207
- # [3.160.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.159.0...v3.160.0) (2022-08-29)
208
-
209
- **Note:** Version bump only for package @aws-sdk/util-endpoints
210
-
211
-
212
-
213
-
214
-
215
- # [3.159.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.158.0...v3.159.0) (2022-08-26)
216
-
217
-
218
- ### Features
219
-
220
- * **util-endpoints:** add ruleSet standard library ([#3880](https://github.com/aws/aws-sdk-js-v3/issues/3880)) ([4ffc67b](https://github.com/aws/aws-sdk-js-v3/commit/4ffc67b6f9c8349f93ccf91b9b3aa17d6a22b06e))