Chenloong999 commited on
Commit
ec892d6
·
verified ·
1 Parent(s): 52e57a3

backup 2026-08-23T20:24:25.191693 (part 11)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .opencode/node_modules/msgpackr-extract/package.json +8 -8
  2. .opencode/node_modules/msgpackr-extract/src/extract.cpp +5 -1
  3. .opencode/node_modules/msgpackr/README.md +16 -0
  4. .opencode/node_modules/msgpackr/dist/index-no-eval.cjs +296 -259
  5. .opencode/node_modules/msgpackr/dist/index-no-eval.cjs.map +0 -0
  6. .opencode/node_modules/msgpackr/dist/index-no-eval.min.js +1 -1
  7. .opencode/node_modules/msgpackr/dist/index-no-eval.min.js.map +0 -0
  8. .opencode/node_modules/msgpackr/dist/index.js +296 -259
  9. .opencode/node_modules/msgpackr/dist/index.js.map +0 -0
  10. .opencode/node_modules/msgpackr/dist/index.min.js +1 -1
  11. .opencode/node_modules/msgpackr/dist/index.min.js.map +0 -0
  12. .opencode/node_modules/msgpackr/dist/node.cjs +320 -1078
  13. .opencode/node_modules/msgpackr/dist/node.cjs.map +0 -0
  14. .opencode/node_modules/msgpackr/dist/test.js +466 -1153
  15. .opencode/node_modules/msgpackr/dist/test.js.map +0 -0
  16. .opencode/node_modules/msgpackr/dist/unpack-no-eval.cjs +222 -207
  17. .opencode/node_modules/msgpackr/dist/unpack-no-eval.cjs.map +0 -0
  18. .opencode/node_modules/msgpackr/index.js +5 -5
  19. .opencode/node_modules/msgpackr/iterators.js +28 -28
  20. .opencode/node_modules/msgpackr/node-index.js +12 -13
  21. .opencode/node_modules/msgpackr/pack.js +615 -607
  22. .opencode/node_modules/msgpackr/package.json +2 -2
  23. .opencode/node_modules/msgpackr/stream.js +31 -31
  24. .opencode/node_modules/msgpackr/unpack.js +653 -637
  25. .opencode/node_modules/multipasta/dist/cjs/web.js +5 -2
  26. .opencode/node_modules/multipasta/dist/cjs/web.js.map +1 -1
  27. .opencode/node_modules/multipasta/dist/dts/web.d.ts.map +1 -1
  28. .opencode/node_modules/multipasta/dist/esm/web.js +5 -2
  29. .opencode/node_modules/multipasta/dist/esm/web.js.map +1 -1
  30. .opencode/node_modules/multipasta/package.json +1 -1
  31. .opencode/node_modules/multipasta/src/web.ts +5 -2
  32. .opencode/node_modules/pure-rand/lib/RandomGenerator-DcXj09Ch.d.ts +14 -0
  33. .opencode/node_modules/pure-rand/lib/distribution/uniformBigInt.d.ts +1 -1
  34. .opencode/node_modules/pure-rand/lib/distribution/uniformFloat32.d.ts +1 -1
  35. .opencode/node_modules/pure-rand/lib/distribution/uniformFloat64.d.ts +1 -1
  36. .opencode/node_modules/pure-rand/lib/distribution/uniformFloat64.js +3 -3
  37. .opencode/node_modules/pure-rand/lib/distribution/uniformInt.d.ts +1 -1
  38. .opencode/node_modules/pure-rand/lib/esm/RandomGenerator-DcXj09Ch.d.ts +14 -0
  39. .opencode/node_modules/pure-rand/lib/esm/distribution/uniformBigInt.d.ts +1 -1
  40. .opencode/node_modules/pure-rand/lib/esm/distribution/uniformFloat32.d.ts +1 -1
  41. .opencode/node_modules/pure-rand/lib/esm/distribution/uniformFloat64.d.ts +1 -1
  42. .opencode/node_modules/pure-rand/lib/esm/distribution/uniformFloat64.js +3 -3
  43. .opencode/node_modules/pure-rand/lib/esm/distribution/uniformInt.d.ts +1 -1
  44. .opencode/node_modules/pure-rand/lib/esm/generator/congruential32.js +12 -12
  45. .opencode/node_modules/pure-rand/lib/esm/generator/mersenne.js +1 -1
  46. .opencode/node_modules/pure-rand/lib/esm/generator/xoroshiro128plus.js +27 -13
  47. .opencode/node_modules/pure-rand/lib/esm/generator/xorshift128plus.js +32 -20
  48. .opencode/node_modules/pure-rand/lib/esm/types/JumpableRandomGenerator.d.ts +1 -1
  49. .opencode/node_modules/pure-rand/lib/esm/types/RandomGenerator.d.ts +1 -1
  50. .opencode/node_modules/pure-rand/lib/esm/utils/generateN.d.ts +1 -1
.opencode/node_modules/msgpackr-extract/package.json CHANGED
@@ -1,7 +1,7 @@
1
  {
2
  "name": "msgpackr-extract",
3
  "author": "Kris Zyp",
4
- "version": "3.0.3",
5
  "description": "Node addon for string extraction for msgpackr",
6
  "license": "MIT",
7
  "repository": {
@@ -17,7 +17,7 @@
17
  "prebuild-libc": "prebuildify-platform-packages --tag-libc --target 20.14.0 && prebuildify-platform-packages --platform-packages --napi --tag-libc --target 22.2.0 && ENABLE_V8_FUNCTIONS=false prebuildify-platform-packages --platform-packages --napi --tag-libc --target 20.14.0",
18
  "prebuild-libc-napi": "ENABLE_V8_FUNCTIONS=false prebuildify-platform-packages --platform-packages --napi --tag-libc --target 20.14.0",
19
  "prebuild-libc-alpine": "prebuildify-cross --image alpine --tag-libc --target 20.14.0",
20
- "publish-all": "cd prebuilds/win32-x64 && npm publish --access public && cd ../darwin-x64 && npm publish --access public && cd ../darwin-arm64 && npm publish --access public && cd ../linux-x64 && npm publish --access public && cd ../linux-arm64 && npm publish --access public && cd ../linux-arm && npm publish --access public && cd ../.. && npm publish --access public",
21
  "test": "node ./index.js"
22
  },
23
  "main": "./index.js",
@@ -35,12 +35,12 @@
35
  "download-msgpackr-prebuilds": "./bin/download-prebuilds.js"
36
  },
37
  "optionalDependencies": {
38
- "@msgpackr-extract/msgpackr-extract-darwin-arm64": "3.0.3",
39
- "@msgpackr-extract/msgpackr-extract-darwin-x64": "3.0.3",
40
- "@msgpackr-extract/msgpackr-extract-linux-arm": "3.0.3",
41
- "@msgpackr-extract/msgpackr-extract-linux-arm64": "3.0.3",
42
- "@msgpackr-extract/msgpackr-extract-linux-x64": "3.0.3",
43
- "@msgpackr-extract/msgpackr-extract-win32-x64": "3.0.3"
44
  },
45
  "devDependencies": {
46
  "prebuildify-platform-packages": "5.0.4",
 
1
  {
2
  "name": "msgpackr-extract",
3
  "author": "Kris Zyp",
4
+ "version": "3.0.4",
5
  "description": "Node addon for string extraction for msgpackr",
6
  "license": "MIT",
7
  "repository": {
 
17
  "prebuild-libc": "prebuildify-platform-packages --tag-libc --target 20.14.0 && prebuildify-platform-packages --platform-packages --napi --tag-libc --target 22.2.0 && ENABLE_V8_FUNCTIONS=false prebuildify-platform-packages --platform-packages --napi --tag-libc --target 20.14.0",
18
  "prebuild-libc-napi": "ENABLE_V8_FUNCTIONS=false prebuildify-platform-packages --platform-packages --napi --tag-libc --target 20.14.0",
19
  "prebuild-libc-alpine": "prebuildify-cross --image alpine --tag-libc --target 20.14.0",
20
+ "publish-all": "cd prebuilds/win32-x64 && (npm publish --access public || true) && cd ../darwin-x64 && (npm publish --access public || true) && cd ../darwin-arm64 && (npm publish --access public || true) && cd ../linux-x64 && (npm publish --access public || true) && cd ../linux-arm64 && (npm publish --access public || true) && cd ../linux-arm && (npm publish --access public || true) && cd ../.. && npm publish --access public",
21
  "test": "node ./index.js"
22
  },
23
  "main": "./index.js",
 
35
  "download-msgpackr-prebuilds": "./bin/download-prebuilds.js"
36
  },
37
  "optionalDependencies": {
38
+ "@msgpackr-extract/msgpackr-extract-darwin-arm64": "3.0.4",
39
+ "@msgpackr-extract/msgpackr-extract-darwin-x64": "3.0.4",
40
+ "@msgpackr-extract/msgpackr-extract-linux-arm": "3.0.4",
41
+ "@msgpackr-extract/msgpackr-extract-linux-arm64": "3.0.4",
42
+ "@msgpackr-extract/msgpackr-extract-linux-x64": "3.0.4",
43
+ "@msgpackr-extract/msgpackr-extract-win32-x64": "3.0.4"
44
  },
45
  "devDependencies": {
46
  "prebuildify-platform-packages": "5.0.4",
.opencode/node_modules/msgpackr-extract/src/extract.cpp CHANGED
@@ -131,7 +131,7 @@ public:
131
  length += source[position++] << 16;
132
  length += source[position++] << 8;
133
  length += source[position++];
134
- if (length + position > size) {
135
  return unexpectedEnd(env);
136
  }
137
  readString(env, length, false, target);
@@ -220,6 +220,8 @@ void setupTokenTable() {
220
  length += source[position++] << 16;
221
  length += source[position++] << 8;
222
  length += source[position++];
 
 
223
  return position + length;
224
  });
225
  // ext 8
@@ -247,6 +249,8 @@ void setupTokenTable() {
247
  length += source[position++] << 16;
248
  length += source[position++] << 8;
249
  length += source[position++];
 
 
250
  position++;
251
  return position + length;
252
  });
 
131
  length += source[position++] << 16;
132
  length += source[position++] << 8;
133
  length += source[position++];
134
+ if (length > size - position) {
135
  return unexpectedEnd(env);
136
  }
137
  readString(env, length, false, target);
 
220
  length += source[position++] << 16;
221
  length += source[position++] << 8;
222
  length += source[position++];
223
+ if (length > size - position)
224
+ return UNEXPECTED_END;
225
  return position + length;
226
  });
227
  // ext 8
 
249
  length += source[position++] << 16;
250
  length += source[position++] << 8;
251
  length += source[position++];
252
+ if (length >= size - position)
253
+ return UNEXPECTED_END;
254
  position++;
255
  return position + length;
256
  });
.opencode/node_modules/msgpackr/README.md CHANGED
@@ -353,6 +353,22 @@ msgpackr saves all JavaScript `Date`s using the standard MessagePack date extens
353
  ### Structured Cloning
354
  With structured cloning enabled, msgpackr will also use extensions to store Set, Map, Error, RegExp, ArrayBufferView objects and preserve their types.
355
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
356
  ## Alternate Encoding/Package
357
  The high-performance serialization and deserialization algorithms in the msgpackr package are also available in the [cbor-x](https://github.com/kriszyp/cbor-x) for the CBOR format, with the same API and design. A quick summary of the pros and cons of using MessagePack vs CBOR are:
358
  * MessagePack has wider adoption, and, at least with this implementation is slightly more efficient (by roughly 1%).
 
353
  ### Structured Cloning
354
  With structured cloning enabled, msgpackr will also use extensions to store Set, Map, Error, RegExp, ArrayBufferView objects and preserve their types.
355
 
356
+ ## Upgrading to 2.0
357
+
358
+ msgpackr 2.0 removes the `randomAccessStructure` option and the internal `struct.js` module that implemented random-access struct encoding. This feature was previously undocumented and intended for internal use.
359
+
360
+ If you were using `randomAccessStructure: true`, the functionality is now available as the standalone [`structon`](https://github.com/HarperFast/structon) package. Structon provides the same random-access encoding with a more explicit API:
361
+
362
+ ```js
363
+ import { Packr } from 'msgpackr';
364
+ import { createStructon } from 'structon';
365
+
366
+ const Structon = createStructon(Packr);
367
+ const codec = new Structon({ structures: [] });
368
+ ```
369
+
370
+ Data encoded with `randomAccessStructure: true` in earlier msgpackr versions is fully readable by structon, and vice versa—the binary format is identical.
371
+
372
  ## Alternate Encoding/Package
373
  The high-performance serialization and deserialization algorithms in the msgpackr package are also available in the [cbor-x](https://github.com/kriszyp/cbor-x) for the CBOR format, with the same API and design. A quick summary of the pros and cons of using MessagePack vs CBOR are:
374
  * MessagePack has wider adoption, and, at least with this implementation is slightly more efficient (by roughly 1%).
.opencode/node_modules/msgpackr/dist/index-no-eval.cjs CHANGED
@@ -29,7 +29,6 @@
29
  C1.name = 'MessagePack 0xC1';
30
  var sequentialMode = false;
31
  var inlineObjectReadThreshold = 2;
32
- var readStruct;
33
  var BlockedFunction; // we use search and replace to change the next call to BlockedFunction to avoid CSP issues for
34
 
35
  class Unpackr {
@@ -62,8 +61,8 @@
62
  // re-entrant execution, save the state and restore it after we do this unpack
63
  return saveState(() => {
64
  clearSource();
65
- return this ? this.unpack(source, options) : Unpackr.prototype.unpack.call(defaultOptions, source, options)
66
- })
67
  }
68
  if (!source.buffer && source.constructor === ArrayBuffer)
69
  source = typeof Buffer !== 'undefined' ? Buffer.from(source) : new Uint8Array(source);
@@ -87,14 +86,14 @@
87
  // if it doesn't have a buffer, maybe it is the wrong type of object
88
  src = null;
89
  if (source instanceof Uint8Array)
90
- throw error
91
- throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source))
92
  }
93
  if (this instanceof Unpackr) {
94
  currentUnpackr = this;
95
  if (this.structures) {
96
  currentStructures = this.structures;
97
- return checkedRead(options)
98
  } else if (!currentStructures || currentStructures.length > 0) {
99
  currentStructures = [];
100
  }
@@ -103,7 +102,7 @@
103
  if (!currentStructures || currentStructures.length > 0)
104
  currentStructures = [];
105
  }
106
- return checkedRead(options)
107
  }
108
  unpackMultiple(source, forEach) {
109
  let values, lastPosition = 0;
@@ -116,7 +115,7 @@
116
  while(position$1 < size) {
117
  lastPosition = position$1;
118
  if (forEach(checkedRead(), lastPosition, position$1) === false) {
119
- return
120
  }
121
  }
122
  }
@@ -126,18 +125,20 @@
126
  lastPosition = position$1;
127
  values.push(checkedRead());
128
  }
129
- return values
130
  }
131
  } catch(error) {
132
  error.lastPosition = lastPosition;
133
  error.values = values;
134
- throw error
135
  } finally {
136
  sequentialMode = false;
137
  clearSource();
138
  }
139
  }
140
  _mergeStructures(loadedStructures, existingStructures) {
 
 
141
  loadedStructures = loadedStructures || [];
142
  if (Object.isFrozen(loadedStructures))
143
  loadedStructures = loadedStructures.map(structure => structure.slice(0));
@@ -161,10 +162,10 @@
161
  }
162
  }
163
  }
164
- return this.structures = loadedStructures
165
  }
166
  decode(source, options) {
167
- return this.unpack(source, options)
168
  }
169
  }
170
  function checkedRead(options) {
@@ -175,8 +176,8 @@
175
  currentStructures.length = sharedLength;
176
  }
177
  let result;
178
- if (currentUnpackr.randomAccessStructure && src[position$1] < 0x40 && src[position$1] >= 0x20 && readStruct) {
179
- result = readStruct(src, position$1, srcEnd, currentUnpackr);
180
  src = null; // dispose of this so that recursive unpack calls don't save state
181
  if (!(options && options.lazy) && result)
182
  result = result.toJSON();
@@ -202,7 +203,7 @@
202
  referenceMap = null;
203
  } else if (position$1 > srcEnd) {
204
  // over read
205
- throw new Error('Unexpected end of MessagePack data')
206
  } else if (!sequentialMode) {
207
  let jsonView;
208
  try {
@@ -210,10 +211,10 @@
210
  } catch(error) {
211
  jsonView = '(JSON view not available ' + error + ')';
212
  }
213
- throw new Error('Data read, but end of buffer not reached ' + jsonView)
214
  }
215
  // else more to read, but we are reading sequentially, so don't clear source yet
216
- return result
217
  } catch(error) {
218
  if (currentStructures && currentStructures.restoreStructures)
219
  restoreStructures();
@@ -221,7 +222,7 @@
221
  if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position$1 > srcEnd) {
222
  error.incomplete = true;
223
  }
224
- throw error
225
  }
226
  }
227
 
@@ -237,7 +238,7 @@
237
  if (token < 0xa0) {
238
  if (token < 0x80) {
239
  if (token < 0x40)
240
- return token
241
  else {
242
  let structure = currentStructures[token & 0x3f] ||
243
  currentUnpackr.getStructures && loadStructures()[token & 0x3f];
@@ -245,9 +246,9 @@
245
  if (!structure.read) {
246
  structure.read = createStructureReader(structure, token & 0x3f);
247
  }
248
- return structure.read()
249
  } else
250
- return token
251
  }
252
  } else if (token < 0x90) {
253
  // map
@@ -260,13 +261,13 @@
260
  key = '__proto_';
261
  object[key] = read();
262
  }
263
- return object
264
  } else {
265
  let map = new Map();
266
  for (let i = 0; i < token; i++) {
267
  map.set(read(), read());
268
  }
269
- return map
270
  }
271
  } else {
272
  token -= 0x90;
@@ -275,91 +276,91 @@
275
  array[i] = read();
276
  }
277
  if (currentUnpackr.freezeData)
278
- return Object.freeze(array)
279
- return array
280
  }
281
  } else if (token < 0xc0) {
282
  // fixstr
283
  let length = token - 0xa0;
284
  if (srcStringEnd >= position$1) {
285
- return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart)
286
  }
287
  if (srcStringEnd == 0 && srcEnd < 140) {
288
  // for small blocks, avoiding the overhead of the extract call is helpful
289
  let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
290
  if (string != null)
291
- return string
292
  }
293
- return readFixedString(length)
294
  } else {
295
  let value;
296
  switch (token) {
297
- case 0xc0: return null
298
  case 0xc1:
299
  if (bundledStrings$1) {
300
  value = read(); // followed by the length of the string in characters (not bytes!)
301
  if (value > 0)
302
- return bundledStrings$1[1].slice(bundledStrings$1.position1, bundledStrings$1.position1 += value)
303
  else
304
- return bundledStrings$1[0].slice(bundledStrings$1.position0, bundledStrings$1.position0 -= value)
305
  }
306
  return C1; // "never-used", return special object to denote that
307
- case 0xc2: return false
308
- case 0xc3: return true
309
  case 0xc4:
310
  // bin 8
311
  value = src[position$1++];
312
  if (value === undefined)
313
- throw new Error('Unexpected end of buffer')
314
- return readBin(value)
315
  case 0xc5:
316
  // bin 16
317
  value = dataView.getUint16(position$1);
318
  position$1 += 2;
319
- return readBin(value)
320
  case 0xc6:
321
  // bin 32
322
  value = dataView.getUint32(position$1);
323
  position$1 += 4;
324
- return readBin(value)
325
  case 0xc7:
326
  // ext 8
327
- return readExt(src[position$1++])
328
  case 0xc8:
329
  // ext 16
330
  value = dataView.getUint16(position$1);
331
  position$1 += 2;
332
- return readExt(value)
333
  case 0xc9:
334
  // ext 32
335
  value = dataView.getUint32(position$1);
336
  position$1 += 4;
337
- return readExt(value)
338
  case 0xca:
339
  value = dataView.getFloat32(position$1);
340
  if (currentUnpackr.useFloat32 > 2) {
341
  // this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
342
  let multiplier = mult10[((src[position$1] & 0x7f) << 1) | (src[position$1 + 1] >> 7)];
343
  position$1 += 4;
344
- return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier
345
  }
346
  position$1 += 4;
347
- return value
348
  case 0xcb:
349
  value = dataView.getFloat64(position$1);
350
  position$1 += 8;
351
- return value
352
  // uint handlers
353
  case 0xcc:
354
- return src[position$1++]
355
  case 0xcd:
356
  value = dataView.getUint16(position$1);
357
  position$1 += 2;
358
- return value
359
  case 0xce:
360
  value = dataView.getUint32(position$1);
361
  position$1 += 4;
362
- return value
363
  case 0xcf:
364
  if (currentUnpackr.int64AsType === 'number') {
365
  value = dataView.getUint32(position$1) * 0x100000000;
@@ -372,19 +373,19 @@
372
  } else
373
  value = dataView.getBigUint64(position$1);
374
  position$1 += 8;
375
- return value
376
 
377
  // int handlers
378
  case 0xd0:
379
- return dataView.getInt8(position$1++)
380
  case 0xd1:
381
  value = dataView.getInt16(position$1);
382
  position$1 += 2;
383
- return value
384
  case 0xd2:
385
  value = dataView.getInt32(position$1);
386
  position$1 += 4;
387
- return value
388
  case 0xd3:
389
  if (currentUnpackr.int64AsType === 'number') {
390
  value = dataView.getInt32(position$1) * 0x100000000;
@@ -397,96 +398,96 @@
397
  } else
398
  value = dataView.getBigInt64(position$1);
399
  position$1 += 8;
400
- return value
401
 
402
  case 0xd4:
403
  // fixext 1
404
  value = src[position$1++];
405
  if (value == 0x72) {
406
- return recordDefinition(src[position$1++] & 0x3f)
407
  } else {
408
  let extension = currentExtensions[value];
409
  if (extension) {
410
  if (extension.read) {
411
  position$1++; // skip filler byte
412
- return extension.read(read())
413
  } else if (extension.noBuffer) {
414
  position$1++; // skip filler byte
415
- return extension()
416
  } else
417
- return extension(src.subarray(position$1, ++position$1))
418
  } else
419
- throw new Error('Unknown extension ' + value)
420
  }
421
  case 0xd5:
422
  // fixext 2
423
  value = src[position$1];
424
  if (value == 0x72) {
425
  position$1++;
426
- return recordDefinition(src[position$1++] & 0x3f, src[position$1++])
427
  } else
428
- return readExt(2)
429
  case 0xd6:
430
  // fixext 4
431
- return readExt(4)
432
  case 0xd7:
433
  // fixext 8
434
- return readExt(8)
435
  case 0xd8:
436
  // fixext 16
437
- return readExt(16)
438
  case 0xd9:
439
  // str 8
440
  value = src[position$1++];
441
  if (srcStringEnd >= position$1) {
442
- return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
443
  }
444
- return readString8(value)
445
  case 0xda:
446
  // str 16
447
  value = dataView.getUint16(position$1);
448
  position$1 += 2;
449
  if (srcStringEnd >= position$1) {
450
- return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
451
  }
452
- return readString16(value)
453
  case 0xdb:
454
  // str 32
455
  value = dataView.getUint32(position$1);
456
  position$1 += 4;
457
  if (srcStringEnd >= position$1) {
458
- return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
459
  }
460
- return readString32(value)
461
  case 0xdc:
462
  // array 16
463
  value = dataView.getUint16(position$1);
464
  position$1 += 2;
465
- return readArray(value)
466
  case 0xdd:
467
  // array 32
468
  value = dataView.getUint32(position$1);
469
  position$1 += 4;
470
- return readArray(value)
471
  case 0xde:
472
  // map 16
473
  value = dataView.getUint16(position$1);
474
  position$1 += 2;
475
- return readMap(value)
476
  case 0xdf:
477
  // map 32
478
  value = dataView.getUint32(position$1);
479
  position$1 += 4;
480
- return readMap(value)
481
  default: // negative int
482
  if (token >= 0xe0)
483
- return token - 0x100
484
  if (token === undefined) {
485
  let error = new Error('Unexpected end of MessagePack data');
486
  error.incomplete = true;
487
- throw error
488
  }
489
- throw new Error('Unknown MessagePack token ' + token)
490
 
491
  }
492
  }
@@ -505,9 +506,10 @@
505
  inlineObjectReadThreshold = Infinity; // disable going forward
506
  return readObject(); // recursively try again
507
  }
 
508
  if (structure.highByte === 0)
509
  structure.read = createSecondByteReader(firstId, structure.read);
510
- return optimizedReadObject() // second byte is already read, if there is one so immediately read object
511
  }
512
  let object = {};
513
  for (let i = 0, l = structure.length; i < l; i++) {
@@ -518,38 +520,44 @@
518
  }
519
  if (currentUnpackr.freezeData)
520
  return Object.freeze(object);
521
- return object
522
  }
523
  readObject.count = 0;
 
 
 
 
 
 
524
  if (structure.highByte === 0) {
525
- return createSecondByteReader(firstId, readObject)
526
  }
527
- return readObject
528
  }
529
 
530
  const createSecondByteReader = (firstId, read0) => {
531
  return function() {
532
  let highByte = src[position$1++];
533
  if (highByte === 0)
534
- return read0()
535
  let id = firstId < 32 ? -(firstId + (highByte << 5)) : firstId + (highByte << 5);
536
  let structure = currentStructures[id] || loadStructures()[id];
537
  if (!structure) {
538
- throw new Error('Record id is not defined for ' + id)
539
  }
540
  if (!structure.read)
541
  structure.read = createStructureReader(structure, firstId);
542
- return structure.read()
543
- }
544
  };
545
 
546
  function loadStructures() {
547
  let loadedStructures = saveState(() => {
548
  // save the state in case getStructures modifies our buffer
549
  src = null;
550
- return currentUnpackr.getStructures()
551
  });
552
- return currentStructures = currentUnpackr._mergeStructures(loadedStructures, currentStructures)
553
  }
554
 
555
  var readFixedString = readStringJS;
@@ -561,10 +569,10 @@
561
  let result;
562
  if (length < 16) {
563
  if (result = shortStringInJS(length))
564
- return result
565
  }
566
  if (length > 64 && decoder)
567
- return decoder.decode(src.subarray(position$1, position$1 += length))
568
  const end = position$1 + length;
569
  const units = [];
570
  result = '';
@@ -575,43 +583,49 @@
575
  units.push(byte1);
576
  } else if ((byte1 & 0xe0) === 0xc0) {
577
  // 2 bytes
578
- const byte2 = src[position$1++] & 0x3f;
579
- const codePoint = ((byte1 & 0x1f) << 6) | byte2;
580
- // Reject overlong encoding: 2-byte sequences must encode values >= 0x80
581
- if (codePoint < 0x80) {
582
- units.push(0xFFFD); // replacement character
583
  } else {
584
- units.push(codePoint);
 
585
  }
586
  } else if ((byte1 & 0xf0) === 0xe0) {
587
  // 3 bytes
588
- const byte2 = src[position$1++] & 0x3f;
589
- const byte3 = src[position$1++] & 0x3f;
590
- const codePoint = ((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3;
591
- // Reject overlong encoding: 3-byte sequences must encode values >= 0x800
592
- // Also reject surrogates (0xD800-0xDFFF)
593
- if (codePoint < 0x800 || (codePoint >= 0xD800 && codePoint <= 0xDFFF)) {
594
- units.push(0xFFFD); // replacement character
595
  } else {
596
- units.push(codePoint);
 
 
 
 
 
 
597
  }
598
  } else if ((byte1 & 0xf8) === 0xf0) {
599
  // 4 bytes
600
- const byte2 = src[position$1++] & 0x3f;
601
- const byte3 = src[position$1++] & 0x3f;
602
- const byte4 = src[position$1++] & 0x3f;
603
- let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;
604
- // Reject overlong encoding: 4-byte sequences must encode values >= 0x10000
605
- // Also reject values > 0x10FFFF (maximum valid Unicode)
606
- if (unit < 0x10000 || unit > 0x10FFFF) {
607
- units.push(0xFFFD); // replacement character
608
- } else if (unit > 0xffff) {
609
- unit -= 0x10000;
610
- units.push(((unit >>> 10) & 0x3ff) | 0xd800);
611
- unit = 0xdc00 | (unit & 0x3ff);
612
- units.push(unit);
613
  } else {
614
- units.push(unit);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
615
  }
616
  } else {
617
  units.push(0xFFFD); // replacement character for invalid lead byte
@@ -627,7 +641,7 @@
627
  result += fromCharCode.apply(String, units);
628
  }
629
 
630
- return result
631
  }
632
 
633
  function readArray(length) {
@@ -636,8 +650,8 @@
636
  array[i] = read();
637
  }
638
  if (currentUnpackr.freezeData)
639
- return Object.freeze(array)
640
- return array
641
  }
642
 
643
  function readMap(length) {
@@ -649,13 +663,13 @@
649
  key = '__proto_';
650
  object[key] = read();
651
  }
652
- return object
653
  } else {
654
  let map = new Map();
655
  for (let i = 0; i < length; i++) {
656
  map.set(read(), read());
657
  }
658
- return map
659
  }
660
  }
661
 
@@ -667,40 +681,40 @@
667
  const byte = src[position$1++];
668
  if ((byte & 0x80) > 0) {
669
  position$1 = start;
670
- return
671
  }
672
  bytes[i] = byte;
673
  }
674
- return fromCharCode.apply(String, bytes)
675
  }
676
  function shortStringInJS(length) {
677
  if (length < 4) {
678
  if (length < 2) {
679
  if (length === 0)
680
- return ''
681
  else {
682
  let a = src[position$1++];
683
  if ((a & 0x80) > 1) {
684
  position$1 -= 1;
685
- return
686
  }
687
- return fromCharCode(a)
688
  }
689
  } else {
690
  let a = src[position$1++];
691
  let b = src[position$1++];
692
  if ((a & 0x80) > 0 || (b & 0x80) > 0) {
693
  position$1 -= 2;
694
- return
695
  }
696
  if (length < 3)
697
- return fromCharCode(a, b)
698
  let c = src[position$1++];
699
  if ((c & 0x80) > 0) {
700
  position$1 -= 3;
701
- return
702
  }
703
- return fromCharCode(a, b, c)
704
  }
705
  } else {
706
  let a = src[position$1++];
@@ -709,34 +723,34 @@
709
  let d = src[position$1++];
710
  if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
711
  position$1 -= 4;
712
- return
713
  }
714
  if (length < 6) {
715
  if (length === 4)
716
- return fromCharCode(a, b, c, d)
717
  else {
718
  let e = src[position$1++];
719
  if ((e & 0x80) > 0) {
720
  position$1 -= 5;
721
- return
722
  }
723
- return fromCharCode(a, b, c, d, e)
724
  }
725
  } else if (length < 8) {
726
  let e = src[position$1++];
727
  let f = src[position$1++];
728
  if ((e & 0x80) > 0 || (f & 0x80) > 0) {
729
  position$1 -= 6;
730
- return
731
  }
732
  if (length < 7)
733
- return fromCharCode(a, b, c, d, e, f)
734
  let g = src[position$1++];
735
  if ((g & 0x80) > 0) {
736
  position$1 -= 7;
737
- return
738
  }
739
- return fromCharCode(a, b, c, d, e, f, g)
740
  } else {
741
  let e = src[position$1++];
742
  let f = src[position$1++];
@@ -744,34 +758,34 @@
744
  let h = src[position$1++];
745
  if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
746
  position$1 -= 8;
747
- return
748
  }
749
  if (length < 10) {
750
  if (length === 8)
751
- return fromCharCode(a, b, c, d, e, f, g, h)
752
  else {
753
  let i = src[position$1++];
754
  if ((i & 0x80) > 0) {
755
  position$1 -= 9;
756
- return
757
  }
758
- return fromCharCode(a, b, c, d, e, f, g, h, i)
759
  }
760
  } else if (length < 12) {
761
  let i = src[position$1++];
762
  let j = src[position$1++];
763
  if ((i & 0x80) > 0 || (j & 0x80) > 0) {
764
  position$1 -= 10;
765
- return
766
  }
767
  if (length < 11)
768
- return fromCharCode(a, b, c, d, e, f, g, h, i, j)
769
  let k = src[position$1++];
770
  if ((k & 0x80) > 0) {
771
  position$1 -= 11;
772
- return
773
  }
774
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k)
775
  } else {
776
  let i = src[position$1++];
777
  let j = src[position$1++];
@@ -779,34 +793,34 @@
779
  let l = src[position$1++];
780
  if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
781
  position$1 -= 12;
782
- return
783
  }
784
  if (length < 14) {
785
  if (length === 12)
786
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l)
787
  else {
788
  let m = src[position$1++];
789
  if ((m & 0x80) > 0) {
790
  position$1 -= 13;
791
- return
792
  }
793
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m)
794
  }
795
  } else {
796
  let m = src[position$1++];
797
  let n = src[position$1++];
798
  if ((m & 0x80) > 0 || (n & 0x80) > 0) {
799
  position$1 -= 14;
800
- return
801
  }
802
  if (length < 15)
803
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
804
  let o = src[position$1++];
805
  if ((o & 0x80) > 0) {
806
  position$1 -= 15;
807
- return
808
  }
809
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
810
  }
811
  }
812
  }
@@ -824,22 +838,22 @@
824
  case 0xd9:
825
  // str 8
826
  length = src[position$1++];
827
- break
828
  case 0xda:
829
  // str 16
830
  length = dataView.getUint16(position$1);
831
  position$1 += 2;
832
- break
833
  case 0xdb:
834
  // str 32
835
  length = dataView.getUint32(position$1);
836
  position$1 += 4;
837
- break
838
  default:
839
- throw new Error('Expected string')
840
  }
841
  }
842
- return readStringJS(length)
843
  }
844
 
845
 
@@ -847,7 +861,7 @@
847
  return currentUnpackr.copyBuffers ?
848
  // specifically use the copying slice (not the node one)
849
  Uint8Array.prototype.slice.call(src, position$1, position$1 += length) :
850
- src.subarray(position$1, position$1 += length)
851
  }
852
  function readExt(length) {
853
  let type = src[position$1++];
@@ -860,10 +874,10 @@
860
  } finally {
861
  position$1 = end;
862
  }
863
- })
864
  }
865
  else
866
- throw new Error('Unknown extension type ' + type)
867
  }
868
 
869
  var keyCache = new Array(4096);
@@ -873,12 +887,12 @@
873
  // fixstr, potentially use key cache
874
  length = length - 0xa0;
875
  if (srcStringEnd >= position$1) // if it has been extracted, must use it (and faster anyway)
876
- return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart)
877
  else if (!(srcStringEnd == 0 && srcEnd < 180))
878
- return readFixedString(length)
879
  } else { // not cacheable, go back and do a standard read
880
  position$1--;
881
- return asSafeString(read())
882
  }
883
  let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position$1) : length > 0 ? src[position$1] : 0)) & 0xfff;
884
  let entry = keyCache[key];
@@ -891,7 +905,7 @@
891
  chunk = dataView.getUint32(checkPosition);
892
  if (chunk != entry[i++]) {
893
  checkPosition = 0x70000000;
894
- break
895
  }
896
  checkPosition += 4;
897
  }
@@ -900,12 +914,12 @@
900
  chunk = src[checkPosition++];
901
  if (chunk != entry[i++]) {
902
  checkPosition = 0x70000000;
903
- break
904
  }
905
  }
906
  if (checkPosition === end) {
907
  position$1 = checkPosition;
908
- return entry.string
909
  }
910
  end -= 3;
911
  checkPosition = position$1;
@@ -926,8 +940,8 @@
926
  // for small blocks, avoiding the overhead of the extract call is helpful
927
  let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
928
  if (string != null)
929
- return entry.string = string
930
- return entry.string = readFixedString(length)
931
  }
932
 
933
  function asSafeString(property) {
@@ -958,7 +972,12 @@
958
  }
959
  currentStructures[id] = structure;
960
  structure.read = createStructureReader(structure, firstByte);
961
- return structure.read()
 
 
 
 
 
962
  };
963
  currentExtensions[0] = () => {}; // notepack defines extension 0 to mean undefined, so use that as the default here
964
  currentExtensions[0].noBuffer = true;
@@ -980,17 +999,17 @@
980
  out <<= BigInt(64);
981
  out |= view.getBigUint64(i);
982
  }
983
- return out
984
  }
985
  // if (length === 8) return view.getBigUint64(start)
986
  let middle = start + (length >> 4 << 3);
987
  let left = decode(start, middle);
988
  let right = decode(middle, end);
989
- return (left << BigInt((end - middle) * 8)) | right
990
  };
991
  head = (head << BigInt((view.byteLength - headLength) * 8)) | decode(headLength, view.byteLength);
992
  }
993
- return head
994
  };
995
 
996
  let errors = {
@@ -1001,14 +1020,14 @@
1001
  if (!errors[data[0]]) {
1002
  let error = Error(data[1], { cause: data[2] });
1003
  error.name = data[0];
1004
- return error
1005
  }
1006
- return errors[data[0]](data[1], { cause: data[2] })
1007
  };
1008
 
1009
  currentExtensions[0x69] = (data) => {
1010
  // id extension (for structured clones)
1011
- if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled')
1012
  let id = dataView.getUint32(position$1 - 4);
1013
  if (!referenceMap)
1014
  referenceMap = new Map();
@@ -1029,7 +1048,7 @@
1029
  let targetProperties = read(); // read the next value as the target object to id
1030
  if (!refEntry.used) {
1031
  // no cycle, can just use the returned read object
1032
- return refEntry.target = targetProperties // replace the placeholder with the real one
1033
  } else {
1034
  // there is a cycle, so we have to assign properties to original target
1035
  Object.assign(target, targetProperties);
@@ -1040,16 +1059,16 @@
1040
  for (let [k, v] of targetProperties.entries()) target.set(k, v);
1041
  if (target instanceof Set)
1042
  for (let i of Array.from(targetProperties)) target.add(i);
1043
- return target
1044
  };
1045
 
1046
  currentExtensions[0x70] = (data) => {
1047
  // pointer extension (for structured clones)
1048
- if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled')
1049
  let id = dataView.getUint32(position$1 - 4);
1050
  let refEntry = referenceMap.get(id);
1051
  refEntry.used = true;
1052
- return refEntry.target
1053
  };
1054
 
1055
  currentExtensions[0x73] = () => new Set(read());
@@ -1064,15 +1083,15 @@
1064
 
1065
  let typedArrayName = typedArrays[typeCode];
1066
  if (!typedArrayName) {
1067
- if (typeCode === 16) return buffer
1068
- if (typeCode === 17) return new DataView(buffer)
1069
- throw new Error('Could not find typed array for code ' + typeCode)
1070
  }
1071
- return new glbl[typedArrayName](buffer)
1072
  };
1073
  currentExtensions[0x78] = () => {
1074
  let data = read();
1075
- return new RegExp(data[0], data[1])
1076
  };
1077
  const TEMP_BUNDLE = [];
1078
  currentExtensions[0x62] = (data) => {
@@ -1085,28 +1104,30 @@
1085
  bundledStrings$1.position1 = 0;
1086
  bundledStrings$1.postBundlePosition = position$1;
1087
  position$1 = dataPosition;
1088
- return read()
1089
  };
1090
 
1091
  currentExtensions[0xff] = (data) => {
1092
  // 32-bit date extension
1093
  if (data.length == 4)
1094
- return new Date((data[0] * 0x1000000 + (data[1] << 16) + (data[2] << 8) + data[3]) * 1000)
1095
  else if (data.length == 8)
1096
  return new Date(
1097
  ((data[0] << 22) + (data[1] << 14) + (data[2] << 6) + (data[3] >> 2)) / 1000000 +
1098
- ((data[3] & 0x3) * 0x100000000 + data[4] * 0x1000000 + (data[5] << 16) + (data[6] << 8) + data[7]) * 1000)
1099
  else if (data.length == 12)
1100
  return new Date(
1101
  ((data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]) / 1000000 +
1102
- (((data[4] & 0x80) ? -0x1000000000000 : 0) + data[6] * 0x10000000000 + data[7] * 0x100000000 + data[8] * 0x1000000 + (data[9] << 16) + (data[10] << 8) + data[11]) * 1000)
1103
  else
1104
- return new Date('invalid')
1105
  };
1106
  // registration of bulk record definition?
1107
  // currentExtensions[0x52] = () =>
1108
 
1109
  function saveState(callback) {
 
 
1110
  let savedSrcEnd = srcEnd;
1111
  let savedPosition = position$1;
1112
  let savedSrcStringStart = srcStringStart;
@@ -1135,7 +1156,7 @@
1135
  currentStructures.splice(0, currentStructures.length, ...savedStructuresContents);
1136
  currentUnpackr = savedPackr;
1137
  dataView = new DataView(src.buffer, src.byteOffset, src.byteLength);
1138
- return value
1139
  }
1140
  function clearSource() {
1141
  src = null;
@@ -1170,8 +1191,12 @@
1170
  function roundFloat32(float32Number) {
1171
  f32Array[0] = float32Number;
1172
  let multiplier = mult10[((u8Array[3] & 0x7f) << 1) | (u8Array[2] >> 7)];
1173
- return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier
1174
  }
 
 
 
 
1175
 
1176
  let textEncoder;
1177
  try {
@@ -1180,7 +1205,7 @@
1180
  let extensions, extensionClasses;
1181
  const hasNodeBuffer = typeof Buffer !== 'undefined';
1182
  const ByteArrayAllocate = hasNodeBuffer ?
1183
- function(length) { return Buffer.allocUnsafeSlow(length) } : Uint8Array;
1184
  const ByteArray = hasNodeBuffer ? Buffer : Uint8Array;
1185
  const MAX_BUFFER_SIZE = hasNodeBuffer ? 0x100000000 : 0x7fd00000;
1186
  let target, keysTarget;
@@ -1188,7 +1213,6 @@
1188
  let position = 0;
1189
  let safeEnd;
1190
  let bundledStrings = null;
1191
- let writeStructSlots;
1192
  const MAX_BUNDLE_SIZE = 0x5500; // maximum characters such that the encoded bytes fits in 16 bits.
1193
  const hasNonLatin = /[\u0080-\uFFFF]/;
1194
  const RECORD_SYMBOL = Symbol('record-id');
@@ -1201,10 +1225,10 @@
1201
  let structures;
1202
  let referenceMap;
1203
  let encodeUtf8 = ByteArray.prototype.utf8Write ? function(string, position) {
1204
- return target.utf8Write(string, position, target.byteLength - position)
1205
  } : (textEncoder && textEncoder.encodeInto) ?
1206
  function(string, position) {
1207
- return textEncoder.encodeInto(string, target.subarray(position)).written
1208
  } : false;
1209
 
1210
  let packr = this;
@@ -1216,7 +1240,7 @@
1216
  if (maxSharedStructures == null)
1217
  maxSharedStructures = hasSharedStructures ? 32 : 0;
1218
  if (maxSharedStructures > 8160)
1219
- throw new Error('Maximum maxSharedStructure is 8160')
1220
  if (options.structuredClone && options.moreTypes == undefined) {
1221
  this.moreTypes = true;
1222
  }
@@ -1230,7 +1254,7 @@
1230
  let sharedLimitId = maxSharedStructures + 0x40;
1231
  let maxStructureId = maxSharedStructures + maxOwnStructures + 0x40;
1232
  if (maxStructureId > 8256) {
1233
- throw new Error('Maximum maxSharedStructure + maxOwnStructure is 8192')
1234
  }
1235
  let recordIdsToRemove = [];
1236
  let transitionsCount = 0;
@@ -1266,7 +1290,7 @@
1266
  let sharedLength = structures.sharedLength || 0;
1267
  if (sharedLength > maxSharedStructures) {
1268
  //if (maxSharedStructures <= 32 && structures.sharedLength > 32) // TODO: could support this, but would need to update the limit ids
1269
- throw new Error('Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to ' + structures.sharedLength)
1270
  }
1271
  if (!structures.transitions) {
1272
  // rebuild our structure transitions
@@ -1274,7 +1298,7 @@
1274
  for (let i = 0; i < sharedLength; i++) {
1275
  let keys = structures[i];
1276
  if (!keys)
1277
- continue
1278
  let nextTransition, transition = structures.transitions;
1279
  for (let j = 0, l = keys.length; j < l; j++) {
1280
  let key = keys[j];
@@ -1296,7 +1320,7 @@
1296
  hasSharedUpdate = false;
1297
  let encodingError;
1298
  try {
1299
- if (packr.randomAccessStructure && value && typeof value === 'object') {
1300
  if (value.constructor === Object) writeStruct(value); // simple object
1301
  else if (value.constructor !== Map && !Array.isArray(value) && !extensionClasses.some(extClass => value instanceof extClass)) {
1302
  // allow user classes, if they don't need special handling (but do use toJSON if available)
@@ -1340,15 +1364,15 @@
1340
  packr.offset = position;
1341
  let serialized = insertIds(target.subarray(start, position), idsToInsert);
1342
  referenceMap = null;
1343
- return serialized
1344
  }
1345
  packr.offset = position; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
1346
  if (encodeOptions & REUSE_BUFFER_MODE) {
1347
  target.start = start;
1348
  target.end = position;
1349
- return target
1350
  }
1351
- return target.subarray(start, position) // position can change if we call pack again in saveStructures, so we get the buffer now
1352
  } catch(error) {
1353
  encodingError = error;
1354
  throw error;
@@ -1359,16 +1383,23 @@
1359
  let sharedLength = structures.sharedLength || 0;
1360
  // we can't rely on start/end with REUSE_BUFFER_MODE since they will (probably) change when we save
1361
  let returnBuffer = target.subarray(start, position);
1362
- let newSharedData = prepareStructures(structures, packr);
1363
  if (!encodingError) { // TODO: If there is an encoding error, should make the structures as uninitialized so they get rebuilt next time
1364
  if (packr.saveStructures(newSharedData, newSharedData.isCompatible) === false) {
1365
- // get updated structures and try again if the update failed
1366
- return packr.pack(value, encodeOptions)
 
 
 
 
 
 
 
1367
  }
1368
  packr.lastNamedStructuresLength = sharedLength;
1369
  // don't keep large buffers around
1370
  if (target.length > 0x40000000) target = null;
1371
- return returnBuffer
1372
  }
1373
  }
1374
  }
@@ -1454,7 +1485,7 @@
1454
  bundledStrings[twoByte ? 0 : 1] += value;
1455
  target[position++] = 0xc1;
1456
  pack(twoByte ? -strLength : strLength);
1457
- return
1458
  }
1459
  let headerSize;
1460
  // first we estimate the header size, so we can write to the correct location
@@ -1528,7 +1559,7 @@
1528
  } else if (type === 'number') {
1529
  if (value >>> 0 === value) {// positive integer, 32-bit or less
1530
  // positive uint
1531
- if (value < 0x20 || (value < 0x80 && this.useRecords === false) || (value < 0x40 && !this.randomAccessStructure)) {
1532
  target[position++] = value;
1533
  } else if (value < 0x100) {
1534
  target[position++] = 0xcc;
@@ -1567,7 +1598,7 @@
1567
  // this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
1568
  ((xShifted = value * mult10[((target[position] & 0x7f) << 1) | (target[position + 1] >> 7)]) >> 0) === xShifted) {
1569
  position += 4;
1570
- return
1571
  } else
1572
  position--; // move back into position for writing a double
1573
  }
@@ -1590,7 +1621,7 @@
1590
  target[position++] = 0x70; // "p" for pointer
1591
  targetView.setUint32(position, referee.id);
1592
  position += 4;
1593
- return
1594
  } else
1595
  referenceMap.set(value, { offset: position - start });
1596
  }
@@ -1640,7 +1671,7 @@
1640
  } else {
1641
  pack(writeResult);
1642
  }
1643
- return
1644
  }
1645
  let currentTarget = target;
1646
  let currentTargetView = targetView;
@@ -1657,7 +1688,7 @@
1657
  makeRoom(position);
1658
  return {
1659
  target, targetView, position: position - size
1660
- }
1661
  }, pack);
1662
  } finally {
1663
  // restore current target information (unless already restored)
@@ -1673,7 +1704,7 @@
1673
  makeRoom(result.length + position);
1674
  position = writeExtensionData(result, target, position, extension.type);
1675
  }
1676
- return
1677
  }
1678
  }
1679
  // check isArray after extensions, because extensions can extend Array
@@ -1685,7 +1716,7 @@
1685
  const json = value.toJSON();
1686
  // if for some reason value.toJSON returns itself it'll loop forever
1687
  if (json !== value)
1688
- return pack(json)
1689
  }
1690
 
1691
  // if there is a writeFunction, use it, otherwise just encode as undefined
@@ -1724,7 +1755,7 @@
1724
  let chunks = [];
1725
  while (true) {
1726
  chunks.push(value & mask);
1727
- if ((value >> BigInt(63)) === empty) break
1728
  value >>= BigInt(64);
1729
  }
1730
 
@@ -1756,11 +1787,11 @@
1756
  if (array.length + position > safeEnd)
1757
  makeRoom(array.length + position);
1758
  position = writeExtensionData(array, target, position, 0x42);
1759
- return
1760
  } else {
1761
  throw new RangeError(value + ' was too large to fit in MessagePack 64-bit integer format, use' +
1762
  ' useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set' +
1763
- ' largeBigIntToString to convert to string')
1764
  }
1765
  }
1766
  position += 8;
@@ -1773,7 +1804,7 @@
1773
  target[position++] = 0;
1774
  }
1775
  } else {
1776
- throw new Error('Unknown type: ' + type)
1777
  }
1778
  };
1779
 
@@ -1919,12 +1950,30 @@
1919
  checkUseRecords(object) ? writeRecord(object) : writePlainObject(object);
1920
  } : writeRecord;
1921
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1922
  const makeRoom = (end) => {
1923
  let newSize;
1924
  if (end > 0x1000000) {
1925
  // special handling for really large buffers
1926
  if ((end - start) > MAX_BUFFER_SIZE)
1927
- throw new Error('Packed buffer would be larger than maximum buffer size')
1928
  newSize = Math.min(MAX_BUFFER_SIZE,
1929
  Math.round(Math.max((end - start) * (end > 0x4000000 ? 1.25 : 2), 0x400000) / 0x1000) * 0x1000);
1930
  } else // faster handling for smaller buffers
@@ -1939,7 +1988,7 @@
1939
  position -= start;
1940
  start = 0;
1941
  safeEnd = newBuffer.length - 10;
1942
- return target = newBuffer
1943
  };
1944
  const newRecord = (transition, keys, newTransitions) => {
1945
  let recordId = structures.nextId;
@@ -2021,23 +2070,6 @@
2021
  target[insertionOffset + start] = keysTarget[0];
2022
  }
2023
  };
2024
- const writeStruct = (object) => {
2025
- let newPosition = writeStructSlots(object, target, start, position, structures, makeRoom, (value, newPosition, notifySharedUpdate) => {
2026
- if (notifySharedUpdate)
2027
- return hasSharedUpdate = true;
2028
- position = newPosition;
2029
- let startTarget = target;
2030
- pack(value);
2031
- resetStructures();
2032
- if (startTarget !== target) {
2033
- return { position, targetView, target }; // indicate the buffer was re-allocated
2034
- }
2035
- return position;
2036
- }, this);
2037
- if (newPosition === 0) // bail and go to a msgpack object
2038
- return writeObject(object);
2039
- position = newPosition;
2040
- };
2041
  }
2042
  useBuffer(buffer) {
2043
  // this means we are finished using our own buffer and we can write over it safely
@@ -2080,7 +2112,7 @@
2080
  } else if (isNaN(seconds)) {
2081
  if (this.onInvalidDate) {
2082
  allocateForWrite(0);
2083
- return pack(this.onInvalidDate())
2084
  }
2085
  // Intentionally invalid timestamp
2086
  let { target, targetView, position} = allocateForWrite(3);
@@ -2101,7 +2133,7 @@
2101
  pack(set, allocateForWrite, pack) {
2102
  if (this.setAsEmptyObject) {
2103
  allocateForWrite(0);
2104
- return pack({})
2105
  }
2106
  let array = Array.from(set);
2107
  let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
@@ -2209,19 +2241,19 @@
2209
  switch (length) {
2210
  case 1:
2211
  target[position++] = 0xd4;
2212
- break
2213
  case 2:
2214
  target[position++] = 0xd5;
2215
- break
2216
  case 4:
2217
  target[position++] = 0xd6;
2218
- break
2219
  case 8:
2220
  target[position++] = 0xd7;
2221
- break
2222
  case 16:
2223
  target[position++] = 0xd8;
2224
- break
2225
  default:
2226
  if (length < 0x100) {
2227
  target[position++] = 0xc7;
@@ -2241,7 +2273,7 @@
2241
  target[position++] = type;
2242
  target.set(result, position);
2243
  position += length;
2244
- return position
2245
  }
2246
 
2247
  function insertIds(serialized, idsToInsert) {
@@ -2263,7 +2295,7 @@
2263
  serialized[position++] = id & 0xff;
2264
  lastEnd = offset;
2265
  }
2266
- return serialized
2267
  }
2268
 
2269
  function writeBundles(start, pack, incrementPosition) {
@@ -2280,9 +2312,9 @@
2280
  function addExtension(extension) {
2281
  if (extension.Class) {
2282
  if (!extension.pack && !extension.write)
2283
- throw new Error('Extension has no pack or write function')
2284
  if (extension.pack && !extension.type)
2285
- throw new Error('Extension has no type (numeric code to identify the extension)')
2286
  extensionClasses.unshift(extension.Class);
2287
  extensions.unshift(extension);
2288
  }
@@ -2295,9 +2327,14 @@
2295
  packr._mergeStructures(existingStructures);
2296
  return compatible;
2297
  };
2298
- return structures
2299
  }
2300
 
 
 
 
 
 
2301
  let defaultPackr = new Packr({ useRecords: false });
2302
  const pack = defaultPackr.pack;
2303
  const encode = defaultPackr.pack;
@@ -2316,13 +2353,13 @@
2316
  */
2317
  function packIter (objectIterator, options = {}) {
2318
  if (!objectIterator || typeof objectIterator !== 'object') {
2319
- throw new Error('first argument must be an Iterable, Async Iterable, or a Promise for an Async Iterable')
2320
  } else if (typeof objectIterator[Symbol.iterator] === 'function') {
2321
- return packIterSync(objectIterator, options)
2322
  } else if (typeof objectIterator.then === 'function' || typeof objectIterator[Symbol.asyncIterator] === 'function') {
2323
- return packIterAsync(objectIterator, options)
2324
  } else {
2325
- throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a Promise')
2326
  }
2327
  }
2328
 
@@ -2349,7 +2386,7 @@
2349
  */
2350
  function unpackIter (bufferIterator, options = {}) {
2351
  if (!bufferIterator || typeof bufferIterator !== 'object') {
2352
- throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a promise')
2353
  }
2354
 
2355
  const unpackr = new Unpackr(options);
@@ -2369,10 +2406,10 @@
2369
  incomplete = chunk.slice(err.lastPosition);
2370
  yields = err.values;
2371
  } else {
2372
- throw err
2373
  }
2374
  }
2375
- return yields
2376
  };
2377
 
2378
  if (typeof bufferIterator[Symbol.iterator] === 'function') {
@@ -2380,13 +2417,13 @@
2380
  for (const value of bufferIterator) {
2381
  yield * parser(value);
2382
  }
2383
- })()
2384
  } else if (typeof bufferIterator[Symbol.asyncIterator] === 'function') {
2385
  return (async function * iter () {
2386
  for await (const value of bufferIterator) {
2387
  yield * parser(value);
2388
  }
2389
- })()
2390
  }
2391
  }
2392
  const decodeIter = unpackIter;
 
29
  C1.name = 'MessagePack 0xC1';
30
  var sequentialMode = false;
31
  var inlineObjectReadThreshold = 2;
 
32
  var BlockedFunction; // we use search and replace to change the next call to BlockedFunction to avoid CSP issues for
33
 
34
  class Unpackr {
 
61
  // re-entrant execution, save the state and restore it after we do this unpack
62
  return saveState(() => {
63
  clearSource();
64
+ return this ? this.unpack(source, options) : Unpackr.prototype.unpack.call(defaultOptions, source, options);
65
+ });
66
  }
67
  if (!source.buffer && source.constructor === ArrayBuffer)
68
  source = typeof Buffer !== 'undefined' ? Buffer.from(source) : new Uint8Array(source);
 
86
  // if it doesn't have a buffer, maybe it is the wrong type of object
87
  src = null;
88
  if (source instanceof Uint8Array)
89
+ throw error;
90
+ throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source));
91
  }
92
  if (this instanceof Unpackr) {
93
  currentUnpackr = this;
94
  if (this.structures) {
95
  currentStructures = this.structures;
96
+ return checkedRead(options);
97
  } else if (!currentStructures || currentStructures.length > 0) {
98
  currentStructures = [];
99
  }
 
102
  if (!currentStructures || currentStructures.length > 0)
103
  currentStructures = [];
104
  }
105
+ return checkedRead(options);
106
  }
107
  unpackMultiple(source, forEach) {
108
  let values, lastPosition = 0;
 
115
  while(position$1 < size) {
116
  lastPosition = position$1;
117
  if (forEach(checkedRead(), lastPosition, position$1) === false) {
118
+ return;
119
  }
120
  }
121
  }
 
125
  lastPosition = position$1;
126
  values.push(checkedRead());
127
  }
128
+ return values;
129
  }
130
  } catch(error) {
131
  error.lastPosition = lastPosition;
132
  error.values = values;
133
+ throw error;
134
  } finally {
135
  sequentialMode = false;
136
  clearSource();
137
  }
138
  }
139
  _mergeStructures(loadedStructures, existingStructures) {
140
+ if (this._onLoadedStructures)
141
+ loadedStructures = this._onLoadedStructures(loadedStructures);
142
  loadedStructures = loadedStructures || [];
143
  if (Object.isFrozen(loadedStructures))
144
  loadedStructures = loadedStructures.map(structure => structure.slice(0));
 
162
  }
163
  }
164
  }
165
+ return this.structures = loadedStructures;
166
  }
167
  decode(source, options) {
168
+ return this.unpack(source, options);
169
  }
170
  }
171
  function checkedRead(options) {
 
176
  currentStructures.length = sharedLength;
177
  }
178
  let result;
179
+ if (currentUnpackr._readStruct && src[position$1] < 0x40 && src[position$1] >= 0x20) {
180
+ result = currentUnpackr._readStruct(src, position$1, srcEnd);
181
  src = null; // dispose of this so that recursive unpack calls don't save state
182
  if (!(options && options.lazy) && result)
183
  result = result.toJSON();
 
203
  referenceMap = null;
204
  } else if (position$1 > srcEnd) {
205
  // over read
206
+ throw new Error('Unexpected end of MessagePack data');
207
  } else if (!sequentialMode) {
208
  let jsonView;
209
  try {
 
211
  } catch(error) {
212
  jsonView = '(JSON view not available ' + error + ')';
213
  }
214
+ throw new Error('Data read, but end of buffer not reached ' + jsonView);
215
  }
216
  // else more to read, but we are reading sequentially, so don't clear source yet
217
+ return result;
218
  } catch(error) {
219
  if (currentStructures && currentStructures.restoreStructures)
220
  restoreStructures();
 
222
  if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position$1 > srcEnd) {
223
  error.incomplete = true;
224
  }
225
+ throw error;
226
  }
227
  }
228
 
 
238
  if (token < 0xa0) {
239
  if (token < 0x80) {
240
  if (token < 0x40)
241
+ return token;
242
  else {
243
  let structure = currentStructures[token & 0x3f] ||
244
  currentUnpackr.getStructures && loadStructures()[token & 0x3f];
 
246
  if (!structure.read) {
247
  structure.read = createStructureReader(structure, token & 0x3f);
248
  }
249
+ return structure.read();
250
  } else
251
+ return token;
252
  }
253
  } else if (token < 0x90) {
254
  // map
 
261
  key = '__proto_';
262
  object[key] = read();
263
  }
264
+ return object;
265
  } else {
266
  let map = new Map();
267
  for (let i = 0; i < token; i++) {
268
  map.set(read(), read());
269
  }
270
+ return map;
271
  }
272
  } else {
273
  token -= 0x90;
 
276
  array[i] = read();
277
  }
278
  if (currentUnpackr.freezeData)
279
+ return Object.freeze(array);
280
+ return array;
281
  }
282
  } else if (token < 0xc0) {
283
  // fixstr
284
  let length = token - 0xa0;
285
  if (srcStringEnd >= position$1) {
286
+ return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart);
287
  }
288
  if (srcStringEnd == 0 && srcEnd < 140) {
289
  // for small blocks, avoiding the overhead of the extract call is helpful
290
  let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
291
  if (string != null)
292
+ return string;
293
  }
294
+ return readFixedString(length);
295
  } else {
296
  let value;
297
  switch (token) {
298
+ case 0xc0: return null;
299
  case 0xc1:
300
  if (bundledStrings$1) {
301
  value = read(); // followed by the length of the string in characters (not bytes!)
302
  if (value > 0)
303
+ return bundledStrings$1[1].slice(bundledStrings$1.position1, bundledStrings$1.position1 += value);
304
  else
305
+ return bundledStrings$1[0].slice(bundledStrings$1.position0, bundledStrings$1.position0 -= value);
306
  }
307
  return C1; // "never-used", return special object to denote that
308
+ case 0xc2: return false;
309
+ case 0xc3: return true;
310
  case 0xc4:
311
  // bin 8
312
  value = src[position$1++];
313
  if (value === undefined)
314
+ throw new Error('Unexpected end of buffer');
315
+ return readBin(value);
316
  case 0xc5:
317
  // bin 16
318
  value = dataView.getUint16(position$1);
319
  position$1 += 2;
320
+ return readBin(value);
321
  case 0xc6:
322
  // bin 32
323
  value = dataView.getUint32(position$1);
324
  position$1 += 4;
325
+ return readBin(value);
326
  case 0xc7:
327
  // ext 8
328
+ return readExt(src[position$1++]);
329
  case 0xc8:
330
  // ext 16
331
  value = dataView.getUint16(position$1);
332
  position$1 += 2;
333
+ return readExt(value);
334
  case 0xc9:
335
  // ext 32
336
  value = dataView.getUint32(position$1);
337
  position$1 += 4;
338
+ return readExt(value);
339
  case 0xca:
340
  value = dataView.getFloat32(position$1);
341
  if (currentUnpackr.useFloat32 > 2) {
342
  // this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
343
  let multiplier = mult10[((src[position$1] & 0x7f) << 1) | (src[position$1 + 1] >> 7)];
344
  position$1 += 4;
345
+ return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier;
346
  }
347
  position$1 += 4;
348
+ return value;
349
  case 0xcb:
350
  value = dataView.getFloat64(position$1);
351
  position$1 += 8;
352
+ return value;
353
  // uint handlers
354
  case 0xcc:
355
+ return src[position$1++];
356
  case 0xcd:
357
  value = dataView.getUint16(position$1);
358
  position$1 += 2;
359
+ return value;
360
  case 0xce:
361
  value = dataView.getUint32(position$1);
362
  position$1 += 4;
363
+ return value;
364
  case 0xcf:
365
  if (currentUnpackr.int64AsType === 'number') {
366
  value = dataView.getUint32(position$1) * 0x100000000;
 
373
  } else
374
  value = dataView.getBigUint64(position$1);
375
  position$1 += 8;
376
+ return value;
377
 
378
  // int handlers
379
  case 0xd0:
380
+ return dataView.getInt8(position$1++);
381
  case 0xd1:
382
  value = dataView.getInt16(position$1);
383
  position$1 += 2;
384
+ return value;
385
  case 0xd2:
386
  value = dataView.getInt32(position$1);
387
  position$1 += 4;
388
+ return value;
389
  case 0xd3:
390
  if (currentUnpackr.int64AsType === 'number') {
391
  value = dataView.getInt32(position$1) * 0x100000000;
 
398
  } else
399
  value = dataView.getBigInt64(position$1);
400
  position$1 += 8;
401
+ return value;
402
 
403
  case 0xd4:
404
  // fixext 1
405
  value = src[position$1++];
406
  if (value == 0x72) {
407
+ return recordDefinition(src[position$1++] & 0x3f);
408
  } else {
409
  let extension = currentExtensions[value];
410
  if (extension) {
411
  if (extension.read) {
412
  position$1++; // skip filler byte
413
+ return extension.read(read());
414
  } else if (extension.noBuffer) {
415
  position$1++; // skip filler byte
416
+ return extension();
417
  } else
418
+ return extension(src.subarray(position$1, ++position$1));
419
  } else
420
+ throw new Error('Unknown extension ' + value);
421
  }
422
  case 0xd5:
423
  // fixext 2
424
  value = src[position$1];
425
  if (value == 0x72) {
426
  position$1++;
427
+ return recordDefinition(src[position$1++] & 0x3f, src[position$1++]);
428
  } else
429
+ return readExt(2);
430
  case 0xd6:
431
  // fixext 4
432
+ return readExt(4);
433
  case 0xd7:
434
  // fixext 8
435
+ return readExt(8);
436
  case 0xd8:
437
  // fixext 16
438
+ return readExt(16);
439
  case 0xd9:
440
  // str 8
441
  value = src[position$1++];
442
  if (srcStringEnd >= position$1) {
443
+ return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart);
444
  }
445
+ return readString8(value);
446
  case 0xda:
447
  // str 16
448
  value = dataView.getUint16(position$1);
449
  position$1 += 2;
450
  if (srcStringEnd >= position$1) {
451
+ return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart);
452
  }
453
+ return readString16(value);
454
  case 0xdb:
455
  // str 32
456
  value = dataView.getUint32(position$1);
457
  position$1 += 4;
458
  if (srcStringEnd >= position$1) {
459
+ return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart);
460
  }
461
+ return readString32(value);
462
  case 0xdc:
463
  // array 16
464
  value = dataView.getUint16(position$1);
465
  position$1 += 2;
466
+ return readArray(value);
467
  case 0xdd:
468
  // array 32
469
  value = dataView.getUint32(position$1);
470
  position$1 += 4;
471
+ return readArray(value);
472
  case 0xde:
473
  // map 16
474
  value = dataView.getUint16(position$1);
475
  position$1 += 2;
476
+ return readMap(value);
477
  case 0xdf:
478
  // map 32
479
  value = dataView.getUint32(position$1);
480
  position$1 += 4;
481
+ return readMap(value);
482
  default: // negative int
483
  if (token >= 0xe0)
484
+ return token - 0x100;
485
  if (token === undefined) {
486
  let error = new Error('Unexpected end of MessagePack data');
487
  error.incomplete = true;
488
+ throw error;
489
  }
490
+ throw new Error('Unknown MessagePack token ' + token);
491
 
492
  }
493
  }
 
506
  inlineObjectReadThreshold = Infinity; // disable going forward
507
  return readObject(); // recursively try again
508
  }
509
+ structure.read0 = optimizedReadObject; // keep the un-wrapped body reader in sync
510
  if (structure.highByte === 0)
511
  structure.read = createSecondByteReader(firstId, structure.read);
512
+ return optimizedReadObject(); // second byte is already read, if there is one so immediately read object
513
  }
514
  let object = {};
515
  for (let i = 0, l = structure.length; i < l; i++) {
 
520
  }
521
  if (currentUnpackr.freezeData)
522
  return Object.freeze(object);
523
+ return object;
524
  }
525
  readObject.count = 0;
526
+ // read0 is the un-wrapped body reader: it reads the record's values directly without
527
+ // consuming a leading high byte. recordDefinition uses it for the immediate read that follows
528
+ // a record definition (the high byte, if present, was already consumed). For highByte === 0
529
+ // structures the public reader is a second-byte reader (used by later references), but the
530
+ // definition read itself must not consume that byte.
531
+ structure.read0 = readObject;
532
  if (structure.highByte === 0) {
533
+ return createSecondByteReader(firstId, readObject);
534
  }
535
+ return readObject;
536
  }
537
 
538
  const createSecondByteReader = (firstId, read0) => {
539
  return function() {
540
  let highByte = src[position$1++];
541
  if (highByte === 0)
542
+ return read0();
543
  let id = firstId < 32 ? -(firstId + (highByte << 5)) : firstId + (highByte << 5);
544
  let structure = currentStructures[id] || loadStructures()[id];
545
  if (!structure) {
546
+ throw new Error('Record id is not defined for ' + id);
547
  }
548
  if (!structure.read)
549
  structure.read = createStructureReader(structure, firstId);
550
+ return structure.read();
551
+ };
552
  };
553
 
554
  function loadStructures() {
555
  let loadedStructures = saveState(() => {
556
  // save the state in case getStructures modifies our buffer
557
  src = null;
558
+ return currentUnpackr.getStructures();
559
  });
560
+ return currentStructures = currentUnpackr._mergeStructures(loadedStructures, currentStructures);
561
  }
562
 
563
  var readFixedString = readStringJS;
 
569
  let result;
570
  if (length < 16) {
571
  if (result = shortStringInJS(length))
572
+ return result;
573
  }
574
  if (length > 64 && decoder)
575
+ return decoder.decode(src.subarray(position$1, position$1 += length));
576
  const end = position$1 + length;
577
  const units = [];
578
  result = '';
 
583
  units.push(byte1);
584
  } else if ((byte1 & 0xe0) === 0xc0) {
585
  // 2 bytes
586
+ if (byte1 < 0xc2 || position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
587
+ units.push(0xFFFD);
 
 
 
588
  } else {
589
+ const byte2 = src[position$1++] & 0x3f;
590
+ units.push(((byte1 & 0x1f) << 6) | byte2);
591
  }
592
  } else if ((byte1 & 0xf0) === 0xe0) {
593
  // 3 bytes
594
+ const byte2 = position$1 < end ? src[position$1] : 0;
595
+ if (position$1 >= end || (byte2 & 0xc0) !== 0x80 ||
596
+ (byte1 === 0xe0 && byte2 < 0xa0) || (byte1 === 0xed && byte2 >= 0xa0)) {
597
+ units.push(0xFFFD);
 
 
 
598
  } else {
599
+ position$1++;
600
+ if (position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
601
+ units.push(0xFFFD);
602
+ } else {
603
+ const byte3 = src[position$1++] & 0x3f;
604
+ units.push(((byte1 & 0x1f) << 12) | ((byte2 & 0x3f) << 6) | byte3);
605
+ }
606
  }
607
  } else if ((byte1 & 0xf8) === 0xf0) {
608
  // 4 bytes
609
+ const byte2 = position$1 < end ? src[position$1] : 0;
610
+ if (byte1 > 0xf4 || position$1 >= end || (byte2 & 0xc0) !== 0x80 ||
611
+ (byte1 === 0xf0 && byte2 < 0x90) || (byte1 === 0xf4 && byte2 >= 0x90)) {
612
+ units.push(0xFFFD);
 
 
 
 
 
 
 
 
 
613
  } else {
614
+ position$1++;
615
+ if (position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
616
+ units.push(0xFFFD);
617
+ } else {
618
+ const byte3 = src[position$1++] & 0x3f;
619
+ if (position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
620
+ units.push(0xFFFD);
621
+ } else {
622
+ const byte4 = src[position$1++] & 0x3f;
623
+ let unit = ((byte1 & 0x07) << 0x12) | ((byte2 & 0x3f) << 0x0c) | (byte3 << 0x06) | byte4;
624
+ unit -= 0x10000;
625
+ units.push(((unit >>> 10) & 0x3ff) | 0xd800);
626
+ units.push(0xdc00 | (unit & 0x3ff));
627
+ }
628
+ }
629
  }
630
  } else {
631
  units.push(0xFFFD); // replacement character for invalid lead byte
 
641
  result += fromCharCode.apply(String, units);
642
  }
643
 
644
+ return result;
645
  }
646
 
647
  function readArray(length) {
 
650
  array[i] = read();
651
  }
652
  if (currentUnpackr.freezeData)
653
+ return Object.freeze(array);
654
+ return array;
655
  }
656
 
657
  function readMap(length) {
 
663
  key = '__proto_';
664
  object[key] = read();
665
  }
666
+ return object;
667
  } else {
668
  let map = new Map();
669
  for (let i = 0; i < length; i++) {
670
  map.set(read(), read());
671
  }
672
+ return map;
673
  }
674
  }
675
 
 
681
  const byte = src[position$1++];
682
  if ((byte & 0x80) > 0) {
683
  position$1 = start;
684
+ return;
685
  }
686
  bytes[i] = byte;
687
  }
688
+ return fromCharCode.apply(String, bytes);
689
  }
690
  function shortStringInJS(length) {
691
  if (length < 4) {
692
  if (length < 2) {
693
  if (length === 0)
694
+ return '';
695
  else {
696
  let a = src[position$1++];
697
  if ((a & 0x80) > 1) {
698
  position$1 -= 1;
699
+ return;
700
  }
701
+ return fromCharCode(a);
702
  }
703
  } else {
704
  let a = src[position$1++];
705
  let b = src[position$1++];
706
  if ((a & 0x80) > 0 || (b & 0x80) > 0) {
707
  position$1 -= 2;
708
+ return;
709
  }
710
  if (length < 3)
711
+ return fromCharCode(a, b);
712
  let c = src[position$1++];
713
  if ((c & 0x80) > 0) {
714
  position$1 -= 3;
715
+ return;
716
  }
717
+ return fromCharCode(a, b, c);
718
  }
719
  } else {
720
  let a = src[position$1++];
 
723
  let d = src[position$1++];
724
  if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
725
  position$1 -= 4;
726
+ return;
727
  }
728
  if (length < 6) {
729
  if (length === 4)
730
+ return fromCharCode(a, b, c, d);
731
  else {
732
  let e = src[position$1++];
733
  if ((e & 0x80) > 0) {
734
  position$1 -= 5;
735
+ return;
736
  }
737
+ return fromCharCode(a, b, c, d, e);
738
  }
739
  } else if (length < 8) {
740
  let e = src[position$1++];
741
  let f = src[position$1++];
742
  if ((e & 0x80) > 0 || (f & 0x80) > 0) {
743
  position$1 -= 6;
744
+ return;
745
  }
746
  if (length < 7)
747
+ return fromCharCode(a, b, c, d, e, f);
748
  let g = src[position$1++];
749
  if ((g & 0x80) > 0) {
750
  position$1 -= 7;
751
+ return;
752
  }
753
+ return fromCharCode(a, b, c, d, e, f, g);
754
  } else {
755
  let e = src[position$1++];
756
  let f = src[position$1++];
 
758
  let h = src[position$1++];
759
  if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
760
  position$1 -= 8;
761
+ return;
762
  }
763
  if (length < 10) {
764
  if (length === 8)
765
+ return fromCharCode(a, b, c, d, e, f, g, h);
766
  else {
767
  let i = src[position$1++];
768
  if ((i & 0x80) > 0) {
769
  position$1 -= 9;
770
+ return;
771
  }
772
+ return fromCharCode(a, b, c, d, e, f, g, h, i);
773
  }
774
  } else if (length < 12) {
775
  let i = src[position$1++];
776
  let j = src[position$1++];
777
  if ((i & 0x80) > 0 || (j & 0x80) > 0) {
778
  position$1 -= 10;
779
+ return;
780
  }
781
  if (length < 11)
782
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j);
783
  let k = src[position$1++];
784
  if ((k & 0x80) > 0) {
785
  position$1 -= 11;
786
+ return;
787
  }
788
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k);
789
  } else {
790
  let i = src[position$1++];
791
  let j = src[position$1++];
 
793
  let l = src[position$1++];
794
  if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
795
  position$1 -= 12;
796
+ return;
797
  }
798
  if (length < 14) {
799
  if (length === 12)
800
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l);
801
  else {
802
  let m = src[position$1++];
803
  if ((m & 0x80) > 0) {
804
  position$1 -= 13;
805
+ return;
806
  }
807
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m);
808
  }
809
  } else {
810
  let m = src[position$1++];
811
  let n = src[position$1++];
812
  if ((m & 0x80) > 0 || (n & 0x80) > 0) {
813
  position$1 -= 14;
814
+ return;
815
  }
816
  if (length < 15)
817
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n);
818
  let o = src[position$1++];
819
  if ((o & 0x80) > 0) {
820
  position$1 -= 15;
821
+ return;
822
  }
823
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
824
  }
825
  }
826
  }
 
838
  case 0xd9:
839
  // str 8
840
  length = src[position$1++];
841
+ break;
842
  case 0xda:
843
  // str 16
844
  length = dataView.getUint16(position$1);
845
  position$1 += 2;
846
+ break;
847
  case 0xdb:
848
  // str 32
849
  length = dataView.getUint32(position$1);
850
  position$1 += 4;
851
+ break;
852
  default:
853
+ throw new Error('Expected string');
854
  }
855
  }
856
+ return readStringJS(length);
857
  }
858
 
859
 
 
861
  return currentUnpackr.copyBuffers ?
862
  // specifically use the copying slice (not the node one)
863
  Uint8Array.prototype.slice.call(src, position$1, position$1 += length) :
864
+ src.subarray(position$1, position$1 += length);
865
  }
866
  function readExt(length) {
867
  let type = src[position$1++];
 
874
  } finally {
875
  position$1 = end;
876
  }
877
+ });
878
  }
879
  else
880
+ throw new Error('Unknown extension type ' + type);
881
  }
882
 
883
  var keyCache = new Array(4096);
 
887
  // fixstr, potentially use key cache
888
  length = length - 0xa0;
889
  if (srcStringEnd >= position$1) // if it has been extracted, must use it (and faster anyway)
890
+ return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart);
891
  else if (!(srcStringEnd == 0 && srcEnd < 180))
892
+ return readFixedString(length);
893
  } else { // not cacheable, go back and do a standard read
894
  position$1--;
895
+ return asSafeString(read());
896
  }
897
  let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position$1) : length > 0 ? src[position$1] : 0)) & 0xfff;
898
  let entry = keyCache[key];
 
905
  chunk = dataView.getUint32(checkPosition);
906
  if (chunk != entry[i++]) {
907
  checkPosition = 0x70000000;
908
+ break;
909
  }
910
  checkPosition += 4;
911
  }
 
914
  chunk = src[checkPosition++];
915
  if (chunk != entry[i++]) {
916
  checkPosition = 0x70000000;
917
+ break;
918
  }
919
  }
920
  if (checkPosition === end) {
921
  position$1 = checkPosition;
922
+ return entry.string;
923
  }
924
  end -= 3;
925
  checkPosition = position$1;
 
940
  // for small blocks, avoiding the overhead of the extract call is helpful
941
  let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
942
  if (string != null)
943
+ return entry.string = string;
944
+ return entry.string = readFixedString(length);
945
  }
946
 
947
  function asSafeString(property) {
 
972
  }
973
  currentStructures[id] = structure;
974
  structure.read = createStructureReader(structure, firstByte);
975
+ // The high byte (if any) was already consumed as the `highByte` argument above, so read the
976
+ // record body directly. Going through structure.read (a second-byte reader when highByte === 0)
977
+ // would misinterpret the first value byte as a high byte — corrupting two-byte own-record
978
+ // definitions (0xd5 0x72 ...). createStructureReader stashes the un-wrapped body reader on
979
+ // structure.read0 precisely for this immediate post-definition read.
980
+ return (structure.read0 || structure.read)();
981
  };
982
  currentExtensions[0] = () => {}; // notepack defines extension 0 to mean undefined, so use that as the default here
983
  currentExtensions[0].noBuffer = true;
 
999
  out <<= BigInt(64);
1000
  out |= view.getBigUint64(i);
1001
  }
1002
+ return out;
1003
  }
1004
  // if (length === 8) return view.getBigUint64(start)
1005
  let middle = start + (length >> 4 << 3);
1006
  let left = decode(start, middle);
1007
  let right = decode(middle, end);
1008
+ return (left << BigInt((end - middle) * 8)) | right;
1009
  };
1010
  head = (head << BigInt((view.byteLength - headLength) * 8)) | decode(headLength, view.byteLength);
1011
  }
1012
+ return head;
1013
  };
1014
 
1015
  let errors = {
 
1020
  if (!errors[data[0]]) {
1021
  let error = Error(data[1], { cause: data[2] });
1022
  error.name = data[0];
1023
+ return error;
1024
  }
1025
+ return errors[data[0]](data[1], { cause: data[2] });
1026
  };
1027
 
1028
  currentExtensions[0x69] = (data) => {
1029
  // id extension (for structured clones)
1030
+ if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled');
1031
  let id = dataView.getUint32(position$1 - 4);
1032
  if (!referenceMap)
1033
  referenceMap = new Map();
 
1048
  let targetProperties = read(); // read the next value as the target object to id
1049
  if (!refEntry.used) {
1050
  // no cycle, can just use the returned read object
1051
+ return refEntry.target = targetProperties; // replace the placeholder with the real one
1052
  } else {
1053
  // there is a cycle, so we have to assign properties to original target
1054
  Object.assign(target, targetProperties);
 
1059
  for (let [k, v] of targetProperties.entries()) target.set(k, v);
1060
  if (target instanceof Set)
1061
  for (let i of Array.from(targetProperties)) target.add(i);
1062
+ return target;
1063
  };
1064
 
1065
  currentExtensions[0x70] = (data) => {
1066
  // pointer extension (for structured clones)
1067
+ if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled');
1068
  let id = dataView.getUint32(position$1 - 4);
1069
  let refEntry = referenceMap.get(id);
1070
  refEntry.used = true;
1071
+ return refEntry.target;
1072
  };
1073
 
1074
  currentExtensions[0x73] = () => new Set(read());
 
1083
 
1084
  let typedArrayName = typedArrays[typeCode];
1085
  if (!typedArrayName) {
1086
+ if (typeCode === 16) return buffer;
1087
+ if (typeCode === 17) return new DataView(buffer);
1088
+ throw new Error('Could not find typed array for code ' + typeCode);
1089
  }
1090
+ return new glbl[typedArrayName](buffer);
1091
  };
1092
  currentExtensions[0x78] = () => {
1093
  let data = read();
1094
+ return new RegExp(data[0], data[1]);
1095
  };
1096
  const TEMP_BUNDLE = [];
1097
  currentExtensions[0x62] = (data) => {
 
1104
  bundledStrings$1.position1 = 0;
1105
  bundledStrings$1.postBundlePosition = position$1;
1106
  position$1 = dataPosition;
1107
+ return read();
1108
  };
1109
 
1110
  currentExtensions[0xff] = (data) => {
1111
  // 32-bit date extension
1112
  if (data.length == 4)
1113
+ return new Date((data[0] * 0x1000000 + (data[1] << 16) + (data[2] << 8) + data[3]) * 1000);
1114
  else if (data.length == 8)
1115
  return new Date(
1116
  ((data[0] << 22) + (data[1] << 14) + (data[2] << 6) + (data[3] >> 2)) / 1000000 +
1117
+ ((data[3] & 0x3) * 0x100000000 + data[4] * 0x1000000 + (data[5] << 16) + (data[6] << 8) + data[7]) * 1000);
1118
  else if (data.length == 12)
1119
  return new Date(
1120
  ((data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]) / 1000000 +
1121
+ (((data[4] & 0x80) ? -0x1000000000000 : 0) + data[6] * 0x10000000000 + data[7] * 0x100000000 + data[8] * 0x1000000 + (data[9] << 16) + (data[10] << 8) + data[11]) * 1000);
1122
  else
1123
+ return new Date('invalid');
1124
  };
1125
  // registration of bulk record definition?
1126
  // currentExtensions[0x52] = () =>
1127
 
1128
  function saveState(callback) {
1129
+ if (currentUnpackr && currentUnpackr._onSaveState)
1130
+ currentUnpackr._onSaveState();
1131
  let savedSrcEnd = srcEnd;
1132
  let savedPosition = position$1;
1133
  let savedSrcStringStart = srcStringStart;
 
1156
  currentStructures.splice(0, currentStructures.length, ...savedStructuresContents);
1157
  currentUnpackr = savedPackr;
1158
  dataView = new DataView(src.buffer, src.byteOffset, src.byteLength);
1159
+ return value;
1160
  }
1161
  function clearSource() {
1162
  src = null;
 
1191
  function roundFloat32(float32Number) {
1192
  f32Array[0] = float32Number;
1193
  let multiplier = mult10[((u8Array[3] & 0x7f) << 1) | (u8Array[2] >> 7)];
1194
+ return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier;
1195
  }
1196
+ // Marker for downstream libraries (e.g. structon) to detect per-instance
1197
+ // struct-decoding hooks (this._readStruct, this._onLoadedStructures,
1198
+ // this._onSaveState). See `checkedRead` for the dispatch.
1199
+ Unpackr.SUPPORTS_STRUCT_HOOKS = true;
1200
 
1201
  let textEncoder;
1202
  try {
 
1205
  let extensions, extensionClasses;
1206
  const hasNodeBuffer = typeof Buffer !== 'undefined';
1207
  const ByteArrayAllocate = hasNodeBuffer ?
1208
+ function(length) { return Buffer.allocUnsafeSlow(length); } : Uint8Array;
1209
  const ByteArray = hasNodeBuffer ? Buffer : Uint8Array;
1210
  const MAX_BUFFER_SIZE = hasNodeBuffer ? 0x100000000 : 0x7fd00000;
1211
  let target, keysTarget;
 
1213
  let position = 0;
1214
  let safeEnd;
1215
  let bundledStrings = null;
 
1216
  const MAX_BUNDLE_SIZE = 0x5500; // maximum characters such that the encoded bytes fits in 16 bits.
1217
  const hasNonLatin = /[\u0080-\uFFFF]/;
1218
  const RECORD_SYMBOL = Symbol('record-id');
 
1225
  let structures;
1226
  let referenceMap;
1227
  let encodeUtf8 = ByteArray.prototype.utf8Write ? function(string, position) {
1228
+ return target.utf8Write(string, position, target.byteLength - position);
1229
  } : (textEncoder && textEncoder.encodeInto) ?
1230
  function(string, position) {
1231
+ return textEncoder.encodeInto(string, target.subarray(position)).written;
1232
  } : false;
1233
 
1234
  let packr = this;
 
1240
  if (maxSharedStructures == null)
1241
  maxSharedStructures = hasSharedStructures ? 32 : 0;
1242
  if (maxSharedStructures > 8160)
1243
+ throw new Error('Maximum maxSharedStructure is 8160');
1244
  if (options.structuredClone && options.moreTypes == undefined) {
1245
  this.moreTypes = true;
1246
  }
 
1254
  let sharedLimitId = maxSharedStructures + 0x40;
1255
  let maxStructureId = maxSharedStructures + maxOwnStructures + 0x40;
1256
  if (maxStructureId > 8256) {
1257
+ throw new Error('Maximum maxSharedStructure + maxOwnStructure is 8192');
1258
  }
1259
  let recordIdsToRemove = [];
1260
  let transitionsCount = 0;
 
1290
  let sharedLength = structures.sharedLength || 0;
1291
  if (sharedLength > maxSharedStructures) {
1292
  //if (maxSharedStructures <= 32 && structures.sharedLength > 32) // TODO: could support this, but would need to update the limit ids
1293
+ throw new Error('Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to ' + structures.sharedLength);
1294
  }
1295
  if (!structures.transitions) {
1296
  // rebuild our structure transitions
 
1298
  for (let i = 0; i < sharedLength; i++) {
1299
  let keys = structures[i];
1300
  if (!keys)
1301
+ continue;
1302
  let nextTransition, transition = structures.transitions;
1303
  for (let j = 0, l = keys.length; j < l; j++) {
1304
  let key = keys[j];
 
1320
  hasSharedUpdate = false;
1321
  let encodingError;
1322
  try {
1323
+ if (packr._writeStruct && value && typeof value === 'object') {
1324
  if (value.constructor === Object) writeStruct(value); // simple object
1325
  else if (value.constructor !== Map && !Array.isArray(value) && !extensionClasses.some(extClass => value instanceof extClass)) {
1326
  // allow user classes, if they don't need special handling (but do use toJSON if available)
 
1364
  packr.offset = position;
1365
  let serialized = insertIds(target.subarray(start, position), idsToInsert);
1366
  referenceMap = null;
1367
+ return serialized;
1368
  }
1369
  packr.offset = position; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
1370
  if (encodeOptions & REUSE_BUFFER_MODE) {
1371
  target.start = start;
1372
  target.end = position;
1373
+ return target;
1374
  }
1375
+ return target.subarray(start, position); // position can change if we call pack again in saveStructures, so we get the buffer now
1376
  } catch(error) {
1377
  encodingError = error;
1378
  throw error;
 
1383
  let sharedLength = structures.sharedLength || 0;
1384
  // we can't rely on start/end with REUSE_BUFFER_MODE since they will (probably) change when we save
1385
  let returnBuffer = target.subarray(start, position);
1386
+ let newSharedData = (packr._prepareStructures || prepareStructures)(structures, packr);
1387
  if (!encodingError) { // TODO: If there is an encoding error, should make the structures as uninitialized so they get rebuilt next time
1388
  if (packr.saveStructures(newSharedData, newSharedData.isCompatible) === false) {
1389
+ // The save was declined (a concurrent writer updated the shared structures,
1390
+ // or the store transaction did not durably commit). Our in-memory
1391
+ // structures + transition trie may now reference record ids that were
1392
+ // never persisted; re-packing as-is would re-emit the same record pointing
1393
+ // at an unpersisted structure (-> "Record id is not defined" on decode).
1394
+ // Mark structures uninitialized so the re-pack reloads durable structures
1395
+ // via getStructures, rebuilds the transition trie, and re-mints + re-saves.
1396
+ structures.uninitialized = true;
1397
+ return packr.pack(value, encodeOptions);
1398
  }
1399
  packr.lastNamedStructuresLength = sharedLength;
1400
  // don't keep large buffers around
1401
  if (target.length > 0x40000000) target = null;
1402
+ return returnBuffer;
1403
  }
1404
  }
1405
  }
 
1485
  bundledStrings[twoByte ? 0 : 1] += value;
1486
  target[position++] = 0xc1;
1487
  pack(twoByte ? -strLength : strLength);
1488
+ return;
1489
  }
1490
  let headerSize;
1491
  // first we estimate the header size, so we can write to the correct location
 
1559
  } else if (type === 'number') {
1560
  if (value >>> 0 === value) {// positive integer, 32-bit or less
1561
  // positive uint
1562
+ if (value < 0x20 || (value < 0x80 && this.useRecords === false) || (value < 0x40 && !this._writeStruct)) {
1563
  target[position++] = value;
1564
  } else if (value < 0x100) {
1565
  target[position++] = 0xcc;
 
1598
  // this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
1599
  ((xShifted = value * mult10[((target[position] & 0x7f) << 1) | (target[position + 1] >> 7)]) >> 0) === xShifted) {
1600
  position += 4;
1601
+ return;
1602
  } else
1603
  position--; // move back into position for writing a double
1604
  }
 
1621
  target[position++] = 0x70; // "p" for pointer
1622
  targetView.setUint32(position, referee.id);
1623
  position += 4;
1624
+ return;
1625
  } else
1626
  referenceMap.set(value, { offset: position - start });
1627
  }
 
1671
  } else {
1672
  pack(writeResult);
1673
  }
1674
+ return;
1675
  }
1676
  let currentTarget = target;
1677
  let currentTargetView = targetView;
 
1688
  makeRoom(position);
1689
  return {
1690
  target, targetView, position: position - size
1691
+ };
1692
  }, pack);
1693
  } finally {
1694
  // restore current target information (unless already restored)
 
1704
  makeRoom(result.length + position);
1705
  position = writeExtensionData(result, target, position, extension.type);
1706
  }
1707
+ return;
1708
  }
1709
  }
1710
  // check isArray after extensions, because extensions can extend Array
 
1716
  const json = value.toJSON();
1717
  // if for some reason value.toJSON returns itself it'll loop forever
1718
  if (json !== value)
1719
+ return pack(json);
1720
  }
1721
 
1722
  // if there is a writeFunction, use it, otherwise just encode as undefined
 
1755
  let chunks = [];
1756
  while (true) {
1757
  chunks.push(value & mask);
1758
+ if ((value >> BigInt(63)) === empty) break;
1759
  value >>= BigInt(64);
1760
  }
1761
 
 
1787
  if (array.length + position > safeEnd)
1788
  makeRoom(array.length + position);
1789
  position = writeExtensionData(array, target, position, 0x42);
1790
+ return;
1791
  } else {
1792
  throw new RangeError(value + ' was too large to fit in MessagePack 64-bit integer format, use' +
1793
  ' useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set' +
1794
+ ' largeBigIntToString to convert to string');
1795
  }
1796
  }
1797
  position += 8;
 
1804
  target[position++] = 0;
1805
  }
1806
  } else {
1807
+ throw new Error('Unknown type: ' + type);
1808
  }
1809
  };
1810
 
 
1950
  checkUseRecords(object) ? writeRecord(object) : writePlainObject(object);
1951
  } : writeRecord;
1952
 
1953
+ const writeStruct = (object) => {
1954
+ let newPosition = packr._writeStruct(object, target, start, position, structures, makeRoom, (value, newPosition, notifySharedUpdate) => {
1955
+ if (notifySharedUpdate)
1956
+ return hasSharedUpdate = true;
1957
+ position = newPosition;
1958
+ let startTarget = target;
1959
+ pack(value);
1960
+ resetStructures();
1961
+ if (startTarget !== target) {
1962
+ return { position, targetView, target }; // indicate the buffer was re-allocated
1963
+ }
1964
+ return position;
1965
+ });
1966
+ if (newPosition === 0) // bail and go to a msgpack object
1967
+ return writeObject(object);
1968
+ position = newPosition;
1969
+ };
1970
+
1971
  const makeRoom = (end) => {
1972
  let newSize;
1973
  if (end > 0x1000000) {
1974
  // special handling for really large buffers
1975
  if ((end - start) > MAX_BUFFER_SIZE)
1976
+ throw new Error('Packed buffer would be larger than maximum buffer size');
1977
  newSize = Math.min(MAX_BUFFER_SIZE,
1978
  Math.round(Math.max((end - start) * (end > 0x4000000 ? 1.25 : 2), 0x400000) / 0x1000) * 0x1000);
1979
  } else // faster handling for smaller buffers
 
1988
  position -= start;
1989
  start = 0;
1990
  safeEnd = newBuffer.length - 10;
1991
+ return target = newBuffer;
1992
  };
1993
  const newRecord = (transition, keys, newTransitions) => {
1994
  let recordId = structures.nextId;
 
2070
  target[insertionOffset + start] = keysTarget[0];
2071
  }
2072
  };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2073
  }
2074
  useBuffer(buffer) {
2075
  // this means we are finished using our own buffer and we can write over it safely
 
2112
  } else if (isNaN(seconds)) {
2113
  if (this.onInvalidDate) {
2114
  allocateForWrite(0);
2115
+ return pack(this.onInvalidDate());
2116
  }
2117
  // Intentionally invalid timestamp
2118
  let { target, targetView, position} = allocateForWrite(3);
 
2133
  pack(set, allocateForWrite, pack) {
2134
  if (this.setAsEmptyObject) {
2135
  allocateForWrite(0);
2136
+ return pack({});
2137
  }
2138
  let array = Array.from(set);
2139
  let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
 
2241
  switch (length) {
2242
  case 1:
2243
  target[position++] = 0xd4;
2244
+ break;
2245
  case 2:
2246
  target[position++] = 0xd5;
2247
+ break;
2248
  case 4:
2249
  target[position++] = 0xd6;
2250
+ break;
2251
  case 8:
2252
  target[position++] = 0xd7;
2253
+ break;
2254
  case 16:
2255
  target[position++] = 0xd8;
2256
+ break;
2257
  default:
2258
  if (length < 0x100) {
2259
  target[position++] = 0xc7;
 
2273
  target[position++] = type;
2274
  target.set(result, position);
2275
  position += length;
2276
+ return position;
2277
  }
2278
 
2279
  function insertIds(serialized, idsToInsert) {
 
2295
  serialized[position++] = id & 0xff;
2296
  lastEnd = offset;
2297
  }
2298
+ return serialized;
2299
  }
2300
 
2301
  function writeBundles(start, pack, incrementPosition) {
 
2312
  function addExtension(extension) {
2313
  if (extension.Class) {
2314
  if (!extension.pack && !extension.write)
2315
+ throw new Error('Extension has no pack or write function');
2316
  if (extension.pack && !extension.type)
2317
+ throw new Error('Extension has no type (numeric code to identify the extension)');
2318
  extensionClasses.unshift(extension.Class);
2319
  extensions.unshift(extension);
2320
  }
 
2327
  packr._mergeStructures(existingStructures);
2328
  return compatible;
2329
  };
2330
+ return structures;
2331
  }
2332
 
2333
+ // Marker for downstream libraries (e.g. structon) to detect that this Packr
2334
+ // supports per-instance struct-encoding hooks (this._writeStruct,
2335
+ // this._prepareStructures). See `pack` for the dispatch.
2336
+ Packr.SUPPORTS_STRUCT_HOOKS = true;
2337
+
2338
  let defaultPackr = new Packr({ useRecords: false });
2339
  const pack = defaultPackr.pack;
2340
  const encode = defaultPackr.pack;
 
2353
  */
2354
  function packIter (objectIterator, options = {}) {
2355
  if (!objectIterator || typeof objectIterator !== 'object') {
2356
+ throw new Error('first argument must be an Iterable, Async Iterable, or a Promise for an Async Iterable');
2357
  } else if (typeof objectIterator[Symbol.iterator] === 'function') {
2358
+ return packIterSync(objectIterator, options);
2359
  } else if (typeof objectIterator.then === 'function' || typeof objectIterator[Symbol.asyncIterator] === 'function') {
2360
+ return packIterAsync(objectIterator, options);
2361
  } else {
2362
+ throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a Promise');
2363
  }
2364
  }
2365
 
 
2386
  */
2387
  function unpackIter (bufferIterator, options = {}) {
2388
  if (!bufferIterator || typeof bufferIterator !== 'object') {
2389
+ throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a promise');
2390
  }
2391
 
2392
  const unpackr = new Unpackr(options);
 
2406
  incomplete = chunk.slice(err.lastPosition);
2407
  yields = err.values;
2408
  } else {
2409
+ throw err;
2410
  }
2411
  }
2412
+ return yields;
2413
  };
2414
 
2415
  if (typeof bufferIterator[Symbol.iterator] === 'function') {
 
2417
  for (const value of bufferIterator) {
2418
  yield * parser(value);
2419
  }
2420
+ })();
2421
  } else if (typeof bufferIterator[Symbol.asyncIterator] === 'function') {
2422
  return (async function * iter () {
2423
  for await (const value of bufferIterator) {
2424
  yield * parser(value);
2425
  }
2426
+ })();
2427
  }
2428
  }
2429
  const decodeIter = unpackIter;
.opencode/node_modules/msgpackr/dist/index-no-eval.cjs.map CHANGED
The diff for this file is too large to render. See raw diff
 
.opencode/node_modules/msgpackr/dist/index-no-eval.min.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).msgpackr={})}(this,(function(e){"use strict";var t,r,n;try{t=new TextDecoder}catch(e){}var i,s,o,a,u,l=0,f={},c=0,h=0,g=[],p={useRecords:!1,mapsAsObjects:!0};class d{}const y=new d;y.name="MessagePack 0xC1";var w=!1,b=2;class m{constructor(e){e&&(!1===e.useRecords&&void 0===e.mapsAsObjects&&(e.mapsAsObjects=!0),e.sequential&&!1!==e.trusted&&(e.trusted=!0,e.structures||0==e.useRecords||(e.structures=[],e.maxSharedStructures||(e.maxSharedStructures=0))),e.structures?e.structures.sharedLength=e.structures.length:e.getStructures&&((e.structures=[]).uninitialized=!0,e.structures.sharedLength=0),e.int64AsNumber&&(e.int64AsType="number")),Object.assign(this,e)}unpack(e,t){if(r)return q((()=>(Z(),this?this.unpack(e,t):m.prototype.unpack.call(p,e,t))));e.buffer||e.constructor!==ArrayBuffer||(e="undefined"!=typeof Buffer?Buffer.from(e):new Uint8Array(e)),"object"==typeof t?(n=t.end||e.length,l=t.start||0):(l=0,n=t>-1?t:e.length),h=0,s=null,o=null,r=e;try{u=e.dataView||(e.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength))}catch(t){if(r=null,e instanceof Uint8Array)throw t;throw new Error("Source must be a Uint8Array or Buffer but was a "+(e&&"object"==typeof e?e.constructor.name:typeof e))}if(this instanceof m){if(f=this,this.structures)return i=this.structures,S(t);(!i||i.length>0)&&(i=[])}else f=p,(!i||i.length>0)&&(i=[]);return S(t)}unpackMultiple(e,t){let r,n=0;try{w=!0;let i=e.length,s=this?this.unpack(e,i):Q.unpack(e,i);if(!t){for(r=[s];l<i;)n=l,r.push(S());return r}if(!1===t(s,n,l))return;for(;l<i;)if(n=l,!1===t(S(),n,l))return}catch(e){throw e.lastPosition=n,e.values=r,e}finally{w=!1,Z()}}_mergeStructures(e,t){e=e||[],Object.isFrozen(e)&&(e=e.map((e=>e.slice(0))));for(let t=0,r=e.length;t<r;t++){let r=e[t];r&&(r.isShared=!0,t>=32&&(r.highByte=t-32>>5))}e.sharedLength=e.length;for(let r in t||[])if(r>=0){let n=e[r],i=t[r];i&&(n&&((e.restoreStructures||(e.restoreStructures=[]))[r]=n),e[r]=i)}return this.structures=e}decode(e,t){return this.unpack(e,t)}}function S(e){try{if(!f.trusted&&!w){let e=i.sharedLength||0;e<i.length&&(i.length=e)}let e;if(f.randomAccessStructure&&r[l]<64&&r[l],e=U(),o&&(l=o.postBundlePosition,o=null),w&&(i.restoreStructures=null),l==n)i&&i.restoreStructures&&A(),i=null,r=null,a&&(a=null);else{if(l>n)throw new Error("Unexpected end of MessagePack data");if(!w){let t;try{t=JSON.stringify(e,((e,t)=>"bigint"==typeof t?`${t}n`:t)).slice(0,100)}catch(e){t="(JSON view not available "+e+")"}throw new Error("Data read, but end of buffer not reached "+t)}}return e}catch(e){throw i&&i.restoreStructures&&A(),Z(),(e instanceof RangeError||e.message.startsWith("Unexpected end of buffer")||l>n)&&(e.incomplete=!0),e}}function A(){for(let e in i.restoreStructures)i[e]=i.restoreStructures[e];i.restoreStructures=null}function U(){let e=r[l++];if(e<160){if(e<128){if(e<64)return e;{let t=i[63&e]||f.getStructures&&v()[63&e];return t?(t.read||(t.read=I(t,63&e)),t.read()):e}}if(e<144){if(e-=128,f.mapsAsObjects){let t={};for(let r=0;r<e;r++){let e=z();"__proto__"===e&&(e="__proto_"),t[e]=U()}return t}{let t=new Map;for(let r=0;r<e;r++)t.set(U(),U());return t}}{e-=144;let t=new Array(e);for(let r=0;r<e;r++)t[r]=U();return f.freezeData?Object.freeze(t):t}}if(e<192){let t=e-160;if(h>=l)return s.slice(l-c,(l+=t)-c);if(0==h&&n<140){let e=t<16?V(t):D(t);if(null!=e)return e}return B(t)}{let t;switch(e){case 192:return null;case 193:return o?(t=U(),t>0?o[1].slice(o.position1,o.position1+=t):o[0].slice(o.position0,o.position0-=t)):y;case 194:return!1;case 195:return!0;case 196:if(t=r[l++],void 0===t)throw new Error("Unexpected end of buffer");return N(t);case 197:return t=u.getUint16(l),l+=2,N(t);case 198:return t=u.getUint32(l),l+=4,N(t);case 199:return F(r[l++]);case 200:return t=u.getUint16(l),l+=2,F(t);case 201:return t=u.getUint32(l),l+=4,F(t);case 202:if(t=u.getFloat32(l),f.useFloat32>2){let e=G[(127&r[l])<<1|r[l+1]>>7];return l+=4,(e*t+(t>0?.5:-.5)>>0)/e}return l+=4,t;case 203:return t=u.getFloat64(l),l+=8,t;case 204:return r[l++];case 205:return t=u.getUint16(l),l+=2,t;case 206:return t=u.getUint32(l),l+=4,t;case 207:return"number"===f.int64AsType?(t=4294967296*u.getUint32(l),t+=u.getUint32(l+4)):"string"===f.int64AsType?t=u.getBigUint64(l).toString():"auto"===f.int64AsType?(t=u.getBigUint64(l),t<=BigInt(2)<<BigInt(52)&&(t=Number(t))):t=u.getBigUint64(l),l+=8,t;case 208:return u.getInt8(l++);case 209:return t=u.getInt16(l),l+=2,t;case 210:return t=u.getInt32(l),l+=4,t;case 211:return"number"===f.int64AsType?(t=4294967296*u.getInt32(l),t+=u.getUint32(l+4)):"string"===f.int64AsType?t=u.getBigInt64(l).toString():"auto"===f.int64AsType?(t=u.getBigInt64(l),t>=BigInt(-2)<<BigInt(52)&&t<=BigInt(2)<<BigInt(52)&&(t=Number(t))):t=u.getBigInt64(l),l+=8,t;case 212:if(t=r[l++],114==t)return W(63&r[l++]);{let e=g[t];if(e)return e.read?(l++,e.read(U())):e.noBuffer?(l++,e()):e(r.subarray(l,++l));throw new Error("Unknown extension "+t)}case 213:return t=r[l],114==t?(l++,W(63&r[l++],r[l++])):F(2);case 214:return F(4);case 215:return F(8);case 216:return F(16);case 217:return t=r[l++],h>=l?s.slice(l-c,(l+=t)-c):O(t);case 218:return t=u.getUint16(l),h>=(l+=2)?s.slice(l-c,(l+=t)-c):_(t);case 219:return t=u.getUint32(l),h>=(l+=4)?s.slice(l-c,(l+=t)-c):x(t);case 220:return t=u.getUint16(l),l+=2,M(t);case 221:return t=u.getUint32(l),l+=4,M(t);case 222:return t=u.getUint16(l),l+=2,j(t);case 223:return t=u.getUint32(l),l+=4,j(t);default:if(e>=224)return e-256;if(void 0===e){let e=new Error("Unexpected end of MessagePack data");throw e.incomplete=!0,e}throw new Error("Unknown MessagePack token "+e)}}}const E=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function I(e,t){function r(){if(r.count++>b){let n;try{n=e.read=new undefined("r","return function(){return "+(f.freezeData?"Object.freeze":"")+"({"+e.map((e=>"__proto__"===e?"__proto_:r()":E.test(e)?e+":r()":"["+JSON.stringify(e)+"]:r()")).join(",")+"})}")(U)}catch(e){return b=1/0,r()}return 0===e.highByte&&(e.read=k(t,e.read)),n()}let n={};for(let t=0,r=e.length;t<r;t++){let r=e[t];"__proto__"===r&&(r="__proto_"),n[r]=U()}return f.freezeData?Object.freeze(n):n}return r.count=0,0===e.highByte?k(t,r):r}const k=(e,t)=>function(){let n=r[l++];if(0===n)return t();let s=e<32?-(e+(n<<5)):e+(n<<5),o=i[s]||v()[s];if(!o)throw new Error("Record id is not defined for "+s);return o.read||(o.read=I(o,e)),o.read()};function v(){let e=q((()=>(r=null,f.getStructures())));return i=f._mergeStructures(e,i)}var B=T,O=T,_=T,x=T;function T(e){let n;if(e<16&&(n=V(e)))return n;if(e>64&&t)return t.decode(r.subarray(l,l+=e));const i=l+e,s=[];for(n="";l<i;){const e=r[l++];if(0==(128&e))s.push(e);else if(192==(224&e)){const t=(31&e)<<6|63&r[l++];t<128?s.push(65533):s.push(t)}else if(224==(240&e)){const t=(31&e)<<12|(63&r[l++])<<6|63&r[l++];t<2048||t>=55296&&t<=57343?s.push(65533):s.push(t)}else if(240==(248&e)){let t=(7&e)<<18|(63&r[l++])<<12|(63&r[l++])<<6|63&r[l++];t<65536||t>1114111?s.push(65533):t>65535?(t-=65536,s.push(t>>>10&1023|55296),t=56320|1023&t,s.push(t)):s.push(t)}else s.push(65533);s.length>=4096&&(n+=R.apply(String,s),s.length=0)}return s.length>0&&(n+=R.apply(String,s)),n}function M(e){let t=new Array(e);for(let r=0;r<e;r++)t[r]=U();return f.freezeData?Object.freeze(t):t}function j(e){if(f.mapsAsObjects){let t={};for(let r=0;r<e;r++){let e=z();"__proto__"===e&&(e="__proto_"),t[e]=U()}return t}{let t=new Map;for(let r=0;r<e;r++)t.set(U(),U());return t}}var R=String.fromCharCode;function D(e){let t=l,n=new Array(e);for(let i=0;i<e;i++){const e=r[l++];if((128&e)>0)return void(l=t);n[i]=e}return R.apply(String,n)}function V(e){if(e<4){if(e<2){if(0===e)return"";{let e=r[l++];return(128&e)>1?void(l-=1):R(e)}}{let t=r[l++],n=r[l++];if((128&t)>0||(128&n)>0)return void(l-=2);if(e<3)return R(t,n);let i=r[l++];return(128&i)>0?void(l-=3):R(t,n,i)}}{let t=r[l++],n=r[l++],i=r[l++],s=r[l++];if((128&t)>0||(128&n)>0||(128&i)>0||(128&s)>0)return void(l-=4);if(e<6){if(4===e)return R(t,n,i,s);{let e=r[l++];return(128&e)>0?void(l-=5):R(t,n,i,s,e)}}if(e<8){let o=r[l++],a=r[l++];if((128&o)>0||(128&a)>0)return void(l-=6);if(e<7)return R(t,n,i,s,o,a);let u=r[l++];return(128&u)>0?void(l-=7):R(t,n,i,s,o,a,u)}{let o=r[l++],a=r[l++],u=r[l++],f=r[l++];if((128&o)>0||(128&a)>0||(128&u)>0||(128&f)>0)return void(l-=8);if(e<10){if(8===e)return R(t,n,i,s,o,a,u,f);{let e=r[l++];return(128&e)>0?void(l-=9):R(t,n,i,s,o,a,u,f,e)}}if(e<12){let c=r[l++],h=r[l++];if((128&c)>0||(128&h)>0)return void(l-=10);if(e<11)return R(t,n,i,s,o,a,u,f,c,h);let g=r[l++];return(128&g)>0?void(l-=11):R(t,n,i,s,o,a,u,f,c,h,g)}{let c=r[l++],h=r[l++],g=r[l++],p=r[l++];if((128&c)>0||(128&h)>0||(128&g)>0||(128&p)>0)return void(l-=12);if(e<14){if(12===e)return R(t,n,i,s,o,a,u,f,c,h,g,p);{let e=r[l++];return(128&e)>0?void(l-=13):R(t,n,i,s,o,a,u,f,c,h,g,p,e)}}{let d=r[l++],y=r[l++];if((128&d)>0||(128&y)>0)return void(l-=14);if(e<15)return R(t,n,i,s,o,a,u,f,c,h,g,p,d,y);let w=r[l++];return(128&w)>0?void(l-=15):R(t,n,i,s,o,a,u,f,c,h,g,p,d,y,w)}}}}}function L(){let e,t=r[l++];if(t<192)e=t-160;else switch(t){case 217:e=r[l++];break;case 218:e=u.getUint16(l),l+=2;break;case 219:e=u.getUint32(l),l+=4;break;default:throw new Error("Expected string")}return T(e)}function N(e){return f.copyBuffers?Uint8Array.prototype.slice.call(r,l,l+=e):r.subarray(l,l+=e)}function F(e){let t=r[l++];if(g[t]){let n;return g[t](r.subarray(l,n=l+=e),(e=>{l=e;try{return U()}finally{l=n}}))}throw new Error("Unknown extension type "+t)}var P=new Array(4096);function z(){let e=r[l++];if(!(e>=160&&e<192))return l--,C(U());if(e-=160,h>=l)return s.slice(l-c,(l+=e)-c);if(!(0==h&&n<180))return B(e);let t,i=4095&(e<<5^(e>1?u.getUint16(l):e>0?r[l]:0)),o=P[i],a=l,f=l+e-3,g=0;if(o&&o.bytes==e){for(;a<f;){if(t=u.getUint32(a),t!=o[g++]){a=1879048192;break}a+=4}for(f+=3;a<f;)if(t=r[a++],t!=o[g++]){a=1879048192;break}if(a===f)return l=a,o.string;f-=3,a=l}for(o=[],P[i]=o,o.bytes=e;a<f;)t=u.getUint32(a),o.push(t),a+=4;for(f+=3;a<f;)t=r[a++],o.push(t);let p=e<16?V(e):D(e);return o.string=null!=p?p:B(e)}function C(e){if("string"==typeof e)return e;if("number"==typeof e||"boolean"==typeof e||"bigint"==typeof e)return e.toString();if(null==e)return e+"";if(f.allowArraysInMapKeys&&Array.isArray(e)&&e.flat().every((e=>["string","number","boolean","bigint"].includes(typeof e))))return e.flat().toString();throw new Error("Invalid property type for record: "+typeof e)}const W=(e,t)=>{let r=U().map(C),n=e;void 0!==t&&(e=e<32?-((t<<5)+e):(t<<5)+e,r.highByte=t);let s=i[e];return s&&(s.isShared||w)&&((i.restoreStructures||(i.restoreStructures=[]))[e]=s),i[e]=r,r.read=I(r,n),r.read()};g[0]=()=>{},g[0].noBuffer=!0,g[66]=e=>{let t=e.byteLength%8||8,r=BigInt(128&e[0]?e[0]-256:e[0]);for(let n=1;n<t;n++)r<<=BigInt(8),r+=BigInt(e[n]);if(e.byteLength!==t){let n=new DataView(e.buffer,e.byteOffset,e.byteLength),i=(e,t)=>{let r=t-e;if(r<=40){let r=n.getBigUint64(e);for(let i=e+8;i<t;i+=8)r<<=BigInt(64),r|=n.getBigUint64(i);return r}let s=e+(r>>4<<3),o=i(e,s),a=i(s,t);return o<<BigInt(8*(t-s))|a};r=r<<BigInt(8*(n.byteLength-t))|i(t,n.byteLength)}return r};let J={Error:Error,EvalError:EvalError,RangeError:RangeError,ReferenceError:ReferenceError,SyntaxError:SyntaxError,TypeError:TypeError,URIError:URIError,AggregateError:"function"==typeof AggregateError?AggregateError:null};g[101]=()=>{let e=U();if(!J[e[0]]){let t=Error(e[1],{cause:e[2]});return t.name=e[0],t}return J[e[0]](e[1],{cause:e[2]})},g[105]=e=>{if(!1===f.structuredClone)throw new Error("Structured clone extension is disabled");let t=u.getUint32(l-4);a||(a=new Map);let n,i=r[l];n=i>=144&&i<160||220==i||221==i?[]:i>=128&&i<144||222==i||223==i?new Map:(i>=199&&i<=201||i>=212&&i<=216)&&115===r[l+1]?new Set:{};let s={target:n};a.set(t,s);let o=U();if(!s.used)return s.target=o;if(Object.assign(n,o),n instanceof Map)for(let[e,t]of o.entries())n.set(e,t);if(n instanceof Set)for(let e of Array.from(o))n.add(e);return n},g[112]=e=>{if(!1===f.structuredClone)throw new Error("Structured clone extension is disabled");let t=u.getUint32(l-4),r=a.get(t);return r.used=!0,r.target},g[115]=()=>new Set(U());const $=["Int8","Uint8","Uint8Clamped","Int16","Uint16","Int32","Uint32","Float32","Float64","BigInt64","BigUint64"].map((e=>e+"Array"));let K="object"==typeof globalThis?globalThis:window;g[116]=e=>{let t=e[0],r=Uint8Array.prototype.slice.call(e,1).buffer,n=$[t];if(!n){if(16===t)return r;if(17===t)return new DataView(r);throw new Error("Could not find typed array for code "+t)}return new K[n](r)},g[120]=()=>{let e=U();return new RegExp(e[0],e[1])};const Y=[];function q(e){let t=n,g=l,p=c,d=h,y=s,b=a,m=o,S=new Uint8Array(r.slice(0,n)),A=i,U=i.slice(0,i.length),E=f,I=w,k=e();return n=t,l=g,c=p,h=d,s=y,a=b,o=m,r=S,w=I,(i=A).splice(0,i.length,...U),f=E,u=new DataView(r.buffer,r.byteOffset,r.byteLength),k}function Z(){r=null,a=null,i=null}g[98]=e=>{let t=(e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3],r=l;return l+=t-e.length,o=Y,(o=[L(),L()]).position0=0,o.position1=0,o.postBundlePosition=l,l=r,U()},g[255]=e=>4==e.length?new Date(1e3*(16777216*e[0]+(e[1]<<16)+(e[2]<<8)+e[3])):8==e.length?new Date(((e[0]<<22)+(e[1]<<14)+(e[2]<<6)+(e[3]>>2))/1e6+1e3*(4294967296*(3&e[3])+16777216*e[4]+(e[5]<<16)+(e[6]<<8)+e[7])):12==e.length?new Date(((e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3])/1e6+1e3*((128&e[4]?-281474976710656:0)+1099511627776*e[6]+4294967296*e[7]+16777216*e[8]+(e[9]<<16)+(e[10]<<8)+e[11])):new Date("invalid");const G=new Array(147);for(let e=0;e<256;e++)G[e]=+("1e"+Math.floor(45.15-.30103*e));const H=m;var Q=new m({useRecords:!1});const X=Q.unpack,ee=Q.unpackMultiple,te=Q.unpack,re={NEVER:0,ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4};let ne,ie,se,oe=new Float32Array(1),ae=new Uint8Array(oe.buffer,0,4);try{ne=new TextEncoder}catch(e){}const ue="undefined"!=typeof Buffer,le=ue?function(e){return Buffer.allocUnsafeSlow(e)}:Uint8Array,fe=ue?Buffer:Uint8Array,ce=ue?4294967296:2144337920;let he,ge,pe,de,ye=0,we=null;const be=/[\u0080-\uFFFF]/,me=Symbol("record-id");class Se extends m{constructor(e){let t,r,n,i;super(e),this.offset=0;let s=fe.prototype.utf8Write?function(e,t){return he.utf8Write(e,t,he.byteLength-t)}:!(!ne||!ne.encodeInto)&&function(e,t){return ne.encodeInto(e,he.subarray(t)).written},o=this;e||(e={});let a=e&&e.sequential,u=e.structures||e.saveStructures,l=e.maxSharedStructures;if(null==l&&(l=u?32:0),l>8160)throw new Error("Maximum maxSharedStructure is 8160");e.structuredClone&&null==e.moreTypes&&(this.moreTypes=!0);let f=e.maxOwnStructures;null==f&&(f=u?32:64),this.structures||0==e.useRecords||(this.structures=[]);let c=l>32||f+l>64,h=l+64,g=l+f+64;if(g>8256)throw new Error("Maximum maxSharedStructure + maxOwnStructure is 8192");let p=[],d=0,y=0;this.pack=this.encode=function(e,s){if(he||(he=new le(8192),pe=he.dataView||(he.dataView=new DataView(he.buffer,0,8192)),ye=0),de=he.length-10,de-ye<2048?(he=new le(he.length),pe=he.dataView||(he.dataView=new DataView(he.buffer,0,he.length)),de=he.length-10,ye=0):ye=ye+7&2147483640,t=ye,s&De&&(ye+=255&s),i=o.structuredClone?new Map:null,o.bundleStrings&&"string"!=typeof e?(we=[],we.size=1/0):we=null,n=o.structures,n){n.uninitialized&&(n=o._mergeStructures(o.getStructures()));let e=n.sharedLength||0;if(e>l)throw new Error("Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to "+n.sharedLength);if(!n.transitions){n.transitions=Object.create(null);for(let t=0;t<e;t++){let e=n[t];if(!e)continue;let r,i=n.transitions;for(let t=0,n=e.length;t<n;t++){let n=e[t];r=i[n],r||(r=i[n]=Object.create(null)),i=r}i[me]=t+64}this.lastNamedStructuresLength=e}a||(n.nextId=e+64)}let u;r&&(r=!1);try{o.randomAccessStructure&&e&&"object"==typeof e?e.constructor===Object?B(e):e.constructor===Map||Array.isArray(e)||se.some((t=>e instanceof t))?m(e):B(e.toJSON?e.toJSON():e):m(e);let a=we;if(we&&Ie(t,m,0),i&&i.idsToInsert){let e=i.idsToInsert.sort(((e,t)=>e.offset>t.offset?1:-1)),r=e.length,n=-1;for(;a&&r>0;){let i=e[--r].offset+t;i<a.stringsPosition+t&&-1===n&&(n=0),i>a.position+t?n>=0&&(n+=6):(n>=0&&(pe.setUint32(a.position+t,pe.getUint32(a.position+t)+n),n=-1),a=a.previous,r++)}n>=0&&a&&pe.setUint32(a.position+t,pe.getUint32(a.position+t)+n),ye+=6*e.length,ye>de&&I(ye),o.offset=ye;let s=function(e,t){let r,n=6*t.length,i=e.length-n;for(;r=t.pop();){let t=r.offset,s=r.id;e.copyWithin(t+n,t,i),n-=6;let o=t+n;e[o++]=214,e[o++]=105,e[o++]=s>>24,e[o++]=s>>16&255,e[o++]=s>>8&255,e[o++]=255&s,i=t}return e}(he.subarray(t,ye),e);return i=null,s}return o.offset=ye,s&je?(he.start=t,he.end=ye,he):he.subarray(t,ye)}catch(e){throw u=e,e}finally{if(n&&(w(),r&&o.saveStructures)){let r=n.sharedLength||0,i=he.subarray(t,ye),a=function(e,t){return e.isCompatible=e=>{let r=!e||(t.lastNamedStructuresLength||0)===e.length;return r||t._mergeStructures(e),r},e}(n,o);if(!u)return!1===o.saveStructures(a,a.isCompatible)?o.pack(e,s):(o.lastNamedStructuresLength=r,he.length>1073741824&&(he=null),i)}he.length>1073741824&&(he=null),s&Re&&(ye=t)}};const w=()=>{y<10&&y++;let e=n.sharedLength||0;if(n.length>e&&!a&&(n.length=e),d>1e4)n.transitions=null,y=0,d=0,p.length>0&&(p=[]);else if(p.length>0&&!a){for(let e=0,t=p.length;e<t;e++)p[e][me]=0;p=[]}},b=e=>{var t=e.length;t<16?he[ye++]=144|t:t<65536?(he[ye++]=220,he[ye++]=t>>8,he[ye++]=255&t):(he[ye++]=221,pe.setUint32(ye,t),ye+=4);for(let r=0;r<t;r++)m(e[r])},m=e=>{ye>de&&(he=I(ye));var r,n=typeof e;if("string"===n){let n,i=e.length;if(we&&i>=4&&i<4096){if((we.size+=i)>21760){let e,r,n=(we[0]?3*we[0].length+we[1].length:0)+10;ye+n>de&&(he=I(ye+n)),we.position?(r=we,he[ye]=200,ye+=3,he[ye++]=98,e=ye-t,ye+=4,Ie(t,m,0),pe.setUint16(e+t-3,ye-t-e)):(he[ye++]=214,he[ye++]=98,e=ye-t,ye+=4),we=["",""],we.previous=r,we.size=0,we.position=e}let r=be.test(e);return we[r?0:1]+=e,he[ye++]=193,void m(r?-i:i)}n=i<32?1:i<256?2:i<65536?3:5;let o=3*i;if(ye+o>de&&(he=I(ye+o)),i<64||!s){let t,s,o,a=ye+n;for(t=0;t<i;t++)s=e.charCodeAt(t),s<128?he[a++]=s:s<2048?(he[a++]=s>>6|192,he[a++]=63&s|128):55296==(64512&s)&&56320==(64512&(o=e.charCodeAt(t+1)))?(s=65536+((1023&s)<<10)+(1023&o),t++,he[a++]=s>>18|240,he[a++]=s>>12&63|128,he[a++]=s>>6&63|128,he[a++]=63&s|128):(he[a++]=s>>12|224,he[a++]=s>>6&63|128,he[a++]=63&s|128);r=a-ye-n}else r=s(e,ye+n);r<32?he[ye++]=160|r:r<256?(n<2&&he.copyWithin(ye+2,ye+1,ye+1+r),he[ye++]=217,he[ye++]=r):r<65536?(n<3&&he.copyWithin(ye+3,ye+2,ye+2+r),he[ye++]=218,he[ye++]=r>>8,he[ye++]=255&r):(n<5&&he.copyWithin(ye+5,ye+3,ye+3+r),he[ye++]=219,pe.setUint32(ye,r),ye+=4),ye+=r}else if("number"===n)if(e>>>0===e)e<32||e<128&&!1===this.useRecords||e<64&&!this.randomAccessStructure?he[ye++]=e:e<256?(he[ye++]=204,he[ye++]=e):e<65536?(he[ye++]=205,he[ye++]=e>>8,he[ye++]=255&e):(he[ye++]=206,pe.setUint32(ye,e),ye+=4);else if(e>>0===e)e>=-32?he[ye++]=256+e:e>=-128?(he[ye++]=208,he[ye++]=e+256):e>=-32768?(he[ye++]=209,pe.setInt16(ye,e),ye+=2):(he[ye++]=210,pe.setInt32(ye,e),ye+=4);else{let t;if((t=this.useFloat32)>0&&e<4294967296&&e>=-2147483648){let r;if(he[ye++]=202,pe.setFloat32(ye,e),t<4||(r=e*G[(127&he[ye])<<1|he[ye+1]>>7])>>0===r)return void(ye+=4);ye--}he[ye++]=203,pe.setFloat64(ye,e),ye+=8}else if("object"===n||"function"===n)if(e){if(i){let r=i.get(e);if(r){if(!r.id){let e=i.idsToInsert||(i.idsToInsert=[]);r.id=e.push(r)}return he[ye++]=214,he[ye++]=112,pe.setUint32(ye,r.id),void(ye+=4)}i.set(e,{offset:ye-t})}let s=e.constructor;if(s===Object)E(e);else if(s===Array)b(e);else if(s===Map)if(this.mapAsEmptyObject)he[ye++]=128;else{(r=e.size)<16?he[ye++]=128|r:r<65536?(he[ye++]=222,he[ye++]=r>>8,he[ye++]=255&r):(he[ye++]=223,pe.setUint32(ye,r),ye+=4);for(let[t,r]of e)m(t),m(r)}else{for(let t=0,r=ie.length;t<r;t++){if(e instanceof se[t]){let r=ie[t];if(r.write){r.type&&(he[ye++]=212,he[ye++]=r.type,he[ye++]=0);let t=r.write.call(this,e);return void(t===e?Array.isArray(e)?b(e):E(e):m(t))}let n,i=he,s=pe,o=ye;he=null;try{n=r.pack.call(this,e,(e=>(he=i,i=null,ye+=e,ye>de&&I(ye),{target:he,targetView:pe,position:ye-e})),m)}finally{i&&(he=i,pe=s,ye=o,de=he.length-10)}return void(n&&(n.length+ye>de&&I(n.length+ye),ye=Ee(n,he,ye,r.type)))}}if(Array.isArray(e))b(e);else{if(e.toJSON){const t=e.toJSON();if(t!==e)return m(t)}if("function"===n)return m(this.writeFunction&&this.writeFunction(e));E(e)}}}else he[ye++]=192;else if("boolean"===n)he[ye++]=e?195:194;else if("bigint"===n){if(e<0x8000000000000000&&e>=-0x8000000000000000)he[ye++]=211,pe.setBigInt64(ye,e);else if(e<0x10000000000000000&&e>0)he[ye++]=207,pe.setBigUint64(ye,e);else{if(!this.largeBigIntToFloat){if(this.largeBigIntToString)return m(e.toString());if(this.useBigIntExtension||this.moreTypes){let t,r=e<0?BigInt(-1):BigInt(0);if(e>>BigInt(65536)===r){let n=BigInt(0x10000000000000000)-BigInt(1),i=[];for(;i.push(e&n),e>>BigInt(63)!==r;)e>>=BigInt(64);t=new Uint8Array(new BigUint64Array(i).buffer),t.reverse()}else{let r=e<0,n=(r?~e:e).toString(16);if(n.length%2?n="0"+n:parseInt(n.charAt(0),16)>=8&&(n="00"+n),ue)t=Buffer.from(n,"hex");else{t=new Uint8Array(n.length/2);for(let e=0;e<t.length;e++)t[e]=parseInt(n.slice(2*e,2*e+2),16)}if(r)for(let e=0;e<t.length;e++)t[e]=~t[e]}return t.length+ye>de&&I(t.length+ye),void(ye=Ee(t,he,ye,66))}throw new RangeError(e+" was too large to fit in MessagePack 64-bit integer format, use useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set largeBigIntToString to convert to string")}he[ye++]=203,pe.setFloat64(ye,Number(e))}ye+=8}else{if("undefined"!==n)throw new Error("Unknown type: "+n);this.encodeUndefinedAsNil?he[ye++]=192:(he[ye++]=212,he[ye++]=0,he[ye++]=0)}},S=this.variableMapSize||this.coercibleKeyAsNumber||this.skipValues?e=>{let t;if(this.skipValues){t=[];for(let r in e)"function"==typeof e.hasOwnProperty&&!e.hasOwnProperty(r)||this.skipValues.includes(e[r])||t.push(r)}else t=Object.keys(e);let r,n=t.length;if(n<16?he[ye++]=128|n:n<65536?(he[ye++]=222,he[ye++]=n>>8,he[ye++]=255&n):(he[ye++]=223,pe.setUint32(ye,n),ye+=4),this.coercibleKeyAsNumber)for(let i=0;i<n;i++){r=t[i];let n=Number(r);m(isNaN(n)?r:n),m(e[r])}else for(let i=0;i<n;i++)m(r=t[i]),m(e[r])}:e=>{he[ye++]=222;let r=ye-t;ye+=2;let n=0;for(let t in e)("function"!=typeof e.hasOwnProperty||e.hasOwnProperty(t))&&(m(t),m(e[t]),n++);if(n>65535)throw new Error('Object is too large to serialize with fast 16-bit map size, use the "variableMapSize" option to serialize this object');he[r+++t]=n>>8,he[r+t]=255&n},A=!1===this.useRecords?S:e.progressiveRecords&&!c?e=>{let r,i,s=n.transitions||(n.transitions=Object.create(null)),o=ye++-t;for(let a in e)if("function"!=typeof e.hasOwnProperty||e.hasOwnProperty(a)){if(r=s[a],r)s=r;else{let u=Object.keys(e),l=s;s=n.transitions;let f=0;for(let e=0,t=u.length;e<t;e++){let t=u[e];r=s[t],r||(r=s[t]=Object.create(null),f++),s=r}o+t+1==ye?(ye--,k(s,u,f)):v(s,u,o,f),i=!0,s=l[a]}m(e[a])}if(!i){let r=s[me];r?he[o+t]=r:v(s,Object.keys(e),o,0)}}:e=>{let t,r=n.transitions||(n.transitions=Object.create(null)),i=0;for(let n in e)("function"!=typeof e.hasOwnProperty||e.hasOwnProperty(n))&&(t=r[n],t||(t=r[n]=Object.create(null),i++),r=t);let s=r[me];s?s>=96&&c?(he[ye++]=96+(31&(s-=96)),he[ye++]=s>>5):he[ye++]=s:k(r,r.__keys__||Object.keys(e),i);for(let t in e)("function"!=typeof e.hasOwnProperty||e.hasOwnProperty(t))&&m(e[t])},U="function"==typeof this.useRecords&&this.useRecords,E=U?e=>{U(e)?A(e):S(e)}:A,I=e=>{let r;if(e>16777216){if(e-t>ce)throw new Error("Packed buffer would be larger than maximum buffer size");r=Math.min(ce,4096*Math.round(Math.max((e-t)*(e>67108864?1.25:2),4194304)/4096))}else r=1+(Math.max(e-t<<2,he.length-1)>>12)<<12;let n=new le(r);return pe=n.dataView||(n.dataView=new DataView(n.buffer,0,r)),e=Math.min(e,he.length),he.copy?he.copy(n,0,t,e):n.set(he.slice(t,e)),ye-=t,t=0,de=n.length-10,he=n},k=(e,t,i)=>{let s=n.nextId;s||(s=64),s<h&&this.shouldShareStructure&&!this.shouldShareStructure(t)?(s=n.nextOwnId,s<g||(s=h),n.nextOwnId=s+1):(s>=g&&(s=h),n.nextId=s+1);let o=t.highByte=s>=96&&c?s-96>>5:-1;e[me]=s,e.__keys__=t,n[s-64]=t,s<h?(t.isShared=!0,n.sharedLength=s-63,r=!0,o>=0?(he[ye++]=96+(31&s),he[ye++]=o):he[ye++]=s):(o>=0?(he[ye++]=213,he[ye++]=114,he[ye++]=96+(31&s),he[ye++]=o):(he[ye++]=212,he[ye++]=114,he[ye++]=s),i&&(d+=y*i),p.length>=f&&(p.shift()[me]=0),p.push(e),m(t))},v=(e,r,n,i)=>{let s=he,o=ye,a=de,u=t;he=ge,ye=0,t=0,he||(ge=he=new le(8192)),de=he.length-10,k(e,r,i),ge=he;let l=ye;if(he=s,ye=o,de=a,t=u,l>1){let e=ye+l-1;e>de&&I(e);let r=n+t;he.copyWithin(r+l,r+1,ye),he.set(ge.slice(0,l),r),ye=e}else he[n+t]=ge[0]},B=e=>{let i=undefined(e,he,t,ye,n,I,((e,t,n)=>{if(n)return r=!0;ye=t;let i=he;return m(e),w(),i!==he?{position:ye,targetView:pe,target:he}:ye}),this);if(0===i)return E(e);ye=i}}useBuffer(e){he=e,he.dataView||(he.dataView=new DataView(he.buffer,he.byteOffset,he.byteLength)),pe=he.dataView,ye=0}set position(e){ye=e}get position(){return ye}clearSharedData(){this.structures&&(this.structures=[]),this.typedStructs&&(this.typedStructs=[])}}function Ae(e,t,r,n){let i=e.byteLength;if(i+1<256){var{target:s,position:o}=r(4+i);s[o++]=199,s[o++]=i+1}else if(i+1<65536){var{target:s,position:o}=r(5+i);s[o++]=200,s[o++]=i+1>>8,s[o++]=i+1&255}else{var{target:s,position:o,targetView:a}=r(7+i);s[o++]=201,a.setUint32(o,i+1),o+=4}s[o++]=116,s[o++]=t,e.buffer||(e=new Uint8Array(e)),s.set(new Uint8Array(e.buffer,e.byteOffset,e.byteLength),o)}function Ue(e,t){let r=e.byteLength;var n,i;if(r<256){var{target:n,position:i}=t(r+2);n[i++]=196,n[i++]=r}else if(r<65536){var{target:n,position:i}=t(r+3);n[i++]=197,n[i++]=r>>8,n[i++]=255&r}else{var{target:n,position:i,targetView:s}=t(r+5);n[i++]=198,s.setUint32(i,r),i+=4}n.set(e,i)}function Ee(e,t,r,n){let i=e.length;switch(i){case 1:t[r++]=212;break;case 2:t[r++]=213;break;case 4:t[r++]=214;break;case 8:t[r++]=215;break;case 16:t[r++]=216;break;default:i<256?(t[r++]=199,t[r++]=i):i<65536?(t[r++]=200,t[r++]=i>>8,t[r++]=255&i):(t[r++]=201,t[r++]=i>>24,t[r++]=i>>16&255,t[r++]=i>>8&255,t[r++]=255&i)}return t[r++]=n,t.set(e,r),r+=i}function Ie(e,t,r){if(we.length>0){pe.setUint32(we.position+e,ye+r-we.position-e),we.stringsPosition=ye-e;let n=we;we=null,t(n[0]),t(n[1])}}se=[Date,Set,Error,RegExp,ArrayBuffer,Object.getPrototypeOf(Uint8Array.prototype).constructor,DataView,d],ie=[{pack(e,t,r){let n=e.getTime()/1e3;if((this.useTimestamp32||0===e.getMilliseconds())&&n>=0&&n<4294967296){let{target:e,targetView:r,position:i}=t(6);e[i++]=214,e[i++]=255,r.setUint32(i,n)}else if(n>0&&n<4294967296){let{target:r,targetView:i,position:s}=t(10);r[s++]=215,r[s++]=255,i.setUint32(s,4e6*e.getMilliseconds()+(n/1e3/4294967296>>0)),i.setUint32(s+4,n)}else if(isNaN(n)){if(this.onInvalidDate)return t(0),r(this.onInvalidDate());let{target:e,targetView:n,position:i}=t(3);e[i++]=212,e[i++]=255,e[i++]=255}else{let{target:r,targetView:i,position:s}=t(15);r[s++]=199,r[s++]=12,r[s++]=255,i.setUint32(s,1e6*e.getMilliseconds()),i.setBigInt64(s+4,BigInt(Math.floor(n)))}}},{pack(e,t,r){if(this.setAsEmptyObject)return t(0),r({});let n=Array.from(e),{target:i,position:s}=t(this.moreTypes?3:0);this.moreTypes&&(i[s++]=212,i[s++]=115,i[s++]=0),r(n)}},{pack(e,t,r){let{target:n,position:i}=t(this.moreTypes?3:0);this.moreTypes&&(n[i++]=212,n[i++]=101,n[i++]=0),r([e.name,e.message,e.cause])}},{pack(e,t,r){let{target:n,position:i}=t(this.moreTypes?3:0);this.moreTypes&&(n[i++]=212,n[i++]=120,n[i++]=0),r([e.source,e.flags])}},{pack(e,t){this.moreTypes?Ae(e,16,t):Ue(ue?Buffer.from(e):new Uint8Array(e),t)}},{pack(e,t){let r=e.constructor;r!==fe&&this.moreTypes?Ae(e,$.indexOf(r.name),t):Ue(e,t)}},{pack(e,t){this.moreTypes?Ae(e,17,t):Ue(ue?Buffer.from(e):new Uint8Array(e),t)}},{pack(e,t){let{target:r,position:n}=t(1);r[n]=193}}];let ke=new Se({useRecords:!1});const ve=ke.pack,Be=ke.pack,Oe=Se,{NEVER:_e,ALWAYS:xe,DECIMAL_ROUND:Te,DECIMAL_FIT:Me}=re,je=512,Re=1024,De=2048;const Ve=function(e,t={}){if(!e||"object"!=typeof e)throw new Error("first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a promise");const r=new m(t);let n;const i=e=>{let t;n&&(e=Buffer.concat([n,e]),n=void 0);try{t=r.unpackMultiple(e)}catch(r){if(!r.incomplete)throw r;n=e.slice(r.lastPosition),t=r.values}return t};return"function"==typeof e[Symbol.iterator]?function*(){for(const t of e)yield*i(t)}():"function"==typeof e[Symbol.asyncIterator]?async function*(){for await(const t of e)yield*i(t)}():void 0},Le=function(e,t={}){if(e&&"object"==typeof e){if("function"==typeof e[Symbol.iterator])return function*(e,t){const r=new Se(t);for(const t of e)yield r.pack(t)}(e,t);if("function"==typeof e.then||"function"==typeof e[Symbol.asyncIterator])return async function*(e,t){const r=new Se(t);for await(const t of e)yield r.pack(t)}(e,t);throw new Error("first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a Promise")}throw new Error("first argument must be an Iterable, Async Iterable, or a Promise for an Async Iterable")};e.ALWAYS=xe,e.C1=y,e.DECIMAL_FIT=Me,e.DECIMAL_ROUND=Te,e.Decoder=H,e.Encoder=Oe,e.FLOAT32_OPTIONS=re,e.NEVER=_e,e.Packr=Se,e.RESERVE_START_SPACE=De,e.RESET_BUFFER_MODE=Re,e.REUSE_BUFFER_MODE=je,e.Unpackr=m,e.addExtension=function(e){if(e.Class){if(!e.pack&&!e.write)throw new Error("Extension has no pack or write function");if(e.pack&&!e.type)throw new Error("Extension has no type (numeric code to identify the extension)");se.unshift(e.Class),ie.unshift(e)}!function(e){e.unpack?g[e.type]=e.unpack:g[e.type]=e}(e)},e.clearSource=Z,e.decode=te,e.decodeIter=Ve,e.encode=Be,e.encodeIter=Le,e.isNativeAccelerationEnabled=!1,e.mapsAsObjects=!0,e.pack=ve,e.roundFloat32=function(e){oe[0]=e;let t=G[(127&ae[3])<<1|ae[2]>>7];return(t*e+(e>0?.5:-.5)>>0)/t},e.unpack=X,e.unpackMultiple=ee,e.useRecords=!1}));
2
  //# sourceMappingURL=index-no-eval.min.js.map
 
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).msgpackr={})}(this,function(e){"use strict";var t,r,n;try{t=new TextDecoder}catch(e){}var i,s,o,a,u,l=0,f={},c=0,h=0,g=[],p={useRecords:!1,mapsAsObjects:!0};class d{}const y=new d;y.name="MessagePack 0xC1";var w=!1,b=2;class S{constructor(e){e&&(!1===e.useRecords&&void 0===e.mapsAsObjects&&(e.mapsAsObjects=!0),e.sequential&&!1!==e.trusted&&(e.trusted=!0,e.structures||0==e.useRecords||(e.structures=[],e.maxSharedStructures||(e.maxSharedStructures=0))),e.structures?e.structures.sharedLength=e.structures.length:e.getStructures&&((e.structures=[]).uninitialized=!0,e.structures.sharedLength=0),e.int64AsNumber&&(e.int64AsType="number")),Object.assign(this,e)}unpack(e,t){if(r)return q(()=>(H(),this?this.unpack(e,t):S.prototype.unpack.call(p,e,t)));e.buffer||e.constructor!==ArrayBuffer||(e="undefined"!=typeof Buffer?Buffer.from(e):new Uint8Array(e)),"object"==typeof t?(n=t.end||e.length,l=t.start||0):(l=0,n=t>-1?t:e.length),h=0,s=null,o=null,r=e;try{u=e.dataView||(e.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength))}catch(t){if(r=null,e instanceof Uint8Array)throw t;throw new Error("Source must be a Uint8Array or Buffer but was a "+(e&&"object"==typeof e?e.constructor.name:typeof e))}if(this instanceof S){if(f=this,this.structures)return i=this.structures,m(t);(!i||i.length>0)&&(i=[])}else f=p,(!i||i.length>0)&&(i=[]);return m(t)}unpackMultiple(e,t){let r,n=0;try{w=!0;let i=e.length,s=this?this.unpack(e,i):Q.unpack(e,i);if(!t){for(r=[s];l<i;)n=l,r.push(m());return r}if(!1===t(s,n,l))return;for(;l<i;)if(n=l,!1===t(m(),n,l))return}catch(e){throw e.lastPosition=n,e.values=r,e}finally{w=!1,H()}}_mergeStructures(e,t){this._onLoadedStructures&&(e=this._onLoadedStructures(e)),e=e||[],Object.isFrozen(e)&&(e=e.map(e=>e.slice(0)));for(let t=0,r=e.length;t<r;t++){let r=e[t];r&&(r.isShared=!0,t>=32&&(r.highByte=t-32>>5))}e.sharedLength=e.length;for(let r in t||[])if(r>=0){let n=e[r],i=t[r];i&&(n&&((e.restoreStructures||(e.restoreStructures=[]))[r]=n),e[r]=i)}return this.structures=e}decode(e,t){return this.unpack(e,t)}}function m(e){try{if(!f.trusted&&!w){let e=i.sharedLength||0;e<i.length&&(i.length=e)}let t;if(f._readStruct&&r[l]<64&&r[l]>=32?(t=f._readStruct(r,l,n),r=null,e&&e.lazy||!t||(t=t.toJSON()),l=n):t=A(),o&&(l=o.postBundlePosition,o=null),w&&(i.restoreStructures=null),l==n)i&&i.restoreStructures&&U(),i=null,r=null,a&&(a=null);else{if(l>n)throw new Error("Unexpected end of MessagePack data");if(!w){let e;try{e=JSON.stringify(t,(e,t)=>"bigint"==typeof t?`${t}n`:t).slice(0,100)}catch(t){e="(JSON view not available "+t+")"}throw new Error("Data read, but end of buffer not reached "+e)}}return t}catch(e){throw i&&i.restoreStructures&&U(),H(),(e instanceof RangeError||e.message.startsWith("Unexpected end of buffer")||l>n)&&(e.incomplete=!0),e}}function U(){for(let e in i.restoreStructures)i[e]=i.restoreStructures[e];i.restoreStructures=null}function A(){let e=r[l++];if(e<160){if(e<128){if(e<64)return e;{let t=i[63&e]||f.getStructures&&v()[63&e];return t?(t.read||(t.read=I(t,63&e)),t.read()):e}}if(e<144){if(e-=128,f.mapsAsObjects){let t={};for(let r=0;r<e;r++){let e=z();"__proto__"===e&&(e="__proto_"),t[e]=A()}return t}{let t=new Map;for(let r=0;r<e;r++)t.set(A(),A());return t}}{e-=144;let t=new Array(e);for(let r=0;r<e;r++)t[r]=A();return f.freezeData?Object.freeze(t):t}}if(e<192){let t=e-160;if(h>=l)return s.slice(l-c,(l+=t)-c);if(0==h&&n<140){let e=t<16?D(t):L(t);if(null!=e)return e}return _(t)}{let t;switch(e){case 192:return null;case 193:return o?(t=A(),t>0?o[1].slice(o.position1,o.position1+=t):o[0].slice(o.position0,o.position0-=t)):y;case 194:return!1;case 195:return!0;case 196:if(t=r[l++],void 0===t)throw new Error("Unexpected end of buffer");return P(t);case 197:return t=u.getUint16(l),l+=2,P(t);case 198:return t=u.getUint32(l),l+=4,P(t);case 199:return N(r[l++]);case 200:return t=u.getUint16(l),l+=2,N(t);case 201:return t=u.getUint32(l),l+=4,N(t);case 202:if(t=u.getFloat32(l),f.useFloat32>2){let e=Z[(127&r[l])<<1|r[l+1]>>7];return l+=4,(e*t+(t>0?.5:-.5)|0)/e}return l+=4,t;case 203:return t=u.getFloat64(l),l+=8,t;case 204:return r[l++];case 205:return t=u.getUint16(l),l+=2,t;case 206:return t=u.getUint32(l),l+=4,t;case 207:return"number"===f.int64AsType?(t=4294967296*u.getUint32(l),t+=u.getUint32(l+4)):"string"===f.int64AsType?t=u.getBigUint64(l).toString():"auto"===f.int64AsType?(t=u.getBigUint64(l),t<=BigInt(2)<<BigInt(52)&&(t=Number(t))):t=u.getBigUint64(l),l+=8,t;case 208:return u.getInt8(l++);case 209:return t=u.getInt16(l),l+=2,t;case 210:return t=u.getInt32(l),l+=4,t;case 211:return"number"===f.int64AsType?(t=4294967296*u.getInt32(l),t+=u.getUint32(l+4)):"string"===f.int64AsType?t=u.getBigInt64(l).toString():"auto"===f.int64AsType?(t=u.getBigInt64(l),t>=BigInt(-2)<<BigInt(52)&&t<=BigInt(2)<<BigInt(52)&&(t=Number(t))):t=u.getBigInt64(l),l+=8,t;case 212:if(t=r[l++],114==t)return W(63&r[l++]);{let e=g[t];if(e)return e.read?(l++,e.read(A())):e.noBuffer?(l++,e()):e(r.subarray(l,++l));throw new Error("Unknown extension "+t)}case 213:return t=r[l],114==t?(l++,W(63&r[l++],r[l++])):N(2);case 214:return N(4);case 215:return N(8);case 216:return N(16);case 217:return t=r[l++],h>=l?s.slice(l-c,(l+=t)-c):k(t);case 218:return t=u.getUint16(l),h>=(l+=2)?s.slice(l-c,(l+=t)-c):B(t);case 219:return t=u.getUint32(l),h>=(l+=4)?s.slice(l-c,(l+=t)-c):x(t);case 220:return t=u.getUint16(l),l+=2,M(t);case 221:return t=u.getUint32(l),l+=4,M(t);case 222:return t=u.getUint16(l),l+=2,R(t);case 223:return t=u.getUint32(l),l+=4,R(t);default:if(e>=224)return e-256;if(void 0===e){let e=new Error("Unexpected end of MessagePack data");throw e.incomplete=!0,e}throw new Error("Unknown MessagePack token "+e)}}}const E=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function I(e,t){function r(){if(r.count++>b){let n;try{n=e.read=new(void 0)("r","return function(){return "+(f.freezeData?"Object.freeze":"")+"({"+e.map(e=>"__proto__"===e?"__proto_:r()":E.test(e)?e+":r()":"["+JSON.stringify(e)+"]:r()").join(",")+"})}")(A)}catch(e){return b=1/0,r()}return e.read0=n,0===e.highByte&&(e.read=O(t,e.read)),n()}let n={};for(let t=0,r=e.length;t<r;t++){let r=e[t];"__proto__"===r&&(r="__proto_"),n[r]=A()}return f.freezeData?Object.freeze(n):n}return r.count=0,e.read0=r,0===e.highByte?O(t,r):r}const O=(e,t)=>function(){let n=r[l++];if(0===n)return t();let s=e<32?-(e+(n<<5)):e+(n<<5),o=i[s]||v()[s];if(!o)throw new Error("Record id is not defined for "+s);return o.read||(o.read=I(o,e)),o.read()};function v(){let e=q(()=>(r=null,f.getStructures()));return i=f._mergeStructures(e,i)}var _=T,k=T,B=T,x=T;function T(e){let n;if(e<16&&(n=D(e)))return n;if(e>64&&t)return t.decode(r.subarray(l,l+=e));const i=l+e,s=[];for(n="";l<i;){const e=r[l++];if(128&e)if(192==(224&e))if(e<194||l>=i||128!=(192&r[l]))s.push(65533);else{const t=63&r[l++];s.push((31&e)<<6|t)}else if(224==(240&e)){const t=l<i?r[l]:0;if(l>=i||128!=(192&t)||224===e&&t<160||237===e&&t>=160)s.push(65533);else if(++l>=i||128!=(192&r[l]))s.push(65533);else{const n=63&r[l++];s.push((31&e)<<12|(63&t)<<6|n)}}else if(240==(248&e)){const t=l<i?r[l]:0;if(e>244||l>=i||128!=(192&t)||240===e&&t<144||244===e&&t>=144)s.push(65533);else if(++l>=i||128!=(192&r[l]))s.push(65533);else{const n=63&r[l++];if(l>=i||128!=(192&r[l]))s.push(65533);else{let i=(7&e)<<18|(63&t)<<12|n<<6|63&r[l++];i-=65536,s.push(i>>>10&1023|55296),s.push(56320|1023&i)}}}else s.push(65533);else s.push(e);s.length>=4096&&(n+=j.apply(String,s),s.length=0)}return s.length>0&&(n+=j.apply(String,s)),n}function M(e){let t=new Array(e);for(let r=0;r<e;r++)t[r]=A();return f.freezeData?Object.freeze(t):t}function R(e){if(f.mapsAsObjects){let t={};for(let r=0;r<e;r++){let e=z();"__proto__"===e&&(e="__proto_"),t[e]=A()}return t}{let t=new Map;for(let r=0;r<e;r++)t.set(A(),A());return t}}var j=String.fromCharCode;function L(e){let t=l,n=new Array(e);for(let i=0;i<e;i++){const e=r[l++];if((128&e)>0)return void(l=t);n[i]=e}return j.apply(String,n)}function D(e){if(e<4){if(e<2){if(0===e)return"";{let e=r[l++];return(128&e)>1?void(l-=1):j(e)}}{let t=r[l++],n=r[l++];if((128&t)>0||(128&n)>0)return void(l-=2);if(e<3)return j(t,n);let i=r[l++];return(128&i)>0?void(l-=3):j(t,n,i)}}{let t=r[l++],n=r[l++],i=r[l++],s=r[l++];if((128&t)>0||(128&n)>0||(128&i)>0||(128&s)>0)return void(l-=4);if(e<6){if(4===e)return j(t,n,i,s);{let e=r[l++];return(128&e)>0?void(l-=5):j(t,n,i,s,e)}}if(e<8){let o=r[l++],a=r[l++];if((128&o)>0||(128&a)>0)return void(l-=6);if(e<7)return j(t,n,i,s,o,a);let u=r[l++];return(128&u)>0?void(l-=7):j(t,n,i,s,o,a,u)}{let o=r[l++],a=r[l++],u=r[l++],f=r[l++];if((128&o)>0||(128&a)>0||(128&u)>0||(128&f)>0)return void(l-=8);if(e<10){if(8===e)return j(t,n,i,s,o,a,u,f);{let e=r[l++];return(128&e)>0?void(l-=9):j(t,n,i,s,o,a,u,f,e)}}if(e<12){let c=r[l++],h=r[l++];if((128&c)>0||(128&h)>0)return void(l-=10);if(e<11)return j(t,n,i,s,o,a,u,f,c,h);let g=r[l++];return(128&g)>0?void(l-=11):j(t,n,i,s,o,a,u,f,c,h,g)}{let c=r[l++],h=r[l++],g=r[l++],p=r[l++];if((128&c)>0||(128&h)>0||(128&g)>0||(128&p)>0)return void(l-=12);if(e<14){if(12===e)return j(t,n,i,s,o,a,u,f,c,h,g,p);{let e=r[l++];return(128&e)>0?void(l-=13):j(t,n,i,s,o,a,u,f,c,h,g,p,e)}}{let d=r[l++],y=r[l++];if((128&d)>0||(128&y)>0)return void(l-=14);if(e<15)return j(t,n,i,s,o,a,u,f,c,h,g,p,d,y);let w=r[l++];return(128&w)>0?void(l-=15):j(t,n,i,s,o,a,u,f,c,h,g,p,d,y,w)}}}}}function V(){let e,t=r[l++];if(t<192)e=t-160;else switch(t){case 217:e=r[l++];break;case 218:e=u.getUint16(l),l+=2;break;case 219:e=u.getUint32(l),l+=4;break;default:throw new Error("Expected string")}return T(e)}function P(e){return f.copyBuffers?Uint8Array.prototype.slice.call(r,l,l+=e):r.subarray(l,l+=e)}function N(e){let t=r[l++];if(g[t]){let n;return g[t](r.subarray(l,n=l+=e),e=>{l=e;try{return A()}finally{l=n}})}throw new Error("Unknown extension type "+t)}var F=new Array(4096);function z(){let e=r[l++];if(!(e>=160&&e<192))return l--,C(A());if(e-=160,h>=l)return s.slice(l-c,(l+=e)-c);if(!(0==h&&n<180))return _(e);let t,i=4095&(e<<5^(e>1?u.getUint16(l):e>0?r[l]:0)),o=F[i],a=l,f=l+e-3,g=0;if(o&&o.bytes==e){for(;a<f;){if(t=u.getUint32(a),t!=o[g++]){a=1879048192;break}a+=4}for(f+=3;a<f;)if(t=r[a++],t!=o[g++]){a=1879048192;break}if(a===f)return l=a,o.string;f-=3,a=l}for(o=[],F[i]=o,o.bytes=e;a<f;)t=u.getUint32(a),o.push(t),a+=4;for(f+=3;a<f;)t=r[a++],o.push(t);let p=e<16?D(e):L(e);return o.string=null!=p?p:_(e)}function C(e){if("string"==typeof e)return e;if("number"==typeof e||"boolean"==typeof e||"bigint"==typeof e)return e.toString();if(null==e)return e+"";if(f.allowArraysInMapKeys&&Array.isArray(e)&&e.flat().every(e=>["string","number","boolean","bigint"].includes(typeof e)))return e.flat().toString();throw new Error("Invalid property type for record: "+typeof e)}const W=(e,t)=>{let r=A().map(C),n=e;void 0!==t&&(e=e<32?-((t<<5)+e):(t<<5)+e,r.highByte=t);let s=i[e];return s&&(s.isShared||w)&&((i.restoreStructures||(i.restoreStructures=[]))[e]=s),i[e]=r,r.read=I(r,n),(r.read0||r.read)()};g[0]=()=>{},g[0].noBuffer=!0,g[66]=e=>{let t=e.byteLength%8||8,r=BigInt(128&e[0]?e[0]-256:e[0]);for(let n=1;n<t;n++)r<<=BigInt(8),r+=BigInt(e[n]);if(e.byteLength!==t){let n=new DataView(e.buffer,e.byteOffset,e.byteLength),i=(e,t)=>{let r=t-e;if(r<=40){let r=n.getBigUint64(e);for(let i=e+8;i<t;i+=8)r<<=BigInt(64),r|=n.getBigUint64(i);return r}let s=e+(r>>4<<3),o=i(e,s),a=i(s,t);return o<<BigInt(8*(t-s))|a};r=r<<BigInt(8*(n.byteLength-t))|i(t,n.byteLength)}return r};let J={Error:Error,EvalError:EvalError,RangeError:RangeError,ReferenceError:ReferenceError,SyntaxError:SyntaxError,TypeError:TypeError,URIError:URIError,AggregateError:"function"==typeof AggregateError?AggregateError:null};g[101]=()=>{let e=A();if(!J[e[0]]){let t=Error(e[1],{cause:e[2]});return t.name=e[0],t}return J[e[0]](e[1],{cause:e[2]})},g[105]=e=>{if(!1===f.structuredClone)throw new Error("Structured clone extension is disabled");let t=u.getUint32(l-4);a||(a=new Map);let n,i=r[l];n=i>=144&&i<160||220==i||221==i?[]:i>=128&&i<144||222==i||223==i?new Map:(i>=199&&i<=201||i>=212&&i<=216)&&115===r[l+1]?new Set:{};let s={target:n};a.set(t,s);let o=A();if(!s.used)return s.target=o;if(Object.assign(n,o),n instanceof Map)for(let[e,t]of o.entries())n.set(e,t);if(n instanceof Set)for(let e of Array.from(o))n.add(e);return n},g[112]=e=>{if(!1===f.structuredClone)throw new Error("Structured clone extension is disabled");let t=u.getUint32(l-4),r=a.get(t);return r.used=!0,r.target},g[115]=()=>new Set(A());const K=["Int8","Uint8","Uint8Clamped","Int16","Uint16","Int32","Uint32","Float32","Float64","BigInt64","BigUint64"].map(e=>e+"Array");let $="object"==typeof globalThis?globalThis:window;g[116]=e=>{let t=e[0],r=Uint8Array.prototype.slice.call(e,1).buffer,n=K[t];if(!n){if(16===t)return r;if(17===t)return new DataView(r);throw new Error("Could not find typed array for code "+t)}return new $[n](r)},g[120]=()=>{let e=A();return new RegExp(e[0],e[1])};const Y=[];function q(e){f&&f._onSaveState&&f._onSaveState();let t=n,g=l,p=c,d=h,y=s,b=a,S=o,m=new Uint8Array(r.slice(0,n)),U=i,A=i.slice(0,i.length),E=f,I=w,O=e();return n=t,l=g,c=p,h=d,s=y,a=b,o=S,r=m,w=I,(i=U).splice(0,i.length,...A),f=E,u=new DataView(r.buffer,r.byteOffset,r.byteLength),O}function H(){r=null,a=null,i=null}g[98]=e=>{let t=(e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3],r=l;return l+=t-e.length,o=Y,(o=[V(),V()]).position0=0,o.position1=0,o.postBundlePosition=l,l=r,A()},g[255]=e=>4==e.length?new Date(1e3*(16777216*e[0]+(e[1]<<16)+(e[2]<<8)+e[3])):8==e.length?new Date(((e[0]<<22)+(e[1]<<14)+(e[2]<<6)+(e[3]>>2))/1e6+1e3*(4294967296*(3&e[3])+16777216*e[4]+(e[5]<<16)+(e[6]<<8)+e[7])):12==e.length?new Date(((e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3])/1e6+1e3*((128&e[4]?-281474976710656:0)+1099511627776*e[6]+4294967296*e[7]+16777216*e[8]+(e[9]<<16)+(e[10]<<8)+e[11])):new Date("invalid");const Z=new Array(147);for(let e=0;e<256;e++)Z[e]=+("1e"+Math.floor(45.15-.30103*e));const G=S;var Q=new S({useRecords:!1});const X=Q.unpack,ee=Q.unpackMultiple,te=Q.unpack,re={NEVER:0,ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4};let ne,ie,se,oe=new Float32Array(1),ae=new Uint8Array(oe.buffer,0,4);S.SUPPORTS_STRUCT_HOOKS=!0;try{ne=new TextEncoder}catch(e){}const ue="undefined"!=typeof Buffer,le=ue?function(e){return Buffer.allocUnsafeSlow(e)}:Uint8Array,fe=ue?Buffer:Uint8Array,ce=ue?4294967296:2144337920;let he,ge,pe,de,ye=0,we=null;const be=/[\u0080-\uFFFF]/,Se=Symbol("record-id");class me extends S{constructor(e){let t,r,n,i;super(e),this.offset=0;let s=fe.prototype.utf8Write?function(e,t){return he.utf8Write(e,t,he.byteLength-t)}:!(!ne||!ne.encodeInto)&&function(e,t){return ne.encodeInto(e,he.subarray(t)).written},o=this;e||(e={});let a=e&&e.sequential,u=e.structures||e.saveStructures,l=e.maxSharedStructures;if(null==l&&(l=u?32:0),l>8160)throw new Error("Maximum maxSharedStructure is 8160");e.structuredClone&&null==e.moreTypes&&(this.moreTypes=!0);let f=e.maxOwnStructures;null==f&&(f=u?32:64),this.structures||0==e.useRecords||(this.structures=[]);let c=l>32||f+l>64,h=l+64,g=l+f+64;if(g>8256)throw new Error("Maximum maxSharedStructure + maxOwnStructure is 8192");let p=[],d=0,y=0;this.pack=this.encode=function(e,s){if(he||(he=new le(8192),pe=he.dataView||(he.dataView=new DataView(he.buffer,0,8192)),ye=0),de=he.length-10,de-ye<2048?(he=new le(he.length),pe=he.dataView||(he.dataView=new DataView(he.buffer,0,he.length)),de=he.length-10,ye=0):ye=ye+7&2147483640,t=ye,s&De&&(ye+=255&s),i=o.structuredClone?new Map:null,o.bundleStrings&&"string"!=typeof e?(we=[],we.size=1/0):we=null,n=o.structures,n){n.uninitialized&&(n=o._mergeStructures(o.getStructures()));let e=n.sharedLength||0;if(e>l)throw new Error("Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to "+n.sharedLength);if(!n.transitions){n.transitions=Object.create(null);for(let t=0;t<e;t++){let e=n[t];if(!e)continue;let r,i=n.transitions;for(let t=0,n=e.length;t<n;t++){let n=e[t];r=i[n],r||(r=i[n]=Object.create(null)),i=r}i[Se]=t+64}this.lastNamedStructuresLength=e}a||(n.nextId=e+64)}let u;r&&(r=!1);try{o._writeStruct&&e&&"object"==typeof e?e.constructor===Object?I(e):e.constructor===Map||Array.isArray(e)||se.some(t=>e instanceof t)?S(e):I(e.toJSON?e.toJSON():e):S(e);let r=we;if(we&&Ie(t,S,0),i&&i.idsToInsert){let e=i.idsToInsert.sort((e,t)=>e.offset>t.offset?1:-1),n=e.length,s=-1;for(;r&&n>0;){let i=e[--n].offset+t;i<r.stringsPosition+t&&-1===s&&(s=0),i>r.position+t?s>=0&&(s+=6):(s>=0&&(pe.setUint32(r.position+t,pe.getUint32(r.position+t)+s),s=-1),r=r.previous,n++)}s>=0&&r&&pe.setUint32(r.position+t,pe.getUint32(r.position+t)+s),ye+=6*e.length,ye>de&&O(ye),o.offset=ye;let a=function(e,t){let r,n=6*t.length,i=e.length-n;for(;r=t.pop();){let t=r.offset,s=r.id;e.copyWithin(t+n,t,i),n-=6;let o=t+n;e[o++]=214,e[o++]=105,e[o++]=s>>24,e[o++]=s>>16&255,e[o++]=s>>8&255,e[o++]=255&s,i=t}return e}(he.subarray(t,ye),e);return i=null,a}return o.offset=ye,s&je?(he.start=t,he.end=ye,he):he.subarray(t,ye)}catch(e){throw u=e,e}finally{if(n&&(w(),r&&o.saveStructures)){let r=n.sharedLength||0,i=he.subarray(t,ye),a=(o._prepareStructures||Oe)(n,o);if(!u)return!1===o.saveStructures(a,a.isCompatible)?(n.uninitialized=!0,o.pack(e,s)):(o.lastNamedStructuresLength=r,he.length>1073741824&&(he=null),i)}he.length>1073741824&&(he=null),s&Le&&(ye=t)}};const w=()=>{y<10&&y++;let e=n.sharedLength||0;if(n.length>e&&!a&&(n.length=e),d>1e4)n.transitions=null,y=0,d=0,p.length>0&&(p=[]);else if(p.length>0&&!a){for(let e=0,t=p.length;e<t;e++)p[e][Se]=0;p=[]}},b=e=>{var t=e.length;t<16?he[ye++]=144|t:t<65536?(he[ye++]=220,he[ye++]=t>>8,he[ye++]=255&t):(he[ye++]=221,pe.setUint32(ye,t),ye+=4);for(let r=0;r<t;r++)S(e[r])},S=e=>{ye>de&&(he=O(ye));var r,n=typeof e;if("string"===n){let n,i=e.length;if(we&&i>=4&&i<4096){if((we.size+=i)>21760){let e,r,n=(we[0]?3*we[0].length+we[1].length:0)+10;ye+n>de&&(he=O(ye+n)),we.position?(r=we,he[ye]=200,ye+=3,he[ye++]=98,e=ye-t,ye+=4,Ie(t,S,0),pe.setUint16(e+t-3,ye-t-e)):(he[ye++]=214,he[ye++]=98,e=ye-t,ye+=4),we=["",""],we.previous=r,we.size=0,we.position=e}let r=be.test(e);return we[r?0:1]+=e,he[ye++]=193,void S(r?-i:i)}n=i<32?1:i<256?2:i<65536?3:5;let o=3*i;if(ye+o>de&&(he=O(ye+o)),i<64||!s){let t,s,o,a=ye+n;for(t=0;t<i;t++)s=e.charCodeAt(t),s<128?he[a++]=s:s<2048?(he[a++]=s>>6|192,he[a++]=63&s|128):55296==(64512&s)&&56320==(64512&(o=e.charCodeAt(t+1)))?(s=65536+((1023&s)<<10)+(1023&o),t++,he[a++]=s>>18|240,he[a++]=s>>12&63|128,he[a++]=s>>6&63|128,he[a++]=63&s|128):(he[a++]=s>>12|224,he[a++]=s>>6&63|128,he[a++]=63&s|128);r=a-ye-n}else r=s(e,ye+n);r<32?he[ye++]=160|r:r<256?(n<2&&he.copyWithin(ye+2,ye+1,ye+1+r),he[ye++]=217,he[ye++]=r):r<65536?(n<3&&he.copyWithin(ye+3,ye+2,ye+2+r),he[ye++]=218,he[ye++]=r>>8,he[ye++]=255&r):(n<5&&he.copyWithin(ye+5,ye+3,ye+3+r),he[ye++]=219,pe.setUint32(ye,r),ye+=4),ye+=r}else if("number"===n)if(e>>>0===e)e<32||e<128&&!1===this.useRecords||e<64&&!this._writeStruct?he[ye++]=e:e<256?(he[ye++]=204,he[ye++]=e):e<65536?(he[ye++]=205,he[ye++]=e>>8,he[ye++]=255&e):(he[ye++]=206,pe.setUint32(ye,e),ye+=4);else if((e|0)===e)e>=-32?he[ye++]=256+e:e>=-128?(he[ye++]=208,he[ye++]=e+256):e>=-32768?(he[ye++]=209,pe.setInt16(ye,e),ye+=2):(he[ye++]=210,pe.setInt32(ye,e),ye+=4);else{let t;if((t=this.useFloat32)>0&&e<4294967296&&e>=-2147483648){let r;if(he[ye++]=202,pe.setFloat32(ye,e),t<4||((r=e*Z[(127&he[ye])<<1|he[ye+1]>>7])|0)===r)return void(ye+=4);ye--}he[ye++]=203,pe.setFloat64(ye,e),ye+=8}else if("object"===n||"function"===n)if(e){if(i){let r=i.get(e);if(r){if(!r.id){let e=i.idsToInsert||(i.idsToInsert=[]);r.id=e.push(r)}return he[ye++]=214,he[ye++]=112,pe.setUint32(ye,r.id),void(ye+=4)}i.set(e,{offset:ye-t})}let s=e.constructor;if(s===Object)E(e);else if(s===Array)b(e);else if(s===Map)if(this.mapAsEmptyObject)he[ye++]=128;else{(r=e.size)<16?he[ye++]=128|r:r<65536?(he[ye++]=222,he[ye++]=r>>8,he[ye++]=255&r):(he[ye++]=223,pe.setUint32(ye,r),ye+=4);for(let[t,r]of e)S(t),S(r)}else{for(let t=0,r=ie.length;t<r;t++){if(e instanceof se[t]){let r=ie[t];if(r.write){r.type&&(he[ye++]=212,he[ye++]=r.type,he[ye++]=0);let t=r.write.call(this,e);return void(t===e?Array.isArray(e)?b(e):E(e):S(t))}let n,i=he,s=pe,o=ye;he=null;try{n=r.pack.call(this,e,e=>(he=i,i=null,ye+=e,ye>de&&O(ye),{target:he,targetView:pe,position:ye-e}),S)}finally{i&&(he=i,pe=s,ye=o,de=he.length-10)}return void(n&&(n.length+ye>de&&O(n.length+ye),ye=Ee(n,he,ye,r.type)))}}if(Array.isArray(e))b(e);else{if(e.toJSON){const t=e.toJSON();if(t!==e)return S(t)}if("function"===n)return S(this.writeFunction&&this.writeFunction(e));E(e)}}}else he[ye++]=192;else if("boolean"===n)he[ye++]=e?195:194;else if("bigint"===n){if(e<0x8000000000000000&&e>=-0x8000000000000000)he[ye++]=211,pe.setBigInt64(ye,e);else if(e<0x10000000000000000&&e>0)he[ye++]=207,pe.setBigUint64(ye,e);else{if(!this.largeBigIntToFloat){if(this.largeBigIntToString)return S(e.toString());if(this.useBigIntExtension||this.moreTypes){let t,r=e<0?BigInt(-1):BigInt(0);if(e>>BigInt(65536)===r){let n=BigInt(0x10000000000000000)-BigInt(1),i=[];for(;i.push(e&n),e>>BigInt(63)!==r;)e>>=BigInt(64);t=new Uint8Array(new BigUint64Array(i).buffer),t.reverse()}else{let r=e<0,n=(r?~e:e).toString(16);if(n.length%2?n="0"+n:parseInt(n.charAt(0),16)>=8&&(n="00"+n),ue)t=Buffer.from(n,"hex");else{t=new Uint8Array(n.length/2);for(let e=0;e<t.length;e++)t[e]=parseInt(n.slice(2*e,2*e+2),16)}if(r)for(let e=0;e<t.length;e++)t[e]=~t[e]}return t.length+ye>de&&O(t.length+ye),void(ye=Ee(t,he,ye,66))}throw new RangeError(e+" was too large to fit in MessagePack 64-bit integer format, use useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set largeBigIntToString to convert to string")}he[ye++]=203,pe.setFloat64(ye,Number(e))}ye+=8}else{if("undefined"!==n)throw new Error("Unknown type: "+n);this.encodeUndefinedAsNil?he[ye++]=192:(he[ye++]=212,he[ye++]=0,he[ye++]=0)}},m=this.variableMapSize||this.coercibleKeyAsNumber||this.skipValues?e=>{let t;if(this.skipValues){t=[];for(let r in e)"function"==typeof e.hasOwnProperty&&!e.hasOwnProperty(r)||this.skipValues.includes(e[r])||t.push(r)}else t=Object.keys(e);let r,n=t.length;if(n<16?he[ye++]=128|n:n<65536?(he[ye++]=222,he[ye++]=n>>8,he[ye++]=255&n):(he[ye++]=223,pe.setUint32(ye,n),ye+=4),this.coercibleKeyAsNumber)for(let i=0;i<n;i++){r=t[i];let n=Number(r);S(isNaN(n)?r:n),S(e[r])}else for(let i=0;i<n;i++)S(r=t[i]),S(e[r])}:e=>{he[ye++]=222;let r=ye-t;ye+=2;let n=0;for(let t in e)("function"!=typeof e.hasOwnProperty||e.hasOwnProperty(t))&&(S(t),S(e[t]),n++);if(n>65535)throw new Error('Object is too large to serialize with fast 16-bit map size, use the "variableMapSize" option to serialize this object');he[r+++t]=n>>8,he[r+t]=255&n},U=!1===this.useRecords?m:e.progressiveRecords&&!c?e=>{let r,i,s=n.transitions||(n.transitions=Object.create(null)),o=ye++-t;for(let a in e)if("function"!=typeof e.hasOwnProperty||e.hasOwnProperty(a)){if(r=s[a],r)s=r;else{let u=Object.keys(e),l=s;s=n.transitions;let f=0;for(let e=0,t=u.length;e<t;e++){let t=u[e];r=s[t],r||(r=s[t]=Object.create(null),f++),s=r}o+t+1==ye?(ye--,v(s,u,f)):_(s,u,o,f),i=!0,s=l[a]}S(e[a])}if(!i){let r=s[Se];r?he[o+t]=r:_(s,Object.keys(e),o,0)}}:e=>{let t,r=n.transitions||(n.transitions=Object.create(null)),i=0;for(let n in e)("function"!=typeof e.hasOwnProperty||e.hasOwnProperty(n))&&(t=r[n],t||(t=r[n]=Object.create(null),i++),r=t);let s=r[Se];s?s>=96&&c?(he[ye++]=96+(31&(s-=96)),he[ye++]=s>>5):he[ye++]=s:v(r,r.__keys__||Object.keys(e),i);for(let t in e)("function"!=typeof e.hasOwnProperty||e.hasOwnProperty(t))&&S(e[t])},A="function"==typeof this.useRecords&&this.useRecords,E=A?e=>{A(e)?U(e):m(e)}:U,I=e=>{let i=o._writeStruct(e,he,t,ye,n,O,(e,t,n)=>{if(n)return r=!0;ye=t;let i=he;return S(e),w(),i!==he?{position:ye,targetView:pe,target:he}:ye});if(0===i)return E(e);ye=i},O=e=>{let r;if(e>16777216){if(e-t>ce)throw new Error("Packed buffer would be larger than maximum buffer size");r=Math.min(ce,4096*Math.round(Math.max((e-t)*(e>67108864?1.25:2),4194304)/4096))}else r=1+(Math.max(e-t<<2,he.length-1)>>12)<<12;let n=new le(r);return pe=n.dataView||(n.dataView=new DataView(n.buffer,0,r)),e=Math.min(e,he.length),he.copy?he.copy(n,0,t,e):n.set(he.slice(t,e)),ye-=t,t=0,de=n.length-10,he=n},v=(e,t,i)=>{let s=n.nextId;s||(s=64),s<h&&this.shouldShareStructure&&!this.shouldShareStructure(t)?(s=n.nextOwnId,s<g||(s=h),n.nextOwnId=s+1):(s>=g&&(s=h),n.nextId=s+1);let o=t.highByte=s>=96&&c?s-96>>5:-1;e[Se]=s,e.__keys__=t,n[s-64]=t,s<h?(t.isShared=!0,n.sharedLength=s-63,r=!0,o>=0?(he[ye++]=96+(31&s),he[ye++]=o):he[ye++]=s):(o>=0?(he[ye++]=213,he[ye++]=114,he[ye++]=96+(31&s),he[ye++]=o):(he[ye++]=212,he[ye++]=114,he[ye++]=s),i&&(d+=y*i),p.length>=f&&(p.shift()[Se]=0),p.push(e),S(t))},_=(e,r,n,i)=>{let s=he,o=ye,a=de,u=t;he=ge,ye=0,t=0,he||(ge=he=new le(8192)),de=he.length-10,v(e,r,i),ge=he;let l=ye;if(he=s,ye=o,de=a,t=u,l>1){let e=ye+l-1;e>de&&O(e);let r=n+t;he.copyWithin(r+l,r+1,ye),he.set(ge.slice(0,l),r),ye=e}else he[n+t]=ge[0]}}useBuffer(e){he=e,he.dataView||(he.dataView=new DataView(he.buffer,he.byteOffset,he.byteLength)),pe=he.dataView,ye=0}set position(e){ye=e}get position(){return ye}clearSharedData(){this.structures&&(this.structures=[]),this.typedStructs&&(this.typedStructs=[])}}function Ue(e,t,r,n){let i=e.byteLength;if(i+1<256){var{target:s,position:o}=r(4+i);s[o++]=199,s[o++]=i+1}else if(i+1<65536){var{target:s,position:o}=r(5+i);s[o++]=200,s[o++]=i+1>>8,s[o++]=i+1&255}else{var{target:s,position:o,targetView:a}=r(7+i);s[o++]=201,a.setUint32(o,i+1),o+=4}s[o++]=116,s[o++]=t,e.buffer||(e=new Uint8Array(e)),s.set(new Uint8Array(e.buffer,e.byteOffset,e.byteLength),o)}function Ae(e,t){let r=e.byteLength;var n,i;if(r<256){var{target:n,position:i}=t(r+2);n[i++]=196,n[i++]=r}else if(r<65536){var{target:n,position:i}=t(r+3);n[i++]=197,n[i++]=r>>8,n[i++]=255&r}else{var{target:n,position:i,targetView:s}=t(r+5);n[i++]=198,s.setUint32(i,r),i+=4}n.set(e,i)}function Ee(e,t,r,n){let i=e.length;switch(i){case 1:t[r++]=212;break;case 2:t[r++]=213;break;case 4:t[r++]=214;break;case 8:t[r++]=215;break;case 16:t[r++]=216;break;default:i<256?(t[r++]=199,t[r++]=i):i<65536?(t[r++]=200,t[r++]=i>>8,t[r++]=255&i):(t[r++]=201,t[r++]=i>>24,t[r++]=i>>16&255,t[r++]=i>>8&255,t[r++]=255&i)}return t[r++]=n,t.set(e,r),r+=i}function Ie(e,t,r){if(we.length>0){pe.setUint32(we.position+e,ye+r-we.position-e),we.stringsPosition=ye-e;let n=we;we=null,t(n[0]),t(n[1])}}function Oe(e,t){return e.isCompatible=e=>{let r=!e||(t.lastNamedStructuresLength||0)===e.length;return r||t._mergeStructures(e),r},e}se=[Date,Set,Error,RegExp,ArrayBuffer,Object.getPrototypeOf(Uint8Array.prototype).constructor,DataView,d],ie=[{pack(e,t,r){let n=e.getTime()/1e3;if((this.useTimestamp32||0===e.getMilliseconds())&&n>=0&&n<4294967296){let{target:e,targetView:r,position:i}=t(6);e[i++]=214,e[i++]=255,r.setUint32(i,n)}else if(n>0&&n<4294967296){let{target:r,targetView:i,position:s}=t(10);r[s++]=215,r[s++]=255,i.setUint32(s,4e6*e.getMilliseconds()+(n/1e3/4294967296|0)),i.setUint32(s+4,n)}else if(isNaN(n)){if(this.onInvalidDate)return t(0),r(this.onInvalidDate());let{target:e,targetView:n,position:i}=t(3);e[i++]=212,e[i++]=255,e[i++]=255}else{let{target:r,targetView:i,position:s}=t(15);r[s++]=199,r[s++]=12,r[s++]=255,i.setUint32(s,1e6*e.getMilliseconds()),i.setBigInt64(s+4,BigInt(Math.floor(n)))}}},{pack(e,t,r){if(this.setAsEmptyObject)return t(0),r({});let n=Array.from(e),{target:i,position:s}=t(this.moreTypes?3:0);this.moreTypes&&(i[s++]=212,i[s++]=115,i[s++]=0),r(n)}},{pack(e,t,r){let{target:n,position:i}=t(this.moreTypes?3:0);this.moreTypes&&(n[i++]=212,n[i++]=101,n[i++]=0),r([e.name,e.message,e.cause])}},{pack(e,t,r){let{target:n,position:i}=t(this.moreTypes?3:0);this.moreTypes&&(n[i++]=212,n[i++]=120,n[i++]=0),r([e.source,e.flags])}},{pack(e,t){this.moreTypes?Ue(e,16,t):Ae(ue?Buffer.from(e):new Uint8Array(e),t)}},{pack(e,t){let r=e.constructor;r!==fe&&this.moreTypes?Ue(e,K.indexOf(r.name),t):Ae(e,t)}},{pack(e,t){this.moreTypes?Ue(e,17,t):Ae(ue?Buffer.from(e):new Uint8Array(e),t)}},{pack(e,t){let{target:r,position:n}=t(1);r[n]=193}}],me.SUPPORTS_STRUCT_HOOKS=!0;let ve=new me({useRecords:!1});const _e=ve.pack,ke=ve.pack,Be=me,{NEVER:xe,ALWAYS:Te,DECIMAL_ROUND:Me,DECIMAL_FIT:Re}=re,je=512,Le=1024,De=2048;const Ve=function(e,t={}){if(!e||"object"!=typeof e)throw new Error("first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a promise");const r=new S(t);let n;const i=e=>{let t;n&&(e=Buffer.concat([n,e]),n=void 0);try{t=r.unpackMultiple(e)}catch(r){if(!r.incomplete)throw r;n=e.slice(r.lastPosition),t=r.values}return t};return"function"==typeof e[Symbol.iterator]?function*(){for(const t of e)yield*i(t)}():"function"==typeof e[Symbol.asyncIterator]?async function*(){for await(const t of e)yield*i(t)}():void 0},Pe=function(e,t={}){if(e&&"object"==typeof e){if("function"==typeof e[Symbol.iterator])return function*(e,t){const r=new me(t);for(const t of e)yield r.pack(t)}(e,t);if("function"==typeof e.then||"function"==typeof e[Symbol.asyncIterator])return async function*(e,t){const r=new me(t);for await(const t of e)yield r.pack(t)}(e,t);throw new Error("first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a Promise")}throw new Error("first argument must be an Iterable, Async Iterable, or a Promise for an Async Iterable")};e.ALWAYS=Te,e.C1=y,e.DECIMAL_FIT=Re,e.DECIMAL_ROUND=Me,e.Decoder=G,e.Encoder=Be,e.FLOAT32_OPTIONS=re,e.NEVER=xe,e.Packr=me,e.RESERVE_START_SPACE=De,e.RESET_BUFFER_MODE=Le,e.REUSE_BUFFER_MODE=je,e.Unpackr=S,e.addExtension=function(e){if(e.Class){if(!e.pack&&!e.write)throw new Error("Extension has no pack or write function");if(e.pack&&!e.type)throw new Error("Extension has no type (numeric code to identify the extension)");se.unshift(e.Class),ie.unshift(e)}!function(e){e.unpack?g[e.type]=e.unpack:g[e.type]=e}(e)},e.clearSource=H,e.decode=te,e.decodeIter=Ve,e.encode=ke,e.encodeIter=Pe,e.isNativeAccelerationEnabled=!1,e.mapsAsObjects=!0,e.pack=_e,e.roundFloat32=function(e){oe[0]=e;let t=Z[(127&ae[3])<<1|ae[2]>>7];return(t*e+(e>0?.5:-.5)|0)/t},e.unpack=X,e.unpackMultiple=ee,e.useRecords=!1});
2
  //# sourceMappingURL=index-no-eval.min.js.map
.opencode/node_modules/msgpackr/dist/index-no-eval.min.js.map CHANGED
The diff for this file is too large to render. See raw diff
 
.opencode/node_modules/msgpackr/dist/index.js CHANGED
@@ -29,7 +29,6 @@
29
  C1.name = 'MessagePack 0xC1';
30
  var sequentialMode = false;
31
  var inlineObjectReadThreshold = 2;
32
- var readStruct;
33
 
34
  class Unpackr {
35
  constructor(options) {
@@ -61,8 +60,8 @@
61
  // re-entrant execution, save the state and restore it after we do this unpack
62
  return saveState(() => {
63
  clearSource();
64
- return this ? this.unpack(source, options) : Unpackr.prototype.unpack.call(defaultOptions, source, options)
65
- })
66
  }
67
  if (!source.buffer && source.constructor === ArrayBuffer)
68
  source = typeof Buffer !== 'undefined' ? Buffer.from(source) : new Uint8Array(source);
@@ -86,14 +85,14 @@
86
  // if it doesn't have a buffer, maybe it is the wrong type of object
87
  src = null;
88
  if (source instanceof Uint8Array)
89
- throw error
90
- throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source))
91
  }
92
  if (this instanceof Unpackr) {
93
  currentUnpackr = this;
94
  if (this.structures) {
95
  currentStructures = this.structures;
96
- return checkedRead(options)
97
  } else if (!currentStructures || currentStructures.length > 0) {
98
  currentStructures = [];
99
  }
@@ -102,7 +101,7 @@
102
  if (!currentStructures || currentStructures.length > 0)
103
  currentStructures = [];
104
  }
105
- return checkedRead(options)
106
  }
107
  unpackMultiple(source, forEach) {
108
  let values, lastPosition = 0;
@@ -115,7 +114,7 @@
115
  while(position$1 < size) {
116
  lastPosition = position$1;
117
  if (forEach(checkedRead(), lastPosition, position$1) === false) {
118
- return
119
  }
120
  }
121
  }
@@ -125,18 +124,20 @@
125
  lastPosition = position$1;
126
  values.push(checkedRead());
127
  }
128
- return values
129
  }
130
  } catch(error) {
131
  error.lastPosition = lastPosition;
132
  error.values = values;
133
- throw error
134
  } finally {
135
  sequentialMode = false;
136
  clearSource();
137
  }
138
  }
139
  _mergeStructures(loadedStructures, existingStructures) {
 
 
140
  loadedStructures = loadedStructures || [];
141
  if (Object.isFrozen(loadedStructures))
142
  loadedStructures = loadedStructures.map(structure => structure.slice(0));
@@ -160,10 +161,10 @@
160
  }
161
  }
162
  }
163
- return this.structures = loadedStructures
164
  }
165
  decode(source, options) {
166
- return this.unpack(source, options)
167
  }
168
  }
169
  function checkedRead(options) {
@@ -174,8 +175,8 @@
174
  currentStructures.length = sharedLength;
175
  }
176
  let result;
177
- if (currentUnpackr.randomAccessStructure && src[position$1] < 0x40 && src[position$1] >= 0x20 && readStruct) {
178
- result = readStruct(src, position$1, srcEnd, currentUnpackr);
179
  src = null; // dispose of this so that recursive unpack calls don't save state
180
  if (!(options && options.lazy) && result)
181
  result = result.toJSON();
@@ -201,7 +202,7 @@
201
  referenceMap = null;
202
  } else if (position$1 > srcEnd) {
203
  // over read
204
- throw new Error('Unexpected end of MessagePack data')
205
  } else if (!sequentialMode) {
206
  let jsonView;
207
  try {
@@ -209,10 +210,10 @@
209
  } catch(error) {
210
  jsonView = '(JSON view not available ' + error + ')';
211
  }
212
- throw new Error('Data read, but end of buffer not reached ' + jsonView)
213
  }
214
  // else more to read, but we are reading sequentially, so don't clear source yet
215
- return result
216
  } catch(error) {
217
  if (currentStructures && currentStructures.restoreStructures)
218
  restoreStructures();
@@ -220,7 +221,7 @@
220
  if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position$1 > srcEnd) {
221
  error.incomplete = true;
222
  }
223
- throw error
224
  }
225
  }
226
 
@@ -236,7 +237,7 @@
236
  if (token < 0xa0) {
237
  if (token < 0x80) {
238
  if (token < 0x40)
239
- return token
240
  else {
241
  let structure = currentStructures[token & 0x3f] ||
242
  currentUnpackr.getStructures && loadStructures()[token & 0x3f];
@@ -244,9 +245,9 @@
244
  if (!structure.read) {
245
  structure.read = createStructureReader(structure, token & 0x3f);
246
  }
247
- return structure.read()
248
  } else
249
- return token
250
  }
251
  } else if (token < 0x90) {
252
  // map
@@ -259,13 +260,13 @@
259
  key = '__proto_';
260
  object[key] = read();
261
  }
262
- return object
263
  } else {
264
  let map = new Map();
265
  for (let i = 0; i < token; i++) {
266
  map.set(read(), read());
267
  }
268
- return map
269
  }
270
  } else {
271
  token -= 0x90;
@@ -274,91 +275,91 @@
274
  array[i] = read();
275
  }
276
  if (currentUnpackr.freezeData)
277
- return Object.freeze(array)
278
- return array
279
  }
280
  } else if (token < 0xc0) {
281
  // fixstr
282
  let length = token - 0xa0;
283
  if (srcStringEnd >= position$1) {
284
- return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart)
285
  }
286
  if (srcStringEnd == 0 && srcEnd < 140) {
287
  // for small blocks, avoiding the overhead of the extract call is helpful
288
  let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
289
  if (string != null)
290
- return string
291
  }
292
- return readFixedString(length)
293
  } else {
294
  let value;
295
  switch (token) {
296
- case 0xc0: return null
297
  case 0xc1:
298
  if (bundledStrings$1) {
299
  value = read(); // followed by the length of the string in characters (not bytes!)
300
  if (value > 0)
301
- return bundledStrings$1[1].slice(bundledStrings$1.position1, bundledStrings$1.position1 += value)
302
  else
303
- return bundledStrings$1[0].slice(bundledStrings$1.position0, bundledStrings$1.position0 -= value)
304
  }
305
  return C1; // "never-used", return special object to denote that
306
- case 0xc2: return false
307
- case 0xc3: return true
308
  case 0xc4:
309
  // bin 8
310
  value = src[position$1++];
311
  if (value === undefined)
312
- throw new Error('Unexpected end of buffer')
313
- return readBin(value)
314
  case 0xc5:
315
  // bin 16
316
  value = dataView.getUint16(position$1);
317
  position$1 += 2;
318
- return readBin(value)
319
  case 0xc6:
320
  // bin 32
321
  value = dataView.getUint32(position$1);
322
  position$1 += 4;
323
- return readBin(value)
324
  case 0xc7:
325
  // ext 8
326
- return readExt(src[position$1++])
327
  case 0xc8:
328
  // ext 16
329
  value = dataView.getUint16(position$1);
330
  position$1 += 2;
331
- return readExt(value)
332
  case 0xc9:
333
  // ext 32
334
  value = dataView.getUint32(position$1);
335
  position$1 += 4;
336
- return readExt(value)
337
  case 0xca:
338
  value = dataView.getFloat32(position$1);
339
  if (currentUnpackr.useFloat32 > 2) {
340
  // this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
341
  let multiplier = mult10[((src[position$1] & 0x7f) << 1) | (src[position$1 + 1] >> 7)];
342
  position$1 += 4;
343
- return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier
344
  }
345
  position$1 += 4;
346
- return value
347
  case 0xcb:
348
  value = dataView.getFloat64(position$1);
349
  position$1 += 8;
350
- return value
351
  // uint handlers
352
  case 0xcc:
353
- return src[position$1++]
354
  case 0xcd:
355
  value = dataView.getUint16(position$1);
356
  position$1 += 2;
357
- return value
358
  case 0xce:
359
  value = dataView.getUint32(position$1);
360
  position$1 += 4;
361
- return value
362
  case 0xcf:
363
  if (currentUnpackr.int64AsType === 'number') {
364
  value = dataView.getUint32(position$1) * 0x100000000;
@@ -371,19 +372,19 @@
371
  } else
372
  value = dataView.getBigUint64(position$1);
373
  position$1 += 8;
374
- return value
375
 
376
  // int handlers
377
  case 0xd0:
378
- return dataView.getInt8(position$1++)
379
  case 0xd1:
380
  value = dataView.getInt16(position$1);
381
  position$1 += 2;
382
- return value
383
  case 0xd2:
384
  value = dataView.getInt32(position$1);
385
  position$1 += 4;
386
- return value
387
  case 0xd3:
388
  if (currentUnpackr.int64AsType === 'number') {
389
  value = dataView.getInt32(position$1) * 0x100000000;
@@ -396,96 +397,96 @@
396
  } else
397
  value = dataView.getBigInt64(position$1);
398
  position$1 += 8;
399
- return value
400
 
401
  case 0xd4:
402
  // fixext 1
403
  value = src[position$1++];
404
  if (value == 0x72) {
405
- return recordDefinition(src[position$1++] & 0x3f)
406
  } else {
407
  let extension = currentExtensions[value];
408
  if (extension) {
409
  if (extension.read) {
410
  position$1++; // skip filler byte
411
- return extension.read(read())
412
  } else if (extension.noBuffer) {
413
  position$1++; // skip filler byte
414
- return extension()
415
  } else
416
- return extension(src.subarray(position$1, ++position$1))
417
  } else
418
- throw new Error('Unknown extension ' + value)
419
  }
420
  case 0xd5:
421
  // fixext 2
422
  value = src[position$1];
423
  if (value == 0x72) {
424
  position$1++;
425
- return recordDefinition(src[position$1++] & 0x3f, src[position$1++])
426
  } else
427
- return readExt(2)
428
  case 0xd6:
429
  // fixext 4
430
- return readExt(4)
431
  case 0xd7:
432
  // fixext 8
433
- return readExt(8)
434
  case 0xd8:
435
  // fixext 16
436
- return readExt(16)
437
  case 0xd9:
438
  // str 8
439
  value = src[position$1++];
440
  if (srcStringEnd >= position$1) {
441
- return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
442
  }
443
- return readString8(value)
444
  case 0xda:
445
  // str 16
446
  value = dataView.getUint16(position$1);
447
  position$1 += 2;
448
  if (srcStringEnd >= position$1) {
449
- return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
450
  }
451
- return readString16(value)
452
  case 0xdb:
453
  // str 32
454
  value = dataView.getUint32(position$1);
455
  position$1 += 4;
456
  if (srcStringEnd >= position$1) {
457
- return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
458
  }
459
- return readString32(value)
460
  case 0xdc:
461
  // array 16
462
  value = dataView.getUint16(position$1);
463
  position$1 += 2;
464
- return readArray(value)
465
  case 0xdd:
466
  // array 32
467
  value = dataView.getUint32(position$1);
468
  position$1 += 4;
469
- return readArray(value)
470
  case 0xde:
471
  // map 16
472
  value = dataView.getUint16(position$1);
473
  position$1 += 2;
474
- return readMap(value)
475
  case 0xdf:
476
  // map 32
477
  value = dataView.getUint32(position$1);
478
  position$1 += 4;
479
- return readMap(value)
480
  default: // negative int
481
  if (token >= 0xe0)
482
- return token - 0x100
483
  if (token === undefined) {
484
  let error = new Error('Unexpected end of MessagePack data');
485
  error.incomplete = true;
486
- throw error
487
  }
488
- throw new Error('Unknown MessagePack token ' + token)
489
 
490
  }
491
  }
@@ -504,9 +505,10 @@
504
  inlineObjectReadThreshold = Infinity; // disable going forward
505
  return readObject(); // recursively try again
506
  }
 
507
  if (structure.highByte === 0)
508
  structure.read = createSecondByteReader(firstId, structure.read);
509
- return optimizedReadObject() // second byte is already read, if there is one so immediately read object
510
  }
511
  let object = {};
512
  for (let i = 0, l = structure.length; i < l; i++) {
@@ -517,38 +519,44 @@
517
  }
518
  if (currentUnpackr.freezeData)
519
  return Object.freeze(object);
520
- return object
521
  }
522
  readObject.count = 0;
 
 
 
 
 
 
523
  if (structure.highByte === 0) {
524
- return createSecondByteReader(firstId, readObject)
525
  }
526
- return readObject
527
  }
528
 
529
  const createSecondByteReader = (firstId, read0) => {
530
  return function() {
531
  let highByte = src[position$1++];
532
  if (highByte === 0)
533
- return read0()
534
  let id = firstId < 32 ? -(firstId + (highByte << 5)) : firstId + (highByte << 5);
535
  let structure = currentStructures[id] || loadStructures()[id];
536
  if (!structure) {
537
- throw new Error('Record id is not defined for ' + id)
538
  }
539
  if (!structure.read)
540
  structure.read = createStructureReader(structure, firstId);
541
- return structure.read()
542
- }
543
  };
544
 
545
  function loadStructures() {
546
  let loadedStructures = saveState(() => {
547
  // save the state in case getStructures modifies our buffer
548
  src = null;
549
- return currentUnpackr.getStructures()
550
  });
551
- return currentStructures = currentUnpackr._mergeStructures(loadedStructures, currentStructures)
552
  }
553
 
554
  var readFixedString = readStringJS;
@@ -560,10 +568,10 @@
560
  let result;
561
  if (length < 16) {
562
  if (result = shortStringInJS(length))
563
- return result
564
  }
565
  if (length > 64 && decoder)
566
- return decoder.decode(src.subarray(position$1, position$1 += length))
567
  const end = position$1 + length;
568
  const units = [];
569
  result = '';
@@ -574,43 +582,49 @@
574
  units.push(byte1);
575
  } else if ((byte1 & 0xe0) === 0xc0) {
576
  // 2 bytes
577
- const byte2 = src[position$1++] & 0x3f;
578
- const codePoint = ((byte1 & 0x1f) << 6) | byte2;
579
- // Reject overlong encoding: 2-byte sequences must encode values >= 0x80
580
- if (codePoint < 0x80) {
581
- units.push(0xFFFD); // replacement character
582
  } else {
583
- units.push(codePoint);
 
584
  }
585
  } else if ((byte1 & 0xf0) === 0xe0) {
586
  // 3 bytes
587
- const byte2 = src[position$1++] & 0x3f;
588
- const byte3 = src[position$1++] & 0x3f;
589
- const codePoint = ((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3;
590
- // Reject overlong encoding: 3-byte sequences must encode values >= 0x800
591
- // Also reject surrogates (0xD800-0xDFFF)
592
- if (codePoint < 0x800 || (codePoint >= 0xD800 && codePoint <= 0xDFFF)) {
593
- units.push(0xFFFD); // replacement character
594
  } else {
595
- units.push(codePoint);
 
 
 
 
 
 
596
  }
597
  } else if ((byte1 & 0xf8) === 0xf0) {
598
  // 4 bytes
599
- const byte2 = src[position$1++] & 0x3f;
600
- const byte3 = src[position$1++] & 0x3f;
601
- const byte4 = src[position$1++] & 0x3f;
602
- let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;
603
- // Reject overlong encoding: 4-byte sequences must encode values >= 0x10000
604
- // Also reject values > 0x10FFFF (maximum valid Unicode)
605
- if (unit < 0x10000 || unit > 0x10FFFF) {
606
- units.push(0xFFFD); // replacement character
607
- } else if (unit > 0xffff) {
608
- unit -= 0x10000;
609
- units.push(((unit >>> 10) & 0x3ff) | 0xd800);
610
- unit = 0xdc00 | (unit & 0x3ff);
611
- units.push(unit);
612
  } else {
613
- units.push(unit);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
614
  }
615
  } else {
616
  units.push(0xFFFD); // replacement character for invalid lead byte
@@ -626,7 +640,7 @@
626
  result += fromCharCode.apply(String, units);
627
  }
628
 
629
- return result
630
  }
631
 
632
  function readArray(length) {
@@ -635,8 +649,8 @@
635
  array[i] = read();
636
  }
637
  if (currentUnpackr.freezeData)
638
- return Object.freeze(array)
639
- return array
640
  }
641
 
642
  function readMap(length) {
@@ -648,13 +662,13 @@
648
  key = '__proto_';
649
  object[key] = read();
650
  }
651
- return object
652
  } else {
653
  let map = new Map();
654
  for (let i = 0; i < length; i++) {
655
  map.set(read(), read());
656
  }
657
- return map
658
  }
659
  }
660
 
@@ -666,40 +680,40 @@
666
  const byte = src[position$1++];
667
  if ((byte & 0x80) > 0) {
668
  position$1 = start;
669
- return
670
  }
671
  bytes[i] = byte;
672
  }
673
- return fromCharCode.apply(String, bytes)
674
  }
675
  function shortStringInJS(length) {
676
  if (length < 4) {
677
  if (length < 2) {
678
  if (length === 0)
679
- return ''
680
  else {
681
  let a = src[position$1++];
682
  if ((a & 0x80) > 1) {
683
  position$1 -= 1;
684
- return
685
  }
686
- return fromCharCode(a)
687
  }
688
  } else {
689
  let a = src[position$1++];
690
  let b = src[position$1++];
691
  if ((a & 0x80) > 0 || (b & 0x80) > 0) {
692
  position$1 -= 2;
693
- return
694
  }
695
  if (length < 3)
696
- return fromCharCode(a, b)
697
  let c = src[position$1++];
698
  if ((c & 0x80) > 0) {
699
  position$1 -= 3;
700
- return
701
  }
702
- return fromCharCode(a, b, c)
703
  }
704
  } else {
705
  let a = src[position$1++];
@@ -708,34 +722,34 @@
708
  let d = src[position$1++];
709
  if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
710
  position$1 -= 4;
711
- return
712
  }
713
  if (length < 6) {
714
  if (length === 4)
715
- return fromCharCode(a, b, c, d)
716
  else {
717
  let e = src[position$1++];
718
  if ((e & 0x80) > 0) {
719
  position$1 -= 5;
720
- return
721
  }
722
- return fromCharCode(a, b, c, d, e)
723
  }
724
  } else if (length < 8) {
725
  let e = src[position$1++];
726
  let f = src[position$1++];
727
  if ((e & 0x80) > 0 || (f & 0x80) > 0) {
728
  position$1 -= 6;
729
- return
730
  }
731
  if (length < 7)
732
- return fromCharCode(a, b, c, d, e, f)
733
  let g = src[position$1++];
734
  if ((g & 0x80) > 0) {
735
  position$1 -= 7;
736
- return
737
  }
738
- return fromCharCode(a, b, c, d, e, f, g)
739
  } else {
740
  let e = src[position$1++];
741
  let f = src[position$1++];
@@ -743,34 +757,34 @@
743
  let h = src[position$1++];
744
  if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
745
  position$1 -= 8;
746
- return
747
  }
748
  if (length < 10) {
749
  if (length === 8)
750
- return fromCharCode(a, b, c, d, e, f, g, h)
751
  else {
752
  let i = src[position$1++];
753
  if ((i & 0x80) > 0) {
754
  position$1 -= 9;
755
- return
756
  }
757
- return fromCharCode(a, b, c, d, e, f, g, h, i)
758
  }
759
  } else if (length < 12) {
760
  let i = src[position$1++];
761
  let j = src[position$1++];
762
  if ((i & 0x80) > 0 || (j & 0x80) > 0) {
763
  position$1 -= 10;
764
- return
765
  }
766
  if (length < 11)
767
- return fromCharCode(a, b, c, d, e, f, g, h, i, j)
768
  let k = src[position$1++];
769
  if ((k & 0x80) > 0) {
770
  position$1 -= 11;
771
- return
772
  }
773
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k)
774
  } else {
775
  let i = src[position$1++];
776
  let j = src[position$1++];
@@ -778,34 +792,34 @@
778
  let l = src[position$1++];
779
  if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
780
  position$1 -= 12;
781
- return
782
  }
783
  if (length < 14) {
784
  if (length === 12)
785
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l)
786
  else {
787
  let m = src[position$1++];
788
  if ((m & 0x80) > 0) {
789
  position$1 -= 13;
790
- return
791
  }
792
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m)
793
  }
794
  } else {
795
  let m = src[position$1++];
796
  let n = src[position$1++];
797
  if ((m & 0x80) > 0 || (n & 0x80) > 0) {
798
  position$1 -= 14;
799
- return
800
  }
801
  if (length < 15)
802
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
803
  let o = src[position$1++];
804
  if ((o & 0x80) > 0) {
805
  position$1 -= 15;
806
- return
807
  }
808
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
809
  }
810
  }
811
  }
@@ -823,22 +837,22 @@
823
  case 0xd9:
824
  // str 8
825
  length = src[position$1++];
826
- break
827
  case 0xda:
828
  // str 16
829
  length = dataView.getUint16(position$1);
830
  position$1 += 2;
831
- break
832
  case 0xdb:
833
  // str 32
834
  length = dataView.getUint32(position$1);
835
  position$1 += 4;
836
- break
837
  default:
838
- throw new Error('Expected string')
839
  }
840
  }
841
- return readStringJS(length)
842
  }
843
 
844
 
@@ -846,7 +860,7 @@
846
  return currentUnpackr.copyBuffers ?
847
  // specifically use the copying slice (not the node one)
848
  Uint8Array.prototype.slice.call(src, position$1, position$1 += length) :
849
- src.subarray(position$1, position$1 += length)
850
  }
851
  function readExt(length) {
852
  let type = src[position$1++];
@@ -859,10 +873,10 @@
859
  } finally {
860
  position$1 = end;
861
  }
862
- })
863
  }
864
  else
865
- throw new Error('Unknown extension type ' + type)
866
  }
867
 
868
  var keyCache = new Array(4096);
@@ -872,12 +886,12 @@
872
  // fixstr, potentially use key cache
873
  length = length - 0xa0;
874
  if (srcStringEnd >= position$1) // if it has been extracted, must use it (and faster anyway)
875
- return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart)
876
  else if (!(srcStringEnd == 0 && srcEnd < 180))
877
- return readFixedString(length)
878
  } else { // not cacheable, go back and do a standard read
879
  position$1--;
880
- return asSafeString(read())
881
  }
882
  let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position$1) : length > 0 ? src[position$1] : 0)) & 0xfff;
883
  let entry = keyCache[key];
@@ -890,7 +904,7 @@
890
  chunk = dataView.getUint32(checkPosition);
891
  if (chunk != entry[i++]) {
892
  checkPosition = 0x70000000;
893
- break
894
  }
895
  checkPosition += 4;
896
  }
@@ -899,12 +913,12 @@
899
  chunk = src[checkPosition++];
900
  if (chunk != entry[i++]) {
901
  checkPosition = 0x70000000;
902
- break
903
  }
904
  }
905
  if (checkPosition === end) {
906
  position$1 = checkPosition;
907
- return entry.string
908
  }
909
  end -= 3;
910
  checkPosition = position$1;
@@ -925,8 +939,8 @@
925
  // for small blocks, avoiding the overhead of the extract call is helpful
926
  let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
927
  if (string != null)
928
- return entry.string = string
929
- return entry.string = readFixedString(length)
930
  }
931
 
932
  function asSafeString(property) {
@@ -957,7 +971,12 @@
957
  }
958
  currentStructures[id] = structure;
959
  structure.read = createStructureReader(structure, firstByte);
960
- return structure.read()
 
 
 
 
 
961
  };
962
  currentExtensions[0] = () => {}; // notepack defines extension 0 to mean undefined, so use that as the default here
963
  currentExtensions[0].noBuffer = true;
@@ -979,17 +998,17 @@
979
  out <<= BigInt(64);
980
  out |= view.getBigUint64(i);
981
  }
982
- return out
983
  }
984
  // if (length === 8) return view.getBigUint64(start)
985
  let middle = start + (length >> 4 << 3);
986
  let left = decode(start, middle);
987
  let right = decode(middle, end);
988
- return (left << BigInt((end - middle) * 8)) | right
989
  };
990
  head = (head << BigInt((view.byteLength - headLength) * 8)) | decode(headLength, view.byteLength);
991
  }
992
- return head
993
  };
994
 
995
  let errors = {
@@ -1000,14 +1019,14 @@
1000
  if (!errors[data[0]]) {
1001
  let error = Error(data[1], { cause: data[2] });
1002
  error.name = data[0];
1003
- return error
1004
  }
1005
- return errors[data[0]](data[1], { cause: data[2] })
1006
  };
1007
 
1008
  currentExtensions[0x69] = (data) => {
1009
  // id extension (for structured clones)
1010
- if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled')
1011
  let id = dataView.getUint32(position$1 - 4);
1012
  if (!referenceMap)
1013
  referenceMap = new Map();
@@ -1028,7 +1047,7 @@
1028
  let targetProperties = read(); // read the next value as the target object to id
1029
  if (!refEntry.used) {
1030
  // no cycle, can just use the returned read object
1031
- return refEntry.target = targetProperties // replace the placeholder with the real one
1032
  } else {
1033
  // there is a cycle, so we have to assign properties to original target
1034
  Object.assign(target, targetProperties);
@@ -1039,16 +1058,16 @@
1039
  for (let [k, v] of targetProperties.entries()) target.set(k, v);
1040
  if (target instanceof Set)
1041
  for (let i of Array.from(targetProperties)) target.add(i);
1042
- return target
1043
  };
1044
 
1045
  currentExtensions[0x70] = (data) => {
1046
  // pointer extension (for structured clones)
1047
- if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled')
1048
  let id = dataView.getUint32(position$1 - 4);
1049
  let refEntry = referenceMap.get(id);
1050
  refEntry.used = true;
1051
- return refEntry.target
1052
  };
1053
 
1054
  currentExtensions[0x73] = () => new Set(read());
@@ -1063,15 +1082,15 @@
1063
 
1064
  let typedArrayName = typedArrays[typeCode];
1065
  if (!typedArrayName) {
1066
- if (typeCode === 16) return buffer
1067
- if (typeCode === 17) return new DataView(buffer)
1068
- throw new Error('Could not find typed array for code ' + typeCode)
1069
  }
1070
- return new glbl[typedArrayName](buffer)
1071
  };
1072
  currentExtensions[0x78] = () => {
1073
  let data = read();
1074
- return new RegExp(data[0], data[1])
1075
  };
1076
  const TEMP_BUNDLE = [];
1077
  currentExtensions[0x62] = (data) => {
@@ -1084,28 +1103,30 @@
1084
  bundledStrings$1.position1 = 0;
1085
  bundledStrings$1.postBundlePosition = position$1;
1086
  position$1 = dataPosition;
1087
- return read()
1088
  };
1089
 
1090
  currentExtensions[0xff] = (data) => {
1091
  // 32-bit date extension
1092
  if (data.length == 4)
1093
- return new Date((data[0] * 0x1000000 + (data[1] << 16) + (data[2] << 8) + data[3]) * 1000)
1094
  else if (data.length == 8)
1095
  return new Date(
1096
  ((data[0] << 22) + (data[1] << 14) + (data[2] << 6) + (data[3] >> 2)) / 1000000 +
1097
- ((data[3] & 0x3) * 0x100000000 + data[4] * 0x1000000 + (data[5] << 16) + (data[6] << 8) + data[7]) * 1000)
1098
  else if (data.length == 12)
1099
  return new Date(
1100
  ((data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]) / 1000000 +
1101
- (((data[4] & 0x80) ? -0x1000000000000 : 0) + data[6] * 0x10000000000 + data[7] * 0x100000000 + data[8] * 0x1000000 + (data[9] << 16) + (data[10] << 8) + data[11]) * 1000)
1102
  else
1103
- return new Date('invalid')
1104
  };
1105
  // registration of bulk record definition?
1106
  // currentExtensions[0x52] = () =>
1107
 
1108
  function saveState(callback) {
 
 
1109
  let savedSrcEnd = srcEnd;
1110
  let savedPosition = position$1;
1111
  let savedSrcStringStart = srcStringStart;
@@ -1134,7 +1155,7 @@
1134
  currentStructures.splice(0, currentStructures.length, ...savedStructuresContents);
1135
  currentUnpackr = savedPackr;
1136
  dataView = new DataView(src.buffer, src.byteOffset, src.byteLength);
1137
- return value
1138
  }
1139
  function clearSource() {
1140
  src = null;
@@ -1169,8 +1190,12 @@
1169
  function roundFloat32(float32Number) {
1170
  f32Array[0] = float32Number;
1171
  let multiplier = mult10[((u8Array[3] & 0x7f) << 1) | (u8Array[2] >> 7)];
1172
- return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier
1173
  }
 
 
 
 
1174
 
1175
  let textEncoder;
1176
  try {
@@ -1179,7 +1204,7 @@
1179
  let extensions, extensionClasses;
1180
  const hasNodeBuffer = typeof Buffer !== 'undefined';
1181
  const ByteArrayAllocate = hasNodeBuffer ?
1182
- function(length) { return Buffer.allocUnsafeSlow(length) } : Uint8Array;
1183
  const ByteArray = hasNodeBuffer ? Buffer : Uint8Array;
1184
  const MAX_BUFFER_SIZE = hasNodeBuffer ? 0x100000000 : 0x7fd00000;
1185
  let target, keysTarget;
@@ -1187,7 +1212,6 @@
1187
  let position = 0;
1188
  let safeEnd;
1189
  let bundledStrings = null;
1190
- let writeStructSlots;
1191
  const MAX_BUNDLE_SIZE = 0x5500; // maximum characters such that the encoded bytes fits in 16 bits.
1192
  const hasNonLatin = /[\u0080-\uFFFF]/;
1193
  const RECORD_SYMBOL = Symbol('record-id');
@@ -1200,10 +1224,10 @@
1200
  let structures;
1201
  let referenceMap;
1202
  let encodeUtf8 = ByteArray.prototype.utf8Write ? function(string, position) {
1203
- return target.utf8Write(string, position, target.byteLength - position)
1204
  } : (textEncoder && textEncoder.encodeInto) ?
1205
  function(string, position) {
1206
- return textEncoder.encodeInto(string, target.subarray(position)).written
1207
  } : false;
1208
 
1209
  let packr = this;
@@ -1215,7 +1239,7 @@
1215
  if (maxSharedStructures == null)
1216
  maxSharedStructures = hasSharedStructures ? 32 : 0;
1217
  if (maxSharedStructures > 8160)
1218
- throw new Error('Maximum maxSharedStructure is 8160')
1219
  if (options.structuredClone && options.moreTypes == undefined) {
1220
  this.moreTypes = true;
1221
  }
@@ -1229,7 +1253,7 @@
1229
  let sharedLimitId = maxSharedStructures + 0x40;
1230
  let maxStructureId = maxSharedStructures + maxOwnStructures + 0x40;
1231
  if (maxStructureId > 8256) {
1232
- throw new Error('Maximum maxSharedStructure + maxOwnStructure is 8192')
1233
  }
1234
  let recordIdsToRemove = [];
1235
  let transitionsCount = 0;
@@ -1265,7 +1289,7 @@
1265
  let sharedLength = structures.sharedLength || 0;
1266
  if (sharedLength > maxSharedStructures) {
1267
  //if (maxSharedStructures <= 32 && structures.sharedLength > 32) // TODO: could support this, but would need to update the limit ids
1268
- throw new Error('Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to ' + structures.sharedLength)
1269
  }
1270
  if (!structures.transitions) {
1271
  // rebuild our structure transitions
@@ -1273,7 +1297,7 @@
1273
  for (let i = 0; i < sharedLength; i++) {
1274
  let keys = structures[i];
1275
  if (!keys)
1276
- continue
1277
  let nextTransition, transition = structures.transitions;
1278
  for (let j = 0, l = keys.length; j < l; j++) {
1279
  let key = keys[j];
@@ -1295,7 +1319,7 @@
1295
  hasSharedUpdate = false;
1296
  let encodingError;
1297
  try {
1298
- if (packr.randomAccessStructure && value && typeof value === 'object') {
1299
  if (value.constructor === Object) writeStruct(value); // simple object
1300
  else if (value.constructor !== Map && !Array.isArray(value) && !extensionClasses.some(extClass => value instanceof extClass)) {
1301
  // allow user classes, if they don't need special handling (but do use toJSON if available)
@@ -1339,15 +1363,15 @@
1339
  packr.offset = position;
1340
  let serialized = insertIds(target.subarray(start, position), idsToInsert);
1341
  referenceMap = null;
1342
- return serialized
1343
  }
1344
  packr.offset = position; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
1345
  if (encodeOptions & REUSE_BUFFER_MODE) {
1346
  target.start = start;
1347
  target.end = position;
1348
- return target
1349
  }
1350
- return target.subarray(start, position) // position can change if we call pack again in saveStructures, so we get the buffer now
1351
  } catch(error) {
1352
  encodingError = error;
1353
  throw error;
@@ -1358,16 +1382,23 @@
1358
  let sharedLength = structures.sharedLength || 0;
1359
  // we can't rely on start/end with REUSE_BUFFER_MODE since they will (probably) change when we save
1360
  let returnBuffer = target.subarray(start, position);
1361
- let newSharedData = prepareStructures(structures, packr);
1362
  if (!encodingError) { // TODO: If there is an encoding error, should make the structures as uninitialized so they get rebuilt next time
1363
  if (packr.saveStructures(newSharedData, newSharedData.isCompatible) === false) {
1364
- // get updated structures and try again if the update failed
1365
- return packr.pack(value, encodeOptions)
 
 
 
 
 
 
 
1366
  }
1367
  packr.lastNamedStructuresLength = sharedLength;
1368
  // don't keep large buffers around
1369
  if (target.length > 0x40000000) target = null;
1370
- return returnBuffer
1371
  }
1372
  }
1373
  }
@@ -1453,7 +1484,7 @@
1453
  bundledStrings[twoByte ? 0 : 1] += value;
1454
  target[position++] = 0xc1;
1455
  pack(twoByte ? -strLength : strLength);
1456
- return
1457
  }
1458
  let headerSize;
1459
  // first we estimate the header size, so we can write to the correct location
@@ -1527,7 +1558,7 @@
1527
  } else if (type === 'number') {
1528
  if (value >>> 0 === value) {// positive integer, 32-bit or less
1529
  // positive uint
1530
- if (value < 0x20 || (value < 0x80 && this.useRecords === false) || (value < 0x40 && !this.randomAccessStructure)) {
1531
  target[position++] = value;
1532
  } else if (value < 0x100) {
1533
  target[position++] = 0xcc;
@@ -1566,7 +1597,7 @@
1566
  // this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
1567
  ((xShifted = value * mult10[((target[position] & 0x7f) << 1) | (target[position + 1] >> 7)]) >> 0) === xShifted) {
1568
  position += 4;
1569
- return
1570
  } else
1571
  position--; // move back into position for writing a double
1572
  }
@@ -1589,7 +1620,7 @@
1589
  target[position++] = 0x70; // "p" for pointer
1590
  targetView.setUint32(position, referee.id);
1591
  position += 4;
1592
- return
1593
  } else
1594
  referenceMap.set(value, { offset: position - start });
1595
  }
@@ -1639,7 +1670,7 @@
1639
  } else {
1640
  pack(writeResult);
1641
  }
1642
- return
1643
  }
1644
  let currentTarget = target;
1645
  let currentTargetView = targetView;
@@ -1656,7 +1687,7 @@
1656
  makeRoom(position);
1657
  return {
1658
  target, targetView, position: position - size
1659
- }
1660
  }, pack);
1661
  } finally {
1662
  // restore current target information (unless already restored)
@@ -1672,7 +1703,7 @@
1672
  makeRoom(result.length + position);
1673
  position = writeExtensionData(result, target, position, extension.type);
1674
  }
1675
- return
1676
  }
1677
  }
1678
  // check isArray after extensions, because extensions can extend Array
@@ -1684,7 +1715,7 @@
1684
  const json = value.toJSON();
1685
  // if for some reason value.toJSON returns itself it'll loop forever
1686
  if (json !== value)
1687
- return pack(json)
1688
  }
1689
 
1690
  // if there is a writeFunction, use it, otherwise just encode as undefined
@@ -1723,7 +1754,7 @@
1723
  let chunks = [];
1724
  while (true) {
1725
  chunks.push(value & mask);
1726
- if ((value >> BigInt(63)) === empty) break
1727
  value >>= BigInt(64);
1728
  }
1729
 
@@ -1755,11 +1786,11 @@
1755
  if (array.length + position > safeEnd)
1756
  makeRoom(array.length + position);
1757
  position = writeExtensionData(array, target, position, 0x42);
1758
- return
1759
  } else {
1760
  throw new RangeError(value + ' was too large to fit in MessagePack 64-bit integer format, use' +
1761
  ' useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set' +
1762
- ' largeBigIntToString to convert to string')
1763
  }
1764
  }
1765
  position += 8;
@@ -1772,7 +1803,7 @@
1772
  target[position++] = 0;
1773
  }
1774
  } else {
1775
- throw new Error('Unknown type: ' + type)
1776
  }
1777
  };
1778
 
@@ -1918,12 +1949,30 @@
1918
  checkUseRecords(object) ? writeRecord(object) : writePlainObject(object);
1919
  } : writeRecord;
1920
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1921
  const makeRoom = (end) => {
1922
  let newSize;
1923
  if (end > 0x1000000) {
1924
  // special handling for really large buffers
1925
  if ((end - start) > MAX_BUFFER_SIZE)
1926
- throw new Error('Packed buffer would be larger than maximum buffer size')
1927
  newSize = Math.min(MAX_BUFFER_SIZE,
1928
  Math.round(Math.max((end - start) * (end > 0x4000000 ? 1.25 : 2), 0x400000) / 0x1000) * 0x1000);
1929
  } else // faster handling for smaller buffers
@@ -1938,7 +1987,7 @@
1938
  position -= start;
1939
  start = 0;
1940
  safeEnd = newBuffer.length - 10;
1941
- return target = newBuffer
1942
  };
1943
  const newRecord = (transition, keys, newTransitions) => {
1944
  let recordId = structures.nextId;
@@ -2020,23 +2069,6 @@
2020
  target[insertionOffset + start] = keysTarget[0];
2021
  }
2022
  };
2023
- const writeStruct = (object) => {
2024
- let newPosition = writeStructSlots(object, target, start, position, structures, makeRoom, (value, newPosition, notifySharedUpdate) => {
2025
- if (notifySharedUpdate)
2026
- return hasSharedUpdate = true;
2027
- position = newPosition;
2028
- let startTarget = target;
2029
- pack(value);
2030
- resetStructures();
2031
- if (startTarget !== target) {
2032
- return { position, targetView, target }; // indicate the buffer was re-allocated
2033
- }
2034
- return position;
2035
- }, this);
2036
- if (newPosition === 0) // bail and go to a msgpack object
2037
- return writeObject(object);
2038
- position = newPosition;
2039
- };
2040
  }
2041
  useBuffer(buffer) {
2042
  // this means we are finished using our own buffer and we can write over it safely
@@ -2079,7 +2111,7 @@
2079
  } else if (isNaN(seconds)) {
2080
  if (this.onInvalidDate) {
2081
  allocateForWrite(0);
2082
- return pack(this.onInvalidDate())
2083
  }
2084
  // Intentionally invalid timestamp
2085
  let { target, targetView, position} = allocateForWrite(3);
@@ -2100,7 +2132,7 @@
2100
  pack(set, allocateForWrite, pack) {
2101
  if (this.setAsEmptyObject) {
2102
  allocateForWrite(0);
2103
- return pack({})
2104
  }
2105
  let array = Array.from(set);
2106
  let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
@@ -2208,19 +2240,19 @@
2208
  switch (length) {
2209
  case 1:
2210
  target[position++] = 0xd4;
2211
- break
2212
  case 2:
2213
  target[position++] = 0xd5;
2214
- break
2215
  case 4:
2216
  target[position++] = 0xd6;
2217
- break
2218
  case 8:
2219
  target[position++] = 0xd7;
2220
- break
2221
  case 16:
2222
  target[position++] = 0xd8;
2223
- break
2224
  default:
2225
  if (length < 0x100) {
2226
  target[position++] = 0xc7;
@@ -2240,7 +2272,7 @@
2240
  target[position++] = type;
2241
  target.set(result, position);
2242
  position += length;
2243
- return position
2244
  }
2245
 
2246
  function insertIds(serialized, idsToInsert) {
@@ -2262,7 +2294,7 @@
2262
  serialized[position++] = id & 0xff;
2263
  lastEnd = offset;
2264
  }
2265
- return serialized
2266
  }
2267
 
2268
  function writeBundles(start, pack, incrementPosition) {
@@ -2279,9 +2311,9 @@
2279
  function addExtension(extension) {
2280
  if (extension.Class) {
2281
  if (!extension.pack && !extension.write)
2282
- throw new Error('Extension has no pack or write function')
2283
  if (extension.pack && !extension.type)
2284
- throw new Error('Extension has no type (numeric code to identify the extension)')
2285
  extensionClasses.unshift(extension.Class);
2286
  extensions.unshift(extension);
2287
  }
@@ -2294,9 +2326,14 @@
2294
  packr._mergeStructures(existingStructures);
2295
  return compatible;
2296
  };
2297
- return structures
2298
  }
2299
 
 
 
 
 
 
2300
  let defaultPackr = new Packr({ useRecords: false });
2301
  const pack = defaultPackr.pack;
2302
  const encode = defaultPackr.pack;
@@ -2315,13 +2352,13 @@
2315
  */
2316
  function packIter (objectIterator, options = {}) {
2317
  if (!objectIterator || typeof objectIterator !== 'object') {
2318
- throw new Error('first argument must be an Iterable, Async Iterable, or a Promise for an Async Iterable')
2319
  } else if (typeof objectIterator[Symbol.iterator] === 'function') {
2320
- return packIterSync(objectIterator, options)
2321
  } else if (typeof objectIterator.then === 'function' || typeof objectIterator[Symbol.asyncIterator] === 'function') {
2322
- return packIterAsync(objectIterator, options)
2323
  } else {
2324
- throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a Promise')
2325
  }
2326
  }
2327
 
@@ -2348,7 +2385,7 @@
2348
  */
2349
  function unpackIter (bufferIterator, options = {}) {
2350
  if (!bufferIterator || typeof bufferIterator !== 'object') {
2351
- throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a promise')
2352
  }
2353
 
2354
  const unpackr = new Unpackr(options);
@@ -2368,10 +2405,10 @@
2368
  incomplete = chunk.slice(err.lastPosition);
2369
  yields = err.values;
2370
  } else {
2371
- throw err
2372
  }
2373
  }
2374
- return yields
2375
  };
2376
 
2377
  if (typeof bufferIterator[Symbol.iterator] === 'function') {
@@ -2379,13 +2416,13 @@
2379
  for (const value of bufferIterator) {
2380
  yield * parser(value);
2381
  }
2382
- })()
2383
  } else if (typeof bufferIterator[Symbol.asyncIterator] === 'function') {
2384
  return (async function * iter () {
2385
  for await (const value of bufferIterator) {
2386
  yield * parser(value);
2387
  }
2388
- })()
2389
  }
2390
  }
2391
  const decodeIter = unpackIter;
 
29
  C1.name = 'MessagePack 0xC1';
30
  var sequentialMode = false;
31
  var inlineObjectReadThreshold = 2;
 
32
 
33
  class Unpackr {
34
  constructor(options) {
 
60
  // re-entrant execution, save the state and restore it after we do this unpack
61
  return saveState(() => {
62
  clearSource();
63
+ return this ? this.unpack(source, options) : Unpackr.prototype.unpack.call(defaultOptions, source, options);
64
+ });
65
  }
66
  if (!source.buffer && source.constructor === ArrayBuffer)
67
  source = typeof Buffer !== 'undefined' ? Buffer.from(source) : new Uint8Array(source);
 
85
  // if it doesn't have a buffer, maybe it is the wrong type of object
86
  src = null;
87
  if (source instanceof Uint8Array)
88
+ throw error;
89
+ throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source));
90
  }
91
  if (this instanceof Unpackr) {
92
  currentUnpackr = this;
93
  if (this.structures) {
94
  currentStructures = this.structures;
95
+ return checkedRead(options);
96
  } else if (!currentStructures || currentStructures.length > 0) {
97
  currentStructures = [];
98
  }
 
101
  if (!currentStructures || currentStructures.length > 0)
102
  currentStructures = [];
103
  }
104
+ return checkedRead(options);
105
  }
106
  unpackMultiple(source, forEach) {
107
  let values, lastPosition = 0;
 
114
  while(position$1 < size) {
115
  lastPosition = position$1;
116
  if (forEach(checkedRead(), lastPosition, position$1) === false) {
117
+ return;
118
  }
119
  }
120
  }
 
124
  lastPosition = position$1;
125
  values.push(checkedRead());
126
  }
127
+ return values;
128
  }
129
  } catch(error) {
130
  error.lastPosition = lastPosition;
131
  error.values = values;
132
+ throw error;
133
  } finally {
134
  sequentialMode = false;
135
  clearSource();
136
  }
137
  }
138
  _mergeStructures(loadedStructures, existingStructures) {
139
+ if (this._onLoadedStructures)
140
+ loadedStructures = this._onLoadedStructures(loadedStructures);
141
  loadedStructures = loadedStructures || [];
142
  if (Object.isFrozen(loadedStructures))
143
  loadedStructures = loadedStructures.map(structure => structure.slice(0));
 
161
  }
162
  }
163
  }
164
+ return this.structures = loadedStructures;
165
  }
166
  decode(source, options) {
167
+ return this.unpack(source, options);
168
  }
169
  }
170
  function checkedRead(options) {
 
175
  currentStructures.length = sharedLength;
176
  }
177
  let result;
178
+ if (currentUnpackr._readStruct && src[position$1] < 0x40 && src[position$1] >= 0x20) {
179
+ result = currentUnpackr._readStruct(src, position$1, srcEnd);
180
  src = null; // dispose of this so that recursive unpack calls don't save state
181
  if (!(options && options.lazy) && result)
182
  result = result.toJSON();
 
202
  referenceMap = null;
203
  } else if (position$1 > srcEnd) {
204
  // over read
205
+ throw new Error('Unexpected end of MessagePack data');
206
  } else if (!sequentialMode) {
207
  let jsonView;
208
  try {
 
210
  } catch(error) {
211
  jsonView = '(JSON view not available ' + error + ')';
212
  }
213
+ throw new Error('Data read, but end of buffer not reached ' + jsonView);
214
  }
215
  // else more to read, but we are reading sequentially, so don't clear source yet
216
+ return result;
217
  } catch(error) {
218
  if (currentStructures && currentStructures.restoreStructures)
219
  restoreStructures();
 
221
  if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position$1 > srcEnd) {
222
  error.incomplete = true;
223
  }
224
+ throw error;
225
  }
226
  }
227
 
 
237
  if (token < 0xa0) {
238
  if (token < 0x80) {
239
  if (token < 0x40)
240
+ return token;
241
  else {
242
  let structure = currentStructures[token & 0x3f] ||
243
  currentUnpackr.getStructures && loadStructures()[token & 0x3f];
 
245
  if (!structure.read) {
246
  structure.read = createStructureReader(structure, token & 0x3f);
247
  }
248
+ return structure.read();
249
  } else
250
+ return token;
251
  }
252
  } else if (token < 0x90) {
253
  // map
 
260
  key = '__proto_';
261
  object[key] = read();
262
  }
263
+ return object;
264
  } else {
265
  let map = new Map();
266
  for (let i = 0; i < token; i++) {
267
  map.set(read(), read());
268
  }
269
+ return map;
270
  }
271
  } else {
272
  token -= 0x90;
 
275
  array[i] = read();
276
  }
277
  if (currentUnpackr.freezeData)
278
+ return Object.freeze(array);
279
+ return array;
280
  }
281
  } else if (token < 0xc0) {
282
  // fixstr
283
  let length = token - 0xa0;
284
  if (srcStringEnd >= position$1) {
285
+ return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart);
286
  }
287
  if (srcStringEnd == 0 && srcEnd < 140) {
288
  // for small blocks, avoiding the overhead of the extract call is helpful
289
  let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
290
  if (string != null)
291
+ return string;
292
  }
293
+ return readFixedString(length);
294
  } else {
295
  let value;
296
  switch (token) {
297
+ case 0xc0: return null;
298
  case 0xc1:
299
  if (bundledStrings$1) {
300
  value = read(); // followed by the length of the string in characters (not bytes!)
301
  if (value > 0)
302
+ return bundledStrings$1[1].slice(bundledStrings$1.position1, bundledStrings$1.position1 += value);
303
  else
304
+ return bundledStrings$1[0].slice(bundledStrings$1.position0, bundledStrings$1.position0 -= value);
305
  }
306
  return C1; // "never-used", return special object to denote that
307
+ case 0xc2: return false;
308
+ case 0xc3: return true;
309
  case 0xc4:
310
  // bin 8
311
  value = src[position$1++];
312
  if (value === undefined)
313
+ throw new Error('Unexpected end of buffer');
314
+ return readBin(value);
315
  case 0xc5:
316
  // bin 16
317
  value = dataView.getUint16(position$1);
318
  position$1 += 2;
319
+ return readBin(value);
320
  case 0xc6:
321
  // bin 32
322
  value = dataView.getUint32(position$1);
323
  position$1 += 4;
324
+ return readBin(value);
325
  case 0xc7:
326
  // ext 8
327
+ return readExt(src[position$1++]);
328
  case 0xc8:
329
  // ext 16
330
  value = dataView.getUint16(position$1);
331
  position$1 += 2;
332
+ return readExt(value);
333
  case 0xc9:
334
  // ext 32
335
  value = dataView.getUint32(position$1);
336
  position$1 += 4;
337
+ return readExt(value);
338
  case 0xca:
339
  value = dataView.getFloat32(position$1);
340
  if (currentUnpackr.useFloat32 > 2) {
341
  // this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
342
  let multiplier = mult10[((src[position$1] & 0x7f) << 1) | (src[position$1 + 1] >> 7)];
343
  position$1 += 4;
344
+ return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier;
345
  }
346
  position$1 += 4;
347
+ return value;
348
  case 0xcb:
349
  value = dataView.getFloat64(position$1);
350
  position$1 += 8;
351
+ return value;
352
  // uint handlers
353
  case 0xcc:
354
+ return src[position$1++];
355
  case 0xcd:
356
  value = dataView.getUint16(position$1);
357
  position$1 += 2;
358
+ return value;
359
  case 0xce:
360
  value = dataView.getUint32(position$1);
361
  position$1 += 4;
362
+ return value;
363
  case 0xcf:
364
  if (currentUnpackr.int64AsType === 'number') {
365
  value = dataView.getUint32(position$1) * 0x100000000;
 
372
  } else
373
  value = dataView.getBigUint64(position$1);
374
  position$1 += 8;
375
+ return value;
376
 
377
  // int handlers
378
  case 0xd0:
379
+ return dataView.getInt8(position$1++);
380
  case 0xd1:
381
  value = dataView.getInt16(position$1);
382
  position$1 += 2;
383
+ return value;
384
  case 0xd2:
385
  value = dataView.getInt32(position$1);
386
  position$1 += 4;
387
+ return value;
388
  case 0xd3:
389
  if (currentUnpackr.int64AsType === 'number') {
390
  value = dataView.getInt32(position$1) * 0x100000000;
 
397
  } else
398
  value = dataView.getBigInt64(position$1);
399
  position$1 += 8;
400
+ return value;
401
 
402
  case 0xd4:
403
  // fixext 1
404
  value = src[position$1++];
405
  if (value == 0x72) {
406
+ return recordDefinition(src[position$1++] & 0x3f);
407
  } else {
408
  let extension = currentExtensions[value];
409
  if (extension) {
410
  if (extension.read) {
411
  position$1++; // skip filler byte
412
+ return extension.read(read());
413
  } else if (extension.noBuffer) {
414
  position$1++; // skip filler byte
415
+ return extension();
416
  } else
417
+ return extension(src.subarray(position$1, ++position$1));
418
  } else
419
+ throw new Error('Unknown extension ' + value);
420
  }
421
  case 0xd5:
422
  // fixext 2
423
  value = src[position$1];
424
  if (value == 0x72) {
425
  position$1++;
426
+ return recordDefinition(src[position$1++] & 0x3f, src[position$1++]);
427
  } else
428
+ return readExt(2);
429
  case 0xd6:
430
  // fixext 4
431
+ return readExt(4);
432
  case 0xd7:
433
  // fixext 8
434
+ return readExt(8);
435
  case 0xd8:
436
  // fixext 16
437
+ return readExt(16);
438
  case 0xd9:
439
  // str 8
440
  value = src[position$1++];
441
  if (srcStringEnd >= position$1) {
442
+ return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart);
443
  }
444
+ return readString8(value);
445
  case 0xda:
446
  // str 16
447
  value = dataView.getUint16(position$1);
448
  position$1 += 2;
449
  if (srcStringEnd >= position$1) {
450
+ return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart);
451
  }
452
+ return readString16(value);
453
  case 0xdb:
454
  // str 32
455
  value = dataView.getUint32(position$1);
456
  position$1 += 4;
457
  if (srcStringEnd >= position$1) {
458
+ return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart);
459
  }
460
+ return readString32(value);
461
  case 0xdc:
462
  // array 16
463
  value = dataView.getUint16(position$1);
464
  position$1 += 2;
465
+ return readArray(value);
466
  case 0xdd:
467
  // array 32
468
  value = dataView.getUint32(position$1);
469
  position$1 += 4;
470
+ return readArray(value);
471
  case 0xde:
472
  // map 16
473
  value = dataView.getUint16(position$1);
474
  position$1 += 2;
475
+ return readMap(value);
476
  case 0xdf:
477
  // map 32
478
  value = dataView.getUint32(position$1);
479
  position$1 += 4;
480
+ return readMap(value);
481
  default: // negative int
482
  if (token >= 0xe0)
483
+ return token - 0x100;
484
  if (token === undefined) {
485
  let error = new Error('Unexpected end of MessagePack data');
486
  error.incomplete = true;
487
+ throw error;
488
  }
489
+ throw new Error('Unknown MessagePack token ' + token);
490
 
491
  }
492
  }
 
505
  inlineObjectReadThreshold = Infinity; // disable going forward
506
  return readObject(); // recursively try again
507
  }
508
+ structure.read0 = optimizedReadObject; // keep the un-wrapped body reader in sync
509
  if (structure.highByte === 0)
510
  structure.read = createSecondByteReader(firstId, structure.read);
511
+ return optimizedReadObject(); // second byte is already read, if there is one so immediately read object
512
  }
513
  let object = {};
514
  for (let i = 0, l = structure.length; i < l; i++) {
 
519
  }
520
  if (currentUnpackr.freezeData)
521
  return Object.freeze(object);
522
+ return object;
523
  }
524
  readObject.count = 0;
525
+ // read0 is the un-wrapped body reader: it reads the record's values directly without
526
+ // consuming a leading high byte. recordDefinition uses it for the immediate read that follows
527
+ // a record definition (the high byte, if present, was already consumed). For highByte === 0
528
+ // structures the public reader is a second-byte reader (used by later references), but the
529
+ // definition read itself must not consume that byte.
530
+ structure.read0 = readObject;
531
  if (structure.highByte === 0) {
532
+ return createSecondByteReader(firstId, readObject);
533
  }
534
+ return readObject;
535
  }
536
 
537
  const createSecondByteReader = (firstId, read0) => {
538
  return function() {
539
  let highByte = src[position$1++];
540
  if (highByte === 0)
541
+ return read0();
542
  let id = firstId < 32 ? -(firstId + (highByte << 5)) : firstId + (highByte << 5);
543
  let structure = currentStructures[id] || loadStructures()[id];
544
  if (!structure) {
545
+ throw new Error('Record id is not defined for ' + id);
546
  }
547
  if (!structure.read)
548
  structure.read = createStructureReader(structure, firstId);
549
+ return structure.read();
550
+ };
551
  };
552
 
553
  function loadStructures() {
554
  let loadedStructures = saveState(() => {
555
  // save the state in case getStructures modifies our buffer
556
  src = null;
557
+ return currentUnpackr.getStructures();
558
  });
559
+ return currentStructures = currentUnpackr._mergeStructures(loadedStructures, currentStructures);
560
  }
561
 
562
  var readFixedString = readStringJS;
 
568
  let result;
569
  if (length < 16) {
570
  if (result = shortStringInJS(length))
571
+ return result;
572
  }
573
  if (length > 64 && decoder)
574
+ return decoder.decode(src.subarray(position$1, position$1 += length));
575
  const end = position$1 + length;
576
  const units = [];
577
  result = '';
 
582
  units.push(byte1);
583
  } else if ((byte1 & 0xe0) === 0xc0) {
584
  // 2 bytes
585
+ if (byte1 < 0xc2 || position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
586
+ units.push(0xFFFD);
 
 
 
587
  } else {
588
+ const byte2 = src[position$1++] & 0x3f;
589
+ units.push(((byte1 & 0x1f) << 6) | byte2);
590
  }
591
  } else if ((byte1 & 0xf0) === 0xe0) {
592
  // 3 bytes
593
+ const byte2 = position$1 < end ? src[position$1] : 0;
594
+ if (position$1 >= end || (byte2 & 0xc0) !== 0x80 ||
595
+ (byte1 === 0xe0 && byte2 < 0xa0) || (byte1 === 0xed && byte2 >= 0xa0)) {
596
+ units.push(0xFFFD);
 
 
 
597
  } else {
598
+ position$1++;
599
+ if (position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
600
+ units.push(0xFFFD);
601
+ } else {
602
+ const byte3 = src[position$1++] & 0x3f;
603
+ units.push(((byte1 & 0x1f) << 12) | ((byte2 & 0x3f) << 6) | byte3);
604
+ }
605
  }
606
  } else if ((byte1 & 0xf8) === 0xf0) {
607
  // 4 bytes
608
+ const byte2 = position$1 < end ? src[position$1] : 0;
609
+ if (byte1 > 0xf4 || position$1 >= end || (byte2 & 0xc0) !== 0x80 ||
610
+ (byte1 === 0xf0 && byte2 < 0x90) || (byte1 === 0xf4 && byte2 >= 0x90)) {
611
+ units.push(0xFFFD);
 
 
 
 
 
 
 
 
 
612
  } else {
613
+ position$1++;
614
+ if (position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
615
+ units.push(0xFFFD);
616
+ } else {
617
+ const byte3 = src[position$1++] & 0x3f;
618
+ if (position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
619
+ units.push(0xFFFD);
620
+ } else {
621
+ const byte4 = src[position$1++] & 0x3f;
622
+ let unit = ((byte1 & 0x07) << 0x12) | ((byte2 & 0x3f) << 0x0c) | (byte3 << 0x06) | byte4;
623
+ unit -= 0x10000;
624
+ units.push(((unit >>> 10) & 0x3ff) | 0xd800);
625
+ units.push(0xdc00 | (unit & 0x3ff));
626
+ }
627
+ }
628
  }
629
  } else {
630
  units.push(0xFFFD); // replacement character for invalid lead byte
 
640
  result += fromCharCode.apply(String, units);
641
  }
642
 
643
+ return result;
644
  }
645
 
646
  function readArray(length) {
 
649
  array[i] = read();
650
  }
651
  if (currentUnpackr.freezeData)
652
+ return Object.freeze(array);
653
+ return array;
654
  }
655
 
656
  function readMap(length) {
 
662
  key = '__proto_';
663
  object[key] = read();
664
  }
665
+ return object;
666
  } else {
667
  let map = new Map();
668
  for (let i = 0; i < length; i++) {
669
  map.set(read(), read());
670
  }
671
+ return map;
672
  }
673
  }
674
 
 
680
  const byte = src[position$1++];
681
  if ((byte & 0x80) > 0) {
682
  position$1 = start;
683
+ return;
684
  }
685
  bytes[i] = byte;
686
  }
687
+ return fromCharCode.apply(String, bytes);
688
  }
689
  function shortStringInJS(length) {
690
  if (length < 4) {
691
  if (length < 2) {
692
  if (length === 0)
693
+ return '';
694
  else {
695
  let a = src[position$1++];
696
  if ((a & 0x80) > 1) {
697
  position$1 -= 1;
698
+ return;
699
  }
700
+ return fromCharCode(a);
701
  }
702
  } else {
703
  let a = src[position$1++];
704
  let b = src[position$1++];
705
  if ((a & 0x80) > 0 || (b & 0x80) > 0) {
706
  position$1 -= 2;
707
+ return;
708
  }
709
  if (length < 3)
710
+ return fromCharCode(a, b);
711
  let c = src[position$1++];
712
  if ((c & 0x80) > 0) {
713
  position$1 -= 3;
714
+ return;
715
  }
716
+ return fromCharCode(a, b, c);
717
  }
718
  } else {
719
  let a = src[position$1++];
 
722
  let d = src[position$1++];
723
  if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
724
  position$1 -= 4;
725
+ return;
726
  }
727
  if (length < 6) {
728
  if (length === 4)
729
+ return fromCharCode(a, b, c, d);
730
  else {
731
  let e = src[position$1++];
732
  if ((e & 0x80) > 0) {
733
  position$1 -= 5;
734
+ return;
735
  }
736
+ return fromCharCode(a, b, c, d, e);
737
  }
738
  } else if (length < 8) {
739
  let e = src[position$1++];
740
  let f = src[position$1++];
741
  if ((e & 0x80) > 0 || (f & 0x80) > 0) {
742
  position$1 -= 6;
743
+ return;
744
  }
745
  if (length < 7)
746
+ return fromCharCode(a, b, c, d, e, f);
747
  let g = src[position$1++];
748
  if ((g & 0x80) > 0) {
749
  position$1 -= 7;
750
+ return;
751
  }
752
+ return fromCharCode(a, b, c, d, e, f, g);
753
  } else {
754
  let e = src[position$1++];
755
  let f = src[position$1++];
 
757
  let h = src[position$1++];
758
  if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
759
  position$1 -= 8;
760
+ return;
761
  }
762
  if (length < 10) {
763
  if (length === 8)
764
+ return fromCharCode(a, b, c, d, e, f, g, h);
765
  else {
766
  let i = src[position$1++];
767
  if ((i & 0x80) > 0) {
768
  position$1 -= 9;
769
+ return;
770
  }
771
+ return fromCharCode(a, b, c, d, e, f, g, h, i);
772
  }
773
  } else if (length < 12) {
774
  let i = src[position$1++];
775
  let j = src[position$1++];
776
  if ((i & 0x80) > 0 || (j & 0x80) > 0) {
777
  position$1 -= 10;
778
+ return;
779
  }
780
  if (length < 11)
781
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j);
782
  let k = src[position$1++];
783
  if ((k & 0x80) > 0) {
784
  position$1 -= 11;
785
+ return;
786
  }
787
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k);
788
  } else {
789
  let i = src[position$1++];
790
  let j = src[position$1++];
 
792
  let l = src[position$1++];
793
  if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
794
  position$1 -= 12;
795
+ return;
796
  }
797
  if (length < 14) {
798
  if (length === 12)
799
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l);
800
  else {
801
  let m = src[position$1++];
802
  if ((m & 0x80) > 0) {
803
  position$1 -= 13;
804
+ return;
805
  }
806
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m);
807
  }
808
  } else {
809
  let m = src[position$1++];
810
  let n = src[position$1++];
811
  if ((m & 0x80) > 0 || (n & 0x80) > 0) {
812
  position$1 -= 14;
813
+ return;
814
  }
815
  if (length < 15)
816
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n);
817
  let o = src[position$1++];
818
  if ((o & 0x80) > 0) {
819
  position$1 -= 15;
820
+ return;
821
  }
822
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
823
  }
824
  }
825
  }
 
837
  case 0xd9:
838
  // str 8
839
  length = src[position$1++];
840
+ break;
841
  case 0xda:
842
  // str 16
843
  length = dataView.getUint16(position$1);
844
  position$1 += 2;
845
+ break;
846
  case 0xdb:
847
  // str 32
848
  length = dataView.getUint32(position$1);
849
  position$1 += 4;
850
+ break;
851
  default:
852
+ throw new Error('Expected string');
853
  }
854
  }
855
+ return readStringJS(length);
856
  }
857
 
858
 
 
860
  return currentUnpackr.copyBuffers ?
861
  // specifically use the copying slice (not the node one)
862
  Uint8Array.prototype.slice.call(src, position$1, position$1 += length) :
863
+ src.subarray(position$1, position$1 += length);
864
  }
865
  function readExt(length) {
866
  let type = src[position$1++];
 
873
  } finally {
874
  position$1 = end;
875
  }
876
+ });
877
  }
878
  else
879
+ throw new Error('Unknown extension type ' + type);
880
  }
881
 
882
  var keyCache = new Array(4096);
 
886
  // fixstr, potentially use key cache
887
  length = length - 0xa0;
888
  if (srcStringEnd >= position$1) // if it has been extracted, must use it (and faster anyway)
889
+ return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart);
890
  else if (!(srcStringEnd == 0 && srcEnd < 180))
891
+ return readFixedString(length);
892
  } else { // not cacheable, go back and do a standard read
893
  position$1--;
894
+ return asSafeString(read());
895
  }
896
  let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position$1) : length > 0 ? src[position$1] : 0)) & 0xfff;
897
  let entry = keyCache[key];
 
904
  chunk = dataView.getUint32(checkPosition);
905
  if (chunk != entry[i++]) {
906
  checkPosition = 0x70000000;
907
+ break;
908
  }
909
  checkPosition += 4;
910
  }
 
913
  chunk = src[checkPosition++];
914
  if (chunk != entry[i++]) {
915
  checkPosition = 0x70000000;
916
+ break;
917
  }
918
  }
919
  if (checkPosition === end) {
920
  position$1 = checkPosition;
921
+ return entry.string;
922
  }
923
  end -= 3;
924
  checkPosition = position$1;
 
939
  // for small blocks, avoiding the overhead of the extract call is helpful
940
  let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
941
  if (string != null)
942
+ return entry.string = string;
943
+ return entry.string = readFixedString(length);
944
  }
945
 
946
  function asSafeString(property) {
 
971
  }
972
  currentStructures[id] = structure;
973
  structure.read = createStructureReader(structure, firstByte);
974
+ // The high byte (if any) was already consumed as the `highByte` argument above, so read the
975
+ // record body directly. Going through structure.read (a second-byte reader when highByte === 0)
976
+ // would misinterpret the first value byte as a high byte — corrupting two-byte own-record
977
+ // definitions (0xd5 0x72 ...). createStructureReader stashes the un-wrapped body reader on
978
+ // structure.read0 precisely for this immediate post-definition read.
979
+ return (structure.read0 || structure.read)();
980
  };
981
  currentExtensions[0] = () => {}; // notepack defines extension 0 to mean undefined, so use that as the default here
982
  currentExtensions[0].noBuffer = true;
 
998
  out <<= BigInt(64);
999
  out |= view.getBigUint64(i);
1000
  }
1001
+ return out;
1002
  }
1003
  // if (length === 8) return view.getBigUint64(start)
1004
  let middle = start + (length >> 4 << 3);
1005
  let left = decode(start, middle);
1006
  let right = decode(middle, end);
1007
+ return (left << BigInt((end - middle) * 8)) | right;
1008
  };
1009
  head = (head << BigInt((view.byteLength - headLength) * 8)) | decode(headLength, view.byteLength);
1010
  }
1011
+ return head;
1012
  };
1013
 
1014
  let errors = {
 
1019
  if (!errors[data[0]]) {
1020
  let error = Error(data[1], { cause: data[2] });
1021
  error.name = data[0];
1022
+ return error;
1023
  }
1024
+ return errors[data[0]](data[1], { cause: data[2] });
1025
  };
1026
 
1027
  currentExtensions[0x69] = (data) => {
1028
  // id extension (for structured clones)
1029
+ if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled');
1030
  let id = dataView.getUint32(position$1 - 4);
1031
  if (!referenceMap)
1032
  referenceMap = new Map();
 
1047
  let targetProperties = read(); // read the next value as the target object to id
1048
  if (!refEntry.used) {
1049
  // no cycle, can just use the returned read object
1050
+ return refEntry.target = targetProperties; // replace the placeholder with the real one
1051
  } else {
1052
  // there is a cycle, so we have to assign properties to original target
1053
  Object.assign(target, targetProperties);
 
1058
  for (let [k, v] of targetProperties.entries()) target.set(k, v);
1059
  if (target instanceof Set)
1060
  for (let i of Array.from(targetProperties)) target.add(i);
1061
+ return target;
1062
  };
1063
 
1064
  currentExtensions[0x70] = (data) => {
1065
  // pointer extension (for structured clones)
1066
+ if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled');
1067
  let id = dataView.getUint32(position$1 - 4);
1068
  let refEntry = referenceMap.get(id);
1069
  refEntry.used = true;
1070
+ return refEntry.target;
1071
  };
1072
 
1073
  currentExtensions[0x73] = () => new Set(read());
 
1082
 
1083
  let typedArrayName = typedArrays[typeCode];
1084
  if (!typedArrayName) {
1085
+ if (typeCode === 16) return buffer;
1086
+ if (typeCode === 17) return new DataView(buffer);
1087
+ throw new Error('Could not find typed array for code ' + typeCode);
1088
  }
1089
+ return new glbl[typedArrayName](buffer);
1090
  };
1091
  currentExtensions[0x78] = () => {
1092
  let data = read();
1093
+ return new RegExp(data[0], data[1]);
1094
  };
1095
  const TEMP_BUNDLE = [];
1096
  currentExtensions[0x62] = (data) => {
 
1103
  bundledStrings$1.position1 = 0;
1104
  bundledStrings$1.postBundlePosition = position$1;
1105
  position$1 = dataPosition;
1106
+ return read();
1107
  };
1108
 
1109
  currentExtensions[0xff] = (data) => {
1110
  // 32-bit date extension
1111
  if (data.length == 4)
1112
+ return new Date((data[0] * 0x1000000 + (data[1] << 16) + (data[2] << 8) + data[3]) * 1000);
1113
  else if (data.length == 8)
1114
  return new Date(
1115
  ((data[0] << 22) + (data[1] << 14) + (data[2] << 6) + (data[3] >> 2)) / 1000000 +
1116
+ ((data[3] & 0x3) * 0x100000000 + data[4] * 0x1000000 + (data[5] << 16) + (data[6] << 8) + data[7]) * 1000);
1117
  else if (data.length == 12)
1118
  return new Date(
1119
  ((data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]) / 1000000 +
1120
+ (((data[4] & 0x80) ? -0x1000000000000 : 0) + data[6] * 0x10000000000 + data[7] * 0x100000000 + data[8] * 0x1000000 + (data[9] << 16) + (data[10] << 8) + data[11]) * 1000);
1121
  else
1122
+ return new Date('invalid');
1123
  };
1124
  // registration of bulk record definition?
1125
  // currentExtensions[0x52] = () =>
1126
 
1127
  function saveState(callback) {
1128
+ if (currentUnpackr && currentUnpackr._onSaveState)
1129
+ currentUnpackr._onSaveState();
1130
  let savedSrcEnd = srcEnd;
1131
  let savedPosition = position$1;
1132
  let savedSrcStringStart = srcStringStart;
 
1155
  currentStructures.splice(0, currentStructures.length, ...savedStructuresContents);
1156
  currentUnpackr = savedPackr;
1157
  dataView = new DataView(src.buffer, src.byteOffset, src.byteLength);
1158
+ return value;
1159
  }
1160
  function clearSource() {
1161
  src = null;
 
1190
  function roundFloat32(float32Number) {
1191
  f32Array[0] = float32Number;
1192
  let multiplier = mult10[((u8Array[3] & 0x7f) << 1) | (u8Array[2] >> 7)];
1193
+ return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier;
1194
  }
1195
+ // Marker for downstream libraries (e.g. structon) to detect per-instance
1196
+ // struct-decoding hooks (this._readStruct, this._onLoadedStructures,
1197
+ // this._onSaveState). See `checkedRead` for the dispatch.
1198
+ Unpackr.SUPPORTS_STRUCT_HOOKS = true;
1199
 
1200
  let textEncoder;
1201
  try {
 
1204
  let extensions, extensionClasses;
1205
  const hasNodeBuffer = typeof Buffer !== 'undefined';
1206
  const ByteArrayAllocate = hasNodeBuffer ?
1207
+ function(length) { return Buffer.allocUnsafeSlow(length); } : Uint8Array;
1208
  const ByteArray = hasNodeBuffer ? Buffer : Uint8Array;
1209
  const MAX_BUFFER_SIZE = hasNodeBuffer ? 0x100000000 : 0x7fd00000;
1210
  let target, keysTarget;
 
1212
  let position = 0;
1213
  let safeEnd;
1214
  let bundledStrings = null;
 
1215
  const MAX_BUNDLE_SIZE = 0x5500; // maximum characters such that the encoded bytes fits in 16 bits.
1216
  const hasNonLatin = /[\u0080-\uFFFF]/;
1217
  const RECORD_SYMBOL = Symbol('record-id');
 
1224
  let structures;
1225
  let referenceMap;
1226
  let encodeUtf8 = ByteArray.prototype.utf8Write ? function(string, position) {
1227
+ return target.utf8Write(string, position, target.byteLength - position);
1228
  } : (textEncoder && textEncoder.encodeInto) ?
1229
  function(string, position) {
1230
+ return textEncoder.encodeInto(string, target.subarray(position)).written;
1231
  } : false;
1232
 
1233
  let packr = this;
 
1239
  if (maxSharedStructures == null)
1240
  maxSharedStructures = hasSharedStructures ? 32 : 0;
1241
  if (maxSharedStructures > 8160)
1242
+ throw new Error('Maximum maxSharedStructure is 8160');
1243
  if (options.structuredClone && options.moreTypes == undefined) {
1244
  this.moreTypes = true;
1245
  }
 
1253
  let sharedLimitId = maxSharedStructures + 0x40;
1254
  let maxStructureId = maxSharedStructures + maxOwnStructures + 0x40;
1255
  if (maxStructureId > 8256) {
1256
+ throw new Error('Maximum maxSharedStructure + maxOwnStructure is 8192');
1257
  }
1258
  let recordIdsToRemove = [];
1259
  let transitionsCount = 0;
 
1289
  let sharedLength = structures.sharedLength || 0;
1290
  if (sharedLength > maxSharedStructures) {
1291
  //if (maxSharedStructures <= 32 && structures.sharedLength > 32) // TODO: could support this, but would need to update the limit ids
1292
+ throw new Error('Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to ' + structures.sharedLength);
1293
  }
1294
  if (!structures.transitions) {
1295
  // rebuild our structure transitions
 
1297
  for (let i = 0; i < sharedLength; i++) {
1298
  let keys = structures[i];
1299
  if (!keys)
1300
+ continue;
1301
  let nextTransition, transition = structures.transitions;
1302
  for (let j = 0, l = keys.length; j < l; j++) {
1303
  let key = keys[j];
 
1319
  hasSharedUpdate = false;
1320
  let encodingError;
1321
  try {
1322
+ if (packr._writeStruct && value && typeof value === 'object') {
1323
  if (value.constructor === Object) writeStruct(value); // simple object
1324
  else if (value.constructor !== Map && !Array.isArray(value) && !extensionClasses.some(extClass => value instanceof extClass)) {
1325
  // allow user classes, if they don't need special handling (but do use toJSON if available)
 
1363
  packr.offset = position;
1364
  let serialized = insertIds(target.subarray(start, position), idsToInsert);
1365
  referenceMap = null;
1366
+ return serialized;
1367
  }
1368
  packr.offset = position; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
1369
  if (encodeOptions & REUSE_BUFFER_MODE) {
1370
  target.start = start;
1371
  target.end = position;
1372
+ return target;
1373
  }
1374
+ return target.subarray(start, position); // position can change if we call pack again in saveStructures, so we get the buffer now
1375
  } catch(error) {
1376
  encodingError = error;
1377
  throw error;
 
1382
  let sharedLength = structures.sharedLength || 0;
1383
  // we can't rely on start/end with REUSE_BUFFER_MODE since they will (probably) change when we save
1384
  let returnBuffer = target.subarray(start, position);
1385
+ let newSharedData = (packr._prepareStructures || prepareStructures)(structures, packr);
1386
  if (!encodingError) { // TODO: If there is an encoding error, should make the structures as uninitialized so they get rebuilt next time
1387
  if (packr.saveStructures(newSharedData, newSharedData.isCompatible) === false) {
1388
+ // The save was declined (a concurrent writer updated the shared structures,
1389
+ // or the store transaction did not durably commit). Our in-memory
1390
+ // structures + transition trie may now reference record ids that were
1391
+ // never persisted; re-packing as-is would re-emit the same record pointing
1392
+ // at an unpersisted structure (-> "Record id is not defined" on decode).
1393
+ // Mark structures uninitialized so the re-pack reloads durable structures
1394
+ // via getStructures, rebuilds the transition trie, and re-mints + re-saves.
1395
+ structures.uninitialized = true;
1396
+ return packr.pack(value, encodeOptions);
1397
  }
1398
  packr.lastNamedStructuresLength = sharedLength;
1399
  // don't keep large buffers around
1400
  if (target.length > 0x40000000) target = null;
1401
+ return returnBuffer;
1402
  }
1403
  }
1404
  }
 
1484
  bundledStrings[twoByte ? 0 : 1] += value;
1485
  target[position++] = 0xc1;
1486
  pack(twoByte ? -strLength : strLength);
1487
+ return;
1488
  }
1489
  let headerSize;
1490
  // first we estimate the header size, so we can write to the correct location
 
1558
  } else if (type === 'number') {
1559
  if (value >>> 0 === value) {// positive integer, 32-bit or less
1560
  // positive uint
1561
+ if (value < 0x20 || (value < 0x80 && this.useRecords === false) || (value < 0x40 && !this._writeStruct)) {
1562
  target[position++] = value;
1563
  } else if (value < 0x100) {
1564
  target[position++] = 0xcc;
 
1597
  // this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
1598
  ((xShifted = value * mult10[((target[position] & 0x7f) << 1) | (target[position + 1] >> 7)]) >> 0) === xShifted) {
1599
  position += 4;
1600
+ return;
1601
  } else
1602
  position--; // move back into position for writing a double
1603
  }
 
1620
  target[position++] = 0x70; // "p" for pointer
1621
  targetView.setUint32(position, referee.id);
1622
  position += 4;
1623
+ return;
1624
  } else
1625
  referenceMap.set(value, { offset: position - start });
1626
  }
 
1670
  } else {
1671
  pack(writeResult);
1672
  }
1673
+ return;
1674
  }
1675
  let currentTarget = target;
1676
  let currentTargetView = targetView;
 
1687
  makeRoom(position);
1688
  return {
1689
  target, targetView, position: position - size
1690
+ };
1691
  }, pack);
1692
  } finally {
1693
  // restore current target information (unless already restored)
 
1703
  makeRoom(result.length + position);
1704
  position = writeExtensionData(result, target, position, extension.type);
1705
  }
1706
+ return;
1707
  }
1708
  }
1709
  // check isArray after extensions, because extensions can extend Array
 
1715
  const json = value.toJSON();
1716
  // if for some reason value.toJSON returns itself it'll loop forever
1717
  if (json !== value)
1718
+ return pack(json);
1719
  }
1720
 
1721
  // if there is a writeFunction, use it, otherwise just encode as undefined
 
1754
  let chunks = [];
1755
  while (true) {
1756
  chunks.push(value & mask);
1757
+ if ((value >> BigInt(63)) === empty) break;
1758
  value >>= BigInt(64);
1759
  }
1760
 
 
1786
  if (array.length + position > safeEnd)
1787
  makeRoom(array.length + position);
1788
  position = writeExtensionData(array, target, position, 0x42);
1789
+ return;
1790
  } else {
1791
  throw new RangeError(value + ' was too large to fit in MessagePack 64-bit integer format, use' +
1792
  ' useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set' +
1793
+ ' largeBigIntToString to convert to string');
1794
  }
1795
  }
1796
  position += 8;
 
1803
  target[position++] = 0;
1804
  }
1805
  } else {
1806
+ throw new Error('Unknown type: ' + type);
1807
  }
1808
  };
1809
 
 
1949
  checkUseRecords(object) ? writeRecord(object) : writePlainObject(object);
1950
  } : writeRecord;
1951
 
1952
+ const writeStruct = (object) => {
1953
+ let newPosition = packr._writeStruct(object, target, start, position, structures, makeRoom, (value, newPosition, notifySharedUpdate) => {
1954
+ if (notifySharedUpdate)
1955
+ return hasSharedUpdate = true;
1956
+ position = newPosition;
1957
+ let startTarget = target;
1958
+ pack(value);
1959
+ resetStructures();
1960
+ if (startTarget !== target) {
1961
+ return { position, targetView, target }; // indicate the buffer was re-allocated
1962
+ }
1963
+ return position;
1964
+ });
1965
+ if (newPosition === 0) // bail and go to a msgpack object
1966
+ return writeObject(object);
1967
+ position = newPosition;
1968
+ };
1969
+
1970
  const makeRoom = (end) => {
1971
  let newSize;
1972
  if (end > 0x1000000) {
1973
  // special handling for really large buffers
1974
  if ((end - start) > MAX_BUFFER_SIZE)
1975
+ throw new Error('Packed buffer would be larger than maximum buffer size');
1976
  newSize = Math.min(MAX_BUFFER_SIZE,
1977
  Math.round(Math.max((end - start) * (end > 0x4000000 ? 1.25 : 2), 0x400000) / 0x1000) * 0x1000);
1978
  } else // faster handling for smaller buffers
 
1987
  position -= start;
1988
  start = 0;
1989
  safeEnd = newBuffer.length - 10;
1990
+ return target = newBuffer;
1991
  };
1992
  const newRecord = (transition, keys, newTransitions) => {
1993
  let recordId = structures.nextId;
 
2069
  target[insertionOffset + start] = keysTarget[0];
2070
  }
2071
  };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2072
  }
2073
  useBuffer(buffer) {
2074
  // this means we are finished using our own buffer and we can write over it safely
 
2111
  } else if (isNaN(seconds)) {
2112
  if (this.onInvalidDate) {
2113
  allocateForWrite(0);
2114
+ return pack(this.onInvalidDate());
2115
  }
2116
  // Intentionally invalid timestamp
2117
  let { target, targetView, position} = allocateForWrite(3);
 
2132
  pack(set, allocateForWrite, pack) {
2133
  if (this.setAsEmptyObject) {
2134
  allocateForWrite(0);
2135
+ return pack({});
2136
  }
2137
  let array = Array.from(set);
2138
  let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
 
2240
  switch (length) {
2241
  case 1:
2242
  target[position++] = 0xd4;
2243
+ break;
2244
  case 2:
2245
  target[position++] = 0xd5;
2246
+ break;
2247
  case 4:
2248
  target[position++] = 0xd6;
2249
+ break;
2250
  case 8:
2251
  target[position++] = 0xd7;
2252
+ break;
2253
  case 16:
2254
  target[position++] = 0xd8;
2255
+ break;
2256
  default:
2257
  if (length < 0x100) {
2258
  target[position++] = 0xc7;
 
2272
  target[position++] = type;
2273
  target.set(result, position);
2274
  position += length;
2275
+ return position;
2276
  }
2277
 
2278
  function insertIds(serialized, idsToInsert) {
 
2294
  serialized[position++] = id & 0xff;
2295
  lastEnd = offset;
2296
  }
2297
+ return serialized;
2298
  }
2299
 
2300
  function writeBundles(start, pack, incrementPosition) {
 
2311
  function addExtension(extension) {
2312
  if (extension.Class) {
2313
  if (!extension.pack && !extension.write)
2314
+ throw new Error('Extension has no pack or write function');
2315
  if (extension.pack && !extension.type)
2316
+ throw new Error('Extension has no type (numeric code to identify the extension)');
2317
  extensionClasses.unshift(extension.Class);
2318
  extensions.unshift(extension);
2319
  }
 
2326
  packr._mergeStructures(existingStructures);
2327
  return compatible;
2328
  };
2329
+ return structures;
2330
  }
2331
 
2332
+ // Marker for downstream libraries (e.g. structon) to detect that this Packr
2333
+ // supports per-instance struct-encoding hooks (this._writeStruct,
2334
+ // this._prepareStructures). See `pack` for the dispatch.
2335
+ Packr.SUPPORTS_STRUCT_HOOKS = true;
2336
+
2337
  let defaultPackr = new Packr({ useRecords: false });
2338
  const pack = defaultPackr.pack;
2339
  const encode = defaultPackr.pack;
 
2352
  */
2353
  function packIter (objectIterator, options = {}) {
2354
  if (!objectIterator || typeof objectIterator !== 'object') {
2355
+ throw new Error('first argument must be an Iterable, Async Iterable, or a Promise for an Async Iterable');
2356
  } else if (typeof objectIterator[Symbol.iterator] === 'function') {
2357
+ return packIterSync(objectIterator, options);
2358
  } else if (typeof objectIterator.then === 'function' || typeof objectIterator[Symbol.asyncIterator] === 'function') {
2359
+ return packIterAsync(objectIterator, options);
2360
  } else {
2361
+ throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a Promise');
2362
  }
2363
  }
2364
 
 
2385
  */
2386
  function unpackIter (bufferIterator, options = {}) {
2387
  if (!bufferIterator || typeof bufferIterator !== 'object') {
2388
+ throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a promise');
2389
  }
2390
 
2391
  const unpackr = new Unpackr(options);
 
2405
  incomplete = chunk.slice(err.lastPosition);
2406
  yields = err.values;
2407
  } else {
2408
+ throw err;
2409
  }
2410
  }
2411
+ return yields;
2412
  };
2413
 
2414
  if (typeof bufferIterator[Symbol.iterator] === 'function') {
 
2416
  for (const value of bufferIterator) {
2417
  yield * parser(value);
2418
  }
2419
+ })();
2420
  } else if (typeof bufferIterator[Symbol.asyncIterator] === 'function') {
2421
  return (async function * iter () {
2422
  for await (const value of bufferIterator) {
2423
  yield * parser(value);
2424
  }
2425
+ })();
2426
  }
2427
  }
2428
  const decodeIter = unpackIter;
.opencode/node_modules/msgpackr/dist/index.js.map CHANGED
The diff for this file is too large to render. See raw diff
 
.opencode/node_modules/msgpackr/dist/index.min.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).msgpackr={})}(this,(function(e){"use strict";var t,r,n;try{t=new TextDecoder}catch(e){}var i,s,o,a,u,l=0,f={},c=0,h=0,g=[],p={useRecords:!1,mapsAsObjects:!0};class d{}const y=new d;y.name="MessagePack 0xC1";var w=!1,b=2;class m{constructor(e){e&&(!1===e.useRecords&&void 0===e.mapsAsObjects&&(e.mapsAsObjects=!0),e.sequential&&!1!==e.trusted&&(e.trusted=!0,e.structures||0==e.useRecords||(e.structures=[],e.maxSharedStructures||(e.maxSharedStructures=0))),e.structures?e.structures.sharedLength=e.structures.length:e.getStructures&&((e.structures=[]).uninitialized=!0,e.structures.sharedLength=0),e.int64AsNumber&&(e.int64AsType="number")),Object.assign(this,e)}unpack(e,t){if(r)return q((()=>(Z(),this?this.unpack(e,t):m.prototype.unpack.call(p,e,t))));e.buffer||e.constructor!==ArrayBuffer||(e="undefined"!=typeof Buffer?Buffer.from(e):new Uint8Array(e)),"object"==typeof t?(n=t.end||e.length,l=t.start||0):(l=0,n=t>-1?t:e.length),h=0,s=null,o=null,r=e;try{u=e.dataView||(e.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength))}catch(t){if(r=null,e instanceof Uint8Array)throw t;throw new Error("Source must be a Uint8Array or Buffer but was a "+(e&&"object"==typeof e?e.constructor.name:typeof e))}if(this instanceof m){if(f=this,this.structures)return i=this.structures,S(t);(!i||i.length>0)&&(i=[])}else f=p,(!i||i.length>0)&&(i=[]);return S(t)}unpackMultiple(e,t){let r,n=0;try{w=!0;let i=e.length,s=this?this.unpack(e,i):Q.unpack(e,i);if(!t){for(r=[s];l<i;)n=l,r.push(S());return r}if(!1===t(s,n,l))return;for(;l<i;)if(n=l,!1===t(S(),n,l))return}catch(e){throw e.lastPosition=n,e.values=r,e}finally{w=!1,Z()}}_mergeStructures(e,t){e=e||[],Object.isFrozen(e)&&(e=e.map((e=>e.slice(0))));for(let t=0,r=e.length;t<r;t++){let r=e[t];r&&(r.isShared=!0,t>=32&&(r.highByte=t-32>>5))}e.sharedLength=e.length;for(let r in t||[])if(r>=0){let n=e[r],i=t[r];i&&(n&&((e.restoreStructures||(e.restoreStructures=[]))[r]=n),e[r]=i)}return this.structures=e}decode(e,t){return this.unpack(e,t)}}function S(e){try{if(!f.trusted&&!w){let e=i.sharedLength||0;e<i.length&&(i.length=e)}let e;if(f.randomAccessStructure&&r[l]<64&&r[l],e=U(),o&&(l=o.postBundlePosition,o=null),w&&(i.restoreStructures=null),l==n)i&&i.restoreStructures&&A(),i=null,r=null,a&&(a=null);else{if(l>n)throw new Error("Unexpected end of MessagePack data");if(!w){let t;try{t=JSON.stringify(e,((e,t)=>"bigint"==typeof t?`${t}n`:t)).slice(0,100)}catch(e){t="(JSON view not available "+e+")"}throw new Error("Data read, but end of buffer not reached "+t)}}return e}catch(e){throw i&&i.restoreStructures&&A(),Z(),(e instanceof RangeError||e.message.startsWith("Unexpected end of buffer")||l>n)&&(e.incomplete=!0),e}}function A(){for(let e in i.restoreStructures)i[e]=i.restoreStructures[e];i.restoreStructures=null}function U(){let e=r[l++];if(e<160){if(e<128){if(e<64)return e;{let t=i[63&e]||f.getStructures&&v()[63&e];return t?(t.read||(t.read=I(t,63&e)),t.read()):e}}if(e<144){if(e-=128,f.mapsAsObjects){let t={};for(let r=0;r<e;r++){let e=z();"__proto__"===e&&(e="__proto_"),t[e]=U()}return t}{let t=new Map;for(let r=0;r<e;r++)t.set(U(),U());return t}}{e-=144;let t=new Array(e);for(let r=0;r<e;r++)t[r]=U();return f.freezeData?Object.freeze(t):t}}if(e<192){let t=e-160;if(h>=l)return s.slice(l-c,(l+=t)-c);if(0==h&&n<140){let e=t<16?V(t):D(t);if(null!=e)return e}return B(t)}{let t;switch(e){case 192:return null;case 193:return o?(t=U(),t>0?o[1].slice(o.position1,o.position1+=t):o[0].slice(o.position0,o.position0-=t)):y;case 194:return!1;case 195:return!0;case 196:if(t=r[l++],void 0===t)throw new Error("Unexpected end of buffer");return N(t);case 197:return t=u.getUint16(l),l+=2,N(t);case 198:return t=u.getUint32(l),l+=4,N(t);case 199:return F(r[l++]);case 200:return t=u.getUint16(l),l+=2,F(t);case 201:return t=u.getUint32(l),l+=4,F(t);case 202:if(t=u.getFloat32(l),f.useFloat32>2){let e=G[(127&r[l])<<1|r[l+1]>>7];return l+=4,(e*t+(t>0?.5:-.5)>>0)/e}return l+=4,t;case 203:return t=u.getFloat64(l),l+=8,t;case 204:return r[l++];case 205:return t=u.getUint16(l),l+=2,t;case 206:return t=u.getUint32(l),l+=4,t;case 207:return"number"===f.int64AsType?(t=4294967296*u.getUint32(l),t+=u.getUint32(l+4)):"string"===f.int64AsType?t=u.getBigUint64(l).toString():"auto"===f.int64AsType?(t=u.getBigUint64(l),t<=BigInt(2)<<BigInt(52)&&(t=Number(t))):t=u.getBigUint64(l),l+=8,t;case 208:return u.getInt8(l++);case 209:return t=u.getInt16(l),l+=2,t;case 210:return t=u.getInt32(l),l+=4,t;case 211:return"number"===f.int64AsType?(t=4294967296*u.getInt32(l),t+=u.getUint32(l+4)):"string"===f.int64AsType?t=u.getBigInt64(l).toString():"auto"===f.int64AsType?(t=u.getBigInt64(l),t>=BigInt(-2)<<BigInt(52)&&t<=BigInt(2)<<BigInt(52)&&(t=Number(t))):t=u.getBigInt64(l),l+=8,t;case 212:if(t=r[l++],114==t)return W(63&r[l++]);{let e=g[t];if(e)return e.read?(l++,e.read(U())):e.noBuffer?(l++,e()):e(r.subarray(l,++l));throw new Error("Unknown extension "+t)}case 213:return t=r[l],114==t?(l++,W(63&r[l++],r[l++])):F(2);case 214:return F(4);case 215:return F(8);case 216:return F(16);case 217:return t=r[l++],h>=l?s.slice(l-c,(l+=t)-c):O(t);case 218:return t=u.getUint16(l),h>=(l+=2)?s.slice(l-c,(l+=t)-c):_(t);case 219:return t=u.getUint32(l),h>=(l+=4)?s.slice(l-c,(l+=t)-c):x(t);case 220:return t=u.getUint16(l),l+=2,M(t);case 221:return t=u.getUint32(l),l+=4,M(t);case 222:return t=u.getUint16(l),l+=2,j(t);case 223:return t=u.getUint32(l),l+=4,j(t);default:if(e>=224)return e-256;if(void 0===e){let e=new Error("Unexpected end of MessagePack data");throw e.incomplete=!0,e}throw new Error("Unknown MessagePack token "+e)}}}const E=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function I(e,t){function r(){if(r.count++>b){let n;try{n=e.read=new Function("r","return function(){return "+(f.freezeData?"Object.freeze":"")+"({"+e.map((e=>"__proto__"===e?"__proto_:r()":E.test(e)?e+":r()":"["+JSON.stringify(e)+"]:r()")).join(",")+"})}")(U)}catch(e){return b=1/0,r()}return 0===e.highByte&&(e.read=k(t,e.read)),n()}let n={};for(let t=0,r=e.length;t<r;t++){let r=e[t];"__proto__"===r&&(r="__proto_"),n[r]=U()}return f.freezeData?Object.freeze(n):n}return r.count=0,0===e.highByte?k(t,r):r}const k=(e,t)=>function(){let n=r[l++];if(0===n)return t();let s=e<32?-(e+(n<<5)):e+(n<<5),o=i[s]||v()[s];if(!o)throw new Error("Record id is not defined for "+s);return o.read||(o.read=I(o,e)),o.read()};function v(){let e=q((()=>(r=null,f.getStructures())));return i=f._mergeStructures(e,i)}var B=T,O=T,_=T,x=T;function T(e){let n;if(e<16&&(n=V(e)))return n;if(e>64&&t)return t.decode(r.subarray(l,l+=e));const i=l+e,s=[];for(n="";l<i;){const e=r[l++];if(0==(128&e))s.push(e);else if(192==(224&e)){const t=(31&e)<<6|63&r[l++];t<128?s.push(65533):s.push(t)}else if(224==(240&e)){const t=(31&e)<<12|(63&r[l++])<<6|63&r[l++];t<2048||t>=55296&&t<=57343?s.push(65533):s.push(t)}else if(240==(248&e)){let t=(7&e)<<18|(63&r[l++])<<12|(63&r[l++])<<6|63&r[l++];t<65536||t>1114111?s.push(65533):t>65535?(t-=65536,s.push(t>>>10&1023|55296),t=56320|1023&t,s.push(t)):s.push(t)}else s.push(65533);s.length>=4096&&(n+=R.apply(String,s),s.length=0)}return s.length>0&&(n+=R.apply(String,s)),n}function M(e){let t=new Array(e);for(let r=0;r<e;r++)t[r]=U();return f.freezeData?Object.freeze(t):t}function j(e){if(f.mapsAsObjects){let t={};for(let r=0;r<e;r++){let e=z();"__proto__"===e&&(e="__proto_"),t[e]=U()}return t}{let t=new Map;for(let r=0;r<e;r++)t.set(U(),U());return t}}var R=String.fromCharCode;function D(e){let t=l,n=new Array(e);for(let i=0;i<e;i++){const e=r[l++];if((128&e)>0)return void(l=t);n[i]=e}return R.apply(String,n)}function V(e){if(e<4){if(e<2){if(0===e)return"";{let e=r[l++];return(128&e)>1?void(l-=1):R(e)}}{let t=r[l++],n=r[l++];if((128&t)>0||(128&n)>0)return void(l-=2);if(e<3)return R(t,n);let i=r[l++];return(128&i)>0?void(l-=3):R(t,n,i)}}{let t=r[l++],n=r[l++],i=r[l++],s=r[l++];if((128&t)>0||(128&n)>0||(128&i)>0||(128&s)>0)return void(l-=4);if(e<6){if(4===e)return R(t,n,i,s);{let e=r[l++];return(128&e)>0?void(l-=5):R(t,n,i,s,e)}}if(e<8){let o=r[l++],a=r[l++];if((128&o)>0||(128&a)>0)return void(l-=6);if(e<7)return R(t,n,i,s,o,a);let u=r[l++];return(128&u)>0?void(l-=7):R(t,n,i,s,o,a,u)}{let o=r[l++],a=r[l++],u=r[l++],f=r[l++];if((128&o)>0||(128&a)>0||(128&u)>0||(128&f)>0)return void(l-=8);if(e<10){if(8===e)return R(t,n,i,s,o,a,u,f);{let e=r[l++];return(128&e)>0?void(l-=9):R(t,n,i,s,o,a,u,f,e)}}if(e<12){let c=r[l++],h=r[l++];if((128&c)>0||(128&h)>0)return void(l-=10);if(e<11)return R(t,n,i,s,o,a,u,f,c,h);let g=r[l++];return(128&g)>0?void(l-=11):R(t,n,i,s,o,a,u,f,c,h,g)}{let c=r[l++],h=r[l++],g=r[l++],p=r[l++];if((128&c)>0||(128&h)>0||(128&g)>0||(128&p)>0)return void(l-=12);if(e<14){if(12===e)return R(t,n,i,s,o,a,u,f,c,h,g,p);{let e=r[l++];return(128&e)>0?void(l-=13):R(t,n,i,s,o,a,u,f,c,h,g,p,e)}}{let d=r[l++],y=r[l++];if((128&d)>0||(128&y)>0)return void(l-=14);if(e<15)return R(t,n,i,s,o,a,u,f,c,h,g,p,d,y);let w=r[l++];return(128&w)>0?void(l-=15):R(t,n,i,s,o,a,u,f,c,h,g,p,d,y,w)}}}}}function L(){let e,t=r[l++];if(t<192)e=t-160;else switch(t){case 217:e=r[l++];break;case 218:e=u.getUint16(l),l+=2;break;case 219:e=u.getUint32(l),l+=4;break;default:throw new Error("Expected string")}return T(e)}function N(e){return f.copyBuffers?Uint8Array.prototype.slice.call(r,l,l+=e):r.subarray(l,l+=e)}function F(e){let t=r[l++];if(g[t]){let n;return g[t](r.subarray(l,n=l+=e),(e=>{l=e;try{return U()}finally{l=n}}))}throw new Error("Unknown extension type "+t)}var P=new Array(4096);function z(){let e=r[l++];if(!(e>=160&&e<192))return l--,C(U());if(e-=160,h>=l)return s.slice(l-c,(l+=e)-c);if(!(0==h&&n<180))return B(e);let t,i=4095&(e<<5^(e>1?u.getUint16(l):e>0?r[l]:0)),o=P[i],a=l,f=l+e-3,g=0;if(o&&o.bytes==e){for(;a<f;){if(t=u.getUint32(a),t!=o[g++]){a=1879048192;break}a+=4}for(f+=3;a<f;)if(t=r[a++],t!=o[g++]){a=1879048192;break}if(a===f)return l=a,o.string;f-=3,a=l}for(o=[],P[i]=o,o.bytes=e;a<f;)t=u.getUint32(a),o.push(t),a+=4;for(f+=3;a<f;)t=r[a++],o.push(t);let p=e<16?V(e):D(e);return o.string=null!=p?p:B(e)}function C(e){if("string"==typeof e)return e;if("number"==typeof e||"boolean"==typeof e||"bigint"==typeof e)return e.toString();if(null==e)return e+"";if(f.allowArraysInMapKeys&&Array.isArray(e)&&e.flat().every((e=>["string","number","boolean","bigint"].includes(typeof e))))return e.flat().toString();throw new Error("Invalid property type for record: "+typeof e)}const W=(e,t)=>{let r=U().map(C),n=e;void 0!==t&&(e=e<32?-((t<<5)+e):(t<<5)+e,r.highByte=t);let s=i[e];return s&&(s.isShared||w)&&((i.restoreStructures||(i.restoreStructures=[]))[e]=s),i[e]=r,r.read=I(r,n),r.read()};g[0]=()=>{},g[0].noBuffer=!0,g[66]=e=>{let t=e.byteLength%8||8,r=BigInt(128&e[0]?e[0]-256:e[0]);for(let n=1;n<t;n++)r<<=BigInt(8),r+=BigInt(e[n]);if(e.byteLength!==t){let n=new DataView(e.buffer,e.byteOffset,e.byteLength),i=(e,t)=>{let r=t-e;if(r<=40){let r=n.getBigUint64(e);for(let i=e+8;i<t;i+=8)r<<=BigInt(64),r|=n.getBigUint64(i);return r}let s=e+(r>>4<<3),o=i(e,s),a=i(s,t);return o<<BigInt(8*(t-s))|a};r=r<<BigInt(8*(n.byteLength-t))|i(t,n.byteLength)}return r};let J={Error:Error,EvalError:EvalError,RangeError:RangeError,ReferenceError:ReferenceError,SyntaxError:SyntaxError,TypeError:TypeError,URIError:URIError,AggregateError:"function"==typeof AggregateError?AggregateError:null};g[101]=()=>{let e=U();if(!J[e[0]]){let t=Error(e[1],{cause:e[2]});return t.name=e[0],t}return J[e[0]](e[1],{cause:e[2]})},g[105]=e=>{if(!1===f.structuredClone)throw new Error("Structured clone extension is disabled");let t=u.getUint32(l-4);a||(a=new Map);let n,i=r[l];n=i>=144&&i<160||220==i||221==i?[]:i>=128&&i<144||222==i||223==i?new Map:(i>=199&&i<=201||i>=212&&i<=216)&&115===r[l+1]?new Set:{};let s={target:n};a.set(t,s);let o=U();if(!s.used)return s.target=o;if(Object.assign(n,o),n instanceof Map)for(let[e,t]of o.entries())n.set(e,t);if(n instanceof Set)for(let e of Array.from(o))n.add(e);return n},g[112]=e=>{if(!1===f.structuredClone)throw new Error("Structured clone extension is disabled");let t=u.getUint32(l-4),r=a.get(t);return r.used=!0,r.target},g[115]=()=>new Set(U());const $=["Int8","Uint8","Uint8Clamped","Int16","Uint16","Int32","Uint32","Float32","Float64","BigInt64","BigUint64"].map((e=>e+"Array"));let K="object"==typeof globalThis?globalThis:window;g[116]=e=>{let t=e[0],r=Uint8Array.prototype.slice.call(e,1).buffer,n=$[t];if(!n){if(16===t)return r;if(17===t)return new DataView(r);throw new Error("Could not find typed array for code "+t)}return new K[n](r)},g[120]=()=>{let e=U();return new RegExp(e[0],e[1])};const Y=[];function q(e){let t=n,g=l,p=c,d=h,y=s,b=a,m=o,S=new Uint8Array(r.slice(0,n)),A=i,U=i.slice(0,i.length),E=f,I=w,k=e();return n=t,l=g,c=p,h=d,s=y,a=b,o=m,r=S,w=I,(i=A).splice(0,i.length,...U),f=E,u=new DataView(r.buffer,r.byteOffset,r.byteLength),k}function Z(){r=null,a=null,i=null}g[98]=e=>{let t=(e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3],r=l;return l+=t-e.length,o=Y,(o=[L(),L()]).position0=0,o.position1=0,o.postBundlePosition=l,l=r,U()},g[255]=e=>4==e.length?new Date(1e3*(16777216*e[0]+(e[1]<<16)+(e[2]<<8)+e[3])):8==e.length?new Date(((e[0]<<22)+(e[1]<<14)+(e[2]<<6)+(e[3]>>2))/1e6+1e3*(4294967296*(3&e[3])+16777216*e[4]+(e[5]<<16)+(e[6]<<8)+e[7])):12==e.length?new Date(((e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3])/1e6+1e3*((128&e[4]?-281474976710656:0)+1099511627776*e[6]+4294967296*e[7]+16777216*e[8]+(e[9]<<16)+(e[10]<<8)+e[11])):new Date("invalid");const G=new Array(147);for(let e=0;e<256;e++)G[e]=+("1e"+Math.floor(45.15-.30103*e));const H=m;var Q=new m({useRecords:!1});const X=Q.unpack,ee=Q.unpackMultiple,te=Q.unpack,re={NEVER:0,ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4};let ne,ie,se,oe=new Float32Array(1),ae=new Uint8Array(oe.buffer,0,4);try{ne=new TextEncoder}catch(e){}const ue="undefined"!=typeof Buffer,le=ue?function(e){return Buffer.allocUnsafeSlow(e)}:Uint8Array,fe=ue?Buffer:Uint8Array,ce=ue?4294967296:2144337920;let he,ge,pe,de,ye=0,we=null;const be=/[\u0080-\uFFFF]/,me=Symbol("record-id");class Se extends m{constructor(e){let t,r,n,i;super(e),this.offset=0;let s=fe.prototype.utf8Write?function(e,t){return he.utf8Write(e,t,he.byteLength-t)}:!(!ne||!ne.encodeInto)&&function(e,t){return ne.encodeInto(e,he.subarray(t)).written},o=this;e||(e={});let a=e&&e.sequential,u=e.structures||e.saveStructures,l=e.maxSharedStructures;if(null==l&&(l=u?32:0),l>8160)throw new Error("Maximum maxSharedStructure is 8160");e.structuredClone&&null==e.moreTypes&&(this.moreTypes=!0);let f=e.maxOwnStructures;null==f&&(f=u?32:64),this.structures||0==e.useRecords||(this.structures=[]);let c=l>32||f+l>64,h=l+64,g=l+f+64;if(g>8256)throw new Error("Maximum maxSharedStructure + maxOwnStructure is 8192");let p=[],d=0,y=0;this.pack=this.encode=function(e,s){if(he||(he=new le(8192),pe=he.dataView||(he.dataView=new DataView(he.buffer,0,8192)),ye=0),de=he.length-10,de-ye<2048?(he=new le(he.length),pe=he.dataView||(he.dataView=new DataView(he.buffer,0,he.length)),de=he.length-10,ye=0):ye=ye+7&2147483640,t=ye,s&De&&(ye+=255&s),i=o.structuredClone?new Map:null,o.bundleStrings&&"string"!=typeof e?(we=[],we.size=1/0):we=null,n=o.structures,n){n.uninitialized&&(n=o._mergeStructures(o.getStructures()));let e=n.sharedLength||0;if(e>l)throw new Error("Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to "+n.sharedLength);if(!n.transitions){n.transitions=Object.create(null);for(let t=0;t<e;t++){let e=n[t];if(!e)continue;let r,i=n.transitions;for(let t=0,n=e.length;t<n;t++){let n=e[t];r=i[n],r||(r=i[n]=Object.create(null)),i=r}i[me]=t+64}this.lastNamedStructuresLength=e}a||(n.nextId=e+64)}let u;r&&(r=!1);try{o.randomAccessStructure&&e&&"object"==typeof e?e.constructor===Object?B(e):e.constructor===Map||Array.isArray(e)||se.some((t=>e instanceof t))?m(e):B(e.toJSON?e.toJSON():e):m(e);let a=we;if(we&&Ie(t,m,0),i&&i.idsToInsert){let e=i.idsToInsert.sort(((e,t)=>e.offset>t.offset?1:-1)),r=e.length,n=-1;for(;a&&r>0;){let i=e[--r].offset+t;i<a.stringsPosition+t&&-1===n&&(n=0),i>a.position+t?n>=0&&(n+=6):(n>=0&&(pe.setUint32(a.position+t,pe.getUint32(a.position+t)+n),n=-1),a=a.previous,r++)}n>=0&&a&&pe.setUint32(a.position+t,pe.getUint32(a.position+t)+n),ye+=6*e.length,ye>de&&I(ye),o.offset=ye;let s=function(e,t){let r,n=6*t.length,i=e.length-n;for(;r=t.pop();){let t=r.offset,s=r.id;e.copyWithin(t+n,t,i),n-=6;let o=t+n;e[o++]=214,e[o++]=105,e[o++]=s>>24,e[o++]=s>>16&255,e[o++]=s>>8&255,e[o++]=255&s,i=t}return e}(he.subarray(t,ye),e);return i=null,s}return o.offset=ye,s&je?(he.start=t,he.end=ye,he):he.subarray(t,ye)}catch(e){throw u=e,e}finally{if(n&&(w(),r&&o.saveStructures)){let r=n.sharedLength||0,i=he.subarray(t,ye),a=function(e,t){return e.isCompatible=e=>{let r=!e||(t.lastNamedStructuresLength||0)===e.length;return r||t._mergeStructures(e),r},e}(n,o);if(!u)return!1===o.saveStructures(a,a.isCompatible)?o.pack(e,s):(o.lastNamedStructuresLength=r,he.length>1073741824&&(he=null),i)}he.length>1073741824&&(he=null),s&Re&&(ye=t)}};const w=()=>{y<10&&y++;let e=n.sharedLength||0;if(n.length>e&&!a&&(n.length=e),d>1e4)n.transitions=null,y=0,d=0,p.length>0&&(p=[]);else if(p.length>0&&!a){for(let e=0,t=p.length;e<t;e++)p[e][me]=0;p=[]}},b=e=>{var t=e.length;t<16?he[ye++]=144|t:t<65536?(he[ye++]=220,he[ye++]=t>>8,he[ye++]=255&t):(he[ye++]=221,pe.setUint32(ye,t),ye+=4);for(let r=0;r<t;r++)m(e[r])},m=e=>{ye>de&&(he=I(ye));var r,n=typeof e;if("string"===n){let n,i=e.length;if(we&&i>=4&&i<4096){if((we.size+=i)>21760){let e,r,n=(we[0]?3*we[0].length+we[1].length:0)+10;ye+n>de&&(he=I(ye+n)),we.position?(r=we,he[ye]=200,ye+=3,he[ye++]=98,e=ye-t,ye+=4,Ie(t,m,0),pe.setUint16(e+t-3,ye-t-e)):(he[ye++]=214,he[ye++]=98,e=ye-t,ye+=4),we=["",""],we.previous=r,we.size=0,we.position=e}let r=be.test(e);return we[r?0:1]+=e,he[ye++]=193,void m(r?-i:i)}n=i<32?1:i<256?2:i<65536?3:5;let o=3*i;if(ye+o>de&&(he=I(ye+o)),i<64||!s){let t,s,o,a=ye+n;for(t=0;t<i;t++)s=e.charCodeAt(t),s<128?he[a++]=s:s<2048?(he[a++]=s>>6|192,he[a++]=63&s|128):55296==(64512&s)&&56320==(64512&(o=e.charCodeAt(t+1)))?(s=65536+((1023&s)<<10)+(1023&o),t++,he[a++]=s>>18|240,he[a++]=s>>12&63|128,he[a++]=s>>6&63|128,he[a++]=63&s|128):(he[a++]=s>>12|224,he[a++]=s>>6&63|128,he[a++]=63&s|128);r=a-ye-n}else r=s(e,ye+n);r<32?he[ye++]=160|r:r<256?(n<2&&he.copyWithin(ye+2,ye+1,ye+1+r),he[ye++]=217,he[ye++]=r):r<65536?(n<3&&he.copyWithin(ye+3,ye+2,ye+2+r),he[ye++]=218,he[ye++]=r>>8,he[ye++]=255&r):(n<5&&he.copyWithin(ye+5,ye+3,ye+3+r),he[ye++]=219,pe.setUint32(ye,r),ye+=4),ye+=r}else if("number"===n)if(e>>>0===e)e<32||e<128&&!1===this.useRecords||e<64&&!this.randomAccessStructure?he[ye++]=e:e<256?(he[ye++]=204,he[ye++]=e):e<65536?(he[ye++]=205,he[ye++]=e>>8,he[ye++]=255&e):(he[ye++]=206,pe.setUint32(ye,e),ye+=4);else if(e>>0===e)e>=-32?he[ye++]=256+e:e>=-128?(he[ye++]=208,he[ye++]=e+256):e>=-32768?(he[ye++]=209,pe.setInt16(ye,e),ye+=2):(he[ye++]=210,pe.setInt32(ye,e),ye+=4);else{let t;if((t=this.useFloat32)>0&&e<4294967296&&e>=-2147483648){let r;if(he[ye++]=202,pe.setFloat32(ye,e),t<4||(r=e*G[(127&he[ye])<<1|he[ye+1]>>7])>>0===r)return void(ye+=4);ye--}he[ye++]=203,pe.setFloat64(ye,e),ye+=8}else if("object"===n||"function"===n)if(e){if(i){let r=i.get(e);if(r){if(!r.id){let e=i.idsToInsert||(i.idsToInsert=[]);r.id=e.push(r)}return he[ye++]=214,he[ye++]=112,pe.setUint32(ye,r.id),void(ye+=4)}i.set(e,{offset:ye-t})}let s=e.constructor;if(s===Object)E(e);else if(s===Array)b(e);else if(s===Map)if(this.mapAsEmptyObject)he[ye++]=128;else{(r=e.size)<16?he[ye++]=128|r:r<65536?(he[ye++]=222,he[ye++]=r>>8,he[ye++]=255&r):(he[ye++]=223,pe.setUint32(ye,r),ye+=4);for(let[t,r]of e)m(t),m(r)}else{for(let t=0,r=ie.length;t<r;t++){if(e instanceof se[t]){let r=ie[t];if(r.write){r.type&&(he[ye++]=212,he[ye++]=r.type,he[ye++]=0);let t=r.write.call(this,e);return void(t===e?Array.isArray(e)?b(e):E(e):m(t))}let n,i=he,s=pe,o=ye;he=null;try{n=r.pack.call(this,e,(e=>(he=i,i=null,ye+=e,ye>de&&I(ye),{target:he,targetView:pe,position:ye-e})),m)}finally{i&&(he=i,pe=s,ye=o,de=he.length-10)}return void(n&&(n.length+ye>de&&I(n.length+ye),ye=Ee(n,he,ye,r.type)))}}if(Array.isArray(e))b(e);else{if(e.toJSON){const t=e.toJSON();if(t!==e)return m(t)}if("function"===n)return m(this.writeFunction&&this.writeFunction(e));E(e)}}}else he[ye++]=192;else if("boolean"===n)he[ye++]=e?195:194;else if("bigint"===n){if(e<0x8000000000000000&&e>=-0x8000000000000000)he[ye++]=211,pe.setBigInt64(ye,e);else if(e<0x10000000000000000&&e>0)he[ye++]=207,pe.setBigUint64(ye,e);else{if(!this.largeBigIntToFloat){if(this.largeBigIntToString)return m(e.toString());if(this.useBigIntExtension||this.moreTypes){let t,r=e<0?BigInt(-1):BigInt(0);if(e>>BigInt(65536)===r){let n=BigInt(0x10000000000000000)-BigInt(1),i=[];for(;i.push(e&n),e>>BigInt(63)!==r;)e>>=BigInt(64);t=new Uint8Array(new BigUint64Array(i).buffer),t.reverse()}else{let r=e<0,n=(r?~e:e).toString(16);if(n.length%2?n="0"+n:parseInt(n.charAt(0),16)>=8&&(n="00"+n),ue)t=Buffer.from(n,"hex");else{t=new Uint8Array(n.length/2);for(let e=0;e<t.length;e++)t[e]=parseInt(n.slice(2*e,2*e+2),16)}if(r)for(let e=0;e<t.length;e++)t[e]=~t[e]}return t.length+ye>de&&I(t.length+ye),void(ye=Ee(t,he,ye,66))}throw new RangeError(e+" was too large to fit in MessagePack 64-bit integer format, use useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set largeBigIntToString to convert to string")}he[ye++]=203,pe.setFloat64(ye,Number(e))}ye+=8}else{if("undefined"!==n)throw new Error("Unknown type: "+n);this.encodeUndefinedAsNil?he[ye++]=192:(he[ye++]=212,he[ye++]=0,he[ye++]=0)}},S=this.variableMapSize||this.coercibleKeyAsNumber||this.skipValues?e=>{let t;if(this.skipValues){t=[];for(let r in e)"function"==typeof e.hasOwnProperty&&!e.hasOwnProperty(r)||this.skipValues.includes(e[r])||t.push(r)}else t=Object.keys(e);let r,n=t.length;if(n<16?he[ye++]=128|n:n<65536?(he[ye++]=222,he[ye++]=n>>8,he[ye++]=255&n):(he[ye++]=223,pe.setUint32(ye,n),ye+=4),this.coercibleKeyAsNumber)for(let i=0;i<n;i++){r=t[i];let n=Number(r);m(isNaN(n)?r:n),m(e[r])}else for(let i=0;i<n;i++)m(r=t[i]),m(e[r])}:e=>{he[ye++]=222;let r=ye-t;ye+=2;let n=0;for(let t in e)("function"!=typeof e.hasOwnProperty||e.hasOwnProperty(t))&&(m(t),m(e[t]),n++);if(n>65535)throw new Error('Object is too large to serialize with fast 16-bit map size, use the "variableMapSize" option to serialize this object');he[r+++t]=n>>8,he[r+t]=255&n},A=!1===this.useRecords?S:e.progressiveRecords&&!c?e=>{let r,i,s=n.transitions||(n.transitions=Object.create(null)),o=ye++-t;for(let a in e)if("function"!=typeof e.hasOwnProperty||e.hasOwnProperty(a)){if(r=s[a],r)s=r;else{let u=Object.keys(e),l=s;s=n.transitions;let f=0;for(let e=0,t=u.length;e<t;e++){let t=u[e];r=s[t],r||(r=s[t]=Object.create(null),f++),s=r}o+t+1==ye?(ye--,k(s,u,f)):v(s,u,o,f),i=!0,s=l[a]}m(e[a])}if(!i){let r=s[me];r?he[o+t]=r:v(s,Object.keys(e),o,0)}}:e=>{let t,r=n.transitions||(n.transitions=Object.create(null)),i=0;for(let n in e)("function"!=typeof e.hasOwnProperty||e.hasOwnProperty(n))&&(t=r[n],t||(t=r[n]=Object.create(null),i++),r=t);let s=r[me];s?s>=96&&c?(he[ye++]=96+(31&(s-=96)),he[ye++]=s>>5):he[ye++]=s:k(r,r.__keys__||Object.keys(e),i);for(let t in e)("function"!=typeof e.hasOwnProperty||e.hasOwnProperty(t))&&m(e[t])},U="function"==typeof this.useRecords&&this.useRecords,E=U?e=>{U(e)?A(e):S(e)}:A,I=e=>{let r;if(e>16777216){if(e-t>ce)throw new Error("Packed buffer would be larger than maximum buffer size");r=Math.min(ce,4096*Math.round(Math.max((e-t)*(e>67108864?1.25:2),4194304)/4096))}else r=1+(Math.max(e-t<<2,he.length-1)>>12)<<12;let n=new le(r);return pe=n.dataView||(n.dataView=new DataView(n.buffer,0,r)),e=Math.min(e,he.length),he.copy?he.copy(n,0,t,e):n.set(he.slice(t,e)),ye-=t,t=0,de=n.length-10,he=n},k=(e,t,i)=>{let s=n.nextId;s||(s=64),s<h&&this.shouldShareStructure&&!this.shouldShareStructure(t)?(s=n.nextOwnId,s<g||(s=h),n.nextOwnId=s+1):(s>=g&&(s=h),n.nextId=s+1);let o=t.highByte=s>=96&&c?s-96>>5:-1;e[me]=s,e.__keys__=t,n[s-64]=t,s<h?(t.isShared=!0,n.sharedLength=s-63,r=!0,o>=0?(he[ye++]=96+(31&s),he[ye++]=o):he[ye++]=s):(o>=0?(he[ye++]=213,he[ye++]=114,he[ye++]=96+(31&s),he[ye++]=o):(he[ye++]=212,he[ye++]=114,he[ye++]=s),i&&(d+=y*i),p.length>=f&&(p.shift()[me]=0),p.push(e),m(t))},v=(e,r,n,i)=>{let s=he,o=ye,a=de,u=t;he=ge,ye=0,t=0,he||(ge=he=new le(8192)),de=he.length-10,k(e,r,i),ge=he;let l=ye;if(he=s,ye=o,de=a,t=u,l>1){let e=ye+l-1;e>de&&I(e);let r=n+t;he.copyWithin(r+l,r+1,ye),he.set(ge.slice(0,l),r),ye=e}else he[n+t]=ge[0]},B=e=>{let i=undefined(e,he,t,ye,n,I,((e,t,n)=>{if(n)return r=!0;ye=t;let i=he;return m(e),w(),i!==he?{position:ye,targetView:pe,target:he}:ye}),this);if(0===i)return E(e);ye=i}}useBuffer(e){he=e,he.dataView||(he.dataView=new DataView(he.buffer,he.byteOffset,he.byteLength)),pe=he.dataView,ye=0}set position(e){ye=e}get position(){return ye}clearSharedData(){this.structures&&(this.structures=[]),this.typedStructs&&(this.typedStructs=[])}}function Ae(e,t,r,n){let i=e.byteLength;if(i+1<256){var{target:s,position:o}=r(4+i);s[o++]=199,s[o++]=i+1}else if(i+1<65536){var{target:s,position:o}=r(5+i);s[o++]=200,s[o++]=i+1>>8,s[o++]=i+1&255}else{var{target:s,position:o,targetView:a}=r(7+i);s[o++]=201,a.setUint32(o,i+1),o+=4}s[o++]=116,s[o++]=t,e.buffer||(e=new Uint8Array(e)),s.set(new Uint8Array(e.buffer,e.byteOffset,e.byteLength),o)}function Ue(e,t){let r=e.byteLength;var n,i;if(r<256){var{target:n,position:i}=t(r+2);n[i++]=196,n[i++]=r}else if(r<65536){var{target:n,position:i}=t(r+3);n[i++]=197,n[i++]=r>>8,n[i++]=255&r}else{var{target:n,position:i,targetView:s}=t(r+5);n[i++]=198,s.setUint32(i,r),i+=4}n.set(e,i)}function Ee(e,t,r,n){let i=e.length;switch(i){case 1:t[r++]=212;break;case 2:t[r++]=213;break;case 4:t[r++]=214;break;case 8:t[r++]=215;break;case 16:t[r++]=216;break;default:i<256?(t[r++]=199,t[r++]=i):i<65536?(t[r++]=200,t[r++]=i>>8,t[r++]=255&i):(t[r++]=201,t[r++]=i>>24,t[r++]=i>>16&255,t[r++]=i>>8&255,t[r++]=255&i)}return t[r++]=n,t.set(e,r),r+=i}function Ie(e,t,r){if(we.length>0){pe.setUint32(we.position+e,ye+r-we.position-e),we.stringsPosition=ye-e;let n=we;we=null,t(n[0]),t(n[1])}}se=[Date,Set,Error,RegExp,ArrayBuffer,Object.getPrototypeOf(Uint8Array.prototype).constructor,DataView,d],ie=[{pack(e,t,r){let n=e.getTime()/1e3;if((this.useTimestamp32||0===e.getMilliseconds())&&n>=0&&n<4294967296){let{target:e,targetView:r,position:i}=t(6);e[i++]=214,e[i++]=255,r.setUint32(i,n)}else if(n>0&&n<4294967296){let{target:r,targetView:i,position:s}=t(10);r[s++]=215,r[s++]=255,i.setUint32(s,4e6*e.getMilliseconds()+(n/1e3/4294967296>>0)),i.setUint32(s+4,n)}else if(isNaN(n)){if(this.onInvalidDate)return t(0),r(this.onInvalidDate());let{target:e,targetView:n,position:i}=t(3);e[i++]=212,e[i++]=255,e[i++]=255}else{let{target:r,targetView:i,position:s}=t(15);r[s++]=199,r[s++]=12,r[s++]=255,i.setUint32(s,1e6*e.getMilliseconds()),i.setBigInt64(s+4,BigInt(Math.floor(n)))}}},{pack(e,t,r){if(this.setAsEmptyObject)return t(0),r({});let n=Array.from(e),{target:i,position:s}=t(this.moreTypes?3:0);this.moreTypes&&(i[s++]=212,i[s++]=115,i[s++]=0),r(n)}},{pack(e,t,r){let{target:n,position:i}=t(this.moreTypes?3:0);this.moreTypes&&(n[i++]=212,n[i++]=101,n[i++]=0),r([e.name,e.message,e.cause])}},{pack(e,t,r){let{target:n,position:i}=t(this.moreTypes?3:0);this.moreTypes&&(n[i++]=212,n[i++]=120,n[i++]=0),r([e.source,e.flags])}},{pack(e,t){this.moreTypes?Ae(e,16,t):Ue(ue?Buffer.from(e):new Uint8Array(e),t)}},{pack(e,t){let r=e.constructor;r!==fe&&this.moreTypes?Ae(e,$.indexOf(r.name),t):Ue(e,t)}},{pack(e,t){this.moreTypes?Ae(e,17,t):Ue(ue?Buffer.from(e):new Uint8Array(e),t)}},{pack(e,t){let{target:r,position:n}=t(1);r[n]=193}}];let ke=new Se({useRecords:!1});const ve=ke.pack,Be=ke.pack,Oe=Se,{NEVER:_e,ALWAYS:xe,DECIMAL_ROUND:Te,DECIMAL_FIT:Me}=re,je=512,Re=1024,De=2048;const Ve=function(e,t={}){if(!e||"object"!=typeof e)throw new Error("first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a promise");const r=new m(t);let n;const i=e=>{let t;n&&(e=Buffer.concat([n,e]),n=void 0);try{t=r.unpackMultiple(e)}catch(r){if(!r.incomplete)throw r;n=e.slice(r.lastPosition),t=r.values}return t};return"function"==typeof e[Symbol.iterator]?function*(){for(const t of e)yield*i(t)}():"function"==typeof e[Symbol.asyncIterator]?async function*(){for await(const t of e)yield*i(t)}():void 0},Le=function(e,t={}){if(e&&"object"==typeof e){if("function"==typeof e[Symbol.iterator])return function*(e,t){const r=new Se(t);for(const t of e)yield r.pack(t)}(e,t);if("function"==typeof e.then||"function"==typeof e[Symbol.asyncIterator])return async function*(e,t){const r=new Se(t);for await(const t of e)yield r.pack(t)}(e,t);throw new Error("first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a Promise")}throw new Error("first argument must be an Iterable, Async Iterable, or a Promise for an Async Iterable")};e.ALWAYS=xe,e.C1=y,e.DECIMAL_FIT=Me,e.DECIMAL_ROUND=Te,e.Decoder=H,e.Encoder=Oe,e.FLOAT32_OPTIONS=re,e.NEVER=_e,e.Packr=Se,e.RESERVE_START_SPACE=De,e.RESET_BUFFER_MODE=Re,e.REUSE_BUFFER_MODE=je,e.Unpackr=m,e.addExtension=function(e){if(e.Class){if(!e.pack&&!e.write)throw new Error("Extension has no pack or write function");if(e.pack&&!e.type)throw new Error("Extension has no type (numeric code to identify the extension)");se.unshift(e.Class),ie.unshift(e)}!function(e){e.unpack?g[e.type]=e.unpack:g[e.type]=e}(e)},e.clearSource=Z,e.decode=te,e.decodeIter=Ve,e.encode=Be,e.encodeIter=Le,e.isNativeAccelerationEnabled=!1,e.mapsAsObjects=!0,e.pack=ve,e.roundFloat32=function(e){oe[0]=e;let t=G[(127&ae[3])<<1|ae[2]>>7];return(t*e+(e>0?.5:-.5)>>0)/t},e.unpack=X,e.unpackMultiple=ee,e.useRecords=!1}));
2
  //# sourceMappingURL=index.min.js.map
 
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).msgpackr={})}(this,function(e){"use strict";var t,r,n;try{t=new TextDecoder}catch(e){}var i,s,o,a,u,l=0,f={},c=0,h=0,g=[],p={useRecords:!1,mapsAsObjects:!0};class d{}const y=new d;y.name="MessagePack 0xC1";var w=!1,b=2;class S{constructor(e){e&&(!1===e.useRecords&&void 0===e.mapsAsObjects&&(e.mapsAsObjects=!0),e.sequential&&!1!==e.trusted&&(e.trusted=!0,e.structures||0==e.useRecords||(e.structures=[],e.maxSharedStructures||(e.maxSharedStructures=0))),e.structures?e.structures.sharedLength=e.structures.length:e.getStructures&&((e.structures=[]).uninitialized=!0,e.structures.sharedLength=0),e.int64AsNumber&&(e.int64AsType="number")),Object.assign(this,e)}unpack(e,t){if(r)return q(()=>(H(),this?this.unpack(e,t):S.prototype.unpack.call(p,e,t)));e.buffer||e.constructor!==ArrayBuffer||(e="undefined"!=typeof Buffer?Buffer.from(e):new Uint8Array(e)),"object"==typeof t?(n=t.end||e.length,l=t.start||0):(l=0,n=t>-1?t:e.length),h=0,s=null,o=null,r=e;try{u=e.dataView||(e.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength))}catch(t){if(r=null,e instanceof Uint8Array)throw t;throw new Error("Source must be a Uint8Array or Buffer but was a "+(e&&"object"==typeof e?e.constructor.name:typeof e))}if(this instanceof S){if(f=this,this.structures)return i=this.structures,m(t);(!i||i.length>0)&&(i=[])}else f=p,(!i||i.length>0)&&(i=[]);return m(t)}unpackMultiple(e,t){let r,n=0;try{w=!0;let i=e.length,s=this?this.unpack(e,i):Q.unpack(e,i);if(!t){for(r=[s];l<i;)n=l,r.push(m());return r}if(!1===t(s,n,l))return;for(;l<i;)if(n=l,!1===t(m(),n,l))return}catch(e){throw e.lastPosition=n,e.values=r,e}finally{w=!1,H()}}_mergeStructures(e,t){this._onLoadedStructures&&(e=this._onLoadedStructures(e)),e=e||[],Object.isFrozen(e)&&(e=e.map(e=>e.slice(0)));for(let t=0,r=e.length;t<r;t++){let r=e[t];r&&(r.isShared=!0,t>=32&&(r.highByte=t-32>>5))}e.sharedLength=e.length;for(let r in t||[])if(r>=0){let n=e[r],i=t[r];i&&(n&&((e.restoreStructures||(e.restoreStructures=[]))[r]=n),e[r]=i)}return this.structures=e}decode(e,t){return this.unpack(e,t)}}function m(e){try{if(!f.trusted&&!w){let e=i.sharedLength||0;e<i.length&&(i.length=e)}let t;if(f._readStruct&&r[l]<64&&r[l]>=32?(t=f._readStruct(r,l,n),r=null,e&&e.lazy||!t||(t=t.toJSON()),l=n):t=A(),o&&(l=o.postBundlePosition,o=null),w&&(i.restoreStructures=null),l==n)i&&i.restoreStructures&&U(),i=null,r=null,a&&(a=null);else{if(l>n)throw new Error("Unexpected end of MessagePack data");if(!w){let e;try{e=JSON.stringify(t,(e,t)=>"bigint"==typeof t?`${t}n`:t).slice(0,100)}catch(t){e="(JSON view not available "+t+")"}throw new Error("Data read, but end of buffer not reached "+e)}}return t}catch(e){throw i&&i.restoreStructures&&U(),H(),(e instanceof RangeError||e.message.startsWith("Unexpected end of buffer")||l>n)&&(e.incomplete=!0),e}}function U(){for(let e in i.restoreStructures)i[e]=i.restoreStructures[e];i.restoreStructures=null}function A(){let e=r[l++];if(e<160){if(e<128){if(e<64)return e;{let t=i[63&e]||f.getStructures&&v()[63&e];return t?(t.read||(t.read=I(t,63&e)),t.read()):e}}if(e<144){if(e-=128,f.mapsAsObjects){let t={};for(let r=0;r<e;r++){let e=z();"__proto__"===e&&(e="__proto_"),t[e]=A()}return t}{let t=new Map;for(let r=0;r<e;r++)t.set(A(),A());return t}}{e-=144;let t=new Array(e);for(let r=0;r<e;r++)t[r]=A();return f.freezeData?Object.freeze(t):t}}if(e<192){let t=e-160;if(h>=l)return s.slice(l-c,(l+=t)-c);if(0==h&&n<140){let e=t<16?D(t):L(t);if(null!=e)return e}return _(t)}{let t;switch(e){case 192:return null;case 193:return o?(t=A(),t>0?o[1].slice(o.position1,o.position1+=t):o[0].slice(o.position0,o.position0-=t)):y;case 194:return!1;case 195:return!0;case 196:if(t=r[l++],void 0===t)throw new Error("Unexpected end of buffer");return P(t);case 197:return t=u.getUint16(l),l+=2,P(t);case 198:return t=u.getUint32(l),l+=4,P(t);case 199:return N(r[l++]);case 200:return t=u.getUint16(l),l+=2,N(t);case 201:return t=u.getUint32(l),l+=4,N(t);case 202:if(t=u.getFloat32(l),f.useFloat32>2){let e=Z[(127&r[l])<<1|r[l+1]>>7];return l+=4,(e*t+(t>0?.5:-.5)|0)/e}return l+=4,t;case 203:return t=u.getFloat64(l),l+=8,t;case 204:return r[l++];case 205:return t=u.getUint16(l),l+=2,t;case 206:return t=u.getUint32(l),l+=4,t;case 207:return"number"===f.int64AsType?(t=4294967296*u.getUint32(l),t+=u.getUint32(l+4)):"string"===f.int64AsType?t=u.getBigUint64(l).toString():"auto"===f.int64AsType?(t=u.getBigUint64(l),t<=BigInt(2)<<BigInt(52)&&(t=Number(t))):t=u.getBigUint64(l),l+=8,t;case 208:return u.getInt8(l++);case 209:return t=u.getInt16(l),l+=2,t;case 210:return t=u.getInt32(l),l+=4,t;case 211:return"number"===f.int64AsType?(t=4294967296*u.getInt32(l),t+=u.getUint32(l+4)):"string"===f.int64AsType?t=u.getBigInt64(l).toString():"auto"===f.int64AsType?(t=u.getBigInt64(l),t>=BigInt(-2)<<BigInt(52)&&t<=BigInt(2)<<BigInt(52)&&(t=Number(t))):t=u.getBigInt64(l),l+=8,t;case 212:if(t=r[l++],114==t)return W(63&r[l++]);{let e=g[t];if(e)return e.read?(l++,e.read(A())):e.noBuffer?(l++,e()):e(r.subarray(l,++l));throw new Error("Unknown extension "+t)}case 213:return t=r[l],114==t?(l++,W(63&r[l++],r[l++])):N(2);case 214:return N(4);case 215:return N(8);case 216:return N(16);case 217:return t=r[l++],h>=l?s.slice(l-c,(l+=t)-c):k(t);case 218:return t=u.getUint16(l),h>=(l+=2)?s.slice(l-c,(l+=t)-c):B(t);case 219:return t=u.getUint32(l),h>=(l+=4)?s.slice(l-c,(l+=t)-c):x(t);case 220:return t=u.getUint16(l),l+=2,M(t);case 221:return t=u.getUint32(l),l+=4,M(t);case 222:return t=u.getUint16(l),l+=2,R(t);case 223:return t=u.getUint32(l),l+=4,R(t);default:if(e>=224)return e-256;if(void 0===e){let e=new Error("Unexpected end of MessagePack data");throw e.incomplete=!0,e}throw new Error("Unknown MessagePack token "+e)}}}const E=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function I(e,t){function r(){if(r.count++>b){let n;try{n=e.read=new Function("r","return function(){return "+(f.freezeData?"Object.freeze":"")+"({"+e.map(e=>"__proto__"===e?"__proto_:r()":E.test(e)?e+":r()":"["+JSON.stringify(e)+"]:r()").join(",")+"})}")(A)}catch(e){return b=1/0,r()}return e.read0=n,0===e.highByte&&(e.read=O(t,e.read)),n()}let n={};for(let t=0,r=e.length;t<r;t++){let r=e[t];"__proto__"===r&&(r="__proto_"),n[r]=A()}return f.freezeData?Object.freeze(n):n}return r.count=0,e.read0=r,0===e.highByte?O(t,r):r}const O=(e,t)=>function(){let n=r[l++];if(0===n)return t();let s=e<32?-(e+(n<<5)):e+(n<<5),o=i[s]||v()[s];if(!o)throw new Error("Record id is not defined for "+s);return o.read||(o.read=I(o,e)),o.read()};function v(){let e=q(()=>(r=null,f.getStructures()));return i=f._mergeStructures(e,i)}var _=T,k=T,B=T,x=T;function T(e){let n;if(e<16&&(n=D(e)))return n;if(e>64&&t)return t.decode(r.subarray(l,l+=e));const i=l+e,s=[];for(n="";l<i;){const e=r[l++];if(128&e)if(192==(224&e))if(e<194||l>=i||128!=(192&r[l]))s.push(65533);else{const t=63&r[l++];s.push((31&e)<<6|t)}else if(224==(240&e)){const t=l<i?r[l]:0;if(l>=i||128!=(192&t)||224===e&&t<160||237===e&&t>=160)s.push(65533);else if(++l>=i||128!=(192&r[l]))s.push(65533);else{const n=63&r[l++];s.push((31&e)<<12|(63&t)<<6|n)}}else if(240==(248&e)){const t=l<i?r[l]:0;if(e>244||l>=i||128!=(192&t)||240===e&&t<144||244===e&&t>=144)s.push(65533);else if(++l>=i||128!=(192&r[l]))s.push(65533);else{const n=63&r[l++];if(l>=i||128!=(192&r[l]))s.push(65533);else{let i=(7&e)<<18|(63&t)<<12|n<<6|63&r[l++];i-=65536,s.push(i>>>10&1023|55296),s.push(56320|1023&i)}}}else s.push(65533);else s.push(e);s.length>=4096&&(n+=j.apply(String,s),s.length=0)}return s.length>0&&(n+=j.apply(String,s)),n}function M(e){let t=new Array(e);for(let r=0;r<e;r++)t[r]=A();return f.freezeData?Object.freeze(t):t}function R(e){if(f.mapsAsObjects){let t={};for(let r=0;r<e;r++){let e=z();"__proto__"===e&&(e="__proto_"),t[e]=A()}return t}{let t=new Map;for(let r=0;r<e;r++)t.set(A(),A());return t}}var j=String.fromCharCode;function L(e){let t=l,n=new Array(e);for(let i=0;i<e;i++){const e=r[l++];if((128&e)>0)return void(l=t);n[i]=e}return j.apply(String,n)}function D(e){if(e<4){if(e<2){if(0===e)return"";{let e=r[l++];return(128&e)>1?void(l-=1):j(e)}}{let t=r[l++],n=r[l++];if((128&t)>0||(128&n)>0)return void(l-=2);if(e<3)return j(t,n);let i=r[l++];return(128&i)>0?void(l-=3):j(t,n,i)}}{let t=r[l++],n=r[l++],i=r[l++],s=r[l++];if((128&t)>0||(128&n)>0||(128&i)>0||(128&s)>0)return void(l-=4);if(e<6){if(4===e)return j(t,n,i,s);{let e=r[l++];return(128&e)>0?void(l-=5):j(t,n,i,s,e)}}if(e<8){let o=r[l++],a=r[l++];if((128&o)>0||(128&a)>0)return void(l-=6);if(e<7)return j(t,n,i,s,o,a);let u=r[l++];return(128&u)>0?void(l-=7):j(t,n,i,s,o,a,u)}{let o=r[l++],a=r[l++],u=r[l++],f=r[l++];if((128&o)>0||(128&a)>0||(128&u)>0||(128&f)>0)return void(l-=8);if(e<10){if(8===e)return j(t,n,i,s,o,a,u,f);{let e=r[l++];return(128&e)>0?void(l-=9):j(t,n,i,s,o,a,u,f,e)}}if(e<12){let c=r[l++],h=r[l++];if((128&c)>0||(128&h)>0)return void(l-=10);if(e<11)return j(t,n,i,s,o,a,u,f,c,h);let g=r[l++];return(128&g)>0?void(l-=11):j(t,n,i,s,o,a,u,f,c,h,g)}{let c=r[l++],h=r[l++],g=r[l++],p=r[l++];if((128&c)>0||(128&h)>0||(128&g)>0||(128&p)>0)return void(l-=12);if(e<14){if(12===e)return j(t,n,i,s,o,a,u,f,c,h,g,p);{let e=r[l++];return(128&e)>0?void(l-=13):j(t,n,i,s,o,a,u,f,c,h,g,p,e)}}{let d=r[l++],y=r[l++];if((128&d)>0||(128&y)>0)return void(l-=14);if(e<15)return j(t,n,i,s,o,a,u,f,c,h,g,p,d,y);let w=r[l++];return(128&w)>0?void(l-=15):j(t,n,i,s,o,a,u,f,c,h,g,p,d,y,w)}}}}}function V(){let e,t=r[l++];if(t<192)e=t-160;else switch(t){case 217:e=r[l++];break;case 218:e=u.getUint16(l),l+=2;break;case 219:e=u.getUint32(l),l+=4;break;default:throw new Error("Expected string")}return T(e)}function P(e){return f.copyBuffers?Uint8Array.prototype.slice.call(r,l,l+=e):r.subarray(l,l+=e)}function N(e){let t=r[l++];if(g[t]){let n;return g[t](r.subarray(l,n=l+=e),e=>{l=e;try{return A()}finally{l=n}})}throw new Error("Unknown extension type "+t)}var F=new Array(4096);function z(){let e=r[l++];if(!(e>=160&&e<192))return l--,C(A());if(e-=160,h>=l)return s.slice(l-c,(l+=e)-c);if(!(0==h&&n<180))return _(e);let t,i=4095&(e<<5^(e>1?u.getUint16(l):e>0?r[l]:0)),o=F[i],a=l,f=l+e-3,g=0;if(o&&o.bytes==e){for(;a<f;){if(t=u.getUint32(a),t!=o[g++]){a=1879048192;break}a+=4}for(f+=3;a<f;)if(t=r[a++],t!=o[g++]){a=1879048192;break}if(a===f)return l=a,o.string;f-=3,a=l}for(o=[],F[i]=o,o.bytes=e;a<f;)t=u.getUint32(a),o.push(t),a+=4;for(f+=3;a<f;)t=r[a++],o.push(t);let p=e<16?D(e):L(e);return o.string=null!=p?p:_(e)}function C(e){if("string"==typeof e)return e;if("number"==typeof e||"boolean"==typeof e||"bigint"==typeof e)return e.toString();if(null==e)return e+"";if(f.allowArraysInMapKeys&&Array.isArray(e)&&e.flat().every(e=>["string","number","boolean","bigint"].includes(typeof e)))return e.flat().toString();throw new Error("Invalid property type for record: "+typeof e)}const W=(e,t)=>{let r=A().map(C),n=e;void 0!==t&&(e=e<32?-((t<<5)+e):(t<<5)+e,r.highByte=t);let s=i[e];return s&&(s.isShared||w)&&((i.restoreStructures||(i.restoreStructures=[]))[e]=s),i[e]=r,r.read=I(r,n),(r.read0||r.read)()};g[0]=()=>{},g[0].noBuffer=!0,g[66]=e=>{let t=e.byteLength%8||8,r=BigInt(128&e[0]?e[0]-256:e[0]);for(let n=1;n<t;n++)r<<=BigInt(8),r+=BigInt(e[n]);if(e.byteLength!==t){let n=new DataView(e.buffer,e.byteOffset,e.byteLength),i=(e,t)=>{let r=t-e;if(r<=40){let r=n.getBigUint64(e);for(let i=e+8;i<t;i+=8)r<<=BigInt(64),r|=n.getBigUint64(i);return r}let s=e+(r>>4<<3),o=i(e,s),a=i(s,t);return o<<BigInt(8*(t-s))|a};r=r<<BigInt(8*(n.byteLength-t))|i(t,n.byteLength)}return r};let J={Error:Error,EvalError:EvalError,RangeError:RangeError,ReferenceError:ReferenceError,SyntaxError:SyntaxError,TypeError:TypeError,URIError:URIError,AggregateError:"function"==typeof AggregateError?AggregateError:null};g[101]=()=>{let e=A();if(!J[e[0]]){let t=Error(e[1],{cause:e[2]});return t.name=e[0],t}return J[e[0]](e[1],{cause:e[2]})},g[105]=e=>{if(!1===f.structuredClone)throw new Error("Structured clone extension is disabled");let t=u.getUint32(l-4);a||(a=new Map);let n,i=r[l];n=i>=144&&i<160||220==i||221==i?[]:i>=128&&i<144||222==i||223==i?new Map:(i>=199&&i<=201||i>=212&&i<=216)&&115===r[l+1]?new Set:{};let s={target:n};a.set(t,s);let o=A();if(!s.used)return s.target=o;if(Object.assign(n,o),n instanceof Map)for(let[e,t]of o.entries())n.set(e,t);if(n instanceof Set)for(let e of Array.from(o))n.add(e);return n},g[112]=e=>{if(!1===f.structuredClone)throw new Error("Structured clone extension is disabled");let t=u.getUint32(l-4),r=a.get(t);return r.used=!0,r.target},g[115]=()=>new Set(A());const K=["Int8","Uint8","Uint8Clamped","Int16","Uint16","Int32","Uint32","Float32","Float64","BigInt64","BigUint64"].map(e=>e+"Array");let $="object"==typeof globalThis?globalThis:window;g[116]=e=>{let t=e[0],r=Uint8Array.prototype.slice.call(e,1).buffer,n=K[t];if(!n){if(16===t)return r;if(17===t)return new DataView(r);throw new Error("Could not find typed array for code "+t)}return new $[n](r)},g[120]=()=>{let e=A();return new RegExp(e[0],e[1])};const Y=[];function q(e){f&&f._onSaveState&&f._onSaveState();let t=n,g=l,p=c,d=h,y=s,b=a,S=o,m=new Uint8Array(r.slice(0,n)),U=i,A=i.slice(0,i.length),E=f,I=w,O=e();return n=t,l=g,c=p,h=d,s=y,a=b,o=S,r=m,w=I,(i=U).splice(0,i.length,...A),f=E,u=new DataView(r.buffer,r.byteOffset,r.byteLength),O}function H(){r=null,a=null,i=null}g[98]=e=>{let t=(e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3],r=l;return l+=t-e.length,o=Y,(o=[V(),V()]).position0=0,o.position1=0,o.postBundlePosition=l,l=r,A()},g[255]=e=>4==e.length?new Date(1e3*(16777216*e[0]+(e[1]<<16)+(e[2]<<8)+e[3])):8==e.length?new Date(((e[0]<<22)+(e[1]<<14)+(e[2]<<6)+(e[3]>>2))/1e6+1e3*(4294967296*(3&e[3])+16777216*e[4]+(e[5]<<16)+(e[6]<<8)+e[7])):12==e.length?new Date(((e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3])/1e6+1e3*((128&e[4]?-281474976710656:0)+1099511627776*e[6]+4294967296*e[7]+16777216*e[8]+(e[9]<<16)+(e[10]<<8)+e[11])):new Date("invalid");const Z=new Array(147);for(let e=0;e<256;e++)Z[e]=+("1e"+Math.floor(45.15-.30103*e));const G=S;var Q=new S({useRecords:!1});const X=Q.unpack,ee=Q.unpackMultiple,te=Q.unpack,re={NEVER:0,ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4};let ne,ie,se,oe=new Float32Array(1),ae=new Uint8Array(oe.buffer,0,4);S.SUPPORTS_STRUCT_HOOKS=!0;try{ne=new TextEncoder}catch(e){}const ue="undefined"!=typeof Buffer,le=ue?function(e){return Buffer.allocUnsafeSlow(e)}:Uint8Array,fe=ue?Buffer:Uint8Array,ce=ue?4294967296:2144337920;let he,ge,pe,de,ye=0,we=null;const be=/[\u0080-\uFFFF]/,Se=Symbol("record-id");class me extends S{constructor(e){let t,r,n,i;super(e),this.offset=0;let s=fe.prototype.utf8Write?function(e,t){return he.utf8Write(e,t,he.byteLength-t)}:!(!ne||!ne.encodeInto)&&function(e,t){return ne.encodeInto(e,he.subarray(t)).written},o=this;e||(e={});let a=e&&e.sequential,u=e.structures||e.saveStructures,l=e.maxSharedStructures;if(null==l&&(l=u?32:0),l>8160)throw new Error("Maximum maxSharedStructure is 8160");e.structuredClone&&null==e.moreTypes&&(this.moreTypes=!0);let f=e.maxOwnStructures;null==f&&(f=u?32:64),this.structures||0==e.useRecords||(this.structures=[]);let c=l>32||f+l>64,h=l+64,g=l+f+64;if(g>8256)throw new Error("Maximum maxSharedStructure + maxOwnStructure is 8192");let p=[],d=0,y=0;this.pack=this.encode=function(e,s){if(he||(he=new le(8192),pe=he.dataView||(he.dataView=new DataView(he.buffer,0,8192)),ye=0),de=he.length-10,de-ye<2048?(he=new le(he.length),pe=he.dataView||(he.dataView=new DataView(he.buffer,0,he.length)),de=he.length-10,ye=0):ye=ye+7&2147483640,t=ye,s&De&&(ye+=255&s),i=o.structuredClone?new Map:null,o.bundleStrings&&"string"!=typeof e?(we=[],we.size=1/0):we=null,n=o.structures,n){n.uninitialized&&(n=o._mergeStructures(o.getStructures()));let e=n.sharedLength||0;if(e>l)throw new Error("Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to "+n.sharedLength);if(!n.transitions){n.transitions=Object.create(null);for(let t=0;t<e;t++){let e=n[t];if(!e)continue;let r,i=n.transitions;for(let t=0,n=e.length;t<n;t++){let n=e[t];r=i[n],r||(r=i[n]=Object.create(null)),i=r}i[Se]=t+64}this.lastNamedStructuresLength=e}a||(n.nextId=e+64)}let u;r&&(r=!1);try{o._writeStruct&&e&&"object"==typeof e?e.constructor===Object?I(e):e.constructor===Map||Array.isArray(e)||se.some(t=>e instanceof t)?S(e):I(e.toJSON?e.toJSON():e):S(e);let r=we;if(we&&Ie(t,S,0),i&&i.idsToInsert){let e=i.idsToInsert.sort((e,t)=>e.offset>t.offset?1:-1),n=e.length,s=-1;for(;r&&n>0;){let i=e[--n].offset+t;i<r.stringsPosition+t&&-1===s&&(s=0),i>r.position+t?s>=0&&(s+=6):(s>=0&&(pe.setUint32(r.position+t,pe.getUint32(r.position+t)+s),s=-1),r=r.previous,n++)}s>=0&&r&&pe.setUint32(r.position+t,pe.getUint32(r.position+t)+s),ye+=6*e.length,ye>de&&O(ye),o.offset=ye;let a=function(e,t){let r,n=6*t.length,i=e.length-n;for(;r=t.pop();){let t=r.offset,s=r.id;e.copyWithin(t+n,t,i),n-=6;let o=t+n;e[o++]=214,e[o++]=105,e[o++]=s>>24,e[o++]=s>>16&255,e[o++]=s>>8&255,e[o++]=255&s,i=t}return e}(he.subarray(t,ye),e);return i=null,a}return o.offset=ye,s&je?(he.start=t,he.end=ye,he):he.subarray(t,ye)}catch(e){throw u=e,e}finally{if(n&&(w(),r&&o.saveStructures)){let r=n.sharedLength||0,i=he.subarray(t,ye),a=(o._prepareStructures||Oe)(n,o);if(!u)return!1===o.saveStructures(a,a.isCompatible)?(n.uninitialized=!0,o.pack(e,s)):(o.lastNamedStructuresLength=r,he.length>1073741824&&(he=null),i)}he.length>1073741824&&(he=null),s&Le&&(ye=t)}};const w=()=>{y<10&&y++;let e=n.sharedLength||0;if(n.length>e&&!a&&(n.length=e),d>1e4)n.transitions=null,y=0,d=0,p.length>0&&(p=[]);else if(p.length>0&&!a){for(let e=0,t=p.length;e<t;e++)p[e][Se]=0;p=[]}},b=e=>{var t=e.length;t<16?he[ye++]=144|t:t<65536?(he[ye++]=220,he[ye++]=t>>8,he[ye++]=255&t):(he[ye++]=221,pe.setUint32(ye,t),ye+=4);for(let r=0;r<t;r++)S(e[r])},S=e=>{ye>de&&(he=O(ye));var r,n=typeof e;if("string"===n){let n,i=e.length;if(we&&i>=4&&i<4096){if((we.size+=i)>21760){let e,r,n=(we[0]?3*we[0].length+we[1].length:0)+10;ye+n>de&&(he=O(ye+n)),we.position?(r=we,he[ye]=200,ye+=3,he[ye++]=98,e=ye-t,ye+=4,Ie(t,S,0),pe.setUint16(e+t-3,ye-t-e)):(he[ye++]=214,he[ye++]=98,e=ye-t,ye+=4),we=["",""],we.previous=r,we.size=0,we.position=e}let r=be.test(e);return we[r?0:1]+=e,he[ye++]=193,void S(r?-i:i)}n=i<32?1:i<256?2:i<65536?3:5;let o=3*i;if(ye+o>de&&(he=O(ye+o)),i<64||!s){let t,s,o,a=ye+n;for(t=0;t<i;t++)s=e.charCodeAt(t),s<128?he[a++]=s:s<2048?(he[a++]=s>>6|192,he[a++]=63&s|128):55296==(64512&s)&&56320==(64512&(o=e.charCodeAt(t+1)))?(s=65536+((1023&s)<<10)+(1023&o),t++,he[a++]=s>>18|240,he[a++]=s>>12&63|128,he[a++]=s>>6&63|128,he[a++]=63&s|128):(he[a++]=s>>12|224,he[a++]=s>>6&63|128,he[a++]=63&s|128);r=a-ye-n}else r=s(e,ye+n);r<32?he[ye++]=160|r:r<256?(n<2&&he.copyWithin(ye+2,ye+1,ye+1+r),he[ye++]=217,he[ye++]=r):r<65536?(n<3&&he.copyWithin(ye+3,ye+2,ye+2+r),he[ye++]=218,he[ye++]=r>>8,he[ye++]=255&r):(n<5&&he.copyWithin(ye+5,ye+3,ye+3+r),he[ye++]=219,pe.setUint32(ye,r),ye+=4),ye+=r}else if("number"===n)if(e>>>0===e)e<32||e<128&&!1===this.useRecords||e<64&&!this._writeStruct?he[ye++]=e:e<256?(he[ye++]=204,he[ye++]=e):e<65536?(he[ye++]=205,he[ye++]=e>>8,he[ye++]=255&e):(he[ye++]=206,pe.setUint32(ye,e),ye+=4);else if((e|0)===e)e>=-32?he[ye++]=256+e:e>=-128?(he[ye++]=208,he[ye++]=e+256):e>=-32768?(he[ye++]=209,pe.setInt16(ye,e),ye+=2):(he[ye++]=210,pe.setInt32(ye,e),ye+=4);else{let t;if((t=this.useFloat32)>0&&e<4294967296&&e>=-2147483648){let r;if(he[ye++]=202,pe.setFloat32(ye,e),t<4||((r=e*Z[(127&he[ye])<<1|he[ye+1]>>7])|0)===r)return void(ye+=4);ye--}he[ye++]=203,pe.setFloat64(ye,e),ye+=8}else if("object"===n||"function"===n)if(e){if(i){let r=i.get(e);if(r){if(!r.id){let e=i.idsToInsert||(i.idsToInsert=[]);r.id=e.push(r)}return he[ye++]=214,he[ye++]=112,pe.setUint32(ye,r.id),void(ye+=4)}i.set(e,{offset:ye-t})}let s=e.constructor;if(s===Object)E(e);else if(s===Array)b(e);else if(s===Map)if(this.mapAsEmptyObject)he[ye++]=128;else{(r=e.size)<16?he[ye++]=128|r:r<65536?(he[ye++]=222,he[ye++]=r>>8,he[ye++]=255&r):(he[ye++]=223,pe.setUint32(ye,r),ye+=4);for(let[t,r]of e)S(t),S(r)}else{for(let t=0,r=ie.length;t<r;t++){if(e instanceof se[t]){let r=ie[t];if(r.write){r.type&&(he[ye++]=212,he[ye++]=r.type,he[ye++]=0);let t=r.write.call(this,e);return void(t===e?Array.isArray(e)?b(e):E(e):S(t))}let n,i=he,s=pe,o=ye;he=null;try{n=r.pack.call(this,e,e=>(he=i,i=null,ye+=e,ye>de&&O(ye),{target:he,targetView:pe,position:ye-e}),S)}finally{i&&(he=i,pe=s,ye=o,de=he.length-10)}return void(n&&(n.length+ye>de&&O(n.length+ye),ye=Ee(n,he,ye,r.type)))}}if(Array.isArray(e))b(e);else{if(e.toJSON){const t=e.toJSON();if(t!==e)return S(t)}if("function"===n)return S(this.writeFunction&&this.writeFunction(e));E(e)}}}else he[ye++]=192;else if("boolean"===n)he[ye++]=e?195:194;else if("bigint"===n){if(e<0x8000000000000000&&e>=-0x8000000000000000)he[ye++]=211,pe.setBigInt64(ye,e);else if(e<0x10000000000000000&&e>0)he[ye++]=207,pe.setBigUint64(ye,e);else{if(!this.largeBigIntToFloat){if(this.largeBigIntToString)return S(e.toString());if(this.useBigIntExtension||this.moreTypes){let t,r=e<0?BigInt(-1):BigInt(0);if(e>>BigInt(65536)===r){let n=BigInt(0x10000000000000000)-BigInt(1),i=[];for(;i.push(e&n),e>>BigInt(63)!==r;)e>>=BigInt(64);t=new Uint8Array(new BigUint64Array(i).buffer),t.reverse()}else{let r=e<0,n=(r?~e:e).toString(16);if(n.length%2?n="0"+n:parseInt(n.charAt(0),16)>=8&&(n="00"+n),ue)t=Buffer.from(n,"hex");else{t=new Uint8Array(n.length/2);for(let e=0;e<t.length;e++)t[e]=parseInt(n.slice(2*e,2*e+2),16)}if(r)for(let e=0;e<t.length;e++)t[e]=~t[e]}return t.length+ye>de&&O(t.length+ye),void(ye=Ee(t,he,ye,66))}throw new RangeError(e+" was too large to fit in MessagePack 64-bit integer format, use useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set largeBigIntToString to convert to string")}he[ye++]=203,pe.setFloat64(ye,Number(e))}ye+=8}else{if("undefined"!==n)throw new Error("Unknown type: "+n);this.encodeUndefinedAsNil?he[ye++]=192:(he[ye++]=212,he[ye++]=0,he[ye++]=0)}},m=this.variableMapSize||this.coercibleKeyAsNumber||this.skipValues?e=>{let t;if(this.skipValues){t=[];for(let r in e)"function"==typeof e.hasOwnProperty&&!e.hasOwnProperty(r)||this.skipValues.includes(e[r])||t.push(r)}else t=Object.keys(e);let r,n=t.length;if(n<16?he[ye++]=128|n:n<65536?(he[ye++]=222,he[ye++]=n>>8,he[ye++]=255&n):(he[ye++]=223,pe.setUint32(ye,n),ye+=4),this.coercibleKeyAsNumber)for(let i=0;i<n;i++){r=t[i];let n=Number(r);S(isNaN(n)?r:n),S(e[r])}else for(let i=0;i<n;i++)S(r=t[i]),S(e[r])}:e=>{he[ye++]=222;let r=ye-t;ye+=2;let n=0;for(let t in e)("function"!=typeof e.hasOwnProperty||e.hasOwnProperty(t))&&(S(t),S(e[t]),n++);if(n>65535)throw new Error('Object is too large to serialize with fast 16-bit map size, use the "variableMapSize" option to serialize this object');he[r+++t]=n>>8,he[r+t]=255&n},U=!1===this.useRecords?m:e.progressiveRecords&&!c?e=>{let r,i,s=n.transitions||(n.transitions=Object.create(null)),o=ye++-t;for(let a in e)if("function"!=typeof e.hasOwnProperty||e.hasOwnProperty(a)){if(r=s[a],r)s=r;else{let u=Object.keys(e),l=s;s=n.transitions;let f=0;for(let e=0,t=u.length;e<t;e++){let t=u[e];r=s[t],r||(r=s[t]=Object.create(null),f++),s=r}o+t+1==ye?(ye--,v(s,u,f)):_(s,u,o,f),i=!0,s=l[a]}S(e[a])}if(!i){let r=s[Se];r?he[o+t]=r:_(s,Object.keys(e),o,0)}}:e=>{let t,r=n.transitions||(n.transitions=Object.create(null)),i=0;for(let n in e)("function"!=typeof e.hasOwnProperty||e.hasOwnProperty(n))&&(t=r[n],t||(t=r[n]=Object.create(null),i++),r=t);let s=r[Se];s?s>=96&&c?(he[ye++]=96+(31&(s-=96)),he[ye++]=s>>5):he[ye++]=s:v(r,r.__keys__||Object.keys(e),i);for(let t in e)("function"!=typeof e.hasOwnProperty||e.hasOwnProperty(t))&&S(e[t])},A="function"==typeof this.useRecords&&this.useRecords,E=A?e=>{A(e)?U(e):m(e)}:U,I=e=>{let i=o._writeStruct(e,he,t,ye,n,O,(e,t,n)=>{if(n)return r=!0;ye=t;let i=he;return S(e),w(),i!==he?{position:ye,targetView:pe,target:he}:ye});if(0===i)return E(e);ye=i},O=e=>{let r;if(e>16777216){if(e-t>ce)throw new Error("Packed buffer would be larger than maximum buffer size");r=Math.min(ce,4096*Math.round(Math.max((e-t)*(e>67108864?1.25:2),4194304)/4096))}else r=1+(Math.max(e-t<<2,he.length-1)>>12)<<12;let n=new le(r);return pe=n.dataView||(n.dataView=new DataView(n.buffer,0,r)),e=Math.min(e,he.length),he.copy?he.copy(n,0,t,e):n.set(he.slice(t,e)),ye-=t,t=0,de=n.length-10,he=n},v=(e,t,i)=>{let s=n.nextId;s||(s=64),s<h&&this.shouldShareStructure&&!this.shouldShareStructure(t)?(s=n.nextOwnId,s<g||(s=h),n.nextOwnId=s+1):(s>=g&&(s=h),n.nextId=s+1);let o=t.highByte=s>=96&&c?s-96>>5:-1;e[Se]=s,e.__keys__=t,n[s-64]=t,s<h?(t.isShared=!0,n.sharedLength=s-63,r=!0,o>=0?(he[ye++]=96+(31&s),he[ye++]=o):he[ye++]=s):(o>=0?(he[ye++]=213,he[ye++]=114,he[ye++]=96+(31&s),he[ye++]=o):(he[ye++]=212,he[ye++]=114,he[ye++]=s),i&&(d+=y*i),p.length>=f&&(p.shift()[Se]=0),p.push(e),S(t))},_=(e,r,n,i)=>{let s=he,o=ye,a=de,u=t;he=ge,ye=0,t=0,he||(ge=he=new le(8192)),de=he.length-10,v(e,r,i),ge=he;let l=ye;if(he=s,ye=o,de=a,t=u,l>1){let e=ye+l-1;e>de&&O(e);let r=n+t;he.copyWithin(r+l,r+1,ye),he.set(ge.slice(0,l),r),ye=e}else he[n+t]=ge[0]}}useBuffer(e){he=e,he.dataView||(he.dataView=new DataView(he.buffer,he.byteOffset,he.byteLength)),pe=he.dataView,ye=0}set position(e){ye=e}get position(){return ye}clearSharedData(){this.structures&&(this.structures=[]),this.typedStructs&&(this.typedStructs=[])}}function Ue(e,t,r,n){let i=e.byteLength;if(i+1<256){var{target:s,position:o}=r(4+i);s[o++]=199,s[o++]=i+1}else if(i+1<65536){var{target:s,position:o}=r(5+i);s[o++]=200,s[o++]=i+1>>8,s[o++]=i+1&255}else{var{target:s,position:o,targetView:a}=r(7+i);s[o++]=201,a.setUint32(o,i+1),o+=4}s[o++]=116,s[o++]=t,e.buffer||(e=new Uint8Array(e)),s.set(new Uint8Array(e.buffer,e.byteOffset,e.byteLength),o)}function Ae(e,t){let r=e.byteLength;var n,i;if(r<256){var{target:n,position:i}=t(r+2);n[i++]=196,n[i++]=r}else if(r<65536){var{target:n,position:i}=t(r+3);n[i++]=197,n[i++]=r>>8,n[i++]=255&r}else{var{target:n,position:i,targetView:s}=t(r+5);n[i++]=198,s.setUint32(i,r),i+=4}n.set(e,i)}function Ee(e,t,r,n){let i=e.length;switch(i){case 1:t[r++]=212;break;case 2:t[r++]=213;break;case 4:t[r++]=214;break;case 8:t[r++]=215;break;case 16:t[r++]=216;break;default:i<256?(t[r++]=199,t[r++]=i):i<65536?(t[r++]=200,t[r++]=i>>8,t[r++]=255&i):(t[r++]=201,t[r++]=i>>24,t[r++]=i>>16&255,t[r++]=i>>8&255,t[r++]=255&i)}return t[r++]=n,t.set(e,r),r+=i}function Ie(e,t,r){if(we.length>0){pe.setUint32(we.position+e,ye+r-we.position-e),we.stringsPosition=ye-e;let n=we;we=null,t(n[0]),t(n[1])}}function Oe(e,t){return e.isCompatible=e=>{let r=!e||(t.lastNamedStructuresLength||0)===e.length;return r||t._mergeStructures(e),r},e}se=[Date,Set,Error,RegExp,ArrayBuffer,Object.getPrototypeOf(Uint8Array.prototype).constructor,DataView,d],ie=[{pack(e,t,r){let n=e.getTime()/1e3;if((this.useTimestamp32||0===e.getMilliseconds())&&n>=0&&n<4294967296){let{target:e,targetView:r,position:i}=t(6);e[i++]=214,e[i++]=255,r.setUint32(i,n)}else if(n>0&&n<4294967296){let{target:r,targetView:i,position:s}=t(10);r[s++]=215,r[s++]=255,i.setUint32(s,4e6*e.getMilliseconds()+(n/1e3/4294967296|0)),i.setUint32(s+4,n)}else if(isNaN(n)){if(this.onInvalidDate)return t(0),r(this.onInvalidDate());let{target:e,targetView:n,position:i}=t(3);e[i++]=212,e[i++]=255,e[i++]=255}else{let{target:r,targetView:i,position:s}=t(15);r[s++]=199,r[s++]=12,r[s++]=255,i.setUint32(s,1e6*e.getMilliseconds()),i.setBigInt64(s+4,BigInt(Math.floor(n)))}}},{pack(e,t,r){if(this.setAsEmptyObject)return t(0),r({});let n=Array.from(e),{target:i,position:s}=t(this.moreTypes?3:0);this.moreTypes&&(i[s++]=212,i[s++]=115,i[s++]=0),r(n)}},{pack(e,t,r){let{target:n,position:i}=t(this.moreTypes?3:0);this.moreTypes&&(n[i++]=212,n[i++]=101,n[i++]=0),r([e.name,e.message,e.cause])}},{pack(e,t,r){let{target:n,position:i}=t(this.moreTypes?3:0);this.moreTypes&&(n[i++]=212,n[i++]=120,n[i++]=0),r([e.source,e.flags])}},{pack(e,t){this.moreTypes?Ue(e,16,t):Ae(ue?Buffer.from(e):new Uint8Array(e),t)}},{pack(e,t){let r=e.constructor;r!==fe&&this.moreTypes?Ue(e,K.indexOf(r.name),t):Ae(e,t)}},{pack(e,t){this.moreTypes?Ue(e,17,t):Ae(ue?Buffer.from(e):new Uint8Array(e),t)}},{pack(e,t){let{target:r,position:n}=t(1);r[n]=193}}],me.SUPPORTS_STRUCT_HOOKS=!0;let ve=new me({useRecords:!1});const _e=ve.pack,ke=ve.pack,Be=me,{NEVER:xe,ALWAYS:Te,DECIMAL_ROUND:Me,DECIMAL_FIT:Re}=re,je=512,Le=1024,De=2048;const Ve=function(e,t={}){if(!e||"object"!=typeof e)throw new Error("first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a promise");const r=new S(t);let n;const i=e=>{let t;n&&(e=Buffer.concat([n,e]),n=void 0);try{t=r.unpackMultiple(e)}catch(r){if(!r.incomplete)throw r;n=e.slice(r.lastPosition),t=r.values}return t};return"function"==typeof e[Symbol.iterator]?function*(){for(const t of e)yield*i(t)}():"function"==typeof e[Symbol.asyncIterator]?async function*(){for await(const t of e)yield*i(t)}():void 0},Pe=function(e,t={}){if(e&&"object"==typeof e){if("function"==typeof e[Symbol.iterator])return function*(e,t){const r=new me(t);for(const t of e)yield r.pack(t)}(e,t);if("function"==typeof e.then||"function"==typeof e[Symbol.asyncIterator])return async function*(e,t){const r=new me(t);for await(const t of e)yield r.pack(t)}(e,t);throw new Error("first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a Promise")}throw new Error("first argument must be an Iterable, Async Iterable, or a Promise for an Async Iterable")};e.ALWAYS=Te,e.C1=y,e.DECIMAL_FIT=Re,e.DECIMAL_ROUND=Me,e.Decoder=G,e.Encoder=Be,e.FLOAT32_OPTIONS=re,e.NEVER=xe,e.Packr=me,e.RESERVE_START_SPACE=De,e.RESET_BUFFER_MODE=Le,e.REUSE_BUFFER_MODE=je,e.Unpackr=S,e.addExtension=function(e){if(e.Class){if(!e.pack&&!e.write)throw new Error("Extension has no pack or write function");if(e.pack&&!e.type)throw new Error("Extension has no type (numeric code to identify the extension)");se.unshift(e.Class),ie.unshift(e)}!function(e){e.unpack?g[e.type]=e.unpack:g[e.type]=e}(e)},e.clearSource=H,e.decode=te,e.decodeIter=Ve,e.encode=ke,e.encodeIter=Pe,e.isNativeAccelerationEnabled=!1,e.mapsAsObjects=!0,e.pack=_e,e.roundFloat32=function(e){oe[0]=e;let t=Z[(127&ae[3])<<1|ae[2]>>7];return(t*e+(e>0?.5:-.5)|0)/t},e.unpack=X,e.unpackMultiple=ee,e.useRecords=!1});
2
  //# sourceMappingURL=index.min.js.map
.opencode/node_modules/msgpackr/dist/index.min.js.map CHANGED
The diff for this file is too large to render. See raw diff
 
.opencode/node_modules/msgpackr/dist/node.cjs CHANGED
@@ -3,6 +3,7 @@
3
  var stream = require('stream');
4
  var module$1 = require('module');
5
 
 
6
  var decoder;
7
  try {
8
  decoder = new TextDecoder();
@@ -31,7 +32,6 @@ const C1 = new C1Type();
31
  C1.name = 'MessagePack 0xC1';
32
  var sequentialMode = false;
33
  var inlineObjectReadThreshold = 2;
34
- var readStruct$1, onLoadedStructures$1, onSaveState;
35
 
36
  class Unpackr {
37
  constructor(options) {
@@ -61,10 +61,10 @@ class Unpackr {
61
  unpack(source, options) {
62
  if (src) {
63
  // re-entrant execution, save the state and restore it after we do this unpack
64
- return saveState$1(() => {
65
  clearSource();
66
- return this ? this.unpack(source, options) : Unpackr.prototype.unpack.call(defaultOptions, source, options)
67
- })
68
  }
69
  if (!source.buffer && source.constructor === ArrayBuffer)
70
  source = typeof Buffer !== 'undefined' ? Buffer.from(source) : new Uint8Array(source);
@@ -90,14 +90,14 @@ class Unpackr {
90
  // if it doesn't have a buffer, maybe it is the wrong type of object
91
  src = null;
92
  if (source instanceof Uint8Array)
93
- throw error
94
- throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source))
95
  }
96
  if (this instanceof Unpackr) {
97
  currentUnpackr = this;
98
  if (this.structures) {
99
  currentStructures = this.structures;
100
- return checkedRead(options)
101
  } else if (!currentStructures || currentStructures.length > 0) {
102
  currentStructures = [];
103
  }
@@ -106,7 +106,7 @@ class Unpackr {
106
  if (!currentStructures || currentStructures.length > 0)
107
  currentStructures = [];
108
  }
109
- return checkedRead(options)
110
  }
111
  unpackMultiple(source, forEach) {
112
  let values, lastPosition = 0;
@@ -119,7 +119,7 @@ class Unpackr {
119
  while(position$1 < size) {
120
  lastPosition = position$1;
121
  if (forEach(checkedRead(), lastPosition, position$1) === false) {
122
- return
123
  }
124
  }
125
  }
@@ -129,20 +129,20 @@ class Unpackr {
129
  lastPosition = position$1;
130
  values.push(checkedRead());
131
  }
132
- return values
133
  }
134
  } catch(error) {
135
  error.lastPosition = lastPosition;
136
  error.values = values;
137
- throw error
138
  } finally {
139
  sequentialMode = false;
140
  clearSource();
141
  }
142
  }
143
  _mergeStructures(loadedStructures, existingStructures) {
144
- if (onLoadedStructures$1)
145
- loadedStructures = onLoadedStructures$1.call(this, loadedStructures);
146
  loadedStructures = loadedStructures || [];
147
  if (Object.isFrozen(loadedStructures))
148
  loadedStructures = loadedStructures.map(structure => structure.slice(0));
@@ -166,10 +166,10 @@ class Unpackr {
166
  }
167
  }
168
  }
169
- return this.structures = loadedStructures
170
  }
171
  decode(source, options) {
172
- return this.unpack(source, options)
173
  }
174
  }
175
  function checkedRead(options) {
@@ -180,8 +180,8 @@ function checkedRead(options) {
180
  currentStructures.length = sharedLength;
181
  }
182
  let result;
183
- if (currentUnpackr.randomAccessStructure && src[position$1] < 0x40 && src[position$1] >= 0x20 && readStruct$1) {
184
- result = readStruct$1(src, position$1, srcEnd, currentUnpackr);
185
  src = null; // dispose of this so that recursive unpack calls don't save state
186
  if (!(options && options.lazy) && result)
187
  result = result.toJSON();
@@ -207,7 +207,7 @@ function checkedRead(options) {
207
  referenceMap = null;
208
  } else if (position$1 > srcEnd) {
209
  // over read
210
- throw new Error('Unexpected end of MessagePack data')
211
  } else if (!sequentialMode) {
212
  let jsonView;
213
  try {
@@ -215,10 +215,10 @@ function checkedRead(options) {
215
  } catch(error) {
216
  jsonView = '(JSON view not available ' + error + ')';
217
  }
218
- throw new Error('Data read, but end of buffer not reached ' + jsonView)
219
  }
220
  // else more to read, but we are reading sequentially, so don't clear source yet
221
- return result
222
  } catch(error) {
223
  if (currentStructures && currentStructures.restoreStructures)
224
  restoreStructures();
@@ -226,7 +226,7 @@ function checkedRead(options) {
226
  if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position$1 > srcEnd) {
227
  error.incomplete = true;
228
  }
229
- throw error
230
  }
231
  }
232
 
@@ -242,7 +242,7 @@ function read() {
242
  if (token < 0xa0) {
243
  if (token < 0x80) {
244
  if (token < 0x40)
245
- return token
246
  else {
247
  let structure = currentStructures[token & 0x3f] ||
248
  currentUnpackr.getStructures && loadStructures()[token & 0x3f];
@@ -250,9 +250,9 @@ function read() {
250
  if (!structure.read) {
251
  structure.read = createStructureReader(structure, token & 0x3f);
252
  }
253
- return structure.read()
254
  } else
255
- return token
256
  }
257
  } else if (token < 0x90) {
258
  // map
@@ -265,13 +265,13 @@ function read() {
265
  key = '__proto_';
266
  object[key] = read();
267
  }
268
- return object
269
  } else {
270
  let map = new Map();
271
  for (let i = 0; i < token; i++) {
272
  map.set(read(), read());
273
  }
274
- return map
275
  }
276
  } else {
277
  token -= 0x90;
@@ -280,91 +280,91 @@ function read() {
280
  array[i] = read();
281
  }
282
  if (currentUnpackr.freezeData)
283
- return Object.freeze(array)
284
- return array
285
  }
286
  } else if (token < 0xc0) {
287
  // fixstr
288
  let length = token - 0xa0;
289
  if (srcStringEnd >= position$1) {
290
- return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart)
291
  }
292
  if (srcStringEnd == 0 && srcEnd < 140) {
293
  // for small blocks, avoiding the overhead of the extract call is helpful
294
  let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
295
  if (string != null)
296
- return string
297
  }
298
- return readFixedString(length)
299
  } else {
300
  let value;
301
  switch (token) {
302
- case 0xc0: return null
303
  case 0xc1:
304
  if (bundledStrings$1) {
305
  value = read(); // followed by the length of the string in characters (not bytes!)
306
  if (value > 0)
307
- return bundledStrings$1[1].slice(bundledStrings$1.position1, bundledStrings$1.position1 += value)
308
  else
309
- return bundledStrings$1[0].slice(bundledStrings$1.position0, bundledStrings$1.position0 -= value)
310
  }
311
  return C1; // "never-used", return special object to denote that
312
- case 0xc2: return false
313
- case 0xc3: return true
314
  case 0xc4:
315
  // bin 8
316
  value = src[position$1++];
317
  if (value === undefined)
318
- throw new Error('Unexpected end of buffer')
319
- return readBin(value)
320
  case 0xc5:
321
  // bin 16
322
  value = dataView.getUint16(position$1);
323
  position$1 += 2;
324
- return readBin(value)
325
  case 0xc6:
326
  // bin 32
327
  value = dataView.getUint32(position$1);
328
  position$1 += 4;
329
- return readBin(value)
330
  case 0xc7:
331
  // ext 8
332
- return readExt(src[position$1++])
333
  case 0xc8:
334
  // ext 16
335
  value = dataView.getUint16(position$1);
336
  position$1 += 2;
337
- return readExt(value)
338
  case 0xc9:
339
  // ext 32
340
  value = dataView.getUint32(position$1);
341
  position$1 += 4;
342
- return readExt(value)
343
  case 0xca:
344
  value = dataView.getFloat32(position$1);
345
  if (currentUnpackr.useFloat32 > 2) {
346
  // this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
347
  let multiplier = mult10[((src[position$1] & 0x7f) << 1) | (src[position$1 + 1] >> 7)];
348
  position$1 += 4;
349
- return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier
350
  }
351
  position$1 += 4;
352
- return value
353
  case 0xcb:
354
  value = dataView.getFloat64(position$1);
355
  position$1 += 8;
356
- return value
357
  // uint handlers
358
  case 0xcc:
359
- return src[position$1++]
360
  case 0xcd:
361
  value = dataView.getUint16(position$1);
362
  position$1 += 2;
363
- return value
364
  case 0xce:
365
  value = dataView.getUint32(position$1);
366
  position$1 += 4;
367
- return value
368
  case 0xcf:
369
  if (currentUnpackr.int64AsType === 'number') {
370
  value = dataView.getUint32(position$1) * 0x100000000;
@@ -377,19 +377,19 @@ function read() {
377
  } else
378
  value = dataView.getBigUint64(position$1);
379
  position$1 += 8;
380
- return value
381
 
382
  // int handlers
383
  case 0xd0:
384
- return dataView.getInt8(position$1++)
385
  case 0xd1:
386
  value = dataView.getInt16(position$1);
387
  position$1 += 2;
388
- return value
389
  case 0xd2:
390
  value = dataView.getInt32(position$1);
391
  position$1 += 4;
392
- return value
393
  case 0xd3:
394
  if (currentUnpackr.int64AsType === 'number') {
395
  value = dataView.getInt32(position$1) * 0x100000000;
@@ -402,96 +402,96 @@ function read() {
402
  } else
403
  value = dataView.getBigInt64(position$1);
404
  position$1 += 8;
405
- return value
406
 
407
  case 0xd4:
408
  // fixext 1
409
  value = src[position$1++];
410
  if (value == 0x72) {
411
- return recordDefinition(src[position$1++] & 0x3f)
412
  } else {
413
  let extension = currentExtensions[value];
414
  if (extension) {
415
  if (extension.read) {
416
  position$1++; // skip filler byte
417
- return extension.read(read())
418
  } else if (extension.noBuffer) {
419
  position$1++; // skip filler byte
420
- return extension()
421
  } else
422
- return extension(src.subarray(position$1, ++position$1))
423
  } else
424
- throw new Error('Unknown extension ' + value)
425
  }
426
  case 0xd5:
427
  // fixext 2
428
  value = src[position$1];
429
  if (value == 0x72) {
430
  position$1++;
431
- return recordDefinition(src[position$1++] & 0x3f, src[position$1++])
432
  } else
433
- return readExt(2)
434
  case 0xd6:
435
  // fixext 4
436
- return readExt(4)
437
  case 0xd7:
438
  // fixext 8
439
- return readExt(8)
440
  case 0xd8:
441
  // fixext 16
442
- return readExt(16)
443
  case 0xd9:
444
  // str 8
445
  value = src[position$1++];
446
  if (srcStringEnd >= position$1) {
447
- return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
448
  }
449
- return readString8(value)
450
  case 0xda:
451
  // str 16
452
  value = dataView.getUint16(position$1);
453
  position$1 += 2;
454
  if (srcStringEnd >= position$1) {
455
- return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
456
  }
457
- return readString16(value)
458
  case 0xdb:
459
  // str 32
460
  value = dataView.getUint32(position$1);
461
  position$1 += 4;
462
  if (srcStringEnd >= position$1) {
463
- return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
464
  }
465
- return readString32(value)
466
  case 0xdc:
467
  // array 16
468
  value = dataView.getUint16(position$1);
469
  position$1 += 2;
470
- return readArray(value)
471
  case 0xdd:
472
  // array 32
473
  value = dataView.getUint32(position$1);
474
  position$1 += 4;
475
- return readArray(value)
476
  case 0xde:
477
  // map 16
478
  value = dataView.getUint16(position$1);
479
  position$1 += 2;
480
- return readMap(value)
481
  case 0xdf:
482
  // map 32
483
  value = dataView.getUint32(position$1);
484
  position$1 += 4;
485
- return readMap(value)
486
  default: // negative int
487
  if (token >= 0xe0)
488
- return token - 0x100
489
  if (token === undefined) {
490
  let error = new Error('Unexpected end of MessagePack data');
491
  error.incomplete = true;
492
- throw error
493
  }
494
- throw new Error('Unknown MessagePack token ' + token)
495
 
496
  }
497
  }
@@ -510,9 +510,10 @@ function createStructureReader(structure, firstId) {
510
  inlineObjectReadThreshold = Infinity; // disable going forward
511
  return readObject(); // recursively try again
512
  }
 
513
  if (structure.highByte === 0)
514
  structure.read = createSecondByteReader(firstId, structure.read);
515
- return optimizedReadObject() // second byte is already read, if there is one so immediately read object
516
  }
517
  let object = {};
518
  for (let i = 0, l = structure.length; i < l; i++) {
@@ -523,38 +524,44 @@ function createStructureReader(structure, firstId) {
523
  }
524
  if (currentUnpackr.freezeData)
525
  return Object.freeze(object);
526
- return object
527
  }
528
  readObject.count = 0;
 
 
 
 
 
 
529
  if (structure.highByte === 0) {
530
- return createSecondByteReader(firstId, readObject)
531
  }
532
- return readObject
533
  }
534
 
535
  const createSecondByteReader = (firstId, read0) => {
536
  return function() {
537
  let highByte = src[position$1++];
538
  if (highByte === 0)
539
- return read0()
540
  let id = firstId < 32 ? -(firstId + (highByte << 5)) : firstId + (highByte << 5);
541
  let structure = currentStructures[id] || loadStructures()[id];
542
  if (!structure) {
543
- throw new Error('Record id is not defined for ' + id)
544
  }
545
  if (!structure.read)
546
  structure.read = createStructureReader(structure, firstId);
547
- return structure.read()
548
- }
549
  };
550
 
551
  function loadStructures() {
552
- let loadedStructures = saveState$1(() => {
553
  // save the state in case getStructures modifies our buffer
554
  src = null;
555
- return currentUnpackr.getStructures()
556
  });
557
- return currentStructures = currentUnpackr._mergeStructures(loadedStructures, currentStructures)
558
  }
559
 
560
  var readFixedString = readStringJS;
@@ -574,7 +581,7 @@ function setExtractor(extractStrings) {
574
  let string = strings[stringPosition++];
575
  if (string == null) {
576
  if (bundledStrings$1)
577
- return readStringJS(length)
578
  let byteOffset = src.byteOffset;
579
  let extraction = extractStrings(position$1 - headerLength + byteOffset, srcEnd + byteOffset, src.buffer);
580
  if (typeof extraction == 'string') {
@@ -586,30 +593,30 @@ function setExtractor(extractStrings) {
586
  srcStringEnd = 1; // even if a utf-8 string was decoded, must indicate we are in the midst of extracted strings and can't skip strings
587
  string = strings[0];
588
  if (string === undefined)
589
- throw new Error('Unexpected end of buffer')
590
  }
591
  }
592
  let srcStringLength = string.length;
593
  if (srcStringLength <= length) {
594
  position$1 += length;
595
- return string
596
  }
597
  srcString = string;
598
  srcStringStart = position$1;
599
  srcStringEnd = position$1 + srcStringLength;
600
  position$1 += length;
601
- return string.slice(0, length) // we know we just want the beginning
602
- }
603
  }
604
  }
605
  function readStringJS(length) {
606
  let result;
607
  if (length < 16) {
608
  if (result = shortStringInJS(length))
609
- return result
610
  }
611
  if (length > 64 && decoder)
612
- return decoder.decode(src.subarray(position$1, position$1 += length))
613
  const end = position$1 + length;
614
  const units = [];
615
  result = '';
@@ -620,43 +627,49 @@ function readStringJS(length) {
620
  units.push(byte1);
621
  } else if ((byte1 & 0xe0) === 0xc0) {
622
  // 2 bytes
623
- const byte2 = src[position$1++] & 0x3f;
624
- const codePoint = ((byte1 & 0x1f) << 6) | byte2;
625
- // Reject overlong encoding: 2-byte sequences must encode values >= 0x80
626
- if (codePoint < 0x80) {
627
- units.push(0xFFFD); // replacement character
628
  } else {
629
- units.push(codePoint);
 
630
  }
631
  } else if ((byte1 & 0xf0) === 0xe0) {
632
  // 3 bytes
633
- const byte2 = src[position$1++] & 0x3f;
634
- const byte3 = src[position$1++] & 0x3f;
635
- const codePoint = ((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3;
636
- // Reject overlong encoding: 3-byte sequences must encode values >= 0x800
637
- // Also reject surrogates (0xD800-0xDFFF)
638
- if (codePoint < 0x800 || (codePoint >= 0xD800 && codePoint <= 0xDFFF)) {
639
- units.push(0xFFFD); // replacement character
640
  } else {
641
- units.push(codePoint);
 
 
 
 
 
 
642
  }
643
  } else if ((byte1 & 0xf8) === 0xf0) {
644
  // 4 bytes
645
- const byte2 = src[position$1++] & 0x3f;
646
- const byte3 = src[position$1++] & 0x3f;
647
- const byte4 = src[position$1++] & 0x3f;
648
- let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;
649
- // Reject overlong encoding: 4-byte sequences must encode values >= 0x10000
650
- // Also reject values > 0x10FFFF (maximum valid Unicode)
651
- if (unit < 0x10000 || unit > 0x10FFFF) {
652
- units.push(0xFFFD); // replacement character
653
- } else if (unit > 0xffff) {
654
- unit -= 0x10000;
655
- units.push(((unit >>> 10) & 0x3ff) | 0xd800);
656
- unit = 0xdc00 | (unit & 0x3ff);
657
- units.push(unit);
658
  } else {
659
- units.push(unit);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
660
  }
661
  } else {
662
  units.push(0xFFFD); // replacement character for invalid lead byte
@@ -672,17 +685,7 @@ function readStringJS(length) {
672
  result += fromCharCode.apply(String, units);
673
  }
674
 
675
- return result
676
- }
677
- function readString(source, start, length) {
678
- let existingSrc = src;
679
- src = source;
680
- position$1 = start;
681
- try {
682
- return readStringJS(length);
683
- } finally {
684
- src = existingSrc;
685
- }
686
  }
687
 
688
  function readArray(length) {
@@ -691,8 +694,8 @@ function readArray(length) {
691
  array[i] = read();
692
  }
693
  if (currentUnpackr.freezeData)
694
- return Object.freeze(array)
695
- return array
696
  }
697
 
698
  function readMap(length) {
@@ -704,13 +707,13 @@ function readMap(length) {
704
  key = '__proto_';
705
  object[key] = read();
706
  }
707
- return object
708
  } else {
709
  let map = new Map();
710
  for (let i = 0; i < length; i++) {
711
  map.set(read(), read());
712
  }
713
- return map
714
  }
715
  }
716
 
@@ -722,40 +725,40 @@ function longStringInJS(length) {
722
  const byte = src[position$1++];
723
  if ((byte & 0x80) > 0) {
724
  position$1 = start;
725
- return
726
  }
727
  bytes[i] = byte;
728
  }
729
- return fromCharCode.apply(String, bytes)
730
  }
731
  function shortStringInJS(length) {
732
  if (length < 4) {
733
  if (length < 2) {
734
  if (length === 0)
735
- return ''
736
  else {
737
  let a = src[position$1++];
738
  if ((a & 0x80) > 1) {
739
  position$1 -= 1;
740
- return
741
  }
742
- return fromCharCode(a)
743
  }
744
  } else {
745
  let a = src[position$1++];
746
  let b = src[position$1++];
747
  if ((a & 0x80) > 0 || (b & 0x80) > 0) {
748
  position$1 -= 2;
749
- return
750
  }
751
  if (length < 3)
752
- return fromCharCode(a, b)
753
  let c = src[position$1++];
754
  if ((c & 0x80) > 0) {
755
  position$1 -= 3;
756
- return
757
  }
758
- return fromCharCode(a, b, c)
759
  }
760
  } else {
761
  let a = src[position$1++];
@@ -764,34 +767,34 @@ function shortStringInJS(length) {
764
  let d = src[position$1++];
765
  if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
766
  position$1 -= 4;
767
- return
768
  }
769
  if (length < 6) {
770
  if (length === 4)
771
- return fromCharCode(a, b, c, d)
772
  else {
773
  let e = src[position$1++];
774
  if ((e & 0x80) > 0) {
775
  position$1 -= 5;
776
- return
777
  }
778
- return fromCharCode(a, b, c, d, e)
779
  }
780
  } else if (length < 8) {
781
  let e = src[position$1++];
782
  let f = src[position$1++];
783
  if ((e & 0x80) > 0 || (f & 0x80) > 0) {
784
  position$1 -= 6;
785
- return
786
  }
787
  if (length < 7)
788
- return fromCharCode(a, b, c, d, e, f)
789
  let g = src[position$1++];
790
  if ((g & 0x80) > 0) {
791
  position$1 -= 7;
792
- return
793
  }
794
- return fromCharCode(a, b, c, d, e, f, g)
795
  } else {
796
  let e = src[position$1++];
797
  let f = src[position$1++];
@@ -799,34 +802,34 @@ function shortStringInJS(length) {
799
  let h = src[position$1++];
800
  if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
801
  position$1 -= 8;
802
- return
803
  }
804
  if (length < 10) {
805
  if (length === 8)
806
- return fromCharCode(a, b, c, d, e, f, g, h)
807
  else {
808
  let i = src[position$1++];
809
  if ((i & 0x80) > 0) {
810
  position$1 -= 9;
811
- return
812
  }
813
- return fromCharCode(a, b, c, d, e, f, g, h, i)
814
  }
815
  } else if (length < 12) {
816
  let i = src[position$1++];
817
  let j = src[position$1++];
818
  if ((i & 0x80) > 0 || (j & 0x80) > 0) {
819
  position$1 -= 10;
820
- return
821
  }
822
  if (length < 11)
823
- return fromCharCode(a, b, c, d, e, f, g, h, i, j)
824
  let k = src[position$1++];
825
  if ((k & 0x80) > 0) {
826
  position$1 -= 11;
827
- return
828
  }
829
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k)
830
  } else {
831
  let i = src[position$1++];
832
  let j = src[position$1++];
@@ -834,34 +837,34 @@ function shortStringInJS(length) {
834
  let l = src[position$1++];
835
  if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
836
  position$1 -= 12;
837
- return
838
  }
839
  if (length < 14) {
840
  if (length === 12)
841
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l)
842
  else {
843
  let m = src[position$1++];
844
  if ((m & 0x80) > 0) {
845
  position$1 -= 13;
846
- return
847
  }
848
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m)
849
  }
850
  } else {
851
  let m = src[position$1++];
852
  let n = src[position$1++];
853
  if ((m & 0x80) > 0 || (n & 0x80) > 0) {
854
  position$1 -= 14;
855
- return
856
  }
857
  if (length < 15)
858
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
859
  let o = src[position$1++];
860
  if ((o & 0x80) > 0) {
861
  position$1 -= 15;
862
- return
863
  }
864
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
865
  }
866
  }
867
  }
@@ -879,22 +882,22 @@ function readOnlyJSString() {
879
  case 0xd9:
880
  // str 8
881
  length = src[position$1++];
882
- break
883
  case 0xda:
884
  // str 16
885
  length = dataView.getUint16(position$1);
886
  position$1 += 2;
887
- break
888
  case 0xdb:
889
  // str 32
890
  length = dataView.getUint32(position$1);
891
  position$1 += 4;
892
- break
893
  default:
894
- throw new Error('Expected string')
895
  }
896
  }
897
- return readStringJS(length)
898
  }
899
 
900
 
@@ -902,7 +905,7 @@ function readBin(length) {
902
  return currentUnpackr.copyBuffers ?
903
  // specifically use the copying slice (not the node one)
904
  Uint8Array.prototype.slice.call(src, position$1, position$1 += length) :
905
- src.subarray(position$1, position$1 += length)
906
  }
907
  function readExt(length) {
908
  let type = src[position$1++];
@@ -915,10 +918,10 @@ function readExt(length) {
915
  } finally {
916
  position$1 = end;
917
  }
918
- })
919
  }
920
  else
921
- throw new Error('Unknown extension type ' + type)
922
  }
923
 
924
  var keyCache = new Array(4096);
@@ -928,12 +931,12 @@ function readKey() {
928
  // fixstr, potentially use key cache
929
  length = length - 0xa0;
930
  if (srcStringEnd >= position$1) // if it has been extracted, must use it (and faster anyway)
931
- return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart)
932
  else if (!(srcStringEnd == 0 && srcEnd < 180))
933
- return readFixedString(length)
934
  } else { // not cacheable, go back and do a standard read
935
  position$1--;
936
- return asSafeString(read())
937
  }
938
  let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position$1) : length > 0 ? src[position$1] : 0)) & 0xfff;
939
  let entry = keyCache[key];
@@ -946,7 +949,7 @@ function readKey() {
946
  chunk = dataView.getUint32(checkPosition);
947
  if (chunk != entry[i++]) {
948
  checkPosition = 0x70000000;
949
- break
950
  }
951
  checkPosition += 4;
952
  }
@@ -955,12 +958,12 @@ function readKey() {
955
  chunk = src[checkPosition++];
956
  if (chunk != entry[i++]) {
957
  checkPosition = 0x70000000;
958
- break
959
  }
960
  }
961
  if (checkPosition === end) {
962
  position$1 = checkPosition;
963
- return entry.string
964
  }
965
  end -= 3;
966
  checkPosition = position$1;
@@ -981,8 +984,8 @@ function readKey() {
981
  // for small blocks, avoiding the overhead of the extract call is helpful
982
  let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
983
  if (string != null)
984
- return entry.string = string
985
- return entry.string = readFixedString(length)
986
  }
987
 
988
  function asSafeString(property) {
@@ -1013,7 +1016,12 @@ const recordDefinition = (id, highByte) => {
1013
  }
1014
  currentStructures[id] = structure;
1015
  structure.read = createStructureReader(structure, firstByte);
1016
- return structure.read()
 
 
 
 
 
1017
  };
1018
  currentExtensions[0] = () => {}; // notepack defines extension 0 to mean undefined, so use that as the default here
1019
  currentExtensions[0].noBuffer = true;
@@ -1035,17 +1043,17 @@ currentExtensions[0x42] = data => {
1035
  out <<= BigInt(64);
1036
  out |= view.getBigUint64(i);
1037
  }
1038
- return out
1039
  }
1040
  // if (length === 8) return view.getBigUint64(start)
1041
  let middle = start + (length >> 4 << 3);
1042
  let left = decode(start, middle);
1043
  let right = decode(middle, end);
1044
- return (left << BigInt((end - middle) * 8)) | right
1045
  };
1046
  head = (head << BigInt((view.byteLength - headLength) * 8)) | decode(headLength, view.byteLength);
1047
  }
1048
- return head
1049
  };
1050
 
1051
  let errors = {
@@ -1056,14 +1064,14 @@ currentExtensions[0x65] = () => {
1056
  if (!errors[data[0]]) {
1057
  let error = Error(data[1], { cause: data[2] });
1058
  error.name = data[0];
1059
- return error
1060
  }
1061
- return errors[data[0]](data[1], { cause: data[2] })
1062
  };
1063
 
1064
  currentExtensions[0x69] = (data) => {
1065
  // id extension (for structured clones)
1066
- if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled')
1067
  let id = dataView.getUint32(position$1 - 4);
1068
  if (!referenceMap)
1069
  referenceMap = new Map();
@@ -1084,7 +1092,7 @@ currentExtensions[0x69] = (data) => {
1084
  let targetProperties = read(); // read the next value as the target object to id
1085
  if (!refEntry.used) {
1086
  // no cycle, can just use the returned read object
1087
- return refEntry.target = targetProperties // replace the placeholder with the real one
1088
  } else {
1089
  // there is a cycle, so we have to assign properties to original target
1090
  Object.assign(target, targetProperties);
@@ -1095,16 +1103,16 @@ currentExtensions[0x69] = (data) => {
1095
  for (let [k, v] of targetProperties.entries()) target.set(k, v);
1096
  if (target instanceof Set)
1097
  for (let i of Array.from(targetProperties)) target.add(i);
1098
- return target
1099
  };
1100
 
1101
  currentExtensions[0x70] = (data) => {
1102
  // pointer extension (for structured clones)
1103
- if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled')
1104
  let id = dataView.getUint32(position$1 - 4);
1105
  let refEntry = referenceMap.get(id);
1106
  refEntry.used = true;
1107
- return refEntry.target
1108
  };
1109
 
1110
  currentExtensions[0x73] = () => new Set(read());
@@ -1119,15 +1127,15 @@ currentExtensions[0x74] = (data) => {
1119
 
1120
  let typedArrayName = typedArrays[typeCode];
1121
  if (!typedArrayName) {
1122
- if (typeCode === 16) return buffer
1123
- if (typeCode === 17) return new DataView(buffer)
1124
- throw new Error('Could not find typed array for code ' + typeCode)
1125
  }
1126
- return new glbl[typedArrayName](buffer)
1127
  };
1128
  currentExtensions[0x78] = () => {
1129
  let data = read();
1130
- return new RegExp(data[0], data[1])
1131
  };
1132
  const TEMP_BUNDLE = [];
1133
  currentExtensions[0x62] = (data) => {
@@ -1140,30 +1148,30 @@ currentExtensions[0x62] = (data) => {
1140
  bundledStrings$1.position1 = 0;
1141
  bundledStrings$1.postBundlePosition = position$1;
1142
  position$1 = dataPosition;
1143
- return read()
1144
  };
1145
 
1146
  currentExtensions[0xff] = (data) => {
1147
  // 32-bit date extension
1148
  if (data.length == 4)
1149
- return new Date((data[0] * 0x1000000 + (data[1] << 16) + (data[2] << 8) + data[3]) * 1000)
1150
  else if (data.length == 8)
1151
  return new Date(
1152
  ((data[0] << 22) + (data[1] << 14) + (data[2] << 6) + (data[3] >> 2)) / 1000000 +
1153
- ((data[3] & 0x3) * 0x100000000 + data[4] * 0x1000000 + (data[5] << 16) + (data[6] << 8) + data[7]) * 1000)
1154
  else if (data.length == 12)
1155
  return new Date(
1156
  ((data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]) / 1000000 +
1157
- (((data[4] & 0x80) ? -0x1000000000000 : 0) + data[6] * 0x10000000000 + data[7] * 0x100000000 + data[8] * 0x1000000 + (data[9] << 16) + (data[10] << 8) + data[11]) * 1000)
1158
  else
1159
- return new Date('invalid')
1160
  };
1161
  // registration of bulk record definition?
1162
  // currentExtensions[0x52] = () =>
1163
 
1164
- function saveState$1(callback) {
1165
- if (onSaveState)
1166
- onSaveState();
1167
  let savedSrcEnd = srcEnd;
1168
  let savedPosition = position$1;
1169
  let savedStringPosition = stringPosition;
@@ -1196,7 +1204,7 @@ function saveState$1(callback) {
1196
  currentStructures.splice(0, currentStructures.length, ...savedStructuresContents);
1197
  currentUnpackr = savedPackr;
1198
  dataView = new DataView(src.buffer, src.byteOffset, src.byteLength);
1199
- return value
1200
  }
1201
  function clearSource() {
1202
  src = null;
@@ -1231,30 +1239,28 @@ let u8Array = new Uint8Array(f32Array.buffer, 0, 4);
1231
  function roundFloat32(float32Number) {
1232
  f32Array[0] = float32Number;
1233
  let multiplier = mult10[((u8Array[3] & 0x7f) << 1) | (u8Array[2] >> 7)];
1234
- return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier
1235
- }
1236
- function setReadStruct(updatedReadStruct, loadedStructs, saveState) {
1237
- readStruct$1 = updatedReadStruct;
1238
- onLoadedStructures$1 = loadedStructs;
1239
- onSaveState = saveState;
1240
  }
 
 
 
 
1241
 
1242
- let textEncoder$1;
1243
  try {
1244
- textEncoder$1 = new TextEncoder();
1245
  } catch (error) {}
1246
  let extensions, extensionClasses;
1247
- const hasNodeBuffer$1 = typeof Buffer !== 'undefined';
1248
- const ByteArrayAllocate = hasNodeBuffer$1 ?
1249
- function(length) { return Buffer.allocUnsafeSlow(length) } : Uint8Array;
1250
- const ByteArray = hasNodeBuffer$1 ? Buffer : Uint8Array;
1251
- const MAX_BUFFER_SIZE = hasNodeBuffer$1 ? 0x100000000 : 0x7fd00000;
1252
  let target, keysTarget;
1253
  let targetView;
1254
  let position = 0;
1255
  let safeEnd;
1256
  let bundledStrings = null;
1257
- let writeStructSlots;
1258
  const MAX_BUNDLE_SIZE = 0x5500; // maximum characters such that the encoded bytes fits in 16 bits.
1259
  const hasNonLatin = /[\u0080-\uFFFF]/;
1260
  const RECORD_SYMBOL = Symbol('record-id');
@@ -1267,10 +1273,10 @@ class Packr extends Unpackr {
1267
  let structures;
1268
  let referenceMap;
1269
  let encodeUtf8 = ByteArray.prototype.utf8Write ? function(string, position) {
1270
- return target.utf8Write(string, position, target.byteLength - position)
1271
- } : (textEncoder$1 && textEncoder$1.encodeInto) ?
1272
  function(string, position) {
1273
- return textEncoder$1.encodeInto(string, target.subarray(position)).written
1274
  } : false;
1275
 
1276
  let packr = this;
@@ -1282,7 +1288,7 @@ class Packr extends Unpackr {
1282
  if (maxSharedStructures == null)
1283
  maxSharedStructures = hasSharedStructures ? 32 : 0;
1284
  if (maxSharedStructures > 8160)
1285
- throw new Error('Maximum maxSharedStructure is 8160')
1286
  if (options.structuredClone && options.moreTypes == undefined) {
1287
  this.moreTypes = true;
1288
  }
@@ -1296,7 +1302,7 @@ class Packr extends Unpackr {
1296
  let sharedLimitId = maxSharedStructures + 0x40;
1297
  let maxStructureId = maxSharedStructures + maxOwnStructures + 0x40;
1298
  if (maxStructureId > 8256) {
1299
- throw new Error('Maximum maxSharedStructure + maxOwnStructure is 8192')
1300
  }
1301
  let recordIdsToRemove = [];
1302
  let transitionsCount = 0;
@@ -1332,7 +1338,7 @@ class Packr extends Unpackr {
1332
  let sharedLength = structures.sharedLength || 0;
1333
  if (sharedLength > maxSharedStructures) {
1334
  //if (maxSharedStructures <= 32 && structures.sharedLength > 32) // TODO: could support this, but would need to update the limit ids
1335
- throw new Error('Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to ' + structures.sharedLength)
1336
  }
1337
  if (!structures.transitions) {
1338
  // rebuild our structure transitions
@@ -1340,7 +1346,7 @@ class Packr extends Unpackr {
1340
  for (let i = 0; i < sharedLength; i++) {
1341
  let keys = structures[i];
1342
  if (!keys)
1343
- continue
1344
  let nextTransition, transition = structures.transitions;
1345
  for (let j = 0, l = keys.length; j < l; j++) {
1346
  let key = keys[j];
@@ -1362,7 +1368,7 @@ class Packr extends Unpackr {
1362
  hasSharedUpdate = false;
1363
  let encodingError;
1364
  try {
1365
- if (packr.randomAccessStructure && value && typeof value === 'object') {
1366
  if (value.constructor === Object) writeStruct(value); // simple object
1367
  else if (value.constructor !== Map && !Array.isArray(value) && !extensionClasses.some(extClass => value instanceof extClass)) {
1368
  // allow user classes, if they don't need special handling (but do use toJSON if available)
@@ -1406,15 +1412,15 @@ class Packr extends Unpackr {
1406
  packr.offset = position;
1407
  let serialized = insertIds(target.subarray(start, position), idsToInsert);
1408
  referenceMap = null;
1409
- return serialized
1410
  }
1411
  packr.offset = position; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
1412
  if (encodeOptions & REUSE_BUFFER_MODE) {
1413
  target.start = start;
1414
  target.end = position;
1415
- return target
1416
  }
1417
- return target.subarray(start, position) // position can change if we call pack again in saveStructures, so we get the buffer now
1418
  } catch(error) {
1419
  encodingError = error;
1420
  throw error;
@@ -1425,16 +1431,23 @@ class Packr extends Unpackr {
1425
  let sharedLength = structures.sharedLength || 0;
1426
  // we can't rely on start/end with REUSE_BUFFER_MODE since they will (probably) change when we save
1427
  let returnBuffer = target.subarray(start, position);
1428
- let newSharedData = prepareStructures$1(structures, packr);
1429
  if (!encodingError) { // TODO: If there is an encoding error, should make the structures as uninitialized so they get rebuilt next time
1430
  if (packr.saveStructures(newSharedData, newSharedData.isCompatible) === false) {
1431
- // get updated structures and try again if the update failed
1432
- return packr.pack(value, encodeOptions)
 
 
 
 
 
 
 
1433
  }
1434
  packr.lastNamedStructuresLength = sharedLength;
1435
  // don't keep large buffers around
1436
  if (target.length > 0x40000000) target = null;
1437
- return returnBuffer
1438
  }
1439
  }
1440
  }
@@ -1520,7 +1533,7 @@ class Packr extends Unpackr {
1520
  bundledStrings[twoByte ? 0 : 1] += value;
1521
  target[position++] = 0xc1;
1522
  pack(twoByte ? -strLength : strLength);
1523
- return
1524
  }
1525
  let headerSize;
1526
  // first we estimate the header size, so we can write to the correct location
@@ -1594,7 +1607,7 @@ class Packr extends Unpackr {
1594
  } else if (type === 'number') {
1595
  if (value >>> 0 === value) {// positive integer, 32-bit or less
1596
  // positive uint
1597
- if (value < 0x20 || (value < 0x80 && this.useRecords === false) || (value < 0x40 && !this.randomAccessStructure)) {
1598
  target[position++] = value;
1599
  } else if (value < 0x100) {
1600
  target[position++] = 0xcc;
@@ -1633,7 +1646,7 @@ class Packr extends Unpackr {
1633
  // this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
1634
  ((xShifted = value * mult10[((target[position] & 0x7f) << 1) | (target[position + 1] >> 7)]) >> 0) === xShifted) {
1635
  position += 4;
1636
- return
1637
  } else
1638
  position--; // move back into position for writing a double
1639
  }
@@ -1656,7 +1669,7 @@ class Packr extends Unpackr {
1656
  target[position++] = 0x70; // "p" for pointer
1657
  targetView.setUint32(position, referee.id);
1658
  position += 4;
1659
- return
1660
  } else
1661
  referenceMap.set(value, { offset: position - start });
1662
  }
@@ -1706,7 +1719,7 @@ class Packr extends Unpackr {
1706
  } else {
1707
  pack(writeResult);
1708
  }
1709
- return
1710
  }
1711
  let currentTarget = target;
1712
  let currentTargetView = targetView;
@@ -1723,7 +1736,7 @@ class Packr extends Unpackr {
1723
  makeRoom(position);
1724
  return {
1725
  target, targetView, position: position - size
1726
- }
1727
  }, pack);
1728
  } finally {
1729
  // restore current target information (unless already restored)
@@ -1739,7 +1752,7 @@ class Packr extends Unpackr {
1739
  makeRoom(result.length + position);
1740
  position = writeExtensionData(result, target, position, extension.type);
1741
  }
1742
- return
1743
  }
1744
  }
1745
  // check isArray after extensions, because extensions can extend Array
@@ -1751,7 +1764,7 @@ class Packr extends Unpackr {
1751
  const json = value.toJSON();
1752
  // if for some reason value.toJSON returns itself it'll loop forever
1753
  if (json !== value)
1754
- return pack(json)
1755
  }
1756
 
1757
  // if there is a writeFunction, use it, otherwise just encode as undefined
@@ -1790,7 +1803,7 @@ class Packr extends Unpackr {
1790
  let chunks = [];
1791
  while (true) {
1792
  chunks.push(value & mask);
1793
- if ((value >> BigInt(63)) === empty) break
1794
  value >>= BigInt(64);
1795
  }
1796
 
@@ -1805,7 +1818,7 @@ class Packr extends Unpackr {
1805
  string = '00' + string;
1806
  }
1807
 
1808
- if (hasNodeBuffer$1) {
1809
  array = Buffer.from(string, 'hex');
1810
  } else {
1811
  array = new Uint8Array(string.length / 2);
@@ -1822,11 +1835,11 @@ class Packr extends Unpackr {
1822
  if (array.length + position > safeEnd)
1823
  makeRoom(array.length + position);
1824
  position = writeExtensionData(array, target, position, 0x42);
1825
- return
1826
  } else {
1827
  throw new RangeError(value + ' was too large to fit in MessagePack 64-bit integer format, use' +
1828
  ' useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set' +
1829
- ' largeBigIntToString to convert to string')
1830
  }
1831
  }
1832
  position += 8;
@@ -1839,7 +1852,7 @@ class Packr extends Unpackr {
1839
  target[position++] = 0;
1840
  }
1841
  } else {
1842
- throw new Error('Unknown type: ' + type)
1843
  }
1844
  };
1845
 
@@ -1985,12 +1998,30 @@ class Packr extends Unpackr {
1985
  checkUseRecords(object) ? writeRecord(object) : writePlainObject(object);
1986
  } : writeRecord;
1987
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1988
  const makeRoom = (end) => {
1989
  let newSize;
1990
  if (end > 0x1000000) {
1991
  // special handling for really large buffers
1992
  if ((end - start) > MAX_BUFFER_SIZE)
1993
- throw new Error('Packed buffer would be larger than maximum buffer size')
1994
  newSize = Math.min(MAX_BUFFER_SIZE,
1995
  Math.round(Math.max((end - start) * (end > 0x4000000 ? 1.25 : 2), 0x400000) / 0x1000) * 0x1000);
1996
  } else // faster handling for smaller buffers
@@ -2005,7 +2036,7 @@ class Packr extends Unpackr {
2005
  position -= start;
2006
  start = 0;
2007
  safeEnd = newBuffer.length - 10;
2008
- return target = newBuffer
2009
  };
2010
  const newRecord = (transition, keys, newTransitions) => {
2011
  let recordId = structures.nextId;
@@ -2087,23 +2118,6 @@ class Packr extends Unpackr {
2087
  target[insertionOffset + start] = keysTarget[0];
2088
  }
2089
  };
2090
- const writeStruct = (object) => {
2091
- let newPosition = writeStructSlots(object, target, start, position, structures, makeRoom, (value, newPosition, notifySharedUpdate) => {
2092
- if (notifySharedUpdate)
2093
- return hasSharedUpdate = true;
2094
- position = newPosition;
2095
- let startTarget = target;
2096
- pack(value);
2097
- resetStructures();
2098
- if (startTarget !== target) {
2099
- return { position, targetView, target }; // indicate the buffer was re-allocated
2100
- }
2101
- return position;
2102
- }, this);
2103
- if (newPosition === 0) // bail and go to a msgpack object
2104
- return writeObject(object);
2105
- position = newPosition;
2106
- };
2107
  }
2108
  useBuffer(buffer) {
2109
  // this means we are finished using our own buffer and we can write over it safely
@@ -2146,7 +2160,7 @@ extensions = [{
2146
  } else if (isNaN(seconds)) {
2147
  if (this.onInvalidDate) {
2148
  allocateForWrite(0);
2149
- return pack(this.onInvalidDate())
2150
  }
2151
  // Intentionally invalid timestamp
2152
  let { target, targetView, position} = allocateForWrite(3);
@@ -2167,7 +2181,7 @@ extensions = [{
2167
  pack(set, allocateForWrite, pack) {
2168
  if (this.setAsEmptyObject) {
2169
  allocateForWrite(0);
2170
- return pack({})
2171
  }
2172
  let array = Array.from(set);
2173
  let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
@@ -2203,7 +2217,7 @@ extensions = [{
2203
  if (this.moreTypes)
2204
  writeExtBuffer(arrayBuffer, 0x10, allocateForWrite);
2205
  else
2206
- writeBuffer(hasNodeBuffer$1 ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite);
2207
  }
2208
  }, {
2209
  pack(typedArray, allocateForWrite) {
@@ -2218,7 +2232,7 @@ extensions = [{
2218
  if (this.moreTypes)
2219
  writeExtBuffer(arrayBuffer, 0x11, allocateForWrite);
2220
  else
2221
- writeBuffer(hasNodeBuffer$1 ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite);
2222
  }
2223
  }, {
2224
  pack(c1, allocateForWrite) { // specific 0xC1 object
@@ -2275,19 +2289,19 @@ function writeExtensionData(result, target, position, type) {
2275
  switch (length) {
2276
  case 1:
2277
  target[position++] = 0xd4;
2278
- break
2279
  case 2:
2280
  target[position++] = 0xd5;
2281
- break
2282
  case 4:
2283
  target[position++] = 0xd6;
2284
- break
2285
  case 8:
2286
  target[position++] = 0xd7;
2287
- break
2288
  case 16:
2289
  target[position++] = 0xd8;
2290
- break
2291
  default:
2292
  if (length < 0x100) {
2293
  target[position++] = 0xc7;
@@ -2307,7 +2321,7 @@ function writeExtensionData(result, target, position, type) {
2307
  target[position++] = type;
2308
  target.set(result, position);
2309
  position += length;
2310
- return position
2311
  }
2312
 
2313
  function insertIds(serialized, idsToInsert) {
@@ -2329,7 +2343,7 @@ function insertIds(serialized, idsToInsert) {
2329
  serialized[position++] = id & 0xff;
2330
  lastEnd = offset;
2331
  }
2332
- return serialized
2333
  }
2334
 
2335
  function writeBundles(start, pack, incrementPosition) {
@@ -2346,28 +2360,29 @@ function writeBundles(start, pack, incrementPosition) {
2346
  function addExtension(extension) {
2347
  if (extension.Class) {
2348
  if (!extension.pack && !extension.write)
2349
- throw new Error('Extension has no pack or write function')
2350
  if (extension.pack && !extension.type)
2351
- throw new Error('Extension has no type (numeric code to identify the extension)')
2352
  extensionClasses.unshift(extension.Class);
2353
  extensions.unshift(extension);
2354
  }
2355
  addExtension$1(extension);
2356
  }
2357
- function prepareStructures$1(structures, packr) {
2358
  structures.isCompatible = (existingStructures) => {
2359
  let compatible = !existingStructures || ((packr.lastNamedStructuresLength || 0) === existingStructures.length);
2360
  if (!compatible) // we want to merge these existing structures immediately since we already have it and we are in the right transaction
2361
  packr._mergeStructures(existingStructures);
2362
  return compatible;
2363
  };
2364
- return structures
2365
- }
2366
- function setWriteStructSlots(writeSlots, makeStructures) {
2367
- writeStructSlots = writeSlots;
2368
- prepareStructures$1 = makeStructures;
2369
  }
2370
 
 
 
 
 
 
2371
  let defaultPackr = new Packr({ useRecords: false });
2372
  const pack = defaultPackr.pack;
2373
  const encode = defaultPackr.pack;
@@ -2377,779 +2392,6 @@ const REUSE_BUFFER_MODE = 512;
2377
  const RESET_BUFFER_MODE = 1024;
2378
  const RESERVE_START_SPACE = 2048;
2379
 
2380
- const ASCII = 3; // the MIBenum from https://www.iana.org/assignments/character-sets/character-sets.xhtml (and other character encodings could be referenced by MIBenum)
2381
- const NUMBER = 0;
2382
- const UTF8 = 2;
2383
- const OBJECT_DATA = 1;
2384
- const DATE = 16;
2385
- const TYPE_NAMES = ['num', 'object', 'string', 'ascii'];
2386
- TYPE_NAMES[DATE] = 'date';
2387
- const float32Headers = [false, true, true, false, false, true, true, false];
2388
- let evalSupported;
2389
- try {
2390
- new Function('');
2391
- evalSupported = true;
2392
- } catch(error) {
2393
- // if eval variants are not supported, do not create inline object readers ever
2394
- }
2395
-
2396
- let updatedPosition;
2397
- const hasNodeBuffer = typeof Buffer !== 'undefined';
2398
- let textEncoder, currentSource;
2399
- try {
2400
- textEncoder = new TextEncoder();
2401
- } catch (error) {}
2402
- const encodeUtf8 = hasNodeBuffer ? function(target, string, position) {
2403
- return target.utf8Write(string, position, target.byteLength - position)
2404
- } : (textEncoder && textEncoder.encodeInto) ?
2405
- function(target, string, position) {
2406
- return textEncoder.encodeInto(string, target.subarray(position)).written
2407
- } : false;
2408
- setWriteStructSlots(writeStruct, prepareStructures);
2409
- function writeStruct(object, target, encodingStart, position, structures, makeRoom, pack, packr) {
2410
- let typedStructs = packr.typedStructs || (packr.typedStructs = []);
2411
- // note that we rely on pack.js to load stored structures before we get to this point
2412
- let targetView = target.dataView;
2413
- let refsStartPosition = (typedStructs.lastStringStart || 100) + position;
2414
- let safeEnd = target.length - 10;
2415
- let start = position;
2416
- if (position > safeEnd) {
2417
- target = makeRoom(position);
2418
- targetView = target.dataView;
2419
- position -= encodingStart;
2420
- start -= encodingStart;
2421
- refsStartPosition -= encodingStart;
2422
- encodingStart = 0;
2423
- safeEnd = target.length - 10;
2424
- }
2425
-
2426
- let refOffset, refPosition = refsStartPosition;
2427
-
2428
- let transition = typedStructs.transitions || (typedStructs.transitions = Object.create(null));
2429
- let nextId = typedStructs.nextId || typedStructs.length;
2430
- let headerSize =
2431
- nextId < 0xf ? 1 :
2432
- nextId < 0xf0 ? 2 :
2433
- nextId < 0xf000 ? 3 :
2434
- nextId < 0xf00000 ? 4 : 0;
2435
- if (headerSize === 0)
2436
- return 0;
2437
- position += headerSize;
2438
- let queuedReferences = [];
2439
- let usedAscii0;
2440
- let keyIndex = 0;
2441
- for (let key in object) {
2442
- let value = object[key];
2443
- let nextTransition = transition[key];
2444
- if (!nextTransition) {
2445
- transition[key] = nextTransition = {
2446
- key,
2447
- parent: transition,
2448
- enumerationOffset: 0,
2449
- ascii0: null,
2450
- ascii8: null,
2451
- num8: null,
2452
- string16: null,
2453
- object16: null,
2454
- num32: null,
2455
- float64: null,
2456
- date64: null
2457
- };
2458
- }
2459
- if (position > safeEnd) {
2460
- target = makeRoom(position);
2461
- targetView = target.dataView;
2462
- position -= encodingStart;
2463
- start -= encodingStart;
2464
- refsStartPosition -= encodingStart;
2465
- refPosition -= encodingStart;
2466
- encodingStart = 0;
2467
- safeEnd = target.length - 10;
2468
- }
2469
- switch (typeof value) {
2470
- case 'number':
2471
- let number = value;
2472
- // first check to see if we are using a lot of ids and should default to wide/common format
2473
- if (nextId < 200 || !nextTransition.num64) {
2474
- if (number >> 0 === number && number < 0x20000000 && number > -0x1f000000) {
2475
- if (number < 0xf6 && number >= 0 && (nextTransition.num8 && !(nextId > 200 && nextTransition.num32) || number < 0x20 && !nextTransition.num32)) {
2476
- transition = nextTransition.num8 || createTypeTransition(nextTransition, NUMBER, 1);
2477
- target[position++] = number;
2478
- } else {
2479
- transition = nextTransition.num32 || createTypeTransition(nextTransition, NUMBER, 4);
2480
- targetView.setUint32(position, number, true);
2481
- position += 4;
2482
- }
2483
- break;
2484
- } else if (number < 0x100000000 && number >= -0x80000000) {
2485
- targetView.setFloat32(position, number, true);
2486
- if (float32Headers[target[position + 3] >>> 5]) {
2487
- let xShifted;
2488
- // this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
2489
- if (((xShifted = number * mult10[((target[position + 3] & 0x7f) << 1) | (target[position + 2] >> 7)]) >> 0) === xShifted) {
2490
- transition = nextTransition.num32 || createTypeTransition(nextTransition, NUMBER, 4);
2491
- position += 4;
2492
- break;
2493
- }
2494
- }
2495
- }
2496
- }
2497
- transition = nextTransition.num64 || createTypeTransition(nextTransition, NUMBER, 8);
2498
- targetView.setFloat64(position, number, true);
2499
- position += 8;
2500
- break;
2501
- case 'string':
2502
- let strLength = value.length;
2503
- refOffset = refPosition - refsStartPosition;
2504
- if ((strLength << 2) + refPosition > safeEnd) {
2505
- target = makeRoom((strLength << 2) + refPosition);
2506
- targetView = target.dataView;
2507
- position -= encodingStart;
2508
- start -= encodingStart;
2509
- refsStartPosition -= encodingStart;
2510
- refPosition -= encodingStart;
2511
- encodingStart = 0;
2512
- safeEnd = target.length - 10;
2513
- }
2514
- if (strLength > ((0xff00 + refOffset) >> 2)) {
2515
- queuedReferences.push(key, value, position - start);
2516
- break;
2517
- }
2518
- let isNotAscii;
2519
- let strStart = refPosition;
2520
- if (strLength < 0x40) {
2521
- let i, c1, c2;
2522
- for (i = 0; i < strLength; i++) {
2523
- c1 = value.charCodeAt(i);
2524
- if (c1 < 0x80) {
2525
- target[refPosition++] = c1;
2526
- } else if (c1 < 0x800) {
2527
- isNotAscii = true;
2528
- target[refPosition++] = c1 >> 6 | 0xc0;
2529
- target[refPosition++] = c1 & 0x3f | 0x80;
2530
- } else if (
2531
- (c1 & 0xfc00) === 0xd800 &&
2532
- ((c2 = value.charCodeAt(i + 1)) & 0xfc00) === 0xdc00
2533
- ) {
2534
- isNotAscii = true;
2535
- c1 = 0x10000 + ((c1 & 0x03ff) << 10) + (c2 & 0x03ff);
2536
- i++;
2537
- target[refPosition++] = c1 >> 18 | 0xf0;
2538
- target[refPosition++] = c1 >> 12 & 0x3f | 0x80;
2539
- target[refPosition++] = c1 >> 6 & 0x3f | 0x80;
2540
- target[refPosition++] = c1 & 0x3f | 0x80;
2541
- } else {
2542
- isNotAscii = true;
2543
- target[refPosition++] = c1 >> 12 | 0xe0;
2544
- target[refPosition++] = c1 >> 6 & 0x3f | 0x80;
2545
- target[refPosition++] = c1 & 0x3f | 0x80;
2546
- }
2547
- }
2548
- } else {
2549
- refPosition += encodeUtf8(target, value, refPosition);
2550
- isNotAscii = refPosition - strStart > strLength;
2551
- }
2552
- if (refOffset < 0xa0 || (refOffset < 0xf6 && (nextTransition.ascii8 || nextTransition.string8))) {
2553
- // short strings
2554
- if (isNotAscii) {
2555
- if (!(transition = nextTransition.string8)) {
2556
- if (typedStructs.length > 10 && (transition = nextTransition.ascii8)) {
2557
- // we can safely change ascii to utf8 in place since they are compatible
2558
- transition.__type = UTF8;
2559
- nextTransition.ascii8 = null;
2560
- nextTransition.string8 = transition;
2561
- pack(null, 0, true); // special call to notify that structures have been updated
2562
- } else {
2563
- transition = createTypeTransition(nextTransition, UTF8, 1);
2564
- }
2565
- }
2566
- } else if (refOffset === 0 && !usedAscii0) {
2567
- usedAscii0 = true;
2568
- transition = nextTransition.ascii0 || createTypeTransition(nextTransition, ASCII, 0);
2569
- break; // don't increment position
2570
- }// else ascii:
2571
- else if (!(transition = nextTransition.ascii8) && !(typedStructs.length > 10 && (transition = nextTransition.string8)))
2572
- transition = createTypeTransition(nextTransition, ASCII, 1);
2573
- target[position++] = refOffset;
2574
- } else {
2575
- // TODO: Enable ascii16 at some point, but get the logic right
2576
- //if (isNotAscii)
2577
- transition = nextTransition.string16 || createTypeTransition(nextTransition, UTF8, 2);
2578
- //else
2579
- //transition = nextTransition.ascii16 || createTypeTransition(nextTransition, ASCII, 2);
2580
- targetView.setUint16(position, refOffset, true);
2581
- position += 2;
2582
- }
2583
- break;
2584
- case 'object':
2585
- if (value) {
2586
- if (value.constructor === Date) {
2587
- transition = nextTransition.date64 || createTypeTransition(nextTransition, DATE, 8);
2588
- targetView.setFloat64(position, value.getTime(), true);
2589
- position += 8;
2590
- } else {
2591
- queuedReferences.push(key, value, keyIndex);
2592
- }
2593
- break;
2594
- } else { // null
2595
- nextTransition = anyType(nextTransition, position, targetView, -10); // match CBOR with this
2596
- if (nextTransition) {
2597
- transition = nextTransition;
2598
- position = updatedPosition;
2599
- } else queuedReferences.push(key, value, keyIndex);
2600
- }
2601
- break;
2602
- case 'boolean':
2603
- transition = nextTransition.num8 || nextTransition.ascii8 || createTypeTransition(nextTransition, NUMBER, 1);
2604
- target[position++] = value ? 0xf9 : 0xf8; // match CBOR with these
2605
- break;
2606
- case 'undefined':
2607
- nextTransition = anyType(nextTransition, position, targetView, -9); // match CBOR with this
2608
- if (nextTransition) {
2609
- transition = nextTransition;
2610
- position = updatedPosition;
2611
- } else queuedReferences.push(key, value, keyIndex);
2612
- break;
2613
- default:
2614
- queuedReferences.push(key, value, keyIndex);
2615
- }
2616
- keyIndex++;
2617
- }
2618
-
2619
- for (let i = 0, l = queuedReferences.length; i < l;) {
2620
- let key = queuedReferences[i++];
2621
- let value = queuedReferences[i++];
2622
- let propertyIndex = queuedReferences[i++];
2623
- let nextTransition = transition[key];
2624
- if (!nextTransition) {
2625
- transition[key] = nextTransition = {
2626
- key,
2627
- parent: transition,
2628
- enumerationOffset: propertyIndex - keyIndex,
2629
- ascii0: null,
2630
- ascii8: null,
2631
- num8: null,
2632
- string16: null,
2633
- object16: null,
2634
- num32: null,
2635
- float64: null
2636
- };
2637
- }
2638
- let newPosition;
2639
- if (value) {
2640
- /*if (typeof value === 'string') { // TODO: we could re-enable long strings
2641
- if (position + value.length * 3 > safeEnd) {
2642
- target = makeRoom(position + value.length * 3);
2643
- position -= start;
2644
- targetView = target.dataView;
2645
- start = 0;
2646
- }
2647
- newPosition = position + target.utf8Write(value, position, 0xffffffff);
2648
- } else { */
2649
- let size;
2650
- refOffset = refPosition - refsStartPosition;
2651
- if (refOffset < 0xff00) {
2652
- transition = nextTransition.object16;
2653
- if (transition)
2654
- size = 2;
2655
- else if ((transition = nextTransition.object32))
2656
- size = 4;
2657
- else {
2658
- transition = createTypeTransition(nextTransition, OBJECT_DATA, 2);
2659
- size = 2;
2660
- }
2661
- } else {
2662
- transition = nextTransition.object32 || createTypeTransition(nextTransition, OBJECT_DATA, 4);
2663
- size = 4;
2664
- }
2665
- newPosition = pack(value, refPosition);
2666
- //}
2667
- if (typeof newPosition === 'object') {
2668
- // re-allocated
2669
- refPosition = newPosition.position;
2670
- targetView = newPosition.targetView;
2671
- target = newPosition.target;
2672
- refsStartPosition -= encodingStart;
2673
- position -= encodingStart;
2674
- start -= encodingStart;
2675
- encodingStart = 0;
2676
- } else
2677
- refPosition = newPosition;
2678
- if (size === 2) {
2679
- targetView.setUint16(position, refOffset, true);
2680
- position += 2;
2681
- } else {
2682
- targetView.setUint32(position, refOffset, true);
2683
- position += 4;
2684
- }
2685
- } else { // null or undefined
2686
- transition = nextTransition.object16 || createTypeTransition(nextTransition, OBJECT_DATA, 2);
2687
- targetView.setInt16(position, value === null ? -10 : -9, true);
2688
- position += 2;
2689
- }
2690
- keyIndex++;
2691
- }
2692
-
2693
-
2694
- let recordId = transition[RECORD_SYMBOL];
2695
- if (recordId == null) {
2696
- recordId = packr.typedStructs.length;
2697
- let structure = [];
2698
- let nextTransition = transition;
2699
- let key, type;
2700
- while ((type = nextTransition.__type) !== undefined) {
2701
- let size = nextTransition.__size;
2702
- nextTransition = nextTransition.__parent;
2703
- key = nextTransition.key;
2704
- let property = [type, size, key];
2705
- if (nextTransition.enumerationOffset)
2706
- property.push(nextTransition.enumerationOffset);
2707
- structure.push(property);
2708
- nextTransition = nextTransition.parent;
2709
- }
2710
- structure.reverse();
2711
- transition[RECORD_SYMBOL] = recordId;
2712
- packr.typedStructs[recordId] = structure;
2713
- pack(null, 0, true); // special call to notify that structures have been updated
2714
- }
2715
-
2716
-
2717
- switch (headerSize) {
2718
- case 1:
2719
- if (recordId >= 0x10) return 0;
2720
- target[start] = recordId + 0x20;
2721
- break;
2722
- case 2:
2723
- if (recordId >= 0x100) return 0;
2724
- target[start] = 0x38;
2725
- target[start + 1] = recordId;
2726
- break;
2727
- case 3:
2728
- if (recordId >= 0x10000) return 0;
2729
- target[start] = 0x39;
2730
- targetView.setUint16(start + 1, recordId, true);
2731
- break;
2732
- case 4:
2733
- if (recordId >= 0x1000000) return 0;
2734
- targetView.setUint32(start, (recordId << 8) + 0x3a, true);
2735
- break;
2736
- }
2737
-
2738
- if (position < refsStartPosition) {
2739
- if (refsStartPosition === refPosition)
2740
- return position; // no refs
2741
- // adjust positioning
2742
- target.copyWithin(position, refsStartPosition, refPosition);
2743
- refPosition += position - refsStartPosition;
2744
- typedStructs.lastStringStart = position - start;
2745
- } else if (position > refsStartPosition) {
2746
- if (refsStartPosition === refPosition)
2747
- return position; // no refs
2748
- typedStructs.lastStringStart = position - start;
2749
- return writeStruct(object, target, encodingStart, start, structures, makeRoom, pack, packr);
2750
- }
2751
- return refPosition;
2752
- }
2753
- function anyType(transition, position, targetView, value) {
2754
- let nextTransition;
2755
- if ((nextTransition = transition.ascii8 || transition.num8)) {
2756
- targetView.setInt8(position, value, true);
2757
- updatedPosition = position + 1;
2758
- return nextTransition;
2759
- }
2760
- if ((nextTransition = transition.string16 || transition.object16)) {
2761
- targetView.setInt16(position, value, true);
2762
- updatedPosition = position + 2;
2763
- return nextTransition;
2764
- }
2765
- if (nextTransition = transition.num32) {
2766
- targetView.setUint32(position, 0xe0000100 + value, true);
2767
- updatedPosition = position + 4;
2768
- return nextTransition;
2769
- }
2770
- // transition.float64
2771
- if (nextTransition = transition.num64) {
2772
- targetView.setFloat64(position, NaN, true);
2773
- targetView.setInt8(position, value);
2774
- updatedPosition = position + 8;
2775
- return nextTransition;
2776
- }
2777
- updatedPosition = position;
2778
- // TODO: can we do an "any" type where we defer the decision?
2779
- return;
2780
- }
2781
- function createTypeTransition(transition, type, size) {
2782
- let typeName = TYPE_NAMES[type] + (size << 3);
2783
- let newTransition = transition[typeName] || (transition[typeName] = Object.create(null));
2784
- newTransition.__type = type;
2785
- newTransition.__size = size;
2786
- newTransition.__parent = transition;
2787
- return newTransition;
2788
- }
2789
- function onLoadedStructures(sharedData) {
2790
- if (!(sharedData instanceof Map))
2791
- return sharedData;
2792
- let typed = sharedData.get('typed') || [];
2793
- if (Object.isFrozen(typed))
2794
- typed = typed.map(structure => structure.slice(0));
2795
- let named = sharedData.get('named');
2796
- let transitions = Object.create(null);
2797
- for (let i = 0, l = typed.length; i < l; i++) {
2798
- let structure = typed[i];
2799
- let transition = transitions;
2800
- for (let [type, size, key] of structure) {
2801
- let nextTransition = transition[key];
2802
- if (!nextTransition) {
2803
- transition[key] = nextTransition = {
2804
- key,
2805
- parent: transition,
2806
- enumerationOffset: 0,
2807
- ascii0: null,
2808
- ascii8: null,
2809
- num8: null,
2810
- string16: null,
2811
- object16: null,
2812
- num32: null,
2813
- float64: null,
2814
- date64: null,
2815
- };
2816
- }
2817
- transition = createTypeTransition(nextTransition, type, size);
2818
- }
2819
- transition[RECORD_SYMBOL] = i;
2820
- }
2821
- typed.transitions = transitions;
2822
- this.typedStructs = typed;
2823
- this.lastTypedStructuresLength = typed.length;
2824
- return named;
2825
- }
2826
- var sourceSymbol = Symbol.for('source');
2827
- function readStruct(src, position, srcEnd, unpackr) {
2828
- let recordId = src[position++] - 0x20;
2829
- if (recordId >= 24) {
2830
- switch(recordId) {
2831
- case 24: recordId = src[position++]; break;
2832
- // little endian:
2833
- case 25: recordId = src[position++] + (src[position++] << 8); break;
2834
- case 26: recordId = src[position++] + (src[position++] << 8) + (src[position++] << 16); break;
2835
- case 27: recordId = src[position++] + (src[position++] << 8) + (src[position++] << 16) + (src[position++] << 24); break;
2836
- }
2837
- }
2838
- let structure = unpackr.typedStructs && unpackr.typedStructs[recordId];
2839
- if (!structure) {
2840
- // copy src buffer because getStructures will override it
2841
- src = Uint8Array.prototype.slice.call(src, position, srcEnd);
2842
- srcEnd -= position;
2843
- position = 0;
2844
- if (!unpackr.getStructures)
2845
- throw new Error(`Reference to shared structure ${recordId} without getStructures method`);
2846
- unpackr._mergeStructures(unpackr.getStructures());
2847
- if (!unpackr.typedStructs)
2848
- throw new Error('Could not find any shared typed structures');
2849
- unpackr.lastTypedStructuresLength = unpackr.typedStructs.length;
2850
- structure = unpackr.typedStructs[recordId];
2851
- if (!structure)
2852
- throw new Error('Could not find typed structure ' + recordId);
2853
- }
2854
- var construct = structure.construct;
2855
- var fullConstruct = structure.fullConstruct;
2856
- if (!construct) {
2857
- construct = structure.construct = function LazyObject() {
2858
- };
2859
- fullConstruct = structure.fullConstruct = function LoadedObject() {
2860
- };
2861
- fullConstruct.prototype = unpackr.structPrototype || {};
2862
- var prototype = construct.prototype = unpackr.structPrototype ? Object.create(unpackr.structPrototype) : {};
2863
- let properties = [];
2864
- let currentOffset = 0;
2865
- let lastRefProperty;
2866
- for (let i = 0, l = structure.length; i < l; i++) {
2867
- let definition = structure[i];
2868
- let [ type, size, key, enumerationOffset ] = definition;
2869
- if (key === '__proto__')
2870
- key = '__proto_';
2871
- let property = {
2872
- key,
2873
- offset: currentOffset,
2874
- };
2875
- if (enumerationOffset)
2876
- properties.splice(i + enumerationOffset, 0, property);
2877
- else
2878
- properties.push(property);
2879
- let getRef;
2880
- switch(size) { // TODO: Move into a separate function
2881
- case 0: getRef = () => 0; break;
2882
- case 1:
2883
- getRef = (source, position) => {
2884
- let ref = source.bytes[position + property.offset];
2885
- return ref >= 0xf6 ? toConstant(ref) : ref;
2886
- };
2887
- break;
2888
- case 2:
2889
- getRef = (source, position) => {
2890
- let src = source.bytes;
2891
- let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
2892
- let ref = dataView.getUint16(position + property.offset, true);
2893
- return ref >= 0xff00 ? toConstant(ref & 0xff) : ref;
2894
- };
2895
- break;
2896
- case 4:
2897
- getRef = (source, position) => {
2898
- let src = source.bytes;
2899
- let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
2900
- let ref = dataView.getUint32(position + property.offset, true);
2901
- return ref >= 0xffffff00 ? toConstant(ref & 0xff) : ref;
2902
- };
2903
- break;
2904
- }
2905
- property.getRef = getRef;
2906
- currentOffset += size;
2907
- let get;
2908
- switch(type) {
2909
- case ASCII:
2910
- if (lastRefProperty && !lastRefProperty.next)
2911
- lastRefProperty.next = property;
2912
- lastRefProperty = property;
2913
- property.multiGetCount = 0;
2914
- get = function(source) {
2915
- let src = source.bytes;
2916
- let position = source.position;
2917
- let refStart = currentOffset + position;
2918
- let ref = getRef(source, position);
2919
- if (typeof ref !== 'number') return ref;
2920
-
2921
- let end, next = property.next;
2922
- while(next) {
2923
- end = next.getRef(source, position);
2924
- if (typeof end === 'number')
2925
- break;
2926
- else
2927
- end = null;
2928
- next = next.next;
2929
- }
2930
- if (end == null)
2931
- end = source.bytesEnd - refStart;
2932
- if (source.srcString) {
2933
- return source.srcString.slice(ref, end);
2934
- }
2935
- /*if (property.multiGetCount > 0) {
2936
- let asciiEnd;
2937
- next = firstRefProperty;
2938
- let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
2939
- do {
2940
- asciiEnd = dataView.getUint16(source.position + next.offset, true);
2941
- if (asciiEnd < 0xff00)
2942
- break;
2943
- else
2944
- asciiEnd = null;
2945
- } while((next = next.next));
2946
- if (asciiEnd == null)
2947
- asciiEnd = source.bytesEnd - refStart
2948
- source.srcString = src.toString('latin1', refStart, refStart + asciiEnd);
2949
- return source.srcString.slice(ref, end);
2950
- }
2951
- if (source.prevStringGet) {
2952
- source.prevStringGet.multiGetCount += 2;
2953
- } else {
2954
- source.prevStringGet = property;
2955
- property.multiGetCount--;
2956
- }*/
2957
- return readString(src, ref + refStart, end - ref);
2958
- //return src.toString('latin1', ref + refStart, end + refStart);
2959
- };
2960
- break;
2961
- case UTF8: case OBJECT_DATA:
2962
- if (lastRefProperty && !lastRefProperty.next)
2963
- lastRefProperty.next = property;
2964
- lastRefProperty = property;
2965
- get = function(source) {
2966
- let position = source.position;
2967
- let refStart = currentOffset + position;
2968
- let ref = getRef(source, position);
2969
- if (typeof ref !== 'number') return ref;
2970
- let src = source.bytes;
2971
- let end, next = property.next;
2972
- while(next) {
2973
- end = next.getRef(source, position);
2974
- if (typeof end === 'number')
2975
- break;
2976
- else
2977
- end = null;
2978
- next = next.next;
2979
- }
2980
- if (end == null)
2981
- end = source.bytesEnd - refStart;
2982
- if (type === UTF8) {
2983
- return src.toString('utf8', ref + refStart, end + refStart);
2984
- } else {
2985
- currentSource = source;
2986
- try {
2987
- return unpackr.unpack(src, { start: ref + refStart, end: end + refStart });
2988
- } finally {
2989
- currentSource = null;
2990
- }
2991
- }
2992
- };
2993
- break;
2994
- case NUMBER:
2995
- switch(size) {
2996
- case 4:
2997
- get = function (source) {
2998
- let src = source.bytes;
2999
- let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
3000
- let position = source.position + property.offset;
3001
- let value = dataView.getInt32(position, true);
3002
- if (value < 0x20000000) {
3003
- if (value > -0x1f000000)
3004
- return value;
3005
- if (value > -0x20000000)
3006
- return toConstant(value & 0xff);
3007
- }
3008
- let fValue = dataView.getFloat32(position, true);
3009
- // this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
3010
- let multiplier = mult10[((src[position + 3] & 0x7f) << 1) | (src[position + 2] >> 7)];
3011
- return ((multiplier * fValue + (fValue > 0 ? 0.5 : -0.5)) >> 0) / multiplier;
3012
- };
3013
- break;
3014
- case 8:
3015
- get = function (source) {
3016
- let src = source.bytes;
3017
- let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
3018
- let value = dataView.getFloat64(source.position + property.offset, true);
3019
- if (isNaN(value)) {
3020
- let byte = src[source.position + property.offset];
3021
- if (byte >= 0xf6)
3022
- return toConstant(byte);
3023
- }
3024
- return value;
3025
- };
3026
- break;
3027
- case 1:
3028
- get = function (source) {
3029
- let src = source.bytes;
3030
- let value = src[source.position + property.offset];
3031
- return value < 0xf6 ? value : toConstant(value);
3032
- };
3033
- break;
3034
- }
3035
- break;
3036
- case DATE:
3037
- get = function (source) {
3038
- let src = source.bytes;
3039
- let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
3040
- return new Date(dataView.getFloat64(source.position + property.offset, true));
3041
- };
3042
- break;
3043
-
3044
- }
3045
- property.get = get;
3046
- }
3047
- // TODO: load the srcString for faster string decoding on toJSON
3048
- if (evalSupported) {
3049
- let objectLiteralProperties = [];
3050
- let args = [];
3051
- let i = 0;
3052
- let hasInheritedProperties;
3053
- for (let property of properties) { // assign in enumeration order
3054
- if (unpackr.alwaysLazyProperty && unpackr.alwaysLazyProperty(property.key)) {
3055
- // these properties are not eagerly evaluated and this can be used for creating properties
3056
- // that are not serialized as JSON
3057
- hasInheritedProperties = true;
3058
- continue;
3059
- }
3060
- Object.defineProperty(prototype, property.key, { get: withSource(property.get), enumerable: true });
3061
- let valueFunction = 'v' + i++;
3062
- args.push(valueFunction);
3063
- objectLiteralProperties.push('o[' + JSON.stringify(property.key) + ']=' + valueFunction + '(s)');
3064
- }
3065
- if (hasInheritedProperties) {
3066
- objectLiteralProperties.push('__proto__:this');
3067
- }
3068
- let toObject = (new Function(...args, 'var c=this;return function(s){var o=new c();' + objectLiteralProperties.join(';') + ';return o;}')).apply(fullConstruct, properties.map(prop => prop.get));
3069
- Object.defineProperty(prototype, 'toJSON', {
3070
- value(omitUnderscoredProperties) {
3071
- return toObject.call(this, this[sourceSymbol]);
3072
- }
3073
- });
3074
- } else {
3075
- Object.defineProperty(prototype, 'toJSON', {
3076
- value(omitUnderscoredProperties) {
3077
- // return an enumerable object with own properties to JSON stringify
3078
- let resolved = {};
3079
- for (let i = 0, l = properties.length; i < l; i++) {
3080
- // TODO: check alwaysLazyProperty
3081
- let key = properties[i].key;
3082
-
3083
- resolved[key] = this[key];
3084
- }
3085
- return resolved;
3086
- },
3087
- // not enumerable or anything
3088
- });
3089
- }
3090
- }
3091
- var instance = new construct();
3092
- instance[sourceSymbol] = {
3093
- bytes: src,
3094
- position,
3095
- srcString: '',
3096
- bytesEnd: srcEnd
3097
- };
3098
- return instance;
3099
- }
3100
- function toConstant(code) {
3101
- switch(code) {
3102
- case 0xf6: return null;
3103
- case 0xf7: return undefined;
3104
- case 0xf8: return false;
3105
- case 0xf9: return true;
3106
- }
3107
- throw new Error('Unknown constant');
3108
- }
3109
- function withSource(get) {
3110
- return function() {
3111
- return get(this[sourceSymbol]);
3112
- }
3113
- }
3114
-
3115
- function saveState() {
3116
- if (currentSource) {
3117
- currentSource.bytes = Uint8Array.prototype.slice.call(currentSource.bytes, currentSource.position, currentSource.bytesEnd);
3118
- currentSource.position = 0;
3119
- currentSource.bytesEnd = currentSource.bytes.length;
3120
- }
3121
- }
3122
- function prepareStructures(structures, packr) {
3123
- if (packr.typedStructs) {
3124
- let structMap = new Map();
3125
- structMap.set('named', structures);
3126
- structMap.set('typed', packr.typedStructs);
3127
- structures = structMap;
3128
- }
3129
- let lastTypedStructuresLength = packr.lastTypedStructuresLength || 0;
3130
- structures.isCompatible = existing => {
3131
- let compatible = true;
3132
- if (existing instanceof Map) {
3133
- let named = existing.get('named') || [];
3134
- if (named.length !== (packr.lastNamedStructuresLength || 0))
3135
- compatible = false;
3136
- let typed = existing.get('typed') || [];
3137
- if (typed.length !== lastTypedStructuresLength)
3138
- compatible = false;
3139
- } else if (existing instanceof Array || Array.isArray(existing)) {
3140
- if (existing.length !== (packr.lastNamedStructuresLength || 0))
3141
- compatible = false;
3142
- }
3143
- if (!compatible)
3144
- packr._mergeStructures(existing);
3145
- return compatible;
3146
- };
3147
- packr.lastTypedStructuresLength = packr.typedStructs && packr.typedStructs.length;
3148
- return structures;
3149
- }
3150
-
3151
- setReadStruct(readStruct, onLoadedStructures, saveState);
3152
-
3153
  class PackrStream extends stream.Transform {
3154
  constructor(options) {
3155
  if (!options)
@@ -3188,12 +2430,12 @@ class UnpackrStream extends stream.Transform {
3188
  let incompleteBuffer = chunk.slice(error.lastPosition);
3189
  if (incompleteBuffer.length > this.maxIncompleteBufferSize) {
3190
  this.incompleteBuffer = null;
3191
- return callback(new Error('Maximum incomplete buffer size exceeded'))
3192
  }
3193
  this.incompleteBuffer = incompleteBuffer;
3194
  values = error.values;
3195
  } else {
3196
- return callback(error)
3197
  }
3198
  }
3199
  for (let value of values || []) {
@@ -3204,7 +2446,7 @@ class UnpackrStream extends stream.Transform {
3204
  callback();
3205
  }
3206
  getNullValue() {
3207
- return Symbol.for(null)
3208
  }
3209
  }
3210
 
@@ -3217,13 +2459,13 @@ class UnpackrStream extends stream.Transform {
3217
  */
3218
  function packIter (objectIterator, options = {}) {
3219
  if (!objectIterator || typeof objectIterator !== 'object') {
3220
- throw new Error('first argument must be an Iterable, Async Iterable, or a Promise for an Async Iterable')
3221
  } else if (typeof objectIterator[Symbol.iterator] === 'function') {
3222
- return packIterSync(objectIterator, options)
3223
  } else if (typeof objectIterator.then === 'function' || typeof objectIterator[Symbol.asyncIterator] === 'function') {
3224
- return packIterAsync(objectIterator, options)
3225
  } else {
3226
- throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a Promise')
3227
  }
3228
  }
3229
 
@@ -3250,7 +2492,7 @@ async function * packIterAsync (objectIterator, options) {
3250
  */
3251
  function unpackIter (bufferIterator, options = {}) {
3252
  if (!bufferIterator || typeof bufferIterator !== 'object') {
3253
- throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a promise')
3254
  }
3255
 
3256
  const unpackr = new Unpackr(options);
@@ -3270,10 +2512,10 @@ function unpackIter (bufferIterator, options = {}) {
3270
  incomplete = chunk.slice(err.lastPosition);
3271
  yields = err.values;
3272
  } else {
3273
- throw err
3274
  }
3275
  }
3276
- return yields
3277
  };
3278
 
3279
  if (typeof bufferIterator[Symbol.iterator] === 'function') {
@@ -3281,13 +2523,13 @@ function unpackIter (bufferIterator, options = {}) {
3281
  for (const value of bufferIterator) {
3282
  yield * parser(value);
3283
  }
3284
- })()
3285
  } else if (typeof bufferIterator[Symbol.asyncIterator] === 'function') {
3286
  return (async function * iter () {
3287
  for await (const value of bufferIterator) {
3288
  yield * parser(value);
3289
  }
3290
- })()
3291
  }
3292
  }
3293
  const decodeIter = unpackIter;
@@ -3304,7 +2546,7 @@ if (!nativeAccelerationDisabled) {
3304
  if (typeof require == 'function')
3305
  extractor = require('msgpackr-extract');
3306
  else
3307
- extractor = module$1.createRequire((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('node.cjs', document.baseURI).href)))('msgpackr-extract');
3308
  if (extractor)
3309
  setExtractor(extractor.extractStrings);
3310
  } catch (error) {
 
3
  var stream = require('stream');
4
  var module$1 = require('module');
5
 
6
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
7
  var decoder;
8
  try {
9
  decoder = new TextDecoder();
 
32
  C1.name = 'MessagePack 0xC1';
33
  var sequentialMode = false;
34
  var inlineObjectReadThreshold = 2;
 
35
 
36
  class Unpackr {
37
  constructor(options) {
 
61
  unpack(source, options) {
62
  if (src) {
63
  // re-entrant execution, save the state and restore it after we do this unpack
64
+ return saveState(() => {
65
  clearSource();
66
+ return this ? this.unpack(source, options) : Unpackr.prototype.unpack.call(defaultOptions, source, options);
67
+ });
68
  }
69
  if (!source.buffer && source.constructor === ArrayBuffer)
70
  source = typeof Buffer !== 'undefined' ? Buffer.from(source) : new Uint8Array(source);
 
90
  // if it doesn't have a buffer, maybe it is the wrong type of object
91
  src = null;
92
  if (source instanceof Uint8Array)
93
+ throw error;
94
+ throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source));
95
  }
96
  if (this instanceof Unpackr) {
97
  currentUnpackr = this;
98
  if (this.structures) {
99
  currentStructures = this.structures;
100
+ return checkedRead(options);
101
  } else if (!currentStructures || currentStructures.length > 0) {
102
  currentStructures = [];
103
  }
 
106
  if (!currentStructures || currentStructures.length > 0)
107
  currentStructures = [];
108
  }
109
+ return checkedRead(options);
110
  }
111
  unpackMultiple(source, forEach) {
112
  let values, lastPosition = 0;
 
119
  while(position$1 < size) {
120
  lastPosition = position$1;
121
  if (forEach(checkedRead(), lastPosition, position$1) === false) {
122
+ return;
123
  }
124
  }
125
  }
 
129
  lastPosition = position$1;
130
  values.push(checkedRead());
131
  }
132
+ return values;
133
  }
134
  } catch(error) {
135
  error.lastPosition = lastPosition;
136
  error.values = values;
137
+ throw error;
138
  } finally {
139
  sequentialMode = false;
140
  clearSource();
141
  }
142
  }
143
  _mergeStructures(loadedStructures, existingStructures) {
144
+ if (this._onLoadedStructures)
145
+ loadedStructures = this._onLoadedStructures(loadedStructures);
146
  loadedStructures = loadedStructures || [];
147
  if (Object.isFrozen(loadedStructures))
148
  loadedStructures = loadedStructures.map(structure => structure.slice(0));
 
166
  }
167
  }
168
  }
169
+ return this.structures = loadedStructures;
170
  }
171
  decode(source, options) {
172
+ return this.unpack(source, options);
173
  }
174
  }
175
  function checkedRead(options) {
 
180
  currentStructures.length = sharedLength;
181
  }
182
  let result;
183
+ if (currentUnpackr._readStruct && src[position$1] < 0x40 && src[position$1] >= 0x20) {
184
+ result = currentUnpackr._readStruct(src, position$1, srcEnd);
185
  src = null; // dispose of this so that recursive unpack calls don't save state
186
  if (!(options && options.lazy) && result)
187
  result = result.toJSON();
 
207
  referenceMap = null;
208
  } else if (position$1 > srcEnd) {
209
  // over read
210
+ throw new Error('Unexpected end of MessagePack data');
211
  } else if (!sequentialMode) {
212
  let jsonView;
213
  try {
 
215
  } catch(error) {
216
  jsonView = '(JSON view not available ' + error + ')';
217
  }
218
+ throw new Error('Data read, but end of buffer not reached ' + jsonView);
219
  }
220
  // else more to read, but we are reading sequentially, so don't clear source yet
221
+ return result;
222
  } catch(error) {
223
  if (currentStructures && currentStructures.restoreStructures)
224
  restoreStructures();
 
226
  if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position$1 > srcEnd) {
227
  error.incomplete = true;
228
  }
229
+ throw error;
230
  }
231
  }
232
 
 
242
  if (token < 0xa0) {
243
  if (token < 0x80) {
244
  if (token < 0x40)
245
+ return token;
246
  else {
247
  let structure = currentStructures[token & 0x3f] ||
248
  currentUnpackr.getStructures && loadStructures()[token & 0x3f];
 
250
  if (!structure.read) {
251
  structure.read = createStructureReader(structure, token & 0x3f);
252
  }
253
+ return structure.read();
254
  } else
255
+ return token;
256
  }
257
  } else if (token < 0x90) {
258
  // map
 
265
  key = '__proto_';
266
  object[key] = read();
267
  }
268
+ return object;
269
  } else {
270
  let map = new Map();
271
  for (let i = 0; i < token; i++) {
272
  map.set(read(), read());
273
  }
274
+ return map;
275
  }
276
  } else {
277
  token -= 0x90;
 
280
  array[i] = read();
281
  }
282
  if (currentUnpackr.freezeData)
283
+ return Object.freeze(array);
284
+ return array;
285
  }
286
  } else if (token < 0xc0) {
287
  // fixstr
288
  let length = token - 0xa0;
289
  if (srcStringEnd >= position$1) {
290
+ return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart);
291
  }
292
  if (srcStringEnd == 0 && srcEnd < 140) {
293
  // for small blocks, avoiding the overhead of the extract call is helpful
294
  let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
295
  if (string != null)
296
+ return string;
297
  }
298
+ return readFixedString(length);
299
  } else {
300
  let value;
301
  switch (token) {
302
+ case 0xc0: return null;
303
  case 0xc1:
304
  if (bundledStrings$1) {
305
  value = read(); // followed by the length of the string in characters (not bytes!)
306
  if (value > 0)
307
+ return bundledStrings$1[1].slice(bundledStrings$1.position1, bundledStrings$1.position1 += value);
308
  else
309
+ return bundledStrings$1[0].slice(bundledStrings$1.position0, bundledStrings$1.position0 -= value);
310
  }
311
  return C1; // "never-used", return special object to denote that
312
+ case 0xc2: return false;
313
+ case 0xc3: return true;
314
  case 0xc4:
315
  // bin 8
316
  value = src[position$1++];
317
  if (value === undefined)
318
+ throw new Error('Unexpected end of buffer');
319
+ return readBin(value);
320
  case 0xc5:
321
  // bin 16
322
  value = dataView.getUint16(position$1);
323
  position$1 += 2;
324
+ return readBin(value);
325
  case 0xc6:
326
  // bin 32
327
  value = dataView.getUint32(position$1);
328
  position$1 += 4;
329
+ return readBin(value);
330
  case 0xc7:
331
  // ext 8
332
+ return readExt(src[position$1++]);
333
  case 0xc8:
334
  // ext 16
335
  value = dataView.getUint16(position$1);
336
  position$1 += 2;
337
+ return readExt(value);
338
  case 0xc9:
339
  // ext 32
340
  value = dataView.getUint32(position$1);
341
  position$1 += 4;
342
+ return readExt(value);
343
  case 0xca:
344
  value = dataView.getFloat32(position$1);
345
  if (currentUnpackr.useFloat32 > 2) {
346
  // this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
347
  let multiplier = mult10[((src[position$1] & 0x7f) << 1) | (src[position$1 + 1] >> 7)];
348
  position$1 += 4;
349
+ return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier;
350
  }
351
  position$1 += 4;
352
+ return value;
353
  case 0xcb:
354
  value = dataView.getFloat64(position$1);
355
  position$1 += 8;
356
+ return value;
357
  // uint handlers
358
  case 0xcc:
359
+ return src[position$1++];
360
  case 0xcd:
361
  value = dataView.getUint16(position$1);
362
  position$1 += 2;
363
+ return value;
364
  case 0xce:
365
  value = dataView.getUint32(position$1);
366
  position$1 += 4;
367
+ return value;
368
  case 0xcf:
369
  if (currentUnpackr.int64AsType === 'number') {
370
  value = dataView.getUint32(position$1) * 0x100000000;
 
377
  } else
378
  value = dataView.getBigUint64(position$1);
379
  position$1 += 8;
380
+ return value;
381
 
382
  // int handlers
383
  case 0xd0:
384
+ return dataView.getInt8(position$1++);
385
  case 0xd1:
386
  value = dataView.getInt16(position$1);
387
  position$1 += 2;
388
+ return value;
389
  case 0xd2:
390
  value = dataView.getInt32(position$1);
391
  position$1 += 4;
392
+ return value;
393
  case 0xd3:
394
  if (currentUnpackr.int64AsType === 'number') {
395
  value = dataView.getInt32(position$1) * 0x100000000;
 
402
  } else
403
  value = dataView.getBigInt64(position$1);
404
  position$1 += 8;
405
+ return value;
406
 
407
  case 0xd4:
408
  // fixext 1
409
  value = src[position$1++];
410
  if (value == 0x72) {
411
+ return recordDefinition(src[position$1++] & 0x3f);
412
  } else {
413
  let extension = currentExtensions[value];
414
  if (extension) {
415
  if (extension.read) {
416
  position$1++; // skip filler byte
417
+ return extension.read(read());
418
  } else if (extension.noBuffer) {
419
  position$1++; // skip filler byte
420
+ return extension();
421
  } else
422
+ return extension(src.subarray(position$1, ++position$1));
423
  } else
424
+ throw new Error('Unknown extension ' + value);
425
  }
426
  case 0xd5:
427
  // fixext 2
428
  value = src[position$1];
429
  if (value == 0x72) {
430
  position$1++;
431
+ return recordDefinition(src[position$1++] & 0x3f, src[position$1++]);
432
  } else
433
+ return readExt(2);
434
  case 0xd6:
435
  // fixext 4
436
+ return readExt(4);
437
  case 0xd7:
438
  // fixext 8
439
+ return readExt(8);
440
  case 0xd8:
441
  // fixext 16
442
+ return readExt(16);
443
  case 0xd9:
444
  // str 8
445
  value = src[position$1++];
446
  if (srcStringEnd >= position$1) {
447
+ return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart);
448
  }
449
+ return readString8(value);
450
  case 0xda:
451
  // str 16
452
  value = dataView.getUint16(position$1);
453
  position$1 += 2;
454
  if (srcStringEnd >= position$1) {
455
+ return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart);
456
  }
457
+ return readString16(value);
458
  case 0xdb:
459
  // str 32
460
  value = dataView.getUint32(position$1);
461
  position$1 += 4;
462
  if (srcStringEnd >= position$1) {
463
+ return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart);
464
  }
465
+ return readString32(value);
466
  case 0xdc:
467
  // array 16
468
  value = dataView.getUint16(position$1);
469
  position$1 += 2;
470
+ return readArray(value);
471
  case 0xdd:
472
  // array 32
473
  value = dataView.getUint32(position$1);
474
  position$1 += 4;
475
+ return readArray(value);
476
  case 0xde:
477
  // map 16
478
  value = dataView.getUint16(position$1);
479
  position$1 += 2;
480
+ return readMap(value);
481
  case 0xdf:
482
  // map 32
483
  value = dataView.getUint32(position$1);
484
  position$1 += 4;
485
+ return readMap(value);
486
  default: // negative int
487
  if (token >= 0xe0)
488
+ return token - 0x100;
489
  if (token === undefined) {
490
  let error = new Error('Unexpected end of MessagePack data');
491
  error.incomplete = true;
492
+ throw error;
493
  }
494
+ throw new Error('Unknown MessagePack token ' + token);
495
 
496
  }
497
  }
 
510
  inlineObjectReadThreshold = Infinity; // disable going forward
511
  return readObject(); // recursively try again
512
  }
513
+ structure.read0 = optimizedReadObject; // keep the un-wrapped body reader in sync
514
  if (structure.highByte === 0)
515
  structure.read = createSecondByteReader(firstId, structure.read);
516
+ return optimizedReadObject(); // second byte is already read, if there is one so immediately read object
517
  }
518
  let object = {};
519
  for (let i = 0, l = structure.length; i < l; i++) {
 
524
  }
525
  if (currentUnpackr.freezeData)
526
  return Object.freeze(object);
527
+ return object;
528
  }
529
  readObject.count = 0;
530
+ // read0 is the un-wrapped body reader: it reads the record's values directly without
531
+ // consuming a leading high byte. recordDefinition uses it for the immediate read that follows
532
+ // a record definition (the high byte, if present, was already consumed). For highByte === 0
533
+ // structures the public reader is a second-byte reader (used by later references), but the
534
+ // definition read itself must not consume that byte.
535
+ structure.read0 = readObject;
536
  if (structure.highByte === 0) {
537
+ return createSecondByteReader(firstId, readObject);
538
  }
539
+ return readObject;
540
  }
541
 
542
  const createSecondByteReader = (firstId, read0) => {
543
  return function() {
544
  let highByte = src[position$1++];
545
  if (highByte === 0)
546
+ return read0();
547
  let id = firstId < 32 ? -(firstId + (highByte << 5)) : firstId + (highByte << 5);
548
  let structure = currentStructures[id] || loadStructures()[id];
549
  if (!structure) {
550
+ throw new Error('Record id is not defined for ' + id);
551
  }
552
  if (!structure.read)
553
  structure.read = createStructureReader(structure, firstId);
554
+ return structure.read();
555
+ };
556
  };
557
 
558
  function loadStructures() {
559
+ let loadedStructures = saveState(() => {
560
  // save the state in case getStructures modifies our buffer
561
  src = null;
562
+ return currentUnpackr.getStructures();
563
  });
564
+ return currentStructures = currentUnpackr._mergeStructures(loadedStructures, currentStructures);
565
  }
566
 
567
  var readFixedString = readStringJS;
 
581
  let string = strings[stringPosition++];
582
  if (string == null) {
583
  if (bundledStrings$1)
584
+ return readStringJS(length);
585
  let byteOffset = src.byteOffset;
586
  let extraction = extractStrings(position$1 - headerLength + byteOffset, srcEnd + byteOffset, src.buffer);
587
  if (typeof extraction == 'string') {
 
593
  srcStringEnd = 1; // even if a utf-8 string was decoded, must indicate we are in the midst of extracted strings and can't skip strings
594
  string = strings[0];
595
  if (string === undefined)
596
+ throw new Error('Unexpected end of buffer');
597
  }
598
  }
599
  let srcStringLength = string.length;
600
  if (srcStringLength <= length) {
601
  position$1 += length;
602
+ return string;
603
  }
604
  srcString = string;
605
  srcStringStart = position$1;
606
  srcStringEnd = position$1 + srcStringLength;
607
  position$1 += length;
608
+ return string.slice(0, length); // we know we just want the beginning
609
+ };
610
  }
611
  }
612
  function readStringJS(length) {
613
  let result;
614
  if (length < 16) {
615
  if (result = shortStringInJS(length))
616
+ return result;
617
  }
618
  if (length > 64 && decoder)
619
+ return decoder.decode(src.subarray(position$1, position$1 += length));
620
  const end = position$1 + length;
621
  const units = [];
622
  result = '';
 
627
  units.push(byte1);
628
  } else if ((byte1 & 0xe0) === 0xc0) {
629
  // 2 bytes
630
+ if (byte1 < 0xc2 || position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
631
+ units.push(0xFFFD);
 
 
 
632
  } else {
633
+ const byte2 = src[position$1++] & 0x3f;
634
+ units.push(((byte1 & 0x1f) << 6) | byte2);
635
  }
636
  } else if ((byte1 & 0xf0) === 0xe0) {
637
  // 3 bytes
638
+ const byte2 = position$1 < end ? src[position$1] : 0;
639
+ if (position$1 >= end || (byte2 & 0xc0) !== 0x80 ||
640
+ (byte1 === 0xe0 && byte2 < 0xa0) || (byte1 === 0xed && byte2 >= 0xa0)) {
641
+ units.push(0xFFFD);
 
 
 
642
  } else {
643
+ position$1++;
644
+ if (position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
645
+ units.push(0xFFFD);
646
+ } else {
647
+ const byte3 = src[position$1++] & 0x3f;
648
+ units.push(((byte1 & 0x1f) << 12) | ((byte2 & 0x3f) << 6) | byte3);
649
+ }
650
  }
651
  } else if ((byte1 & 0xf8) === 0xf0) {
652
  // 4 bytes
653
+ const byte2 = position$1 < end ? src[position$1] : 0;
654
+ if (byte1 > 0xf4 || position$1 >= end || (byte2 & 0xc0) !== 0x80 ||
655
+ (byte1 === 0xf0 && byte2 < 0x90) || (byte1 === 0xf4 && byte2 >= 0x90)) {
656
+ units.push(0xFFFD);
 
 
 
 
 
 
 
 
 
657
  } else {
658
+ position$1++;
659
+ if (position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
660
+ units.push(0xFFFD);
661
+ } else {
662
+ const byte3 = src[position$1++] & 0x3f;
663
+ if (position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
664
+ units.push(0xFFFD);
665
+ } else {
666
+ const byte4 = src[position$1++] & 0x3f;
667
+ let unit = ((byte1 & 0x07) << 0x12) | ((byte2 & 0x3f) << 0x0c) | (byte3 << 0x06) | byte4;
668
+ unit -= 0x10000;
669
+ units.push(((unit >>> 10) & 0x3ff) | 0xd800);
670
+ units.push(0xdc00 | (unit & 0x3ff));
671
+ }
672
+ }
673
  }
674
  } else {
675
  units.push(0xFFFD); // replacement character for invalid lead byte
 
685
  result += fromCharCode.apply(String, units);
686
  }
687
 
688
+ return result;
 
 
 
 
 
 
 
 
 
 
689
  }
690
 
691
  function readArray(length) {
 
694
  array[i] = read();
695
  }
696
  if (currentUnpackr.freezeData)
697
+ return Object.freeze(array);
698
+ return array;
699
  }
700
 
701
  function readMap(length) {
 
707
  key = '__proto_';
708
  object[key] = read();
709
  }
710
+ return object;
711
  } else {
712
  let map = new Map();
713
  for (let i = 0; i < length; i++) {
714
  map.set(read(), read());
715
  }
716
+ return map;
717
  }
718
  }
719
 
 
725
  const byte = src[position$1++];
726
  if ((byte & 0x80) > 0) {
727
  position$1 = start;
728
+ return;
729
  }
730
  bytes[i] = byte;
731
  }
732
+ return fromCharCode.apply(String, bytes);
733
  }
734
  function shortStringInJS(length) {
735
  if (length < 4) {
736
  if (length < 2) {
737
  if (length === 0)
738
+ return '';
739
  else {
740
  let a = src[position$1++];
741
  if ((a & 0x80) > 1) {
742
  position$1 -= 1;
743
+ return;
744
  }
745
+ return fromCharCode(a);
746
  }
747
  } else {
748
  let a = src[position$1++];
749
  let b = src[position$1++];
750
  if ((a & 0x80) > 0 || (b & 0x80) > 0) {
751
  position$1 -= 2;
752
+ return;
753
  }
754
  if (length < 3)
755
+ return fromCharCode(a, b);
756
  let c = src[position$1++];
757
  if ((c & 0x80) > 0) {
758
  position$1 -= 3;
759
+ return;
760
  }
761
+ return fromCharCode(a, b, c);
762
  }
763
  } else {
764
  let a = src[position$1++];
 
767
  let d = src[position$1++];
768
  if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
769
  position$1 -= 4;
770
+ return;
771
  }
772
  if (length < 6) {
773
  if (length === 4)
774
+ return fromCharCode(a, b, c, d);
775
  else {
776
  let e = src[position$1++];
777
  if ((e & 0x80) > 0) {
778
  position$1 -= 5;
779
+ return;
780
  }
781
+ return fromCharCode(a, b, c, d, e);
782
  }
783
  } else if (length < 8) {
784
  let e = src[position$1++];
785
  let f = src[position$1++];
786
  if ((e & 0x80) > 0 || (f & 0x80) > 0) {
787
  position$1 -= 6;
788
+ return;
789
  }
790
  if (length < 7)
791
+ return fromCharCode(a, b, c, d, e, f);
792
  let g = src[position$1++];
793
  if ((g & 0x80) > 0) {
794
  position$1 -= 7;
795
+ return;
796
  }
797
+ return fromCharCode(a, b, c, d, e, f, g);
798
  } else {
799
  let e = src[position$1++];
800
  let f = src[position$1++];
 
802
  let h = src[position$1++];
803
  if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
804
  position$1 -= 8;
805
+ return;
806
  }
807
  if (length < 10) {
808
  if (length === 8)
809
+ return fromCharCode(a, b, c, d, e, f, g, h);
810
  else {
811
  let i = src[position$1++];
812
  if ((i & 0x80) > 0) {
813
  position$1 -= 9;
814
+ return;
815
  }
816
+ return fromCharCode(a, b, c, d, e, f, g, h, i);
817
  }
818
  } else if (length < 12) {
819
  let i = src[position$1++];
820
  let j = src[position$1++];
821
  if ((i & 0x80) > 0 || (j & 0x80) > 0) {
822
  position$1 -= 10;
823
+ return;
824
  }
825
  if (length < 11)
826
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j);
827
  let k = src[position$1++];
828
  if ((k & 0x80) > 0) {
829
  position$1 -= 11;
830
+ return;
831
  }
832
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k);
833
  } else {
834
  let i = src[position$1++];
835
  let j = src[position$1++];
 
837
  let l = src[position$1++];
838
  if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
839
  position$1 -= 12;
840
+ return;
841
  }
842
  if (length < 14) {
843
  if (length === 12)
844
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l);
845
  else {
846
  let m = src[position$1++];
847
  if ((m & 0x80) > 0) {
848
  position$1 -= 13;
849
+ return;
850
  }
851
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m);
852
  }
853
  } else {
854
  let m = src[position$1++];
855
  let n = src[position$1++];
856
  if ((m & 0x80) > 0 || (n & 0x80) > 0) {
857
  position$1 -= 14;
858
+ return;
859
  }
860
  if (length < 15)
861
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n);
862
  let o = src[position$1++];
863
  if ((o & 0x80) > 0) {
864
  position$1 -= 15;
865
+ return;
866
  }
867
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
868
  }
869
  }
870
  }
 
882
  case 0xd9:
883
  // str 8
884
  length = src[position$1++];
885
+ break;
886
  case 0xda:
887
  // str 16
888
  length = dataView.getUint16(position$1);
889
  position$1 += 2;
890
+ break;
891
  case 0xdb:
892
  // str 32
893
  length = dataView.getUint32(position$1);
894
  position$1 += 4;
895
+ break;
896
  default:
897
+ throw new Error('Expected string');
898
  }
899
  }
900
+ return readStringJS(length);
901
  }
902
 
903
 
 
905
  return currentUnpackr.copyBuffers ?
906
  // specifically use the copying slice (not the node one)
907
  Uint8Array.prototype.slice.call(src, position$1, position$1 += length) :
908
+ src.subarray(position$1, position$1 += length);
909
  }
910
  function readExt(length) {
911
  let type = src[position$1++];
 
918
  } finally {
919
  position$1 = end;
920
  }
921
+ });
922
  }
923
  else
924
+ throw new Error('Unknown extension type ' + type);
925
  }
926
 
927
  var keyCache = new Array(4096);
 
931
  // fixstr, potentially use key cache
932
  length = length - 0xa0;
933
  if (srcStringEnd >= position$1) // if it has been extracted, must use it (and faster anyway)
934
+ return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart);
935
  else if (!(srcStringEnd == 0 && srcEnd < 180))
936
+ return readFixedString(length);
937
  } else { // not cacheable, go back and do a standard read
938
  position$1--;
939
+ return asSafeString(read());
940
  }
941
  let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position$1) : length > 0 ? src[position$1] : 0)) & 0xfff;
942
  let entry = keyCache[key];
 
949
  chunk = dataView.getUint32(checkPosition);
950
  if (chunk != entry[i++]) {
951
  checkPosition = 0x70000000;
952
+ break;
953
  }
954
  checkPosition += 4;
955
  }
 
958
  chunk = src[checkPosition++];
959
  if (chunk != entry[i++]) {
960
  checkPosition = 0x70000000;
961
+ break;
962
  }
963
  }
964
  if (checkPosition === end) {
965
  position$1 = checkPosition;
966
+ return entry.string;
967
  }
968
  end -= 3;
969
  checkPosition = position$1;
 
984
  // for small blocks, avoiding the overhead of the extract call is helpful
985
  let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
986
  if (string != null)
987
+ return entry.string = string;
988
+ return entry.string = readFixedString(length);
989
  }
990
 
991
  function asSafeString(property) {
 
1016
  }
1017
  currentStructures[id] = structure;
1018
  structure.read = createStructureReader(structure, firstByte);
1019
+ // The high byte (if any) was already consumed as the `highByte` argument above, so read the
1020
+ // record body directly. Going through structure.read (a second-byte reader when highByte === 0)
1021
+ // would misinterpret the first value byte as a high byte — corrupting two-byte own-record
1022
+ // definitions (0xd5 0x72 ...). createStructureReader stashes the un-wrapped body reader on
1023
+ // structure.read0 precisely for this immediate post-definition read.
1024
+ return (structure.read0 || structure.read)();
1025
  };
1026
  currentExtensions[0] = () => {}; // notepack defines extension 0 to mean undefined, so use that as the default here
1027
  currentExtensions[0].noBuffer = true;
 
1043
  out <<= BigInt(64);
1044
  out |= view.getBigUint64(i);
1045
  }
1046
+ return out;
1047
  }
1048
  // if (length === 8) return view.getBigUint64(start)
1049
  let middle = start + (length >> 4 << 3);
1050
  let left = decode(start, middle);
1051
  let right = decode(middle, end);
1052
+ return (left << BigInt((end - middle) * 8)) | right;
1053
  };
1054
  head = (head << BigInt((view.byteLength - headLength) * 8)) | decode(headLength, view.byteLength);
1055
  }
1056
+ return head;
1057
  };
1058
 
1059
  let errors = {
 
1064
  if (!errors[data[0]]) {
1065
  let error = Error(data[1], { cause: data[2] });
1066
  error.name = data[0];
1067
+ return error;
1068
  }
1069
+ return errors[data[0]](data[1], { cause: data[2] });
1070
  };
1071
 
1072
  currentExtensions[0x69] = (data) => {
1073
  // id extension (for structured clones)
1074
+ if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled');
1075
  let id = dataView.getUint32(position$1 - 4);
1076
  if (!referenceMap)
1077
  referenceMap = new Map();
 
1092
  let targetProperties = read(); // read the next value as the target object to id
1093
  if (!refEntry.used) {
1094
  // no cycle, can just use the returned read object
1095
+ return refEntry.target = targetProperties; // replace the placeholder with the real one
1096
  } else {
1097
  // there is a cycle, so we have to assign properties to original target
1098
  Object.assign(target, targetProperties);
 
1103
  for (let [k, v] of targetProperties.entries()) target.set(k, v);
1104
  if (target instanceof Set)
1105
  for (let i of Array.from(targetProperties)) target.add(i);
1106
+ return target;
1107
  };
1108
 
1109
  currentExtensions[0x70] = (data) => {
1110
  // pointer extension (for structured clones)
1111
+ if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled');
1112
  let id = dataView.getUint32(position$1 - 4);
1113
  let refEntry = referenceMap.get(id);
1114
  refEntry.used = true;
1115
+ return refEntry.target;
1116
  };
1117
 
1118
  currentExtensions[0x73] = () => new Set(read());
 
1127
 
1128
  let typedArrayName = typedArrays[typeCode];
1129
  if (!typedArrayName) {
1130
+ if (typeCode === 16) return buffer;
1131
+ if (typeCode === 17) return new DataView(buffer);
1132
+ throw new Error('Could not find typed array for code ' + typeCode);
1133
  }
1134
+ return new glbl[typedArrayName](buffer);
1135
  };
1136
  currentExtensions[0x78] = () => {
1137
  let data = read();
1138
+ return new RegExp(data[0], data[1]);
1139
  };
1140
  const TEMP_BUNDLE = [];
1141
  currentExtensions[0x62] = (data) => {
 
1148
  bundledStrings$1.position1 = 0;
1149
  bundledStrings$1.postBundlePosition = position$1;
1150
  position$1 = dataPosition;
1151
+ return read();
1152
  };
1153
 
1154
  currentExtensions[0xff] = (data) => {
1155
  // 32-bit date extension
1156
  if (data.length == 4)
1157
+ return new Date((data[0] * 0x1000000 + (data[1] << 16) + (data[2] << 8) + data[3]) * 1000);
1158
  else if (data.length == 8)
1159
  return new Date(
1160
  ((data[0] << 22) + (data[1] << 14) + (data[2] << 6) + (data[3] >> 2)) / 1000000 +
1161
+ ((data[3] & 0x3) * 0x100000000 + data[4] * 0x1000000 + (data[5] << 16) + (data[6] << 8) + data[7]) * 1000);
1162
  else if (data.length == 12)
1163
  return new Date(
1164
  ((data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]) / 1000000 +
1165
+ (((data[4] & 0x80) ? -0x1000000000000 : 0) + data[6] * 0x10000000000 + data[7] * 0x100000000 + data[8] * 0x1000000 + (data[9] << 16) + (data[10] << 8) + data[11]) * 1000);
1166
  else
1167
+ return new Date('invalid');
1168
  };
1169
  // registration of bulk record definition?
1170
  // currentExtensions[0x52] = () =>
1171
 
1172
+ function saveState(callback) {
1173
+ if (currentUnpackr && currentUnpackr._onSaveState)
1174
+ currentUnpackr._onSaveState();
1175
  let savedSrcEnd = srcEnd;
1176
  let savedPosition = position$1;
1177
  let savedStringPosition = stringPosition;
 
1204
  currentStructures.splice(0, currentStructures.length, ...savedStructuresContents);
1205
  currentUnpackr = savedPackr;
1206
  dataView = new DataView(src.buffer, src.byteOffset, src.byteLength);
1207
+ return value;
1208
  }
1209
  function clearSource() {
1210
  src = null;
 
1239
  function roundFloat32(float32Number) {
1240
  f32Array[0] = float32Number;
1241
  let multiplier = mult10[((u8Array[3] & 0x7f) << 1) | (u8Array[2] >> 7)];
1242
+ return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier;
 
 
 
 
 
1243
  }
1244
+ // Marker for downstream libraries (e.g. structon) to detect per-instance
1245
+ // struct-decoding hooks (this._readStruct, this._onLoadedStructures,
1246
+ // this._onSaveState). See `checkedRead` for the dispatch.
1247
+ Unpackr.SUPPORTS_STRUCT_HOOKS = true;
1248
 
1249
+ let textEncoder;
1250
  try {
1251
+ textEncoder = new TextEncoder();
1252
  } catch (error) {}
1253
  let extensions, extensionClasses;
1254
+ const hasNodeBuffer = typeof Buffer !== 'undefined';
1255
+ const ByteArrayAllocate = hasNodeBuffer ?
1256
+ function(length) { return Buffer.allocUnsafeSlow(length); } : Uint8Array;
1257
+ const ByteArray = hasNodeBuffer ? Buffer : Uint8Array;
1258
+ const MAX_BUFFER_SIZE = hasNodeBuffer ? 0x100000000 : 0x7fd00000;
1259
  let target, keysTarget;
1260
  let targetView;
1261
  let position = 0;
1262
  let safeEnd;
1263
  let bundledStrings = null;
 
1264
  const MAX_BUNDLE_SIZE = 0x5500; // maximum characters such that the encoded bytes fits in 16 bits.
1265
  const hasNonLatin = /[\u0080-\uFFFF]/;
1266
  const RECORD_SYMBOL = Symbol('record-id');
 
1273
  let structures;
1274
  let referenceMap;
1275
  let encodeUtf8 = ByteArray.prototype.utf8Write ? function(string, position) {
1276
+ return target.utf8Write(string, position, target.byteLength - position);
1277
+ } : (textEncoder && textEncoder.encodeInto) ?
1278
  function(string, position) {
1279
+ return textEncoder.encodeInto(string, target.subarray(position)).written;
1280
  } : false;
1281
 
1282
  let packr = this;
 
1288
  if (maxSharedStructures == null)
1289
  maxSharedStructures = hasSharedStructures ? 32 : 0;
1290
  if (maxSharedStructures > 8160)
1291
+ throw new Error('Maximum maxSharedStructure is 8160');
1292
  if (options.structuredClone && options.moreTypes == undefined) {
1293
  this.moreTypes = true;
1294
  }
 
1302
  let sharedLimitId = maxSharedStructures + 0x40;
1303
  let maxStructureId = maxSharedStructures + maxOwnStructures + 0x40;
1304
  if (maxStructureId > 8256) {
1305
+ throw new Error('Maximum maxSharedStructure + maxOwnStructure is 8192');
1306
  }
1307
  let recordIdsToRemove = [];
1308
  let transitionsCount = 0;
 
1338
  let sharedLength = structures.sharedLength || 0;
1339
  if (sharedLength > maxSharedStructures) {
1340
  //if (maxSharedStructures <= 32 && structures.sharedLength > 32) // TODO: could support this, but would need to update the limit ids
1341
+ throw new Error('Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to ' + structures.sharedLength);
1342
  }
1343
  if (!structures.transitions) {
1344
  // rebuild our structure transitions
 
1346
  for (let i = 0; i < sharedLength; i++) {
1347
  let keys = structures[i];
1348
  if (!keys)
1349
+ continue;
1350
  let nextTransition, transition = structures.transitions;
1351
  for (let j = 0, l = keys.length; j < l; j++) {
1352
  let key = keys[j];
 
1368
  hasSharedUpdate = false;
1369
  let encodingError;
1370
  try {
1371
+ if (packr._writeStruct && value && typeof value === 'object') {
1372
  if (value.constructor === Object) writeStruct(value); // simple object
1373
  else if (value.constructor !== Map && !Array.isArray(value) && !extensionClasses.some(extClass => value instanceof extClass)) {
1374
  // allow user classes, if they don't need special handling (but do use toJSON if available)
 
1412
  packr.offset = position;
1413
  let serialized = insertIds(target.subarray(start, position), idsToInsert);
1414
  referenceMap = null;
1415
+ return serialized;
1416
  }
1417
  packr.offset = position; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
1418
  if (encodeOptions & REUSE_BUFFER_MODE) {
1419
  target.start = start;
1420
  target.end = position;
1421
+ return target;
1422
  }
1423
+ return target.subarray(start, position); // position can change if we call pack again in saveStructures, so we get the buffer now
1424
  } catch(error) {
1425
  encodingError = error;
1426
  throw error;
 
1431
  let sharedLength = structures.sharedLength || 0;
1432
  // we can't rely on start/end with REUSE_BUFFER_MODE since they will (probably) change when we save
1433
  let returnBuffer = target.subarray(start, position);
1434
+ let newSharedData = (packr._prepareStructures || prepareStructures)(structures, packr);
1435
  if (!encodingError) { // TODO: If there is an encoding error, should make the structures as uninitialized so they get rebuilt next time
1436
  if (packr.saveStructures(newSharedData, newSharedData.isCompatible) === false) {
1437
+ // The save was declined (a concurrent writer updated the shared structures,
1438
+ // or the store transaction did not durably commit). Our in-memory
1439
+ // structures + transition trie may now reference record ids that were
1440
+ // never persisted; re-packing as-is would re-emit the same record pointing
1441
+ // at an unpersisted structure (-> "Record id is not defined" on decode).
1442
+ // Mark structures uninitialized so the re-pack reloads durable structures
1443
+ // via getStructures, rebuilds the transition trie, and re-mints + re-saves.
1444
+ structures.uninitialized = true;
1445
+ return packr.pack(value, encodeOptions);
1446
  }
1447
  packr.lastNamedStructuresLength = sharedLength;
1448
  // don't keep large buffers around
1449
  if (target.length > 0x40000000) target = null;
1450
+ return returnBuffer;
1451
  }
1452
  }
1453
  }
 
1533
  bundledStrings[twoByte ? 0 : 1] += value;
1534
  target[position++] = 0xc1;
1535
  pack(twoByte ? -strLength : strLength);
1536
+ return;
1537
  }
1538
  let headerSize;
1539
  // first we estimate the header size, so we can write to the correct location
 
1607
  } else if (type === 'number') {
1608
  if (value >>> 0 === value) {// positive integer, 32-bit or less
1609
  // positive uint
1610
+ if (value < 0x20 || (value < 0x80 && this.useRecords === false) || (value < 0x40 && !this._writeStruct)) {
1611
  target[position++] = value;
1612
  } else if (value < 0x100) {
1613
  target[position++] = 0xcc;
 
1646
  // this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
1647
  ((xShifted = value * mult10[((target[position] & 0x7f) << 1) | (target[position + 1] >> 7)]) >> 0) === xShifted) {
1648
  position += 4;
1649
+ return;
1650
  } else
1651
  position--; // move back into position for writing a double
1652
  }
 
1669
  target[position++] = 0x70; // "p" for pointer
1670
  targetView.setUint32(position, referee.id);
1671
  position += 4;
1672
+ return;
1673
  } else
1674
  referenceMap.set(value, { offset: position - start });
1675
  }
 
1719
  } else {
1720
  pack(writeResult);
1721
  }
1722
+ return;
1723
  }
1724
  let currentTarget = target;
1725
  let currentTargetView = targetView;
 
1736
  makeRoom(position);
1737
  return {
1738
  target, targetView, position: position - size
1739
+ };
1740
  }, pack);
1741
  } finally {
1742
  // restore current target information (unless already restored)
 
1752
  makeRoom(result.length + position);
1753
  position = writeExtensionData(result, target, position, extension.type);
1754
  }
1755
+ return;
1756
  }
1757
  }
1758
  // check isArray after extensions, because extensions can extend Array
 
1764
  const json = value.toJSON();
1765
  // if for some reason value.toJSON returns itself it'll loop forever
1766
  if (json !== value)
1767
+ return pack(json);
1768
  }
1769
 
1770
  // if there is a writeFunction, use it, otherwise just encode as undefined
 
1803
  let chunks = [];
1804
  while (true) {
1805
  chunks.push(value & mask);
1806
+ if ((value >> BigInt(63)) === empty) break;
1807
  value >>= BigInt(64);
1808
  }
1809
 
 
1818
  string = '00' + string;
1819
  }
1820
 
1821
+ if (hasNodeBuffer) {
1822
  array = Buffer.from(string, 'hex');
1823
  } else {
1824
  array = new Uint8Array(string.length / 2);
 
1835
  if (array.length + position > safeEnd)
1836
  makeRoom(array.length + position);
1837
  position = writeExtensionData(array, target, position, 0x42);
1838
+ return;
1839
  } else {
1840
  throw new RangeError(value + ' was too large to fit in MessagePack 64-bit integer format, use' +
1841
  ' useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set' +
1842
+ ' largeBigIntToString to convert to string');
1843
  }
1844
  }
1845
  position += 8;
 
1852
  target[position++] = 0;
1853
  }
1854
  } else {
1855
+ throw new Error('Unknown type: ' + type);
1856
  }
1857
  };
1858
 
 
1998
  checkUseRecords(object) ? writeRecord(object) : writePlainObject(object);
1999
  } : writeRecord;
2000
 
2001
+ const writeStruct = (object) => {
2002
+ let newPosition = packr._writeStruct(object, target, start, position, structures, makeRoom, (value, newPosition, notifySharedUpdate) => {
2003
+ if (notifySharedUpdate)
2004
+ return hasSharedUpdate = true;
2005
+ position = newPosition;
2006
+ let startTarget = target;
2007
+ pack(value);
2008
+ resetStructures();
2009
+ if (startTarget !== target) {
2010
+ return { position, targetView, target }; // indicate the buffer was re-allocated
2011
+ }
2012
+ return position;
2013
+ });
2014
+ if (newPosition === 0) // bail and go to a msgpack object
2015
+ return writeObject(object);
2016
+ position = newPosition;
2017
+ };
2018
+
2019
  const makeRoom = (end) => {
2020
  let newSize;
2021
  if (end > 0x1000000) {
2022
  // special handling for really large buffers
2023
  if ((end - start) > MAX_BUFFER_SIZE)
2024
+ throw new Error('Packed buffer would be larger than maximum buffer size');
2025
  newSize = Math.min(MAX_BUFFER_SIZE,
2026
  Math.round(Math.max((end - start) * (end > 0x4000000 ? 1.25 : 2), 0x400000) / 0x1000) * 0x1000);
2027
  } else // faster handling for smaller buffers
 
2036
  position -= start;
2037
  start = 0;
2038
  safeEnd = newBuffer.length - 10;
2039
+ return target = newBuffer;
2040
  };
2041
  const newRecord = (transition, keys, newTransitions) => {
2042
  let recordId = structures.nextId;
 
2118
  target[insertionOffset + start] = keysTarget[0];
2119
  }
2120
  };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2121
  }
2122
  useBuffer(buffer) {
2123
  // this means we are finished using our own buffer and we can write over it safely
 
2160
  } else if (isNaN(seconds)) {
2161
  if (this.onInvalidDate) {
2162
  allocateForWrite(0);
2163
+ return pack(this.onInvalidDate());
2164
  }
2165
  // Intentionally invalid timestamp
2166
  let { target, targetView, position} = allocateForWrite(3);
 
2181
  pack(set, allocateForWrite, pack) {
2182
  if (this.setAsEmptyObject) {
2183
  allocateForWrite(0);
2184
+ return pack({});
2185
  }
2186
  let array = Array.from(set);
2187
  let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
 
2217
  if (this.moreTypes)
2218
  writeExtBuffer(arrayBuffer, 0x10, allocateForWrite);
2219
  else
2220
+ writeBuffer(hasNodeBuffer ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite);
2221
  }
2222
  }, {
2223
  pack(typedArray, allocateForWrite) {
 
2232
  if (this.moreTypes)
2233
  writeExtBuffer(arrayBuffer, 0x11, allocateForWrite);
2234
  else
2235
+ writeBuffer(hasNodeBuffer ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite);
2236
  }
2237
  }, {
2238
  pack(c1, allocateForWrite) { // specific 0xC1 object
 
2289
  switch (length) {
2290
  case 1:
2291
  target[position++] = 0xd4;
2292
+ break;
2293
  case 2:
2294
  target[position++] = 0xd5;
2295
+ break;
2296
  case 4:
2297
  target[position++] = 0xd6;
2298
+ break;
2299
  case 8:
2300
  target[position++] = 0xd7;
2301
+ break;
2302
  case 16:
2303
  target[position++] = 0xd8;
2304
+ break;
2305
  default:
2306
  if (length < 0x100) {
2307
  target[position++] = 0xc7;
 
2321
  target[position++] = type;
2322
  target.set(result, position);
2323
  position += length;
2324
+ return position;
2325
  }
2326
 
2327
  function insertIds(serialized, idsToInsert) {
 
2343
  serialized[position++] = id & 0xff;
2344
  lastEnd = offset;
2345
  }
2346
+ return serialized;
2347
  }
2348
 
2349
  function writeBundles(start, pack, incrementPosition) {
 
2360
  function addExtension(extension) {
2361
  if (extension.Class) {
2362
  if (!extension.pack && !extension.write)
2363
+ throw new Error('Extension has no pack or write function');
2364
  if (extension.pack && !extension.type)
2365
+ throw new Error('Extension has no type (numeric code to identify the extension)');
2366
  extensionClasses.unshift(extension.Class);
2367
  extensions.unshift(extension);
2368
  }
2369
  addExtension$1(extension);
2370
  }
2371
+ function prepareStructures(structures, packr) {
2372
  structures.isCompatible = (existingStructures) => {
2373
  let compatible = !existingStructures || ((packr.lastNamedStructuresLength || 0) === existingStructures.length);
2374
  if (!compatible) // we want to merge these existing structures immediately since we already have it and we are in the right transaction
2375
  packr._mergeStructures(existingStructures);
2376
  return compatible;
2377
  };
2378
+ return structures;
 
 
 
 
2379
  }
2380
 
2381
+ // Marker for downstream libraries (e.g. structon) to detect that this Packr
2382
+ // supports per-instance struct-encoding hooks (this._writeStruct,
2383
+ // this._prepareStructures). See `pack` for the dispatch.
2384
+ Packr.SUPPORTS_STRUCT_HOOKS = true;
2385
+
2386
  let defaultPackr = new Packr({ useRecords: false });
2387
  const pack = defaultPackr.pack;
2388
  const encode = defaultPackr.pack;
 
2392
  const RESET_BUFFER_MODE = 1024;
2393
  const RESERVE_START_SPACE = 2048;
2394
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2395
  class PackrStream extends stream.Transform {
2396
  constructor(options) {
2397
  if (!options)
 
2430
  let incompleteBuffer = chunk.slice(error.lastPosition);
2431
  if (incompleteBuffer.length > this.maxIncompleteBufferSize) {
2432
  this.incompleteBuffer = null;
2433
+ return callback(new Error('Maximum incomplete buffer size exceeded'));
2434
  }
2435
  this.incompleteBuffer = incompleteBuffer;
2436
  values = error.values;
2437
  } else {
2438
+ return callback(error);
2439
  }
2440
  }
2441
  for (let value of values || []) {
 
2446
  callback();
2447
  }
2448
  getNullValue() {
2449
+ return Symbol.for(null);
2450
  }
2451
  }
2452
 
 
2459
  */
2460
  function packIter (objectIterator, options = {}) {
2461
  if (!objectIterator || typeof objectIterator !== 'object') {
2462
+ throw new Error('first argument must be an Iterable, Async Iterable, or a Promise for an Async Iterable');
2463
  } else if (typeof objectIterator[Symbol.iterator] === 'function') {
2464
+ return packIterSync(objectIterator, options);
2465
  } else if (typeof objectIterator.then === 'function' || typeof objectIterator[Symbol.asyncIterator] === 'function') {
2466
+ return packIterAsync(objectIterator, options);
2467
  } else {
2468
+ throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a Promise');
2469
  }
2470
  }
2471
 
 
2492
  */
2493
  function unpackIter (bufferIterator, options = {}) {
2494
  if (!bufferIterator || typeof bufferIterator !== 'object') {
2495
+ throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a promise');
2496
  }
2497
 
2498
  const unpackr = new Unpackr(options);
 
2512
  incomplete = chunk.slice(err.lastPosition);
2513
  yields = err.values;
2514
  } else {
2515
+ throw err;
2516
  }
2517
  }
2518
+ return yields;
2519
  };
2520
 
2521
  if (typeof bufferIterator[Symbol.iterator] === 'function') {
 
2523
  for (const value of bufferIterator) {
2524
  yield * parser(value);
2525
  }
2526
+ })();
2527
  } else if (typeof bufferIterator[Symbol.asyncIterator] === 'function') {
2528
  return (async function * iter () {
2529
  for await (const value of bufferIterator) {
2530
  yield * parser(value);
2531
  }
2532
+ })();
2533
  }
2534
  }
2535
  const decodeIter = unpackIter;
 
2546
  if (typeof require == 'function')
2547
  extractor = require('msgpackr-extract');
2548
  else
2549
+ extractor = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('node.cjs', document.baseURI).href)))('msgpackr-extract');
2550
  if (extractor)
2551
  setExtractor(extractor.extractStrings);
2552
  } catch (error) {
.opencode/node_modules/msgpackr/dist/node.cjs.map CHANGED
The diff for this file is too large to render. See raw diff
 
.opencode/node_modules/msgpackr/dist/test.js CHANGED
@@ -1,6 +1,7 @@
1
  (function (chai, stream, module, fs) {
2
  'use strict';
3
 
 
4
  var decoder;
5
  try {
6
  decoder = new TextDecoder();
@@ -29,7 +30,6 @@
29
  C1.name = 'MessagePack 0xC1';
30
  var sequentialMode = false;
31
  var inlineObjectReadThreshold = 2;
32
- var readStruct$1, onLoadedStructures$1, onSaveState;
33
 
34
  let Unpackr$1 = class Unpackr {
35
  constructor(options) {
@@ -59,10 +59,10 @@
59
  unpack(source, options) {
60
  if (src) {
61
  // re-entrant execution, save the state and restore it after we do this unpack
62
- return saveState$1(() => {
63
  clearSource();
64
- return this ? this.unpack(source, options) : Unpackr$1.prototype.unpack.call(defaultOptions, source, options)
65
- })
66
  }
67
  if (!source.buffer && source.constructor === ArrayBuffer)
68
  source = typeof Buffer !== 'undefined' ? Buffer.from(source) : new Uint8Array(source);
@@ -88,14 +88,14 @@
88
  // if it doesn't have a buffer, maybe it is the wrong type of object
89
  src = null;
90
  if (source instanceof Uint8Array)
91
- throw error
92
- throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source))
93
  }
94
- if (this instanceof Unpackr$1) {
95
  currentUnpackr = this;
96
  if (this.structures) {
97
  currentStructures = this.structures;
98
- return checkedRead(options)
99
  } else if (!currentStructures || currentStructures.length > 0) {
100
  currentStructures = [];
101
  }
@@ -104,7 +104,7 @@
104
  if (!currentStructures || currentStructures.length > 0)
105
  currentStructures = [];
106
  }
107
- return checkedRead(options)
108
  }
109
  unpackMultiple(source, forEach) {
110
  let values, lastPosition = 0;
@@ -117,7 +117,7 @@
117
  while(position$1 < size) {
118
  lastPosition = position$1;
119
  if (forEach(checkedRead(), lastPosition, position$1) === false) {
120
- return
121
  }
122
  }
123
  }
@@ -127,20 +127,20 @@
127
  lastPosition = position$1;
128
  values.push(checkedRead());
129
  }
130
- return values
131
  }
132
  } catch(error) {
133
  error.lastPosition = lastPosition;
134
  error.values = values;
135
- throw error
136
  } finally {
137
  sequentialMode = false;
138
  clearSource();
139
  }
140
  }
141
  _mergeStructures(loadedStructures, existingStructures) {
142
- if (onLoadedStructures$1)
143
- loadedStructures = onLoadedStructures$1.call(this, loadedStructures);
144
  loadedStructures = loadedStructures || [];
145
  if (Object.isFrozen(loadedStructures))
146
  loadedStructures = loadedStructures.map(structure => structure.slice(0));
@@ -164,10 +164,10 @@
164
  }
165
  }
166
  }
167
- return this.structures = loadedStructures
168
  }
169
  decode(source, options) {
170
- return this.unpack(source, options)
171
  }
172
  };
173
  function checkedRead(options) {
@@ -178,8 +178,8 @@
178
  currentStructures.length = sharedLength;
179
  }
180
  let result;
181
- if (currentUnpackr.randomAccessStructure && src[position$1] < 0x40 && src[position$1] >= 0x20 && readStruct$1) {
182
- result = readStruct$1(src, position$1, srcEnd, currentUnpackr);
183
  src = null; // dispose of this so that recursive unpack calls don't save state
184
  if (!(options && options.lazy) && result)
185
  result = result.toJSON();
@@ -205,7 +205,7 @@
205
  referenceMap = null;
206
  } else if (position$1 > srcEnd) {
207
  // over read
208
- throw new Error('Unexpected end of MessagePack data')
209
  } else if (!sequentialMode) {
210
  let jsonView;
211
  try {
@@ -213,10 +213,10 @@
213
  } catch(error) {
214
  jsonView = '(JSON view not available ' + error + ')';
215
  }
216
- throw new Error('Data read, but end of buffer not reached ' + jsonView)
217
  }
218
  // else more to read, but we are reading sequentially, so don't clear source yet
219
- return result
220
  } catch(error) {
221
  if (currentStructures && currentStructures.restoreStructures)
222
  restoreStructures();
@@ -224,7 +224,7 @@
224
  if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position$1 > srcEnd) {
225
  error.incomplete = true;
226
  }
227
- throw error
228
  }
229
  }
230
 
@@ -240,7 +240,7 @@
240
  if (token < 0xa0) {
241
  if (token < 0x80) {
242
  if (token < 0x40)
243
- return token
244
  else {
245
  let structure = currentStructures[token & 0x3f] ||
246
  currentUnpackr.getStructures && loadStructures()[token & 0x3f];
@@ -248,9 +248,9 @@
248
  if (!structure.read) {
249
  structure.read = createStructureReader(structure, token & 0x3f);
250
  }
251
- return structure.read()
252
  } else
253
- return token
254
  }
255
  } else if (token < 0x90) {
256
  // map
@@ -263,13 +263,13 @@
263
  key = '__proto_';
264
  object[key] = read();
265
  }
266
- return object
267
  } else {
268
  let map = new Map();
269
  for (let i = 0; i < token; i++) {
270
  map.set(read(), read());
271
  }
272
- return map
273
  }
274
  } else {
275
  token -= 0x90;
@@ -278,91 +278,91 @@
278
  array[i] = read();
279
  }
280
  if (currentUnpackr.freezeData)
281
- return Object.freeze(array)
282
- return array
283
  }
284
  } else if (token < 0xc0) {
285
  // fixstr
286
  let length = token - 0xa0;
287
  if (srcStringEnd >= position$1) {
288
- return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart)
289
  }
290
  if (srcStringEnd == 0 && srcEnd < 140) {
291
  // for small blocks, avoiding the overhead of the extract call is helpful
292
  let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
293
  if (string != null)
294
- return string
295
  }
296
- return readFixedString(length)
297
  } else {
298
  let value;
299
  switch (token) {
300
- case 0xc0: return null
301
  case 0xc1:
302
  if (bundledStrings$1) {
303
  value = read(); // followed by the length of the string in characters (not bytes!)
304
  if (value > 0)
305
- return bundledStrings$1[1].slice(bundledStrings$1.position1, bundledStrings$1.position1 += value)
306
  else
307
- return bundledStrings$1[0].slice(bundledStrings$1.position0, bundledStrings$1.position0 -= value)
308
  }
309
  return C1; // "never-used", return special object to denote that
310
- case 0xc2: return false
311
- case 0xc3: return true
312
  case 0xc4:
313
  // bin 8
314
  value = src[position$1++];
315
  if (value === undefined)
316
- throw new Error('Unexpected end of buffer')
317
- return readBin(value)
318
  case 0xc5:
319
  // bin 16
320
  value = dataView.getUint16(position$1);
321
  position$1 += 2;
322
- return readBin(value)
323
  case 0xc6:
324
  // bin 32
325
  value = dataView.getUint32(position$1);
326
  position$1 += 4;
327
- return readBin(value)
328
  case 0xc7:
329
  // ext 8
330
- return readExt(src[position$1++])
331
  case 0xc8:
332
  // ext 16
333
  value = dataView.getUint16(position$1);
334
  position$1 += 2;
335
- return readExt(value)
336
  case 0xc9:
337
  // ext 32
338
  value = dataView.getUint32(position$1);
339
  position$1 += 4;
340
- return readExt(value)
341
  case 0xca:
342
  value = dataView.getFloat32(position$1);
343
  if (currentUnpackr.useFloat32 > 2) {
344
  // this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
345
  let multiplier = mult10[((src[position$1] & 0x7f) << 1) | (src[position$1 + 1] >> 7)];
346
  position$1 += 4;
347
- return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier
348
  }
349
  position$1 += 4;
350
- return value
351
  case 0xcb:
352
  value = dataView.getFloat64(position$1);
353
  position$1 += 8;
354
- return value
355
  // uint handlers
356
  case 0xcc:
357
- return src[position$1++]
358
  case 0xcd:
359
  value = dataView.getUint16(position$1);
360
  position$1 += 2;
361
- return value
362
  case 0xce:
363
  value = dataView.getUint32(position$1);
364
  position$1 += 4;
365
- return value
366
  case 0xcf:
367
  if (currentUnpackr.int64AsType === 'number') {
368
  value = dataView.getUint32(position$1) * 0x100000000;
@@ -375,19 +375,19 @@
375
  } else
376
  value = dataView.getBigUint64(position$1);
377
  position$1 += 8;
378
- return value
379
 
380
  // int handlers
381
  case 0xd0:
382
- return dataView.getInt8(position$1++)
383
  case 0xd1:
384
  value = dataView.getInt16(position$1);
385
  position$1 += 2;
386
- return value
387
  case 0xd2:
388
  value = dataView.getInt32(position$1);
389
  position$1 += 4;
390
- return value
391
  case 0xd3:
392
  if (currentUnpackr.int64AsType === 'number') {
393
  value = dataView.getInt32(position$1) * 0x100000000;
@@ -400,96 +400,96 @@
400
  } else
401
  value = dataView.getBigInt64(position$1);
402
  position$1 += 8;
403
- return value
404
 
405
  case 0xd4:
406
  // fixext 1
407
  value = src[position$1++];
408
  if (value == 0x72) {
409
- return recordDefinition(src[position$1++] & 0x3f)
410
  } else {
411
  let extension = currentExtensions[value];
412
  if (extension) {
413
  if (extension.read) {
414
  position$1++; // skip filler byte
415
- return extension.read(read())
416
  } else if (extension.noBuffer) {
417
  position$1++; // skip filler byte
418
- return extension()
419
  } else
420
- return extension(src.subarray(position$1, ++position$1))
421
  } else
422
- throw new Error('Unknown extension ' + value)
423
  }
424
  case 0xd5:
425
  // fixext 2
426
  value = src[position$1];
427
  if (value == 0x72) {
428
  position$1++;
429
- return recordDefinition(src[position$1++] & 0x3f, src[position$1++])
430
  } else
431
- return readExt(2)
432
  case 0xd6:
433
  // fixext 4
434
- return readExt(4)
435
  case 0xd7:
436
  // fixext 8
437
- return readExt(8)
438
  case 0xd8:
439
  // fixext 16
440
- return readExt(16)
441
  case 0xd9:
442
  // str 8
443
  value = src[position$1++];
444
  if (srcStringEnd >= position$1) {
445
- return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
446
  }
447
- return readString8(value)
448
  case 0xda:
449
  // str 16
450
  value = dataView.getUint16(position$1);
451
  position$1 += 2;
452
  if (srcStringEnd >= position$1) {
453
- return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
454
  }
455
- return readString16(value)
456
  case 0xdb:
457
  // str 32
458
  value = dataView.getUint32(position$1);
459
  position$1 += 4;
460
  if (srcStringEnd >= position$1) {
461
- return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart)
462
  }
463
- return readString32(value)
464
  case 0xdc:
465
  // array 16
466
  value = dataView.getUint16(position$1);
467
  position$1 += 2;
468
- return readArray(value)
469
  case 0xdd:
470
  // array 32
471
  value = dataView.getUint32(position$1);
472
  position$1 += 4;
473
- return readArray(value)
474
  case 0xde:
475
  // map 16
476
  value = dataView.getUint16(position$1);
477
  position$1 += 2;
478
- return readMap(value)
479
  case 0xdf:
480
  // map 32
481
  value = dataView.getUint32(position$1);
482
  position$1 += 4;
483
- return readMap(value)
484
  default: // negative int
485
  if (token >= 0xe0)
486
- return token - 0x100
487
  if (token === undefined) {
488
  let error = new Error('Unexpected end of MessagePack data');
489
  error.incomplete = true;
490
- throw error
491
  }
492
- throw new Error('Unknown MessagePack token ' + token)
493
 
494
  }
495
  }
@@ -508,9 +508,10 @@
508
  inlineObjectReadThreshold = Infinity; // disable going forward
509
  return readObject(); // recursively try again
510
  }
 
511
  if (structure.highByte === 0)
512
  structure.read = createSecondByteReader(firstId, structure.read);
513
- return optimizedReadObject() // second byte is already read, if there is one so immediately read object
514
  }
515
  let object = {};
516
  for (let i = 0, l = structure.length; i < l; i++) {
@@ -521,38 +522,44 @@
521
  }
522
  if (currentUnpackr.freezeData)
523
  return Object.freeze(object);
524
- return object
525
  }
526
  readObject.count = 0;
 
 
 
 
 
 
527
  if (structure.highByte === 0) {
528
- return createSecondByteReader(firstId, readObject)
529
  }
530
- return readObject
531
  }
532
 
533
  const createSecondByteReader = (firstId, read0) => {
534
  return function() {
535
  let highByte = src[position$1++];
536
  if (highByte === 0)
537
- return read0()
538
  let id = firstId < 32 ? -(firstId + (highByte << 5)) : firstId + (highByte << 5);
539
  let structure = currentStructures[id] || loadStructures()[id];
540
  if (!structure) {
541
- throw new Error('Record id is not defined for ' + id)
542
  }
543
  if (!structure.read)
544
  structure.read = createStructureReader(structure, firstId);
545
- return structure.read()
546
- }
547
  };
548
 
549
  function loadStructures() {
550
- let loadedStructures = saveState$1(() => {
551
  // save the state in case getStructures modifies our buffer
552
  src = null;
553
- return currentUnpackr.getStructures()
554
  });
555
- return currentStructures = currentUnpackr._mergeStructures(loadedStructures, currentStructures)
556
  }
557
 
558
  var readFixedString = readStringJS;
@@ -570,7 +577,7 @@
570
  let string = strings[stringPosition++];
571
  if (string == null) {
572
  if (bundledStrings$1)
573
- return readStringJS(length)
574
  let byteOffset = src.byteOffset;
575
  let extraction = extractStrings(position$1 - headerLength + byteOffset, srcEnd + byteOffset, src.buffer);
576
  if (typeof extraction == 'string') {
@@ -582,30 +589,30 @@
582
  srcStringEnd = 1; // even if a utf-8 string was decoded, must indicate we are in the midst of extracted strings and can't skip strings
583
  string = strings[0];
584
  if (string === undefined)
585
- throw new Error('Unexpected end of buffer')
586
  }
587
  }
588
  let srcStringLength = string.length;
589
  if (srcStringLength <= length) {
590
  position$1 += length;
591
- return string
592
  }
593
  srcString = string;
594
  srcStringStart = position$1;
595
  srcStringEnd = position$1 + srcStringLength;
596
  position$1 += length;
597
- return string.slice(0, length) // we know we just want the beginning
598
- }
599
  }
600
  }
601
  function readStringJS(length) {
602
  let result;
603
  if (length < 16) {
604
  if (result = shortStringInJS(length))
605
- return result
606
  }
607
  if (length > 64 && decoder)
608
- return decoder.decode(src.subarray(position$1, position$1 += length))
609
  const end = position$1 + length;
610
  const units = [];
611
  result = '';
@@ -616,43 +623,49 @@
616
  units.push(byte1);
617
  } else if ((byte1 & 0xe0) === 0xc0) {
618
  // 2 bytes
619
- const byte2 = src[position$1++] & 0x3f;
620
- const codePoint = ((byte1 & 0x1f) << 6) | byte2;
621
- // Reject overlong encoding: 2-byte sequences must encode values >= 0x80
622
- if (codePoint < 0x80) {
623
- units.push(0xFFFD); // replacement character
624
  } else {
625
- units.push(codePoint);
 
626
  }
627
  } else if ((byte1 & 0xf0) === 0xe0) {
628
  // 3 bytes
629
- const byte2 = src[position$1++] & 0x3f;
630
- const byte3 = src[position$1++] & 0x3f;
631
- const codePoint = ((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3;
632
- // Reject overlong encoding: 3-byte sequences must encode values >= 0x800
633
- // Also reject surrogates (0xD800-0xDFFF)
634
- if (codePoint < 0x800 || (codePoint >= 0xD800 && codePoint <= 0xDFFF)) {
635
- units.push(0xFFFD); // replacement character
636
  } else {
637
- units.push(codePoint);
 
 
 
 
 
 
638
  }
639
  } else if ((byte1 & 0xf8) === 0xf0) {
640
  // 4 bytes
641
- const byte2 = src[position$1++] & 0x3f;
642
- const byte3 = src[position$1++] & 0x3f;
643
- const byte4 = src[position$1++] & 0x3f;
644
- let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;
645
- // Reject overlong encoding: 4-byte sequences must encode values >= 0x10000
646
- // Also reject values > 0x10FFFF (maximum valid Unicode)
647
- if (unit < 0x10000 || unit > 0x10FFFF) {
648
- units.push(0xFFFD); // replacement character
649
- } else if (unit > 0xffff) {
650
- unit -= 0x10000;
651
- units.push(((unit >>> 10) & 0x3ff) | 0xd800);
652
- unit = 0xdc00 | (unit & 0x3ff);
653
- units.push(unit);
654
  } else {
655
- units.push(unit);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
656
  }
657
  } else {
658
  units.push(0xFFFD); // replacement character for invalid lead byte
@@ -668,17 +681,7 @@
668
  result += fromCharCode.apply(String, units);
669
  }
670
 
671
- return result
672
- }
673
- function readString(source, start, length) {
674
- let existingSrc = src;
675
- src = source;
676
- position$1 = start;
677
- try {
678
- return readStringJS(length);
679
- } finally {
680
- src = existingSrc;
681
- }
682
  }
683
 
684
  function readArray(length) {
@@ -687,8 +690,8 @@
687
  array[i] = read();
688
  }
689
  if (currentUnpackr.freezeData)
690
- return Object.freeze(array)
691
- return array
692
  }
693
 
694
  function readMap(length) {
@@ -700,13 +703,13 @@
700
  key = '__proto_';
701
  object[key] = read();
702
  }
703
- return object
704
  } else {
705
  let map = new Map();
706
  for (let i = 0; i < length; i++) {
707
  map.set(read(), read());
708
  }
709
- return map
710
  }
711
  }
712
 
@@ -718,40 +721,40 @@
718
  const byte = src[position$1++];
719
  if ((byte & 0x80) > 0) {
720
  position$1 = start;
721
- return
722
  }
723
  bytes[i] = byte;
724
  }
725
- return fromCharCode.apply(String, bytes)
726
  }
727
  function shortStringInJS(length) {
728
  if (length < 4) {
729
  if (length < 2) {
730
  if (length === 0)
731
- return ''
732
  else {
733
  let a = src[position$1++];
734
  if ((a & 0x80) > 1) {
735
  position$1 -= 1;
736
- return
737
  }
738
- return fromCharCode(a)
739
  }
740
  } else {
741
  let a = src[position$1++];
742
  let b = src[position$1++];
743
  if ((a & 0x80) > 0 || (b & 0x80) > 0) {
744
  position$1 -= 2;
745
- return
746
  }
747
  if (length < 3)
748
- return fromCharCode(a, b)
749
  let c = src[position$1++];
750
  if ((c & 0x80) > 0) {
751
  position$1 -= 3;
752
- return
753
  }
754
- return fromCharCode(a, b, c)
755
  }
756
  } else {
757
  let a = src[position$1++];
@@ -760,34 +763,34 @@
760
  let d = src[position$1++];
761
  if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
762
  position$1 -= 4;
763
- return
764
  }
765
  if (length < 6) {
766
  if (length === 4)
767
- return fromCharCode(a, b, c, d)
768
  else {
769
  let e = src[position$1++];
770
  if ((e & 0x80) > 0) {
771
  position$1 -= 5;
772
- return
773
  }
774
- return fromCharCode(a, b, c, d, e)
775
  }
776
  } else if (length < 8) {
777
  let e = src[position$1++];
778
  let f = src[position$1++];
779
  if ((e & 0x80) > 0 || (f & 0x80) > 0) {
780
  position$1 -= 6;
781
- return
782
  }
783
  if (length < 7)
784
- return fromCharCode(a, b, c, d, e, f)
785
  let g = src[position$1++];
786
  if ((g & 0x80) > 0) {
787
  position$1 -= 7;
788
- return
789
  }
790
- return fromCharCode(a, b, c, d, e, f, g)
791
  } else {
792
  let e = src[position$1++];
793
  let f = src[position$1++];
@@ -795,34 +798,34 @@
795
  let h = src[position$1++];
796
  if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
797
  position$1 -= 8;
798
- return
799
  }
800
  if (length < 10) {
801
  if (length === 8)
802
- return fromCharCode(a, b, c, d, e, f, g, h)
803
  else {
804
  let i = src[position$1++];
805
  if ((i & 0x80) > 0) {
806
  position$1 -= 9;
807
- return
808
  }
809
- return fromCharCode(a, b, c, d, e, f, g, h, i)
810
  }
811
  } else if (length < 12) {
812
  let i = src[position$1++];
813
  let j = src[position$1++];
814
  if ((i & 0x80) > 0 || (j & 0x80) > 0) {
815
  position$1 -= 10;
816
- return
817
  }
818
  if (length < 11)
819
- return fromCharCode(a, b, c, d, e, f, g, h, i, j)
820
  let k = src[position$1++];
821
  if ((k & 0x80) > 0) {
822
  position$1 -= 11;
823
- return
824
  }
825
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k)
826
  } else {
827
  let i = src[position$1++];
828
  let j = src[position$1++];
@@ -830,34 +833,34 @@
830
  let l = src[position$1++];
831
  if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
832
  position$1 -= 12;
833
- return
834
  }
835
  if (length < 14) {
836
  if (length === 12)
837
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l)
838
  else {
839
  let m = src[position$1++];
840
  if ((m & 0x80) > 0) {
841
  position$1 -= 13;
842
- return
843
  }
844
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m)
845
  }
846
  } else {
847
  let m = src[position$1++];
848
  let n = src[position$1++];
849
  if ((m & 0x80) > 0 || (n & 0x80) > 0) {
850
  position$1 -= 14;
851
- return
852
  }
853
  if (length < 15)
854
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
855
  let o = src[position$1++];
856
  if ((o & 0x80) > 0) {
857
  position$1 -= 15;
858
- return
859
  }
860
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
861
  }
862
  }
863
  }
@@ -875,22 +878,22 @@
875
  case 0xd9:
876
  // str 8
877
  length = src[position$1++];
878
- break
879
  case 0xda:
880
  // str 16
881
  length = dataView.getUint16(position$1);
882
  position$1 += 2;
883
- break
884
  case 0xdb:
885
  // str 32
886
  length = dataView.getUint32(position$1);
887
  position$1 += 4;
888
- break
889
  default:
890
- throw new Error('Expected string')
891
  }
892
  }
893
- return readStringJS(length)
894
  }
895
 
896
 
@@ -898,7 +901,7 @@
898
  return currentUnpackr.copyBuffers ?
899
  // specifically use the copying slice (not the node one)
900
  Uint8Array.prototype.slice.call(src, position$1, position$1 += length) :
901
- src.subarray(position$1, position$1 += length)
902
  }
903
  function readExt(length) {
904
  let type = src[position$1++];
@@ -911,10 +914,10 @@
911
  } finally {
912
  position$1 = end;
913
  }
914
- })
915
  }
916
  else
917
- throw new Error('Unknown extension type ' + type)
918
  }
919
 
920
  var keyCache = new Array(4096);
@@ -924,12 +927,12 @@
924
  // fixstr, potentially use key cache
925
  length = length - 0xa0;
926
  if (srcStringEnd >= position$1) // if it has been extracted, must use it (and faster anyway)
927
- return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart)
928
  else if (!(srcStringEnd == 0 && srcEnd < 180))
929
- return readFixedString(length)
930
  } else { // not cacheable, go back and do a standard read
931
  position$1--;
932
- return asSafeString(read())
933
  }
934
  let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position$1) : length > 0 ? src[position$1] : 0)) & 0xfff;
935
  let entry = keyCache[key];
@@ -942,7 +945,7 @@
942
  chunk = dataView.getUint32(checkPosition);
943
  if (chunk != entry[i++]) {
944
  checkPosition = 0x70000000;
945
- break
946
  }
947
  checkPosition += 4;
948
  }
@@ -951,12 +954,12 @@
951
  chunk = src[checkPosition++];
952
  if (chunk != entry[i++]) {
953
  checkPosition = 0x70000000;
954
- break
955
  }
956
  }
957
  if (checkPosition === end) {
958
  position$1 = checkPosition;
959
- return entry.string
960
  }
961
  end -= 3;
962
  checkPosition = position$1;
@@ -977,8 +980,8 @@
977
  // for small blocks, avoiding the overhead of the extract call is helpful
978
  let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
979
  if (string != null)
980
- return entry.string = string
981
- return entry.string = readFixedString(length)
982
  }
983
 
984
  function asSafeString(property) {
@@ -1009,7 +1012,12 @@
1009
  }
1010
  currentStructures[id] = structure;
1011
  structure.read = createStructureReader(structure, firstByte);
1012
- return structure.read()
 
 
 
 
 
1013
  };
1014
  currentExtensions[0] = () => {}; // notepack defines extension 0 to mean undefined, so use that as the default here
1015
  currentExtensions[0].noBuffer = true;
@@ -1031,17 +1039,17 @@
1031
  out <<= BigInt(64);
1032
  out |= view.getBigUint64(i);
1033
  }
1034
- return out
1035
  }
1036
  // if (length === 8) return view.getBigUint64(start)
1037
  let middle = start + (length >> 4 << 3);
1038
  let left = decode(start, middle);
1039
  let right = decode(middle, end);
1040
- return (left << BigInt((end - middle) * 8)) | right
1041
  };
1042
  head = (head << BigInt((view.byteLength - headLength) * 8)) | decode(headLength, view.byteLength);
1043
  }
1044
- return head
1045
  };
1046
 
1047
  let errors = {
@@ -1052,14 +1060,14 @@
1052
  if (!errors[data[0]]) {
1053
  let error = Error(data[1], { cause: data[2] });
1054
  error.name = data[0];
1055
- return error
1056
  }
1057
- return errors[data[0]](data[1], { cause: data[2] })
1058
  };
1059
 
1060
  currentExtensions[0x69] = (data) => {
1061
  // id extension (for structured clones)
1062
- if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled')
1063
  let id = dataView.getUint32(position$1 - 4);
1064
  if (!referenceMap)
1065
  referenceMap = new Map();
@@ -1080,7 +1088,7 @@
1080
  let targetProperties = read(); // read the next value as the target object to id
1081
  if (!refEntry.used) {
1082
  // no cycle, can just use the returned read object
1083
- return refEntry.target = targetProperties // replace the placeholder with the real one
1084
  } else {
1085
  // there is a cycle, so we have to assign properties to original target
1086
  Object.assign(target, targetProperties);
@@ -1091,16 +1099,16 @@
1091
  for (let [k, v] of targetProperties.entries()) target.set(k, v);
1092
  if (target instanceof Set)
1093
  for (let i of Array.from(targetProperties)) target.add(i);
1094
- return target
1095
  };
1096
 
1097
  currentExtensions[0x70] = (data) => {
1098
  // pointer extension (for structured clones)
1099
- if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled')
1100
  let id = dataView.getUint32(position$1 - 4);
1101
  let refEntry = referenceMap.get(id);
1102
  refEntry.used = true;
1103
- return refEntry.target
1104
  };
1105
 
1106
  currentExtensions[0x73] = () => new Set(read());
@@ -1115,15 +1123,15 @@
1115
 
1116
  let typedArrayName = typedArrays[typeCode];
1117
  if (!typedArrayName) {
1118
- if (typeCode === 16) return buffer
1119
- if (typeCode === 17) return new DataView(buffer)
1120
- throw new Error('Could not find typed array for code ' + typeCode)
1121
  }
1122
- return new glbl[typedArrayName](buffer)
1123
  };
1124
  currentExtensions[0x78] = () => {
1125
  let data = read();
1126
- return new RegExp(data[0], data[1])
1127
  };
1128
  const TEMP_BUNDLE = [];
1129
  currentExtensions[0x62] = (data) => {
@@ -1136,30 +1144,30 @@
1136
  bundledStrings$1.position1 = 0;
1137
  bundledStrings$1.postBundlePosition = position$1;
1138
  position$1 = dataPosition;
1139
- return read()
1140
  };
1141
 
1142
  currentExtensions[0xff] = (data) => {
1143
  // 32-bit date extension
1144
  if (data.length == 4)
1145
- return new Date((data[0] * 0x1000000 + (data[1] << 16) + (data[2] << 8) + data[3]) * 1000)
1146
  else if (data.length == 8)
1147
  return new Date(
1148
  ((data[0] << 22) + (data[1] << 14) + (data[2] << 6) + (data[3] >> 2)) / 1000000 +
1149
- ((data[3] & 0x3) * 0x100000000 + data[4] * 0x1000000 + (data[5] << 16) + (data[6] << 8) + data[7]) * 1000)
1150
  else if (data.length == 12)
1151
  return new Date(
1152
  ((data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]) / 1000000 +
1153
- (((data[4] & 0x80) ? -0x1000000000000 : 0) + data[6] * 0x10000000000 + data[7] * 0x100000000 + data[8] * 0x1000000 + (data[9] << 16) + (data[10] << 8) + data[11]) * 1000)
1154
  else
1155
- return new Date('invalid')
1156
  };
1157
  // registration of bulk record definition?
1158
  // currentExtensions[0x52] = () =>
1159
 
1160
- function saveState$1(callback) {
1161
- if (onSaveState)
1162
- onSaveState();
1163
  let savedSrcEnd = srcEnd;
1164
  let savedPosition = position$1;
1165
  let savedStringPosition = stringPosition;
@@ -1192,7 +1200,7 @@
1192
  currentStructures.splice(0, currentStructures.length, ...savedStructuresContents);
1193
  currentUnpackr = savedPackr;
1194
  dataView = new DataView(src.buffer, src.byteOffset, src.byteLength);
1195
- return value
1196
  }
1197
  function clearSource() {
1198
  src = null;
@@ -1226,30 +1234,28 @@
1226
  function roundFloat32$1(float32Number) {
1227
  f32Array[0] = float32Number;
1228
  let multiplier = mult10[((u8Array[3] & 0x7f) << 1) | (u8Array[2] >> 7)];
1229
- return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier
1230
- }
1231
- function setReadStruct(updatedReadStruct, loadedStructs, saveState) {
1232
- readStruct$1 = updatedReadStruct;
1233
- onLoadedStructures$1 = loadedStructs;
1234
- onSaveState = saveState;
1235
  }
 
 
 
 
1236
 
1237
- let textEncoder$1;
1238
  try {
1239
- textEncoder$1 = new TextEncoder();
1240
  } catch (error) {}
1241
  let extensions, extensionClasses;
1242
- const hasNodeBuffer$1 = typeof Buffer !== 'undefined';
1243
- const ByteArrayAllocate = hasNodeBuffer$1 ?
1244
- function(length) { return Buffer.allocUnsafeSlow(length) } : Uint8Array;
1245
- const ByteArray = hasNodeBuffer$1 ? Buffer : Uint8Array;
1246
- const MAX_BUFFER_SIZE = hasNodeBuffer$1 ? 0x100000000 : 0x7fd00000;
1247
  let target, keysTarget;
1248
  let targetView;
1249
  let position = 0;
1250
  let safeEnd;
1251
  let bundledStrings = null;
1252
- let writeStructSlots;
1253
  const MAX_BUNDLE_SIZE = 0x5500; // maximum characters such that the encoded bytes fits in 16 bits.
1254
  const hasNonLatin = /[\u0080-\uFFFF]/;
1255
  const RECORD_SYMBOL = Symbol('record-id');
@@ -1262,10 +1268,10 @@
1262
  let structures;
1263
  let referenceMap;
1264
  let encodeUtf8 = ByteArray.prototype.utf8Write ? function(string, position) {
1265
- return target.utf8Write(string, position, target.byteLength - position)
1266
- } : (textEncoder$1 && textEncoder$1.encodeInto) ?
1267
  function(string, position) {
1268
- return textEncoder$1.encodeInto(string, target.subarray(position)).written
1269
  } : false;
1270
 
1271
  let packr = this;
@@ -1277,7 +1283,7 @@
1277
  if (maxSharedStructures == null)
1278
  maxSharedStructures = hasSharedStructures ? 32 : 0;
1279
  if (maxSharedStructures > 8160)
1280
- throw new Error('Maximum maxSharedStructure is 8160')
1281
  if (options.structuredClone && options.moreTypes == undefined) {
1282
  this.moreTypes = true;
1283
  }
@@ -1291,7 +1297,7 @@
1291
  let sharedLimitId = maxSharedStructures + 0x40;
1292
  let maxStructureId = maxSharedStructures + maxOwnStructures + 0x40;
1293
  if (maxStructureId > 8256) {
1294
- throw new Error('Maximum maxSharedStructure + maxOwnStructure is 8192')
1295
  }
1296
  let recordIdsToRemove = [];
1297
  let transitionsCount = 0;
@@ -1327,7 +1333,7 @@
1327
  let sharedLength = structures.sharedLength || 0;
1328
  if (sharedLength > maxSharedStructures) {
1329
  //if (maxSharedStructures <= 32 && structures.sharedLength > 32) // TODO: could support this, but would need to update the limit ids
1330
- throw new Error('Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to ' + structures.sharedLength)
1331
  }
1332
  if (!structures.transitions) {
1333
  // rebuild our structure transitions
@@ -1335,7 +1341,7 @@
1335
  for (let i = 0; i < sharedLength; i++) {
1336
  let keys = structures[i];
1337
  if (!keys)
1338
- continue
1339
  let nextTransition, transition = structures.transitions;
1340
  for (let j = 0, l = keys.length; j < l; j++) {
1341
  let key = keys[j];
@@ -1357,7 +1363,7 @@
1357
  hasSharedUpdate = false;
1358
  let encodingError;
1359
  try {
1360
- if (packr.randomAccessStructure && value && typeof value === 'object') {
1361
  if (value.constructor === Object) writeStruct(value); // simple object
1362
  else if (value.constructor !== Map && !Array.isArray(value) && !extensionClasses.some(extClass => value instanceof extClass)) {
1363
  // allow user classes, if they don't need special handling (but do use toJSON if available)
@@ -1401,15 +1407,15 @@
1401
  packr.offset = position;
1402
  let serialized = insertIds(target.subarray(start, position), idsToInsert);
1403
  referenceMap = null;
1404
- return serialized
1405
  }
1406
  packr.offset = position; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
1407
  if (encodeOptions & REUSE_BUFFER_MODE) {
1408
  target.start = start;
1409
  target.end = position;
1410
- return target
1411
  }
1412
- return target.subarray(start, position) // position can change if we call pack again in saveStructures, so we get the buffer now
1413
  } catch(error) {
1414
  encodingError = error;
1415
  throw error;
@@ -1420,16 +1426,23 @@
1420
  let sharedLength = structures.sharedLength || 0;
1421
  // we can't rely on start/end with REUSE_BUFFER_MODE since they will (probably) change when we save
1422
  let returnBuffer = target.subarray(start, position);
1423
- let newSharedData = prepareStructures$1(structures, packr);
1424
  if (!encodingError) { // TODO: If there is an encoding error, should make the structures as uninitialized so they get rebuilt next time
1425
  if (packr.saveStructures(newSharedData, newSharedData.isCompatible) === false) {
1426
- // get updated structures and try again if the update failed
1427
- return packr.pack(value, encodeOptions)
 
 
 
 
 
 
 
1428
  }
1429
  packr.lastNamedStructuresLength = sharedLength;
1430
  // don't keep large buffers around
1431
  if (target.length > 0x40000000) target = null;
1432
- return returnBuffer
1433
  }
1434
  }
1435
  }
@@ -1515,7 +1528,7 @@
1515
  bundledStrings[twoByte ? 0 : 1] += value;
1516
  target[position++] = 0xc1;
1517
  pack(twoByte ? -strLength : strLength);
1518
- return
1519
  }
1520
  let headerSize;
1521
  // first we estimate the header size, so we can write to the correct location
@@ -1589,7 +1602,7 @@
1589
  } else if (type === 'number') {
1590
  if (value >>> 0 === value) {// positive integer, 32-bit or less
1591
  // positive uint
1592
- if (value < 0x20 || (value < 0x80 && this.useRecords === false) || (value < 0x40 && !this.randomAccessStructure)) {
1593
  target[position++] = value;
1594
  } else if (value < 0x100) {
1595
  target[position++] = 0xcc;
@@ -1628,7 +1641,7 @@
1628
  // this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
1629
  ((xShifted = value * mult10[((target[position] & 0x7f) << 1) | (target[position + 1] >> 7)]) >> 0) === xShifted) {
1630
  position += 4;
1631
- return
1632
  } else
1633
  position--; // move back into position for writing a double
1634
  }
@@ -1651,7 +1664,7 @@
1651
  target[position++] = 0x70; // "p" for pointer
1652
  targetView.setUint32(position, referee.id);
1653
  position += 4;
1654
- return
1655
  } else
1656
  referenceMap.set(value, { offset: position - start });
1657
  }
@@ -1701,7 +1714,7 @@
1701
  } else {
1702
  pack(writeResult);
1703
  }
1704
- return
1705
  }
1706
  let currentTarget = target;
1707
  let currentTargetView = targetView;
@@ -1718,7 +1731,7 @@
1718
  makeRoom(position);
1719
  return {
1720
  target, targetView, position: position - size
1721
- }
1722
  }, pack);
1723
  } finally {
1724
  // restore current target information (unless already restored)
@@ -1734,7 +1747,7 @@
1734
  makeRoom(result.length + position);
1735
  position = writeExtensionData(result, target, position, extension.type);
1736
  }
1737
- return
1738
  }
1739
  }
1740
  // check isArray after extensions, because extensions can extend Array
@@ -1746,7 +1759,7 @@
1746
  const json = value.toJSON();
1747
  // if for some reason value.toJSON returns itself it'll loop forever
1748
  if (json !== value)
1749
- return pack(json)
1750
  }
1751
 
1752
  // if there is a writeFunction, use it, otherwise just encode as undefined
@@ -1785,7 +1798,7 @@
1785
  let chunks = [];
1786
  while (true) {
1787
  chunks.push(value & mask);
1788
- if ((value >> BigInt(63)) === empty) break
1789
  value >>= BigInt(64);
1790
  }
1791
 
@@ -1800,7 +1813,7 @@
1800
  string = '00' + string;
1801
  }
1802
 
1803
- if (hasNodeBuffer$1) {
1804
  array = Buffer.from(string, 'hex');
1805
  } else {
1806
  array = new Uint8Array(string.length / 2);
@@ -1817,11 +1830,11 @@
1817
  if (array.length + position > safeEnd)
1818
  makeRoom(array.length + position);
1819
  position = writeExtensionData(array, target, position, 0x42);
1820
- return
1821
  } else {
1822
  throw new RangeError(value + ' was too large to fit in MessagePack 64-bit integer format, use' +
1823
  ' useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set' +
1824
- ' largeBigIntToString to convert to string')
1825
  }
1826
  }
1827
  position += 8;
@@ -1834,7 +1847,7 @@
1834
  target[position++] = 0;
1835
  }
1836
  } else {
1837
- throw new Error('Unknown type: ' + type)
1838
  }
1839
  };
1840
 
@@ -1980,12 +1993,30 @@
1980
  checkUseRecords(object) ? writeRecord(object) : writePlainObject(object);
1981
  } : writeRecord;
1982
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1983
  const makeRoom = (end) => {
1984
  let newSize;
1985
  if (end > 0x1000000) {
1986
  // special handling for really large buffers
1987
  if ((end - start) > MAX_BUFFER_SIZE)
1988
- throw new Error('Packed buffer would be larger than maximum buffer size')
1989
  newSize = Math.min(MAX_BUFFER_SIZE,
1990
  Math.round(Math.max((end - start) * (end > 0x4000000 ? 1.25 : 2), 0x400000) / 0x1000) * 0x1000);
1991
  } else // faster handling for smaller buffers
@@ -2000,7 +2031,7 @@
2000
  position -= start;
2001
  start = 0;
2002
  safeEnd = newBuffer.length - 10;
2003
- return target = newBuffer
2004
  };
2005
  const newRecord = (transition, keys, newTransitions) => {
2006
  let recordId = structures.nextId;
@@ -2082,23 +2113,6 @@
2082
  target[insertionOffset + start] = keysTarget[0];
2083
  }
2084
  };
2085
- const writeStruct = (object) => {
2086
- let newPosition = writeStructSlots(object, target, start, position, structures, makeRoom, (value, newPosition, notifySharedUpdate) => {
2087
- if (notifySharedUpdate)
2088
- return hasSharedUpdate = true;
2089
- position = newPosition;
2090
- let startTarget = target;
2091
- pack(value);
2092
- resetStructures();
2093
- if (startTarget !== target) {
2094
- return { position, targetView, target }; // indicate the buffer was re-allocated
2095
- }
2096
- return position;
2097
- }, this);
2098
- if (newPosition === 0) // bail and go to a msgpack object
2099
- return writeObject(object);
2100
- position = newPosition;
2101
- };
2102
  }
2103
  useBuffer(buffer) {
2104
  // this means we are finished using our own buffer and we can write over it safely
@@ -2141,7 +2155,7 @@
2141
  } else if (isNaN(seconds)) {
2142
  if (this.onInvalidDate) {
2143
  allocateForWrite(0);
2144
- return pack(this.onInvalidDate())
2145
  }
2146
  // Intentionally invalid timestamp
2147
  let { target, targetView, position} = allocateForWrite(3);
@@ -2162,7 +2176,7 @@
2162
  pack(set, allocateForWrite, pack) {
2163
  if (this.setAsEmptyObject) {
2164
  allocateForWrite(0);
2165
- return pack({})
2166
  }
2167
  let array = Array.from(set);
2168
  let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
@@ -2198,7 +2212,7 @@
2198
  if (this.moreTypes)
2199
  writeExtBuffer(arrayBuffer, 0x10, allocateForWrite);
2200
  else
2201
- writeBuffer(hasNodeBuffer$1 ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite);
2202
  }
2203
  }, {
2204
  pack(typedArray, allocateForWrite) {
@@ -2213,7 +2227,7 @@
2213
  if (this.moreTypes)
2214
  writeExtBuffer(arrayBuffer, 0x11, allocateForWrite);
2215
  else
2216
- writeBuffer(hasNodeBuffer$1 ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite);
2217
  }
2218
  }, {
2219
  pack(c1, allocateForWrite) { // specific 0xC1 object
@@ -2270,19 +2284,19 @@
2270
  switch (length) {
2271
  case 1:
2272
  target[position++] = 0xd4;
2273
- break
2274
  case 2:
2275
  target[position++] = 0xd5;
2276
- break
2277
  case 4:
2278
  target[position++] = 0xd6;
2279
- break
2280
  case 8:
2281
  target[position++] = 0xd7;
2282
- break
2283
  case 16:
2284
  target[position++] = 0xd8;
2285
- break
2286
  default:
2287
  if (length < 0x100) {
2288
  target[position++] = 0xc7;
@@ -2302,7 +2316,7 @@
2302
  target[position++] = type;
2303
  target.set(result, position);
2304
  position += length;
2305
- return position
2306
  }
2307
 
2308
  function insertIds(serialized, idsToInsert) {
@@ -2324,7 +2338,7 @@
2324
  serialized[position++] = id & 0xff;
2325
  lastEnd = offset;
2326
  }
2327
- return serialized
2328
  }
2329
 
2330
  function writeBundles(start, pack, incrementPosition) {
@@ -2341,28 +2355,29 @@
2341
  function addExtension$1(extension) {
2342
  if (extension.Class) {
2343
  if (!extension.pack && !extension.write)
2344
- throw new Error('Extension has no pack or write function')
2345
  if (extension.pack && !extension.type)
2346
- throw new Error('Extension has no type (numeric code to identify the extension)')
2347
  extensionClasses.unshift(extension.Class);
2348
  extensions.unshift(extension);
2349
  }
2350
  addExtension$2(extension);
2351
  }
2352
- function prepareStructures$1(structures, packr) {
2353
  structures.isCompatible = (existingStructures) => {
2354
  let compatible = !existingStructures || ((packr.lastNamedStructuresLength || 0) === existingStructures.length);
2355
  if (!compatible) // we want to merge these existing structures immediately since we already have it and we are in the right transaction
2356
  packr._mergeStructures(existingStructures);
2357
  return compatible;
2358
  };
2359
- return structures
2360
- }
2361
- function setWriteStructSlots(writeSlots, makeStructures) {
2362
- writeStructSlots = writeSlots;
2363
- prepareStructures$1 = makeStructures;
2364
  }
2365
 
 
 
 
 
 
2366
  let defaultPackr = new Packr$1({ useRecords: false });
2367
  const pack$1 = defaultPackr.pack;
2368
  defaultPackr.pack;
@@ -2370,779 +2385,6 @@
2370
  const RESET_BUFFER_MODE = 1024;
2371
  const RESERVE_START_SPACE = 2048;
2372
 
2373
- const ASCII = 3; // the MIBenum from https://www.iana.org/assignments/character-sets/character-sets.xhtml (and other character encodings could be referenced by MIBenum)
2374
- const NUMBER = 0;
2375
- const UTF8 = 2;
2376
- const OBJECT_DATA = 1;
2377
- const DATE = 16;
2378
- const TYPE_NAMES = ['num', 'object', 'string', 'ascii'];
2379
- TYPE_NAMES[DATE] = 'date';
2380
- const float32Headers = [false, true, true, false, false, true, true, false];
2381
- let evalSupported;
2382
- try {
2383
- new Function('');
2384
- evalSupported = true;
2385
- } catch(error) {
2386
- // if eval variants are not supported, do not create inline object readers ever
2387
- }
2388
-
2389
- let updatedPosition;
2390
- const hasNodeBuffer = typeof Buffer !== 'undefined';
2391
- let textEncoder, currentSource;
2392
- try {
2393
- textEncoder = new TextEncoder();
2394
- } catch (error) {}
2395
- const encodeUtf8 = hasNodeBuffer ? function(target, string, position) {
2396
- return target.utf8Write(string, position, target.byteLength - position)
2397
- } : (textEncoder && textEncoder.encodeInto) ?
2398
- function(target, string, position) {
2399
- return textEncoder.encodeInto(string, target.subarray(position)).written
2400
- } : false;
2401
- setWriteStructSlots(writeStruct, prepareStructures);
2402
- function writeStruct(object, target, encodingStart, position, structures, makeRoom, pack, packr) {
2403
- let typedStructs = packr.typedStructs || (packr.typedStructs = []);
2404
- // note that we rely on pack.js to load stored structures before we get to this point
2405
- let targetView = target.dataView;
2406
- let refsStartPosition = (typedStructs.lastStringStart || 100) + position;
2407
- let safeEnd = target.length - 10;
2408
- let start = position;
2409
- if (position > safeEnd) {
2410
- target = makeRoom(position);
2411
- targetView = target.dataView;
2412
- position -= encodingStart;
2413
- start -= encodingStart;
2414
- refsStartPosition -= encodingStart;
2415
- encodingStart = 0;
2416
- safeEnd = target.length - 10;
2417
- }
2418
-
2419
- let refOffset, refPosition = refsStartPosition;
2420
-
2421
- let transition = typedStructs.transitions || (typedStructs.transitions = Object.create(null));
2422
- let nextId = typedStructs.nextId || typedStructs.length;
2423
- let headerSize =
2424
- nextId < 0xf ? 1 :
2425
- nextId < 0xf0 ? 2 :
2426
- nextId < 0xf000 ? 3 :
2427
- nextId < 0xf00000 ? 4 : 0;
2428
- if (headerSize === 0)
2429
- return 0;
2430
- position += headerSize;
2431
- let queuedReferences = [];
2432
- let usedAscii0;
2433
- let keyIndex = 0;
2434
- for (let key in object) {
2435
- let value = object[key];
2436
- let nextTransition = transition[key];
2437
- if (!nextTransition) {
2438
- transition[key] = nextTransition = {
2439
- key,
2440
- parent: transition,
2441
- enumerationOffset: 0,
2442
- ascii0: null,
2443
- ascii8: null,
2444
- num8: null,
2445
- string16: null,
2446
- object16: null,
2447
- num32: null,
2448
- float64: null,
2449
- date64: null
2450
- };
2451
- }
2452
- if (position > safeEnd) {
2453
- target = makeRoom(position);
2454
- targetView = target.dataView;
2455
- position -= encodingStart;
2456
- start -= encodingStart;
2457
- refsStartPosition -= encodingStart;
2458
- refPosition -= encodingStart;
2459
- encodingStart = 0;
2460
- safeEnd = target.length - 10;
2461
- }
2462
- switch (typeof value) {
2463
- case 'number':
2464
- let number = value;
2465
- // first check to see if we are using a lot of ids and should default to wide/common format
2466
- if (nextId < 200 || !nextTransition.num64) {
2467
- if (number >> 0 === number && number < 0x20000000 && number > -0x1f000000) {
2468
- if (number < 0xf6 && number >= 0 && (nextTransition.num8 && !(nextId > 200 && nextTransition.num32) || number < 0x20 && !nextTransition.num32)) {
2469
- transition = nextTransition.num8 || createTypeTransition(nextTransition, NUMBER, 1);
2470
- target[position++] = number;
2471
- } else {
2472
- transition = nextTransition.num32 || createTypeTransition(nextTransition, NUMBER, 4);
2473
- targetView.setUint32(position, number, true);
2474
- position += 4;
2475
- }
2476
- break;
2477
- } else if (number < 0x100000000 && number >= -0x80000000) {
2478
- targetView.setFloat32(position, number, true);
2479
- if (float32Headers[target[position + 3] >>> 5]) {
2480
- let xShifted;
2481
- // this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
2482
- if (((xShifted = number * mult10[((target[position + 3] & 0x7f) << 1) | (target[position + 2] >> 7)]) >> 0) === xShifted) {
2483
- transition = nextTransition.num32 || createTypeTransition(nextTransition, NUMBER, 4);
2484
- position += 4;
2485
- break;
2486
- }
2487
- }
2488
- }
2489
- }
2490
- transition = nextTransition.num64 || createTypeTransition(nextTransition, NUMBER, 8);
2491
- targetView.setFloat64(position, number, true);
2492
- position += 8;
2493
- break;
2494
- case 'string':
2495
- let strLength = value.length;
2496
- refOffset = refPosition - refsStartPosition;
2497
- if ((strLength << 2) + refPosition > safeEnd) {
2498
- target = makeRoom((strLength << 2) + refPosition);
2499
- targetView = target.dataView;
2500
- position -= encodingStart;
2501
- start -= encodingStart;
2502
- refsStartPosition -= encodingStart;
2503
- refPosition -= encodingStart;
2504
- encodingStart = 0;
2505
- safeEnd = target.length - 10;
2506
- }
2507
- if (strLength > ((0xff00 + refOffset) >> 2)) {
2508
- queuedReferences.push(key, value, position - start);
2509
- break;
2510
- }
2511
- let isNotAscii;
2512
- let strStart = refPosition;
2513
- if (strLength < 0x40) {
2514
- let i, c1, c2;
2515
- for (i = 0; i < strLength; i++) {
2516
- c1 = value.charCodeAt(i);
2517
- if (c1 < 0x80) {
2518
- target[refPosition++] = c1;
2519
- } else if (c1 < 0x800) {
2520
- isNotAscii = true;
2521
- target[refPosition++] = c1 >> 6 | 0xc0;
2522
- target[refPosition++] = c1 & 0x3f | 0x80;
2523
- } else if (
2524
- (c1 & 0xfc00) === 0xd800 &&
2525
- ((c2 = value.charCodeAt(i + 1)) & 0xfc00) === 0xdc00
2526
- ) {
2527
- isNotAscii = true;
2528
- c1 = 0x10000 + ((c1 & 0x03ff) << 10) + (c2 & 0x03ff);
2529
- i++;
2530
- target[refPosition++] = c1 >> 18 | 0xf0;
2531
- target[refPosition++] = c1 >> 12 & 0x3f | 0x80;
2532
- target[refPosition++] = c1 >> 6 & 0x3f | 0x80;
2533
- target[refPosition++] = c1 & 0x3f | 0x80;
2534
- } else {
2535
- isNotAscii = true;
2536
- target[refPosition++] = c1 >> 12 | 0xe0;
2537
- target[refPosition++] = c1 >> 6 & 0x3f | 0x80;
2538
- target[refPosition++] = c1 & 0x3f | 0x80;
2539
- }
2540
- }
2541
- } else {
2542
- refPosition += encodeUtf8(target, value, refPosition);
2543
- isNotAscii = refPosition - strStart > strLength;
2544
- }
2545
- if (refOffset < 0xa0 || (refOffset < 0xf6 && (nextTransition.ascii8 || nextTransition.string8))) {
2546
- // short strings
2547
- if (isNotAscii) {
2548
- if (!(transition = nextTransition.string8)) {
2549
- if (typedStructs.length > 10 && (transition = nextTransition.ascii8)) {
2550
- // we can safely change ascii to utf8 in place since they are compatible
2551
- transition.__type = UTF8;
2552
- nextTransition.ascii8 = null;
2553
- nextTransition.string8 = transition;
2554
- pack(null, 0, true); // special call to notify that structures have been updated
2555
- } else {
2556
- transition = createTypeTransition(nextTransition, UTF8, 1);
2557
- }
2558
- }
2559
- } else if (refOffset === 0 && !usedAscii0) {
2560
- usedAscii0 = true;
2561
- transition = nextTransition.ascii0 || createTypeTransition(nextTransition, ASCII, 0);
2562
- break; // don't increment position
2563
- }// else ascii:
2564
- else if (!(transition = nextTransition.ascii8) && !(typedStructs.length > 10 && (transition = nextTransition.string8)))
2565
- transition = createTypeTransition(nextTransition, ASCII, 1);
2566
- target[position++] = refOffset;
2567
- } else {
2568
- // TODO: Enable ascii16 at some point, but get the logic right
2569
- //if (isNotAscii)
2570
- transition = nextTransition.string16 || createTypeTransition(nextTransition, UTF8, 2);
2571
- //else
2572
- //transition = nextTransition.ascii16 || createTypeTransition(nextTransition, ASCII, 2);
2573
- targetView.setUint16(position, refOffset, true);
2574
- position += 2;
2575
- }
2576
- break;
2577
- case 'object':
2578
- if (value) {
2579
- if (value.constructor === Date) {
2580
- transition = nextTransition.date64 || createTypeTransition(nextTransition, DATE, 8);
2581
- targetView.setFloat64(position, value.getTime(), true);
2582
- position += 8;
2583
- } else {
2584
- queuedReferences.push(key, value, keyIndex);
2585
- }
2586
- break;
2587
- } else { // null
2588
- nextTransition = anyType(nextTransition, position, targetView, -10); // match CBOR with this
2589
- if (nextTransition) {
2590
- transition = nextTransition;
2591
- position = updatedPosition;
2592
- } else queuedReferences.push(key, value, keyIndex);
2593
- }
2594
- break;
2595
- case 'boolean':
2596
- transition = nextTransition.num8 || nextTransition.ascii8 || createTypeTransition(nextTransition, NUMBER, 1);
2597
- target[position++] = value ? 0xf9 : 0xf8; // match CBOR with these
2598
- break;
2599
- case 'undefined':
2600
- nextTransition = anyType(nextTransition, position, targetView, -9); // match CBOR with this
2601
- if (nextTransition) {
2602
- transition = nextTransition;
2603
- position = updatedPosition;
2604
- } else queuedReferences.push(key, value, keyIndex);
2605
- break;
2606
- default:
2607
- queuedReferences.push(key, value, keyIndex);
2608
- }
2609
- keyIndex++;
2610
- }
2611
-
2612
- for (let i = 0, l = queuedReferences.length; i < l;) {
2613
- let key = queuedReferences[i++];
2614
- let value = queuedReferences[i++];
2615
- let propertyIndex = queuedReferences[i++];
2616
- let nextTransition = transition[key];
2617
- if (!nextTransition) {
2618
- transition[key] = nextTransition = {
2619
- key,
2620
- parent: transition,
2621
- enumerationOffset: propertyIndex - keyIndex,
2622
- ascii0: null,
2623
- ascii8: null,
2624
- num8: null,
2625
- string16: null,
2626
- object16: null,
2627
- num32: null,
2628
- float64: null
2629
- };
2630
- }
2631
- let newPosition;
2632
- if (value) {
2633
- /*if (typeof value === 'string') { // TODO: we could re-enable long strings
2634
- if (position + value.length * 3 > safeEnd) {
2635
- target = makeRoom(position + value.length * 3);
2636
- position -= start;
2637
- targetView = target.dataView;
2638
- start = 0;
2639
- }
2640
- newPosition = position + target.utf8Write(value, position, 0xffffffff);
2641
- } else { */
2642
- let size;
2643
- refOffset = refPosition - refsStartPosition;
2644
- if (refOffset < 0xff00) {
2645
- transition = nextTransition.object16;
2646
- if (transition)
2647
- size = 2;
2648
- else if ((transition = nextTransition.object32))
2649
- size = 4;
2650
- else {
2651
- transition = createTypeTransition(nextTransition, OBJECT_DATA, 2);
2652
- size = 2;
2653
- }
2654
- } else {
2655
- transition = nextTransition.object32 || createTypeTransition(nextTransition, OBJECT_DATA, 4);
2656
- size = 4;
2657
- }
2658
- newPosition = pack(value, refPosition);
2659
- //}
2660
- if (typeof newPosition === 'object') {
2661
- // re-allocated
2662
- refPosition = newPosition.position;
2663
- targetView = newPosition.targetView;
2664
- target = newPosition.target;
2665
- refsStartPosition -= encodingStart;
2666
- position -= encodingStart;
2667
- start -= encodingStart;
2668
- encodingStart = 0;
2669
- } else
2670
- refPosition = newPosition;
2671
- if (size === 2) {
2672
- targetView.setUint16(position, refOffset, true);
2673
- position += 2;
2674
- } else {
2675
- targetView.setUint32(position, refOffset, true);
2676
- position += 4;
2677
- }
2678
- } else { // null or undefined
2679
- transition = nextTransition.object16 || createTypeTransition(nextTransition, OBJECT_DATA, 2);
2680
- targetView.setInt16(position, value === null ? -10 : -9, true);
2681
- position += 2;
2682
- }
2683
- keyIndex++;
2684
- }
2685
-
2686
-
2687
- let recordId = transition[RECORD_SYMBOL];
2688
- if (recordId == null) {
2689
- recordId = packr.typedStructs.length;
2690
- let structure = [];
2691
- let nextTransition = transition;
2692
- let key, type;
2693
- while ((type = nextTransition.__type) !== undefined) {
2694
- let size = nextTransition.__size;
2695
- nextTransition = nextTransition.__parent;
2696
- key = nextTransition.key;
2697
- let property = [type, size, key];
2698
- if (nextTransition.enumerationOffset)
2699
- property.push(nextTransition.enumerationOffset);
2700
- structure.push(property);
2701
- nextTransition = nextTransition.parent;
2702
- }
2703
- structure.reverse();
2704
- transition[RECORD_SYMBOL] = recordId;
2705
- packr.typedStructs[recordId] = structure;
2706
- pack(null, 0, true); // special call to notify that structures have been updated
2707
- }
2708
-
2709
-
2710
- switch (headerSize) {
2711
- case 1:
2712
- if (recordId >= 0x10) return 0;
2713
- target[start] = recordId + 0x20;
2714
- break;
2715
- case 2:
2716
- if (recordId >= 0x100) return 0;
2717
- target[start] = 0x38;
2718
- target[start + 1] = recordId;
2719
- break;
2720
- case 3:
2721
- if (recordId >= 0x10000) return 0;
2722
- target[start] = 0x39;
2723
- targetView.setUint16(start + 1, recordId, true);
2724
- break;
2725
- case 4:
2726
- if (recordId >= 0x1000000) return 0;
2727
- targetView.setUint32(start, (recordId << 8) + 0x3a, true);
2728
- break;
2729
- }
2730
-
2731
- if (position < refsStartPosition) {
2732
- if (refsStartPosition === refPosition)
2733
- return position; // no refs
2734
- // adjust positioning
2735
- target.copyWithin(position, refsStartPosition, refPosition);
2736
- refPosition += position - refsStartPosition;
2737
- typedStructs.lastStringStart = position - start;
2738
- } else if (position > refsStartPosition) {
2739
- if (refsStartPosition === refPosition)
2740
- return position; // no refs
2741
- typedStructs.lastStringStart = position - start;
2742
- return writeStruct(object, target, encodingStart, start, structures, makeRoom, pack, packr);
2743
- }
2744
- return refPosition;
2745
- }
2746
- function anyType(transition, position, targetView, value) {
2747
- let nextTransition;
2748
- if ((nextTransition = transition.ascii8 || transition.num8)) {
2749
- targetView.setInt8(position, value, true);
2750
- updatedPosition = position + 1;
2751
- return nextTransition;
2752
- }
2753
- if ((nextTransition = transition.string16 || transition.object16)) {
2754
- targetView.setInt16(position, value, true);
2755
- updatedPosition = position + 2;
2756
- return nextTransition;
2757
- }
2758
- if (nextTransition = transition.num32) {
2759
- targetView.setUint32(position, 0xe0000100 + value, true);
2760
- updatedPosition = position + 4;
2761
- return nextTransition;
2762
- }
2763
- // transition.float64
2764
- if (nextTransition = transition.num64) {
2765
- targetView.setFloat64(position, NaN, true);
2766
- targetView.setInt8(position, value);
2767
- updatedPosition = position + 8;
2768
- return nextTransition;
2769
- }
2770
- updatedPosition = position;
2771
- // TODO: can we do an "any" type where we defer the decision?
2772
- return;
2773
- }
2774
- function createTypeTransition(transition, type, size) {
2775
- let typeName = TYPE_NAMES[type] + (size << 3);
2776
- let newTransition = transition[typeName] || (transition[typeName] = Object.create(null));
2777
- newTransition.__type = type;
2778
- newTransition.__size = size;
2779
- newTransition.__parent = transition;
2780
- return newTransition;
2781
- }
2782
- function onLoadedStructures(sharedData) {
2783
- if (!(sharedData instanceof Map))
2784
- return sharedData;
2785
- let typed = sharedData.get('typed') || [];
2786
- if (Object.isFrozen(typed))
2787
- typed = typed.map(structure => structure.slice(0));
2788
- let named = sharedData.get('named');
2789
- let transitions = Object.create(null);
2790
- for (let i = 0, l = typed.length; i < l; i++) {
2791
- let structure = typed[i];
2792
- let transition = transitions;
2793
- for (let [type, size, key] of structure) {
2794
- let nextTransition = transition[key];
2795
- if (!nextTransition) {
2796
- transition[key] = nextTransition = {
2797
- key,
2798
- parent: transition,
2799
- enumerationOffset: 0,
2800
- ascii0: null,
2801
- ascii8: null,
2802
- num8: null,
2803
- string16: null,
2804
- object16: null,
2805
- num32: null,
2806
- float64: null,
2807
- date64: null,
2808
- };
2809
- }
2810
- transition = createTypeTransition(nextTransition, type, size);
2811
- }
2812
- transition[RECORD_SYMBOL] = i;
2813
- }
2814
- typed.transitions = transitions;
2815
- this.typedStructs = typed;
2816
- this.lastTypedStructuresLength = typed.length;
2817
- return named;
2818
- }
2819
- var sourceSymbol = Symbol.for('source');
2820
- function readStruct(src, position, srcEnd, unpackr) {
2821
- let recordId = src[position++] - 0x20;
2822
- if (recordId >= 24) {
2823
- switch(recordId) {
2824
- case 24: recordId = src[position++]; break;
2825
- // little endian:
2826
- case 25: recordId = src[position++] + (src[position++] << 8); break;
2827
- case 26: recordId = src[position++] + (src[position++] << 8) + (src[position++] << 16); break;
2828
- case 27: recordId = src[position++] + (src[position++] << 8) + (src[position++] << 16) + (src[position++] << 24); break;
2829
- }
2830
- }
2831
- let structure = unpackr.typedStructs && unpackr.typedStructs[recordId];
2832
- if (!structure) {
2833
- // copy src buffer because getStructures will override it
2834
- src = Uint8Array.prototype.slice.call(src, position, srcEnd);
2835
- srcEnd -= position;
2836
- position = 0;
2837
- if (!unpackr.getStructures)
2838
- throw new Error(`Reference to shared structure ${recordId} without getStructures method`);
2839
- unpackr._mergeStructures(unpackr.getStructures());
2840
- if (!unpackr.typedStructs)
2841
- throw new Error('Could not find any shared typed structures');
2842
- unpackr.lastTypedStructuresLength = unpackr.typedStructs.length;
2843
- structure = unpackr.typedStructs[recordId];
2844
- if (!structure)
2845
- throw new Error('Could not find typed structure ' + recordId);
2846
- }
2847
- var construct = structure.construct;
2848
- var fullConstruct = structure.fullConstruct;
2849
- if (!construct) {
2850
- construct = structure.construct = function LazyObject() {
2851
- };
2852
- fullConstruct = structure.fullConstruct = function LoadedObject() {
2853
- };
2854
- fullConstruct.prototype = unpackr.structPrototype || {};
2855
- var prototype = construct.prototype = unpackr.structPrototype ? Object.create(unpackr.structPrototype) : {};
2856
- let properties = [];
2857
- let currentOffset = 0;
2858
- let lastRefProperty;
2859
- for (let i = 0, l = structure.length; i < l; i++) {
2860
- let definition = structure[i];
2861
- let [ type, size, key, enumerationOffset ] = definition;
2862
- if (key === '__proto__')
2863
- key = '__proto_';
2864
- let property = {
2865
- key,
2866
- offset: currentOffset,
2867
- };
2868
- if (enumerationOffset)
2869
- properties.splice(i + enumerationOffset, 0, property);
2870
- else
2871
- properties.push(property);
2872
- let getRef;
2873
- switch(size) { // TODO: Move into a separate function
2874
- case 0: getRef = () => 0; break;
2875
- case 1:
2876
- getRef = (source, position) => {
2877
- let ref = source.bytes[position + property.offset];
2878
- return ref >= 0xf6 ? toConstant(ref) : ref;
2879
- };
2880
- break;
2881
- case 2:
2882
- getRef = (source, position) => {
2883
- let src = source.bytes;
2884
- let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
2885
- let ref = dataView.getUint16(position + property.offset, true);
2886
- return ref >= 0xff00 ? toConstant(ref & 0xff) : ref;
2887
- };
2888
- break;
2889
- case 4:
2890
- getRef = (source, position) => {
2891
- let src = source.bytes;
2892
- let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
2893
- let ref = dataView.getUint32(position + property.offset, true);
2894
- return ref >= 0xffffff00 ? toConstant(ref & 0xff) : ref;
2895
- };
2896
- break;
2897
- }
2898
- property.getRef = getRef;
2899
- currentOffset += size;
2900
- let get;
2901
- switch(type) {
2902
- case ASCII:
2903
- if (lastRefProperty && !lastRefProperty.next)
2904
- lastRefProperty.next = property;
2905
- lastRefProperty = property;
2906
- property.multiGetCount = 0;
2907
- get = function(source) {
2908
- let src = source.bytes;
2909
- let position = source.position;
2910
- let refStart = currentOffset + position;
2911
- let ref = getRef(source, position);
2912
- if (typeof ref !== 'number') return ref;
2913
-
2914
- let end, next = property.next;
2915
- while(next) {
2916
- end = next.getRef(source, position);
2917
- if (typeof end === 'number')
2918
- break;
2919
- else
2920
- end = null;
2921
- next = next.next;
2922
- }
2923
- if (end == null)
2924
- end = source.bytesEnd - refStart;
2925
- if (source.srcString) {
2926
- return source.srcString.slice(ref, end);
2927
- }
2928
- /*if (property.multiGetCount > 0) {
2929
- let asciiEnd;
2930
- next = firstRefProperty;
2931
- let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
2932
- do {
2933
- asciiEnd = dataView.getUint16(source.position + next.offset, true);
2934
- if (asciiEnd < 0xff00)
2935
- break;
2936
- else
2937
- asciiEnd = null;
2938
- } while((next = next.next));
2939
- if (asciiEnd == null)
2940
- asciiEnd = source.bytesEnd - refStart
2941
- source.srcString = src.toString('latin1', refStart, refStart + asciiEnd);
2942
- return source.srcString.slice(ref, end);
2943
- }
2944
- if (source.prevStringGet) {
2945
- source.prevStringGet.multiGetCount += 2;
2946
- } else {
2947
- source.prevStringGet = property;
2948
- property.multiGetCount--;
2949
- }*/
2950
- return readString(src, ref + refStart, end - ref);
2951
- //return src.toString('latin1', ref + refStart, end + refStart);
2952
- };
2953
- break;
2954
- case UTF8: case OBJECT_DATA:
2955
- if (lastRefProperty && !lastRefProperty.next)
2956
- lastRefProperty.next = property;
2957
- lastRefProperty = property;
2958
- get = function(source) {
2959
- let position = source.position;
2960
- let refStart = currentOffset + position;
2961
- let ref = getRef(source, position);
2962
- if (typeof ref !== 'number') return ref;
2963
- let src = source.bytes;
2964
- let end, next = property.next;
2965
- while(next) {
2966
- end = next.getRef(source, position);
2967
- if (typeof end === 'number')
2968
- break;
2969
- else
2970
- end = null;
2971
- next = next.next;
2972
- }
2973
- if (end == null)
2974
- end = source.bytesEnd - refStart;
2975
- if (type === UTF8) {
2976
- return src.toString('utf8', ref + refStart, end + refStart);
2977
- } else {
2978
- currentSource = source;
2979
- try {
2980
- return unpackr.unpack(src, { start: ref + refStart, end: end + refStart });
2981
- } finally {
2982
- currentSource = null;
2983
- }
2984
- }
2985
- };
2986
- break;
2987
- case NUMBER:
2988
- switch(size) {
2989
- case 4:
2990
- get = function (source) {
2991
- let src = source.bytes;
2992
- let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
2993
- let position = source.position + property.offset;
2994
- let value = dataView.getInt32(position, true);
2995
- if (value < 0x20000000) {
2996
- if (value > -0x1f000000)
2997
- return value;
2998
- if (value > -0x20000000)
2999
- return toConstant(value & 0xff);
3000
- }
3001
- let fValue = dataView.getFloat32(position, true);
3002
- // this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
3003
- let multiplier = mult10[((src[position + 3] & 0x7f) << 1) | (src[position + 2] >> 7)];
3004
- return ((multiplier * fValue + (fValue > 0 ? 0.5 : -0.5)) >> 0) / multiplier;
3005
- };
3006
- break;
3007
- case 8:
3008
- get = function (source) {
3009
- let src = source.bytes;
3010
- let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
3011
- let value = dataView.getFloat64(source.position + property.offset, true);
3012
- if (isNaN(value)) {
3013
- let byte = src[source.position + property.offset];
3014
- if (byte >= 0xf6)
3015
- return toConstant(byte);
3016
- }
3017
- return value;
3018
- };
3019
- break;
3020
- case 1:
3021
- get = function (source) {
3022
- let src = source.bytes;
3023
- let value = src[source.position + property.offset];
3024
- return value < 0xf6 ? value : toConstant(value);
3025
- };
3026
- break;
3027
- }
3028
- break;
3029
- case DATE:
3030
- get = function (source) {
3031
- let src = source.bytes;
3032
- let dataView = src.dataView || (src.dataView = new DataView(src.buffer, src.byteOffset, src.byteLength));
3033
- return new Date(dataView.getFloat64(source.position + property.offset, true));
3034
- };
3035
- break;
3036
-
3037
- }
3038
- property.get = get;
3039
- }
3040
- // TODO: load the srcString for faster string decoding on toJSON
3041
- if (evalSupported) {
3042
- let objectLiteralProperties = [];
3043
- let args = [];
3044
- let i = 0;
3045
- let hasInheritedProperties;
3046
- for (let property of properties) { // assign in enumeration order
3047
- if (unpackr.alwaysLazyProperty && unpackr.alwaysLazyProperty(property.key)) {
3048
- // these properties are not eagerly evaluated and this can be used for creating properties
3049
- // that are not serialized as JSON
3050
- hasInheritedProperties = true;
3051
- continue;
3052
- }
3053
- Object.defineProperty(prototype, property.key, { get: withSource(property.get), enumerable: true });
3054
- let valueFunction = 'v' + i++;
3055
- args.push(valueFunction);
3056
- objectLiteralProperties.push('o[' + JSON.stringify(property.key) + ']=' + valueFunction + '(s)');
3057
- }
3058
- if (hasInheritedProperties) {
3059
- objectLiteralProperties.push('__proto__:this');
3060
- }
3061
- let toObject = (new Function(...args, 'var c=this;return function(s){var o=new c();' + objectLiteralProperties.join(';') + ';return o;}')).apply(fullConstruct, properties.map(prop => prop.get));
3062
- Object.defineProperty(prototype, 'toJSON', {
3063
- value(omitUnderscoredProperties) {
3064
- return toObject.call(this, this[sourceSymbol]);
3065
- }
3066
- });
3067
- } else {
3068
- Object.defineProperty(prototype, 'toJSON', {
3069
- value(omitUnderscoredProperties) {
3070
- // return an enumerable object with own properties to JSON stringify
3071
- let resolved = {};
3072
- for (let i = 0, l = properties.length; i < l; i++) {
3073
- // TODO: check alwaysLazyProperty
3074
- let key = properties[i].key;
3075
-
3076
- resolved[key] = this[key];
3077
- }
3078
- return resolved;
3079
- },
3080
- // not enumerable or anything
3081
- });
3082
- }
3083
- }
3084
- var instance = new construct();
3085
- instance[sourceSymbol] = {
3086
- bytes: src,
3087
- position,
3088
- srcString: '',
3089
- bytesEnd: srcEnd
3090
- };
3091
- return instance;
3092
- }
3093
- function toConstant(code) {
3094
- switch(code) {
3095
- case 0xf6: return null;
3096
- case 0xf7: return undefined;
3097
- case 0xf8: return false;
3098
- case 0xf9: return true;
3099
- }
3100
- throw new Error('Unknown constant');
3101
- }
3102
- function withSource(get) {
3103
- return function() {
3104
- return get(this[sourceSymbol]);
3105
- }
3106
- }
3107
-
3108
- function saveState() {
3109
- if (currentSource) {
3110
- currentSource.bytes = Uint8Array.prototype.slice.call(currentSource.bytes, currentSource.position, currentSource.bytesEnd);
3111
- currentSource.position = 0;
3112
- currentSource.bytesEnd = currentSource.bytes.length;
3113
- }
3114
- }
3115
- function prepareStructures(structures, packr) {
3116
- if (packr.typedStructs) {
3117
- let structMap = new Map();
3118
- structMap.set('named', structures);
3119
- structMap.set('typed', packr.typedStructs);
3120
- structures = structMap;
3121
- }
3122
- let lastTypedStructuresLength = packr.lastTypedStructuresLength || 0;
3123
- structures.isCompatible = existing => {
3124
- let compatible = true;
3125
- if (existing instanceof Map) {
3126
- let named = existing.get('named') || [];
3127
- if (named.length !== (packr.lastNamedStructuresLength || 0))
3128
- compatible = false;
3129
- let typed = existing.get('typed') || [];
3130
- if (typed.length !== lastTypedStructuresLength)
3131
- compatible = false;
3132
- } else if (existing instanceof Array || Array.isArray(existing)) {
3133
- if (existing.length !== (packr.lastNamedStructuresLength || 0))
3134
- compatible = false;
3135
- }
3136
- if (!compatible)
3137
- packr._mergeStructures(existing);
3138
- return compatible;
3139
- };
3140
- packr.lastTypedStructuresLength = packr.typedStructs && packr.typedStructs.length;
3141
- return structures;
3142
- }
3143
-
3144
- setReadStruct(readStruct, onLoadedStructures, saveState);
3145
-
3146
  const nativeAccelerationDisabled = process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED !== undefined && process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED.toLowerCase() === 'true';
3147
 
3148
  if (!nativeAccelerationDisabled) {
@@ -3151,7 +2393,7 @@
3151
  if (typeof require == 'function')
3152
  extractor = require('msgpackr-extract');
3153
  else
3154
- extractor = module.createRequire((document.currentScript && document.currentScript.src || new URL('test.js', document.baseURI).href))('msgpackr-extract');
3155
  if (extractor)
3156
  setExtractor(extractor.extractStrings);
3157
  } catch (error) {
@@ -3161,7 +2403,7 @@
3161
 
3162
  let allSampleData = [];
3163
  for (let i = 1; i < 6; i++) {
3164
- allSampleData.push(JSON.parse(fs.readFileSync(new URL(`./example${i > 1 ? i : ''}.json`, (document.currentScript && document.currentScript.src || new URL('test.js', document.baseURI).href)))));
3165
  }
3166
  allSampleData.push({
3167
  name: 'some other types',
@@ -3171,18 +2413,11 @@
3171
  const sampleData = allSampleData[3];
3172
  function tryRequire(module) {
3173
  try {
3174
- return require(module)
3175
  } catch(error) {
3176
- return {}
3177
  }
3178
  }
3179
-
3180
- let seed = 0;
3181
- function random() {
3182
- seed++;
3183
- let a = seed * 15485863;
3184
- return (a * a * a % 2038074743) / 2038074743;
3185
- }
3186
  //if (typeof chai === 'undefined') { chai = require('chai') }
3187
  var assert = chai.assert;
3188
  //if (typeof msgpackr === 'undefined') { msgpackr = require('..') }
@@ -3303,6 +2538,30 @@
3303
  const result = unpack(payload);
3304
  assert.notEqual(result, '/');
3305
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3306
  test('use ArrayBuffer', function () {
3307
  const data = {prop: 'a test'};
3308
  var serialized = pack(data);
@@ -3312,39 +2571,6 @@
3312
  var deserialized = unpack(ab);
3313
  assert.deepEqual(deserialized, data);
3314
  });
3315
- test('pack/unpack varying data with random access structures', function () {
3316
- let structures = [];
3317
- let packr = new Packr({
3318
- structures, useRecords: true, randomAccessStructure: true, freezeData: true, saveStructures(structures) {
3319
- }, getStructures() {
3320
- console.log('getStructures');
3321
- }
3322
- });
3323
- for (let i = 0; i < 2000; i++) {
3324
- let data = {};
3325
- let props = ['foo', 'bar', 'a', 'b', 'c', 'name', 'age', 'd'];
3326
-
3327
- function makeString() {
3328
- let str = '';
3329
- while (random() < 0.9) {
3330
- str += random() < 0.8 ? 'hello world' : String.fromCharCode(300);
3331
- }
3332
- return str;
3333
- }
3334
-
3335
- for (let i = 0; i < random() * 20; i++) {
3336
- data[props[Math.floor(random() * 8)]] =
3337
- random() < 0.3 ? Math.floor(random() * 400) / 2 :
3338
- random() < 0.3 ? makeString() : random() < 0.3 ? true : random() < 0.3 ? sampleData : null;
3339
- }
3340
- var serialized = packr.pack(data);
3341
- var deserialized = packr.unpack(serialized);
3342
- for (let key in deserialized) {
3343
- deserialized[key];
3344
- }
3345
- assert.deepEqual(deserialized, data);
3346
- }
3347
- });
3348
 
3349
  for (let sampleData of allSampleData) {
3350
  let snippet = JSON.stringify(sampleData).slice(0, 20) + '...';
@@ -3367,25 +2593,6 @@
3367
  var deserialized = unpack(serialized);
3368
  assert.deepEqual(deserialized, data);
3369
  });
3370
- test('pack/unpack sample data with random access structures ' + snippet, function () {
3371
- var data = sampleData;
3372
- let structures = [];
3373
- let packr = new Packr({
3374
- structures, useRecords: true, randomAccessStructure: true, freezeData: true, saveStructures(structures) {
3375
- }, getStructures() {
3376
- console.log('getStructures');
3377
- }
3378
- });
3379
- for (let i = 0; i < 20; i++) {
3380
- var serialized = packr.pack(data);
3381
- var deserialized = packr.unpack(serialized, {lazy: true});
3382
- var copied = {};
3383
- for (let key in deserialized) {
3384
- copied[key] = deserialized[key];
3385
- }
3386
- assert.deepEqual(copied, data);
3387
- }
3388
- });
3389
  test('pack/unpack sample data with bundled strings ' + snippet, function () {
3390
  var data = sampleData;
3391
  let packr = new Packr({ /*structures,*/ useRecords: false, bundleStrings: true});
@@ -3576,7 +2783,7 @@
3576
 
3577
  }
3578
  Extended.prototype.getDouble = function() {
3579
- return this.value * 2
3580
  };
3581
  var instance = new Extended();
3582
  instance.value = 4;
@@ -3596,10 +2803,10 @@
3596
  let data = packr.unpack(buffer);
3597
  e.value = data[0];
3598
  e.string = data[1];
3599
- return e
3600
  },
3601
  pack: function(instance) {
3602
- return packr.pack([instance.value, instance.string])
3603
  }
3604
  });
3605
  var serialized = pack(data);
@@ -3625,10 +2832,10 @@
3625
  type: 12,
3626
  read: function(data) {
3627
  Object.setPrototypeOf(data, ExtendArray.prototype);
3628
- return data
3629
  },
3630
  write: function(instance) {
3631
- return [...instance]
3632
  }
3633
  });
3634
  var serialized = pack(data);
@@ -3681,10 +2888,10 @@
3681
  Class: TestClass,
3682
  type: 0x01,
3683
  pack() {
3684
- return typeof Buffer != 'undefined' ? Buffer.alloc(256) : new Uint8Array(256)
3685
  },
3686
  unpack(data) {
3687
- return data.length
3688
  }
3689
  });
3690
  let result = unpack(pack(new TestClass()));
@@ -3696,7 +2903,7 @@
3696
 
3697
  }
3698
  Extended.prototype.getDouble = function() {
3699
- return this.value * 2
3700
  };
3701
  var instance = new Extended();
3702
  instance.value = 4;
@@ -3715,10 +2922,10 @@
3715
  let e = new Extended();
3716
  e.value = data[0];
3717
  e.string = data[1];
3718
- return e
3719
  },
3720
  write: function(instance) {
3721
- return [instance.value, instance.string]
3722
  }
3723
  });
3724
  var serialized = pack(data);
@@ -3731,7 +2938,7 @@
3731
 
3732
  }
3733
  Extended.prototype.getDouble = function() {
3734
- return this.value * 2
3735
  };
3736
  var instance = new Extended();
3737
  instance.value = 4;
@@ -3748,10 +2955,10 @@
3748
  type: 13,
3749
  read: function(data) {
3750
  Object.setPrototypeOf(data, Extended.prototype);
3751
- return data
3752
  },
3753
  write: function(data) {
3754
- return data
3755
  }
3756
  });
3757
  var serialized = pack(data);
@@ -3776,10 +2983,10 @@
3776
  type: 14,
3777
  read: function(data) {
3778
  Object.setPrototypeOf(data, ExtendArray3.prototype);
3779
- return data
3780
  },
3781
  write: function(data) {
3782
- return data
3783
  }
3784
  });
3785
  var serialized = pack(data);
@@ -3794,10 +3001,10 @@
3794
 
3795
  }
3796
  Extended.prototype.__call__ = function(){
3797
- return this.value * 4
3798
  };
3799
  Extended.prototype.getDouble = function() {
3800
- return this.value * 2
3801
  };
3802
 
3803
  var instance = function() { instance.__call__();/* callable stuff */ };
@@ -3814,10 +3021,10 @@
3814
  var e = function() { e.__call__(); };
3815
  Object.setPrototypeOf(e,Extended.prototype);
3816
  e.value = packr.unpack(buffer);
3817
- return e
3818
  },
3819
  pack: function(instance) {
3820
- return packr.pack(instance.value)
3821
  }
3822
  });
3823
  var serialized = pack(data);
@@ -3833,7 +3040,7 @@
3833
  addExtension({
3834
  Class: Date,
3835
  write(date) {
3836
- return date.toString()
3837
  }
3838
  });
3839
  var serialized = pack(data);
@@ -4130,7 +3337,7 @@
4130
  const structures2 = [...structures];
4131
  const packr = new Packr({
4132
  getStructures() {
4133
- return structures
4134
  },
4135
  saveStructures(structures) {
4136
  },
@@ -4138,7 +3345,7 @@
4138
  });
4139
  const packr2 = new Packr({
4140
  getStructures() {
4141
- return structures2
4142
  },
4143
  saveStructures(structures) {
4144
  },
@@ -4150,6 +3357,30 @@
4150
  assert.deepEqual(inputData, outputData);
4151
  });
4152
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4153
  test('big buffer', function() {
4154
  var size = 100000000;
4155
  var data = new Uint8Array(size).fill(1);
@@ -4459,9 +3690,9 @@
4459
 
4460
  test('pack toJSON returning this', () => {
4461
  class Serializable {
4462
- someData = [1, 2, 3, 4]
4463
  toJSON() {
4464
- return this
4465
  }
4466
  }
4467
  const serialized = pack(new Serializable);
@@ -4564,5 +3795,87 @@
4564
  });
4565
  });
4566
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4567
  })(chai, null, module, fs);
4568
  //# sourceMappingURL=test.js.map
 
1
  (function (chai, stream, module, fs) {
2
  'use strict';
3
 
4
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
5
  var decoder;
6
  try {
7
  decoder = new TextDecoder();
 
30
  C1.name = 'MessagePack 0xC1';
31
  var sequentialMode = false;
32
  var inlineObjectReadThreshold = 2;
 
33
 
34
  let Unpackr$1 = class Unpackr {
35
  constructor(options) {
 
59
  unpack(source, options) {
60
  if (src) {
61
  // re-entrant execution, save the state and restore it after we do this unpack
62
+ return saveState(() => {
63
  clearSource();
64
+ return this ? this.unpack(source, options) : Unpackr.prototype.unpack.call(defaultOptions, source, options);
65
+ });
66
  }
67
  if (!source.buffer && source.constructor === ArrayBuffer)
68
  source = typeof Buffer !== 'undefined' ? Buffer.from(source) : new Uint8Array(source);
 
88
  // if it doesn't have a buffer, maybe it is the wrong type of object
89
  src = null;
90
  if (source instanceof Uint8Array)
91
+ throw error;
92
+ throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source));
93
  }
94
+ if (this instanceof Unpackr) {
95
  currentUnpackr = this;
96
  if (this.structures) {
97
  currentStructures = this.structures;
98
+ return checkedRead(options);
99
  } else if (!currentStructures || currentStructures.length > 0) {
100
  currentStructures = [];
101
  }
 
104
  if (!currentStructures || currentStructures.length > 0)
105
  currentStructures = [];
106
  }
107
+ return checkedRead(options);
108
  }
109
  unpackMultiple(source, forEach) {
110
  let values, lastPosition = 0;
 
117
  while(position$1 < size) {
118
  lastPosition = position$1;
119
  if (forEach(checkedRead(), lastPosition, position$1) === false) {
120
+ return;
121
  }
122
  }
123
  }
 
127
  lastPosition = position$1;
128
  values.push(checkedRead());
129
  }
130
+ return values;
131
  }
132
  } catch(error) {
133
  error.lastPosition = lastPosition;
134
  error.values = values;
135
+ throw error;
136
  } finally {
137
  sequentialMode = false;
138
  clearSource();
139
  }
140
  }
141
  _mergeStructures(loadedStructures, existingStructures) {
142
+ if (this._onLoadedStructures)
143
+ loadedStructures = this._onLoadedStructures(loadedStructures);
144
  loadedStructures = loadedStructures || [];
145
  if (Object.isFrozen(loadedStructures))
146
  loadedStructures = loadedStructures.map(structure => structure.slice(0));
 
164
  }
165
  }
166
  }
167
+ return this.structures = loadedStructures;
168
  }
169
  decode(source, options) {
170
+ return this.unpack(source, options);
171
  }
172
  };
173
  function checkedRead(options) {
 
178
  currentStructures.length = sharedLength;
179
  }
180
  let result;
181
+ if (currentUnpackr._readStruct && src[position$1] < 0x40 && src[position$1] >= 0x20) {
182
+ result = currentUnpackr._readStruct(src, position$1, srcEnd);
183
  src = null; // dispose of this so that recursive unpack calls don't save state
184
  if (!(options && options.lazy) && result)
185
  result = result.toJSON();
 
205
  referenceMap = null;
206
  } else if (position$1 > srcEnd) {
207
  // over read
208
+ throw new Error('Unexpected end of MessagePack data');
209
  } else if (!sequentialMode) {
210
  let jsonView;
211
  try {
 
213
  } catch(error) {
214
  jsonView = '(JSON view not available ' + error + ')';
215
  }
216
+ throw new Error('Data read, but end of buffer not reached ' + jsonView);
217
  }
218
  // else more to read, but we are reading sequentially, so don't clear source yet
219
+ return result;
220
  } catch(error) {
221
  if (currentStructures && currentStructures.restoreStructures)
222
  restoreStructures();
 
224
  if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position$1 > srcEnd) {
225
  error.incomplete = true;
226
  }
227
+ throw error;
228
  }
229
  }
230
 
 
240
  if (token < 0xa0) {
241
  if (token < 0x80) {
242
  if (token < 0x40)
243
+ return token;
244
  else {
245
  let structure = currentStructures[token & 0x3f] ||
246
  currentUnpackr.getStructures && loadStructures()[token & 0x3f];
 
248
  if (!structure.read) {
249
  structure.read = createStructureReader(structure, token & 0x3f);
250
  }
251
+ return structure.read();
252
  } else
253
+ return token;
254
  }
255
  } else if (token < 0x90) {
256
  // map
 
263
  key = '__proto_';
264
  object[key] = read();
265
  }
266
+ return object;
267
  } else {
268
  let map = new Map();
269
  for (let i = 0; i < token; i++) {
270
  map.set(read(), read());
271
  }
272
+ return map;
273
  }
274
  } else {
275
  token -= 0x90;
 
278
  array[i] = read();
279
  }
280
  if (currentUnpackr.freezeData)
281
+ return Object.freeze(array);
282
+ return array;
283
  }
284
  } else if (token < 0xc0) {
285
  // fixstr
286
  let length = token - 0xa0;
287
  if (srcStringEnd >= position$1) {
288
+ return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart);
289
  }
290
  if (srcStringEnd == 0 && srcEnd < 140) {
291
  // for small blocks, avoiding the overhead of the extract call is helpful
292
  let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
293
  if (string != null)
294
+ return string;
295
  }
296
+ return readFixedString(length);
297
  } else {
298
  let value;
299
  switch (token) {
300
+ case 0xc0: return null;
301
  case 0xc1:
302
  if (bundledStrings$1) {
303
  value = read(); // followed by the length of the string in characters (not bytes!)
304
  if (value > 0)
305
+ return bundledStrings$1[1].slice(bundledStrings$1.position1, bundledStrings$1.position1 += value);
306
  else
307
+ return bundledStrings$1[0].slice(bundledStrings$1.position0, bundledStrings$1.position0 -= value);
308
  }
309
  return C1; // "never-used", return special object to denote that
310
+ case 0xc2: return false;
311
+ case 0xc3: return true;
312
  case 0xc4:
313
  // bin 8
314
  value = src[position$1++];
315
  if (value === undefined)
316
+ throw new Error('Unexpected end of buffer');
317
+ return readBin(value);
318
  case 0xc5:
319
  // bin 16
320
  value = dataView.getUint16(position$1);
321
  position$1 += 2;
322
+ return readBin(value);
323
  case 0xc6:
324
  // bin 32
325
  value = dataView.getUint32(position$1);
326
  position$1 += 4;
327
+ return readBin(value);
328
  case 0xc7:
329
  // ext 8
330
+ return readExt(src[position$1++]);
331
  case 0xc8:
332
  // ext 16
333
  value = dataView.getUint16(position$1);
334
  position$1 += 2;
335
+ return readExt(value);
336
  case 0xc9:
337
  // ext 32
338
  value = dataView.getUint32(position$1);
339
  position$1 += 4;
340
+ return readExt(value);
341
  case 0xca:
342
  value = dataView.getFloat32(position$1);
343
  if (currentUnpackr.useFloat32 > 2) {
344
  // this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
345
  let multiplier = mult10[((src[position$1] & 0x7f) << 1) | (src[position$1 + 1] >> 7)];
346
  position$1 += 4;
347
+ return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier;
348
  }
349
  position$1 += 4;
350
+ return value;
351
  case 0xcb:
352
  value = dataView.getFloat64(position$1);
353
  position$1 += 8;
354
+ return value;
355
  // uint handlers
356
  case 0xcc:
357
+ return src[position$1++];
358
  case 0xcd:
359
  value = dataView.getUint16(position$1);
360
  position$1 += 2;
361
+ return value;
362
  case 0xce:
363
  value = dataView.getUint32(position$1);
364
  position$1 += 4;
365
+ return value;
366
  case 0xcf:
367
  if (currentUnpackr.int64AsType === 'number') {
368
  value = dataView.getUint32(position$1) * 0x100000000;
 
375
  } else
376
  value = dataView.getBigUint64(position$1);
377
  position$1 += 8;
378
+ return value;
379
 
380
  // int handlers
381
  case 0xd0:
382
+ return dataView.getInt8(position$1++);
383
  case 0xd1:
384
  value = dataView.getInt16(position$1);
385
  position$1 += 2;
386
+ return value;
387
  case 0xd2:
388
  value = dataView.getInt32(position$1);
389
  position$1 += 4;
390
+ return value;
391
  case 0xd3:
392
  if (currentUnpackr.int64AsType === 'number') {
393
  value = dataView.getInt32(position$1) * 0x100000000;
 
400
  } else
401
  value = dataView.getBigInt64(position$1);
402
  position$1 += 8;
403
+ return value;
404
 
405
  case 0xd4:
406
  // fixext 1
407
  value = src[position$1++];
408
  if (value == 0x72) {
409
+ return recordDefinition(src[position$1++] & 0x3f);
410
  } else {
411
  let extension = currentExtensions[value];
412
  if (extension) {
413
  if (extension.read) {
414
  position$1++; // skip filler byte
415
+ return extension.read(read());
416
  } else if (extension.noBuffer) {
417
  position$1++; // skip filler byte
418
+ return extension();
419
  } else
420
+ return extension(src.subarray(position$1, ++position$1));
421
  } else
422
+ throw new Error('Unknown extension ' + value);
423
  }
424
  case 0xd5:
425
  // fixext 2
426
  value = src[position$1];
427
  if (value == 0x72) {
428
  position$1++;
429
+ return recordDefinition(src[position$1++] & 0x3f, src[position$1++]);
430
  } else
431
+ return readExt(2);
432
  case 0xd6:
433
  // fixext 4
434
+ return readExt(4);
435
  case 0xd7:
436
  // fixext 8
437
+ return readExt(8);
438
  case 0xd8:
439
  // fixext 16
440
+ return readExt(16);
441
  case 0xd9:
442
  // str 8
443
  value = src[position$1++];
444
  if (srcStringEnd >= position$1) {
445
+ return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart);
446
  }
447
+ return readString8(value);
448
  case 0xda:
449
  // str 16
450
  value = dataView.getUint16(position$1);
451
  position$1 += 2;
452
  if (srcStringEnd >= position$1) {
453
+ return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart);
454
  }
455
+ return readString16(value);
456
  case 0xdb:
457
  // str 32
458
  value = dataView.getUint32(position$1);
459
  position$1 += 4;
460
  if (srcStringEnd >= position$1) {
461
+ return srcString.slice(position$1 - srcStringStart, (position$1 += value) - srcStringStart);
462
  }
463
+ return readString32(value);
464
  case 0xdc:
465
  // array 16
466
  value = dataView.getUint16(position$1);
467
  position$1 += 2;
468
+ return readArray(value);
469
  case 0xdd:
470
  // array 32
471
  value = dataView.getUint32(position$1);
472
  position$1 += 4;
473
+ return readArray(value);
474
  case 0xde:
475
  // map 16
476
  value = dataView.getUint16(position$1);
477
  position$1 += 2;
478
+ return readMap(value);
479
  case 0xdf:
480
  // map 32
481
  value = dataView.getUint32(position$1);
482
  position$1 += 4;
483
+ return readMap(value);
484
  default: // negative int
485
  if (token >= 0xe0)
486
+ return token - 0x100;
487
  if (token === undefined) {
488
  let error = new Error('Unexpected end of MessagePack data');
489
  error.incomplete = true;
490
+ throw error;
491
  }
492
+ throw new Error('Unknown MessagePack token ' + token);
493
 
494
  }
495
  }
 
508
  inlineObjectReadThreshold = Infinity; // disable going forward
509
  return readObject(); // recursively try again
510
  }
511
+ structure.read0 = optimizedReadObject; // keep the un-wrapped body reader in sync
512
  if (structure.highByte === 0)
513
  structure.read = createSecondByteReader(firstId, structure.read);
514
+ return optimizedReadObject(); // second byte is already read, if there is one so immediately read object
515
  }
516
  let object = {};
517
  for (let i = 0, l = structure.length; i < l; i++) {
 
522
  }
523
  if (currentUnpackr.freezeData)
524
  return Object.freeze(object);
525
+ return object;
526
  }
527
  readObject.count = 0;
528
+ // read0 is the un-wrapped body reader: it reads the record's values directly without
529
+ // consuming a leading high byte. recordDefinition uses it for the immediate read that follows
530
+ // a record definition (the high byte, if present, was already consumed). For highByte === 0
531
+ // structures the public reader is a second-byte reader (used by later references), but the
532
+ // definition read itself must not consume that byte.
533
+ structure.read0 = readObject;
534
  if (structure.highByte === 0) {
535
+ return createSecondByteReader(firstId, readObject);
536
  }
537
+ return readObject;
538
  }
539
 
540
  const createSecondByteReader = (firstId, read0) => {
541
  return function() {
542
  let highByte = src[position$1++];
543
  if (highByte === 0)
544
+ return read0();
545
  let id = firstId < 32 ? -(firstId + (highByte << 5)) : firstId + (highByte << 5);
546
  let structure = currentStructures[id] || loadStructures()[id];
547
  if (!structure) {
548
+ throw new Error('Record id is not defined for ' + id);
549
  }
550
  if (!structure.read)
551
  structure.read = createStructureReader(structure, firstId);
552
+ return structure.read();
553
+ };
554
  };
555
 
556
  function loadStructures() {
557
+ let loadedStructures = saveState(() => {
558
  // save the state in case getStructures modifies our buffer
559
  src = null;
560
+ return currentUnpackr.getStructures();
561
  });
562
+ return currentStructures = currentUnpackr._mergeStructures(loadedStructures, currentStructures);
563
  }
564
 
565
  var readFixedString = readStringJS;
 
577
  let string = strings[stringPosition++];
578
  if (string == null) {
579
  if (bundledStrings$1)
580
+ return readStringJS(length);
581
  let byteOffset = src.byteOffset;
582
  let extraction = extractStrings(position$1 - headerLength + byteOffset, srcEnd + byteOffset, src.buffer);
583
  if (typeof extraction == 'string') {
 
589
  srcStringEnd = 1; // even if a utf-8 string was decoded, must indicate we are in the midst of extracted strings and can't skip strings
590
  string = strings[0];
591
  if (string === undefined)
592
+ throw new Error('Unexpected end of buffer');
593
  }
594
  }
595
  let srcStringLength = string.length;
596
  if (srcStringLength <= length) {
597
  position$1 += length;
598
+ return string;
599
  }
600
  srcString = string;
601
  srcStringStart = position$1;
602
  srcStringEnd = position$1 + srcStringLength;
603
  position$1 += length;
604
+ return string.slice(0, length); // we know we just want the beginning
605
+ };
606
  }
607
  }
608
  function readStringJS(length) {
609
  let result;
610
  if (length < 16) {
611
  if (result = shortStringInJS(length))
612
+ return result;
613
  }
614
  if (length > 64 && decoder)
615
+ return decoder.decode(src.subarray(position$1, position$1 += length));
616
  const end = position$1 + length;
617
  const units = [];
618
  result = '';
 
623
  units.push(byte1);
624
  } else if ((byte1 & 0xe0) === 0xc0) {
625
  // 2 bytes
626
+ if (byte1 < 0xc2 || position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
627
+ units.push(0xFFFD);
 
 
 
628
  } else {
629
+ const byte2 = src[position$1++] & 0x3f;
630
+ units.push(((byte1 & 0x1f) << 6) | byte2);
631
  }
632
  } else if ((byte1 & 0xf0) === 0xe0) {
633
  // 3 bytes
634
+ const byte2 = position$1 < end ? src[position$1] : 0;
635
+ if (position$1 >= end || (byte2 & 0xc0) !== 0x80 ||
636
+ (byte1 === 0xe0 && byte2 < 0xa0) || (byte1 === 0xed && byte2 >= 0xa0)) {
637
+ units.push(0xFFFD);
 
 
 
638
  } else {
639
+ position$1++;
640
+ if (position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
641
+ units.push(0xFFFD);
642
+ } else {
643
+ const byte3 = src[position$1++] & 0x3f;
644
+ units.push(((byte1 & 0x1f) << 12) | ((byte2 & 0x3f) << 6) | byte3);
645
+ }
646
  }
647
  } else if ((byte1 & 0xf8) === 0xf0) {
648
  // 4 bytes
649
+ const byte2 = position$1 < end ? src[position$1] : 0;
650
+ if (byte1 > 0xf4 || position$1 >= end || (byte2 & 0xc0) !== 0x80 ||
651
+ (byte1 === 0xf0 && byte2 < 0x90) || (byte1 === 0xf4 && byte2 >= 0x90)) {
652
+ units.push(0xFFFD);
 
 
 
 
 
 
 
 
 
653
  } else {
654
+ position$1++;
655
+ if (position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
656
+ units.push(0xFFFD);
657
+ } else {
658
+ const byte3 = src[position$1++] & 0x3f;
659
+ if (position$1 >= end || (src[position$1] & 0xc0) !== 0x80) {
660
+ units.push(0xFFFD);
661
+ } else {
662
+ const byte4 = src[position$1++] & 0x3f;
663
+ let unit = ((byte1 & 0x07) << 0x12) | ((byte2 & 0x3f) << 0x0c) | (byte3 << 0x06) | byte4;
664
+ unit -= 0x10000;
665
+ units.push(((unit >>> 10) & 0x3ff) | 0xd800);
666
+ units.push(0xdc00 | (unit & 0x3ff));
667
+ }
668
+ }
669
  }
670
  } else {
671
  units.push(0xFFFD); // replacement character for invalid lead byte
 
681
  result += fromCharCode.apply(String, units);
682
  }
683
 
684
+ return result;
 
 
 
 
 
 
 
 
 
 
685
  }
686
 
687
  function readArray(length) {
 
690
  array[i] = read();
691
  }
692
  if (currentUnpackr.freezeData)
693
+ return Object.freeze(array);
694
+ return array;
695
  }
696
 
697
  function readMap(length) {
 
703
  key = '__proto_';
704
  object[key] = read();
705
  }
706
+ return object;
707
  } else {
708
  let map = new Map();
709
  for (let i = 0; i < length; i++) {
710
  map.set(read(), read());
711
  }
712
+ return map;
713
  }
714
  }
715
 
 
721
  const byte = src[position$1++];
722
  if ((byte & 0x80) > 0) {
723
  position$1 = start;
724
+ return;
725
  }
726
  bytes[i] = byte;
727
  }
728
+ return fromCharCode.apply(String, bytes);
729
  }
730
  function shortStringInJS(length) {
731
  if (length < 4) {
732
  if (length < 2) {
733
  if (length === 0)
734
+ return '';
735
  else {
736
  let a = src[position$1++];
737
  if ((a & 0x80) > 1) {
738
  position$1 -= 1;
739
+ return;
740
  }
741
+ return fromCharCode(a);
742
  }
743
  } else {
744
  let a = src[position$1++];
745
  let b = src[position$1++];
746
  if ((a & 0x80) > 0 || (b & 0x80) > 0) {
747
  position$1 -= 2;
748
+ return;
749
  }
750
  if (length < 3)
751
+ return fromCharCode(a, b);
752
  let c = src[position$1++];
753
  if ((c & 0x80) > 0) {
754
  position$1 -= 3;
755
+ return;
756
  }
757
+ return fromCharCode(a, b, c);
758
  }
759
  } else {
760
  let a = src[position$1++];
 
763
  let d = src[position$1++];
764
  if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
765
  position$1 -= 4;
766
+ return;
767
  }
768
  if (length < 6) {
769
  if (length === 4)
770
+ return fromCharCode(a, b, c, d);
771
  else {
772
  let e = src[position$1++];
773
  if ((e & 0x80) > 0) {
774
  position$1 -= 5;
775
+ return;
776
  }
777
+ return fromCharCode(a, b, c, d, e);
778
  }
779
  } else if (length < 8) {
780
  let e = src[position$1++];
781
  let f = src[position$1++];
782
  if ((e & 0x80) > 0 || (f & 0x80) > 0) {
783
  position$1 -= 6;
784
+ return;
785
  }
786
  if (length < 7)
787
+ return fromCharCode(a, b, c, d, e, f);
788
  let g = src[position$1++];
789
  if ((g & 0x80) > 0) {
790
  position$1 -= 7;
791
+ return;
792
  }
793
+ return fromCharCode(a, b, c, d, e, f, g);
794
  } else {
795
  let e = src[position$1++];
796
  let f = src[position$1++];
 
798
  let h = src[position$1++];
799
  if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
800
  position$1 -= 8;
801
+ return;
802
  }
803
  if (length < 10) {
804
  if (length === 8)
805
+ return fromCharCode(a, b, c, d, e, f, g, h);
806
  else {
807
  let i = src[position$1++];
808
  if ((i & 0x80) > 0) {
809
  position$1 -= 9;
810
+ return;
811
  }
812
+ return fromCharCode(a, b, c, d, e, f, g, h, i);
813
  }
814
  } else if (length < 12) {
815
  let i = src[position$1++];
816
  let j = src[position$1++];
817
  if ((i & 0x80) > 0 || (j & 0x80) > 0) {
818
  position$1 -= 10;
819
+ return;
820
  }
821
  if (length < 11)
822
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j);
823
  let k = src[position$1++];
824
  if ((k & 0x80) > 0) {
825
  position$1 -= 11;
826
+ return;
827
  }
828
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k);
829
  } else {
830
  let i = src[position$1++];
831
  let j = src[position$1++];
 
833
  let l = src[position$1++];
834
  if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
835
  position$1 -= 12;
836
+ return;
837
  }
838
  if (length < 14) {
839
  if (length === 12)
840
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l);
841
  else {
842
  let m = src[position$1++];
843
  if ((m & 0x80) > 0) {
844
  position$1 -= 13;
845
+ return;
846
  }
847
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m);
848
  }
849
  } else {
850
  let m = src[position$1++];
851
  let n = src[position$1++];
852
  if ((m & 0x80) > 0 || (n & 0x80) > 0) {
853
  position$1 -= 14;
854
+ return;
855
  }
856
  if (length < 15)
857
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n);
858
  let o = src[position$1++];
859
  if ((o & 0x80) > 0) {
860
  position$1 -= 15;
861
+ return;
862
  }
863
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
864
  }
865
  }
866
  }
 
878
  case 0xd9:
879
  // str 8
880
  length = src[position$1++];
881
+ break;
882
  case 0xda:
883
  // str 16
884
  length = dataView.getUint16(position$1);
885
  position$1 += 2;
886
+ break;
887
  case 0xdb:
888
  // str 32
889
  length = dataView.getUint32(position$1);
890
  position$1 += 4;
891
+ break;
892
  default:
893
+ throw new Error('Expected string');
894
  }
895
  }
896
+ return readStringJS(length);
897
  }
898
 
899
 
 
901
  return currentUnpackr.copyBuffers ?
902
  // specifically use the copying slice (not the node one)
903
  Uint8Array.prototype.slice.call(src, position$1, position$1 += length) :
904
+ src.subarray(position$1, position$1 += length);
905
  }
906
  function readExt(length) {
907
  let type = src[position$1++];
 
914
  } finally {
915
  position$1 = end;
916
  }
917
+ });
918
  }
919
  else
920
+ throw new Error('Unknown extension type ' + type);
921
  }
922
 
923
  var keyCache = new Array(4096);
 
927
  // fixstr, potentially use key cache
928
  length = length - 0xa0;
929
  if (srcStringEnd >= position$1) // if it has been extracted, must use it (and faster anyway)
930
+ return srcString.slice(position$1 - srcStringStart, (position$1 += length) - srcStringStart);
931
  else if (!(srcStringEnd == 0 && srcEnd < 180))
932
+ return readFixedString(length);
933
  } else { // not cacheable, go back and do a standard read
934
  position$1--;
935
+ return asSafeString(read());
936
  }
937
  let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position$1) : length > 0 ? src[position$1] : 0)) & 0xfff;
938
  let entry = keyCache[key];
 
945
  chunk = dataView.getUint32(checkPosition);
946
  if (chunk != entry[i++]) {
947
  checkPosition = 0x70000000;
948
+ break;
949
  }
950
  checkPosition += 4;
951
  }
 
954
  chunk = src[checkPosition++];
955
  if (chunk != entry[i++]) {
956
  checkPosition = 0x70000000;
957
+ break;
958
  }
959
  }
960
  if (checkPosition === end) {
961
  position$1 = checkPosition;
962
+ return entry.string;
963
  }
964
  end -= 3;
965
  checkPosition = position$1;
 
980
  // for small blocks, avoiding the overhead of the extract call is helpful
981
  let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
982
  if (string != null)
983
+ return entry.string = string;
984
+ return entry.string = readFixedString(length);
985
  }
986
 
987
  function asSafeString(property) {
 
1012
  }
1013
  currentStructures[id] = structure;
1014
  structure.read = createStructureReader(structure, firstByte);
1015
+ // The high byte (if any) was already consumed as the `highByte` argument above, so read the
1016
+ // record body directly. Going through structure.read (a second-byte reader when highByte === 0)
1017
+ // would misinterpret the first value byte as a high byte — corrupting two-byte own-record
1018
+ // definitions (0xd5 0x72 ...). createStructureReader stashes the un-wrapped body reader on
1019
+ // structure.read0 precisely for this immediate post-definition read.
1020
+ return (structure.read0 || structure.read)();
1021
  };
1022
  currentExtensions[0] = () => {}; // notepack defines extension 0 to mean undefined, so use that as the default here
1023
  currentExtensions[0].noBuffer = true;
 
1039
  out <<= BigInt(64);
1040
  out |= view.getBigUint64(i);
1041
  }
1042
+ return out;
1043
  }
1044
  // if (length === 8) return view.getBigUint64(start)
1045
  let middle = start + (length >> 4 << 3);
1046
  let left = decode(start, middle);
1047
  let right = decode(middle, end);
1048
+ return (left << BigInt((end - middle) * 8)) | right;
1049
  };
1050
  head = (head << BigInt((view.byteLength - headLength) * 8)) | decode(headLength, view.byteLength);
1051
  }
1052
+ return head;
1053
  };
1054
 
1055
  let errors = {
 
1060
  if (!errors[data[0]]) {
1061
  let error = Error(data[1], { cause: data[2] });
1062
  error.name = data[0];
1063
+ return error;
1064
  }
1065
+ return errors[data[0]](data[1], { cause: data[2] });
1066
  };
1067
 
1068
  currentExtensions[0x69] = (data) => {
1069
  // id extension (for structured clones)
1070
+ if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled');
1071
  let id = dataView.getUint32(position$1 - 4);
1072
  if (!referenceMap)
1073
  referenceMap = new Map();
 
1088
  let targetProperties = read(); // read the next value as the target object to id
1089
  if (!refEntry.used) {
1090
  // no cycle, can just use the returned read object
1091
+ return refEntry.target = targetProperties; // replace the placeholder with the real one
1092
  } else {
1093
  // there is a cycle, so we have to assign properties to original target
1094
  Object.assign(target, targetProperties);
 
1099
  for (let [k, v] of targetProperties.entries()) target.set(k, v);
1100
  if (target instanceof Set)
1101
  for (let i of Array.from(targetProperties)) target.add(i);
1102
+ return target;
1103
  };
1104
 
1105
  currentExtensions[0x70] = (data) => {
1106
  // pointer extension (for structured clones)
1107
+ if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled');
1108
  let id = dataView.getUint32(position$1 - 4);
1109
  let refEntry = referenceMap.get(id);
1110
  refEntry.used = true;
1111
+ return refEntry.target;
1112
  };
1113
 
1114
  currentExtensions[0x73] = () => new Set(read());
 
1123
 
1124
  let typedArrayName = typedArrays[typeCode];
1125
  if (!typedArrayName) {
1126
+ if (typeCode === 16) return buffer;
1127
+ if (typeCode === 17) return new DataView(buffer);
1128
+ throw new Error('Could not find typed array for code ' + typeCode);
1129
  }
1130
+ return new glbl[typedArrayName](buffer);
1131
  };
1132
  currentExtensions[0x78] = () => {
1133
  let data = read();
1134
+ return new RegExp(data[0], data[1]);
1135
  };
1136
  const TEMP_BUNDLE = [];
1137
  currentExtensions[0x62] = (data) => {
 
1144
  bundledStrings$1.position1 = 0;
1145
  bundledStrings$1.postBundlePosition = position$1;
1146
  position$1 = dataPosition;
1147
+ return read();
1148
  };
1149
 
1150
  currentExtensions[0xff] = (data) => {
1151
  // 32-bit date extension
1152
  if (data.length == 4)
1153
+ return new Date((data[0] * 0x1000000 + (data[1] << 16) + (data[2] << 8) + data[3]) * 1000);
1154
  else if (data.length == 8)
1155
  return new Date(
1156
  ((data[0] << 22) + (data[1] << 14) + (data[2] << 6) + (data[3] >> 2)) / 1000000 +
1157
+ ((data[3] & 0x3) * 0x100000000 + data[4] * 0x1000000 + (data[5] << 16) + (data[6] << 8) + data[7]) * 1000);
1158
  else if (data.length == 12)
1159
  return new Date(
1160
  ((data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]) / 1000000 +
1161
+ (((data[4] & 0x80) ? -0x1000000000000 : 0) + data[6] * 0x10000000000 + data[7] * 0x100000000 + data[8] * 0x1000000 + (data[9] << 16) + (data[10] << 8) + data[11]) * 1000);
1162
  else
1163
+ return new Date('invalid');
1164
  };
1165
  // registration of bulk record definition?
1166
  // currentExtensions[0x52] = () =>
1167
 
1168
+ function saveState(callback) {
1169
+ if (currentUnpackr && currentUnpackr._onSaveState)
1170
+ currentUnpackr._onSaveState();
1171
  let savedSrcEnd = srcEnd;
1172
  let savedPosition = position$1;
1173
  let savedStringPosition = stringPosition;
 
1200
  currentStructures.splice(0, currentStructures.length, ...savedStructuresContents);
1201
  currentUnpackr = savedPackr;
1202
  dataView = new DataView(src.buffer, src.byteOffset, src.byteLength);
1203
+ return value;
1204
  }
1205
  function clearSource() {
1206
  src = null;
 
1234
  function roundFloat32$1(float32Number) {
1235
  f32Array[0] = float32Number;
1236
  let multiplier = mult10[((u8Array[3] & 0x7f) << 1) | (u8Array[2] >> 7)];
1237
+ return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier;
 
 
 
 
 
1238
  }
1239
+ // Marker for downstream libraries (e.g. structon) to detect per-instance
1240
+ // struct-decoding hooks (this._readStruct, this._onLoadedStructures,
1241
+ // this._onSaveState). See `checkedRead` for the dispatch.
1242
+ Unpackr$1.SUPPORTS_STRUCT_HOOKS = true;
1243
 
1244
+ let textEncoder;
1245
  try {
1246
+ textEncoder = new TextEncoder();
1247
  } catch (error) {}
1248
  let extensions, extensionClasses;
1249
+ const hasNodeBuffer = typeof Buffer !== 'undefined';
1250
+ const ByteArrayAllocate = hasNodeBuffer ?
1251
+ function(length) { return Buffer.allocUnsafeSlow(length); } : Uint8Array;
1252
+ const ByteArray = hasNodeBuffer ? Buffer : Uint8Array;
1253
+ const MAX_BUFFER_SIZE = hasNodeBuffer ? 0x100000000 : 0x7fd00000;
1254
  let target, keysTarget;
1255
  let targetView;
1256
  let position = 0;
1257
  let safeEnd;
1258
  let bundledStrings = null;
 
1259
  const MAX_BUNDLE_SIZE = 0x5500; // maximum characters such that the encoded bytes fits in 16 bits.
1260
  const hasNonLatin = /[\u0080-\uFFFF]/;
1261
  const RECORD_SYMBOL = Symbol('record-id');
 
1268
  let structures;
1269
  let referenceMap;
1270
  let encodeUtf8 = ByteArray.prototype.utf8Write ? function(string, position) {
1271
+ return target.utf8Write(string, position, target.byteLength - position);
1272
+ } : (textEncoder && textEncoder.encodeInto) ?
1273
  function(string, position) {
1274
+ return textEncoder.encodeInto(string, target.subarray(position)).written;
1275
  } : false;
1276
 
1277
  let packr = this;
 
1283
  if (maxSharedStructures == null)
1284
  maxSharedStructures = hasSharedStructures ? 32 : 0;
1285
  if (maxSharedStructures > 8160)
1286
+ throw new Error('Maximum maxSharedStructure is 8160');
1287
  if (options.structuredClone && options.moreTypes == undefined) {
1288
  this.moreTypes = true;
1289
  }
 
1297
  let sharedLimitId = maxSharedStructures + 0x40;
1298
  let maxStructureId = maxSharedStructures + maxOwnStructures + 0x40;
1299
  if (maxStructureId > 8256) {
1300
+ throw new Error('Maximum maxSharedStructure + maxOwnStructure is 8192');
1301
  }
1302
  let recordIdsToRemove = [];
1303
  let transitionsCount = 0;
 
1333
  let sharedLength = structures.sharedLength || 0;
1334
  if (sharedLength > maxSharedStructures) {
1335
  //if (maxSharedStructures <= 32 && structures.sharedLength > 32) // TODO: could support this, but would need to update the limit ids
1336
+ throw new Error('Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to ' + structures.sharedLength);
1337
  }
1338
  if (!structures.transitions) {
1339
  // rebuild our structure transitions
 
1341
  for (let i = 0; i < sharedLength; i++) {
1342
  let keys = structures[i];
1343
  if (!keys)
1344
+ continue;
1345
  let nextTransition, transition = structures.transitions;
1346
  for (let j = 0, l = keys.length; j < l; j++) {
1347
  let key = keys[j];
 
1363
  hasSharedUpdate = false;
1364
  let encodingError;
1365
  try {
1366
+ if (packr._writeStruct && value && typeof value === 'object') {
1367
  if (value.constructor === Object) writeStruct(value); // simple object
1368
  else if (value.constructor !== Map && !Array.isArray(value) && !extensionClasses.some(extClass => value instanceof extClass)) {
1369
  // allow user classes, if they don't need special handling (but do use toJSON if available)
 
1407
  packr.offset = position;
1408
  let serialized = insertIds(target.subarray(start, position), idsToInsert);
1409
  referenceMap = null;
1410
+ return serialized;
1411
  }
1412
  packr.offset = position; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
1413
  if (encodeOptions & REUSE_BUFFER_MODE) {
1414
  target.start = start;
1415
  target.end = position;
1416
+ return target;
1417
  }
1418
+ return target.subarray(start, position); // position can change if we call pack again in saveStructures, so we get the buffer now
1419
  } catch(error) {
1420
  encodingError = error;
1421
  throw error;
 
1426
  let sharedLength = structures.sharedLength || 0;
1427
  // we can't rely on start/end with REUSE_BUFFER_MODE since they will (probably) change when we save
1428
  let returnBuffer = target.subarray(start, position);
1429
+ let newSharedData = (packr._prepareStructures || prepareStructures)(structures, packr);
1430
  if (!encodingError) { // TODO: If there is an encoding error, should make the structures as uninitialized so they get rebuilt next time
1431
  if (packr.saveStructures(newSharedData, newSharedData.isCompatible) === false) {
1432
+ // The save was declined (a concurrent writer updated the shared structures,
1433
+ // or the store transaction did not durably commit). Our in-memory
1434
+ // structures + transition trie may now reference record ids that were
1435
+ // never persisted; re-packing as-is would re-emit the same record pointing
1436
+ // at an unpersisted structure (-> "Record id is not defined" on decode).
1437
+ // Mark structures uninitialized so the re-pack reloads durable structures
1438
+ // via getStructures, rebuilds the transition trie, and re-mints + re-saves.
1439
+ structures.uninitialized = true;
1440
+ return packr.pack(value, encodeOptions);
1441
  }
1442
  packr.lastNamedStructuresLength = sharedLength;
1443
  // don't keep large buffers around
1444
  if (target.length > 0x40000000) target = null;
1445
+ return returnBuffer;
1446
  }
1447
  }
1448
  }
 
1528
  bundledStrings[twoByte ? 0 : 1] += value;
1529
  target[position++] = 0xc1;
1530
  pack(twoByte ? -strLength : strLength);
1531
+ return;
1532
  }
1533
  let headerSize;
1534
  // first we estimate the header size, so we can write to the correct location
 
1602
  } else if (type === 'number') {
1603
  if (value >>> 0 === value) {// positive integer, 32-bit or less
1604
  // positive uint
1605
+ if (value < 0x20 || (value < 0x80 && this.useRecords === false) || (value < 0x40 && !this._writeStruct)) {
1606
  target[position++] = value;
1607
  } else if (value < 0x100) {
1608
  target[position++] = 0xcc;
 
1641
  // this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
1642
  ((xShifted = value * mult10[((target[position] & 0x7f) << 1) | (target[position + 1] >> 7)]) >> 0) === xShifted) {
1643
  position += 4;
1644
+ return;
1645
  } else
1646
  position--; // move back into position for writing a double
1647
  }
 
1664
  target[position++] = 0x70; // "p" for pointer
1665
  targetView.setUint32(position, referee.id);
1666
  position += 4;
1667
+ return;
1668
  } else
1669
  referenceMap.set(value, { offset: position - start });
1670
  }
 
1714
  } else {
1715
  pack(writeResult);
1716
  }
1717
+ return;
1718
  }
1719
  let currentTarget = target;
1720
  let currentTargetView = targetView;
 
1731
  makeRoom(position);
1732
  return {
1733
  target, targetView, position: position - size
1734
+ };
1735
  }, pack);
1736
  } finally {
1737
  // restore current target information (unless already restored)
 
1747
  makeRoom(result.length + position);
1748
  position = writeExtensionData(result, target, position, extension.type);
1749
  }
1750
+ return;
1751
  }
1752
  }
1753
  // check isArray after extensions, because extensions can extend Array
 
1759
  const json = value.toJSON();
1760
  // if for some reason value.toJSON returns itself it'll loop forever
1761
  if (json !== value)
1762
+ return pack(json);
1763
  }
1764
 
1765
  // if there is a writeFunction, use it, otherwise just encode as undefined
 
1798
  let chunks = [];
1799
  while (true) {
1800
  chunks.push(value & mask);
1801
+ if ((value >> BigInt(63)) === empty) break;
1802
  value >>= BigInt(64);
1803
  }
1804
 
 
1813
  string = '00' + string;
1814
  }
1815
 
1816
+ if (hasNodeBuffer) {
1817
  array = Buffer.from(string, 'hex');
1818
  } else {
1819
  array = new Uint8Array(string.length / 2);
 
1830
  if (array.length + position > safeEnd)
1831
  makeRoom(array.length + position);
1832
  position = writeExtensionData(array, target, position, 0x42);
1833
+ return;
1834
  } else {
1835
  throw new RangeError(value + ' was too large to fit in MessagePack 64-bit integer format, use' +
1836
  ' useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set' +
1837
+ ' largeBigIntToString to convert to string');
1838
  }
1839
  }
1840
  position += 8;
 
1847
  target[position++] = 0;
1848
  }
1849
  } else {
1850
+ throw new Error('Unknown type: ' + type);
1851
  }
1852
  };
1853
 
 
1993
  checkUseRecords(object) ? writeRecord(object) : writePlainObject(object);
1994
  } : writeRecord;
1995
 
1996
+ const writeStruct = (object) => {
1997
+ let newPosition = packr._writeStruct(object, target, start, position, structures, makeRoom, (value, newPosition, notifySharedUpdate) => {
1998
+ if (notifySharedUpdate)
1999
+ return hasSharedUpdate = true;
2000
+ position = newPosition;
2001
+ let startTarget = target;
2002
+ pack(value);
2003
+ resetStructures();
2004
+ if (startTarget !== target) {
2005
+ return { position, targetView, target }; // indicate the buffer was re-allocated
2006
+ }
2007
+ return position;
2008
+ });
2009
+ if (newPosition === 0) // bail and go to a msgpack object
2010
+ return writeObject(object);
2011
+ position = newPosition;
2012
+ };
2013
+
2014
  const makeRoom = (end) => {
2015
  let newSize;
2016
  if (end > 0x1000000) {
2017
  // special handling for really large buffers
2018
  if ((end - start) > MAX_BUFFER_SIZE)
2019
+ throw new Error('Packed buffer would be larger than maximum buffer size');
2020
  newSize = Math.min(MAX_BUFFER_SIZE,
2021
  Math.round(Math.max((end - start) * (end > 0x4000000 ? 1.25 : 2), 0x400000) / 0x1000) * 0x1000);
2022
  } else // faster handling for smaller buffers
 
2031
  position -= start;
2032
  start = 0;
2033
  safeEnd = newBuffer.length - 10;
2034
+ return target = newBuffer;
2035
  };
2036
  const newRecord = (transition, keys, newTransitions) => {
2037
  let recordId = structures.nextId;
 
2113
  target[insertionOffset + start] = keysTarget[0];
2114
  }
2115
  };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2116
  }
2117
  useBuffer(buffer) {
2118
  // this means we are finished using our own buffer and we can write over it safely
 
2155
  } else if (isNaN(seconds)) {
2156
  if (this.onInvalidDate) {
2157
  allocateForWrite(0);
2158
+ return pack(this.onInvalidDate());
2159
  }
2160
  // Intentionally invalid timestamp
2161
  let { target, targetView, position} = allocateForWrite(3);
 
2176
  pack(set, allocateForWrite, pack) {
2177
  if (this.setAsEmptyObject) {
2178
  allocateForWrite(0);
2179
+ return pack({});
2180
  }
2181
  let array = Array.from(set);
2182
  let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
 
2212
  if (this.moreTypes)
2213
  writeExtBuffer(arrayBuffer, 0x10, allocateForWrite);
2214
  else
2215
+ writeBuffer(hasNodeBuffer ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite);
2216
  }
2217
  }, {
2218
  pack(typedArray, allocateForWrite) {
 
2227
  if (this.moreTypes)
2228
  writeExtBuffer(arrayBuffer, 0x11, allocateForWrite);
2229
  else
2230
+ writeBuffer(hasNodeBuffer ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite);
2231
  }
2232
  }, {
2233
  pack(c1, allocateForWrite) { // specific 0xC1 object
 
2284
  switch (length) {
2285
  case 1:
2286
  target[position++] = 0xd4;
2287
+ break;
2288
  case 2:
2289
  target[position++] = 0xd5;
2290
+ break;
2291
  case 4:
2292
  target[position++] = 0xd6;
2293
+ break;
2294
  case 8:
2295
  target[position++] = 0xd7;
2296
+ break;
2297
  case 16:
2298
  target[position++] = 0xd8;
2299
+ break;
2300
  default:
2301
  if (length < 0x100) {
2302
  target[position++] = 0xc7;
 
2316
  target[position++] = type;
2317
  target.set(result, position);
2318
  position += length;
2319
+ return position;
2320
  }
2321
 
2322
  function insertIds(serialized, idsToInsert) {
 
2338
  serialized[position++] = id & 0xff;
2339
  lastEnd = offset;
2340
  }
2341
+ return serialized;
2342
  }
2343
 
2344
  function writeBundles(start, pack, incrementPosition) {
 
2355
  function addExtension$1(extension) {
2356
  if (extension.Class) {
2357
  if (!extension.pack && !extension.write)
2358
+ throw new Error('Extension has no pack or write function');
2359
  if (extension.pack && !extension.type)
2360
+ throw new Error('Extension has no type (numeric code to identify the extension)');
2361
  extensionClasses.unshift(extension.Class);
2362
  extensions.unshift(extension);
2363
  }
2364
  addExtension$2(extension);
2365
  }
2366
+ function prepareStructures(structures, packr) {
2367
  structures.isCompatible = (existingStructures) => {
2368
  let compatible = !existingStructures || ((packr.lastNamedStructuresLength || 0) === existingStructures.length);
2369
  if (!compatible) // we want to merge these existing structures immediately since we already have it and we are in the right transaction
2370
  packr._mergeStructures(existingStructures);
2371
  return compatible;
2372
  };
2373
+ return structures;
 
 
 
 
2374
  }
2375
 
2376
+ // Marker for downstream libraries (e.g. structon) to detect that this Packr
2377
+ // supports per-instance struct-encoding hooks (this._writeStruct,
2378
+ // this._prepareStructures). See `pack` for the dispatch.
2379
+ Packr$1.SUPPORTS_STRUCT_HOOKS = true;
2380
+
2381
  let defaultPackr = new Packr$1({ useRecords: false });
2382
  const pack$1 = defaultPackr.pack;
2383
  defaultPackr.pack;
 
2385
  const RESET_BUFFER_MODE = 1024;
2386
  const RESERVE_START_SPACE = 2048;
2387
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2388
  const nativeAccelerationDisabled = process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED !== undefined && process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED.toLowerCase() === 'true';
2389
 
2390
  if (!nativeAccelerationDisabled) {
 
2393
  if (typeof require == 'function')
2394
  extractor = require('msgpackr-extract');
2395
  else
2396
+ extractor = module.createRequire((_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('test.js', document.baseURI).href))('msgpackr-extract');
2397
  if (extractor)
2398
  setExtractor(extractor.extractStrings);
2399
  } catch (error) {
 
2403
 
2404
  let allSampleData = [];
2405
  for (let i = 1; i < 6; i++) {
2406
+ allSampleData.push(JSON.parse(fs.readFileSync(new URL(`./example${i > 1 ? i : ''}.json`, (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('test.js', document.baseURI).href)))));
2407
  }
2408
  allSampleData.push({
2409
  name: 'some other types',
 
2413
  const sampleData = allSampleData[3];
2414
  function tryRequire(module) {
2415
  try {
2416
+ return require(module);
2417
  } catch(error) {
2418
+ return {};
2419
  }
2420
  }
 
 
 
 
 
 
 
2421
  //if (typeof chai === 'undefined') { chai = require('chai') }
2422
  var assert = chai.assert;
2423
  //if (typeof msgpackr === 'undefined') { msgpackr = require('..') }
 
2538
  const result = unpack(payload);
2539
  assert.notEqual(result, '/');
2540
  });
2541
+ test('invalid UTF-8 continuation bytes', function () {
2542
+ const replacement = '\uFFFD';
2543
+ const strings = [
2544
+ [[0xc2, 0x41], replacement + 'A'],
2545
+ [[0xe1, 0x41, 0x42], replacement + 'AB'],
2546
+ [[0xe1, 0x80, 0x41], replacement + 'A'],
2547
+ [[0xf1, 0x41, 0x42, 0x43], replacement + 'ABC'],
2548
+ [[0xf1, 0x80, 0x41, 0x42], replacement + 'AB'],
2549
+ [[0xf1, 0x80, 0x80, 0x41], replacement + 'A'],
2550
+ ];
2551
+ for (const [bytes, expected] of strings) {
2552
+ const payload = Buffer.from([0xa0 + bytes.length, ...bytes]);
2553
+ assert.equal(unpack(payload), expected);
2554
+ }
2555
+ });
2556
+ test('truncated UTF-8 sequences do not consume following values', function () {
2557
+ assert.deepEqual(unpack(Buffer.from([0x92, 0xa1, 0xc2, 0x01])), ['\uFFFD', 1]);
2558
+ assert.deepEqual(unpack(Buffer.from([0x92, 0xa2, 0xe1, 0x80, 0x01])), ['\uFFFD', 1]);
2559
+ assert.deepEqual(unpack(Buffer.from([0x92, 0xa3, 0xf1, 0x80, 0x80, 0x01])), ['\uFFFD', 1]);
2560
+ assert.deepEqual(
2561
+ unpack(Buffer.from([0x93, 0xa1, 0xe0, 0xa4, 0x6e, 0x65, 0x78, 0x74, 0x07])),
2562
+ ['\uFFFD', 'next', 7]
2563
+ );
2564
+ });
2565
  test('use ArrayBuffer', function () {
2566
  const data = {prop: 'a test'};
2567
  var serialized = pack(data);
 
2571
  var deserialized = unpack(ab);
2572
  assert.deepEqual(deserialized, data);
2573
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2574
 
2575
  for (let sampleData of allSampleData) {
2576
  let snippet = JSON.stringify(sampleData).slice(0, 20) + '...';
 
2593
  var deserialized = unpack(serialized);
2594
  assert.deepEqual(deserialized, data);
2595
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2596
  test('pack/unpack sample data with bundled strings ' + snippet, function () {
2597
  var data = sampleData;
2598
  let packr = new Packr({ /*structures,*/ useRecords: false, bundleStrings: true});
 
2783
 
2784
  }
2785
  Extended.prototype.getDouble = function() {
2786
+ return this.value * 2;
2787
  };
2788
  var instance = new Extended();
2789
  instance.value = 4;
 
2803
  let data = packr.unpack(buffer);
2804
  e.value = data[0];
2805
  e.string = data[1];
2806
+ return e;
2807
  },
2808
  pack: function(instance) {
2809
+ return packr.pack([instance.value, instance.string]);
2810
  }
2811
  });
2812
  var serialized = pack(data);
 
2832
  type: 12,
2833
  read: function(data) {
2834
  Object.setPrototypeOf(data, ExtendArray.prototype);
2835
+ return data;
2836
  },
2837
  write: function(instance) {
2838
+ return [...instance];
2839
  }
2840
  });
2841
  var serialized = pack(data);
 
2888
  Class: TestClass,
2889
  type: 0x01,
2890
  pack() {
2891
+ return typeof Buffer != 'undefined' ? Buffer.alloc(256) : new Uint8Array(256);
2892
  },
2893
  unpack(data) {
2894
+ return data.length;
2895
  }
2896
  });
2897
  let result = unpack(pack(new TestClass()));
 
2903
 
2904
  }
2905
  Extended.prototype.getDouble = function() {
2906
+ return this.value * 2;
2907
  };
2908
  var instance = new Extended();
2909
  instance.value = 4;
 
2922
  let e = new Extended();
2923
  e.value = data[0];
2924
  e.string = data[1];
2925
+ return e;
2926
  },
2927
  write: function(instance) {
2928
+ return [instance.value, instance.string];
2929
  }
2930
  });
2931
  var serialized = pack(data);
 
2938
 
2939
  }
2940
  Extended.prototype.getDouble = function() {
2941
+ return this.value * 2;
2942
  };
2943
  var instance = new Extended();
2944
  instance.value = 4;
 
2955
  type: 13,
2956
  read: function(data) {
2957
  Object.setPrototypeOf(data, Extended.prototype);
2958
+ return data;
2959
  },
2960
  write: function(data) {
2961
+ return data;
2962
  }
2963
  });
2964
  var serialized = pack(data);
 
2983
  type: 14,
2984
  read: function(data) {
2985
  Object.setPrototypeOf(data, ExtendArray3.prototype);
2986
+ return data;
2987
  },
2988
  write: function(data) {
2989
+ return data;
2990
  }
2991
  });
2992
  var serialized = pack(data);
 
3001
 
3002
  }
3003
  Extended.prototype.__call__ = function(){
3004
+ return this.value * 4;
3005
  };
3006
  Extended.prototype.getDouble = function() {
3007
+ return this.value * 2;
3008
  };
3009
 
3010
  var instance = function() { instance.__call__();/* callable stuff */ };
 
3021
  var e = function() { e.__call__(); };
3022
  Object.setPrototypeOf(e,Extended.prototype);
3023
  e.value = packr.unpack(buffer);
3024
+ return e;
3025
  },
3026
  pack: function(instance) {
3027
+ return packr.pack(instance.value);
3028
  }
3029
  });
3030
  var serialized = pack(data);
 
3040
  addExtension({
3041
  Class: Date,
3042
  write(date) {
3043
+ return date.toString();
3044
  }
3045
  });
3046
  var serialized = pack(data);
 
3337
  const structures2 = [...structures];
3338
  const packr = new Packr({
3339
  getStructures() {
3340
+ return structures;
3341
  },
3342
  saveStructures(structures) {
3343
  },
 
3345
  });
3346
  const packr2 = new Packr({
3347
  getStructures() {
3348
+ return structures2;
3349
  },
3350
  saveStructures(structures) {
3351
  },
 
3357
  assert.deepEqual(inputData, outputData);
3358
  });
3359
 
3360
+ test('declined structure save re-packs against durable structures (no dangling record)', function() {
3361
+ // Regression: when saveStructures declines a save (a concurrent writer updated the shared
3362
+ // structures, or the store txn did not durably commit), the in-memory structures/transition
3363
+ // trie reference a record id that was never persisted. The re-pack must reload the durable
3364
+ // structures and re-mint/re-save — otherwise it re-emits the same record pointing at an
3365
+ // unsaved structure, and reads throw "Record id is not defined".
3366
+ const meta = new Packr();
3367
+ let store = null;
3368
+ let declinedOnce = false;
3369
+ const packr = new Packr({
3370
+ useRecords: true,
3371
+ getStructures() { return store ? meta.unpack(store) : undefined; },
3372
+ saveStructures(structures) {
3373
+ if (!declinedOnce) { declinedOnce = true; return false; } // decline the first save
3374
+ store = meta.pack(structures); return true;
3375
+ },
3376
+ });
3377
+ const a = packr.pack({ x: 9, y: 8 });
3378
+ const b = packr.pack({ x: 7, y: 6 });
3379
+ const reader = new Packr({ getStructures() { return store ? meta.unpack(store) : undefined; } });
3380
+ assert.deepEqual(reader.unpack(a), { x: 9, y: 8 });
3381
+ assert.deepEqual(reader.unpack(b), { x: 7, y: 6 });
3382
+ });
3383
+
3384
  test('big buffer', function() {
3385
  var size = 100000000;
3386
  var data = new Uint8Array(size).fill(1);
 
3690
 
3691
  test('pack toJSON returning this', () => {
3692
  class Serializable {
3693
+ someData = [1, 2, 3, 4];
3694
  toJSON() {
3695
+ return this;
3696
  }
3697
  }
3698
  const serialized = pack(new Serializable);
 
3795
  });
3796
  });
3797
 
3798
+ suite('msgpackr – two-byte record definitions (over-cap own records with a shared store)', function () {
3799
+ // Regression for a data-corruption bug: with a shared-structures store (getStructures/
3800
+ // saveStructures) and maxOwnStructures > 32, msgpackr uses two-byte record ids
3801
+ // (useTwoByteRecords). Over-cap "own" record shapes fall back to the classic record encoder,
3802
+ // which emits a SELF-CONTAINED record definition (0xd5 0x72 <firstByte> <highByte> <keys>
3803
+ // <values>). On read, recordDefinition() consumed the high byte itself, then invoked
3804
+ // structure.read() — which, for a highByte === 0 structure, was a second-byte reader that
3805
+ // consumed the FIRST VALUE BYTE as a phantom high byte, mis-resolving to a never-defined id
3806
+ // ("Record id is not defined for N"). The one-byte path (maxOwnStructures <= 32, fixext 1
3807
+ // 0xd4 0x72) was unaffected because no high byte / second-byte reader is involved.
3808
+ // Fix: recordDefinition reads the body via the un-wrapped reader (structure.read0).
3809
+ const sharedStore = () => {
3810
+ let saved = [];
3811
+ return { getStructures: () => saved, saveStructures: (s) => { saved = s; return true; }, peek: () => saved };
3812
+ };
3813
+ // Width-heterogeneous record generator: many distinct shapes, exceeding any modest cap, so
3814
+ // the over-cap classic-record fallback path is exercised heavily.
3815
+ const makeRecords = (count) => {
3816
+ const out = [];
3817
+ for (let i = 0; i < count; i++) {
3818
+ const rec = { id: i };
3819
+ const n = 1 + (i % 6);
3820
+ for (let a = 0; a < n; a++) rec['attr_' + ((i * 7 + a) % 400)] = i % 2 ? 's' + i : i;
3821
+ out.push(rec);
3822
+ }
3823
+ return out;
3824
+ };
3825
+
3826
+ test('cap=256 + shared store round-trips every over-cap shape (two-byte mode)', function () {
3827
+ const store = sharedStore();
3828
+ const o = { randomAccessStructure: true, useRecords: true, useBigIntExtension: true, maxOwnStructures: 256, ...store };
3829
+ const w = new Packr(o), r = new Packr(o);
3830
+ const records = makeRecords(3000);
3831
+ let sawTwoByteDef = false;
3832
+ for (const rec of records) {
3833
+ const buf = w.pack(rec);
3834
+ if (buf[0] === 0xd5 && buf[1] === 0x72) sawTwoByteDef = true;
3835
+ assert.deepEqual(r.unpack(buf), rec);
3836
+ }
3837
+ assert.ok(sawTwoByteDef, 'expected at least one two-byte (0xd5 0x72) record definition to be exercised');
3838
+ });
3839
+
3840
+ test('over-cap own records do not grow the shared dictionary without bound', function () {
3841
+ const store = sharedStore();
3842
+ const o = { randomAccessStructure: true, useRecords: true, useBigIntExtension: true, maxOwnStructures: 256, ...store };
3843
+ const w = new Packr(o);
3844
+ for (const rec of makeRecords(3000)) w.pack(rec);
3845
+ const saved = store.peek();
3846
+ const named = saved instanceof Map ? (saved.get('named') || []) : (saved || []);
3847
+ // Over-cap shapes are inlined as self-contained definitions, not minted as ever-growing
3848
+ // shared ids, so the shared store stays bounded by the few genuinely shared shapes.
3849
+ assert.ok(named.length < 100, 'named structures should stay bounded, got ' + named.length);
3850
+ });
3851
+
3852
+ test('two-byte record REFERENCES (shared, maxShared=64) round-trip with stable shapes', function () {
3853
+ // maxSharedStructures > 32 forces two-byte mode; stable repeated shapes get a definition
3854
+ // once then are emitted as two-byte references (0x60-0x7f + high byte) — the path that
3855
+ // relies on structure.read remaining a second-byte reader after the fix.
3856
+ const store = sharedStore();
3857
+ const o = { useRecords: true, maxSharedStructures: 64, maxOwnStructures: 64, ...store };
3858
+ const w = new Packr(o), r = new Packr(o);
3859
+ const shapes = [];
3860
+ for (let s = 0; s < 100; s++) { const rec = {}; for (let f = 0; f <= s % 8; f++) rec['k' + s + '_' + f] = s * 10 + f; shapes.push(rec); }
3861
+ let sawRef = false;
3862
+ for (let round = 0; round < 4; round++) for (const shp of shapes) {
3863
+ const buf = w.pack(shp);
3864
+ if (buf[0] >= 0x60 && buf[0] < 0x80) sawRef = true;
3865
+ assert.deepEqual(r.unpack(buf), shp);
3866
+ }
3867
+ assert.ok(sawRef, 'expected at least one two-byte record reference (0x60-0x7f) to be exercised');
3868
+ });
3869
+
3870
+ test('one-byte path (maxOwn=32) keeps working with a shared store', function () {
3871
+ const store = sharedStore();
3872
+ const o = { randomAccessStructure: true, useRecords: true, useBigIntExtension: true, maxOwnStructures: 32, ...store };
3873
+ const w = new Packr(o), r = new Packr(o);
3874
+ for (const rec of makeRecords(3000)) {
3875
+ assert.deepEqual(r.unpack(w.pack(rec)), rec);
3876
+ }
3877
+ });
3878
+ });
3879
+
3880
  })(chai, null, module, fs);
3881
  //# sourceMappingURL=test.js.map
.opencode/node_modules/msgpackr/dist/test.js.map CHANGED
The diff for this file is too large to render. See raw diff
 
.opencode/node_modules/msgpackr/dist/unpack-no-eval.cjs CHANGED
@@ -32,7 +32,6 @@
32
  C1.name = 'MessagePack 0xC1';
33
  var sequentialMode = false;
34
  var inlineObjectReadThreshold = 2;
35
- var readStruct, onLoadedStructures, onSaveState;
36
  var BlockedFunction; // we use search and replace to change the next call to BlockedFunction to avoid CSP issues for
37
 
38
  class Unpackr {
@@ -65,8 +64,8 @@
65
  // re-entrant execution, save the state and restore it after we do this unpack
66
  return saveState(() => {
67
  clearSource();
68
- return this ? this.unpack(source, options) : Unpackr.prototype.unpack.call(defaultOptions, source, options)
69
- })
70
  }
71
  if (!source.buffer && source.constructor === ArrayBuffer)
72
  source = typeof Buffer !== 'undefined' ? Buffer.from(source) : new Uint8Array(source);
@@ -92,14 +91,14 @@
92
  // if it doesn't have a buffer, maybe it is the wrong type of object
93
  src = null;
94
  if (source instanceof Uint8Array)
95
- throw error
96
- throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source))
97
  }
98
  if (this instanceof Unpackr) {
99
  currentUnpackr = this;
100
  if (this.structures) {
101
  currentStructures = this.structures;
102
- return checkedRead(options)
103
  } else if (!currentStructures || currentStructures.length > 0) {
104
  currentStructures = [];
105
  }
@@ -108,7 +107,7 @@
108
  if (!currentStructures || currentStructures.length > 0)
109
  currentStructures = [];
110
  }
111
- return checkedRead(options)
112
  }
113
  unpackMultiple(source, forEach) {
114
  let values, lastPosition = 0;
@@ -121,7 +120,7 @@
121
  while(position < size) {
122
  lastPosition = position;
123
  if (forEach(checkedRead(), lastPosition, position) === false) {
124
- return
125
  }
126
  }
127
  }
@@ -131,20 +130,20 @@
131
  lastPosition = position;
132
  values.push(checkedRead());
133
  }
134
- return values
135
  }
136
  } catch(error) {
137
  error.lastPosition = lastPosition;
138
  error.values = values;
139
- throw error
140
  } finally {
141
  sequentialMode = false;
142
  clearSource();
143
  }
144
  }
145
  _mergeStructures(loadedStructures, existingStructures) {
146
- if (onLoadedStructures)
147
- loadedStructures = onLoadedStructures.call(this, loadedStructures);
148
  loadedStructures = loadedStructures || [];
149
  if (Object.isFrozen(loadedStructures))
150
  loadedStructures = loadedStructures.map(structure => structure.slice(0));
@@ -168,14 +167,14 @@
168
  }
169
  }
170
  }
171
- return this.structures = loadedStructures
172
  }
173
  decode(source, options) {
174
- return this.unpack(source, options)
175
  }
176
  }
177
  function getPosition() {
178
- return position
179
  }
180
  function checkedRead(options) {
181
  try {
@@ -185,8 +184,8 @@
185
  currentStructures.length = sharedLength;
186
  }
187
  let result;
188
- if (currentUnpackr.randomAccessStructure && src[position] < 0x40 && src[position] >= 0x20 && readStruct) {
189
- result = readStruct(src, position, srcEnd, currentUnpackr);
190
  src = null; // dispose of this so that recursive unpack calls don't save state
191
  if (!(options && options.lazy) && result)
192
  result = result.toJSON();
@@ -212,7 +211,7 @@
212
  referenceMap = null;
213
  } else if (position > srcEnd) {
214
  // over read
215
- throw new Error('Unexpected end of MessagePack data')
216
  } else if (!sequentialMode) {
217
  let jsonView;
218
  try {
@@ -220,10 +219,10 @@
220
  } catch(error) {
221
  jsonView = '(JSON view not available ' + error + ')';
222
  }
223
- throw new Error('Data read, but end of buffer not reached ' + jsonView)
224
  }
225
  // else more to read, but we are reading sequentially, so don't clear source yet
226
- return result
227
  } catch(error) {
228
  if (currentStructures && currentStructures.restoreStructures)
229
  restoreStructures();
@@ -231,7 +230,7 @@
231
  if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position > srcEnd) {
232
  error.incomplete = true;
233
  }
234
- throw error
235
  }
236
  }
237
 
@@ -247,7 +246,7 @@
247
  if (token < 0xa0) {
248
  if (token < 0x80) {
249
  if (token < 0x40)
250
- return token
251
  else {
252
  let structure = currentStructures[token & 0x3f] ||
253
  currentUnpackr.getStructures && loadStructures()[token & 0x3f];
@@ -255,9 +254,9 @@
255
  if (!structure.read) {
256
  structure.read = createStructureReader(structure, token & 0x3f);
257
  }
258
- return structure.read()
259
  } else
260
- return token
261
  }
262
  } else if (token < 0x90) {
263
  // map
@@ -270,13 +269,13 @@
270
  key = '__proto_';
271
  object[key] = read();
272
  }
273
- return object
274
  } else {
275
  let map = new Map();
276
  for (let i = 0; i < token; i++) {
277
  map.set(read(), read());
278
  }
279
- return map
280
  }
281
  } else {
282
  token -= 0x90;
@@ -285,91 +284,91 @@
285
  array[i] = read();
286
  }
287
  if (currentUnpackr.freezeData)
288
- return Object.freeze(array)
289
- return array
290
  }
291
  } else if (token < 0xc0) {
292
  // fixstr
293
  let length = token - 0xa0;
294
  if (srcStringEnd >= position) {
295
- return srcString.slice(position - srcStringStart, (position += length) - srcStringStart)
296
  }
297
  if (srcStringEnd == 0 && srcEnd < 140) {
298
  // for small blocks, avoiding the overhead of the extract call is helpful
299
  let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
300
  if (string != null)
301
- return string
302
  }
303
- return readFixedString(length)
304
  } else {
305
  let value;
306
  switch (token) {
307
- case 0xc0: return null
308
  case 0xc1:
309
  if (bundledStrings) {
310
  value = read(); // followed by the length of the string in characters (not bytes!)
311
  if (value > 0)
312
- return bundledStrings[1].slice(bundledStrings.position1, bundledStrings.position1 += value)
313
  else
314
- return bundledStrings[0].slice(bundledStrings.position0, bundledStrings.position0 -= value)
315
  }
316
  return C1; // "never-used", return special object to denote that
317
- case 0xc2: return false
318
- case 0xc3: return true
319
  case 0xc4:
320
  // bin 8
321
  value = src[position++];
322
  if (value === undefined)
323
- throw new Error('Unexpected end of buffer')
324
- return readBin(value)
325
  case 0xc5:
326
  // bin 16
327
  value = dataView.getUint16(position);
328
  position += 2;
329
- return readBin(value)
330
  case 0xc6:
331
  // bin 32
332
  value = dataView.getUint32(position);
333
  position += 4;
334
- return readBin(value)
335
  case 0xc7:
336
  // ext 8
337
- return readExt(src[position++])
338
  case 0xc8:
339
  // ext 16
340
  value = dataView.getUint16(position);
341
  position += 2;
342
- return readExt(value)
343
  case 0xc9:
344
  // ext 32
345
  value = dataView.getUint32(position);
346
  position += 4;
347
- return readExt(value)
348
  case 0xca:
349
  value = dataView.getFloat32(position);
350
  if (currentUnpackr.useFloat32 > 2) {
351
  // this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
352
  let multiplier = mult10[((src[position] & 0x7f) << 1) | (src[position + 1] >> 7)];
353
  position += 4;
354
- return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier
355
  }
356
  position += 4;
357
- return value
358
  case 0xcb:
359
  value = dataView.getFloat64(position);
360
  position += 8;
361
- return value
362
  // uint handlers
363
  case 0xcc:
364
- return src[position++]
365
  case 0xcd:
366
  value = dataView.getUint16(position);
367
  position += 2;
368
- return value
369
  case 0xce:
370
  value = dataView.getUint32(position);
371
  position += 4;
372
- return value
373
  case 0xcf:
374
  if (currentUnpackr.int64AsType === 'number') {
375
  value = dataView.getUint32(position) * 0x100000000;
@@ -382,19 +381,19 @@
382
  } else
383
  value = dataView.getBigUint64(position);
384
  position += 8;
385
- return value
386
 
387
  // int handlers
388
  case 0xd0:
389
- return dataView.getInt8(position++)
390
  case 0xd1:
391
  value = dataView.getInt16(position);
392
  position += 2;
393
- return value
394
  case 0xd2:
395
  value = dataView.getInt32(position);
396
  position += 4;
397
- return value
398
  case 0xd3:
399
  if (currentUnpackr.int64AsType === 'number') {
400
  value = dataView.getInt32(position) * 0x100000000;
@@ -407,96 +406,96 @@
407
  } else
408
  value = dataView.getBigInt64(position);
409
  position += 8;
410
- return value
411
 
412
  case 0xd4:
413
  // fixext 1
414
  value = src[position++];
415
  if (value == 0x72) {
416
- return recordDefinition(src[position++] & 0x3f)
417
  } else {
418
  let extension = currentExtensions[value];
419
  if (extension) {
420
  if (extension.read) {
421
  position++; // skip filler byte
422
- return extension.read(read())
423
  } else if (extension.noBuffer) {
424
  position++; // skip filler byte
425
- return extension()
426
  } else
427
- return extension(src.subarray(position, ++position))
428
  } else
429
- throw new Error('Unknown extension ' + value)
430
  }
431
  case 0xd5:
432
  // fixext 2
433
  value = src[position];
434
  if (value == 0x72) {
435
  position++;
436
- return recordDefinition(src[position++] & 0x3f, src[position++])
437
  } else
438
- return readExt(2)
439
  case 0xd6:
440
  // fixext 4
441
- return readExt(4)
442
  case 0xd7:
443
  // fixext 8
444
- return readExt(8)
445
  case 0xd8:
446
  // fixext 16
447
- return readExt(16)
448
  case 0xd9:
449
  // str 8
450
  value = src[position++];
451
  if (srcStringEnd >= position) {
452
- return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
453
  }
454
- return readString8(value)
455
  case 0xda:
456
  // str 16
457
  value = dataView.getUint16(position);
458
  position += 2;
459
  if (srcStringEnd >= position) {
460
- return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
461
  }
462
- return readString16(value)
463
  case 0xdb:
464
  // str 32
465
  value = dataView.getUint32(position);
466
  position += 4;
467
  if (srcStringEnd >= position) {
468
- return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
469
  }
470
- return readString32(value)
471
  case 0xdc:
472
  // array 16
473
  value = dataView.getUint16(position);
474
  position += 2;
475
- return readArray(value)
476
  case 0xdd:
477
  // array 32
478
  value = dataView.getUint32(position);
479
  position += 4;
480
- return readArray(value)
481
  case 0xde:
482
  // map 16
483
  value = dataView.getUint16(position);
484
  position += 2;
485
- return readMap(value)
486
  case 0xdf:
487
  // map 32
488
  value = dataView.getUint32(position);
489
  position += 4;
490
- return readMap(value)
491
  default: // negative int
492
  if (token >= 0xe0)
493
- return token - 0x100
494
  if (token === undefined) {
495
  let error = new Error('Unexpected end of MessagePack data');
496
  error.incomplete = true;
497
- throw error
498
  }
499
- throw new Error('Unknown MessagePack token ' + token)
500
 
501
  }
502
  }
@@ -515,9 +514,10 @@
515
  inlineObjectReadThreshold = Infinity; // disable going forward
516
  return readObject(); // recursively try again
517
  }
 
518
  if (structure.highByte === 0)
519
  structure.read = createSecondByteReader(firstId, structure.read);
520
- return optimizedReadObject() // second byte is already read, if there is one so immediately read object
521
  }
522
  let object = {};
523
  for (let i = 0, l = structure.length; i < l; i++) {
@@ -528,38 +528,44 @@
528
  }
529
  if (currentUnpackr.freezeData)
530
  return Object.freeze(object);
531
- return object
532
  }
533
  readObject.count = 0;
 
 
 
 
 
 
534
  if (structure.highByte === 0) {
535
- return createSecondByteReader(firstId, readObject)
536
  }
537
- return readObject
538
  }
539
 
540
  const createSecondByteReader = (firstId, read0) => {
541
  return function() {
542
  let highByte = src[position++];
543
  if (highByte === 0)
544
- return read0()
545
  let id = firstId < 32 ? -(firstId + (highByte << 5)) : firstId + (highByte << 5);
546
  let structure = currentStructures[id] || loadStructures()[id];
547
  if (!structure) {
548
- throw new Error('Record id is not defined for ' + id)
549
  }
550
  if (!structure.read)
551
  structure.read = createStructureReader(structure, firstId);
552
- return structure.read()
553
- }
554
  };
555
 
556
  function loadStructures() {
557
  let loadedStructures = saveState(() => {
558
  // save the state in case getStructures modifies our buffer
559
  src = null;
560
- return currentUnpackr.getStructures()
561
  });
562
- return currentStructures = currentUnpackr._mergeStructures(loadedStructures, currentStructures)
563
  }
564
 
565
  var readFixedString = readStringJS;
@@ -579,7 +585,7 @@
579
  let string = strings[stringPosition++];
580
  if (string == null) {
581
  if (bundledStrings)
582
- return readStringJS(length)
583
  let byteOffset = src.byteOffset;
584
  let extraction = extractStrings(position - headerLength + byteOffset, srcEnd + byteOffset, src.buffer);
585
  if (typeof extraction == 'string') {
@@ -591,30 +597,30 @@
591
  srcStringEnd = 1; // even if a utf-8 string was decoded, must indicate we are in the midst of extracted strings and can't skip strings
592
  string = strings[0];
593
  if (string === undefined)
594
- throw new Error('Unexpected end of buffer')
595
  }
596
  }
597
  let srcStringLength = string.length;
598
  if (srcStringLength <= length) {
599
  position += length;
600
- return string
601
  }
602
  srcString = string;
603
  srcStringStart = position;
604
  srcStringEnd = position + srcStringLength;
605
  position += length;
606
- return string.slice(0, length) // we know we just want the beginning
607
- }
608
  }
609
  }
610
  function readStringJS(length) {
611
  let result;
612
  if (length < 16) {
613
  if (result = shortStringInJS(length))
614
- return result
615
  }
616
  if (length > 64 && decoder)
617
- return decoder.decode(src.subarray(position, position += length))
618
  const end = position + length;
619
  const units = [];
620
  result = '';
@@ -625,43 +631,49 @@
625
  units.push(byte1);
626
  } else if ((byte1 & 0xe0) === 0xc0) {
627
  // 2 bytes
628
- const byte2 = src[position++] & 0x3f;
629
- const codePoint = ((byte1 & 0x1f) << 6) | byte2;
630
- // Reject overlong encoding: 2-byte sequences must encode values >= 0x80
631
- if (codePoint < 0x80) {
632
- units.push(0xFFFD); // replacement character
633
  } else {
634
- units.push(codePoint);
 
635
  }
636
  } else if ((byte1 & 0xf0) === 0xe0) {
637
  // 3 bytes
638
- const byte2 = src[position++] & 0x3f;
639
- const byte3 = src[position++] & 0x3f;
640
- const codePoint = ((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3;
641
- // Reject overlong encoding: 3-byte sequences must encode values >= 0x800
642
- // Also reject surrogates (0xD800-0xDFFF)
643
- if (codePoint < 0x800 || (codePoint >= 0xD800 && codePoint <= 0xDFFF)) {
644
- units.push(0xFFFD); // replacement character
645
  } else {
646
- units.push(codePoint);
 
 
 
 
 
 
647
  }
648
  } else if ((byte1 & 0xf8) === 0xf0) {
649
  // 4 bytes
650
- const byte2 = src[position++] & 0x3f;
651
- const byte3 = src[position++] & 0x3f;
652
- const byte4 = src[position++] & 0x3f;
653
- let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4;
654
- // Reject overlong encoding: 4-byte sequences must encode values >= 0x10000
655
- // Also reject values > 0x10FFFF (maximum valid Unicode)
656
- if (unit < 0x10000 || unit > 0x10FFFF) {
657
- units.push(0xFFFD); // replacement character
658
- } else if (unit > 0xffff) {
659
- unit -= 0x10000;
660
- units.push(((unit >>> 10) & 0x3ff) | 0xd800);
661
- unit = 0xdc00 | (unit & 0x3ff);
662
- units.push(unit);
663
  } else {
664
- units.push(unit);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
665
  }
666
  } else {
667
  units.push(0xFFFD); // replacement character for invalid lead byte
@@ -677,7 +689,7 @@
677
  result += fromCharCode.apply(String, units);
678
  }
679
 
680
- return result
681
  }
682
  function readString(source, start, length) {
683
  let existingSrc = src;
@@ -696,8 +708,8 @@
696
  array[i] = read();
697
  }
698
  if (currentUnpackr.freezeData)
699
- return Object.freeze(array)
700
- return array
701
  }
702
 
703
  function readMap(length) {
@@ -709,13 +721,13 @@
709
  key = '__proto_';
710
  object[key] = read();
711
  }
712
- return object
713
  } else {
714
  let map = new Map();
715
  for (let i = 0; i < length; i++) {
716
  map.set(read(), read());
717
  }
718
- return map
719
  }
720
  }
721
 
@@ -727,40 +739,40 @@
727
  const byte = src[position++];
728
  if ((byte & 0x80) > 0) {
729
  position = start;
730
- return
731
  }
732
  bytes[i] = byte;
733
  }
734
- return fromCharCode.apply(String, bytes)
735
  }
736
  function shortStringInJS(length) {
737
  if (length < 4) {
738
  if (length < 2) {
739
  if (length === 0)
740
- return ''
741
  else {
742
  let a = src[position++];
743
  if ((a & 0x80) > 1) {
744
  position -= 1;
745
- return
746
  }
747
- return fromCharCode(a)
748
  }
749
  } else {
750
  let a = src[position++];
751
  let b = src[position++];
752
  if ((a & 0x80) > 0 || (b & 0x80) > 0) {
753
  position -= 2;
754
- return
755
  }
756
  if (length < 3)
757
- return fromCharCode(a, b)
758
  let c = src[position++];
759
  if ((c & 0x80) > 0) {
760
  position -= 3;
761
- return
762
  }
763
- return fromCharCode(a, b, c)
764
  }
765
  } else {
766
  let a = src[position++];
@@ -769,34 +781,34 @@
769
  let d = src[position++];
770
  if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
771
  position -= 4;
772
- return
773
  }
774
  if (length < 6) {
775
  if (length === 4)
776
- return fromCharCode(a, b, c, d)
777
  else {
778
  let e = src[position++];
779
  if ((e & 0x80) > 0) {
780
  position -= 5;
781
- return
782
  }
783
- return fromCharCode(a, b, c, d, e)
784
  }
785
  } else if (length < 8) {
786
  let e = src[position++];
787
  let f = src[position++];
788
  if ((e & 0x80) > 0 || (f & 0x80) > 0) {
789
  position -= 6;
790
- return
791
  }
792
  if (length < 7)
793
- return fromCharCode(a, b, c, d, e, f)
794
  let g = src[position++];
795
  if ((g & 0x80) > 0) {
796
  position -= 7;
797
- return
798
  }
799
- return fromCharCode(a, b, c, d, e, f, g)
800
  } else {
801
  let e = src[position++];
802
  let f = src[position++];
@@ -804,34 +816,34 @@
804
  let h = src[position++];
805
  if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
806
  position -= 8;
807
- return
808
  }
809
  if (length < 10) {
810
  if (length === 8)
811
- return fromCharCode(a, b, c, d, e, f, g, h)
812
  else {
813
  let i = src[position++];
814
  if ((i & 0x80) > 0) {
815
  position -= 9;
816
- return
817
  }
818
- return fromCharCode(a, b, c, d, e, f, g, h, i)
819
  }
820
  } else if (length < 12) {
821
  let i = src[position++];
822
  let j = src[position++];
823
  if ((i & 0x80) > 0 || (j & 0x80) > 0) {
824
  position -= 10;
825
- return
826
  }
827
  if (length < 11)
828
- return fromCharCode(a, b, c, d, e, f, g, h, i, j)
829
  let k = src[position++];
830
  if ((k & 0x80) > 0) {
831
  position -= 11;
832
- return
833
  }
834
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k)
835
  } else {
836
  let i = src[position++];
837
  let j = src[position++];
@@ -839,34 +851,34 @@
839
  let l = src[position++];
840
  if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
841
  position -= 12;
842
- return
843
  }
844
  if (length < 14) {
845
  if (length === 12)
846
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l)
847
  else {
848
  let m = src[position++];
849
  if ((m & 0x80) > 0) {
850
  position -= 13;
851
- return
852
  }
853
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m)
854
  }
855
  } else {
856
  let m = src[position++];
857
  let n = src[position++];
858
  if ((m & 0x80) > 0 || (n & 0x80) > 0) {
859
  position -= 14;
860
- return
861
  }
862
  if (length < 15)
863
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
864
  let o = src[position++];
865
  if ((o & 0x80) > 0) {
866
  position -= 15;
867
- return
868
  }
869
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
870
  }
871
  }
872
  }
@@ -884,22 +896,22 @@
884
  case 0xd9:
885
  // str 8
886
  length = src[position++];
887
- break
888
  case 0xda:
889
  // str 16
890
  length = dataView.getUint16(position);
891
  position += 2;
892
- break
893
  case 0xdb:
894
  // str 32
895
  length = dataView.getUint32(position);
896
  position += 4;
897
- break
898
  default:
899
- throw new Error('Expected string')
900
  }
901
  }
902
- return readStringJS(length)
903
  }
904
 
905
 
@@ -907,7 +919,7 @@
907
  return currentUnpackr.copyBuffers ?
908
  // specifically use the copying slice (not the node one)
909
  Uint8Array.prototype.slice.call(src, position, position += length) :
910
- src.subarray(position, position += length)
911
  }
912
  function readExt(length) {
913
  let type = src[position++];
@@ -920,10 +932,10 @@
920
  } finally {
921
  position = end;
922
  }
923
- })
924
  }
925
  else
926
- throw new Error('Unknown extension type ' + type)
927
  }
928
 
929
  var keyCache = new Array(4096);
@@ -933,12 +945,12 @@
933
  // fixstr, potentially use key cache
934
  length = length - 0xa0;
935
  if (srcStringEnd >= position) // if it has been extracted, must use it (and faster anyway)
936
- return srcString.slice(position - srcStringStart, (position += length) - srcStringStart)
937
  else if (!(srcStringEnd == 0 && srcEnd < 180))
938
- return readFixedString(length)
939
  } else { // not cacheable, go back and do a standard read
940
  position--;
941
- return asSafeString(read())
942
  }
943
  let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position) : length > 0 ? src[position] : 0)) & 0xfff;
944
  let entry = keyCache[key];
@@ -951,7 +963,7 @@
951
  chunk = dataView.getUint32(checkPosition);
952
  if (chunk != entry[i++]) {
953
  checkPosition = 0x70000000;
954
- break
955
  }
956
  checkPosition += 4;
957
  }
@@ -960,12 +972,12 @@
960
  chunk = src[checkPosition++];
961
  if (chunk != entry[i++]) {
962
  checkPosition = 0x70000000;
963
- break
964
  }
965
  }
966
  if (checkPosition === end) {
967
  position = checkPosition;
968
- return entry.string
969
  }
970
  end -= 3;
971
  checkPosition = position;
@@ -986,8 +998,8 @@
986
  // for small blocks, avoiding the overhead of the extract call is helpful
987
  let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
988
  if (string != null)
989
- return entry.string = string
990
- return entry.string = readFixedString(length)
991
  }
992
 
993
  function asSafeString(property) {
@@ -1018,7 +1030,12 @@
1018
  }
1019
  currentStructures[id] = structure;
1020
  structure.read = createStructureReader(structure, firstByte);
1021
- return structure.read()
 
 
 
 
 
1022
  };
1023
  currentExtensions[0] = () => {}; // notepack defines extension 0 to mean undefined, so use that as the default here
1024
  currentExtensions[0].noBuffer = true;
@@ -1040,17 +1057,17 @@
1040
  out <<= BigInt(64);
1041
  out |= view.getBigUint64(i);
1042
  }
1043
- return out
1044
  }
1045
  // if (length === 8) return view.getBigUint64(start)
1046
  let middle = start + (length >> 4 << 3);
1047
  let left = decode(start, middle);
1048
  let right = decode(middle, end);
1049
- return (left << BigInt((end - middle) * 8)) | right
1050
  };
1051
  head = (head << BigInt((view.byteLength - headLength) * 8)) | decode(headLength, view.byteLength);
1052
  }
1053
- return head
1054
  };
1055
 
1056
  let errors = {
@@ -1061,14 +1078,14 @@
1061
  if (!errors[data[0]]) {
1062
  let error = Error(data[1], { cause: data[2] });
1063
  error.name = data[0];
1064
- return error
1065
  }
1066
- return errors[data[0]](data[1], { cause: data[2] })
1067
  };
1068
 
1069
  currentExtensions[0x69] = (data) => {
1070
  // id extension (for structured clones)
1071
- if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled')
1072
  let id = dataView.getUint32(position - 4);
1073
  if (!referenceMap)
1074
  referenceMap = new Map();
@@ -1089,7 +1106,7 @@
1089
  let targetProperties = read(); // read the next value as the target object to id
1090
  if (!refEntry.used) {
1091
  // no cycle, can just use the returned read object
1092
- return refEntry.target = targetProperties // replace the placeholder with the real one
1093
  } else {
1094
  // there is a cycle, so we have to assign properties to original target
1095
  Object.assign(target, targetProperties);
@@ -1100,16 +1117,16 @@
1100
  for (let [k, v] of targetProperties.entries()) target.set(k, v);
1101
  if (target instanceof Set)
1102
  for (let i of Array.from(targetProperties)) target.add(i);
1103
- return target
1104
  };
1105
 
1106
  currentExtensions[0x70] = (data) => {
1107
  // pointer extension (for structured clones)
1108
- if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled')
1109
  let id = dataView.getUint32(position - 4);
1110
  let refEntry = referenceMap.get(id);
1111
  refEntry.used = true;
1112
- return refEntry.target
1113
  };
1114
 
1115
  currentExtensions[0x73] = () => new Set(read());
@@ -1124,15 +1141,15 @@
1124
 
1125
  let typedArrayName = typedArrays[typeCode];
1126
  if (!typedArrayName) {
1127
- if (typeCode === 16) return buffer
1128
- if (typeCode === 17) return new DataView(buffer)
1129
- throw new Error('Could not find typed array for code ' + typeCode)
1130
  }
1131
- return new glbl[typedArrayName](buffer)
1132
  };
1133
  currentExtensions[0x78] = () => {
1134
  let data = read();
1135
- return new RegExp(data[0], data[1])
1136
  };
1137
  const TEMP_BUNDLE = [];
1138
  currentExtensions[0x62] = (data) => {
@@ -1145,30 +1162,30 @@
1145
  bundledStrings.position1 = 0;
1146
  bundledStrings.postBundlePosition = position;
1147
  position = dataPosition;
1148
- return read()
1149
  };
1150
 
1151
  currentExtensions[0xff] = (data) => {
1152
  // 32-bit date extension
1153
  if (data.length == 4)
1154
- return new Date((data[0] * 0x1000000 + (data[1] << 16) + (data[2] << 8) + data[3]) * 1000)
1155
  else if (data.length == 8)
1156
  return new Date(
1157
  ((data[0] << 22) + (data[1] << 14) + (data[2] << 6) + (data[3] >> 2)) / 1000000 +
1158
- ((data[3] & 0x3) * 0x100000000 + data[4] * 0x1000000 + (data[5] << 16) + (data[6] << 8) + data[7]) * 1000)
1159
  else if (data.length == 12)
1160
  return new Date(
1161
  ((data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]) / 1000000 +
1162
- (((data[4] & 0x80) ? -0x1000000000000 : 0) + data[6] * 0x10000000000 + data[7] * 0x100000000 + data[8] * 0x1000000 + (data[9] << 16) + (data[10] << 8) + data[11]) * 1000)
1163
  else
1164
- return new Date('invalid')
1165
  };
1166
  // registration of bulk record definition?
1167
  // currentExtensions[0x52] = () =>
1168
 
1169
  function saveState(callback) {
1170
- if (onSaveState)
1171
- onSaveState();
1172
  let savedSrcEnd = srcEnd;
1173
  let savedPosition = position;
1174
  let savedStringPosition = stringPosition;
@@ -1201,7 +1218,7 @@
1201
  currentStructures.splice(0, currentStructures.length, ...savedStructuresContents);
1202
  currentUnpackr = savedPackr;
1203
  dataView = new DataView(src.buffer, src.byteOffset, src.byteLength);
1204
- return value
1205
  }
1206
  function clearSource() {
1207
  src = null;
@@ -1236,13 +1253,12 @@
1236
  function roundFloat32(float32Number) {
1237
  f32Array[0] = float32Number;
1238
  let multiplier = mult10[((u8Array[3] & 0x7f) << 1) | (u8Array[2] >> 7)];
1239
- return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier
1240
- }
1241
- function setReadStruct(updatedReadStruct, loadedStructs, saveState) {
1242
- readStruct = updatedReadStruct;
1243
- onLoadedStructures = loadedStructs;
1244
- onSaveState = saveState;
1245
  }
 
 
 
 
1246
 
1247
  exports.C1 = C1;
1248
  exports.C1Type = C1Type;
@@ -1260,7 +1276,6 @@
1260
  exports.readString = readString;
1261
  exports.roundFloat32 = roundFloat32;
1262
  exports.setExtractor = setExtractor;
1263
- exports.setReadStruct = setReadStruct;
1264
  exports.typedArrays = typedArrays;
1265
  exports.unpack = unpack;
1266
  exports.unpackMultiple = unpackMultiple;
 
32
  C1.name = 'MessagePack 0xC1';
33
  var sequentialMode = false;
34
  var inlineObjectReadThreshold = 2;
 
35
  var BlockedFunction; // we use search and replace to change the next call to BlockedFunction to avoid CSP issues for
36
 
37
  class Unpackr {
 
64
  // re-entrant execution, save the state and restore it after we do this unpack
65
  return saveState(() => {
66
  clearSource();
67
+ return this ? this.unpack(source, options) : Unpackr.prototype.unpack.call(defaultOptions, source, options);
68
+ });
69
  }
70
  if (!source.buffer && source.constructor === ArrayBuffer)
71
  source = typeof Buffer !== 'undefined' ? Buffer.from(source) : new Uint8Array(source);
 
91
  // if it doesn't have a buffer, maybe it is the wrong type of object
92
  src = null;
93
  if (source instanceof Uint8Array)
94
+ throw error;
95
+ throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source));
96
  }
97
  if (this instanceof Unpackr) {
98
  currentUnpackr = this;
99
  if (this.structures) {
100
  currentStructures = this.structures;
101
+ return checkedRead(options);
102
  } else if (!currentStructures || currentStructures.length > 0) {
103
  currentStructures = [];
104
  }
 
107
  if (!currentStructures || currentStructures.length > 0)
108
  currentStructures = [];
109
  }
110
+ return checkedRead(options);
111
  }
112
  unpackMultiple(source, forEach) {
113
  let values, lastPosition = 0;
 
120
  while(position < size) {
121
  lastPosition = position;
122
  if (forEach(checkedRead(), lastPosition, position) === false) {
123
+ return;
124
  }
125
  }
126
  }
 
130
  lastPosition = position;
131
  values.push(checkedRead());
132
  }
133
+ return values;
134
  }
135
  } catch(error) {
136
  error.lastPosition = lastPosition;
137
  error.values = values;
138
+ throw error;
139
  } finally {
140
  sequentialMode = false;
141
  clearSource();
142
  }
143
  }
144
  _mergeStructures(loadedStructures, existingStructures) {
145
+ if (this._onLoadedStructures)
146
+ loadedStructures = this._onLoadedStructures(loadedStructures);
147
  loadedStructures = loadedStructures || [];
148
  if (Object.isFrozen(loadedStructures))
149
  loadedStructures = loadedStructures.map(structure => structure.slice(0));
 
167
  }
168
  }
169
  }
170
+ return this.structures = loadedStructures;
171
  }
172
  decode(source, options) {
173
+ return this.unpack(source, options);
174
  }
175
  }
176
  function getPosition() {
177
+ return position;
178
  }
179
  function checkedRead(options) {
180
  try {
 
184
  currentStructures.length = sharedLength;
185
  }
186
  let result;
187
+ if (currentUnpackr._readStruct && src[position] < 0x40 && src[position] >= 0x20) {
188
+ result = currentUnpackr._readStruct(src, position, srcEnd);
189
  src = null; // dispose of this so that recursive unpack calls don't save state
190
  if (!(options && options.lazy) && result)
191
  result = result.toJSON();
 
211
  referenceMap = null;
212
  } else if (position > srcEnd) {
213
  // over read
214
+ throw new Error('Unexpected end of MessagePack data');
215
  } else if (!sequentialMode) {
216
  let jsonView;
217
  try {
 
219
  } catch(error) {
220
  jsonView = '(JSON view not available ' + error + ')';
221
  }
222
+ throw new Error('Data read, but end of buffer not reached ' + jsonView);
223
  }
224
  // else more to read, but we are reading sequentially, so don't clear source yet
225
+ return result;
226
  } catch(error) {
227
  if (currentStructures && currentStructures.restoreStructures)
228
  restoreStructures();
 
230
  if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position > srcEnd) {
231
  error.incomplete = true;
232
  }
233
+ throw error;
234
  }
235
  }
236
 
 
246
  if (token < 0xa0) {
247
  if (token < 0x80) {
248
  if (token < 0x40)
249
+ return token;
250
  else {
251
  let structure = currentStructures[token & 0x3f] ||
252
  currentUnpackr.getStructures && loadStructures()[token & 0x3f];
 
254
  if (!structure.read) {
255
  structure.read = createStructureReader(structure, token & 0x3f);
256
  }
257
+ return structure.read();
258
  } else
259
+ return token;
260
  }
261
  } else if (token < 0x90) {
262
  // map
 
269
  key = '__proto_';
270
  object[key] = read();
271
  }
272
+ return object;
273
  } else {
274
  let map = new Map();
275
  for (let i = 0; i < token; i++) {
276
  map.set(read(), read());
277
  }
278
+ return map;
279
  }
280
  } else {
281
  token -= 0x90;
 
284
  array[i] = read();
285
  }
286
  if (currentUnpackr.freezeData)
287
+ return Object.freeze(array);
288
+ return array;
289
  }
290
  } else if (token < 0xc0) {
291
  // fixstr
292
  let length = token - 0xa0;
293
  if (srcStringEnd >= position) {
294
+ return srcString.slice(position - srcStringStart, (position += length) - srcStringStart);
295
  }
296
  if (srcStringEnd == 0 && srcEnd < 140) {
297
  // for small blocks, avoiding the overhead of the extract call is helpful
298
  let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
299
  if (string != null)
300
+ return string;
301
  }
302
+ return readFixedString(length);
303
  } else {
304
  let value;
305
  switch (token) {
306
+ case 0xc0: return null;
307
  case 0xc1:
308
  if (bundledStrings) {
309
  value = read(); // followed by the length of the string in characters (not bytes!)
310
  if (value > 0)
311
+ return bundledStrings[1].slice(bundledStrings.position1, bundledStrings.position1 += value);
312
  else
313
+ return bundledStrings[0].slice(bundledStrings.position0, bundledStrings.position0 -= value);
314
  }
315
  return C1; // "never-used", return special object to denote that
316
+ case 0xc2: return false;
317
+ case 0xc3: return true;
318
  case 0xc4:
319
  // bin 8
320
  value = src[position++];
321
  if (value === undefined)
322
+ throw new Error('Unexpected end of buffer');
323
+ return readBin(value);
324
  case 0xc5:
325
  // bin 16
326
  value = dataView.getUint16(position);
327
  position += 2;
328
+ return readBin(value);
329
  case 0xc6:
330
  // bin 32
331
  value = dataView.getUint32(position);
332
  position += 4;
333
+ return readBin(value);
334
  case 0xc7:
335
  // ext 8
336
+ return readExt(src[position++]);
337
  case 0xc8:
338
  // ext 16
339
  value = dataView.getUint16(position);
340
  position += 2;
341
+ return readExt(value);
342
  case 0xc9:
343
  // ext 32
344
  value = dataView.getUint32(position);
345
  position += 4;
346
+ return readExt(value);
347
  case 0xca:
348
  value = dataView.getFloat32(position);
349
  if (currentUnpackr.useFloat32 > 2) {
350
  // this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
351
  let multiplier = mult10[((src[position] & 0x7f) << 1) | (src[position + 1] >> 7)];
352
  position += 4;
353
+ return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier;
354
  }
355
  position += 4;
356
+ return value;
357
  case 0xcb:
358
  value = dataView.getFloat64(position);
359
  position += 8;
360
+ return value;
361
  // uint handlers
362
  case 0xcc:
363
+ return src[position++];
364
  case 0xcd:
365
  value = dataView.getUint16(position);
366
  position += 2;
367
+ return value;
368
  case 0xce:
369
  value = dataView.getUint32(position);
370
  position += 4;
371
+ return value;
372
  case 0xcf:
373
  if (currentUnpackr.int64AsType === 'number') {
374
  value = dataView.getUint32(position) * 0x100000000;
 
381
  } else
382
  value = dataView.getBigUint64(position);
383
  position += 8;
384
+ return value;
385
 
386
  // int handlers
387
  case 0xd0:
388
+ return dataView.getInt8(position++);
389
  case 0xd1:
390
  value = dataView.getInt16(position);
391
  position += 2;
392
+ return value;
393
  case 0xd2:
394
  value = dataView.getInt32(position);
395
  position += 4;
396
+ return value;
397
  case 0xd3:
398
  if (currentUnpackr.int64AsType === 'number') {
399
  value = dataView.getInt32(position) * 0x100000000;
 
406
  } else
407
  value = dataView.getBigInt64(position);
408
  position += 8;
409
+ return value;
410
 
411
  case 0xd4:
412
  // fixext 1
413
  value = src[position++];
414
  if (value == 0x72) {
415
+ return recordDefinition(src[position++] & 0x3f);
416
  } else {
417
  let extension = currentExtensions[value];
418
  if (extension) {
419
  if (extension.read) {
420
  position++; // skip filler byte
421
+ return extension.read(read());
422
  } else if (extension.noBuffer) {
423
  position++; // skip filler byte
424
+ return extension();
425
  } else
426
+ return extension(src.subarray(position, ++position));
427
  } else
428
+ throw new Error('Unknown extension ' + value);
429
  }
430
  case 0xd5:
431
  // fixext 2
432
  value = src[position];
433
  if (value == 0x72) {
434
  position++;
435
+ return recordDefinition(src[position++] & 0x3f, src[position++]);
436
  } else
437
+ return readExt(2);
438
  case 0xd6:
439
  // fixext 4
440
+ return readExt(4);
441
  case 0xd7:
442
  // fixext 8
443
+ return readExt(8);
444
  case 0xd8:
445
  // fixext 16
446
+ return readExt(16);
447
  case 0xd9:
448
  // str 8
449
  value = src[position++];
450
  if (srcStringEnd >= position) {
451
+ return srcString.slice(position - srcStringStart, (position += value) - srcStringStart);
452
  }
453
+ return readString8(value);
454
  case 0xda:
455
  // str 16
456
  value = dataView.getUint16(position);
457
  position += 2;
458
  if (srcStringEnd >= position) {
459
+ return srcString.slice(position - srcStringStart, (position += value) - srcStringStart);
460
  }
461
+ return readString16(value);
462
  case 0xdb:
463
  // str 32
464
  value = dataView.getUint32(position);
465
  position += 4;
466
  if (srcStringEnd >= position) {
467
+ return srcString.slice(position - srcStringStart, (position += value) - srcStringStart);
468
  }
469
+ return readString32(value);
470
  case 0xdc:
471
  // array 16
472
  value = dataView.getUint16(position);
473
  position += 2;
474
+ return readArray(value);
475
  case 0xdd:
476
  // array 32
477
  value = dataView.getUint32(position);
478
  position += 4;
479
+ return readArray(value);
480
  case 0xde:
481
  // map 16
482
  value = dataView.getUint16(position);
483
  position += 2;
484
+ return readMap(value);
485
  case 0xdf:
486
  // map 32
487
  value = dataView.getUint32(position);
488
  position += 4;
489
+ return readMap(value);
490
  default: // negative int
491
  if (token >= 0xe0)
492
+ return token - 0x100;
493
  if (token === undefined) {
494
  let error = new Error('Unexpected end of MessagePack data');
495
  error.incomplete = true;
496
+ throw error;
497
  }
498
+ throw new Error('Unknown MessagePack token ' + token);
499
 
500
  }
501
  }
 
514
  inlineObjectReadThreshold = Infinity; // disable going forward
515
  return readObject(); // recursively try again
516
  }
517
+ structure.read0 = optimizedReadObject; // keep the un-wrapped body reader in sync
518
  if (structure.highByte === 0)
519
  structure.read = createSecondByteReader(firstId, structure.read);
520
+ return optimizedReadObject(); // second byte is already read, if there is one so immediately read object
521
  }
522
  let object = {};
523
  for (let i = 0, l = structure.length; i < l; i++) {
 
528
  }
529
  if (currentUnpackr.freezeData)
530
  return Object.freeze(object);
531
+ return object;
532
  }
533
  readObject.count = 0;
534
+ // read0 is the un-wrapped body reader: it reads the record's values directly without
535
+ // consuming a leading high byte. recordDefinition uses it for the immediate read that follows
536
+ // a record definition (the high byte, if present, was already consumed). For highByte === 0
537
+ // structures the public reader is a second-byte reader (used by later references), but the
538
+ // definition read itself must not consume that byte.
539
+ structure.read0 = readObject;
540
  if (structure.highByte === 0) {
541
+ return createSecondByteReader(firstId, readObject);
542
  }
543
+ return readObject;
544
  }
545
 
546
  const createSecondByteReader = (firstId, read0) => {
547
  return function() {
548
  let highByte = src[position++];
549
  if (highByte === 0)
550
+ return read0();
551
  let id = firstId < 32 ? -(firstId + (highByte << 5)) : firstId + (highByte << 5);
552
  let structure = currentStructures[id] || loadStructures()[id];
553
  if (!structure) {
554
+ throw new Error('Record id is not defined for ' + id);
555
  }
556
  if (!structure.read)
557
  structure.read = createStructureReader(structure, firstId);
558
+ return structure.read();
559
+ };
560
  };
561
 
562
  function loadStructures() {
563
  let loadedStructures = saveState(() => {
564
  // save the state in case getStructures modifies our buffer
565
  src = null;
566
+ return currentUnpackr.getStructures();
567
  });
568
+ return currentStructures = currentUnpackr._mergeStructures(loadedStructures, currentStructures);
569
  }
570
 
571
  var readFixedString = readStringJS;
 
585
  let string = strings[stringPosition++];
586
  if (string == null) {
587
  if (bundledStrings)
588
+ return readStringJS(length);
589
  let byteOffset = src.byteOffset;
590
  let extraction = extractStrings(position - headerLength + byteOffset, srcEnd + byteOffset, src.buffer);
591
  if (typeof extraction == 'string') {
 
597
  srcStringEnd = 1; // even if a utf-8 string was decoded, must indicate we are in the midst of extracted strings and can't skip strings
598
  string = strings[0];
599
  if (string === undefined)
600
+ throw new Error('Unexpected end of buffer');
601
  }
602
  }
603
  let srcStringLength = string.length;
604
  if (srcStringLength <= length) {
605
  position += length;
606
+ return string;
607
  }
608
  srcString = string;
609
  srcStringStart = position;
610
  srcStringEnd = position + srcStringLength;
611
  position += length;
612
+ return string.slice(0, length); // we know we just want the beginning
613
+ };
614
  }
615
  }
616
  function readStringJS(length) {
617
  let result;
618
  if (length < 16) {
619
  if (result = shortStringInJS(length))
620
+ return result;
621
  }
622
  if (length > 64 && decoder)
623
+ return decoder.decode(src.subarray(position, position += length));
624
  const end = position + length;
625
  const units = [];
626
  result = '';
 
631
  units.push(byte1);
632
  } else if ((byte1 & 0xe0) === 0xc0) {
633
  // 2 bytes
634
+ if (byte1 < 0xc2 || position >= end || (src[position] & 0xc0) !== 0x80) {
635
+ units.push(0xFFFD);
 
 
 
636
  } else {
637
+ const byte2 = src[position++] & 0x3f;
638
+ units.push(((byte1 & 0x1f) << 6) | byte2);
639
  }
640
  } else if ((byte1 & 0xf0) === 0xe0) {
641
  // 3 bytes
642
+ const byte2 = position < end ? src[position] : 0;
643
+ if (position >= end || (byte2 & 0xc0) !== 0x80 ||
644
+ (byte1 === 0xe0 && byte2 < 0xa0) || (byte1 === 0xed && byte2 >= 0xa0)) {
645
+ units.push(0xFFFD);
 
 
 
646
  } else {
647
+ position++;
648
+ if (position >= end || (src[position] & 0xc0) !== 0x80) {
649
+ units.push(0xFFFD);
650
+ } else {
651
+ const byte3 = src[position++] & 0x3f;
652
+ units.push(((byte1 & 0x1f) << 12) | ((byte2 & 0x3f) << 6) | byte3);
653
+ }
654
  }
655
  } else if ((byte1 & 0xf8) === 0xf0) {
656
  // 4 bytes
657
+ const byte2 = position < end ? src[position] : 0;
658
+ if (byte1 > 0xf4 || position >= end || (byte2 & 0xc0) !== 0x80 ||
659
+ (byte1 === 0xf0 && byte2 < 0x90) || (byte1 === 0xf4 && byte2 >= 0x90)) {
660
+ units.push(0xFFFD);
 
 
 
 
 
 
 
 
 
661
  } else {
662
+ position++;
663
+ if (position >= end || (src[position] & 0xc0) !== 0x80) {
664
+ units.push(0xFFFD);
665
+ } else {
666
+ const byte3 = src[position++] & 0x3f;
667
+ if (position >= end || (src[position] & 0xc0) !== 0x80) {
668
+ units.push(0xFFFD);
669
+ } else {
670
+ const byte4 = src[position++] & 0x3f;
671
+ let unit = ((byte1 & 0x07) << 0x12) | ((byte2 & 0x3f) << 0x0c) | (byte3 << 0x06) | byte4;
672
+ unit -= 0x10000;
673
+ units.push(((unit >>> 10) & 0x3ff) | 0xd800);
674
+ units.push(0xdc00 | (unit & 0x3ff));
675
+ }
676
+ }
677
  }
678
  } else {
679
  units.push(0xFFFD); // replacement character for invalid lead byte
 
689
  result += fromCharCode.apply(String, units);
690
  }
691
 
692
+ return result;
693
  }
694
  function readString(source, start, length) {
695
  let existingSrc = src;
 
708
  array[i] = read();
709
  }
710
  if (currentUnpackr.freezeData)
711
+ return Object.freeze(array);
712
+ return array;
713
  }
714
 
715
  function readMap(length) {
 
721
  key = '__proto_';
722
  object[key] = read();
723
  }
724
+ return object;
725
  } else {
726
  let map = new Map();
727
  for (let i = 0; i < length; i++) {
728
  map.set(read(), read());
729
  }
730
+ return map;
731
  }
732
  }
733
 
 
739
  const byte = src[position++];
740
  if ((byte & 0x80) > 0) {
741
  position = start;
742
+ return;
743
  }
744
  bytes[i] = byte;
745
  }
746
+ return fromCharCode.apply(String, bytes);
747
  }
748
  function shortStringInJS(length) {
749
  if (length < 4) {
750
  if (length < 2) {
751
  if (length === 0)
752
+ return '';
753
  else {
754
  let a = src[position++];
755
  if ((a & 0x80) > 1) {
756
  position -= 1;
757
+ return;
758
  }
759
+ return fromCharCode(a);
760
  }
761
  } else {
762
  let a = src[position++];
763
  let b = src[position++];
764
  if ((a & 0x80) > 0 || (b & 0x80) > 0) {
765
  position -= 2;
766
+ return;
767
  }
768
  if (length < 3)
769
+ return fromCharCode(a, b);
770
  let c = src[position++];
771
  if ((c & 0x80) > 0) {
772
  position -= 3;
773
+ return;
774
  }
775
+ return fromCharCode(a, b, c);
776
  }
777
  } else {
778
  let a = src[position++];
 
781
  let d = src[position++];
782
  if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
783
  position -= 4;
784
+ return;
785
  }
786
  if (length < 6) {
787
  if (length === 4)
788
+ return fromCharCode(a, b, c, d);
789
  else {
790
  let e = src[position++];
791
  if ((e & 0x80) > 0) {
792
  position -= 5;
793
+ return;
794
  }
795
+ return fromCharCode(a, b, c, d, e);
796
  }
797
  } else if (length < 8) {
798
  let e = src[position++];
799
  let f = src[position++];
800
  if ((e & 0x80) > 0 || (f & 0x80) > 0) {
801
  position -= 6;
802
+ return;
803
  }
804
  if (length < 7)
805
+ return fromCharCode(a, b, c, d, e, f);
806
  let g = src[position++];
807
  if ((g & 0x80) > 0) {
808
  position -= 7;
809
+ return;
810
  }
811
+ return fromCharCode(a, b, c, d, e, f, g);
812
  } else {
813
  let e = src[position++];
814
  let f = src[position++];
 
816
  let h = src[position++];
817
  if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
818
  position -= 8;
819
+ return;
820
  }
821
  if (length < 10) {
822
  if (length === 8)
823
+ return fromCharCode(a, b, c, d, e, f, g, h);
824
  else {
825
  let i = src[position++];
826
  if ((i & 0x80) > 0) {
827
  position -= 9;
828
+ return;
829
  }
830
+ return fromCharCode(a, b, c, d, e, f, g, h, i);
831
  }
832
  } else if (length < 12) {
833
  let i = src[position++];
834
  let j = src[position++];
835
  if ((i & 0x80) > 0 || (j & 0x80) > 0) {
836
  position -= 10;
837
+ return;
838
  }
839
  if (length < 11)
840
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j);
841
  let k = src[position++];
842
  if ((k & 0x80) > 0) {
843
  position -= 11;
844
+ return;
845
  }
846
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k);
847
  } else {
848
  let i = src[position++];
849
  let j = src[position++];
 
851
  let l = src[position++];
852
  if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
853
  position -= 12;
854
+ return;
855
  }
856
  if (length < 14) {
857
  if (length === 12)
858
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l);
859
  else {
860
  let m = src[position++];
861
  if ((m & 0x80) > 0) {
862
  position -= 13;
863
+ return;
864
  }
865
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m);
866
  }
867
  } else {
868
  let m = src[position++];
869
  let n = src[position++];
870
  if ((m & 0x80) > 0 || (n & 0x80) > 0) {
871
  position -= 14;
872
+ return;
873
  }
874
  if (length < 15)
875
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n);
876
  let o = src[position++];
877
  if ((o & 0x80) > 0) {
878
  position -= 15;
879
+ return;
880
  }
881
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
882
  }
883
  }
884
  }
 
896
  case 0xd9:
897
  // str 8
898
  length = src[position++];
899
+ break;
900
  case 0xda:
901
  // str 16
902
  length = dataView.getUint16(position);
903
  position += 2;
904
+ break;
905
  case 0xdb:
906
  // str 32
907
  length = dataView.getUint32(position);
908
  position += 4;
909
+ break;
910
  default:
911
+ throw new Error('Expected string');
912
  }
913
  }
914
+ return readStringJS(length);
915
  }
916
 
917
 
 
919
  return currentUnpackr.copyBuffers ?
920
  // specifically use the copying slice (not the node one)
921
  Uint8Array.prototype.slice.call(src, position, position += length) :
922
+ src.subarray(position, position += length);
923
  }
924
  function readExt(length) {
925
  let type = src[position++];
 
932
  } finally {
933
  position = end;
934
  }
935
+ });
936
  }
937
  else
938
+ throw new Error('Unknown extension type ' + type);
939
  }
940
 
941
  var keyCache = new Array(4096);
 
945
  // fixstr, potentially use key cache
946
  length = length - 0xa0;
947
  if (srcStringEnd >= position) // if it has been extracted, must use it (and faster anyway)
948
+ return srcString.slice(position - srcStringStart, (position += length) - srcStringStart);
949
  else if (!(srcStringEnd == 0 && srcEnd < 180))
950
+ return readFixedString(length);
951
  } else { // not cacheable, go back and do a standard read
952
  position--;
953
+ return asSafeString(read());
954
  }
955
  let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position) : length > 0 ? src[position] : 0)) & 0xfff;
956
  let entry = keyCache[key];
 
963
  chunk = dataView.getUint32(checkPosition);
964
  if (chunk != entry[i++]) {
965
  checkPosition = 0x70000000;
966
+ break;
967
  }
968
  checkPosition += 4;
969
  }
 
972
  chunk = src[checkPosition++];
973
  if (chunk != entry[i++]) {
974
  checkPosition = 0x70000000;
975
+ break;
976
  }
977
  }
978
  if (checkPosition === end) {
979
  position = checkPosition;
980
+ return entry.string;
981
  }
982
  end -= 3;
983
  checkPosition = position;
 
998
  // for small blocks, avoiding the overhead of the extract call is helpful
999
  let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
1000
  if (string != null)
1001
+ return entry.string = string;
1002
+ return entry.string = readFixedString(length);
1003
  }
1004
 
1005
  function asSafeString(property) {
 
1030
  }
1031
  currentStructures[id] = structure;
1032
  structure.read = createStructureReader(structure, firstByte);
1033
+ // The high byte (if any) was already consumed as the `highByte` argument above, so read the
1034
+ // record body directly. Going through structure.read (a second-byte reader when highByte === 0)
1035
+ // would misinterpret the first value byte as a high byte — corrupting two-byte own-record
1036
+ // definitions (0xd5 0x72 ...). createStructureReader stashes the un-wrapped body reader on
1037
+ // structure.read0 precisely for this immediate post-definition read.
1038
+ return (structure.read0 || structure.read)();
1039
  };
1040
  currentExtensions[0] = () => {}; // notepack defines extension 0 to mean undefined, so use that as the default here
1041
  currentExtensions[0].noBuffer = true;
 
1057
  out <<= BigInt(64);
1058
  out |= view.getBigUint64(i);
1059
  }
1060
+ return out;
1061
  }
1062
  // if (length === 8) return view.getBigUint64(start)
1063
  let middle = start + (length >> 4 << 3);
1064
  let left = decode(start, middle);
1065
  let right = decode(middle, end);
1066
+ return (left << BigInt((end - middle) * 8)) | right;
1067
  };
1068
  head = (head << BigInt((view.byteLength - headLength) * 8)) | decode(headLength, view.byteLength);
1069
  }
1070
+ return head;
1071
  };
1072
 
1073
  let errors = {
 
1078
  if (!errors[data[0]]) {
1079
  let error = Error(data[1], { cause: data[2] });
1080
  error.name = data[0];
1081
+ return error;
1082
  }
1083
+ return errors[data[0]](data[1], { cause: data[2] });
1084
  };
1085
 
1086
  currentExtensions[0x69] = (data) => {
1087
  // id extension (for structured clones)
1088
+ if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled');
1089
  let id = dataView.getUint32(position - 4);
1090
  if (!referenceMap)
1091
  referenceMap = new Map();
 
1106
  let targetProperties = read(); // read the next value as the target object to id
1107
  if (!refEntry.used) {
1108
  // no cycle, can just use the returned read object
1109
+ return refEntry.target = targetProperties; // replace the placeholder with the real one
1110
  } else {
1111
  // there is a cycle, so we have to assign properties to original target
1112
  Object.assign(target, targetProperties);
 
1117
  for (let [k, v] of targetProperties.entries()) target.set(k, v);
1118
  if (target instanceof Set)
1119
  for (let i of Array.from(targetProperties)) target.add(i);
1120
+ return target;
1121
  };
1122
 
1123
  currentExtensions[0x70] = (data) => {
1124
  // pointer extension (for structured clones)
1125
+ if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled');
1126
  let id = dataView.getUint32(position - 4);
1127
  let refEntry = referenceMap.get(id);
1128
  refEntry.used = true;
1129
+ return refEntry.target;
1130
  };
1131
 
1132
  currentExtensions[0x73] = () => new Set(read());
 
1141
 
1142
  let typedArrayName = typedArrays[typeCode];
1143
  if (!typedArrayName) {
1144
+ if (typeCode === 16) return buffer;
1145
+ if (typeCode === 17) return new DataView(buffer);
1146
+ throw new Error('Could not find typed array for code ' + typeCode);
1147
  }
1148
+ return new glbl[typedArrayName](buffer);
1149
  };
1150
  currentExtensions[0x78] = () => {
1151
  let data = read();
1152
+ return new RegExp(data[0], data[1]);
1153
  };
1154
  const TEMP_BUNDLE = [];
1155
  currentExtensions[0x62] = (data) => {
 
1162
  bundledStrings.position1 = 0;
1163
  bundledStrings.postBundlePosition = position;
1164
  position = dataPosition;
1165
+ return read();
1166
  };
1167
 
1168
  currentExtensions[0xff] = (data) => {
1169
  // 32-bit date extension
1170
  if (data.length == 4)
1171
+ return new Date((data[0] * 0x1000000 + (data[1] << 16) + (data[2] << 8) + data[3]) * 1000);
1172
  else if (data.length == 8)
1173
  return new Date(
1174
  ((data[0] << 22) + (data[1] << 14) + (data[2] << 6) + (data[3] >> 2)) / 1000000 +
1175
+ ((data[3] & 0x3) * 0x100000000 + data[4] * 0x1000000 + (data[5] << 16) + (data[6] << 8) + data[7]) * 1000);
1176
  else if (data.length == 12)
1177
  return new Date(
1178
  ((data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]) / 1000000 +
1179
+ (((data[4] & 0x80) ? -0x1000000000000 : 0) + data[6] * 0x10000000000 + data[7] * 0x100000000 + data[8] * 0x1000000 + (data[9] << 16) + (data[10] << 8) + data[11]) * 1000);
1180
  else
1181
+ return new Date('invalid');
1182
  };
1183
  // registration of bulk record definition?
1184
  // currentExtensions[0x52] = () =>
1185
 
1186
  function saveState(callback) {
1187
+ if (currentUnpackr && currentUnpackr._onSaveState)
1188
+ currentUnpackr._onSaveState();
1189
  let savedSrcEnd = srcEnd;
1190
  let savedPosition = position;
1191
  let savedStringPosition = stringPosition;
 
1218
  currentStructures.splice(0, currentStructures.length, ...savedStructuresContents);
1219
  currentUnpackr = savedPackr;
1220
  dataView = new DataView(src.buffer, src.byteOffset, src.byteLength);
1221
+ return value;
1222
  }
1223
  function clearSource() {
1224
  src = null;
 
1253
  function roundFloat32(float32Number) {
1254
  f32Array[0] = float32Number;
1255
  let multiplier = mult10[((u8Array[3] & 0x7f) << 1) | (u8Array[2] >> 7)];
1256
+ return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier;
 
 
 
 
 
1257
  }
1258
+ // Marker for downstream libraries (e.g. structon) to detect per-instance
1259
+ // struct-decoding hooks (this._readStruct, this._onLoadedStructures,
1260
+ // this._onSaveState). See `checkedRead` for the dispatch.
1261
+ Unpackr.SUPPORTS_STRUCT_HOOKS = true;
1262
 
1263
  exports.C1 = C1;
1264
  exports.C1Type = C1Type;
 
1276
  exports.readString = readString;
1277
  exports.roundFloat32 = roundFloat32;
1278
  exports.setExtractor = setExtractor;
 
1279
  exports.typedArrays = typedArrays;
1280
  exports.unpack = unpack;
1281
  exports.unpackMultiple = unpackMultiple;
.opencode/node_modules/msgpackr/dist/unpack-no-eval.cjs.map CHANGED
The diff for this file is too large to render. See raw diff
 
.opencode/node_modules/msgpackr/index.js CHANGED
@@ -1,5 +1,5 @@
1
- export { Packr, Encoder, addExtension, pack, encode, NEVER, ALWAYS, DECIMAL_ROUND, DECIMAL_FIT, REUSE_BUFFER_MODE, RESET_BUFFER_MODE, RESERVE_START_SPACE } from './pack.js'
2
- export { Unpackr, Decoder, C1, unpack, unpackMultiple, decode, FLOAT32_OPTIONS, clearSource, roundFloat32, isNativeAccelerationEnabled } from './unpack.js'
3
- export { decodeIter, encodeIter } from './iterators.js'
4
- export const useRecords = false
5
- export const mapsAsObjects = true
 
1
+ export { Packr, Encoder, addExtension, pack, encode, NEVER, ALWAYS, DECIMAL_ROUND, DECIMAL_FIT, REUSE_BUFFER_MODE, RESET_BUFFER_MODE, RESERVE_START_SPACE } from './pack.js';
2
+ export { Unpackr, Decoder, C1, unpack, unpackMultiple, decode, FLOAT32_OPTIONS, clearSource, roundFloat32, isNativeAccelerationEnabled } from './unpack.js';
3
+ export { decodeIter, encodeIter } from './iterators.js';
4
+ export const useRecords = false;
5
+ export const mapsAsObjects = true;
.opencode/node_modules/msgpackr/iterators.js CHANGED
@@ -1,5 +1,5 @@
1
- import { Packr } from './pack.js'
2
- import { Unpackr } from './unpack.js'
3
 
4
  /**
5
  * Given an Iterable first argument, returns an Iterable where each value is packed as a Buffer
@@ -10,27 +10,27 @@ import { Unpackr } from './unpack.js'
10
  */
11
  export function packIter (objectIterator, options = {}) {
12
  if (!objectIterator || typeof objectIterator !== 'object') {
13
- throw new Error('first argument must be an Iterable, Async Iterable, or a Promise for an Async Iterable')
14
  } else if (typeof objectIterator[Symbol.iterator] === 'function') {
15
- return packIterSync(objectIterator, options)
16
  } else if (typeof objectIterator.then === 'function' || typeof objectIterator[Symbol.asyncIterator] === 'function') {
17
- return packIterAsync(objectIterator, options)
18
  } else {
19
- throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a Promise')
20
  }
21
  }
22
 
23
  function * packIterSync (objectIterator, options) {
24
- const packr = new Packr(options)
25
  for (const value of objectIterator) {
26
- yield packr.pack(value)
27
  }
28
  }
29
 
30
  async function * packIterAsync (objectIterator, options) {
31
- const packr = new Packr(options)
32
  for await (const value of objectIterator) {
33
- yield packr.pack(value)
34
  }
35
  }
36
 
@@ -43,45 +43,45 @@ async function * packIterAsync (objectIterator, options) {
43
  */
44
  export function unpackIter (bufferIterator, options = {}) {
45
  if (!bufferIterator || typeof bufferIterator !== 'object') {
46
- throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a promise')
47
  }
48
 
49
- const unpackr = new Unpackr(options)
50
- let incomplete
51
  const parser = (chunk) => {
52
- let yields
53
  // if there's incomplete data from previous chunk, concatinate and try again
54
  if (incomplete) {
55
- chunk = Buffer.concat([incomplete, chunk])
56
- incomplete = undefined
57
  }
58
 
59
  try {
60
- yields = unpackr.unpackMultiple(chunk)
61
  } catch (err) {
62
  if (err.incomplete) {
63
- incomplete = chunk.slice(err.lastPosition)
64
- yields = err.values
65
  } else {
66
- throw err
67
  }
68
  }
69
- return yields
70
- }
71
 
72
  if (typeof bufferIterator[Symbol.iterator] === 'function') {
73
  return (function * iter () {
74
  for (const value of bufferIterator) {
75
- yield * parser(value)
76
  }
77
- })()
78
  } else if (typeof bufferIterator[Symbol.asyncIterator] === 'function') {
79
  return (async function * iter () {
80
  for await (const value of bufferIterator) {
81
- yield * parser(value)
82
  }
83
- })()
84
  }
85
  }
86
- export const decodeIter = unpackIter
87
- export const encodeIter = packIter
 
1
+ import { Packr } from './pack.js';
2
+ import { Unpackr } from './unpack.js';
3
 
4
  /**
5
  * Given an Iterable first argument, returns an Iterable where each value is packed as a Buffer
 
10
  */
11
  export function packIter (objectIterator, options = {}) {
12
  if (!objectIterator || typeof objectIterator !== 'object') {
13
+ throw new Error('first argument must be an Iterable, Async Iterable, or a Promise for an Async Iterable');
14
  } else if (typeof objectIterator[Symbol.iterator] === 'function') {
15
+ return packIterSync(objectIterator, options);
16
  } else if (typeof objectIterator.then === 'function' || typeof objectIterator[Symbol.asyncIterator] === 'function') {
17
+ return packIterAsync(objectIterator, options);
18
  } else {
19
+ throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a Promise');
20
  }
21
  }
22
 
23
  function * packIterSync (objectIterator, options) {
24
+ const packr = new Packr(options);
25
  for (const value of objectIterator) {
26
+ yield packr.pack(value);
27
  }
28
  }
29
 
30
  async function * packIterAsync (objectIterator, options) {
31
+ const packr = new Packr(options);
32
  for await (const value of objectIterator) {
33
+ yield packr.pack(value);
34
  }
35
  }
36
 
 
43
  */
44
  export function unpackIter (bufferIterator, options = {}) {
45
  if (!bufferIterator || typeof bufferIterator !== 'object') {
46
+ throw new Error('first argument must be an Iterable, Async Iterable, Iterator, Async Iterator, or a promise');
47
  }
48
 
49
+ const unpackr = new Unpackr(options);
50
+ let incomplete;
51
  const parser = (chunk) => {
52
+ let yields;
53
  // if there's incomplete data from previous chunk, concatinate and try again
54
  if (incomplete) {
55
+ chunk = Buffer.concat([incomplete, chunk]);
56
+ incomplete = undefined;
57
  }
58
 
59
  try {
60
+ yields = unpackr.unpackMultiple(chunk);
61
  } catch (err) {
62
  if (err.incomplete) {
63
+ incomplete = chunk.slice(err.lastPosition);
64
+ yields = err.values;
65
  } else {
66
+ throw err;
67
  }
68
  }
69
+ return yields;
70
+ };
71
 
72
  if (typeof bufferIterator[Symbol.iterator] === 'function') {
73
  return (function * iter () {
74
  for (const value of bufferIterator) {
75
+ yield * parser(value);
76
  }
77
+ })();
78
  } else if (typeof bufferIterator[Symbol.asyncIterator] === 'function') {
79
  return (async function * iter () {
80
  for await (const value of bufferIterator) {
81
+ yield * parser(value);
82
  }
83
+ })();
84
  }
85
  }
86
+ export const decodeIter = unpackIter;
87
+ export const encodeIter = packIter;
.opencode/node_modules/msgpackr/node-index.js CHANGED
@@ -1,24 +1,23 @@
1
- export { Packr, Encoder, addExtension, pack, encode, NEVER, ALWAYS, DECIMAL_ROUND, DECIMAL_FIT, REUSE_BUFFER_MODE, RESET_BUFFER_MODE, RESERVE_START_SPACE } from './pack.js'
2
- export { Unpackr, Decoder, C1, unpack, unpackMultiple, decode, FLOAT32_OPTIONS, clearSource, roundFloat32, isNativeAccelerationEnabled } from './unpack.js'
3
- import './struct.js'
4
- export { PackrStream, UnpackrStream, PackrStream as EncoderStream, UnpackrStream as DecoderStream } from './stream.js'
5
- export { decodeIter, encodeIter } from './iterators.js'
6
- export const useRecords = false
7
- export const mapsAsObjects = true
8
- import { setExtractor } from './unpack.js'
9
- import { createRequire } from 'module'
10
 
11
  const nativeAccelerationDisabled = process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED !== undefined && process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED.toLowerCase() === 'true';
12
 
13
  if (!nativeAccelerationDisabled) {
14
- let extractor
15
  try {
16
  if (typeof require == 'function')
17
- extractor = require('msgpackr-extract')
18
  else
19
- extractor = createRequire(import.meta.url)('msgpackr-extract')
20
  if (extractor)
21
- setExtractor(extractor.extractStrings)
22
  } catch (error) {
23
  // native module is optional
24
  }
 
1
+ export { Packr, Encoder, addExtension, pack, encode, NEVER, ALWAYS, DECIMAL_ROUND, DECIMAL_FIT, REUSE_BUFFER_MODE, RESET_BUFFER_MODE, RESERVE_START_SPACE } from './pack.js';
2
+ export { Unpackr, Decoder, C1, unpack, unpackMultiple, decode, FLOAT32_OPTIONS, clearSource, roundFloat32, isNativeAccelerationEnabled } from './unpack.js';
3
+ export { PackrStream, UnpackrStream, PackrStream as EncoderStream, UnpackrStream as DecoderStream } from './stream.js';
4
+ export { decodeIter, encodeIter } from './iterators.js';
5
+ export const useRecords = false;
6
+ export const mapsAsObjects = true;
7
+ import { setExtractor } from './unpack.js';
8
+ import { createRequire } from 'module';
 
9
 
10
  const nativeAccelerationDisabled = process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED !== undefined && process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED.toLowerCase() === 'true';
11
 
12
  if (!nativeAccelerationDisabled) {
13
+ let extractor;
14
  try {
15
  if (typeof require == 'function')
16
+ extractor = require('msgpackr-extract');
17
  else
18
+ extractor = createRequire(import.meta.url)('msgpackr-extract');
19
  if (extractor)
20
+ setExtractor(extractor.extractStrings);
21
  } catch (error) {
22
  // native module is optional
23
  }
.opencode/node_modules/msgpackr/pack.js CHANGED
@@ -1,139 +1,138 @@
1
- import { Unpackr, mult10, C1Type, typedArrays, addExtension as unpackAddExtension } from './unpack.js'
2
- let textEncoder
3
  try {
4
- textEncoder = new TextEncoder()
5
  } catch (error) {}
6
- let extensions, extensionClasses
7
- const hasNodeBuffer = typeof Buffer !== 'undefined'
8
  const ByteArrayAllocate = hasNodeBuffer ?
9
- function(length) { return Buffer.allocUnsafeSlow(length) } : Uint8Array
10
- const ByteArray = hasNodeBuffer ? Buffer : Uint8Array
11
- const MAX_BUFFER_SIZE = hasNodeBuffer ? 0x100000000 : 0x7fd00000
12
- let target, keysTarget
13
- let targetView
14
- let position = 0
15
- let safeEnd
16
- let bundledStrings = null
17
- let writeStructSlots
18
- const MAX_BUNDLE_SIZE = 0x5500 // maximum characters such that the encoded bytes fits in 16 bits.
19
- const hasNonLatin = /[\u0080-\uFFFF]/
20
- export const RECORD_SYMBOL = Symbol('record-id')
21
  export class Packr extends Unpackr {
22
  constructor(options) {
23
- super(options)
24
- this.offset = 0
25
- let typeBuffer
26
- let start
27
- let hasSharedUpdate
28
- let structures
29
- let referenceMap
30
  let encodeUtf8 = ByteArray.prototype.utf8Write ? function(string, position) {
31
- return target.utf8Write(string, position, target.byteLength - position)
32
  } : (textEncoder && textEncoder.encodeInto) ?
33
  function(string, position) {
34
- return textEncoder.encodeInto(string, target.subarray(position)).written
35
- } : false
36
 
37
- let packr = this
38
  if (!options)
39
- options = {}
40
- let isSequential = options && options.sequential
41
- let hasSharedStructures = options.structures || options.saveStructures
42
- let maxSharedStructures = options.maxSharedStructures
43
  if (maxSharedStructures == null)
44
- maxSharedStructures = hasSharedStructures ? 32 : 0
45
  if (maxSharedStructures > 8160)
46
- throw new Error('Maximum maxSharedStructure is 8160')
47
  if (options.structuredClone && options.moreTypes == undefined) {
48
- this.moreTypes = true
49
  }
50
- let maxOwnStructures = options.maxOwnStructures
51
  if (maxOwnStructures == null)
52
- maxOwnStructures = hasSharedStructures ? 32 : 64
53
  if (!this.structures && options.useRecords != false)
54
- this.structures = []
55
  // two byte record ids for shared structures
56
- let useTwoByteRecords = maxSharedStructures > 32 || (maxOwnStructures + maxSharedStructures > 64)
57
- let sharedLimitId = maxSharedStructures + 0x40
58
- let maxStructureId = maxSharedStructures + maxOwnStructures + 0x40
59
  if (maxStructureId > 8256) {
60
- throw new Error('Maximum maxSharedStructure + maxOwnStructure is 8192')
61
  }
62
- let recordIdsToRemove = []
63
- let transitionsCount = 0
64
- let serializationsSinceTransitionRebuild = 0
65
 
66
  this.pack = this.encode = function(value, encodeOptions) {
67
  if (!target) {
68
- target = new ByteArrayAllocate(8192)
69
- targetView = target.dataView || (target.dataView = new DataView(target.buffer, 0, 8192))
70
- position = 0
71
  }
72
- safeEnd = target.length - 10
73
  if (safeEnd - position < 0x800) {
74
  // don't start too close to the end,
75
- target = new ByteArrayAllocate(target.length)
76
- targetView = target.dataView || (target.dataView = new DataView(target.buffer, 0, target.length))
77
- safeEnd = target.length - 10
78
- position = 0
79
  } else
80
- position = (position + 7) & 0x7ffffff8 // Word align to make any future copying of this buffer faster
81
- start = position
82
- if (encodeOptions & RESERVE_START_SPACE) position += (encodeOptions & 0xff)
83
- referenceMap = packr.structuredClone ? new Map() : null
84
  if (packr.bundleStrings && typeof value !== 'string') {
85
- bundledStrings = []
86
- bundledStrings.size = Infinity // force a new bundle start on first string
87
  } else
88
- bundledStrings = null
89
- structures = packr.structures
90
  if (structures) {
91
  if (structures.uninitialized)
92
- structures = packr._mergeStructures(packr.getStructures())
93
- let sharedLength = structures.sharedLength || 0
94
  if (sharedLength > maxSharedStructures) {
95
  //if (maxSharedStructures <= 32 && structures.sharedLength > 32) // TODO: could support this, but would need to update the limit ids
96
- throw new Error('Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to ' + structures.sharedLength)
97
  }
98
  if (!structures.transitions) {
99
  // rebuild our structure transitions
100
- structures.transitions = Object.create(null)
101
  for (let i = 0; i < sharedLength; i++) {
102
- let keys = structures[i]
103
  if (!keys)
104
- continue
105
- let nextTransition, transition = structures.transitions
106
  for (let j = 0, l = keys.length; j < l; j++) {
107
- let key = keys[j]
108
- nextTransition = transition[key]
109
  if (!nextTransition) {
110
- nextTransition = transition[key] = Object.create(null)
111
  }
112
- transition = nextTransition
113
  }
114
- transition[RECORD_SYMBOL] = i + 0x40
115
  }
116
- this.lastNamedStructuresLength = sharedLength
117
  }
118
  if (!isSequential) {
119
- structures.nextId = sharedLength + 0x40
120
  }
121
  }
122
  if (hasSharedUpdate)
123
- hasSharedUpdate = false
124
  let encodingError;
125
  try {
126
- if (packr.randomAccessStructure && value && typeof value === 'object') {
127
  if (value.constructor === Object) writeStruct(value); // simple object
128
  else if (value.constructor !== Map && !Array.isArray(value) && !extensionClasses.some(extClass => value instanceof extClass)) {
129
  // allow user classes, if they don't need special handling (but do use toJSON if available)
130
  writeStruct(value.toJSON ? value.toJSON() : value);
131
- } else pack(value)
132
  } else
133
- pack(value)
134
  let lastBundle = bundledStrings;
135
  if (bundledStrings)
136
- writeBundles(start, pack, 0)
137
  if (referenceMap && referenceMap.idsToInsert) {
138
  let idsToInsert = referenceMap.idsToInsert.sort((a, b) => a.offset > b.offset ? 1 : -1);
139
  let i = idsToInsert.length;
@@ -149,7 +148,7 @@ export class Packr extends Unpackr {
149
  if (incrementPosition >= 0) {
150
  // update the bundle reference now
151
  targetView.setUint32(lastBundle.position + start,
152
- targetView.getUint32(lastBundle.position + start) + incrementPosition)
153
  incrementPosition = -1; // reset
154
  }
155
  lastBundle = lastBundle.previous;
@@ -159,23 +158,23 @@ export class Packr extends Unpackr {
159
  if (incrementPosition >= 0 && lastBundle) {
160
  // update the bundle reference now
161
  targetView.setUint32(lastBundle.position + start,
162
- targetView.getUint32(lastBundle.position + start) + incrementPosition)
163
  }
164
  position += idsToInsert.length * 6;
165
  if (position > safeEnd)
166
- makeRoom(position)
167
- packr.offset = position
168
- let serialized = insertIds(target.subarray(start, position), idsToInsert)
169
- referenceMap = null
170
- return serialized
171
  }
172
- packr.offset = position // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
173
  if (encodeOptions & REUSE_BUFFER_MODE) {
174
- target.start = start
175
- target.end = position
176
- return target
177
  }
178
- return target.subarray(start, position) // position can change if we call pack again in saveStructures, so we get the buffer now
179
  } catch(error) {
180
  encodingError = error;
181
  throw error;
@@ -183,336 +182,343 @@ export class Packr extends Unpackr {
183
  if (structures) {
184
  resetStructures();
185
  if (hasSharedUpdate && packr.saveStructures) {
186
- let sharedLength = structures.sharedLength || 0
187
  // we can't rely on start/end with REUSE_BUFFER_MODE since they will (probably) change when we save
188
- let returnBuffer = target.subarray(start, position)
189
- let newSharedData = prepareStructures(structures, packr);
190
  if (!encodingError) { // TODO: If there is an encoding error, should make the structures as uninitialized so they get rebuilt next time
191
  if (packr.saveStructures(newSharedData, newSharedData.isCompatible) === false) {
192
- // get updated structures and try again if the update failed
193
- return packr.pack(value, encodeOptions)
 
 
 
 
 
 
 
194
  }
195
- packr.lastNamedStructuresLength = sharedLength
196
  // don't keep large buffers around
197
- if (target.length > 0x40000000) target = null
198
- return returnBuffer
199
  }
200
  }
201
  }
202
  // don't keep large buffers around, they take too much memory and cause problems (limit at 1GB)
203
- if (target.length > 0x40000000) target = null
204
  if (encodeOptions & RESET_BUFFER_MODE)
205
- position = start
206
  }
207
- }
208
  const resetStructures = () => {
209
  if (serializationsSinceTransitionRebuild < 10)
210
- serializationsSinceTransitionRebuild++
211
- let sharedLength = structures.sharedLength || 0
212
  if (structures.length > sharedLength && !isSequential)
213
- structures.length = sharedLength
214
  if (transitionsCount > 10000) {
215
  // force a rebuild occasionally after a lot of transitions so it can get cleaned up
216
- structures.transitions = null
217
- serializationsSinceTransitionRebuild = 0
218
- transitionsCount = 0
219
  if (recordIdsToRemove.length > 0)
220
- recordIdsToRemove = []
221
  } else if (recordIdsToRemove.length > 0 && !isSequential) {
222
  for (let i = 0, l = recordIdsToRemove.length; i < l; i++) {
223
- recordIdsToRemove[i][RECORD_SYMBOL] = 0
224
  }
225
- recordIdsToRemove = []
226
  }
227
- }
228
  const packArray = (value) => {
229
- var length = value.length
230
  if (length < 0x10) {
231
- target[position++] = 0x90 | length
232
  } else if (length < 0x10000) {
233
- target[position++] = 0xdc
234
- target[position++] = length >> 8
235
- target[position++] = length & 0xff
236
  } else {
237
- target[position++] = 0xdd
238
- targetView.setUint32(position, length)
239
- position += 4
240
  }
241
  for (let i = 0; i < length; i++) {
242
- pack(value[i])
243
  }
244
- }
245
  const pack = (value) => {
246
  if (position > safeEnd)
247
- target = makeRoom(position)
248
 
249
- var type = typeof value
250
- var length
251
  if (type === 'string') {
252
- let strLength = value.length
253
  if (bundledStrings && strLength >= 4 && strLength < 0x1000) {
254
  if ((bundledStrings.size += strLength) > MAX_BUNDLE_SIZE) {
255
- let extStart
256
- let maxBytes = (bundledStrings[0] ? bundledStrings[0].length * 3 + bundledStrings[1].length : 0) + 10
257
  if (position + maxBytes > safeEnd)
258
- target = makeRoom(position + maxBytes)
259
- let lastBundle
260
  if (bundledStrings.position) { // here we use the 0x62 extension to write the last bundle and reserve space for the reference pointer to the next/current bundle
261
- lastBundle = bundledStrings
262
- target[position] = 0xc8 // ext 16
263
- position += 3 // reserve for the writing bundle size
264
- target[position++] = 0x62 // 'b'
265
- extStart = position - start
266
- position += 4 // reserve for writing bundle reference
267
- writeBundles(start, pack, 0) // write the last bundles
268
- targetView.setUint16(extStart + start - 3, position - start - extStart)
269
  } else { // here we use the 0x62 extension just to reserve the space for the reference pointer to the bundle (will be updated once the bundle is written)
270
- target[position++] = 0xd6 // fixext 4
271
- target[position++] = 0x62 // 'b'
272
- extStart = position - start
273
- position += 4 // reserve for writing bundle reference
274
  }
275
- bundledStrings = ['', ''] // create new ones
276
  bundledStrings.previous = lastBundle;
277
- bundledStrings.size = 0
278
- bundledStrings.position = extStart
279
  }
280
- let twoByte = hasNonLatin.test(value)
281
- bundledStrings[twoByte ? 0 : 1] += value
282
- target[position++] = 0xc1
283
  pack(twoByte ? -strLength : strLength);
284
- return
285
  }
286
- let headerSize
287
  // first we estimate the header size, so we can write to the correct location
288
  if (strLength < 0x20) {
289
- headerSize = 1
290
  } else if (strLength < 0x100) {
291
- headerSize = 2
292
  } else if (strLength < 0x10000) {
293
- headerSize = 3
294
  } else {
295
- headerSize = 5
296
  }
297
- let maxBytes = strLength * 3
298
  if (position + maxBytes > safeEnd)
299
- target = makeRoom(position + maxBytes)
300
 
301
  if (strLength < 0x40 || !encodeUtf8) {
302
- let i, c1, c2, strPosition = position + headerSize
303
  for (i = 0; i < strLength; i++) {
304
- c1 = value.charCodeAt(i)
305
  if (c1 < 0x80) {
306
- target[strPosition++] = c1
307
  } else if (c1 < 0x800) {
308
- target[strPosition++] = c1 >> 6 | 0xc0
309
- target[strPosition++] = c1 & 0x3f | 0x80
310
  } else if (
311
  (c1 & 0xfc00) === 0xd800 &&
312
  ((c2 = value.charCodeAt(i + 1)) & 0xfc00) === 0xdc00
313
  ) {
314
- c1 = 0x10000 + ((c1 & 0x03ff) << 10) + (c2 & 0x03ff)
315
- i++
316
- target[strPosition++] = c1 >> 18 | 0xf0
317
- target[strPosition++] = c1 >> 12 & 0x3f | 0x80
318
- target[strPosition++] = c1 >> 6 & 0x3f | 0x80
319
- target[strPosition++] = c1 & 0x3f | 0x80
320
  } else {
321
- target[strPosition++] = c1 >> 12 | 0xe0
322
- target[strPosition++] = c1 >> 6 & 0x3f | 0x80
323
- target[strPosition++] = c1 & 0x3f | 0x80
324
  }
325
  }
326
- length = strPosition - position - headerSize
327
  } else {
328
- length = encodeUtf8(value, position + headerSize)
329
  }
330
 
331
  if (length < 0x20) {
332
- target[position++] = 0xa0 | length
333
  } else if (length < 0x100) {
334
  if (headerSize < 2) {
335
- target.copyWithin(position + 2, position + 1, position + 1 + length)
336
  }
337
- target[position++] = 0xd9
338
- target[position++] = length
339
  } else if (length < 0x10000) {
340
  if (headerSize < 3) {
341
- target.copyWithin(position + 3, position + 2, position + 2 + length)
342
  }
343
- target[position++] = 0xda
344
- target[position++] = length >> 8
345
- target[position++] = length & 0xff
346
  } else {
347
  if (headerSize < 5) {
348
- target.copyWithin(position + 5, position + 3, position + 3 + length)
349
  }
350
- target[position++] = 0xdb
351
- targetView.setUint32(position, length)
352
- position += 4
353
  }
354
- position += length
355
  } else if (type === 'number') {
356
  if (value >>> 0 === value) {// positive integer, 32-bit or less
357
  // positive uint
358
- if (value < 0x20 || (value < 0x80 && this.useRecords === false) || (value < 0x40 && !this.randomAccessStructure)) {
359
- target[position++] = value
360
  } else if (value < 0x100) {
361
- target[position++] = 0xcc
362
- target[position++] = value
363
  } else if (value < 0x10000) {
364
- target[position++] = 0xcd
365
- target[position++] = value >> 8
366
- target[position++] = value & 0xff
367
  } else {
368
- target[position++] = 0xce
369
- targetView.setUint32(position, value)
370
- position += 4
371
  }
372
  } else if (value >> 0 === value) { // negative integer
373
  if (value >= -0x20) {
374
- target[position++] = 0x100 + value
375
  } else if (value >= -0x80) {
376
- target[position++] = 0xd0
377
- target[position++] = value + 0x100
378
  } else if (value >= -0x8000) {
379
- target[position++] = 0xd1
380
- targetView.setInt16(position, value)
381
- position += 2
382
  } else {
383
- target[position++] = 0xd2
384
- targetView.setInt32(position, value)
385
- position += 4
386
  }
387
  } else {
388
- let useFloat32
389
  if ((useFloat32 = this.useFloat32) > 0 && value < 0x100000000 && value >= -0x80000000) {
390
- target[position++] = 0xca
391
- targetView.setFloat32(position, value)
392
- let xShifted
393
  if (useFloat32 < 4 ||
394
  // this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
395
  ((xShifted = value * mult10[((target[position] & 0x7f) << 1) | (target[position + 1] >> 7)]) >> 0) === xShifted) {
396
- position += 4
397
- return
398
  } else
399
- position-- // move back into position for writing a double
400
  }
401
- target[position++] = 0xcb
402
- targetView.setFloat64(position, value)
403
- position += 8
404
  }
405
  } else if (type === 'object' || type === 'function') {
406
  if (!value)
407
- target[position++] = 0xc0
408
  else {
409
  if (referenceMap) {
410
- let referee = referenceMap.get(value)
411
  if (referee) {
412
  if (!referee.id) {
413
- let idsToInsert = referenceMap.idsToInsert || (referenceMap.idsToInsert = [])
414
- referee.id = idsToInsert.push(referee)
415
  }
416
- target[position++] = 0xd6 // fixext 4
417
- target[position++] = 0x70 // "p" for pointer
418
- targetView.setUint32(position, referee.id)
419
- position += 4
420
- return
421
  } else
422
- referenceMap.set(value, { offset: position - start })
423
  }
424
- let constructor = value.constructor
425
  if (constructor === Object) {
426
- writeObject(value)
427
  } else if (constructor === Array) {
428
- packArray(value)
429
  } else if (constructor === Map) {
430
- if (this.mapAsEmptyObject) target[position++] = 0x80
431
  else {
432
- length = value.size
433
  if (length < 0x10) {
434
- target[position++] = 0x80 | length
435
  } else if (length < 0x10000) {
436
- target[position++] = 0xde
437
- target[position++] = length >> 8
438
- target[position++] = length & 0xff
439
  } else {
440
- target[position++] = 0xdf
441
- targetView.setUint32(position, length)
442
- position += 4
443
  }
444
  for (let [key, entryValue] of value) {
445
- pack(key)
446
- pack(entryValue)
447
  }
448
  }
449
  } else {
450
  for (let i = 0, l = extensions.length; i < l; i++) {
451
- let extensionClass = extensionClasses[i]
452
  if (value instanceof extensionClass) {
453
- let extension = extensions[i]
454
  if (extension.write) {
455
  if (extension.type) {
456
- target[position++] = 0xd4 // one byte "tag" extension
457
- target[position++] = extension.type
458
- target[position++] = 0
459
  }
460
- let writeResult = extension.write.call(this, value)
461
  if (writeResult === value) { // avoid infinite recursion
462
  if (Array.isArray(value)) {
463
- packArray(value)
464
  } else {
465
- writeObject(value)
466
  }
467
  } else {
468
- pack(writeResult)
469
  }
470
- return
471
  }
472
- let currentTarget = target
473
- let currentTargetView = targetView
474
- let currentPosition = position
475
- target = null
476
- let result
477
  try {
478
  result = extension.pack.call(this, value, (size) => {
479
  // restore target and use it
480
- target = currentTarget
481
- currentTarget = null
482
- position += size
483
  if (position > safeEnd)
484
- makeRoom(position)
485
  return {
486
  target, targetView, position: position - size
487
- }
488
- }, pack)
489
  } finally {
490
  // restore current target information (unless already restored)
491
  if (currentTarget) {
492
- target = currentTarget
493
- targetView = currentTargetView
494
- position = currentPosition
495
- safeEnd = target.length - 10
496
  }
497
  }
498
  if (result) {
499
  if (result.length + position > safeEnd)
500
- makeRoom(result.length + position)
501
- position = writeExtensionData(result, target, position, extension.type)
502
  }
503
- return
504
  }
505
  }
506
  // check isArray after extensions, because extensions can extend Array
507
  if (Array.isArray(value)) {
508
- packArray(value)
509
  } else {
510
  // use this as an alternate mechanism for expressing how to serialize
511
  if (value.toJSON) {
512
- const json = value.toJSON()
513
  // if for some reason value.toJSON returns itself it'll loop forever
514
  if (json !== value)
515
- return pack(json)
516
  }
517
 
518
  // if there is a writeFunction, use it, otherwise just encode as undefined
@@ -520,89 +526,89 @@ export class Packr extends Unpackr {
520
  return pack(this.writeFunction && this.writeFunction(value));
521
 
522
  // no extension found, write as plain object
523
- writeObject(value)
524
  }
525
  }
526
  }
527
  } else if (type === 'boolean') {
528
- target[position++] = value ? 0xc3 : 0xc2
529
  } else if (type === 'bigint') {
530
  if (value < 0x8000000000000000 && value >= -0x8000000000000000) {
531
  // use a signed int as long as it fits
532
- target[position++] = 0xd3
533
- targetView.setBigInt64(position, value)
534
  } else if (value < 0x10000000000000000 && value > 0) {
535
  // if we can fit an unsigned int, use that
536
- target[position++] = 0xcf
537
- targetView.setBigUint64(position, value)
538
  } else {
539
  // overflow
540
  if (this.largeBigIntToFloat) {
541
- target[position++] = 0xcb
542
- targetView.setFloat64(position, Number(value))
543
  } else if (this.largeBigIntToString) {
544
  return pack(value.toString());
545
  } else if (this.useBigIntExtension || this.moreTypes) {
546
- let empty = value < 0 ? BigInt(-1) : BigInt(0)
547
 
548
- let array
549
  if (value >> BigInt(0x10000) === empty) {
550
- let mask = BigInt(0x10000000000000000) - BigInt(1) // literal would overflow
551
- let chunks = []
552
  while (true) {
553
- chunks.push(value & mask)
554
- if ((value >> BigInt(63)) === empty) break
555
- value >>= BigInt(64)
556
  }
557
 
558
- array = new Uint8Array(new BigUint64Array(chunks).buffer)
559
- array.reverse()
560
  } else {
561
- let invert = value < 0
562
- let string = (invert ? ~value : value).toString(16)
563
  if (string.length % 2) {
564
- string = '0' + string
565
  } else if (parseInt(string.charAt(0), 16) >= 8) {
566
- string = '00' + string
567
  }
568
 
569
  if (hasNodeBuffer) {
570
- array = Buffer.from(string, 'hex')
571
  } else {
572
- array = new Uint8Array(string.length / 2)
573
  for (let i = 0; i < array.length; i++) {
574
- array[i] = parseInt(string.slice(i * 2, i * 2 + 2), 16)
575
  }
576
  }
577
 
578
  if (invert) {
579
- for (let i = 0; i < array.length; i++) array[i] = ~array[i]
580
  }
581
  }
582
 
583
  if (array.length + position > safeEnd)
584
- makeRoom(array.length + position)
585
- position = writeExtensionData(array, target, position, 0x42)
586
- return
587
  } else {
588
  throw new RangeError(value + ' was too large to fit in MessagePack 64-bit integer format, use' +
589
  ' useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set' +
590
- ' largeBigIntToString to convert to string')
591
  }
592
  }
593
- position += 8
594
  } else if (type === 'undefined') {
595
  if (this.encodeUndefinedAsNil)
596
- target[position++] = 0xc0
597
  else {
598
- target[position++] = 0xd4 // a number of implementations use fixext1 with type 0, data 0 to denote undefined, so we follow suite
599
- target[position++] = 0
600
- target[position++] = 0
601
  }
602
  } else {
603
- throw new Error('Unknown type: ' + type)
604
  }
605
- }
606
 
607
  const writePlainObject = (this.variableMapSize || this.coercibleKeyAsNumber || this.skipValues) ? (object) => {
608
  // this method is slightly slower, but generates "preferred serialization" (optimally small for smaller objects)
@@ -615,263 +621,264 @@ export class Packr extends Unpackr {
615
  keys.push(key);
616
  }
617
  } else {
618
- keys = Object.keys(object)
619
  }
620
- let length = keys.length
621
  if (length < 0x10) {
622
- target[position++] = 0x80 | length
623
  } else if (length < 0x10000) {
624
- target[position++] = 0xde
625
- target[position++] = length >> 8
626
- target[position++] = length & 0xff
627
  } else {
628
- target[position++] = 0xdf
629
- targetView.setUint32(position, length)
630
- position += 4
631
  }
632
- let key
633
  if (this.coercibleKeyAsNumber) {
634
  for (let i = 0; i < length; i++) {
635
- key = keys[i]
636
- let num = Number(key)
637
- pack(isNaN(num) ? key : num)
638
- pack(object[key])
639
  }
640
 
641
  } else {
642
  for (let i = 0; i < length; i++) {
643
- pack(key = keys[i])
644
- pack(object[key])
645
  }
646
  }
647
  } :
648
  (object) => {
649
- target[position++] = 0xde // always using map 16, so we can preallocate and set the length afterwards
650
- let objectOffset = position - start
651
- position += 2
652
- let size = 0
653
  for (let key in object) {
654
  if (typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key)) {
655
- pack(key)
656
- pack(object[key])
657
- size++
658
  }
659
  }
660
  if (size > 0xffff) {
661
  throw new Error('Object is too large to serialize with fast 16-bit map size,' +
662
  ' use the "variableMapSize" option to serialize this object');
663
  }
664
- target[objectOffset++ + start] = size >> 8
665
- target[objectOffset + start] = size & 0xff
666
- }
667
 
668
  const writeRecord = this.useRecords === false ? writePlainObject :
669
  (options.progressiveRecords && !useTwoByteRecords) ? // this is about 2% faster for highly stable structures, since it only requires one for-in loop (but much more expensive when new structure needs to be written)
670
  (object) => {
671
- let nextTransition, transition = structures.transitions || (structures.transitions = Object.create(null))
672
- let objectOffset = position++ - start
673
- let wroteKeys
674
  for (let key in object) {
675
  if (typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key)) {
676
- nextTransition = transition[key]
677
  if (nextTransition)
678
- transition = nextTransition
679
  else {
680
  // record doesn't exist, create full new record and insert it
681
- let keys = Object.keys(object)
682
- let lastTransition = transition
683
- transition = structures.transitions
684
- let newTransitions = 0
685
  for (let i = 0, l = keys.length; i < l; i++) {
686
- let key = keys[i]
687
- nextTransition = transition[key]
688
  if (!nextTransition) {
689
- nextTransition = transition[key] = Object.create(null)
690
- newTransitions++
691
  }
692
- transition = nextTransition
693
  }
694
  if (objectOffset + start + 1 == position) {
695
  // first key, so we don't need to insert, we can just write record directly
696
- position--
697
- newRecord(transition, keys, newTransitions)
698
  } else // otherwise we need to insert the record, moving existing data after the record
699
- insertNewRecord(transition, keys, objectOffset, newTransitions)
700
- wroteKeys = true
701
- transition = lastTransition[key]
702
  }
703
- pack(object[key])
704
  }
705
  }
706
  if (!wroteKeys) {
707
- let recordId = transition[RECORD_SYMBOL]
708
  if (recordId)
709
- target[objectOffset + start] = recordId
710
  else
711
- insertNewRecord(transition, Object.keys(object), objectOffset, 0)
712
  }
713
  } :
714
  (object) => {
715
- let nextTransition, transition = structures.transitions || (structures.transitions = Object.create(null))
716
- let newTransitions = 0
717
  for (let key in object) if (typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key)) {
718
- nextTransition = transition[key]
719
  if (!nextTransition) {
720
- nextTransition = transition[key] = Object.create(null)
721
- newTransitions++
722
  }
723
- transition = nextTransition
724
  }
725
- let recordId = transition[RECORD_SYMBOL]
726
  if (recordId) {
727
  if (recordId >= 0x60 && useTwoByteRecords) {
728
- target[position++] = ((recordId -= 0x60) & 0x1f) + 0x60
729
- target[position++] = recordId >> 5
730
  } else
731
- target[position++] = recordId
732
  } else {
733
- newRecord(transition, transition.__keys__ || Object.keys(object), newTransitions)
734
  }
735
  // now write the values
736
  for (let key in object)
737
  if (typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key)) {
738
- pack(object[key])
739
  }
740
- }
741
 
742
  // create reference to useRecords if useRecords is a function
743
  const checkUseRecords = typeof this.useRecords == 'function' && this.useRecords;
744
 
745
  const writeObject = checkUseRecords ? (object) => {
746
- checkUseRecords(object) ? writeRecord(object) : writePlainObject(object)
747
- } : writeRecord
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
748
 
749
  const makeRoom = (end) => {
750
- let newSize
751
  if (end > 0x1000000) {
752
  // special handling for really large buffers
753
  if ((end - start) > MAX_BUFFER_SIZE)
754
- throw new Error('Packed buffer would be larger than maximum buffer size')
755
  newSize = Math.min(MAX_BUFFER_SIZE,
756
- Math.round(Math.max((end - start) * (end > 0x4000000 ? 1.25 : 2), 0x400000) / 0x1000) * 0x1000)
757
  } else // faster handling for smaller buffers
758
- newSize = ((Math.max((end - start) << 2, target.length - 1) >> 12) + 1) << 12
759
- let newBuffer = new ByteArrayAllocate(newSize)
760
- targetView = newBuffer.dataView || (newBuffer.dataView = new DataView(newBuffer.buffer, 0, newSize))
761
- end = Math.min(end, target.length)
762
  if (target.copy)
763
- target.copy(newBuffer, 0, start, end)
764
  else
765
- newBuffer.set(target.slice(start, end))
766
- position -= start
767
- start = 0
768
- safeEnd = newBuffer.length - 10
769
- return target = newBuffer
770
- }
771
  const newRecord = (transition, keys, newTransitions) => {
772
- let recordId = structures.nextId
773
  if (!recordId)
774
- recordId = 0x40
775
  if (recordId < sharedLimitId && this.shouldShareStructure && !this.shouldShareStructure(keys)) {
776
- recordId = structures.nextOwnId
777
  if (!(recordId < maxStructureId))
778
- recordId = sharedLimitId
779
- structures.nextOwnId = recordId + 1
780
  } else {
781
  if (recordId >= maxStructureId)// cycle back around
782
- recordId = sharedLimitId
783
- structures.nextId = recordId + 1
784
  }
785
- let highByte = keys.highByte = recordId >= 0x60 && useTwoByteRecords ? (recordId - 0x60) >> 5 : -1
786
- transition[RECORD_SYMBOL] = recordId
787
- transition.__keys__ = keys
788
- structures[recordId - 0x40] = keys
789
 
790
  if (recordId < sharedLimitId) {
791
- keys.isShared = true
792
- structures.sharedLength = recordId - 0x3f
793
- hasSharedUpdate = true
794
  if (highByte >= 0) {
795
- target[position++] = (recordId & 0x1f) + 0x60
796
- target[position++] = highByte
797
  } else {
798
- target[position++] = recordId
799
  }
800
  } else {
801
  if (highByte >= 0) {
802
- target[position++] = 0xd5 // fixext 2
803
- target[position++] = 0x72 // "r" record defintion extension type
804
- target[position++] = (recordId & 0x1f) + 0x60
805
- target[position++] = highByte
806
  } else {
807
- target[position++] = 0xd4 // fixext 1
808
- target[position++] = 0x72 // "r" record defintion extension type
809
- target[position++] = recordId
810
  }
811
 
812
  if (newTransitions)
813
- transitionsCount += serializationsSinceTransitionRebuild * newTransitions
814
  // record the removal of the id, we can maintain our shared structure
815
  if (recordIdsToRemove.length >= maxOwnStructures)
816
- recordIdsToRemove.shift()[RECORD_SYMBOL] = 0 // we are cycling back through, and have to remove old ones
817
- recordIdsToRemove.push(transition)
818
- pack(keys)
819
  }
820
- }
821
  const insertNewRecord = (transition, keys, insertionOffset, newTransitions) => {
822
- let mainTarget = target
823
- let mainPosition = position
824
- let mainSafeEnd = safeEnd
825
- let mainStart = start
826
- target = keysTarget
827
- position = 0
828
- start = 0
829
  if (!target)
830
- keysTarget = target = new ByteArrayAllocate(8192)
831
- safeEnd = target.length - 10
832
- newRecord(transition, keys, newTransitions)
833
- keysTarget = target
834
- let keysPosition = position
835
- target = mainTarget
836
- position = mainPosition
837
- safeEnd = mainSafeEnd
838
- start = mainStart
839
  if (keysPosition > 1) {
840
- let newEnd = position + keysPosition - 1
841
  if (newEnd > safeEnd)
842
- makeRoom(newEnd)
843
- let insertionPosition = insertionOffset + start
844
- target.copyWithin(insertionPosition + keysPosition, insertionPosition + 1, position)
845
- target.set(keysTarget.slice(0, keysPosition), insertionPosition)
846
- position = newEnd
847
  } else {
848
- target[insertionOffset + start] = keysTarget[0]
849
  }
850
- }
851
- const writeStruct = (object) => {
852
- let newPosition = writeStructSlots(object, target, start, position, structures, makeRoom, (value, newPosition, notifySharedUpdate) => {
853
- if (notifySharedUpdate)
854
- return hasSharedUpdate = true;
855
- position = newPosition;
856
- let startTarget = target;
857
- pack(value);
858
- resetStructures();
859
- if (startTarget !== target) {
860
- return { position, targetView, target }; // indicate the buffer was re-allocated
861
- }
862
- return position;
863
- }, this);
864
- if (newPosition === 0) // bail and go to a msgpack object
865
- return writeObject(object);
866
- position = newPosition;
867
- }
868
  }
869
  useBuffer(buffer) {
870
  // this means we are finished using our own buffer and we can write over it safely
871
- target = buffer
872
- target.dataView || (target.dataView = new DataView(target.buffer, target.byteOffset, target.byteLength))
873
  targetView = target.dataView;
874
- position = 0
875
  }
876
  set position (value) {
877
  position = value;
@@ -881,261 +888,262 @@ export class Packr extends Unpackr {
881
  }
882
  clearSharedData() {
883
  if (this.structures)
884
- this.structures = []
885
  if (this.typedStructs)
886
- this.typedStructs = []
887
  }
888
  }
889
 
890
- extensionClasses = [ Date, Set, Error, RegExp, ArrayBuffer, Object.getPrototypeOf(Uint8Array.prototype).constructor /*TypedArray*/, DataView, C1Type ]
891
  extensions = [{
892
  pack(date, allocateForWrite, pack) {
893
- let seconds = date.getTime() / 1000
894
  if ((this.useTimestamp32 || date.getMilliseconds() === 0) && seconds >= 0 && seconds < 0x100000000) {
895
  // Timestamp 32
896
- let { target, targetView, position} = allocateForWrite(6)
897
- target[position++] = 0xd6
898
- target[position++] = 0xff
899
- targetView.setUint32(position, seconds)
900
  } else if (seconds > 0 && seconds < 0x100000000) {
901
  // Timestamp 64
902
- let { target, targetView, position} = allocateForWrite(10)
903
- target[position++] = 0xd7
904
- target[position++] = 0xff
905
- targetView.setUint32(position, date.getMilliseconds() * 4000000 + ((seconds / 1000 / 0x100000000) >> 0))
906
- targetView.setUint32(position + 4, seconds)
907
  } else if (isNaN(seconds)) {
908
  if (this.onInvalidDate) {
909
- allocateForWrite(0)
910
- return pack(this.onInvalidDate())
911
  }
912
  // Intentionally invalid timestamp
913
- let { target, targetView, position} = allocateForWrite(3)
914
- target[position++] = 0xd4
915
- target[position++] = 0xff
916
- target[position++] = 0xff
917
  } else {
918
  // Timestamp 96
919
- let { target, targetView, position} = allocateForWrite(15)
920
- target[position++] = 0xc7
921
- target[position++] = 12
922
- target[position++] = 0xff
923
- targetView.setUint32(position, date.getMilliseconds() * 1000000)
924
- targetView.setBigInt64(position + 4, BigInt(Math.floor(seconds)))
925
  }
926
  }
927
  }, {
928
  pack(set, allocateForWrite, pack) {
929
  if (this.setAsEmptyObject) {
930
  allocateForWrite(0);
931
- return pack({})
932
  }
933
- let array = Array.from(set)
934
- let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0)
935
  if (this.moreTypes) {
936
- target[position++] = 0xd4
937
- target[position++] = 0x73 // 's' for Set
938
- target[position++] = 0
939
  }
940
- pack(array)
941
  }
942
  }, {
943
  pack(error, allocateForWrite, pack) {
944
- let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0)
945
  if (this.moreTypes) {
946
- target[position++] = 0xd4
947
- target[position++] = 0x65 // 'e' for error
948
- target[position++] = 0
949
  }
950
- pack([ error.name, error.message, error.cause ])
951
  }
952
  }, {
953
  pack(regex, allocateForWrite, pack) {
954
- let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0)
955
  if (this.moreTypes) {
956
- target[position++] = 0xd4
957
- target[position++] = 0x78 // 'x' for regeXp
958
- target[position++] = 0
959
  }
960
- pack([ regex.source, regex.flags ])
961
  }
962
  }, {
963
  pack(arrayBuffer, allocateForWrite) {
964
  if (this.moreTypes)
965
- writeExtBuffer(arrayBuffer, 0x10, allocateForWrite)
966
  else
967
- writeBuffer(hasNodeBuffer ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite)
968
  }
969
  }, {
970
  pack(typedArray, allocateForWrite) {
971
- let constructor = typedArray.constructor
972
  if (constructor !== ByteArray && this.moreTypes)
973
- writeExtBuffer(typedArray, typedArrays.indexOf(constructor.name), allocateForWrite)
974
  else
975
- writeBuffer(typedArray, allocateForWrite)
976
  }
977
  }, {
978
  pack(arrayBuffer, allocateForWrite) {
979
  if (this.moreTypes)
980
- writeExtBuffer(arrayBuffer, 0x11, allocateForWrite)
981
  else
982
- writeBuffer(hasNodeBuffer ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite)
983
  }
984
  }, {
985
  pack(c1, allocateForWrite) { // specific 0xC1 object
986
- let { target, position} = allocateForWrite(1)
987
- target[position] = 0xc1
988
  }
989
- }]
990
 
991
  function writeExtBuffer(typedArray, type, allocateForWrite, encode) {
992
- let length = typedArray.byteLength
993
  if (length + 1 < 0x100) {
994
- var { target, position } = allocateForWrite(4 + length)
995
- target[position++] = 0xc7
996
- target[position++] = length + 1
997
  } else if (length + 1 < 0x10000) {
998
- var { target, position } = allocateForWrite(5 + length)
999
- target[position++] = 0xc8
1000
- target[position++] = (length + 1) >> 8
1001
- target[position++] = (length + 1) & 0xff
1002
  } else {
1003
- var { target, position, targetView } = allocateForWrite(7 + length)
1004
- target[position++] = 0xc9
1005
- targetView.setUint32(position, length + 1) // plus one for the type byte
1006
- position += 4
1007
  }
1008
- target[position++] = 0x74 // "t" for typed array
1009
- target[position++] = type
1010
- if (!typedArray.buffer) typedArray = new Uint8Array(typedArray)
1011
- target.set(new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength), position)
1012
  }
1013
  function writeBuffer(buffer, allocateForWrite) {
1014
- let length = buffer.byteLength
1015
- var target, position
1016
  if (length < 0x100) {
1017
- var { target, position } = allocateForWrite(length + 2)
1018
- target[position++] = 0xc4
1019
- target[position++] = length
1020
  } else if (length < 0x10000) {
1021
- var { target, position } = allocateForWrite(length + 3)
1022
- target[position++] = 0xc5
1023
- target[position++] = length >> 8
1024
- target[position++] = length & 0xff
1025
  } else {
1026
- var { target, position, targetView } = allocateForWrite(length + 5)
1027
- target[position++] = 0xc6
1028
- targetView.setUint32(position, length)
1029
- position += 4
1030
  }
1031
- target.set(buffer, position)
1032
  }
1033
 
1034
  function writeExtensionData(result, target, position, type) {
1035
- let length = result.length
1036
  switch (length) {
1037
  case 1:
1038
- target[position++] = 0xd4
1039
- break
1040
  case 2:
1041
- target[position++] = 0xd5
1042
- break
1043
  case 4:
1044
- target[position++] = 0xd6
1045
- break
1046
  case 8:
1047
- target[position++] = 0xd7
1048
- break
1049
  case 16:
1050
- target[position++] = 0xd8
1051
- break
1052
  default:
1053
  if (length < 0x100) {
1054
- target[position++] = 0xc7
1055
- target[position++] = length
1056
  } else if (length < 0x10000) {
1057
- target[position++] = 0xc8
1058
- target[position++] = length >> 8
1059
- target[position++] = length & 0xff
1060
  } else {
1061
- target[position++] = 0xc9
1062
- target[position++] = length >> 24
1063
- target[position++] = (length >> 16) & 0xff
1064
- target[position++] = (length >> 8) & 0xff
1065
- target[position++] = length & 0xff
1066
  }
1067
  }
1068
- target[position++] = type
1069
- target.set(result, position)
1070
- position += length
1071
- return position
1072
  }
1073
 
1074
  function insertIds(serialized, idsToInsert) {
1075
  // insert the ids that need to be referenced for structured clones
1076
- let nextId
1077
- let distanceToMove = idsToInsert.length * 6
1078
- let lastEnd = serialized.length - distanceToMove
1079
  while (nextId = idsToInsert.pop()) {
1080
- let offset = nextId.offset
1081
- let id = nextId.id
1082
- serialized.copyWithin(offset + distanceToMove, offset, lastEnd)
1083
- distanceToMove -= 6
1084
- let position = offset + distanceToMove
1085
- serialized[position++] = 0xd6
1086
- serialized[position++] = 0x69 // 'i'
1087
- serialized[position++] = id >> 24
1088
- serialized[position++] = (id >> 16) & 0xff
1089
- serialized[position++] = (id >> 8) & 0xff
1090
- serialized[position++] = id & 0xff
1091
- lastEnd = offset
1092
  }
1093
- return serialized
1094
  }
1095
 
1096
  function writeBundles(start, pack, incrementPosition) {
1097
  if (bundledStrings.length > 0) {
1098
- targetView.setUint32(bundledStrings.position + start, position + incrementPosition - bundledStrings.position - start)
1099
  bundledStrings.stringsPosition = position - start;
1100
- let writeStrings = bundledStrings
1101
- bundledStrings = null
1102
- pack(writeStrings[0])
1103
- pack(writeStrings[1])
1104
  }
1105
  }
1106
 
1107
  export function addExtension(extension) {
1108
  if (extension.Class) {
1109
  if (!extension.pack && !extension.write)
1110
- throw new Error('Extension has no pack or write function')
1111
  if (extension.pack && !extension.type)
1112
- throw new Error('Extension has no type (numeric code to identify the extension)')
1113
- extensionClasses.unshift(extension.Class)
1114
- extensions.unshift(extension)
1115
  }
1116
- unpackAddExtension(extension)
1117
  }
1118
  function prepareStructures(structures, packr) {
1119
  structures.isCompatible = (existingStructures) => {
1120
- let compatible = !existingStructures || ((packr.lastNamedStructuresLength || 0) === existingStructures.length)
1121
  if (!compatible) // we want to merge these existing structures immediately since we already have it and we are in the right transaction
1122
  packr._mergeStructures(existingStructures);
1123
  return compatible;
1124
- }
1125
- return structures
1126
- }
1127
- export function setWriteStructSlots(writeSlots, makeStructures) {
1128
- writeStructSlots = writeSlots;
1129
- prepareStructures = makeStructures;
1130
  }
1131
 
1132
- let defaultPackr = new Packr({ useRecords: false })
1133
- export const pack = defaultPackr.pack
1134
- export const encode = defaultPackr.pack
1135
- export const Encoder = Packr
1136
- export { FLOAT32_OPTIONS } from './unpack.js'
1137
- import { FLOAT32_OPTIONS } from './unpack.js'
1138
- export const { NEVER, ALWAYS, DECIMAL_ROUND, DECIMAL_FIT } = FLOAT32_OPTIONS
1139
- export const REUSE_BUFFER_MODE = 512
1140
- export const RESET_BUFFER_MODE = 1024
1141
- export const RESERVE_START_SPACE = 2048
 
 
 
 
 
 
1
+ import { Unpackr, mult10, C1Type, typedArrays, addExtension as unpackAddExtension } from './unpack.js';
2
+ let textEncoder;
3
  try {
4
+ textEncoder = new TextEncoder();
5
  } catch (error) {}
6
+ let extensions, extensionClasses;
7
+ const hasNodeBuffer = typeof Buffer !== 'undefined';
8
  const ByteArrayAllocate = hasNodeBuffer ?
9
+ function(length) { return Buffer.allocUnsafeSlow(length); } : Uint8Array;
10
+ const ByteArray = hasNodeBuffer ? Buffer : Uint8Array;
11
+ const MAX_BUFFER_SIZE = hasNodeBuffer ? 0x100000000 : 0x7fd00000;
12
+ let target, keysTarget;
13
+ let targetView;
14
+ let position = 0;
15
+ let safeEnd;
16
+ let bundledStrings = null;
17
+ const MAX_BUNDLE_SIZE = 0x5500; // maximum characters such that the encoded bytes fits in 16 bits.
18
+ const hasNonLatin = /[\u0080-\uFFFF]/;
19
+ export const RECORD_SYMBOL = Symbol('record-id');
 
20
  export class Packr extends Unpackr {
21
  constructor(options) {
22
+ super(options);
23
+ this.offset = 0;
24
+ let typeBuffer;
25
+ let start;
26
+ let hasSharedUpdate;
27
+ let structures;
28
+ let referenceMap;
29
  let encodeUtf8 = ByteArray.prototype.utf8Write ? function(string, position) {
30
+ return target.utf8Write(string, position, target.byteLength - position);
31
  } : (textEncoder && textEncoder.encodeInto) ?
32
  function(string, position) {
33
+ return textEncoder.encodeInto(string, target.subarray(position)).written;
34
+ } : false;
35
 
36
+ let packr = this;
37
  if (!options)
38
+ options = {};
39
+ let isSequential = options && options.sequential;
40
+ let hasSharedStructures = options.structures || options.saveStructures;
41
+ let maxSharedStructures = options.maxSharedStructures;
42
  if (maxSharedStructures == null)
43
+ maxSharedStructures = hasSharedStructures ? 32 : 0;
44
  if (maxSharedStructures > 8160)
45
+ throw new Error('Maximum maxSharedStructure is 8160');
46
  if (options.structuredClone && options.moreTypes == undefined) {
47
+ this.moreTypes = true;
48
  }
49
+ let maxOwnStructures = options.maxOwnStructures;
50
  if (maxOwnStructures == null)
51
+ maxOwnStructures = hasSharedStructures ? 32 : 64;
52
  if (!this.structures && options.useRecords != false)
53
+ this.structures = [];
54
  // two byte record ids for shared structures
55
+ let useTwoByteRecords = maxSharedStructures > 32 || (maxOwnStructures + maxSharedStructures > 64);
56
+ let sharedLimitId = maxSharedStructures + 0x40;
57
+ let maxStructureId = maxSharedStructures + maxOwnStructures + 0x40;
58
  if (maxStructureId > 8256) {
59
+ throw new Error('Maximum maxSharedStructure + maxOwnStructure is 8192');
60
  }
61
+ let recordIdsToRemove = [];
62
+ let transitionsCount = 0;
63
+ let serializationsSinceTransitionRebuild = 0;
64
 
65
  this.pack = this.encode = function(value, encodeOptions) {
66
  if (!target) {
67
+ target = new ByteArrayAllocate(8192);
68
+ targetView = target.dataView || (target.dataView = new DataView(target.buffer, 0, 8192));
69
+ position = 0;
70
  }
71
+ safeEnd = target.length - 10;
72
  if (safeEnd - position < 0x800) {
73
  // don't start too close to the end,
74
+ target = new ByteArrayAllocate(target.length);
75
+ targetView = target.dataView || (target.dataView = new DataView(target.buffer, 0, target.length));
76
+ safeEnd = target.length - 10;
77
+ position = 0;
78
  } else
79
+ position = (position + 7) & 0x7ffffff8; // Word align to make any future copying of this buffer faster
80
+ start = position;
81
+ if (encodeOptions & RESERVE_START_SPACE) position += (encodeOptions & 0xff);
82
+ referenceMap = packr.structuredClone ? new Map() : null;
83
  if (packr.bundleStrings && typeof value !== 'string') {
84
+ bundledStrings = [];
85
+ bundledStrings.size = Infinity; // force a new bundle start on first string
86
  } else
87
+ bundledStrings = null;
88
+ structures = packr.structures;
89
  if (structures) {
90
  if (structures.uninitialized)
91
+ structures = packr._mergeStructures(packr.getStructures());
92
+ let sharedLength = structures.sharedLength || 0;
93
  if (sharedLength > maxSharedStructures) {
94
  //if (maxSharedStructures <= 32 && structures.sharedLength > 32) // TODO: could support this, but would need to update the limit ids
95
+ throw new Error('Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to ' + structures.sharedLength);
96
  }
97
  if (!structures.transitions) {
98
  // rebuild our structure transitions
99
+ structures.transitions = Object.create(null);
100
  for (let i = 0; i < sharedLength; i++) {
101
+ let keys = structures[i];
102
  if (!keys)
103
+ continue;
104
+ let nextTransition, transition = structures.transitions;
105
  for (let j = 0, l = keys.length; j < l; j++) {
106
+ let key = keys[j];
107
+ nextTransition = transition[key];
108
  if (!nextTransition) {
109
+ nextTransition = transition[key] = Object.create(null);
110
  }
111
+ transition = nextTransition;
112
  }
113
+ transition[RECORD_SYMBOL] = i + 0x40;
114
  }
115
+ this.lastNamedStructuresLength = sharedLength;
116
  }
117
  if (!isSequential) {
118
+ structures.nextId = sharedLength + 0x40;
119
  }
120
  }
121
  if (hasSharedUpdate)
122
+ hasSharedUpdate = false;
123
  let encodingError;
124
  try {
125
+ if (packr._writeStruct && value && typeof value === 'object') {
126
  if (value.constructor === Object) writeStruct(value); // simple object
127
  else if (value.constructor !== Map && !Array.isArray(value) && !extensionClasses.some(extClass => value instanceof extClass)) {
128
  // allow user classes, if they don't need special handling (but do use toJSON if available)
129
  writeStruct(value.toJSON ? value.toJSON() : value);
130
+ } else pack(value);
131
  } else
132
+ pack(value);
133
  let lastBundle = bundledStrings;
134
  if (bundledStrings)
135
+ writeBundles(start, pack, 0);
136
  if (referenceMap && referenceMap.idsToInsert) {
137
  let idsToInsert = referenceMap.idsToInsert.sort((a, b) => a.offset > b.offset ? 1 : -1);
138
  let i = idsToInsert.length;
 
148
  if (incrementPosition >= 0) {
149
  // update the bundle reference now
150
  targetView.setUint32(lastBundle.position + start,
151
+ targetView.getUint32(lastBundle.position + start) + incrementPosition);
152
  incrementPosition = -1; // reset
153
  }
154
  lastBundle = lastBundle.previous;
 
158
  if (incrementPosition >= 0 && lastBundle) {
159
  // update the bundle reference now
160
  targetView.setUint32(lastBundle.position + start,
161
+ targetView.getUint32(lastBundle.position + start) + incrementPosition);
162
  }
163
  position += idsToInsert.length * 6;
164
  if (position > safeEnd)
165
+ makeRoom(position);
166
+ packr.offset = position;
167
+ let serialized = insertIds(target.subarray(start, position), idsToInsert);
168
+ referenceMap = null;
169
+ return serialized;
170
  }
171
+ packr.offset = position; // update the offset so next serialization doesn't write over our buffer, but can continue writing to same buffer sequentially
172
  if (encodeOptions & REUSE_BUFFER_MODE) {
173
+ target.start = start;
174
+ target.end = position;
175
+ return target;
176
  }
177
+ return target.subarray(start, position); // position can change if we call pack again in saveStructures, so we get the buffer now
178
  } catch(error) {
179
  encodingError = error;
180
  throw error;
 
182
  if (structures) {
183
  resetStructures();
184
  if (hasSharedUpdate && packr.saveStructures) {
185
+ let sharedLength = structures.sharedLength || 0;
186
  // we can't rely on start/end with REUSE_BUFFER_MODE since they will (probably) change when we save
187
+ let returnBuffer = target.subarray(start, position);
188
+ let newSharedData = (packr._prepareStructures || prepareStructures)(structures, packr);
189
  if (!encodingError) { // TODO: If there is an encoding error, should make the structures as uninitialized so they get rebuilt next time
190
  if (packr.saveStructures(newSharedData, newSharedData.isCompatible) === false) {
191
+ // The save was declined (a concurrent writer updated the shared structures,
192
+ // or the store transaction did not durably commit). Our in-memory
193
+ // structures + transition trie may now reference record ids that were
194
+ // never persisted; re-packing as-is would re-emit the same record pointing
195
+ // at an unpersisted structure (-> "Record id is not defined" on decode).
196
+ // Mark structures uninitialized so the re-pack reloads durable structures
197
+ // via getStructures, rebuilds the transition trie, and re-mints + re-saves.
198
+ structures.uninitialized = true;
199
+ return packr.pack(value, encodeOptions);
200
  }
201
+ packr.lastNamedStructuresLength = sharedLength;
202
  // don't keep large buffers around
203
+ if (target.length > 0x40000000) target = null;
204
+ return returnBuffer;
205
  }
206
  }
207
  }
208
  // don't keep large buffers around, they take too much memory and cause problems (limit at 1GB)
209
+ if (target.length > 0x40000000) target = null;
210
  if (encodeOptions & RESET_BUFFER_MODE)
211
+ position = start;
212
  }
213
+ };
214
  const resetStructures = () => {
215
  if (serializationsSinceTransitionRebuild < 10)
216
+ serializationsSinceTransitionRebuild++;
217
+ let sharedLength = structures.sharedLength || 0;
218
  if (structures.length > sharedLength && !isSequential)
219
+ structures.length = sharedLength;
220
  if (transitionsCount > 10000) {
221
  // force a rebuild occasionally after a lot of transitions so it can get cleaned up
222
+ structures.transitions = null;
223
+ serializationsSinceTransitionRebuild = 0;
224
+ transitionsCount = 0;
225
  if (recordIdsToRemove.length > 0)
226
+ recordIdsToRemove = [];
227
  } else if (recordIdsToRemove.length > 0 && !isSequential) {
228
  for (let i = 0, l = recordIdsToRemove.length; i < l; i++) {
229
+ recordIdsToRemove[i][RECORD_SYMBOL] = 0;
230
  }
231
+ recordIdsToRemove = [];
232
  }
233
+ };
234
  const packArray = (value) => {
235
+ var length = value.length;
236
  if (length < 0x10) {
237
+ target[position++] = 0x90 | length;
238
  } else if (length < 0x10000) {
239
+ target[position++] = 0xdc;
240
+ target[position++] = length >> 8;
241
+ target[position++] = length & 0xff;
242
  } else {
243
+ target[position++] = 0xdd;
244
+ targetView.setUint32(position, length);
245
+ position += 4;
246
  }
247
  for (let i = 0; i < length; i++) {
248
+ pack(value[i]);
249
  }
250
+ };
251
  const pack = (value) => {
252
  if (position > safeEnd)
253
+ target = makeRoom(position);
254
 
255
+ var type = typeof value;
256
+ var length;
257
  if (type === 'string') {
258
+ let strLength = value.length;
259
  if (bundledStrings && strLength >= 4 && strLength < 0x1000) {
260
  if ((bundledStrings.size += strLength) > MAX_BUNDLE_SIZE) {
261
+ let extStart;
262
+ let maxBytes = (bundledStrings[0] ? bundledStrings[0].length * 3 + bundledStrings[1].length : 0) + 10;
263
  if (position + maxBytes > safeEnd)
264
+ target = makeRoom(position + maxBytes);
265
+ let lastBundle;
266
  if (bundledStrings.position) { // here we use the 0x62 extension to write the last bundle and reserve space for the reference pointer to the next/current bundle
267
+ lastBundle = bundledStrings;
268
+ target[position] = 0xc8; // ext 16
269
+ position += 3; // reserve for the writing bundle size
270
+ target[position++] = 0x62; // 'b'
271
+ extStart = position - start;
272
+ position += 4; // reserve for writing bundle reference
273
+ writeBundles(start, pack, 0); // write the last bundles
274
+ targetView.setUint16(extStart + start - 3, position - start - extStart);
275
  } else { // here we use the 0x62 extension just to reserve the space for the reference pointer to the bundle (will be updated once the bundle is written)
276
+ target[position++] = 0xd6; // fixext 4
277
+ target[position++] = 0x62; // 'b'
278
+ extStart = position - start;
279
+ position += 4; // reserve for writing bundle reference
280
  }
281
+ bundledStrings = ['', '']; // create new ones
282
  bundledStrings.previous = lastBundle;
283
+ bundledStrings.size = 0;
284
+ bundledStrings.position = extStart;
285
  }
286
+ let twoByte = hasNonLatin.test(value);
287
+ bundledStrings[twoByte ? 0 : 1] += value;
288
+ target[position++] = 0xc1;
289
  pack(twoByte ? -strLength : strLength);
290
+ return;
291
  }
292
+ let headerSize;
293
  // first we estimate the header size, so we can write to the correct location
294
  if (strLength < 0x20) {
295
+ headerSize = 1;
296
  } else if (strLength < 0x100) {
297
+ headerSize = 2;
298
  } else if (strLength < 0x10000) {
299
+ headerSize = 3;
300
  } else {
301
+ headerSize = 5;
302
  }
303
+ let maxBytes = strLength * 3;
304
  if (position + maxBytes > safeEnd)
305
+ target = makeRoom(position + maxBytes);
306
 
307
  if (strLength < 0x40 || !encodeUtf8) {
308
+ let i, c1, c2, strPosition = position + headerSize;
309
  for (i = 0; i < strLength; i++) {
310
+ c1 = value.charCodeAt(i);
311
  if (c1 < 0x80) {
312
+ target[strPosition++] = c1;
313
  } else if (c1 < 0x800) {
314
+ target[strPosition++] = c1 >> 6 | 0xc0;
315
+ target[strPosition++] = c1 & 0x3f | 0x80;
316
  } else if (
317
  (c1 & 0xfc00) === 0xd800 &&
318
  ((c2 = value.charCodeAt(i + 1)) & 0xfc00) === 0xdc00
319
  ) {
320
+ c1 = 0x10000 + ((c1 & 0x03ff) << 10) + (c2 & 0x03ff);
321
+ i++;
322
+ target[strPosition++] = c1 >> 18 | 0xf0;
323
+ target[strPosition++] = c1 >> 12 & 0x3f | 0x80;
324
+ target[strPosition++] = c1 >> 6 & 0x3f | 0x80;
325
+ target[strPosition++] = c1 & 0x3f | 0x80;
326
  } else {
327
+ target[strPosition++] = c1 >> 12 | 0xe0;
328
+ target[strPosition++] = c1 >> 6 & 0x3f | 0x80;
329
+ target[strPosition++] = c1 & 0x3f | 0x80;
330
  }
331
  }
332
+ length = strPosition - position - headerSize;
333
  } else {
334
+ length = encodeUtf8(value, position + headerSize);
335
  }
336
 
337
  if (length < 0x20) {
338
+ target[position++] = 0xa0 | length;
339
  } else if (length < 0x100) {
340
  if (headerSize < 2) {
341
+ target.copyWithin(position + 2, position + 1, position + 1 + length);
342
  }
343
+ target[position++] = 0xd9;
344
+ target[position++] = length;
345
  } else if (length < 0x10000) {
346
  if (headerSize < 3) {
347
+ target.copyWithin(position + 3, position + 2, position + 2 + length);
348
  }
349
+ target[position++] = 0xda;
350
+ target[position++] = length >> 8;
351
+ target[position++] = length & 0xff;
352
  } else {
353
  if (headerSize < 5) {
354
+ target.copyWithin(position + 5, position + 3, position + 3 + length);
355
  }
356
+ target[position++] = 0xdb;
357
+ targetView.setUint32(position, length);
358
+ position += 4;
359
  }
360
+ position += length;
361
  } else if (type === 'number') {
362
  if (value >>> 0 === value) {// positive integer, 32-bit or less
363
  // positive uint
364
+ if (value < 0x20 || (value < 0x80 && this.useRecords === false) || (value < 0x40 && !this._writeStruct)) {
365
+ target[position++] = value;
366
  } else if (value < 0x100) {
367
+ target[position++] = 0xcc;
368
+ target[position++] = value;
369
  } else if (value < 0x10000) {
370
+ target[position++] = 0xcd;
371
+ target[position++] = value >> 8;
372
+ target[position++] = value & 0xff;
373
  } else {
374
+ target[position++] = 0xce;
375
+ targetView.setUint32(position, value);
376
+ position += 4;
377
  }
378
  } else if (value >> 0 === value) { // negative integer
379
  if (value >= -0x20) {
380
+ target[position++] = 0x100 + value;
381
  } else if (value >= -0x80) {
382
+ target[position++] = 0xd0;
383
+ target[position++] = value + 0x100;
384
  } else if (value >= -0x8000) {
385
+ target[position++] = 0xd1;
386
+ targetView.setInt16(position, value);
387
+ position += 2;
388
  } else {
389
+ target[position++] = 0xd2;
390
+ targetView.setInt32(position, value);
391
+ position += 4;
392
  }
393
  } else {
394
+ let useFloat32;
395
  if ((useFloat32 = this.useFloat32) > 0 && value < 0x100000000 && value >= -0x80000000) {
396
+ target[position++] = 0xca;
397
+ targetView.setFloat32(position, value);
398
+ let xShifted;
399
  if (useFloat32 < 4 ||
400
  // this checks for rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
401
  ((xShifted = value * mult10[((target[position] & 0x7f) << 1) | (target[position + 1] >> 7)]) >> 0) === xShifted) {
402
+ position += 4;
403
+ return;
404
  } else
405
+ position--; // move back into position for writing a double
406
  }
407
+ target[position++] = 0xcb;
408
+ targetView.setFloat64(position, value);
409
+ position += 8;
410
  }
411
  } else if (type === 'object' || type === 'function') {
412
  if (!value)
413
+ target[position++] = 0xc0;
414
  else {
415
  if (referenceMap) {
416
+ let referee = referenceMap.get(value);
417
  if (referee) {
418
  if (!referee.id) {
419
+ let idsToInsert = referenceMap.idsToInsert || (referenceMap.idsToInsert = []);
420
+ referee.id = idsToInsert.push(referee);
421
  }
422
+ target[position++] = 0xd6; // fixext 4
423
+ target[position++] = 0x70; // "p" for pointer
424
+ targetView.setUint32(position, referee.id);
425
+ position += 4;
426
+ return;
427
  } else
428
+ referenceMap.set(value, { offset: position - start });
429
  }
430
+ let constructor = value.constructor;
431
  if (constructor === Object) {
432
+ writeObject(value);
433
  } else if (constructor === Array) {
434
+ packArray(value);
435
  } else if (constructor === Map) {
436
+ if (this.mapAsEmptyObject) target[position++] = 0x80;
437
  else {
438
+ length = value.size;
439
  if (length < 0x10) {
440
+ target[position++] = 0x80 | length;
441
  } else if (length < 0x10000) {
442
+ target[position++] = 0xde;
443
+ target[position++] = length >> 8;
444
+ target[position++] = length & 0xff;
445
  } else {
446
+ target[position++] = 0xdf;
447
+ targetView.setUint32(position, length);
448
+ position += 4;
449
  }
450
  for (let [key, entryValue] of value) {
451
+ pack(key);
452
+ pack(entryValue);
453
  }
454
  }
455
  } else {
456
  for (let i = 0, l = extensions.length; i < l; i++) {
457
+ let extensionClass = extensionClasses[i];
458
  if (value instanceof extensionClass) {
459
+ let extension = extensions[i];
460
  if (extension.write) {
461
  if (extension.type) {
462
+ target[position++] = 0xd4; // one byte "tag" extension
463
+ target[position++] = extension.type;
464
+ target[position++] = 0;
465
  }
466
+ let writeResult = extension.write.call(this, value);
467
  if (writeResult === value) { // avoid infinite recursion
468
  if (Array.isArray(value)) {
469
+ packArray(value);
470
  } else {
471
+ writeObject(value);
472
  }
473
  } else {
474
+ pack(writeResult);
475
  }
476
+ return;
477
  }
478
+ let currentTarget = target;
479
+ let currentTargetView = targetView;
480
+ let currentPosition = position;
481
+ target = null;
482
+ let result;
483
  try {
484
  result = extension.pack.call(this, value, (size) => {
485
  // restore target and use it
486
+ target = currentTarget;
487
+ currentTarget = null;
488
+ position += size;
489
  if (position > safeEnd)
490
+ makeRoom(position);
491
  return {
492
  target, targetView, position: position - size
493
+ };
494
+ }, pack);
495
  } finally {
496
  // restore current target information (unless already restored)
497
  if (currentTarget) {
498
+ target = currentTarget;
499
+ targetView = currentTargetView;
500
+ position = currentPosition;
501
+ safeEnd = target.length - 10;
502
  }
503
  }
504
  if (result) {
505
  if (result.length + position > safeEnd)
506
+ makeRoom(result.length + position);
507
+ position = writeExtensionData(result, target, position, extension.type);
508
  }
509
+ return;
510
  }
511
  }
512
  // check isArray after extensions, because extensions can extend Array
513
  if (Array.isArray(value)) {
514
+ packArray(value);
515
  } else {
516
  // use this as an alternate mechanism for expressing how to serialize
517
  if (value.toJSON) {
518
+ const json = value.toJSON();
519
  // if for some reason value.toJSON returns itself it'll loop forever
520
  if (json !== value)
521
+ return pack(json);
522
  }
523
 
524
  // if there is a writeFunction, use it, otherwise just encode as undefined
 
526
  return pack(this.writeFunction && this.writeFunction(value));
527
 
528
  // no extension found, write as plain object
529
+ writeObject(value);
530
  }
531
  }
532
  }
533
  } else if (type === 'boolean') {
534
+ target[position++] = value ? 0xc3 : 0xc2;
535
  } else if (type === 'bigint') {
536
  if (value < 0x8000000000000000 && value >= -0x8000000000000000) {
537
  // use a signed int as long as it fits
538
+ target[position++] = 0xd3;
539
+ targetView.setBigInt64(position, value);
540
  } else if (value < 0x10000000000000000 && value > 0) {
541
  // if we can fit an unsigned int, use that
542
+ target[position++] = 0xcf;
543
+ targetView.setBigUint64(position, value);
544
  } else {
545
  // overflow
546
  if (this.largeBigIntToFloat) {
547
+ target[position++] = 0xcb;
548
+ targetView.setFloat64(position, Number(value));
549
  } else if (this.largeBigIntToString) {
550
  return pack(value.toString());
551
  } else if (this.useBigIntExtension || this.moreTypes) {
552
+ let empty = value < 0 ? BigInt(-1) : BigInt(0);
553
 
554
+ let array;
555
  if (value >> BigInt(0x10000) === empty) {
556
+ let mask = BigInt(0x10000000000000000) - BigInt(1); // literal would overflow
557
+ let chunks = [];
558
  while (true) {
559
+ chunks.push(value & mask);
560
+ if ((value >> BigInt(63)) === empty) break;
561
+ value >>= BigInt(64);
562
  }
563
 
564
+ array = new Uint8Array(new BigUint64Array(chunks).buffer);
565
+ array.reverse();
566
  } else {
567
+ let invert = value < 0;
568
+ let string = (invert ? ~value : value).toString(16);
569
  if (string.length % 2) {
570
+ string = '0' + string;
571
  } else if (parseInt(string.charAt(0), 16) >= 8) {
572
+ string = '00' + string;
573
  }
574
 
575
  if (hasNodeBuffer) {
576
+ array = Buffer.from(string, 'hex');
577
  } else {
578
+ array = new Uint8Array(string.length / 2);
579
  for (let i = 0; i < array.length; i++) {
580
+ array[i] = parseInt(string.slice(i * 2, i * 2 + 2), 16);
581
  }
582
  }
583
 
584
  if (invert) {
585
+ for (let i = 0; i < array.length; i++) array[i] = ~array[i];
586
  }
587
  }
588
 
589
  if (array.length + position > safeEnd)
590
+ makeRoom(array.length + position);
591
+ position = writeExtensionData(array, target, position, 0x42);
592
+ return;
593
  } else {
594
  throw new RangeError(value + ' was too large to fit in MessagePack 64-bit integer format, use' +
595
  ' useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set' +
596
+ ' largeBigIntToString to convert to string');
597
  }
598
  }
599
+ position += 8;
600
  } else if (type === 'undefined') {
601
  if (this.encodeUndefinedAsNil)
602
+ target[position++] = 0xc0;
603
  else {
604
+ target[position++] = 0xd4; // a number of implementations use fixext1 with type 0, data 0 to denote undefined, so we follow suite
605
+ target[position++] = 0;
606
+ target[position++] = 0;
607
  }
608
  } else {
609
+ throw new Error('Unknown type: ' + type);
610
  }
611
+ };
612
 
613
  const writePlainObject = (this.variableMapSize || this.coercibleKeyAsNumber || this.skipValues) ? (object) => {
614
  // this method is slightly slower, but generates "preferred serialization" (optimally small for smaller objects)
 
621
  keys.push(key);
622
  }
623
  } else {
624
+ keys = Object.keys(object);
625
  }
626
+ let length = keys.length;
627
  if (length < 0x10) {
628
+ target[position++] = 0x80 | length;
629
  } else if (length < 0x10000) {
630
+ target[position++] = 0xde;
631
+ target[position++] = length >> 8;
632
+ target[position++] = length & 0xff;
633
  } else {
634
+ target[position++] = 0xdf;
635
+ targetView.setUint32(position, length);
636
+ position += 4;
637
  }
638
+ let key;
639
  if (this.coercibleKeyAsNumber) {
640
  for (let i = 0; i < length; i++) {
641
+ key = keys[i];
642
+ let num = Number(key);
643
+ pack(isNaN(num) ? key : num);
644
+ pack(object[key]);
645
  }
646
 
647
  } else {
648
  for (let i = 0; i < length; i++) {
649
+ pack(key = keys[i]);
650
+ pack(object[key]);
651
  }
652
  }
653
  } :
654
  (object) => {
655
+ target[position++] = 0xde; // always using map 16, so we can preallocate and set the length afterwards
656
+ let objectOffset = position - start;
657
+ position += 2;
658
+ let size = 0;
659
  for (let key in object) {
660
  if (typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key)) {
661
+ pack(key);
662
+ pack(object[key]);
663
+ size++;
664
  }
665
  }
666
  if (size > 0xffff) {
667
  throw new Error('Object is too large to serialize with fast 16-bit map size,' +
668
  ' use the "variableMapSize" option to serialize this object');
669
  }
670
+ target[objectOffset++ + start] = size >> 8;
671
+ target[objectOffset + start] = size & 0xff;
672
+ };
673
 
674
  const writeRecord = this.useRecords === false ? writePlainObject :
675
  (options.progressiveRecords && !useTwoByteRecords) ? // this is about 2% faster for highly stable structures, since it only requires one for-in loop (but much more expensive when new structure needs to be written)
676
  (object) => {
677
+ let nextTransition, transition = structures.transitions || (structures.transitions = Object.create(null));
678
+ let objectOffset = position++ - start;
679
+ let wroteKeys;
680
  for (let key in object) {
681
  if (typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key)) {
682
+ nextTransition = transition[key];
683
  if (nextTransition)
684
+ transition = nextTransition;
685
  else {
686
  // record doesn't exist, create full new record and insert it
687
+ let keys = Object.keys(object);
688
+ let lastTransition = transition;
689
+ transition = structures.transitions;
690
+ let newTransitions = 0;
691
  for (let i = 0, l = keys.length; i < l; i++) {
692
+ let key = keys[i];
693
+ nextTransition = transition[key];
694
  if (!nextTransition) {
695
+ nextTransition = transition[key] = Object.create(null);
696
+ newTransitions++;
697
  }
698
+ transition = nextTransition;
699
  }
700
  if (objectOffset + start + 1 == position) {
701
  // first key, so we don't need to insert, we can just write record directly
702
+ position--;
703
+ newRecord(transition, keys, newTransitions);
704
  } else // otherwise we need to insert the record, moving existing data after the record
705
+ insertNewRecord(transition, keys, objectOffset, newTransitions);
706
+ wroteKeys = true;
707
+ transition = lastTransition[key];
708
  }
709
+ pack(object[key]);
710
  }
711
  }
712
  if (!wroteKeys) {
713
+ let recordId = transition[RECORD_SYMBOL];
714
  if (recordId)
715
+ target[objectOffset + start] = recordId;
716
  else
717
+ insertNewRecord(transition, Object.keys(object), objectOffset, 0);
718
  }
719
  } :
720
  (object) => {
721
+ let nextTransition, transition = structures.transitions || (structures.transitions = Object.create(null));
722
+ let newTransitions = 0;
723
  for (let key in object) if (typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key)) {
724
+ nextTransition = transition[key];
725
  if (!nextTransition) {
726
+ nextTransition = transition[key] = Object.create(null);
727
+ newTransitions++;
728
  }
729
+ transition = nextTransition;
730
  }
731
+ let recordId = transition[RECORD_SYMBOL];
732
  if (recordId) {
733
  if (recordId >= 0x60 && useTwoByteRecords) {
734
+ target[position++] = ((recordId -= 0x60) & 0x1f) + 0x60;
735
+ target[position++] = recordId >> 5;
736
  } else
737
+ target[position++] = recordId;
738
  } else {
739
+ newRecord(transition, transition.__keys__ || Object.keys(object), newTransitions);
740
  }
741
  // now write the values
742
  for (let key in object)
743
  if (typeof object.hasOwnProperty !== 'function' || object.hasOwnProperty(key)) {
744
+ pack(object[key]);
745
  }
746
+ };
747
 
748
  // create reference to useRecords if useRecords is a function
749
  const checkUseRecords = typeof this.useRecords == 'function' && this.useRecords;
750
 
751
  const writeObject = checkUseRecords ? (object) => {
752
+ checkUseRecords(object) ? writeRecord(object) : writePlainObject(object);
753
+ } : writeRecord;
754
+
755
+ const writeStruct = (object) => {
756
+ let newPosition = packr._writeStruct(object, target, start, position, structures, makeRoom, (value, newPosition, notifySharedUpdate) => {
757
+ if (notifySharedUpdate)
758
+ return hasSharedUpdate = true;
759
+ position = newPosition;
760
+ let startTarget = target;
761
+ pack(value);
762
+ resetStructures();
763
+ if (startTarget !== target) {
764
+ return { position, targetView, target }; // indicate the buffer was re-allocated
765
+ }
766
+ return position;
767
+ });
768
+ if (newPosition === 0) // bail and go to a msgpack object
769
+ return writeObject(object);
770
+ position = newPosition;
771
+ };
772
 
773
  const makeRoom = (end) => {
774
+ let newSize;
775
  if (end > 0x1000000) {
776
  // special handling for really large buffers
777
  if ((end - start) > MAX_BUFFER_SIZE)
778
+ throw new Error('Packed buffer would be larger than maximum buffer size');
779
  newSize = Math.min(MAX_BUFFER_SIZE,
780
+ Math.round(Math.max((end - start) * (end > 0x4000000 ? 1.25 : 2), 0x400000) / 0x1000) * 0x1000);
781
  } else // faster handling for smaller buffers
782
+ newSize = ((Math.max((end - start) << 2, target.length - 1) >> 12) + 1) << 12;
783
+ let newBuffer = new ByteArrayAllocate(newSize);
784
+ targetView = newBuffer.dataView || (newBuffer.dataView = new DataView(newBuffer.buffer, 0, newSize));
785
+ end = Math.min(end, target.length);
786
  if (target.copy)
787
+ target.copy(newBuffer, 0, start, end);
788
  else
789
+ newBuffer.set(target.slice(start, end));
790
+ position -= start;
791
+ start = 0;
792
+ safeEnd = newBuffer.length - 10;
793
+ return target = newBuffer;
794
+ };
795
  const newRecord = (transition, keys, newTransitions) => {
796
+ let recordId = structures.nextId;
797
  if (!recordId)
798
+ recordId = 0x40;
799
  if (recordId < sharedLimitId && this.shouldShareStructure && !this.shouldShareStructure(keys)) {
800
+ recordId = structures.nextOwnId;
801
  if (!(recordId < maxStructureId))
802
+ recordId = sharedLimitId;
803
+ structures.nextOwnId = recordId + 1;
804
  } else {
805
  if (recordId >= maxStructureId)// cycle back around
806
+ recordId = sharedLimitId;
807
+ structures.nextId = recordId + 1;
808
  }
809
+ let highByte = keys.highByte = recordId >= 0x60 && useTwoByteRecords ? (recordId - 0x60) >> 5 : -1;
810
+ transition[RECORD_SYMBOL] = recordId;
811
+ transition.__keys__ = keys;
812
+ structures[recordId - 0x40] = keys;
813
 
814
  if (recordId < sharedLimitId) {
815
+ keys.isShared = true;
816
+ structures.sharedLength = recordId - 0x3f;
817
+ hasSharedUpdate = true;
818
  if (highByte >= 0) {
819
+ target[position++] = (recordId & 0x1f) + 0x60;
820
+ target[position++] = highByte;
821
  } else {
822
+ target[position++] = recordId;
823
  }
824
  } else {
825
  if (highByte >= 0) {
826
+ target[position++] = 0xd5; // fixext 2
827
+ target[position++] = 0x72; // "r" record defintion extension type
828
+ target[position++] = (recordId & 0x1f) + 0x60;
829
+ target[position++] = highByte;
830
  } else {
831
+ target[position++] = 0xd4; // fixext 1
832
+ target[position++] = 0x72; // "r" record defintion extension type
833
+ target[position++] = recordId;
834
  }
835
 
836
  if (newTransitions)
837
+ transitionsCount += serializationsSinceTransitionRebuild * newTransitions;
838
  // record the removal of the id, we can maintain our shared structure
839
  if (recordIdsToRemove.length >= maxOwnStructures)
840
+ recordIdsToRemove.shift()[RECORD_SYMBOL] = 0; // we are cycling back through, and have to remove old ones
841
+ recordIdsToRemove.push(transition);
842
+ pack(keys);
843
  }
844
+ };
845
  const insertNewRecord = (transition, keys, insertionOffset, newTransitions) => {
846
+ let mainTarget = target;
847
+ let mainPosition = position;
848
+ let mainSafeEnd = safeEnd;
849
+ let mainStart = start;
850
+ target = keysTarget;
851
+ position = 0;
852
+ start = 0;
853
  if (!target)
854
+ keysTarget = target = new ByteArrayAllocate(8192);
855
+ safeEnd = target.length - 10;
856
+ newRecord(transition, keys, newTransitions);
857
+ keysTarget = target;
858
+ let keysPosition = position;
859
+ target = mainTarget;
860
+ position = mainPosition;
861
+ safeEnd = mainSafeEnd;
862
+ start = mainStart;
863
  if (keysPosition > 1) {
864
+ let newEnd = position + keysPosition - 1;
865
  if (newEnd > safeEnd)
866
+ makeRoom(newEnd);
867
+ let insertionPosition = insertionOffset + start;
868
+ target.copyWithin(insertionPosition + keysPosition, insertionPosition + 1, position);
869
+ target.set(keysTarget.slice(0, keysPosition), insertionPosition);
870
+ position = newEnd;
871
  } else {
872
+ target[insertionOffset + start] = keysTarget[0];
873
  }
874
+ };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
875
  }
876
  useBuffer(buffer) {
877
  // this means we are finished using our own buffer and we can write over it safely
878
+ target = buffer;
879
+ target.dataView || (target.dataView = new DataView(target.buffer, target.byteOffset, target.byteLength));
880
  targetView = target.dataView;
881
+ position = 0;
882
  }
883
  set position (value) {
884
  position = value;
 
888
  }
889
  clearSharedData() {
890
  if (this.structures)
891
+ this.structures = [];
892
  if (this.typedStructs)
893
+ this.typedStructs = [];
894
  }
895
  }
896
 
897
+ extensionClasses = [ Date, Set, Error, RegExp, ArrayBuffer, Object.getPrototypeOf(Uint8Array.prototype).constructor /*TypedArray*/, DataView, C1Type ];
898
  extensions = [{
899
  pack(date, allocateForWrite, pack) {
900
+ let seconds = date.getTime() / 1000;
901
  if ((this.useTimestamp32 || date.getMilliseconds() === 0) && seconds >= 0 && seconds < 0x100000000) {
902
  // Timestamp 32
903
+ let { target, targetView, position} = allocateForWrite(6);
904
+ target[position++] = 0xd6;
905
+ target[position++] = 0xff;
906
+ targetView.setUint32(position, seconds);
907
  } else if (seconds > 0 && seconds < 0x100000000) {
908
  // Timestamp 64
909
+ let { target, targetView, position} = allocateForWrite(10);
910
+ target[position++] = 0xd7;
911
+ target[position++] = 0xff;
912
+ targetView.setUint32(position, date.getMilliseconds() * 4000000 + ((seconds / 1000 / 0x100000000) >> 0));
913
+ targetView.setUint32(position + 4, seconds);
914
  } else if (isNaN(seconds)) {
915
  if (this.onInvalidDate) {
916
+ allocateForWrite(0);
917
+ return pack(this.onInvalidDate());
918
  }
919
  // Intentionally invalid timestamp
920
+ let { target, targetView, position} = allocateForWrite(3);
921
+ target[position++] = 0xd4;
922
+ target[position++] = 0xff;
923
+ target[position++] = 0xff;
924
  } else {
925
  // Timestamp 96
926
+ let { target, targetView, position} = allocateForWrite(15);
927
+ target[position++] = 0xc7;
928
+ target[position++] = 12;
929
+ target[position++] = 0xff;
930
+ targetView.setUint32(position, date.getMilliseconds() * 1000000);
931
+ targetView.setBigInt64(position + 4, BigInt(Math.floor(seconds)));
932
  }
933
  }
934
  }, {
935
  pack(set, allocateForWrite, pack) {
936
  if (this.setAsEmptyObject) {
937
  allocateForWrite(0);
938
+ return pack({});
939
  }
940
+ let array = Array.from(set);
941
+ let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
942
  if (this.moreTypes) {
943
+ target[position++] = 0xd4;
944
+ target[position++] = 0x73; // 's' for Set
945
+ target[position++] = 0;
946
  }
947
+ pack(array);
948
  }
949
  }, {
950
  pack(error, allocateForWrite, pack) {
951
+ let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
952
  if (this.moreTypes) {
953
+ target[position++] = 0xd4;
954
+ target[position++] = 0x65; // 'e' for error
955
+ target[position++] = 0;
956
  }
957
+ pack([ error.name, error.message, error.cause ]);
958
  }
959
  }, {
960
  pack(regex, allocateForWrite, pack) {
961
+ let { target, position} = allocateForWrite(this.moreTypes ? 3 : 0);
962
  if (this.moreTypes) {
963
+ target[position++] = 0xd4;
964
+ target[position++] = 0x78; // 'x' for regeXp
965
+ target[position++] = 0;
966
  }
967
+ pack([ regex.source, regex.flags ]);
968
  }
969
  }, {
970
  pack(arrayBuffer, allocateForWrite) {
971
  if (this.moreTypes)
972
+ writeExtBuffer(arrayBuffer, 0x10, allocateForWrite);
973
  else
974
+ writeBuffer(hasNodeBuffer ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite);
975
  }
976
  }, {
977
  pack(typedArray, allocateForWrite) {
978
+ let constructor = typedArray.constructor;
979
  if (constructor !== ByteArray && this.moreTypes)
980
+ writeExtBuffer(typedArray, typedArrays.indexOf(constructor.name), allocateForWrite);
981
  else
982
+ writeBuffer(typedArray, allocateForWrite);
983
  }
984
  }, {
985
  pack(arrayBuffer, allocateForWrite) {
986
  if (this.moreTypes)
987
+ writeExtBuffer(arrayBuffer, 0x11, allocateForWrite);
988
  else
989
+ writeBuffer(hasNodeBuffer ? Buffer.from(arrayBuffer) : new Uint8Array(arrayBuffer), allocateForWrite);
990
  }
991
  }, {
992
  pack(c1, allocateForWrite) { // specific 0xC1 object
993
+ let { target, position} = allocateForWrite(1);
994
+ target[position] = 0xc1;
995
  }
996
+ }];
997
 
998
  function writeExtBuffer(typedArray, type, allocateForWrite, encode) {
999
+ let length = typedArray.byteLength;
1000
  if (length + 1 < 0x100) {
1001
+ var { target, position } = allocateForWrite(4 + length);
1002
+ target[position++] = 0xc7;
1003
+ target[position++] = length + 1;
1004
  } else if (length + 1 < 0x10000) {
1005
+ var { target, position } = allocateForWrite(5 + length);
1006
+ target[position++] = 0xc8;
1007
+ target[position++] = (length + 1) >> 8;
1008
+ target[position++] = (length + 1) & 0xff;
1009
  } else {
1010
+ var { target, position, targetView } = allocateForWrite(7 + length);
1011
+ target[position++] = 0xc9;
1012
+ targetView.setUint32(position, length + 1); // plus one for the type byte
1013
+ position += 4;
1014
  }
1015
+ target[position++] = 0x74; // "t" for typed array
1016
+ target[position++] = type;
1017
+ if (!typedArray.buffer) typedArray = new Uint8Array(typedArray);
1018
+ target.set(new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength), position);
1019
  }
1020
  function writeBuffer(buffer, allocateForWrite) {
1021
+ let length = buffer.byteLength;
1022
+ var target, position;
1023
  if (length < 0x100) {
1024
+ var { target, position } = allocateForWrite(length + 2);
1025
+ target[position++] = 0xc4;
1026
+ target[position++] = length;
1027
  } else if (length < 0x10000) {
1028
+ var { target, position } = allocateForWrite(length + 3);
1029
+ target[position++] = 0xc5;
1030
+ target[position++] = length >> 8;
1031
+ target[position++] = length & 0xff;
1032
  } else {
1033
+ var { target, position, targetView } = allocateForWrite(length + 5);
1034
+ target[position++] = 0xc6;
1035
+ targetView.setUint32(position, length);
1036
+ position += 4;
1037
  }
1038
+ target.set(buffer, position);
1039
  }
1040
 
1041
  function writeExtensionData(result, target, position, type) {
1042
+ let length = result.length;
1043
  switch (length) {
1044
  case 1:
1045
+ target[position++] = 0xd4;
1046
+ break;
1047
  case 2:
1048
+ target[position++] = 0xd5;
1049
+ break;
1050
  case 4:
1051
+ target[position++] = 0xd6;
1052
+ break;
1053
  case 8:
1054
+ target[position++] = 0xd7;
1055
+ break;
1056
  case 16:
1057
+ target[position++] = 0xd8;
1058
+ break;
1059
  default:
1060
  if (length < 0x100) {
1061
+ target[position++] = 0xc7;
1062
+ target[position++] = length;
1063
  } else if (length < 0x10000) {
1064
+ target[position++] = 0xc8;
1065
+ target[position++] = length >> 8;
1066
+ target[position++] = length & 0xff;
1067
  } else {
1068
+ target[position++] = 0xc9;
1069
+ target[position++] = length >> 24;
1070
+ target[position++] = (length >> 16) & 0xff;
1071
+ target[position++] = (length >> 8) & 0xff;
1072
+ target[position++] = length & 0xff;
1073
  }
1074
  }
1075
+ target[position++] = type;
1076
+ target.set(result, position);
1077
+ position += length;
1078
+ return position;
1079
  }
1080
 
1081
  function insertIds(serialized, idsToInsert) {
1082
  // insert the ids that need to be referenced for structured clones
1083
+ let nextId;
1084
+ let distanceToMove = idsToInsert.length * 6;
1085
+ let lastEnd = serialized.length - distanceToMove;
1086
  while (nextId = idsToInsert.pop()) {
1087
+ let offset = nextId.offset;
1088
+ let id = nextId.id;
1089
+ serialized.copyWithin(offset + distanceToMove, offset, lastEnd);
1090
+ distanceToMove -= 6;
1091
+ let position = offset + distanceToMove;
1092
+ serialized[position++] = 0xd6;
1093
+ serialized[position++] = 0x69; // 'i'
1094
+ serialized[position++] = id >> 24;
1095
+ serialized[position++] = (id >> 16) & 0xff;
1096
+ serialized[position++] = (id >> 8) & 0xff;
1097
+ serialized[position++] = id & 0xff;
1098
+ lastEnd = offset;
1099
  }
1100
+ return serialized;
1101
  }
1102
 
1103
  function writeBundles(start, pack, incrementPosition) {
1104
  if (bundledStrings.length > 0) {
1105
+ targetView.setUint32(bundledStrings.position + start, position + incrementPosition - bundledStrings.position - start);
1106
  bundledStrings.stringsPosition = position - start;
1107
+ let writeStrings = bundledStrings;
1108
+ bundledStrings = null;
1109
+ pack(writeStrings[0]);
1110
+ pack(writeStrings[1]);
1111
  }
1112
  }
1113
 
1114
  export function addExtension(extension) {
1115
  if (extension.Class) {
1116
  if (!extension.pack && !extension.write)
1117
+ throw new Error('Extension has no pack or write function');
1118
  if (extension.pack && !extension.type)
1119
+ throw new Error('Extension has no type (numeric code to identify the extension)');
1120
+ extensionClasses.unshift(extension.Class);
1121
+ extensions.unshift(extension);
1122
  }
1123
+ unpackAddExtension(extension);
1124
  }
1125
  function prepareStructures(structures, packr) {
1126
  structures.isCompatible = (existingStructures) => {
1127
+ let compatible = !existingStructures || ((packr.lastNamedStructuresLength || 0) === existingStructures.length);
1128
  if (!compatible) // we want to merge these existing structures immediately since we already have it and we are in the right transaction
1129
  packr._mergeStructures(existingStructures);
1130
  return compatible;
1131
+ };
1132
+ return structures;
 
 
 
 
1133
  }
1134
 
1135
+ // Marker for downstream libraries (e.g. structon) to detect that this Packr
1136
+ // supports per-instance struct-encoding hooks (this._writeStruct,
1137
+ // this._prepareStructures). See `pack` for the dispatch.
1138
+ Packr.SUPPORTS_STRUCT_HOOKS = true;
1139
+
1140
+ let defaultPackr = new Packr({ useRecords: false });
1141
+ export const pack = defaultPackr.pack;
1142
+ export const encode = defaultPackr.pack;
1143
+ export const Encoder = Packr;
1144
+ export { FLOAT32_OPTIONS } from './unpack.js';
1145
+ import { FLOAT32_OPTIONS } from './unpack.js';
1146
+ export const { NEVER, ALWAYS, DECIMAL_ROUND, DECIMAL_FIT } = FLOAT32_OPTIONS;
1147
+ export const REUSE_BUFFER_MODE = 512;
1148
+ export const RESET_BUFFER_MODE = 1024;
1149
+ export const RESERVE_START_SPACE = 2048;
.opencode/node_modules/msgpackr/package.json CHANGED
@@ -1,7 +1,7 @@
1
  {
2
  "name": "msgpackr",
3
  "author": "Kris Zyp",
4
- "version": "1.11.12",
5
  "description": "Ultra-fast MessagePack implementation with extensions for records and structured cloning",
6
  "license": "MIT",
7
  "types": "./index.d.ts",
@@ -87,7 +87,7 @@
87
  "/*.cts"
88
  ],
89
  "optionalDependencies": {
90
- "msgpackr-extract": "^3.0.2"
91
  },
92
  "devDependencies": {
93
  "@rollup/plugin-json": "^5.0.1",
 
1
  {
2
  "name": "msgpackr",
3
  "author": "Kris Zyp",
4
+ "version": "2.0.5",
5
  "description": "Ultra-fast MessagePack implementation with extensions for records and structured cloning",
6
  "license": "MIT",
7
  "types": "./index.d.ts",
 
87
  "/*.cts"
88
  ],
89
  "optionalDependencies": {
90
+ "msgpackr-extract": "^3.0.4"
91
  },
92
  "devDependencies": {
93
  "@rollup/plugin-json": "^5.0.1",
.opencode/node_modules/msgpackr/stream.js CHANGED
@@ -1,62 +1,62 @@
1
- import { Transform } from 'stream'
2
- import { Packr } from './pack.js'
3
- import { Unpackr } from './unpack.js'
4
- var DEFAULT_OPTIONS = {objectMode: true}
5
 
6
  export class PackrStream extends Transform {
7
  constructor(options) {
8
  if (!options)
9
- options = {}
10
- options.writableObjectMode = true
11
- super(options)
12
- options.sequential = true
13
- this.packr = options.packr || new Packr(options)
14
  }
15
  _transform(value, encoding, callback) {
16
- this.push(this.packr.pack(value))
17
- callback()
18
  }
19
  }
20
 
21
  export class UnpackrStream extends Transform {
22
  constructor(options) {
23
  if (!options)
24
- options = {}
25
- options.objectMode = true
26
- super(options)
27
- options.structures = []
28
- this.maxIncompleteBufferSize = options.maxIncompleteBufferSize !== undefined ? options.maxIncompleteBufferSize : 0x4000000
29
- this.unpackr = options.unpackr || new Unpackr(options)
30
  }
31
  _transform(chunk, encoding, callback) {
32
  if (this.incompleteBuffer) {
33
- chunk = Buffer.concat([this.incompleteBuffer, chunk])
34
- this.incompleteBuffer = null
35
  }
36
- let values
37
  try {
38
- values = this.unpackr.unpackMultiple(chunk)
39
  } catch(error) {
40
  if (error.incomplete) {
41
- let incompleteBuffer = chunk.slice(error.lastPosition)
42
  if (incompleteBuffer.length > this.maxIncompleteBufferSize) {
43
- this.incompleteBuffer = null
44
- return callback(new Error('Maximum incomplete buffer size exceeded'))
45
  }
46
- this.incompleteBuffer = incompleteBuffer
47
- values = error.values
48
  } else {
49
- return callback(error)
50
  }
51
  }
52
  for (let value of values || []) {
53
  if (value === null)
54
- value = this.getNullValue()
55
- this.push(value)
56
  }
57
- callback()
58
  }
59
  getNullValue() {
60
- return Symbol.for(null)
61
  }
62
  }
 
1
+ import { Transform } from 'stream';
2
+ import { Packr } from './pack.js';
3
+ import { Unpackr } from './unpack.js';
4
+ var DEFAULT_OPTIONS = {objectMode: true};
5
 
6
  export class PackrStream extends Transform {
7
  constructor(options) {
8
  if (!options)
9
+ options = {};
10
+ options.writableObjectMode = true;
11
+ super(options);
12
+ options.sequential = true;
13
+ this.packr = options.packr || new Packr(options);
14
  }
15
  _transform(value, encoding, callback) {
16
+ this.push(this.packr.pack(value));
17
+ callback();
18
  }
19
  }
20
 
21
  export class UnpackrStream extends Transform {
22
  constructor(options) {
23
  if (!options)
24
+ options = {};
25
+ options.objectMode = true;
26
+ super(options);
27
+ options.structures = [];
28
+ this.maxIncompleteBufferSize = options.maxIncompleteBufferSize !== undefined ? options.maxIncompleteBufferSize : 0x4000000;
29
+ this.unpackr = options.unpackr || new Unpackr(options);
30
  }
31
  _transform(chunk, encoding, callback) {
32
  if (this.incompleteBuffer) {
33
+ chunk = Buffer.concat([this.incompleteBuffer, chunk]);
34
+ this.incompleteBuffer = null;
35
  }
36
+ let values;
37
  try {
38
+ values = this.unpackr.unpackMultiple(chunk);
39
  } catch(error) {
40
  if (error.incomplete) {
41
+ let incompleteBuffer = chunk.slice(error.lastPosition);
42
  if (incompleteBuffer.length > this.maxIncompleteBufferSize) {
43
+ this.incompleteBuffer = null;
44
+ return callback(new Error('Maximum incomplete buffer size exceeded'));
45
  }
46
+ this.incompleteBuffer = incompleteBuffer;
47
+ values = error.values;
48
  } else {
49
+ return callback(error);
50
  }
51
  }
52
  for (let value of values || []) {
53
  if (value === null)
54
+ value = this.getNullValue();
55
+ this.push(value);
56
  }
57
+ callback();
58
  }
59
  getNullValue() {
60
+ return Symbol.for(null);
61
  }
62
  }
.opencode/node_modules/msgpackr/unpack.js CHANGED
@@ -1,678 +1,690 @@
1
- var decoder
2
  try {
3
- decoder = new TextDecoder()
4
  } catch(error) {}
5
- var src
6
- var srcEnd
7
- var position = 0
8
- var alreadySet
9
- const EMPTY_ARRAY = []
10
- var strings = EMPTY_ARRAY
11
- var stringPosition = 0
12
- var currentUnpackr = {}
13
- var currentStructures
14
- var srcString
15
- var srcStringStart = 0
16
- var srcStringEnd = 0
17
- var bundledStrings
18
- var referenceMap
19
- var currentExtensions = []
20
- var dataView
21
  var defaultOptions = {
22
  useRecords: false,
23
  mapsAsObjects: true
24
- }
25
  export class C1Type {}
26
- export const C1 = new C1Type()
27
- C1.name = 'MessagePack 0xC1'
28
- var sequentialMode = false
29
- var inlineObjectReadThreshold = 2
30
- var readStruct, onLoadedStructures, onSaveState
31
- var BlockedFunction // we use search and replace to change the next call to BlockedFunction to avoid CSP issues for
32
 
33
  export class Unpackr {
34
  constructor(options) {
35
  if (options) {
36
  if (options.useRecords === false && options.mapsAsObjects === undefined)
37
- options.mapsAsObjects = true
38
  if (options.sequential && options.trusted !== false) {
39
  options.trusted = true;
40
  if (!options.structures && options.useRecords != false) {
41
- options.structures = []
42
  if (!options.maxSharedStructures)
43
- options.maxSharedStructures = 0
44
  }
45
  }
46
  if (options.structures)
47
- options.structures.sharedLength = options.structures.length
48
  else if (options.getStructures) {
49
- (options.structures = []).uninitialized = true // this is what we use to denote an uninitialized structures
50
- options.structures.sharedLength = 0
51
  }
52
  if (options.int64AsNumber) {
53
- options.int64AsType = 'number'
54
  }
55
  }
56
- Object.assign(this, options)
57
  }
58
  unpack(source, options) {
59
  if (src) {
60
  // re-entrant execution, save the state and restore it after we do this unpack
61
  return saveState(() => {
62
- clearSource()
63
- return this ? this.unpack(source, options) : Unpackr.prototype.unpack.call(defaultOptions, source, options)
64
- })
65
  }
66
  if (!source.buffer && source.constructor === ArrayBuffer)
67
  source = typeof Buffer !== 'undefined' ? Buffer.from(source) : new Uint8Array(source);
68
  if (typeof options === 'object') {
69
- srcEnd = options.end || source.length
70
- position = options.start || 0
71
  } else {
72
- position = 0
73
- srcEnd = options > -1 ? options : source.length
74
  }
75
- stringPosition = 0
76
- srcStringEnd = 0
77
- srcString = null
78
- strings = EMPTY_ARRAY
79
- bundledStrings = null
80
- src = source
81
  // this provides cached access to the data view for a buffer if it is getting reused, which is a recommend
82
  // technique for getting data from a database where it can be copied into an existing buffer instead of creating
83
  // new ones
84
  try {
85
- dataView = source.dataView || (source.dataView = new DataView(source.buffer, source.byteOffset, source.byteLength))
86
  } catch(error) {
87
  // if it doesn't have a buffer, maybe it is the wrong type of object
88
- src = null
89
  if (source instanceof Uint8Array)
90
- throw error
91
- throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source))
92
  }
93
  if (this instanceof Unpackr) {
94
- currentUnpackr = this
95
  if (this.structures) {
96
- currentStructures = this.structures
97
- return checkedRead(options)
98
  } else if (!currentStructures || currentStructures.length > 0) {
99
- currentStructures = []
100
  }
101
  } else {
102
- currentUnpackr = defaultOptions
103
  if (!currentStructures || currentStructures.length > 0)
104
- currentStructures = []
105
  }
106
- return checkedRead(options)
107
  }
108
  unpackMultiple(source, forEach) {
109
- let values, lastPosition = 0
110
  try {
111
- sequentialMode = true
112
- let size = source.length
113
- let value = this ? this.unpack(source, size) : defaultUnpackr.unpack(source, size)
114
  if (forEach) {
115
  if (forEach(value, lastPosition, position) === false) return;
116
  while(position < size) {
117
- lastPosition = position
118
  if (forEach(checkedRead(), lastPosition, position) === false) {
119
- return
120
  }
121
  }
122
  }
123
  else {
124
- values = [ value ]
125
  while(position < size) {
126
- lastPosition = position
127
- values.push(checkedRead())
128
  }
129
- return values
130
  }
131
  } catch(error) {
132
- error.lastPosition = lastPosition
133
- error.values = values
134
- throw error
135
  } finally {
136
- sequentialMode = false
137
- clearSource()
138
  }
139
  }
140
  _mergeStructures(loadedStructures, existingStructures) {
141
- if (onLoadedStructures)
142
- loadedStructures = onLoadedStructures.call(this, loadedStructures);
143
- loadedStructures = loadedStructures || []
144
  if (Object.isFrozen(loadedStructures))
145
- loadedStructures = loadedStructures.map(structure => structure.slice(0))
146
  for (let i = 0, l = loadedStructures.length; i < l; i++) {
147
- let structure = loadedStructures[i]
148
  if (structure) {
149
- structure.isShared = true
150
  if (i >= 32)
151
- structure.highByte = (i - 32) >> 5
152
  }
153
  }
154
- loadedStructures.sharedLength = loadedStructures.length
155
  for (let id in existingStructures || []) {
156
  if (id >= 0) {
157
- let structure = loadedStructures[id]
158
- let existing = existingStructures[id]
159
  if (existing) {
160
  if (structure)
161
- (loadedStructures.restoreStructures || (loadedStructures.restoreStructures = []))[id] = structure
162
- loadedStructures[id] = existing
163
  }
164
  }
165
  }
166
- return this.structures = loadedStructures
167
  }
168
  decode(source, options) {
169
- return this.unpack(source, options)
170
  }
171
  }
172
  export function getPosition() {
173
- return position
174
  }
175
  export function checkedRead(options) {
176
  try {
177
  if (!currentUnpackr.trusted && !sequentialMode) {
178
- let sharedLength = currentStructures.sharedLength || 0
179
  if (sharedLength < currentStructures.length)
180
- currentStructures.length = sharedLength
181
  }
182
- let result
183
- if (currentUnpackr.randomAccessStructure && src[position] < 0x40 && src[position] >= 0x20 && readStruct) {
184
- result = readStruct(src, position, srcEnd, currentUnpackr)
185
- src = null // dispose of this so that recursive unpack calls don't save state
186
  if (!(options && options.lazy) && result)
187
- result = result.toJSON()
188
- position = srcEnd
189
  } else
190
- result = read()
191
  if (bundledStrings) { // bundled strings to skip past
192
- position = bundledStrings.postBundlePosition
193
- bundledStrings = null
194
  }
195
  if (sequentialMode)
196
  // we only need to restore the structures if there was an error, but if we completed a read,
197
  // we can clear this out and keep the structures we read
198
- currentStructures.restoreStructures = null
199
 
200
  if (position == srcEnd) {
201
  // finished reading this source, cleanup references
202
  if (currentStructures && currentStructures.restoreStructures)
203
- restoreStructures()
204
- currentStructures = null
205
- src = null
206
  if (referenceMap)
207
- referenceMap = null
208
  } else if (position > srcEnd) {
209
  // over read
210
- throw new Error('Unexpected end of MessagePack data')
211
  } else if (!sequentialMode) {
212
  let jsonView;
213
  try {
214
- jsonView = JSON.stringify(result, (_, value) => typeof value === "bigint" ? `${value}n` : value).slice(0, 100)
215
  } catch(error) {
216
- jsonView = '(JSON view not available ' + error + ')'
217
  }
218
- throw new Error('Data read, but end of buffer not reached ' + jsonView)
219
  }
220
  // else more to read, but we are reading sequentially, so don't clear source yet
221
- return result
222
  } catch(error) {
223
  if (currentStructures && currentStructures.restoreStructures)
224
- restoreStructures()
225
- clearSource()
226
  if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position > srcEnd) {
227
- error.incomplete = true
228
  }
229
- throw error
230
  }
231
  }
232
 
233
  function restoreStructures() {
234
  for (let id in currentStructures.restoreStructures) {
235
- currentStructures[id] = currentStructures.restoreStructures[id]
236
  }
237
- currentStructures.restoreStructures = null
238
  }
239
 
240
  export function read() {
241
- let token = src[position++]
242
  if (token < 0xa0) {
243
  if (token < 0x80) {
244
  if (token < 0x40)
245
- return token
246
  else {
247
  let structure = currentStructures[token & 0x3f] ||
248
- currentUnpackr.getStructures && loadStructures()[token & 0x3f]
249
  if (structure) {
250
  if (!structure.read) {
251
- structure.read = createStructureReader(structure, token & 0x3f)
252
  }
253
- return structure.read()
254
  } else
255
- return token
256
  }
257
  } else if (token < 0x90) {
258
  // map
259
- token -= 0x80
260
  if (currentUnpackr.mapsAsObjects) {
261
- let object = {}
262
  for (let i = 0; i < token; i++) {
263
- let key = readKey()
264
  if (key === '__proto__')
265
- key = '__proto_'
266
- object[key] = read()
267
  }
268
- return object
269
  } else {
270
- let map = new Map()
271
  for (let i = 0; i < token; i++) {
272
- map.set(read(), read())
273
  }
274
- return map
275
  }
276
  } else {
277
- token -= 0x90
278
- let array = new Array(token)
279
  for (let i = 0; i < token; i++) {
280
- array[i] = read()
281
  }
282
  if (currentUnpackr.freezeData)
283
- return Object.freeze(array)
284
- return array
285
  }
286
  } else if (token < 0xc0) {
287
  // fixstr
288
- let length = token - 0xa0
289
  if (srcStringEnd >= position) {
290
- return srcString.slice(position - srcStringStart, (position += length) - srcStringStart)
291
  }
292
  if (srcStringEnd == 0 && srcEnd < 140) {
293
  // for small blocks, avoiding the overhead of the extract call is helpful
294
- let string = length < 16 ? shortStringInJS(length) : longStringInJS(length)
295
  if (string != null)
296
- return string
297
  }
298
- return readFixedString(length)
299
  } else {
300
- let value
301
  switch (token) {
302
- case 0xc0: return null
303
  case 0xc1:
304
  if (bundledStrings) {
305
- value = read() // followed by the length of the string in characters (not bytes!)
306
  if (value > 0)
307
- return bundledStrings[1].slice(bundledStrings.position1, bundledStrings.position1 += value)
308
  else
309
- return bundledStrings[0].slice(bundledStrings.position0, bundledStrings.position0 -= value)
310
  }
311
  return C1; // "never-used", return special object to denote that
312
- case 0xc2: return false
313
- case 0xc3: return true
314
  case 0xc4:
315
  // bin 8
316
- value = src[position++]
317
  if (value === undefined)
318
- throw new Error('Unexpected end of buffer')
319
- return readBin(value)
320
  case 0xc5:
321
  // bin 16
322
- value = dataView.getUint16(position)
323
- position += 2
324
- return readBin(value)
325
  case 0xc6:
326
  // bin 32
327
- value = dataView.getUint32(position)
328
- position += 4
329
- return readBin(value)
330
  case 0xc7:
331
  // ext 8
332
- return readExt(src[position++])
333
  case 0xc8:
334
  // ext 16
335
- value = dataView.getUint16(position)
336
- position += 2
337
- return readExt(value)
338
  case 0xc9:
339
  // ext 32
340
- value = dataView.getUint32(position)
341
- position += 4
342
- return readExt(value)
343
  case 0xca:
344
- value = dataView.getFloat32(position)
345
  if (currentUnpackr.useFloat32 > 2) {
346
  // this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
347
- let multiplier = mult10[((src[position] & 0x7f) << 1) | (src[position + 1] >> 7)]
348
- position += 4
349
- return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier
350
  }
351
- position += 4
352
- return value
353
  case 0xcb:
354
- value = dataView.getFloat64(position)
355
- position += 8
356
- return value
357
  // uint handlers
358
  case 0xcc:
359
- return src[position++]
360
  case 0xcd:
361
- value = dataView.getUint16(position)
362
- position += 2
363
- return value
364
  case 0xce:
365
- value = dataView.getUint32(position)
366
- position += 4
367
- return value
368
  case 0xcf:
369
  if (currentUnpackr.int64AsType === 'number') {
370
- value = dataView.getUint32(position) * 0x100000000
371
- value += dataView.getUint32(position + 4)
372
  } else if (currentUnpackr.int64AsType === 'string') {
373
- value = dataView.getBigUint64(position).toString()
374
  } else if (currentUnpackr.int64AsType === 'auto') {
375
- value = dataView.getBigUint64(position)
376
- if (value<=BigInt(2)<<BigInt(52)) value=Number(value)
377
  } else
378
- value = dataView.getBigUint64(position)
379
- position += 8
380
- return value
381
 
382
  // int handlers
383
  case 0xd0:
384
- return dataView.getInt8(position++)
385
  case 0xd1:
386
- value = dataView.getInt16(position)
387
- position += 2
388
- return value
389
  case 0xd2:
390
- value = dataView.getInt32(position)
391
- position += 4
392
- return value
393
  case 0xd3:
394
  if (currentUnpackr.int64AsType === 'number') {
395
- value = dataView.getInt32(position) * 0x100000000
396
- value += dataView.getUint32(position + 4)
397
  } else if (currentUnpackr.int64AsType === 'string') {
398
- value = dataView.getBigInt64(position).toString()
399
  } else if (currentUnpackr.int64AsType === 'auto') {
400
- value = dataView.getBigInt64(position)
401
- if (value>=BigInt(-2)<<BigInt(52)&&value<=BigInt(2)<<BigInt(52)) value=Number(value)
402
  } else
403
- value = dataView.getBigInt64(position)
404
- position += 8
405
- return value
406
 
407
  case 0xd4:
408
  // fixext 1
409
- value = src[position++]
410
  if (value == 0x72) {
411
- return recordDefinition(src[position++] & 0x3f)
412
  } else {
413
- let extension = currentExtensions[value]
414
  if (extension) {
415
  if (extension.read) {
416
- position++ // skip filler byte
417
- return extension.read(read())
418
  } else if (extension.noBuffer) {
419
- position++ // skip filler byte
420
- return extension()
421
  } else
422
- return extension(src.subarray(position, ++position))
423
  } else
424
- throw new Error('Unknown extension ' + value)
425
  }
426
  case 0xd5:
427
  // fixext 2
428
- value = src[position]
429
  if (value == 0x72) {
430
- position++
431
- return recordDefinition(src[position++] & 0x3f, src[position++])
432
  } else
433
- return readExt(2)
434
  case 0xd6:
435
  // fixext 4
436
- return readExt(4)
437
  case 0xd7:
438
  // fixext 8
439
- return readExt(8)
440
  case 0xd8:
441
  // fixext 16
442
- return readExt(16)
443
  case 0xd9:
444
  // str 8
445
- value = src[position++]
446
  if (srcStringEnd >= position) {
447
- return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
448
  }
449
- return readString8(value)
450
  case 0xda:
451
  // str 16
452
- value = dataView.getUint16(position)
453
- position += 2
454
  if (srcStringEnd >= position) {
455
- return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
456
  }
457
- return readString16(value)
458
  case 0xdb:
459
  // str 32
460
- value = dataView.getUint32(position)
461
- position += 4
462
  if (srcStringEnd >= position) {
463
- return srcString.slice(position - srcStringStart, (position += value) - srcStringStart)
464
  }
465
- return readString32(value)
466
  case 0xdc:
467
  // array 16
468
- value = dataView.getUint16(position)
469
- position += 2
470
- return readArray(value)
471
  case 0xdd:
472
  // array 32
473
- value = dataView.getUint32(position)
474
- position += 4
475
- return readArray(value)
476
  case 0xde:
477
  // map 16
478
- value = dataView.getUint16(position)
479
- position += 2
480
- return readMap(value)
481
  case 0xdf:
482
  // map 32
483
- value = dataView.getUint32(position)
484
- position += 4
485
- return readMap(value)
486
  default: // negative int
487
  if (token >= 0xe0)
488
- return token - 0x100
489
  if (token === undefined) {
490
- let error = new Error('Unexpected end of MessagePack data')
491
- error.incomplete = true
492
- throw error
493
  }
494
- throw new Error('Unknown MessagePack token ' + token)
495
 
496
  }
497
  }
498
  }
499
- const validName = /^[a-zA-Z_$][a-zA-Z\d_$]*$/
500
  function createStructureReader(structure, firstId) {
501
  function readObject() {
502
  // This initial function is quick to instantiate, but runs slower. After several iterations pay the cost to build the faster function
503
  if (readObject.count++ > inlineObjectReadThreshold) {
504
- let optimizedReadObject
505
  try {
506
  optimizedReadObject = structure.read = (new Function('r', 'return function(){return ' + (currentUnpackr.freezeData ? 'Object.freeze' : '') +
507
- '({' + structure.map(key => key === '__proto__' ? '__proto_:r()' : validName.test(key) ? key + ':r()' : ('[' + JSON.stringify(key) + ']:r()')).join(',') + '})}'))(read)
508
  } catch(error) {
509
  // in CF workers, the new Function call could begin to fail at any point in time
510
- inlineObjectReadThreshold = Infinity // disable going forward
511
  return readObject(); // recursively try again
512
  }
 
513
  if (structure.highByte === 0)
514
- structure.read = createSecondByteReader(firstId, structure.read)
515
- return optimizedReadObject() // second byte is already read, if there is one so immediately read object
516
  }
517
- let object = {}
518
  for (let i = 0, l = structure.length; i < l; i++) {
519
- let key = structure[i]
520
  if (key === '__proto__')
521
- key = '__proto_'
522
- object[key] = read()
523
  }
524
  if (currentUnpackr.freezeData)
525
  return Object.freeze(object);
526
- return object
527
  }
528
- readObject.count = 0
 
 
 
 
 
 
529
  if (structure.highByte === 0) {
530
- return createSecondByteReader(firstId, readObject)
531
  }
532
- return readObject
533
  }
534
 
535
  const createSecondByteReader = (firstId, read0) => {
536
  return function() {
537
- let highByte = src[position++]
538
  if (highByte === 0)
539
- return read0()
540
- let id = firstId < 32 ? -(firstId + (highByte << 5)) : firstId + (highByte << 5)
541
- let structure = currentStructures[id] || loadStructures()[id]
542
  if (!structure) {
543
- throw new Error('Record id is not defined for ' + id)
544
  }
545
  if (!structure.read)
546
- structure.read = createStructureReader(structure, firstId)
547
- return structure.read()
548
- }
549
- }
550
 
551
  export function loadStructures() {
552
  let loadedStructures = saveState(() => {
553
  // save the state in case getStructures modifies our buffer
554
- src = null
555
- return currentUnpackr.getStructures()
556
- })
557
- return currentStructures = currentUnpackr._mergeStructures(loadedStructures, currentStructures)
558
  }
559
 
560
- var readFixedString = readStringJS
561
- var readString8 = readStringJS
562
- var readString16 = readStringJS
563
- var readString32 = readStringJS
564
- export let isNativeAccelerationEnabled = false
565
 
566
  export function setExtractor(extractStrings) {
567
- isNativeAccelerationEnabled = true
568
- readFixedString = readString(1)
569
- readString8 = readString(2)
570
- readString16 = readString(3)
571
- readString32 = readString(5)
572
  function readString(headerLength) {
573
  return function readString(length) {
574
- let string = strings[stringPosition++]
575
  if (string == null) {
576
  if (bundledStrings)
577
- return readStringJS(length)
578
- let byteOffset = src.byteOffset
579
- let extraction = extractStrings(position - headerLength + byteOffset, srcEnd + byteOffset, src.buffer)
580
  if (typeof extraction == 'string') {
581
- string = extraction
582
- strings = EMPTY_ARRAY
583
  } else {
584
- strings = extraction
585
- stringPosition = 1
586
- srcStringEnd = 1 // even if a utf-8 string was decoded, must indicate we are in the midst of extracted strings and can't skip strings
587
- string = strings[0]
588
  if (string === undefined)
589
- throw new Error('Unexpected end of buffer')
590
  }
591
  }
592
- let srcStringLength = string.length
593
  if (srcStringLength <= length) {
594
- position += length
595
- return string
596
  }
597
- srcString = string
598
- srcStringStart = position
599
- srcStringEnd = position + srcStringLength
600
- position += length
601
- return string.slice(0, length) // we know we just want the beginning
602
- }
603
  }
604
  }
605
  function readStringJS(length) {
606
- let result
607
  if (length < 16) {
608
  if (result = shortStringInJS(length))
609
- return result
610
  }
611
  if (length > 64 && decoder)
612
- return decoder.decode(src.subarray(position, position += length))
613
- const end = position + length
614
- const units = []
615
- result = ''
616
  while (position < end) {
617
- const byte1 = src[position++]
618
  if ((byte1 & 0x80) === 0) {
619
  // 1 byte
620
- units.push(byte1)
621
  } else if ((byte1 & 0xe0) === 0xc0) {
622
  // 2 bytes
623
- const byte2 = src[position++] & 0x3f
624
- const codePoint = ((byte1 & 0x1f) << 6) | byte2
625
- // Reject overlong encoding: 2-byte sequences must encode values >= 0x80
626
- if (codePoint < 0x80) {
627
- units.push(0xFFFD) // replacement character
628
  } else {
629
- units.push(codePoint)
 
630
  }
631
  } else if ((byte1 & 0xf0) === 0xe0) {
632
  // 3 bytes
633
- const byte2 = src[position++] & 0x3f
634
- const byte3 = src[position++] & 0x3f
635
- const codePoint = ((byte1 & 0x1f) << 12) | (byte2 << 6) | byte3
636
- // Reject overlong encoding: 3-byte sequences must encode values >= 0x800
637
- // Also reject surrogates (0xD800-0xDFFF)
638
- if (codePoint < 0x800 || (codePoint >= 0xD800 && codePoint <= 0xDFFF)) {
639
- units.push(0xFFFD) // replacement character
640
  } else {
641
- units.push(codePoint)
 
 
 
 
 
 
642
  }
643
  } else if ((byte1 & 0xf8) === 0xf0) {
644
  // 4 bytes
645
- const byte2 = src[position++] & 0x3f
646
- const byte3 = src[position++] & 0x3f
647
- const byte4 = src[position++] & 0x3f
648
- let unit = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4
649
- // Reject overlong encoding: 4-byte sequences must encode values >= 0x10000
650
- // Also reject values > 0x10FFFF (maximum valid Unicode)
651
- if (unit < 0x10000 || unit > 0x10FFFF) {
652
- units.push(0xFFFD) // replacement character
653
- } else if (unit > 0xffff) {
654
- unit -= 0x10000
655
- units.push(((unit >>> 10) & 0x3ff) | 0xd800)
656
- unit = 0xdc00 | (unit & 0x3ff)
657
- units.push(unit)
658
  } else {
659
- units.push(unit)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
660
  }
661
  } else {
662
- units.push(0xFFFD) // replacement character for invalid lead byte
663
  }
664
 
665
  if (units.length >= 0x1000) {
666
- result += fromCharCode.apply(String, units)
667
- units.length = 0
668
  }
669
  }
670
 
671
  if (units.length > 0) {
672
- result += fromCharCode.apply(String, units)
673
  }
674
 
675
- return result
676
  }
677
  export function readString(source, start, length) {
678
  let existingSrc = src;
@@ -686,182 +698,182 @@ export function readString(source, start, length) {
686
  }
687
 
688
  function readArray(length) {
689
- let array = new Array(length)
690
  for (let i = 0; i < length; i++) {
691
- array[i] = read()
692
  }
693
  if (currentUnpackr.freezeData)
694
- return Object.freeze(array)
695
- return array
696
  }
697
 
698
  function readMap(length) {
699
  if (currentUnpackr.mapsAsObjects) {
700
- let object = {}
701
  for (let i = 0; i < length; i++) {
702
- let key = readKey()
703
  if (key === '__proto__')
704
  key = '__proto_';
705
- object[key] = read()
706
  }
707
- return object
708
  } else {
709
- let map = new Map()
710
  for (let i = 0; i < length; i++) {
711
- map.set(read(), read())
712
  }
713
- return map
714
  }
715
  }
716
 
717
- var fromCharCode = String.fromCharCode
718
  function longStringInJS(length) {
719
- let start = position
720
- let bytes = new Array(length)
721
  for (let i = 0; i < length; i++) {
722
  const byte = src[position++];
723
  if ((byte & 0x80) > 0) {
724
- position = start
725
- return
726
  }
727
- bytes[i] = byte
728
  }
729
- return fromCharCode.apply(String, bytes)
730
  }
731
  function shortStringInJS(length) {
732
  if (length < 4) {
733
  if (length < 2) {
734
  if (length === 0)
735
- return ''
736
  else {
737
- let a = src[position++]
738
  if ((a & 0x80) > 1) {
739
- position -= 1
740
- return
741
  }
742
- return fromCharCode(a)
743
  }
744
  } else {
745
- let a = src[position++]
746
- let b = src[position++]
747
  if ((a & 0x80) > 0 || (b & 0x80) > 0) {
748
- position -= 2
749
- return
750
  }
751
  if (length < 3)
752
- return fromCharCode(a, b)
753
- let c = src[position++]
754
  if ((c & 0x80) > 0) {
755
- position -= 3
756
- return
757
  }
758
- return fromCharCode(a, b, c)
759
  }
760
  } else {
761
- let a = src[position++]
762
- let b = src[position++]
763
- let c = src[position++]
764
- let d = src[position++]
765
  if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
766
- position -= 4
767
- return
768
  }
769
  if (length < 6) {
770
  if (length === 4)
771
- return fromCharCode(a, b, c, d)
772
  else {
773
- let e = src[position++]
774
  if ((e & 0x80) > 0) {
775
- position -= 5
776
- return
777
  }
778
- return fromCharCode(a, b, c, d, e)
779
  }
780
  } else if (length < 8) {
781
- let e = src[position++]
782
- let f = src[position++]
783
  if ((e & 0x80) > 0 || (f & 0x80) > 0) {
784
- position -= 6
785
- return
786
  }
787
  if (length < 7)
788
- return fromCharCode(a, b, c, d, e, f)
789
- let g = src[position++]
790
  if ((g & 0x80) > 0) {
791
- position -= 7
792
- return
793
  }
794
- return fromCharCode(a, b, c, d, e, f, g)
795
  } else {
796
- let e = src[position++]
797
- let f = src[position++]
798
- let g = src[position++]
799
- let h = src[position++]
800
  if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
801
- position -= 8
802
- return
803
  }
804
  if (length < 10) {
805
  if (length === 8)
806
- return fromCharCode(a, b, c, d, e, f, g, h)
807
  else {
808
- let i = src[position++]
809
  if ((i & 0x80) > 0) {
810
- position -= 9
811
- return
812
  }
813
- return fromCharCode(a, b, c, d, e, f, g, h, i)
814
  }
815
  } else if (length < 12) {
816
- let i = src[position++]
817
- let j = src[position++]
818
  if ((i & 0x80) > 0 || (j & 0x80) > 0) {
819
- position -= 10
820
- return
821
  }
822
  if (length < 11)
823
- return fromCharCode(a, b, c, d, e, f, g, h, i, j)
824
- let k = src[position++]
825
  if ((k & 0x80) > 0) {
826
- position -= 11
827
- return
828
  }
829
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k)
830
  } else {
831
- let i = src[position++]
832
- let j = src[position++]
833
- let k = src[position++]
834
- let l = src[position++]
835
  if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
836
- position -= 12
837
- return
838
  }
839
  if (length < 14) {
840
  if (length === 12)
841
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l)
842
  else {
843
- let m = src[position++]
844
  if ((m & 0x80) > 0) {
845
- position -= 13
846
- return
847
  }
848
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m)
849
  }
850
  } else {
851
- let m = src[position++]
852
- let n = src[position++]
853
  if ((m & 0x80) > 0 || (n & 0x80) > 0) {
854
- position -= 14
855
- return
856
  }
857
  if (length < 15)
858
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
859
- let o = src[position++]
860
  if ((o & 0x80) > 0) {
861
- position -= 15
862
- return
863
  }
864
- return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
865
  }
866
  }
867
  }
@@ -869,32 +881,32 @@ function shortStringInJS(length) {
869
  }
870
 
871
  function readOnlyJSString() {
872
- let token = src[position++]
873
- let length
874
  if (token < 0xc0) {
875
  // fixstr
876
- length = token - 0xa0
877
  } else {
878
  switch(token) {
879
  case 0xd9:
880
  // str 8
881
- length = src[position++]
882
- break
883
  case 0xda:
884
  // str 16
885
- length = dataView.getUint16(position)
886
- position += 2
887
- break
888
  case 0xdb:
889
  // str 32
890
- length = dataView.getUint32(position)
891
- position += 4
892
- break
893
  default:
894
- throw new Error('Expected string')
895
  }
896
  }
897
- return readStringJS(length)
898
  }
899
 
900
 
@@ -902,12 +914,12 @@ function readBin(length) {
902
  return currentUnpackr.copyBuffers ?
903
  // specifically use the copying slice (not the node one)
904
  Uint8Array.prototype.slice.call(src, position, position += length) :
905
- src.subarray(position, position += length)
906
  }
907
  function readExt(length) {
908
- let type = src[position++]
909
  if (currentExtensions[type]) {
910
- let end
911
  return currentExtensions[type](src.subarray(position, end = (position += length)), (readPosition) => {
912
  position = readPosition;
913
  try {
@@ -915,74 +927,74 @@ function readExt(length) {
915
  } finally {
916
  position = end;
917
  }
918
- })
919
  }
920
  else
921
- throw new Error('Unknown extension type ' + type)
922
  }
923
 
924
- var keyCache = new Array(4096)
925
  function readKey() {
926
- let length = src[position++]
927
  if (length >= 0xa0 && length < 0xc0) {
928
  // fixstr, potentially use key cache
929
- length = length - 0xa0
930
  if (srcStringEnd >= position) // if it has been extracted, must use it (and faster anyway)
931
- return srcString.slice(position - srcStringStart, (position += length) - srcStringStart)
932
  else if (!(srcStringEnd == 0 && srcEnd < 180))
933
- return readFixedString(length)
934
  } else { // not cacheable, go back and do a standard read
935
- position--
936
- return asSafeString(read())
937
  }
938
- let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position) : length > 0 ? src[position] : 0)) & 0xfff
939
- let entry = keyCache[key]
940
- let checkPosition = position
941
- let end = position + length - 3
942
- let chunk
943
- let i = 0
944
  if (entry && entry.bytes == length) {
945
  while (checkPosition < end) {
946
- chunk = dataView.getUint32(checkPosition)
947
  if (chunk != entry[i++]) {
948
- checkPosition = 0x70000000
949
- break
950
  }
951
- checkPosition += 4
952
  }
953
- end += 3
954
  while (checkPosition < end) {
955
- chunk = src[checkPosition++]
956
  if (chunk != entry[i++]) {
957
- checkPosition = 0x70000000
958
- break
959
  }
960
  }
961
  if (checkPosition === end) {
962
- position = checkPosition
963
- return entry.string
964
  }
965
- end -= 3
966
- checkPosition = position
967
  }
968
- entry = []
969
- keyCache[key] = entry
970
- entry.bytes = length
971
  while (checkPosition < end) {
972
- chunk = dataView.getUint32(checkPosition)
973
- entry.push(chunk)
974
- checkPosition += 4
975
  }
976
- end += 3
977
  while (checkPosition < end) {
978
- chunk = src[checkPosition++]
979
- entry.push(chunk)
980
  }
981
  // for small blocks, avoiding the overhead of the extract call is helpful
982
- let string = length < 16 ? shortStringInJS(length) : longStringInJS(length)
983
  if (string != null)
984
- return entry.string = string
985
- return entry.string = readFixedString(length)
986
  }
987
 
988
  function asSafeString(property) {
@@ -997,244 +1009,248 @@ function asSafeString(property) {
997
  }
998
  // the registration of the record definition extension (as "r")
999
  const recordDefinition = (id, highByte) => {
1000
- let structure = read().map(asSafeString) // ensure that all keys are strings and
1001
  // that the array is mutable
1002
- let firstByte = id
1003
  if (highByte !== undefined) {
1004
- id = id < 32 ? -((highByte << 5) + id) : ((highByte << 5) + id)
1005
- structure.highByte = highByte
1006
  }
1007
- let existingStructure = currentStructures[id]
1008
  // If it is a shared structure, we need to restore any changes after reading.
1009
  // Also in sequential mode, we may get incomplete reads and thus errors, and we need to restore
1010
  // to the state prior to an incomplete read in order to properly resume.
1011
  if (existingStructure && (existingStructure.isShared || sequentialMode)) {
1012
- (currentStructures.restoreStructures || (currentStructures.restoreStructures = []))[id] = existingStructure
1013
  }
1014
- currentStructures[id] = structure
1015
- structure.read = createStructureReader(structure, firstByte)
1016
- return structure.read()
1017
- }
1018
- currentExtensions[0] = () => {} // notepack defines extension 0 to mean undefined, so use that as the default here
1019
- currentExtensions[0].noBuffer = true
 
 
 
 
 
1020
 
1021
  currentExtensions[0x42] = data => {
1022
- let headLength = (data.byteLength % 8) || 8
1023
- let head = BigInt(data[0] & 0x80 ? data[0] - 0x100 : data[0])
1024
  for (let i = 1; i < headLength; i++) {
1025
- head <<= BigInt(8)
1026
- head += BigInt(data[i])
1027
  }
1028
  if (data.byteLength !== headLength) {
1029
- let view = new DataView(data.buffer, data.byteOffset, data.byteLength)
1030
  let decode = (start, end) => {
1031
- let length = end - start
1032
  if (length <= 40) {
1033
- let out = view.getBigUint64(start)
1034
  for (let i = start + 8; i < end; i += 8) {
1035
- out <<= BigInt(64)
1036
- out |= view.getBigUint64(i)
1037
  }
1038
- return out
1039
  }
1040
  // if (length === 8) return view.getBigUint64(start)
1041
- let middle = start + (length >> 4 << 3)
1042
- let left = decode(start, middle)
1043
- let right = decode(middle, end)
1044
- return (left << BigInt((end - middle) * 8)) | right
1045
- }
1046
- head = (head << BigInt((view.byteLength - headLength) * 8)) | decode(headLength, view.byteLength)
1047
  }
1048
- return head
1049
- }
1050
 
1051
  let errors = {
1052
  Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError, AggregateError: typeof AggregateError === 'function' ? AggregateError : null,
1053
- }
1054
  currentExtensions[0x65] = () => {
1055
- let data = read()
1056
  if (!errors[data[0]]) {
1057
- let error = Error(data[1], { cause: data[2] })
1058
- error.name = data[0]
1059
- return error
1060
  }
1061
- return errors[data[0]](data[1], { cause: data[2] })
1062
- }
1063
 
1064
  currentExtensions[0x69] = (data) => {
1065
  // id extension (for structured clones)
1066
- if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled')
1067
- let id = dataView.getUint32(position - 4)
1068
  if (!referenceMap)
1069
- referenceMap = new Map()
1070
- let token = src[position]
1071
- let target
1072
  // TODO: handle any other types that can cycle and make the code more robust if there are other extensions
1073
  if (token >= 0x90 && token < 0xa0 || token == 0xdc || token == 0xdd)
1074
- target = []
1075
  else if (token >= 0x80 && token < 0x90 || token == 0xde || token == 0xdf)
1076
- target = new Map()
1077
  else if ((token >= 0xc7 && token <= 0xc9 || token >= 0xd4 && token <= 0xd8) && src[position + 1] === 0x73)
1078
- target = new Set()
1079
  else
1080
- target = {}
1081
 
1082
- let refEntry = { target } // a placeholder object
1083
- referenceMap.set(id, refEntry)
1084
- let targetProperties = read() // read the next value as the target object to id
1085
  if (!refEntry.used) {
1086
  // no cycle, can just use the returned read object
1087
- return refEntry.target = targetProperties // replace the placeholder with the real one
1088
  } else {
1089
  // there is a cycle, so we have to assign properties to original target
1090
- Object.assign(target, targetProperties)
1091
  }
1092
 
1093
  // copy over map/set entries if we're able to
1094
  if (target instanceof Map)
1095
- for (let [k, v] of targetProperties.entries()) target.set(k, v)
1096
  if (target instanceof Set)
1097
- for (let i of Array.from(targetProperties)) target.add(i)
1098
- return target
1099
- }
1100
 
1101
  currentExtensions[0x70] = (data) => {
1102
  // pointer extension (for structured clones)
1103
- if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled')
1104
- let id = dataView.getUint32(position - 4)
1105
- let refEntry = referenceMap.get(id)
1106
- refEntry.used = true
1107
- return refEntry.target
1108
- }
1109
 
1110
- currentExtensions[0x73] = () => new Set(read())
1111
 
1112
- export const typedArrays = ['Int8','Uint8','Uint8Clamped','Int16','Uint16','Int32','Uint32','Float32','Float64','BigInt64','BigUint64'].map(type => type + 'Array')
1113
 
1114
  let glbl = typeof globalThis === 'object' ? globalThis : window;
1115
  currentExtensions[0x74] = (data) => {
1116
- let typeCode = data[0]
1117
  // we always have to slice to get a new ArrayBuffer that is aligned
1118
- let buffer = Uint8Array.prototype.slice.call(data, 1).buffer
1119
 
1120
- let typedArrayName = typedArrays[typeCode]
1121
  if (!typedArrayName) {
1122
- if (typeCode === 16) return buffer
1123
- if (typeCode === 17) return new DataView(buffer)
1124
- throw new Error('Could not find typed array for code ' + typeCode)
1125
  }
1126
- return new glbl[typedArrayName](buffer)
1127
- }
1128
  currentExtensions[0x78] = () => {
1129
- let data = read()
1130
- return new RegExp(data[0], data[1])
1131
- }
1132
- const TEMP_BUNDLE = []
1133
  currentExtensions[0x62] = (data) => {
1134
- let dataSize = (data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]
1135
- let dataPosition = position
1136
- position += dataSize - data.length
1137
- bundledStrings = TEMP_BUNDLE
1138
- bundledStrings = [readOnlyJSString(), readOnlyJSString()]
1139
- bundledStrings.position0 = 0
1140
- bundledStrings.position1 = 0
1141
- bundledStrings.postBundlePosition = position
1142
- position = dataPosition
1143
- return read()
1144
- }
1145
 
1146
  currentExtensions[0xff] = (data) => {
1147
  // 32-bit date extension
1148
  if (data.length == 4)
1149
- return new Date((data[0] * 0x1000000 + (data[1] << 16) + (data[2] << 8) + data[3]) * 1000)
1150
  else if (data.length == 8)
1151
  return new Date(
1152
  ((data[0] << 22) + (data[1] << 14) + (data[2] << 6) + (data[3] >> 2)) / 1000000 +
1153
- ((data[3] & 0x3) * 0x100000000 + data[4] * 0x1000000 + (data[5] << 16) + (data[6] << 8) + data[7]) * 1000)
1154
  else if (data.length == 12)
1155
  return new Date(
1156
  ((data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]) / 1000000 +
1157
- (((data[4] & 0x80) ? -0x1000000000000 : 0) + data[6] * 0x10000000000 + data[7] * 0x100000000 + data[8] * 0x1000000 + (data[9] << 16) + (data[10] << 8) + data[11]) * 1000)
1158
  else
1159
- return new Date('invalid')
1160
- }
1161
  // registration of bulk record definition?
1162
  // currentExtensions[0x52] = () =>
1163
 
1164
  function saveState(callback) {
1165
- if (onSaveState)
1166
- onSaveState();
1167
- let savedSrcEnd = srcEnd
1168
- let savedPosition = position
1169
- let savedStringPosition = stringPosition
1170
- let savedSrcStringStart = srcStringStart
1171
- let savedSrcStringEnd = srcStringEnd
1172
- let savedSrcString = srcString
1173
- let savedStrings = strings
1174
- let savedReferenceMap = referenceMap
1175
- let savedBundledStrings = bundledStrings
1176
 
1177
  // TODO: We may need to revisit this if we do more external calls to user code (since it could be slow)
1178
- let savedSrc = new Uint8Array(src.slice(0, srcEnd)) // we copy the data in case it changes while external data is processed
1179
- let savedStructures = currentStructures
1180
- let savedStructuresContents = currentStructures.slice(0, currentStructures.length)
1181
- let savedPackr = currentUnpackr
1182
- let savedSequentialMode = sequentialMode
1183
- let value = callback()
1184
- srcEnd = savedSrcEnd
1185
- position = savedPosition
1186
- stringPosition = savedStringPosition
1187
- srcStringStart = savedSrcStringStart
1188
- srcStringEnd = savedSrcStringEnd
1189
- srcString = savedSrcString
1190
- strings = savedStrings
1191
- referenceMap = savedReferenceMap
1192
- bundledStrings = savedBundledStrings
1193
- src = savedSrc
1194
- sequentialMode = savedSequentialMode
1195
- currentStructures = savedStructures
1196
- currentStructures.splice(0, currentStructures.length, ...savedStructuresContents)
1197
- currentUnpackr = savedPackr
1198
- dataView = new DataView(src.buffer, src.byteOffset, src.byteLength)
1199
- return value
1200
  }
1201
  export function clearSource() {
1202
- src = null
1203
- referenceMap = null
1204
- currentStructures = null
1205
  }
1206
 
1207
  export function addExtension(extension) {
1208
  if (extension.unpack)
1209
- currentExtensions[extension.type] = extension.unpack
1210
  else
1211
- currentExtensions[extension.type] = extension
1212
  }
1213
 
1214
- export const mult10 = new Array(147) // this is a table matching binary exponents to the multiplier to determine significant digit rounding
1215
  for (let i = 0; i < 256; i++) {
1216
- mult10[i] = +('1e' + Math.floor(45.15 - i * 0.30103))
1217
  }
1218
- export const Decoder = Unpackr
1219
- var defaultUnpackr = new Unpackr({ useRecords: false })
1220
- export const unpack = defaultUnpackr.unpack
1221
- export const unpackMultiple = defaultUnpackr.unpackMultiple
1222
- export const decode = defaultUnpackr.unpack
1223
  export const FLOAT32_OPTIONS = {
1224
  NEVER: 0,
1225
  ALWAYS: 1,
1226
  DECIMAL_ROUND: 3,
1227
  DECIMAL_FIT: 4
1228
- }
1229
- let f32Array = new Float32Array(1)
1230
- let u8Array = new Uint8Array(f32Array.buffer, 0, 4)
1231
  export function roundFloat32(float32Number) {
1232
- f32Array[0] = float32Number
1233
- let multiplier = mult10[((u8Array[3] & 0x7f) << 1) | (u8Array[2] >> 7)]
1234
- return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier
1235
- }
1236
- export function setReadStruct(updatedReadStruct, loadedStructs, saveState) {
1237
- readStruct = updatedReadStruct;
1238
- onLoadedStructures = loadedStructs;
1239
- onSaveState = saveState;
1240
  }
 
 
 
 
 
1
+ var decoder;
2
  try {
3
+ decoder = new TextDecoder();
4
  } catch(error) {}
5
+ var src;
6
+ var srcEnd;
7
+ var position = 0;
8
+ var alreadySet;
9
+ const EMPTY_ARRAY = [];
10
+ var strings = EMPTY_ARRAY;
11
+ var stringPosition = 0;
12
+ var currentUnpackr = {};
13
+ var currentStructures;
14
+ var srcString;
15
+ var srcStringStart = 0;
16
+ var srcStringEnd = 0;
17
+ var bundledStrings;
18
+ var referenceMap;
19
+ var currentExtensions = [];
20
+ var dataView;
21
  var defaultOptions = {
22
  useRecords: false,
23
  mapsAsObjects: true
24
+ };
25
  export class C1Type {}
26
+ export const C1 = new C1Type();
27
+ C1.name = 'MessagePack 0xC1';
28
+ var sequentialMode = false;
29
+ var inlineObjectReadThreshold = 2;
30
+ var BlockedFunction; // we use search and replace to change the next call to BlockedFunction to avoid CSP issues for
 
31
 
32
  export class Unpackr {
33
  constructor(options) {
34
  if (options) {
35
  if (options.useRecords === false && options.mapsAsObjects === undefined)
36
+ options.mapsAsObjects = true;
37
  if (options.sequential && options.trusted !== false) {
38
  options.trusted = true;
39
  if (!options.structures && options.useRecords != false) {
40
+ options.structures = [];
41
  if (!options.maxSharedStructures)
42
+ options.maxSharedStructures = 0;
43
  }
44
  }
45
  if (options.structures)
46
+ options.structures.sharedLength = options.structures.length;
47
  else if (options.getStructures) {
48
+ (options.structures = []).uninitialized = true; // this is what we use to denote an uninitialized structures
49
+ options.structures.sharedLength = 0;
50
  }
51
  if (options.int64AsNumber) {
52
+ options.int64AsType = 'number';
53
  }
54
  }
55
+ Object.assign(this, options);
56
  }
57
  unpack(source, options) {
58
  if (src) {
59
  // re-entrant execution, save the state and restore it after we do this unpack
60
  return saveState(() => {
61
+ clearSource();
62
+ return this ? this.unpack(source, options) : Unpackr.prototype.unpack.call(defaultOptions, source, options);
63
+ });
64
  }
65
  if (!source.buffer && source.constructor === ArrayBuffer)
66
  source = typeof Buffer !== 'undefined' ? Buffer.from(source) : new Uint8Array(source);
67
  if (typeof options === 'object') {
68
+ srcEnd = options.end || source.length;
69
+ position = options.start || 0;
70
  } else {
71
+ position = 0;
72
+ srcEnd = options > -1 ? options : source.length;
73
  }
74
+ stringPosition = 0;
75
+ srcStringEnd = 0;
76
+ srcString = null;
77
+ strings = EMPTY_ARRAY;
78
+ bundledStrings = null;
79
+ src = source;
80
  // this provides cached access to the data view for a buffer if it is getting reused, which is a recommend
81
  // technique for getting data from a database where it can be copied into an existing buffer instead of creating
82
  // new ones
83
  try {
84
+ dataView = source.dataView || (source.dataView = new DataView(source.buffer, source.byteOffset, source.byteLength));
85
  } catch(error) {
86
  // if it doesn't have a buffer, maybe it is the wrong type of object
87
+ src = null;
88
  if (source instanceof Uint8Array)
89
+ throw error;
90
+ throw new Error('Source must be a Uint8Array or Buffer but was a ' + ((source && typeof source == 'object') ? source.constructor.name : typeof source));
91
  }
92
  if (this instanceof Unpackr) {
93
+ currentUnpackr = this;
94
  if (this.structures) {
95
+ currentStructures = this.structures;
96
+ return checkedRead(options);
97
  } else if (!currentStructures || currentStructures.length > 0) {
98
+ currentStructures = [];
99
  }
100
  } else {
101
+ currentUnpackr = defaultOptions;
102
  if (!currentStructures || currentStructures.length > 0)
103
+ currentStructures = [];
104
  }
105
+ return checkedRead(options);
106
  }
107
  unpackMultiple(source, forEach) {
108
+ let values, lastPosition = 0;
109
  try {
110
+ sequentialMode = true;
111
+ let size = source.length;
112
+ let value = this ? this.unpack(source, size) : defaultUnpackr.unpack(source, size);
113
  if (forEach) {
114
  if (forEach(value, lastPosition, position) === false) return;
115
  while(position < size) {
116
+ lastPosition = position;
117
  if (forEach(checkedRead(), lastPosition, position) === false) {
118
+ return;
119
  }
120
  }
121
  }
122
  else {
123
+ values = [ value ];
124
  while(position < size) {
125
+ lastPosition = position;
126
+ values.push(checkedRead());
127
  }
128
+ return values;
129
  }
130
  } catch(error) {
131
+ error.lastPosition = lastPosition;
132
+ error.values = values;
133
+ throw error;
134
  } finally {
135
+ sequentialMode = false;
136
+ clearSource();
137
  }
138
  }
139
  _mergeStructures(loadedStructures, existingStructures) {
140
+ if (this._onLoadedStructures)
141
+ loadedStructures = this._onLoadedStructures(loadedStructures);
142
+ loadedStructures = loadedStructures || [];
143
  if (Object.isFrozen(loadedStructures))
144
+ loadedStructures = loadedStructures.map(structure => structure.slice(0));
145
  for (let i = 0, l = loadedStructures.length; i < l; i++) {
146
+ let structure = loadedStructures[i];
147
  if (structure) {
148
+ structure.isShared = true;
149
  if (i >= 32)
150
+ structure.highByte = (i - 32) >> 5;
151
  }
152
  }
153
+ loadedStructures.sharedLength = loadedStructures.length;
154
  for (let id in existingStructures || []) {
155
  if (id >= 0) {
156
+ let structure = loadedStructures[id];
157
+ let existing = existingStructures[id];
158
  if (existing) {
159
  if (structure)
160
+ (loadedStructures.restoreStructures || (loadedStructures.restoreStructures = []))[id] = structure;
161
+ loadedStructures[id] = existing;
162
  }
163
  }
164
  }
165
+ return this.structures = loadedStructures;
166
  }
167
  decode(source, options) {
168
+ return this.unpack(source, options);
169
  }
170
  }
171
  export function getPosition() {
172
+ return position;
173
  }
174
  export function checkedRead(options) {
175
  try {
176
  if (!currentUnpackr.trusted && !sequentialMode) {
177
+ let sharedLength = currentStructures.sharedLength || 0;
178
  if (sharedLength < currentStructures.length)
179
+ currentStructures.length = sharedLength;
180
  }
181
+ let result;
182
+ if (currentUnpackr._readStruct && src[position] < 0x40 && src[position] >= 0x20) {
183
+ result = currentUnpackr._readStruct(src, position, srcEnd);
184
+ src = null; // dispose of this so that recursive unpack calls don't save state
185
  if (!(options && options.lazy) && result)
186
+ result = result.toJSON();
187
+ position = srcEnd;
188
  } else
189
+ result = read();
190
  if (bundledStrings) { // bundled strings to skip past
191
+ position = bundledStrings.postBundlePosition;
192
+ bundledStrings = null;
193
  }
194
  if (sequentialMode)
195
  // we only need to restore the structures if there was an error, but if we completed a read,
196
  // we can clear this out and keep the structures we read
197
+ currentStructures.restoreStructures = null;
198
 
199
  if (position == srcEnd) {
200
  // finished reading this source, cleanup references
201
  if (currentStructures && currentStructures.restoreStructures)
202
+ restoreStructures();
203
+ currentStructures = null;
204
+ src = null;
205
  if (referenceMap)
206
+ referenceMap = null;
207
  } else if (position > srcEnd) {
208
  // over read
209
+ throw new Error('Unexpected end of MessagePack data');
210
  } else if (!sequentialMode) {
211
  let jsonView;
212
  try {
213
+ jsonView = JSON.stringify(result, (_, value) => typeof value === "bigint" ? `${value}n` : value).slice(0, 100);
214
  } catch(error) {
215
+ jsonView = '(JSON view not available ' + error + ')';
216
  }
217
+ throw new Error('Data read, but end of buffer not reached ' + jsonView);
218
  }
219
  // else more to read, but we are reading sequentially, so don't clear source yet
220
+ return result;
221
  } catch(error) {
222
  if (currentStructures && currentStructures.restoreStructures)
223
+ restoreStructures();
224
+ clearSource();
225
  if (error instanceof RangeError || error.message.startsWith('Unexpected end of buffer') || position > srcEnd) {
226
+ error.incomplete = true;
227
  }
228
+ throw error;
229
  }
230
  }
231
 
232
  function restoreStructures() {
233
  for (let id in currentStructures.restoreStructures) {
234
+ currentStructures[id] = currentStructures.restoreStructures[id];
235
  }
236
+ currentStructures.restoreStructures = null;
237
  }
238
 
239
  export function read() {
240
+ let token = src[position++];
241
  if (token < 0xa0) {
242
  if (token < 0x80) {
243
  if (token < 0x40)
244
+ return token;
245
  else {
246
  let structure = currentStructures[token & 0x3f] ||
247
+ currentUnpackr.getStructures && loadStructures()[token & 0x3f];
248
  if (structure) {
249
  if (!structure.read) {
250
+ structure.read = createStructureReader(structure, token & 0x3f);
251
  }
252
+ return structure.read();
253
  } else
254
+ return token;
255
  }
256
  } else if (token < 0x90) {
257
  // map
258
+ token -= 0x80;
259
  if (currentUnpackr.mapsAsObjects) {
260
+ let object = {};
261
  for (let i = 0; i < token; i++) {
262
+ let key = readKey();
263
  if (key === '__proto__')
264
+ key = '__proto_';
265
+ object[key] = read();
266
  }
267
+ return object;
268
  } else {
269
+ let map = new Map();
270
  for (let i = 0; i < token; i++) {
271
+ map.set(read(), read());
272
  }
273
+ return map;
274
  }
275
  } else {
276
+ token -= 0x90;
277
+ let array = new Array(token);
278
  for (let i = 0; i < token; i++) {
279
+ array[i] = read();
280
  }
281
  if (currentUnpackr.freezeData)
282
+ return Object.freeze(array);
283
+ return array;
284
  }
285
  } else if (token < 0xc0) {
286
  // fixstr
287
+ let length = token - 0xa0;
288
  if (srcStringEnd >= position) {
289
+ return srcString.slice(position - srcStringStart, (position += length) - srcStringStart);
290
  }
291
  if (srcStringEnd == 0 && srcEnd < 140) {
292
  // for small blocks, avoiding the overhead of the extract call is helpful
293
+ let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
294
  if (string != null)
295
+ return string;
296
  }
297
+ return readFixedString(length);
298
  } else {
299
+ let value;
300
  switch (token) {
301
+ case 0xc0: return null;
302
  case 0xc1:
303
  if (bundledStrings) {
304
+ value = read(); // followed by the length of the string in characters (not bytes!)
305
  if (value > 0)
306
+ return bundledStrings[1].slice(bundledStrings.position1, bundledStrings.position1 += value);
307
  else
308
+ return bundledStrings[0].slice(bundledStrings.position0, bundledStrings.position0 -= value);
309
  }
310
  return C1; // "never-used", return special object to denote that
311
+ case 0xc2: return false;
312
+ case 0xc3: return true;
313
  case 0xc4:
314
  // bin 8
315
+ value = src[position++];
316
  if (value === undefined)
317
+ throw new Error('Unexpected end of buffer');
318
+ return readBin(value);
319
  case 0xc5:
320
  // bin 16
321
+ value = dataView.getUint16(position);
322
+ position += 2;
323
+ return readBin(value);
324
  case 0xc6:
325
  // bin 32
326
+ value = dataView.getUint32(position);
327
+ position += 4;
328
+ return readBin(value);
329
  case 0xc7:
330
  // ext 8
331
+ return readExt(src[position++]);
332
  case 0xc8:
333
  // ext 16
334
+ value = dataView.getUint16(position);
335
+ position += 2;
336
+ return readExt(value);
337
  case 0xc9:
338
  // ext 32
339
+ value = dataView.getUint32(position);
340
+ position += 4;
341
+ return readExt(value);
342
  case 0xca:
343
+ value = dataView.getFloat32(position);
344
  if (currentUnpackr.useFloat32 > 2) {
345
  // this does rounding of numbers that were encoded in 32-bit float to nearest significant decimal digit that could be preserved
346
+ let multiplier = mult10[((src[position] & 0x7f) << 1) | (src[position + 1] >> 7)];
347
+ position += 4;
348
+ return ((multiplier * value + (value > 0 ? 0.5 : -0.5)) >> 0) / multiplier;
349
  }
350
+ position += 4;
351
+ return value;
352
  case 0xcb:
353
+ value = dataView.getFloat64(position);
354
+ position += 8;
355
+ return value;
356
  // uint handlers
357
  case 0xcc:
358
+ return src[position++];
359
  case 0xcd:
360
+ value = dataView.getUint16(position);
361
+ position += 2;
362
+ return value;
363
  case 0xce:
364
+ value = dataView.getUint32(position);
365
+ position += 4;
366
+ return value;
367
  case 0xcf:
368
  if (currentUnpackr.int64AsType === 'number') {
369
+ value = dataView.getUint32(position) * 0x100000000;
370
+ value += dataView.getUint32(position + 4);
371
  } else if (currentUnpackr.int64AsType === 'string') {
372
+ value = dataView.getBigUint64(position).toString();
373
  } else if (currentUnpackr.int64AsType === 'auto') {
374
+ value = dataView.getBigUint64(position);
375
+ if (value<=BigInt(2)<<BigInt(52)) value=Number(value);
376
  } else
377
+ value = dataView.getBigUint64(position);
378
+ position += 8;
379
+ return value;
380
 
381
  // int handlers
382
  case 0xd0:
383
+ return dataView.getInt8(position++);
384
  case 0xd1:
385
+ value = dataView.getInt16(position);
386
+ position += 2;
387
+ return value;
388
  case 0xd2:
389
+ value = dataView.getInt32(position);
390
+ position += 4;
391
+ return value;
392
  case 0xd3:
393
  if (currentUnpackr.int64AsType === 'number') {
394
+ value = dataView.getInt32(position) * 0x100000000;
395
+ value += dataView.getUint32(position + 4);
396
  } else if (currentUnpackr.int64AsType === 'string') {
397
+ value = dataView.getBigInt64(position).toString();
398
  } else if (currentUnpackr.int64AsType === 'auto') {
399
+ value = dataView.getBigInt64(position);
400
+ if (value>=BigInt(-2)<<BigInt(52)&&value<=BigInt(2)<<BigInt(52)) value=Number(value);
401
  } else
402
+ value = dataView.getBigInt64(position);
403
+ position += 8;
404
+ return value;
405
 
406
  case 0xd4:
407
  // fixext 1
408
+ value = src[position++];
409
  if (value == 0x72) {
410
+ return recordDefinition(src[position++] & 0x3f);
411
  } else {
412
+ let extension = currentExtensions[value];
413
  if (extension) {
414
  if (extension.read) {
415
+ position++; // skip filler byte
416
+ return extension.read(read());
417
  } else if (extension.noBuffer) {
418
+ position++; // skip filler byte
419
+ return extension();
420
  } else
421
+ return extension(src.subarray(position, ++position));
422
  } else
423
+ throw new Error('Unknown extension ' + value);
424
  }
425
  case 0xd5:
426
  // fixext 2
427
+ value = src[position];
428
  if (value == 0x72) {
429
+ position++;
430
+ return recordDefinition(src[position++] & 0x3f, src[position++]);
431
  } else
432
+ return readExt(2);
433
  case 0xd6:
434
  // fixext 4
435
+ return readExt(4);
436
  case 0xd7:
437
  // fixext 8
438
+ return readExt(8);
439
  case 0xd8:
440
  // fixext 16
441
+ return readExt(16);
442
  case 0xd9:
443
  // str 8
444
+ value = src[position++];
445
  if (srcStringEnd >= position) {
446
+ return srcString.slice(position - srcStringStart, (position += value) - srcStringStart);
447
  }
448
+ return readString8(value);
449
  case 0xda:
450
  // str 16
451
+ value = dataView.getUint16(position);
452
+ position += 2;
453
  if (srcStringEnd >= position) {
454
+ return srcString.slice(position - srcStringStart, (position += value) - srcStringStart);
455
  }
456
+ return readString16(value);
457
  case 0xdb:
458
  // str 32
459
+ value = dataView.getUint32(position);
460
+ position += 4;
461
  if (srcStringEnd >= position) {
462
+ return srcString.slice(position - srcStringStart, (position += value) - srcStringStart);
463
  }
464
+ return readString32(value);
465
  case 0xdc:
466
  // array 16
467
+ value = dataView.getUint16(position);
468
+ position += 2;
469
+ return readArray(value);
470
  case 0xdd:
471
  // array 32
472
+ value = dataView.getUint32(position);
473
+ position += 4;
474
+ return readArray(value);
475
  case 0xde:
476
  // map 16
477
+ value = dataView.getUint16(position);
478
+ position += 2;
479
+ return readMap(value);
480
  case 0xdf:
481
  // map 32
482
+ value = dataView.getUint32(position);
483
+ position += 4;
484
+ return readMap(value);
485
  default: // negative int
486
  if (token >= 0xe0)
487
+ return token - 0x100;
488
  if (token === undefined) {
489
+ let error = new Error('Unexpected end of MessagePack data');
490
+ error.incomplete = true;
491
+ throw error;
492
  }
493
+ throw new Error('Unknown MessagePack token ' + token);
494
 
495
  }
496
  }
497
  }
498
+ const validName = /^[a-zA-Z_$][a-zA-Z\d_$]*$/;
499
  function createStructureReader(structure, firstId) {
500
  function readObject() {
501
  // This initial function is quick to instantiate, but runs slower. After several iterations pay the cost to build the faster function
502
  if (readObject.count++ > inlineObjectReadThreshold) {
503
+ let optimizedReadObject;
504
  try {
505
  optimizedReadObject = structure.read = (new Function('r', 'return function(){return ' + (currentUnpackr.freezeData ? 'Object.freeze' : '') +
506
+ '({' + structure.map(key => key === '__proto__' ? '__proto_:r()' : validName.test(key) ? key + ':r()' : ('[' + JSON.stringify(key) + ']:r()')).join(',') + '})}'))(read);
507
  } catch(error) {
508
  // in CF workers, the new Function call could begin to fail at any point in time
509
+ inlineObjectReadThreshold = Infinity; // disable going forward
510
  return readObject(); // recursively try again
511
  }
512
+ structure.read0 = optimizedReadObject; // keep the un-wrapped body reader in sync
513
  if (structure.highByte === 0)
514
+ structure.read = createSecondByteReader(firstId, structure.read);
515
+ return optimizedReadObject(); // second byte is already read, if there is one so immediately read object
516
  }
517
+ let object = {};
518
  for (let i = 0, l = structure.length; i < l; i++) {
519
+ let key = structure[i];
520
  if (key === '__proto__')
521
+ key = '__proto_';
522
+ object[key] = read();
523
  }
524
  if (currentUnpackr.freezeData)
525
  return Object.freeze(object);
526
+ return object;
527
  }
528
+ readObject.count = 0;
529
+ // read0 is the un-wrapped body reader: it reads the record's values directly without
530
+ // consuming a leading high byte. recordDefinition uses it for the immediate read that follows
531
+ // a record definition (the high byte, if present, was already consumed). For highByte === 0
532
+ // structures the public reader is a second-byte reader (used by later references), but the
533
+ // definition read itself must not consume that byte.
534
+ structure.read0 = readObject;
535
  if (structure.highByte === 0) {
536
+ return createSecondByteReader(firstId, readObject);
537
  }
538
+ return readObject;
539
  }
540
 
541
  const createSecondByteReader = (firstId, read0) => {
542
  return function() {
543
+ let highByte = src[position++];
544
  if (highByte === 0)
545
+ return read0();
546
+ let id = firstId < 32 ? -(firstId + (highByte << 5)) : firstId + (highByte << 5);
547
+ let structure = currentStructures[id] || loadStructures()[id];
548
  if (!structure) {
549
+ throw new Error('Record id is not defined for ' + id);
550
  }
551
  if (!structure.read)
552
+ structure.read = createStructureReader(structure, firstId);
553
+ return structure.read();
554
+ };
555
+ };
556
 
557
  export function loadStructures() {
558
  let loadedStructures = saveState(() => {
559
  // save the state in case getStructures modifies our buffer
560
+ src = null;
561
+ return currentUnpackr.getStructures();
562
+ });
563
+ return currentStructures = currentUnpackr._mergeStructures(loadedStructures, currentStructures);
564
  }
565
 
566
+ var readFixedString = readStringJS;
567
+ var readString8 = readStringJS;
568
+ var readString16 = readStringJS;
569
+ var readString32 = readStringJS;
570
+ export let isNativeAccelerationEnabled = false;
571
 
572
  export function setExtractor(extractStrings) {
573
+ isNativeAccelerationEnabled = true;
574
+ readFixedString = readString(1);
575
+ readString8 = readString(2);
576
+ readString16 = readString(3);
577
+ readString32 = readString(5);
578
  function readString(headerLength) {
579
  return function readString(length) {
580
+ let string = strings[stringPosition++];
581
  if (string == null) {
582
  if (bundledStrings)
583
+ return readStringJS(length);
584
+ let byteOffset = src.byteOffset;
585
+ let extraction = extractStrings(position - headerLength + byteOffset, srcEnd + byteOffset, src.buffer);
586
  if (typeof extraction == 'string') {
587
+ string = extraction;
588
+ strings = EMPTY_ARRAY;
589
  } else {
590
+ strings = extraction;
591
+ stringPosition = 1;
592
+ srcStringEnd = 1; // even if a utf-8 string was decoded, must indicate we are in the midst of extracted strings and can't skip strings
593
+ string = strings[0];
594
  if (string === undefined)
595
+ throw new Error('Unexpected end of buffer');
596
  }
597
  }
598
+ let srcStringLength = string.length;
599
  if (srcStringLength <= length) {
600
+ position += length;
601
+ return string;
602
  }
603
+ srcString = string;
604
+ srcStringStart = position;
605
+ srcStringEnd = position + srcStringLength;
606
+ position += length;
607
+ return string.slice(0, length); // we know we just want the beginning
608
+ };
609
  }
610
  }
611
  function readStringJS(length) {
612
+ let result;
613
  if (length < 16) {
614
  if (result = shortStringInJS(length))
615
+ return result;
616
  }
617
  if (length > 64 && decoder)
618
+ return decoder.decode(src.subarray(position, position += length));
619
+ const end = position + length;
620
+ const units = [];
621
+ result = '';
622
  while (position < end) {
623
+ const byte1 = src[position++];
624
  if ((byte1 & 0x80) === 0) {
625
  // 1 byte
626
+ units.push(byte1);
627
  } else if ((byte1 & 0xe0) === 0xc0) {
628
  // 2 bytes
629
+ if (byte1 < 0xc2 || position >= end || (src[position] & 0xc0) !== 0x80) {
630
+ units.push(0xFFFD);
 
 
 
631
  } else {
632
+ const byte2 = src[position++] & 0x3f;
633
+ units.push(((byte1 & 0x1f) << 6) | byte2);
634
  }
635
  } else if ((byte1 & 0xf0) === 0xe0) {
636
  // 3 bytes
637
+ const byte2 = position < end ? src[position] : 0;
638
+ if (position >= end || (byte2 & 0xc0) !== 0x80 ||
639
+ (byte1 === 0xe0 && byte2 < 0xa0) || (byte1 === 0xed && byte2 >= 0xa0)) {
640
+ units.push(0xFFFD);
 
 
 
641
  } else {
642
+ position++;
643
+ if (position >= end || (src[position] & 0xc0) !== 0x80) {
644
+ units.push(0xFFFD);
645
+ } else {
646
+ const byte3 = src[position++] & 0x3f;
647
+ units.push(((byte1 & 0x1f) << 12) | ((byte2 & 0x3f) << 6) | byte3);
648
+ }
649
  }
650
  } else if ((byte1 & 0xf8) === 0xf0) {
651
  // 4 bytes
652
+ const byte2 = position < end ? src[position] : 0;
653
+ if (byte1 > 0xf4 || position >= end || (byte2 & 0xc0) !== 0x80 ||
654
+ (byte1 === 0xf0 && byte2 < 0x90) || (byte1 === 0xf4 && byte2 >= 0x90)) {
655
+ units.push(0xFFFD);
 
 
 
 
 
 
 
 
 
656
  } else {
657
+ position++;
658
+ if (position >= end || (src[position] & 0xc0) !== 0x80) {
659
+ units.push(0xFFFD);
660
+ } else {
661
+ const byte3 = src[position++] & 0x3f;
662
+ if (position >= end || (src[position] & 0xc0) !== 0x80) {
663
+ units.push(0xFFFD);
664
+ } else {
665
+ const byte4 = src[position++] & 0x3f;
666
+ let unit = ((byte1 & 0x07) << 0x12) | ((byte2 & 0x3f) << 0x0c) | (byte3 << 0x06) | byte4;
667
+ unit -= 0x10000;
668
+ units.push(((unit >>> 10) & 0x3ff) | 0xd800);
669
+ units.push(0xdc00 | (unit & 0x3ff));
670
+ }
671
+ }
672
  }
673
  } else {
674
+ units.push(0xFFFD); // replacement character for invalid lead byte
675
  }
676
 
677
  if (units.length >= 0x1000) {
678
+ result += fromCharCode.apply(String, units);
679
+ units.length = 0;
680
  }
681
  }
682
 
683
  if (units.length > 0) {
684
+ result += fromCharCode.apply(String, units);
685
  }
686
 
687
+ return result;
688
  }
689
  export function readString(source, start, length) {
690
  let existingSrc = src;
 
698
  }
699
 
700
  function readArray(length) {
701
+ let array = new Array(length);
702
  for (let i = 0; i < length; i++) {
703
+ array[i] = read();
704
  }
705
  if (currentUnpackr.freezeData)
706
+ return Object.freeze(array);
707
+ return array;
708
  }
709
 
710
  function readMap(length) {
711
  if (currentUnpackr.mapsAsObjects) {
712
+ let object = {};
713
  for (let i = 0; i < length; i++) {
714
+ let key = readKey();
715
  if (key === '__proto__')
716
  key = '__proto_';
717
+ object[key] = read();
718
  }
719
+ return object;
720
  } else {
721
+ let map = new Map();
722
  for (let i = 0; i < length; i++) {
723
+ map.set(read(), read());
724
  }
725
+ return map;
726
  }
727
  }
728
 
729
+ var fromCharCode = String.fromCharCode;
730
  function longStringInJS(length) {
731
+ let start = position;
732
+ let bytes = new Array(length);
733
  for (let i = 0; i < length; i++) {
734
  const byte = src[position++];
735
  if ((byte & 0x80) > 0) {
736
+ position = start;
737
+ return;
738
  }
739
+ bytes[i] = byte;
740
  }
741
+ return fromCharCode.apply(String, bytes);
742
  }
743
  function shortStringInJS(length) {
744
  if (length < 4) {
745
  if (length < 2) {
746
  if (length === 0)
747
+ return '';
748
  else {
749
+ let a = src[position++];
750
  if ((a & 0x80) > 1) {
751
+ position -= 1;
752
+ return;
753
  }
754
+ return fromCharCode(a);
755
  }
756
  } else {
757
+ let a = src[position++];
758
+ let b = src[position++];
759
  if ((a & 0x80) > 0 || (b & 0x80) > 0) {
760
+ position -= 2;
761
+ return;
762
  }
763
  if (length < 3)
764
+ return fromCharCode(a, b);
765
+ let c = src[position++];
766
  if ((c & 0x80) > 0) {
767
+ position -= 3;
768
+ return;
769
  }
770
+ return fromCharCode(a, b, c);
771
  }
772
  } else {
773
+ let a = src[position++];
774
+ let b = src[position++];
775
+ let c = src[position++];
776
+ let d = src[position++];
777
  if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
778
+ position -= 4;
779
+ return;
780
  }
781
  if (length < 6) {
782
  if (length === 4)
783
+ return fromCharCode(a, b, c, d);
784
  else {
785
+ let e = src[position++];
786
  if ((e & 0x80) > 0) {
787
+ position -= 5;
788
+ return;
789
  }
790
+ return fromCharCode(a, b, c, d, e);
791
  }
792
  } else if (length < 8) {
793
+ let e = src[position++];
794
+ let f = src[position++];
795
  if ((e & 0x80) > 0 || (f & 0x80) > 0) {
796
+ position -= 6;
797
+ return;
798
  }
799
  if (length < 7)
800
+ return fromCharCode(a, b, c, d, e, f);
801
+ let g = src[position++];
802
  if ((g & 0x80) > 0) {
803
+ position -= 7;
804
+ return;
805
  }
806
+ return fromCharCode(a, b, c, d, e, f, g);
807
  } else {
808
+ let e = src[position++];
809
+ let f = src[position++];
810
+ let g = src[position++];
811
+ let h = src[position++];
812
  if ((e & 0x80) > 0 || (f & 0x80) > 0 || (g & 0x80) > 0 || (h & 0x80) > 0) {
813
+ position -= 8;
814
+ return;
815
  }
816
  if (length < 10) {
817
  if (length === 8)
818
+ return fromCharCode(a, b, c, d, e, f, g, h);
819
  else {
820
+ let i = src[position++];
821
  if ((i & 0x80) > 0) {
822
+ position -= 9;
823
+ return;
824
  }
825
+ return fromCharCode(a, b, c, d, e, f, g, h, i);
826
  }
827
  } else if (length < 12) {
828
+ let i = src[position++];
829
+ let j = src[position++];
830
  if ((i & 0x80) > 0 || (j & 0x80) > 0) {
831
+ position -= 10;
832
+ return;
833
  }
834
  if (length < 11)
835
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j);
836
+ let k = src[position++];
837
  if ((k & 0x80) > 0) {
838
+ position -= 11;
839
+ return;
840
  }
841
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k);
842
  } else {
843
+ let i = src[position++];
844
+ let j = src[position++];
845
+ let k = src[position++];
846
+ let l = src[position++];
847
  if ((i & 0x80) > 0 || (j & 0x80) > 0 || (k & 0x80) > 0 || (l & 0x80) > 0) {
848
+ position -= 12;
849
+ return;
850
  }
851
  if (length < 14) {
852
  if (length === 12)
853
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l);
854
  else {
855
+ let m = src[position++];
856
  if ((m & 0x80) > 0) {
857
+ position -= 13;
858
+ return;
859
  }
860
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m);
861
  }
862
  } else {
863
+ let m = src[position++];
864
+ let n = src[position++];
865
  if ((m & 0x80) > 0 || (n & 0x80) > 0) {
866
+ position -= 14;
867
+ return;
868
  }
869
  if (length < 15)
870
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n);
871
+ let o = src[position++];
872
  if ((o & 0x80) > 0) {
873
+ position -= 15;
874
+ return;
875
  }
876
+ return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
877
  }
878
  }
879
  }
 
881
  }
882
 
883
  function readOnlyJSString() {
884
+ let token = src[position++];
885
+ let length;
886
  if (token < 0xc0) {
887
  // fixstr
888
+ length = token - 0xa0;
889
  } else {
890
  switch(token) {
891
  case 0xd9:
892
  // str 8
893
+ length = src[position++];
894
+ break;
895
  case 0xda:
896
  // str 16
897
+ length = dataView.getUint16(position);
898
+ position += 2;
899
+ break;
900
  case 0xdb:
901
  // str 32
902
+ length = dataView.getUint32(position);
903
+ position += 4;
904
+ break;
905
  default:
906
+ throw new Error('Expected string');
907
  }
908
  }
909
+ return readStringJS(length);
910
  }
911
 
912
 
 
914
  return currentUnpackr.copyBuffers ?
915
  // specifically use the copying slice (not the node one)
916
  Uint8Array.prototype.slice.call(src, position, position += length) :
917
+ src.subarray(position, position += length);
918
  }
919
  function readExt(length) {
920
+ let type = src[position++];
921
  if (currentExtensions[type]) {
922
+ let end;
923
  return currentExtensions[type](src.subarray(position, end = (position += length)), (readPosition) => {
924
  position = readPosition;
925
  try {
 
927
  } finally {
928
  position = end;
929
  }
930
+ });
931
  }
932
  else
933
+ throw new Error('Unknown extension type ' + type);
934
  }
935
 
936
+ var keyCache = new Array(4096);
937
  function readKey() {
938
+ let length = src[position++];
939
  if (length >= 0xa0 && length < 0xc0) {
940
  // fixstr, potentially use key cache
941
+ length = length - 0xa0;
942
  if (srcStringEnd >= position) // if it has been extracted, must use it (and faster anyway)
943
+ return srcString.slice(position - srcStringStart, (position += length) - srcStringStart);
944
  else if (!(srcStringEnd == 0 && srcEnd < 180))
945
+ return readFixedString(length);
946
  } else { // not cacheable, go back and do a standard read
947
+ position--;
948
+ return asSafeString(read());
949
  }
950
+ let key = ((length << 5) ^ (length > 1 ? dataView.getUint16(position) : length > 0 ? src[position] : 0)) & 0xfff;
951
+ let entry = keyCache[key];
952
+ let checkPosition = position;
953
+ let end = position + length - 3;
954
+ let chunk;
955
+ let i = 0;
956
  if (entry && entry.bytes == length) {
957
  while (checkPosition < end) {
958
+ chunk = dataView.getUint32(checkPosition);
959
  if (chunk != entry[i++]) {
960
+ checkPosition = 0x70000000;
961
+ break;
962
  }
963
+ checkPosition += 4;
964
  }
965
+ end += 3;
966
  while (checkPosition < end) {
967
+ chunk = src[checkPosition++];
968
  if (chunk != entry[i++]) {
969
+ checkPosition = 0x70000000;
970
+ break;
971
  }
972
  }
973
  if (checkPosition === end) {
974
+ position = checkPosition;
975
+ return entry.string;
976
  }
977
+ end -= 3;
978
+ checkPosition = position;
979
  }
980
+ entry = [];
981
+ keyCache[key] = entry;
982
+ entry.bytes = length;
983
  while (checkPosition < end) {
984
+ chunk = dataView.getUint32(checkPosition);
985
+ entry.push(chunk);
986
+ checkPosition += 4;
987
  }
988
+ end += 3;
989
  while (checkPosition < end) {
990
+ chunk = src[checkPosition++];
991
+ entry.push(chunk);
992
  }
993
  // for small blocks, avoiding the overhead of the extract call is helpful
994
+ let string = length < 16 ? shortStringInJS(length) : longStringInJS(length);
995
  if (string != null)
996
+ return entry.string = string;
997
+ return entry.string = readFixedString(length);
998
  }
999
 
1000
  function asSafeString(property) {
 
1009
  }
1010
  // the registration of the record definition extension (as "r")
1011
  const recordDefinition = (id, highByte) => {
1012
+ let structure = read().map(asSafeString); // ensure that all keys are strings and
1013
  // that the array is mutable
1014
+ let firstByte = id;
1015
  if (highByte !== undefined) {
1016
+ id = id < 32 ? -((highByte << 5) + id) : ((highByte << 5) + id);
1017
+ structure.highByte = highByte;
1018
  }
1019
+ let existingStructure = currentStructures[id];
1020
  // If it is a shared structure, we need to restore any changes after reading.
1021
  // Also in sequential mode, we may get incomplete reads and thus errors, and we need to restore
1022
  // to the state prior to an incomplete read in order to properly resume.
1023
  if (existingStructure && (existingStructure.isShared || sequentialMode)) {
1024
+ (currentStructures.restoreStructures || (currentStructures.restoreStructures = []))[id] = existingStructure;
1025
  }
1026
+ currentStructures[id] = structure;
1027
+ structure.read = createStructureReader(structure, firstByte);
1028
+ // The high byte (if any) was already consumed as the `highByte` argument above, so read the
1029
+ // record body directly. Going through structure.read (a second-byte reader when highByte === 0)
1030
+ // would misinterpret the first value byte as a high byte — corrupting two-byte own-record
1031
+ // definitions (0xd5 0x72 ...). createStructureReader stashes the un-wrapped body reader on
1032
+ // structure.read0 precisely for this immediate post-definition read.
1033
+ return (structure.read0 || structure.read)();
1034
+ };
1035
+ currentExtensions[0] = () => {}; // notepack defines extension 0 to mean undefined, so use that as the default here
1036
+ currentExtensions[0].noBuffer = true;
1037
 
1038
  currentExtensions[0x42] = data => {
1039
+ let headLength = (data.byteLength % 8) || 8;
1040
+ let head = BigInt(data[0] & 0x80 ? data[0] - 0x100 : data[0]);
1041
  for (let i = 1; i < headLength; i++) {
1042
+ head <<= BigInt(8);
1043
+ head += BigInt(data[i]);
1044
  }
1045
  if (data.byteLength !== headLength) {
1046
+ let view = new DataView(data.buffer, data.byteOffset, data.byteLength);
1047
  let decode = (start, end) => {
1048
+ let length = end - start;
1049
  if (length <= 40) {
1050
+ let out = view.getBigUint64(start);
1051
  for (let i = start + 8; i < end; i += 8) {
1052
+ out <<= BigInt(64);
1053
+ out |= view.getBigUint64(i);
1054
  }
1055
+ return out;
1056
  }
1057
  // if (length === 8) return view.getBigUint64(start)
1058
+ let middle = start + (length >> 4 << 3);
1059
+ let left = decode(start, middle);
1060
+ let right = decode(middle, end);
1061
+ return (left << BigInt((end - middle) * 8)) | right;
1062
+ };
1063
+ head = (head << BigInt((view.byteLength - headLength) * 8)) | decode(headLength, view.byteLength);
1064
  }
1065
+ return head;
1066
+ };
1067
 
1068
  let errors = {
1069
  Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError, AggregateError: typeof AggregateError === 'function' ? AggregateError : null,
1070
+ };
1071
  currentExtensions[0x65] = () => {
1072
+ let data = read();
1073
  if (!errors[data[0]]) {
1074
+ let error = Error(data[1], { cause: data[2] });
1075
+ error.name = data[0];
1076
+ return error;
1077
  }
1078
+ return errors[data[0]](data[1], { cause: data[2] });
1079
+ };
1080
 
1081
  currentExtensions[0x69] = (data) => {
1082
  // id extension (for structured clones)
1083
+ if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled');
1084
+ let id = dataView.getUint32(position - 4);
1085
  if (!referenceMap)
1086
+ referenceMap = new Map();
1087
+ let token = src[position];
1088
+ let target;
1089
  // TODO: handle any other types that can cycle and make the code more robust if there are other extensions
1090
  if (token >= 0x90 && token < 0xa0 || token == 0xdc || token == 0xdd)
1091
+ target = [];
1092
  else if (token >= 0x80 && token < 0x90 || token == 0xde || token == 0xdf)
1093
+ target = new Map();
1094
  else if ((token >= 0xc7 && token <= 0xc9 || token >= 0xd4 && token <= 0xd8) && src[position + 1] === 0x73)
1095
+ target = new Set();
1096
  else
1097
+ target = {};
1098
 
1099
+ let refEntry = { target }; // a placeholder object
1100
+ referenceMap.set(id, refEntry);
1101
+ let targetProperties = read(); // read the next value as the target object to id
1102
  if (!refEntry.used) {
1103
  // no cycle, can just use the returned read object
1104
+ return refEntry.target = targetProperties; // replace the placeholder with the real one
1105
  } else {
1106
  // there is a cycle, so we have to assign properties to original target
1107
+ Object.assign(target, targetProperties);
1108
  }
1109
 
1110
  // copy over map/set entries if we're able to
1111
  if (target instanceof Map)
1112
+ for (let [k, v] of targetProperties.entries()) target.set(k, v);
1113
  if (target instanceof Set)
1114
+ for (let i of Array.from(targetProperties)) target.add(i);
1115
+ return target;
1116
+ };
1117
 
1118
  currentExtensions[0x70] = (data) => {
1119
  // pointer extension (for structured clones)
1120
+ if (currentUnpackr.structuredClone === false) throw new Error('Structured clone extension is disabled');
1121
+ let id = dataView.getUint32(position - 4);
1122
+ let refEntry = referenceMap.get(id);
1123
+ refEntry.used = true;
1124
+ return refEntry.target;
1125
+ };
1126
 
1127
+ currentExtensions[0x73] = () => new Set(read());
1128
 
1129
+ export const typedArrays = ['Int8','Uint8','Uint8Clamped','Int16','Uint16','Int32','Uint32','Float32','Float64','BigInt64','BigUint64'].map(type => type + 'Array');
1130
 
1131
  let glbl = typeof globalThis === 'object' ? globalThis : window;
1132
  currentExtensions[0x74] = (data) => {
1133
+ let typeCode = data[0];
1134
  // we always have to slice to get a new ArrayBuffer that is aligned
1135
+ let buffer = Uint8Array.prototype.slice.call(data, 1).buffer;
1136
 
1137
+ let typedArrayName = typedArrays[typeCode];
1138
  if (!typedArrayName) {
1139
+ if (typeCode === 16) return buffer;
1140
+ if (typeCode === 17) return new DataView(buffer);
1141
+ throw new Error('Could not find typed array for code ' + typeCode);
1142
  }
1143
+ return new glbl[typedArrayName](buffer);
1144
+ };
1145
  currentExtensions[0x78] = () => {
1146
+ let data = read();
1147
+ return new RegExp(data[0], data[1]);
1148
+ };
1149
+ const TEMP_BUNDLE = [];
1150
  currentExtensions[0x62] = (data) => {
1151
+ let dataSize = (data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3];
1152
+ let dataPosition = position;
1153
+ position += dataSize - data.length;
1154
+ bundledStrings = TEMP_BUNDLE;
1155
+ bundledStrings = [readOnlyJSString(), readOnlyJSString()];
1156
+ bundledStrings.position0 = 0;
1157
+ bundledStrings.position1 = 0;
1158
+ bundledStrings.postBundlePosition = position;
1159
+ position = dataPosition;
1160
+ return read();
1161
+ };
1162
 
1163
  currentExtensions[0xff] = (data) => {
1164
  // 32-bit date extension
1165
  if (data.length == 4)
1166
+ return new Date((data[0] * 0x1000000 + (data[1] << 16) + (data[2] << 8) + data[3]) * 1000);
1167
  else if (data.length == 8)
1168
  return new Date(
1169
  ((data[0] << 22) + (data[1] << 14) + (data[2] << 6) + (data[3] >> 2)) / 1000000 +
1170
+ ((data[3] & 0x3) * 0x100000000 + data[4] * 0x1000000 + (data[5] << 16) + (data[6] << 8) + data[7]) * 1000);
1171
  else if (data.length == 12)
1172
  return new Date(
1173
  ((data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]) / 1000000 +
1174
+ (((data[4] & 0x80) ? -0x1000000000000 : 0) + data[6] * 0x10000000000 + data[7] * 0x100000000 + data[8] * 0x1000000 + (data[9] << 16) + (data[10] << 8) + data[11]) * 1000);
1175
  else
1176
+ return new Date('invalid');
1177
+ };
1178
  // registration of bulk record definition?
1179
  // currentExtensions[0x52] = () =>
1180
 
1181
  function saveState(callback) {
1182
+ if (currentUnpackr && currentUnpackr._onSaveState)
1183
+ currentUnpackr._onSaveState();
1184
+ let savedSrcEnd = srcEnd;
1185
+ let savedPosition = position;
1186
+ let savedStringPosition = stringPosition;
1187
+ let savedSrcStringStart = srcStringStart;
1188
+ let savedSrcStringEnd = srcStringEnd;
1189
+ let savedSrcString = srcString;
1190
+ let savedStrings = strings;
1191
+ let savedReferenceMap = referenceMap;
1192
+ let savedBundledStrings = bundledStrings;
1193
 
1194
  // TODO: We may need to revisit this if we do more external calls to user code (since it could be slow)
1195
+ let savedSrc = new Uint8Array(src.slice(0, srcEnd)); // we copy the data in case it changes while external data is processed
1196
+ let savedStructures = currentStructures;
1197
+ let savedStructuresContents = currentStructures.slice(0, currentStructures.length);
1198
+ let savedPackr = currentUnpackr;
1199
+ let savedSequentialMode = sequentialMode;
1200
+ let value = callback();
1201
+ srcEnd = savedSrcEnd;
1202
+ position = savedPosition;
1203
+ stringPosition = savedStringPosition;
1204
+ srcStringStart = savedSrcStringStart;
1205
+ srcStringEnd = savedSrcStringEnd;
1206
+ srcString = savedSrcString;
1207
+ strings = savedStrings;
1208
+ referenceMap = savedReferenceMap;
1209
+ bundledStrings = savedBundledStrings;
1210
+ src = savedSrc;
1211
+ sequentialMode = savedSequentialMode;
1212
+ currentStructures = savedStructures;
1213
+ currentStructures.splice(0, currentStructures.length, ...savedStructuresContents);
1214
+ currentUnpackr = savedPackr;
1215
+ dataView = new DataView(src.buffer, src.byteOffset, src.byteLength);
1216
+ return value;
1217
  }
1218
  export function clearSource() {
1219
+ src = null;
1220
+ referenceMap = null;
1221
+ currentStructures = null;
1222
  }
1223
 
1224
  export function addExtension(extension) {
1225
  if (extension.unpack)
1226
+ currentExtensions[extension.type] = extension.unpack;
1227
  else
1228
+ currentExtensions[extension.type] = extension;
1229
  }
1230
 
1231
+ export const mult10 = new Array(147); // this is a table matching binary exponents to the multiplier to determine significant digit rounding
1232
  for (let i = 0; i < 256; i++) {
1233
+ mult10[i] = +('1e' + Math.floor(45.15 - i * 0.30103));
1234
  }
1235
+ export const Decoder = Unpackr;
1236
+ var defaultUnpackr = new Unpackr({ useRecords: false });
1237
+ export const unpack = defaultUnpackr.unpack;
1238
+ export const unpackMultiple = defaultUnpackr.unpackMultiple;
1239
+ export const decode = defaultUnpackr.unpack;
1240
  export const FLOAT32_OPTIONS = {
1241
  NEVER: 0,
1242
  ALWAYS: 1,
1243
  DECIMAL_ROUND: 3,
1244
  DECIMAL_FIT: 4
1245
+ };
1246
+ let f32Array = new Float32Array(1);
1247
+ let u8Array = new Uint8Array(f32Array.buffer, 0, 4);
1248
  export function roundFloat32(float32Number) {
1249
+ f32Array[0] = float32Number;
1250
+ let multiplier = mult10[((u8Array[3] & 0x7f) << 1) | (u8Array[2] >> 7)];
1251
+ return ((multiplier * float32Number + (float32Number > 0 ? 0.5 : -0.5)) >> 0) / multiplier;
 
 
 
 
 
1252
  }
1253
+ // Marker for downstream libraries (e.g. structon) to detect per-instance
1254
+ // struct-decoding hooks (this._readStruct, this._onLoadedStructures,
1255
+ // this._onSaveState). See `checkedRead` for the dispatch.
1256
+ Unpackr.SUPPORTS_STRUCT_HOOKS = true;
.opencode/node_modules/multipasta/dist/cjs/web.js CHANGED
@@ -36,6 +36,7 @@ const make = config => {
36
  let error;
37
  let partBuffer = [];
38
  let readResolve;
 
39
  let finished = false;
40
  const parser = MP.make({
41
  ...config,
@@ -50,7 +51,6 @@ const make = config => {
50
  },
51
  onFile(info) {
52
  let chunkBuffer = [];
53
- let chunkResolve;
54
  let finished = false;
55
  const readable = new ReadableStream({
56
  pull(controller) {
@@ -60,6 +60,8 @@ const make = config => {
60
  for (const chunk of chunks) {
61
  controller.enqueue(chunk);
62
  }
 
 
63
  } else if (finished) {
64
  controller.close();
65
  } else {
@@ -92,6 +94,7 @@ const make = config => {
92
  onError(error_) {
93
  if (error !== undefined) return;
94
  error = error_;
 
95
  if (readResolve !== undefined) readResolve();
96
  },
97
  onDone() {
@@ -100,7 +103,7 @@ const make = config => {
100
  }
101
  });
102
  const writable = new WritableStream({
103
- write(chunk, controller) {
104
  parser.write(chunk);
105
  },
106
  close() {
 
36
  let error;
37
  let partBuffer = [];
38
  let readResolve;
39
+ let chunkResolve;
40
  let finished = false;
41
  const parser = MP.make({
42
  ...config,
 
51
  },
52
  onFile(info) {
53
  let chunkBuffer = [];
 
54
  let finished = false;
55
  const readable = new ReadableStream({
56
  pull(controller) {
 
60
  for (const chunk of chunks) {
61
  controller.enqueue(chunk);
62
  }
63
+ } else if (error) {
64
+ controller.error(error);
65
  } else if (finished) {
66
  controller.close();
67
  } else {
 
94
  onError(error_) {
95
  if (error !== undefined) return;
96
  error = error_;
97
+ if (chunkResolve !== undefined) chunkResolve();
98
  if (readResolve !== undefined) readResolve();
99
  },
100
  onDone() {
 
103
  }
104
  });
105
  const writable = new WritableStream({
106
+ write(chunk, _controller) {
107
  parser.write(chunk);
108
  },
109
  close() {
.opencode/node_modules/multipasta/dist/cjs/web.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","names":["MP","_interopRequireWildcard","require","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","make","config","headers","fromEntries","error","partBuffer","readResolve","finished","parser","onField","info","value","push","_tag","undefined","onFile","chunkBuffer","chunkResolve","readable","ReadableStream","pull","controller","length","chunks","chunk","enqueue","close","Promise","resolve","then","onError","error_","onDone","writable","WritableStream","write","end","parts","part","exports"],"sources":["../../src/web.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;AAAA,IAAAA,EAAA,gBAAAC,uBAAA,cAAAC,OAAA;AAAgC,SAAAD,wBAAAE,CAAA,EAAAC,CAAA;EAAA,yBAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA;IAAAE,CAAA,OAAAF,OAAA;EAAA,QAAAJ,uBAAA,YAAAA,CAAAE,CAAA,EAAAC,CAAA;IAAA,KAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA;IAAA,IAAAM,CAAA;MAAAC,CAAA;MAAAC,CAAA;QAAAC,SAAA;QAAAC,OAAA,EAAAV;MAAA;IAAA,aAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA;IAAA,IAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA;MAAA,IAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA;MAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA;IAAA;IAAA,WAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,IAAAP,CAAA,CAAAE,CAAA,EAAAP,CAAA,EAAAM,CAAA,IAAAC,CAAA,CAAAP,CAAA,IAAAD,CAAA,CAAAC,CAAA;IAAA,OAAAO,CAAA;EAAA,GAAAR,CAAA,EAAAC,CAAA;AAAA;AA4BzB,MAAMkB,IAAI,GAAIC,MAAiB,IAAsB;EAC1D,MAAMC,OAAO,GAAGL,MAAM,CAACM,WAAW,CAAC,CAAC,GAAGF,MAAM,CAACC,OAAO,CAAC,CAAC;EACvD,IAAIE,KAAoC;EACxC,IAAIC,UAAU,GAAgB,EAAE;EAChC,IAAIC,WAAqC;EACzC,IAAIC,QAAQ,GAAG,KAAK;EAEpB,MAAMC,MAAM,GAAG9B,EAAE,CAACsB,IAAI,CAAC;IACrB,GAAGC,MAAM;IACTC,OAAO;IACPO,OAAOA,CAACC,IAAI,EAAEC,KAAK;MACjBN,UAAU,CAACO,IAAI,CAAC;QAAEC,IAAI,EAAE,OAAO;QAAEH,IAAI;QAAEC;MAAK,CAAE,CAAC;MAC/C,IAAIL,WAAW,KAAKQ,SAAS,EAAER,WAAW,EAAE;IAC9C,CAAC;IACDS,MAAMA,CAACL,IAAI;MACT,IAAIM,WAAW,GAAsB,EAAE;MACvC,IAAIC,YAAsC;MAC1C,IAAIV,QAAQ,GAAG,KAAK;MAEpB,MAAMW,QAAQ,GAAG,IAAIC,cAAc,CAAa;QAC9CC,IAAIA,CAACC,UAAU;UACb,IAAIL,WAAW,CAACM,MAAM,GAAG,CAAC,EAAE;YAC1B,MAAMC,MAAM,GAAGP,WAAW;YAC1BA,WAAW,GAAG,EAAE;YAChB,KAAK,MAAMQ,KAAK,IAAID,MAAM,EAAE;cAC1BF,UAAU,CAACI,OAAO,CAACD,KAAK,CAAC;YAC3B;UACF,CAAC,MAAM,IAAIjB,QAAQ,EAAE;YACnBc,UAAU,CAACK,KAAK,EAAE;UACpB,CAAC,MAAM;YACL,OAAO,IAAIC,OAAO,CAAOC,OAAO,IAAG;cACjCX,YAAY,GAAGA,CAAA,KAAK;gBAClBA,YAAY,GAAGH,SAAS;gBACxBc,OAAO,EAAE;cACX,CAAC;YACH,CAAC,CAAC,CAACC,IAAI,CAAC,MAAM,IAAI,CAACT,IAAK,CAACC,UAAU,CAAC,CAAC;UACvC;QACF;OACD,CAAC;MAEFhB,UAAU,CAACO,IAAI,CAAC;QAAEC,IAAI,EAAE,MAAM;QAAEH,IAAI;QAAEQ;MAAQ,CAAE,CAAC;MACjD,IAAIZ,WAAW,KAAKQ,SAAS,EAAER,WAAW,EAAE;MAE5C,OAAO,UAAUkB,KAAK;QACpB,IAAIA,KAAK,KAAK,IAAI,EAAE;UAClBjB,QAAQ,GAAG,IAAI;QACjB,CAAC,MAAM;UACLS,WAAW,CAACJ,IAAI,CAACY,KAAK,CAAC;QACzB;QACA,IAAIP,YAAY,KAAKH,SAAS,EAAE;UAC9BG,YAAY,EAAE;QAChB;MACF,CAAC;IACH,CAAC;IACDa,OAAOA,CAACC,MAAM;MACZ,IAAI3B,KAAK,KAAKU,SAAS,EAAE;MACzBV,KAAK,GAAG2B,MAAM;MACd,IAAIzB,WAAW,KAAKQ,SAAS,EAAER,WAAW,EAAE;IAC9C,CAAC;IAED0B,MAAMA,CAAA;MACJzB,QAAQ,GAAG,IAAI;MACf,IAAID,WAAW,KAAKQ,SAAS,EAAER,WAAW,EAAE;IAC9C;GACD,CAAC;EAEF,MAAM2B,QAAQ,GAAG,IAAIC,cAAc,CAAa;IAC9CC,KAAKA,CAACX,KAAK,EAAEH,UAAU;MACrBb,MAAM,CAAC2B,KAAK,CAACX,KAAK,CAAC;IACrB,CAAC;IACDE,KAAKA,CAAA;MACHlB,MAAM,CAAC4B,GAAG,EAAE;IACd;GACD,CAAC;EAEF,MAAMlB,QAAQ,GAAG,IAAIC,cAAc,CAAO;IACxCC,IAAIA,CAACC,UAAU;MACb,IAAIhB,UAAU,CAACiB,MAAM,GAAG,CAAC,EAAE;QACzB,MAAMe,KAAK,GAAGhC,UAAU;QACxBA,UAAU,GAAG,EAAE;QACf,KAAK,MAAMiC,IAAI,IAAID,KAAK,EAAE;UACxBhB,UAAU,CAACI,OAAO,CAACa,IAAI,CAAC;QAC1B;MACF,CAAC,MAAM,IAAIlC,KAAK,EAAE;QAChBiB,UAAU,CAACjB,KAAK,CAACA,KAAK,CAAC;MACzB,CAAC,MAAM,IAAIG,QAAQ,EAAE;QACnBc,UAAU,CAACK,KAAK,EAAE;MACpB,CAAC,MAAM;QACL,OAAO,IAAIC,OAAO,CAAOC,OAAO,IAAG;UACjCtB,WAAW,GAAGA,CAAA,KAAK;YACjBA,WAAW,GAAGQ,SAAS;YACvBc,OAAO,EAAE;UACX,CAAC;QACH,CAAC,CAAC,CAACC,IAAI,CAAC,MAAM,IAAI,CAACT,IAAK,CAACC,UAAU,CAAC,CAAC;MACvC;IACF;GACD,CAAC;EAEF,OAAO;IACLY,QAAQ;IACRf;GACD;AACH,CAAC;AAAAqB,OAAA,CAAAvC,IAAA,GAAAA,IAAA","ignoreList":[]}
 
1
+ {"version":3,"file":"web.js","names":["MP","_interopRequireWildcard","require","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","make","config","headers","fromEntries","error","partBuffer","readResolve","chunkResolve","finished","parser","onField","info","value","push","_tag","undefined","onFile","chunkBuffer","readable","ReadableStream","pull","controller","length","chunks","chunk","enqueue","close","Promise","resolve","then","onError","error_","onDone","writable","WritableStream","write","_controller","end","parts","part","exports"],"sources":["../../src/web.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;AAAA,IAAAA,EAAA,gBAAAC,uBAAA,cAAAC,OAAA;AAAgC,SAAAD,wBAAAE,CAAA,EAAAC,CAAA;EAAA,yBAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA;IAAAE,CAAA,OAAAF,OAAA;EAAA,QAAAJ,uBAAA,YAAAA,CAAAE,CAAA,EAAAC,CAAA;IAAA,KAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA;IAAA,IAAAM,CAAA;MAAAC,CAAA;MAAAC,CAAA;QAAAC,SAAA;QAAAC,OAAA,EAAAV;MAAA;IAAA,aAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA;IAAA,IAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA;MAAA,IAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA;MAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA;IAAA;IAAA,WAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,IAAAP,CAAA,CAAAE,CAAA,EAAAP,CAAA,EAAAM,CAAA,IAAAC,CAAA,CAAAP,CAAA,IAAAD,CAAA,CAAAC,CAAA;IAAA,OAAAO,CAAA;EAAA,GAAAR,CAAA,EAAAC,CAAA;AAAA;AA4BzB,MAAMkB,IAAI,GAAIC,MAAiB,IAAsB;EAC1D,MAAMC,OAAO,GAAGL,MAAM,CAACM,WAAW,CAAC,CAAC,GAAGF,MAAM,CAACC,OAAO,CAAC,CAAC;EACvD,IAAIE,KAAoC;EACxC,IAAIC,UAAU,GAAgB,EAAE;EAChC,IAAIC,WAAqC;EACzC,IAAIC,YAAsC;EAC1C,IAAIC,QAAQ,GAAG,KAAK;EAEpB,MAAMC,MAAM,GAAG/B,EAAE,CAACsB,IAAI,CAAC;IACrB,GAAGC,MAAM;IACTC,OAAO;IACPQ,OAAOA,CAACC,IAAI,EAAEC,KAAK;MACjBP,UAAU,CAACQ,IAAI,CAAC;QAAEC,IAAI,EAAE,OAAO;QAAEH,IAAI;QAAEC;MAAK,CAAE,CAAC;MAC/C,IAAIN,WAAW,KAAKS,SAAS,EAAET,WAAW,EAAE;IAC9C,CAAC;IACDU,MAAMA,CAACL,IAAI;MACT,IAAIM,WAAW,GAAsB,EAAE;MACvC,IAAIT,QAAQ,GAAG,KAAK;MAEpB,MAAMU,QAAQ,GAAG,IAAIC,cAAc,CAAa;QAC9CC,IAAIA,CAACC,UAAU;UACb,IAAIJ,WAAW,CAACK,MAAM,GAAG,CAAC,EAAE;YAC1B,MAAMC,MAAM,GAAGN,WAAW;YAC1BA,WAAW,GAAG,EAAE;YAChB,KAAK,MAAMO,KAAK,IAAID,MAAM,EAAE;cAC1BF,UAAU,CAACI,OAAO,CAACD,KAAK,CAAC;YAC3B;UACF,CAAC,MAAM,IAAIpB,KAAK,EAAE;YAChBiB,UAAU,CAACjB,KAAK,CAACA,KAAK,CAAC;UACzB,CAAC,MAAM,IAAII,QAAQ,EAAE;YACnBa,UAAU,CAACK,KAAK,EAAE;UACpB,CAAC,MAAM;YACL,OAAO,IAAIC,OAAO,CAAOC,OAAO,IAAG;cACjCrB,YAAY,GAAGA,CAAA,KAAK;gBAClBA,YAAY,GAAGQ,SAAS;gBACxBa,OAAO,EAAE;cACX,CAAC;YACH,CAAC,CAAC,CAACC,IAAI,CAAC,MAAM,IAAI,CAACT,IAAK,CAACC,UAAU,CAAC,CAAC;UACvC;QACF;OACD,CAAC;MAEFhB,UAAU,CAACQ,IAAI,CAAC;QAAEC,IAAI,EAAE,MAAM;QAAEH,IAAI;QAAEO;MAAQ,CAAE,CAAC;MACjD,IAAIZ,WAAW,KAAKS,SAAS,EAAET,WAAW,EAAE;MAE5C,OAAO,UAAUkB,KAAK;QACpB,IAAIA,KAAK,KAAK,IAAI,EAAE;UAClBhB,QAAQ,GAAG,IAAI;QACjB,CAAC,MAAM;UACLS,WAAW,CAACJ,IAAI,CAACW,KAAK,CAAC;QACzB;QACA,IAAIjB,YAAY,KAAKQ,SAAS,EAAE;UAC9BR,YAAY,EAAE;QAChB;MACF,CAAC;IACH,CAAC;IACDuB,OAAOA,CAACC,MAAM;MACZ,IAAI3B,KAAK,KAAKW,SAAS,EAAE;MACzBX,KAAK,GAAG2B,MAAM;MACd,IAAIxB,YAAY,KAAKQ,SAAS,EAAER,YAAY,EAAE;MAC9C,IAAID,WAAW,KAAKS,SAAS,EAAET,WAAW,EAAE;IAC9C,CAAC;IAED0B,MAAMA,CAAA;MACJxB,QAAQ,GAAG,IAAI;MACf,IAAIF,WAAW,KAAKS,SAAS,EAAET,WAAW,EAAE;IAC9C;GACD,CAAC;EAEF,MAAM2B,QAAQ,GAAG,IAAIC,cAAc,CAAa;IAC9CC,KAAKA,CAACX,KAAK,EAAEY,WAAW;MACtB3B,MAAM,CAAC0B,KAAK,CAACX,KAAK,CAAC;IACrB,CAAC;IACDE,KAAKA,CAAA;MACHjB,MAAM,CAAC4B,GAAG,EAAE;IACd;GACD,CAAC;EAEF,MAAMnB,QAAQ,GAAG,IAAIC,cAAc,CAAO;IACxCC,IAAIA,CAACC,UAAU;MACb,IAAIhB,UAAU,CAACiB,MAAM,GAAG,CAAC,EAAE;QACzB,MAAMgB,KAAK,GAAGjC,UAAU;QACxBA,UAAU,GAAG,EAAE;QACf,KAAK,MAAMkC,IAAI,IAAID,KAAK,EAAE;UACxBjB,UAAU,CAACI,OAAO,CAACc,IAAI,CAAC;QAC1B;MACF,CAAC,MAAM,IAAInC,KAAK,EAAE;QAChBiB,UAAU,CAACjB,KAAK,CAACA,KAAK,CAAC;MACzB,CAAC,MAAM,IAAII,QAAQ,EAAE;QACnBa,UAAU,CAACK,KAAK,EAAE;MACpB,CAAC,MAAM;QACL,OAAO,IAAIC,OAAO,CAAOC,OAAO,IAAG;UACjCtB,WAAW,GAAGA,CAAA,KAAK;YACjBA,WAAW,GAAGS,SAAS;YACvBa,OAAO,EAAE;UACX,CAAC;QACH,CAAC,CAAC,CAACC,IAAI,CAAC,MAAM,IAAI,CAACT,IAAK,CAACC,UAAU,CAAC,CAAC;MACvC;IACF;GACD,CAAC;EAEF,OAAO;IACLY,QAAQ;IACRf;GACD;AACH,CAAC;AAAAsB,OAAA,CAAAxC,IAAA,GAAAA,IAAA","ignoreList":[]}
.opencode/node_modules/multipasta/dist/dts/web.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAA;AAEhC,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAExC,MAAM,MAAM,IAAI,GAAG,KAAK,GAAG,IAAI,CAAA;AAE/B,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;IACtB,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAA;IAC1B,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAA;CAC3B;AAED,MAAM,WAAW,IAAI;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAA;IAC1B,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC,UAAU,CAAC,CAAA;CAC9C;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC,UAAU,CAAC,CAAA;IAC7C,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC,IAAI,CAAC,CAAA;CACxC;AAED,MAAM,MAAM,SAAS,GAAG,IAAI,CAAC,EAAE,CAAC,UAAU,EAAE,SAAS,CAAC,GAAG;IACvD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAC1B,CAAA;AAED,eAAO,MAAM,IAAI,GAAI,QAAQ,SAAS,KAAG,gBAsGxC,CAAA"}
 
1
+ {"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAA;AAEhC,YAAY,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAExC,MAAM,MAAM,IAAI,GAAG,KAAK,GAAG,IAAI,CAAA;AAE/B,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;IACtB,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAA;IAC1B,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAA;CAC3B;AAED,MAAM,WAAW,IAAI;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAA;IAC1B,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC,UAAU,CAAC,CAAA;CAC9C;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC,UAAU,CAAC,CAAA;IAC7C,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC,IAAI,CAAC,CAAA;CACxC;AAED,MAAM,MAAM,SAAS,GAAG,IAAI,CAAC,EAAE,CAAC,UAAU,EAAE,SAAS,CAAC,GAAG;IACvD,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAC1B,CAAA;AAED,eAAO,MAAM,IAAI,GAAI,QAAQ,SAAS,KAAG,gBAyGxC,CAAA"}
.opencode/node_modules/multipasta/dist/esm/web.js CHANGED
@@ -5,6 +5,7 @@ export const make = config => {
5
  let error;
6
  let partBuffer = [];
7
  let readResolve;
 
8
  let finished = false;
9
  const parser = MP.make({
10
  ...config,
@@ -19,7 +20,6 @@ export const make = config => {
19
  },
20
  onFile(info) {
21
  let chunkBuffer = [];
22
- let chunkResolve;
23
  let finished = false;
24
  const readable = new ReadableStream({
25
  pull(controller) {
@@ -29,6 +29,8 @@ export const make = config => {
29
  for (const chunk of chunks) {
30
  controller.enqueue(chunk);
31
  }
 
 
32
  } else if (finished) {
33
  controller.close();
34
  } else {
@@ -61,6 +63,7 @@ export const make = config => {
61
  onError(error_) {
62
  if (error !== undefined) return;
63
  error = error_;
 
64
  if (readResolve !== undefined) readResolve();
65
  },
66
  onDone() {
@@ -69,7 +72,7 @@ export const make = config => {
69
  }
70
  });
71
  const writable = new WritableStream({
72
- write(chunk, controller) {
73
  parser.write(chunk);
74
  },
75
  close() {
 
5
  let error;
6
  let partBuffer = [];
7
  let readResolve;
8
+ let chunkResolve;
9
  let finished = false;
10
  const parser = MP.make({
11
  ...config,
 
20
  },
21
  onFile(info) {
22
  let chunkBuffer = [];
 
23
  let finished = false;
24
  const readable = new ReadableStream({
25
  pull(controller) {
 
29
  for (const chunk of chunks) {
30
  controller.enqueue(chunk);
31
  }
32
+ } else if (error) {
33
+ controller.error(error);
34
  } else if (finished) {
35
  controller.close();
36
  } else {
 
63
  onError(error_) {
64
  if (error !== undefined) return;
65
  error = error_;
66
+ if (chunkResolve !== undefined) chunkResolve();
67
  if (readResolve !== undefined) readResolve();
68
  },
69
  onDone() {
 
72
  }
73
  });
74
  const writable = new WritableStream({
75
+ write(chunk, _controller) {
76
  parser.write(chunk);
77
  },
78
  close() {
.opencode/node_modules/multipasta/dist/esm/web.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","names":["MP","decodeField","make","config","headers","Object","fromEntries","error","partBuffer","readResolve","finished","parser","onField","info","value","push","_tag","undefined","onFile","chunkBuffer","chunkResolve","readable","ReadableStream","pull","controller","length","chunks","chunk","enqueue","close","Promise","resolve","then","onError","error_","onDone","writable","WritableStream","write","end","parts","part"],"sources":["../../src/web.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAO,KAAKA,EAAE,MAAM,YAAY;AAGhC,SAASC,WAAW,QAAQ,YAAY;AAyBxC,OAAO,MAAMC,IAAI,GAAIC,MAAiB,IAAsB;EAC1D,MAAMC,OAAO,GAAGC,MAAM,CAACC,WAAW,CAAC,CAAC,GAAGH,MAAM,CAACC,OAAO,CAAC,CAAC;EACvD,IAAIG,KAAoC;EACxC,IAAIC,UAAU,GAAgB,EAAE;EAChC,IAAIC,WAAqC;EACzC,IAAIC,QAAQ,GAAG,KAAK;EAEpB,MAAMC,MAAM,GAAGX,EAAE,CAACE,IAAI,CAAC;IACrB,GAAGC,MAAM;IACTC,OAAO;IACPQ,OAAOA,CAACC,IAAI,EAAEC,KAAK;MACjBN,UAAU,CAACO,IAAI,CAAC;QAAEC,IAAI,EAAE,OAAO;QAAEH,IAAI;QAAEC;MAAK,CAAE,CAAC;MAC/C,IAAIL,WAAW,KAAKQ,SAAS,EAAER,WAAW,EAAE;IAC9C,CAAC;IACDS,MAAMA,CAACL,IAAI;MACT,IAAIM,WAAW,GAAsB,EAAE;MACvC,IAAIC,YAAsC;MAC1C,IAAIV,QAAQ,GAAG,KAAK;MAEpB,MAAMW,QAAQ,GAAG,IAAIC,cAAc,CAAa;QAC9CC,IAAIA,CAACC,UAAU;UACb,IAAIL,WAAW,CAACM,MAAM,GAAG,CAAC,EAAE;YAC1B,MAAMC,MAAM,GAAGP,WAAW;YAC1BA,WAAW,GAAG,EAAE;YAChB,KAAK,MAAMQ,KAAK,IAAID,MAAM,EAAE;cAC1BF,UAAU,CAACI,OAAO,CAACD,KAAK,CAAC;YAC3B;UACF,CAAC,MAAM,IAAIjB,QAAQ,EAAE;YACnBc,UAAU,CAACK,KAAK,EAAE;UACpB,CAAC,MAAM;YACL,OAAO,IAAIC,OAAO,CAAOC,OAAO,IAAG;cACjCX,YAAY,GAAGA,CAAA,KAAK;gBAClBA,YAAY,GAAGH,SAAS;gBACxBc,OAAO,EAAE;cACX,CAAC;YACH,CAAC,CAAC,CAACC,IAAI,CAAC,MAAM,IAAI,CAACT,IAAK,CAACC,UAAU,CAAC,CAAC;UACvC;QACF;OACD,CAAC;MAEFhB,UAAU,CAACO,IAAI,CAAC;QAAEC,IAAI,EAAE,MAAM;QAAEH,IAAI;QAAEQ;MAAQ,CAAE,CAAC;MACjD,IAAIZ,WAAW,KAAKQ,SAAS,EAAER,WAAW,EAAE;MAE5C,OAAO,UAAUkB,KAAK;QACpB,IAAIA,KAAK,KAAK,IAAI,EAAE;UAClBjB,QAAQ,GAAG,IAAI;QACjB,CAAC,MAAM;UACLS,WAAW,CAACJ,IAAI,CAACY,KAAK,CAAC;QACzB;QACA,IAAIP,YAAY,KAAKH,SAAS,EAAE;UAC9BG,YAAY,EAAE;QAChB;MACF,CAAC;IACH,CAAC;IACDa,OAAOA,CAACC,MAAM;MACZ,IAAI3B,KAAK,KAAKU,SAAS,EAAE;MACzBV,KAAK,GAAG2B,MAAM;MACd,IAAIzB,WAAW,KAAKQ,SAAS,EAAER,WAAW,EAAE;IAC9C,CAAC;IAED0B,MAAMA,CAAA;MACJzB,QAAQ,GAAG,IAAI;MACf,IAAID,WAAW,KAAKQ,SAAS,EAAER,WAAW,EAAE;IAC9C;GACD,CAAC;EAEF,MAAM2B,QAAQ,GAAG,IAAIC,cAAc,CAAa;IAC9CC,KAAKA,CAACX,KAAK,EAAEH,UAAU;MACrBb,MAAM,CAAC2B,KAAK,CAACX,KAAK,CAAC;IACrB,CAAC;IACDE,KAAKA,CAAA;MACHlB,MAAM,CAAC4B,GAAG,EAAE;IACd;GACD,CAAC;EAEF,MAAMlB,QAAQ,GAAG,IAAIC,cAAc,CAAO;IACxCC,IAAIA,CAACC,UAAU;MACb,IAAIhB,UAAU,CAACiB,MAAM,GAAG,CAAC,EAAE;QACzB,MAAMe,KAAK,GAAGhC,UAAU;QACxBA,UAAU,GAAG,EAAE;QACf,KAAK,MAAMiC,IAAI,IAAID,KAAK,EAAE;UACxBhB,UAAU,CAACI,OAAO,CAACa,IAAI,CAAC;QAC1B;MACF,CAAC,MAAM,IAAIlC,KAAK,EAAE;QAChBiB,UAAU,CAACjB,KAAK,CAACA,KAAK,CAAC;MACzB,CAAC,MAAM,IAAIG,QAAQ,EAAE;QACnBc,UAAU,CAACK,KAAK,EAAE;MACpB,CAAC,MAAM;QACL,OAAO,IAAIC,OAAO,CAAOC,OAAO,IAAG;UACjCtB,WAAW,GAAGA,CAAA,KAAK;YACjBA,WAAW,GAAGQ,SAAS;YACvBc,OAAO,EAAE;UACX,CAAC;QACH,CAAC,CAAC,CAACC,IAAI,CAAC,MAAM,IAAI,CAACT,IAAK,CAACC,UAAU,CAAC,CAAC;MACvC;IACF;GACD,CAAC;EAEF,OAAO;IACLY,QAAQ;IACRf;GACD;AACH,CAAC","ignoreList":[]}
 
1
+ {"version":3,"file":"web.js","names":["MP","decodeField","make","config","headers","Object","fromEntries","error","partBuffer","readResolve","chunkResolve","finished","parser","onField","info","value","push","_tag","undefined","onFile","chunkBuffer","readable","ReadableStream","pull","controller","length","chunks","chunk","enqueue","close","Promise","resolve","then","onError","error_","onDone","writable","WritableStream","write","_controller","end","parts","part"],"sources":["../../src/web.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAO,KAAKA,EAAE,MAAM,YAAY;AAGhC,SAASC,WAAW,QAAQ,YAAY;AAyBxC,OAAO,MAAMC,IAAI,GAAIC,MAAiB,IAAsB;EAC1D,MAAMC,OAAO,GAAGC,MAAM,CAACC,WAAW,CAAC,CAAC,GAAGH,MAAM,CAACC,OAAO,CAAC,CAAC;EACvD,IAAIG,KAAoC;EACxC,IAAIC,UAAU,GAAgB,EAAE;EAChC,IAAIC,WAAqC;EACzC,IAAIC,YAAsC;EAC1C,IAAIC,QAAQ,GAAG,KAAK;EAEpB,MAAMC,MAAM,GAAGZ,EAAE,CAACE,IAAI,CAAC;IACrB,GAAGC,MAAM;IACTC,OAAO;IACPS,OAAOA,CAACC,IAAI,EAAEC,KAAK;MACjBP,UAAU,CAACQ,IAAI,CAAC;QAAEC,IAAI,EAAE,OAAO;QAAEH,IAAI;QAAEC;MAAK,CAAE,CAAC;MAC/C,IAAIN,WAAW,KAAKS,SAAS,EAAET,WAAW,EAAE;IAC9C,CAAC;IACDU,MAAMA,CAACL,IAAI;MACT,IAAIM,WAAW,GAAsB,EAAE;MACvC,IAAIT,QAAQ,GAAG,KAAK;MAEpB,MAAMU,QAAQ,GAAG,IAAIC,cAAc,CAAa;QAC9CC,IAAIA,CAACC,UAAU;UACb,IAAIJ,WAAW,CAACK,MAAM,GAAG,CAAC,EAAE;YAC1B,MAAMC,MAAM,GAAGN,WAAW;YAC1BA,WAAW,GAAG,EAAE;YAChB,KAAK,MAAMO,KAAK,IAAID,MAAM,EAAE;cAC1BF,UAAU,CAACI,OAAO,CAACD,KAAK,CAAC;YAC3B;UACF,CAAC,MAAM,IAAIpB,KAAK,EAAE;YAChBiB,UAAU,CAACjB,KAAK,CAACA,KAAK,CAAC;UACzB,CAAC,MAAM,IAAII,QAAQ,EAAE;YACnBa,UAAU,CAACK,KAAK,EAAE;UACpB,CAAC,MAAM;YACL,OAAO,IAAIC,OAAO,CAAOC,OAAO,IAAG;cACjCrB,YAAY,GAAGA,CAAA,KAAK;gBAClBA,YAAY,GAAGQ,SAAS;gBACxBa,OAAO,EAAE;cACX,CAAC;YACH,CAAC,CAAC,CAACC,IAAI,CAAC,MAAM,IAAI,CAACT,IAAK,CAACC,UAAU,CAAC,CAAC;UACvC;QACF;OACD,CAAC;MAEFhB,UAAU,CAACQ,IAAI,CAAC;QAAEC,IAAI,EAAE,MAAM;QAAEH,IAAI;QAAEO;MAAQ,CAAE,CAAC;MACjD,IAAIZ,WAAW,KAAKS,SAAS,EAAET,WAAW,EAAE;MAE5C,OAAO,UAAUkB,KAAK;QACpB,IAAIA,KAAK,KAAK,IAAI,EAAE;UAClBhB,QAAQ,GAAG,IAAI;QACjB,CAAC,MAAM;UACLS,WAAW,CAACJ,IAAI,CAACW,KAAK,CAAC;QACzB;QACA,IAAIjB,YAAY,KAAKQ,SAAS,EAAE;UAC9BR,YAAY,EAAE;QAChB;MACF,CAAC;IACH,CAAC;IACDuB,OAAOA,CAACC,MAAM;MACZ,IAAI3B,KAAK,KAAKW,SAAS,EAAE;MACzBX,KAAK,GAAG2B,MAAM;MACd,IAAIxB,YAAY,KAAKQ,SAAS,EAAER,YAAY,EAAE;MAC9C,IAAID,WAAW,KAAKS,SAAS,EAAET,WAAW,EAAE;IAC9C,CAAC;IAED0B,MAAMA,CAAA;MACJxB,QAAQ,GAAG,IAAI;MACf,IAAIF,WAAW,KAAKS,SAAS,EAAET,WAAW,EAAE;IAC9C;GACD,CAAC;EAEF,MAAM2B,QAAQ,GAAG,IAAIC,cAAc,CAAa;IAC9CC,KAAKA,CAACX,KAAK,EAAEY,WAAW;MACtB3B,MAAM,CAAC0B,KAAK,CAACX,KAAK,CAAC;IACrB,CAAC;IACDE,KAAKA,CAAA;MACHjB,MAAM,CAAC4B,GAAG,EAAE;IACd;GACD,CAAC;EAEF,MAAMnB,QAAQ,GAAG,IAAIC,cAAc,CAAO;IACxCC,IAAIA,CAACC,UAAU;MACb,IAAIhB,UAAU,CAACiB,MAAM,GAAG,CAAC,EAAE;QACzB,MAAMgB,KAAK,GAAGjC,UAAU;QACxBA,UAAU,GAAG,EAAE;QACf,KAAK,MAAMkC,IAAI,IAAID,KAAK,EAAE;UACxBjB,UAAU,CAACI,OAAO,CAACc,IAAI,CAAC;QAC1B;MACF,CAAC,MAAM,IAAInC,KAAK,EAAE;QAChBiB,UAAU,CAACjB,KAAK,CAACA,KAAK,CAAC;MACzB,CAAC,MAAM,IAAII,QAAQ,EAAE;QACnBa,UAAU,CAACK,KAAK,EAAE;MACpB,CAAC,MAAM;QACL,OAAO,IAAIC,OAAO,CAAOC,OAAO,IAAG;UACjCtB,WAAW,GAAGA,CAAA,KAAK;YACjBA,WAAW,GAAGS,SAAS;YACvBa,OAAO,EAAE;UACX,CAAC;QACH,CAAC,CAAC,CAACC,IAAI,CAAC,MAAM,IAAI,CAACT,IAAK,CAACC,UAAU,CAAC,CAAC;MACvC;IACF;GACD,CAAC;EAEF,OAAO;IACLY,QAAQ;IACRf;GACD;AACH,CAAC","ignoreList":[]}
.opencode/node_modules/multipasta/package.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "multipasta",
3
- "version": "0.2.7",
4
  "description": "",
5
  "license": "MIT",
6
  "repository": {
 
1
  {
2
  "name": "multipasta",
3
+ "version": "0.2.8",
4
  "description": "",
5
  "license": "MIT",
6
  "repository": {
.opencode/node_modules/multipasta/src/web.ts CHANGED
@@ -31,6 +31,7 @@ export const make = (config: WebConfig): MultipastaStream => {
31
  let error: MP.MultipartError | undefined
32
  let partBuffer: Array<Part> = []
33
  let readResolve: (() => void) | undefined
 
34
  let finished = false
35
 
36
  const parser = MP.make({
@@ -42,7 +43,6 @@ export const make = (config: WebConfig): MultipastaStream => {
42
  },
43
  onFile(info) {
44
  let chunkBuffer: Array<Uint8Array> = []
45
- let chunkResolve: (() => void) | undefined
46
  let finished = false
47
 
48
  const readable = new ReadableStream<Uint8Array>({
@@ -53,6 +53,8 @@ export const make = (config: WebConfig): MultipastaStream => {
53
  for (const chunk of chunks) {
54
  controller.enqueue(chunk)
55
  }
 
 
56
  } else if (finished) {
57
  controller.close()
58
  } else {
@@ -83,6 +85,7 @@ export const make = (config: WebConfig): MultipastaStream => {
83
  onError(error_) {
84
  if (error !== undefined) return
85
  error = error_
 
86
  if (readResolve !== undefined) readResolve()
87
  },
88
 
@@ -93,7 +96,7 @@ export const make = (config: WebConfig): MultipastaStream => {
93
  })
94
 
95
  const writable = new WritableStream<Uint8Array>({
96
- write(chunk, controller) {
97
  parser.write(chunk)
98
  },
99
  close() {
 
31
  let error: MP.MultipartError | undefined
32
  let partBuffer: Array<Part> = []
33
  let readResolve: (() => void) | undefined
34
+ let chunkResolve: (() => void) | undefined
35
  let finished = false
36
 
37
  const parser = MP.make({
 
43
  },
44
  onFile(info) {
45
  let chunkBuffer: Array<Uint8Array> = []
 
46
  let finished = false
47
 
48
  const readable = new ReadableStream<Uint8Array>({
 
53
  for (const chunk of chunks) {
54
  controller.enqueue(chunk)
55
  }
56
+ } else if (error) {
57
+ controller.error(error)
58
  } else if (finished) {
59
  controller.close()
60
  } else {
 
85
  onError(error_) {
86
  if (error !== undefined) return
87
  error = error_
88
+ if (chunkResolve !== undefined) chunkResolve()
89
  if (readResolve !== undefined) readResolve()
90
  },
91
 
 
96
  })
97
 
98
  const writable = new WritableStream<Uint8Array>({
99
+ write(chunk, _controller) {
100
  parser.write(chunk)
101
  },
102
  close() {
.opencode/node_modules/pure-rand/lib/RandomGenerator-DcXj09Ch.d.ts ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //#region src/types/RandomGenerator.d.ts
2
+ interface RandomGenerator {
3
+ /** Produce a fully independent clone of the current instance */
4
+ clone(): RandomGenerator;
5
+ /**
6
+ * Generate next value BUT alters current generator.
7
+ * Values uniform in range -0x8000_0000 (included) to 0x7fff_ffff (included)
8
+ */
9
+ next(): number;
10
+ /** Access to the internal state of a RandomGenerator in a read-only fashion */
11
+ getState(): readonly number[];
12
+ }
13
+ //#endregion
14
+ export { RandomGenerator as t };
.opencode/node_modules/pure-rand/lib/distribution/uniformBigInt.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as RandomGenerator } from "../RandomGenerator-CKZRB3Fu.js";
2
 
3
  //#region src/distribution/uniformBigInt.d.ts
4
  /**
 
1
+ import { t as RandomGenerator } from "../RandomGenerator-DcXj09Ch.js";
2
 
3
  //#region src/distribution/uniformBigInt.d.ts
4
  /**
.opencode/node_modules/pure-rand/lib/distribution/uniformFloat32.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as RandomGenerator } from "../RandomGenerator-CKZRB3Fu.js";
2
 
3
  //#region src/distribution/uniformFloat32.d.ts
4
  /**
 
1
+ import { t as RandomGenerator } from "../RandomGenerator-DcXj09Ch.js";
2
 
3
  //#region src/distribution/uniformFloat32.d.ts
4
  /**
.opencode/node_modules/pure-rand/lib/distribution/uniformFloat64.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as RandomGenerator } from "../RandomGenerator-CKZRB3Fu.js";
2
 
3
  //#region src/distribution/uniformFloat64.d.ts
4
  /**
 
1
+ import { t as RandomGenerator } from "../RandomGenerator-DcXj09Ch.js";
2
 
3
  //#region src/distribution/uniformFloat64.d.ts
4
  /**
.opencode/node_modules/pure-rand/lib/distribution/uniformFloat64.js CHANGED
@@ -1,7 +1,7 @@
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
  //#region src/distribution/uniformFloat64.ts
3
- const factor = 134217728;
4
- const scale = 11102230246251565e-32;
5
  const mask1 = 67108863;
6
  const mask2 = 134217727;
7
  /**
@@ -16,7 +16,7 @@ const mask2 = 134217727;
16
  function uniformFloat64(rng) {
17
  const value1 = rng.next() & mask1;
18
  const value2 = rng.next() & mask2;
19
- return (value1 * factor + value2) * scale;
20
  }
21
  //#endregion
22
  exports.uniformFloat64 = uniformFloat64;
 
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
  //#region src/distribution/uniformFloat64.ts
3
+ const scale26 = 1.4901161193847656e-8;
4
+ const scale53 = 11102230246251565e-32;
5
  const mask1 = 67108863;
6
  const mask2 = 134217727;
7
  /**
 
16
  function uniformFloat64(rng) {
17
  const value1 = rng.next() & mask1;
18
  const value2 = rng.next() & mask2;
19
+ return value1 * scale26 + value2 * scale53;
20
  }
21
  //#endregion
22
  exports.uniformFloat64 = uniformFloat64;
.opencode/node_modules/pure-rand/lib/distribution/uniformInt.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as RandomGenerator } from "../RandomGenerator-CKZRB3Fu.js";
2
 
3
  //#region src/distribution/uniformInt.d.ts
4
  /**
 
1
+ import { t as RandomGenerator } from "../RandomGenerator-DcXj09Ch.js";
2
 
3
  //#region src/distribution/uniformInt.d.ts
4
  /**
.opencode/node_modules/pure-rand/lib/esm/RandomGenerator-DcXj09Ch.d.ts ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //#region src/types/RandomGenerator.d.ts
2
+ interface RandomGenerator {
3
+ /** Produce a fully independent clone of the current instance */
4
+ clone(): RandomGenerator;
5
+ /**
6
+ * Generate next value BUT alters current generator.
7
+ * Values uniform in range -0x8000_0000 (included) to 0x7fff_ffff (included)
8
+ */
9
+ next(): number;
10
+ /** Access to the internal state of a RandomGenerator in a read-only fashion */
11
+ getState(): readonly number[];
12
+ }
13
+ //#endregion
14
+ export { RandomGenerator as t };
.opencode/node_modules/pure-rand/lib/esm/distribution/uniformBigInt.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as RandomGenerator } from "../RandomGenerator-CKZRB3Fu.js";
2
 
3
  //#region src/distribution/uniformBigInt.d.ts
4
  /**
 
1
+ import { t as RandomGenerator } from "../RandomGenerator-DcXj09Ch.js";
2
 
3
  //#region src/distribution/uniformBigInt.d.ts
4
  /**
.opencode/node_modules/pure-rand/lib/esm/distribution/uniformFloat32.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as RandomGenerator } from "../RandomGenerator-CKZRB3Fu.js";
2
 
3
  //#region src/distribution/uniformFloat32.d.ts
4
  /**
 
1
+ import { t as RandomGenerator } from "../RandomGenerator-DcXj09Ch.js";
2
 
3
  //#region src/distribution/uniformFloat32.d.ts
4
  /**
.opencode/node_modules/pure-rand/lib/esm/distribution/uniformFloat64.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as RandomGenerator } from "../RandomGenerator-CKZRB3Fu.js";
2
 
3
  //#region src/distribution/uniformFloat64.d.ts
4
  /**
 
1
+ import { t as RandomGenerator } from "../RandomGenerator-DcXj09Ch.js";
2
 
3
  //#region src/distribution/uniformFloat64.d.ts
4
  /**
.opencode/node_modules/pure-rand/lib/esm/distribution/uniformFloat64.js CHANGED
@@ -1,6 +1,6 @@
1
  //#region src/distribution/uniformFloat64.ts
2
- const factor = 134217728;
3
- const scale = 11102230246251565e-32;
4
  const mask1 = 67108863;
5
  const mask2 = 134217727;
6
  /**
@@ -15,7 +15,7 @@ const mask2 = 134217727;
15
  function uniformFloat64(rng) {
16
  const value1 = rng.next() & mask1;
17
  const value2 = rng.next() & mask2;
18
- return (value1 * factor + value2) * scale;
19
  }
20
  //#endregion
21
  export { uniformFloat64 };
 
1
  //#region src/distribution/uniformFloat64.ts
2
+ const scale26 = 1.4901161193847656e-8;
3
+ const scale53 = 11102230246251565e-32;
4
  const mask1 = 67108863;
5
  const mask2 = 134217727;
6
  /**
 
15
  function uniformFloat64(rng) {
16
  const value1 = rng.next() & mask1;
17
  const value2 = rng.next() & mask2;
18
+ return value1 * scale26 + value2 * scale53;
19
  }
20
  //#endregion
21
  export { uniformFloat64 };
.opencode/node_modules/pure-rand/lib/esm/distribution/uniformInt.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as RandomGenerator } from "../RandomGenerator-CKZRB3Fu.js";
2
 
3
  //#region src/distribution/uniformInt.d.ts
4
  /**
 
1
+ import { t as RandomGenerator } from "../RandomGenerator-DcXj09Ch.js";
2
 
3
  //#region src/distribution/uniformInt.d.ts
4
  /**
.opencode/node_modules/pure-rand/lib/esm/generator/congruential32.js CHANGED
@@ -3,6 +3,10 @@ const MULTIPLIER = 214013;
3
  const INCREMENT = 2531011;
4
  const MASK = 4294967295;
5
  const MASK_2 = -2147483649;
 
 
 
 
6
  const JUMP_MULTIPLIER = 1994129409;
7
  const JUMP_INCREMENT = 916127744;
8
  var LinearCongruential32 = class LinearCongruential32 {
@@ -13,12 +17,14 @@ var LinearCongruential32 = class LinearCongruential32 {
13
  return new LinearCongruential32(this.seed);
14
  }
15
  next() {
16
- const s1 = computeNextSeed(this.seed);
17
- const v1 = computeValueFromNextSeed(s1);
18
- const s2 = computeNextSeed(s1);
19
- const v2 = computeValueFromNextSeed(s2);
20
- this.seed = computeNextSeed(s2);
21
- return computeValueFromNextSeed(this.seed) + (v2 + (v1 << 15) << 15) | 0;
 
 
22
  }
23
  jump() {
24
  this.seed = Math.imul(this.seed, JUMP_MULTIPLIER) + JUMP_INCREMENT & MASK;
@@ -27,12 +33,6 @@ var LinearCongruential32 = class LinearCongruential32 {
27
  return [this.seed];
28
  }
29
  };
30
- function computeNextSeed(seed) {
31
- return Math.imul(seed, MULTIPLIER) + INCREMENT & MASK;
32
- }
33
- function computeValueFromNextSeed(nextseed) {
34
- return (nextseed & MASK_2) >> 16;
35
- }
36
  function congruential32FromState(state) {
37
  if (!(state.length === 1)) throw new Error("The state must have been produced by a congruential32 RandomGenerator");
38
  return new LinearCongruential32(state[0]);
 
3
  const INCREMENT = 2531011;
4
  const MASK = 4294967295;
5
  const MASK_2 = -2147483649;
6
+ const MULTIPLIER_2 = -1443076087;
7
+ const INCREMENT_2 = 505908858;
8
+ const MULTIPLIER_3 = 1170746341;
9
+ const INCREMENT_3 = -755606699;
10
  const JUMP_MULTIPLIER = 1994129409;
11
  const JUMP_INCREMENT = 916127744;
12
  var LinearCongruential32 = class LinearCongruential32 {
 
17
  return new LinearCongruential32(this.seed);
18
  }
19
  next() {
20
+ const s0 = this.seed;
21
+ const s1 = Math.imul(s0, MULTIPLIER) + INCREMENT | 0;
22
+ const s2 = Math.imul(s0, MULTIPLIER_2) + INCREMENT_2 | 0;
23
+ const s3 = Math.imul(s0, MULTIPLIER_3) + INCREMENT_3 | 0;
24
+ this.seed = s3;
25
+ const v1 = (s1 & MASK_2) >> 16;
26
+ const v2 = (s2 & MASK_2) >> 16;
27
+ return (s3 & MASK_2) >> 16 | v2 << 15 | v1 << 30;
28
  }
29
  jump() {
30
  this.seed = Math.imul(this.seed, JUMP_MULTIPLIER) + JUMP_INCREMENT & MASK;
 
33
  return [this.seed];
34
  }
35
  };
 
 
 
 
 
 
36
  function congruential32FromState(state) {
37
  if (!(state.length === 1)) throw new Error("The state must have been produced by a congruential32 RandomGenerator");
38
  return new LinearCongruential32(state[0]);
.opencode/node_modules/pure-rand/lib/esm/generator/mersenne.js CHANGED
@@ -74,7 +74,7 @@ function twist(mt) {
74
  for (let idx = 0; idx !== N; ++idx) twistedNext(mt, idx);
75
  }
76
  function mersenneFromState(state) {
77
- if (!(state.length === N + 1 && state[0] >= 0 && state[0] < N)) throw new Error("The state must have been produced by a mersenne RandomGenerator");
78
  return new MersenneTwister(state.slice(1), state[0]);
79
  }
80
  function mersenne(seed) {
 
74
  for (let idx = 0; idx !== N; ++idx) twistedNext(mt, idx);
75
  }
76
  function mersenneFromState(state) {
77
+ if (!(state.length === 625 && state[0] >= 0 && state[0] < N)) throw new Error("The state must have been produced by a mersenne RandomGenerator");
78
  return new MersenneTwister(state.slice(1), state[0]);
79
  }
80
  function mersenne(seed) {
.opencode/node_modules/pure-rand/lib/esm/generator/xoroshiro128plus.js CHANGED
@@ -1,4 +1,10 @@
1
  //#region src/generator/xoroshiro128plus.ts
 
 
 
 
 
 
2
  var XoroShiro128Plus = class XoroShiro128Plus {
3
  constructor(s01, s00, s11, s10) {
4
  this.s01 = s01;
@@ -26,20 +32,28 @@ var XoroShiro128Plus = class XoroShiro128Plus {
26
  let ns00 = 0;
27
  let ns11 = 0;
28
  let ns10 = 0;
29
- const jump = [
30
- 3639956645,
31
- 3750757012,
32
- 1261568508,
33
- 386426335
34
- ];
35
- for (let i = 0; i !== 4; ++i) for (let mask = 1; mask; mask <<= 1) {
36
- if (jump[i] & mask) {
37
- ns01 ^= this.s01;
38
- ns00 ^= this.s00;
39
- ns11 ^= this.s11;
40
- ns10 ^= this.s10;
 
 
 
 
 
 
 
 
 
41
  }
42
- this.next();
43
  }
44
  this.s01 = ns01;
45
  this.s00 = ns00;
 
1
  //#region src/generator/xoroshiro128plus.ts
2
+ const jumps = [
3
+ 3639956645,
4
+ 3750757012,
5
+ 1261568508,
6
+ 386426335
7
+ ];
8
  var XoroShiro128Plus = class XoroShiro128Plus {
9
  constructor(s01, s00, s11, s10) {
10
  this.s01 = s01;
 
32
  let ns00 = 0;
33
  let ns11 = 0;
34
  let ns10 = 0;
35
+ let s01 = this.s01;
36
+ let s00 = this.s00;
37
+ let s11 = this.s11;
38
+ let s10 = this.s10;
39
+ for (let i = 0; i !== 4; ++i) {
40
+ const ji = jumps[i];
41
+ for (let mask = 1; mask; mask <<= 1) {
42
+ if (ji & mask) {
43
+ ns01 ^= s01;
44
+ ns00 ^= s00;
45
+ ns11 ^= s11;
46
+ ns10 ^= s10;
47
+ }
48
+ const a0 = s10 ^ s00;
49
+ const a1 = s11 ^ s01;
50
+ const s00_ = s00;
51
+ const s01_ = s01;
52
+ s00 = s00_ << 24 ^ s01_ >>> 8 ^ a0 ^ a0 << 16;
53
+ s01 = s01_ << 24 ^ s00_ >>> 8 ^ a1 ^ (a1 << 16 | a0 >>> 16);
54
+ s10 = a1 << 5 ^ a0 >>> 27;
55
+ s11 = a0 << 5 ^ a1 >>> 27;
56
  }
 
57
  }
58
  this.s01 = ns01;
59
  this.s00 = ns00;
.opencode/node_modules/pure-rand/lib/esm/generator/xorshift128plus.js CHANGED
@@ -1,4 +1,10 @@
1
  //#region src/generator/xorshift128plus.ts
 
 
 
 
 
 
2
  var XorShift128Plus = class XorShift128Plus {
3
  constructor(s01, s00, s11, s10) {
4
  this.s01 = s01;
@@ -12,13 +18,13 @@ var XorShift128Plus = class XorShift128Plus {
12
  next() {
13
  const a0 = this.s00 ^ this.s00 << 23;
14
  const a1 = this.s01 ^ (this.s01 << 23 | this.s00 >>> 9);
15
- const b0 = a0 ^ this.s10 ^ (a0 >>> 18 | a1 << 14) ^ (this.s10 >>> 5 | this.s11 << 27);
16
- const b1 = a1 ^ this.s11 ^ a1 >>> 18 ^ this.s11 >>> 5;
17
- const out = this.s00 + this.s10 | 0;
18
- this.s01 = this.s11;
19
- this.s00 = this.s10;
20
- this.s11 = b1;
21
- this.s10 = b0;
22
  return out;
23
  }
24
  jump() {
@@ -26,20 +32,26 @@ var XorShift128Plus = class XorShift128Plus {
26
  let ns00 = 0;
27
  let ns11 = 0;
28
  let ns10 = 0;
29
- const jump = [
30
- 1667051007,
31
- 2321340297,
32
- 1548169110,
33
- 304075285
34
- ];
35
- for (let i = 0; i !== 4; ++i) for (let mask = 1; mask; mask <<= 1) {
36
- if (jump[i] & mask) {
37
- ns01 ^= this.s01;
38
- ns00 ^= this.s00;
39
- ns11 ^= this.s11;
40
- ns10 ^= this.s10;
 
 
 
 
 
 
 
41
  }
42
- this.next();
43
  }
44
  this.s01 = ns01;
45
  this.s00 = ns00;
 
1
  //#region src/generator/xorshift128plus.ts
2
+ const jumps = [
3
+ 1667051007,
4
+ 2321340297,
5
+ 1548169110,
6
+ 304075285
7
+ ];
8
  var XorShift128Plus = class XorShift128Plus {
9
  constructor(s01, s00, s11, s10) {
10
  this.s01 = s01;
 
18
  next() {
19
  const a0 = this.s00 ^ this.s00 << 23;
20
  const a1 = this.s01 ^ (this.s01 << 23 | this.s00 >>> 9);
21
+ const s10 = this.s10;
22
+ const s11 = this.s11;
23
+ const out = this.s00 + s10 | 0;
24
+ this.s01 = s11;
25
+ this.s00 = s10;
26
+ this.s11 = a1 ^ s11 ^ a1 >>> 18 ^ s11 >>> 5;
27
+ this.s10 = a0 ^ s10 ^ (a0 >>> 18 | a1 << 14) ^ (s10 >>> 5 | s11 << 27);
28
  return out;
29
  }
30
  jump() {
 
32
  let ns00 = 0;
33
  let ns11 = 0;
34
  let ns10 = 0;
35
+ let s01 = this.s01;
36
+ let s00 = this.s00;
37
+ let s11 = this.s11;
38
+ let s10 = this.s10;
39
+ for (let i = 0; i !== 4; ++i) {
40
+ const ji = jumps[i];
41
+ for (let mask = 1; mask; mask <<= 1) {
42
+ if (ji & mask) {
43
+ ns01 ^= s01;
44
+ ns00 ^= s00;
45
+ ns11 ^= s11;
46
+ ns10 ^= s10;
47
+ }
48
+ const a0 = s00 ^ s00 << 23;
49
+ const a1 = s01 ^ (s01 << 23 | s00 >>> 9);
50
+ s01 = s11;
51
+ s00 = s10;
52
+ s10 = a0 ^ s10 ^ (a0 >>> 18 | a1 << 14) ^ (s10 >>> 5 | s11 << 27);
53
+ s11 = a1 ^ s11 ^ a1 >>> 18 ^ s11 >>> 5;
54
  }
 
55
  }
56
  this.s01 = ns01;
57
  this.s00 = ns00;
.opencode/node_modules/pure-rand/lib/esm/types/JumpableRandomGenerator.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as RandomGenerator } from "../RandomGenerator-CKZRB3Fu.js";
2
 
3
  //#region src/types/JumpableRandomGenerator.d.ts
4
  interface JumpableRandomGenerator extends RandomGenerator {
 
1
+ import { t as RandomGenerator } from "../RandomGenerator-DcXj09Ch.js";
2
 
3
  //#region src/types/JumpableRandomGenerator.d.ts
4
  interface JumpableRandomGenerator extends RandomGenerator {
.opencode/node_modules/pure-rand/lib/esm/types/RandomGenerator.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { t as RandomGenerator } from "../RandomGenerator-CKZRB3Fu.js";
2
  export { RandomGenerator };
 
1
+ import { t as RandomGenerator } from "../RandomGenerator-DcXj09Ch.js";
2
  export { RandomGenerator };
.opencode/node_modules/pure-rand/lib/esm/utils/generateN.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { t as RandomGenerator } from "../RandomGenerator-CKZRB3Fu.js";
2
 
3
  //#region src/utils/generateN.d.ts
4
  declare function generateN(rng: RandomGenerator, num: number): number[];
 
1
+ import { t as RandomGenerator } from "../RandomGenerator-DcXj09Ch.js";
2
 
3
  //#region src/utils/generateN.d.ts
4
  declare function generateN(rng: RandomGenerator, num: number): number[];