@aws-sdk/core 3.977.3 → 3.977.5
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.
- package/dist-cjs/submodules/protocols/index.js +939 -790
- package/dist-es/submodules/protocols/json/AwsJsonRpcProtocol.js +2 -2
- package/dist-es/submodules/protocols/json/AwsRestJsonProtocol.js +3 -3
- package/dist-es/submodules/protocols/json/codec-v1/JsonShapeSerializer.js +5 -2
- package/dist-es/submodules/protocols/json/codec-v2/JsonBytesStringAdapter.js +103 -0
- package/dist-es/submodules/protocols/json/codec-v2/JsonShapeDeserializer2.js +37 -17
- package/dist-es/submodules/protocols/json/codec-v2/JsonShapeSerializer2.js +84 -62
- package/dist-types/submodules/protocols/json/AwsJson1_0Protocol.d.ts +2 -1
- package/dist-types/submodules/protocols/json/AwsJson1_1Protocol.d.ts +2 -1
- package/dist-types/submodules/protocols/json/AwsJsonRpcProtocol.d.ts +4 -3
- package/dist-types/submodules/protocols/json/AwsRestJsonProtocol.d.ts +5 -3
- package/dist-types/submodules/protocols/json/codec-v2/JsonBytesStringAdapter.d.ts +51 -0
- package/dist-types/submodules/protocols/json/codec-v2/JsonCodec2.d.ts +1 -0
- package/dist-types/submodules/protocols/json/codec-v2/JsonShapeDeserializer2.d.ts +1 -0
- package/dist-types/ts3.4/submodules/protocols/json/AwsJson1_0Protocol.d.ts +2 -1
- package/dist-types/ts3.4/submodules/protocols/json/AwsJson1_1Protocol.d.ts +2 -1
- package/dist-types/ts3.4/submodules/protocols/json/AwsJsonRpcProtocol.d.ts +3 -2
- package/dist-types/ts3.4/submodules/protocols/json/AwsRestJsonProtocol.d.ts +4 -1
- package/dist-types/ts3.4/submodules/protocols/json/codec-v2/JsonBytesStringAdapter.d.ts +27 -0
- package/dist-types/ts3.4/submodules/protocols/json/codec-v2/JsonShapeDeserializer2.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RpcProtocol } from "@smithy/core/protocols";
|
|
2
2
|
import { deref, NormalizedSchema } from "@smithy/core/schema";
|
|
3
3
|
import { ProtocolLib } from "../ProtocolLib";
|
|
4
|
-
import {
|
|
4
|
+
import { JsonCodec2 } from "./codec-v2/JsonCodec2";
|
|
5
5
|
import { loadJsonRpcErrorCode } from "./parseJsonBody";
|
|
6
6
|
export class AwsJsonRpcProtocol extends RpcProtocol {
|
|
7
7
|
serializer;
|
|
@@ -18,7 +18,7 @@ export class AwsJsonRpcProtocol extends RpcProtocol {
|
|
|
18
18
|
this.serviceTarget = serviceTarget;
|
|
19
19
|
this.codec =
|
|
20
20
|
jsonCodec ??
|
|
21
|
-
new
|
|
21
|
+
new JsonCodec2({
|
|
22
22
|
timestampFormat: {
|
|
23
23
|
useTrait: true,
|
|
24
24
|
default: 7,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { HttpBindingProtocol, HttpInterceptingShapeDeserializer, HttpInterceptingShapeSerializer, } from "@smithy/core/protocols";
|
|
2
2
|
import { NormalizedSchema } from "@smithy/core/schema";
|
|
3
3
|
import { ProtocolLib } from "../ProtocolLib";
|
|
4
|
-
import {
|
|
4
|
+
import { JsonCodec2 } from "./codec-v2/JsonCodec2";
|
|
5
5
|
import { loadRestJsonErrorCode } from "./parseJsonBody";
|
|
6
6
|
export class AwsRestJsonProtocol extends HttpBindingProtocol {
|
|
7
7
|
serializer;
|
|
8
8
|
deserializer;
|
|
9
9
|
codec;
|
|
10
10
|
mixin = new ProtocolLib();
|
|
11
|
-
constructor({ defaultNamespace, errorTypeRegistries, }) {
|
|
11
|
+
constructor({ defaultNamespace, errorTypeRegistries, jsonCodec, }) {
|
|
12
12
|
super({
|
|
13
13
|
defaultNamespace,
|
|
14
14
|
errorTypeRegistries,
|
|
@@ -21,7 +21,7 @@ export class AwsRestJsonProtocol extends HttpBindingProtocol {
|
|
|
21
21
|
httpBindings: true,
|
|
22
22
|
jsonName: true,
|
|
23
23
|
};
|
|
24
|
-
this.codec = new
|
|
24
|
+
this.codec = jsonCodec ?? new JsonCodec2(settings);
|
|
25
25
|
this.serializer = new HttpInterceptingShapeSerializer(this.codec.createSerializer(), settings);
|
|
26
26
|
this.deserializer = new HttpInterceptingShapeDeserializer(this.codec.createDeserializer(), settings);
|
|
27
27
|
}
|
|
@@ -108,7 +108,7 @@ export class JsonShapeSerializer extends SerdeContextConfig {
|
|
|
108
108
|
}
|
|
109
109
|
return out;
|
|
110
110
|
}
|
|
111
|
-
if (value instanceof Uint8Array &&
|
|
111
|
+
if (value instanceof Uint8Array && ns.isBlobSchema()) {
|
|
112
112
|
if (ns === this.rootSchema) {
|
|
113
113
|
return value;
|
|
114
114
|
}
|
|
@@ -148,7 +148,7 @@ export class JsonShapeSerializer extends SerdeContextConfig {
|
|
|
148
148
|
}
|
|
149
149
|
return value;
|
|
150
150
|
}
|
|
151
|
-
if (typeof value === "number"
|
|
151
|
+
if (typeof value === "number") {
|
|
152
152
|
if (Math.abs(value) === Infinity || isNaN(value)) {
|
|
153
153
|
return String(value);
|
|
154
154
|
}
|
|
@@ -165,6 +165,9 @@ export class JsonShapeSerializer extends SerdeContextConfig {
|
|
|
165
165
|
}
|
|
166
166
|
if (ns.isDocumentSchema()) {
|
|
167
167
|
if (isObject) {
|
|
168
|
+
if (value instanceof Uint8Array) {
|
|
169
|
+
return (this.serdeContext?.base64Encoder ?? toBase64)(value);
|
|
170
|
+
}
|
|
168
171
|
const out = Array.isArray(value) ? [] : {};
|
|
169
172
|
for (const k in value) {
|
|
170
173
|
const v = value[k];
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { toUtf8 } from "@smithy/core/serde";
|
|
2
|
+
export class JsonBytesStringAdapter extends Uint8Array {
|
|
3
|
+
string = null;
|
|
4
|
+
static allocUnsafe(bytes) {
|
|
5
|
+
if (typeof Buffer === "function") {
|
|
6
|
+
const buffer = Buffer.allocUnsafe(bytes);
|
|
7
|
+
return new JsonBytesStringAdapter(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
8
|
+
}
|
|
9
|
+
return new JsonBytesStringAdapter(bytes);
|
|
10
|
+
}
|
|
11
|
+
toString() {
|
|
12
|
+
return this.s();
|
|
13
|
+
}
|
|
14
|
+
valueOf() {
|
|
15
|
+
return this.s();
|
|
16
|
+
}
|
|
17
|
+
includes(searchString, position) {
|
|
18
|
+
if (typeof searchString === "string") {
|
|
19
|
+
return this.s().includes(searchString, position);
|
|
20
|
+
}
|
|
21
|
+
return Uint8Array.prototype.includes.call(this, searchString, position);
|
|
22
|
+
}
|
|
23
|
+
indexOf(searchString, position) {
|
|
24
|
+
if (typeof searchString === "string") {
|
|
25
|
+
return this.s().indexOf(searchString, position);
|
|
26
|
+
}
|
|
27
|
+
return Uint8Array.prototype.indexOf.call(this, searchString, position);
|
|
28
|
+
}
|
|
29
|
+
lastIndexOf(searchString, position) {
|
|
30
|
+
if (typeof searchString === "string") {
|
|
31
|
+
return this.s().lastIndexOf(searchString, position);
|
|
32
|
+
}
|
|
33
|
+
const fn = Uint8Array.prototype.lastIndexOf;
|
|
34
|
+
if (position !== undefined) {
|
|
35
|
+
return fn.call(this, searchString, position);
|
|
36
|
+
}
|
|
37
|
+
return fn.call(this, searchString);
|
|
38
|
+
}
|
|
39
|
+
startsWith(searchString, position) {
|
|
40
|
+
return this.s().startsWith(searchString, position);
|
|
41
|
+
}
|
|
42
|
+
endsWith(searchString, endPosition) {
|
|
43
|
+
return this.s().endsWith(searchString, endPosition);
|
|
44
|
+
}
|
|
45
|
+
match(regexp) {
|
|
46
|
+
return this.s().match(regexp);
|
|
47
|
+
}
|
|
48
|
+
replace(searchValue, replaceValue) {
|
|
49
|
+
return this.s().replace(searchValue, replaceValue);
|
|
50
|
+
}
|
|
51
|
+
search(regexp) {
|
|
52
|
+
return this.s().search(regexp);
|
|
53
|
+
}
|
|
54
|
+
split(separator, limit) {
|
|
55
|
+
return this.s().split(separator, limit);
|
|
56
|
+
}
|
|
57
|
+
substring(start, end) {
|
|
58
|
+
return this.s().substring(start, end);
|
|
59
|
+
}
|
|
60
|
+
trim() {
|
|
61
|
+
return this.s().trim();
|
|
62
|
+
}
|
|
63
|
+
trimStart() {
|
|
64
|
+
return this.s().trimStart();
|
|
65
|
+
}
|
|
66
|
+
trimEnd() {
|
|
67
|
+
return this.s().trimEnd();
|
|
68
|
+
}
|
|
69
|
+
charAt(pos) {
|
|
70
|
+
return this.s().charAt(pos);
|
|
71
|
+
}
|
|
72
|
+
charCodeAt(index) {
|
|
73
|
+
return this.s().charCodeAt(index);
|
|
74
|
+
}
|
|
75
|
+
padStart(maxLength, fillString) {
|
|
76
|
+
return this.s().padStart(maxLength, fillString);
|
|
77
|
+
}
|
|
78
|
+
padEnd(maxLength, fillString) {
|
|
79
|
+
return this.s().padEnd(maxLength, fillString);
|
|
80
|
+
}
|
|
81
|
+
repeat(count) {
|
|
82
|
+
return this.s().repeat(count);
|
|
83
|
+
}
|
|
84
|
+
toUpperCase() {
|
|
85
|
+
return this.s().toUpperCase();
|
|
86
|
+
}
|
|
87
|
+
toLowerCase() {
|
|
88
|
+
return this.s().toLowerCase();
|
|
89
|
+
}
|
|
90
|
+
s() {
|
|
91
|
+
if (this.string == null) {
|
|
92
|
+
const n = Date.now();
|
|
93
|
+
if (n > warned + 60_000) {
|
|
94
|
+
console.warn("@aws-sdk/core/protocols - WARN - JsonCodec2: you have called a string method on a Uint8Array request body. " +
|
|
95
|
+
"It has been automatically converted to string. In a future version this will throw an error.");
|
|
96
|
+
warned = n;
|
|
97
|
+
}
|
|
98
|
+
this.string = toUtf8(this);
|
|
99
|
+
}
|
|
100
|
+
return this.string;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
var warned = 0;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { determineTimestampFormat } from "@smithy/core/protocols";
|
|
2
2
|
import { NormalizedSchema } from "@smithy/core/schema";
|
|
3
|
-
import { LazyJsonString, NumericValue, parseEpochTimestamp, parseRfc3339DateTimeWithOffset, parseRfc7231DateTime, } from "@smithy/core/serde";
|
|
4
|
-
import { fromBase64 } from "@smithy/core/serde";
|
|
3
|
+
import { fromBase64, LazyJsonString, NumericValue, parseEpochTimestamp, parseRfc3339DateTimeWithOffset, parseRfc7231DateTime, } from "@smithy/core/serde";
|
|
5
4
|
import { SerdeContextConfig } from "../../ConfigurableSerdeContext";
|
|
6
5
|
import { UnionSerde } from "../../UnionSerde";
|
|
7
6
|
import { detectBufferParsing } from "../detectBufferParsing";
|
|
@@ -19,14 +18,20 @@ export class JsonShapeDeserializer2 extends SerdeContextConfig {
|
|
|
19
18
|
const reviver = needsReviver(schema) ? jsonReviver : undefined;
|
|
20
19
|
let parsed;
|
|
21
20
|
if (typeof data === "string") {
|
|
21
|
+
if (data.length === 0) {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
22
24
|
parsed = JSON.parse(data, reviver);
|
|
23
25
|
}
|
|
24
26
|
else if (data instanceof Uint8Array && detectBufferParsing()) {
|
|
27
|
+
if (data.byteLength === 0) {
|
|
28
|
+
return {};
|
|
29
|
+
}
|
|
25
30
|
const buf = Buffer.isBuffer(data) ? data : Buffer.from(data.buffer, data.byteOffset, data.byteLength);
|
|
26
31
|
parsed = JSON.parse(buf, reviver);
|
|
27
32
|
}
|
|
28
33
|
else {
|
|
29
|
-
parsed = await parseJsonBody(data, this.serdeContext);
|
|
34
|
+
parsed = await parseJsonBody(data, this.serdeContext, schema);
|
|
30
35
|
}
|
|
31
36
|
return this._read(schema, parsed);
|
|
32
37
|
}
|
|
@@ -42,19 +47,23 @@ export class JsonShapeDeserializer2 extends SerdeContextConfig {
|
|
|
42
47
|
}
|
|
43
48
|
if (Array.isArray(value) && ns.isListSchema()) {
|
|
44
49
|
const listMember = ns.getValueSchema();
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
if (this.needsTransform(listMember)) {
|
|
51
|
+
for (let i = 0; i < value.length; ++i) {
|
|
52
|
+
value[i] = this._read(listMember, value[i]);
|
|
53
|
+
}
|
|
47
54
|
}
|
|
48
55
|
return value;
|
|
49
56
|
}
|
|
50
57
|
if (ns.isMapSchema()) {
|
|
51
58
|
const mapMember = ns.getValueSchema();
|
|
52
59
|
const map = value;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
60
|
+
if (this.needsTransform(mapMember)) {
|
|
61
|
+
for (const k in map) {
|
|
62
|
+
if (k === "__proto__") {
|
|
63
|
+
writeKey(map);
|
|
64
|
+
}
|
|
65
|
+
map[k] = this._read(mapMember, map[k]);
|
|
56
66
|
}
|
|
57
|
-
map[k] = this._read(mapMember, map[k]);
|
|
58
67
|
}
|
|
59
68
|
return map;
|
|
60
69
|
}
|
|
@@ -130,10 +139,6 @@ export class JsonShapeDeserializer2 extends SerdeContextConfig {
|
|
|
130
139
|
}
|
|
131
140
|
}
|
|
132
141
|
}
|
|
133
|
-
return value;
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
return value;
|
|
137
142
|
}
|
|
138
143
|
}
|
|
139
144
|
return value;
|
|
@@ -141,9 +146,10 @@ export class JsonShapeDeserializer2 extends SerdeContextConfig {
|
|
|
141
146
|
_readStruct(ns, record) {
|
|
142
147
|
const union = ns.isUnionSchema();
|
|
143
148
|
const out = {};
|
|
144
|
-
let nameMap
|
|
149
|
+
let nameMap;
|
|
150
|
+
const hasType = typeof record.__type === "string";
|
|
145
151
|
const { jsonName } = this.settings;
|
|
146
|
-
if (jsonName) {
|
|
152
|
+
if (jsonName && hasType) {
|
|
147
153
|
nameMap = {};
|
|
148
154
|
}
|
|
149
155
|
let unionSerde;
|
|
@@ -154,7 +160,9 @@ export class JsonShapeDeserializer2 extends SerdeContextConfig {
|
|
|
154
160
|
let fromKey = memberName;
|
|
155
161
|
if (jsonName) {
|
|
156
162
|
fromKey = memberSchema.getMergedTraits().jsonName ?? fromKey;
|
|
157
|
-
|
|
163
|
+
if (hasType) {
|
|
164
|
+
nameMap[fromKey] = memberName;
|
|
165
|
+
}
|
|
158
166
|
}
|
|
159
167
|
if (union) {
|
|
160
168
|
unionSerde.mark(fromKey);
|
|
@@ -166,7 +174,7 @@ export class JsonShapeDeserializer2 extends SerdeContextConfig {
|
|
|
166
174
|
if (union) {
|
|
167
175
|
unionSerde.writeUnknown();
|
|
168
176
|
}
|
|
169
|
-
else if (
|
|
177
|
+
else if (hasType) {
|
|
170
178
|
for (const k in record) {
|
|
171
179
|
const v = record[k];
|
|
172
180
|
const t = jsonName ? (nameMap[k] ?? k) : k;
|
|
@@ -177,4 +185,16 @@ export class JsonShapeDeserializer2 extends SerdeContextConfig {
|
|
|
177
185
|
}
|
|
178
186
|
return out;
|
|
179
187
|
}
|
|
188
|
+
needsTransform(ns) {
|
|
189
|
+
if (ns.isBlobSchema() || ns.isTimestampSchema() || ns.isBigIntegerSchema() || ns.isBigDecimalSchema()) {
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
if (ns.isDocumentSchema() || ns.isStructSchema() || ns.isListSchema() || ns.isMapSchema()) {
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
if (ns.isStringSchema() && ns.getMergedTraits().mediaType) {
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
180
200
|
}
|
|
@@ -2,7 +2,7 @@ import { determineTimestampFormat } from "@smithy/core/protocols";
|
|
|
2
2
|
import { NormalizedSchema } from "@smithy/core/schema";
|
|
3
3
|
import { dateToUtcString, generateIdempotencyToken, LazyJsonString, NumericValue, toBase64 } from "@smithy/core/serde";
|
|
4
4
|
import { SerdeContextConfig } from "../../ConfigurableSerdeContext";
|
|
5
|
-
import {
|
|
5
|
+
import { JsonBytesStringAdapter } from "./JsonBytesStringAdapter";
|
|
6
6
|
const encoder = new TextEncoder();
|
|
7
7
|
const OPEN_BRACE = 0x7b;
|
|
8
8
|
const CLOSE_BRACE = 0x7d;
|
|
@@ -30,7 +30,7 @@ for (let i = 0; i < 0x20; i++) {
|
|
|
30
30
|
}
|
|
31
31
|
const INITIAL_BUFFER_SIZE = 2048;
|
|
32
32
|
function alloc(size) {
|
|
33
|
-
return
|
|
33
|
+
return JsonBytesStringAdapter.allocUnsafe(size);
|
|
34
34
|
}
|
|
35
35
|
export class JsonShapeSerializer2 extends SerdeContextConfig {
|
|
36
36
|
settings;
|
|
@@ -48,10 +48,7 @@ export class JsonShapeSerializer2 extends SerdeContextConfig {
|
|
|
48
48
|
this.i = 0;
|
|
49
49
|
this.rawValue = value;
|
|
50
50
|
this.rootSchema = NormalizedSchema.of(schema);
|
|
51
|
-
this.passthrough =
|
|
52
|
-
!this.rootSchema.isStructSchema() &&
|
|
53
|
-
!this.rootSchema.isDocumentSchema() &&
|
|
54
|
-
(this.rootSchema.isBlobSchema() || this.rootSchema.isStringSchema());
|
|
51
|
+
this.passthrough = this.rootSchema.isBlobSchema() || this.rootSchema.isStringSchema();
|
|
55
52
|
if (!this.passthrough) {
|
|
56
53
|
this.writeValue(this.rootSchema, value, undefined);
|
|
57
54
|
}
|
|
@@ -61,30 +58,13 @@ export class JsonShapeSerializer2 extends SerdeContextConfig {
|
|
|
61
58
|
this.rootSchema = NormalizedSchema.of(schema);
|
|
62
59
|
const ns = this.rootSchema;
|
|
63
60
|
if (ns.isStructSchema() && value != null && typeof value === "object") {
|
|
64
|
-
this.
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
this.
|
|
68
|
-
this.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
for (const [memberName, memberSchema] of ns.structIterator()) {
|
|
72
|
-
const item = value[memberName];
|
|
73
|
-
if (item == null && !memberSchema.isIdempotencyToken()) {
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
if (wroteAny) {
|
|
77
|
-
this.ensure(1);
|
|
78
|
-
this.json[this.i++] = COMMA;
|
|
79
|
-
}
|
|
80
|
-
const targetKey = jsonName ? (memberSchema.getMergedTraits().jsonName ?? memberName) : memberName;
|
|
81
|
-
this.writeAsciiQuoted(targetKey);
|
|
82
|
-
this.json[this.i++] = COLON;
|
|
83
|
-
this.writeValue(memberSchema, item, ns);
|
|
84
|
-
wroteAny = true;
|
|
85
|
-
}
|
|
86
|
-
this.ensure(1);
|
|
87
|
-
this.json[this.i++] = CLOSE_BRACE;
|
|
61
|
+
this.writeValue(ns, value, undefined);
|
|
62
|
+
const prefix = `"__type":"${ns.getName(true) ?? "Unknown"}",`;
|
|
63
|
+
const z = prefix.length;
|
|
64
|
+
this.ensure(z);
|
|
65
|
+
this.json.copyWithin(1 + z, 1, this.i);
|
|
66
|
+
encoder.encodeInto(prefix, this.json.subarray(1));
|
|
67
|
+
this.i += z;
|
|
88
68
|
}
|
|
89
69
|
else {
|
|
90
70
|
this.writeValue(ns, value, undefined);
|
|
@@ -137,7 +117,7 @@ export class JsonShapeSerializer2 extends SerdeContextConfig {
|
|
|
137
117
|
this.i = i;
|
|
138
118
|
}
|
|
139
119
|
writeJsonString(s) {
|
|
140
|
-
this.ensure(s.length *
|
|
120
|
+
this.ensure(s.length * 3 + 2);
|
|
141
121
|
this.json[this.i++] = QUOTE;
|
|
142
122
|
const z = s.length;
|
|
143
123
|
for (let j = 0; j < z; ++j) {
|
|
@@ -164,7 +144,7 @@ export class JsonShapeSerializer2 extends SerdeContextConfig {
|
|
|
164
144
|
this.ensure(4);
|
|
165
145
|
const { written } = encoder.encodeInto(s.substring(j, j + 2), this.json.subarray(this.i));
|
|
166
146
|
this.i += written;
|
|
167
|
-
j
|
|
147
|
+
++j;
|
|
168
148
|
}
|
|
169
149
|
else {
|
|
170
150
|
this.ensure(6);
|
|
@@ -204,8 +184,9 @@ export class JsonShapeSerializer2 extends SerdeContextConfig {
|
|
|
204
184
|
static B64 = (() => {
|
|
205
185
|
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
206
186
|
const table = new Uint8Array(64);
|
|
207
|
-
for (let i = 0; i < 64; i
|
|
187
|
+
for (let i = 0; i < 64; ++i) {
|
|
208
188
|
table[i] = chars.charCodeAt(i);
|
|
189
|
+
}
|
|
209
190
|
return table;
|
|
210
191
|
})();
|
|
211
192
|
writeBase64(data) {
|
|
@@ -322,7 +303,7 @@ export class JsonShapeSerializer2 extends SerdeContextConfig {
|
|
|
322
303
|
return;
|
|
323
304
|
}
|
|
324
305
|
if (typeof value === "number") {
|
|
325
|
-
if (
|
|
306
|
+
if (Math.abs(value) === Infinity || Number.isNaN(value)) {
|
|
326
307
|
this.writeAsciiQuoted(String(value));
|
|
327
308
|
return;
|
|
328
309
|
}
|
|
@@ -332,14 +313,16 @@ export class JsonShapeSerializer2 extends SerdeContextConfig {
|
|
|
332
313
|
}
|
|
333
314
|
if (typeof value === "boolean") {
|
|
334
315
|
this.ensure(5);
|
|
316
|
+
let { i, json } = this;
|
|
335
317
|
if (value) {
|
|
336
|
-
|
|
337
|
-
|
|
318
|
+
json.set(TRUE, i);
|
|
319
|
+
i += 4;
|
|
338
320
|
}
|
|
339
321
|
else {
|
|
340
|
-
|
|
341
|
-
|
|
322
|
+
json.set(FALSE, i);
|
|
323
|
+
i += 5;
|
|
342
324
|
}
|
|
325
|
+
this.i = i;
|
|
343
326
|
return;
|
|
344
327
|
}
|
|
345
328
|
if (typeof value === "bigint") {
|
|
@@ -351,7 +334,6 @@ export class JsonShapeSerializer2 extends SerdeContextConfig {
|
|
|
351
334
|
writeStruct(ns, value) {
|
|
352
335
|
this.ensure(2);
|
|
353
336
|
this.json[this.i++] = OPEN_BRACE;
|
|
354
|
-
let first = true;
|
|
355
337
|
let wroteAny = false;
|
|
356
338
|
const hasType = typeof value.__type === "string";
|
|
357
339
|
let writtenKeys;
|
|
@@ -360,13 +342,13 @@ export class JsonShapeSerializer2 extends SerdeContextConfig {
|
|
|
360
342
|
}
|
|
361
343
|
for (const [memberName, memberSchema] of ns.structIterator()) {
|
|
362
344
|
const item = value[memberName];
|
|
363
|
-
if (item == null && !memberSchema.isIdempotencyToken())
|
|
345
|
+
if (item == null && !memberSchema.isIdempotencyToken()) {
|
|
364
346
|
continue;
|
|
365
|
-
|
|
347
|
+
}
|
|
348
|
+
if (wroteAny) {
|
|
366
349
|
this.ensure(1);
|
|
367
350
|
this.json[this.i++] = COMMA;
|
|
368
351
|
}
|
|
369
|
-
first = false;
|
|
370
352
|
wroteAny = true;
|
|
371
353
|
const targetKey = this.settings.jsonName ? (memberSchema.getMergedTraits().jsonName ?? memberName) : memberName;
|
|
372
354
|
if (writtenKeys) {
|
|
@@ -389,17 +371,17 @@ export class JsonShapeSerializer2 extends SerdeContextConfig {
|
|
|
389
371
|
}
|
|
390
372
|
else if (hasType) {
|
|
391
373
|
for (const k in value) {
|
|
392
|
-
|
|
393
|
-
if (writtenKeys.has(targetKey))
|
|
374
|
+
if (writtenKeys.has(k)) {
|
|
394
375
|
continue;
|
|
395
|
-
|
|
376
|
+
}
|
|
377
|
+
writtenKeys.add(k);
|
|
396
378
|
const v = value[k];
|
|
397
|
-
if (
|
|
379
|
+
if (wroteAny) {
|
|
398
380
|
this.ensure(1);
|
|
399
381
|
this.json[this.i++] = COMMA;
|
|
400
382
|
}
|
|
401
|
-
|
|
402
|
-
this.writeAsciiQuoted(
|
|
383
|
+
wroteAny = true;
|
|
384
|
+
this.writeAsciiQuoted(k);
|
|
403
385
|
this.ensure(1);
|
|
404
386
|
this.json[this.i++] = COLON;
|
|
405
387
|
this.writeValue(15, v, undefined);
|
|
@@ -409,20 +391,56 @@ export class JsonShapeSerializer2 extends SerdeContextConfig {
|
|
|
409
391
|
this.json[this.i++] = CLOSE_BRACE;
|
|
410
392
|
}
|
|
411
393
|
writeList(ns, value, isDocument) {
|
|
412
|
-
this.ensure(2);
|
|
413
|
-
this.json[this.i++] = OPEN_BRACKET;
|
|
414
394
|
const sparse = !!ns.getMergedTraits().sparse;
|
|
415
395
|
const valueSchema = ns.getValueSchema();
|
|
396
|
+
if (!isDocument) {
|
|
397
|
+
if (valueSchema.isStringSchema() || valueSchema.isNumericSchema() || valueSchema.isBooleanSchema()) {
|
|
398
|
+
let hasSpecials = false;
|
|
399
|
+
for (let i = 0; i < value.length; ++i) {
|
|
400
|
+
const v = value[i];
|
|
401
|
+
if (Number.isNaN(v) || v === Infinity || v === -Infinity || (v == null && !sparse)) {
|
|
402
|
+
hasSpecials = true;
|
|
403
|
+
break;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
let json;
|
|
407
|
+
if (!hasSpecials) {
|
|
408
|
+
json = JSON.stringify(value);
|
|
409
|
+
}
|
|
410
|
+
else {
|
|
411
|
+
const out = [];
|
|
412
|
+
for (let i = 0; i < value.length; ++i) {
|
|
413
|
+
const v = value[i];
|
|
414
|
+
if (v == null && !sparse)
|
|
415
|
+
continue;
|
|
416
|
+
if (Number.isNaN(v) || v === Infinity || v === -Infinity) {
|
|
417
|
+
out.push(String(v));
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
out.push(v);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
json = JSON.stringify(out);
|
|
424
|
+
}
|
|
425
|
+
this.ensure(json.length * 3);
|
|
426
|
+
this.i += encoder.encodeInto(json, this.json.subarray(this.i)).written;
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
this.ensure(2);
|
|
431
|
+
this.json[this.i++] = OPEN_BRACKET;
|
|
432
|
+
let wroteFirstItem = false;
|
|
416
433
|
for (let i = 0; i < value.length; ++i) {
|
|
417
434
|
const item = value[i];
|
|
418
435
|
if (isDocument ? item === undefined : item == null && !sparse) {
|
|
419
436
|
continue;
|
|
420
437
|
}
|
|
421
|
-
if (
|
|
438
|
+
if (wroteFirstItem) {
|
|
422
439
|
this.ensure(1);
|
|
423
440
|
this.json[this.i++] = COMMA;
|
|
424
441
|
}
|
|
425
442
|
this.writeValue(valueSchema, item, undefined);
|
|
443
|
+
wroteFirstItem = true;
|
|
426
444
|
}
|
|
427
445
|
this.ensure(1);
|
|
428
446
|
this.json[this.i++] = CLOSE_BRACKET;
|
|
@@ -432,20 +450,24 @@ export class JsonShapeSerializer2 extends SerdeContextConfig {
|
|
|
432
450
|
const valueSchema = ns.getValueSchema();
|
|
433
451
|
if (!isDocument) {
|
|
434
452
|
if (valueSchema.isStringSchema() || valueSchema.isNumericSchema() || valueSchema.isBooleanSchema()) {
|
|
435
|
-
let
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
}
|
|
442
|
-
input[k] = value[k] ?? null;
|
|
453
|
+
let modifications;
|
|
454
|
+
for (const k in value) {
|
|
455
|
+
const v = value[k];
|
|
456
|
+
if (Number.isNaN(v) || v === Infinity || v === -Infinity) {
|
|
457
|
+
(modifications ??= {})[k] = v;
|
|
458
|
+
value[k] = String(v);
|
|
443
459
|
}
|
|
460
|
+
else if (v === null && !sparse) {
|
|
461
|
+
(modifications ??= {})[k] = null;
|
|
462
|
+
value[k] = undefined;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
const json = JSON.stringify(value);
|
|
466
|
+
if (modifications) {
|
|
467
|
+
Object.assign(value, modifications);
|
|
444
468
|
}
|
|
445
|
-
const json = JSON.stringify(input);
|
|
446
469
|
this.ensure(json.length * 3);
|
|
447
|
-
|
|
448
|
-
this.i += written;
|
|
470
|
+
this.i += encoder.encodeInto(json, this.json.subarray(this.i)).written;
|
|
449
471
|
return;
|
|
450
472
|
}
|
|
451
473
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { TypeRegistry } from "@smithy/core/schema";
|
|
2
2
|
import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
|
|
3
3
|
import type { JsonCodec } from "./codec-v1/JsonCodec";
|
|
4
|
+
import type { JsonCodec2 } from "./codec-v2/JsonCodec2";
|
|
4
5
|
/**
|
|
5
6
|
* @public
|
|
6
7
|
* @see https://smithy.io/2.0/aws/protocols/aws-json-1_1-protocol.html#differences-between-awsjson1-0-and-awsjson1-1
|
|
@@ -11,7 +12,7 @@ export declare class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
|
|
|
11
12
|
errorTypeRegistries?: TypeRegistry[];
|
|
12
13
|
serviceTarget: string;
|
|
13
14
|
awsQueryCompatible?: boolean;
|
|
14
|
-
jsonCodec?: JsonCodec;
|
|
15
|
+
jsonCodec?: JsonCodec | JsonCodec2;
|
|
15
16
|
});
|
|
16
17
|
getShapeId(): string;
|
|
17
18
|
protected getJsonRpcVersion(): "1.0";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { TypeRegistry } from "@smithy/core/schema";
|
|
2
2
|
import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
|
|
3
3
|
import type { JsonCodec } from "./codec-v1/JsonCodec";
|
|
4
|
+
import type { JsonCodec2 } from "./codec-v2/JsonCodec2";
|
|
4
5
|
/**
|
|
5
6
|
* @public
|
|
6
7
|
* @see https://smithy.io/2.0/aws/protocols/aws-json-1_1-protocol.html#differences-between-awsjson1-0-and-awsjson1-1
|
|
@@ -11,7 +12,7 @@ export declare class AwsJson1_1Protocol extends AwsJsonRpcProtocol {
|
|
|
11
12
|
errorTypeRegistries?: TypeRegistry[];
|
|
12
13
|
serviceTarget: string;
|
|
13
14
|
awsQueryCompatible?: boolean;
|
|
14
|
-
jsonCodec?: JsonCodec;
|
|
15
|
+
jsonCodec?: JsonCodec | JsonCodec2;
|
|
15
16
|
});
|
|
16
17
|
getShapeId(): string;
|
|
17
18
|
protected getJsonRpcVersion(): "1.1";
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { RpcProtocol } from "@smithy/core/protocols";
|
|
2
2
|
import type { TypeRegistry } from "@smithy/core/schema";
|
|
3
3
|
import type { EndpointBearer, HandlerExecutionContext, HttpRequest, HttpResponse, OperationSchema, ResponseMetadata, SerdeFunctions, ShapeDeserializer, ShapeSerializer } from "@smithy/types";
|
|
4
|
-
import { JsonCodec } from "./codec-v1/JsonCodec";
|
|
4
|
+
import type { JsonCodec } from "./codec-v1/JsonCodec";
|
|
5
|
+
import { JsonCodec2 } from "./codec-v2/JsonCodec2";
|
|
5
6
|
/**
|
|
6
7
|
* @public
|
|
7
8
|
*/
|
|
@@ -17,10 +18,10 @@ export declare abstract class AwsJsonRpcProtocol extends RpcProtocol {
|
|
|
17
18
|
errorTypeRegistries?: TypeRegistry[];
|
|
18
19
|
serviceTarget: string;
|
|
19
20
|
awsQueryCompatible?: boolean;
|
|
20
|
-
jsonCodec?: JsonCodec;
|
|
21
|
+
jsonCodec?: JsonCodec | JsonCodec2;
|
|
21
22
|
});
|
|
22
23
|
serializeRequest<Input extends object>(operationSchema: OperationSchema, input: Input, context: HandlerExecutionContext & SerdeFunctions & EndpointBearer): Promise<HttpRequest>;
|
|
23
|
-
getPayloadCodec(): JsonCodec;
|
|
24
|
+
getPayloadCodec(): JsonCodec | JsonCodec2;
|
|
24
25
|
protected abstract getJsonRpcVersion(): "1.1" | "1.0";
|
|
25
26
|
/**
|
|
26
27
|
* @override
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { HttpBindingProtocol } from "@smithy/core/protocols";
|
|
2
2
|
import type { TypeRegistry } from "@smithy/core/schema";
|
|
3
3
|
import type { EndpointBearer, HandlerExecutionContext, HttpRequest, HttpResponse, MetadataBearer, OperationSchema, ResponseMetadata, SerdeFunctions, ShapeDeserializer, ShapeSerializer } from "@smithy/types";
|
|
4
|
-
import { JsonCodec } from "./codec-v1/JsonCodec";
|
|
4
|
+
import type { JsonCodec } from "./codec-v1/JsonCodec";
|
|
5
|
+
import { JsonCodec2 } from "./codec-v2/JsonCodec2";
|
|
5
6
|
/**
|
|
6
7
|
* @public
|
|
7
8
|
*/
|
|
@@ -10,12 +11,13 @@ export declare class AwsRestJsonProtocol extends HttpBindingProtocol {
|
|
|
10
11
|
protected deserializer: ShapeDeserializer<string | Uint8Array>;
|
|
11
12
|
private readonly codec;
|
|
12
13
|
private readonly mixin;
|
|
13
|
-
constructor({ defaultNamespace, errorTypeRegistries, }: {
|
|
14
|
+
constructor({ defaultNamespace, errorTypeRegistries, jsonCodec, }: {
|
|
14
15
|
defaultNamespace: string;
|
|
15
16
|
errorTypeRegistries?: TypeRegistry[];
|
|
17
|
+
jsonCodec?: JsonCodec | JsonCodec2;
|
|
16
18
|
});
|
|
17
19
|
getShapeId(): string;
|
|
18
|
-
getPayloadCodec(): JsonCodec;
|
|
20
|
+
getPayloadCodec(): JsonCodec | JsonCodec2;
|
|
19
21
|
setSerdeContext(serdeContext: SerdeFunctions): void;
|
|
20
22
|
/**
|
|
21
23
|
* @override
|