@jjrawlins/cdk-iam-policy-builder-helper 0.0.52 → 0.0.53

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 (110) hide show
  1. package/.jsii +3 -3
  2. package/cdk-iam-policy-builder-helper/jsii/jsii.go +2 -2
  3. package/cdk-iam-policy-builder-helper/version +1 -1
  4. package/node_modules/@aws-sdk/client-iam/dist-cjs/index.js +13439 -13574
  5. package/node_modules/@aws-sdk/client-iam/package.json +5 -5
  6. package/node_modules/@aws-sdk/client-sso/dist-cjs/index.js +478 -596
  7. package/node_modules/@aws-sdk/client-sso/package.json +4 -4
  8. package/node_modules/@aws-sdk/core/dist-cjs/index.js +1969 -6
  9. package/node_modules/@aws-sdk/core/dist-cjs/submodules/account-id-endpoint/index.js +48 -88
  10. package/node_modules/@aws-sdk/core/dist-cjs/submodules/client/index.js +35 -74
  11. package/node_modules/@aws-sdk/core/dist-cjs/submodules/httpAuthSchemes/index.js +273 -365
  12. package/node_modules/@aws-sdk/core/dist-cjs/submodules/protocols/index.js +1581 -1863
  13. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsJsonRpcProtocol.js +2 -2
  14. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsRestJsonProtocol.js +2 -2
  15. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/JsonShapeDeserializer.js +4 -4
  16. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/JsonShapeSerializer.js +4 -4
  17. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/query/AwsQueryProtocol.js +3 -3
  18. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/query/QueryShapeSerializer.js +4 -4
  19. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/xml/AwsRestXmlProtocol.js +2 -2
  20. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/xml/XmlShapeSerializer.js +4 -4
  21. package/node_modules/@aws-sdk/core/dist-types/submodules/account-id-endpoint/AccountIdEndpointModeConfigResolver.d.ts +1 -1
  22. package/node_modules/@aws-sdk/core/dist-types/submodules/httpAuthSchemes/aws_sdk/AwsSdkSigV4ASigner.d.ts +1 -1
  23. package/node_modules/@aws-sdk/core/dist-types/submodules/httpAuthSchemes/aws_sdk/AwsSdkSigV4Signer.d.ts +1 -1
  24. package/node_modules/@aws-sdk/core/dist-types/submodules/httpAuthSchemes/aws_sdk/resolveAwsSdkSigV4AConfig.d.ts +1 -1
  25. package/node_modules/@aws-sdk/core/dist-types/submodules/httpAuthSchemes/aws_sdk/resolveAwsSdkSigV4Config.d.ts +1 -1
  26. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/ConfigurableSerdeContext.d.ts +1 -1
  27. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/JsonCodec.d.ts +1 -1
  28. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/JsonShapeDeserializer.d.ts +1 -1
  29. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/JsonShapeSerializer.d.ts +2 -2
  30. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/query/QuerySerializerSettings.d.ts +1 -1
  31. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/xml/XmlCodec.d.ts +1 -1
  32. package/node_modules/@aws-sdk/core/package.json +1 -1
  33. package/node_modules/@aws-sdk/credential-provider-env/dist-cjs/index.js +38 -73
  34. package/node_modules/@aws-sdk/credential-provider-env/package.json +2 -2
  35. package/node_modules/@aws-sdk/credential-provider-http/package.json +2 -2
  36. package/node_modules/@aws-sdk/credential-provider-ini/dist-cjs/index.js +194 -259
  37. package/node_modules/@aws-sdk/credential-provider-ini/package.json +8 -8
  38. package/node_modules/@aws-sdk/credential-provider-node/dist-cjs/index.js +72 -132
  39. package/node_modules/@aws-sdk/credential-provider-node/package.json +7 -7
  40. package/node_modules/@aws-sdk/credential-provider-process/dist-cjs/index.js +71 -107
  41. package/node_modules/@aws-sdk/credential-provider-process/package.json +2 -2
  42. package/node_modules/@aws-sdk/credential-provider-sso/dist-cjs/index.js +176 -249
  43. package/node_modules/@aws-sdk/credential-provider-sso/dist-cjs/loadSso-CVy8iqsZ.js +14 -0
  44. package/node_modules/@aws-sdk/credential-provider-sso/package.json +4 -4
  45. package/node_modules/@aws-sdk/credential-provider-web-identity/dist-cjs/index.js +16 -25
  46. package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +3 -3
  47. package/node_modules/@aws-sdk/middleware-user-agent/dist-cjs/index.js +170 -203
  48. package/node_modules/@aws-sdk/middleware-user-agent/package.json +2 -2
  49. package/node_modules/@aws-sdk/nested-clients/dist-cjs/index.js +2 -2
  50. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/index.js +583 -858
  51. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/index.js +795 -928
  52. package/node_modules/@aws-sdk/nested-clients/package.json +4 -4
  53. package/node_modules/@aws-sdk/token-providers/dist-cjs/index.js +147 -222
  54. package/node_modules/@aws-sdk/token-providers/package.json +3 -3
  55. package/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/index.js +50 -94
  56. package/node_modules/@aws-sdk/util-user-agent-node/package.json +2 -2
  57. package/node_modules/@smithy/core/dist-cjs/submodules/cbor/index.js +1 -1
  58. package/node_modules/@smithy/core/dist-cjs/submodules/event-streams/index.js +5 -3
  59. package/node_modules/@smithy/core/dist-cjs/submodules/protocols/index.js +32 -30
  60. package/node_modules/@smithy/core/dist-cjs/submodules/schema/index.js +133 -202
  61. package/node_modules/@smithy/core/dist-cjs/submodules/serde/index.js +126 -34
  62. package/node_modules/@smithy/core/dist-es/submodules/cbor/CborCodec.js +2 -2
  63. package/node_modules/@smithy/core/dist-es/submodules/event-streams/EventStreamSerde.js +5 -3
  64. package/node_modules/@smithy/core/dist-es/submodules/protocols/HttpBindingProtocol.js +4 -4
  65. package/node_modules/@smithy/core/dist-es/submodules/protocols/HttpProtocol.js +3 -3
  66. package/node_modules/@smithy/core/dist-es/submodules/protocols/RpcProtocol.js +2 -2
  67. package/node_modules/@smithy/core/dist-es/submodules/protocols/serde/FromStringShapeDeserializer.js +19 -17
  68. package/node_modules/@smithy/core/dist-es/submodules/protocols/serde/ToStringShapeSerializer.js +4 -4
  69. package/node_modules/@smithy/core/dist-es/submodules/protocols/serde/determineTimestampFormat.js +5 -6
  70. package/node_modules/@smithy/core/dist-es/submodules/schema/index.js +1 -0
  71. package/node_modules/@smithy/core/dist-es/submodules/schema/schemas/NormalizedSchema.js +82 -176
  72. package/node_modules/@smithy/core/dist-es/submodules/schema/schemas/translateTraits.js +22 -0
  73. package/node_modules/@smithy/core/dist-es/submodules/serde/index.js +1 -0
  74. package/node_modules/@smithy/core/dist-es/submodules/serde/schema-serde-lib/schema-date-utils.js +110 -0
  75. package/node_modules/@smithy/core/dist-es/submodules/serde/value/NumericValue.js +4 -26
  76. package/node_modules/@smithy/core/dist-types/submodules/schema/index.d.ts +1 -0
  77. package/node_modules/@smithy/core/dist-types/submodules/schema/schemas/NormalizedSchema.d.ts +5 -24
  78. package/node_modules/@smithy/core/dist-types/submodules/schema/schemas/sentinels.d.ts +2 -0
  79. package/node_modules/@smithy/core/dist-types/submodules/schema/schemas/translateTraits.d.ts +7 -0
  80. package/node_modules/@smithy/core/dist-types/submodules/serde/index.d.ts +1 -0
  81. package/node_modules/@smithy/core/dist-types/submodules/serde/schema-serde-lib/schema-date-utils.d.ts +47 -0
  82. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/schema/index.d.ts +1 -0
  83. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/schema/schemas/NormalizedSchema.d.ts +5 -24
  84. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/schema/schemas/sentinels.d.ts +2 -0
  85. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/schema/schemas/translateTraits.d.ts +7 -0
  86. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/serde/index.d.ts +1 -0
  87. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/serde/schema-serde-lib/schema-date-utils.d.ts +47 -0
  88. package/node_modules/@smithy/core/package.json +3 -3
  89. package/node_modules/@smithy/fetch-http-handler/package.json +2 -2
  90. package/node_modules/@smithy/middleware-endpoint/package.json +2 -2
  91. package/node_modules/@smithy/middleware-retry/package.json +2 -2
  92. package/node_modules/@smithy/smithy-client/package.json +4 -4
  93. package/node_modules/@smithy/util-base64/dist-cjs/constants.browser.js +9 -32
  94. package/node_modules/@smithy/util-base64/dist-es/constants.browser.js +9 -28
  95. package/node_modules/@smithy/util-base64/dist-types/constants.browser.d.ts +5 -6
  96. package/node_modules/@smithy/util-base64/dist-types/ts3.4/constants.browser.d.ts +5 -6
  97. package/node_modules/@smithy/util-base64/package.json +1 -1
  98. package/node_modules/@smithy/util-body-length-node/dist-cjs/index.js +8 -6
  99. package/node_modules/@smithy/util-body-length-node/dist-es/calculateBodyLength.js +8 -6
  100. package/node_modules/@smithy/util-body-length-node/package.json +1 -1
  101. package/node_modules/@smithy/util-defaults-mode-browser/dist-cjs/resolveDefaultsModeConfig.js +11 -9
  102. package/node_modules/@smithy/util-defaults-mode-browser/dist-es/resolveDefaultsModeConfig.js +11 -8
  103. package/node_modules/@smithy/util-defaults-mode-browser/package.json +2 -3
  104. package/node_modules/@smithy/util-defaults-mode-node/package.json +2 -2
  105. package/node_modules/@smithy/util-stream/dist-cjs/index.js +3 -5
  106. package/node_modules/@smithy/util-stream/dist-es/blob/Uint8ArrayBlobAdapter.js +3 -5
  107. package/node_modules/@smithy/util-stream/dist-types/blob/Uint8ArrayBlobAdapter.d.ts +1 -0
  108. package/node_modules/@smithy/util-stream/dist-types/ts3.4/blob/Uint8ArrayBlobAdapter.d.ts +1 -0
  109. package/node_modules/@smithy/util-stream/package.json +3 -3
  110. package/package.json +3 -3
@@ -1,1906 +1,1624 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
-
21
- // src/submodules/protocols/index.ts
22
- var index_exports = {};
23
- __export(index_exports, {
24
- AwsEc2QueryProtocol: () => AwsEc2QueryProtocol,
25
- AwsJson1_0Protocol: () => AwsJson1_0Protocol,
26
- AwsJson1_1Protocol: () => AwsJson1_1Protocol,
27
- AwsJsonRpcProtocol: () => AwsJsonRpcProtocol,
28
- AwsQueryProtocol: () => AwsQueryProtocol,
29
- AwsRestJsonProtocol: () => AwsRestJsonProtocol,
30
- AwsRestXmlProtocol: () => AwsRestXmlProtocol,
31
- AwsSmithyRpcV2CborProtocol: () => AwsSmithyRpcV2CborProtocol,
32
- JsonCodec: () => JsonCodec,
33
- JsonShapeDeserializer: () => JsonShapeDeserializer,
34
- JsonShapeSerializer: () => JsonShapeSerializer,
35
- XmlCodec: () => XmlCodec,
36
- XmlShapeDeserializer: () => XmlShapeDeserializer,
37
- XmlShapeSerializer: () => XmlShapeSerializer,
38
- _toBool: () => _toBool,
39
- _toNum: () => _toNum,
40
- _toStr: () => _toStr,
41
- awsExpectUnion: () => awsExpectUnion,
42
- loadRestJsonErrorCode: () => loadRestJsonErrorCode,
43
- loadRestXmlErrorCode: () => loadRestXmlErrorCode,
44
- parseJsonBody: () => parseJsonBody,
45
- parseJsonErrorBody: () => parseJsonErrorBody,
46
- parseXmlBody: () => parseXmlBody,
47
- parseXmlErrorBody: () => parseXmlErrorBody
48
- });
49
- module.exports = __toCommonJS(index_exports);
1
+ 'use strict';
50
2
 
51
- // src/submodules/protocols/cbor/AwsSmithyRpcV2CborProtocol.ts
52
- var import_cbor = require("@smithy/core/cbor");
53
- var import_schema2 = require("@smithy/core/schema");
3
+ var cbor = require('@smithy/core/cbor');
4
+ var schema = require('@smithy/core/schema');
5
+ var protocols = require('@smithy/core/protocols');
6
+ var serde = require('@smithy/core/serde');
7
+ var utilBase64 = require('@smithy/util-base64');
8
+ var smithyClient = require('@smithy/smithy-client');
9
+ var utilUtf8 = require('@smithy/util-utf8');
10
+ var xmlBuilder = require('@aws-sdk/xml-builder');
54
11
 
55
- // src/submodules/protocols/ProtocolLib.ts
56
- var import_schema = require("@smithy/core/schema");
57
- var ProtocolLib = class {
58
- static {
59
- __name(this, "ProtocolLib");
60
- }
61
- /**
62
- * This is only for REST protocols.
63
- *
64
- * @param defaultContentType - of the protocol.
65
- * @param inputSchema - schema for which to determine content type.
66
- *
67
- * @returns content-type header value or undefined when not applicable.
68
- */
69
- resolveRestContentType(defaultContentType, inputSchema) {
70
- const members = inputSchema.getMemberSchemas();
71
- const httpPayloadMember = Object.values(members).find((m) => {
72
- return !!m.getMergedTraits().httpPayload;
73
- });
74
- if (httpPayloadMember) {
75
- const mediaType = httpPayloadMember.getMergedTraits().mediaType;
76
- if (mediaType) {
77
- return mediaType;
78
- } else if (httpPayloadMember.isStringSchema()) {
79
- return "text/plain";
80
- } else if (httpPayloadMember.isBlobSchema()) {
81
- return "application/octet-stream";
82
- } else {
83
- return defaultContentType;
84
- }
85
- } else if (!inputSchema.isUnitSchema()) {
86
- const hasBody = Object.values(members).find((m) => {
87
- const { httpQuery, httpQueryParams, httpHeader, httpLabel, httpPrefixHeaders } = m.getMergedTraits();
88
- const noPrefixHeaders = httpPrefixHeaders === void 0;
89
- return !httpQuery && !httpQueryParams && !httpHeader && !httpLabel && noPrefixHeaders;
90
- });
91
- if (hasBody) {
92
- return defaultContentType;
93
- }
94
- }
95
- }
96
- /**
97
- * Shared code for finding error schema or throwing an unmodeled base error.
98
- * @returns error schema and error metadata.
99
- *
100
- * @throws ServiceBaseException or generic Error if no error schema could be found.
101
- */
102
- async getErrorSchemaOrThrowBaseException(errorIdentifier, defaultNamespace, response, dataObject, metadata, getErrorSchema) {
103
- let namespace = defaultNamespace;
104
- let errorName = errorIdentifier;
105
- if (errorIdentifier.includes("#")) {
106
- [namespace, errorName] = errorIdentifier.split("#");
107
- }
108
- const errorMetadata = {
109
- $metadata: metadata,
110
- $response: response,
111
- $fault: response.statusCode < 500 ? "client" : "server"
112
- };
113
- const registry = import_schema.TypeRegistry.for(namespace);
114
- try {
115
- const errorSchema = getErrorSchema?.(registry, errorName) ?? registry.getSchema(errorIdentifier);
116
- return { errorSchema, errorMetadata };
117
- } catch (e) {
118
- dataObject.message = dataObject.message ?? dataObject.Message ?? "UnknownError";
119
- const synthetic = import_schema.TypeRegistry.for("smithy.ts.sdk.synthetic." + namespace);
120
- const baseExceptionSchema = synthetic.getBaseException();
121
- if (baseExceptionSchema) {
122
- const ErrorCtor = synthetic.getErrorCtor(baseExceptionSchema) ?? Error;
123
- throw Object.assign(new ErrorCtor({ name: errorName }), errorMetadata, dataObject);
124
- }
125
- throw Object.assign(new Error(errorName), errorMetadata, dataObject);
126
- }
127
- }
128
- /**
129
- * Reads the x-amzn-query-error header for awsQuery compatibility.
130
- *
131
- * @param output - values that will be assigned to an error object.
132
- * @param response - from which to read awsQueryError headers.
133
- */
134
- setQueryCompatError(output, response) {
135
- const queryErrorHeader = response.headers?.["x-amzn-query-error"];
136
- if (output !== void 0 && queryErrorHeader != null) {
137
- const [Code, Type] = queryErrorHeader.split(";");
138
- const entries = Object.entries(output);
139
- const Error2 = {
140
- Code,
141
- Type
142
- };
143
- Object.assign(output, Error2);
144
- for (const [k, v] of entries) {
145
- Error2[k] = v;
146
- }
147
- delete Error2.__type;
148
- output.Error = Error2;
149
- }
150
- }
151
- /**
152
- * Assigns Error, Type, Code from the awsQuery error object to the output error object.
153
- * @param queryCompatErrorData - query compat error object.
154
- * @param errorData - canonical error object returned to the caller.
155
- */
156
- queryCompatOutput(queryCompatErrorData, errorData) {
157
- if (queryCompatErrorData.Error) {
158
- errorData.Error = queryCompatErrorData.Error;
159
- }
160
- if (queryCompatErrorData.Type) {
161
- errorData.Type = queryCompatErrorData.Type;
162
- }
163
- if (queryCompatErrorData.Code) {
164
- errorData.Code = queryCompatErrorData.Code;
165
- }
166
- }
167
- };
12
+ class ProtocolLib {
13
+ resolveRestContentType(defaultContentType, inputSchema) {
14
+ const members = inputSchema.getMemberSchemas();
15
+ const httpPayloadMember = Object.values(members).find((m) => {
16
+ return !!m.getMergedTraits().httpPayload;
17
+ });
18
+ if (httpPayloadMember) {
19
+ const mediaType = httpPayloadMember.getMergedTraits().mediaType;
20
+ if (mediaType) {
21
+ return mediaType;
22
+ }
23
+ else if (httpPayloadMember.isStringSchema()) {
24
+ return "text/plain";
25
+ }
26
+ else if (httpPayloadMember.isBlobSchema()) {
27
+ return "application/octet-stream";
28
+ }
29
+ else {
30
+ return defaultContentType;
31
+ }
32
+ }
33
+ else if (!inputSchema.isUnitSchema()) {
34
+ const hasBody = Object.values(members).find((m) => {
35
+ const { httpQuery, httpQueryParams, httpHeader, httpLabel, httpPrefixHeaders } = m.getMergedTraits();
36
+ const noPrefixHeaders = httpPrefixHeaders === void 0;
37
+ return !httpQuery && !httpQueryParams && !httpHeader && !httpLabel && noPrefixHeaders;
38
+ });
39
+ if (hasBody) {
40
+ return defaultContentType;
41
+ }
42
+ }
43
+ }
44
+ async getErrorSchemaOrThrowBaseException(errorIdentifier, defaultNamespace, response, dataObject, metadata, getErrorSchema) {
45
+ let namespace = defaultNamespace;
46
+ let errorName = errorIdentifier;
47
+ if (errorIdentifier.includes("#")) {
48
+ [namespace, errorName] = errorIdentifier.split("#");
49
+ }
50
+ const errorMetadata = {
51
+ $metadata: metadata,
52
+ $response: response,
53
+ $fault: response.statusCode < 500 ? "client" : "server",
54
+ };
55
+ const registry = schema.TypeRegistry.for(namespace);
56
+ try {
57
+ const errorSchema = getErrorSchema?.(registry, errorName) ?? registry.getSchema(errorIdentifier);
58
+ return { errorSchema, errorMetadata };
59
+ }
60
+ catch (e) {
61
+ dataObject.message = dataObject.message ?? dataObject.Message ?? "UnknownError";
62
+ const synthetic = schema.TypeRegistry.for("smithy.ts.sdk.synthetic." + namespace);
63
+ const baseExceptionSchema = synthetic.getBaseException();
64
+ if (baseExceptionSchema) {
65
+ const ErrorCtor = synthetic.getErrorCtor(baseExceptionSchema) ?? Error;
66
+ throw Object.assign(new ErrorCtor({ name: errorName }), errorMetadata, dataObject);
67
+ }
68
+ throw Object.assign(new Error(errorName), errorMetadata, dataObject);
69
+ }
70
+ }
71
+ setQueryCompatError(output, response) {
72
+ const queryErrorHeader = response.headers?.["x-amzn-query-error"];
73
+ if (output !== undefined && queryErrorHeader != null) {
74
+ const [Code, Type] = queryErrorHeader.split(";");
75
+ const entries = Object.entries(output);
76
+ const Error = {
77
+ Code,
78
+ Type,
79
+ };
80
+ Object.assign(output, Error);
81
+ for (const [k, v] of entries) {
82
+ Error[k] = v;
83
+ }
84
+ delete Error.__type;
85
+ output.Error = Error;
86
+ }
87
+ }
88
+ queryCompatOutput(queryCompatErrorData, errorData) {
89
+ if (queryCompatErrorData.Error) {
90
+ errorData.Error = queryCompatErrorData.Error;
91
+ }
92
+ if (queryCompatErrorData.Type) {
93
+ errorData.Type = queryCompatErrorData.Type;
94
+ }
95
+ if (queryCompatErrorData.Code) {
96
+ errorData.Code = queryCompatErrorData.Code;
97
+ }
98
+ }
99
+ }
168
100
 
169
- // src/submodules/protocols/cbor/AwsSmithyRpcV2CborProtocol.ts
170
- var AwsSmithyRpcV2CborProtocol = class extends import_cbor.SmithyRpcV2CborProtocol {
171
- static {
172
- __name(this, "AwsSmithyRpcV2CborProtocol");
173
- }
174
- awsQueryCompatible;
175
- mixin = new ProtocolLib();
176
- constructor({
177
- defaultNamespace,
178
- awsQueryCompatible
179
- }) {
180
- super({ defaultNamespace });
181
- this.awsQueryCompatible = !!awsQueryCompatible;
182
- }
183
- /**
184
- * @override
185
- */
186
- async serializeRequest(operationSchema, input, context) {
187
- const request = await super.serializeRequest(operationSchema, input, context);
188
- if (this.awsQueryCompatible) {
189
- request.headers["x-amzn-query-mode"] = "true";
190
- }
191
- return request;
192
- }
193
- /**
194
- * @override
195
- */
196
- async handleError(operationSchema, context, response, dataObject, metadata) {
197
- if (this.awsQueryCompatible) {
198
- this.mixin.setQueryCompatError(dataObject, response);
199
- }
200
- const errorName = (0, import_cbor.loadSmithyRpcV2CborErrorCode)(response, dataObject) ?? "Unknown";
201
- const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(
202
- errorName,
203
- this.options.defaultNamespace,
204
- response,
205
- dataObject,
206
- metadata
207
- );
208
- const ns = import_schema2.NormalizedSchema.of(errorSchema);
209
- const message = dataObject.message ?? dataObject.Message ?? "Unknown";
210
- const ErrorCtor = import_schema2.TypeRegistry.for(errorSchema.namespace).getErrorCtor(errorSchema) ?? Error;
211
- const exception = new ErrorCtor(message);
212
- const output = {};
213
- for (const [name, member] of ns.structIterator()) {
214
- output[name] = this.deserializer.readValue(member, dataObject[name]);
215
- }
216
- if (this.awsQueryCompatible) {
217
- this.mixin.queryCompatOutput(dataObject, output);
218
- }
219
- throw Object.assign(
220
- exception,
221
- errorMetadata,
222
- {
223
- $fault: ns.getMergedTraits().error,
224
- message
225
- },
226
- output
227
- );
228
- }
229
- };
101
+ class AwsSmithyRpcV2CborProtocol extends cbor.SmithyRpcV2CborProtocol {
102
+ awsQueryCompatible;
103
+ mixin = new ProtocolLib();
104
+ constructor({ defaultNamespace, awsQueryCompatible, }) {
105
+ super({ defaultNamespace });
106
+ this.awsQueryCompatible = !!awsQueryCompatible;
107
+ }
108
+ async serializeRequest(operationSchema, input, context) {
109
+ const request = await super.serializeRequest(operationSchema, input, context);
110
+ if (this.awsQueryCompatible) {
111
+ request.headers["x-amzn-query-mode"] = "true";
112
+ }
113
+ return request;
114
+ }
115
+ async handleError(operationSchema, context, response, dataObject, metadata) {
116
+ if (this.awsQueryCompatible) {
117
+ this.mixin.setQueryCompatError(dataObject, response);
118
+ }
119
+ const errorName = cbor.loadSmithyRpcV2CborErrorCode(response, dataObject) ?? "Unknown";
120
+ const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorName, this.options.defaultNamespace, response, dataObject, metadata);
121
+ const ns = schema.NormalizedSchema.of(errorSchema);
122
+ const message = dataObject.message ?? dataObject.Message ?? "Unknown";
123
+ const ErrorCtor = schema.TypeRegistry.for(errorSchema.namespace).getErrorCtor(errorSchema) ?? Error;
124
+ const exception = new ErrorCtor(message);
125
+ const output = {};
126
+ for (const [name, member] of ns.structIterator()) {
127
+ output[name] = this.deserializer.readValue(member, dataObject[name]);
128
+ }
129
+ if (this.awsQueryCompatible) {
130
+ this.mixin.queryCompatOutput(dataObject, output);
131
+ }
132
+ throw Object.assign(exception, errorMetadata, {
133
+ $fault: ns.getMergedTraits().error,
134
+ message,
135
+ }, output);
136
+ }
137
+ }
230
138
 
231
- // src/submodules/protocols/coercing-serializers.ts
232
- var _toStr = /* @__PURE__ */ __name((val) => {
233
- if (val == null) {
139
+ const _toStr = (val) => {
140
+ if (val == null) {
141
+ return val;
142
+ }
143
+ if (typeof val === "number" || typeof val === "bigint") {
144
+ const warning = new Error(`Received number ${val} where a string was expected.`);
145
+ warning.name = "Warning";
146
+ console.warn(warning);
147
+ return String(val);
148
+ }
149
+ if (typeof val === "boolean") {
150
+ const warning = new Error(`Received boolean ${val} where a string was expected.`);
151
+ warning.name = "Warning";
152
+ console.warn(warning);
153
+ return String(val);
154
+ }
234
155
  return val;
235
- }
236
- if (typeof val === "number" || typeof val === "bigint") {
237
- const warning = new Error(`Received number ${val} where a string was expected.`);
238
- warning.name = "Warning";
239
- console.warn(warning);
240
- return String(val);
241
- }
242
- if (typeof val === "boolean") {
243
- const warning = new Error(`Received boolean ${val} where a string was expected.`);
244
- warning.name = "Warning";
245
- console.warn(warning);
246
- return String(val);
247
- }
248
- return val;
249
- }, "_toStr");
250
- var _toBool = /* @__PURE__ */ __name((val) => {
251
- if (val == null) {
156
+ };
157
+ const _toBool = (val) => {
158
+ if (val == null) {
159
+ return val;
160
+ }
161
+ if (typeof val === "string") {
162
+ const lowercase = val.toLowerCase();
163
+ if (val !== "" && lowercase !== "false" && lowercase !== "true") {
164
+ const warning = new Error(`Received string "${val}" where a boolean was expected.`);
165
+ warning.name = "Warning";
166
+ console.warn(warning);
167
+ }
168
+ return val !== "" && lowercase !== "false";
169
+ }
252
170
  return val;
253
- }
254
- if (typeof val === "number") {
255
- }
256
- if (typeof val === "string") {
257
- const lowercase = val.toLowerCase();
258
- if (val !== "" && lowercase !== "false" && lowercase !== "true") {
259
- const warning = new Error(`Received string "${val}" where a boolean was expected.`);
260
- warning.name = "Warning";
261
- console.warn(warning);
262
- }
263
- return val !== "" && lowercase !== "false";
264
- }
265
- return val;
266
- }, "_toBool");
267
- var _toNum = /* @__PURE__ */ __name((val) => {
268
- if (val == null) {
171
+ };
172
+ const _toNum = (val) => {
173
+ if (val == null) {
174
+ return val;
175
+ }
176
+ if (typeof val === "string") {
177
+ const num = Number(val);
178
+ if (num.toString() !== val) {
179
+ const warning = new Error(`Received string "${val}" where a number was expected.`);
180
+ warning.name = "Warning";
181
+ console.warn(warning);
182
+ return val;
183
+ }
184
+ return num;
185
+ }
269
186
  return val;
270
- }
271
- if (typeof val === "boolean") {
272
- }
273
- if (typeof val === "string") {
274
- const num = Number(val);
275
- if (num.toString() !== val) {
276
- const warning = new Error(`Received string "${val}" where a number was expected.`);
277
- warning.name = "Warning";
278
- console.warn(warning);
279
- return val;
280
- }
281
- return num;
282
- }
283
- return val;
284
- }, "_toNum");
285
-
286
- // src/submodules/protocols/json/AwsJsonRpcProtocol.ts
287
- var import_protocols3 = require("@smithy/core/protocols");
288
- var import_schema5 = require("@smithy/core/schema");
289
-
290
- // src/submodules/protocols/ConfigurableSerdeContext.ts
291
- var SerdeContextConfig = class {
292
- static {
293
- __name(this, "SerdeContextConfig");
294
- }
295
- serdeContext;
296
- setSerdeContext(serdeContext) {
297
- this.serdeContext = serdeContext;
298
- }
299
187
  };
300
188
 
301
- // src/submodules/protocols/json/JsonShapeDeserializer.ts
302
- var import_protocols = require("@smithy/core/protocols");
303
- var import_schema3 = require("@smithy/core/schema");
304
- var import_serde2 = require("@smithy/core/serde");
305
- var import_util_base64 = require("@smithy/util-base64");
189
+ class SerdeContextConfig {
190
+ serdeContext;
191
+ setSerdeContext(serdeContext) {
192
+ this.serdeContext = serdeContext;
193
+ }
194
+ }
306
195
 
307
- // src/submodules/protocols/json/jsonReviver.ts
308
- var import_serde = require("@smithy/core/serde");
309
196
  function jsonReviver(key, value, context) {
310
- if (context?.source) {
311
- const numericString = context.source;
312
- if (typeof value === "number") {
313
- if (value > Number.MAX_SAFE_INTEGER || value < Number.MIN_SAFE_INTEGER || numericString !== String(value)) {
314
- const isFractional = numericString.includes(".");
315
- if (isFractional) {
316
- return new import_serde.NumericValue(numericString, "bigDecimal");
317
- } else {
318
- return BigInt(numericString);
319
- }
320
- }
321
- }
322
- }
323
- return value;
197
+ if (context?.source) {
198
+ const numericString = context.source;
199
+ if (typeof value === "number") {
200
+ if (value > Number.MAX_SAFE_INTEGER || value < Number.MIN_SAFE_INTEGER || numericString !== String(value)) {
201
+ const isFractional = numericString.includes(".");
202
+ if (isFractional) {
203
+ return new serde.NumericValue(numericString, "bigDecimal");
204
+ }
205
+ else {
206
+ return BigInt(numericString);
207
+ }
208
+ }
209
+ }
210
+ }
211
+ return value;
324
212
  }
325
- __name(jsonReviver, "jsonReviver");
326
213
 
327
- // src/submodules/protocols/common.ts
328
- var import_smithy_client = require("@smithy/smithy-client");
329
- var import_util_utf8 = require("@smithy/util-utf8");
330
- var collectBodyString = /* @__PURE__ */ __name((streamBody, context) => (0, import_smithy_client.collectBody)(streamBody, context).then((body) => (context?.utf8Encoder ?? import_util_utf8.toUtf8)(body)), "collectBodyString");
214
+ const collectBodyString = (streamBody, context) => smithyClient.collectBody(streamBody, context).then((body) => (context?.utf8Encoder ?? utilUtf8.toUtf8)(body));
331
215
 
332
- // src/submodules/protocols/json/parseJsonBody.ts
333
- var parseJsonBody = /* @__PURE__ */ __name((streamBody, context) => collectBodyString(streamBody, context).then((encoded) => {
334
- if (encoded.length) {
335
- try {
336
- return JSON.parse(encoded);
337
- } catch (e) {
338
- if (e?.name === "SyntaxError") {
339
- Object.defineProperty(e, "$responseBodyText", {
340
- value: encoded
341
- });
342
- }
343
- throw e;
344
- }
345
- }
346
- return {};
347
- }), "parseJsonBody");
348
- var parseJsonErrorBody = /* @__PURE__ */ __name(async (errorBody, context) => {
349
- const value = await parseJsonBody(errorBody, context);
350
- value.message = value.message ?? value.Message;
351
- return value;
352
- }, "parseJsonErrorBody");
353
- var loadRestJsonErrorCode = /* @__PURE__ */ __name((output, data) => {
354
- const findKey = /* @__PURE__ */ __name((object, key) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase()), "findKey");
355
- const sanitizeErrorCode = /* @__PURE__ */ __name((rawValue) => {
356
- let cleanValue = rawValue;
357
- if (typeof cleanValue === "number") {
358
- cleanValue = cleanValue.toString();
359
- }
360
- if (cleanValue.indexOf(",") >= 0) {
361
- cleanValue = cleanValue.split(",")[0];
362
- }
363
- if (cleanValue.indexOf(":") >= 0) {
364
- cleanValue = cleanValue.split(":")[0];
365
- }
366
- if (cleanValue.indexOf("#") >= 0) {
367
- cleanValue = cleanValue.split("#")[1];
368
- }
369
- return cleanValue;
370
- }, "sanitizeErrorCode");
371
- const headerKey = findKey(output.headers, "x-amzn-errortype");
372
- if (headerKey !== void 0) {
373
- return sanitizeErrorCode(output.headers[headerKey]);
374
- }
375
- if (data && typeof data === "object") {
376
- const codeKey = findKey(data, "code");
377
- if (codeKey && data[codeKey] !== void 0) {
378
- return sanitizeErrorCode(data[codeKey]);
379
- }
380
- if (data["__type"] !== void 0) {
381
- return sanitizeErrorCode(data["__type"]);
382
- }
383
- }
384
- }, "loadRestJsonErrorCode");
385
-
386
- // src/submodules/protocols/json/JsonShapeDeserializer.ts
387
- var JsonShapeDeserializer = class extends SerdeContextConfig {
388
- constructor(settings) {
389
- super();
390
- this.settings = settings;
391
- }
392
- static {
393
- __name(this, "JsonShapeDeserializer");
394
- }
395
- async read(schema, data) {
396
- return this._read(
397
- schema,
398
- typeof data === "string" ? JSON.parse(data, jsonReviver) : await parseJsonBody(data, this.serdeContext)
399
- );
400
- }
401
- readObject(schema, data) {
402
- return this._read(schema, data);
403
- }
404
- _read(schema, value) {
405
- const isObject = value !== null && typeof value === "object";
406
- const ns = import_schema3.NormalizedSchema.of(schema);
407
- if (ns.isListSchema() && Array.isArray(value)) {
408
- const listMember = ns.getValueSchema();
409
- const out = [];
410
- const sparse = !!ns.getMergedTraits().sparse;
411
- for (const item of value) {
412
- if (sparse || item != null) {
413
- out.push(this._read(listMember, item));
414
- }
415
- }
416
- return out;
417
- } else if (ns.isMapSchema() && isObject) {
418
- const mapMember = ns.getValueSchema();
419
- const out = {};
420
- const sparse = !!ns.getMergedTraits().sparse;
421
- for (const [_k, _v] of Object.entries(value)) {
422
- if (sparse || _v != null) {
423
- out[_k] = this._read(mapMember, _v);
424
- }
425
- }
426
- return out;
427
- } else if (ns.isStructSchema() && isObject) {
428
- const out = {};
429
- for (const [memberName, memberSchema] of ns.structIterator()) {
430
- const fromKey = this.settings.jsonName ? memberSchema.getMergedTraits().jsonName ?? memberName : memberName;
431
- const deserializedValue = this._read(memberSchema, value[fromKey]);
432
- if (deserializedValue != null) {
433
- out[memberName] = deserializedValue;
434
- }
435
- }
436
- return out;
437
- }
438
- if (ns.isBlobSchema() && typeof value === "string") {
439
- return (0, import_util_base64.fromBase64)(value);
440
- }
441
- const mediaType = ns.getMergedTraits().mediaType;
442
- if (ns.isStringSchema() && typeof value === "string" && mediaType) {
443
- const isJson = mediaType === "application/json" || mediaType.endsWith("+json");
444
- if (isJson) {
445
- return import_serde2.LazyJsonString.from(value);
446
- }
447
- }
448
- if (ns.isTimestampSchema() && value != null) {
449
- const format = (0, import_protocols.determineTimestampFormat)(ns, this.settings);
450
- switch (format) {
451
- case import_schema3.SCHEMA.TIMESTAMP_DATE_TIME:
452
- return (0, import_serde2.parseRfc3339DateTimeWithOffset)(value);
453
- case import_schema3.SCHEMA.TIMESTAMP_HTTP_DATE:
454
- return (0, import_serde2.parseRfc7231DateTime)(value);
455
- case import_schema3.SCHEMA.TIMESTAMP_EPOCH_SECONDS:
456
- return (0, import_serde2.parseEpochTimestamp)(value);
457
- default:
458
- console.warn("Missing timestamp format, parsing value with Date constructor:", value);
459
- return new Date(value);
460
- }
461
- }
462
- if (ns.isBigIntegerSchema() && (typeof value === "number" || typeof value === "string")) {
463
- return BigInt(value);
464
- }
465
- if (ns.isBigDecimalSchema() && value != void 0) {
466
- if (value instanceof import_serde2.NumericValue) {
467
- return value;
468
- }
469
- const untyped = value;
470
- if (untyped.type === "bigDecimal" && "string" in untyped) {
471
- return new import_serde2.NumericValue(untyped.string, untyped.type);
472
- }
473
- return new import_serde2.NumericValue(String(value), "bigDecimal");
474
- }
475
- if (ns.isNumericSchema() && typeof value === "string") {
476
- switch (value) {
477
- case "Infinity":
478
- return Infinity;
479
- case "-Infinity":
480
- return -Infinity;
481
- case "NaN":
482
- return NaN;
483
- }
484
- }
485
- if (ns.isDocumentSchema()) {
486
- if (isObject) {
487
- const out = Array.isArray(value) ? [] : {};
488
- for (const [k, v] of Object.entries(value)) {
489
- if (v instanceof import_serde2.NumericValue) {
490
- out[k] = v;
491
- } else {
492
- out[k] = this._read(ns, v);
493
- }
494
- }
495
- return out;
496
- } else {
497
- return structuredClone(value);
498
- }
216
+ const parseJsonBody = (streamBody, context) => collectBodyString(streamBody, context).then((encoded) => {
217
+ if (encoded.length) {
218
+ try {
219
+ return JSON.parse(encoded);
220
+ }
221
+ catch (e) {
222
+ if (e?.name === "SyntaxError") {
223
+ Object.defineProperty(e, "$responseBodyText", {
224
+ value: encoded,
225
+ });
226
+ }
227
+ throw e;
228
+ }
499
229
  }
230
+ return {};
231
+ });
232
+ const parseJsonErrorBody = async (errorBody, context) => {
233
+ const value = await parseJsonBody(errorBody, context);
234
+ value.message = value.message ?? value.Message;
500
235
  return value;
501
- }
502
236
  };
503
-
504
- // src/submodules/protocols/json/JsonShapeSerializer.ts
505
- var import_protocols2 = require("@smithy/core/protocols");
506
- var import_schema4 = require("@smithy/core/schema");
507
- var import_serde4 = require("@smithy/core/serde");
508
- var import_util_base642 = require("@smithy/util-base64");
509
-
510
- // src/submodules/protocols/json/jsonReplacer.ts
511
- var import_serde3 = require("@smithy/core/serde");
512
- var NUMERIC_CONTROL_CHAR = String.fromCharCode(925);
513
- var JsonReplacer = class {
514
- static {
515
- __name(this, "JsonReplacer");
516
- }
517
- /**
518
- * Stores placeholder key to true serialized value lookup.
519
- */
520
- values = /* @__PURE__ */ new Map();
521
- counter = 0;
522
- stage = 0;
523
- /**
524
- * Creates a jsonReplacer function that reserves big integer and big decimal values
525
- * for later replacement.
526
- */
527
- createReplacer() {
528
- if (this.stage === 1) {
529
- throw new Error("@aws-sdk/core/protocols - JsonReplacer already created.");
530
- }
531
- if (this.stage === 2) {
532
- throw new Error("@aws-sdk/core/protocols - JsonReplacer exhausted.");
533
- }
534
- this.stage = 1;
535
- return (key, value) => {
536
- if (value instanceof import_serde3.NumericValue) {
537
- const v = `${NUMERIC_CONTROL_CHAR + "nv" + this.counter++}_` + value.string;
538
- this.values.set(`"${v}"`, value.string);
539
- return v;
540
- }
541
- if (typeof value === "bigint") {
542
- const s = value.toString();
543
- const v = `${NUMERIC_CONTROL_CHAR + "b" + this.counter++}_` + s;
544
- this.values.set(`"${v}"`, s);
545
- return v;
546
- }
547
- return value;
237
+ const loadRestJsonErrorCode = (output, data) => {
238
+ const findKey = (object, key) => Object.keys(object).find((k) => k.toLowerCase() === key.toLowerCase());
239
+ const sanitizeErrorCode = (rawValue) => {
240
+ let cleanValue = rawValue;
241
+ if (typeof cleanValue === "number") {
242
+ cleanValue = cleanValue.toString();
243
+ }
244
+ if (cleanValue.indexOf(",") >= 0) {
245
+ cleanValue = cleanValue.split(",")[0];
246
+ }
247
+ if (cleanValue.indexOf(":") >= 0) {
248
+ cleanValue = cleanValue.split(":")[0];
249
+ }
250
+ if (cleanValue.indexOf("#") >= 0) {
251
+ cleanValue = cleanValue.split("#")[1];
252
+ }
253
+ return cleanValue;
548
254
  };
549
- }
550
- /**
551
- * Replaces placeholder keys with their true values.
552
- */
553
- replaceInJson(json) {
554
- if (this.stage === 0) {
555
- throw new Error("@aws-sdk/core/protocols - JsonReplacer not created yet.");
556
- }
557
- if (this.stage === 2) {
558
- throw new Error("@aws-sdk/core/protocols - JsonReplacer exhausted.");
559
- }
560
- this.stage = 2;
561
- if (this.counter === 0) {
562
- return json;
563
- }
564
- for (const [key, value] of this.values) {
565
- json = json.replace(key, value);
566
- }
567
- return json;
568
- }
255
+ const headerKey = findKey(output.headers, "x-amzn-errortype");
256
+ if (headerKey !== undefined) {
257
+ return sanitizeErrorCode(output.headers[headerKey]);
258
+ }
259
+ if (data && typeof data === "object") {
260
+ const codeKey = findKey(data, "code");
261
+ if (codeKey && data[codeKey] !== undefined) {
262
+ return sanitizeErrorCode(data[codeKey]);
263
+ }
264
+ if (data["__type"] !== undefined) {
265
+ return sanitizeErrorCode(data["__type"]);
266
+ }
267
+ }
569
268
  };
570
269
 
571
- // src/submodules/protocols/json/JsonShapeSerializer.ts
572
- var JsonShapeSerializer = class extends SerdeContextConfig {
573
- constructor(settings) {
574
- super();
575
- this.settings = settings;
576
- }
577
- static {
578
- __name(this, "JsonShapeSerializer");
579
- }
580
- buffer;
581
- rootSchema;
582
- write(schema, value) {
583
- this.rootSchema = import_schema4.NormalizedSchema.of(schema);
584
- this.buffer = this._write(this.rootSchema, value);
585
- }
586
- /**
587
- * @internal
588
- */
589
- writeDiscriminatedDocument(schema, value) {
590
- this.write(schema, value);
591
- if (typeof this.buffer === "object") {
592
- this.buffer.__type = import_schema4.NormalizedSchema.of(schema).getName(true);
593
- }
594
- }
595
- flush() {
596
- const { rootSchema } = this;
597
- this.rootSchema = void 0;
598
- if (rootSchema?.isStructSchema() || rootSchema?.isDocumentSchema()) {
599
- const replacer = new JsonReplacer();
600
- return replacer.replaceInJson(JSON.stringify(this.buffer, replacer.createReplacer(), 0));
601
- }
602
- return this.buffer;
603
- }
604
- _write(schema, value, container) {
605
- const isObject = value !== null && typeof value === "object";
606
- const ns = import_schema4.NormalizedSchema.of(schema);
607
- if (ns.isListSchema() && Array.isArray(value)) {
608
- const listMember = ns.getValueSchema();
609
- const out = [];
610
- const sparse = !!ns.getMergedTraits().sparse;
611
- for (const item of value) {
612
- if (sparse || item != null) {
613
- out.push(this._write(listMember, item));
614
- }
615
- }
616
- return out;
617
- } else if (ns.isMapSchema() && isObject) {
618
- const mapMember = ns.getValueSchema();
619
- const out = {};
620
- const sparse = !!ns.getMergedTraits().sparse;
621
- for (const [_k, _v] of Object.entries(value)) {
622
- if (sparse || _v != null) {
623
- out[_k] = this._write(mapMember, _v);
624
- }
625
- }
626
- return out;
627
- } else if (ns.isStructSchema() && isObject) {
628
- const out = {};
629
- for (const [memberName, memberSchema] of ns.structIterator()) {
630
- const targetKey = this.settings.jsonName ? memberSchema.getMergedTraits().jsonName ?? memberName : memberName;
631
- const serializableValue = this._write(memberSchema, value[memberName], ns);
632
- if (serializableValue !== void 0) {
633
- out[targetKey] = serializableValue;
634
- }
635
- }
636
- return out;
637
- }
638
- if (value === null && container?.isStructSchema()) {
639
- return void 0;
640
- }
641
- if (ns.isBlobSchema() && (value instanceof Uint8Array || typeof value === "string") || ns.isDocumentSchema() && value instanceof Uint8Array) {
642
- if (ns === this.rootSchema) {
270
+ class JsonShapeDeserializer extends SerdeContextConfig {
271
+ settings;
272
+ constructor(settings) {
273
+ super();
274
+ this.settings = settings;
275
+ }
276
+ async read(schema, data) {
277
+ return this._read(schema, typeof data === "string" ? JSON.parse(data, jsonReviver) : await parseJsonBody(data, this.serdeContext));
278
+ }
279
+ readObject(schema, data) {
280
+ return this._read(schema, data);
281
+ }
282
+ _read(schema$1, value) {
283
+ const isObject = value !== null && typeof value === "object";
284
+ const ns = schema.NormalizedSchema.of(schema$1);
285
+ if (ns.isListSchema() && Array.isArray(value)) {
286
+ const listMember = ns.getValueSchema();
287
+ const out = [];
288
+ const sparse = !!ns.getMergedTraits().sparse;
289
+ for (const item of value) {
290
+ if (sparse || item != null) {
291
+ out.push(this._read(listMember, item));
292
+ }
293
+ }
294
+ return out;
295
+ }
296
+ else if (ns.isMapSchema() && isObject) {
297
+ const mapMember = ns.getValueSchema();
298
+ const out = {};
299
+ const sparse = !!ns.getMergedTraits().sparse;
300
+ for (const [_k, _v] of Object.entries(value)) {
301
+ if (sparse || _v != null) {
302
+ out[_k] = this._read(mapMember, _v);
303
+ }
304
+ }
305
+ return out;
306
+ }
307
+ else if (ns.isStructSchema() && isObject) {
308
+ const out = {};
309
+ for (const [memberName, memberSchema] of ns.structIterator()) {
310
+ const fromKey = this.settings.jsonName ? memberSchema.getMergedTraits().jsonName ?? memberName : memberName;
311
+ const deserializedValue = this._read(memberSchema, value[fromKey]);
312
+ if (deserializedValue != null) {
313
+ out[memberName] = deserializedValue;
314
+ }
315
+ }
316
+ return out;
317
+ }
318
+ if (ns.isBlobSchema() && typeof value === "string") {
319
+ return utilBase64.fromBase64(value);
320
+ }
321
+ const mediaType = ns.getMergedTraits().mediaType;
322
+ if (ns.isStringSchema() && typeof value === "string" && mediaType) {
323
+ const isJson = mediaType === "application/json" || mediaType.endsWith("+json");
324
+ if (isJson) {
325
+ return serde.LazyJsonString.from(value);
326
+ }
327
+ }
328
+ if (ns.isTimestampSchema() && value != null) {
329
+ const format = protocols.determineTimestampFormat(ns, this.settings);
330
+ switch (format) {
331
+ case 5:
332
+ return serde.parseRfc3339DateTimeWithOffset(value);
333
+ case 6:
334
+ return serde.parseRfc7231DateTime(value);
335
+ case 7:
336
+ return serde.parseEpochTimestamp(value);
337
+ default:
338
+ console.warn("Missing timestamp format, parsing value with Date constructor:", value);
339
+ return new Date(value);
340
+ }
341
+ }
342
+ if (ns.isBigIntegerSchema() && (typeof value === "number" || typeof value === "string")) {
343
+ return BigInt(value);
344
+ }
345
+ if (ns.isBigDecimalSchema() && value != undefined) {
346
+ if (value instanceof serde.NumericValue) {
347
+ return value;
348
+ }
349
+ const untyped = value;
350
+ if (untyped.type === "bigDecimal" && "string" in untyped) {
351
+ return new serde.NumericValue(untyped.string, untyped.type);
352
+ }
353
+ return new serde.NumericValue(String(value), "bigDecimal");
354
+ }
355
+ if (ns.isNumericSchema() && typeof value === "string") {
356
+ switch (value) {
357
+ case "Infinity":
358
+ return Infinity;
359
+ case "-Infinity":
360
+ return -Infinity;
361
+ case "NaN":
362
+ return NaN;
363
+ }
364
+ }
365
+ if (ns.isDocumentSchema()) {
366
+ if (isObject) {
367
+ const out = Array.isArray(value) ? [] : {};
368
+ for (const [k, v] of Object.entries(value)) {
369
+ if (v instanceof serde.NumericValue) {
370
+ out[k] = v;
371
+ }
372
+ else {
373
+ out[k] = this._read(ns, v);
374
+ }
375
+ }
376
+ return out;
377
+ }
378
+ else {
379
+ return structuredClone(value);
380
+ }
381
+ }
643
382
  return value;
644
- }
645
- if (!this.serdeContext?.base64Encoder) {
646
- return (0, import_util_base642.toBase64)(value);
647
- }
648
- return this.serdeContext?.base64Encoder(value);
649
- }
650
- if ((ns.isTimestampSchema() || ns.isDocumentSchema()) && value instanceof Date) {
651
- const format = (0, import_protocols2.determineTimestampFormat)(ns, this.settings);
652
- switch (format) {
653
- case import_schema4.SCHEMA.TIMESTAMP_DATE_TIME:
654
- return value.toISOString().replace(".000Z", "Z");
655
- case import_schema4.SCHEMA.TIMESTAMP_HTTP_DATE:
656
- return (0, import_serde4.dateToUtcString)(value);
657
- case import_schema4.SCHEMA.TIMESTAMP_EPOCH_SECONDS:
658
- return value.getTime() / 1e3;
659
- default:
660
- console.warn("Missing timestamp format, using epoch seconds", value);
661
- return value.getTime() / 1e3;
662
- }
663
- }
664
- if (ns.isNumericSchema() && typeof value === "number") {
665
- if (Math.abs(value) === Infinity || isNaN(value)) {
666
- return String(value);
667
- }
668
- }
669
- if (ns.isStringSchema()) {
670
- if (typeof value === "undefined" && ns.isIdempotencyToken()) {
671
- return (0, import_serde4.generateIdempotencyToken)();
672
- }
673
- const mediaType = ns.getMergedTraits().mediaType;
674
- if (value != null && mediaType) {
675
- const isJson = mediaType === "application/json" || mediaType.endsWith("+json");
676
- if (isJson) {
677
- return import_serde4.LazyJsonString.from(value);
678
- }
679
- }
680
- }
681
- if (ns.isDocumentSchema()) {
682
- if (isObject) {
683
- const out = Array.isArray(value) ? [] : {};
684
- for (const [k, v] of Object.entries(value)) {
685
- if (v instanceof import_serde4.NumericValue) {
686
- out[k] = v;
687
- } else {
688
- out[k] = this._write(ns, v);
689
- }
690
- }
691
- return out;
692
- } else {
693
- return structuredClone(value);
694
- }
695
383
  }
696
- return value;
697
- }
698
- };
699
-
700
- // src/submodules/protocols/json/JsonCodec.ts
701
- var JsonCodec = class extends SerdeContextConfig {
702
- constructor(settings) {
703
- super();
704
- this.settings = settings;
705
- }
706
- static {
707
- __name(this, "JsonCodec");
708
- }
709
- createSerializer() {
710
- const serializer = new JsonShapeSerializer(this.settings);
711
- serializer.setSerdeContext(this.serdeContext);
712
- return serializer;
713
- }
714
- createDeserializer() {
715
- const deserializer = new JsonShapeDeserializer(this.settings);
716
- deserializer.setSerdeContext(this.serdeContext);
717
- return deserializer;
718
- }
719
- };
384
+ }
720
385
 
721
- // src/submodules/protocols/json/AwsJsonRpcProtocol.ts
722
- var AwsJsonRpcProtocol = class extends import_protocols3.RpcProtocol {
723
- static {
724
- __name(this, "AwsJsonRpcProtocol");
725
- }
726
- serializer;
727
- deserializer;
728
- serviceTarget;
729
- codec;
730
- mixin = new ProtocolLib();
731
- awsQueryCompatible;
732
- constructor({
733
- defaultNamespace,
734
- serviceTarget,
735
- awsQueryCompatible
736
- }) {
737
- super({
738
- defaultNamespace
739
- });
740
- this.serviceTarget = serviceTarget;
741
- this.codec = new JsonCodec({
742
- timestampFormat: {
743
- useTrait: true,
744
- default: import_schema5.SCHEMA.TIMESTAMP_EPOCH_SECONDS
745
- },
746
- jsonName: false
747
- });
748
- this.serializer = this.codec.createSerializer();
749
- this.deserializer = this.codec.createDeserializer();
750
- this.awsQueryCompatible = !!awsQueryCompatible;
751
- }
752
- async serializeRequest(operationSchema, input, context) {
753
- const request = await super.serializeRequest(operationSchema, input, context);
754
- if (!request.path.endsWith("/")) {
755
- request.path += "/";
756
- }
757
- Object.assign(request.headers, {
758
- "content-type": `application/x-amz-json-${this.getJsonRpcVersion()}`,
759
- "x-amz-target": `${this.serviceTarget}.${import_schema5.NormalizedSchema.of(operationSchema).getName()}`
760
- });
761
- if (this.awsQueryCompatible) {
762
- request.headers["x-amzn-query-mode"] = "true";
763
- }
764
- if ((0, import_schema5.deref)(operationSchema.input) === "unit" || !request.body) {
765
- request.body = "{}";
766
- }
767
- return request;
768
- }
769
- getPayloadCodec() {
770
- return this.codec;
771
- }
772
- async handleError(operationSchema, context, response, dataObject, metadata) {
773
- if (this.awsQueryCompatible) {
774
- this.mixin.setQueryCompatError(dataObject, response);
775
- }
776
- const errorIdentifier = loadRestJsonErrorCode(response, dataObject) ?? "Unknown";
777
- const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(
778
- errorIdentifier,
779
- this.options.defaultNamespace,
780
- response,
781
- dataObject,
782
- metadata
783
- );
784
- const ns = import_schema5.NormalizedSchema.of(errorSchema);
785
- const message = dataObject.message ?? dataObject.Message ?? "Unknown";
786
- const ErrorCtor = import_schema5.TypeRegistry.for(errorSchema.namespace).getErrorCtor(errorSchema) ?? Error;
787
- const exception = new ErrorCtor(message);
788
- const output = {};
789
- for (const [name, member] of ns.structIterator()) {
790
- const target = member.getMergedTraits().jsonName ?? name;
791
- output[name] = this.codec.createDeserializer().readObject(member, dataObject[target]);
792
- }
793
- if (this.awsQueryCompatible) {
794
- this.mixin.queryCompatOutput(dataObject, output);
795
- }
796
- throw Object.assign(
797
- exception,
798
- errorMetadata,
799
- {
800
- $fault: ns.getMergedTraits().error,
801
- message
802
- },
803
- output
804
- );
805
- }
806
- };
386
+ const NUMERIC_CONTROL_CHAR = String.fromCharCode(925);
387
+ class JsonReplacer {
388
+ values = new Map();
389
+ counter = 0;
390
+ stage = 0;
391
+ createReplacer() {
392
+ if (this.stage === 1) {
393
+ throw new Error("@aws-sdk/core/protocols - JsonReplacer already created.");
394
+ }
395
+ if (this.stage === 2) {
396
+ throw new Error("@aws-sdk/core/protocols - JsonReplacer exhausted.");
397
+ }
398
+ this.stage = 1;
399
+ return (key, value) => {
400
+ if (value instanceof serde.NumericValue) {
401
+ const v = `${NUMERIC_CONTROL_CHAR + "nv" + this.counter++}_` + value.string;
402
+ this.values.set(`"${v}"`, value.string);
403
+ return v;
404
+ }
405
+ if (typeof value === "bigint") {
406
+ const s = value.toString();
407
+ const v = `${NUMERIC_CONTROL_CHAR + "b" + this.counter++}_` + s;
408
+ this.values.set(`"${v}"`, s);
409
+ return v;
410
+ }
411
+ return value;
412
+ };
413
+ }
414
+ replaceInJson(json) {
415
+ if (this.stage === 0) {
416
+ throw new Error("@aws-sdk/core/protocols - JsonReplacer not created yet.");
417
+ }
418
+ if (this.stage === 2) {
419
+ throw new Error("@aws-sdk/core/protocols - JsonReplacer exhausted.");
420
+ }
421
+ this.stage = 2;
422
+ if (this.counter === 0) {
423
+ return json;
424
+ }
425
+ for (const [key, value] of this.values) {
426
+ json = json.replace(key, value);
427
+ }
428
+ return json;
429
+ }
430
+ }
807
431
 
808
- // src/submodules/protocols/json/AwsJson1_0Protocol.ts
809
- var AwsJson1_0Protocol = class extends AwsJsonRpcProtocol {
810
- static {
811
- __name(this, "AwsJson1_0Protocol");
812
- }
813
- constructor({
814
- defaultNamespace,
815
- serviceTarget,
816
- awsQueryCompatible
817
- }) {
818
- super({
819
- defaultNamespace,
820
- serviceTarget,
821
- awsQueryCompatible
822
- });
823
- }
824
- getShapeId() {
825
- return "aws.protocols#awsJson1_0";
826
- }
827
- getJsonRpcVersion() {
828
- return "1.0";
829
- }
830
- /**
831
- * @override
832
- */
833
- getDefaultContentType() {
834
- return "application/x-amz-json-1.0";
835
- }
836
- };
432
+ class JsonShapeSerializer extends SerdeContextConfig {
433
+ settings;
434
+ buffer;
435
+ rootSchema;
436
+ constructor(settings) {
437
+ super();
438
+ this.settings = settings;
439
+ }
440
+ write(schema$1, value) {
441
+ this.rootSchema = schema.NormalizedSchema.of(schema$1);
442
+ this.buffer = this._write(this.rootSchema, value);
443
+ }
444
+ writeDiscriminatedDocument(schema$1, value) {
445
+ this.write(schema$1, value);
446
+ if (typeof this.buffer === "object") {
447
+ this.buffer.__type = schema.NormalizedSchema.of(schema$1).getName(true);
448
+ }
449
+ }
450
+ flush() {
451
+ const { rootSchema } = this;
452
+ this.rootSchema = undefined;
453
+ if (rootSchema?.isStructSchema() || rootSchema?.isDocumentSchema()) {
454
+ const replacer = new JsonReplacer();
455
+ return replacer.replaceInJson(JSON.stringify(this.buffer, replacer.createReplacer(), 0));
456
+ }
457
+ return this.buffer;
458
+ }
459
+ _write(schema$1, value, container) {
460
+ const isObject = value !== null && typeof value === "object";
461
+ const ns = schema.NormalizedSchema.of(schema$1);
462
+ if (ns.isListSchema() && Array.isArray(value)) {
463
+ const listMember = ns.getValueSchema();
464
+ const out = [];
465
+ const sparse = !!ns.getMergedTraits().sparse;
466
+ for (const item of value) {
467
+ if (sparse || item != null) {
468
+ out.push(this._write(listMember, item));
469
+ }
470
+ }
471
+ return out;
472
+ }
473
+ else if (ns.isMapSchema() && isObject) {
474
+ const mapMember = ns.getValueSchema();
475
+ const out = {};
476
+ const sparse = !!ns.getMergedTraits().sparse;
477
+ for (const [_k, _v] of Object.entries(value)) {
478
+ if (sparse || _v != null) {
479
+ out[_k] = this._write(mapMember, _v);
480
+ }
481
+ }
482
+ return out;
483
+ }
484
+ else if (ns.isStructSchema() && isObject) {
485
+ const out = {};
486
+ for (const [memberName, memberSchema] of ns.structIterator()) {
487
+ const targetKey = this.settings.jsonName ? memberSchema.getMergedTraits().jsonName ?? memberName : memberName;
488
+ const serializableValue = this._write(memberSchema, value[memberName], ns);
489
+ if (serializableValue !== undefined) {
490
+ out[targetKey] = serializableValue;
491
+ }
492
+ }
493
+ return out;
494
+ }
495
+ if (value === null && container?.isStructSchema()) {
496
+ return void 0;
497
+ }
498
+ if ((ns.isBlobSchema() && (value instanceof Uint8Array || typeof value === "string")) ||
499
+ (ns.isDocumentSchema() && value instanceof Uint8Array)) {
500
+ if (ns === this.rootSchema) {
501
+ return value;
502
+ }
503
+ if (!this.serdeContext?.base64Encoder) {
504
+ return utilBase64.toBase64(value);
505
+ }
506
+ return this.serdeContext?.base64Encoder(value);
507
+ }
508
+ if ((ns.isTimestampSchema() || ns.isDocumentSchema()) && value instanceof Date) {
509
+ const format = protocols.determineTimestampFormat(ns, this.settings);
510
+ switch (format) {
511
+ case 5:
512
+ return value.toISOString().replace(".000Z", "Z");
513
+ case 6:
514
+ return serde.dateToUtcString(value);
515
+ case 7:
516
+ return value.getTime() / 1000;
517
+ default:
518
+ console.warn("Missing timestamp format, using epoch seconds", value);
519
+ return value.getTime() / 1000;
520
+ }
521
+ }
522
+ if (ns.isNumericSchema() && typeof value === "number") {
523
+ if (Math.abs(value) === Infinity || isNaN(value)) {
524
+ return String(value);
525
+ }
526
+ }
527
+ if (ns.isStringSchema()) {
528
+ if (typeof value === "undefined" && ns.isIdempotencyToken()) {
529
+ return serde.generateIdempotencyToken();
530
+ }
531
+ const mediaType = ns.getMergedTraits().mediaType;
532
+ if (value != null && mediaType) {
533
+ const isJson = mediaType === "application/json" || mediaType.endsWith("+json");
534
+ if (isJson) {
535
+ return serde.LazyJsonString.from(value);
536
+ }
537
+ }
538
+ }
539
+ if (ns.isDocumentSchema()) {
540
+ if (isObject) {
541
+ const out = Array.isArray(value) ? [] : {};
542
+ for (const [k, v] of Object.entries(value)) {
543
+ if (v instanceof serde.NumericValue) {
544
+ out[k] = v;
545
+ }
546
+ else {
547
+ out[k] = this._write(ns, v);
548
+ }
549
+ }
550
+ return out;
551
+ }
552
+ else {
553
+ return structuredClone(value);
554
+ }
555
+ }
556
+ return value;
557
+ }
558
+ }
837
559
 
838
- // src/submodules/protocols/json/AwsJson1_1Protocol.ts
839
- var AwsJson1_1Protocol = class extends AwsJsonRpcProtocol {
840
- static {
841
- __name(this, "AwsJson1_1Protocol");
842
- }
843
- constructor({
844
- defaultNamespace,
845
- serviceTarget,
846
- awsQueryCompatible
847
- }) {
848
- super({
849
- defaultNamespace,
850
- serviceTarget,
851
- awsQueryCompatible
852
- });
853
- }
854
- getShapeId() {
855
- return "aws.protocols#awsJson1_1";
856
- }
857
- getJsonRpcVersion() {
858
- return "1.1";
859
- }
860
- /**
861
- * @override
862
- */
863
- getDefaultContentType() {
864
- return "application/x-amz-json-1.1";
865
- }
866
- };
560
+ class JsonCodec extends SerdeContextConfig {
561
+ settings;
562
+ constructor(settings) {
563
+ super();
564
+ this.settings = settings;
565
+ }
566
+ createSerializer() {
567
+ const serializer = new JsonShapeSerializer(this.settings);
568
+ serializer.setSerdeContext(this.serdeContext);
569
+ return serializer;
570
+ }
571
+ createDeserializer() {
572
+ const deserializer = new JsonShapeDeserializer(this.settings);
573
+ deserializer.setSerdeContext(this.serdeContext);
574
+ return deserializer;
575
+ }
576
+ }
867
577
 
868
- // src/submodules/protocols/json/AwsRestJsonProtocol.ts
869
- var import_protocols4 = require("@smithy/core/protocols");
870
- var import_schema6 = require("@smithy/core/schema");
871
- var AwsRestJsonProtocol = class extends import_protocols4.HttpBindingProtocol {
872
- static {
873
- __name(this, "AwsRestJsonProtocol");
874
- }
875
- serializer;
876
- deserializer;
877
- codec;
878
- mixin = new ProtocolLib();
879
- constructor({ defaultNamespace }) {
880
- super({
881
- defaultNamespace
882
- });
883
- const settings = {
884
- timestampFormat: {
885
- useTrait: true,
886
- default: import_schema6.SCHEMA.TIMESTAMP_EPOCH_SECONDS
887
- },
888
- httpBindings: true,
889
- jsonName: true
890
- };
891
- this.codec = new JsonCodec(settings);
892
- this.serializer = new import_protocols4.HttpInterceptingShapeSerializer(this.codec.createSerializer(), settings);
893
- this.deserializer = new import_protocols4.HttpInterceptingShapeDeserializer(this.codec.createDeserializer(), settings);
894
- }
895
- getShapeId() {
896
- return "aws.protocols#restJson1";
897
- }
898
- getPayloadCodec() {
899
- return this.codec;
900
- }
901
- setSerdeContext(serdeContext) {
902
- this.codec.setSerdeContext(serdeContext);
903
- super.setSerdeContext(serdeContext);
904
- }
905
- async serializeRequest(operationSchema, input, context) {
906
- const request = await super.serializeRequest(operationSchema, input, context);
907
- const inputSchema = import_schema6.NormalizedSchema.of(operationSchema.input);
908
- if (!request.headers["content-type"]) {
909
- const contentType = this.mixin.resolveRestContentType(this.getDefaultContentType(), inputSchema);
910
- if (contentType) {
911
- request.headers["content-type"] = contentType;
912
- }
913
- }
914
- if (request.headers["content-type"] && !request.body) {
915
- request.body = "{}";
916
- }
917
- return request;
918
- }
919
- async handleError(operationSchema, context, response, dataObject, metadata) {
920
- const errorIdentifier = loadRestJsonErrorCode(response, dataObject) ?? "Unknown";
921
- const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(
922
- errorIdentifier,
923
- this.options.defaultNamespace,
924
- response,
925
- dataObject,
926
- metadata
927
- );
928
- const ns = import_schema6.NormalizedSchema.of(errorSchema);
929
- const message = dataObject.message ?? dataObject.Message ?? "Unknown";
930
- const ErrorCtor = import_schema6.TypeRegistry.for(errorSchema.namespace).getErrorCtor(errorSchema) ?? Error;
931
- const exception = new ErrorCtor(message);
932
- await this.deserializeHttpMessage(errorSchema, context, response, dataObject);
933
- const output = {};
934
- for (const [name, member] of ns.structIterator()) {
935
- const target = member.getMergedTraits().jsonName ?? name;
936
- output[name] = this.codec.createDeserializer().readObject(member, dataObject[target]);
937
- }
938
- throw Object.assign(
939
- exception,
940
- errorMetadata,
941
- {
942
- $fault: ns.getMergedTraits().error,
943
- message
944
- },
945
- output
946
- );
947
- }
948
- /**
949
- * @override
950
- */
951
- getDefaultContentType() {
952
- return "application/json";
953
- }
954
- };
578
+ class AwsJsonRpcProtocol extends protocols.RpcProtocol {
579
+ serializer;
580
+ deserializer;
581
+ serviceTarget;
582
+ codec;
583
+ mixin = new ProtocolLib();
584
+ awsQueryCompatible;
585
+ constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
586
+ super({
587
+ defaultNamespace,
588
+ });
589
+ this.serviceTarget = serviceTarget;
590
+ this.codec = new JsonCodec({
591
+ timestampFormat: {
592
+ useTrait: true,
593
+ default: 7,
594
+ },
595
+ jsonName: false,
596
+ });
597
+ this.serializer = this.codec.createSerializer();
598
+ this.deserializer = this.codec.createDeserializer();
599
+ this.awsQueryCompatible = !!awsQueryCompatible;
600
+ }
601
+ async serializeRequest(operationSchema, input, context) {
602
+ const request = await super.serializeRequest(operationSchema, input, context);
603
+ if (!request.path.endsWith("/")) {
604
+ request.path += "/";
605
+ }
606
+ Object.assign(request.headers, {
607
+ "content-type": `application/x-amz-json-${this.getJsonRpcVersion()}`,
608
+ "x-amz-target": `${this.serviceTarget}.${schema.NormalizedSchema.of(operationSchema).getName()}`,
609
+ });
610
+ if (this.awsQueryCompatible) {
611
+ request.headers["x-amzn-query-mode"] = "true";
612
+ }
613
+ if (schema.deref(operationSchema.input) === "unit" || !request.body) {
614
+ request.body = "{}";
615
+ }
616
+ return request;
617
+ }
618
+ getPayloadCodec() {
619
+ return this.codec;
620
+ }
621
+ async handleError(operationSchema, context, response, dataObject, metadata) {
622
+ if (this.awsQueryCompatible) {
623
+ this.mixin.setQueryCompatError(dataObject, response);
624
+ }
625
+ const errorIdentifier = loadRestJsonErrorCode(response, dataObject) ?? "Unknown";
626
+ const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorIdentifier, this.options.defaultNamespace, response, dataObject, metadata);
627
+ const ns = schema.NormalizedSchema.of(errorSchema);
628
+ const message = dataObject.message ?? dataObject.Message ?? "Unknown";
629
+ const ErrorCtor = schema.TypeRegistry.for(errorSchema.namespace).getErrorCtor(errorSchema) ?? Error;
630
+ const exception = new ErrorCtor(message);
631
+ const output = {};
632
+ for (const [name, member] of ns.structIterator()) {
633
+ const target = member.getMergedTraits().jsonName ?? name;
634
+ output[name] = this.codec.createDeserializer().readObject(member, dataObject[target]);
635
+ }
636
+ if (this.awsQueryCompatible) {
637
+ this.mixin.queryCompatOutput(dataObject, output);
638
+ }
639
+ throw Object.assign(exception, errorMetadata, {
640
+ $fault: ns.getMergedTraits().error,
641
+ message,
642
+ }, output);
643
+ }
644
+ }
955
645
 
956
- // src/submodules/protocols/json/awsExpectUnion.ts
957
- var import_smithy_client2 = require("@smithy/smithy-client");
958
- var awsExpectUnion = /* @__PURE__ */ __name((value) => {
959
- if (value == null) {
960
- return void 0;
961
- }
962
- if (typeof value === "object" && "__type" in value) {
963
- delete value.__type;
964
- }
965
- return (0, import_smithy_client2.expectUnion)(value);
966
- }, "awsExpectUnion");
646
+ class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
647
+ constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
648
+ super({
649
+ defaultNamespace,
650
+ serviceTarget,
651
+ awsQueryCompatible,
652
+ });
653
+ }
654
+ getShapeId() {
655
+ return "aws.protocols#awsJson1_0";
656
+ }
657
+ getJsonRpcVersion() {
658
+ return "1.0";
659
+ }
660
+ getDefaultContentType() {
661
+ return "application/x-amz-json-1.0";
662
+ }
663
+ }
967
664
 
968
- // src/submodules/protocols/query/AwsQueryProtocol.ts
969
- var import_protocols7 = require("@smithy/core/protocols");
970
- var import_schema9 = require("@smithy/core/schema");
665
+ class AwsJson1_1Protocol extends AwsJsonRpcProtocol {
666
+ constructor({ defaultNamespace, serviceTarget, awsQueryCompatible, }) {
667
+ super({
668
+ defaultNamespace,
669
+ serviceTarget,
670
+ awsQueryCompatible,
671
+ });
672
+ }
673
+ getShapeId() {
674
+ return "aws.protocols#awsJson1_1";
675
+ }
676
+ getJsonRpcVersion() {
677
+ return "1.1";
678
+ }
679
+ getDefaultContentType() {
680
+ return "application/x-amz-json-1.1";
681
+ }
682
+ }
971
683
 
972
- // src/submodules/protocols/xml/XmlShapeDeserializer.ts
973
- var import_xml_builder = require("@aws-sdk/xml-builder");
974
- var import_protocols5 = require("@smithy/core/protocols");
975
- var import_schema7 = require("@smithy/core/schema");
976
- var import_smithy_client3 = require("@smithy/smithy-client");
977
- var import_util_utf82 = require("@smithy/util-utf8");
978
- var XmlShapeDeserializer = class extends SerdeContextConfig {
979
- constructor(settings) {
980
- super();
981
- this.settings = settings;
982
- this.stringDeserializer = new import_protocols5.FromStringShapeDeserializer(settings);
983
- }
984
- static {
985
- __name(this, "XmlShapeDeserializer");
986
- }
987
- stringDeserializer;
988
- setSerdeContext(serdeContext) {
989
- this.serdeContext = serdeContext;
990
- this.stringDeserializer.setSerdeContext(serdeContext);
991
- }
992
- /**
993
- * @param schema - describing the data.
994
- * @param bytes - serialized data.
995
- * @param key - used by AwsQuery to step one additional depth into the object before reading it.
996
- */
997
- read(schema, bytes, key) {
998
- const ns = import_schema7.NormalizedSchema.of(schema);
999
- const memberSchemas = ns.getMemberSchemas();
1000
- const isEventPayload = ns.isStructSchema() && ns.isMemberSchema() && !!Object.values(memberSchemas).find((memberNs) => {
1001
- return !!memberNs.getMemberTraits().eventPayload;
1002
- });
1003
- if (isEventPayload) {
1004
- const output = {};
1005
- const memberName = Object.keys(memberSchemas)[0];
1006
- const eventMemberSchema = memberSchemas[memberName];
1007
- if (eventMemberSchema.isBlobSchema()) {
1008
- output[memberName] = bytes;
1009
- } else {
1010
- output[memberName] = this.read(memberSchemas[memberName], bytes);
1011
- }
1012
- return output;
1013
- }
1014
- const xmlString = (this.serdeContext?.utf8Encoder ?? import_util_utf82.toUtf8)(bytes);
1015
- const parsedObject = this.parseXml(xmlString);
1016
- return this.readSchema(schema, key ? parsedObject[key] : parsedObject);
1017
- }
1018
- readSchema(_schema, value) {
1019
- const ns = import_schema7.NormalizedSchema.of(_schema);
1020
- if (ns.isUnitSchema()) {
1021
- return;
1022
- }
1023
- const traits = ns.getMergedTraits();
1024
- if (ns.isListSchema() && !Array.isArray(value)) {
1025
- return this.readSchema(ns, [value]);
684
+ class AwsRestJsonProtocol extends protocols.HttpBindingProtocol {
685
+ serializer;
686
+ deserializer;
687
+ codec;
688
+ mixin = new ProtocolLib();
689
+ constructor({ defaultNamespace }) {
690
+ super({
691
+ defaultNamespace,
692
+ });
693
+ const settings = {
694
+ timestampFormat: {
695
+ useTrait: true,
696
+ default: 7,
697
+ },
698
+ httpBindings: true,
699
+ jsonName: true,
700
+ };
701
+ this.codec = new JsonCodec(settings);
702
+ this.serializer = new protocols.HttpInterceptingShapeSerializer(this.codec.createSerializer(), settings);
703
+ this.deserializer = new protocols.HttpInterceptingShapeDeserializer(this.codec.createDeserializer(), settings);
704
+ }
705
+ getShapeId() {
706
+ return "aws.protocols#restJson1";
707
+ }
708
+ getPayloadCodec() {
709
+ return this.codec;
710
+ }
711
+ setSerdeContext(serdeContext) {
712
+ this.codec.setSerdeContext(serdeContext);
713
+ super.setSerdeContext(serdeContext);
714
+ }
715
+ async serializeRequest(operationSchema, input, context) {
716
+ const request = await super.serializeRequest(operationSchema, input, context);
717
+ const inputSchema = schema.NormalizedSchema.of(operationSchema.input);
718
+ if (!request.headers["content-type"]) {
719
+ const contentType = this.mixin.resolveRestContentType(this.getDefaultContentType(), inputSchema);
720
+ if (contentType) {
721
+ request.headers["content-type"] = contentType;
722
+ }
723
+ }
724
+ if (request.headers["content-type"] && !request.body) {
725
+ request.body = "{}";
726
+ }
727
+ return request;
728
+ }
729
+ async handleError(operationSchema, context, response, dataObject, metadata) {
730
+ const errorIdentifier = loadRestJsonErrorCode(response, dataObject) ?? "Unknown";
731
+ const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorIdentifier, this.options.defaultNamespace, response, dataObject, metadata);
732
+ const ns = schema.NormalizedSchema.of(errorSchema);
733
+ const message = dataObject.message ?? dataObject.Message ?? "Unknown";
734
+ const ErrorCtor = schema.TypeRegistry.for(errorSchema.namespace).getErrorCtor(errorSchema) ?? Error;
735
+ const exception = new ErrorCtor(message);
736
+ await this.deserializeHttpMessage(errorSchema, context, response, dataObject);
737
+ const output = {};
738
+ for (const [name, member] of ns.structIterator()) {
739
+ const target = member.getMergedTraits().jsonName ?? name;
740
+ output[name] = this.codec.createDeserializer().readObject(member, dataObject[target]);
741
+ }
742
+ throw Object.assign(exception, errorMetadata, {
743
+ $fault: ns.getMergedTraits().error,
744
+ message,
745
+ }, output);
746
+ }
747
+ getDefaultContentType() {
748
+ return "application/json";
1026
749
  }
750
+ }
751
+
752
+ const awsExpectUnion = (value) => {
1027
753
  if (value == null) {
1028
- return value;
1029
- }
1030
- if (typeof value === "object") {
1031
- const sparse = !!traits.sparse;
1032
- const flat = !!traits.xmlFlattened;
1033
- if (ns.isListSchema()) {
1034
- const listValue = ns.getValueSchema();
1035
- const buffer2 = [];
1036
- const sourceKey = listValue.getMergedTraits().xmlName ?? "member";
1037
- const source = flat ? value : (value[0] ?? value)[sourceKey];
1038
- const sourceArray = Array.isArray(source) ? source : [source];
1039
- for (const v of sourceArray) {
1040
- if (v != null || sparse) {
1041
- buffer2.push(this.readSchema(listValue, v));
1042
- }
1043
- }
1044
- return buffer2;
1045
- }
1046
- const buffer = {};
1047
- if (ns.isMapSchema()) {
1048
- const keyNs = ns.getKeySchema();
1049
- const memberNs = ns.getValueSchema();
1050
- let entries;
1051
- if (flat) {
1052
- entries = Array.isArray(value) ? value : [value];
1053
- } else {
1054
- entries = Array.isArray(value.entry) ? value.entry : [value.entry];
1055
- }
1056
- const keyProperty = keyNs.getMergedTraits().xmlName ?? "key";
1057
- const valueProperty = memberNs.getMergedTraits().xmlName ?? "value";
1058
- for (const entry of entries) {
1059
- const key = entry[keyProperty];
1060
- const value2 = entry[valueProperty];
1061
- if (value2 != null || sparse) {
1062
- buffer[key] = this.readSchema(memberNs, value2);
1063
- }
1064
- }
1065
- return buffer;
1066
- }
1067
- if (ns.isStructSchema()) {
1068
- for (const [memberName, memberSchema] of ns.structIterator()) {
1069
- const memberTraits = memberSchema.getMergedTraits();
1070
- const xmlObjectKey = !memberTraits.httpPayload ? memberSchema.getMemberTraits().xmlName ?? memberName : memberTraits.xmlName ?? memberSchema.getName();
1071
- if (value[xmlObjectKey] != null) {
1072
- buffer[memberName] = this.readSchema(memberSchema, value[xmlObjectKey]);
1073
- }
1074
- }
1075
- return buffer;
1076
- }
1077
- if (ns.isDocumentSchema()) {
1078
- return value;
1079
- }
1080
- throw new Error(`@aws-sdk/core/protocols - xml deserializer unhandled schema type for ${ns.getName(true)}`);
1081
- }
1082
- if (ns.isListSchema()) {
1083
- return [];
1084
- }
1085
- if (ns.isMapSchema() || ns.isStructSchema()) {
1086
- return {};
1087
- }
1088
- return this.stringDeserializer.read(ns, value);
1089
- }
1090
- parseXml(xml) {
1091
- if (xml.length) {
1092
- let parsedObj;
1093
- try {
1094
- parsedObj = (0, import_xml_builder.parseXML)(xml);
1095
- } catch (e) {
1096
- if (e && typeof e === "object") {
1097
- Object.defineProperty(e, "$responseBodyText", {
1098
- value: xml
1099
- });
1100
- }
1101
- throw e;
1102
- }
1103
- const textNodeName = "#text";
1104
- const key = Object.keys(parsedObj)[0];
1105
- const parsedObjToReturn = parsedObj[key];
1106
- if (parsedObjToReturn[textNodeName]) {
1107
- parsedObjToReturn[key] = parsedObjToReturn[textNodeName];
1108
- delete parsedObjToReturn[textNodeName];
1109
- }
1110
- return (0, import_smithy_client3.getValueFromTextNode)(parsedObjToReturn);
754
+ return undefined;
1111
755
  }
1112
- return {};
1113
- }
756
+ if (typeof value === "object" && "__type" in value) {
757
+ delete value.__type;
758
+ }
759
+ return smithyClient.expectUnion(value);
1114
760
  };
1115
761
 
1116
- // src/submodules/protocols/query/QueryShapeSerializer.ts
1117
- var import_protocols6 = require("@smithy/core/protocols");
1118
- var import_schema8 = require("@smithy/core/schema");
1119
- var import_serde5 = require("@smithy/core/serde");
1120
- var import_smithy_client4 = require("@smithy/smithy-client");
1121
- var import_util_base643 = require("@smithy/util-base64");
1122
- var QueryShapeSerializer = class extends SerdeContextConfig {
1123
- constructor(settings) {
1124
- super();
1125
- this.settings = settings;
1126
- }
1127
- static {
1128
- __name(this, "QueryShapeSerializer");
1129
- }
1130
- buffer;
1131
- write(schema, value, prefix = "") {
1132
- if (this.buffer === void 0) {
1133
- this.buffer = "";
1134
- }
1135
- const ns = import_schema8.NormalizedSchema.of(schema);
1136
- if (prefix && !prefix.endsWith(".")) {
1137
- prefix += ".";
1138
- }
1139
- if (ns.isBlobSchema()) {
1140
- if (typeof value === "string" || value instanceof Uint8Array) {
1141
- this.writeKey(prefix);
1142
- this.writeValue((this.serdeContext?.base64Encoder ?? import_util_base643.toBase64)(value));
1143
- }
1144
- } else if (ns.isBooleanSchema() || ns.isNumericSchema() || ns.isStringSchema()) {
1145
- if (value != null) {
1146
- this.writeKey(prefix);
1147
- this.writeValue(String(value));
1148
- } else if (ns.isIdempotencyToken()) {
1149
- this.writeKey(prefix);
1150
- this.writeValue((0, import_serde5.generateIdempotencyToken)());
1151
- }
1152
- } else if (ns.isBigIntegerSchema()) {
1153
- if (value != null) {
1154
- this.writeKey(prefix);
1155
- this.writeValue(String(value));
1156
- }
1157
- } else if (ns.isBigDecimalSchema()) {
1158
- if (value != null) {
1159
- this.writeKey(prefix);
1160
- this.writeValue(value instanceof import_serde5.NumericValue ? value.string : String(value));
1161
- }
1162
- } else if (ns.isTimestampSchema()) {
1163
- if (value instanceof Date) {
1164
- this.writeKey(prefix);
1165
- const format = (0, import_protocols6.determineTimestampFormat)(ns, this.settings);
1166
- switch (format) {
1167
- case import_schema8.SCHEMA.TIMESTAMP_DATE_TIME:
1168
- this.writeValue(value.toISOString().replace(".000Z", "Z"));
1169
- break;
1170
- case import_schema8.SCHEMA.TIMESTAMP_HTTP_DATE:
1171
- this.writeValue((0, import_smithy_client4.dateToUtcString)(value));
1172
- break;
1173
- case import_schema8.SCHEMA.TIMESTAMP_EPOCH_SECONDS:
1174
- this.writeValue(String(value.getTime() / 1e3));
1175
- break;
1176
- }
1177
- }
1178
- } else if (ns.isDocumentSchema()) {
1179
- throw new Error(`@aws-sdk/core/protocols - QuerySerializer unsupported document type ${ns.getName(true)}`);
1180
- } else if (ns.isListSchema()) {
1181
- if (Array.isArray(value)) {
1182
- if (value.length === 0) {
1183
- if (this.settings.serializeEmptyLists) {
1184
- this.writeKey(prefix);
1185
- this.writeValue("");
1186
- }
1187
- } else {
1188
- const member = ns.getValueSchema();
1189
- const flat = this.settings.flattenLists || ns.getMergedTraits().xmlFlattened;
1190
- let i = 1;
1191
- for (const item of value) {
1192
- if (item == null) {
1193
- continue;
1194
- }
1195
- const suffix = this.getKey("member", member.getMergedTraits().xmlName);
1196
- const key = flat ? `${prefix}${i}` : `${prefix}${suffix}.${i}`;
1197
- this.write(member, item, key);
1198
- ++i;
1199
- }
1200
- }
1201
- }
1202
- } else if (ns.isMapSchema()) {
1203
- if (value && typeof value === "object") {
1204
- const keySchema = ns.getKeySchema();
1205
- const memberSchema = ns.getValueSchema();
1206
- const flat = ns.getMergedTraits().xmlFlattened;
1207
- let i = 1;
1208
- for (const [k, v] of Object.entries(value)) {
1209
- if (v == null) {
1210
- continue;
1211
- }
1212
- const keySuffix = this.getKey("key", keySchema.getMergedTraits().xmlName);
1213
- const key = flat ? `${prefix}${i}.${keySuffix}` : `${prefix}entry.${i}.${keySuffix}`;
1214
- const valueSuffix = this.getKey("value", memberSchema.getMergedTraits().xmlName);
1215
- const valueKey = flat ? `${prefix}${i}.${valueSuffix}` : `${prefix}entry.${i}.${valueSuffix}`;
1216
- this.write(keySchema, k, key);
1217
- this.write(memberSchema, v, valueKey);
1218
- ++i;
1219
- }
1220
- }
1221
- } else if (ns.isStructSchema()) {
1222
- if (value && typeof value === "object") {
1223
- for (const [memberName, member] of ns.structIterator()) {
1224
- if (value[memberName] == null && !member.isIdempotencyToken()) {
1225
- continue;
1226
- }
1227
- const suffix = this.getKey(memberName, member.getMergedTraits().xmlName);
1228
- const key = `${prefix}${suffix}`;
1229
- this.write(member, value[memberName], key);
1230
- }
1231
- }
1232
- } else if (ns.isUnitSchema()) {
1233
- } else {
1234
- throw new Error(`@aws-sdk/core/protocols - QuerySerializer unrecognized schema type ${ns.getName(true)}`);
1235
- }
1236
- }
1237
- flush() {
1238
- if (this.buffer === void 0) {
1239
- throw new Error("@aws-sdk/core/protocols - QuerySerializer cannot flush with nothing written to buffer.");
1240
- }
1241
- const str = this.buffer;
1242
- delete this.buffer;
1243
- return str;
1244
- }
1245
- getKey(memberName, xmlName) {
1246
- const key = xmlName ?? memberName;
1247
- if (this.settings.capitalizeKeys) {
1248
- return key[0].toUpperCase() + key.slice(1);
1249
- }
1250
- return key;
1251
- }
1252
- writeKey(key) {
1253
- if (key.endsWith(".")) {
1254
- key = key.slice(0, key.length - 1);
1255
- }
1256
- this.buffer += `&${(0, import_protocols6.extendedEncodeURIComponent)(key)}=`;
1257
- }
1258
- writeValue(value) {
1259
- this.buffer += (0, import_protocols6.extendedEncodeURIComponent)(value);
1260
- }
1261
- };
762
+ class XmlShapeDeserializer extends SerdeContextConfig {
763
+ settings;
764
+ stringDeserializer;
765
+ constructor(settings) {
766
+ super();
767
+ this.settings = settings;
768
+ this.stringDeserializer = new protocols.FromStringShapeDeserializer(settings);
769
+ }
770
+ setSerdeContext(serdeContext) {
771
+ this.serdeContext = serdeContext;
772
+ this.stringDeserializer.setSerdeContext(serdeContext);
773
+ }
774
+ read(schema$1, bytes, key) {
775
+ const ns = schema.NormalizedSchema.of(schema$1);
776
+ const memberSchemas = ns.getMemberSchemas();
777
+ const isEventPayload = ns.isStructSchema() &&
778
+ ns.isMemberSchema() &&
779
+ !!Object.values(memberSchemas).find((memberNs) => {
780
+ return !!memberNs.getMemberTraits().eventPayload;
781
+ });
782
+ if (isEventPayload) {
783
+ const output = {};
784
+ const memberName = Object.keys(memberSchemas)[0];
785
+ const eventMemberSchema = memberSchemas[memberName];
786
+ if (eventMemberSchema.isBlobSchema()) {
787
+ output[memberName] = bytes;
788
+ }
789
+ else {
790
+ output[memberName] = this.read(memberSchemas[memberName], bytes);
791
+ }
792
+ return output;
793
+ }
794
+ const xmlString = (this.serdeContext?.utf8Encoder ?? utilUtf8.toUtf8)(bytes);
795
+ const parsedObject = this.parseXml(xmlString);
796
+ return this.readSchema(schema$1, key ? parsedObject[key] : parsedObject);
797
+ }
798
+ readSchema(_schema, value) {
799
+ const ns = schema.NormalizedSchema.of(_schema);
800
+ if (ns.isUnitSchema()) {
801
+ return;
802
+ }
803
+ const traits = ns.getMergedTraits();
804
+ if (ns.isListSchema() && !Array.isArray(value)) {
805
+ return this.readSchema(ns, [value]);
806
+ }
807
+ if (value == null) {
808
+ return value;
809
+ }
810
+ if (typeof value === "object") {
811
+ const sparse = !!traits.sparse;
812
+ const flat = !!traits.xmlFlattened;
813
+ if (ns.isListSchema()) {
814
+ const listValue = ns.getValueSchema();
815
+ const buffer = [];
816
+ const sourceKey = listValue.getMergedTraits().xmlName ?? "member";
817
+ const source = flat ? value : (value[0] ?? value)[sourceKey];
818
+ const sourceArray = Array.isArray(source) ? source : [source];
819
+ for (const v of sourceArray) {
820
+ if (v != null || sparse) {
821
+ buffer.push(this.readSchema(listValue, v));
822
+ }
823
+ }
824
+ return buffer;
825
+ }
826
+ const buffer = {};
827
+ if (ns.isMapSchema()) {
828
+ const keyNs = ns.getKeySchema();
829
+ const memberNs = ns.getValueSchema();
830
+ let entries;
831
+ if (flat) {
832
+ entries = Array.isArray(value) ? value : [value];
833
+ }
834
+ else {
835
+ entries = Array.isArray(value.entry) ? value.entry : [value.entry];
836
+ }
837
+ const keyProperty = keyNs.getMergedTraits().xmlName ?? "key";
838
+ const valueProperty = memberNs.getMergedTraits().xmlName ?? "value";
839
+ for (const entry of entries) {
840
+ const key = entry[keyProperty];
841
+ const value = entry[valueProperty];
842
+ if (value != null || sparse) {
843
+ buffer[key] = this.readSchema(memberNs, value);
844
+ }
845
+ }
846
+ return buffer;
847
+ }
848
+ if (ns.isStructSchema()) {
849
+ for (const [memberName, memberSchema] of ns.structIterator()) {
850
+ const memberTraits = memberSchema.getMergedTraits();
851
+ const xmlObjectKey = !memberTraits.httpPayload
852
+ ? memberSchema.getMemberTraits().xmlName ?? memberName
853
+ : memberTraits.xmlName ?? memberSchema.getName();
854
+ if (value[xmlObjectKey] != null) {
855
+ buffer[memberName] = this.readSchema(memberSchema, value[xmlObjectKey]);
856
+ }
857
+ }
858
+ return buffer;
859
+ }
860
+ if (ns.isDocumentSchema()) {
861
+ return value;
862
+ }
863
+ throw new Error(`@aws-sdk/core/protocols - xml deserializer unhandled schema type for ${ns.getName(true)}`);
864
+ }
865
+ if (ns.isListSchema()) {
866
+ return [];
867
+ }
868
+ if (ns.isMapSchema() || ns.isStructSchema()) {
869
+ return {};
870
+ }
871
+ return this.stringDeserializer.read(ns, value);
872
+ }
873
+ parseXml(xml) {
874
+ if (xml.length) {
875
+ let parsedObj;
876
+ try {
877
+ parsedObj = xmlBuilder.parseXML(xml);
878
+ }
879
+ catch (e) {
880
+ if (e && typeof e === "object") {
881
+ Object.defineProperty(e, "$responseBodyText", {
882
+ value: xml,
883
+ });
884
+ }
885
+ throw e;
886
+ }
887
+ const textNodeName = "#text";
888
+ const key = Object.keys(parsedObj)[0];
889
+ const parsedObjToReturn = parsedObj[key];
890
+ if (parsedObjToReturn[textNodeName]) {
891
+ parsedObjToReturn[key] = parsedObjToReturn[textNodeName];
892
+ delete parsedObjToReturn[textNodeName];
893
+ }
894
+ return smithyClient.getValueFromTextNode(parsedObjToReturn);
895
+ }
896
+ return {};
897
+ }
898
+ }
1262
899
 
1263
- // src/submodules/protocols/query/AwsQueryProtocol.ts
1264
- var AwsQueryProtocol = class extends import_protocols7.RpcProtocol {
1265
- constructor(options) {
1266
- super({
1267
- defaultNamespace: options.defaultNamespace
1268
- });
1269
- this.options = options;
1270
- const settings = {
1271
- timestampFormat: {
1272
- useTrait: true,
1273
- default: import_schema9.SCHEMA.TIMESTAMP_DATE_TIME
1274
- },
1275
- httpBindings: false,
1276
- xmlNamespace: options.xmlNamespace,
1277
- serviceNamespace: options.defaultNamespace,
1278
- serializeEmptyLists: true
1279
- };
1280
- this.serializer = new QueryShapeSerializer(settings);
1281
- this.deserializer = new XmlShapeDeserializer(settings);
1282
- }
1283
- static {
1284
- __name(this, "AwsQueryProtocol");
1285
- }
1286
- serializer;
1287
- deserializer;
1288
- mixin = new ProtocolLib();
1289
- getShapeId() {
1290
- return "aws.protocols#awsQuery";
1291
- }
1292
- setSerdeContext(serdeContext) {
1293
- this.serializer.setSerdeContext(serdeContext);
1294
- this.deserializer.setSerdeContext(serdeContext);
1295
- }
1296
- getPayloadCodec() {
1297
- throw new Error("AWSQuery protocol has no payload codec.");
1298
- }
1299
- async serializeRequest(operationSchema, input, context) {
1300
- const request = await super.serializeRequest(operationSchema, input, context);
1301
- if (!request.path.endsWith("/")) {
1302
- request.path += "/";
1303
- }
1304
- Object.assign(request.headers, {
1305
- "content-type": `application/x-www-form-urlencoded`
1306
- });
1307
- if ((0, import_schema9.deref)(operationSchema.input) === "unit" || !request.body) {
1308
- request.body = "";
1309
- }
1310
- const action = operationSchema.name.split("#")[1] ?? operationSchema.name;
1311
- request.body = `Action=${action}&Version=${this.options.version}` + request.body;
1312
- if (request.body.endsWith("&")) {
1313
- request.body = request.body.slice(-1);
1314
- }
1315
- return request;
1316
- }
1317
- async deserializeResponse(operationSchema, context, response) {
1318
- const deserializer = this.deserializer;
1319
- const ns = import_schema9.NormalizedSchema.of(operationSchema.output);
1320
- const dataObject = {};
1321
- if (response.statusCode >= 300) {
1322
- const bytes2 = await (0, import_protocols7.collectBody)(response.body, context);
1323
- if (bytes2.byteLength > 0) {
1324
- Object.assign(dataObject, await deserializer.read(import_schema9.SCHEMA.DOCUMENT, bytes2));
1325
- }
1326
- await this.handleError(operationSchema, context, response, dataObject, this.deserializeMetadata(response));
1327
- }
1328
- for (const header in response.headers) {
1329
- const value = response.headers[header];
1330
- delete response.headers[header];
1331
- response.headers[header.toLowerCase()] = value;
1332
- }
1333
- const shortName = operationSchema.name.split("#")[1] ?? operationSchema.name;
1334
- const awsQueryResultKey = ns.isStructSchema() && this.useNestedResult() ? shortName + "Result" : void 0;
1335
- const bytes = await (0, import_protocols7.collectBody)(response.body, context);
1336
- if (bytes.byteLength > 0) {
1337
- Object.assign(dataObject, await deserializer.read(ns, bytes, awsQueryResultKey));
1338
- }
1339
- const output = {
1340
- $metadata: this.deserializeMetadata(response),
1341
- ...dataObject
1342
- };
1343
- return output;
1344
- }
1345
- /**
1346
- * EC2 Query overrides this.
1347
- */
1348
- useNestedResult() {
1349
- return true;
1350
- }
1351
- async handleError(operationSchema, context, response, dataObject, metadata) {
1352
- const errorIdentifier = this.loadQueryErrorCode(response, dataObject) ?? "Unknown";
1353
- const errorData = this.loadQueryError(dataObject);
1354
- const message = this.loadQueryErrorMessage(dataObject);
1355
- errorData.message = message;
1356
- errorData.Error = {
1357
- Type: errorData.Type,
1358
- Code: errorData.Code,
1359
- Message: message
1360
- };
1361
- const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(
1362
- errorIdentifier,
1363
- this.options.defaultNamespace,
1364
- response,
1365
- errorData,
1366
- metadata,
1367
- (registry, errorName) => registry.find(
1368
- (schema) => import_schema9.NormalizedSchema.of(schema).getMergedTraits().awsQueryError?.[0] === errorName
1369
- )
1370
- );
1371
- const ns = import_schema9.NormalizedSchema.of(errorSchema);
1372
- const ErrorCtor = import_schema9.TypeRegistry.for(errorSchema.namespace).getErrorCtor(errorSchema) ?? Error;
1373
- const exception = new ErrorCtor(message);
1374
- const output = {
1375
- Error: errorData.Error
1376
- };
1377
- for (const [name, member] of ns.structIterator()) {
1378
- const target = member.getMergedTraits().xmlName ?? name;
1379
- const value = errorData[target] ?? dataObject[target];
1380
- output[name] = this.deserializer.readSchema(member, value);
1381
- }
1382
- throw Object.assign(
1383
- exception,
1384
- errorMetadata,
1385
- {
1386
- $fault: ns.getMergedTraits().error,
1387
- message
1388
- },
1389
- output
1390
- );
1391
- }
1392
- /**
1393
- * The variations in the error and error message locations are attributed to
1394
- * divergence between AWS Query and EC2 Query behavior.
1395
- */
1396
- loadQueryErrorCode(output, data) {
1397
- const code = (data.Errors?.[0]?.Error ?? data.Errors?.Error ?? data.Error)?.Code;
1398
- if (code !== void 0) {
1399
- return code;
900
+ class QueryShapeSerializer extends SerdeContextConfig {
901
+ settings;
902
+ buffer;
903
+ constructor(settings) {
904
+ super();
905
+ this.settings = settings;
906
+ }
907
+ write(schema$1, value, prefix = "") {
908
+ if (this.buffer === undefined) {
909
+ this.buffer = "";
910
+ }
911
+ const ns = schema.NormalizedSchema.of(schema$1);
912
+ if (prefix && !prefix.endsWith(".")) {
913
+ prefix += ".";
914
+ }
915
+ if (ns.isBlobSchema()) {
916
+ if (typeof value === "string" || value instanceof Uint8Array) {
917
+ this.writeKey(prefix);
918
+ this.writeValue((this.serdeContext?.base64Encoder ?? utilBase64.toBase64)(value));
919
+ }
920
+ }
921
+ else if (ns.isBooleanSchema() || ns.isNumericSchema() || ns.isStringSchema()) {
922
+ if (value != null) {
923
+ this.writeKey(prefix);
924
+ this.writeValue(String(value));
925
+ }
926
+ else if (ns.isIdempotencyToken()) {
927
+ this.writeKey(prefix);
928
+ this.writeValue(serde.generateIdempotencyToken());
929
+ }
930
+ }
931
+ else if (ns.isBigIntegerSchema()) {
932
+ if (value != null) {
933
+ this.writeKey(prefix);
934
+ this.writeValue(String(value));
935
+ }
936
+ }
937
+ else if (ns.isBigDecimalSchema()) {
938
+ if (value != null) {
939
+ this.writeKey(prefix);
940
+ this.writeValue(value instanceof serde.NumericValue ? value.string : String(value));
941
+ }
942
+ }
943
+ else if (ns.isTimestampSchema()) {
944
+ if (value instanceof Date) {
945
+ this.writeKey(prefix);
946
+ const format = protocols.determineTimestampFormat(ns, this.settings);
947
+ switch (format) {
948
+ case 5:
949
+ this.writeValue(value.toISOString().replace(".000Z", "Z"));
950
+ break;
951
+ case 6:
952
+ this.writeValue(smithyClient.dateToUtcString(value));
953
+ break;
954
+ case 7:
955
+ this.writeValue(String(value.getTime() / 1000));
956
+ break;
957
+ }
958
+ }
959
+ }
960
+ else if (ns.isDocumentSchema()) {
961
+ throw new Error(`@aws-sdk/core/protocols - QuerySerializer unsupported document type ${ns.getName(true)}`);
962
+ }
963
+ else if (ns.isListSchema()) {
964
+ if (Array.isArray(value)) {
965
+ if (value.length === 0) {
966
+ if (this.settings.serializeEmptyLists) {
967
+ this.writeKey(prefix);
968
+ this.writeValue("");
969
+ }
970
+ }
971
+ else {
972
+ const member = ns.getValueSchema();
973
+ const flat = this.settings.flattenLists || ns.getMergedTraits().xmlFlattened;
974
+ let i = 1;
975
+ for (const item of value) {
976
+ if (item == null) {
977
+ continue;
978
+ }
979
+ const suffix = this.getKey("member", member.getMergedTraits().xmlName);
980
+ const key = flat ? `${prefix}${i}` : `${prefix}${suffix}.${i}`;
981
+ this.write(member, item, key);
982
+ ++i;
983
+ }
984
+ }
985
+ }
986
+ }
987
+ else if (ns.isMapSchema()) {
988
+ if (value && typeof value === "object") {
989
+ const keySchema = ns.getKeySchema();
990
+ const memberSchema = ns.getValueSchema();
991
+ const flat = ns.getMergedTraits().xmlFlattened;
992
+ let i = 1;
993
+ for (const [k, v] of Object.entries(value)) {
994
+ if (v == null) {
995
+ continue;
996
+ }
997
+ const keySuffix = this.getKey("key", keySchema.getMergedTraits().xmlName);
998
+ const key = flat ? `${prefix}${i}.${keySuffix}` : `${prefix}entry.${i}.${keySuffix}`;
999
+ const valueSuffix = this.getKey("value", memberSchema.getMergedTraits().xmlName);
1000
+ const valueKey = flat ? `${prefix}${i}.${valueSuffix}` : `${prefix}entry.${i}.${valueSuffix}`;
1001
+ this.write(keySchema, k, key);
1002
+ this.write(memberSchema, v, valueKey);
1003
+ ++i;
1004
+ }
1005
+ }
1006
+ }
1007
+ else if (ns.isStructSchema()) {
1008
+ if (value && typeof value === "object") {
1009
+ for (const [memberName, member] of ns.structIterator()) {
1010
+ if (value[memberName] == null && !member.isIdempotencyToken()) {
1011
+ continue;
1012
+ }
1013
+ const suffix = this.getKey(memberName, member.getMergedTraits().xmlName);
1014
+ const key = `${prefix}${suffix}`;
1015
+ this.write(member, value[memberName], key);
1016
+ }
1017
+ }
1018
+ }
1019
+ else if (ns.isUnitSchema()) ;
1020
+ else {
1021
+ throw new Error(`@aws-sdk/core/protocols - QuerySerializer unrecognized schema type ${ns.getName(true)}`);
1022
+ }
1400
1023
  }
1401
- if (output.statusCode == 404) {
1402
- return "NotFound";
1403
- }
1404
- }
1405
- loadQueryError(data) {
1406
- return data.Errors?.[0]?.Error ?? data.Errors?.Error ?? data.Error;
1407
- }
1408
- loadQueryErrorMessage(data) {
1409
- const errorData = this.loadQueryError(data);
1410
- return errorData?.message ?? errorData?.Message ?? data.message ?? data.Message ?? "Unknown";
1411
- }
1412
- /**
1413
- * @override
1414
- */
1415
- getDefaultContentType() {
1416
- return "application/x-www-form-urlencoded";
1417
- }
1418
- };
1024
+ flush() {
1025
+ if (this.buffer === undefined) {
1026
+ throw new Error("@aws-sdk/core/protocols - QuerySerializer cannot flush with nothing written to buffer.");
1027
+ }
1028
+ const str = this.buffer;
1029
+ delete this.buffer;
1030
+ return str;
1031
+ }
1032
+ getKey(memberName, xmlName) {
1033
+ const key = xmlName ?? memberName;
1034
+ if (this.settings.capitalizeKeys) {
1035
+ return key[0].toUpperCase() + key.slice(1);
1036
+ }
1037
+ return key;
1038
+ }
1039
+ writeKey(key) {
1040
+ if (key.endsWith(".")) {
1041
+ key = key.slice(0, key.length - 1);
1042
+ }
1043
+ this.buffer += `&${protocols.extendedEncodeURIComponent(key)}=`;
1044
+ }
1045
+ writeValue(value) {
1046
+ this.buffer += protocols.extendedEncodeURIComponent(value);
1047
+ }
1048
+ }
1419
1049
 
1420
- // src/submodules/protocols/query/AwsEc2QueryProtocol.ts
1421
- var AwsEc2QueryProtocol = class extends AwsQueryProtocol {
1422
- constructor(options) {
1423
- super(options);
1424
- this.options = options;
1425
- const ec2Settings = {
1426
- capitalizeKeys: true,
1427
- flattenLists: true,
1428
- serializeEmptyLists: false
1429
- };
1430
- Object.assign(this.serializer.settings, ec2Settings);
1431
- }
1432
- static {
1433
- __name(this, "AwsEc2QueryProtocol");
1434
- }
1435
- /**
1436
- * EC2 Query reads XResponse.XResult instead of XResponse directly.
1437
- */
1438
- useNestedResult() {
1439
- return false;
1440
- }
1441
- };
1050
+ class AwsQueryProtocol extends protocols.RpcProtocol {
1051
+ options;
1052
+ serializer;
1053
+ deserializer;
1054
+ mixin = new ProtocolLib();
1055
+ constructor(options) {
1056
+ super({
1057
+ defaultNamespace: options.defaultNamespace,
1058
+ });
1059
+ this.options = options;
1060
+ const settings = {
1061
+ timestampFormat: {
1062
+ useTrait: true,
1063
+ default: 5,
1064
+ },
1065
+ httpBindings: false,
1066
+ xmlNamespace: options.xmlNamespace,
1067
+ serviceNamespace: options.defaultNamespace,
1068
+ serializeEmptyLists: true,
1069
+ };
1070
+ this.serializer = new QueryShapeSerializer(settings);
1071
+ this.deserializer = new XmlShapeDeserializer(settings);
1072
+ }
1073
+ getShapeId() {
1074
+ return "aws.protocols#awsQuery";
1075
+ }
1076
+ setSerdeContext(serdeContext) {
1077
+ this.serializer.setSerdeContext(serdeContext);
1078
+ this.deserializer.setSerdeContext(serdeContext);
1079
+ }
1080
+ getPayloadCodec() {
1081
+ throw new Error("AWSQuery protocol has no payload codec.");
1082
+ }
1083
+ async serializeRequest(operationSchema, input, context) {
1084
+ const request = await super.serializeRequest(operationSchema, input, context);
1085
+ if (!request.path.endsWith("/")) {
1086
+ request.path += "/";
1087
+ }
1088
+ Object.assign(request.headers, {
1089
+ "content-type": `application/x-www-form-urlencoded`,
1090
+ });
1091
+ if (schema.deref(operationSchema.input) === "unit" || !request.body) {
1092
+ request.body = "";
1093
+ }
1094
+ const action = operationSchema.name.split("#")[1] ?? operationSchema.name;
1095
+ request.body = `Action=${action}&Version=${this.options.version}` + request.body;
1096
+ if (request.body.endsWith("&")) {
1097
+ request.body = request.body.slice(-1);
1098
+ }
1099
+ return request;
1100
+ }
1101
+ async deserializeResponse(operationSchema, context, response) {
1102
+ const deserializer = this.deserializer;
1103
+ const ns = schema.NormalizedSchema.of(operationSchema.output);
1104
+ const dataObject = {};
1105
+ if (response.statusCode >= 300) {
1106
+ const bytes = await protocols.collectBody(response.body, context);
1107
+ if (bytes.byteLength > 0) {
1108
+ Object.assign(dataObject, await deserializer.read(15, bytes));
1109
+ }
1110
+ await this.handleError(operationSchema, context, response, dataObject, this.deserializeMetadata(response));
1111
+ }
1112
+ for (const header in response.headers) {
1113
+ const value = response.headers[header];
1114
+ delete response.headers[header];
1115
+ response.headers[header.toLowerCase()] = value;
1116
+ }
1117
+ const shortName = operationSchema.name.split("#")[1] ?? operationSchema.name;
1118
+ const awsQueryResultKey = ns.isStructSchema() && this.useNestedResult() ? shortName + "Result" : undefined;
1119
+ const bytes = await protocols.collectBody(response.body, context);
1120
+ if (bytes.byteLength > 0) {
1121
+ Object.assign(dataObject, await deserializer.read(ns, bytes, awsQueryResultKey));
1122
+ }
1123
+ const output = {
1124
+ $metadata: this.deserializeMetadata(response),
1125
+ ...dataObject,
1126
+ };
1127
+ return output;
1128
+ }
1129
+ useNestedResult() {
1130
+ return true;
1131
+ }
1132
+ async handleError(operationSchema, context, response, dataObject, metadata) {
1133
+ const errorIdentifier = this.loadQueryErrorCode(response, dataObject) ?? "Unknown";
1134
+ const errorData = this.loadQueryError(dataObject);
1135
+ const message = this.loadQueryErrorMessage(dataObject);
1136
+ errorData.message = message;
1137
+ errorData.Error = {
1138
+ Type: errorData.Type,
1139
+ Code: errorData.Code,
1140
+ Message: message,
1141
+ };
1142
+ const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorIdentifier, this.options.defaultNamespace, response, errorData, metadata, (registry, errorName) => registry.find((schema$1) => schema.NormalizedSchema.of(schema$1).getMergedTraits().awsQueryError?.[0] === errorName));
1143
+ const ns = schema.NormalizedSchema.of(errorSchema);
1144
+ const ErrorCtor = schema.TypeRegistry.for(errorSchema.namespace).getErrorCtor(errorSchema) ?? Error;
1145
+ const exception = new ErrorCtor(message);
1146
+ const output = {
1147
+ Error: errorData.Error,
1148
+ };
1149
+ for (const [name, member] of ns.structIterator()) {
1150
+ const target = member.getMergedTraits().xmlName ?? name;
1151
+ const value = errorData[target] ?? dataObject[target];
1152
+ output[name] = this.deserializer.readSchema(member, value);
1153
+ }
1154
+ throw Object.assign(exception, errorMetadata, {
1155
+ $fault: ns.getMergedTraits().error,
1156
+ message,
1157
+ }, output);
1158
+ }
1159
+ loadQueryErrorCode(output, data) {
1160
+ const code = (data.Errors?.[0]?.Error ?? data.Errors?.Error ?? data.Error)?.Code;
1161
+ if (code !== undefined) {
1162
+ return code;
1163
+ }
1164
+ if (output.statusCode == 404) {
1165
+ return "NotFound";
1166
+ }
1167
+ }
1168
+ loadQueryError(data) {
1169
+ return data.Errors?.[0]?.Error ?? data.Errors?.Error ?? data.Error;
1170
+ }
1171
+ loadQueryErrorMessage(data) {
1172
+ const errorData = this.loadQueryError(data);
1173
+ return errorData?.message ?? errorData?.Message ?? data.message ?? data.Message ?? "Unknown";
1174
+ }
1175
+ getDefaultContentType() {
1176
+ return "application/x-www-form-urlencoded";
1177
+ }
1178
+ }
1442
1179
 
1443
- // src/submodules/protocols/xml/AwsRestXmlProtocol.ts
1444
- var import_protocols9 = require("@smithy/core/protocols");
1445
- var import_schema11 = require("@smithy/core/schema");
1180
+ class AwsEc2QueryProtocol extends AwsQueryProtocol {
1181
+ options;
1182
+ constructor(options) {
1183
+ super(options);
1184
+ this.options = options;
1185
+ const ec2Settings = {
1186
+ capitalizeKeys: true,
1187
+ flattenLists: true,
1188
+ serializeEmptyLists: false,
1189
+ };
1190
+ Object.assign(this.serializer.settings, ec2Settings);
1191
+ }
1192
+ useNestedResult() {
1193
+ return false;
1194
+ }
1195
+ }
1446
1196
 
1447
- // src/submodules/protocols/xml/parseXmlBody.ts
1448
- var import_xml_builder2 = require("@aws-sdk/xml-builder");
1449
- var import_smithy_client5 = require("@smithy/smithy-client");
1450
- var parseXmlBody = /* @__PURE__ */ __name((streamBody, context) => collectBodyString(streamBody, context).then((encoded) => {
1451
- if (encoded.length) {
1452
- let parsedObj;
1453
- try {
1454
- parsedObj = (0, import_xml_builder2.parseXML)(encoded);
1455
- } catch (e) {
1456
- if (e && typeof e === "object") {
1457
- Object.defineProperty(e, "$responseBodyText", {
1458
- value: encoded
1459
- });
1460
- }
1461
- throw e;
1462
- }
1463
- const textNodeName = "#text";
1464
- const key = Object.keys(parsedObj)[0];
1465
- const parsedObjToReturn = parsedObj[key];
1466
- if (parsedObjToReturn[textNodeName]) {
1467
- parsedObjToReturn[key] = parsedObjToReturn[textNodeName];
1468
- delete parsedObjToReturn[textNodeName];
1469
- }
1470
- return (0, import_smithy_client5.getValueFromTextNode)(parsedObjToReturn);
1471
- }
1472
- return {};
1473
- }), "parseXmlBody");
1474
- var parseXmlErrorBody = /* @__PURE__ */ __name(async (errorBody, context) => {
1475
- const value = await parseXmlBody(errorBody, context);
1476
- if (value.Error) {
1477
- value.Error.message = value.Error.message ?? value.Error.Message;
1478
- }
1479
- return value;
1480
- }, "parseXmlErrorBody");
1481
- var loadRestXmlErrorCode = /* @__PURE__ */ __name((output, data) => {
1482
- if (data?.Error?.Code !== void 0) {
1483
- return data.Error.Code;
1484
- }
1485
- if (data?.Code !== void 0) {
1486
- return data.Code;
1487
- }
1488
- if (output.statusCode == 404) {
1489
- return "NotFound";
1490
- }
1491
- }, "loadRestXmlErrorCode");
1197
+ const parseXmlBody = (streamBody, context) => collectBodyString(streamBody, context).then((encoded) => {
1198
+ if (encoded.length) {
1199
+ let parsedObj;
1200
+ try {
1201
+ parsedObj = xmlBuilder.parseXML(encoded);
1202
+ }
1203
+ catch (e) {
1204
+ if (e && typeof e === "object") {
1205
+ Object.defineProperty(e, "$responseBodyText", {
1206
+ value: encoded,
1207
+ });
1208
+ }
1209
+ throw e;
1210
+ }
1211
+ const textNodeName = "#text";
1212
+ const key = Object.keys(parsedObj)[0];
1213
+ const parsedObjToReturn = parsedObj[key];
1214
+ if (parsedObjToReturn[textNodeName]) {
1215
+ parsedObjToReturn[key] = parsedObjToReturn[textNodeName];
1216
+ delete parsedObjToReturn[textNodeName];
1217
+ }
1218
+ return smithyClient.getValueFromTextNode(parsedObjToReturn);
1219
+ }
1220
+ return {};
1221
+ });
1222
+ const parseXmlErrorBody = async (errorBody, context) => {
1223
+ const value = await parseXmlBody(errorBody, context);
1224
+ if (value.Error) {
1225
+ value.Error.message = value.Error.message ?? value.Error.Message;
1226
+ }
1227
+ return value;
1228
+ };
1229
+ const loadRestXmlErrorCode = (output, data) => {
1230
+ if (data?.Error?.Code !== undefined) {
1231
+ return data.Error.Code;
1232
+ }
1233
+ if (data?.Code !== undefined) {
1234
+ return data.Code;
1235
+ }
1236
+ if (output.statusCode == 404) {
1237
+ return "NotFound";
1238
+ }
1239
+ };
1492
1240
 
1493
- // src/submodules/protocols/xml/XmlShapeSerializer.ts
1494
- var import_xml_builder3 = require("@aws-sdk/xml-builder");
1495
- var import_protocols8 = require("@smithy/core/protocols");
1496
- var import_schema10 = require("@smithy/core/schema");
1497
- var import_serde6 = require("@smithy/core/serde");
1498
- var import_smithy_client6 = require("@smithy/smithy-client");
1499
- var import_util_base644 = require("@smithy/util-base64");
1500
- var XmlShapeSerializer = class extends SerdeContextConfig {
1501
- constructor(settings) {
1502
- super();
1503
- this.settings = settings;
1504
- }
1505
- static {
1506
- __name(this, "XmlShapeSerializer");
1507
- }
1508
- stringBuffer;
1509
- byteBuffer;
1510
- buffer;
1511
- write(schema, value) {
1512
- const ns = import_schema10.NormalizedSchema.of(schema);
1513
- if (ns.isStringSchema() && typeof value === "string") {
1514
- this.stringBuffer = value;
1515
- } else if (ns.isBlobSchema()) {
1516
- this.byteBuffer = "byteLength" in value ? value : (this.serdeContext?.base64Decoder ?? import_util_base644.fromBase64)(value);
1517
- } else {
1518
- this.buffer = this.writeStruct(ns, value, void 0);
1519
- const traits = ns.getMergedTraits();
1520
- if (traits.httpPayload && !traits.xmlName) {
1521
- this.buffer.withName(ns.getName());
1522
- }
1523
- }
1524
- }
1525
- flush() {
1526
- if (this.byteBuffer !== void 0) {
1527
- const bytes = this.byteBuffer;
1528
- delete this.byteBuffer;
1529
- return bytes;
1530
- }
1531
- if (this.stringBuffer !== void 0) {
1532
- const str = this.stringBuffer;
1533
- delete this.stringBuffer;
1534
- return str;
1535
- }
1536
- const buffer = this.buffer;
1537
- if (this.settings.xmlNamespace) {
1538
- if (!buffer?.attributes?.["xmlns"]) {
1539
- buffer.addAttribute("xmlns", this.settings.xmlNamespace);
1540
- }
1541
- }
1542
- delete this.buffer;
1543
- return buffer.toString();
1544
- }
1545
- writeStruct(ns, value, parentXmlns) {
1546
- const traits = ns.getMergedTraits();
1547
- const name = ns.isMemberSchema() && !traits.httpPayload ? ns.getMemberTraits().xmlName ?? ns.getMemberName() : traits.xmlName ?? ns.getName();
1548
- if (!name || !ns.isStructSchema()) {
1549
- throw new Error(
1550
- `@aws-sdk/core/protocols - xml serializer, cannot write struct with empty name or non-struct, schema=${ns.getName(
1551
- true
1552
- )}.`
1553
- );
1554
- }
1555
- const structXmlNode = import_xml_builder3.XmlNode.of(name);
1556
- const [xmlnsAttr, xmlns] = this.getXmlnsAttribute(ns, parentXmlns);
1557
- for (const [memberName, memberSchema] of ns.structIterator()) {
1558
- const val = value[memberName];
1559
- if (val != null || memberSchema.isIdempotencyToken()) {
1560
- if (memberSchema.getMergedTraits().xmlAttribute) {
1561
- structXmlNode.addAttribute(
1562
- memberSchema.getMergedTraits().xmlName ?? memberName,
1563
- this.writeSimple(memberSchema, val)
1564
- );
1565
- continue;
1566
- }
1567
- if (memberSchema.isListSchema()) {
1568
- this.writeList(memberSchema, val, structXmlNode, xmlns);
1569
- } else if (memberSchema.isMapSchema()) {
1570
- this.writeMap(memberSchema, val, structXmlNode, xmlns);
1571
- } else if (memberSchema.isStructSchema()) {
1572
- structXmlNode.addChildNode(this.writeStruct(memberSchema, val, xmlns));
1573
- } else {
1574
- const memberNode = import_xml_builder3.XmlNode.of(memberSchema.getMergedTraits().xmlName ?? memberSchema.getMemberName());
1575
- this.writeSimpleInto(memberSchema, val, memberNode, xmlns);
1576
- structXmlNode.addChildNode(memberNode);
1577
- }
1578
- }
1579
- }
1580
- if (xmlns) {
1581
- structXmlNode.addAttribute(xmlnsAttr, xmlns);
1582
- }
1583
- return structXmlNode;
1584
- }
1585
- writeList(listMember, array, container, parentXmlns) {
1586
- if (!listMember.isMemberSchema()) {
1587
- throw new Error(
1588
- `@aws-sdk/core/protocols - xml serializer, cannot write non-member list: ${listMember.getName(true)}`
1589
- );
1590
- }
1591
- const listTraits = listMember.getMergedTraits();
1592
- const listValueSchema = listMember.getValueSchema();
1593
- const listValueTraits = listValueSchema.getMergedTraits();
1594
- const sparse = !!listValueTraits.sparse;
1595
- const flat = !!listTraits.xmlFlattened;
1596
- const [xmlnsAttr, xmlns] = this.getXmlnsAttribute(listMember, parentXmlns);
1597
- const writeItem = /* @__PURE__ */ __name((container2, value) => {
1598
- if (listValueSchema.isListSchema()) {
1599
- this.writeList(listValueSchema, Array.isArray(value) ? value : [value], container2, xmlns);
1600
- } else if (listValueSchema.isMapSchema()) {
1601
- this.writeMap(listValueSchema, value, container2, xmlns);
1602
- } else if (listValueSchema.isStructSchema()) {
1603
- const struct = this.writeStruct(listValueSchema, value, xmlns);
1604
- container2.addChildNode(
1605
- struct.withName(flat ? listTraits.xmlName ?? listMember.getMemberName() : listValueTraits.xmlName ?? "member")
1606
- );
1607
- } else {
1608
- const listItemNode = import_xml_builder3.XmlNode.of(
1609
- flat ? listTraits.xmlName ?? listMember.getMemberName() : listValueTraits.xmlName ?? "member"
1610
- );
1611
- this.writeSimpleInto(listValueSchema, value, listItemNode, xmlns);
1612
- container2.addChildNode(listItemNode);
1613
- }
1614
- }, "writeItem");
1615
- if (flat) {
1616
- for (const value of array) {
1617
- if (sparse || value != null) {
1618
- writeItem(container, value);
1619
- }
1620
- }
1621
- } else {
1622
- const listNode = import_xml_builder3.XmlNode.of(listTraits.xmlName ?? listMember.getMemberName());
1623
- if (xmlns) {
1624
- listNode.addAttribute(xmlnsAttr, xmlns);
1625
- }
1626
- for (const value of array) {
1627
- if (sparse || value != null) {
1628
- writeItem(listNode, value);
1629
- }
1630
- }
1631
- container.addChildNode(listNode);
1632
- }
1633
- }
1634
- writeMap(mapMember, map, container, parentXmlns, containerIsMap = false) {
1635
- if (!mapMember.isMemberSchema()) {
1636
- throw new Error(
1637
- `@aws-sdk/core/protocols - xml serializer, cannot write non-member map: ${mapMember.getName(true)}`
1638
- );
1639
- }
1640
- const mapTraits = mapMember.getMergedTraits();
1641
- const mapKeySchema = mapMember.getKeySchema();
1642
- const mapKeyTraits = mapKeySchema.getMergedTraits();
1643
- const keyTag = mapKeyTraits.xmlName ?? "key";
1644
- const mapValueSchema = mapMember.getValueSchema();
1645
- const mapValueTraits = mapValueSchema.getMergedTraits();
1646
- const valueTag = mapValueTraits.xmlName ?? "value";
1647
- const sparse = !!mapValueTraits.sparse;
1648
- const flat = !!mapTraits.xmlFlattened;
1649
- const [xmlnsAttr, xmlns] = this.getXmlnsAttribute(mapMember, parentXmlns);
1650
- const addKeyValue = /* @__PURE__ */ __name((entry, key, val) => {
1651
- const keyNode = import_xml_builder3.XmlNode.of(keyTag, key);
1652
- const [keyXmlnsAttr, keyXmlns] = this.getXmlnsAttribute(mapKeySchema, xmlns);
1653
- if (keyXmlns) {
1654
- keyNode.addAttribute(keyXmlnsAttr, keyXmlns);
1655
- }
1656
- entry.addChildNode(keyNode);
1657
- let valueNode = import_xml_builder3.XmlNode.of(valueTag);
1658
- if (mapValueSchema.isListSchema()) {
1659
- this.writeList(mapValueSchema, val, valueNode, xmlns);
1660
- } else if (mapValueSchema.isMapSchema()) {
1661
- this.writeMap(mapValueSchema, val, valueNode, xmlns, true);
1662
- } else if (mapValueSchema.isStructSchema()) {
1663
- valueNode = this.writeStruct(mapValueSchema, val, xmlns);
1664
- } else {
1665
- this.writeSimpleInto(mapValueSchema, val, valueNode, xmlns);
1666
- }
1667
- entry.addChildNode(valueNode);
1668
- }, "addKeyValue");
1669
- if (flat) {
1670
- for (const [key, val] of Object.entries(map)) {
1671
- if (sparse || val != null) {
1672
- const entry = import_xml_builder3.XmlNode.of(mapTraits.xmlName ?? mapMember.getMemberName());
1673
- addKeyValue(entry, key, val);
1674
- container.addChildNode(entry);
1675
- }
1676
- }
1677
- } else {
1678
- let mapNode;
1679
- if (!containerIsMap) {
1680
- mapNode = import_xml_builder3.XmlNode.of(mapTraits.xmlName ?? mapMember.getMemberName());
1241
+ class XmlShapeSerializer extends SerdeContextConfig {
1242
+ settings;
1243
+ stringBuffer;
1244
+ byteBuffer;
1245
+ buffer;
1246
+ constructor(settings) {
1247
+ super();
1248
+ this.settings = settings;
1249
+ }
1250
+ write(schema$1, value) {
1251
+ const ns = schema.NormalizedSchema.of(schema$1);
1252
+ if (ns.isStringSchema() && typeof value === "string") {
1253
+ this.stringBuffer = value;
1254
+ }
1255
+ else if (ns.isBlobSchema()) {
1256
+ this.byteBuffer =
1257
+ "byteLength" in value
1258
+ ? value
1259
+ : (this.serdeContext?.base64Decoder ?? utilBase64.fromBase64)(value);
1260
+ }
1261
+ else {
1262
+ this.buffer = this.writeStruct(ns, value, undefined);
1263
+ const traits = ns.getMergedTraits();
1264
+ if (traits.httpPayload && !traits.xmlName) {
1265
+ this.buffer.withName(ns.getName());
1266
+ }
1267
+ }
1268
+ }
1269
+ flush() {
1270
+ if (this.byteBuffer !== undefined) {
1271
+ const bytes = this.byteBuffer;
1272
+ delete this.byteBuffer;
1273
+ return bytes;
1274
+ }
1275
+ if (this.stringBuffer !== undefined) {
1276
+ const str = this.stringBuffer;
1277
+ delete this.stringBuffer;
1278
+ return str;
1279
+ }
1280
+ const buffer = this.buffer;
1281
+ if (this.settings.xmlNamespace) {
1282
+ if (!buffer?.attributes?.["xmlns"]) {
1283
+ buffer.addAttribute("xmlns", this.settings.xmlNamespace);
1284
+ }
1285
+ }
1286
+ delete this.buffer;
1287
+ return buffer.toString();
1288
+ }
1289
+ writeStruct(ns, value, parentXmlns) {
1290
+ const traits = ns.getMergedTraits();
1291
+ const name = ns.isMemberSchema() && !traits.httpPayload
1292
+ ? ns.getMemberTraits().xmlName ?? ns.getMemberName()
1293
+ : traits.xmlName ?? ns.getName();
1294
+ if (!name || !ns.isStructSchema()) {
1295
+ throw new Error(`@aws-sdk/core/protocols - xml serializer, cannot write struct with empty name or non-struct, schema=${ns.getName(true)}.`);
1296
+ }
1297
+ const structXmlNode = xmlBuilder.XmlNode.of(name);
1298
+ const [xmlnsAttr, xmlns] = this.getXmlnsAttribute(ns, parentXmlns);
1299
+ for (const [memberName, memberSchema] of ns.structIterator()) {
1300
+ const val = value[memberName];
1301
+ if (val != null || memberSchema.isIdempotencyToken()) {
1302
+ if (memberSchema.getMergedTraits().xmlAttribute) {
1303
+ structXmlNode.addAttribute(memberSchema.getMergedTraits().xmlName ?? memberName, this.writeSimple(memberSchema, val));
1304
+ continue;
1305
+ }
1306
+ if (memberSchema.isListSchema()) {
1307
+ this.writeList(memberSchema, val, structXmlNode, xmlns);
1308
+ }
1309
+ else if (memberSchema.isMapSchema()) {
1310
+ this.writeMap(memberSchema, val, structXmlNode, xmlns);
1311
+ }
1312
+ else if (memberSchema.isStructSchema()) {
1313
+ structXmlNode.addChildNode(this.writeStruct(memberSchema, val, xmlns));
1314
+ }
1315
+ else {
1316
+ const memberNode = xmlBuilder.XmlNode.of(memberSchema.getMergedTraits().xmlName ?? memberSchema.getMemberName());
1317
+ this.writeSimpleInto(memberSchema, val, memberNode, xmlns);
1318
+ structXmlNode.addChildNode(memberNode);
1319
+ }
1320
+ }
1321
+ }
1681
1322
  if (xmlns) {
1682
- mapNode.addAttribute(xmlnsAttr, xmlns);
1683
- }
1684
- container.addChildNode(mapNode);
1685
- }
1686
- for (const [key, val] of Object.entries(map)) {
1687
- if (sparse || val != null) {
1688
- const entry = import_xml_builder3.XmlNode.of("entry");
1689
- addKeyValue(entry, key, val);
1690
- (containerIsMap ? container : mapNode).addChildNode(entry);
1691
- }
1692
- }
1693
- }
1694
- }
1695
- writeSimple(_schema, value) {
1696
- if (null === value) {
1697
- throw new Error("@aws-sdk/core/protocols - (XML serializer) cannot write null value.");
1698
- }
1699
- const ns = import_schema10.NormalizedSchema.of(_schema);
1700
- let nodeContents = null;
1701
- if (value && typeof value === "object") {
1702
- if (ns.isBlobSchema()) {
1703
- nodeContents = (this.serdeContext?.base64Encoder ?? import_util_base644.toBase64)(value);
1704
- } else if (ns.isTimestampSchema() && value instanceof Date) {
1705
- const format = (0, import_protocols8.determineTimestampFormat)(ns, this.settings);
1706
- switch (format) {
1707
- case import_schema10.SCHEMA.TIMESTAMP_DATE_TIME:
1708
- nodeContents = value.toISOString().replace(".000Z", "Z");
1709
- break;
1710
- case import_schema10.SCHEMA.TIMESTAMP_HTTP_DATE:
1711
- nodeContents = (0, import_smithy_client6.dateToUtcString)(value);
1712
- break;
1713
- case import_schema10.SCHEMA.TIMESTAMP_EPOCH_SECONDS:
1714
- nodeContents = String(value.getTime() / 1e3);
1715
- break;
1716
- default:
1717
- console.warn("Missing timestamp format, using http date", value);
1718
- nodeContents = (0, import_smithy_client6.dateToUtcString)(value);
1719
- break;
1720
- }
1721
- } else if (ns.isBigDecimalSchema() && value) {
1722
- if (value instanceof import_serde6.NumericValue) {
1723
- return value.string;
1724
- }
1725
- return String(value);
1726
- } else if (ns.isMapSchema() || ns.isListSchema()) {
1727
- throw new Error(
1728
- "@aws-sdk/core/protocols - xml serializer, cannot call _write() on List/Map schema, call writeList or writeMap() instead."
1729
- );
1730
- } else {
1731
- throw new Error(
1732
- `@aws-sdk/core/protocols - xml serializer, unhandled schema type for object value and schema: ${ns.getName(
1733
- true
1734
- )}`
1735
- );
1736
- }
1737
- }
1738
- if (ns.isBooleanSchema() || ns.isNumericSchema() || ns.isBigIntegerSchema() || ns.isBigDecimalSchema()) {
1739
- nodeContents = String(value);
1740
- }
1741
- if (ns.isStringSchema()) {
1742
- if (value === void 0 && ns.isIdempotencyToken()) {
1743
- nodeContents = (0, import_serde6.generateIdempotencyToken)();
1744
- } else {
1745
- nodeContents = String(value);
1746
- }
1747
- }
1748
- if (nodeContents === null) {
1749
- throw new Error(`Unhandled schema-value pair ${ns.getName(true)}=${value}`);
1750
- }
1751
- return nodeContents;
1752
- }
1753
- writeSimpleInto(_schema, value, into, parentXmlns) {
1754
- const nodeContents = this.writeSimple(_schema, value);
1755
- const ns = import_schema10.NormalizedSchema.of(_schema);
1756
- const content = new import_xml_builder3.XmlText(nodeContents);
1757
- const [xmlnsAttr, xmlns] = this.getXmlnsAttribute(ns, parentXmlns);
1758
- if (xmlns) {
1759
- into.addAttribute(xmlnsAttr, xmlns);
1760
- }
1761
- into.addChildNode(content);
1762
- }
1763
- getXmlnsAttribute(ns, parentXmlns) {
1764
- const traits = ns.getMergedTraits();
1765
- const [prefix, xmlns] = traits.xmlNamespace ?? [];
1766
- if (xmlns && xmlns !== parentXmlns) {
1767
- return [prefix ? `xmlns:${prefix}` : "xmlns", xmlns];
1768
- }
1769
- return [void 0, void 0];
1770
- }
1771
- };
1323
+ structXmlNode.addAttribute(xmlnsAttr, xmlns);
1324
+ }
1325
+ return structXmlNode;
1326
+ }
1327
+ writeList(listMember, array, container, parentXmlns) {
1328
+ if (!listMember.isMemberSchema()) {
1329
+ throw new Error(`@aws-sdk/core/protocols - xml serializer, cannot write non-member list: ${listMember.getName(true)}`);
1330
+ }
1331
+ const listTraits = listMember.getMergedTraits();
1332
+ const listValueSchema = listMember.getValueSchema();
1333
+ const listValueTraits = listValueSchema.getMergedTraits();
1334
+ const sparse = !!listValueTraits.sparse;
1335
+ const flat = !!listTraits.xmlFlattened;
1336
+ const [xmlnsAttr, xmlns] = this.getXmlnsAttribute(listMember, parentXmlns);
1337
+ const writeItem = (container, value) => {
1338
+ if (listValueSchema.isListSchema()) {
1339
+ this.writeList(listValueSchema, Array.isArray(value) ? value : [value], container, xmlns);
1340
+ }
1341
+ else if (listValueSchema.isMapSchema()) {
1342
+ this.writeMap(listValueSchema, value, container, xmlns);
1343
+ }
1344
+ else if (listValueSchema.isStructSchema()) {
1345
+ const struct = this.writeStruct(listValueSchema, value, xmlns);
1346
+ container.addChildNode(struct.withName(flat ? listTraits.xmlName ?? listMember.getMemberName() : listValueTraits.xmlName ?? "member"));
1347
+ }
1348
+ else {
1349
+ const listItemNode = xmlBuilder.XmlNode.of(flat ? listTraits.xmlName ?? listMember.getMemberName() : listValueTraits.xmlName ?? "member");
1350
+ this.writeSimpleInto(listValueSchema, value, listItemNode, xmlns);
1351
+ container.addChildNode(listItemNode);
1352
+ }
1353
+ };
1354
+ if (flat) {
1355
+ for (const value of array) {
1356
+ if (sparse || value != null) {
1357
+ writeItem(container, value);
1358
+ }
1359
+ }
1360
+ }
1361
+ else {
1362
+ const listNode = xmlBuilder.XmlNode.of(listTraits.xmlName ?? listMember.getMemberName());
1363
+ if (xmlns) {
1364
+ listNode.addAttribute(xmlnsAttr, xmlns);
1365
+ }
1366
+ for (const value of array) {
1367
+ if (sparse || value != null) {
1368
+ writeItem(listNode, value);
1369
+ }
1370
+ }
1371
+ container.addChildNode(listNode);
1372
+ }
1373
+ }
1374
+ writeMap(mapMember, map, container, parentXmlns, containerIsMap = false) {
1375
+ if (!mapMember.isMemberSchema()) {
1376
+ throw new Error(`@aws-sdk/core/protocols - xml serializer, cannot write non-member map: ${mapMember.getName(true)}`);
1377
+ }
1378
+ const mapTraits = mapMember.getMergedTraits();
1379
+ const mapKeySchema = mapMember.getKeySchema();
1380
+ const mapKeyTraits = mapKeySchema.getMergedTraits();
1381
+ const keyTag = mapKeyTraits.xmlName ?? "key";
1382
+ const mapValueSchema = mapMember.getValueSchema();
1383
+ const mapValueTraits = mapValueSchema.getMergedTraits();
1384
+ const valueTag = mapValueTraits.xmlName ?? "value";
1385
+ const sparse = !!mapValueTraits.sparse;
1386
+ const flat = !!mapTraits.xmlFlattened;
1387
+ const [xmlnsAttr, xmlns] = this.getXmlnsAttribute(mapMember, parentXmlns);
1388
+ const addKeyValue = (entry, key, val) => {
1389
+ const keyNode = xmlBuilder.XmlNode.of(keyTag, key);
1390
+ const [keyXmlnsAttr, keyXmlns] = this.getXmlnsAttribute(mapKeySchema, xmlns);
1391
+ if (keyXmlns) {
1392
+ keyNode.addAttribute(keyXmlnsAttr, keyXmlns);
1393
+ }
1394
+ entry.addChildNode(keyNode);
1395
+ let valueNode = xmlBuilder.XmlNode.of(valueTag);
1396
+ if (mapValueSchema.isListSchema()) {
1397
+ this.writeList(mapValueSchema, val, valueNode, xmlns);
1398
+ }
1399
+ else if (mapValueSchema.isMapSchema()) {
1400
+ this.writeMap(mapValueSchema, val, valueNode, xmlns, true);
1401
+ }
1402
+ else if (mapValueSchema.isStructSchema()) {
1403
+ valueNode = this.writeStruct(mapValueSchema, val, xmlns);
1404
+ }
1405
+ else {
1406
+ this.writeSimpleInto(mapValueSchema, val, valueNode, xmlns);
1407
+ }
1408
+ entry.addChildNode(valueNode);
1409
+ };
1410
+ if (flat) {
1411
+ for (const [key, val] of Object.entries(map)) {
1412
+ if (sparse || val != null) {
1413
+ const entry = xmlBuilder.XmlNode.of(mapTraits.xmlName ?? mapMember.getMemberName());
1414
+ addKeyValue(entry, key, val);
1415
+ container.addChildNode(entry);
1416
+ }
1417
+ }
1418
+ }
1419
+ else {
1420
+ let mapNode;
1421
+ if (!containerIsMap) {
1422
+ mapNode = xmlBuilder.XmlNode.of(mapTraits.xmlName ?? mapMember.getMemberName());
1423
+ if (xmlns) {
1424
+ mapNode.addAttribute(xmlnsAttr, xmlns);
1425
+ }
1426
+ container.addChildNode(mapNode);
1427
+ }
1428
+ for (const [key, val] of Object.entries(map)) {
1429
+ if (sparse || val != null) {
1430
+ const entry = xmlBuilder.XmlNode.of("entry");
1431
+ addKeyValue(entry, key, val);
1432
+ (containerIsMap ? container : mapNode).addChildNode(entry);
1433
+ }
1434
+ }
1435
+ }
1436
+ }
1437
+ writeSimple(_schema, value) {
1438
+ if (null === value) {
1439
+ throw new Error("@aws-sdk/core/protocols - (XML serializer) cannot write null value.");
1440
+ }
1441
+ const ns = schema.NormalizedSchema.of(_schema);
1442
+ let nodeContents = null;
1443
+ if (value && typeof value === "object") {
1444
+ if (ns.isBlobSchema()) {
1445
+ nodeContents = (this.serdeContext?.base64Encoder ?? utilBase64.toBase64)(value);
1446
+ }
1447
+ else if (ns.isTimestampSchema() && value instanceof Date) {
1448
+ const format = protocols.determineTimestampFormat(ns, this.settings);
1449
+ switch (format) {
1450
+ case 5:
1451
+ nodeContents = value.toISOString().replace(".000Z", "Z");
1452
+ break;
1453
+ case 6:
1454
+ nodeContents = smithyClient.dateToUtcString(value);
1455
+ break;
1456
+ case 7:
1457
+ nodeContents = String(value.getTime() / 1000);
1458
+ break;
1459
+ default:
1460
+ console.warn("Missing timestamp format, using http date", value);
1461
+ nodeContents = smithyClient.dateToUtcString(value);
1462
+ break;
1463
+ }
1464
+ }
1465
+ else if (ns.isBigDecimalSchema() && value) {
1466
+ if (value instanceof serde.NumericValue) {
1467
+ return value.string;
1468
+ }
1469
+ return String(value);
1470
+ }
1471
+ else if (ns.isMapSchema() || ns.isListSchema()) {
1472
+ throw new Error("@aws-sdk/core/protocols - xml serializer, cannot call _write() on List/Map schema, call writeList or writeMap() instead.");
1473
+ }
1474
+ else {
1475
+ throw new Error(`@aws-sdk/core/protocols - xml serializer, unhandled schema type for object value and schema: ${ns.getName(true)}`);
1476
+ }
1477
+ }
1478
+ if (ns.isBooleanSchema() || ns.isNumericSchema() || ns.isBigIntegerSchema() || ns.isBigDecimalSchema()) {
1479
+ nodeContents = String(value);
1480
+ }
1481
+ if (ns.isStringSchema()) {
1482
+ if (value === undefined && ns.isIdempotencyToken()) {
1483
+ nodeContents = serde.generateIdempotencyToken();
1484
+ }
1485
+ else {
1486
+ nodeContents = String(value);
1487
+ }
1488
+ }
1489
+ if (nodeContents === null) {
1490
+ throw new Error(`Unhandled schema-value pair ${ns.getName(true)}=${value}`);
1491
+ }
1492
+ return nodeContents;
1493
+ }
1494
+ writeSimpleInto(_schema, value, into, parentXmlns) {
1495
+ const nodeContents = this.writeSimple(_schema, value);
1496
+ const ns = schema.NormalizedSchema.of(_schema);
1497
+ const content = new xmlBuilder.XmlText(nodeContents);
1498
+ const [xmlnsAttr, xmlns] = this.getXmlnsAttribute(ns, parentXmlns);
1499
+ if (xmlns) {
1500
+ into.addAttribute(xmlnsAttr, xmlns);
1501
+ }
1502
+ into.addChildNode(content);
1503
+ }
1504
+ getXmlnsAttribute(ns, parentXmlns) {
1505
+ const traits = ns.getMergedTraits();
1506
+ const [prefix, xmlns] = traits.xmlNamespace ?? [];
1507
+ if (xmlns && xmlns !== parentXmlns) {
1508
+ return [prefix ? `xmlns:${prefix}` : "xmlns", xmlns];
1509
+ }
1510
+ return [void 0, void 0];
1511
+ }
1512
+ }
1772
1513
 
1773
- // src/submodules/protocols/xml/XmlCodec.ts
1774
- var XmlCodec = class extends SerdeContextConfig {
1775
- constructor(settings) {
1776
- super();
1777
- this.settings = settings;
1778
- }
1779
- static {
1780
- __name(this, "XmlCodec");
1781
- }
1782
- createSerializer() {
1783
- const serializer = new XmlShapeSerializer(this.settings);
1784
- serializer.setSerdeContext(this.serdeContext);
1785
- return serializer;
1786
- }
1787
- createDeserializer() {
1788
- const deserializer = new XmlShapeDeserializer(this.settings);
1789
- deserializer.setSerdeContext(this.serdeContext);
1790
- return deserializer;
1791
- }
1792
- };
1514
+ class XmlCodec extends SerdeContextConfig {
1515
+ settings;
1516
+ constructor(settings) {
1517
+ super();
1518
+ this.settings = settings;
1519
+ }
1520
+ createSerializer() {
1521
+ const serializer = new XmlShapeSerializer(this.settings);
1522
+ serializer.setSerdeContext(this.serdeContext);
1523
+ return serializer;
1524
+ }
1525
+ createDeserializer() {
1526
+ const deserializer = new XmlShapeDeserializer(this.settings);
1527
+ deserializer.setSerdeContext(this.serdeContext);
1528
+ return deserializer;
1529
+ }
1530
+ }
1793
1531
 
1794
- // src/submodules/protocols/xml/AwsRestXmlProtocol.ts
1795
- var AwsRestXmlProtocol = class extends import_protocols9.HttpBindingProtocol {
1796
- static {
1797
- __name(this, "AwsRestXmlProtocol");
1798
- }
1799
- codec;
1800
- serializer;
1801
- deserializer;
1802
- mixin = new ProtocolLib();
1803
- constructor(options) {
1804
- super(options);
1805
- const settings = {
1806
- timestampFormat: {
1807
- useTrait: true,
1808
- default: import_schema11.SCHEMA.TIMESTAMP_DATE_TIME
1809
- },
1810
- httpBindings: true,
1811
- xmlNamespace: options.xmlNamespace,
1812
- serviceNamespace: options.defaultNamespace
1813
- };
1814
- this.codec = new XmlCodec(settings);
1815
- this.serializer = new import_protocols9.HttpInterceptingShapeSerializer(this.codec.createSerializer(), settings);
1816
- this.deserializer = new import_protocols9.HttpInterceptingShapeDeserializer(this.codec.createDeserializer(), settings);
1817
- }
1818
- getPayloadCodec() {
1819
- return this.codec;
1820
- }
1821
- getShapeId() {
1822
- return "aws.protocols#restXml";
1823
- }
1824
- async serializeRequest(operationSchema, input, context) {
1825
- const request = await super.serializeRequest(operationSchema, input, context);
1826
- const inputSchema = import_schema11.NormalizedSchema.of(operationSchema.input);
1827
- if (!request.headers["content-type"]) {
1828
- const contentType = this.mixin.resolveRestContentType(this.getDefaultContentType(), inputSchema);
1829
- if (contentType) {
1830
- request.headers["content-type"] = contentType;
1831
- }
1832
- }
1833
- if (request.headers["content-type"] === this.getDefaultContentType()) {
1834
- if (typeof request.body === "string") {
1835
- request.body = '<?xml version="1.0" encoding="UTF-8"?>' + request.body;
1836
- }
1837
- }
1838
- return request;
1839
- }
1840
- async deserializeResponse(operationSchema, context, response) {
1841
- return super.deserializeResponse(operationSchema, context, response);
1842
- }
1843
- async handleError(operationSchema, context, response, dataObject, metadata) {
1844
- const errorIdentifier = loadRestXmlErrorCode(response, dataObject) ?? "Unknown";
1845
- const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(
1846
- errorIdentifier,
1847
- this.options.defaultNamespace,
1848
- response,
1849
- dataObject,
1850
- metadata
1851
- );
1852
- const ns = import_schema11.NormalizedSchema.of(errorSchema);
1853
- const message = dataObject.Error?.message ?? dataObject.Error?.Message ?? dataObject.message ?? dataObject.Message ?? "Unknown";
1854
- const ErrorCtor = import_schema11.TypeRegistry.for(errorSchema.namespace).getErrorCtor(errorSchema) ?? Error;
1855
- const exception = new ErrorCtor(message);
1856
- await this.deserializeHttpMessage(errorSchema, context, response, dataObject);
1857
- const output = {};
1858
- for (const [name, member] of ns.structIterator()) {
1859
- const target = member.getMergedTraits().xmlName ?? name;
1860
- const value = dataObject.Error?.[target] ?? dataObject[target];
1861
- output[name] = this.codec.createDeserializer().readSchema(member, value);
1862
- }
1863
- throw Object.assign(
1864
- exception,
1865
- errorMetadata,
1866
- {
1867
- $fault: ns.getMergedTraits().error,
1868
- message
1869
- },
1870
- output
1871
- );
1872
- }
1873
- /**
1874
- * @override
1875
- */
1876
- getDefaultContentType() {
1877
- return "application/xml";
1878
- }
1879
- };
1880
- // Annotate the CommonJS export names for ESM import in node:
1881
- 0 && (module.exports = {
1882
- AwsEc2QueryProtocol,
1883
- AwsJson1_0Protocol,
1884
- AwsJson1_1Protocol,
1885
- AwsJsonRpcProtocol,
1886
- AwsQueryProtocol,
1887
- AwsRestJsonProtocol,
1888
- AwsRestXmlProtocol,
1889
- AwsSmithyRpcV2CborProtocol,
1890
- JsonCodec,
1891
- JsonShapeDeserializer,
1892
- JsonShapeSerializer,
1893
- XmlCodec,
1894
- XmlShapeDeserializer,
1895
- XmlShapeSerializer,
1896
- _toBool,
1897
- _toNum,
1898
- _toStr,
1899
- awsExpectUnion,
1900
- loadRestJsonErrorCode,
1901
- loadRestXmlErrorCode,
1902
- parseJsonBody,
1903
- parseJsonErrorBody,
1904
- parseXmlBody,
1905
- parseXmlErrorBody
1906
- });
1532
+ class AwsRestXmlProtocol extends protocols.HttpBindingProtocol {
1533
+ codec;
1534
+ serializer;
1535
+ deserializer;
1536
+ mixin = new ProtocolLib();
1537
+ constructor(options) {
1538
+ super(options);
1539
+ const settings = {
1540
+ timestampFormat: {
1541
+ useTrait: true,
1542
+ default: 5,
1543
+ },
1544
+ httpBindings: true,
1545
+ xmlNamespace: options.xmlNamespace,
1546
+ serviceNamespace: options.defaultNamespace,
1547
+ };
1548
+ this.codec = new XmlCodec(settings);
1549
+ this.serializer = new protocols.HttpInterceptingShapeSerializer(this.codec.createSerializer(), settings);
1550
+ this.deserializer = new protocols.HttpInterceptingShapeDeserializer(this.codec.createDeserializer(), settings);
1551
+ }
1552
+ getPayloadCodec() {
1553
+ return this.codec;
1554
+ }
1555
+ getShapeId() {
1556
+ return "aws.protocols#restXml";
1557
+ }
1558
+ async serializeRequest(operationSchema, input, context) {
1559
+ const request = await super.serializeRequest(operationSchema, input, context);
1560
+ const inputSchema = schema.NormalizedSchema.of(operationSchema.input);
1561
+ if (!request.headers["content-type"]) {
1562
+ const contentType = this.mixin.resolveRestContentType(this.getDefaultContentType(), inputSchema);
1563
+ if (contentType) {
1564
+ request.headers["content-type"] = contentType;
1565
+ }
1566
+ }
1567
+ if (request.headers["content-type"] === this.getDefaultContentType()) {
1568
+ if (typeof request.body === "string") {
1569
+ request.body = '<?xml version="1.0" encoding="UTF-8"?>' + request.body;
1570
+ }
1571
+ }
1572
+ return request;
1573
+ }
1574
+ async deserializeResponse(operationSchema, context, response) {
1575
+ return super.deserializeResponse(operationSchema, context, response);
1576
+ }
1577
+ async handleError(operationSchema, context, response, dataObject, metadata) {
1578
+ const errorIdentifier = loadRestXmlErrorCode(response, dataObject) ?? "Unknown";
1579
+ const { errorSchema, errorMetadata } = await this.mixin.getErrorSchemaOrThrowBaseException(errorIdentifier, this.options.defaultNamespace, response, dataObject, metadata);
1580
+ const ns = schema.NormalizedSchema.of(errorSchema);
1581
+ const message = dataObject.Error?.message ?? dataObject.Error?.Message ?? dataObject.message ?? dataObject.Message ?? "Unknown";
1582
+ const ErrorCtor = schema.TypeRegistry.for(errorSchema.namespace).getErrorCtor(errorSchema) ?? Error;
1583
+ const exception = new ErrorCtor(message);
1584
+ await this.deserializeHttpMessage(errorSchema, context, response, dataObject);
1585
+ const output = {};
1586
+ for (const [name, member] of ns.structIterator()) {
1587
+ const target = member.getMergedTraits().xmlName ?? name;
1588
+ const value = dataObject.Error?.[target] ?? dataObject[target];
1589
+ output[name] = this.codec.createDeserializer().readSchema(member, value);
1590
+ }
1591
+ throw Object.assign(exception, errorMetadata, {
1592
+ $fault: ns.getMergedTraits().error,
1593
+ message,
1594
+ }, output);
1595
+ }
1596
+ getDefaultContentType() {
1597
+ return "application/xml";
1598
+ }
1599
+ }
1600
+
1601
+ exports.AwsEc2QueryProtocol = AwsEc2QueryProtocol;
1602
+ exports.AwsJson1_0Protocol = AwsJson1_0Protocol;
1603
+ exports.AwsJson1_1Protocol = AwsJson1_1Protocol;
1604
+ exports.AwsJsonRpcProtocol = AwsJsonRpcProtocol;
1605
+ exports.AwsQueryProtocol = AwsQueryProtocol;
1606
+ exports.AwsRestJsonProtocol = AwsRestJsonProtocol;
1607
+ exports.AwsRestXmlProtocol = AwsRestXmlProtocol;
1608
+ exports.AwsSmithyRpcV2CborProtocol = AwsSmithyRpcV2CborProtocol;
1609
+ exports.JsonCodec = JsonCodec;
1610
+ exports.JsonShapeDeserializer = JsonShapeDeserializer;
1611
+ exports.JsonShapeSerializer = JsonShapeSerializer;
1612
+ exports.XmlCodec = XmlCodec;
1613
+ exports.XmlShapeDeserializer = XmlShapeDeserializer;
1614
+ exports.XmlShapeSerializer = XmlShapeSerializer;
1615
+ exports._toBool = _toBool;
1616
+ exports._toNum = _toNum;
1617
+ exports._toStr = _toStr;
1618
+ exports.awsExpectUnion = awsExpectUnion;
1619
+ exports.loadRestJsonErrorCode = loadRestJsonErrorCode;
1620
+ exports.loadRestXmlErrorCode = loadRestXmlErrorCode;
1621
+ exports.parseJsonBody = parseJsonBody;
1622
+ exports.parseJsonErrorBody = parseJsonErrorBody;
1623
+ exports.parseXmlBody = parseXmlBody;
1624
+ exports.parseXmlErrorBody = parseXmlErrorBody;