@cdklabs/cdk-ecs-codedeploy 0.0.436 → 0.0.438

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.
Files changed (177) hide show
  1. package/.jsii +3 -3
  2. package/.jsii.tabl.json +1 -1
  3. package/lib/api-canary/index.js +1 -1
  4. package/lib/ecs-appspec/index.js +1 -1
  5. package/lib/ecs-deployment/index.js +1 -1
  6. package/lib/ecs-patterns/application-load-balanced-codedeployed-fargate-service.js +1 -1
  7. package/node_modules/@aws-sdk/client-codedeploy/package.json +34 -34
  8. package/node_modules/@aws-sdk/core/dist-cjs/index.js +69 -50
  9. package/node_modules/@aws-sdk/core/dist-cjs/submodules/client/index.js +17 -0
  10. package/node_modules/@aws-sdk/core/dist-cjs/submodules/protocols/index.js +52 -50
  11. package/node_modules/@aws-sdk/core/dist-es/submodules/client/index.js +1 -0
  12. package/node_modules/@aws-sdk/core/dist-es/submodules/client/longPollMiddleware.js +15 -0
  13. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/ProtocolLib.js +11 -10
  14. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/UnionSerde.js +4 -1
  15. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsJsonRpcProtocol.js +4 -5
  16. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsRestJsonProtocol.js +2 -1
  17. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/JsonShapeSerializer.js +9 -7
  18. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/parseJsonBody.js +17 -17
  19. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/query/AwsQueryProtocol.js +3 -8
  20. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/xml/AwsRestXmlProtocol.js +2 -1
  21. package/node_modules/@aws-sdk/core/dist-types/submodules/client/index.d.ts +1 -0
  22. package/node_modules/@aws-sdk/core/dist-types/submodules/client/longPollMiddleware.d.ts +14 -0
  23. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/JsonShapeSerializer.d.ts +2 -2
  24. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/client/index.d.ts +1 -0
  25. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/client/longPollMiddleware.d.ts +15 -0
  26. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/JsonShapeSerializer.d.ts +1 -1
  27. package/node_modules/@aws-sdk/core/package.json +11 -11
  28. package/node_modules/@aws-sdk/credential-provider-env/package.json +5 -5
  29. package/node_modules/@aws-sdk/credential-provider-http/package.json +10 -10
  30. package/node_modules/@aws-sdk/credential-provider-ini/package.json +14 -14
  31. package/node_modules/@aws-sdk/credential-provider-login/package.json +8 -8
  32. package/node_modules/@aws-sdk/credential-provider-node/package.json +12 -12
  33. package/node_modules/@aws-sdk/credential-provider-process/package.json +6 -6
  34. package/node_modules/@aws-sdk/credential-provider-sso/package.json +8 -8
  35. package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +7 -7
  36. package/node_modules/@aws-sdk/middleware-host-header/package.json +4 -4
  37. package/node_modules/@aws-sdk/middleware-logger/package.json +3 -3
  38. package/node_modules/@aws-sdk/middleware-recursion-detection/package.json +4 -4
  39. package/node_modules/@aws-sdk/middleware-user-agent/package.json +8 -8
  40. package/node_modules/@aws-sdk/nested-clients/package.json +32 -32
  41. package/node_modules/@aws-sdk/region-config-resolver/package.json +5 -5
  42. package/node_modules/@aws-sdk/token-providers/package.json +7 -7
  43. package/node_modules/@aws-sdk/types/package.json +2 -2
  44. package/node_modules/@aws-sdk/util-endpoints/package.json +5 -5
  45. package/node_modules/@aws-sdk/util-user-agent-browser/package.json +3 -3
  46. package/node_modules/@aws-sdk/util-user-agent-node/package.json +5 -5
  47. package/node_modules/@aws-sdk/xml-builder/package.json +2 -2
  48. package/node_modules/@smithy/config-resolver/package.json +5 -5
  49. package/node_modules/@smithy/core/dist-cjs/index.js +2 -1
  50. package/node_modules/@smithy/core/dist-cjs/submodules/cbor/index.js +32 -14
  51. package/node_modules/@smithy/core/dist-cjs/submodules/endpoints/index.js +2 -2
  52. package/node_modules/@smithy/core/dist-cjs/submodules/event-streams/index.js +16 -8
  53. package/node_modules/@smithy/core/dist-cjs/submodules/protocols/index.js +17 -10
  54. package/node_modules/@smithy/core/dist-cjs/submodules/schema/index.js +6 -1
  55. package/node_modules/@smithy/core/dist-cjs/submodules/serde/index.js +6 -3
  56. package/node_modules/@smithy/core/dist-cjs/util-identity-and-auth/DefaultIdentityProviderConfig.js +2 -1
  57. package/node_modules/@smithy/core/dist-es/submodules/cbor/CborCodec.js +23 -11
  58. package/node_modules/@smithy/core/dist-es/submodules/cbor/parseCborBody.js +9 -3
  59. package/node_modules/@smithy/core/dist-es/submodules/endpoints/toEndpointV1.js +2 -2
  60. package/node_modules/@smithy/core/dist-es/submodules/event-streams/EventStreamSerde.js +16 -8
  61. package/node_modules/@smithy/core/dist-es/submodules/protocols/HttpBindingProtocol.js +9 -4
  62. package/node_modules/@smithy/core/dist-es/submodules/protocols/HttpProtocol.js +8 -6
  63. package/node_modules/@smithy/core/dist-es/submodules/schema/TypeRegistry.js +6 -1
  64. package/node_modules/@smithy/core/dist-es/submodules/serde/parse-utils.js +6 -3
  65. package/node_modules/@smithy/core/dist-es/util-identity-and-auth/DefaultIdentityProviderConfig.js +2 -1
  66. package/node_modules/@smithy/core/dist-types/submodules/schema/TypeRegistry.d.ts +1 -1
  67. package/node_modules/@smithy/core/package.json +7 -7
  68. package/node_modules/@smithy/credential-provider-imds/package.json +5 -5
  69. package/node_modules/@smithy/fetch-http-handler/package.json +5 -5
  70. package/node_modules/@smithy/hash-node/package.json +2 -2
  71. package/node_modules/@smithy/invalid-dependency/package.json +2 -2
  72. package/node_modules/@smithy/middleware-content-length/package.json +3 -3
  73. package/node_modules/@smithy/middleware-endpoint/package.json +8 -8
  74. package/node_modules/@smithy/middleware-retry/package.json +9 -9
  75. package/node_modules/@smithy/middleware-serde/package.json +4 -4
  76. package/node_modules/@smithy/middleware-stack/package.json +2 -2
  77. package/node_modules/@smithy/node-config-provider/package.json +4 -4
  78. package/node_modules/@smithy/node-http-handler/dist-cjs/index.js +191 -96
  79. package/node_modules/@smithy/node-http-handler/dist-es/http2/ClientHttp2SessionRef.js +45 -0
  80. package/node_modules/@smithy/node-http-handler/dist-es/node-http2-connection-manager.js +71 -35
  81. package/node_modules/@smithy/node-http-handler/dist-es/node-http2-connection-pool.js +32 -18
  82. package/node_modules/@smithy/node-http-handler/dist-es/node-http2-handler.js +44 -43
  83. package/node_modules/@smithy/node-http-handler/dist-types/http2/ClientHttp2SessionRef.d.ts +42 -0
  84. package/node_modules/@smithy/node-http-handler/dist-types/node-http2-connection-manager.d.ts +34 -14
  85. package/node_modules/@smithy/node-http-handler/dist-types/node-http2-connection-pool.d.ts +32 -8
  86. package/node_modules/@smithy/node-http-handler/dist-types/node-http2-handler.d.ts +14 -6
  87. package/node_modules/@smithy/node-http-handler/package.json +5 -5
  88. package/node_modules/@smithy/property-provider/package.json +2 -2
  89. package/node_modules/@smithy/protocol-http/package.json +2 -2
  90. package/node_modules/@smithy/querystring-builder/package.json +2 -2
  91. package/node_modules/@smithy/querystring-parser/package.json +2 -2
  92. package/node_modules/@smithy/service-error-classification/dist-cjs/index.js +5 -0
  93. package/node_modules/@smithy/service-error-classification/dist-es/index.js +4 -0
  94. package/node_modules/@smithy/service-error-classification/dist-types/index.d.ts +6 -0
  95. package/node_modules/@smithy/service-error-classification/package.json +2 -2
  96. package/node_modules/@smithy/shared-ini-file-loader/package.json +2 -2
  97. package/node_modules/@smithy/signature-v4/dist-cjs/index.js +11 -5
  98. package/node_modules/@smithy/signature-v4/dist-es/SignatureV4.js +11 -5
  99. package/node_modules/@smithy/signature-v4/dist-types/SignatureV4.d.ts +3 -3
  100. package/node_modules/@smithy/signature-v4/package.json +4 -4
  101. package/node_modules/@smithy/smithy-client/dist-cjs/index.js +8 -1
  102. package/node_modules/@smithy/smithy-client/dist-es/command.js +8 -1
  103. package/node_modules/@smithy/smithy-client/package.json +7 -7
  104. package/node_modules/@smithy/types/dist-types/connection/config.d.ts +5 -0
  105. package/node_modules/@smithy/types/dist-types/signature.d.ts +20 -3
  106. package/node_modules/@smithy/types/package.json +1 -1
  107. package/node_modules/@smithy/url-parser/package.json +3 -3
  108. package/node_modules/@smithy/util-defaults-mode-browser/package.json +4 -4
  109. package/node_modules/@smithy/util-defaults-mode-node/package.json +7 -7
  110. package/node_modules/@smithy/util-endpoints/dist-cjs/index.js +212 -111
  111. package/node_modules/@smithy/util-endpoints/dist-es/bdd/BinaryDecisionDiagram.js +15 -0
  112. package/node_modules/@smithy/util-endpoints/dist-es/decideEndpoint.js +42 -0
  113. package/node_modules/@smithy/util-endpoints/dist-es/index.js +2 -0
  114. package/node_modules/@smithy/util-endpoints/dist-es/lib/coalesce.js +8 -0
  115. package/node_modules/@smithy/util-endpoints/dist-es/lib/getAttr.js +2 -1
  116. package/node_modules/@smithy/util-endpoints/dist-es/lib/index.js +3 -0
  117. package/node_modules/@smithy/util-endpoints/dist-es/lib/ite.js +3 -0
  118. package/node_modules/@smithy/util-endpoints/dist-es/lib/split.js +13 -0
  119. package/node_modules/@smithy/util-endpoints/dist-es/lib/substring.js +1 -1
  120. package/node_modules/@smithy/util-endpoints/dist-es/resolveEndpoint.js +8 -13
  121. package/node_modules/@smithy/util-endpoints/dist-es/utils/endpointFunctions.js +4 -1
  122. package/node_modules/@smithy/util-endpoints/dist-es/utils/evaluateCondition.js +9 -7
  123. package/node_modules/@smithy/util-endpoints/dist-es/utils/evaluateConditions.js +12 -8
  124. package/node_modules/@smithy/util-endpoints/dist-es/utils/evaluateEndpointRule.js +14 -13
  125. package/node_modules/@smithy/util-endpoints/dist-es/utils/evaluateErrorRule.js +7 -4
  126. package/node_modules/@smithy/util-endpoints/dist-es/utils/evaluateExpression.js +22 -5
  127. package/node_modules/@smithy/util-endpoints/dist-es/utils/evaluateRules.js +4 -4
  128. package/node_modules/@smithy/util-endpoints/dist-es/utils/evaluateTemplate.js +3 -6
  129. package/node_modules/@smithy/util-endpoints/dist-es/utils/getEndpointHeaders.js +5 -5
  130. package/node_modules/@smithy/util-endpoints/dist-es/utils/getEndpointProperties.js +4 -4
  131. package/node_modules/@smithy/util-endpoints/dist-es/utils/getReferenceValue.js +1 -5
  132. package/node_modules/@smithy/util-endpoints/dist-types/bdd/BinaryDecisionDiagram.d.ts +22 -0
  133. package/node_modules/@smithy/util-endpoints/dist-types/decideEndpoint.d.ts +7 -0
  134. package/node_modules/@smithy/util-endpoints/dist-types/index.d.ts +2 -0
  135. package/node_modules/@smithy/util-endpoints/dist-types/lib/coalesce.d.ts +7 -0
  136. package/node_modules/@smithy/util-endpoints/dist-types/lib/index.d.ts +3 -0
  137. package/node_modules/@smithy/util-endpoints/dist-types/lib/ite.d.ts +6 -0
  138. package/node_modules/@smithy/util-endpoints/dist-types/lib/split.d.ts +11 -0
  139. package/node_modules/@smithy/util-endpoints/dist-types/types/shared.d.ts +3 -3
  140. package/node_modules/@smithy/util-endpoints/dist-types/utils/endpointFunctions.d.ts +2 -11
  141. package/node_modules/@smithy/util-endpoints/dist-types/utils/evaluateCondition.d.ts +6 -3
  142. package/node_modules/@smithy/util-endpoints/dist-types/utils/evaluateConditions.d.ts +3 -3
  143. package/node_modules/@smithy/util-endpoints/dist-types/utils/getEndpointHeaders.d.ts +1 -1
  144. package/node_modules/@smithy/util-endpoints/dist-types/utils/getEndpointProperties.d.ts +2 -2
  145. package/node_modules/@smithy/util-endpoints/dist-types/utils/getReferenceValue.d.ts +3 -1
  146. package/node_modules/@smithy/util-endpoints/package.json +3 -3
  147. package/node_modules/@smithy/util-middleware/package.json +2 -2
  148. package/node_modules/@smithy/util-retry/dist-cjs/index.js +6 -0
  149. package/node_modules/@smithy/util-retry/dist-es/AdaptiveRetryStrategy.js +3 -0
  150. package/node_modules/@smithy/util-retry/dist-es/StandardRetryStrategy.js +3 -0
  151. package/node_modules/@smithy/util-retry/dist-types/AdaptiveRetryStrategy.d.ts +5 -0
  152. package/node_modules/@smithy/util-retry/dist-types/StandardRetryStrategy.d.ts +5 -0
  153. package/node_modules/@smithy/util-retry/package.json +3 -3
  154. package/node_modules/@smithy/util-stream/package.json +4 -4
  155. package/node_modules/@smithy/util-waiter/package.json +3 -3
  156. package/node_modules/fast-xml-builder/package.json +1 -1
  157. package/node_modules/fast-xml-builder/src/fxb.js +6 -2
  158. package/node_modules/fast-xml-builder/src/orderedJs2Xml.js +16 -2
  159. package/node_modules/path-expression-matcher/README.md +214 -62
  160. package/node_modules/path-expression-matcher/lib/pem.cjs +1 -1
  161. package/node_modules/path-expression-matcher/lib/pem.d.cts +111 -0
  162. package/node_modules/path-expression-matcher/lib/pem.min.js +1 -1
  163. package/node_modules/path-expression-matcher/lib/pem.min.js.map +1 -1
  164. package/node_modules/path-expression-matcher/package.json +1 -1
  165. package/node_modules/path-expression-matcher/src/Expression.js +2 -2
  166. package/node_modules/path-expression-matcher/src/ExpressionSet.js +209 -0
  167. package/node_modules/path-expression-matcher/src/Matcher.js +235 -177
  168. package/node_modules/path-expression-matcher/src/index.d.ts +199 -194
  169. package/node_modules/path-expression-matcher/src/index.js +3 -2
  170. package/node_modules/strnum/package.json +1 -1
  171. package/package.json +6 -6
  172. package/node_modules/strnum/.github/SECURITY.md +0 -5
  173. package/node_modules/strnum/.vscode/launch.json +0 -25
  174. package/node_modules/strnum/algo.stflow +0 -84
  175. package/node_modules/strnum/tests/infinity_test.js +0 -18
  176. package/node_modules/strnum/tests/strnum_test.js +0 -175
  177. package/node_modules/strnum/tests/temp.js +0 -8
@@ -2,6 +2,22 @@
2
2
 
3
3
  var types = require('@smithy/types');
4
4
 
5
+ class BinaryDecisionDiagram {
6
+ nodes;
7
+ root;
8
+ conditions;
9
+ results;
10
+ constructor(bdd, root, conditions, results) {
11
+ this.nodes = bdd;
12
+ this.root = root;
13
+ this.conditions = conditions;
14
+ this.results = results;
15
+ }
16
+ static from(bdd, root, conditions, results) {
17
+ return new BinaryDecisionDiagram(bdd, root, conditions, results);
18
+ }
19
+ }
20
+
5
21
  class EndpointCache {
6
22
  capacity;
7
23
  data = new Map();
@@ -53,24 +69,12 @@ class EndpointCache {
53
69
  }
54
70
  }
55
71
 
56
- const IP_V4_REGEX = new RegExp(`^(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}$`);
57
- const isIpAddress = (value) => IP_V4_REGEX.test(value) || (value.startsWith("[") && value.endsWith("]"));
58
-
59
- const VALID_HOST_LABEL_REGEX = new RegExp(`^(?!.*-$)(?!-)[a-zA-Z0-9-]{1,63}$`);
60
- const isValidHostLabel = (value, allowSubDomains = false) => {
61
- if (!allowSubDomains) {
62
- return VALID_HOST_LABEL_REGEX.test(value);
63
- }
64
- const labels = value.split(".");
65
- for (const label of labels) {
66
- if (!isValidHostLabel(label)) {
67
- return false;
68
- }
72
+ class EndpointError extends Error {
73
+ constructor(message) {
74
+ super(message);
75
+ this.name = "EndpointError";
69
76
  }
70
- return true;
71
- };
72
-
73
- const customEndpointFunctions = {};
77
+ }
74
78
 
75
79
  const debugId = "endpoints";
76
80
 
@@ -87,15 +91,19 @@ function toDebugString(input) {
87
91
  return JSON.stringify(input, null, 2);
88
92
  }
89
93
 
90
- class EndpointError extends Error {
91
- constructor(message) {
92
- super(message);
93
- this.name = "EndpointError";
94
- }
95
- }
94
+ const customEndpointFunctions = {};
96
95
 
97
96
  const booleanEquals = (value1, value2) => value1 === value2;
98
97
 
98
+ function coalesce(...args) {
99
+ for (const arg of args) {
100
+ if (arg != null) {
101
+ return arg;
102
+ }
103
+ }
104
+ return undefined;
105
+ }
106
+
99
107
  const getAttrPathList = (path) => {
100
108
  const parts = path.split(".");
101
109
  const pathList = [];
@@ -126,15 +134,37 @@ const getAttr = (value, path) => getAttrPathList(path).reduce((acc, index) => {
126
134
  throw new EndpointError(`Index '${index}' in '${path}' not found in '${JSON.stringify(value)}'`);
127
135
  }
128
136
  else if (Array.isArray(acc)) {
129
- return acc[parseInt(index)];
137
+ const i = parseInt(index);
138
+ return acc[i < 0 ? acc.length + i : i];
130
139
  }
131
140
  return acc[index];
132
141
  }, value);
133
142
 
134
143
  const isSet = (value) => value != null;
135
144
 
145
+ const VALID_HOST_LABEL_REGEX = new RegExp(`^(?!.*-$)(?!-)[a-zA-Z0-9-]{1,63}$`);
146
+ const isValidHostLabel = (value, allowSubDomains = false) => {
147
+ if (!allowSubDomains) {
148
+ return VALID_HOST_LABEL_REGEX.test(value);
149
+ }
150
+ const labels = value.split(".");
151
+ for (const label of labels) {
152
+ if (!isValidHostLabel(label)) {
153
+ return false;
154
+ }
155
+ }
156
+ return true;
157
+ };
158
+
159
+ function ite(condition, trueValue, falseValue) {
160
+ return condition ? trueValue : falseValue;
161
+ }
162
+
136
163
  const not = (value) => !value;
137
164
 
165
+ const IP_V4_REGEX = new RegExp(`^(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}$`);
166
+ const isIpAddress = (value) => IP_V4_REGEX.test(value) || (value.startsWith("[") && value.endsWith("]"));
167
+
138
168
  const DEFAULT_PORTS = {
139
169
  [types.EndpointURLScheme.HTTP]: 80,
140
170
  [types.EndpointURLScheme.HTTPS]: 443,
@@ -185,10 +215,24 @@ const parseURL = (value) => {
185
215
  };
186
216
  };
187
217
 
218
+ function split(value, delimiter, limit) {
219
+ if (limit === 1) {
220
+ return [value];
221
+ }
222
+ if (value === "") {
223
+ return [""];
224
+ }
225
+ const parts = value.split(delimiter);
226
+ if (limit === 0) {
227
+ return parts;
228
+ }
229
+ return parts.slice(0, limit - 1).concat(parts.slice(1).join(delimiter));
230
+ }
231
+
188
232
  const stringEquals = (value1, value2) => value1 === value2;
189
233
 
190
234
  const substring = (input, start, stop, reverse) => {
191
- if (start >= stop || input.length < stop || /[^\u0000-\u007f]/.test(input)) {
235
+ if (input == null || start >= stop || input.length < stop || /[^\u0000-\u007f]/.test(input)) {
192
236
  return null;
193
237
  }
194
238
  if (!reverse) {
@@ -201,11 +245,14 @@ const uriEncode = (value) => encodeURIComponent(value).replace(/[!*'()]/g, (c) =
201
245
 
202
246
  const endpointFunctions = {
203
247
  booleanEquals,
248
+ coalesce,
204
249
  getAttr,
205
250
  isSet,
206
251
  isValidHostLabel,
252
+ ite,
207
253
  not,
208
254
  parseURL,
255
+ split,
209
256
  stringEquals,
210
257
  substring,
211
258
  uriEncode,
@@ -213,10 +260,7 @@ const endpointFunctions = {
213
260
 
214
261
  const evaluateTemplate = (template, options) => {
215
262
  const evaluatedTemplateArr = [];
216
- const templateContext = {
217
- ...options.endpointParams,
218
- ...options.referenceRecord,
219
- };
263
+ const { referenceRecord, endpointParams } = options;
220
264
  let currentIndex = 0;
221
265
  while (currentIndex < template.length) {
222
266
  const openingBraceIndex = template.indexOf("{", currentIndex);
@@ -237,10 +281,10 @@ const evaluateTemplate = (template, options) => {
237
281
  const parameterName = template.substring(openingBraceIndex + 1, closingBraceIndex);
238
282
  if (parameterName.includes("#")) {
239
283
  const [refName, attrName] = parameterName.split("#");
240
- evaluatedTemplateArr.push(getAttr(templateContext[refName], attrName));
284
+ evaluatedTemplateArr.push(getAttr((referenceRecord[refName] ?? endpointParams[refName]), attrName));
241
285
  }
242
286
  else {
243
- evaluatedTemplateArr.push(templateContext[parameterName]);
287
+ evaluatedTemplateArr.push((referenceRecord[parameterName] ?? endpointParams[parameterName]));
244
288
  }
245
289
  currentIndex = closingBraceIndex + 1;
246
290
  }
@@ -248,11 +292,7 @@ const evaluateTemplate = (template, options) => {
248
292
  };
249
293
 
250
294
  const getReferenceValue = ({ ref }, options) => {
251
- const referenceRecord = {
252
- ...options.endpointParams,
253
- ...options.referenceRecord,
254
- };
255
- return referenceRecord[ref];
295
+ return options.referenceRecord[ref] ?? options.endpointParams[ref];
256
296
  };
257
297
 
258
298
  const evaluateExpression = (obj, keyName, options) => {
@@ -268,66 +308,64 @@ const evaluateExpression = (obj, keyName, options) => {
268
308
  throw new EndpointError(`'${keyName}': ${String(obj)} is not a string, function or reference.`);
269
309
  };
270
310
  const callFunction = ({ fn, argv }, options) => {
271
- const evaluatedArgs = argv.map((arg) => ["boolean", "number"].includes(typeof arg) ? arg : group$2.evaluateExpression(arg, "arg", options));
272
- const fnSegments = fn.split(".");
273
- if (fnSegments[0] in customEndpointFunctions && fnSegments[1] != null) {
274
- return customEndpointFunctions[fnSegments[0]][fnSegments[1]](...evaluatedArgs);
311
+ const evaluatedArgs = Array(argv.length);
312
+ for (let i = 0; i < evaluatedArgs.length; ++i) {
313
+ const arg = argv[i];
314
+ if (typeof arg === "boolean" || typeof arg === "number") {
315
+ evaluatedArgs[i] = arg;
316
+ }
317
+ else {
318
+ evaluatedArgs[i] = group$2.evaluateExpression(arg, "arg", options);
319
+ }
320
+ }
321
+ const namespaceSeparatorIndex = fn.indexOf(".");
322
+ if (namespaceSeparatorIndex !== -1) {
323
+ const namespaceFunctions = customEndpointFunctions[fn.slice(0, namespaceSeparatorIndex)];
324
+ const customFunction = namespaceFunctions?.[fn.slice(namespaceSeparatorIndex + 1)];
325
+ if (typeof customFunction === "function") {
326
+ return customFunction(...evaluatedArgs);
327
+ }
328
+ }
329
+ const callable = endpointFunctions[fn];
330
+ if (typeof callable === "function") {
331
+ return callable(...evaluatedArgs);
275
332
  }
276
- return endpointFunctions[fn](...evaluatedArgs);
333
+ throw new Error(`function ${fn} not loaded in endpointFunctions.`);
277
334
  };
278
335
  const group$2 = {
279
336
  evaluateExpression,
280
337
  callFunction,
281
338
  };
282
339
 
283
- const evaluateCondition = ({ assign, ...fnArgs }, options) => {
340
+ const evaluateCondition = (condition, options) => {
341
+ const { assign } = condition;
284
342
  if (assign && assign in options.referenceRecord) {
285
343
  throw new EndpointError(`'${assign}' is already defined in Reference Record.`);
286
344
  }
287
- const value = callFunction(fnArgs, options);
288
- options.logger?.debug?.(`${debugId} evaluateCondition: ${toDebugString(fnArgs)} = ${toDebugString(value)}`);
289
- return {
290
- result: value === "" ? true : !!value,
291
- ...(assign != null && { toAssign: { name: assign, value } }),
292
- };
293
- };
294
-
295
- const evaluateConditions = (conditions = [], options) => {
296
- const conditionsReferenceRecord = {};
297
- for (const condition of conditions) {
298
- const { result, toAssign } = evaluateCondition(condition, {
299
- ...options,
300
- referenceRecord: {
301
- ...options.referenceRecord,
302
- ...conditionsReferenceRecord,
303
- },
304
- });
305
- if (!result) {
306
- return { result };
307
- }
308
- if (toAssign) {
309
- conditionsReferenceRecord[toAssign.name] = toAssign.value;
310
- options.logger?.debug?.(`${debugId} assign: ${toAssign.name} := ${toDebugString(toAssign.value)}`);
311
- }
345
+ const value = callFunction(condition, options);
346
+ options.logger?.debug?.(`${debugId} evaluateCondition: ${toDebugString(condition)} = ${toDebugString(value)}`);
347
+ const result = value === "" ? true : !!value;
348
+ if (assign != null) {
349
+ return { result, toAssign: { name: assign, value } };
312
350
  }
313
- return { result: true, referenceRecord: conditionsReferenceRecord };
351
+ return { result };
314
352
  };
315
353
 
316
- const getEndpointHeaders = (headers, options) => Object.entries(headers).reduce((acc, [headerKey, headerVal]) => ({
317
- ...acc,
318
- [headerKey]: headerVal.map((headerValEntry) => {
354
+ const getEndpointHeaders = (headers, options) => Object.entries(headers ?? {}).reduce((acc, [headerKey, headerVal]) => {
355
+ acc[headerKey] = headerVal.map((headerValEntry) => {
319
356
  const processedExpr = evaluateExpression(headerValEntry, "Header value entry", options);
320
357
  if (typeof processedExpr !== "string") {
321
358
  throw new EndpointError(`Header '${headerKey}' value '${processedExpr}' is not a string`);
322
359
  }
323
360
  return processedExpr;
324
- }),
325
- }), {});
361
+ });
362
+ return acc;
363
+ }, {});
326
364
 
327
- const getEndpointProperties = (properties, options) => Object.entries(properties).reduce((acc, [propertyKey, propertyVal]) => ({
328
- ...acc,
329
- [propertyKey]: group$1.getEndpointProperty(propertyVal, options),
330
- }), {});
365
+ const getEndpointProperties = (properties, options) => Object.entries(properties).reduce((acc, [propertyKey, propertyVal]) => {
366
+ acc[propertyKey] = group$1.getEndpointProperty(propertyVal, options);
367
+ return acc;
368
+ }, {});
331
369
  const getEndpointProperty = (property, options) => {
332
370
  if (Array.isArray(property)) {
333
371
  return property.map((propertyEntry) => getEndpointProperty(propertyEntry, options));
@@ -365,27 +403,90 @@ const getEndpointUrl = (endpointUrl, options) => {
365
403
  throw new EndpointError(`Endpoint URL must be a string, got ${typeof expression}`);
366
404
  };
367
405
 
406
+ const RESULT = 100_000_000;
407
+ const decideEndpoint = (bdd, options) => {
408
+ const { nodes, root, results, conditions } = bdd;
409
+ let ref = root;
410
+ const referenceRecord = {};
411
+ const closure = {
412
+ referenceRecord,
413
+ endpointParams: options.endpointParams,
414
+ logger: options.logger,
415
+ };
416
+ while (ref !== 1 && ref !== -1 && ref < RESULT) {
417
+ const node_i = 3 * (Math.abs(ref) - 1);
418
+ const [condition_i, highRef, lowRef] = [nodes[node_i], nodes[node_i + 1], nodes[node_i + 2]];
419
+ const [fn, argv, assign] = conditions[condition_i];
420
+ const evaluation = evaluateCondition({ fn, assign, argv }, closure);
421
+ if (evaluation.toAssign) {
422
+ const { name, value } = evaluation.toAssign;
423
+ referenceRecord[name] = value;
424
+ }
425
+ ref = ref >= 0 === evaluation.result ? highRef : lowRef;
426
+ }
427
+ if (ref >= RESULT) {
428
+ const result = results[ref - RESULT];
429
+ if (result[0] === -1) {
430
+ const [, errorExpression] = result;
431
+ throw new EndpointError(evaluateExpression(errorExpression, "Error", closure));
432
+ }
433
+ const [url, properties, headers] = result;
434
+ return {
435
+ url: getEndpointUrl(url, closure),
436
+ properties: getEndpointProperties(properties, closure),
437
+ headers: getEndpointHeaders(headers ?? {}, closure),
438
+ };
439
+ }
440
+ throw new EndpointError(`No matching endpoint.`);
441
+ };
442
+
443
+ const evaluateConditions = (conditions = [], options) => {
444
+ const conditionsReferenceRecord = {};
445
+ const conditionOptions = {
446
+ ...options,
447
+ referenceRecord: { ...options.referenceRecord },
448
+ };
449
+ let didAssign = false;
450
+ for (const condition of conditions) {
451
+ const { result, toAssign } = evaluateCondition(condition, conditionOptions);
452
+ if (!result) {
453
+ return { result };
454
+ }
455
+ if (toAssign) {
456
+ didAssign = true;
457
+ conditionsReferenceRecord[toAssign.name] = toAssign.value;
458
+ conditionOptions.referenceRecord[toAssign.name] = toAssign.value;
459
+ options.logger?.debug?.(`${debugId} assign: ${toAssign.name} := ${toDebugString(toAssign.value)}`);
460
+ }
461
+ }
462
+ if (didAssign) {
463
+ return { result: true, referenceRecord: conditionsReferenceRecord };
464
+ }
465
+ return { result: true };
466
+ };
467
+
368
468
  const evaluateEndpointRule = (endpointRule, options) => {
369
469
  const { conditions, endpoint } = endpointRule;
370
470
  const { result, referenceRecord } = evaluateConditions(conditions, options);
371
471
  if (!result) {
372
472
  return;
373
473
  }
374
- const endpointRuleOptions = {
375
- ...options,
376
- referenceRecord: { ...options.referenceRecord, ...referenceRecord },
377
- };
474
+ const endpointRuleOptions = referenceRecord
475
+ ? {
476
+ ...options,
477
+ referenceRecord: { ...options.referenceRecord, ...referenceRecord },
478
+ }
479
+ : options;
378
480
  const { url, properties, headers } = endpoint;
379
481
  options.logger?.debug?.(`${debugId} Resolving endpoint from template: ${toDebugString(endpoint)}`);
380
- return {
381
- ...(headers != undefined && {
382
- headers: getEndpointHeaders(headers, endpointRuleOptions),
383
- }),
384
- ...(properties != undefined && {
385
- properties: getEndpointProperties(properties, endpointRuleOptions),
386
- }),
387
- url: getEndpointUrl(url, endpointRuleOptions),
388
- };
482
+ const endpointToReturn = { url: getEndpointUrl(url, endpointRuleOptions) };
483
+ if (headers != null) {
484
+ endpointToReturn.headers = getEndpointHeaders(headers, endpointRuleOptions);
485
+ }
486
+ if (properties != null) {
487
+ endpointToReturn.properties = getEndpointProperties(properties, endpointRuleOptions);
488
+ }
489
+ return endpointToReturn;
389
490
  };
390
491
 
391
492
  const evaluateErrorRule = (errorRule, options) => {
@@ -394,10 +495,13 @@ const evaluateErrorRule = (errorRule, options) => {
394
495
  if (!result) {
395
496
  return;
396
497
  }
397
- throw new EndpointError(evaluateExpression(error, "Error", {
398
- ...options,
399
- referenceRecord: { ...options.referenceRecord, ...referenceRecord },
400
- }));
498
+ const errorRuleOptions = referenceRecord
499
+ ? {
500
+ ...options,
501
+ referenceRecord: { ...options.referenceRecord, ...referenceRecord },
502
+ }
503
+ : options;
504
+ throw new EndpointError(evaluateExpression(error, "Error", errorRuleOptions));
401
505
  };
402
506
 
403
507
  const evaluateRules = (rules, options) => {
@@ -429,10 +533,10 @@ const evaluateTreeRule = (treeRule, options) => {
429
533
  if (!result) {
430
534
  return;
431
535
  }
432
- return group.evaluateRules(rules, {
433
- ...options,
434
- referenceRecord: { ...options.referenceRecord, ...referenceRecord },
435
- });
536
+ const treeRuleOptions = referenceRecord
537
+ ? { ...options, referenceRecord: { ...options.referenceRecord, ...referenceRecord } }
538
+ : options;
539
+ return group.evaluateRules(rules, treeRuleOptions);
436
540
  };
437
541
  const group = {
438
542
  evaluateRules,
@@ -443,20 +547,15 @@ const resolveEndpoint = (ruleSetObject, options) => {
443
547
  const { endpointParams, logger } = options;
444
548
  const { parameters, rules } = ruleSetObject;
445
549
  options.logger?.debug?.(`${debugId} Initial EndpointParams: ${toDebugString(endpointParams)}`);
446
- const paramsWithDefault = Object.entries(parameters)
447
- .filter(([, v]) => v.default != null)
448
- .map(([k, v]) => [k, v.default]);
449
- if (paramsWithDefault.length > 0) {
450
- for (const [paramKey, paramDefaultValue] of paramsWithDefault) {
451
- endpointParams[paramKey] = endpointParams[paramKey] ?? paramDefaultValue;
550
+ for (const paramKey in parameters) {
551
+ const parameter = parameters[paramKey];
552
+ const endpointParam = endpointParams[paramKey];
553
+ if (endpointParam == null && parameter.default != null) {
554
+ endpointParams[paramKey] = parameter.default;
555
+ continue;
452
556
  }
453
- }
454
- const requiredParams = Object.entries(parameters)
455
- .filter(([, v]) => v.required)
456
- .map(([k]) => k);
457
- for (const requiredParam of requiredParams) {
458
- if (endpointParams[requiredParam] == null) {
459
- throw new EndpointError(`Missing required parameter: '${requiredParam}'`);
557
+ if (parameter.required && endpointParam == null) {
558
+ throw new EndpointError(`Missing required parameter: '${paramKey}'`);
460
559
  }
461
560
  }
462
561
  const endpoint = evaluateRules(rules, { endpointParams, logger, referenceRecord: {} });
@@ -464,9 +563,11 @@ const resolveEndpoint = (ruleSetObject, options) => {
464
563
  return endpoint;
465
564
  };
466
565
 
566
+ exports.BinaryDecisionDiagram = BinaryDecisionDiagram;
467
567
  exports.EndpointCache = EndpointCache;
468
568
  exports.EndpointError = EndpointError;
469
569
  exports.customEndpointFunctions = customEndpointFunctions;
570
+ exports.decideEndpoint = decideEndpoint;
470
571
  exports.isIpAddress = isIpAddress;
471
572
  exports.isValidHostLabel = isValidHostLabel;
472
573
  exports.resolveEndpoint = resolveEndpoint;
@@ -0,0 +1,15 @@
1
+ export class BinaryDecisionDiagram {
2
+ nodes;
3
+ root;
4
+ conditions;
5
+ results;
6
+ constructor(bdd, root, conditions, results) {
7
+ this.nodes = bdd;
8
+ this.root = root;
9
+ this.conditions = conditions;
10
+ this.results = results;
11
+ }
12
+ static from(bdd, root, conditions, results) {
13
+ return new BinaryDecisionDiagram(bdd, root, conditions, results);
14
+ }
15
+ }
@@ -0,0 +1,42 @@
1
+ import { EndpointError } from "./types";
2
+ import { evaluateCondition } from "./utils/evaluateCondition";
3
+ import { evaluateExpression } from "./utils/evaluateExpression";
4
+ import { getEndpointHeaders } from "./utils/getEndpointHeaders";
5
+ import { getEndpointProperties } from "./utils/getEndpointProperties";
6
+ import { getEndpointUrl } from "./utils/getEndpointUrl";
7
+ const RESULT = 100_000_000;
8
+ export const decideEndpoint = (bdd, options) => {
9
+ const { nodes, root, results, conditions } = bdd;
10
+ let ref = root;
11
+ const referenceRecord = {};
12
+ const closure = {
13
+ referenceRecord,
14
+ endpointParams: options.endpointParams,
15
+ logger: options.logger,
16
+ };
17
+ while (ref !== 1 && ref !== -1 && ref < RESULT) {
18
+ const node_i = 3 * (Math.abs(ref) - 1);
19
+ const [condition_i, highRef, lowRef] = [nodes[node_i], nodes[node_i + 1], nodes[node_i + 2]];
20
+ const [fn, argv, assign] = conditions[condition_i];
21
+ const evaluation = evaluateCondition({ fn, assign, argv }, closure);
22
+ if (evaluation.toAssign) {
23
+ const { name, value } = evaluation.toAssign;
24
+ referenceRecord[name] = value;
25
+ }
26
+ ref = ref >= 0 === evaluation.result ? highRef : lowRef;
27
+ }
28
+ if (ref >= RESULT) {
29
+ const result = results[ref - RESULT];
30
+ if (result[0] === -1) {
31
+ const [, errorExpression] = result;
32
+ throw new EndpointError(evaluateExpression(errorExpression, "Error", closure));
33
+ }
34
+ const [url, properties, headers] = result;
35
+ return {
36
+ url: getEndpointUrl(url, closure),
37
+ properties: getEndpointProperties(properties, closure),
38
+ headers: getEndpointHeaders(headers ?? {}, closure),
39
+ };
40
+ }
41
+ throw new EndpointError(`No matching endpoint.`);
42
+ };
@@ -1,4 +1,6 @@
1
+ export { BinaryDecisionDiagram } from "./bdd/BinaryDecisionDiagram";
1
2
  export * from "./cache/EndpointCache";
3
+ export { decideEndpoint } from "./decideEndpoint";
2
4
  export * from "./lib/isIpAddress";
3
5
  export * from "./lib/isValidHostLabel";
4
6
  export * from "./utils/customEndpointFunctions";
@@ -0,0 +1,8 @@
1
+ export function coalesce(...args) {
2
+ for (const arg of args) {
3
+ if (arg != null) {
4
+ return arg;
5
+ }
6
+ }
7
+ return undefined;
8
+ }
@@ -5,7 +5,8 @@ export const getAttr = (value, path) => getAttrPathList(path).reduce((acc, index
5
5
  throw new EndpointError(`Index '${index}' in '${path}' not found in '${JSON.stringify(value)}'`);
6
6
  }
7
7
  else if (Array.isArray(acc)) {
8
- return acc[parseInt(index)];
8
+ const i = parseInt(index);
9
+ return acc[i < 0 ? acc.length + i : i];
9
10
  }
10
11
  return acc[index];
11
12
  }, value);
@@ -1,9 +1,12 @@
1
1
  export * from "./booleanEquals";
2
+ export * from "./coalesce";
2
3
  export * from "./getAttr";
3
4
  export * from "./isSet";
4
5
  export * from "./isValidHostLabel";
6
+ export * from "./ite";
5
7
  export * from "./not";
6
8
  export * from "./parseURL";
9
+ export * from "./split";
7
10
  export * from "./stringEquals";
8
11
  export * from "./substring";
9
12
  export * from "./uriEncode";
@@ -0,0 +1,3 @@
1
+ export function ite(condition, trueValue, falseValue) {
2
+ return condition ? trueValue : falseValue;
3
+ }
@@ -0,0 +1,13 @@
1
+ export function split(value, delimiter, limit) {
2
+ if (limit === 1) {
3
+ return [value];
4
+ }
5
+ if (value === "") {
6
+ return [""];
7
+ }
8
+ const parts = value.split(delimiter);
9
+ if (limit === 0) {
10
+ return parts;
11
+ }
12
+ return parts.slice(0, limit - 1).concat(parts.slice(1).join(delimiter));
13
+ }
@@ -1,5 +1,5 @@
1
1
  export const substring = (input, start, stop, reverse) => {
2
- if (start >= stop || input.length < stop || /[^\u0000-\u007f]/.test(input)) {
2
+ if (input == null || start >= stop || input.length < stop || /[^\u0000-\u007f]/.test(input)) {
3
3
  return null;
4
4
  }
5
5
  if (!reverse) {
@@ -5,20 +5,15 @@ export const resolveEndpoint = (ruleSetObject, options) => {
5
5
  const { endpointParams, logger } = options;
6
6
  const { parameters, rules } = ruleSetObject;
7
7
  options.logger?.debug?.(`${debugId} Initial EndpointParams: ${toDebugString(endpointParams)}`);
8
- const paramsWithDefault = Object.entries(parameters)
9
- .filter(([, v]) => v.default != null)
10
- .map(([k, v]) => [k, v.default]);
11
- if (paramsWithDefault.length > 0) {
12
- for (const [paramKey, paramDefaultValue] of paramsWithDefault) {
13
- endpointParams[paramKey] = endpointParams[paramKey] ?? paramDefaultValue;
8
+ for (const paramKey in parameters) {
9
+ const parameter = parameters[paramKey];
10
+ const endpointParam = endpointParams[paramKey];
11
+ if (endpointParam == null && parameter.default != null) {
12
+ endpointParams[paramKey] = parameter.default;
13
+ continue;
14
14
  }
15
- }
16
- const requiredParams = Object.entries(parameters)
17
- .filter(([, v]) => v.required)
18
- .map(([k]) => k);
19
- for (const requiredParam of requiredParams) {
20
- if (endpointParams[requiredParam] == null) {
21
- throw new EndpointError(`Missing required parameter: '${requiredParam}'`);
15
+ if (parameter.required && endpointParam == null) {
16
+ throw new EndpointError(`Missing required parameter: '${paramKey}'`);
22
17
  }
23
18
  }
24
19
  const endpoint = evaluateRules(rules, { endpointParams, logger, referenceRecord: {} });
@@ -1,11 +1,14 @@
1
- import { booleanEquals, getAttr, isSet, isValidHostLabel, not, parseURL, stringEquals, substring, uriEncode, } from "../lib";
1
+ import { booleanEquals, coalesce, getAttr, isSet, isValidHostLabel, ite, not, parseURL, split, stringEquals, substring, uriEncode, } from "../lib";
2
2
  export const endpointFunctions = {
3
3
  booleanEquals,
4
+ coalesce,
4
5
  getAttr,
5
6
  isSet,
6
7
  isValidHostLabel,
8
+ ite,
7
9
  not,
8
10
  parseURL,
11
+ split,
9
12
  stringEquals,
10
13
  substring,
11
14
  uriEncode,