@kubb/agent 4.29.0 → 4.31.0
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/.output/nitro.json +1 -1
- package/.output/server/chunks/nitro/nitro.mjs +509 -345
- package/.output/server/chunks/nitro/nitro.mjs.map +1 -1
- package/.output/server/chunks/routes/api/health.get.mjs +3 -1
- package/.output/server/chunks/routes/api/health.get.mjs.map +1 -1
- package/.output/server/index.mjs +3 -1
- package/.output/server/index.mjs.map +1 -1
- package/.output/server/node_modules/@kubb/fabric-core/dist/index.js +6 -3
- package/.output/server/node_modules/@kubb/fabric-core/dist/{onProcessExit-CF200hsz.js → onProcessExit-B0rJqX4s.js} +7 -1
- package/.output/server/node_modules/@kubb/fabric-core/dist/plugins.js +1 -1
- package/.output/server/node_modules/@kubb/fabric-core/package.json +1 -1
- package/.output/server/node_modules/@kubb/react-fabric/dist/index.js +1 -1
- package/.output/server/node_modules/@kubb/react-fabric/dist/plugins.js +1 -1
- package/.output/server/node_modules/@kubb/react-fabric/dist/{reactPlugin-BkDkx1cs.js → reactPlugin-tE73eBS_.js} +5 -1
- package/.output/server/node_modules/@kubb/react-fabric/package.json +2 -2
- package/.output/server/node_modules/@logtail/core/dist/cjs/base.js +339 -0
- package/.output/server/node_modules/@logtail/core/dist/cjs/index.js +9 -0
- package/.output/server/node_modules/@logtail/core/package.json +45 -0
- package/.output/server/node_modules/@logtail/node/dist/cjs/context.js +93 -0
- package/.output/server/node_modules/@logtail/node/dist/cjs/index.js +6 -0
- package/.output/server/node_modules/@logtail/node/dist/cjs/node.js +106 -0
- package/.output/server/node_modules/@logtail/node/package.json +53 -0
- package/.output/server/node_modules/@logtail/tools/dist/cjs/batch.js +122 -0
- package/.output/server/node_modules/@logtail/tools/dist/cjs/burstProtection.js +50 -0
- package/.output/server/node_modules/@logtail/tools/dist/cjs/encode.js +12 -0
- package/.output/server/node_modules/@logtail/tools/dist/cjs/index.js +41 -0
- package/.output/server/node_modules/@logtail/tools/dist/cjs/queue.js +41 -0
- package/.output/server/node_modules/@logtail/tools/dist/cjs/throttle.js +67 -0
- package/.output/server/node_modules/@logtail/tools/package.json +39 -0
- package/.output/server/node_modules/@logtail/types/dist/cjs/types.js +21 -0
- package/.output/server/node_modules/@logtail/types/package.json +45 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/CachedKeyDecoder.js +63 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/DecodeError.js +18 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/Decoder.js +583 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/Encoder.js +408 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/ExtData.js +14 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/ExtensionCodec.js +72 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/decode.js +32 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/decodeAsync.js +44 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/encode.js +17 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/index.js +34 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/timestamp.js +104 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/utils/int.js +34 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/utils/prettyByte.js +8 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/utils/stream.js +40 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/utils/typedArrays.js +28 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/utils/utf8.js +167 -0
- package/.output/server/node_modules/@msgpack/msgpack/package.json +100 -0
- package/.output/server/node_modules/consola/dist/chunks/prompt.mjs +280 -0
- package/.output/server/node_modules/consola/dist/core.mjs +512 -0
- package/.output/server/node_modules/consola/dist/index.mjs +651 -0
- package/.output/server/node_modules/consola/dist/shared/consola.DRwqZj3T.mjs +72 -0
- package/.output/server/node_modules/consola/dist/shared/consola.DXBYu-KD.mjs +288 -0
- package/.output/server/node_modules/consola/package.json +136 -0
- package/.output/server/node_modules/serialize-error/index.js +154 -0
- package/.output/server/node_modules/serialize-error/package.json +41 -0
- package/.output/server/node_modules/stack-trace/lib/stack-trace.js +136 -0
- package/.output/server/node_modules/stack-trace/package.json +21 -0
- package/.output/server/package.json +11 -3
- package/README.md +3 -3
- package/package.json +23 -18
|
@@ -0,0 +1,583 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Decoder = exports.DataViewIndexOutOfBoundsError = void 0;
|
|
4
|
+
const prettyByte_1 = require("./utils/prettyByte");
|
|
5
|
+
const ExtensionCodec_1 = require("./ExtensionCodec");
|
|
6
|
+
const int_1 = require("./utils/int");
|
|
7
|
+
const utf8_1 = require("./utils/utf8");
|
|
8
|
+
const typedArrays_1 = require("./utils/typedArrays");
|
|
9
|
+
const CachedKeyDecoder_1 = require("./CachedKeyDecoder");
|
|
10
|
+
const DecodeError_1 = require("./DecodeError");
|
|
11
|
+
const isValidMapKeyType = (key) => {
|
|
12
|
+
const keyType = typeof key;
|
|
13
|
+
return keyType === "string" || keyType === "number";
|
|
14
|
+
};
|
|
15
|
+
const HEAD_BYTE_REQUIRED = -1;
|
|
16
|
+
const EMPTY_VIEW = new DataView(new ArrayBuffer(0));
|
|
17
|
+
const EMPTY_BYTES = new Uint8Array(EMPTY_VIEW.buffer);
|
|
18
|
+
// IE11: Hack to support IE11.
|
|
19
|
+
// IE11: Drop this hack and just use RangeError when IE11 is obsolete.
|
|
20
|
+
exports.DataViewIndexOutOfBoundsError = (() => {
|
|
21
|
+
try {
|
|
22
|
+
// IE11: The spec says it should throw RangeError,
|
|
23
|
+
// IE11: but in IE11 it throws TypeError.
|
|
24
|
+
EMPTY_VIEW.getInt8(0);
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
return e.constructor;
|
|
28
|
+
}
|
|
29
|
+
throw new Error("never reached");
|
|
30
|
+
})();
|
|
31
|
+
const MORE_DATA = new exports.DataViewIndexOutOfBoundsError("Insufficient data");
|
|
32
|
+
const sharedCachedKeyDecoder = new CachedKeyDecoder_1.CachedKeyDecoder();
|
|
33
|
+
class Decoder {
|
|
34
|
+
constructor(extensionCodec = ExtensionCodec_1.ExtensionCodec.defaultCodec, context = undefined, maxStrLength = int_1.UINT32_MAX, maxBinLength = int_1.UINT32_MAX, maxArrayLength = int_1.UINT32_MAX, maxMapLength = int_1.UINT32_MAX, maxExtLength = int_1.UINT32_MAX, keyDecoder = sharedCachedKeyDecoder) {
|
|
35
|
+
this.extensionCodec = extensionCodec;
|
|
36
|
+
this.context = context;
|
|
37
|
+
this.maxStrLength = maxStrLength;
|
|
38
|
+
this.maxBinLength = maxBinLength;
|
|
39
|
+
this.maxArrayLength = maxArrayLength;
|
|
40
|
+
this.maxMapLength = maxMapLength;
|
|
41
|
+
this.maxExtLength = maxExtLength;
|
|
42
|
+
this.keyDecoder = keyDecoder;
|
|
43
|
+
this.totalPos = 0;
|
|
44
|
+
this.pos = 0;
|
|
45
|
+
this.view = EMPTY_VIEW;
|
|
46
|
+
this.bytes = EMPTY_BYTES;
|
|
47
|
+
this.headByte = HEAD_BYTE_REQUIRED;
|
|
48
|
+
this.stack = [];
|
|
49
|
+
}
|
|
50
|
+
reinitializeState() {
|
|
51
|
+
this.totalPos = 0;
|
|
52
|
+
this.headByte = HEAD_BYTE_REQUIRED;
|
|
53
|
+
this.stack.length = 0;
|
|
54
|
+
// view, bytes, and pos will be re-initialized in setBuffer()
|
|
55
|
+
}
|
|
56
|
+
setBuffer(buffer) {
|
|
57
|
+
this.bytes = (0, typedArrays_1.ensureUint8Array)(buffer);
|
|
58
|
+
this.view = (0, typedArrays_1.createDataView)(this.bytes);
|
|
59
|
+
this.pos = 0;
|
|
60
|
+
}
|
|
61
|
+
appendBuffer(buffer) {
|
|
62
|
+
if (this.headByte === HEAD_BYTE_REQUIRED && !this.hasRemaining(1)) {
|
|
63
|
+
this.setBuffer(buffer);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
const remainingData = this.bytes.subarray(this.pos);
|
|
67
|
+
const newData = (0, typedArrays_1.ensureUint8Array)(buffer);
|
|
68
|
+
// concat remainingData + newData
|
|
69
|
+
const newBuffer = new Uint8Array(remainingData.length + newData.length);
|
|
70
|
+
newBuffer.set(remainingData);
|
|
71
|
+
newBuffer.set(newData, remainingData.length);
|
|
72
|
+
this.setBuffer(newBuffer);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
hasRemaining(size) {
|
|
76
|
+
return this.view.byteLength - this.pos >= size;
|
|
77
|
+
}
|
|
78
|
+
createExtraByteError(posToShow) {
|
|
79
|
+
const { view, pos } = this;
|
|
80
|
+
return new RangeError(`Extra ${view.byteLength - pos} of ${view.byteLength} byte(s) found at buffer[${posToShow}]`);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* @throws {@link DecodeError}
|
|
84
|
+
* @throws {@link RangeError}
|
|
85
|
+
*/
|
|
86
|
+
decode(buffer) {
|
|
87
|
+
this.reinitializeState();
|
|
88
|
+
this.setBuffer(buffer);
|
|
89
|
+
const object = this.doDecodeSync();
|
|
90
|
+
if (this.hasRemaining(1)) {
|
|
91
|
+
throw this.createExtraByteError(this.pos);
|
|
92
|
+
}
|
|
93
|
+
return object;
|
|
94
|
+
}
|
|
95
|
+
*decodeMulti(buffer) {
|
|
96
|
+
this.reinitializeState();
|
|
97
|
+
this.setBuffer(buffer);
|
|
98
|
+
while (this.hasRemaining(1)) {
|
|
99
|
+
yield this.doDecodeSync();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async decodeAsync(stream) {
|
|
103
|
+
let decoded = false;
|
|
104
|
+
let object;
|
|
105
|
+
for await (const buffer of stream) {
|
|
106
|
+
if (decoded) {
|
|
107
|
+
throw this.createExtraByteError(this.totalPos);
|
|
108
|
+
}
|
|
109
|
+
this.appendBuffer(buffer);
|
|
110
|
+
try {
|
|
111
|
+
object = this.doDecodeSync();
|
|
112
|
+
decoded = true;
|
|
113
|
+
}
|
|
114
|
+
catch (e) {
|
|
115
|
+
if (!(e instanceof exports.DataViewIndexOutOfBoundsError)) {
|
|
116
|
+
throw e; // rethrow
|
|
117
|
+
}
|
|
118
|
+
// fallthrough
|
|
119
|
+
}
|
|
120
|
+
this.totalPos += this.pos;
|
|
121
|
+
}
|
|
122
|
+
if (decoded) {
|
|
123
|
+
if (this.hasRemaining(1)) {
|
|
124
|
+
throw this.createExtraByteError(this.totalPos);
|
|
125
|
+
}
|
|
126
|
+
return object;
|
|
127
|
+
}
|
|
128
|
+
const { headByte, pos, totalPos } = this;
|
|
129
|
+
throw new RangeError(`Insufficient data in parsing ${(0, prettyByte_1.prettyByte)(headByte)} at ${totalPos} (${pos} in the current buffer)`);
|
|
130
|
+
}
|
|
131
|
+
decodeArrayStream(stream) {
|
|
132
|
+
return this.decodeMultiAsync(stream, true);
|
|
133
|
+
}
|
|
134
|
+
decodeStream(stream) {
|
|
135
|
+
return this.decodeMultiAsync(stream, false);
|
|
136
|
+
}
|
|
137
|
+
async *decodeMultiAsync(stream, isArray) {
|
|
138
|
+
let isArrayHeaderRequired = isArray;
|
|
139
|
+
let arrayItemsLeft = -1;
|
|
140
|
+
for await (const buffer of stream) {
|
|
141
|
+
if (isArray && arrayItemsLeft === 0) {
|
|
142
|
+
throw this.createExtraByteError(this.totalPos);
|
|
143
|
+
}
|
|
144
|
+
this.appendBuffer(buffer);
|
|
145
|
+
if (isArrayHeaderRequired) {
|
|
146
|
+
arrayItemsLeft = this.readArraySize();
|
|
147
|
+
isArrayHeaderRequired = false;
|
|
148
|
+
this.complete();
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
while (true) {
|
|
152
|
+
yield this.doDecodeSync();
|
|
153
|
+
if (--arrayItemsLeft === 0) {
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
catch (e) {
|
|
159
|
+
if (!(e instanceof exports.DataViewIndexOutOfBoundsError)) {
|
|
160
|
+
throw e; // rethrow
|
|
161
|
+
}
|
|
162
|
+
// fallthrough
|
|
163
|
+
}
|
|
164
|
+
this.totalPos += this.pos;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
doDecodeSync() {
|
|
168
|
+
DECODE: while (true) {
|
|
169
|
+
const headByte = this.readHeadByte();
|
|
170
|
+
let object;
|
|
171
|
+
if (headByte >= 0xe0) {
|
|
172
|
+
// negative fixint (111x xxxx) 0xe0 - 0xff
|
|
173
|
+
object = headByte - 0x100;
|
|
174
|
+
}
|
|
175
|
+
else if (headByte < 0xc0) {
|
|
176
|
+
if (headByte < 0x80) {
|
|
177
|
+
// positive fixint (0xxx xxxx) 0x00 - 0x7f
|
|
178
|
+
object = headByte;
|
|
179
|
+
}
|
|
180
|
+
else if (headByte < 0x90) {
|
|
181
|
+
// fixmap (1000 xxxx) 0x80 - 0x8f
|
|
182
|
+
const size = headByte - 0x80;
|
|
183
|
+
if (size !== 0) {
|
|
184
|
+
this.pushMapState(size);
|
|
185
|
+
this.complete();
|
|
186
|
+
continue DECODE;
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
object = {};
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
else if (headByte < 0xa0) {
|
|
193
|
+
// fixarray (1001 xxxx) 0x90 - 0x9f
|
|
194
|
+
const size = headByte - 0x90;
|
|
195
|
+
if (size !== 0) {
|
|
196
|
+
this.pushArrayState(size);
|
|
197
|
+
this.complete();
|
|
198
|
+
continue DECODE;
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
object = [];
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
// fixstr (101x xxxx) 0xa0 - 0xbf
|
|
206
|
+
const byteLength = headByte - 0xa0;
|
|
207
|
+
object = this.decodeUtf8String(byteLength, 0);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else if (headByte === 0xc0) {
|
|
211
|
+
// nil
|
|
212
|
+
object = null;
|
|
213
|
+
}
|
|
214
|
+
else if (headByte === 0xc2) {
|
|
215
|
+
// false
|
|
216
|
+
object = false;
|
|
217
|
+
}
|
|
218
|
+
else if (headByte === 0xc3) {
|
|
219
|
+
// true
|
|
220
|
+
object = true;
|
|
221
|
+
}
|
|
222
|
+
else if (headByte === 0xca) {
|
|
223
|
+
// float 32
|
|
224
|
+
object = this.readF32();
|
|
225
|
+
}
|
|
226
|
+
else if (headByte === 0xcb) {
|
|
227
|
+
// float 64
|
|
228
|
+
object = this.readF64();
|
|
229
|
+
}
|
|
230
|
+
else if (headByte === 0xcc) {
|
|
231
|
+
// uint 8
|
|
232
|
+
object = this.readU8();
|
|
233
|
+
}
|
|
234
|
+
else if (headByte === 0xcd) {
|
|
235
|
+
// uint 16
|
|
236
|
+
object = this.readU16();
|
|
237
|
+
}
|
|
238
|
+
else if (headByte === 0xce) {
|
|
239
|
+
// uint 32
|
|
240
|
+
object = this.readU32();
|
|
241
|
+
}
|
|
242
|
+
else if (headByte === 0xcf) {
|
|
243
|
+
// uint 64
|
|
244
|
+
object = this.readU64();
|
|
245
|
+
}
|
|
246
|
+
else if (headByte === 0xd0) {
|
|
247
|
+
// int 8
|
|
248
|
+
object = this.readI8();
|
|
249
|
+
}
|
|
250
|
+
else if (headByte === 0xd1) {
|
|
251
|
+
// int 16
|
|
252
|
+
object = this.readI16();
|
|
253
|
+
}
|
|
254
|
+
else if (headByte === 0xd2) {
|
|
255
|
+
// int 32
|
|
256
|
+
object = this.readI32();
|
|
257
|
+
}
|
|
258
|
+
else if (headByte === 0xd3) {
|
|
259
|
+
// int 64
|
|
260
|
+
object = this.readI64();
|
|
261
|
+
}
|
|
262
|
+
else if (headByte === 0xd9) {
|
|
263
|
+
// str 8
|
|
264
|
+
const byteLength = this.lookU8();
|
|
265
|
+
object = this.decodeUtf8String(byteLength, 1);
|
|
266
|
+
}
|
|
267
|
+
else if (headByte === 0xda) {
|
|
268
|
+
// str 16
|
|
269
|
+
const byteLength = this.lookU16();
|
|
270
|
+
object = this.decodeUtf8String(byteLength, 2);
|
|
271
|
+
}
|
|
272
|
+
else if (headByte === 0xdb) {
|
|
273
|
+
// str 32
|
|
274
|
+
const byteLength = this.lookU32();
|
|
275
|
+
object = this.decodeUtf8String(byteLength, 4);
|
|
276
|
+
}
|
|
277
|
+
else if (headByte === 0xdc) {
|
|
278
|
+
// array 16
|
|
279
|
+
const size = this.readU16();
|
|
280
|
+
if (size !== 0) {
|
|
281
|
+
this.pushArrayState(size);
|
|
282
|
+
this.complete();
|
|
283
|
+
continue DECODE;
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
object = [];
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
else if (headByte === 0xdd) {
|
|
290
|
+
// array 32
|
|
291
|
+
const size = this.readU32();
|
|
292
|
+
if (size !== 0) {
|
|
293
|
+
this.pushArrayState(size);
|
|
294
|
+
this.complete();
|
|
295
|
+
continue DECODE;
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
object = [];
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
else if (headByte === 0xde) {
|
|
302
|
+
// map 16
|
|
303
|
+
const size = this.readU16();
|
|
304
|
+
if (size !== 0) {
|
|
305
|
+
this.pushMapState(size);
|
|
306
|
+
this.complete();
|
|
307
|
+
continue DECODE;
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
object = {};
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
else if (headByte === 0xdf) {
|
|
314
|
+
// map 32
|
|
315
|
+
const size = this.readU32();
|
|
316
|
+
if (size !== 0) {
|
|
317
|
+
this.pushMapState(size);
|
|
318
|
+
this.complete();
|
|
319
|
+
continue DECODE;
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
object = {};
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
else if (headByte === 0xc4) {
|
|
326
|
+
// bin 8
|
|
327
|
+
const size = this.lookU8();
|
|
328
|
+
object = this.decodeBinary(size, 1);
|
|
329
|
+
}
|
|
330
|
+
else if (headByte === 0xc5) {
|
|
331
|
+
// bin 16
|
|
332
|
+
const size = this.lookU16();
|
|
333
|
+
object = this.decodeBinary(size, 2);
|
|
334
|
+
}
|
|
335
|
+
else if (headByte === 0xc6) {
|
|
336
|
+
// bin 32
|
|
337
|
+
const size = this.lookU32();
|
|
338
|
+
object = this.decodeBinary(size, 4);
|
|
339
|
+
}
|
|
340
|
+
else if (headByte === 0xd4) {
|
|
341
|
+
// fixext 1
|
|
342
|
+
object = this.decodeExtension(1, 0);
|
|
343
|
+
}
|
|
344
|
+
else if (headByte === 0xd5) {
|
|
345
|
+
// fixext 2
|
|
346
|
+
object = this.decodeExtension(2, 0);
|
|
347
|
+
}
|
|
348
|
+
else if (headByte === 0xd6) {
|
|
349
|
+
// fixext 4
|
|
350
|
+
object = this.decodeExtension(4, 0);
|
|
351
|
+
}
|
|
352
|
+
else if (headByte === 0xd7) {
|
|
353
|
+
// fixext 8
|
|
354
|
+
object = this.decodeExtension(8, 0);
|
|
355
|
+
}
|
|
356
|
+
else if (headByte === 0xd8) {
|
|
357
|
+
// fixext 16
|
|
358
|
+
object = this.decodeExtension(16, 0);
|
|
359
|
+
}
|
|
360
|
+
else if (headByte === 0xc7) {
|
|
361
|
+
// ext 8
|
|
362
|
+
const size = this.lookU8();
|
|
363
|
+
object = this.decodeExtension(size, 1);
|
|
364
|
+
}
|
|
365
|
+
else if (headByte === 0xc8) {
|
|
366
|
+
// ext 16
|
|
367
|
+
const size = this.lookU16();
|
|
368
|
+
object = this.decodeExtension(size, 2);
|
|
369
|
+
}
|
|
370
|
+
else if (headByte === 0xc9) {
|
|
371
|
+
// ext 32
|
|
372
|
+
const size = this.lookU32();
|
|
373
|
+
object = this.decodeExtension(size, 4);
|
|
374
|
+
}
|
|
375
|
+
else {
|
|
376
|
+
throw new DecodeError_1.DecodeError(`Unrecognized type byte: ${(0, prettyByte_1.prettyByte)(headByte)}`);
|
|
377
|
+
}
|
|
378
|
+
this.complete();
|
|
379
|
+
const stack = this.stack;
|
|
380
|
+
while (stack.length > 0) {
|
|
381
|
+
// arrays and maps
|
|
382
|
+
const state = stack[stack.length - 1];
|
|
383
|
+
if (state.type === 0 /* State.ARRAY */) {
|
|
384
|
+
state.array[state.position] = object;
|
|
385
|
+
state.position++;
|
|
386
|
+
if (state.position === state.size) {
|
|
387
|
+
stack.pop();
|
|
388
|
+
object = state.array;
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
continue DECODE;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
else if (state.type === 1 /* State.MAP_KEY */) {
|
|
395
|
+
if (!isValidMapKeyType(object)) {
|
|
396
|
+
throw new DecodeError_1.DecodeError("The type of key must be string or number but " + typeof object);
|
|
397
|
+
}
|
|
398
|
+
if (object === "__proto__") {
|
|
399
|
+
throw new DecodeError_1.DecodeError("The key __proto__ is not allowed");
|
|
400
|
+
}
|
|
401
|
+
state.key = object;
|
|
402
|
+
state.type = 2 /* State.MAP_VALUE */;
|
|
403
|
+
continue DECODE;
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
// it must be `state.type === State.MAP_VALUE` here
|
|
407
|
+
state.map[state.key] = object;
|
|
408
|
+
state.readCount++;
|
|
409
|
+
if (state.readCount === state.size) {
|
|
410
|
+
stack.pop();
|
|
411
|
+
object = state.map;
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
state.key = null;
|
|
415
|
+
state.type = 1 /* State.MAP_KEY */;
|
|
416
|
+
continue DECODE;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
return object;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
readHeadByte() {
|
|
424
|
+
if (this.headByte === HEAD_BYTE_REQUIRED) {
|
|
425
|
+
this.headByte = this.readU8();
|
|
426
|
+
// console.log("headByte", prettyByte(this.headByte));
|
|
427
|
+
}
|
|
428
|
+
return this.headByte;
|
|
429
|
+
}
|
|
430
|
+
complete() {
|
|
431
|
+
this.headByte = HEAD_BYTE_REQUIRED;
|
|
432
|
+
}
|
|
433
|
+
readArraySize() {
|
|
434
|
+
const headByte = this.readHeadByte();
|
|
435
|
+
switch (headByte) {
|
|
436
|
+
case 0xdc:
|
|
437
|
+
return this.readU16();
|
|
438
|
+
case 0xdd:
|
|
439
|
+
return this.readU32();
|
|
440
|
+
default: {
|
|
441
|
+
if (headByte < 0xa0) {
|
|
442
|
+
return headByte - 0x90;
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
throw new DecodeError_1.DecodeError(`Unrecognized array type byte: ${(0, prettyByte_1.prettyByte)(headByte)}`);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
pushMapState(size) {
|
|
451
|
+
if (size > this.maxMapLength) {
|
|
452
|
+
throw new DecodeError_1.DecodeError(`Max length exceeded: map length (${size}) > maxMapLengthLength (${this.maxMapLength})`);
|
|
453
|
+
}
|
|
454
|
+
this.stack.push({
|
|
455
|
+
type: 1 /* State.MAP_KEY */,
|
|
456
|
+
size,
|
|
457
|
+
key: null,
|
|
458
|
+
readCount: 0,
|
|
459
|
+
map: {},
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
pushArrayState(size) {
|
|
463
|
+
if (size > this.maxArrayLength) {
|
|
464
|
+
throw new DecodeError_1.DecodeError(`Max length exceeded: array length (${size}) > maxArrayLength (${this.maxArrayLength})`);
|
|
465
|
+
}
|
|
466
|
+
this.stack.push({
|
|
467
|
+
type: 0 /* State.ARRAY */,
|
|
468
|
+
size,
|
|
469
|
+
array: new Array(size),
|
|
470
|
+
position: 0,
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
decodeUtf8String(byteLength, headerOffset) {
|
|
474
|
+
var _a;
|
|
475
|
+
if (byteLength > this.maxStrLength) {
|
|
476
|
+
throw new DecodeError_1.DecodeError(`Max length exceeded: UTF-8 byte length (${byteLength}) > maxStrLength (${this.maxStrLength})`);
|
|
477
|
+
}
|
|
478
|
+
if (this.bytes.byteLength < this.pos + headerOffset + byteLength) {
|
|
479
|
+
throw MORE_DATA;
|
|
480
|
+
}
|
|
481
|
+
const offset = this.pos + headerOffset;
|
|
482
|
+
let object;
|
|
483
|
+
if (this.stateIsMapKey() && ((_a = this.keyDecoder) === null || _a === void 0 ? void 0 : _a.canBeCached(byteLength))) {
|
|
484
|
+
object = this.keyDecoder.decode(this.bytes, offset, byteLength);
|
|
485
|
+
}
|
|
486
|
+
else if (byteLength > utf8_1.TEXT_DECODER_THRESHOLD) {
|
|
487
|
+
object = (0, utf8_1.utf8DecodeTD)(this.bytes, offset, byteLength);
|
|
488
|
+
}
|
|
489
|
+
else {
|
|
490
|
+
object = (0, utf8_1.utf8DecodeJs)(this.bytes, offset, byteLength);
|
|
491
|
+
}
|
|
492
|
+
this.pos += headerOffset + byteLength;
|
|
493
|
+
return object;
|
|
494
|
+
}
|
|
495
|
+
stateIsMapKey() {
|
|
496
|
+
if (this.stack.length > 0) {
|
|
497
|
+
const state = this.stack[this.stack.length - 1];
|
|
498
|
+
return state.type === 1 /* State.MAP_KEY */;
|
|
499
|
+
}
|
|
500
|
+
return false;
|
|
501
|
+
}
|
|
502
|
+
decodeBinary(byteLength, headOffset) {
|
|
503
|
+
if (byteLength > this.maxBinLength) {
|
|
504
|
+
throw new DecodeError_1.DecodeError(`Max length exceeded: bin length (${byteLength}) > maxBinLength (${this.maxBinLength})`);
|
|
505
|
+
}
|
|
506
|
+
if (!this.hasRemaining(byteLength + headOffset)) {
|
|
507
|
+
throw MORE_DATA;
|
|
508
|
+
}
|
|
509
|
+
const offset = this.pos + headOffset;
|
|
510
|
+
const object = this.bytes.subarray(offset, offset + byteLength);
|
|
511
|
+
this.pos += headOffset + byteLength;
|
|
512
|
+
return object;
|
|
513
|
+
}
|
|
514
|
+
decodeExtension(size, headOffset) {
|
|
515
|
+
if (size > this.maxExtLength) {
|
|
516
|
+
throw new DecodeError_1.DecodeError(`Max length exceeded: ext length (${size}) > maxExtLength (${this.maxExtLength})`);
|
|
517
|
+
}
|
|
518
|
+
const extType = this.view.getInt8(this.pos + headOffset);
|
|
519
|
+
const data = this.decodeBinary(size, headOffset + 1 /* extType */);
|
|
520
|
+
return this.extensionCodec.decode(data, extType, this.context);
|
|
521
|
+
}
|
|
522
|
+
lookU8() {
|
|
523
|
+
return this.view.getUint8(this.pos);
|
|
524
|
+
}
|
|
525
|
+
lookU16() {
|
|
526
|
+
return this.view.getUint16(this.pos);
|
|
527
|
+
}
|
|
528
|
+
lookU32() {
|
|
529
|
+
return this.view.getUint32(this.pos);
|
|
530
|
+
}
|
|
531
|
+
readU8() {
|
|
532
|
+
const value = this.view.getUint8(this.pos);
|
|
533
|
+
this.pos++;
|
|
534
|
+
return value;
|
|
535
|
+
}
|
|
536
|
+
readI8() {
|
|
537
|
+
const value = this.view.getInt8(this.pos);
|
|
538
|
+
this.pos++;
|
|
539
|
+
return value;
|
|
540
|
+
}
|
|
541
|
+
readU16() {
|
|
542
|
+
const value = this.view.getUint16(this.pos);
|
|
543
|
+
this.pos += 2;
|
|
544
|
+
return value;
|
|
545
|
+
}
|
|
546
|
+
readI16() {
|
|
547
|
+
const value = this.view.getInt16(this.pos);
|
|
548
|
+
this.pos += 2;
|
|
549
|
+
return value;
|
|
550
|
+
}
|
|
551
|
+
readU32() {
|
|
552
|
+
const value = this.view.getUint32(this.pos);
|
|
553
|
+
this.pos += 4;
|
|
554
|
+
return value;
|
|
555
|
+
}
|
|
556
|
+
readI32() {
|
|
557
|
+
const value = this.view.getInt32(this.pos);
|
|
558
|
+
this.pos += 4;
|
|
559
|
+
return value;
|
|
560
|
+
}
|
|
561
|
+
readU64() {
|
|
562
|
+
const value = (0, int_1.getUint64)(this.view, this.pos);
|
|
563
|
+
this.pos += 8;
|
|
564
|
+
return value;
|
|
565
|
+
}
|
|
566
|
+
readI64() {
|
|
567
|
+
const value = (0, int_1.getInt64)(this.view, this.pos);
|
|
568
|
+
this.pos += 8;
|
|
569
|
+
return value;
|
|
570
|
+
}
|
|
571
|
+
readF32() {
|
|
572
|
+
const value = this.view.getFloat32(this.pos);
|
|
573
|
+
this.pos += 4;
|
|
574
|
+
return value;
|
|
575
|
+
}
|
|
576
|
+
readF64() {
|
|
577
|
+
const value = this.view.getFloat64(this.pos);
|
|
578
|
+
this.pos += 8;
|
|
579
|
+
return value;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
exports.Decoder = Decoder;
|
|
583
|
+
//# sourceMappingURL=Decoder.js.map
|