@likec4/language-server 1.48.0 → 1.50.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.
Files changed (75) hide show
  1. package/browser/package.json +2 -2
  2. package/browser-worker/package.json +2 -2
  3. package/dist/THIRD-PARTY-LICENSES.md +178 -0
  4. package/dist/_chunks/ConfigurableLayouter.mjs +1 -1956
  5. package/dist/_chunks/LikeC4FileSystem.mjs +3 -0
  6. package/dist/_chunks/WithMCPServer.mjs +1154 -0
  7. package/dist/_chunks/libs/@msgpack/msgpack.mjs +1 -805
  8. package/dist/_chunks/libs/eventemitter3.mjs +1 -243
  9. package/dist/_chunks/libs/fast-equals.mjs +1 -446
  10. package/dist/_chunks/libs/p-queue.mjs +1 -449
  11. package/dist/_chunks/libs/parse-ms.mjs +1 -36
  12. package/dist/_chunks/libs/picomatch.mjs +1 -1673
  13. package/dist/_chunks/libs/pretty-ms.mjs +1 -80
  14. package/dist/_chunks/libs/remeda.mjs +2 -482
  15. package/dist/_chunks/libs/strip-indent.mjs +1 -15
  16. package/dist/_chunks/libs/ufo.mjs +1 -166
  17. package/dist/_chunks/likec4lib.mjs +2 -9
  18. package/dist/_chunks/{LikeC4LanguageServices.d.mts → module.d.mts} +2101 -732
  19. package/dist/_chunks/module.mjs +34 -28
  20. package/dist/_chunks/noop.mjs +1 -0
  21. package/dist/_chunks/protocol.d.mts +6 -2
  22. package/dist/_chunks/rolldown-runtime.mjs +1 -42
  23. package/dist/_chunks/utils.mjs +1 -0
  24. package/dist/_chunks/workspace.mjs +1 -0
  25. package/dist/browser/index.d.mts +15 -0
  26. package/dist/browser/index.mjs +1 -0
  27. package/dist/browser/worker.mjs +1 -0
  28. package/dist/bundled.d.mts +1 -2
  29. package/dist/bundled.mjs +1 -51
  30. package/dist/filesystem/index.d.mts +2 -3
  31. package/dist/filesystem/index.mjs +1 -3
  32. package/dist/index.d.mts +1 -2
  33. package/dist/index.mjs +1 -48
  34. package/dist/likec4lib.d.mts +10 -3
  35. package/dist/likec4lib.mjs +1 -4
  36. package/dist/mcp/index.d.mts +2 -3
  37. package/dist/mcp/index.mjs +1 -3
  38. package/dist/module.d.mts +2 -3
  39. package/dist/module.mjs +1 -3
  40. package/dist/protocol.mjs +1 -3
  41. package/filesystem/package.json +4 -0
  42. package/mcp/package.json +4 -0
  43. package/module/package.json +4 -0
  44. package/package.json +79 -56
  45. package/LICENSE +0 -21
  46. package/dist/LikeC4LanguageServices.d.mts +0 -4
  47. package/dist/LikeC4LanguageServices.mjs +0 -3
  48. package/dist/_chunks/LikeC4LanguageServices.mjs +0 -725
  49. package/dist/_chunks/ast.d.mts +0 -1444
  50. package/dist/_chunks/ast.mjs +0 -2375
  51. package/dist/_chunks/ast2.mjs +0 -176
  52. package/dist/_chunks/filesystem.mjs +0 -58
  53. package/dist/_chunks/grammar.mjs +0 -8
  54. package/dist/_chunks/icons.mjs +0 -5211
  55. package/dist/_chunks/libs/@hono/node-server.mjs +0 -436
  56. package/dist/_chunks/libs/hono.mjs +0 -1829
  57. package/dist/_chunks/mcp.mjs +0 -33
  58. package/dist/_chunks/module2.mjs +0 -6576
  59. package/dist/_chunks/protocol.mjs +0 -78
  60. package/dist/ast.d.mts +0 -4
  61. package/dist/ast.mjs +0 -4
  62. package/dist/browser-worker.mjs +0 -6
  63. package/dist/browser.d.mts +0 -11
  64. package/dist/browser.mjs +0 -27
  65. package/dist/common-exports.d.mts +0 -4
  66. package/dist/common-exports.mjs +0 -5
  67. package/dist/generated/ast.d.mts +0 -2
  68. package/dist/generated/ast.mjs +0 -3
  69. package/dist/generated/grammar.d.mts +0 -6
  70. package/dist/generated/grammar.mjs +0 -3
  71. package/dist/generated/module.d.mts +0 -14
  72. package/dist/generated/module.mjs +0 -3
  73. package/dist/generated-lib/icons.d.mts +0 -4
  74. package/dist/generated-lib/icons.mjs +0 -3
  75. /package/dist/{browser-worker.d.mts → browser/worker.d.mts} +0 -0
@@ -1,805 +1 @@
1
- //#region ../../node_modules/.pnpm/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.esm/utils/utf8.mjs
2
- const sharedTextEncoder = new TextEncoder();
3
- const CHUNK_SIZE = 4096;
4
- function utf8DecodeJs(bytes, inputOffset, byteLength) {
5
- let offset = inputOffset;
6
- const end = offset + byteLength;
7
- const units = [];
8
- let result = "";
9
- while (offset < end) {
10
- const byte1 = bytes[offset++];
11
- if ((byte1 & 128) === 0) units.push(byte1);
12
- else if ((byte1 & 224) === 192) {
13
- const byte2 = bytes[offset++] & 63;
14
- units.push((byte1 & 31) << 6 | byte2);
15
- } else if ((byte1 & 240) === 224) {
16
- const byte2 = bytes[offset++] & 63;
17
- const byte3 = bytes[offset++] & 63;
18
- units.push((byte1 & 31) << 12 | byte2 << 6 | byte3);
19
- } else if ((byte1 & 248) === 240) {
20
- const byte2 = bytes[offset++] & 63;
21
- const byte3 = bytes[offset++] & 63;
22
- const byte4 = bytes[offset++] & 63;
23
- let unit = (byte1 & 7) << 18 | byte2 << 12 | byte3 << 6 | byte4;
24
- if (unit > 65535) {
25
- unit -= 65536;
26
- units.push(unit >>> 10 & 1023 | 55296);
27
- unit = 56320 | unit & 1023;
28
- }
29
- units.push(unit);
30
- } else units.push(byte1);
31
- if (units.length >= CHUNK_SIZE) {
32
- result += String.fromCharCode(...units);
33
- units.length = 0;
34
- }
35
- }
36
- if (units.length > 0) result += String.fromCharCode(...units);
37
- return result;
38
- }
39
- const sharedTextDecoder = new TextDecoder();
40
- const TEXT_DECODER_THRESHOLD = 200;
41
- function utf8DecodeTD(bytes, inputOffset, byteLength) {
42
- const stringBytes = bytes.subarray(inputOffset, inputOffset + byteLength);
43
- return sharedTextDecoder.decode(stringBytes);
44
- }
45
- function utf8Decode(bytes, inputOffset, byteLength) {
46
- if (byteLength > TEXT_DECODER_THRESHOLD) return utf8DecodeTD(bytes, inputOffset, byteLength);
47
- else return utf8DecodeJs(bytes, inputOffset, byteLength);
48
- }
49
-
50
- //#endregion
51
- //#region ../../node_modules/.pnpm/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.esm/ExtData.mjs
52
- /**
53
- * ExtData is used to handle Extension Types that are not registered to ExtensionCodec.
54
- */
55
- var ExtData = class {
56
- constructor(type, data) {
57
- this.type = type;
58
- this.data = data;
59
- }
60
- };
61
-
62
- //#endregion
63
- //#region ../../node_modules/.pnpm/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.esm/DecodeError.mjs
64
- var DecodeError = class DecodeError extends Error {
65
- constructor(message) {
66
- super(message);
67
- const proto = Object.create(DecodeError.prototype);
68
- Object.setPrototypeOf(this, proto);
69
- Object.defineProperty(this, "name", {
70
- configurable: true,
71
- enumerable: false,
72
- value: DecodeError.name
73
- });
74
- }
75
- };
76
-
77
- //#endregion
78
- //#region ../../node_modules/.pnpm/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.esm/utils/int.mjs
79
- const UINT32_MAX = 4294967295;
80
- function setInt64(view, offset, value) {
81
- const high = Math.floor(value / 4294967296);
82
- const low = value;
83
- view.setUint32(offset, high);
84
- view.setUint32(offset + 4, low);
85
- }
86
- function getInt64(view, offset) {
87
- const high = view.getInt32(offset);
88
- const low = view.getUint32(offset + 4);
89
- return high * 4294967296 + low;
90
- }
91
- function getUint64(view, offset) {
92
- const high = view.getUint32(offset);
93
- const low = view.getUint32(offset + 4);
94
- return high * 4294967296 + low;
95
- }
96
-
97
- //#endregion
98
- //#region ../../node_modules/.pnpm/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.esm/timestamp.mjs
99
- const EXT_TIMESTAMP = -1;
100
- const TIMESTAMP32_MAX_SEC = 4294967295;
101
- const TIMESTAMP64_MAX_SEC = 17179869183;
102
- function encodeTimeSpecToTimestamp({ sec, nsec }) {
103
- if (sec >= 0 && nsec >= 0 && sec <= TIMESTAMP64_MAX_SEC) if (nsec === 0 && sec <= TIMESTAMP32_MAX_SEC) {
104
- const rv = new Uint8Array(4);
105
- new DataView(rv.buffer).setUint32(0, sec);
106
- return rv;
107
- } else {
108
- const secHigh = sec / 4294967296;
109
- const secLow = sec & 4294967295;
110
- const rv = new Uint8Array(8);
111
- const view = new DataView(rv.buffer);
112
- view.setUint32(0, nsec << 2 | secHigh & 3);
113
- view.setUint32(4, secLow);
114
- return rv;
115
- }
116
- else {
117
- const rv = new Uint8Array(12);
118
- const view = new DataView(rv.buffer);
119
- view.setUint32(0, nsec);
120
- setInt64(view, 4, sec);
121
- return rv;
122
- }
123
- }
124
- function encodeDateToTimeSpec(date) {
125
- const msec = date.getTime();
126
- const sec = Math.floor(msec / 1e3);
127
- const nsec = (msec - sec * 1e3) * 1e6;
128
- const nsecInSec = Math.floor(nsec / 1e9);
129
- return {
130
- sec: sec + nsecInSec,
131
- nsec: nsec - nsecInSec * 1e9
132
- };
133
- }
134
- function encodeTimestampExtension(object) {
135
- if (object instanceof Date) return encodeTimeSpecToTimestamp(encodeDateToTimeSpec(object));
136
- else return null;
137
- }
138
- function decodeTimestampToTimeSpec(data) {
139
- const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
140
- switch (data.byteLength) {
141
- case 4: return {
142
- sec: view.getUint32(0),
143
- nsec: 0
144
- };
145
- case 8: {
146
- const nsec30AndSecHigh2 = view.getUint32(0);
147
- const secLow32 = view.getUint32(4);
148
- return {
149
- sec: (nsec30AndSecHigh2 & 3) * 4294967296 + secLow32,
150
- nsec: nsec30AndSecHigh2 >>> 2
151
- };
152
- }
153
- case 12: return {
154
- sec: getInt64(view, 4),
155
- nsec: view.getUint32(0)
156
- };
157
- default: throw new DecodeError(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${data.length}`);
158
- }
159
- }
160
- function decodeTimestampExtension(data) {
161
- const timeSpec = decodeTimestampToTimeSpec(data);
162
- return /* @__PURE__ */ new Date(timeSpec.sec * 1e3 + timeSpec.nsec / 1e6);
163
- }
164
- const timestampExtension = {
165
- type: EXT_TIMESTAMP,
166
- encode: encodeTimestampExtension,
167
- decode: decodeTimestampExtension
168
- };
169
-
170
- //#endregion
171
- //#region ../../node_modules/.pnpm/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.esm/ExtensionCodec.mjs
172
- var ExtensionCodec = class {
173
- constructor() {
174
- this.builtInEncoders = [];
175
- this.builtInDecoders = [];
176
- this.encoders = [];
177
- this.decoders = [];
178
- this.register(timestampExtension);
179
- }
180
- register({ type, encode, decode }) {
181
- if (type >= 0) {
182
- this.encoders[type] = encode;
183
- this.decoders[type] = decode;
184
- } else {
185
- const index = -1 - type;
186
- this.builtInEncoders[index] = encode;
187
- this.builtInDecoders[index] = decode;
188
- }
189
- }
190
- tryToEncode(object, context) {
191
- for (let i = 0; i < this.builtInEncoders.length; i++) {
192
- const encodeExt = this.builtInEncoders[i];
193
- if (encodeExt != null) {
194
- const data = encodeExt(object, context);
195
- if (data != null) return new ExtData(-1 - i, data);
196
- }
197
- }
198
- for (let i = 0; i < this.encoders.length; i++) {
199
- const encodeExt = this.encoders[i];
200
- if (encodeExt != null) {
201
- const data = encodeExt(object, context);
202
- if (data != null) return new ExtData(i, data);
203
- }
204
- }
205
- if (object instanceof ExtData) return object;
206
- return null;
207
- }
208
- decode(data, type, context) {
209
- const decodeExt = type < 0 ? this.builtInDecoders[-1 - type] : this.decoders[type];
210
- if (decodeExt) return decodeExt(data, type, context);
211
- else return new ExtData(type, data);
212
- }
213
- };
214
- ExtensionCodec.defaultCodec = new ExtensionCodec();
215
-
216
- //#endregion
217
- //#region ../../node_modules/.pnpm/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.esm/utils/typedArrays.mjs
218
- function isArrayBufferLike(buffer) {
219
- return buffer instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && buffer instanceof SharedArrayBuffer;
220
- }
221
- function ensureUint8Array(buffer) {
222
- if (buffer instanceof Uint8Array) return buffer;
223
- else if (ArrayBuffer.isView(buffer)) return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
224
- else if (isArrayBufferLike(buffer)) return new Uint8Array(buffer);
225
- else return Uint8Array.from(buffer);
226
- }
227
-
228
- //#endregion
229
- //#region ../../node_modules/.pnpm/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.esm/utils/prettyByte.mjs
230
- function prettyByte(byte) {
231
- return `${byte < 0 ? "-" : ""}0x${Math.abs(byte).toString(16).padStart(2, "0")}`;
232
- }
233
-
234
- //#endregion
235
- //#region ../../node_modules/.pnpm/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.esm/CachedKeyDecoder.mjs
236
- const DEFAULT_MAX_KEY_LENGTH = 16;
237
- const DEFAULT_MAX_LENGTH_PER_KEY = 16;
238
- var CachedKeyDecoder = class {
239
- constructor(maxKeyLength = DEFAULT_MAX_KEY_LENGTH, maxLengthPerKey = DEFAULT_MAX_LENGTH_PER_KEY) {
240
- this.hit = 0;
241
- this.miss = 0;
242
- this.maxKeyLength = maxKeyLength;
243
- this.maxLengthPerKey = maxLengthPerKey;
244
- this.caches = [];
245
- for (let i = 0; i < this.maxKeyLength; i++) this.caches.push([]);
246
- }
247
- canBeCached(byteLength) {
248
- return byteLength > 0 && byteLength <= this.maxKeyLength;
249
- }
250
- find(bytes, inputOffset, byteLength) {
251
- const records = this.caches[byteLength - 1];
252
- FIND_CHUNK: for (const record of records) {
253
- const recordBytes = record.bytes;
254
- for (let j = 0; j < byteLength; j++) if (recordBytes[j] !== bytes[inputOffset + j]) continue FIND_CHUNK;
255
- return record.str;
256
- }
257
- return null;
258
- }
259
- store(bytes, value) {
260
- const records = this.caches[bytes.length - 1];
261
- const record = {
262
- bytes,
263
- str: value
264
- };
265
- if (records.length >= this.maxLengthPerKey) records[Math.random() * records.length | 0] = record;
266
- else records.push(record);
267
- }
268
- decode(bytes, inputOffset, byteLength) {
269
- const cachedValue = this.find(bytes, inputOffset, byteLength);
270
- if (cachedValue != null) {
271
- this.hit++;
272
- return cachedValue;
273
- }
274
- this.miss++;
275
- const str = utf8DecodeJs(bytes, inputOffset, byteLength);
276
- const slicedCopyOfBytes = Uint8Array.prototype.slice.call(bytes, inputOffset, inputOffset + byteLength);
277
- this.store(slicedCopyOfBytes, str);
278
- return str;
279
- }
280
- };
281
-
282
- //#endregion
283
- //#region ../../node_modules/.pnpm/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.esm/Decoder.mjs
284
- const STATE_ARRAY = "array";
285
- const STATE_MAP_KEY = "map_key";
286
- const STATE_MAP_VALUE = "map_value";
287
- const mapKeyConverter = (key) => {
288
- if (typeof key === "string" || typeof key === "number") return key;
289
- throw new DecodeError("The type of key must be string or number but " + typeof key);
290
- };
291
- var StackPool = class {
292
- constructor() {
293
- this.stack = [];
294
- this.stackHeadPosition = -1;
295
- }
296
- get length() {
297
- return this.stackHeadPosition + 1;
298
- }
299
- top() {
300
- return this.stack[this.stackHeadPosition];
301
- }
302
- pushArrayState(size) {
303
- const state = this.getUninitializedStateFromPool();
304
- state.type = STATE_ARRAY;
305
- state.position = 0;
306
- state.size = size;
307
- state.array = new Array(size);
308
- }
309
- pushMapState(size) {
310
- const state = this.getUninitializedStateFromPool();
311
- state.type = STATE_MAP_KEY;
312
- state.readCount = 0;
313
- state.size = size;
314
- state.map = {};
315
- }
316
- getUninitializedStateFromPool() {
317
- this.stackHeadPosition++;
318
- if (this.stackHeadPosition === this.stack.length) this.stack.push({
319
- type: void 0,
320
- size: 0,
321
- array: void 0,
322
- position: 0,
323
- readCount: 0,
324
- map: void 0,
325
- key: null
326
- });
327
- return this.stack[this.stackHeadPosition];
328
- }
329
- release(state) {
330
- if (this.stack[this.stackHeadPosition] !== state) throw new Error("Invalid stack state. Released state is not on top of the stack.");
331
- if (state.type === STATE_ARRAY) {
332
- const partialState = state;
333
- partialState.size = 0;
334
- partialState.array = void 0;
335
- partialState.position = 0;
336
- partialState.type = void 0;
337
- }
338
- if (state.type === STATE_MAP_KEY || state.type === STATE_MAP_VALUE) {
339
- const partialState = state;
340
- partialState.size = 0;
341
- partialState.map = void 0;
342
- partialState.readCount = 0;
343
- partialState.type = void 0;
344
- }
345
- this.stackHeadPosition--;
346
- }
347
- reset() {
348
- this.stack.length = 0;
349
- this.stackHeadPosition = -1;
350
- }
351
- };
352
- const HEAD_BYTE_REQUIRED = -1;
353
- const EMPTY_VIEW = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(0));
354
- const EMPTY_BYTES = new Uint8Array(EMPTY_VIEW.buffer);
355
- try {
356
- EMPTY_VIEW.getInt8(0);
357
- } catch (e) {
358
- if (!(e instanceof RangeError)) throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access");
359
- }
360
- const MORE_DATA = /* @__PURE__ */ new RangeError("Insufficient data");
361
- const sharedCachedKeyDecoder = new CachedKeyDecoder();
362
- var Decoder = class Decoder {
363
- constructor(options) {
364
- this.totalPos = 0;
365
- this.pos = 0;
366
- this.view = EMPTY_VIEW;
367
- this.bytes = EMPTY_BYTES;
368
- this.headByte = HEAD_BYTE_REQUIRED;
369
- this.stack = new StackPool();
370
- this.entered = false;
371
- this.extensionCodec = options?.extensionCodec ?? ExtensionCodec.defaultCodec;
372
- this.context = options?.context;
373
- this.useBigInt64 = options?.useBigInt64 ?? false;
374
- this.rawStrings = options?.rawStrings ?? false;
375
- this.maxStrLength = options?.maxStrLength ?? UINT32_MAX;
376
- this.maxBinLength = options?.maxBinLength ?? UINT32_MAX;
377
- this.maxArrayLength = options?.maxArrayLength ?? UINT32_MAX;
378
- this.maxMapLength = options?.maxMapLength ?? UINT32_MAX;
379
- this.maxExtLength = options?.maxExtLength ?? UINT32_MAX;
380
- this.keyDecoder = options?.keyDecoder !== void 0 ? options.keyDecoder : sharedCachedKeyDecoder;
381
- this.mapKeyConverter = options?.mapKeyConverter ?? mapKeyConverter;
382
- }
383
- clone() {
384
- return new Decoder({
385
- extensionCodec: this.extensionCodec,
386
- context: this.context,
387
- useBigInt64: this.useBigInt64,
388
- rawStrings: this.rawStrings,
389
- maxStrLength: this.maxStrLength,
390
- maxBinLength: this.maxBinLength,
391
- maxArrayLength: this.maxArrayLength,
392
- maxMapLength: this.maxMapLength,
393
- maxExtLength: this.maxExtLength,
394
- keyDecoder: this.keyDecoder
395
- });
396
- }
397
- reinitializeState() {
398
- this.totalPos = 0;
399
- this.headByte = HEAD_BYTE_REQUIRED;
400
- this.stack.reset();
401
- }
402
- setBuffer(buffer) {
403
- const bytes = ensureUint8Array(buffer);
404
- this.bytes = bytes;
405
- this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
406
- this.pos = 0;
407
- }
408
- appendBuffer(buffer) {
409
- if (this.headByte === HEAD_BYTE_REQUIRED && !this.hasRemaining(1)) this.setBuffer(buffer);
410
- else {
411
- const remainingData = this.bytes.subarray(this.pos);
412
- const newData = ensureUint8Array(buffer);
413
- const newBuffer = new Uint8Array(remainingData.length + newData.length);
414
- newBuffer.set(remainingData);
415
- newBuffer.set(newData, remainingData.length);
416
- this.setBuffer(newBuffer);
417
- }
418
- }
419
- hasRemaining(size) {
420
- return this.view.byteLength - this.pos >= size;
421
- }
422
- createExtraByteError(posToShow) {
423
- const { view, pos } = this;
424
- return /* @__PURE__ */ new RangeError(`Extra ${view.byteLength - pos} of ${view.byteLength} byte(s) found at buffer[${posToShow}]`);
425
- }
426
- /**
427
- * @throws {@link DecodeError}
428
- * @throws {@link RangeError}
429
- */
430
- decode(buffer) {
431
- if (this.entered) return this.clone().decode(buffer);
432
- try {
433
- this.entered = true;
434
- this.reinitializeState();
435
- this.setBuffer(buffer);
436
- const object = this.doDecodeSync();
437
- if (this.hasRemaining(1)) throw this.createExtraByteError(this.pos);
438
- return object;
439
- } finally {
440
- this.entered = false;
441
- }
442
- }
443
- *decodeMulti(buffer) {
444
- if (this.entered) {
445
- yield* this.clone().decodeMulti(buffer);
446
- return;
447
- }
448
- try {
449
- this.entered = true;
450
- this.reinitializeState();
451
- this.setBuffer(buffer);
452
- while (this.hasRemaining(1)) yield this.doDecodeSync();
453
- } finally {
454
- this.entered = false;
455
- }
456
- }
457
- async decodeAsync(stream) {
458
- if (this.entered) return this.clone().decodeAsync(stream);
459
- try {
460
- this.entered = true;
461
- let decoded = false;
462
- let object;
463
- for await (const buffer of stream) {
464
- if (decoded) {
465
- this.entered = false;
466
- throw this.createExtraByteError(this.totalPos);
467
- }
468
- this.appendBuffer(buffer);
469
- try {
470
- object = this.doDecodeSync();
471
- decoded = true;
472
- } catch (e) {
473
- if (!(e instanceof RangeError)) throw e;
474
- }
475
- this.totalPos += this.pos;
476
- }
477
- if (decoded) {
478
- if (this.hasRemaining(1)) throw this.createExtraByteError(this.totalPos);
479
- return object;
480
- }
481
- const { headByte, pos, totalPos } = this;
482
- throw new RangeError(`Insufficient data in parsing ${prettyByte(headByte)} at ${totalPos} (${pos} in the current buffer)`);
483
- } finally {
484
- this.entered = false;
485
- }
486
- }
487
- decodeArrayStream(stream) {
488
- return this.decodeMultiAsync(stream, true);
489
- }
490
- decodeStream(stream) {
491
- return this.decodeMultiAsync(stream, false);
492
- }
493
- async *decodeMultiAsync(stream, isArray) {
494
- if (this.entered) {
495
- yield* this.clone().decodeMultiAsync(stream, isArray);
496
- return;
497
- }
498
- try {
499
- this.entered = true;
500
- let isArrayHeaderRequired = isArray;
501
- let arrayItemsLeft = -1;
502
- for await (const buffer of stream) {
503
- if (isArray && arrayItemsLeft === 0) throw this.createExtraByteError(this.totalPos);
504
- this.appendBuffer(buffer);
505
- if (isArrayHeaderRequired) {
506
- arrayItemsLeft = this.readArraySize();
507
- isArrayHeaderRequired = false;
508
- this.complete();
509
- }
510
- try {
511
- while (true) {
512
- yield this.doDecodeSync();
513
- if (--arrayItemsLeft === 0) break;
514
- }
515
- } catch (e) {
516
- if (!(e instanceof RangeError)) throw e;
517
- }
518
- this.totalPos += this.pos;
519
- }
520
- } finally {
521
- this.entered = false;
522
- }
523
- }
524
- doDecodeSync() {
525
- DECODE: while (true) {
526
- const headByte = this.readHeadByte();
527
- let object;
528
- if (headByte >= 224) object = headByte - 256;
529
- else if (headByte < 192) if (headByte < 128) object = headByte;
530
- else if (headByte < 144) {
531
- const size = headByte - 128;
532
- if (size !== 0) {
533
- this.pushMapState(size);
534
- this.complete();
535
- continue DECODE;
536
- } else object = {};
537
- } else if (headByte < 160) {
538
- const size = headByte - 144;
539
- if (size !== 0) {
540
- this.pushArrayState(size);
541
- this.complete();
542
- continue DECODE;
543
- } else object = [];
544
- } else {
545
- const byteLength = headByte - 160;
546
- object = this.decodeString(byteLength, 0);
547
- }
548
- else if (headByte === 192) object = null;
549
- else if (headByte === 194) object = false;
550
- else if (headByte === 195) object = true;
551
- else if (headByte === 202) object = this.readF32();
552
- else if (headByte === 203) object = this.readF64();
553
- else if (headByte === 204) object = this.readU8();
554
- else if (headByte === 205) object = this.readU16();
555
- else if (headByte === 206) object = this.readU32();
556
- else if (headByte === 207) if (this.useBigInt64) object = this.readU64AsBigInt();
557
- else object = this.readU64();
558
- else if (headByte === 208) object = this.readI8();
559
- else if (headByte === 209) object = this.readI16();
560
- else if (headByte === 210) object = this.readI32();
561
- else if (headByte === 211) if (this.useBigInt64) object = this.readI64AsBigInt();
562
- else object = this.readI64();
563
- else if (headByte === 217) {
564
- const byteLength = this.lookU8();
565
- object = this.decodeString(byteLength, 1);
566
- } else if (headByte === 218) {
567
- const byteLength = this.lookU16();
568
- object = this.decodeString(byteLength, 2);
569
- } else if (headByte === 219) {
570
- const byteLength = this.lookU32();
571
- object = this.decodeString(byteLength, 4);
572
- } else if (headByte === 220) {
573
- const size = this.readU16();
574
- if (size !== 0) {
575
- this.pushArrayState(size);
576
- this.complete();
577
- continue DECODE;
578
- } else object = [];
579
- } else if (headByte === 221) {
580
- const size = this.readU32();
581
- if (size !== 0) {
582
- this.pushArrayState(size);
583
- this.complete();
584
- continue DECODE;
585
- } else object = [];
586
- } else if (headByte === 222) {
587
- const size = this.readU16();
588
- if (size !== 0) {
589
- this.pushMapState(size);
590
- this.complete();
591
- continue DECODE;
592
- } else object = {};
593
- } else if (headByte === 223) {
594
- const size = this.readU32();
595
- if (size !== 0) {
596
- this.pushMapState(size);
597
- this.complete();
598
- continue DECODE;
599
- } else object = {};
600
- } else if (headByte === 196) {
601
- const size = this.lookU8();
602
- object = this.decodeBinary(size, 1);
603
- } else if (headByte === 197) {
604
- const size = this.lookU16();
605
- object = this.decodeBinary(size, 2);
606
- } else if (headByte === 198) {
607
- const size = this.lookU32();
608
- object = this.decodeBinary(size, 4);
609
- } else if (headByte === 212) object = this.decodeExtension(1, 0);
610
- else if (headByte === 213) object = this.decodeExtension(2, 0);
611
- else if (headByte === 214) object = this.decodeExtension(4, 0);
612
- else if (headByte === 215) object = this.decodeExtension(8, 0);
613
- else if (headByte === 216) object = this.decodeExtension(16, 0);
614
- else if (headByte === 199) {
615
- const size = this.lookU8();
616
- object = this.decodeExtension(size, 1);
617
- } else if (headByte === 200) {
618
- const size = this.lookU16();
619
- object = this.decodeExtension(size, 2);
620
- } else if (headByte === 201) {
621
- const size = this.lookU32();
622
- object = this.decodeExtension(size, 4);
623
- } else throw new DecodeError(`Unrecognized type byte: ${prettyByte(headByte)}`);
624
- this.complete();
625
- const stack = this.stack;
626
- while (stack.length > 0) {
627
- const state = stack.top();
628
- if (state.type === STATE_ARRAY) {
629
- state.array[state.position] = object;
630
- state.position++;
631
- if (state.position === state.size) {
632
- object = state.array;
633
- stack.release(state);
634
- } else continue DECODE;
635
- } else if (state.type === STATE_MAP_KEY) {
636
- if (object === "__proto__") throw new DecodeError("The key __proto__ is not allowed");
637
- state.key = this.mapKeyConverter(object);
638
- state.type = STATE_MAP_VALUE;
639
- continue DECODE;
640
- } else {
641
- state.map[state.key] = object;
642
- state.readCount++;
643
- if (state.readCount === state.size) {
644
- object = state.map;
645
- stack.release(state);
646
- } else {
647
- state.key = null;
648
- state.type = STATE_MAP_KEY;
649
- continue DECODE;
650
- }
651
- }
652
- }
653
- return object;
654
- }
655
- }
656
- readHeadByte() {
657
- if (this.headByte === HEAD_BYTE_REQUIRED) this.headByte = this.readU8();
658
- return this.headByte;
659
- }
660
- complete() {
661
- this.headByte = HEAD_BYTE_REQUIRED;
662
- }
663
- readArraySize() {
664
- const headByte = this.readHeadByte();
665
- switch (headByte) {
666
- case 220: return this.readU16();
667
- case 221: return this.readU32();
668
- default: if (headByte < 160) return headByte - 144;
669
- else throw new DecodeError(`Unrecognized array type byte: ${prettyByte(headByte)}`);
670
- }
671
- }
672
- pushMapState(size) {
673
- if (size > this.maxMapLength) throw new DecodeError(`Max length exceeded: map length (${size}) > maxMapLengthLength (${this.maxMapLength})`);
674
- this.stack.pushMapState(size);
675
- }
676
- pushArrayState(size) {
677
- if (size > this.maxArrayLength) throw new DecodeError(`Max length exceeded: array length (${size}) > maxArrayLength (${this.maxArrayLength})`);
678
- this.stack.pushArrayState(size);
679
- }
680
- decodeString(byteLength, headerOffset) {
681
- if (!this.rawStrings || this.stateIsMapKey()) return this.decodeUtf8String(byteLength, headerOffset);
682
- return this.decodeBinary(byteLength, headerOffset);
683
- }
684
- /**
685
- * @throws {@link RangeError}
686
- */
687
- decodeUtf8String(byteLength, headerOffset) {
688
- if (byteLength > this.maxStrLength) throw new DecodeError(`Max length exceeded: UTF-8 byte length (${byteLength}) > maxStrLength (${this.maxStrLength})`);
689
- if (this.bytes.byteLength < this.pos + headerOffset + byteLength) throw MORE_DATA;
690
- const offset = this.pos + headerOffset;
691
- let object;
692
- if (this.stateIsMapKey() && this.keyDecoder?.canBeCached(byteLength)) object = this.keyDecoder.decode(this.bytes, offset, byteLength);
693
- else object = utf8Decode(this.bytes, offset, byteLength);
694
- this.pos += headerOffset + byteLength;
695
- return object;
696
- }
697
- stateIsMapKey() {
698
- if (this.stack.length > 0) return this.stack.top().type === STATE_MAP_KEY;
699
- return false;
700
- }
701
- /**
702
- * @throws {@link RangeError}
703
- */
704
- decodeBinary(byteLength, headOffset) {
705
- if (byteLength > this.maxBinLength) throw new DecodeError(`Max length exceeded: bin length (${byteLength}) > maxBinLength (${this.maxBinLength})`);
706
- if (!this.hasRemaining(byteLength + headOffset)) throw MORE_DATA;
707
- const offset = this.pos + headOffset;
708
- const object = this.bytes.subarray(offset, offset + byteLength);
709
- this.pos += headOffset + byteLength;
710
- return object;
711
- }
712
- decodeExtension(size, headOffset) {
713
- if (size > this.maxExtLength) throw new DecodeError(`Max length exceeded: ext length (${size}) > maxExtLength (${this.maxExtLength})`);
714
- const extType = this.view.getInt8(this.pos + headOffset);
715
- const data = this.decodeBinary(size, headOffset + 1);
716
- return this.extensionCodec.decode(data, extType, this.context);
717
- }
718
- lookU8() {
719
- return this.view.getUint8(this.pos);
720
- }
721
- lookU16() {
722
- return this.view.getUint16(this.pos);
723
- }
724
- lookU32() {
725
- return this.view.getUint32(this.pos);
726
- }
727
- readU8() {
728
- const value = this.view.getUint8(this.pos);
729
- this.pos++;
730
- return value;
731
- }
732
- readI8() {
733
- const value = this.view.getInt8(this.pos);
734
- this.pos++;
735
- return value;
736
- }
737
- readU16() {
738
- const value = this.view.getUint16(this.pos);
739
- this.pos += 2;
740
- return value;
741
- }
742
- readI16() {
743
- const value = this.view.getInt16(this.pos);
744
- this.pos += 2;
745
- return value;
746
- }
747
- readU32() {
748
- const value = this.view.getUint32(this.pos);
749
- this.pos += 4;
750
- return value;
751
- }
752
- readI32() {
753
- const value = this.view.getInt32(this.pos);
754
- this.pos += 4;
755
- return value;
756
- }
757
- readU64() {
758
- const value = getUint64(this.view, this.pos);
759
- this.pos += 8;
760
- return value;
761
- }
762
- readI64() {
763
- const value = getInt64(this.view, this.pos);
764
- this.pos += 8;
765
- return value;
766
- }
767
- readU64AsBigInt() {
768
- const value = this.view.getBigUint64(this.pos);
769
- this.pos += 8;
770
- return value;
771
- }
772
- readI64AsBigInt() {
773
- const value = this.view.getBigInt64(this.pos);
774
- this.pos += 8;
775
- return value;
776
- }
777
- readF32() {
778
- const value = this.view.getFloat32(this.pos);
779
- this.pos += 4;
780
- return value;
781
- }
782
- readF64() {
783
- const value = this.view.getFloat64(this.pos);
784
- this.pos += 8;
785
- return value;
786
- }
787
- };
788
-
789
- //#endregion
790
- //#region ../../node_modules/.pnpm/@msgpack+msgpack@3.1.2/node_modules/@msgpack/msgpack/dist.esm/decode.mjs
791
- /**
792
- * It decodes a single MessagePack object in a buffer.
793
- *
794
- * This is a synchronous decoding function.
795
- * See other variants for asynchronous decoding: {@link decodeAsync}, {@link decodeMultiStream}, or {@link decodeArrayStream}.
796
- *
797
- * @throws {@link RangeError} if the buffer is incomplete, including the case where the buffer is empty.
798
- * @throws {@link DecodeError} if the buffer contains invalid data.
799
- */
800
- function decode(buffer, options) {
801
- return new Decoder(options).decode(buffer);
802
- }
803
-
804
- //#endregion
805
- export { decode as t };
1
+ new TextEncoder;function utf8DecodeJs(e,t,n){let r=t,i=r+n,a=[],o=``;for(;r<i;){let t=e[r++];if(!(t&128))a.push(t);else if((t&224)==192){let n=e[r++]&63;a.push((t&31)<<6|n)}else if((t&240)==224){let n=e[r++]&63,i=e[r++]&63;a.push((t&31)<<12|n<<6|i)}else if((t&248)==240){let n=e[r++]&63,i=e[r++]&63,o=e[r++]&63,s=(t&7)<<18|n<<12|i<<6|o;s>65535&&(s-=65536,a.push(s>>>10&1023|55296),s=56320|s&1023),a.push(s)}else a.push(t);a.length>=4096&&(o+=String.fromCharCode(...a),a.length=0)}return a.length>0&&(o+=String.fromCharCode(...a)),o}const e=new TextDecoder;function utf8DecodeTD(t,n,r){let i=t.subarray(n,n+r);return e.decode(i)}function utf8Decode(e,t,n){return n>200?utf8DecodeTD(e,t,n):utf8DecodeJs(e,t,n)}var ExtData=class{constructor(e,t){this.type=e,this.data=t}},t=class DecodeError extends Error{constructor(e){super(e);let t=Object.create(DecodeError.prototype);Object.setPrototypeOf(this,t),Object.defineProperty(this,`name`,{configurable:!0,enumerable:!1,value:DecodeError.name})}};const n=4294967295;function setInt64(e,t,n){let r=Math.floor(n/4294967296),i=n;e.setUint32(t,r),e.setUint32(t+4,i)}function getInt64(e,t){let n=e.getInt32(t),r=e.getUint32(t+4);return n*4294967296+r}function getUint64(e,t){let n=e.getUint32(t),r=e.getUint32(t+4);return n*4294967296+r}function encodeTimeSpecToTimestamp({sec:e,nsec:t}){if(e>=0&&t>=0&&e<=17179869183)if(t===0&&e<=4294967295){let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,e),t}else{let n=e/4294967296,r=e&4294967295,i=new Uint8Array(8),a=new DataView(i.buffer);return a.setUint32(0,t<<2|n&3),a.setUint32(4,r),i}else{let n=new Uint8Array(12),r=new DataView(n.buffer);return r.setUint32(0,t),setInt64(r,4,e),n}}function encodeDateToTimeSpec(e){let t=e.getTime(),n=Math.floor(t/1e3),r=(t-n*1e3)*1e6,i=Math.floor(r/1e9);return{sec:n+i,nsec:r-i*1e9}}function encodeTimestampExtension(e){return e instanceof Date?encodeTimeSpecToTimestamp(encodeDateToTimeSpec(e)):null}function decodeTimestampToTimeSpec(e){let n=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(e.byteLength){case 4:return{sec:n.getUint32(0),nsec:0};case 8:{let e=n.getUint32(0),t=n.getUint32(4);return{sec:(e&3)*4294967296+t,nsec:e>>>2}}case 12:return{sec:getInt64(n,4),nsec:n.getUint32(0)};default:throw new t(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${e.length}`)}}function decodeTimestampExtension(e){let t=decodeTimestampToTimeSpec(e);return new Date(t.sec*1e3+t.nsec/1e6)}const r={type:-1,encode:encodeTimestampExtension,decode:decodeTimestampExtension};var ExtensionCodec=class{constructor(){this.builtInEncoders=[],this.builtInDecoders=[],this.encoders=[],this.decoders=[],this.register(r)}register({type:e,encode:t,decode:n}){if(e>=0)this.encoders[e]=t,this.decoders[e]=n;else{let r=-1-e;this.builtInEncoders[r]=t,this.builtInDecoders[r]=n}}tryToEncode(e,t){for(let n=0;n<this.builtInEncoders.length;n++){let r=this.builtInEncoders[n];if(r!=null){let i=r(e,t);if(i!=null)return new ExtData(-1-n,i)}}for(let n=0;n<this.encoders.length;n++){let r=this.encoders[n];if(r!=null){let i=r(e,t);if(i!=null)return new ExtData(n,i)}}return e instanceof ExtData?e:null}decode(e,t,n){let r=t<0?this.builtInDecoders[-1-t]:this.decoders[t];return r?r(e,t,n):new ExtData(t,e)}};ExtensionCodec.defaultCodec=new ExtensionCodec;function isArrayBufferLike(e){return e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer}function ensureUint8Array(e){return e instanceof Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):isArrayBufferLike(e)?new Uint8Array(e):Uint8Array.from(e)}function prettyByte(e){return`${e<0?`-`:``}0x${Math.abs(e).toString(16).padStart(2,`0`)}`}var CachedKeyDecoder=class{constructor(e=16,t=16){this.hit=0,this.miss=0,this.maxKeyLength=e,this.maxLengthPerKey=t,this.caches=[];for(let e=0;e<this.maxKeyLength;e++)this.caches.push([])}canBeCached(e){return e>0&&e<=this.maxKeyLength}find(e,t,n){let r=this.caches[n-1];FIND_CHUNK:for(let i of r){let r=i.bytes;for(let i=0;i<n;i++)if(r[i]!==e[t+i])continue FIND_CHUNK;return i.str}return null}store(e,t){let n=this.caches[e.length-1],r={bytes:e,str:t};n.length>=this.maxLengthPerKey?n[Math.random()*n.length|0]=r:n.push(r)}decode(e,t,n){let r=this.find(e,t,n);if(r!=null)return this.hit++,r;this.miss++;let i=utf8DecodeJs(e,t,n),a=Uint8Array.prototype.slice.call(e,t,t+n);return this.store(a,i),i}};const i=`array`,a=`map_key`,o=`map_value`,mapKeyConverter=e=>{if(typeof e==`string`||typeof e==`number`)return e;throw new t(`The type of key must be string or number but `+typeof e)};var StackPool=class{constructor(){this.stack=[],this.stackHeadPosition=-1}get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(e){let t=this.getUninitializedStateFromPool();t.type=i,t.position=0,t.size=e,t.array=Array(e)}pushMapState(e){let t=this.getUninitializedStateFromPool();t.type=a,t.readCount=0,t.size=e,t.map={}}getUninitializedStateFromPool(){return this.stackHeadPosition++,this.stackHeadPosition===this.stack.length&&this.stack.push({type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null}),this.stack[this.stackHeadPosition]}release(e){if(this.stack[this.stackHeadPosition]!==e)throw Error(`Invalid stack state. Released state is not on top of the stack.`);if(e.type===i){let t=e;t.size=0,t.array=void 0,t.position=0,t.type=void 0}if(e.type===a||e.type===o){let t=e;t.size=0,t.map=void 0,t.readCount=0,t.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}};const s=new DataView(new ArrayBuffer(0)),c=new Uint8Array(s.buffer);try{s.getInt8(0)}catch(e){if(!(e instanceof RangeError))throw Error(`This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access`)}const l=RangeError(`Insufficient data`),u=new CachedKeyDecoder;var d=class Decoder{constructor(e){this.totalPos=0,this.pos=0,this.view=s,this.bytes=c,this.headByte=-1,this.stack=new StackPool,this.entered=!1,this.extensionCodec=e?.extensionCodec??ExtensionCodec.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.rawStrings=e?.rawStrings??!1,this.maxStrLength=e?.maxStrLength??n,this.maxBinLength=e?.maxBinLength??n,this.maxArrayLength=e?.maxArrayLength??n,this.maxMapLength=e?.maxMapLength??n,this.maxExtLength=e?.maxExtLength??n,this.keyDecoder=e?.keyDecoder===void 0?u:e.keyDecoder,this.mapKeyConverter=e?.mapKeyConverter??mapKeyConverter}clone(){return new Decoder({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=-1,this.stack.reset()}setBuffer(e){let t=ensureUint8Array(e);this.bytes=t,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength),this.pos=0}appendBuffer(e){if(this.headByte===-1&&!this.hasRemaining(1))this.setBuffer(e);else{let t=this.bytes.subarray(this.pos),n=ensureUint8Array(e),r=new Uint8Array(t.length+n.length);r.set(t),r.set(n,t.length),this.setBuffer(r)}}hasRemaining(e){return this.view.byteLength-this.pos>=e}createExtraByteError(e){let{view:t,pos:n}=this;return RangeError(`Extra ${t.byteLength-n} of ${t.byteLength} byte(s) found at buffer[${e}]`)}decode(e){if(this.entered)return this.clone().decode(e);try{this.entered=!0,this.reinitializeState(),this.setBuffer(e);let t=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return t}finally{this.entered=!1}}*decodeMulti(e){if(this.entered){yield*this.clone().decodeMulti(e);return}try{for(this.entered=!0,this.reinitializeState(),this.setBuffer(e);this.hasRemaining(1);)yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(e){if(this.entered)return this.clone().decodeAsync(e);try{this.entered=!0;let t=!1,n;for await(let r of e){if(t)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(r);try{n=this.doDecodeSync(),t=!0}catch(e){if(!(e instanceof RangeError))throw e}this.totalPos+=this.pos}if(t){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return n}let{headByte:r,pos:i,totalPos:a}=this;throw RangeError(`Insufficient data in parsing ${prettyByte(r)} at ${a} (${i} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(e){return this.decodeMultiAsync(e,!0)}decodeStream(e){return this.decodeMultiAsync(e,!1)}async*decodeMultiAsync(e,t){if(this.entered){yield*this.clone().decodeMultiAsync(e,t);return}try{this.entered=!0;let n=t,r=-1;for await(let i of e){if(t&&r===0)throw this.createExtraByteError(this.totalPos);this.appendBuffer(i),n&&(r=this.readArraySize(),n=!1,this.complete());try{for(;yield this.doDecodeSync(),--r!==0;);}catch(e){if(!(e instanceof RangeError))throw e}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){DECODE:for(;;){let e=this.readHeadByte(),n;if(e>=224)n=e-256;else if(e<192)if(e<128)n=e;else if(e<144){let t=e-128;if(t!==0){this.pushMapState(t),this.complete();continue DECODE}else n={}}else if(e<160){let t=e-144;if(t!==0){this.pushArrayState(t),this.complete();continue DECODE}else n=[]}else{let t=e-160;n=this.decodeString(t,0)}else if(e===192)n=null;else if(e===194)n=!1;else if(e===195)n=!0;else if(e===202)n=this.readF32();else if(e===203)n=this.readF64();else if(e===204)n=this.readU8();else if(e===205)n=this.readU16();else if(e===206)n=this.readU32();else if(e===207)n=this.useBigInt64?this.readU64AsBigInt():this.readU64();else if(e===208)n=this.readI8();else if(e===209)n=this.readI16();else if(e===210)n=this.readI32();else if(e===211)n=this.useBigInt64?this.readI64AsBigInt():this.readI64();else if(e===217){let e=this.lookU8();n=this.decodeString(e,1)}else if(e===218){let e=this.lookU16();n=this.decodeString(e,2)}else if(e===219){let e=this.lookU32();n=this.decodeString(e,4)}else if(e===220){let e=this.readU16();if(e!==0){this.pushArrayState(e),this.complete();continue DECODE}else n=[]}else if(e===221){let e=this.readU32();if(e!==0){this.pushArrayState(e),this.complete();continue DECODE}else n=[]}else if(e===222){let e=this.readU16();if(e!==0){this.pushMapState(e),this.complete();continue DECODE}else n={}}else if(e===223){let e=this.readU32();if(e!==0){this.pushMapState(e),this.complete();continue DECODE}else n={}}else if(e===196){let e=this.lookU8();n=this.decodeBinary(e,1)}else if(e===197){let e=this.lookU16();n=this.decodeBinary(e,2)}else if(e===198){let e=this.lookU32();n=this.decodeBinary(e,4)}else if(e===212)n=this.decodeExtension(1,0);else if(e===213)n=this.decodeExtension(2,0);else if(e===214)n=this.decodeExtension(4,0);else if(e===215)n=this.decodeExtension(8,0);else if(e===216)n=this.decodeExtension(16,0);else if(e===199){let e=this.lookU8();n=this.decodeExtension(e,1)}else if(e===200){let e=this.lookU16();n=this.decodeExtension(e,2)}else if(e===201){let e=this.lookU32();n=this.decodeExtension(e,4)}else throw new t(`Unrecognized type byte: ${prettyByte(e)}`);this.complete();let r=this.stack;for(;r.length>0;){let e=r.top();if(e.type===i)if(e.array[e.position]=n,e.position++,e.position===e.size)n=e.array,r.release(e);else continue DECODE;else if(e.type===a){if(n===`__proto__`)throw new t(`The key __proto__ is not allowed`);e.key=this.mapKeyConverter(n),e.type=o;continue DECODE}else if(e.map[e.key]=n,e.readCount++,e.readCount===e.size)n=e.map,r.release(e);else{e.key=null,e.type=a;continue DECODE}}return n}}readHeadByte(){return this.headByte===-1&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=-1}readArraySize(){let e=this.readHeadByte();switch(e){case 220:return this.readU16();case 221:return this.readU32();default:if(e<160)return e-144;throw new t(`Unrecognized array type byte: ${prettyByte(e)}`)}}pushMapState(e){if(e>this.maxMapLength)throw new t(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(e)}pushArrayState(e){if(e>this.maxArrayLength)throw new t(`Max length exceeded: array length (${e}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(e)}decodeString(e,t){return!this.rawStrings||this.stateIsMapKey()?this.decodeUtf8String(e,t):this.decodeBinary(e,t)}decodeUtf8String(e,n){if(e>this.maxStrLength)throw new t(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+n+e)throw l;let r=this.pos+n,i;return i=this.stateIsMapKey()&&this.keyDecoder?.canBeCached(e)?this.keyDecoder.decode(this.bytes,r,e):utf8Decode(this.bytes,r,e),this.pos+=n+e,i}stateIsMapKey(){return this.stack.length>0?this.stack.top().type===a:!1}decodeBinary(e,n){if(e>this.maxBinLength)throw new t(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(e+n))throw l;let r=this.pos+n,i=this.bytes.subarray(r,r+e);return this.pos+=n+e,i}decodeExtension(e,n){if(e>this.maxExtLength)throw new t(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);let r=this.view.getInt8(this.pos+n),i=this.decodeBinary(e,n+1);return this.extensionCodec.decode(i,r,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let e=this.view.getUint8(this.pos);return this.pos++,e}readI8(){let e=this.view.getInt8(this.pos);return this.pos++,e}readU16(){let e=this.view.getUint16(this.pos);return this.pos+=2,e}readI16(){let e=this.view.getInt16(this.pos);return this.pos+=2,e}readU32(){let e=this.view.getUint32(this.pos);return this.pos+=4,e}readI32(){let e=this.view.getInt32(this.pos);return this.pos+=4,e}readU64(){let e=getUint64(this.view,this.pos);return this.pos+=8,e}readI64(){let e=getInt64(this.view,this.pos);return this.pos+=8,e}readU64AsBigInt(){let e=this.view.getBigUint64(this.pos);return this.pos+=8,e}readI64AsBigInt(){let e=this.view.getBigInt64(this.pos);return this.pos+=8,e}readF32(){let e=this.view.getFloat32(this.pos);return this.pos+=4,e}readF64(){let e=this.view.getFloat64(this.pos);return this.pos+=8,e}};function decode(e,t){return new d(t).decode(e)}export{decode as t};