@cdklabs/cdk-ecs-codedeploy 0.0.94 → 0.0.95

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 (158) hide show
  1. package/.jsii +3 -3
  2. package/lib/api-canary/index.js +1 -1
  3. package/lib/ecs-appspec/index.js +1 -1
  4. package/lib/ecs-deployment/index.js +1 -1
  5. package/lib/ecs-patterns/application-load-balanced-codedeployed-fargate-service.js +1 -1
  6. package/node_modules/@aws-sdk/abort-controller/package.json +2 -2
  7. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/AddTagsToOnPremisesInstancesCommand.d.ts +23 -0
  8. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/BatchGetApplicationRevisionsCommand.d.ts +19 -0
  9. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/BatchGetApplicationsCommand.d.ts +13 -0
  10. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/BatchGetDeploymentGroupsCommand.d.ts +23 -0
  11. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/BatchGetDeploymentInstancesCommand.d.ts +23 -0
  12. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/BatchGetDeploymentTargetsCommand.d.ts +32 -0
  13. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/BatchGetDeploymentsCommand.d.ts +10 -0
  14. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/BatchGetOnPremisesInstancesCommand.d.ts +10 -0
  15. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/ContinueDeploymentCommand.d.ts +26 -0
  16. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/CreateApplicationCommand.d.ts +19 -0
  17. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/CreateDeploymentCommand.d.ts +124 -0
  18. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/CreateDeploymentConfigCommand.d.ts +24 -0
  19. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/CreateDeploymentGroupCommand.d.ts +131 -0
  20. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/DeleteApplicationCommand.d.ts +12 -0
  21. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/DeleteDeploymentConfigCommand.d.ts +13 -0
  22. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/DeleteDeploymentGroupCommand.d.ts +18 -0
  23. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/DeleteGitHubAccountTokenCommand.d.ts +16 -0
  24. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/DeleteResourcesByExternalIdCommand.d.ts +1 -0
  25. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/DeregisterOnPremisesInstanceCommand.d.ts +7 -0
  26. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/GetApplicationCommand.d.ts +10 -0
  27. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/GetApplicationRevisionCommand.d.ts +19 -0
  28. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/GetDeploymentCommand.d.ts +11 -0
  29. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/GetDeploymentConfigCommand.d.ts +14 -0
  30. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/GetDeploymentGroupCommand.d.ts +23 -0
  31. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/GetDeploymentInstanceCommand.d.ts +23 -0
  32. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/GetDeploymentTargetCommand.d.ts +26 -0
  33. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/GetOnPremisesInstanceCommand.d.ts +10 -0
  34. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/ListApplicationRevisionsCommand.d.ts +32 -0
  35. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/ListApplicationsCommand.d.ts +4 -0
  36. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/ListDeploymentConfigsCommand.d.ts +4 -0
  37. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/ListDeploymentGroupsCommand.d.ts +13 -0
  38. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/ListDeploymentInstancesCommand.d.ts +35 -0
  39. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/ListDeploymentTargetsCommand.d.ts +29 -0
  40. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/ListDeploymentsCommand.d.ts +34 -0
  41. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/ListGitHubAccountTokenNamesCommand.d.ts +10 -0
  42. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/ListOnPremisesInstancesCommand.d.ts +10 -0
  43. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/ListTagsForResourceCommand.d.ts +11 -0
  44. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/PutLifecycleEventHookExecutionStatusCommand.d.ts +27 -0
  45. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/RegisterApplicationRevisionCommand.d.ts +19 -0
  46. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/RegisterOnPremisesInstanceCommand.d.ts +34 -0
  47. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/RemoveTagsFromOnPremisesInstancesCommand.d.ts +23 -0
  48. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/SkipWaitTimeForInstanceTerminationCommand.d.ts +20 -0
  49. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/StopDeploymentCommand.d.ts +20 -0
  50. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/TagResourceCommand.d.ts +27 -0
  51. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/UntagResourceCommand.d.ts +27 -0
  52. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/UpdateApplicationCommand.d.ts +13 -0
  53. package/node_modules/@aws-sdk/client-codedeploy/dist-types/commands/UpdateDeploymentGroupCommand.d.ts +125 -0
  54. package/node_modules/@aws-sdk/client-codedeploy/package.json +30 -30
  55. package/node_modules/@aws-sdk/client-sso/dist-types/commands/GetRoleCredentialsCommand.d.ts +16 -0
  56. package/node_modules/@aws-sdk/client-sso/dist-types/commands/ListAccountRolesCommand.d.ts +16 -0
  57. package/node_modules/@aws-sdk/client-sso/dist-types/commands/ListAccountsCommand.d.ts +16 -0
  58. package/node_modules/@aws-sdk/client-sso/dist-types/commands/LogoutCommand.d.ts +13 -0
  59. package/node_modules/@aws-sdk/client-sso/package.json +26 -26
  60. package/node_modules/@aws-sdk/client-sso-oidc/dist-types/commands/CreateTokenCommand.d.ts +42 -0
  61. package/node_modules/@aws-sdk/client-sso-oidc/dist-types/commands/RegisterClientCommand.d.ts +16 -0
  62. package/node_modules/@aws-sdk/client-sso-oidc/dist-types/commands/StartDeviceAuthorizationCommand.d.ts +22 -0
  63. package/node_modules/@aws-sdk/client-sso-oidc/package.json +26 -26
  64. package/node_modules/@aws-sdk/client-sts/dist-types/commands/AssumeRoleCommand.d.ts +27 -0
  65. package/node_modules/@aws-sdk/client-sts/dist-types/commands/AssumeRoleWithSAMLCommand.d.ts +37 -0
  66. package/node_modules/@aws-sdk/client-sts/dist-types/commands/AssumeRoleWithWebIdentityCommand.d.ts +44 -0
  67. package/node_modules/@aws-sdk/client-sts/dist-types/commands/DecodeAuthorizationMessageCommand.d.ts +6 -0
  68. package/node_modules/@aws-sdk/client-sts/dist-types/commands/GetAccessKeyInfoCommand.d.ts +1 -0
  69. package/node_modules/@aws-sdk/client-sts/dist-types/commands/GetCallerIdentityCommand.d.ts +1 -0
  70. package/node_modules/@aws-sdk/client-sts/dist-types/commands/GetFederationTokenCommand.d.ts +23 -0
  71. package/node_modules/@aws-sdk/client-sts/dist-types/commands/GetSessionTokenCommand.d.ts +8 -0
  72. package/node_modules/@aws-sdk/client-sts/package.json +29 -29
  73. package/node_modules/@aws-sdk/config-resolver/package.json +5 -5
  74. package/node_modules/@aws-sdk/credential-provider-env/package.json +3 -3
  75. package/node_modules/@aws-sdk/credential-provider-imds/package.json +5 -5
  76. package/node_modules/@aws-sdk/credential-provider-ini/package.json +9 -9
  77. package/node_modules/@aws-sdk/credential-provider-node/package.json +10 -10
  78. package/node_modules/@aws-sdk/credential-provider-process/package.json +4 -4
  79. package/node_modules/@aws-sdk/credential-provider-sso/package.json +6 -6
  80. package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +3 -3
  81. package/node_modules/@aws-sdk/fetch-http-handler/package.json +5 -5
  82. package/node_modules/@aws-sdk/hash-node/package.json +2 -2
  83. package/node_modules/@aws-sdk/invalid-dependency/package.json +2 -2
  84. package/node_modules/@aws-sdk/middleware-content-length/package.json +3 -3
  85. package/node_modules/@aws-sdk/middleware-endpoint/package.json +7 -7
  86. package/node_modules/@aws-sdk/middleware-host-header/package.json +3 -3
  87. package/node_modules/@aws-sdk/middleware-logger/package.json +2 -2
  88. package/node_modules/@aws-sdk/middleware-recursion-detection/package.json +3 -3
  89. package/node_modules/@aws-sdk/middleware-retry/package.json +7 -7
  90. package/node_modules/@aws-sdk/middleware-sdk-sts/package.json +6 -6
  91. package/node_modules/@aws-sdk/middleware-serde/package.json +2 -2
  92. package/node_modules/@aws-sdk/middleware-signing/package.json +6 -6
  93. package/node_modules/@aws-sdk/middleware-stack/package.json +2 -2
  94. package/node_modules/@aws-sdk/middleware-user-agent/package.json +4 -4
  95. package/node_modules/@aws-sdk/node-config-provider/package.json +4 -4
  96. package/node_modules/@aws-sdk/node-http-handler/package.json +5 -5
  97. package/node_modules/@aws-sdk/property-provider/package.json +2 -2
  98. package/node_modules/@aws-sdk/protocol-http/dist-cjs/Field.js +1 -3
  99. package/node_modules/@aws-sdk/protocol-http/dist-cjs/Fields.js +10 -0
  100. package/node_modules/@aws-sdk/protocol-http/dist-cjs/headersProxy.js +52 -0
  101. package/node_modules/@aws-sdk/protocol-http/dist-cjs/httpRequest.js +99 -24
  102. package/node_modules/@aws-sdk/protocol-http/dist-cjs/queryProxy.js +71 -0
  103. package/node_modules/@aws-sdk/protocol-http/dist-es/Field.js +1 -3
  104. package/node_modules/@aws-sdk/protocol-http/dist-es/Fields.js +10 -0
  105. package/node_modules/@aws-sdk/protocol-http/dist-es/headersProxy.js +45 -0
  106. package/node_modules/@aws-sdk/protocol-http/dist-es/httpRequest.js +99 -24
  107. package/node_modules/@aws-sdk/protocol-http/dist-es/queryProxy.js +65 -0
  108. package/node_modules/@aws-sdk/protocol-http/dist-types/Field.d.ts +1 -1
  109. package/node_modules/@aws-sdk/protocol-http/dist-types/Fields.d.ts +18 -1
  110. package/node_modules/@aws-sdk/protocol-http/dist-types/headersProxy.d.ts +39 -0
  111. package/node_modules/@aws-sdk/protocol-http/dist-types/httpRequest.d.ts +50 -7
  112. package/node_modules/@aws-sdk/protocol-http/dist-types/queryProxy.d.ts +29 -0
  113. package/node_modules/@aws-sdk/protocol-http/dist-types/ts3.4/Fields.d.ts +3 -1
  114. package/node_modules/@aws-sdk/protocol-http/dist-types/ts3.4/headersProxy.d.ts +8 -0
  115. package/node_modules/@aws-sdk/protocol-http/dist-types/ts3.4/httpRequest.d.ts +30 -15
  116. package/node_modules/@aws-sdk/protocol-http/dist-types/ts3.4/queryProxy.d.ts +10 -0
  117. package/node_modules/@aws-sdk/protocol-http/package.json +3 -3
  118. package/node_modules/@aws-sdk/querystring-builder/package.json +2 -2
  119. package/node_modules/@aws-sdk/querystring-parser/package.json +2 -2
  120. package/node_modules/@aws-sdk/service-error-classification/package.json +2 -2
  121. package/node_modules/@aws-sdk/shared-ini-file-loader/package.json +2 -2
  122. package/node_modules/@aws-sdk/signature-v4/dist-cjs/prepareRequest.js +18 -1
  123. package/node_modules/@aws-sdk/signature-v4/dist-es/prepareRequest.js +18 -1
  124. package/node_modules/@aws-sdk/signature-v4/package.json +4 -4
  125. package/node_modules/@aws-sdk/smithy-client/dist-types/NoOpLogger.d.ts +3 -0
  126. package/node_modules/@aws-sdk/smithy-client/dist-types/client.d.ts +9 -0
  127. package/node_modules/@aws-sdk/smithy-client/dist-types/command.d.ts +3 -0
  128. package/node_modules/@aws-sdk/smithy-client/dist-types/constants.d.ts +3 -0
  129. package/node_modules/@aws-sdk/smithy-client/dist-types/date-utils.d.ts +10 -0
  130. package/node_modules/@aws-sdk/smithy-client/dist-types/default-error-handler.d.ts +1 -1
  131. package/node_modules/@aws-sdk/smithy-client/dist-types/emitWarningIfUnsupportedVersion.d.ts +2 -0
  132. package/node_modules/@aws-sdk/smithy-client/dist-types/exceptions.d.ts +5 -0
  133. package/node_modules/@aws-sdk/smithy-client/dist-types/extended-encode-uri-component.d.ts +2 -0
  134. package/node_modules/@aws-sdk/smithy-client/dist-types/get-array-if-single-item.d.ts +2 -0
  135. package/node_modules/@aws-sdk/smithy-client/dist-types/get-value-from-text-node.d.ts +2 -0
  136. package/node_modules/@aws-sdk/smithy-client/dist-types/lazy-json.d.ts +5 -0
  137. package/node_modules/@aws-sdk/smithy-client/dist-types/object-mapping.d.ts +35 -3
  138. package/node_modules/@aws-sdk/smithy-client/dist-types/parse-utils.d.ts +50 -0
  139. package/node_modules/@aws-sdk/smithy-client/dist-types/resolve-path.d.ts +3 -0
  140. package/node_modules/@aws-sdk/smithy-client/dist-types/ser-utils.d.ts +2 -0
  141. package/node_modules/@aws-sdk/smithy-client/dist-types/split-every.d.ts +2 -0
  142. package/node_modules/@aws-sdk/smithy-client/package.json +3 -3
  143. package/node_modules/@aws-sdk/token-providers/package.json +5 -5
  144. package/node_modules/@aws-sdk/types/dist-types/http.d.ts +6 -0
  145. package/node_modules/@aws-sdk/types/package.json +1 -1
  146. package/node_modules/@aws-sdk/url-parser/package.json +3 -3
  147. package/node_modules/@aws-sdk/util-defaults-mode-browser/package.json +4 -4
  148. package/node_modules/@aws-sdk/util-defaults-mode-node/package.json +7 -7
  149. package/node_modules/@aws-sdk/util-endpoints/package.json +2 -2
  150. package/node_modules/@aws-sdk/util-middleware/package.json +2 -2
  151. package/node_modules/@aws-sdk/util-retry/package.json +3 -3
  152. package/node_modules/@aws-sdk/util-user-agent-browser/package.json +3 -3
  153. package/node_modules/@aws-sdk/util-user-agent-node/package.json +4 -4
  154. package/node_modules/@aws-sdk/util-waiter/dist-types/utils/sleep.d.ts +3 -0
  155. package/node_modules/@aws-sdk/util-waiter/dist-types/utils/validate.d.ts +2 -0
  156. package/node_modules/@aws-sdk/util-waiter/dist-types/waiter.d.ts +13 -2
  157. package/node_modules/@aws-sdk/util-waiter/package.json +3 -3
  158. package/package.json +5 -5
@@ -1,20 +1,89 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HttpRequest = void 0;
4
+ const Fields_1 = require("./Fields");
5
+ const headersProxy_1 = require("./headersProxy");
6
+ const queryProxy_1 = require("./queryProxy");
4
7
  class HttpRequest {
5
8
  constructor(options) {
9
+ this.protocol = "https";
10
+ this.hostname = "localhost";
11
+ this.path = "/";
12
+ this.query = {};
13
+ this.headers = {};
6
14
  this.method = options.method || "GET";
7
- this.hostname = options.hostname || "localhost";
8
- this.port = options.port;
9
- this.query = options.query || {};
10
- this.headers = options.headers || {};
15
+ this.destination = HttpRequest.getDefaultDestination(options);
16
+ this.fields = (0, headersProxy_1.headersToFields)(options.headers || {});
11
17
  this.body = options.body;
12
- this.protocol = options.protocol
13
- ? options.protocol.slice(-1) !== ":"
14
- ? `${options.protocol}:`
15
- : options.protocol
16
- : "https:";
17
- this.path = options.path ? (options.path.charAt(0) !== "/" ? `/${options.path}` : options.path) : "/";
18
+ const httpRequest = this;
19
+ Object.defineProperties(httpRequest, {
20
+ protocol: {
21
+ enumerable: true,
22
+ get() {
23
+ return httpRequest.destination.protocol;
24
+ },
25
+ set(protocol) {
26
+ httpRequest.destination.protocol = protocol;
27
+ },
28
+ },
29
+ hostname: {
30
+ enumerable: true,
31
+ get() {
32
+ return httpRequest.destination.hostname;
33
+ },
34
+ set(hostname) {
35
+ httpRequest.destination.hostname = hostname;
36
+ },
37
+ },
38
+ port: {
39
+ enumerable: true,
40
+ get() {
41
+ const port = httpRequest.destination.port;
42
+ return port ? Number(port) : undefined;
43
+ },
44
+ set(port) {
45
+ httpRequest.destination.port = String(port);
46
+ },
47
+ },
48
+ path: {
49
+ enumerable: true,
50
+ get() {
51
+ return httpRequest.destination.pathname;
52
+ },
53
+ set(path) {
54
+ httpRequest.destination.pathname = path;
55
+ },
56
+ },
57
+ query: {
58
+ enumerable: true,
59
+ get() {
60
+ return (0, queryProxy_1.getQueryProxy)(httpRequest.destination.searchParams);
61
+ },
62
+ set(query) {
63
+ const searchParams = (0, queryProxy_1.queryToSearchParams)(query || {});
64
+ httpRequest.destination.search = searchParams.toString();
65
+ },
66
+ },
67
+ headers: {
68
+ enumerable: true,
69
+ get() {
70
+ return (0, headersProxy_1.getHeadersProxy)(httpRequest.fields);
71
+ },
72
+ set(headers) {
73
+ httpRequest.fields = (0, headersProxy_1.headersToFields)(headers);
74
+ },
75
+ },
76
+ });
77
+ }
78
+ static from(options) {
79
+ const request = new HttpRequest(options);
80
+ if (options.destination) {
81
+ request.destination = options.destination;
82
+ }
83
+ if (options.fields) {
84
+ request.fields = options.fields;
85
+ }
86
+ return request;
18
87
  }
19
88
  static isInstance(request) {
20
89
  if (!request)
@@ -28,22 +97,28 @@ class HttpRequest {
28
97
  typeof req["headers"] === "object");
29
98
  }
30
99
  clone() {
31
- const cloned = new HttpRequest({
100
+ return HttpRequest.from({
32
101
  ...this,
33
- headers: { ...this.headers },
102
+ destination: new URL(this.destination),
103
+ fields: Fields_1.Fields.from(this.fields.getAll().map((field) => ({
104
+ ...field,
105
+ values: [...field.values],
106
+ }))),
34
107
  });
35
- if (cloned.query)
36
- cloned.query = cloneQuery(cloned.query);
37
- return cloned;
108
+ }
109
+ static getDefaultDestination(options) {
110
+ const protocol = options.protocol
111
+ ? options.protocol.slice(-1) !== ":"
112
+ ? `${options.protocol}:`
113
+ : options.protocol
114
+ : "https:";
115
+ const hostname = options.hostname || "localhost";
116
+ const port = options.port ? `:${String(options.port)}` : "";
117
+ const path = options.path ? (options.path.charAt(0) !== "/" ? `/${options.path}` : options.path) : "/";
118
+ const searchParams = (0, queryProxy_1.queryToSearchParams)(options.query || {});
119
+ const url = new URL(`${protocol}//${hostname}${port}${path}`);
120
+ url.search = searchParams.toString();
121
+ return url;
38
122
  }
39
123
  }
40
124
  exports.HttpRequest = HttpRequest;
41
- function cloneQuery(query) {
42
- return Object.keys(query).reduce((carry, paramName) => {
43
- const param = query[paramName];
44
- return {
45
- ...carry,
46
- [paramName]: Array.isArray(param) ? [...param] : param,
47
- };
48
- }, {});
49
- }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.searchParamsToQuery = exports.queryToSearchParams = exports.getQueryProxy = void 0;
4
+ const getQueryProxy = (searchParams) => {
5
+ const query = (0, exports.searchParamsToQuery)(searchParams);
6
+ return new Proxy(query, {
7
+ set(target, property, newValue) {
8
+ if (newValue == null)
9
+ return true;
10
+ Reflect.set(target, property, newValue);
11
+ if (Array.isArray(newValue)) {
12
+ searchParams.delete(property);
13
+ newValue.forEach((value) => searchParams.append(property, value));
14
+ }
15
+ else {
16
+ searchParams.set(property, newValue);
17
+ }
18
+ return true;
19
+ },
20
+ defineProperty(target, property, attributes) {
21
+ const { configurable, enumerable, writable, value } = attributes;
22
+ if (configurable && enumerable && writable && value != null) {
23
+ Reflect.defineProperty(target, property, attributes);
24
+ if (Array.isArray(value)) {
25
+ searchParams.delete(property);
26
+ value.forEach((element) => searchParams.append(property, element));
27
+ }
28
+ else {
29
+ searchParams.set(property, value);
30
+ }
31
+ }
32
+ return true;
33
+ },
34
+ deleteProperty(target, property) {
35
+ Reflect.deleteProperty(target, property);
36
+ searchParams.delete(property);
37
+ return true;
38
+ },
39
+ });
40
+ };
41
+ exports.getQueryProxy = getQueryProxy;
42
+ const queryToSearchParams = (query) => {
43
+ const searchParams = new URLSearchParams();
44
+ for (const [key, value] of Object.entries(query)) {
45
+ if (Array.isArray(value)) {
46
+ value.filter((element) => typeof element === "string").forEach((element) => searchParams.append(key, element));
47
+ }
48
+ else if (typeof value === "string") {
49
+ searchParams.set(key, value);
50
+ }
51
+ }
52
+ return searchParams;
53
+ };
54
+ exports.queryToSearchParams = queryToSearchParams;
55
+ const searchParamsToQuery = (searchParams) => {
56
+ const query = {};
57
+ for (const [key, value] of searchParams.entries()) {
58
+ const currentValue = query[key];
59
+ if (currentValue == null) {
60
+ query[key] = value;
61
+ }
62
+ else if (Array.isArray(currentValue)) {
63
+ query[key] = [...currentValue, value];
64
+ }
65
+ else {
66
+ query[key] = [currentValue, value];
67
+ }
68
+ }
69
+ return query;
70
+ };
71
+ exports.searchParamsToQuery = searchParamsToQuery;
@@ -15,9 +15,7 @@ export class Field {
15
15
  this.values = this.values.filter((v) => v !== value);
16
16
  }
17
17
  toString() {
18
- return this.values
19
- .map((v) => (v.includes(",") || v.includes(" ") ? `"${v}"` : v))
20
- .join(", ");
18
+ return this.values.map((v) => (v.includes(",") ? `"${v}"` : v)).join(", ");
21
19
  }
22
20
  get() {
23
21
  return this.values;
@@ -1,3 +1,4 @@
1
+ import { Field } from "./Field";
1
2
  export class Fields {
2
3
  constructor({ fields = [], encoding = "utf-8" }) {
3
4
  this.entries = {};
@@ -16,4 +17,13 @@ export class Fields {
16
17
  getByType(kind) {
17
18
  return Object.values(this.entries).filter((field) => field.kind === kind);
18
19
  }
20
+ getAll() {
21
+ return Object.values(this.entries);
22
+ }
23
+ static from(fieldsToCreate, encoding) {
24
+ return fieldsToCreate.reduce((fields, fieldArgs) => {
25
+ fields.setField(new Field(fieldArgs));
26
+ return fields;
27
+ }, new Fields({ encoding }));
28
+ }
19
29
  }
@@ -0,0 +1,45 @@
1
+ import { Field } from "./Field";
2
+ import { FieldPosition } from "./FieldPosition";
3
+ import { Fields } from "./Fields";
4
+ export const getHeadersProxy = (fields) => {
5
+ const headers = fieldsToHeaders(fields);
6
+ return new Proxy(headers, {
7
+ set(target, property, newValue) {
8
+ if (newValue == null)
9
+ return true;
10
+ Reflect.set(target, property, newValue);
11
+ const field = new Field({ name: property, values: headerValueToFieldValues(newValue) });
12
+ fields.setField(field);
13
+ return true;
14
+ },
15
+ defineProperty(target, property, attributes) {
16
+ const { configurable, enumerable, writable, value } = attributes;
17
+ if (configurable && enumerable && writable && value != null) {
18
+ Reflect.defineProperty(target, property, attributes);
19
+ const field = new Field({ name: property, values: headerValueToFieldValues(value) });
20
+ fields.setField(field);
21
+ }
22
+ return true;
23
+ },
24
+ deleteProperty(target, property) {
25
+ Reflect.deleteProperty(target, property);
26
+ fields.removeField(property);
27
+ return true;
28
+ },
29
+ });
30
+ };
31
+ export const headersToFields = (headers) => {
32
+ return Fields.from(Object.entries(headers)
33
+ .filter(([, value]) => value != null)
34
+ .map(([key, value]) => ({ name: key, values: headerValueToFieldValues(value), kind: FieldPosition.HEADER })));
35
+ };
36
+ export const fieldsToHeaders = (fields) => {
37
+ return fields
38
+ .getByType(FieldPosition.HEADER)
39
+ .reduce((headers, field) => ({ ...headers, [field.name]: field.values.join(",") }), {});
40
+ };
41
+ export const headerValueToFieldValues = (headerValue) => {
42
+ if (headerValue == null)
43
+ return undefined;
44
+ return String(headerValue).split(",");
45
+ };
@@ -1,17 +1,86 @@
1
+ import { Fields } from "./Fields";
2
+ import { getHeadersProxy, headersToFields } from "./headersProxy";
3
+ import { getQueryProxy, queryToSearchParams } from "./queryProxy";
1
4
  export class HttpRequest {
2
5
  constructor(options) {
6
+ this.protocol = "https";
7
+ this.hostname = "localhost";
8
+ this.path = "/";
9
+ this.query = {};
10
+ this.headers = {};
3
11
  this.method = options.method || "GET";
4
- this.hostname = options.hostname || "localhost";
5
- this.port = options.port;
6
- this.query = options.query || {};
7
- this.headers = options.headers || {};
12
+ this.destination = HttpRequest.getDefaultDestination(options);
13
+ this.fields = headersToFields(options.headers || {});
8
14
  this.body = options.body;
9
- this.protocol = options.protocol
10
- ? options.protocol.slice(-1) !== ":"
11
- ? `${options.protocol}:`
12
- : options.protocol
13
- : "https:";
14
- this.path = options.path ? (options.path.charAt(0) !== "/" ? `/${options.path}` : options.path) : "/";
15
+ const httpRequest = this;
16
+ Object.defineProperties(httpRequest, {
17
+ protocol: {
18
+ enumerable: true,
19
+ get() {
20
+ return httpRequest.destination.protocol;
21
+ },
22
+ set(protocol) {
23
+ httpRequest.destination.protocol = protocol;
24
+ },
25
+ },
26
+ hostname: {
27
+ enumerable: true,
28
+ get() {
29
+ return httpRequest.destination.hostname;
30
+ },
31
+ set(hostname) {
32
+ httpRequest.destination.hostname = hostname;
33
+ },
34
+ },
35
+ port: {
36
+ enumerable: true,
37
+ get() {
38
+ const port = httpRequest.destination.port;
39
+ return port ? Number(port) : undefined;
40
+ },
41
+ set(port) {
42
+ httpRequest.destination.port = String(port);
43
+ },
44
+ },
45
+ path: {
46
+ enumerable: true,
47
+ get() {
48
+ return httpRequest.destination.pathname;
49
+ },
50
+ set(path) {
51
+ httpRequest.destination.pathname = path;
52
+ },
53
+ },
54
+ query: {
55
+ enumerable: true,
56
+ get() {
57
+ return getQueryProxy(httpRequest.destination.searchParams);
58
+ },
59
+ set(query) {
60
+ const searchParams = queryToSearchParams(query || {});
61
+ httpRequest.destination.search = searchParams.toString();
62
+ },
63
+ },
64
+ headers: {
65
+ enumerable: true,
66
+ get() {
67
+ return getHeadersProxy(httpRequest.fields);
68
+ },
69
+ set(headers) {
70
+ httpRequest.fields = headersToFields(headers);
71
+ },
72
+ },
73
+ });
74
+ }
75
+ static from(options) {
76
+ const request = new HttpRequest(options);
77
+ if (options.destination) {
78
+ request.destination = options.destination;
79
+ }
80
+ if (options.fields) {
81
+ request.fields = options.fields;
82
+ }
83
+ return request;
15
84
  }
16
85
  static isInstance(request) {
17
86
  if (!request)
@@ -25,21 +94,27 @@ export class HttpRequest {
25
94
  typeof req["headers"] === "object");
26
95
  }
27
96
  clone() {
28
- const cloned = new HttpRequest({
97
+ return HttpRequest.from({
29
98
  ...this,
30
- headers: { ...this.headers },
99
+ destination: new URL(this.destination),
100
+ fields: Fields.from(this.fields.getAll().map((field) => ({
101
+ ...field,
102
+ values: [...field.values],
103
+ }))),
31
104
  });
32
- if (cloned.query)
33
- cloned.query = cloneQuery(cloned.query);
34
- return cloned;
35
105
  }
36
- }
37
- function cloneQuery(query) {
38
- return Object.keys(query).reduce((carry, paramName) => {
39
- const param = query[paramName];
40
- return {
41
- ...carry,
42
- [paramName]: Array.isArray(param) ? [...param] : param,
43
- };
44
- }, {});
106
+ static getDefaultDestination(options) {
107
+ const protocol = options.protocol
108
+ ? options.protocol.slice(-1) !== ":"
109
+ ? `${options.protocol}:`
110
+ : options.protocol
111
+ : "https:";
112
+ const hostname = options.hostname || "localhost";
113
+ const port = options.port ? `:${String(options.port)}` : "";
114
+ const path = options.path ? (options.path.charAt(0) !== "/" ? `/${options.path}` : options.path) : "/";
115
+ const searchParams = queryToSearchParams(options.query || {});
116
+ const url = new URL(`${protocol}//${hostname}${port}${path}`);
117
+ url.search = searchParams.toString();
118
+ return url;
119
+ }
45
120
  }
@@ -0,0 +1,65 @@
1
+ export const getQueryProxy = (searchParams) => {
2
+ const query = searchParamsToQuery(searchParams);
3
+ return new Proxy(query, {
4
+ set(target, property, newValue) {
5
+ if (newValue == null)
6
+ return true;
7
+ Reflect.set(target, property, newValue);
8
+ if (Array.isArray(newValue)) {
9
+ searchParams.delete(property);
10
+ newValue.forEach((value) => searchParams.append(property, value));
11
+ }
12
+ else {
13
+ searchParams.set(property, newValue);
14
+ }
15
+ return true;
16
+ },
17
+ defineProperty(target, property, attributes) {
18
+ const { configurable, enumerable, writable, value } = attributes;
19
+ if (configurable && enumerable && writable && value != null) {
20
+ Reflect.defineProperty(target, property, attributes);
21
+ if (Array.isArray(value)) {
22
+ searchParams.delete(property);
23
+ value.forEach((element) => searchParams.append(property, element));
24
+ }
25
+ else {
26
+ searchParams.set(property, value);
27
+ }
28
+ }
29
+ return true;
30
+ },
31
+ deleteProperty(target, property) {
32
+ Reflect.deleteProperty(target, property);
33
+ searchParams.delete(property);
34
+ return true;
35
+ },
36
+ });
37
+ };
38
+ export const queryToSearchParams = (query) => {
39
+ const searchParams = new URLSearchParams();
40
+ for (const [key, value] of Object.entries(query)) {
41
+ if (Array.isArray(value)) {
42
+ value.filter((element) => typeof element === "string").forEach((element) => searchParams.append(key, element));
43
+ }
44
+ else if (typeof value === "string") {
45
+ searchParams.set(key, value);
46
+ }
47
+ }
48
+ return searchParams;
49
+ };
50
+ export const searchParamsToQuery = (searchParams) => {
51
+ const query = {};
52
+ for (const [key, value] of searchParams.entries()) {
53
+ const currentValue = query[key];
54
+ if (currentValue == null) {
55
+ query[key] = value;
56
+ }
57
+ else if (Array.isArray(currentValue)) {
58
+ query[key] = [...currentValue, value];
59
+ }
60
+ else {
61
+ query[key] = [currentValue, value];
62
+ }
63
+ }
64
+ return query;
65
+ };
@@ -40,7 +40,7 @@ export declare class Field {
40
40
  */
41
41
  remove(value: string): void;
42
42
  /**
43
- * Get comma-delimited string.
43
+ * Get comma-delimited string to be sent over the wire.
44
44
  *
45
45
  * @returns String representation of {@link Field}.
46
46
  */
@@ -1,4 +1,4 @@
1
- import { Field } from "./Field";
1
+ import { Field, FieldOptions } from "./Field";
2
2
  import { FieldPosition } from "./FieldPosition";
3
3
  export declare type FieldsOptions = {
4
4
  fields?: Field[];
@@ -41,4 +41,21 @@ export declare class Fields {
41
41
  * {@link FieldPosition}.
42
42
  */
43
43
  getByType(kind: FieldPosition): Field[];
44
+ /**
45
+ * Retrieves all the {@link Field}s in the collection.
46
+ * Includes headers and trailers.
47
+ *
48
+ * @returns All fields in the collection.
49
+ */
50
+ getAll(): Field[];
51
+ /**
52
+ * Utility for creating {@link Fields} without having to
53
+ * construct each {@link Field} individually.
54
+ *
55
+ * @param fieldsToCreate List of arguments used to create each
56
+ * {@link Field}.
57
+ * @param encoding Optional encoding of resultant {@link Fields}.
58
+ * @returns The {@link Fields} instance.
59
+ */
60
+ static from(fieldsToCreate: FieldOptions[], encoding?: string): Fields;
44
61
  }
@@ -0,0 +1,39 @@
1
+ import { HeaderBag } from "@aws-sdk/types";
2
+ import { Fields } from "./Fields";
3
+ /**
4
+ * Creates a proxy to a {@link Fields} object that can be used like
5
+ * a {@link HeaderBag} object. Modifying the proxy object modifies
6
+ * the underlying {@link Fields} object.
7
+ *
8
+ * @param fields {@link Fields} to proxy.
9
+ * @returns Proxy to the given {@link Fields} object.
10
+ * @internal To \@aws-sdk/protocol-http package.
11
+ */
12
+ export declare const getHeadersProxy: (fields: Fields) => HeaderBag;
13
+ /**
14
+ * Creates a new {@link Fields} with header fields populated using the given
15
+ * {@link HeaderBag}. Ignores header keys with null or undefined values.
16
+ *
17
+ * @param headers Headers to get as {@link Fields}.
18
+ * @returns A {@link Fields} populated with the given headers.
19
+ * @internal To \@aws-sdk/protocol-http package.
20
+ */
21
+ export declare const headersToFields: (headers: HeaderBag) => Fields;
22
+ /**
23
+ * Creates a new {@link HeaderBag} populated using the header fields in the
24
+ * given {@link Fields}.
25
+ *
26
+ * @param fields {@link Fields} to get as {@link HeaderBag}.
27
+ * @returns A {@link HeaderBag} populated with the given fields.
28
+ * @internal To \@aws-sdk/protocol-http package.
29
+ */
30
+ export declare const fieldsToHeaders: (fields: Fields) => HeaderBag;
31
+ /**
32
+ * Converts a header value into a list of field values. Ignores null and
33
+ * undefined values. Stringifies non-string values using String().
34
+ *
35
+ * @param headerValue Header value to convert.
36
+ * @returns A list of values or undefined if the given value was not defined.
37
+ * @internal To \@aws-sdk/protocol-http package.
38
+ */
39
+ export declare const headerValueToFieldValues: (headerValue: string) => string[] | undefined;
@@ -1,20 +1,63 @@
1
- import { Endpoint, HeaderBag, HttpMessage, HttpRequest as IHttpRequest, QueryParameterBag } from "@aws-sdk/types";
2
- declare type HttpRequestOptions = Partial<HttpMessage> & Partial<Endpoint> & {
1
+ import { HeaderBag, QueryParameterBag, Request } from "@aws-sdk/types";
2
+ import { Fields } from "./Fields";
3
+ export interface HttpRequestOptions {
3
4
  method?: string;
4
- };
5
- export interface HttpRequest extends IHttpRequest {
5
+ protocol?: string;
6
+ hostname?: string;
7
+ port?: number;
8
+ path?: string;
9
+ query?: QueryParameterBag;
10
+ headers?: HeaderBag;
11
+ body?: any;
12
+ }
13
+ export interface HttpRequestFromOptions {
14
+ method?: string;
15
+ destination?: URL;
16
+ fields?: Fields;
17
+ body?: any;
6
18
  }
7
- export declare class HttpRequest implements HttpMessage, Endpoint {
19
+ export interface HttpRequest extends Request {
8
20
  method: string;
21
+ destination: URL;
22
+ fields: Fields;
23
+ body?: any;
24
+ }
25
+ export declare class HttpRequest implements Request {
26
+ method: string;
27
+ destination: URL;
28
+ fields: Fields;
29
+ body?: any;
30
+ /**
31
+ * @deprecated Use protocol in {@link destination}
32
+ */
9
33
  protocol: string;
34
+ /**
35
+ * @deprecated Use hostname in {@link destination}
36
+ */
10
37
  hostname: string;
38
+ /**
39
+ * @deprecated Use port in {@link destination}
40
+ */
11
41
  port?: number;
42
+ /**
43
+ * @deprecated Use pathname in {@link destination}
44
+ */
12
45
  path: string;
46
+ /**
47
+ * @deprecated Use searchParams in {@link destination}
48
+ */
13
49
  query: QueryParameterBag;
50
+ /**
51
+ * @deprecated Use {@link fields}
52
+ */
14
53
  headers: HeaderBag;
15
- body?: any;
54
+ /**
55
+ *
56
+ * @deprecated Use {@link HttpRequest.from}
57
+ */
16
58
  constructor(options: HttpRequestOptions);
59
+ static from(options: HttpRequestFromOptions): HttpRequest;
17
60
  static isInstance(request: unknown): request is HttpRequest;
18
61
  clone(): HttpRequest;
62
+ private static getDefaultDestination;
19
63
  }
20
- export {};
@@ -0,0 +1,29 @@
1
+ import { QueryParameterBag } from "@aws-sdk/types";
2
+ /**
3
+ * Creates a proxy to a {@link URLSearchParams} object that can be used like
4
+ * a {@link QueryParameterBag} object. Modifying the proxy object modifies
5
+ * the underlying {@link URLSearchParams} object.
6
+ *
7
+ * @param searchParams {@link URLSearchParams} to proxy.
8
+ * @returns Proxy to the given {@link URLSearchParams} object.
9
+ * @internal To \@aws-sdk/protocol-http package.
10
+ */
11
+ export declare const getQueryProxy: (searchParams: URLSearchParams) => QueryParameterBag;
12
+ /**
13
+ * Creates a new {@link URLSearchParams} populated with the query parameters
14
+ * in the given {@link QueryParameterBag}. Ignores non-string values.
15
+ *
16
+ * @param query Query parameters to get as {@link URLSearchParams}.
17
+ * @returns A {@link URLSearchParams} populated with the given query parameters.
18
+ * @internal To \@aws-sdk/protocol-http package.
19
+ */
20
+ export declare const queryToSearchParams: (query: QueryParameterBag) => URLSearchParams;
21
+ /**
22
+ * Creates a new {@link QueryParameterBag} populated with the query parameters
23
+ * in the given {@link URLSearchParams}.
24
+ *
25
+ * @param searchParams {@link URLSearchParams} to get as {@link QueryParameterBag}.
26
+ * @returns A {@link QueryParameterBag} populated with the given query parameters.
27
+ * @internal To \@aws-sdk/protocol-http package.
28
+ */
29
+ export declare const searchParamsToQuery: (searchParams: URLSearchParams) => QueryParameterBag;