@smithy/core 3.24.1 → 3.24.2
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/cbor/index.js +1 -1
- package/dist-cjs/submodules/serde/index.browser.js +126 -174
- package/dist-cjs/submodules/serde/index.js +181 -85
- package/dist-cjs/submodules/serde/index.native.js +126 -174
- package/dist-es/submodules/cbor/SmithyRpcV2CborProtocol.js +1 -1
- package/dist-es/submodules/serde/index.browser.js +12 -7
- package/dist-es/submodules/serde/index.js +9 -5
- package/dist-es/submodules/serde/index.native.js +10 -3
- package/dist-es/submodules/serde/util-base64/toBase64.browser.js +1 -1
- package/dist-es/submodules/serde/util-stream/blob/Uint8ArrayBlobAdapter.js +19 -21
- package/dist-es/submodules/serde/util-stream/checksum/createChecksumStream.browser.js +1 -1
- package/dist-es/submodules/serde/util-stream/sdk-stream-mixin.browser.js +2 -2
- package/dist-es/submodules/serde/util-stream/stream-collector.browser.js +1 -1
- package/dist-es/submodules/serde/util-utf8/toUint8Array.browser.js +10 -0
- package/dist-types/submodules/serde/index.browser.d.ts +13 -7
- package/dist-types/submodules/serde/index.d.ts +9 -5
- package/dist-types/submodules/serde/index.native.d.ts +7 -3
- package/dist-types/submodules/serde/util-stream/blob/Uint8ArrayBlobAdapter.d.ts +8 -12
- package/dist-types/submodules/serde/util-utf8/toUint8Array.browser.d.ts +4 -0
- package/package.json +1 -1
|
@@ -1080,7 +1080,7 @@ class SmithyRpcV2CborProtocol extends protocols.RpcProtocol {
|
|
|
1080
1080
|
const ns = schema.NormalizedSchema.of(errorSchema);
|
|
1081
1081
|
const ErrorCtor = registry.getErrorCtor(errorSchema);
|
|
1082
1082
|
const message = dataObject.message ?? dataObject.Message ?? "Unknown";
|
|
1083
|
-
const exception = new ErrorCtor(
|
|
1083
|
+
const exception = new ErrorCtor({});
|
|
1084
1084
|
const output = {};
|
|
1085
1085
|
for (const [name, member] of ns.structIterator()) {
|
|
1086
1086
|
output[name] = this.deserializer.readValue(member, dataObject[name]);
|
|
@@ -3,6 +3,122 @@
|
|
|
3
3
|
var protocols = require('@smithy/core/protocols');
|
|
4
4
|
var endpoints = require('@smithy/core/endpoints');
|
|
5
5
|
|
|
6
|
+
const chars = `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`;
|
|
7
|
+
const alphabetByEncoding = Object.entries(chars).reduce((acc, [i, c]) => {
|
|
8
|
+
acc[c] = Number(i);
|
|
9
|
+
return acc;
|
|
10
|
+
}, {});
|
|
11
|
+
const alphabetByValue = chars.split("");
|
|
12
|
+
const bitsPerLetter = 6;
|
|
13
|
+
const bitsPerByte = 8;
|
|
14
|
+
const maxLetterValue = 0b111111;
|
|
15
|
+
|
|
16
|
+
const fromBase64 = (input) => {
|
|
17
|
+
let totalByteLength = (input.length / 4) * 3;
|
|
18
|
+
if (input.slice(-2) === "==") {
|
|
19
|
+
totalByteLength -= 2;
|
|
20
|
+
}
|
|
21
|
+
else if (input.slice(-1) === "=") {
|
|
22
|
+
totalByteLength--;
|
|
23
|
+
}
|
|
24
|
+
const out = new ArrayBuffer(totalByteLength);
|
|
25
|
+
const dataView = new DataView(out);
|
|
26
|
+
for (let i = 0; i < input.length; i += 4) {
|
|
27
|
+
let bits = 0;
|
|
28
|
+
let bitLength = 0;
|
|
29
|
+
for (let j = i, limit = i + 3; j <= limit; j++) {
|
|
30
|
+
if (input[j] !== "=") {
|
|
31
|
+
if (!(input[j] in alphabetByEncoding)) {
|
|
32
|
+
throw new TypeError(`Invalid character ${input[j]} in base64 string.`);
|
|
33
|
+
}
|
|
34
|
+
bits |= alphabetByEncoding[input[j]] << ((limit - j) * bitsPerLetter);
|
|
35
|
+
bitLength += bitsPerLetter;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
bits >>= bitsPerLetter;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const chunkOffset = (i / 4) * 3;
|
|
42
|
+
bits >>= bitLength % bitsPerByte;
|
|
43
|
+
const byteLength = Math.floor(bitLength / bitsPerByte);
|
|
44
|
+
for (let k = 0; k < byteLength; k++) {
|
|
45
|
+
const offset = (byteLength - k - 1) * bitsPerByte;
|
|
46
|
+
dataView.setUint8(chunkOffset + k, (bits & (255 << offset)) >> offset);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return new Uint8Array(out);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const fromUtf8 = (input) => new TextEncoder().encode(input);
|
|
53
|
+
|
|
54
|
+
function toBase64(_input) {
|
|
55
|
+
let input;
|
|
56
|
+
if (typeof _input === "string") {
|
|
57
|
+
input = fromUtf8(_input);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
input = _input;
|
|
61
|
+
}
|
|
62
|
+
const isArrayLike = typeof input === "object" && typeof input.length === "number";
|
|
63
|
+
const isUint8Array = typeof input === "object" &&
|
|
64
|
+
typeof input.byteOffset === "number" &&
|
|
65
|
+
typeof input.byteLength === "number";
|
|
66
|
+
if (!isArrayLike && !isUint8Array) {
|
|
67
|
+
throw new Error("@smithy/util-base64: toBase64 encoder function only accepts string | Uint8Array.");
|
|
68
|
+
}
|
|
69
|
+
let str = "";
|
|
70
|
+
for (let i = 0; i < input.length; i += 3) {
|
|
71
|
+
let bits = 0;
|
|
72
|
+
let bitLength = 0;
|
|
73
|
+
for (let j = i, limit = Math.min(i + 3, input.length); j < limit; j++) {
|
|
74
|
+
bits |= input[j] << ((limit - j - 1) * bitsPerByte);
|
|
75
|
+
bitLength += bitsPerByte;
|
|
76
|
+
}
|
|
77
|
+
const bitClusterCount = Math.ceil(bitLength / bitsPerLetter);
|
|
78
|
+
bits <<= bitClusterCount * bitsPerLetter - bitLength;
|
|
79
|
+
for (let k = 1; k <= bitClusterCount; k++) {
|
|
80
|
+
const offset = (bitClusterCount - k) * bitsPerLetter;
|
|
81
|
+
str += alphabetByValue[(bits & (maxLetterValue << offset)) >> offset];
|
|
82
|
+
}
|
|
83
|
+
str += "==".slice(0, 4 - bitClusterCount);
|
|
84
|
+
}
|
|
85
|
+
return str;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function bindUint8ArrayBlobAdapter(toUtf8, fromUtf8, toBase64, fromBase64) {
|
|
89
|
+
return class Uint8ArrayBlobAdapter extends Uint8Array {
|
|
90
|
+
static fromString(source, encoding = "utf-8") {
|
|
91
|
+
if (typeof source === "string") {
|
|
92
|
+
if (encoding === "base64") {
|
|
93
|
+
return Uint8ArrayBlobAdapter.mutate(fromBase64(source));
|
|
94
|
+
}
|
|
95
|
+
return Uint8ArrayBlobAdapter.mutate(fromUtf8(source));
|
|
96
|
+
}
|
|
97
|
+
throw new Error(`Unsupported conversion from ${typeof source} to Uint8ArrayBlobAdapter.`);
|
|
98
|
+
}
|
|
99
|
+
static mutate(source) {
|
|
100
|
+
Object.setPrototypeOf(source, Uint8ArrayBlobAdapter.prototype);
|
|
101
|
+
return source;
|
|
102
|
+
}
|
|
103
|
+
transformToString(encoding = "utf-8") {
|
|
104
|
+
if (encoding === "base64") {
|
|
105
|
+
return toBase64(this);
|
|
106
|
+
}
|
|
107
|
+
return toUtf8(this);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const toUtf8 = (input) => {
|
|
113
|
+
if (typeof input === "string") {
|
|
114
|
+
return input;
|
|
115
|
+
}
|
|
116
|
+
if (typeof input !== "object" || typeof input.byteOffset !== "number" || typeof input.byteLength !== "number") {
|
|
117
|
+
throw new Error("@smithy/util-utf8: toUtf8 encoder function only accepts string | Uint8Array.");
|
|
118
|
+
}
|
|
119
|
+
return new TextDecoder("utf-8").decode(input);
|
|
120
|
+
};
|
|
121
|
+
|
|
6
122
|
const decimalToHex = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
|
|
7
123
|
function bindV4(getRandomValues) {
|
|
8
124
|
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
@@ -721,107 +837,6 @@ function toHex(bytes) {
|
|
|
721
837
|
return out;
|
|
722
838
|
}
|
|
723
839
|
|
|
724
|
-
const chars = `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`;
|
|
725
|
-
const alphabetByEncoding = Object.entries(chars).reduce((acc, [i, c]) => {
|
|
726
|
-
acc[c] = Number(i);
|
|
727
|
-
return acc;
|
|
728
|
-
}, {});
|
|
729
|
-
const alphabetByValue = chars.split("");
|
|
730
|
-
const bitsPerLetter = 6;
|
|
731
|
-
const bitsPerByte = 8;
|
|
732
|
-
const maxLetterValue = 0b111111;
|
|
733
|
-
|
|
734
|
-
const fromBase64$1 = (input) => {
|
|
735
|
-
let totalByteLength = (input.length / 4) * 3;
|
|
736
|
-
if (input.slice(-2) === "==") {
|
|
737
|
-
totalByteLength -= 2;
|
|
738
|
-
}
|
|
739
|
-
else if (input.slice(-1) === "=") {
|
|
740
|
-
totalByteLength--;
|
|
741
|
-
}
|
|
742
|
-
const out = new ArrayBuffer(totalByteLength);
|
|
743
|
-
const dataView = new DataView(out);
|
|
744
|
-
for (let i = 0; i < input.length; i += 4) {
|
|
745
|
-
let bits = 0;
|
|
746
|
-
let bitLength = 0;
|
|
747
|
-
for (let j = i, limit = i + 3; j <= limit; j++) {
|
|
748
|
-
if (input[j] !== "=") {
|
|
749
|
-
if (!(input[j] in alphabetByEncoding)) {
|
|
750
|
-
throw new TypeError(`Invalid character ${input[j]} in base64 string.`);
|
|
751
|
-
}
|
|
752
|
-
bits |= alphabetByEncoding[input[j]] << ((limit - j) * bitsPerLetter);
|
|
753
|
-
bitLength += bitsPerLetter;
|
|
754
|
-
}
|
|
755
|
-
else {
|
|
756
|
-
bits >>= bitsPerLetter;
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
const chunkOffset = (i / 4) * 3;
|
|
760
|
-
bits >>= bitLength % bitsPerByte;
|
|
761
|
-
const byteLength = Math.floor(bitLength / bitsPerByte);
|
|
762
|
-
for (let k = 0; k < byteLength; k++) {
|
|
763
|
-
const offset = (byteLength - k - 1) * bitsPerByte;
|
|
764
|
-
dataView.setUint8(chunkOffset + k, (bits & (255 << offset)) >> offset);
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
return new Uint8Array(out);
|
|
768
|
-
};
|
|
769
|
-
|
|
770
|
-
const isArrayBuffer = (arg) => (typeof ArrayBuffer === "function" && arg instanceof ArrayBuffer) ||
|
|
771
|
-
Object.prototype.toString.call(arg) === "[object ArrayBuffer]";
|
|
772
|
-
|
|
773
|
-
const fromArrayBuffer = (input, offset = 0, length = input.byteLength - offset) => {
|
|
774
|
-
if (!isArrayBuffer(input)) {
|
|
775
|
-
throw new TypeError(`The "input" argument must be ArrayBuffer. Received type ${typeof input} (${input})`);
|
|
776
|
-
}
|
|
777
|
-
return Buffer.from(input, offset, length);
|
|
778
|
-
};
|
|
779
|
-
const fromString = (input, encoding) => {
|
|
780
|
-
if (typeof input !== "string") {
|
|
781
|
-
throw new TypeError(`The "input" argument must be of type string. Received type ${typeof input} (${input})`);
|
|
782
|
-
}
|
|
783
|
-
return encoding ? Buffer.from(input, encoding) : Buffer.from(input);
|
|
784
|
-
};
|
|
785
|
-
|
|
786
|
-
const fromUtf8$1 = (input) => {
|
|
787
|
-
const buf = fromString(input, "utf8");
|
|
788
|
-
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength / Uint8Array.BYTES_PER_ELEMENT);
|
|
789
|
-
};
|
|
790
|
-
|
|
791
|
-
function toBase64$1(_input) {
|
|
792
|
-
let input;
|
|
793
|
-
if (typeof _input === "string") {
|
|
794
|
-
input = fromUtf8$1(_input);
|
|
795
|
-
}
|
|
796
|
-
else {
|
|
797
|
-
input = _input;
|
|
798
|
-
}
|
|
799
|
-
const isArrayLike = typeof input === "object" && typeof input.length === "number";
|
|
800
|
-
const isUint8Array = typeof input === "object" &&
|
|
801
|
-
typeof input.byteOffset === "number" &&
|
|
802
|
-
typeof input.byteLength === "number";
|
|
803
|
-
if (!isArrayLike && !isUint8Array) {
|
|
804
|
-
throw new Error("@smithy/util-base64: toBase64 encoder function only accepts string | Uint8Array.");
|
|
805
|
-
}
|
|
806
|
-
let str = "";
|
|
807
|
-
for (let i = 0; i < input.length; i += 3) {
|
|
808
|
-
let bits = 0;
|
|
809
|
-
let bitLength = 0;
|
|
810
|
-
for (let j = i, limit = Math.min(i + 3, input.length); j < limit; j++) {
|
|
811
|
-
bits |= input[j] << ((limit - j - 1) * bitsPerByte);
|
|
812
|
-
bitLength += bitsPerByte;
|
|
813
|
-
}
|
|
814
|
-
const bitClusterCount = Math.ceil(bitLength / bitsPerLetter);
|
|
815
|
-
bits <<= bitClusterCount * bitsPerLetter - bitLength;
|
|
816
|
-
for (let k = 1; k <= bitClusterCount; k++) {
|
|
817
|
-
const offset = (bitClusterCount - k) * bitsPerLetter;
|
|
818
|
-
str += alphabetByValue[(bits & (maxLetterValue << offset)) >> offset];
|
|
819
|
-
}
|
|
820
|
-
str += "==".slice(0, 4 - bitClusterCount);
|
|
821
|
-
}
|
|
822
|
-
return str;
|
|
823
|
-
}
|
|
824
|
-
|
|
825
840
|
const TEXT_ENCODER = typeof TextEncoder == "function" ? new TextEncoder() : null;
|
|
826
841
|
const calculateBodyLength = (body) => {
|
|
827
842
|
if (typeof body === "string") {
|
|
@@ -849,11 +864,9 @@ const calculateBodyLength = (body) => {
|
|
|
849
864
|
throw new Error(`Body Length computation failed for ${body}`);
|
|
850
865
|
};
|
|
851
866
|
|
|
852
|
-
const fromUtf8 = (input) => new TextEncoder().encode(input);
|
|
853
|
-
|
|
854
867
|
const toUint8Array = (data) => {
|
|
855
868
|
if (typeof data === "string") {
|
|
856
|
-
return fromUtf8
|
|
869
|
+
return fromUtf8(data);
|
|
857
870
|
}
|
|
858
871
|
if (ArrayBuffer.isView(data)) {
|
|
859
872
|
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength / Uint8Array.BYTES_PER_ELEMENT);
|
|
@@ -861,15 +874,8 @@ const toUint8Array = (data) => {
|
|
|
861
874
|
return new Uint8Array(data);
|
|
862
875
|
};
|
|
863
876
|
|
|
864
|
-
const
|
|
865
|
-
|
|
866
|
-
return input;
|
|
867
|
-
}
|
|
868
|
-
if (typeof input !== "object" || typeof input.byteOffset !== "number" || typeof input.byteLength !== "number") {
|
|
869
|
-
throw new Error("@smithy/util-utf8: toUtf8 encoder function only accepts string | Uint8Array.");
|
|
870
|
-
}
|
|
871
|
-
return new TextDecoder("utf-8").decode(input);
|
|
872
|
-
};
|
|
877
|
+
const isArrayBuffer = (arg) => (typeof ArrayBuffer === "function" && arg instanceof ArrayBuffer) ||
|
|
878
|
+
Object.prototype.toString.call(arg) === "[object ArrayBuffer]";
|
|
873
879
|
|
|
874
880
|
const deserializerMiddleware = (options, deserializer) => (next, context) => async (args) => {
|
|
875
881
|
const { response } = await next(args);
|
|
@@ -965,64 +971,6 @@ function getSerdePlugin(config, serializer, deserializer) {
|
|
|
965
971
|
};
|
|
966
972
|
}
|
|
967
973
|
|
|
968
|
-
const BASE64_REGEX = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
969
|
-
const fromBase64 = (input) => {
|
|
970
|
-
if ((input.length * 3) % 4 !== 0) {
|
|
971
|
-
throw new TypeError(`Incorrect padding on base64 string.`);
|
|
972
|
-
}
|
|
973
|
-
if (!BASE64_REGEX.exec(input)) {
|
|
974
|
-
throw new TypeError(`Invalid base64 string.`);
|
|
975
|
-
}
|
|
976
|
-
const buffer = fromString(input, "base64");
|
|
977
|
-
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
978
|
-
};
|
|
979
|
-
|
|
980
|
-
const toBase64 = (_input) => {
|
|
981
|
-
let input;
|
|
982
|
-
if (typeof _input === "string") {
|
|
983
|
-
input = fromUtf8$1(_input);
|
|
984
|
-
}
|
|
985
|
-
else {
|
|
986
|
-
input = _input;
|
|
987
|
-
}
|
|
988
|
-
if (typeof input !== "object" || typeof input.byteOffset !== "number" || typeof input.byteLength !== "number") {
|
|
989
|
-
throw new Error("@smithy/util-base64: toBase64 encoder function only accepts string | Uint8Array.");
|
|
990
|
-
}
|
|
991
|
-
return fromArrayBuffer(input.buffer, input.byteOffset, input.byteLength).toString("base64");
|
|
992
|
-
};
|
|
993
|
-
|
|
994
|
-
const toUtf8 = (input) => {
|
|
995
|
-
if (typeof input === "string") {
|
|
996
|
-
return input;
|
|
997
|
-
}
|
|
998
|
-
if (typeof input !== "object" || typeof input.byteOffset !== "number" || typeof input.byteLength !== "number") {
|
|
999
|
-
throw new Error("@smithy/util-utf8: toUtf8 encoder function only accepts string | Uint8Array.");
|
|
1000
|
-
}
|
|
1001
|
-
return fromArrayBuffer(input.buffer, input.byteOffset, input.byteLength).toString("utf8");
|
|
1002
|
-
};
|
|
1003
|
-
|
|
1004
|
-
class Uint8ArrayBlobAdapter extends Uint8Array {
|
|
1005
|
-
static fromString(source, encoding = "utf-8") {
|
|
1006
|
-
if (typeof source === "string") {
|
|
1007
|
-
if (encoding === "base64") {
|
|
1008
|
-
return Uint8ArrayBlobAdapter.mutate(fromBase64(source));
|
|
1009
|
-
}
|
|
1010
|
-
return Uint8ArrayBlobAdapter.mutate(fromUtf8$1(source));
|
|
1011
|
-
}
|
|
1012
|
-
throw new Error(`Unsupported conversion from ${typeof source} to Uint8ArrayBlobAdapter.`);
|
|
1013
|
-
}
|
|
1014
|
-
static mutate(source) {
|
|
1015
|
-
Object.setPrototypeOf(source, Uint8ArrayBlobAdapter.prototype);
|
|
1016
|
-
return source;
|
|
1017
|
-
}
|
|
1018
|
-
transformToString(encoding = "utf-8") {
|
|
1019
|
-
if (encoding === "base64") {
|
|
1020
|
-
return toBase64(this);
|
|
1021
|
-
}
|
|
1022
|
-
return toUtf8(this);
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
|
|
1026
974
|
const ReadableStreamRef = typeof ReadableStream === "function" ? ReadableStream : function () { };
|
|
1027
975
|
class ChecksumStream extends ReadableStreamRef {
|
|
1028
976
|
}
|
|
@@ -1376,7 +1324,11 @@ async function splitStream(stream) {
|
|
|
1376
1324
|
}
|
|
1377
1325
|
|
|
1378
1326
|
const no = Symbol.for("node-only");
|
|
1327
|
+
const fromArrayBuffer = no;
|
|
1328
|
+
const fromString = no;
|
|
1379
1329
|
const Hash = no;
|
|
1330
|
+
class Uint8ArrayBlobAdapter extends bindUint8ArrayBlobAdapter(toUtf8, fromUtf8, toBase64, fromBase64) {
|
|
1331
|
+
}
|
|
1380
1332
|
const _getRandomValues = (array) => crypto.getRandomValues(array);
|
|
1381
1333
|
const v4 = bindV4(_getRandomValues);
|
|
1382
1334
|
const generateIdempotencyToken = v4;
|
|
@@ -1409,7 +1361,7 @@ exports.expectShort = expectShort;
|
|
|
1409
1361
|
exports.expectString = expectString;
|
|
1410
1362
|
exports.expectUnion = expectUnion;
|
|
1411
1363
|
exports.fromArrayBuffer = fromArrayBuffer;
|
|
1412
|
-
exports.fromBase64 = fromBase64
|
|
1364
|
+
exports.fromBase64 = fromBase64;
|
|
1413
1365
|
exports.fromHex = fromHex;
|
|
1414
1366
|
exports.fromString = fromString;
|
|
1415
1367
|
exports.fromUtf8 = fromUtf8;
|
|
@@ -1446,8 +1398,8 @@ exports.strictParseInt = strictParseInt;
|
|
|
1446
1398
|
exports.strictParseInt32 = strictParseInt32;
|
|
1447
1399
|
exports.strictParseLong = strictParseLong;
|
|
1448
1400
|
exports.strictParseShort = strictParseShort;
|
|
1449
|
-
exports.toBase64 = toBase64
|
|
1401
|
+
exports.toBase64 = toBase64;
|
|
1450
1402
|
exports.toHex = toHex;
|
|
1451
1403
|
exports.toUint8Array = toUint8Array;
|
|
1452
|
-
exports.toUtf8 = toUtf8
|
|
1404
|
+
exports.toUtf8 = toUtf8;
|
|
1453
1405
|
exports.v4 = v4;
|