@aws-sdk/core 3.977.2 → 3.977.3
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 +741 -57
- package/dist-es/submodules/protocols/index.js +6 -3
- package/dist-es/submodules/protocols/json/AwsJsonRpcProtocol.js +1 -1
- package/dist-es/submodules/protocols/json/AwsRestJsonProtocol.js +1 -1
- package/dist-es/submodules/protocols/json/JsonSettings.js +1 -0
- package/dist-es/submodules/protocols/json/{JsonCodec.js → codec-v1/JsonCodec.js} +3 -3
- package/dist-es/submodules/protocols/json/codec-v1/JsonSettings.js +1 -0
- package/dist-es/submodules/protocols/json/codec-v2/JsonCodec2.js +20 -0
- package/dist-es/submodules/protocols/json/codec-v2/{BufferJsonShapeDeserializer.js → JsonShapeDeserializer2.js} +1 -1
- package/dist-es/submodules/protocols/json/codec-v2/{ByteJsonShapeSerializer.js → JsonShapeSerializer2.js} +28 -32
- package/dist-types/submodules/protocols/index.d.ts +7 -4
- package/dist-types/submodules/protocols/json/AwsJson1_0Protocol.d.ts +1 -1
- package/dist-types/submodules/protocols/json/AwsJson1_1Protocol.d.ts +1 -1
- package/dist-types/submodules/protocols/json/AwsJsonRpcProtocol.d.ts +1 -1
- package/dist-types/submodules/protocols/json/AwsRestJsonProtocol.d.ts +1 -1
- package/dist-types/submodules/protocols/json/JsonSettings.d.ts +7 -0
- package/dist-types/submodules/protocols/json/codec-v1/JsonCodec.d.ts +15 -0
- package/dist-types/submodules/protocols/json/codec-v1/JsonSettings.d.ts +7 -0
- package/dist-types/submodules/protocols/json/codec-v1/JsonShapeDeserializer.d.ts +2 -1
- package/dist-types/submodules/protocols/json/codec-v1/JsonShapeSerializer.d.ts +2 -1
- package/dist-types/submodules/protocols/json/codec-v2/JsonCodec2.d.ts +12 -0
- package/dist-types/submodules/protocols/json/codec-v2/{BufferJsonShapeDeserializer.d.ts → JsonShapeDeserializer2.d.ts} +3 -3
- package/dist-types/submodules/protocols/json/codec-v2/{ByteJsonShapeSerializer.d.ts → JsonShapeSerializer2.d.ts} +19 -31
- package/dist-types/ts3.4/submodules/protocols/index.d.ts +7 -4
- package/dist-types/ts3.4/submodules/protocols/json/AwsJson1_0Protocol.d.ts +1 -1
- package/dist-types/ts3.4/submodules/protocols/json/AwsJson1_1Protocol.d.ts +1 -1
- package/dist-types/ts3.4/submodules/protocols/json/AwsJsonRpcProtocol.d.ts +1 -1
- package/dist-types/ts3.4/submodules/protocols/json/AwsRestJsonProtocol.d.ts +1 -1
- package/dist-types/ts3.4/submodules/protocols/json/JsonSettings.d.ts +4 -0
- package/dist-types/ts3.4/submodules/protocols/json/codec-v1/JsonCodec.d.ts +11 -0
- package/dist-types/ts3.4/submodules/protocols/json/codec-v1/JsonSettings.d.ts +4 -0
- package/dist-types/ts3.4/submodules/protocols/json/codec-v1/JsonShapeDeserializer.d.ts +1 -1
- package/dist-types/ts3.4/submodules/protocols/json/codec-v1/JsonShapeSerializer.d.ts +1 -1
- package/dist-types/ts3.4/submodules/protocols/json/codec-v2/JsonCodec2.d.ts +9 -0
- package/dist-types/ts3.4/submodules/protocols/json/codec-v2/{BufferJsonShapeDeserializer.d.ts → JsonShapeDeserializer2.d.ts} +2 -2
- package/dist-types/ts3.4/submodules/protocols/json/codec-v2/JsonShapeSerializer2.d.ts +39 -0
- package/package.json +3 -3
- package/dist-types/submodules/protocols/json/JsonCodec.d.ts +0 -19
- package/dist-types/ts3.4/submodules/protocols/json/JsonCodec.d.ts +0 -13
- package/dist-types/ts3.4/submodules/protocols/json/codec-v2/ByteJsonShapeSerializer.d.ts +0 -39
|
@@ -193,56 +193,6 @@ class AwsSmithyRpcV2CborProtocol extends SmithyRpcV2CborProtocol {
|
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
const _toStr = (val) => {
|
|
197
|
-
if (val == null) {
|
|
198
|
-
return val;
|
|
199
|
-
}
|
|
200
|
-
if (typeof val === "number" || typeof val === "bigint") {
|
|
201
|
-
const warning = new Error(`Received number ${val} where a string was expected.`);
|
|
202
|
-
warning.name = "Warning";
|
|
203
|
-
console.warn(warning);
|
|
204
|
-
return String(val);
|
|
205
|
-
}
|
|
206
|
-
if (typeof val === "boolean") {
|
|
207
|
-
const warning = new Error(`Received boolean ${val} where a string was expected.`);
|
|
208
|
-
warning.name = "Warning";
|
|
209
|
-
console.warn(warning);
|
|
210
|
-
return String(val);
|
|
211
|
-
}
|
|
212
|
-
return val;
|
|
213
|
-
};
|
|
214
|
-
const _toBool = (val) => {
|
|
215
|
-
if (val == null) {
|
|
216
|
-
return val;
|
|
217
|
-
}
|
|
218
|
-
if (typeof val === "string") {
|
|
219
|
-
const lowercase = val.toLowerCase();
|
|
220
|
-
if (val !== "" && lowercase !== "false" && lowercase !== "true") {
|
|
221
|
-
const warning = new Error(`Received string "${val}" where a boolean was expected.`);
|
|
222
|
-
warning.name = "Warning";
|
|
223
|
-
console.warn(warning);
|
|
224
|
-
}
|
|
225
|
-
return val !== "" && lowercase !== "false";
|
|
226
|
-
}
|
|
227
|
-
return val;
|
|
228
|
-
};
|
|
229
|
-
const _toNum = (val) => {
|
|
230
|
-
if (val == null) {
|
|
231
|
-
return val;
|
|
232
|
-
}
|
|
233
|
-
if (typeof val === "string") {
|
|
234
|
-
const num = Number(val);
|
|
235
|
-
if (num.toString() !== val) {
|
|
236
|
-
const warning = new Error(`Received string "${val}" where a number was expected.`);
|
|
237
|
-
warning.name = "Warning";
|
|
238
|
-
console.warn(warning);
|
|
239
|
-
return val;
|
|
240
|
-
}
|
|
241
|
-
return num;
|
|
242
|
-
}
|
|
243
|
-
return val;
|
|
244
|
-
};
|
|
245
|
-
|
|
246
196
|
class SerdeContextConfig {
|
|
247
197
|
serdeContext;
|
|
248
198
|
setSerdeContext(serdeContext) {
|
|
@@ -1062,15 +1012,686 @@ class AwsRestJsonProtocol extends HttpBindingProtocol {
|
|
|
1062
1012
|
}
|
|
1063
1013
|
}
|
|
1064
1014
|
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1015
|
+
class JsonShapeDeserializer2 extends SerdeContextConfig {
|
|
1016
|
+
settings;
|
|
1017
|
+
constructor(settings) {
|
|
1018
|
+
super();
|
|
1019
|
+
this.settings = settings;
|
|
1068
1020
|
}
|
|
1069
|
-
|
|
1070
|
-
|
|
1021
|
+
async read(schema, data) {
|
|
1022
|
+
const reviver = needsReviver(schema) ? jsonReviver : undefined;
|
|
1023
|
+
let parsed;
|
|
1024
|
+
if (typeof data === "string") {
|
|
1025
|
+
parsed = JSON.parse(data, reviver);
|
|
1026
|
+
}
|
|
1027
|
+
else if (data instanceof Uint8Array && detectBufferParsing()) {
|
|
1028
|
+
const buf = Buffer.isBuffer(data) ? data : Buffer.from(data.buffer, data.byteOffset, data.byteLength);
|
|
1029
|
+
parsed = JSON.parse(buf, reviver);
|
|
1030
|
+
}
|
|
1031
|
+
else {
|
|
1032
|
+
parsed = await parseJsonBody(data, this.serdeContext);
|
|
1033
|
+
}
|
|
1034
|
+
return this._read(schema, parsed);
|
|
1071
1035
|
}
|
|
1072
|
-
|
|
1073
|
-
|
|
1036
|
+
readObject(schema, data) {
|
|
1037
|
+
return this._read(schema, data);
|
|
1038
|
+
}
|
|
1039
|
+
_read(schema, value) {
|
|
1040
|
+
const isObject = value !== null && typeof value === "object";
|
|
1041
|
+
const ns = NormalizedSchema.of(schema);
|
|
1042
|
+
if (isObject) {
|
|
1043
|
+
if (ns.isStructSchema()) {
|
|
1044
|
+
return this._readStruct(ns, value);
|
|
1045
|
+
}
|
|
1046
|
+
if (Array.isArray(value) && ns.isListSchema()) {
|
|
1047
|
+
const listMember = ns.getValueSchema();
|
|
1048
|
+
for (let i = 0; i < value.length; ++i) {
|
|
1049
|
+
value[i] = this._read(listMember, value[i]);
|
|
1050
|
+
}
|
|
1051
|
+
return value;
|
|
1052
|
+
}
|
|
1053
|
+
if (ns.isMapSchema()) {
|
|
1054
|
+
const mapMember = ns.getValueSchema();
|
|
1055
|
+
const map = value;
|
|
1056
|
+
for (const k in map) {
|
|
1057
|
+
if (k === "__proto__") {
|
|
1058
|
+
writeKey(map);
|
|
1059
|
+
}
|
|
1060
|
+
map[k] = this._read(mapMember, map[k]);
|
|
1061
|
+
}
|
|
1062
|
+
return map;
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
if (ns.isBlobSchema() && typeof value === "string") {
|
|
1066
|
+
return fromBase64(value);
|
|
1067
|
+
}
|
|
1068
|
+
const mediaType = ns.getMergedTraits().mediaType;
|
|
1069
|
+
if (ns.isStringSchema() && typeof value === "string" && mediaType) {
|
|
1070
|
+
const isJson = mediaType === "application/json" || mediaType.endsWith("+json");
|
|
1071
|
+
if (isJson) {
|
|
1072
|
+
return LazyJsonString.from(value);
|
|
1073
|
+
}
|
|
1074
|
+
return value;
|
|
1075
|
+
}
|
|
1076
|
+
if (ns.isTimestampSchema() && value != null) {
|
|
1077
|
+
const format = determineTimestampFormat(ns, this.settings);
|
|
1078
|
+
switch (format) {
|
|
1079
|
+
case 5:
|
|
1080
|
+
return parseRfc3339DateTimeWithOffset(value);
|
|
1081
|
+
case 6:
|
|
1082
|
+
return parseRfc7231DateTime(value);
|
|
1083
|
+
case 7:
|
|
1084
|
+
return parseEpochTimestamp(value);
|
|
1085
|
+
default:
|
|
1086
|
+
console.warn("Missing timestamp format, parsing value with Date constructor:", value);
|
|
1087
|
+
return new Date(value);
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
if (ns.isBigIntegerSchema() && (typeof value === "number" || typeof value === "string")) {
|
|
1091
|
+
return BigInt(value);
|
|
1092
|
+
}
|
|
1093
|
+
if (ns.isBigDecimalSchema() && value != undefined) {
|
|
1094
|
+
if (value instanceof NumericValue) {
|
|
1095
|
+
return value;
|
|
1096
|
+
}
|
|
1097
|
+
const untyped = value;
|
|
1098
|
+
if (untyped.type === "bigDecimal" && "string" in untyped) {
|
|
1099
|
+
return new NumericValue(untyped.string, untyped.type);
|
|
1100
|
+
}
|
|
1101
|
+
return new NumericValue(String(value), "bigDecimal");
|
|
1102
|
+
}
|
|
1103
|
+
if (ns.isNumericSchema() && typeof value === "string") {
|
|
1104
|
+
switch (value) {
|
|
1105
|
+
case "Infinity":
|
|
1106
|
+
return Infinity;
|
|
1107
|
+
case "-Infinity":
|
|
1108
|
+
return -Infinity;
|
|
1109
|
+
case "NaN":
|
|
1110
|
+
return NaN;
|
|
1111
|
+
}
|
|
1112
|
+
return value;
|
|
1113
|
+
}
|
|
1114
|
+
if (ns.isDocumentSchema()) {
|
|
1115
|
+
if (isObject) {
|
|
1116
|
+
if (Array.isArray(value)) {
|
|
1117
|
+
for (let i = 0; i < value.length; ++i) {
|
|
1118
|
+
const v = value[i];
|
|
1119
|
+
if (!(v instanceof NumericValue)) {
|
|
1120
|
+
value[i] = this._read(ns, v);
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
else {
|
|
1125
|
+
const doc = value;
|
|
1126
|
+
for (const k in doc) {
|
|
1127
|
+
if (k === "__proto__") {
|
|
1128
|
+
writeKey(doc);
|
|
1129
|
+
}
|
|
1130
|
+
const v = doc[k];
|
|
1131
|
+
if (!(v instanceof NumericValue)) {
|
|
1132
|
+
doc[k] = this._read(ns, v);
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
return value;
|
|
1137
|
+
}
|
|
1138
|
+
else {
|
|
1139
|
+
return value;
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
return value;
|
|
1143
|
+
}
|
|
1144
|
+
_readStruct(ns, record) {
|
|
1145
|
+
const union = ns.isUnionSchema();
|
|
1146
|
+
const out = {};
|
|
1147
|
+
let nameMap = void 0;
|
|
1148
|
+
const { jsonName } = this.settings;
|
|
1149
|
+
if (jsonName) {
|
|
1150
|
+
nameMap = {};
|
|
1151
|
+
}
|
|
1152
|
+
let unionSerde;
|
|
1153
|
+
if (union) {
|
|
1154
|
+
unionSerde = new UnionSerde(record, out);
|
|
1155
|
+
}
|
|
1156
|
+
for (const [memberName, memberSchema] of ns.structIterator()) {
|
|
1157
|
+
let fromKey = memberName;
|
|
1158
|
+
if (jsonName) {
|
|
1159
|
+
fromKey = memberSchema.getMergedTraits().jsonName ?? fromKey;
|
|
1160
|
+
nameMap[fromKey] = memberName;
|
|
1161
|
+
}
|
|
1162
|
+
if (union) {
|
|
1163
|
+
unionSerde.mark(fromKey);
|
|
1164
|
+
}
|
|
1165
|
+
if (record[fromKey] != null) {
|
|
1166
|
+
out[memberName] = this._read(memberSchema, record[fromKey]);
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
if (union) {
|
|
1170
|
+
unionSerde.writeUnknown();
|
|
1171
|
+
}
|
|
1172
|
+
else if (typeof record.__type === "string") {
|
|
1173
|
+
for (const k in record) {
|
|
1174
|
+
const v = record[k];
|
|
1175
|
+
const t = jsonName ? (nameMap[k] ?? k) : k;
|
|
1176
|
+
if (!(t in out)) {
|
|
1177
|
+
out[t] = v;
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
return out;
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
const encoder = new TextEncoder();
|
|
1186
|
+
const OPEN_BRACE = 0x7b;
|
|
1187
|
+
const CLOSE_BRACE = 0x7d;
|
|
1188
|
+
const OPEN_BRACKET = 0x5b;
|
|
1189
|
+
const CLOSE_BRACKET = 0x5d;
|
|
1190
|
+
const QUOTE = 0x22;
|
|
1191
|
+
const COLON = 0x3a;
|
|
1192
|
+
const COMMA = 0x2c;
|
|
1193
|
+
const BACKSLASH = 0x5c;
|
|
1194
|
+
const TRUE = new Uint8Array([0x74, 0x72, 0x75, 0x65]);
|
|
1195
|
+
const FALSE = new Uint8Array([0x66, 0x61, 0x6c, 0x73, 0x65]);
|
|
1196
|
+
const NULL = new Uint8Array([0x6e, 0x75, 0x6c, 0x6c]);
|
|
1197
|
+
const ESCAPE_TABLE = new Array(128).fill(null);
|
|
1198
|
+
ESCAPE_TABLE[0x08] = "b";
|
|
1199
|
+
ESCAPE_TABLE[0x09] = "t";
|
|
1200
|
+
ESCAPE_TABLE[0x0a] = "n";
|
|
1201
|
+
ESCAPE_TABLE[0x0c] = "f";
|
|
1202
|
+
ESCAPE_TABLE[0x0d] = "r";
|
|
1203
|
+
ESCAPE_TABLE[0x22] = '"';
|
|
1204
|
+
ESCAPE_TABLE[0x5c] = "\\";
|
|
1205
|
+
for (let i = 0; i < 0x20; i++) {
|
|
1206
|
+
if (ESCAPE_TABLE[i] === null) {
|
|
1207
|
+
ESCAPE_TABLE[i] = "u00" + i.toString(16).padStart(2, "0");
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
const INITIAL_BUFFER_SIZE = 2048;
|
|
1211
|
+
function alloc(size) {
|
|
1212
|
+
return typeof Buffer !== "undefined" ? Buffer.allocUnsafe(size) : new Uint8Array(size);
|
|
1213
|
+
}
|
|
1214
|
+
class JsonShapeSerializer2 extends SerdeContextConfig {
|
|
1215
|
+
settings;
|
|
1216
|
+
json;
|
|
1217
|
+
i = 0;
|
|
1218
|
+
rootSchema;
|
|
1219
|
+
rawValue;
|
|
1220
|
+
passthrough = false;
|
|
1221
|
+
constructor(settings) {
|
|
1222
|
+
super();
|
|
1223
|
+
this.settings = settings;
|
|
1224
|
+
this.json = alloc(INITIAL_BUFFER_SIZE);
|
|
1225
|
+
}
|
|
1226
|
+
write(schema, value) {
|
|
1227
|
+
this.i = 0;
|
|
1228
|
+
this.rawValue = value;
|
|
1229
|
+
this.rootSchema = NormalizedSchema.of(schema);
|
|
1230
|
+
this.passthrough =
|
|
1231
|
+
!this.rootSchema.isStructSchema() &&
|
|
1232
|
+
!this.rootSchema.isDocumentSchema() &&
|
|
1233
|
+
(this.rootSchema.isBlobSchema() || this.rootSchema.isStringSchema());
|
|
1234
|
+
if (!this.passthrough) {
|
|
1235
|
+
this.writeValue(this.rootSchema, value, undefined);
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
writeDiscriminatedDocument(schema, value) {
|
|
1239
|
+
this.i = 0;
|
|
1240
|
+
this.rootSchema = NormalizedSchema.of(schema);
|
|
1241
|
+
const ns = this.rootSchema;
|
|
1242
|
+
if (ns.isStructSchema() && value != null && typeof value === "object") {
|
|
1243
|
+
this.ensure(2);
|
|
1244
|
+
this.json[this.i++] = OPEN_BRACE;
|
|
1245
|
+
this.writeAsciiQuoted("__type");
|
|
1246
|
+
this.json[this.i++] = COLON;
|
|
1247
|
+
this.writeAsciiQuoted(ns.getName(true) ?? "Unknown");
|
|
1248
|
+
let wroteAny = true;
|
|
1249
|
+
const { jsonName } = this.settings;
|
|
1250
|
+
for (const [memberName, memberSchema] of ns.structIterator()) {
|
|
1251
|
+
const item = value[memberName];
|
|
1252
|
+
if (item == null && !memberSchema.isIdempotencyToken()) {
|
|
1253
|
+
continue;
|
|
1254
|
+
}
|
|
1255
|
+
if (wroteAny) {
|
|
1256
|
+
this.ensure(1);
|
|
1257
|
+
this.json[this.i++] = COMMA;
|
|
1258
|
+
}
|
|
1259
|
+
const targetKey = jsonName ? (memberSchema.getMergedTraits().jsonName ?? memberName) : memberName;
|
|
1260
|
+
this.writeAsciiQuoted(targetKey);
|
|
1261
|
+
this.json[this.i++] = COLON;
|
|
1262
|
+
this.writeValue(memberSchema, item, ns);
|
|
1263
|
+
wroteAny = true;
|
|
1264
|
+
}
|
|
1265
|
+
this.ensure(1);
|
|
1266
|
+
this.json[this.i++] = CLOSE_BRACE;
|
|
1267
|
+
}
|
|
1268
|
+
else {
|
|
1269
|
+
this.writeValue(ns, value, undefined);
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
flush() {
|
|
1273
|
+
this.rootSchema = undefined;
|
|
1274
|
+
const finalPosition = this.i;
|
|
1275
|
+
this.i = 0;
|
|
1276
|
+
const raw = this.rawValue;
|
|
1277
|
+
this.rawValue = undefined;
|
|
1278
|
+
if (finalPosition === 0) {
|
|
1279
|
+
return raw;
|
|
1280
|
+
}
|
|
1281
|
+
const result = this.json.subarray(0, finalPosition);
|
|
1282
|
+
this.json = alloc(INITIAL_BUFFER_SIZE);
|
|
1283
|
+
return result;
|
|
1284
|
+
}
|
|
1285
|
+
ensure(byteCount) {
|
|
1286
|
+
const { i, json } = this;
|
|
1287
|
+
if (i + byteCount > json.length) {
|
|
1288
|
+
let newSize = json.length * 2;
|
|
1289
|
+
while (newSize < i + byteCount) {
|
|
1290
|
+
newSize *= 2;
|
|
1291
|
+
}
|
|
1292
|
+
const next = alloc(newSize);
|
|
1293
|
+
next.set(this.json);
|
|
1294
|
+
this.json = next;
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
writeAscii(s) {
|
|
1298
|
+
const z = s.length;
|
|
1299
|
+
this.ensure(z);
|
|
1300
|
+
let { i, json } = this;
|
|
1301
|
+
for (let j = 0; j < z; ++j) {
|
|
1302
|
+
json[i] = s.charCodeAt(j);
|
|
1303
|
+
i += 1;
|
|
1304
|
+
}
|
|
1305
|
+
this.i = i;
|
|
1306
|
+
}
|
|
1307
|
+
writeAsciiQuoted(s) {
|
|
1308
|
+
const z = s.length;
|
|
1309
|
+
this.ensure(z + 4);
|
|
1310
|
+
let { json, i } = this;
|
|
1311
|
+
json[i++] = QUOTE;
|
|
1312
|
+
for (let j = 0; j < z; ++j) {
|
|
1313
|
+
json[i++] = s.charCodeAt(j);
|
|
1314
|
+
}
|
|
1315
|
+
json[i++] = QUOTE;
|
|
1316
|
+
this.i = i;
|
|
1317
|
+
}
|
|
1318
|
+
writeJsonString(s) {
|
|
1319
|
+
this.ensure(s.length * 2 + 2);
|
|
1320
|
+
this.json[this.i++] = QUOTE;
|
|
1321
|
+
const z = s.length;
|
|
1322
|
+
for (let j = 0; j < z; ++j) {
|
|
1323
|
+
const c = s.charCodeAt(j);
|
|
1324
|
+
if (c > 0x22 && c < 0x5c) {
|
|
1325
|
+
this.json[this.i++] = c;
|
|
1326
|
+
}
|
|
1327
|
+
else if (c < 0x80) {
|
|
1328
|
+
const esc = ESCAPE_TABLE[c];
|
|
1329
|
+
if (esc !== null) {
|
|
1330
|
+
this.ensure(esc.length + 1);
|
|
1331
|
+
this.json[this.i++] = BACKSLASH;
|
|
1332
|
+
for (let k = 0; k < esc.length; k++) {
|
|
1333
|
+
this.json[this.i++] = esc.charCodeAt(k);
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
else {
|
|
1337
|
+
this.json[this.i++] = c;
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
else if (c >= 0xd800 && c <= 0xdbff) {
|
|
1341
|
+
const next = j + 1 < z ? s.charCodeAt(j + 1) : 0;
|
|
1342
|
+
if (next >= 0xdc00 && next <= 0xdfff) {
|
|
1343
|
+
this.ensure(4);
|
|
1344
|
+
const { written } = encoder.encodeInto(s.substring(j, j + 2), this.json.subarray(this.i));
|
|
1345
|
+
this.i += written;
|
|
1346
|
+
j++;
|
|
1347
|
+
}
|
|
1348
|
+
else {
|
|
1349
|
+
this.ensure(6);
|
|
1350
|
+
this.writeUnicodeEscape(c);
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
else if (c >= 0xdc00 && c <= 0xdfff) {
|
|
1354
|
+
this.ensure(6);
|
|
1355
|
+
this.writeUnicodeEscape(c);
|
|
1356
|
+
}
|
|
1357
|
+
else {
|
|
1358
|
+
let { i, json } = this;
|
|
1359
|
+
if (c < 0x800) {
|
|
1360
|
+
json[i++] = 0xc0 | (c >> 6);
|
|
1361
|
+
json[i++] = 0x80 | (c & 0x3f);
|
|
1362
|
+
}
|
|
1363
|
+
else {
|
|
1364
|
+
json[i++] = 0xe0 | (c >> 12);
|
|
1365
|
+
json[i++] = 0x80 | ((c >> 6) & 0x3f);
|
|
1366
|
+
json[i++] = 0x80 | (c & 0x3f);
|
|
1367
|
+
}
|
|
1368
|
+
this.i = i;
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
this.json[this.i++] = QUOTE;
|
|
1372
|
+
}
|
|
1373
|
+
writeUnicodeEscape(code) {
|
|
1374
|
+
let { json, i } = this;
|
|
1375
|
+
json[i++] = BACKSLASH;
|
|
1376
|
+
json[i++] = 0x75;
|
|
1377
|
+
const hex = code.toString(16).padStart(4, "0");
|
|
1378
|
+
for (let j = 0; j < 4; ++j) {
|
|
1379
|
+
json[i++] = hex.charCodeAt(j);
|
|
1380
|
+
}
|
|
1381
|
+
this.i = i;
|
|
1382
|
+
}
|
|
1383
|
+
static B64 = (() => {
|
|
1384
|
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
1385
|
+
const table = new Uint8Array(64);
|
|
1386
|
+
for (let i = 0; i < 64; i++)
|
|
1387
|
+
table[i] = chars.charCodeAt(i);
|
|
1388
|
+
return table;
|
|
1389
|
+
})();
|
|
1390
|
+
writeBase64(data) {
|
|
1391
|
+
const b64Len = Math.ceil(data.length / 3) * 4;
|
|
1392
|
+
this.ensure(b64Len + 2);
|
|
1393
|
+
const json = this.json;
|
|
1394
|
+
const B64 = JsonShapeSerializer2.B64;
|
|
1395
|
+
let i = this.i;
|
|
1396
|
+
json[i++] = QUOTE;
|
|
1397
|
+
const len = data.length;
|
|
1398
|
+
const remainder = len % 3;
|
|
1399
|
+
const mainLen = len - remainder;
|
|
1400
|
+
for (let j = 0; j < mainLen; j += 3) {
|
|
1401
|
+
const a = data[j];
|
|
1402
|
+
const b = data[j + 1];
|
|
1403
|
+
const c = data[j + 2];
|
|
1404
|
+
json[i++] = B64[a >> 2];
|
|
1405
|
+
json[i++] = B64[((a & 0x03) << 4) | (b >> 4)];
|
|
1406
|
+
json[i++] = B64[((b & 0x0f) << 2) | (c >> 6)];
|
|
1407
|
+
json[i++] = B64[c & 0x3f];
|
|
1408
|
+
}
|
|
1409
|
+
if (remainder === 2) {
|
|
1410
|
+
const a = data[mainLen];
|
|
1411
|
+
const b = data[mainLen + 1];
|
|
1412
|
+
json[i++] = B64[a >> 2];
|
|
1413
|
+
json[i++] = B64[((a & 0x03) << 4) | (b >> 4)];
|
|
1414
|
+
json[i++] = B64[(b & 0x0f) << 2];
|
|
1415
|
+
json[i++] = 0x3d;
|
|
1416
|
+
}
|
|
1417
|
+
else if (remainder === 1) {
|
|
1418
|
+
const a = data[mainLen];
|
|
1419
|
+
json[i++] = B64[a >> 2];
|
|
1420
|
+
json[i++] = B64[(a & 0x03) << 4];
|
|
1421
|
+
json[i++] = 0x3d;
|
|
1422
|
+
json[i++] = 0x3d;
|
|
1423
|
+
}
|
|
1424
|
+
json[i++] = QUOTE;
|
|
1425
|
+
this.i = i;
|
|
1426
|
+
}
|
|
1427
|
+
writeValue(schema, value, container) {
|
|
1428
|
+
if (value == null) {
|
|
1429
|
+
if (container?.isStructSchema()) {
|
|
1430
|
+
if (value === undefined) {
|
|
1431
|
+
const ns = NormalizedSchema.of(schema);
|
|
1432
|
+
if (ns.isIdempotencyToken()) {
|
|
1433
|
+
this.writeAsciiQuoted(generateIdempotencyToken());
|
|
1434
|
+
return;
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
return;
|
|
1438
|
+
}
|
|
1439
|
+
this.ensure(4);
|
|
1440
|
+
this.json.set(NULL, this.i);
|
|
1441
|
+
this.i += 4;
|
|
1442
|
+
return;
|
|
1443
|
+
}
|
|
1444
|
+
const ns = NormalizedSchema.of(schema);
|
|
1445
|
+
const isObject = typeof value === "object";
|
|
1446
|
+
if (ns.isStringSchema()) {
|
|
1447
|
+
const mediaType = ns.getMergedTraits().mediaType;
|
|
1448
|
+
if (mediaType) {
|
|
1449
|
+
const isJson = mediaType === "application/json" || mediaType.endsWith("+json");
|
|
1450
|
+
if (isJson) {
|
|
1451
|
+
this.writeJsonString(LazyJsonString.from(value).toString());
|
|
1452
|
+
return;
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
if (isObject) {
|
|
1457
|
+
if (ns.isStructSchema()) {
|
|
1458
|
+
this.writeStruct(ns, value);
|
|
1459
|
+
return;
|
|
1460
|
+
}
|
|
1461
|
+
if (Array.isArray(value) && (ns.isListSchema() || ns.isDocumentSchema())) {
|
|
1462
|
+
this.writeList(ns, value, ns.isDocumentSchema());
|
|
1463
|
+
return;
|
|
1464
|
+
}
|
|
1465
|
+
if (ns.isMapSchema()) {
|
|
1466
|
+
this.writeMap(ns, value, false);
|
|
1467
|
+
return;
|
|
1468
|
+
}
|
|
1469
|
+
if (value instanceof Uint8Array && (ns.isBlobSchema() || ns.isDocumentSchema())) {
|
|
1470
|
+
this.writeBase64(value);
|
|
1471
|
+
return;
|
|
1472
|
+
}
|
|
1473
|
+
if (value instanceof Date && (ns.isTimestampSchema() || ns.isDocumentSchema())) {
|
|
1474
|
+
this.writeTimestamp(ns, value);
|
|
1475
|
+
return;
|
|
1476
|
+
}
|
|
1477
|
+
if (value instanceof NumericValue) {
|
|
1478
|
+
this.writeAscii(value.string);
|
|
1479
|
+
return;
|
|
1480
|
+
}
|
|
1481
|
+
if (ns.isDocumentSchema()) {
|
|
1482
|
+
if (Array.isArray(value)) {
|
|
1483
|
+
this.writeList(ns, value, true);
|
|
1484
|
+
}
|
|
1485
|
+
else {
|
|
1486
|
+
this.writeMap(ns, value, true);
|
|
1487
|
+
}
|
|
1488
|
+
return;
|
|
1489
|
+
}
|
|
1490
|
+
const json = JSON.stringify(value);
|
|
1491
|
+
this.writeAscii(json);
|
|
1492
|
+
return;
|
|
1493
|
+
}
|
|
1494
|
+
if (typeof value === "string") {
|
|
1495
|
+
if (ns.isBlobSchema()) {
|
|
1496
|
+
const b64 = (this.serdeContext?.base64Encoder ?? toBase64)(value);
|
|
1497
|
+
this.writeAsciiQuoted(b64);
|
|
1498
|
+
return;
|
|
1499
|
+
}
|
|
1500
|
+
this.writeJsonString(value);
|
|
1501
|
+
return;
|
|
1502
|
+
}
|
|
1503
|
+
if (typeof value === "number") {
|
|
1504
|
+
if (ns.isNumericSchema() && (Math.abs(value) === Infinity || isNaN(value))) {
|
|
1505
|
+
this.writeAsciiQuoted(String(value));
|
|
1506
|
+
return;
|
|
1507
|
+
}
|
|
1508
|
+
const numStr = String(value);
|
|
1509
|
+
this.writeAscii(numStr);
|
|
1510
|
+
return;
|
|
1511
|
+
}
|
|
1512
|
+
if (typeof value === "boolean") {
|
|
1513
|
+
this.ensure(5);
|
|
1514
|
+
if (value) {
|
|
1515
|
+
this.json.set(TRUE, this.i);
|
|
1516
|
+
this.i += 4;
|
|
1517
|
+
}
|
|
1518
|
+
else {
|
|
1519
|
+
this.json.set(FALSE, this.i);
|
|
1520
|
+
this.i += 5;
|
|
1521
|
+
}
|
|
1522
|
+
return;
|
|
1523
|
+
}
|
|
1524
|
+
if (typeof value === "bigint") {
|
|
1525
|
+
this.writeAscii(value.toString());
|
|
1526
|
+
return;
|
|
1527
|
+
}
|
|
1528
|
+
this.writeAscii(String(value));
|
|
1529
|
+
}
|
|
1530
|
+
writeStruct(ns, value) {
|
|
1531
|
+
this.ensure(2);
|
|
1532
|
+
this.json[this.i++] = OPEN_BRACE;
|
|
1533
|
+
let first = true;
|
|
1534
|
+
let wroteAny = false;
|
|
1535
|
+
const hasType = typeof value.__type === "string";
|
|
1536
|
+
let writtenKeys;
|
|
1537
|
+
if (hasType) {
|
|
1538
|
+
writtenKeys = new Set();
|
|
1539
|
+
}
|
|
1540
|
+
for (const [memberName, memberSchema] of ns.structIterator()) {
|
|
1541
|
+
const item = value[memberName];
|
|
1542
|
+
if (item == null && !memberSchema.isIdempotencyToken())
|
|
1543
|
+
continue;
|
|
1544
|
+
if (!first) {
|
|
1545
|
+
this.ensure(1);
|
|
1546
|
+
this.json[this.i++] = COMMA;
|
|
1547
|
+
}
|
|
1548
|
+
first = false;
|
|
1549
|
+
wroteAny = true;
|
|
1550
|
+
const targetKey = this.settings.jsonName ? (memberSchema.getMergedTraits().jsonName ?? memberName) : memberName;
|
|
1551
|
+
if (writtenKeys) {
|
|
1552
|
+
writtenKeys.add(memberName);
|
|
1553
|
+
writtenKeys.add(targetKey);
|
|
1554
|
+
}
|
|
1555
|
+
this.writeAsciiQuoted(targetKey);
|
|
1556
|
+
this.json[this.i++] = COLON;
|
|
1557
|
+
this.writeValue(memberSchema, item, ns);
|
|
1558
|
+
}
|
|
1559
|
+
if (!wroteAny && ns.isUnionSchema()) {
|
|
1560
|
+
const { $unknown } = value;
|
|
1561
|
+
if (Array.isArray($unknown)) {
|
|
1562
|
+
const [k, v] = $unknown;
|
|
1563
|
+
this.writeAsciiQuoted(k);
|
|
1564
|
+
this.ensure(1);
|
|
1565
|
+
this.json[this.i++] = COLON;
|
|
1566
|
+
this.writeValue(15, v, ns);
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
else if (hasType) {
|
|
1570
|
+
for (const k in value) {
|
|
1571
|
+
const targetKey = this.settings.jsonName ? (writtenKeys.has(k) ? k : k) : k;
|
|
1572
|
+
if (writtenKeys.has(targetKey))
|
|
1573
|
+
continue;
|
|
1574
|
+
writtenKeys.add(targetKey);
|
|
1575
|
+
const v = value[k];
|
|
1576
|
+
if (!first) {
|
|
1577
|
+
this.ensure(1);
|
|
1578
|
+
this.json[this.i++] = COMMA;
|
|
1579
|
+
}
|
|
1580
|
+
first = false;
|
|
1581
|
+
this.writeAsciiQuoted(targetKey);
|
|
1582
|
+
this.ensure(1);
|
|
1583
|
+
this.json[this.i++] = COLON;
|
|
1584
|
+
this.writeValue(15, v, undefined);
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
this.ensure(1);
|
|
1588
|
+
this.json[this.i++] = CLOSE_BRACE;
|
|
1589
|
+
}
|
|
1590
|
+
writeList(ns, value, isDocument) {
|
|
1591
|
+
this.ensure(2);
|
|
1592
|
+
this.json[this.i++] = OPEN_BRACKET;
|
|
1593
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
1594
|
+
const valueSchema = ns.getValueSchema();
|
|
1595
|
+
for (let i = 0; i < value.length; ++i) {
|
|
1596
|
+
const item = value[i];
|
|
1597
|
+
if (isDocument ? item === undefined : item == null && !sparse) {
|
|
1598
|
+
continue;
|
|
1599
|
+
}
|
|
1600
|
+
if (i !== 0) {
|
|
1601
|
+
this.ensure(1);
|
|
1602
|
+
this.json[this.i++] = COMMA;
|
|
1603
|
+
}
|
|
1604
|
+
this.writeValue(valueSchema, item, undefined);
|
|
1605
|
+
}
|
|
1606
|
+
this.ensure(1);
|
|
1607
|
+
this.json[this.i++] = CLOSE_BRACKET;
|
|
1608
|
+
}
|
|
1609
|
+
writeMap(ns, value, isDocument) {
|
|
1610
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
1611
|
+
const valueSchema = ns.getValueSchema();
|
|
1612
|
+
if (!isDocument) {
|
|
1613
|
+
if (valueSchema.isStringSchema() || valueSchema.isNumericSchema() || valueSchema.isBooleanSchema()) {
|
|
1614
|
+
let input = value;
|
|
1615
|
+
if (sparse) {
|
|
1616
|
+
input = {};
|
|
1617
|
+
for (const k in value) {
|
|
1618
|
+
if (k === "__proto__") {
|
|
1619
|
+
writeKey(input);
|
|
1620
|
+
}
|
|
1621
|
+
input[k] = value[k] ?? null;
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
const json = JSON.stringify(input);
|
|
1625
|
+
this.ensure(json.length * 3);
|
|
1626
|
+
const { written } = encoder.encodeInto(json, this.json.subarray(this.i));
|
|
1627
|
+
this.i += written;
|
|
1628
|
+
return;
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
this.ensure(2);
|
|
1632
|
+
this.json[this.i++] = OPEN_BRACE;
|
|
1633
|
+
let first = true;
|
|
1634
|
+
for (const k in value) {
|
|
1635
|
+
const v = value[k];
|
|
1636
|
+
if (isDocument ? v === undefined : v == null && !sparse) {
|
|
1637
|
+
continue;
|
|
1638
|
+
}
|
|
1639
|
+
if (!first) {
|
|
1640
|
+
this.ensure(1);
|
|
1641
|
+
this.json[this.i++] = COMMA;
|
|
1642
|
+
}
|
|
1643
|
+
first = false;
|
|
1644
|
+
this.writeJsonString(k);
|
|
1645
|
+
this.ensure(1);
|
|
1646
|
+
this.json[this.i++] = COLON;
|
|
1647
|
+
this.writeValue(valueSchema, v, undefined);
|
|
1648
|
+
}
|
|
1649
|
+
this.ensure(1);
|
|
1650
|
+
this.json[this.i++] = CLOSE_BRACE;
|
|
1651
|
+
}
|
|
1652
|
+
writeTimestamp(ns, value) {
|
|
1653
|
+
const format = determineTimestampFormat(ns, this.settings);
|
|
1654
|
+
switch (format) {
|
|
1655
|
+
case 5: {
|
|
1656
|
+
const iso = value.toISOString().replace(".000Z", "Z");
|
|
1657
|
+
this.writeAsciiQuoted(iso);
|
|
1658
|
+
return;
|
|
1659
|
+
}
|
|
1660
|
+
case 6: {
|
|
1661
|
+
this.writeAsciiQuoted(dateToUtcString(value));
|
|
1662
|
+
return;
|
|
1663
|
+
}
|
|
1664
|
+
case 7: {
|
|
1665
|
+
const epochSecs = String(value.getTime() / 1000);
|
|
1666
|
+
this.writeAscii(epochSecs);
|
|
1667
|
+
return;
|
|
1668
|
+
}
|
|
1669
|
+
default: {
|
|
1670
|
+
const epochSecs = String(value.getTime() / 1000);
|
|
1671
|
+
this.writeAscii(epochSecs);
|
|
1672
|
+
return;
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
class JsonCodec2 extends SerdeContextConfig {
|
|
1679
|
+
settings;
|
|
1680
|
+
constructor(settings) {
|
|
1681
|
+
super();
|
|
1682
|
+
this.settings = settings;
|
|
1683
|
+
}
|
|
1684
|
+
createSerializer() {
|
|
1685
|
+
const serializer = new JsonShapeSerializer2(this.settings);
|
|
1686
|
+
serializer.setSerdeContext(this.serdeContext);
|
|
1687
|
+
return serializer;
|
|
1688
|
+
}
|
|
1689
|
+
createDeserializer() {
|
|
1690
|
+
const deserializer = new JsonShapeDeserializer2(this.settings);
|
|
1691
|
+
deserializer.setSerdeContext(this.serdeContext);
|
|
1692
|
+
return deserializer;
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1074
1695
|
|
|
1075
1696
|
class XmlShapeDeserializer extends SerdeContextConfig {
|
|
1076
1697
|
settings;
|
|
@@ -2004,6 +2625,66 @@ class AwsRestXmlProtocol extends HttpBindingProtocol {
|
|
|
2004
2625
|
}
|
|
2005
2626
|
}
|
|
2006
2627
|
|
|
2628
|
+
const awsExpectUnion = (value) => {
|
|
2629
|
+
if (value == null) {
|
|
2630
|
+
return undefined;
|
|
2631
|
+
}
|
|
2632
|
+
if (typeof value === "object" && "__type" in value) {
|
|
2633
|
+
delete value.__type;
|
|
2634
|
+
}
|
|
2635
|
+
return expectUnion(value);
|
|
2636
|
+
};
|
|
2637
|
+
|
|
2638
|
+
const _toStr = (val) => {
|
|
2639
|
+
if (val == null) {
|
|
2640
|
+
return val;
|
|
2641
|
+
}
|
|
2642
|
+
if (typeof val === "number" || typeof val === "bigint") {
|
|
2643
|
+
const warning = new Error(`Received number ${val} where a string was expected.`);
|
|
2644
|
+
warning.name = "Warning";
|
|
2645
|
+
console.warn(warning);
|
|
2646
|
+
return String(val);
|
|
2647
|
+
}
|
|
2648
|
+
if (typeof val === "boolean") {
|
|
2649
|
+
const warning = new Error(`Received boolean ${val} where a string was expected.`);
|
|
2650
|
+
warning.name = "Warning";
|
|
2651
|
+
console.warn(warning);
|
|
2652
|
+
return String(val);
|
|
2653
|
+
}
|
|
2654
|
+
return val;
|
|
2655
|
+
};
|
|
2656
|
+
const _toBool = (val) => {
|
|
2657
|
+
if (val == null) {
|
|
2658
|
+
return val;
|
|
2659
|
+
}
|
|
2660
|
+
if (typeof val === "string") {
|
|
2661
|
+
const lowercase = val.toLowerCase();
|
|
2662
|
+
if (val !== "" && lowercase !== "false" && lowercase !== "true") {
|
|
2663
|
+
const warning = new Error(`Received string "${val}" where a boolean was expected.`);
|
|
2664
|
+
warning.name = "Warning";
|
|
2665
|
+
console.warn(warning);
|
|
2666
|
+
}
|
|
2667
|
+
return val !== "" && lowercase !== "false";
|
|
2668
|
+
}
|
|
2669
|
+
return val;
|
|
2670
|
+
};
|
|
2671
|
+
const _toNum = (val) => {
|
|
2672
|
+
if (val == null) {
|
|
2673
|
+
return val;
|
|
2674
|
+
}
|
|
2675
|
+
if (typeof val === "string") {
|
|
2676
|
+
const num = Number(val);
|
|
2677
|
+
if (num.toString() !== val) {
|
|
2678
|
+
const warning = new Error(`Received string "${val}" where a number was expected.`);
|
|
2679
|
+
warning.name = "Warning";
|
|
2680
|
+
console.warn(warning);
|
|
2681
|
+
return val;
|
|
2682
|
+
}
|
|
2683
|
+
return num;
|
|
2684
|
+
}
|
|
2685
|
+
return val;
|
|
2686
|
+
};
|
|
2687
|
+
|
|
2007
2688
|
exports.AwsEc2QueryProtocol = AwsEc2QueryProtocol;
|
|
2008
2689
|
exports.AwsJson1_0Protocol = AwsJson1_0Protocol;
|
|
2009
2690
|
exports.AwsJson1_1Protocol = AwsJson1_1Protocol;
|
|
@@ -2013,8 +2694,11 @@ exports.AwsRestJsonProtocol = AwsRestJsonProtocol;
|
|
|
2013
2694
|
exports.AwsRestXmlProtocol = AwsRestXmlProtocol;
|
|
2014
2695
|
exports.AwsSmithyRpcV2CborProtocol = AwsSmithyRpcV2CborProtocol;
|
|
2015
2696
|
exports.JsonCodec = JsonCodec;
|
|
2697
|
+
exports.JsonCodec2 = JsonCodec2;
|
|
2016
2698
|
exports.JsonShapeDeserializer = JsonShapeDeserializer;
|
|
2699
|
+
exports.JsonShapeDeserializer2 = JsonShapeDeserializer2;
|
|
2017
2700
|
exports.JsonShapeSerializer = JsonShapeSerializer;
|
|
2701
|
+
exports.JsonShapeSerializer2 = JsonShapeSerializer2;
|
|
2018
2702
|
exports.QueryShapeSerializer = QueryShapeSerializer;
|
|
2019
2703
|
exports.XmlCodec = XmlCodec;
|
|
2020
2704
|
exports.XmlShapeDeserializer = XmlShapeDeserializer;
|