@cdk8s/awscdk-resolver 0.0.303 → 0.0.305

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 (101) hide show
  1. package/.jsii +4 -4
  2. package/lib/resolve.js +1 -1
  3. package/node_modules/@aws-sdk/client-cloudformation/package.json +5 -5
  4. package/node_modules/@aws-sdk/client-sso/package.json +4 -4
  5. package/node_modules/@aws-sdk/core/dist-cjs/submodules/protocols/index.js +1466 -14
  6. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/ConfigurableSerdeContext.js +6 -0
  7. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/index.js +13 -0
  8. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsJson1_0Protocol.js +14 -0
  9. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsJson1_1Protocol.js +14 -0
  10. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsJsonRpcProtocol.js +89 -0
  11. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/AwsRestJsonProtocol.js +123 -0
  12. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/JsonCodec.js +20 -0
  13. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/JsonShapeDeserializer.js +105 -0
  14. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/JsonShapeSerializer.js +106 -0
  15. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/jsonReplacer.js +46 -0
  16. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/json/jsonReviver.js +18 -0
  17. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/query/AwsEc2QueryProtocol.js +3 -0
  18. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/query/AwsQueryProtocol.js +134 -0
  19. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/query/QueryShapeSerializer.js +143 -0
  20. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/xml/AwsRestXmlProtocol.js +131 -0
  21. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/xml/XmlCodec.js +20 -0
  22. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/xml/XmlShapeDeserializer.js +154 -0
  23. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/xml/XmlShapeSerializer.js +279 -0
  24. package/node_modules/@aws-sdk/core/dist-es/submodules/protocols/xml/simpleFormatXml.js +27 -0
  25. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/ConfigurableSerdeContext.d.ts +8 -0
  26. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/common.d.ts +2 -2
  27. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/index.d.ts +13 -0
  28. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/AwsJson1_0Protocol.d.ts +12 -0
  29. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/AwsJson1_1Protocol.d.ts +12 -0
  30. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/AwsJsonRpcProtocol.d.ts +18 -0
  31. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/AwsRestJsonProtocol.d.ts +19 -0
  32. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/JsonCodec.d.ts +19 -0
  33. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/JsonShapeDeserializer.d.ts +13 -0
  34. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/JsonShapeSerializer.d.ts +15 -0
  35. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/jsonReplacer.d.ts +21 -0
  36. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/jsonReviver.d.ts +15 -0
  37. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/json/parseJsonBody.d.ts +3 -3
  38. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/query/AwsEc2QueryProtocol.d.ts +6 -0
  39. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/query/AwsQueryProtocol.d.ts +29 -0
  40. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/query/QueryShapeSerializer.d.ts +14 -0
  41. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/xml/AwsRestXmlProtocol.d.ts +21 -0
  42. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/xml/XmlCodec.d.ts +14 -0
  43. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/xml/XmlShapeDeserializer.d.ts +20 -0
  44. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/xml/XmlShapeSerializer.d.ts +21 -0
  45. package/node_modules/@aws-sdk/core/dist-types/submodules/protocols/xml/simpleFormatXml.d.ts +6 -0
  46. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/ConfigurableSerdeContext.d.ts +5 -0
  47. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/common.d.ts +2 -2
  48. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/index.d.ts +13 -0
  49. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/AwsJson1_0Protocol.d.ts +6 -0
  50. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/AwsJson1_1Protocol.d.ts +6 -0
  51. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/AwsJsonRpcProtocol.d.ts +33 -0
  52. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/AwsRestJsonProtocol.d.ts +34 -0
  53. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/JsonCodec.d.ts +16 -0
  54. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/JsonShapeDeserializer.d.ts +13 -0
  55. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/JsonShapeSerializer.d.ts +15 -0
  56. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/jsonReplacer.d.ts +7 -0
  57. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/jsonReviver.d.ts +7 -0
  58. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/json/parseJsonBody.d.ts +3 -3
  59. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/query/AwsEc2QueryProtocol.d.ts +2 -0
  60. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/query/AwsQueryProtocol.d.ts +52 -0
  61. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/query/QueryShapeSerializer.d.ts +14 -0
  62. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/xml/AwsRestXmlProtocol.d.ts +39 -0
  63. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/xml/XmlCodec.d.ts +17 -0
  64. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/xml/XmlShapeDeserializer.d.ts +15 -0
  65. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/xml/XmlShapeSerializer.d.ts +21 -0
  66. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/protocols/xml/simpleFormatXml.d.ts +1 -0
  67. package/node_modules/@aws-sdk/core/package.json +5 -1
  68. package/node_modules/@aws-sdk/credential-provider-env/package.json +2 -2
  69. package/node_modules/@aws-sdk/credential-provider-http/package.json +2 -2
  70. package/node_modules/@aws-sdk/credential-provider-ini/package.json +8 -8
  71. package/node_modules/@aws-sdk/credential-provider-node/package.json +7 -7
  72. package/node_modules/@aws-sdk/credential-provider-process/package.json +2 -2
  73. package/node_modules/@aws-sdk/credential-provider-sso/package.json +4 -4
  74. package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +3 -3
  75. package/node_modules/@aws-sdk/middleware-user-agent/package.json +2 -2
  76. package/node_modules/@aws-sdk/nested-clients/package.json +4 -4
  77. package/node_modules/@aws-sdk/token-providers/package.json +3 -3
  78. package/node_modules/@aws-sdk/util-user-agent-node/package.json +2 -2
  79. package/node_modules/@aws-sdk/xml-builder/LICENSE +201 -0
  80. package/node_modules/@aws-sdk/xml-builder/README.md +10 -0
  81. package/node_modules/@aws-sdk/xml-builder/dist-cjs/index.js +173 -0
  82. package/node_modules/@aws-sdk/xml-builder/dist-es/XmlNode.js +88 -0
  83. package/node_modules/@aws-sdk/xml-builder/dist-es/XmlText.js +10 -0
  84. package/node_modules/@aws-sdk/xml-builder/dist-es/escape-attribute.js +3 -0
  85. package/node_modules/@aws-sdk/xml-builder/dist-es/escape-element.js +12 -0
  86. package/node_modules/@aws-sdk/xml-builder/dist-es/index.js +2 -0
  87. package/node_modules/@aws-sdk/xml-builder/dist-es/stringable.js +1 -0
  88. package/node_modules/@aws-sdk/xml-builder/dist-types/XmlNode.d.ts +49 -0
  89. package/node_modules/@aws-sdk/xml-builder/dist-types/XmlText.d.ts +11 -0
  90. package/node_modules/@aws-sdk/xml-builder/dist-types/escape-attribute.d.ts +6 -0
  91. package/node_modules/@aws-sdk/xml-builder/dist-types/escape-element.d.ts +6 -0
  92. package/node_modules/@aws-sdk/xml-builder/dist-types/index.d.ts +8 -0
  93. package/node_modules/@aws-sdk/xml-builder/dist-types/stringable.d.ts +6 -0
  94. package/node_modules/@aws-sdk/xml-builder/dist-types/ts3.4/XmlNode.d.ts +29 -0
  95. package/node_modules/@aws-sdk/xml-builder/dist-types/ts3.4/XmlText.d.ts +6 -0
  96. package/node_modules/@aws-sdk/xml-builder/dist-types/ts3.4/escape-attribute.d.ts +1 -0
  97. package/node_modules/@aws-sdk/xml-builder/dist-types/ts3.4/escape-element.d.ts +1 -0
  98. package/node_modules/@aws-sdk/xml-builder/dist-types/ts3.4/index.d.ts +2 -0
  99. package/node_modules/@aws-sdk/xml-builder/dist-types/ts3.4/stringable.d.ts +3 -0
  100. package/node_modules/@aws-sdk/xml-builder/package.json +54 -0
  101. package/package.json +5 -5
@@ -0,0 +1,6 @@
1
+ export class SerdeContextConfig {
2
+ serdeContext;
3
+ setSerdeContext(serdeContext) {
4
+ this.serdeContext = serdeContext;
5
+ }
6
+ }
@@ -1,4 +1,17 @@
1
1
  export * from "./coercing-serializers";
2
+ export * from "./json/AwsJson1_0Protocol";
3
+ export * from "./json/AwsJson1_1Protocol";
4
+ export * from "./json/AwsJsonRpcProtocol";
5
+ export * from "./json/AwsRestJsonProtocol";
6
+ export * from "./json/JsonCodec";
7
+ export * from "./json/JsonShapeDeserializer";
8
+ export * from "./json/JsonShapeSerializer";
2
9
  export * from "./json/awsExpectUnion";
3
10
  export * from "./json/parseJsonBody";
11
+ export * from "./query/AwsEc2QueryProtocol";
12
+ export * from "./query/AwsQueryProtocol";
13
+ export * from "./xml/AwsRestXmlProtocol";
14
+ export * from "./xml/XmlCodec";
15
+ export * from "./xml/XmlShapeDeserializer";
16
+ export * from "./xml/XmlShapeSerializer";
4
17
  export * from "./xml/parseXmlBody";
@@ -0,0 +1,14 @@
1
+ import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
2
+ export class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
3
+ constructor({ defaultNamespace }) {
4
+ super({
5
+ defaultNamespace,
6
+ });
7
+ }
8
+ getShapeId() {
9
+ return "aws.protocols#awsJson1_0";
10
+ }
11
+ getJsonRpcVersion() {
12
+ return "1.0";
13
+ }
14
+ }
@@ -0,0 +1,14 @@
1
+ import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
2
+ export class AwsJson1_1Protocol extends AwsJsonRpcProtocol {
3
+ constructor({ defaultNamespace }) {
4
+ super({
5
+ defaultNamespace,
6
+ });
7
+ }
8
+ getShapeId() {
9
+ return "aws.protocols#awsJson1_1";
10
+ }
11
+ getJsonRpcVersion() {
12
+ return "1.1";
13
+ }
14
+ }
@@ -0,0 +1,89 @@
1
+ import { RpcProtocol } from "@smithy/core/protocols";
2
+ import { deref, NormalizedSchema, SCHEMA, TypeRegistry } from "@smithy/core/schema";
3
+ import { calculateBodyLength } from "@smithy/util-body-length-browser";
4
+ import { JsonCodec } from "./JsonCodec";
5
+ import { loadRestJsonErrorCode } from "./parseJsonBody";
6
+ export class AwsJsonRpcProtocol extends RpcProtocol {
7
+ serializer;
8
+ deserializer;
9
+ codec;
10
+ constructor({ defaultNamespace }) {
11
+ super({
12
+ defaultNamespace,
13
+ });
14
+ this.codec = new JsonCodec({
15
+ timestampFormat: {
16
+ useTrait: true,
17
+ default: SCHEMA.TIMESTAMP_EPOCH_SECONDS,
18
+ },
19
+ jsonName: false,
20
+ });
21
+ this.serializer = this.codec.createSerializer();
22
+ this.deserializer = this.codec.createDeserializer();
23
+ }
24
+ async serializeRequest(operationSchema, input, context) {
25
+ const request = await super.serializeRequest(operationSchema, input, context);
26
+ if (!request.path.endsWith("/")) {
27
+ request.path += "/";
28
+ }
29
+ Object.assign(request.headers, {
30
+ "content-type": `application/x-amz-json-${this.getJsonRpcVersion()}`,
31
+ "x-amz-target": (this.getJsonRpcVersion() === "1.0" ? `JsonRpc10.` : `JsonProtocol.`) +
32
+ NormalizedSchema.of(operationSchema).getName(),
33
+ });
34
+ if (deref(operationSchema.input) === "unit" || !request.body) {
35
+ request.body = "{}";
36
+ }
37
+ try {
38
+ request.headers["content-length"] = String(calculateBodyLength(request.body));
39
+ }
40
+ catch (e) { }
41
+ return request;
42
+ }
43
+ getPayloadCodec() {
44
+ return this.codec;
45
+ }
46
+ async handleError(operationSchema, context, response, dataObject, metadata) {
47
+ const errorIdentifier = loadRestJsonErrorCode(response, dataObject) ?? "Unknown";
48
+ let namespace = this.options.defaultNamespace;
49
+ let errorName = errorIdentifier;
50
+ if (errorIdentifier.includes("#")) {
51
+ [namespace, errorName] = errorIdentifier.split("#");
52
+ }
53
+ const registry = TypeRegistry.for(namespace);
54
+ let errorSchema;
55
+ try {
56
+ errorSchema = registry.getSchema(errorIdentifier);
57
+ }
58
+ catch (e) {
59
+ const baseExceptionSchema = TypeRegistry.for("awssdkjs.synthetic." + namespace).getBaseException();
60
+ if (baseExceptionSchema) {
61
+ const ErrorCtor = baseExceptionSchema.ctor;
62
+ throw Object.assign(new ErrorCtor(errorName), dataObject);
63
+ }
64
+ throw new Error(errorName);
65
+ }
66
+ const ns = NormalizedSchema.of(errorSchema);
67
+ const message = dataObject.message ?? dataObject.Message ?? "Unknown";
68
+ const exception = new errorSchema.ctor(message);
69
+ const headerBindings = new Set(Object.values(NormalizedSchema.of(errorSchema).getMemberSchemas())
70
+ .map((schema) => {
71
+ return schema.getMergedTraits().httpHeader;
72
+ })
73
+ .filter(Boolean));
74
+ await this.deserializeHttpMessage(errorSchema, context, response, headerBindings, dataObject);
75
+ const output = {};
76
+ for (const [name, member] of ns.structIterator()) {
77
+ const target = member.getMergedTraits().jsonName ?? name;
78
+ output[name] = this.codec.createDeserializer().readObject(member, dataObject[target]);
79
+ }
80
+ Object.assign(exception, {
81
+ $metadata: metadata,
82
+ $response: response,
83
+ $fault: ns.getMergedTraits().error,
84
+ message,
85
+ ...output,
86
+ });
87
+ throw exception;
88
+ }
89
+ }
@@ -0,0 +1,123 @@
1
+ import { HttpBindingProtocol, HttpInterceptingShapeDeserializer, HttpInterceptingShapeSerializer, } from "@smithy/core/protocols";
2
+ import { NormalizedSchema, SCHEMA, TypeRegistry } from "@smithy/core/schema";
3
+ import { calculateBodyLength } from "@smithy/util-body-length-browser";
4
+ import { JsonCodec } from "./JsonCodec";
5
+ import { loadRestJsonErrorCode } from "./parseJsonBody";
6
+ export class AwsRestJsonProtocol extends HttpBindingProtocol {
7
+ serializer;
8
+ deserializer;
9
+ codec;
10
+ constructor({ defaultNamespace }) {
11
+ super({
12
+ defaultNamespace,
13
+ });
14
+ const settings = {
15
+ timestampFormat: {
16
+ useTrait: true,
17
+ default: SCHEMA.TIMESTAMP_EPOCH_SECONDS,
18
+ },
19
+ httpBindings: true,
20
+ jsonName: true,
21
+ };
22
+ this.codec = new JsonCodec(settings);
23
+ this.serializer = new HttpInterceptingShapeSerializer(this.codec.createSerializer(), settings);
24
+ this.deserializer = new HttpInterceptingShapeDeserializer(this.codec.createDeserializer(), settings);
25
+ }
26
+ getShapeId() {
27
+ return "aws.protocols#restJson1";
28
+ }
29
+ getPayloadCodec() {
30
+ return this.codec;
31
+ }
32
+ setSerdeContext(serdeContext) {
33
+ this.codec.setSerdeContext(serdeContext);
34
+ super.setSerdeContext(serdeContext);
35
+ }
36
+ async serializeRequest(operationSchema, input, context) {
37
+ const request = await super.serializeRequest(operationSchema, input, context);
38
+ const inputSchema = NormalizedSchema.of(operationSchema.input);
39
+ const members = inputSchema.getMemberSchemas();
40
+ if (!request.headers["content-type"]) {
41
+ const httpPayloadMember = Object.values(members).find((m) => {
42
+ return !!m.getMergedTraits().httpPayload;
43
+ });
44
+ if (httpPayloadMember) {
45
+ const mediaType = httpPayloadMember.getMergedTraits().mediaType;
46
+ if (mediaType) {
47
+ request.headers["content-type"] = mediaType;
48
+ }
49
+ else if (httpPayloadMember.isStringSchema()) {
50
+ request.headers["content-type"] = "text/plain";
51
+ }
52
+ else if (httpPayloadMember.isBlobSchema()) {
53
+ request.headers["content-type"] = "application/octet-stream";
54
+ }
55
+ else {
56
+ request.headers["content-type"] = "application/json";
57
+ }
58
+ }
59
+ else if (!inputSchema.isUnitSchema()) {
60
+ const hasBody = Object.values(members).find((m) => {
61
+ const { httpQuery, httpQueryParams, httpHeader, httpLabel, httpPrefixHeaders } = m.getMergedTraits();
62
+ return !httpQuery && !httpQueryParams && !httpHeader && !httpLabel && httpPrefixHeaders === void 0;
63
+ });
64
+ if (hasBody) {
65
+ request.headers["content-type"] = "application/json";
66
+ }
67
+ }
68
+ }
69
+ if (request.headers["content-type"] && !request.body) {
70
+ request.body = "{}";
71
+ }
72
+ if (request.body) {
73
+ try {
74
+ request.headers["content-length"] = String(calculateBodyLength(request.body));
75
+ }
76
+ catch (e) { }
77
+ }
78
+ return request;
79
+ }
80
+ async handleError(operationSchema, context, response, dataObject, metadata) {
81
+ const errorIdentifier = loadRestJsonErrorCode(response, dataObject) ?? "Unknown";
82
+ let namespace = this.options.defaultNamespace;
83
+ let errorName = errorIdentifier;
84
+ if (errorIdentifier.includes("#")) {
85
+ [namespace, errorName] = errorIdentifier.split("#");
86
+ }
87
+ const registry = TypeRegistry.for(namespace);
88
+ let errorSchema;
89
+ try {
90
+ errorSchema = registry.getSchema(errorIdentifier);
91
+ }
92
+ catch (e) {
93
+ const baseExceptionSchema = TypeRegistry.for("awssdkjs.synthetic." + namespace).getBaseException();
94
+ if (baseExceptionSchema) {
95
+ const ErrorCtor = baseExceptionSchema.ctor;
96
+ throw Object.assign(new ErrorCtor(errorName), dataObject);
97
+ }
98
+ throw new Error(errorName);
99
+ }
100
+ const ns = NormalizedSchema.of(errorSchema);
101
+ const message = dataObject.message ?? dataObject.Message ?? "Unknown";
102
+ const exception = new errorSchema.ctor(message);
103
+ const headerBindings = new Set(Object.values(NormalizedSchema.of(errorSchema).getMemberSchemas())
104
+ .map((schema) => {
105
+ return schema.getMergedTraits().httpHeader;
106
+ })
107
+ .filter(Boolean));
108
+ await this.deserializeHttpMessage(errorSchema, context, response, headerBindings, dataObject);
109
+ const output = {};
110
+ for (const [name, member] of ns.structIterator()) {
111
+ const target = member.getMergedTraits().jsonName ?? name;
112
+ output[name] = this.codec.createDeserializer().readObject(member, dataObject[target]);
113
+ }
114
+ Object.assign(exception, {
115
+ $metadata: metadata,
116
+ $response: response,
117
+ $fault: ns.getMergedTraits().error,
118
+ message,
119
+ ...output,
120
+ });
121
+ throw exception;
122
+ }
123
+ }
@@ -0,0 +1,20 @@
1
+ import { SerdeContextConfig } from "../ConfigurableSerdeContext";
2
+ import { JsonShapeDeserializer } from "./JsonShapeDeserializer";
3
+ import { JsonShapeSerializer } from "./JsonShapeSerializer";
4
+ export class JsonCodec extends SerdeContextConfig {
5
+ settings;
6
+ constructor(settings) {
7
+ super();
8
+ this.settings = settings;
9
+ }
10
+ createSerializer() {
11
+ const serializer = new JsonShapeSerializer(this.settings);
12
+ serializer.setSerdeContext(this.serdeContext);
13
+ return serializer;
14
+ }
15
+ createDeserializer() {
16
+ const deserializer = new JsonShapeDeserializer(this.settings);
17
+ deserializer.setSerdeContext(this.serdeContext);
18
+ return deserializer;
19
+ }
20
+ }
@@ -0,0 +1,105 @@
1
+ import { NormalizedSchema, SCHEMA } from "@smithy/core/schema";
2
+ import { LazyJsonString, NumericValue, parseEpochTimestamp, parseRfc3339DateTimeWithOffset, parseRfc7231DateTime, } from "@smithy/core/serde";
3
+ import { fromBase64 } from "@smithy/util-base64";
4
+ import { SerdeContextConfig } from "../ConfigurableSerdeContext";
5
+ import { jsonReviver } from "./jsonReviver";
6
+ import { parseJsonBody } from "./parseJsonBody";
7
+ export class JsonShapeDeserializer extends SerdeContextConfig {
8
+ settings;
9
+ constructor(settings) {
10
+ super();
11
+ this.settings = settings;
12
+ }
13
+ async read(schema, data) {
14
+ return this._read(schema, typeof data === "string" ? JSON.parse(data, jsonReviver) : await parseJsonBody(data, this.serdeContext));
15
+ }
16
+ readObject(schema, data) {
17
+ return this._read(schema, data);
18
+ }
19
+ _read(schema, value) {
20
+ const isObject = value !== null && typeof value === "object";
21
+ const ns = NormalizedSchema.of(schema);
22
+ if (ns.isListSchema() && Array.isArray(value)) {
23
+ const listMember = ns.getValueSchema();
24
+ const out = [];
25
+ const sparse = !!ns.getMergedTraits().sparse;
26
+ for (const item of value) {
27
+ if (sparse || item != null) {
28
+ out.push(this._read(listMember, item));
29
+ }
30
+ }
31
+ return out;
32
+ }
33
+ else if (ns.isMapSchema() && isObject) {
34
+ const mapMember = ns.getValueSchema();
35
+ const out = {};
36
+ const sparse = !!ns.getMergedTraits().sparse;
37
+ for (const [_k, _v] of Object.entries(value)) {
38
+ if (sparse || _v != null) {
39
+ out[_k] = this._read(mapMember, _v);
40
+ }
41
+ }
42
+ return out;
43
+ }
44
+ else if (ns.isStructSchema() && isObject) {
45
+ const out = {};
46
+ for (const [memberName, memberSchema] of ns.structIterator()) {
47
+ const fromKey = this.settings.jsonName ? memberSchema.getMergedTraits().jsonName ?? memberName : memberName;
48
+ const deserializedValue = this._read(memberSchema, value[fromKey]);
49
+ if (deserializedValue != null) {
50
+ out[memberName] = deserializedValue;
51
+ }
52
+ }
53
+ return out;
54
+ }
55
+ if (ns.isBlobSchema() && typeof value === "string") {
56
+ return fromBase64(value);
57
+ }
58
+ const mediaType = ns.getMergedTraits().mediaType;
59
+ if (ns.isStringSchema() && typeof value === "string" && mediaType) {
60
+ const isJson = mediaType === "application/json" || mediaType.endsWith("+json");
61
+ if (isJson) {
62
+ return LazyJsonString.from(value);
63
+ }
64
+ }
65
+ if (ns.isTimestampSchema()) {
66
+ const options = this.settings.timestampFormat;
67
+ const format = options.useTrait
68
+ ? ns.getSchema() === SCHEMA.TIMESTAMP_DEFAULT
69
+ ? options.default
70
+ : ns.getSchema() ?? options.default
71
+ : options.default;
72
+ switch (format) {
73
+ case SCHEMA.TIMESTAMP_DATE_TIME:
74
+ return parseRfc3339DateTimeWithOffset(value);
75
+ case SCHEMA.TIMESTAMP_HTTP_DATE:
76
+ return parseRfc7231DateTime(value);
77
+ case SCHEMA.TIMESTAMP_EPOCH_SECONDS:
78
+ return parseEpochTimestamp(value);
79
+ default:
80
+ console.warn("Missing timestamp format, parsing value with Date constructor:", value);
81
+ return new Date(value);
82
+ }
83
+ }
84
+ if (ns.isBigIntegerSchema() && (typeof value === "number" || typeof value === "string")) {
85
+ return BigInt(value);
86
+ }
87
+ if (ns.isBigDecimalSchema() && value != undefined) {
88
+ if (value instanceof NumericValue) {
89
+ return value;
90
+ }
91
+ return new NumericValue(String(value), "bigDecimal");
92
+ }
93
+ if (ns.isNumericSchema() && typeof value === "string") {
94
+ switch (value) {
95
+ case "Infinity":
96
+ return Infinity;
97
+ case "-Infinity":
98
+ return -Infinity;
99
+ case "NaN":
100
+ return NaN;
101
+ }
102
+ }
103
+ return value;
104
+ }
105
+ }
@@ -0,0 +1,106 @@
1
+ import { NormalizedSchema, SCHEMA } from "@smithy/core/schema";
2
+ import { dateToUtcString } from "@smithy/core/serde";
3
+ import { LazyJsonString } from "@smithy/core/serde";
4
+ import { SerdeContextConfig } from "../ConfigurableSerdeContext";
5
+ import { JsonReplacer } from "./jsonReplacer";
6
+ export class JsonShapeSerializer extends SerdeContextConfig {
7
+ settings;
8
+ buffer;
9
+ rootSchema;
10
+ constructor(settings) {
11
+ super();
12
+ this.settings = settings;
13
+ }
14
+ write(schema, value) {
15
+ this.rootSchema = NormalizedSchema.of(schema);
16
+ this.buffer = this._write(this.rootSchema, value);
17
+ }
18
+ flush() {
19
+ if (this.rootSchema?.isStructSchema() || this.rootSchema?.isDocumentSchema()) {
20
+ const replacer = new JsonReplacer();
21
+ return replacer.replaceInJson(JSON.stringify(this.buffer, replacer.createReplacer(), 0));
22
+ }
23
+ return this.buffer;
24
+ }
25
+ _write(schema, value, container) {
26
+ const isObject = value !== null && typeof value === "object";
27
+ const ns = NormalizedSchema.of(schema);
28
+ if (ns.isListSchema() && Array.isArray(value)) {
29
+ const listMember = ns.getValueSchema();
30
+ const out = [];
31
+ const sparse = !!ns.getMergedTraits().sparse;
32
+ for (const item of value) {
33
+ if (sparse || item != null) {
34
+ out.push(this._write(listMember, item));
35
+ }
36
+ }
37
+ return out;
38
+ }
39
+ else if (ns.isMapSchema() && isObject) {
40
+ const mapMember = ns.getValueSchema();
41
+ const out = {};
42
+ const sparse = !!ns.getMergedTraits().sparse;
43
+ for (const [_k, _v] of Object.entries(value)) {
44
+ if (sparse || _v != null) {
45
+ out[_k] = this._write(mapMember, _v);
46
+ }
47
+ }
48
+ return out;
49
+ }
50
+ else if (ns.isStructSchema() && isObject) {
51
+ const out = {};
52
+ for (const [memberName, memberSchema] of ns.structIterator()) {
53
+ const targetKey = this.settings.jsonName ? memberSchema.getMergedTraits().jsonName ?? memberName : memberName;
54
+ const serializableValue = this._write(memberSchema, value[memberName], ns);
55
+ if (serializableValue !== undefined) {
56
+ out[targetKey] = serializableValue;
57
+ }
58
+ }
59
+ return out;
60
+ }
61
+ if (value === null && container?.isStructSchema()) {
62
+ return void 0;
63
+ }
64
+ if (ns.isBlobSchema() && (value instanceof Uint8Array || typeof value === "string")) {
65
+ if (ns === this.rootSchema) {
66
+ return value;
67
+ }
68
+ if (!this.serdeContext?.base64Encoder) {
69
+ throw new Error("Missing base64Encoder in serdeContext");
70
+ }
71
+ return this.serdeContext?.base64Encoder(value);
72
+ }
73
+ if (ns.isTimestampSchema() && value instanceof Date) {
74
+ const options = this.settings.timestampFormat;
75
+ const format = options.useTrait
76
+ ? ns.getSchema() === SCHEMA.TIMESTAMP_DEFAULT
77
+ ? options.default
78
+ : ns.getSchema() ?? options.default
79
+ : options.default;
80
+ switch (format) {
81
+ case SCHEMA.TIMESTAMP_DATE_TIME:
82
+ return value.toISOString().replace(".000Z", "Z");
83
+ case SCHEMA.TIMESTAMP_HTTP_DATE:
84
+ return dateToUtcString(value);
85
+ case SCHEMA.TIMESTAMP_EPOCH_SECONDS:
86
+ return value.getTime() / 1000;
87
+ default:
88
+ console.warn("Missing timestamp format, using epoch seconds", value);
89
+ return value.getTime() / 1000;
90
+ }
91
+ }
92
+ if (ns.isNumericSchema() && typeof value === "number") {
93
+ if (Math.abs(value) === Infinity || isNaN(value)) {
94
+ return String(value);
95
+ }
96
+ }
97
+ const mediaType = ns.getMergedTraits().mediaType;
98
+ if (ns.isStringSchema() && typeof value === "string" && mediaType) {
99
+ const isJson = mediaType === "application/json" || mediaType.endsWith("+json");
100
+ if (isJson) {
101
+ return LazyJsonString.from(value);
102
+ }
103
+ }
104
+ return value;
105
+ }
106
+ }
@@ -0,0 +1,46 @@
1
+ import { NumericValue } from "@smithy/core/serde";
2
+ const NUMERIC_CONTROL_CHAR = String.fromCharCode(925);
3
+ export class JsonReplacer {
4
+ values = new Map();
5
+ counter = 0;
6
+ stage = 0;
7
+ createReplacer() {
8
+ if (this.stage === 1) {
9
+ throw new Error("@aws-sdk/core/protocols - JsonReplacer already created.");
10
+ }
11
+ if (this.stage === 2) {
12
+ throw new Error("@aws-sdk/core/protocols - JsonReplacer exhausted.");
13
+ }
14
+ this.stage = 1;
15
+ return (key, value) => {
16
+ if (value instanceof NumericValue) {
17
+ const v = `${NUMERIC_CONTROL_CHAR + +"nv" + this.counter++}_` + value.string;
18
+ this.values.set(`"${v}"`, value.string);
19
+ return v;
20
+ }
21
+ if (typeof value === "bigint") {
22
+ const s = value.toString();
23
+ const v = `${NUMERIC_CONTROL_CHAR + "b" + this.counter++}_` + s;
24
+ this.values.set(`"${v}"`, s);
25
+ return v;
26
+ }
27
+ return value;
28
+ };
29
+ }
30
+ replaceInJson(json) {
31
+ if (this.stage === 0) {
32
+ throw new Error("@aws-sdk/core/protocols - JsonReplacer not created yet.");
33
+ }
34
+ if (this.stage === 2) {
35
+ throw new Error("@aws-sdk/core/protocols - JsonReplacer exhausted.");
36
+ }
37
+ this.stage = 2;
38
+ if (this.counter === 0) {
39
+ return json;
40
+ }
41
+ for (const [key, value] of this.values) {
42
+ json = json.replace(key, value);
43
+ }
44
+ return json;
45
+ }
46
+ }
@@ -0,0 +1,18 @@
1
+ import { NumericValue } from "@smithy/core/serde";
2
+ export function jsonReviver(key, value, context) {
3
+ if (context?.source) {
4
+ const numericString = context.source;
5
+ if (typeof value === "number") {
6
+ if (value > Number.MAX_SAFE_INTEGER || value < Number.MIN_SAFE_INTEGER || numericString !== String(value)) {
7
+ const isFractional = numericString.includes(".");
8
+ if (isFractional) {
9
+ return new NumericValue(numericString, "bigDecimal");
10
+ }
11
+ else {
12
+ return BigInt(numericString);
13
+ }
14
+ }
15
+ }
16
+ }
17
+ return value;
18
+ }
@@ -0,0 +1,3 @@
1
+ import { AwsQueryProtocol } from "./AwsQueryProtocol";
2
+ export class AwsEc2QueryProtocol extends AwsQueryProtocol {
3
+ }