@cdk8s/awscdk-resolver 0.0.145 → 0.0.147
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/.jsii +3 -3
- package/lib/resolve.js +1 -1
- package/node_modules/@aws-sdk/client-cloudformation/package.json +6 -6
- package/node_modules/@aws-sdk/client-sso/package.json +3 -3
- package/node_modules/@aws-sdk/client-sso-oidc/package.json +5 -5
- package/node_modules/@aws-sdk/client-sts/dist-cjs/index.js +8 -2
- package/node_modules/@aws-sdk/client-sts/dist-es/defaultStsRoleAssumers.js +7 -2
- package/node_modules/@aws-sdk/client-sts/package.json +5 -5
- package/node_modules/@aws-sdk/credential-provider-ini/package.json +3 -3
- package/node_modules/@aws-sdk/credential-provider-node/package.json +3 -3
- package/node_modules/@aws-sdk/credential-provider-sso/package.json +2 -2
- package/node_modules/@aws-sdk/middleware-user-agent/package.json +2 -2
- package/node_modules/@aws-sdk/util-endpoints/dist-cjs/index.js +1 -1
- package/node_modules/@aws-sdk/util-endpoints/dist-es/lib/aws/parseArn.js +1 -3
- package/node_modules/@aws-sdk/util-endpoints/package.json +1 -1
- package/node_modules/@smithy/core/cbor.js +6 -0
- package/node_modules/@smithy/core/dist-cjs/submodules/cbor/index.js +707 -0
- package/node_modules/@smithy/core/dist-es/submodules/cbor/cbor-decode.js +391 -0
- package/node_modules/@smithy/core/dist-es/submodules/cbor/cbor-encode.js +181 -0
- package/node_modules/@smithy/core/dist-es/submodules/cbor/cbor-types.js +20 -0
- package/node_modules/@smithy/core/dist-es/submodules/cbor/cbor.js +15 -0
- package/node_modules/@smithy/core/dist-es/submodules/cbor/index.js +2 -0
- package/node_modules/@smithy/core/dist-es/submodules/cbor/parseCborBody.js +82 -0
- package/node_modules/@smithy/core/dist-types/submodules/cbor/cbor-decode.d.ts +17 -0
- package/node_modules/@smithy/core/dist-types/submodules/cbor/cbor-encode.d.ts +9 -0
- package/node_modules/@smithy/core/dist-types/submodules/cbor/cbor-types.d.ts +40 -0
- package/node_modules/@smithy/core/dist-types/submodules/cbor/cbor.d.ts +26 -0
- package/node_modules/@smithy/core/dist-types/submodules/cbor/index.d.ts +2 -0
- package/node_modules/@smithy/core/dist-types/submodules/cbor/parseCborBody.d.ts +29 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/cbor/cbor-decode.d.ts +17 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/cbor/cbor-encode.d.ts +9 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/cbor/cbor-types.d.ts +43 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/cbor/cbor.d.ts +26 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/cbor/index.d.ts +2 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/cbor/parseCborBody.d.ts +29 -0
- package/node_modules/@smithy/core/package.json +17 -5
- package/node_modules/@smithy/middleware-retry/package.json +2 -2
- package/node_modules/@smithy/smithy-client/dist-cjs/index.js +2 -0
- package/node_modules/@smithy/smithy-client/dist-es/date-utils.js +3 -0
- package/node_modules/@smithy/smithy-client/dist-types/serde-json.d.ts +2 -0
- package/node_modules/@smithy/smithy-client/dist-types/ts3.4/serde-json.d.ts +2 -0
- package/node_modules/@smithy/smithy-client/package.json +1 -1
- package/node_modules/@smithy/util-defaults-mode-browser/package.json +2 -2
- package/node_modules/@smithy/util-defaults-mode-node/package.json +2 -2
- package/package.json +4 -4
@@ -0,0 +1,391 @@
|
|
1
|
+
import { toUtf8 } from "@smithy/util-utf8";
|
2
|
+
import { alloc, extendedFloat16, extendedFloat32, extendedFloat64, extendedOneByte, majorList, majorMap, majorNegativeInt64, majorTag, majorUint64, majorUnstructuredByteString, majorUtf8String, minorIndefinite, specialFalse, specialNull, specialTrue, specialUndefined, } from "./cbor-types";
|
3
|
+
const USE_TEXT_DECODER = typeof TextDecoder !== "undefined";
|
4
|
+
const USE_BUFFER = typeof Buffer !== "undefined";
|
5
|
+
let payload = alloc(0);
|
6
|
+
let dataView = new DataView(payload.buffer, payload.byteOffset, payload.byteLength);
|
7
|
+
const textDecoder = USE_TEXT_DECODER ? new TextDecoder() : null;
|
8
|
+
let _offset = 0;
|
9
|
+
export function setPayload(bytes) {
|
10
|
+
payload = bytes;
|
11
|
+
dataView = new DataView(payload.buffer, payload.byteOffset, payload.byteLength);
|
12
|
+
}
|
13
|
+
export function decode(at, to) {
|
14
|
+
if (at >= to) {
|
15
|
+
throw new Error("unexpected end of (decode) payload.");
|
16
|
+
}
|
17
|
+
const major = (payload[at] & 224) >> 5;
|
18
|
+
const minor = payload[at] & 31;
|
19
|
+
switch (major) {
|
20
|
+
case majorUint64:
|
21
|
+
case majorNegativeInt64:
|
22
|
+
case majorTag:
|
23
|
+
let unsignedInt;
|
24
|
+
let offset;
|
25
|
+
if (minor < 24) {
|
26
|
+
unsignedInt = minor;
|
27
|
+
offset = 1;
|
28
|
+
}
|
29
|
+
else {
|
30
|
+
switch (minor) {
|
31
|
+
case extendedOneByte:
|
32
|
+
case extendedFloat16:
|
33
|
+
case extendedFloat32:
|
34
|
+
case extendedFloat64:
|
35
|
+
const countLength = minorValueToArgumentLength[minor];
|
36
|
+
const countOffset = (countLength + 1);
|
37
|
+
offset = countOffset;
|
38
|
+
if (to - at < countOffset) {
|
39
|
+
throw new Error(`countLength ${countLength} greater than remaining buf len.`);
|
40
|
+
}
|
41
|
+
const countIndex = at + 1;
|
42
|
+
if (countLength === 1) {
|
43
|
+
unsignedInt = payload[countIndex];
|
44
|
+
}
|
45
|
+
else if (countLength === 2) {
|
46
|
+
unsignedInt = dataView.getUint16(countIndex);
|
47
|
+
}
|
48
|
+
else if (countLength === 4) {
|
49
|
+
unsignedInt = dataView.getUint32(countIndex);
|
50
|
+
}
|
51
|
+
else {
|
52
|
+
unsignedInt = dataView.getBigUint64(countIndex);
|
53
|
+
}
|
54
|
+
break;
|
55
|
+
default:
|
56
|
+
throw new Error(`unexpected minor value ${minor}.`);
|
57
|
+
}
|
58
|
+
}
|
59
|
+
if (major === majorUint64) {
|
60
|
+
_offset = offset;
|
61
|
+
return castBigInt(unsignedInt);
|
62
|
+
}
|
63
|
+
else if (major === majorNegativeInt64) {
|
64
|
+
let negativeInt;
|
65
|
+
if (typeof unsignedInt === "bigint") {
|
66
|
+
negativeInt = BigInt(-1) - unsignedInt;
|
67
|
+
}
|
68
|
+
else {
|
69
|
+
negativeInt = -1 - unsignedInt;
|
70
|
+
}
|
71
|
+
_offset = offset;
|
72
|
+
return castBigInt(negativeInt);
|
73
|
+
}
|
74
|
+
else {
|
75
|
+
const value = decode(at + offset, to);
|
76
|
+
const valueOffset = _offset;
|
77
|
+
_offset = offset + valueOffset;
|
78
|
+
return { tag: castBigInt(unsignedInt), value };
|
79
|
+
}
|
80
|
+
case majorUtf8String:
|
81
|
+
case majorMap:
|
82
|
+
case majorList:
|
83
|
+
case majorUnstructuredByteString:
|
84
|
+
if (minor === minorIndefinite) {
|
85
|
+
switch (major) {
|
86
|
+
case majorUtf8String:
|
87
|
+
return decodeUtf8StringIndefinite(at, to);
|
88
|
+
case majorMap:
|
89
|
+
return decodeMapIndefinite(at, to);
|
90
|
+
case majorList:
|
91
|
+
return decodeListIndefinite(at, to);
|
92
|
+
case majorUnstructuredByteString:
|
93
|
+
return decodeUnstructuredByteStringIndefinite(at, to);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
else {
|
97
|
+
switch (major) {
|
98
|
+
case majorUtf8String:
|
99
|
+
return decodeUtf8String(at, to);
|
100
|
+
case majorMap:
|
101
|
+
return decodeMap(at, to);
|
102
|
+
case majorList:
|
103
|
+
return decodeList(at, to);
|
104
|
+
case majorUnstructuredByteString:
|
105
|
+
return decodeUnstructuredByteString(at, to);
|
106
|
+
}
|
107
|
+
}
|
108
|
+
default:
|
109
|
+
return decodeSpecial(at, to);
|
110
|
+
}
|
111
|
+
}
|
112
|
+
function bytesToUtf8(bytes, at, to) {
|
113
|
+
if (USE_BUFFER && bytes.constructor?.name === "Buffer") {
|
114
|
+
return bytes.toString("utf-8", at, to);
|
115
|
+
}
|
116
|
+
if (textDecoder) {
|
117
|
+
return textDecoder.decode(bytes.subarray(at, to));
|
118
|
+
}
|
119
|
+
return toUtf8(bytes.subarray(at, to));
|
120
|
+
}
|
121
|
+
function demote(bigInteger) {
|
122
|
+
const num = Number(bigInteger);
|
123
|
+
if (num < Number.MIN_SAFE_INTEGER || Number.MAX_SAFE_INTEGER < num) {
|
124
|
+
console.warn(new Error(`@smithy/core/cbor - truncating BigInt(${bigInteger}) to ${num} with loss of precision.`));
|
125
|
+
}
|
126
|
+
return num;
|
127
|
+
}
|
128
|
+
const minorValueToArgumentLength = {
|
129
|
+
[extendedOneByte]: 1,
|
130
|
+
[extendedFloat16]: 2,
|
131
|
+
[extendedFloat32]: 4,
|
132
|
+
[extendedFloat64]: 8,
|
133
|
+
};
|
134
|
+
export function bytesToFloat16(a, b) {
|
135
|
+
const sign = a >> 7;
|
136
|
+
const exponent = (a & 124) >> 2;
|
137
|
+
const fraction = ((a & 3) << 8) | b;
|
138
|
+
const scalar = sign === 0 ? 1 : -1;
|
139
|
+
let exponentComponent;
|
140
|
+
let summation;
|
141
|
+
if (exponent === 0b00000) {
|
142
|
+
if (fraction === 0) {
|
143
|
+
return 0;
|
144
|
+
}
|
145
|
+
else {
|
146
|
+
exponentComponent = Math.pow(2, 1 - 15);
|
147
|
+
summation = 0;
|
148
|
+
}
|
149
|
+
}
|
150
|
+
else if (exponent === 0b11111) {
|
151
|
+
if (fraction === 0) {
|
152
|
+
return scalar * Infinity;
|
153
|
+
}
|
154
|
+
else {
|
155
|
+
return NaN;
|
156
|
+
}
|
157
|
+
}
|
158
|
+
else {
|
159
|
+
exponentComponent = Math.pow(2, exponent - 15);
|
160
|
+
summation = 1;
|
161
|
+
}
|
162
|
+
summation += fraction / 1024;
|
163
|
+
return scalar * (exponentComponent * summation);
|
164
|
+
}
|
165
|
+
function decodeCount(at, to) {
|
166
|
+
const minor = payload[at] & 31;
|
167
|
+
if (minor < 24) {
|
168
|
+
_offset = 1;
|
169
|
+
return minor;
|
170
|
+
}
|
171
|
+
if (minor === extendedOneByte ||
|
172
|
+
minor === extendedFloat16 ||
|
173
|
+
minor === extendedFloat32 ||
|
174
|
+
minor === extendedFloat64) {
|
175
|
+
const countLength = minorValueToArgumentLength[minor];
|
176
|
+
_offset = (countLength + 1);
|
177
|
+
if (to - at < _offset) {
|
178
|
+
throw new Error(`countLength ${countLength} greater than remaining buf len.`);
|
179
|
+
}
|
180
|
+
const countIndex = at + 1;
|
181
|
+
if (countLength === 1) {
|
182
|
+
return payload[countIndex];
|
183
|
+
}
|
184
|
+
else if (countLength === 2) {
|
185
|
+
return dataView.getUint16(countIndex);
|
186
|
+
}
|
187
|
+
else if (countLength === 4) {
|
188
|
+
return dataView.getUint32(countIndex);
|
189
|
+
}
|
190
|
+
return demote(dataView.getBigUint64(countIndex));
|
191
|
+
}
|
192
|
+
throw new Error(`unexpected minor value ${minor}.`);
|
193
|
+
}
|
194
|
+
function decodeUtf8String(at, to) {
|
195
|
+
const length = decodeCount(at, to);
|
196
|
+
const offset = _offset;
|
197
|
+
at += offset;
|
198
|
+
if (to - at < length) {
|
199
|
+
throw new Error(`string len ${length} greater than remaining buf len.`);
|
200
|
+
}
|
201
|
+
const value = bytesToUtf8(payload, at, at + length);
|
202
|
+
_offset = offset + length;
|
203
|
+
return value;
|
204
|
+
}
|
205
|
+
function decodeUtf8StringIndefinite(at, to) {
|
206
|
+
at += 1;
|
207
|
+
const vector = [];
|
208
|
+
for (const base = at; at < to;) {
|
209
|
+
if (payload[at] === 255) {
|
210
|
+
const data = alloc(vector.length);
|
211
|
+
data.set(vector, 0);
|
212
|
+
_offset = at - base + 2;
|
213
|
+
return bytesToUtf8(data, 0, data.length);
|
214
|
+
}
|
215
|
+
const major = (payload[at] & 224) >> 5;
|
216
|
+
const minor = payload[at] & 31;
|
217
|
+
if (major !== majorUtf8String) {
|
218
|
+
throw new Error(`unexpected major type ${major} in indefinite string.`);
|
219
|
+
}
|
220
|
+
if (minor === minorIndefinite) {
|
221
|
+
throw new Error("nested indefinite string.");
|
222
|
+
}
|
223
|
+
const bytes = decodeUnstructuredByteString(at, to);
|
224
|
+
const length = _offset;
|
225
|
+
at += length;
|
226
|
+
for (let i = 0; i < bytes.length; ++i) {
|
227
|
+
vector.push(bytes[i]);
|
228
|
+
}
|
229
|
+
}
|
230
|
+
throw new Error("expected break marker.");
|
231
|
+
}
|
232
|
+
function decodeUnstructuredByteString(at, to) {
|
233
|
+
const length = decodeCount(at, to);
|
234
|
+
const offset = _offset;
|
235
|
+
at += offset;
|
236
|
+
if (to - at < length) {
|
237
|
+
throw new Error(`unstructured byte string len ${length} greater than remaining buf len.`);
|
238
|
+
}
|
239
|
+
const value = payload.subarray(at, at + length);
|
240
|
+
_offset = offset + length;
|
241
|
+
return value;
|
242
|
+
}
|
243
|
+
function decodeUnstructuredByteStringIndefinite(at, to) {
|
244
|
+
at += 1;
|
245
|
+
const vector = [];
|
246
|
+
for (const base = at; at < to;) {
|
247
|
+
if (payload[at] === 255) {
|
248
|
+
const data = alloc(vector.length);
|
249
|
+
data.set(vector, 0);
|
250
|
+
_offset = at - base + 2;
|
251
|
+
return data;
|
252
|
+
}
|
253
|
+
const major = (payload[at] & 224) >> 5;
|
254
|
+
const minor = payload[at] & 31;
|
255
|
+
if (major !== majorUnstructuredByteString) {
|
256
|
+
throw new Error(`unexpected major type ${major} in indefinite string.`);
|
257
|
+
}
|
258
|
+
if (minor === minorIndefinite) {
|
259
|
+
throw new Error("nested indefinite string.");
|
260
|
+
}
|
261
|
+
const bytes = decodeUnstructuredByteString(at, to);
|
262
|
+
const length = _offset;
|
263
|
+
at += length;
|
264
|
+
for (let i = 0; i < bytes.length; ++i) {
|
265
|
+
vector.push(bytes[i]);
|
266
|
+
}
|
267
|
+
}
|
268
|
+
throw new Error("expected break marker.");
|
269
|
+
}
|
270
|
+
function decodeList(at, to) {
|
271
|
+
const listDataLength = decodeCount(at, to);
|
272
|
+
const offset = _offset;
|
273
|
+
at += offset;
|
274
|
+
const base = at;
|
275
|
+
const list = Array(listDataLength);
|
276
|
+
for (let i = 0; i < listDataLength; ++i) {
|
277
|
+
const item = decode(at, to);
|
278
|
+
const itemOffset = _offset;
|
279
|
+
list[i] = item;
|
280
|
+
at += itemOffset;
|
281
|
+
}
|
282
|
+
_offset = offset + (at - base);
|
283
|
+
return list;
|
284
|
+
}
|
285
|
+
function decodeListIndefinite(at, to) {
|
286
|
+
at += 1;
|
287
|
+
const list = [];
|
288
|
+
for (const base = at; at < to;) {
|
289
|
+
if (payload[at] === 255) {
|
290
|
+
_offset = at - base + 2;
|
291
|
+
return list;
|
292
|
+
}
|
293
|
+
const item = decode(at, to);
|
294
|
+
const n = _offset;
|
295
|
+
at += n;
|
296
|
+
list.push(item);
|
297
|
+
}
|
298
|
+
throw new Error("expected break marker.");
|
299
|
+
}
|
300
|
+
function decodeMap(at, to) {
|
301
|
+
const mapDataLength = decodeCount(at, to);
|
302
|
+
const offset = _offset;
|
303
|
+
at += offset;
|
304
|
+
const base = at;
|
305
|
+
const map = {};
|
306
|
+
for (let i = 0; i < mapDataLength; ++i) {
|
307
|
+
if (at >= to) {
|
308
|
+
throw new Error("unexpected end of map payload.");
|
309
|
+
}
|
310
|
+
const major = (payload[at] & 224) >> 5;
|
311
|
+
if (major !== majorUtf8String) {
|
312
|
+
throw new Error(`unexpected major type ${major} for map key at index ${at}.`);
|
313
|
+
}
|
314
|
+
const key = decode(at, to);
|
315
|
+
at += _offset;
|
316
|
+
const value = decode(at, to);
|
317
|
+
at += _offset;
|
318
|
+
map[key] = value;
|
319
|
+
}
|
320
|
+
_offset = offset + (at - base);
|
321
|
+
return map;
|
322
|
+
}
|
323
|
+
function decodeMapIndefinite(at, to) {
|
324
|
+
at += 1;
|
325
|
+
const base = at;
|
326
|
+
const map = {};
|
327
|
+
for (; at < to;) {
|
328
|
+
if (at >= to) {
|
329
|
+
throw new Error("unexpected end of map payload.");
|
330
|
+
}
|
331
|
+
if (payload[at] === 255) {
|
332
|
+
_offset = at - base + 2;
|
333
|
+
return map;
|
334
|
+
}
|
335
|
+
const major = (payload[at] & 224) >> 5;
|
336
|
+
if (major !== majorUtf8String) {
|
337
|
+
throw new Error(`unexpected major type ${major} for map key.`);
|
338
|
+
}
|
339
|
+
const key = decode(at, to);
|
340
|
+
at += _offset;
|
341
|
+
const value = decode(at, to);
|
342
|
+
at += _offset;
|
343
|
+
map[key] = value;
|
344
|
+
}
|
345
|
+
throw new Error("expected break marker.");
|
346
|
+
}
|
347
|
+
function decodeSpecial(at, to) {
|
348
|
+
const minor = payload[at] & 31;
|
349
|
+
switch (minor) {
|
350
|
+
case specialTrue:
|
351
|
+
case specialFalse:
|
352
|
+
_offset = 1;
|
353
|
+
return minor === specialTrue;
|
354
|
+
case specialNull:
|
355
|
+
_offset = 1;
|
356
|
+
return null;
|
357
|
+
case specialUndefined:
|
358
|
+
_offset = 1;
|
359
|
+
return null;
|
360
|
+
case extendedFloat16:
|
361
|
+
if (to - at < 3) {
|
362
|
+
throw new Error("incomplete float16 at end of buf.");
|
363
|
+
}
|
364
|
+
_offset = 3;
|
365
|
+
return bytesToFloat16(payload[at + 1], payload[at + 2]);
|
366
|
+
case extendedFloat32:
|
367
|
+
if (to - at < 5) {
|
368
|
+
throw new Error("incomplete float32 at end of buf.");
|
369
|
+
}
|
370
|
+
_offset = 5;
|
371
|
+
return dataView.getFloat32(at + 1);
|
372
|
+
case extendedFloat64:
|
373
|
+
if (to - at < 9) {
|
374
|
+
throw new Error("incomplete float64 at end of buf.");
|
375
|
+
}
|
376
|
+
_offset = 9;
|
377
|
+
return dataView.getFloat64(at + 1);
|
378
|
+
default:
|
379
|
+
throw new Error(`unexpected minor value ${minor}.`);
|
380
|
+
}
|
381
|
+
}
|
382
|
+
function castBigInt(bigInt) {
|
383
|
+
if (typeof bigInt === "number") {
|
384
|
+
return bigInt;
|
385
|
+
}
|
386
|
+
const num = Number(bigInt);
|
387
|
+
if (Number.MIN_SAFE_INTEGER <= num && num <= Number.MAX_SAFE_INTEGER) {
|
388
|
+
return num;
|
389
|
+
}
|
390
|
+
return bigInt;
|
391
|
+
}
|
@@ -0,0 +1,181 @@
|
|
1
|
+
import { fromUtf8 } from "@smithy/util-utf8";
|
2
|
+
import { extendedFloat16, extendedFloat32, extendedFloat64, majorList, majorMap, majorNegativeInt64, majorSpecial, majorUint64, majorUnstructuredByteString, majorUtf8String, specialFalse, specialNull, specialTrue, } from "./cbor-types";
|
3
|
+
import { alloc } from "./cbor-types";
|
4
|
+
const USE_BUFFER = typeof Buffer !== "undefined";
|
5
|
+
const initialSize = 2048;
|
6
|
+
let data = alloc(initialSize);
|
7
|
+
let dataView = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
8
|
+
let cursor = 0;
|
9
|
+
function ensureSpace(bytes) {
|
10
|
+
const remaining = data.byteLength - cursor;
|
11
|
+
if (remaining < bytes) {
|
12
|
+
if (cursor < 16000000) {
|
13
|
+
resize(Math.max(data.byteLength * 4, data.byteLength + bytes));
|
14
|
+
}
|
15
|
+
else {
|
16
|
+
resize(data.byteLength + bytes + 16000000);
|
17
|
+
}
|
18
|
+
}
|
19
|
+
}
|
20
|
+
export function toUint8Array() {
|
21
|
+
const out = alloc(cursor);
|
22
|
+
out.set(data.subarray(0, cursor), 0);
|
23
|
+
cursor = 0;
|
24
|
+
return out;
|
25
|
+
}
|
26
|
+
export function resize(size) {
|
27
|
+
const old = data;
|
28
|
+
data = alloc(size);
|
29
|
+
if (old) {
|
30
|
+
if (old.copy) {
|
31
|
+
old.copy(data, 0, 0, old.byteLength);
|
32
|
+
}
|
33
|
+
else {
|
34
|
+
data.set(old, 0);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
dataView = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
38
|
+
}
|
39
|
+
function encodeHeader(major, value) {
|
40
|
+
if (value < 24) {
|
41
|
+
data[cursor++] = (major << 5) | value;
|
42
|
+
}
|
43
|
+
else if (value < 1 << 8) {
|
44
|
+
data[cursor++] = (major << 5) | 24;
|
45
|
+
data[cursor++] = value;
|
46
|
+
}
|
47
|
+
else if (value < 1 << 16) {
|
48
|
+
data[cursor++] = (major << 5) | extendedFloat16;
|
49
|
+
dataView.setUint16(cursor, value);
|
50
|
+
cursor += 2;
|
51
|
+
}
|
52
|
+
else if (value < 2 ** 32) {
|
53
|
+
data[cursor++] = (major << 5) | extendedFloat32;
|
54
|
+
dataView.setUint32(cursor, value);
|
55
|
+
cursor += 4;
|
56
|
+
}
|
57
|
+
else {
|
58
|
+
data[cursor++] = (major << 5) | extendedFloat64;
|
59
|
+
dataView.setBigUint64(cursor, typeof value === "bigint" ? value : BigInt(value));
|
60
|
+
cursor += 8;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
export function encode(_input) {
|
64
|
+
const encodeStack = [_input];
|
65
|
+
while (encodeStack.length) {
|
66
|
+
const input = encodeStack.pop();
|
67
|
+
ensureSpace(typeof input === "string" ? input.length * 4 : 64);
|
68
|
+
if (typeof input === "string") {
|
69
|
+
if (USE_BUFFER) {
|
70
|
+
encodeHeader(majorUtf8String, Buffer.byteLength(input));
|
71
|
+
cursor += data.write(input, cursor);
|
72
|
+
}
|
73
|
+
else {
|
74
|
+
const bytes = fromUtf8(input);
|
75
|
+
encodeHeader(majorUtf8String, bytes.byteLength);
|
76
|
+
data.set(bytes, cursor);
|
77
|
+
cursor += bytes.byteLength;
|
78
|
+
}
|
79
|
+
continue;
|
80
|
+
}
|
81
|
+
else if (typeof input === "number") {
|
82
|
+
if (Number.isInteger(input)) {
|
83
|
+
const nonNegative = input >= 0;
|
84
|
+
const major = nonNegative ? majorUint64 : majorNegativeInt64;
|
85
|
+
const value = nonNegative ? input : -input - 1;
|
86
|
+
if (value < 24) {
|
87
|
+
data[cursor++] = (major << 5) | value;
|
88
|
+
}
|
89
|
+
else if (value < 256) {
|
90
|
+
data[cursor++] = (major << 5) | 24;
|
91
|
+
data[cursor++] = value;
|
92
|
+
}
|
93
|
+
else if (value < 65536) {
|
94
|
+
data[cursor++] = (major << 5) | extendedFloat16;
|
95
|
+
data[cursor++] = value >> 8;
|
96
|
+
data[cursor++] = value;
|
97
|
+
}
|
98
|
+
else if (value < 4294967296) {
|
99
|
+
data[cursor++] = (major << 5) | extendedFloat32;
|
100
|
+
dataView.setUint32(cursor, value);
|
101
|
+
cursor += 4;
|
102
|
+
}
|
103
|
+
else {
|
104
|
+
data[cursor++] = (major << 5) | extendedFloat64;
|
105
|
+
dataView.setBigUint64(cursor, BigInt(value));
|
106
|
+
cursor += 8;
|
107
|
+
}
|
108
|
+
continue;
|
109
|
+
}
|
110
|
+
data[cursor++] = (majorSpecial << 5) | extendedFloat64;
|
111
|
+
dataView.setFloat64(cursor, input);
|
112
|
+
cursor += 8;
|
113
|
+
continue;
|
114
|
+
}
|
115
|
+
else if (typeof input === "bigint") {
|
116
|
+
const nonNegative = input >= 0;
|
117
|
+
const major = nonNegative ? majorUint64 : majorNegativeInt64;
|
118
|
+
const value = nonNegative ? input : -input - BigInt(1);
|
119
|
+
const n = Number(value);
|
120
|
+
if (n < 24) {
|
121
|
+
data[cursor++] = (major << 5) | n;
|
122
|
+
}
|
123
|
+
else if (n < 256) {
|
124
|
+
data[cursor++] = (major << 5) | 24;
|
125
|
+
data[cursor++] = n;
|
126
|
+
}
|
127
|
+
else if (n < 65536) {
|
128
|
+
data[cursor++] = (major << 5) | extendedFloat16;
|
129
|
+
data[cursor++] = n >> 8;
|
130
|
+
data[cursor++] = n & 255;
|
131
|
+
}
|
132
|
+
else if (n < 4294967296) {
|
133
|
+
data[cursor++] = (major << 5) | extendedFloat32;
|
134
|
+
dataView.setUint32(cursor, n);
|
135
|
+
cursor += 4;
|
136
|
+
}
|
137
|
+
else {
|
138
|
+
data[cursor++] = (major << 5) | extendedFloat64;
|
139
|
+
dataView.setBigUint64(cursor, value);
|
140
|
+
cursor += 8;
|
141
|
+
}
|
142
|
+
continue;
|
143
|
+
}
|
144
|
+
else if (input === null) {
|
145
|
+
data[cursor++] = (majorSpecial << 5) | specialNull;
|
146
|
+
continue;
|
147
|
+
}
|
148
|
+
else if (typeof input === "boolean") {
|
149
|
+
data[cursor++] = (majorSpecial << 5) | (input ? specialTrue : specialFalse);
|
150
|
+
continue;
|
151
|
+
}
|
152
|
+
else if (typeof input === "undefined") {
|
153
|
+
throw new Error("@smithy/core/cbor: client may not serialize undefined value.");
|
154
|
+
}
|
155
|
+
else if (Array.isArray(input)) {
|
156
|
+
for (let i = input.length - 1; i >= 0; --i) {
|
157
|
+
encodeStack.push(input[i]);
|
158
|
+
}
|
159
|
+
encodeHeader(majorList, input.length);
|
160
|
+
continue;
|
161
|
+
}
|
162
|
+
else if (typeof input.byteLength === "number") {
|
163
|
+
ensureSpace(input.length * 2);
|
164
|
+
encodeHeader(majorUnstructuredByteString, input.length);
|
165
|
+
data.set(input, cursor);
|
166
|
+
cursor += input.byteLength;
|
167
|
+
continue;
|
168
|
+
}
|
169
|
+
else if (typeof input === "object") {
|
170
|
+
const keys = Object.keys(input);
|
171
|
+
for (let i = keys.length - 1; i >= 0; --i) {
|
172
|
+
const key = keys[i];
|
173
|
+
encodeStack.push(input[key]);
|
174
|
+
encodeStack.push(key);
|
175
|
+
}
|
176
|
+
encodeHeader(majorMap, keys.length);
|
177
|
+
continue;
|
178
|
+
}
|
179
|
+
throw new Error(`data type ${input?.constructor?.name ?? typeof input} not compatible for encoding.`);
|
180
|
+
}
|
181
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
export const majorUint64 = 0;
|
2
|
+
export const majorNegativeInt64 = 1;
|
3
|
+
export const majorUnstructuredByteString = 2;
|
4
|
+
export const majorUtf8String = 3;
|
5
|
+
export const majorList = 4;
|
6
|
+
export const majorMap = 5;
|
7
|
+
export const majorTag = 6;
|
8
|
+
export const majorSpecial = 7;
|
9
|
+
export const specialFalse = 20;
|
10
|
+
export const specialTrue = 21;
|
11
|
+
export const specialNull = 22;
|
12
|
+
export const specialUndefined = 23;
|
13
|
+
export const extendedOneByte = 24;
|
14
|
+
export const extendedFloat16 = 25;
|
15
|
+
export const extendedFloat32 = 26;
|
16
|
+
export const extendedFloat64 = 27;
|
17
|
+
export const minorIndefinite = 31;
|
18
|
+
export function alloc(size) {
|
19
|
+
return typeof Buffer !== "undefined" ? Buffer.alloc(size) : new Uint8Array(size);
|
20
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { decode, setPayload } from "./cbor-decode";
|
2
|
+
import { encode, resize, toUint8Array } from "./cbor-encode";
|
3
|
+
export const cbor = {
|
4
|
+
deserialize(payload) {
|
5
|
+
setPayload(payload);
|
6
|
+
return decode(0, payload.length);
|
7
|
+
},
|
8
|
+
serialize(input) {
|
9
|
+
encode(input);
|
10
|
+
return toUint8Array();
|
11
|
+
},
|
12
|
+
resizeEncodingBuffer(size) {
|
13
|
+
resize(size);
|
14
|
+
},
|
15
|
+
};
|
@@ -0,0 +1,82 @@
|
|
1
|
+
import { HttpRequest as __HttpRequest } from "@smithy/protocol-http";
|
2
|
+
import { collectBody } from "@smithy/smithy-client";
|
3
|
+
import { calculateBodyLength } from "@smithy/util-body-length-browser";
|
4
|
+
import { cbor } from "./cbor";
|
5
|
+
export const parseCborBody = (streamBody, context) => {
|
6
|
+
return collectBody(streamBody, context).then(async (bytes) => {
|
7
|
+
if (bytes.length) {
|
8
|
+
try {
|
9
|
+
return cbor.deserialize(bytes);
|
10
|
+
}
|
11
|
+
catch (e) {
|
12
|
+
Object.defineProperty(e, "$responseBodyText", {
|
13
|
+
value: context.utf8Encoder(bytes),
|
14
|
+
});
|
15
|
+
throw e;
|
16
|
+
}
|
17
|
+
}
|
18
|
+
return {};
|
19
|
+
});
|
20
|
+
};
|
21
|
+
export const dateToTag = (date) => {
|
22
|
+
return {
|
23
|
+
tag: 1,
|
24
|
+
value: date.getTime() / 1000,
|
25
|
+
};
|
26
|
+
};
|
27
|
+
export const parseCborErrorBody = async (errorBody, context) => {
|
28
|
+
const value = await parseCborBody(errorBody, context);
|
29
|
+
value.message = value.message ?? value.Message;
|
30
|
+
return value;
|
31
|
+
};
|
32
|
+
export const loadSmithyRpcV2CborErrorCode = (output, data) => {
|
33
|
+
const sanitizeErrorCode = (rawValue) => {
|
34
|
+
let cleanValue = rawValue;
|
35
|
+
if (typeof cleanValue === "number") {
|
36
|
+
cleanValue = cleanValue.toString();
|
37
|
+
}
|
38
|
+
if (cleanValue.indexOf(",") >= 0) {
|
39
|
+
cleanValue = cleanValue.split(",")[0];
|
40
|
+
}
|
41
|
+
if (cleanValue.indexOf(":") >= 0) {
|
42
|
+
cleanValue = cleanValue.split(":")[0];
|
43
|
+
}
|
44
|
+
if (cleanValue.indexOf("#") >= 0) {
|
45
|
+
cleanValue = cleanValue.split("#")[1];
|
46
|
+
}
|
47
|
+
return cleanValue;
|
48
|
+
};
|
49
|
+
if (data["__type"] !== undefined) {
|
50
|
+
return sanitizeErrorCode(data["__type"]);
|
51
|
+
}
|
52
|
+
if (data.code !== undefined) {
|
53
|
+
return sanitizeErrorCode(data.code);
|
54
|
+
}
|
55
|
+
};
|
56
|
+
export const checkCborResponse = (response) => {
|
57
|
+
if (String(response.headers["smithy-protocol"]).toLowerCase() !== "rpc-v2-cbor") {
|
58
|
+
throw new Error("Malformed RPCv2 CBOR response, status: " + response.statusCode);
|
59
|
+
}
|
60
|
+
};
|
61
|
+
export const buildHttpRpcRequest = async (context, headers, path, resolvedHostname, body) => {
|
62
|
+
const { hostname, protocol = "https", port, path: basePath } = await context.endpoint();
|
63
|
+
const contents = {
|
64
|
+
protocol,
|
65
|
+
hostname,
|
66
|
+
port,
|
67
|
+
method: "POST",
|
68
|
+
path: basePath.endsWith("/") ? basePath.slice(0, -1) + path : basePath + path,
|
69
|
+
headers,
|
70
|
+
};
|
71
|
+
if (resolvedHostname !== undefined) {
|
72
|
+
contents.hostname = resolvedHostname;
|
73
|
+
}
|
74
|
+
if (body !== undefined) {
|
75
|
+
contents.body = body;
|
76
|
+
try {
|
77
|
+
contents.headers["content-length"] = String(calculateBodyLength(body));
|
78
|
+
}
|
79
|
+
catch (e) { }
|
80
|
+
}
|
81
|
+
return new __HttpRequest(contents);
|
82
|
+
};
|