@psnext/slingcli 2.5.20260727-1 → 2.5.20260728-1
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/node_modules/@aws-sdk/credential-provider-env/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-http/node_modules/@smithy/node-http-handler/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-http/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-ini/package.json +9 -9
- package/node_modules/@aws-sdk/credential-provider-login/package.json +3 -3
- package/node_modules/@aws-sdk/credential-provider-node/package.json +7 -7
- package/node_modules/@aws-sdk/credential-provider-process/package.json +2 -2
- package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/package.json +3 -3
- package/node_modules/@aws-sdk/credential-provider-sso/package.json +4 -4
- package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +3 -3
- package/node_modules/@aws-sdk/middleware-websocket/package.json +2 -2
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/cognito-identity/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/index.js +1 -1
- package/node_modules/@aws-sdk/nested-clients/node_modules/@smithy/node-http-handler/package.json +2 -2
- package/node_modules/@aws-sdk/nested-clients/package.json +2 -2
- package/node_modules/@smithy/core/dist-cjs/submodules/cbor/index.js +15 -13
- package/node_modules/@smithy/core/dist-cjs/submodules/schema/index.js +3 -0
- package/node_modules/@smithy/core/dist-es/submodules/cbor/CborCodec.js +2 -203
- package/node_modules/@smithy/core/dist-es/submodules/cbor/codec-v1/CborShapeDeserializer.js +113 -0
- package/node_modules/@smithy/core/dist-es/submodules/cbor/codec-v1/CborShapeSerializer.js +95 -0
- package/node_modules/@smithy/core/dist-es/submodules/cbor/codec-v2/SinglePassCborShapeDeserializer.js +609 -0
- package/node_modules/@smithy/core/dist-es/submodules/cbor/codec-v2/SinglePassCborShapeSerializer.js +611 -0
- package/node_modules/@smithy/core/dist-es/submodules/cbor/index.js +3 -1
- package/node_modules/@smithy/core/dist-es/submodules/schema/schemas/NormalizedSchema.js +3 -0
- package/node_modules/@smithy/core/dist-types/submodules/cbor/CborCodec.d.ts +3 -25
- package/node_modules/@smithy/core/dist-types/submodules/cbor/SmithyRpcV2CborProtocol.d.ts +2 -2
- package/node_modules/@smithy/core/dist-types/submodules/cbor/codec-v1/CborShapeDeserializer.d.ts +13 -0
- package/node_modules/@smithy/core/dist-types/submodules/cbor/codec-v1/CborShapeSerializer.d.ts +15 -0
- package/node_modules/@smithy/core/dist-types/submodules/cbor/codec-v2/SinglePassCborShapeDeserializer.d.ts +19 -0
- package/node_modules/@smithy/core/dist-types/submodules/cbor/codec-v2/SinglePassCborShapeSerializer.d.ts +22 -0
- package/node_modules/@smithy/core/dist-types/submodules/cbor/index.d.ts +3 -1
- package/node_modules/@smithy/core/dist-types/submodules/schema/schemas/NormalizedSchema.d.ts +12 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/cbor/CborCodec.d.ts +3 -25
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/cbor/SmithyRpcV2CborProtocol.d.ts +2 -2
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/cbor/codec-v1/CborShapeDeserializer.d.ts +13 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/cbor/codec-v1/CborShapeSerializer.d.ts +15 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/cbor/codec-v2/SinglePassCborShapeDeserializer.d.ts +19 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/cbor/codec-v2/SinglePassCborShapeSerializer.d.ts +22 -0
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/cbor/index.d.ts +3 -1
- package/node_modules/@smithy/core/dist-types/ts3.4/submodules/schema/schemas/NormalizedSchema.d.ts +12 -0
- package/node_modules/@smithy/core/package.json +2 -1
- package/node_modules/@smithy/credential-provider-imds/package.json +2 -2
- package/node_modules/@smithy/fetch-http-handler/package.json +2 -2
- package/node_modules/@smithy/signature-v4/package.json +2 -2
- package/node_modules/@types/node/README.md +1 -1
- package/node_modules/@types/node/crypto.d.ts +1 -1
- package/node_modules/@types/node/package.json +2 -2
- package/package.json +2 -2
- package/slingshot/index.js +9 -9
package/node_modules/@smithy/core/dist-es/submodules/cbor/codec-v2/SinglePassCborShapeSerializer.js
ADDED
|
@@ -0,0 +1,611 @@
|
|
|
1
|
+
import { SerdeContext } from "@smithy/core/protocols";
|
|
2
|
+
import { NormalizedSchema } from "@smithy/core/schema";
|
|
3
|
+
import { NumericValue, fromBase64, generateIdempotencyToken } from "@smithy/core/serde";
|
|
4
|
+
import { extendedFloat16, extendedFloat32, extendedFloat64, majorList, majorMap, majorNegativeInt64, majorSpecial, majorTag, majorUint64, majorUnstructuredByteString, majorUtf8String, specialFalse, specialNull, specialTrue, tagSymbol, } from "../cbor-types";
|
|
5
|
+
export class SinglePassCborShapeSerializer extends SerdeContext {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
activateCborStructIterator();
|
|
9
|
+
}
|
|
10
|
+
write(schema, value) {
|
|
11
|
+
cursor = 0;
|
|
12
|
+
const ns = NormalizedSchema.of(schema);
|
|
13
|
+
writeValue(ns, value, undefined, this.serdeContext);
|
|
14
|
+
}
|
|
15
|
+
flush() {
|
|
16
|
+
const result = buf.subarray(0, cursor);
|
|
17
|
+
cursor = 0;
|
|
18
|
+
buf = allocUnsafe(INITIAL_BUFFER_SIZE);
|
|
19
|
+
view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export function advanceSinglePassEncodingEpoch() {
|
|
24
|
+
encodeCacheEpoch = (encodeCacheEpoch + 1) & 0xffff;
|
|
25
|
+
encodeCacheSaturated = false;
|
|
26
|
+
}
|
|
27
|
+
export function activateCborStructIterator() {
|
|
28
|
+
NormalizedSchema.prototype.structIteratorCbor = function () {
|
|
29
|
+
return loadCborStructIterator(this);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const CBOR_STRUCT_CACHE = Symbol.for("@smithy/cbor-struct-cache");
|
|
33
|
+
function loadCborStructIterator(ns) {
|
|
34
|
+
const schema = ns.getSchema();
|
|
35
|
+
const existing = schema[CBOR_STRUCT_CACHE];
|
|
36
|
+
if (existing) {
|
|
37
|
+
return existing;
|
|
38
|
+
}
|
|
39
|
+
const memberNames = [];
|
|
40
|
+
const memberSchemas = [];
|
|
41
|
+
for (const [name, memberSchema] of ns.structIterator()) {
|
|
42
|
+
memberNames.push(name);
|
|
43
|
+
memberSchemas.push(memberSchema);
|
|
44
|
+
}
|
|
45
|
+
const encodedKeys = new Array(memberNames.length);
|
|
46
|
+
for (let i = 0; i < memberNames.length; ++i) {
|
|
47
|
+
encodedKeys[i] = encodeCborStringKey(memberNames[i]);
|
|
48
|
+
}
|
|
49
|
+
const cache = { memberNames, memberSchemas, encodedKeys };
|
|
50
|
+
schema[CBOR_STRUCT_CACHE] = cache;
|
|
51
|
+
return cache;
|
|
52
|
+
}
|
|
53
|
+
function encodeCborStringKey(s) {
|
|
54
|
+
let utf8Bytes;
|
|
55
|
+
if (USE_BUFFER) {
|
|
56
|
+
utf8Bytes = Buffer.from(s, "utf-8");
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
utf8Bytes = new TextEncoder().encode(s);
|
|
60
|
+
}
|
|
61
|
+
const byteLen = utf8Bytes.length;
|
|
62
|
+
let headerSize;
|
|
63
|
+
if (byteLen < 24) {
|
|
64
|
+
headerSize = 1;
|
|
65
|
+
}
|
|
66
|
+
else if (byteLen < 256) {
|
|
67
|
+
headerSize = 2;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
headerSize = 3;
|
|
71
|
+
}
|
|
72
|
+
const result = new Uint8Array(headerSize + byteLen);
|
|
73
|
+
if (headerSize === 1) {
|
|
74
|
+
result[0] = (majorUtf8String << 5) | byteLen;
|
|
75
|
+
}
|
|
76
|
+
else if (headerSize === 2) {
|
|
77
|
+
result[0] = (majorUtf8String << 5) | 24;
|
|
78
|
+
result[1] = byteLen;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
result[0] = (majorUtf8String << 5) | extendedFloat16;
|
|
82
|
+
result[1] = byteLen >> 8;
|
|
83
|
+
result[2] = byteLen & 0xff;
|
|
84
|
+
}
|
|
85
|
+
result.set(utf8Bytes, headerSize);
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
const USE_BUFFER = typeof Buffer !== "undefined";
|
|
89
|
+
const textEncoder = new TextEncoder();
|
|
90
|
+
const INITIAL_BUFFER_SIZE = 2048;
|
|
91
|
+
let buf = USE_BUFFER ? Buffer.allocUnsafe(INITIAL_BUFFER_SIZE) : new Uint8Array(INITIAL_BUFFER_SIZE);
|
|
92
|
+
let view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
93
|
+
let cursor = 0;
|
|
94
|
+
const STRING_CACHE_MAX = 2048;
|
|
95
|
+
const stringEncodeCache = new Map();
|
|
96
|
+
let encodeCacheEpoch = 0;
|
|
97
|
+
let encodeCacheSaturated = false;
|
|
98
|
+
function allocUnsafe(size) {
|
|
99
|
+
return USE_BUFFER ? Buffer.allocUnsafe(size) : new Uint8Array(size);
|
|
100
|
+
}
|
|
101
|
+
function writeValue(ns, value, container, serdeContext) {
|
|
102
|
+
if (value == null) {
|
|
103
|
+
if (value === undefined && ns.isIdempotencyToken()) {
|
|
104
|
+
writeString(generateIdempotencyToken());
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (value === undefined) {
|
|
108
|
+
ensure(1);
|
|
109
|
+
buf[cursor++] = (majorSpecial << 5) | specialNull;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
ensure(1);
|
|
113
|
+
buf[cursor++] = (majorSpecial << 5) | specialNull;
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const isObject = typeof value === "object";
|
|
117
|
+
if (isObject) {
|
|
118
|
+
if (ns.isBlobSchema()) {
|
|
119
|
+
if (value instanceof Uint8Array) {
|
|
120
|
+
writeBytes(value);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (ns.isTimestampSchema()) {
|
|
125
|
+
if (value instanceof Date) {
|
|
126
|
+
writeTimestamp(value);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (ns.isStructSchema()) {
|
|
131
|
+
writeStruct(ns, value, serdeContext);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (Array.isArray(value) && (ns.isListSchema() || ns.isDocumentSchema())) {
|
|
135
|
+
writeList(ns, value, ns.isDocumentSchema(), serdeContext);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (ns.isMapSchema()) {
|
|
139
|
+
writeMap(ns, value, false, serdeContext);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (value instanceof Date) {
|
|
143
|
+
writeTimestamp(value);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (value instanceof Uint8Array) {
|
|
147
|
+
writeBytes(value);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (value instanceof NumericValue) {
|
|
151
|
+
writeNumericValue(value);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (value[tagSymbol]) {
|
|
155
|
+
const tagged = value;
|
|
156
|
+
writeTag(tagged.tag, tagged.value);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (ns.isDocumentSchema()) {
|
|
160
|
+
if (Array.isArray(value)) {
|
|
161
|
+
writeList(ns, value, true, serdeContext);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
writeMap(ns, value, true, serdeContext);
|
|
165
|
+
}
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (ns.isBigDecimalSchema()) {
|
|
169
|
+
writeUntypedValue(value);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
writeMap(ns, value, true, serdeContext);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (typeof value === "string") {
|
|
176
|
+
if (ns.isBlobSchema()) {
|
|
177
|
+
const bytes = (serdeContext?.base64Decoder ?? fromBase64)(value);
|
|
178
|
+
writeBytes(bytes);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
writeString(value);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
if (typeof value === "number") {
|
|
185
|
+
ensure(9);
|
|
186
|
+
if (Number.isInteger(value) && value >= -0x20000000000000 && value <= 0x1fffffffffffff) {
|
|
187
|
+
writeInteger(value);
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
writeFloat64(value);
|
|
191
|
+
}
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (typeof value === "boolean") {
|
|
195
|
+
ensure(1);
|
|
196
|
+
buf[cursor++] = (majorSpecial << 5) | (value ? specialTrue : specialFalse);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (typeof value === "bigint") {
|
|
200
|
+
writeBigInt(value);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
writeString(String(value));
|
|
204
|
+
}
|
|
205
|
+
function writeStruct(ns, value, serdeContext) {
|
|
206
|
+
if (ns.isUnionSchema()) {
|
|
207
|
+
let wrote = false;
|
|
208
|
+
for (const [memberName, memberSchema] of ns.structIterator()) {
|
|
209
|
+
const item = value[memberName];
|
|
210
|
+
if (item != null) {
|
|
211
|
+
ensure(9);
|
|
212
|
+
encodeHeader(majorMap, 1);
|
|
213
|
+
writeString(memberName);
|
|
214
|
+
writeValue(memberSchema, item, ns, serdeContext);
|
|
215
|
+
wrote = true;
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (!wrote) {
|
|
220
|
+
const { $unknown } = value;
|
|
221
|
+
if (Array.isArray($unknown)) {
|
|
222
|
+
ensure(9);
|
|
223
|
+
encodeHeader(majorMap, 1);
|
|
224
|
+
writeString($unknown[0]);
|
|
225
|
+
writeUntypedValue($unknown[1]);
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
ensure(9);
|
|
229
|
+
encodeHeader(majorMap, 0);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const cache = ns.structIteratorCbor();
|
|
235
|
+
const { memberNames, memberSchemas, encodedKeys } = cache;
|
|
236
|
+
const z = memberNames.length;
|
|
237
|
+
let headerSize;
|
|
238
|
+
if (z < 24) {
|
|
239
|
+
headerSize = 1;
|
|
240
|
+
}
|
|
241
|
+
else if (z < 256) {
|
|
242
|
+
headerSize = 2;
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
headerSize = 3;
|
|
246
|
+
}
|
|
247
|
+
ensure(headerSize);
|
|
248
|
+
const headerPos = cursor;
|
|
249
|
+
cursor += headerSize;
|
|
250
|
+
let count = 0;
|
|
251
|
+
for (let i = 0; i < z; ++i) {
|
|
252
|
+
const item = value[memberNames[i]];
|
|
253
|
+
if (item == null && !memberSchemas[i].isIdempotencyToken()) {
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
const key = encodedKeys[i];
|
|
257
|
+
ensure(key.length);
|
|
258
|
+
buf.set(key, cursor);
|
|
259
|
+
cursor += key.length;
|
|
260
|
+
writeValue(memberSchemas[i], item, ns, serdeContext);
|
|
261
|
+
++count;
|
|
262
|
+
}
|
|
263
|
+
if (typeof value.__type === "string") {
|
|
264
|
+
for (const k in value) {
|
|
265
|
+
if (!memberNames.includes(k)) {
|
|
266
|
+
writeString(k);
|
|
267
|
+
writeUntypedValue(value[k]);
|
|
268
|
+
++count;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (headerSize === 1) {
|
|
273
|
+
buf[headerPos] = (majorMap << 5) | count;
|
|
274
|
+
}
|
|
275
|
+
else if (headerSize === 2) {
|
|
276
|
+
buf[headerPos] = (majorMap << 5) | 24;
|
|
277
|
+
buf[headerPos + 1] = count;
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
buf[headerPos] = (majorMap << 5) | extendedFloat16;
|
|
281
|
+
buf[headerPos + 1] = count >> 8;
|
|
282
|
+
buf[headerPos + 2] = count & 0xff;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
function writeList(ns, value, isDocument, serdeContext) {
|
|
286
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
287
|
+
const valueSchema = ns.getValueSchema();
|
|
288
|
+
if (isDocument || sparse) {
|
|
289
|
+
const items = [];
|
|
290
|
+
for (let i = 0; i < value.length; ++i) {
|
|
291
|
+
const item = value[i];
|
|
292
|
+
if (isDocument) {
|
|
293
|
+
if (item !== undefined) {
|
|
294
|
+
items.push(item);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
if (item != null || sparse) {
|
|
299
|
+
items.push(item);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
ensure(9);
|
|
304
|
+
encodeHeader(majorList, items.length);
|
|
305
|
+
for (let i = 0; i < items.length; ++i) {
|
|
306
|
+
writeValue(valueSchema, items[i], undefined, serdeContext);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
let count = 0;
|
|
311
|
+
for (let i = 0; i < value.length; ++i) {
|
|
312
|
+
if (value[i] != null) {
|
|
313
|
+
++count;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
ensure(9);
|
|
317
|
+
encodeHeader(majorList, count);
|
|
318
|
+
for (let i = 0; i < value.length; ++i) {
|
|
319
|
+
if (value[i] != null) {
|
|
320
|
+
writeValue(valueSchema, value[i], undefined, serdeContext);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
function writeMap(ns, value, isDocument, serdeContext) {
|
|
326
|
+
const sparse = !!ns.getMergedTraits().sparse;
|
|
327
|
+
const valueSchema = ns.getValueSchema();
|
|
328
|
+
const keys = [];
|
|
329
|
+
for (const k in value) {
|
|
330
|
+
const v = value[k];
|
|
331
|
+
if (isDocument ? v !== undefined : v != null || sparse) {
|
|
332
|
+
keys.push(k);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
ensure(9);
|
|
336
|
+
encodeHeader(majorMap, keys.length);
|
|
337
|
+
for (let i = 0; i < keys.length; ++i) {
|
|
338
|
+
const k = keys[i];
|
|
339
|
+
writeString(k);
|
|
340
|
+
writeValue(valueSchema, value[k], undefined, serdeContext);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
function writeUntypedValue(value) {
|
|
344
|
+
if (value == null) {
|
|
345
|
+
ensure(1);
|
|
346
|
+
buf[cursor++] = (majorSpecial << 5) | specialNull;
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
if (typeof value === "string") {
|
|
350
|
+
writeString(value);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
if (typeof value === "number") {
|
|
354
|
+
ensure(9);
|
|
355
|
+
if (Number.isInteger(value) && value >= -0x20000000000000 && value <= 0x1fffffffffffff) {
|
|
356
|
+
writeInteger(value);
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
writeFloat64(value);
|
|
360
|
+
}
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
if (typeof value === "boolean") {
|
|
364
|
+
ensure(1);
|
|
365
|
+
buf[cursor++] = (majorSpecial << 5) | (value ? specialTrue : specialFalse);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
if (typeof value === "bigint") {
|
|
369
|
+
writeBigInt(value);
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
if (value instanceof Uint8Array) {
|
|
373
|
+
writeBytes(value);
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
if (value instanceof Date) {
|
|
377
|
+
writeTimestamp(value);
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
if (value instanceof NumericValue) {
|
|
381
|
+
writeNumericValue(value);
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
if (value[tagSymbol]) {
|
|
385
|
+
const tagged = value;
|
|
386
|
+
writeTag(tagged.tag, tagged.value);
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
if (Array.isArray(value)) {
|
|
390
|
+
ensure(9);
|
|
391
|
+
encodeHeader(majorList, value.length);
|
|
392
|
+
for (let i = 0; i < value.length; ++i) {
|
|
393
|
+
writeUntypedValue(value[i]);
|
|
394
|
+
}
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
if (typeof value === "object") {
|
|
398
|
+
const keys = Object.keys(value);
|
|
399
|
+
ensure(9);
|
|
400
|
+
encodeHeader(majorMap, keys.length);
|
|
401
|
+
for (let i = 0; i < keys.length; ++i) {
|
|
402
|
+
writeString(keys[i]);
|
|
403
|
+
writeUntypedValue(value[keys[i]]);
|
|
404
|
+
}
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
writeString(String(value));
|
|
408
|
+
}
|
|
409
|
+
function ensure(n) {
|
|
410
|
+
if (cursor + n > buf.length) {
|
|
411
|
+
let newSize = buf.length * 2;
|
|
412
|
+
while (newSize < cursor + n) {
|
|
413
|
+
newSize *= 2;
|
|
414
|
+
}
|
|
415
|
+
const next = allocUnsafe(newSize);
|
|
416
|
+
next.set(buf.subarray(0, cursor));
|
|
417
|
+
buf = next;
|
|
418
|
+
view = new DataView(next.buffer, next.byteOffset, next.byteLength);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
function encodeHeader(major, value) {
|
|
422
|
+
if (value < 24) {
|
|
423
|
+
buf[cursor++] = (major << 5) | value;
|
|
424
|
+
}
|
|
425
|
+
else if (value < 256) {
|
|
426
|
+
buf[cursor++] = (major << 5) | 24;
|
|
427
|
+
buf[cursor++] = value;
|
|
428
|
+
}
|
|
429
|
+
else if (value < 65536) {
|
|
430
|
+
buf[cursor++] = (major << 5) | extendedFloat16;
|
|
431
|
+
buf[cursor++] = value >> 8;
|
|
432
|
+
buf[cursor++] = value & 0xff;
|
|
433
|
+
}
|
|
434
|
+
else if (value < 4294967296) {
|
|
435
|
+
buf[cursor++] = (major << 5) | extendedFloat32;
|
|
436
|
+
view.setUint32(cursor, value);
|
|
437
|
+
cursor += 4;
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
buf[cursor++] = (major << 5) | extendedFloat64;
|
|
441
|
+
const hi = (value / 4294967296) | 0;
|
|
442
|
+
const lo = (value - hi * 4294967296) | 0;
|
|
443
|
+
view.setUint32(cursor, hi);
|
|
444
|
+
view.setUint32(cursor + 4, lo);
|
|
445
|
+
cursor += 8;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
function encodeBigHeader(major, value) {
|
|
449
|
+
const n = Number(value);
|
|
450
|
+
if (n < 4294967296) {
|
|
451
|
+
encodeHeader(major, n);
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
buf[cursor++] = (major << 5) | extendedFloat64;
|
|
455
|
+
view.setBigUint64(cursor, value);
|
|
456
|
+
cursor += 8;
|
|
457
|
+
}
|
|
458
|
+
function writeString(s) {
|
|
459
|
+
const len = s.length;
|
|
460
|
+
if (len <= 23) {
|
|
461
|
+
const cached = stringEncodeCache.get(s);
|
|
462
|
+
if (cached) {
|
|
463
|
+
ensure(cached.bytes.length);
|
|
464
|
+
buf.set(cached.bytes, cursor);
|
|
465
|
+
cursor += cached.bytes.length;
|
|
466
|
+
cached.epoch = encodeCacheEpoch;
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
const start = cursor;
|
|
470
|
+
writeStringUncached(s, len);
|
|
471
|
+
const end = cursor;
|
|
472
|
+
const bytes = Uint8Array.prototype.slice.call(buf, start, end);
|
|
473
|
+
if (stringEncodeCache.size >= STRING_CACHE_MAX) {
|
|
474
|
+
if (encodeCacheSaturated) {
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
let evicted = 0;
|
|
478
|
+
for (const [key, entry] of stringEncodeCache) {
|
|
479
|
+
if (evicted >= 1024) {
|
|
480
|
+
break;
|
|
481
|
+
}
|
|
482
|
+
if (entry.epoch !== encodeCacheEpoch) {
|
|
483
|
+
stringEncodeCache.delete(key);
|
|
484
|
+
++evicted;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
if (evicted === 0) {
|
|
488
|
+
encodeCacheSaturated = true;
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
if (stringEncodeCache.size < STRING_CACHE_MAX) {
|
|
493
|
+
stringEncodeCache.set(s, { epoch: encodeCacheEpoch, bytes });
|
|
494
|
+
}
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
writeStringUncached(s, len);
|
|
498
|
+
}
|
|
499
|
+
function writeStringUncached(s, len) {
|
|
500
|
+
if (USE_BUFFER) {
|
|
501
|
+
const maxBytes = len * 3;
|
|
502
|
+
ensure(maxBytes + 9);
|
|
503
|
+
const byteLen = Buffer.byteLength(s);
|
|
504
|
+
encodeHeader(majorUtf8String, byteLen);
|
|
505
|
+
cursor += buf.write(s, cursor);
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
const maxBytes = len * 3;
|
|
509
|
+
ensure(maxBytes + 9);
|
|
510
|
+
const headerPos = cursor;
|
|
511
|
+
const result = textEncoder.encodeInto(s, buf.subarray(headerPos + 9));
|
|
512
|
+
const byteLen = result.written;
|
|
513
|
+
let headerSize;
|
|
514
|
+
if (byteLen < 24) {
|
|
515
|
+
headerSize = 1;
|
|
516
|
+
}
|
|
517
|
+
else if (byteLen < 256) {
|
|
518
|
+
headerSize = 2;
|
|
519
|
+
}
|
|
520
|
+
else if (byteLen < 65536) {
|
|
521
|
+
headerSize = 3;
|
|
522
|
+
}
|
|
523
|
+
else if (byteLen < 4294967296) {
|
|
524
|
+
headerSize = 5;
|
|
525
|
+
}
|
|
526
|
+
else {
|
|
527
|
+
headerSize = 9;
|
|
528
|
+
}
|
|
529
|
+
if (headerSize < 9) {
|
|
530
|
+
buf.copyWithin(headerPos + headerSize, headerPos + 9, headerPos + 9 + byteLen);
|
|
531
|
+
}
|
|
532
|
+
cursor = headerPos;
|
|
533
|
+
encodeHeader(majorUtf8String, byteLen);
|
|
534
|
+
cursor += byteLen;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
function writeFloat64(value) {
|
|
538
|
+
ensure(9);
|
|
539
|
+
buf[cursor++] = (majorSpecial << 5) | extendedFloat64;
|
|
540
|
+
view.setFloat64(cursor, value);
|
|
541
|
+
cursor += 8;
|
|
542
|
+
}
|
|
543
|
+
function writeInteger(value) {
|
|
544
|
+
ensure(9);
|
|
545
|
+
const nonNegative = value >= 0;
|
|
546
|
+
const major = nonNegative ? majorUint64 : majorNegativeInt64;
|
|
547
|
+
const abs = nonNegative ? value : -value - 1;
|
|
548
|
+
encodeHeader(major, abs);
|
|
549
|
+
}
|
|
550
|
+
function writeBigInt(value) {
|
|
551
|
+
const nonNegative = value >= 0;
|
|
552
|
+
const major = nonNegative ? majorUint64 : majorNegativeInt64;
|
|
553
|
+
const abs = nonNegative ? value : -value - BigInt(1);
|
|
554
|
+
if (abs < BigInt("18446744073709551616")) {
|
|
555
|
+
ensure(9);
|
|
556
|
+
encodeBigHeader(major, abs);
|
|
557
|
+
}
|
|
558
|
+
else {
|
|
559
|
+
const binaryStr = abs.toString(2);
|
|
560
|
+
const byteLen = Math.ceil(binaryStr.length / 8);
|
|
561
|
+
const bigIntBytes = new Uint8Array(byteLen);
|
|
562
|
+
let b = abs;
|
|
563
|
+
for (let i = byteLen - 1; i >= 0; --i) {
|
|
564
|
+
bigIntBytes[i] = Number(b & BigInt(255));
|
|
565
|
+
b >>= BigInt(8);
|
|
566
|
+
}
|
|
567
|
+
ensure(byteLen + 16);
|
|
568
|
+
buf[cursor++] = nonNegative ? 0b110_00010 : 0b110_00011;
|
|
569
|
+
encodeHeader(majorUnstructuredByteString, byteLen);
|
|
570
|
+
buf.set(bigIntBytes, cursor);
|
|
571
|
+
cursor += byteLen;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
function writeBytes(data) {
|
|
575
|
+
ensure(data.length + 9);
|
|
576
|
+
encodeHeader(majorUnstructuredByteString, data.length);
|
|
577
|
+
buf.set(data, cursor);
|
|
578
|
+
cursor += data.length;
|
|
579
|
+
}
|
|
580
|
+
function writeTag(tagValue, innerValue) {
|
|
581
|
+
ensure(9);
|
|
582
|
+
if (typeof tagValue === "bigint") {
|
|
583
|
+
encodeBigHeader(majorTag, tagValue);
|
|
584
|
+
}
|
|
585
|
+
else {
|
|
586
|
+
encodeHeader(majorTag, tagValue);
|
|
587
|
+
}
|
|
588
|
+
writeUntypedValue(innerValue);
|
|
589
|
+
}
|
|
590
|
+
function writeNumericValue(nv) {
|
|
591
|
+
const decimalIndex = nv.string.indexOf(".");
|
|
592
|
+
const exponent = decimalIndex === -1 ? 0 : decimalIndex - nv.string.length + 1;
|
|
593
|
+
const mantissa = BigInt(nv.string.replace(".", ""));
|
|
594
|
+
ensure(9);
|
|
595
|
+
buf[cursor++] = 0b110_00100;
|
|
596
|
+
encodeHeader(majorList, 2);
|
|
597
|
+
ensure(9);
|
|
598
|
+
writeInteger(exponent);
|
|
599
|
+
writeBigInt(mantissa);
|
|
600
|
+
}
|
|
601
|
+
function writeTimestamp(date) {
|
|
602
|
+
ensure(18);
|
|
603
|
+
encodeHeader(majorTag, 1);
|
|
604
|
+
const epochSecs = date.getTime() / 1000;
|
|
605
|
+
if (Number.isInteger(epochSecs)) {
|
|
606
|
+
writeInteger(epochSecs);
|
|
607
|
+
}
|
|
608
|
+
else {
|
|
609
|
+
writeFloat64(epochSecs);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
@@ -2,4 +2,6 @@ export { cbor } from "./cbor";
|
|
|
2
2
|
export { tag, tagSymbol } from "./cbor-types";
|
|
3
3
|
export { buildHttpRpcRequest, checkCborResponse, dateToTag, loadSmithyRpcV2CborErrorCode, parseCborBody, parseCborErrorBody, } from "./parseCborBody";
|
|
4
4
|
export { SmithyRpcV2CborProtocol } from "./SmithyRpcV2CborProtocol";
|
|
5
|
-
export { CborCodec
|
|
5
|
+
export { CborCodec } from "./CborCodec";
|
|
6
|
+
export { CborShapeSerializer } from "./codec-v1/CborShapeSerializer";
|
|
7
|
+
export { CborShapeDeserializer } from "./codec-v1/CborShapeDeserializer";
|
|
@@ -288,6 +288,9 @@ export class NormalizedSchema {
|
|
|
288
288
|
}
|
|
289
289
|
struct[anno.it] = it;
|
|
290
290
|
}
|
|
291
|
+
structIteratorCbor() {
|
|
292
|
+
throw new Error("@smithy/core/schema - structIteratorCbor not loaded.");
|
|
293
|
+
}
|
|
291
294
|
}
|
|
292
295
|
function member(memberSchema, memberName) {
|
|
293
296
|
if (memberSchema instanceof NormalizedSchema) {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { SerdeContext } from "@smithy/core/protocols";
|
|
2
|
-
import type { Codec
|
|
2
|
+
import type { Codec } from "@smithy/types";
|
|
3
|
+
import { CborShapeSerializer } from "./codec-v1/CborShapeSerializer";
|
|
4
|
+
import { CborShapeDeserializer } from "./codec-v1/CborShapeDeserializer";
|
|
3
5
|
/**
|
|
4
6
|
* @public
|
|
5
7
|
*/
|
|
@@ -7,27 +9,3 @@ export declare class CborCodec extends SerdeContext implements Codec<Uint8Array,
|
|
|
7
9
|
createSerializer(): CborShapeSerializer;
|
|
8
10
|
createDeserializer(): CborShapeDeserializer;
|
|
9
11
|
}
|
|
10
|
-
/**
|
|
11
|
-
* @public
|
|
12
|
-
*/
|
|
13
|
-
export declare class CborShapeSerializer extends SerdeContext implements ShapeSerializer {
|
|
14
|
-
private value;
|
|
15
|
-
write(schema: Schema, value: unknown): void;
|
|
16
|
-
/**
|
|
17
|
-
* Recursive serializer transform that copies and prepares the user input object
|
|
18
|
-
* for CBOR serialization.
|
|
19
|
-
*/
|
|
20
|
-
serialize(schema: Schema, source: unknown): any;
|
|
21
|
-
flush(): Uint8Array;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* @public
|
|
25
|
-
*/
|
|
26
|
-
export declare class CborShapeDeserializer extends SerdeContext implements ShapeDeserializer {
|
|
27
|
-
read(schema: Schema, bytes: Uint8Array): any;
|
|
28
|
-
/**
|
|
29
|
-
* Public because it's called by the protocol implementation to deserialize errors.
|
|
30
|
-
* @internal
|
|
31
|
-
*/
|
|
32
|
-
readValue(_schema: Schema, value: any): any;
|
|
33
|
-
}
|
|
@@ -13,8 +13,8 @@ export declare class SmithyRpcV2CborProtocol extends RpcProtocol {
|
|
|
13
13
|
*/
|
|
14
14
|
protected compositeErrorRegistry: TypeRegistry;
|
|
15
15
|
private codec;
|
|
16
|
-
protected serializer: import("
|
|
17
|
-
protected deserializer: import("
|
|
16
|
+
protected serializer: import(".").CborShapeSerializer;
|
|
17
|
+
protected deserializer: import(".").CborShapeDeserializer;
|
|
18
18
|
constructor({ defaultNamespace, errorTypeRegistries, }: {
|
|
19
19
|
defaultNamespace: string;
|
|
20
20
|
errorTypeRegistries?: TypeRegistry[];
|
package/node_modules/@smithy/core/dist-types/submodules/cbor/codec-v1/CborShapeDeserializer.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SerdeContext } from "@smithy/core/protocols";
|
|
2
|
+
import type { Schema, ShapeDeserializer } from "@smithy/types";
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare class CborShapeDeserializer extends SerdeContext implements ShapeDeserializer {
|
|
7
|
+
read(schema: Schema, bytes: Uint8Array): any;
|
|
8
|
+
/**
|
|
9
|
+
* Public because it's called by the protocol implementation to deserialize errors.
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
readValue(_schema: Schema, value: any): any;
|
|
13
|
+
}
|
package/node_modules/@smithy/core/dist-types/submodules/cbor/codec-v1/CborShapeSerializer.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SerdeContext } from "@smithy/core/protocols";
|
|
2
|
+
import type { Schema, ShapeSerializer } from "@smithy/types";
|
|
3
|
+
/**
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare class CborShapeSerializer extends SerdeContext implements ShapeSerializer {
|
|
7
|
+
private value;
|
|
8
|
+
write(schema: Schema, value: unknown): void;
|
|
9
|
+
/**
|
|
10
|
+
* Recursive serializer transform that copies and prepares the user input object
|
|
11
|
+
* for CBOR serialization.
|
|
12
|
+
*/
|
|
13
|
+
serialize(schema: Schema, source: unknown): any;
|
|
14
|
+
flush(): Uint8Array;
|
|
15
|
+
}
|