minotor 11.5.1 → 12.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -497,177 +497,177 @@ class ZoneIsAbstractError extends LuxonError {
497
497
  * @private
498
498
  */
499
499
 
500
- const n = "numeric",
501
- s = "short",
502
- l = "long";
500
+ const n$1 = "numeric",
501
+ s$2 = "short",
502
+ l$1 = "long";
503
503
 
504
504
  const DATE_SHORT = {
505
- year: n,
506
- month: n,
507
- day: n,
505
+ year: n$1,
506
+ month: n$1,
507
+ day: n$1,
508
508
  };
509
509
 
510
510
  const DATE_MED = {
511
- year: n,
512
- month: s,
513
- day: n,
511
+ year: n$1,
512
+ month: s$2,
513
+ day: n$1,
514
514
  };
515
515
 
516
516
  const DATE_MED_WITH_WEEKDAY = {
517
- year: n,
518
- month: s,
519
- day: n,
520
- weekday: s,
517
+ year: n$1,
518
+ month: s$2,
519
+ day: n$1,
520
+ weekday: s$2,
521
521
  };
522
522
 
523
523
  const DATE_FULL = {
524
- year: n,
525
- month: l,
526
- day: n,
524
+ year: n$1,
525
+ month: l$1,
526
+ day: n$1,
527
527
  };
528
528
 
529
529
  const DATE_HUGE = {
530
- year: n,
531
- month: l,
532
- day: n,
533
- weekday: l,
530
+ year: n$1,
531
+ month: l$1,
532
+ day: n$1,
533
+ weekday: l$1,
534
534
  };
535
535
 
536
536
  const TIME_SIMPLE = {
537
- hour: n,
538
- minute: n,
537
+ hour: n$1,
538
+ minute: n$1,
539
539
  };
540
540
 
541
541
  const TIME_WITH_SECONDS = {
542
- hour: n,
543
- minute: n,
544
- second: n,
542
+ hour: n$1,
543
+ minute: n$1,
544
+ second: n$1,
545
545
  };
546
546
 
547
547
  const TIME_WITH_SHORT_OFFSET = {
548
- hour: n,
549
- minute: n,
550
- second: n,
551
- timeZoneName: s,
548
+ hour: n$1,
549
+ minute: n$1,
550
+ second: n$1,
551
+ timeZoneName: s$2,
552
552
  };
553
553
 
554
554
  const TIME_WITH_LONG_OFFSET = {
555
- hour: n,
556
- minute: n,
557
- second: n,
558
- timeZoneName: l,
555
+ hour: n$1,
556
+ minute: n$1,
557
+ second: n$1,
558
+ timeZoneName: l$1,
559
559
  };
560
560
 
561
561
  const TIME_24_SIMPLE = {
562
- hour: n,
563
- minute: n,
562
+ hour: n$1,
563
+ minute: n$1,
564
564
  hourCycle: "h23",
565
565
  };
566
566
 
567
567
  const TIME_24_WITH_SECONDS = {
568
- hour: n,
569
- minute: n,
570
- second: n,
568
+ hour: n$1,
569
+ minute: n$1,
570
+ second: n$1,
571
571
  hourCycle: "h23",
572
572
  };
573
573
 
574
574
  const TIME_24_WITH_SHORT_OFFSET = {
575
- hour: n,
576
- minute: n,
577
- second: n,
575
+ hour: n$1,
576
+ minute: n$1,
577
+ second: n$1,
578
578
  hourCycle: "h23",
579
- timeZoneName: s,
579
+ timeZoneName: s$2,
580
580
  };
581
581
 
582
582
  const TIME_24_WITH_LONG_OFFSET = {
583
- hour: n,
584
- minute: n,
585
- second: n,
583
+ hour: n$1,
584
+ minute: n$1,
585
+ second: n$1,
586
586
  hourCycle: "h23",
587
- timeZoneName: l,
587
+ timeZoneName: l$1,
588
588
  };
589
589
 
590
590
  const DATETIME_SHORT = {
591
- year: n,
592
- month: n,
593
- day: n,
594
- hour: n,
595
- minute: n,
591
+ year: n$1,
592
+ month: n$1,
593
+ day: n$1,
594
+ hour: n$1,
595
+ minute: n$1,
596
596
  };
597
597
 
598
598
  const DATETIME_SHORT_WITH_SECONDS = {
599
- year: n,
600
- month: n,
601
- day: n,
602
- hour: n,
603
- minute: n,
604
- second: n,
599
+ year: n$1,
600
+ month: n$1,
601
+ day: n$1,
602
+ hour: n$1,
603
+ minute: n$1,
604
+ second: n$1,
605
605
  };
606
606
 
607
607
  const DATETIME_MED = {
608
- year: n,
609
- month: s,
610
- day: n,
611
- hour: n,
612
- minute: n,
608
+ year: n$1,
609
+ month: s$2,
610
+ day: n$1,
611
+ hour: n$1,
612
+ minute: n$1,
613
613
  };
614
614
 
615
615
  const DATETIME_MED_WITH_SECONDS = {
616
- year: n,
617
- month: s,
618
- day: n,
619
- hour: n,
620
- minute: n,
621
- second: n,
616
+ year: n$1,
617
+ month: s$2,
618
+ day: n$1,
619
+ hour: n$1,
620
+ minute: n$1,
621
+ second: n$1,
622
622
  };
623
623
 
624
624
  const DATETIME_MED_WITH_WEEKDAY = {
625
- year: n,
626
- month: s,
627
- day: n,
628
- weekday: s,
629
- hour: n,
630
- minute: n,
625
+ year: n$1,
626
+ month: s$2,
627
+ day: n$1,
628
+ weekday: s$2,
629
+ hour: n$1,
630
+ minute: n$1,
631
631
  };
632
632
 
633
633
  const DATETIME_FULL = {
634
- year: n,
635
- month: l,
636
- day: n,
637
- hour: n,
638
- minute: n,
639
- timeZoneName: s,
634
+ year: n$1,
635
+ month: l$1,
636
+ day: n$1,
637
+ hour: n$1,
638
+ minute: n$1,
639
+ timeZoneName: s$2,
640
640
  };
641
641
 
642
642
  const DATETIME_FULL_WITH_SECONDS = {
643
- year: n,
644
- month: l,
645
- day: n,
646
- hour: n,
647
- minute: n,
648
- second: n,
649
- timeZoneName: s,
643
+ year: n$1,
644
+ month: l$1,
645
+ day: n$1,
646
+ hour: n$1,
647
+ minute: n$1,
648
+ second: n$1,
649
+ timeZoneName: s$2,
650
650
  };
651
651
 
652
652
  const DATETIME_HUGE = {
653
- year: n,
654
- month: l,
655
- day: n,
656
- weekday: l,
657
- hour: n,
658
- minute: n,
659
- timeZoneName: l,
653
+ year: n$1,
654
+ month: l$1,
655
+ day: n$1,
656
+ weekday: l$1,
657
+ hour: n$1,
658
+ minute: n$1,
659
+ timeZoneName: l$1,
660
660
  };
661
661
 
662
662
  const DATETIME_HUGE_WITH_SECONDS = {
663
- year: n,
664
- month: l,
665
- day: n,
666
- weekday: l,
667
- hour: n,
668
- minute: n,
669
- second: n,
670
- timeZoneName: l,
663
+ year: n$1,
664
+ month: l$1,
665
+ day: n$1,
666
+ weekday: l$1,
667
+ hour: n$1,
668
+ minute: n$1,
669
+ second: n$1,
670
+ timeZoneName: l$1,
671
671
  };
672
672
 
673
673
  /**
@@ -9428,13 +9428,17 @@ function requireNode_stream_zip () {
9428
9428
  this.crc = data.readUInt32LE(consts.LOCCRC) || this.crc;
9429
9429
  // compressed size
9430
9430
  const compressedSize = data.readUInt32LE(consts.LOCSIZ);
9431
- if (compressedSize && compressedSize !== consts.EF_ZIP64_OR_32) {
9432
- this.compressedSize = compressedSize;
9431
+ if (
9432
+ compressedSize &&
9433
+ compressedSize !== consts.EF_ZIP64_OR_32 &&
9434
+ compressedSize !== this.compressedSize
9435
+ ) {
9436
+ throw new Error('Invalid compressed size');
9433
9437
  }
9434
9438
  // uncompressed size
9435
9439
  const size = data.readUInt32LE(consts.LOCLEN);
9436
- if (size && size !== consts.EF_ZIP64_OR_32) {
9437
- this.size = size;
9440
+ if (size && size !== consts.EF_ZIP64_OR_32 && size !== this.size) {
9441
+ throw new Error('Invalid size');
9438
9442
  }
9439
9443
  // filename length
9440
9444
  this.fnameLen = data.readUInt16LE(consts.LOCNAM);
@@ -9813,77 +9817,52 @@ var StreamZip = /*@__PURE__*/getDefaultExportFromCjs(node_stream_zipExports);
9813
9817
  /**
9814
9818
  * Read a 64 bit varint as two JS numbers.
9815
9819
  *
9816
- * Returns tuple:
9817
- * [0]: low bits
9818
- * [1]: high bits
9820
+ * Stores the low and high words on the reader.
9819
9821
  *
9820
9822
  * Copyright 2008 Google Inc. All rights reserved.
9821
9823
  *
9822
9824
  * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/buffer_decoder.js#L175
9823
9825
  */
9824
9826
  function varint64read() {
9825
- let lowBits = 0;
9826
- let highBits = 0;
9827
+ const buf = this.buf;
9828
+ let pos = this.pos;
9829
+ let lo = 0;
9830
+ let hi = 0;
9827
9831
  for (let shift = 0; shift < 28; shift += 7) {
9828
- let b = this.buf[this.pos++];
9829
- lowBits |= (b & 0x7f) << shift;
9832
+ const b = buf[pos++];
9833
+ lo |= (b & 0x7f) << shift;
9830
9834
  if ((b & 0x80) == 0) {
9835
+ this.pos = pos;
9831
9836
  this.assertBounds();
9832
- return [lowBits, highBits];
9837
+ this.varint64Lo = lo;
9838
+ this.varint64Hi = hi;
9839
+ return;
9833
9840
  }
9834
9841
  }
9835
- let middleByte = this.buf[this.pos++];
9842
+ const middleByte = buf[pos++];
9836
9843
  // last four bits of the first 32 bit number
9837
- lowBits |= (middleByte & 0x0f) << 28;
9844
+ lo |= (middleByte & 0x0f) << 28;
9838
9845
  // 3 upper bits are part of the next 32 bit number
9839
- highBits = (middleByte & 0x70) >> 4;
9846
+ hi = (middleByte & 0x70) >> 4;
9840
9847
  if ((middleByte & 0x80) == 0) {
9848
+ this.pos = pos;
9841
9849
  this.assertBounds();
9842
- return [lowBits, highBits];
9850
+ this.varint64Lo = lo;
9851
+ this.varint64Hi = hi;
9852
+ return;
9843
9853
  }
9844
9854
  for (let shift = 3; shift <= 31; shift += 7) {
9845
- let b = this.buf[this.pos++];
9846
- highBits |= (b & 0x7f) << shift;
9855
+ const b = buf[pos++];
9856
+ hi |= (b & 0x7f) << shift;
9847
9857
  if ((b & 0x80) == 0) {
9858
+ this.pos = pos;
9848
9859
  this.assertBounds();
9849
- return [lowBits, highBits];
9850
- }
9851
- }
9852
- throw new Error("invalid varint");
9853
- }
9854
- /**
9855
- * Write a 64 bit varint, given as two JS numbers, to the given bytes array.
9856
- *
9857
- * Copyright 2008 Google Inc. All rights reserved.
9858
- *
9859
- * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/writer.js#L344
9860
- */
9861
- function varint64write(lo, hi, bytes) {
9862
- for (let i = 0; i < 28; i = i + 7) {
9863
- const shift = lo >>> i;
9864
- const hasNext = !(shift >>> 7 == 0 && hi == 0);
9865
- const byte = (hasNext ? shift | 0x80 : shift) & 0xff;
9866
- bytes.push(byte);
9867
- if (!hasNext) {
9868
- return;
9869
- }
9870
- }
9871
- const splitBits = ((lo >>> 28) & 0x0f) | ((hi & 0x07) << 4);
9872
- const hasMoreBits = !(hi >> 3 == 0);
9873
- bytes.push((hasMoreBits ? splitBits | 0x80 : splitBits) & 0xff);
9874
- if (!hasMoreBits) {
9875
- return;
9876
- }
9877
- for (let i = 3; i < 31; i = i + 7) {
9878
- const shift = hi >>> i;
9879
- const hasNext = !(shift >>> 7 == 0);
9880
- const byte = (hasNext ? shift | 0x80 : shift) & 0xff;
9881
- bytes.push(byte);
9882
- if (!hasNext) {
9860
+ this.varint64Lo = lo;
9861
+ this.varint64Hi = hi;
9883
9862
  return;
9884
9863
  }
9885
9864
  }
9886
- bytes.push((hi >>> 31) & 0x01);
9865
+ throw new Error("invalid varint");
9887
9866
  }
9888
9867
  // constants for binary math
9889
9868
  const TWO_PWR_32_DBL = 0x100000000;
@@ -10026,30 +10005,6 @@ const decimalFrom1e7WithLeadingZeros = (digit1e7) => {
10026
10005
  const partial = String(digit1e7);
10027
10006
  return "0000000".slice(partial.length) + partial;
10028
10007
  };
10029
- /**
10030
- * Write a 32 bit varint, signed or unsigned. Same as `varint64write(0, value, bytes)`
10031
- *
10032
- * Copyright 2008 Google Inc. All rights reserved.
10033
- *
10034
- * See https://github.com/protocolbuffers/protobuf/blob/1b18833f4f2a2f681f4e4a25cdf3b0a43115ec26/js/binary/encoder.js#L144
10035
- */
10036
- function varint32write(value, bytes) {
10037
- if (value >= 0) {
10038
- // write value as varint 32
10039
- while (value > 0x7f) {
10040
- bytes.push((value & 0x7f) | 0x80);
10041
- value = value >>> 7;
10042
- }
10043
- bytes.push(value);
10044
- }
10045
- else {
10046
- for (let i = 0; i < 9; i++) {
10047
- bytes.push((value & 127) | 128);
10048
- value = value >> 7;
10049
- }
10050
- bytes.push(1);
10051
- }
10052
- }
10053
10008
  /**
10054
10009
  * Read an unsigned 32 bit varint.
10055
10010
  *
@@ -10057,26 +10012,26 @@ function varint32write(value, bytes) {
10057
10012
  */
10058
10013
  function varint32read() {
10059
10014
  let b = this.buf[this.pos++];
10060
- let result = b & 0x7f;
10061
- if ((b & 0x80) == 0) {
10015
+ if ((b & 0x80) === 0) {
10062
10016
  this.assertBounds();
10063
- return result;
10017
+ return b;
10064
10018
  }
10019
+ let result = b & 0x7f;
10065
10020
  b = this.buf[this.pos++];
10066
10021
  result |= (b & 0x7f) << 7;
10067
- if ((b & 0x80) == 0) {
10022
+ if ((b & 0x80) === 0) {
10068
10023
  this.assertBounds();
10069
10024
  return result;
10070
10025
  }
10071
10026
  b = this.buf[this.pos++];
10072
10027
  result |= (b & 0x7f) << 14;
10073
- if ((b & 0x80) == 0) {
10028
+ if ((b & 0x80) === 0) {
10074
10029
  this.assertBounds();
10075
10030
  return result;
10076
10031
  }
10077
10032
  b = this.buf[this.pos++];
10078
10033
  result |= (b & 0x7f) << 21;
10079
- if ((b & 0x80) == 0) {
10034
+ if ((b & 0x80) === 0) {
10080
10035
  this.assertBounds();
10081
10036
  return result;
10082
10037
  }
@@ -10085,14 +10040,13 @@ function varint32read() {
10085
10040
  result |= (b & 0x0f) << 28;
10086
10041
  for (let readBytes = 5; (b & 0x80) !== 0 && readBytes < 10; readBytes++)
10087
10042
  b = this.buf[this.pos++];
10088
- if ((b & 0x80) != 0)
10043
+ if ((b & 0x80) !== 0)
10089
10044
  throw new Error("invalid varint");
10090
10045
  this.assertBounds();
10091
- // Result can have 32 bits, convert it to unsigned
10092
10046
  return result >>> 0;
10093
10047
  }
10094
10048
 
10095
- // Copyright 2021-2025 Buf Technologies, Inc.
10049
+ // Copyright 2021-2026 Buf Technologies, Inc.
10096
10050
  //
10097
10051
  // Licensed under the Apache License, Version 2.0 (the "License");
10098
10052
  // you may not use this file except in compliance with the License.
@@ -10118,6 +10072,7 @@ function makeInt64Support() {
10118
10072
  typeof dv.setBigInt64 === "function" &&
10119
10073
  typeof dv.setBigUint64 === "function" &&
10120
10074
  (!!globalThis.Deno ||
10075
+ !!globalThis.Bun ||
10121
10076
  typeof process != "object" ||
10122
10077
  typeof process.env != "object" ||
10123
10078
  process.env.BUF_BIGINT_DISABLE !== "1");
@@ -10219,7 +10174,7 @@ function assertUInt64String(value) {
10219
10174
  }
10220
10175
  }
10221
10176
 
10222
- // Copyright 2021-2025 Buf Technologies, Inc.
10177
+ // Copyright 2021-2026 Buf Technologies, Inc.
10223
10178
  //
10224
10179
  // Licensed under the Apache License, Version 2.0 (the "License");
10225
10180
  // you may not use this file except in compliance with the License.
@@ -10232,17 +10187,55 @@ function assertUInt64String(value) {
10232
10187
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10233
10188
  // See the License for the specific language governing permissions and
10234
10189
  // limitations under the License.
10235
- const symbol = Symbol.for("@bufbuild/protobuf/text-encoding");
10190
+ let te;
10191
+ /**
10192
+ * Protobuf-ES requires the Text Encoding API to convert UTF-8 from and to
10193
+ * binary. This WHATWG API is widely available, but it is not part of the
10194
+ * ECMAScript standard. This function used to be the way to supply an
10195
+ * implementation on runtimes that do not provide one.
10196
+ *
10197
+ * It only configures the copy of the library it is imported from. To provide
10198
+ * the encoding API for every copy of Protobuf-ES in an isolate, install
10199
+ * `TextEncoder` (with the methods `encode` and optionally `encodeInto`) and
10200
+ * `TextDecoder` (with the `fatal: true` constructor argument and the `decode`
10201
+ * method) on `globalThis`.
10202
+ *
10203
+ * Providing `encodeUtf8Into` is optional for backwards compatibility. If it
10204
+ * is omitted, we emulate it with a wrapper that calls `encodeUtf8`.
10205
+ *
10206
+ * Note that the Text Encoding API does not provide a way to validate UTF-8.
10207
+ * Our implementation uses String.prototype.isWellFormed, and falls back
10208
+ * to use encodeURIComponent().
10209
+ *
10210
+ * @deprecated Install `TextEncoder` and `TextDecoder` on `globalThis` instead.
10211
+ */
10212
+ function configureTextEncoding(textEncoding) {
10213
+ var _a;
10214
+ te = Object.assign(Object.assign({}, textEncoding), { encodeUtf8Into: (_a = textEncoding.encodeUtf8Into) !== null && _a !== void 0 ? _a : emulateEncodeInto(textEncoding.encodeUtf8.bind(textEncoding)) });
10215
+ }
10236
10216
  function getTextEncoding() {
10237
- if (globalThis[symbol] == undefined) {
10238
- const te = new globalThis.TextEncoder();
10239
- const td = new globalThis.TextDecoder();
10240
- globalThis[symbol] = {
10217
+ if (!te) {
10218
+ const globals = globalThis;
10219
+ if (!globals.TextEncoder || !globals.TextDecoder) {
10220
+ throw new Error("encoding API missing: install TextEncoder and TextDecoder on globalThis");
10221
+ }
10222
+ const textEncoder = new globals.TextEncoder();
10223
+ const textDecoder = new globals.TextDecoder();
10224
+ let textDecoderStrict;
10225
+ const config = {
10241
10226
  encodeUtf8(text) {
10242
- return te.encode(text);
10227
+ return textEncoder.encode(text);
10243
10228
  },
10244
- decodeUtf8(bytes) {
10245
- return td.decode(bytes);
10229
+ decodeUtf8(bytes, strict) {
10230
+ if (strict) {
10231
+ if (!textDecoderStrict) {
10232
+ textDecoderStrict = new globals.TextDecoder("utf-8", {
10233
+ fatal: true,
10234
+ });
10235
+ }
10236
+ return textDecoderStrict.decode(bytes);
10237
+ }
10238
+ return textDecoder.decode(bytes);
10246
10239
  },
10247
10240
  checkUtf8(text) {
10248
10241
  try {
@@ -10254,11 +10247,36 @@ function getTextEncoding() {
10254
10247
  }
10255
10248
  },
10256
10249
  };
10250
+ // If encodeInto is available, use it. Otherwise, configureTextEncoding
10251
+ // fills in a slower fallback that uses encodeUtf8.
10252
+ if (textEncoder.encodeInto) {
10253
+ config.encodeUtf8Into = textEncoder.encodeInto.bind(textEncoder);
10254
+ }
10255
+ // Native String.prototype.isWellFormed, if the runtime provides it.
10256
+ const nativeStringIsWellFormed = String.prototype.isWellFormed;
10257
+ if (nativeStringIsWellFormed) {
10258
+ config.checkUtf8 = (text) => {
10259
+ return nativeStringIsWellFormed.call(text);
10260
+ };
10261
+ }
10262
+ configureTextEncoding(config);
10257
10263
  }
10258
- return globalThis[symbol];
10264
+ return te;
10265
+ }
10266
+ /**
10267
+ * Simplistic polyfill for encodeUtf8Into.
10268
+ *
10269
+ * @private
10270
+ */
10271
+ function emulateEncodeInto(encodeUtf8) {
10272
+ return (text, dest) => {
10273
+ const bytes = encodeUtf8(text);
10274
+ dest.set(bytes);
10275
+ return { written: bytes.byteLength };
10276
+ };
10259
10277
  }
10260
10278
 
10261
- // Copyright 2021-2025 Buf Technologies, Inc.
10279
+ // Copyright 2021-2026 Buf Technologies, Inc.
10262
10280
  //
10263
10281
  // Licensed under the Apache License, Version 2.0 (the "License");
10264
10282
  // you may not use this file except in compliance with the License.
@@ -10313,14 +10331,6 @@ var WireType;
10313
10331
  */
10314
10332
  WireType[WireType["Bit32"] = 5] = "Bit32";
10315
10333
  })(WireType || (WireType = {}));
10316
- /**
10317
- * Maximum value for a 32-bit floating point value (Protobuf FLOAT).
10318
- */
10319
- const FLOAT32_MAX = 3.4028234663852886e38;
10320
- /**
10321
- * Minimum value for a 32-bit floating point value (Protobuf FLOAT).
10322
- */
10323
- const FLOAT32_MIN = -34028234663852886e22;
10324
10334
  /**
10325
10335
  * Maximum value for an unsigned 32-bit integer (Protobuf UINT32, FIXED32).
10326
10336
  */
@@ -10334,34 +10344,55 @@ const INT32_MAX = 0x7fffffff;
10334
10344
  */
10335
10345
  const INT32_MIN = -2147483648;
10336
10346
  class BinaryWriter {
10337
- constructor(encodeUtf8 = getTextEncoding().encodeUtf8) {
10338
- this.encodeUtf8 = encodeUtf8;
10347
+ constructor(encodeUtf8) {
10339
10348
  /**
10340
- * Previous fork states.
10349
+ * Previous fork positions (the write position at the time
10350
+ * `fork()` was called).
10341
10351
  */
10342
- this.stack = [];
10343
- this.chunks = [];
10344
- this.buf = [];
10352
+ this.stackPos = [];
10353
+ this.encodeUtf8Into = encodeUtf8
10354
+ ? emulateEncodeInto(encodeUtf8)
10355
+ : getTextEncoding().encodeUtf8Into;
10356
+ this.buffer = EMPTY_BUFFER;
10357
+ this.viewCache = EMPTY_VIEW;
10358
+ this.pos = 0;
10359
+ }
10360
+ ensureCapacity(size) {
10361
+ const required = this.pos + size;
10362
+ if (required > this.buffer.length) {
10363
+ let newLen = this.buffer.length || INITIAL_SIZE;
10364
+ while (newLen < required)
10365
+ newLen *= 2;
10366
+ const newBuf = new Uint8Array(newLen);
10367
+ if (this.pos > 0)
10368
+ newBuf.set(this.buffer);
10369
+ this.buffer = newBuf;
10370
+ }
10371
+ }
10372
+ /**
10373
+ * The DataView over `buffer`, rebuilt only if the buffer has grown since it
10374
+ * was last used.
10375
+ */
10376
+ view() {
10377
+ const bytes = this.buffer;
10378
+ const view = this.viewCache;
10379
+ // Since ensureCapacity() only ever replaces the buffer with a strictly larger one,
10380
+ // equal lengths mean the view is still current. This is faster than comparing
10381
+ // buffers directly.
10382
+ if (view.byteLength === bytes.byteLength)
10383
+ return view;
10384
+ const newView = new DataView(bytes.buffer);
10385
+ this.viewCache = newView;
10386
+ return newView;
10345
10387
  }
10346
10388
  /**
10347
10389
  * Return all bytes written and reset this writer.
10348
10390
  */
10349
10391
  finish() {
10350
- if (this.buf.length) {
10351
- this.chunks.push(new Uint8Array(this.buf)); // flush the buffer
10352
- this.buf = [];
10353
- }
10354
- let len = 0;
10355
- for (let i = 0; i < this.chunks.length; i++)
10356
- len += this.chunks[i].length;
10357
- let bytes = new Uint8Array(len);
10358
- let offset = 0;
10359
- for (let i = 0; i < this.chunks.length; i++) {
10360
- bytes.set(this.chunks[i], offset);
10361
- offset += this.chunks[i].length;
10362
- }
10363
- this.chunks = [];
10364
- return bytes;
10392
+ const result = this.buffer.slice(0, this.pos);
10393
+ this.pos = 0;
10394
+ this.stackPos = [];
10395
+ return result;
10365
10396
  }
10366
10397
  /**
10367
10398
  * Start a new fork for length-delimited data like a message
@@ -10370,9 +10401,11 @@ class BinaryWriter {
10370
10401
  * Must be joined later with `join()`.
10371
10402
  */
10372
10403
  fork() {
10373
- this.stack.push({ chunks: this.chunks, buf: this.buf });
10374
- this.chunks = [];
10375
- this.buf = [];
10404
+ this.stackPos.push(this.pos);
10405
+ // Reserve room for the length prefix. Payloads under 128 bytes, fairly
10406
+ // common, will need no copy in join().
10407
+ this.ensureCapacity(DEFAULT_LEN_PREFIX_SIZE);
10408
+ this.buffer[this.pos++] = 0;
10376
10409
  return this;
10377
10410
  }
10378
10411
  /**
@@ -10380,17 +10413,24 @@ class BinaryWriter {
10380
10413
  * return to the previous state.
10381
10414
  */
10382
10415
  join() {
10383
- // get chunk of fork
10384
- let chunk = this.finish();
10385
- // restore previous state
10386
- let prev = this.stack.pop();
10387
- if (!prev)
10416
+ const forkPos = this.stackPos.pop();
10417
+ if (forkPos === undefined)
10388
10418
  throw new Error("invalid state, fork stack empty");
10389
- this.chunks = prev.chunks;
10390
- this.buf = prev.buf;
10391
- // write length of chunk as varint
10392
- this.uint32(chunk.byteLength);
10393
- return this.raw(chunk);
10419
+ // fork() presumed the payload would fit the prefix it reserved. If it
10420
+ // doesn't, we need to shift the bytes we just wrote.
10421
+ const len = this.pos - forkPos - DEFAULT_LEN_PREFIX_SIZE;
10422
+ const lenPrefixSize = varint32Size(len);
10423
+ if (lenPrefixSize > DEFAULT_LEN_PREFIX_SIZE) {
10424
+ // Widening pushes the payload past the end of the buffer, so grow first:
10425
+ // copyWithin clamps to the buffer instead of throwing, so a short buffer
10426
+ // would silently drop the tail of the payload.
10427
+ this.ensureCapacity(lenPrefixSize - DEFAULT_LEN_PREFIX_SIZE);
10428
+ this.buffer.copyWithin(forkPos + lenPrefixSize, forkPos + DEFAULT_LEN_PREFIX_SIZE, this.pos);
10429
+ }
10430
+ this.pos = forkPos;
10431
+ this.uint32(len);
10432
+ this.pos += len;
10433
+ return this;
10394
10434
  }
10395
10435
  /**
10396
10436
  * Writes a tag (field number and wire type).
@@ -10406,11 +10446,9 @@ class BinaryWriter {
10406
10446
  * Write a chunk of raw bytes.
10407
10447
  */
10408
10448
  raw(chunk) {
10409
- if (this.buf.length) {
10410
- this.chunks.push(new Uint8Array(this.buf));
10411
- this.buf = [];
10412
- }
10413
- this.chunks.push(chunk);
10449
+ this.ensureCapacity(chunk.length);
10450
+ this.buffer.set(chunk, this.pos);
10451
+ this.pos += chunk.length;
10414
10452
  return this;
10415
10453
  }
10416
10454
  /**
@@ -10418,12 +10456,18 @@ class BinaryWriter {
10418
10456
  */
10419
10457
  uint32(value) {
10420
10458
  assertUInt32(value);
10421
- // write value as varint 32, inlined for speed
10459
+ // uint32 varints are at most 5 bytes; reserve once and avoid per-byte
10460
+ // capacity checks.
10461
+ this.ensureCapacity(5);
10462
+ if (value < 0x80) {
10463
+ this.buffer[this.pos++] = value;
10464
+ return this;
10465
+ }
10422
10466
  while (value > 0x7f) {
10423
- this.buf.push((value & 0x7f) | 0x80);
10424
- value = value >>> 7;
10467
+ this.buffer[this.pos++] = (value & 0x7f) | 0x80;
10468
+ value >>>= 7;
10425
10469
  }
10426
- this.buf.push(value);
10470
+ this.buffer[this.pos++] = value;
10427
10471
  return this;
10428
10472
  }
10429
10473
  /**
@@ -10431,101 +10475,158 @@ class BinaryWriter {
10431
10475
  */
10432
10476
  int32(value) {
10433
10477
  assertInt32(value);
10434
- varint32write(value, this.buf);
10478
+ if (value >= 0) {
10479
+ return this.uint32(value);
10480
+ }
10481
+ // Negative: sign-extend to 64 bits, encodes to 10 bytes.
10482
+ this.ensureCapacity(10);
10483
+ for (let i = 0; i < 9; i++) {
10484
+ this.buffer[this.pos++] = (value & 0x7f) | 0x80;
10485
+ value >>= 7;
10486
+ }
10487
+ this.buffer[this.pos++] = 1;
10435
10488
  return this;
10436
10489
  }
10437
10490
  /**
10438
- * Write a `bool` value, a variant.
10491
+ * Write a `bool` value, a varint.
10439
10492
  */
10440
10493
  bool(value) {
10441
- this.buf.push(value ? 1 : 0);
10494
+ this.ensureCapacity(1);
10495
+ this.buffer[this.pos++] = value ? 1 : 0;
10442
10496
  return this;
10443
10497
  }
10444
10498
  /**
10445
10499
  * Write a `bytes` value, length-delimited arbitrary data.
10446
10500
  */
10447
10501
  bytes(value) {
10448
- this.uint32(value.byteLength); // write length of chunk as varint
10502
+ this.uint32(value.byteLength);
10449
10503
  return this.raw(value);
10450
10504
  }
10451
10505
  /**
10452
10506
  * Write a `string` value, length-delimited data converted to UTF-8 text.
10453
10507
  */
10454
10508
  string(value) {
10455
- let chunk = this.encodeUtf8(value);
10456
- this.uint32(chunk.byteLength); // write length of chunk as varint
10457
- return this.raw(chunk);
10509
+ // TextEncoder.encode() coerces its argument to string, but encodeInto()
10510
+ // rejects non-strings.
10511
+ if (typeof value !== "string") {
10512
+ value = String(value);
10513
+ }
10514
+ const len = value.length;
10515
+ // Fast path for ASCII.
10516
+ if (len <= ASCII_MAX_LENGTH) {
10517
+ this.ensureCapacity(len + 1);
10518
+ const ascii = this.buffer;
10519
+ let pos = this.pos;
10520
+ ascii[pos++] = len;
10521
+ let i = 0;
10522
+ for (; i < len; i++) {
10523
+ const code = value.charCodeAt(i);
10524
+ if (code > 0x7f)
10525
+ break;
10526
+ ascii[pos++] = code;
10527
+ }
10528
+ if (i == len) {
10529
+ this.pos = pos;
10530
+ return this;
10531
+ }
10532
+ }
10533
+ // encodeUtf8Into needs the full-length buffer upfront. The length prefix
10534
+ // can be upto 5 bytes, and a UTF-16 code unit takes at most 3 UTF-8 bytes.
10535
+ this.ensureCapacity(len * 3 + 5);
10536
+ // The length prefix goes first, but the byte length is only known after
10537
+ // encoding. We guess the final varint size here (assuming most text is
10538
+ // ASCII) and then encode.
10539
+ const lenPrefixSizeGuess = varint32Size(len);
10540
+ const buf = this.buffer;
10541
+ const start = this.pos;
10542
+ const { written } = this.encodeUtf8Into(value, buf.subarray(start + lenPrefixSizeGuess));
10543
+ // If our guess was incorrect, we need to shift the bytes we just wrote.
10544
+ const lenPrefixSize = varint32Size(written);
10545
+ if (lenPrefixSize != lenPrefixSizeGuess) {
10546
+ buf.copyWithin(start + lenPrefixSize, start + lenPrefixSizeGuess, start + lenPrefixSizeGuess + written);
10547
+ }
10548
+ // Write the lenPrefix and advance the pos.
10549
+ this.uint32(written);
10550
+ this.pos += written;
10551
+ return this;
10458
10552
  }
10459
10553
  /**
10460
10554
  * Write a `float` value, 32-bit floating point number.
10461
10555
  */
10462
10556
  float(value) {
10463
10557
  assertFloat32(value);
10464
- let chunk = new Uint8Array(4);
10465
- new DataView(chunk.buffer).setFloat32(0, value, true);
10466
- return this.raw(chunk);
10558
+ this.ensureCapacity(4);
10559
+ this.view().setFloat32(this.pos, value, true);
10560
+ this.pos += 4;
10561
+ return this;
10467
10562
  }
10468
10563
  /**
10469
10564
  * Write a `double` value, a 64-bit floating point number.
10470
10565
  */
10471
10566
  double(value) {
10472
- let chunk = new Uint8Array(8);
10473
- new DataView(chunk.buffer).setFloat64(0, value, true);
10474
- return this.raw(chunk);
10567
+ this.ensureCapacity(8);
10568
+ this.view().setFloat64(this.pos, value, true);
10569
+ this.pos += 8;
10570
+ return this;
10475
10571
  }
10476
10572
  /**
10477
10573
  * Write a `fixed32` value, an unsigned, fixed-length 32-bit integer.
10478
10574
  */
10479
10575
  fixed32(value) {
10480
10576
  assertUInt32(value);
10481
- let chunk = new Uint8Array(4);
10482
- new DataView(chunk.buffer).setUint32(0, value, true);
10483
- return this.raw(chunk);
10577
+ this.ensureCapacity(4);
10578
+ this.view().setUint32(this.pos, value, true);
10579
+ this.pos += 4;
10580
+ return this;
10484
10581
  }
10485
10582
  /**
10486
10583
  * Write a `sfixed32` value, a signed, fixed-length 32-bit integer.
10487
10584
  */
10488
10585
  sfixed32(value) {
10489
10586
  assertInt32(value);
10490
- let chunk = new Uint8Array(4);
10491
- new DataView(chunk.buffer).setInt32(0, value, true);
10492
- return this.raw(chunk);
10587
+ this.ensureCapacity(4);
10588
+ this.view().setInt32(this.pos, value, true);
10589
+ this.pos += 4;
10590
+ return this;
10493
10591
  }
10494
10592
  /**
10495
10593
  * Write a `sint32` value, a signed, zigzag-encoded 32-bit varint.
10496
10594
  */
10497
10595
  sint32(value) {
10498
10596
  assertInt32(value);
10499
- // zigzag encode
10500
- value = ((value << 1) ^ (value >> 31)) >>> 0;
10501
- varint32write(value, this.buf);
10502
- return this;
10597
+ // zigzag encode then emit as uint32 varint
10598
+ return this.uint32(((value << 1) ^ (value >> 31)) >>> 0);
10503
10599
  }
10504
10600
  /**
10505
- * Write a `fixed64` value, a signed, fixed-length 64-bit integer.
10601
+ * Write a `sfixed64` value, a signed, fixed-length 64-bit integer.
10506
10602
  */
10507
10603
  sfixed64(value) {
10508
- let chunk = new Uint8Array(8), view = new DataView(chunk.buffer), tc = protoInt64.enc(value);
10509
- view.setInt32(0, tc.lo, true);
10510
- view.setInt32(4, tc.hi, true);
10511
- return this.raw(chunk);
10604
+ const tc = protoInt64.enc(value);
10605
+ this.ensureCapacity(8);
10606
+ const view = this.view();
10607
+ view.setInt32(this.pos, tc.lo, true);
10608
+ view.setInt32(this.pos + 4, tc.hi, true);
10609
+ this.pos += 8;
10610
+ return this;
10512
10611
  }
10513
10612
  /**
10514
10613
  * Write a `fixed64` value, an unsigned, fixed-length 64 bit integer.
10515
10614
  */
10516
10615
  fixed64(value) {
10517
- let chunk = new Uint8Array(8), view = new DataView(chunk.buffer), tc = protoInt64.uEnc(value);
10518
- view.setInt32(0, tc.lo, true);
10519
- view.setInt32(4, tc.hi, true);
10520
- return this.raw(chunk);
10616
+ const tc = protoInt64.uEnc(value);
10617
+ this.ensureCapacity(8);
10618
+ const view = this.view();
10619
+ view.setInt32(this.pos, tc.lo, true);
10620
+ view.setInt32(this.pos + 4, tc.hi, true);
10621
+ this.pos += 8;
10622
+ return this;
10521
10623
  }
10522
10624
  /**
10523
10625
  * Write a `int64` value, a signed 64-bit varint.
10524
10626
  */
10525
10627
  int64(value) {
10526
- let tc = protoInt64.enc(value);
10527
- varint64write(tc.lo, tc.hi, this.buf);
10528
- return this;
10628
+ const tc = protoInt64.enc(value);
10629
+ return this.writeVarint64(tc.lo, tc.hi);
10529
10630
  }
10530
10631
  /**
10531
10632
  * Write a `sint64` value, a signed, zig-zag-encoded 64-bit varint.
@@ -10534,21 +10635,102 @@ class BinaryWriter {
10534
10635
  const tc = protoInt64.enc(value),
10535
10636
  // zigzag encode
10536
10637
  sign = tc.hi >> 31, lo = (tc.lo << 1) ^ sign, hi = ((tc.hi << 1) | (tc.lo >>> 31)) ^ sign;
10537
- varint64write(lo, hi, this.buf);
10538
- return this;
10638
+ return this.writeVarint64(lo, hi);
10539
10639
  }
10540
10640
  /**
10541
10641
  * Write a `uint64` value, an unsigned 64-bit varint.
10542
10642
  */
10543
10643
  uint64(value) {
10544
10644
  const tc = protoInt64.uEnc(value);
10545
- varint64write(tc.lo, tc.hi, this.buf);
10645
+ return this.writeVarint64(tc.lo, tc.hi);
10646
+ }
10647
+ /**
10648
+ * Write a 64-bit varint directly into the buffer. Accepts the value as
10649
+ * split low/high 32-bit words.
10650
+ *
10651
+ * Ported from varint64write() to avoid the intermediate number[] buffer.
10652
+ * See https://github.com/protocolbuffers/protobuf/blob/8a71927d74a4ce34efe2d8769fda198f52d20d12/js/experimental/runtime/kernel/writer.js#L344
10653
+ */
10654
+ writeVarint64(lo, hi) {
10655
+ // Worst case: 10 bytes.
10656
+ this.ensureCapacity(10);
10657
+ const buf = this.buffer;
10658
+ let pos = this.pos;
10659
+ for (let i = 0; i < 28; i = i + 7) {
10660
+ const shift = lo >>> i;
10661
+ const hasNext = !(shift >>> 7 == 0 && hi == 0);
10662
+ buf[pos++] = (hasNext ? shift | 0x80 : shift) & 0xff;
10663
+ if (!hasNext) {
10664
+ this.pos = pos;
10665
+ return this;
10666
+ }
10667
+ }
10668
+ const splitBits = ((lo >>> 28) & 0x0f) | ((hi & 0x07) << 4);
10669
+ const hasMoreBits = !(hi >> 3 == 0);
10670
+ buf[pos++] = (hasMoreBits ? splitBits | 0x80 : splitBits) & 0xff;
10671
+ if (!hasMoreBits) {
10672
+ this.pos = pos;
10673
+ return this;
10674
+ }
10675
+ for (let i = 3; i < 31; i = i + 7) {
10676
+ const shift = hi >>> i;
10677
+ const hasNext = !(shift >>> 7 == 0);
10678
+ buf[pos++] = (hasNext ? shift | 0x80 : shift) & 0xff;
10679
+ if (!hasNext) {
10680
+ this.pos = pos;
10681
+ return this;
10682
+ }
10683
+ }
10684
+ buf[pos++] = (hi >>> 31) & 0x01;
10685
+ this.pos = pos;
10546
10686
  return this;
10547
10687
  }
10548
10688
  }
10689
+ /**
10690
+ * Capacity of the buffer allocated by the first write..
10691
+ */
10692
+ const INITIAL_SIZE = 128;
10693
+ /**
10694
+ * Bytes `fork()` reserves for the length prefix, betting that the payload will
10695
+ * be under 128 bytes. `join()` fills them in, and widens them if the bet was
10696
+ * wrong.
10697
+ */
10698
+ const DEFAULT_LEN_PREFIX_SIZE = 1;
10699
+ /**
10700
+ * Shared empty buffer used as the initial value before the first write.
10701
+ * Avoids allocating and zeroing `INITIAL_SIZE` bytes per BinaryWriter when a
10702
+ * writer is only used for a tiny message (or not used at all).
10703
+ */
10704
+ const EMPTY_BUFFER = new Uint8Array(0);
10705
+ /**
10706
+ * Shared empty view, paired with `EMPTY_BUFFER`. Never written to: any
10707
+ * fixed-width write first grows the buffer, which replaces this view.
10708
+ */
10709
+ const EMPTY_VIEW = new DataView(EMPTY_BUFFER.buffer);
10710
+ /**
10711
+ * Longest string on the ASCII fast paths. Must stay below 0x80, so
10712
+ * that the writer's length prefix always fits a single varint byte.
10713
+ */
10714
+ const ASCII_MAX_LENGTH = 32;
10715
+ /**
10716
+ * Number of bytes needed to encode `value` as an unsigned 32-bit varint.
10717
+ */
10718
+ function varint32Size(value) {
10719
+ if (value < 0x80)
10720
+ return 1;
10721
+ if (value < 0x4000)
10722
+ return 2;
10723
+ if (value < 0x200000)
10724
+ return 3;
10725
+ if (value < 0x10000000)
10726
+ return 4;
10727
+ return 5;
10728
+ }
10549
10729
  class BinaryReader {
10550
10730
  constructor(buf, decodeUtf8 = getTextEncoding().decodeUtf8) {
10551
10731
  this.decodeUtf8 = decodeUtf8;
10732
+ this.varint64Lo = 0;
10733
+ this.varint64Hi = 0;
10552
10734
  this.varint64 = varint64read; // dirty cast for `this`
10553
10735
  /**
10554
10736
  * Read a `uint32` field, an unsigned 32 bit varint.
@@ -10560,21 +10742,32 @@ class BinaryReader {
10560
10742
  this.view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
10561
10743
  }
10562
10744
  /**
10563
- * Reads a tag - field number and wire type.
10745
+ * Reads a tag - field number and wire type. Tags are uint32 varints; values
10746
+ * that do not fit in uint32 are rejected.
10564
10747
  */
10565
10748
  tag() {
10566
- let tag = this.uint32(), fieldNo = tag >>> 3, wireType = tag & 7;
10567
- if (fieldNo <= 0 || wireType < 0 || wireType > 5)
10749
+ const start = this.pos;
10750
+ const tag = this.uint32();
10751
+ const bytesRead = this.pos - start;
10752
+ if (bytesRead > 5 || (bytesRead == 5 && this.buf[this.pos - 1] > 0x0f)) {
10753
+ throw new Error("illegal tag: varint overflows uint32");
10754
+ }
10755
+ const fieldNo = tag >>> 3;
10756
+ const wireType = tag & 7;
10757
+ if (fieldNo <= 0 || wireType > 5) {
10568
10758
  throw new Error("illegal tag: field no " + fieldNo + " wire type " + wireType);
10759
+ }
10569
10760
  return [fieldNo, wireType];
10570
10761
  }
10571
10762
  /**
10572
10763
  * Skip one element and return the skipped data.
10573
10764
  *
10574
10765
  * When skipping StartGroup, provide the tags field number to check for
10575
- * matching field number in the EndGroup tag.
10766
+ * matching field number in the EndGroup tag. Recursion into nested groups
10767
+ * is guarded by the `recursionLimit` argument: When the limit is reached,
10768
+ * this method throws.
10576
10769
  */
10577
- skip(wireType, fieldNo) {
10770
+ skip(wireType, fieldNo, recursionLimit = 100) {
10578
10771
  let start = this.pos;
10579
10772
  switch (wireType) {
10580
10773
  case WireType.Varint:
@@ -10593,6 +10786,9 @@ class BinaryReader {
10593
10786
  this.pos += len;
10594
10787
  break;
10595
10788
  case WireType.StartGroup:
10789
+ if (recursionLimit <= 0) {
10790
+ throw new Error("maximum recursion depth reached");
10791
+ }
10596
10792
  for (;;) {
10597
10793
  const [fn, wt] = this.tag();
10598
10794
  if (wt === WireType.EndGroup) {
@@ -10601,7 +10797,7 @@ class BinaryReader {
10601
10797
  }
10602
10798
  break;
10603
10799
  }
10604
- this.skip(wt, fn);
10800
+ this.skip(wt, fn, recursionLimit - 1);
10605
10801
  }
10606
10802
  break;
10607
10803
  default:
@@ -10635,19 +10831,23 @@ class BinaryReader {
10635
10831
  * Read a `int64` field, a signed 64-bit varint.
10636
10832
  */
10637
10833
  int64() {
10638
- return protoInt64.dec(...this.varint64());
10834
+ this.varint64();
10835
+ return protoInt64.dec(this.varint64Lo, this.varint64Hi);
10639
10836
  }
10640
10837
  /**
10641
10838
  * Read a `uint64` field, an unsigned 64-bit varint.
10642
10839
  */
10643
10840
  uint64() {
10644
- return protoInt64.uDec(...this.varint64());
10841
+ this.varint64();
10842
+ return protoInt64.uDec(this.varint64Lo, this.varint64Hi);
10645
10843
  }
10646
10844
  /**
10647
10845
  * Read a `sint64` field, a signed, zig-zag-encoded 64-bit varint.
10648
10846
  */
10649
10847
  sint64() {
10650
- let [lo, hi] = this.varint64();
10848
+ this.varint64();
10849
+ let lo = this.varint64Lo;
10850
+ let hi = this.varint64Hi;
10651
10851
  // decode zig zag
10652
10852
  let s = -(lo & 1);
10653
10853
  lo = ((lo >>> 1) | ((hi & 1) << 31)) ^ s;
@@ -10658,8 +10858,14 @@ class BinaryReader {
10658
10858
  * Read a `bool` field, a variant.
10659
10859
  */
10660
10860
  bool() {
10661
- let [lo, hi] = this.varint64();
10662
- return lo !== 0 || hi !== 0;
10861
+ // Fast path: most bools are 0x0 or 0x1.
10862
+ const b = this.buf[this.pos];
10863
+ if (b < 0x80) {
10864
+ this.pos++;
10865
+ return b !== 0;
10866
+ }
10867
+ this.varint64();
10868
+ return this.varint64Lo !== 0 || this.varint64Hi !== 0;
10663
10869
  }
10664
10870
  /**
10665
10871
  * Read a `fixed32` field, an unsigned, fixed-length 32-bit integer.
@@ -10711,10 +10917,25 @@ class BinaryReader {
10711
10917
  return this.buf.subarray(start, start + len);
10712
10918
  }
10713
10919
  /**
10714
- * Read a `string` field, length-delimited data converted to UTF-8 text.
10920
+ * Read a `string` field, length-delimited data converted to UTF-8 text. If
10921
+ * `strict` is true, throw on invalid UTF-8 instead of substituting U+FFFD.
10715
10922
  */
10716
- string() {
10717
- return this.decodeUtf8(this.bytes());
10923
+ string(strict) {
10924
+ const bytes = this.bytes();
10925
+ const len = bytes.length;
10926
+ // Fast path for ASCII.
10927
+ if (len <= ASCII_MAX_LENGTH) {
10928
+ const codes = new Array(len);
10929
+ for (let i = 0; i < len; i++) {
10930
+ const byte = bytes[i];
10931
+ if (byte > 0x7f) {
10932
+ return this.decodeUtf8(bytes, strict);
10933
+ }
10934
+ codes[i] = byte;
10935
+ }
10936
+ return String.fromCharCode.apply(String, codes);
10937
+ }
10938
+ return this.decodeUtf8(bytes, strict);
10718
10939
  }
10719
10940
  }
10720
10941
  /**
@@ -10748,7 +10969,7 @@ function assertUInt32(arg) {
10748
10969
  throw new Error("invalid uint32: " + arg);
10749
10970
  }
10750
10971
  /**
10751
- * Assert a valid protobuf float value as a number or string.
10972
+ * Assert a valid protobuf float32 value as a number or string.
10752
10973
  */
10753
10974
  function assertFloat32(arg) {
10754
10975
  if (typeof arg == "string") {
@@ -10761,13 +10982,15 @@ function assertFloat32(arg) {
10761
10982
  else if (typeof arg != "number") {
10762
10983
  throw new Error("invalid float32: " + typeof arg);
10763
10984
  }
10764
- if (Number.isFinite(arg) &&
10765
- (arg > FLOAT32_MAX || arg < FLOAT32_MIN))
10985
+ // float32 is represented with regular 64-bit numbers. A value too large for
10986
+ // a float32 becomes infinity when rounded. NaN and infinity are valid values.
10987
+ if (!Number.isFinite(Math.fround(arg)) && Number.isFinite(arg)) {
10766
10988
  throw new Error("invalid float32: " + arg);
10989
+ }
10767
10990
  }
10768
10991
 
10769
10992
  class TinyQueue {
10770
- constructor(data = [], compare = defaultCompare) {
10993
+ constructor(data = [], compare = (a, b) => (a < b ? -1 : a > b ? 1 : 0)) {
10771
10994
  this.data = data;
10772
10995
  this.length = this.data.length;
10773
10996
  this.compare = compare;
@@ -10779,8 +11002,7 @@ class TinyQueue {
10779
11002
 
10780
11003
  push(item) {
10781
11004
  this.data.push(item);
10782
- this.length++;
10783
- this._up(this.length - 1);
11005
+ this._up(this.length++);
10784
11006
  }
10785
11007
 
10786
11008
  pop() {
@@ -10788,9 +11010,8 @@ class TinyQueue {
10788
11010
 
10789
11011
  const top = this.data[0];
10790
11012
  const bottom = this.data.pop();
10791
- this.length--;
10792
11013
 
10793
- if (this.length > 0) {
11014
+ if (--this.length > 0) {
10794
11015
  this.data[0] = bottom;
10795
11016
  this._down(0);
10796
11017
  }
@@ -10823,31 +11044,51 @@ class TinyQueue {
10823
11044
  const item = data[pos];
10824
11045
 
10825
11046
  while (pos < halfLength) {
10826
- let left = (pos << 1) + 1;
10827
- let best = data[left];
10828
- const right = left + 1;
11047
+ let bestChild = (pos << 1) + 1; // initially it is the left child
11048
+ const right = bestChild + 1;
10829
11049
 
10830
- if (right < this.length && compare(data[right], best) < 0) {
10831
- left = right;
10832
- best = data[right];
11050
+ if (right < this.length && compare(data[right], data[bestChild]) < 0) {
11051
+ bestChild = right;
10833
11052
  }
10834
- if (compare(best, item) >= 0) break;
11053
+ if (compare(data[bestChild], item) >= 0) break;
10835
11054
 
10836
- data[pos] = best;
10837
- pos = left;
11055
+ data[pos] = data[bestChild];
11056
+ pos = bestChild;
10838
11057
  }
10839
11058
 
10840
11059
  data[pos] = item;
10841
11060
  }
10842
11061
  }
10843
11062
 
10844
- function defaultCompare(a, b) {
10845
- return a < b ? -1 : a > b ? 1 : 0;
10846
- }
10847
-
10848
11063
  const earthRadius = 6371;
10849
11064
  const rad = Math.PI / 180;
10850
11065
 
11066
+ /**
11067
+ * @typedef {object} Node
11068
+ * @prop {number} left left index in the kd-tree array
11069
+ * @prop {number} right right index in the kd-tree array
11070
+ * @prop {number} axis 0 for longitude and 1 for latitude axis
11071
+ * @prop {number} dist the lower bound of children's distances to the query point
11072
+ * @prop {number} minLng
11073
+ * @prop {number} minLat
11074
+ * @prop {number} maxLng
11075
+ * @prop {number} maxLat
11076
+ */
11077
+
11078
+ /**
11079
+ * @typedef {{ id: number, dist: number }} QueueItem
11080
+ */
11081
+
11082
+ /**
11083
+ * Returns an array of the closest points from a given location in order of increasing distance.
11084
+ *
11085
+ * @param {import('kdbush').default} index kdbush index
11086
+ * @param {number} lng Query point longitude
11087
+ * @param {number} lat Query point latitude
11088
+ * @param {number} [maxResults] Maximum number of points to return
11089
+ * @param {number} [maxDistance] Maximum distance in kilometers to search within
11090
+ * @param {(item: number) => boolean} [predicate] A function to filter the results
11091
+ */
10851
11092
  function around(index, lng, lat, maxResults = Infinity, maxDistance = Infinity, predicate) {
10852
11093
  let maxHaverSinDist = 1;
10853
11094
  const result = [];
@@ -10855,15 +11096,21 @@ function around(index, lng, lat, maxResults = Infinity, maxDistance = Infinity,
10855
11096
  if (maxResults === undefined) maxResults = Infinity;
10856
11097
  if (maxDistance !== undefined) maxHaverSinDist = haverSin(maxDistance / earthRadius);
10857
11098
 
10858
- // a distance-sorted priority queue that will contain both points and kd-tree nodes
11099
+ /**
11100
+ * a distance-sorted priority queue that will contain both points and kd-tree nodes
11101
+ * @type {TinyQueue<QueueItem|Node>}
11102
+ */
10859
11103
  const q = new TinyQueue([], compareDist);
10860
11104
 
10861
- // an object that represents the top kd-tree node (the whole Earth)
11105
+ /**
11106
+ * an object that represents the top kd-tree node (the whole Earth)
11107
+ * @type {Node|undefined}
11108
+ */
10862
11109
  let node = {
10863
- left: 0, // left index in the kd-tree array
10864
- right: index.ids.length - 1, // right index
10865
- axis: 0, // 0 for longitude axis and 1 for latitude axis
10866
- minLng: -180, // bounding box of the node
11110
+ left: 0,
11111
+ right: index.ids.length - 1,
11112
+ axis: 0,
11113
+ minLng: -180,
10867
11114
  minLat: -90,
10868
11115
  maxLng: 180,
10869
11116
  maxLat: 90
@@ -10935,21 +11182,27 @@ function around(index, lng, lat, maxResults = Infinity, maxDistance = Infinity,
10935
11182
  // fetch closest points from the queue; they're guaranteed to be closer
10936
11183
  // than all remaining points (both individual and those in kd-tree nodes),
10937
11184
  // since each node's distance is a lower bound of distances to its children
10938
- while (q.length && q.peek().id != null) {
10939
- const candidate = q.pop();
11185
+ let candidate;
11186
+ while ((candidate = q.pop()) && 'id' in candidate) {
10940
11187
  if (candidate.dist > maxHaverSinDist) return result;
10941
11188
  result.push(candidate.id);
10942
11189
  if (result.length === maxResults) return result;
10943
11190
  }
10944
11191
 
10945
11192
  // the next closest kd-tree node
10946
- node = q.pop();
11193
+ node = candidate;
10947
11194
  }
10948
11195
 
10949
11196
  return result;
10950
11197
  }
10951
11198
 
10952
- // lower bound for distance from a location to points inside a bounding box
11199
+ /**
11200
+ * lower bound for distance from a location to points inside a bounding box
11201
+ * @param {number} lng
11202
+ * @param {number} lat
11203
+ * @param {number} cosLat
11204
+ * @param {{ minLng: number, maxLng: number, minLat: number, maxLat: number }} node
11205
+ */
10953
11206
  function boxDist(lng, lat, cosLat, node) {
10954
11207
  const minLng = node.minLng;
10955
11208
  const maxLng = node.maxLng;
@@ -10979,29 +11232,61 @@ function boxDist(lng, lat, cosLat, node) {
10979
11232
  );
10980
11233
  }
10981
11234
 
11235
+ /**
11236
+ * @param {QueueItem|Node} a
11237
+ * @param {QueueItem|Node} b
11238
+ */
10982
11239
  function compareDist(a, b) {
10983
11240
  return a.dist - b.dist;
10984
11241
  }
10985
11242
 
11243
+ /** @param {number} theta */
10986
11244
  function haverSin(theta) {
10987
11245
  const s = Math.sin(theta / 2);
10988
11246
  return s * s;
10989
11247
  }
10990
11248
 
11249
+ /**
11250
+ * @param {number} haverSinDLng
11251
+ * @param {number} cosLat1
11252
+ * @param {number} lat1
11253
+ * @param {number} lat2
11254
+ */
10991
11255
  function haverSinDistPartial(haverSinDLng, cosLat1, lat1, lat2) {
10992
11256
  return cosLat1 * Math.cos(lat2 * rad) * haverSinDLng + haverSin((lat1 - lat2) * rad);
10993
11257
  }
10994
11258
 
11259
+
11260
+ /**
11261
+ * @param {number} lng1
11262
+ * @param {number} lat1
11263
+ * @param {number} lng2
11264
+ * @param {number} lat2
11265
+ * @param {number} cosLat1
11266
+ */
10995
11267
  function haverSinDist(lng1, lat1, lng2, lat2, cosLat1) {
10996
11268
  const haverSinDLng = haverSin((lng1 - lng2) * rad);
10997
11269
  return haverSinDistPartial(haverSinDLng, cosLat1, lat1, lat2);
10998
11270
  }
10999
11271
 
11272
+ /**
11273
+ * Returns great circle distance between two locations in kilometers.
11274
+ *
11275
+ * @param {number} lng1
11276
+ * @param {number} lat1
11277
+ * @param {number} lng2
11278
+ * @param {number} lat2
11279
+ */
11000
11280
  function distance(lng1, lat1, lng2, lat2) {
11001
11281
  const h = haverSinDist(lng1, lat1, lng2, lat2, Math.cos(lat1 * rad));
11002
11282
  return 2 * earthRadius * Math.asin(Math.sqrt(h));
11003
11283
  }
11004
11284
 
11285
+
11286
+ /**
11287
+ * @param {number} lat
11288
+ * @param {number} haverSinDLng
11289
+ */
11005
11290
  function vertexLat(lat, haverSinDLng) {
11006
11291
  const cosDLng = 1 - 2 * haverSinDLng;
11007
11292
  if (cosDLng <= 0) return lat > 0 ? 90 : -90;
@@ -11014,19 +11299,25 @@ const ARRAY_TYPES = [
11014
11299
  ];
11015
11300
 
11016
11301
  /** @typedef {Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor} TypedArrayConstructor */
11302
+ /** @typedef {Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array} TypedArray */
11017
11303
 
11018
11304
  const VERSION = 1; // serialized format version
11019
11305
  const HEADER_SIZE = 8;
11020
11306
 
11307
+ // Shared scratch stack for iterative DFS in range/within. Sized for the worst case:
11308
+ // 3 ints per frame * (treeHeight + 1), with treeHeight ≤ ceil(log2(2^32 / 3)) ≈ 31.
11309
+ const STACK = new Uint32Array(96);
11310
+
11021
11311
  class KDBush {
11022
11312
 
11023
11313
  /**
11024
11314
  * Creates an index from raw `ArrayBuffer` data.
11025
- * @param {ArrayBuffer} data
11315
+ * @param {ArrayBufferLike} data
11026
11316
  */
11027
11317
  static from(data) {
11028
- if (!(data instanceof ArrayBuffer)) {
11029
- throw new Error('Data must be an instance of ArrayBuffer.');
11318
+ // @ts-expect-error duck typing array buffers
11319
+ if (!data || data.byteLength === undefined || data.buffer) {
11320
+ throw new Error('Data must be an instance of ArrayBuffer or SharedArrayBuffer.');
11030
11321
  }
11031
11322
  const [magic, versionAndType] = new Uint8Array(data, 0, 2);
11032
11323
  if (magic !== 0xdb) {
@@ -11043,7 +11334,7 @@ class KDBush {
11043
11334
  const [nodeSize] = new Uint16Array(data, 2, 1);
11044
11335
  const [numItems] = new Uint32Array(data, 4, 1);
11045
11336
 
11046
- return new KDBush(numItems, nodeSize, ArrayType, data);
11337
+ return new KDBush(numItems, nodeSize, ArrayType, undefined, data);
11047
11338
  }
11048
11339
 
11049
11340
  /**
@@ -11051,10 +11342,11 @@ class KDBush {
11051
11342
  * @param {number} numItems
11052
11343
  * @param {number} [nodeSize=64] Size of the KD-tree node (64 by default).
11053
11344
  * @param {TypedArrayConstructor} [ArrayType=Float64Array] The array type used for coordinates storage (`Float64Array` by default).
11054
- * @param {ArrayBuffer} [data] (For internal use only)
11345
+ * @param {ArrayBufferConstructor | SharedArrayBufferConstructor} [ArrayBufferType=ArrayBuffer] The array buffer type used for storage (`ArrayBuffer` by default).
11346
+ * @param {ArrayBufferLike} [data] (For internal use only)
11055
11347
  */
11056
- constructor(numItems, nodeSize = 64, ArrayType = Float64Array, data) {
11057
- if (isNaN(numItems) || numItems < 0) throw new Error(`Unpexpected numItems value: ${numItems}.`);
11348
+ constructor(numItems, nodeSize = 64, ArrayType = Float64Array, ArrayBufferType = ArrayBuffer, data) {
11349
+ if (isNaN(numItems) || numItems < 0) throw new Error(`Unexpected numItems value: ${numItems}.`);
11058
11350
 
11059
11351
  this.numItems = +numItems;
11060
11352
  this.nodeSize = Math.min(Math.max(+nodeSize, 2), 65535);
@@ -11070,23 +11362,28 @@ class KDBush {
11070
11362
  throw new Error(`Unexpected typed array class: ${ArrayType}.`);
11071
11363
  }
11072
11364
 
11073
- if (data && (data instanceof ArrayBuffer)) { // reconstruct an index from a buffer
11365
+ if (data) { // reconstruct an index from a buffer
11074
11366
  this.data = data;
11075
- this.ids = new this.IndexArrayType(this.data, HEADER_SIZE, numItems);
11076
- this.coords = new this.ArrayType(this.data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);
11367
+ // @ts-expect-error TS can't handle SharedArrayBuffer overloads
11368
+ this.ids = new this.IndexArrayType(data, HEADER_SIZE, numItems);
11369
+ // @ts-expect-error TS can't handle SharedArrayBuffer overloads
11370
+ this.coords = new ArrayType(data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);
11077
11371
  this._pos = numItems * 2;
11078
11372
  this._finished = true;
11373
+
11079
11374
  } else { // initialize a new index
11080
- this.data = new ArrayBuffer(HEADER_SIZE + coordsByteSize + idsByteSize + padCoords);
11081
- this.ids = new this.IndexArrayType(this.data, HEADER_SIZE, numItems);
11082
- this.coords = new this.ArrayType(this.data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);
11375
+ const data = this.data = new ArrayBufferType(HEADER_SIZE + coordsByteSize + idsByteSize + padCoords);
11376
+ // @ts-expect-error TS can't handle SharedArrayBuffer overloads
11377
+ this.ids = new this.IndexArrayType(data, HEADER_SIZE, numItems);
11378
+ // @ts-expect-error TS can't handle SharedArrayBuffer overloads
11379
+ this.coords = new ArrayType(data, HEADER_SIZE + idsByteSize + padCoords, numItems * 2);
11083
11380
  this._pos = 0;
11084
11381
  this._finished = false;
11085
11382
 
11086
11383
  // set header
11087
- new Uint8Array(this.data, 0, 2).set([0xdb, (VERSION << 4) + arrayTypeIndex]);
11088
- new Uint16Array(this.data, 2, 1)[0] = nodeSize;
11089
- new Uint32Array(this.data, 4, 1)[0] = numItems;
11384
+ new Uint8Array(data, 0, 2).set([0xdb, (VERSION << 4) + arrayTypeIndex]);
11385
+ new Uint16Array(data, 2, 1)[0] = nodeSize;
11386
+ new Uint32Array(data, 4, 1)[0] = numItems;
11090
11387
  }
11091
11388
  }
11092
11389
 
@@ -11131,14 +11428,17 @@ class KDBush {
11131
11428
  if (!this._finished) throw new Error('Data not yet indexed - call index.finish().');
11132
11429
 
11133
11430
  const {ids, coords, nodeSize} = this;
11134
- const stack = [0, ids.length - 1, 0];
11431
+ STACK[0] = 0;
11432
+ STACK[1] = ids.length - 1;
11433
+ STACK[2] = 0;
11434
+ let sp = 3;
11135
11435
  const result = [];
11136
11436
 
11137
11437
  // recursively search for items in range in the kd-sorted arrays
11138
- while (stack.length) {
11139
- const axis = stack.pop() || 0;
11140
- const right = stack.pop() || 0;
11141
- const left = stack.pop() || 0;
11438
+ while (sp > 0) {
11439
+ const axis = STACK[--sp];
11440
+ const right = STACK[--sp];
11441
+ const left = STACK[--sp];
11142
11442
 
11143
11443
  // if we reached "tree node", search linearly
11144
11444
  if (right - left <= nodeSize) {
@@ -11160,14 +11460,14 @@ class KDBush {
11160
11460
 
11161
11461
  // queue search in halves that intersect the query
11162
11462
  if (axis === 0 ? minX <= x : minY <= y) {
11163
- stack.push(left);
11164
- stack.push(m - 1);
11165
- stack.push(1 - axis);
11463
+ STACK[sp++] = left;
11464
+ STACK[sp++] = m - 1;
11465
+ STACK[sp++] = 1 - axis;
11166
11466
  }
11167
11467
  if (axis === 0 ? maxX >= x : maxY >= y) {
11168
- stack.push(m + 1);
11169
- stack.push(right);
11170
- stack.push(1 - axis);
11468
+ STACK[sp++] = m + 1;
11469
+ STACK[sp++] = right;
11470
+ STACK[sp++] = 1 - axis;
11171
11471
  }
11172
11472
  }
11173
11473
 
@@ -11182,23 +11482,43 @@ class KDBush {
11182
11482
  * @returns {number[]} An array of indices correponding to the found items.
11183
11483
  */
11184
11484
  within(qx, qy, r) {
11485
+ const result = /** @type {number[]} */ ([]);
11486
+ this.withinInto(qx, qy, r, result);
11487
+ return result;
11488
+ }
11489
+
11490
+ /**
11491
+ * Search the index for items within a given radius, writing matching ids into `out`
11492
+ * via indexed assignment (`out[i] = id`). Accepts any indexed-writable container —
11493
+ * a typed array sized to the expected upper bound (allocation-free, fast) or a plain
11494
+ * `Array` (which will grow as needed). Returns the number of matches written.
11495
+ * @param {number} qx
11496
+ * @param {number} qy
11497
+ * @param {number} r Query radius.
11498
+ * @param {number[] | TypedArray} out Container to write matching ids into.
11499
+ * @returns {number} The number of matches written to `out`.
11500
+ */
11501
+ withinInto(qx, qy, r, out) {
11185
11502
  if (!this._finished) throw new Error('Data not yet indexed - call index.finish().');
11186
11503
 
11187
11504
  const {ids, coords, nodeSize} = this;
11188
- const stack = [0, ids.length - 1, 0];
11189
- const result = [];
11505
+ STACK[0] = 0;
11506
+ STACK[1] = ids.length - 1;
11507
+ STACK[2] = 0;
11508
+ let sp = 3;
11509
+ let count = 0;
11190
11510
  const r2 = r * r;
11191
11511
 
11192
11512
  // recursively search for items within radius in the kd-sorted arrays
11193
- while (stack.length) {
11194
- const axis = stack.pop() || 0;
11195
- const right = stack.pop() || 0;
11196
- const left = stack.pop() || 0;
11513
+ while (sp > 0) {
11514
+ const axis = STACK[--sp];
11515
+ const right = STACK[--sp];
11516
+ const left = STACK[--sp];
11197
11517
 
11198
11518
  // if we reached "tree node", search linearly
11199
11519
  if (right - left <= nodeSize) {
11200
11520
  for (let i = left; i <= right; i++) {
11201
- if (sqDist(coords[2 * i], coords[2 * i + 1], qx, qy) <= r2) result.push(ids[i]);
11521
+ if (sqDist(coords[2 * i], coords[2 * i + 1], qx, qy) <= r2) out[count++] = ids[i];
11202
11522
  }
11203
11523
  continue;
11204
11524
  }
@@ -11209,28 +11529,28 @@ class KDBush {
11209
11529
  // include the middle item if it's in range
11210
11530
  const x = coords[2 * m];
11211
11531
  const y = coords[2 * m + 1];
11212
- if (sqDist(x, y, qx, qy) <= r2) result.push(ids[m]);
11532
+ if (sqDist(x, y, qx, qy) <= r2) out[count++] = ids[m];
11213
11533
 
11214
11534
  // queue search in halves that intersect the query
11215
11535
  if (axis === 0 ? qx - r <= x : qy - r <= y) {
11216
- stack.push(left);
11217
- stack.push(m - 1);
11218
- stack.push(1 - axis);
11536
+ STACK[sp++] = left;
11537
+ STACK[sp++] = m - 1;
11538
+ STACK[sp++] = 1 - axis;
11219
11539
  }
11220
11540
  if (axis === 0 ? qx + r >= x : qy + r >= y) {
11221
- stack.push(m + 1);
11222
- stack.push(right);
11223
- stack.push(1 - axis);
11541
+ STACK[sp++] = m + 1;
11542
+ STACK[sp++] = right;
11543
+ STACK[sp++] = 1 - axis;
11224
11544
  }
11225
11545
  }
11226
11546
 
11227
- return result;
11547
+ return count;
11228
11548
  }
11229
11549
  }
11230
11550
 
11231
11551
  /**
11232
11552
  * @param {Uint16Array | Uint32Array} ids
11233
- * @param {InstanceType<TypedArrayConstructor>} coords
11553
+ * @param {TypedArray} coords
11234
11554
  * @param {number} nodeSize
11235
11555
  * @param {number} left
11236
11556
  * @param {number} right
@@ -11254,7 +11574,7 @@ function sort(ids, coords, nodeSize, left, right, axis) {
11254
11574
  * Custom Floyd-Rivest selection algorithm: sort ids and coords so that
11255
11575
  * [left..k-1] items are smaller than k-th item (on either x or y axis)
11256
11576
  * @param {Uint16Array | Uint32Array} ids
11257
- * @param {InstanceType<TypedArrayConstructor>} coords
11577
+ * @param {TypedArray} coords
11258
11578
  * @param {number} k
11259
11579
  * @param {number} left
11260
11580
  * @param {number} right
@@ -11302,7 +11622,7 @@ function select(ids, coords, k, left, right, axis) {
11302
11622
 
11303
11623
  /**
11304
11624
  * @param {Uint16Array | Uint32Array} ids
11305
- * @param {InstanceType<TypedArrayConstructor>} coords
11625
+ * @param {TypedArray} coords
11306
11626
  * @param {number} i
11307
11627
  * @param {number} j
11308
11628
  */
@@ -11313,7 +11633,7 @@ function swapItem(ids, coords, i, j) {
11313
11633
  }
11314
11634
 
11315
11635
  /**
11316
- * @param {InstanceType<TypedArrayConstructor>} arr
11636
+ * @param {TypedArray} arr
11317
11637
  * @param {number} i
11318
11638
  * @param {number} j
11319
11639
  */
@@ -11335,7 +11655,9 @@ function sqDist(ax, ay, bx, by) {
11335
11655
  return dx * dx + dy * dy;
11336
11656
  }
11337
11657
 
11338
- const It="ENTRIES",U="KEYS",B="VALUES";class L{set;_type;_path;constructor(e,n){const o=e._tree,s=Array.from(o.keys());this.set=e,this._type=n,this._path=s.length>0?[{node:o,keys:s}]:[];}next(){const e=this.dive();return this.backtrack(),e}dive(){if(this._path.length===0)return {done:true,value:void 0};const{node:e,keys:n}=x(this._path);if(x(n)==="")return {done:false,value:this.result()};const o=e.get(x(n));return this._path.push({node:o,keys:Array.from(o.keys())}),this.dive()}backtrack(){if(this._path.length===0)return;const e=x(this._path).keys;e.pop(),!(e.length>0)&&(this._path.pop(),this.backtrack());}key(){return this.set._prefix+this._path.map(({keys:e})=>x(e)).filter(e=>e!=="").join("")}value(){return x(this._path).node.get("")}result(){switch(this._type){case B:return this.value();case U:return this.key();default:return [this.key(),this.value()]}}[Symbol.iterator](){return this}}const x=t=>t[t.length-1],xt=(t,e,n)=>{const o=new Map;if(typeof e!="string")return o;const s=e.length+1,r=s+n,i=new Uint8Array(r*s).fill(n+1);for(let c=0;c<s;++c)i[c]=c;for(let c=1;c<r;++c)i[c*s]=c;return G(t,e,n,o,i,1,s,""),o},G=(t,e,n,o,s,r,i,c)=>{const a=r*i;t:for(const d of t.keys())if(d===""){const u=s[a-1];u<=n&&o.set(c,[t.get(d),u]);}else {let u=r;for(let f=0;f<d.length;++f,++u){const m=d[f],_=i*u,g=_-i;let h=s[_];const l=Math.max(0,u-n-1),p=Math.min(i-1,u+n);for(let w=l;w<p;++w){const k=m!==e[w],C=s[g+w]+ +k,z=s[g+w+1]+1,I=s[_+w]+1,F=s[_+w+1]=Math.min(C,z,I);F<h&&(h=F);}if(h>n)continue t}G(t.get(d),e,n,o,s,u,i,c+d);}};class y{_tree;_prefix;_size=void 0;constructor(e=new Map,n=""){this._tree=e,this._prefix=n;}atPrefix(e){if(!e.startsWith(this._prefix))throw new Error("Mismatched prefix");const[n,o]=S(this._tree,e.slice(this._prefix.length));if(n===void 0){const[s,r]=A(o);for(const i of s.keys())if(i!==""&&i.startsWith(r)){const c=new Map;return c.set(i.slice(r.length),s.get(i)),new y(c,e)}}return new y(n,e)}clear(){this._size=void 0,this._tree.clear();}delete(e){return this._size=void 0,Ft(this._tree,e)}entries(){return new L(this,It)}forEach(e){for(const[n,o]of this)e(n,o,this);}fuzzyGet(e,n){return xt(this._tree,e,n)}get(e){const n=O(this._tree,e);return n!==void 0?n.get(""):void 0}has(e){return O(this._tree,e)?.has("")??false}keys(){return new L(this,U)}set(e,n){if(typeof e!="string")throw new Error("key must be a string");return this._size=void 0,E(this._tree,e).set("",n),this}get size(){if(this._size)return this._size;this._size=0;const e=this.entries();for(;!e.next().done;)this._size+=1;return this._size}update(e,n){if(typeof e!="string")throw new Error("key must be a string");this._size=void 0;const o=E(this._tree,e);return o.set("",n(o.get(""))),this}fetch(e,n){if(typeof e!="string")throw new Error("key must be a string");this._size=void 0;const o=E(this._tree,e);let s=o.get("");return s===void 0&&o.set("",s=n()),s}values(){return new L(this,B)}[Symbol.iterator](){return this.entries()}static from(e){const n=new y;for(const[o,s]of e)n.set(o,s);return n}static fromObject(e){return y.from(Object.entries(e))}}const S=(t,e,n=[])=>{if(e.length===0||t==null)return [t,n];for(const o of t.keys())if(o!==""&&e.startsWith(o))return n.push([t,o]),S(t.get(o),e.slice(o.length),n);return n.push([t,e]),S(void 0,"",n)},O=(t,e)=>{if(e.length===0||!t)return t;for(const n of t.keys())if(n!==""&&e.startsWith(n))return O(t.get(n),e.slice(n.length))},E=(t,e)=>{const n=e.length;t:for(let o=0;t&&o<n;){for(const r of t.keys())if(r!==""&&e[o]===r[0]){const i=Math.min(n-o,r.length);let c=1;for(;c<i&&e[o+c]===r[c];)++c;const a=t.get(r);if(c===r.length)t=a;else {const d=new Map;d.set(r.slice(c),a),t.set(e.slice(o,o+c),d),t.delete(r),t=d;}o+=c;continue t}const s=new Map;return t.set(e.slice(o),s),s}return t},Ft=(t,e)=>{const[n,o]=S(t,e);if(n!==void 0){if(n.delete(""),n.size===0)K(o);else if(n.size===1){const[s,r]=n.entries().next().value;Q(o,s,r);}}},K=t=>{if(t.length===0)return;const[e,n]=A(t);if(e.delete(n),e.size===0)K(t.slice(0,-1));else if(e.size===1){const[o,s]=e.entries().next().value;o!==""&&Q(t.slice(0,-1),o,s);}},Q=(t,e,n)=>{if(t.length===0)return;const[o,s]=A(t);o.set(s+e,n),o.delete(s);},A=t=>t[t.length-1],Y=(t,e)=>t._idToShortId.has(e),St=/[\n\r\p{Z}\p{P}]+/u,V="or",Z="and",bt="and_not",vt=(t,e)=>{t.includes(e)||t.push(e);},X=(t,e)=>{for(const n of e)t.includes(n)||t.push(n);},tt=({score:t},{score:e})=>e-t,et=()=>new Map,T=(t,e)=>Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0,nt={[V]:(t,e)=>{for(const n of e.keys()){const o=t.get(n);if(o==null)t.set(n,e.get(n));else {const{score:s,terms:r,match:i}=e.get(n);o.score=o.score+s,o.match=Object.assign(o.match,i),X(o.terms,r);}}return t},[Z]:(t,e)=>{const n=new Map;for(const o of e.keys()){const s=t.get(o);if(s==null)continue;const{score:r,terms:i,match:c}=e.get(o);X(s.terms,i),n.set(o,{score:s.score+r,terms:s.terms,match:Object.assign(s.match,c)});}return n},[bt]:(t,e)=>{for(const n of e.keys())t.delete(n);return t}},kt=(t,e,n,o,s,r)=>{const{k:i,b:c,d:a}=r;return Math.log(1+(n-e+.5)/(e+.5))*(a+t*(i+1)/(t+i*(1-c+c*o/s)))},Ct=t=>(e,n,o)=>({term:e,fuzzy:typeof t.fuzzy=="function"?t.fuzzy(e,n,o):t.fuzzy??false,prefix:typeof t.prefix=="function"?t.prefix(e,n,o):t.prefix===true,termBoost:typeof t.boostTerm=="function"?t.boostTerm(e,n,o):1}),ot=(t,e,n,o)=>{for(const s of Object.keys(t._fieldIds))if(t._fieldIds[s]===n){t._options.logger("warn",`SlimSearch: document with ID ${t._documentIds.get(e)} has changed before removal: term "${o}" was not present in field "${s}". Removing a document after it has changed can corrupt the index!`,"version_conflict");return}},st=(t,e,n,o)=>{const s=t._index.fetch(o,et);let r=s.get(e);if(r==null)r=new Map,r.set(n,1),s.set(e,r);else {const i=r.get(n);r.set(n,(i??0)+1);}},M=(t,e,n,o)=>{if(!t._index.has(o)){ot(t,n,e,o);return}const s=t._index.fetch(o,et),r=s.get(e),i=r?.get(n);!r||typeof i>"u"?ot(t,n,e,o):i<=1?r.size<=1?s.delete(e):r.delete(n):r.set(n,i-1),t._index.get(o).size===0&&t._index.delete(o);},Lt=(t,e,n,o,s)=>{let r=t._fieldLength.get(e);r==null&&t._fieldLength.set(e,r=[]),r[n]=s;const i=(t._avgFieldLength[n]||0)*o+s;t._avgFieldLength[n]=i/(o+1);},Ot=(t,e)=>{const n=t._nextId;return t._idToShortId.set(e,n),t._documentIds.set(n,e),t._documentCount+=1,t._nextId+=1,n},Et=(t,e,n)=>{const{storeFields:o,extractField:s}=t._options;if(o?.length===0)return;let r=t._storedFields.get(e);r===void 0&&t._storedFields.set(e,r={});for(const i of o){const c=s(n,i);c!=null&&(r[i]=c);}},D=(t,e)=>{const{extractField:n,stringifyField:o,tokenize:s,processTerm:r,fields:i,idField:c}=t._options,a=n(e,c);if(a==null)throw new Error(`SlimSearch: document does not have ID field "${c}"`);if(Y(t,a))throw new Error(`SlimSearch: duplicate ID ${a}`);const d=Ot(t,a);Et(t,d,e);for(const u of i){const f=n(e,u);if(f==null)continue;const m=s(o(f,u),u),_=t._fieldIds[u],g=new Set(m).size;Lt(t,d,_,t._documentCount-1,g);for(const h of m){const l=r(h,u);if(Array.isArray(l))for(const p of l)st(t,_,d,p);else l&&st(t,_,d,l);}}},j=(t,e)=>{for(const n of e)D(t,n);},Vt={k:1.2,b:.7,d:.5},q={idField:"id",extractField:(t,e)=>t[e],stringifyField:t=>t.toString(),tokenize:t=>t.split(St),processTerm:t=>t.toLowerCase(),fields:void 0,searchOptions:void 0,storeFields:[],logger:(t,e)=>{console?.[t]?.(e);},autoVacuum:true},it={combineWith:V,prefix:false,fuzzy:false,maxFuzzy:6,boost:{},weights:{fuzzy:.45,prefix:.375},bm25:Vt},Tt={combineWith:Z,prefix:(t,e,n)=>e===n.length-1},$={batchSize:1e3,batchWait:10},N={minDirtFactor:.1,minDirtCount:20},W={...$,...N},P=Symbol("*"),Dt=(t,e)=>{const n=new Map,o={...t._options.searchOptions,...e};for(const[s,r]of t._documentIds){const i=o.boostDocument?o.boostDocument(r,"",t._storedFields.get(s)):1;n.set(s,{score:i,terms:[],match:{}});}return n},rt=(t,e=V)=>{if(t.length===0)return new Map;const n=e.toLowerCase();if(!(n in nt))throw new Error(`Invalid combination operator: ${e}`);return t.reduce(nt[n])},R=(t,e,n,o,s,r,i,c,a,d=new Map)=>{if(r==null)return d;for(const u of Object.keys(i)){const f=i[u],m=t._fieldIds[u],_=r.get(m);if(_==null)continue;let g=_.size;const h=t._avgFieldLength[m];for(const l of _.keys()){if(!t._documentIds.has(l)){M(t,m,l,n),g-=1;continue}const p=c?c(t._documentIds.get(l),n,t._storedFields.get(l)):1;if(!p)continue;const w=_.get(l),k=t._fieldLength.get(l)[m],C=kt(w,g,t._documentCount,k,h,a),z=o*s*f*p*C,I=d.get(l);if(I){I.score+=z,vt(I.terms,e);const F=T(I.match,n);F?F.push(u):I.match[n]=[u];}else d.set(l,{score:z,terms:[e],match:{[n]:[u]}});}}return d},jt=(t,e,n)=>{const o={...t._options.searchOptions,...n},s=(o.fields??t._options.fields).reduce((h,l)=>({...h,[l]:T(o.boost,l)||1}),{}),{boostDocument:r,weights:i,maxFuzzy:c,bm25:a}=o,{fuzzy:d,prefix:u}={...it.weights,...i},f=t._index.get(e.term),m=R(t,e.term,e.term,1,e.termBoost,f,s,r,a);let _,g;if(e.prefix&&(_=t._index.atPrefix(e.term)),e.fuzzy){const h=e.fuzzy===true?.2:e.fuzzy,l=h<1?Math.min(c,Math.round(e.term.length*h)):h;l&&(g=t._index.fuzzyGet(e.term,l));}if(_)for(const[h,l]of _){const p=h.length-e.term.length;if(!p)continue;g?.delete(h);const w=u*h.length/(h.length+.3*p);R(t,e.term,h,w,e.termBoost,l,s,r,a,m);}if(g)for(const h of g.keys()){const[l,p]=g.get(h);if(!p)continue;const w=d*h.length/(h.length+p);R(t,e.term,h,w,e.termBoost,l,s,r,a,m);}return m},ct=(t,e,n={})=>{if(e===P)return Dt(t,n);if(typeof e!="string"){const u={...n,...e,queries:void 0},f=e.queries.map(m=>ct(t,m,u));return rt(f,u.combineWith)}const{tokenize:o,processTerm:s,searchOptions:r}=t._options,i={tokenize:o,processTerm:s,...r,...n},{tokenize:c,processTerm:a}=i,d=c(e).flatMap(u=>a(u)).filter(u=>!!u).map(Ct(i)).map(u=>jt(t,u,i));return rt(d,i.combineWith)},ut=(t,e,n={})=>{const{searchOptions:o}=t._options,s={...o,...n},r=ct(t,e,n),i=[];for(const[c,{score:a,terms:d,match:u}]of r){const f=d.length||1,m={id:t._documentIds.get(c),score:a*f,terms:Object.keys(u),queryTerms:d,match:u};Object.assign(m,t._storedFields.get(c)),(s.filter==null||s.filter(m))&&i.push(m);}return e===P&&s.boostDocument==null||i.sort(tt),i};class $t{_options;_index;_documentCount;_documentIds;_idToShortId;_fieldIds;_fieldLength;_avgFieldLength;_nextId;_storedFields;_dirtCount;_currentVacuum;_enqueuedVacuum;_enqueuedVacuumConditions;constructor(e){if(!e?.fields)throw new Error('SlimSearch: option "fields" must be provided');const n=e.autoVacuum==null||e.autoVacuum===true?W:e.autoVacuum;this._options={...q,...e,autoVacuum:n,searchOptions:{...it,...e.searchOptions},autoSuggestOptions:{...Tt,...e.autoSuggestOptions}},this._index=new y,this._documentCount=0,this._documentIds=new Map,this._idToShortId=new Map,this._fieldIds={},this._fieldLength=new Map,this._avgFieldLength=[],this._nextId=0,this._storedFields=new Map,this._dirtCount=0,this._currentVacuum=null,this._enqueuedVacuum=null,this._enqueuedVacuumConditions=N,this.addFields(this._options.fields);}get isVacuuming(){return this._currentVacuum!=null}get dirtCount(){return this._dirtCount}get dirtFactor(){return this._dirtCount/(1+this._documentCount+this._dirtCount)}get documentCount(){return this._documentCount}get termCount(){return this._index.size}toJSON(){const e=[];for(const[n,o]of this._index){const s={};for(const[r,i]of o)s[r]=Object.fromEntries(i);e.push([n,s]);}return {documentCount:this._documentCount,nextId:this._nextId,documentIds:Object.fromEntries(this._documentIds),fieldIds:this._fieldIds,fieldLength:Object.fromEntries(this._fieldLength),averageFieldLength:this._avgFieldLength,storedFields:Object.fromEntries(this._storedFields),dirtCount:this._dirtCount,index:e,version:2}}addFields(e){for(let n=0;n<e.length;n++)this._fieldIds[e[n]]=n;}}const at=t=>new $t(t);
11658
+ const e=e=>e[e.length-1],t$1=`ENTRIES`,n=`KEYS`,r$1=`VALUES`;var i=class{set;_type;_path;constructor(e,t){let n=e._tree,r=[...n.keys()];this.set=e,this._type=t,this._path=r.length>0?[{node:n,keys:r}]:[];}next(){let e=this.dive();return this.backtrack(),e}key(){return this.set._prefix+this._path.map(({keys:t})=>e(t)).filter(e=>e!==``).join(``)}value(){return e(this._path).node.get(``)}[Symbol.iterator](){return this}result(){switch(this._type){case r$1:return this.value();case n:return this.key();case t$1:return [this.key(),this.value()];default:throw Error(`Unknown iterator type: ${this._type}`)}}dive(){if(this._path.length===0)return {done:true,value:void 0};let{node:t,keys:n}=e(this._path);if(e(n)===``)return {done:false,value:this.result()};let r=t.get(e(n));return this._path.push({node:r,keys:[...r.keys()]}),this.dive()}backtrack(){if(this._path.length===0)return;let{keys:t}=e(this._path);t.pop(),!(t.length>0)&&(this._path.pop(),this.backtrack());}};const a$1=(e,t,n,r,i,o,s,c)=>{let l=o*s;key:for(let u of e.keys())if(u===``){let t=i[l-1];t<=n&&r.set(c,[e.get(u),t]);}else {let l=o;for(let e=0;e<u.length;++e,++l){let r=u[e],a=s*l,o=a-s,c=i[a],d=Math.max(0,l-n-1),f=Math.min(s-1,l+n);for(let e=d;e<f;++e){let n=r!==t[e],s=i[o+e]+Number(n),l=i[o+e+1]+1,u=i[a+e]+1,d=i[a+e+1]=Math.min(s,l,u);d<c&&(c=d);}if(c>n)continue key}a$1(e.get(u),t,n,r,i,l,s,c+u);}},o$1=(e,t,n)=>{let r=new Map;if(typeof t!=`string`)return r;let i=t.length+1,o=i+n,s=new Uint8Array(o*i).fill(n+1);for(let e=0;e<i;++e)s[e]=e;for(let e=1;e<o;++e)s[e*i]=e;return a$1(e,t,n,r,s,1,i,``),r},s$1=(e,t,n=[])=>{if(t.length===0||e==null)return [e,n];for(let r of e.keys())if(r!==``&&t.startsWith(r))return n.push([e,r]),s$1(e.get(r),t.slice(r.length),n);return n.push([e,t]),s$1(void 0,``,n)},c$1=(e,t)=>{if(t.length===0||!e)return e;for(let n of e.keys())if(n!==``&&t.startsWith(n))return c$1(e.get(n),t.slice(n.length))},l=(e,t)=>{let n=t.length;outer:for(let r=0;e&&r<n;){for(let i of e.keys())if(i!==``&&t[r]===i[0]){let a=Math.min(n-r,i.length),o=1;for(;o<a&&t[r+o]===i[o];)o+=1;let s=e.get(i);if(o===i.length)e=s;else {let n=new Map([[i.slice(o),s]]);e.set(t.slice(r,r+o),n),e.delete(i),e=n;}r+=o;continue outer}let i=new Map;return e.set(t.slice(r),i),i}return e},u=(t,n,r)=>{if(t.length===0)return;let[i,a]=e(t);i.set(a+n,r),i.delete(a);},d$1=t=>{if(t.length===0)return;let[n,r]=e(t);if(n.delete(r),n.size===0)d$1(t.slice(0,-1));else if(n.size===1){let[e,r]=n.entries().next().value;e!==``&&u(t.slice(0,-1),e,r);}},f$1=(e,t)=>{let[n,r]=s$1(e,t);if(n!==void 0){if(n.delete(``),n.size===0)d$1(r);else if(n.size===1){let[e,t]=n.entries().next().value;u(r,e,t);}}};var p$1=class a{_tree;_prefix;_size=void 0;constructor(e=new Map,t=``){this._tree=e,this._prefix=t;}atPrefix(t){if(!t.startsWith(this._prefix))throw Error(`Mismatched prefix`);let[n,r]=s$1(this._tree,t.slice(this._prefix.length));if(n===void 0){let[n,i]=e(r);for(let e of n.keys())if(e!==``&&e.startsWith(i)){let r=new Map([[e.slice(i.length),n.get(e)]]);return new a(r,t)}}return new a(n,t)}clear(){this._size=void 0,this._tree.clear();}delete(e){this._size=void 0,f$1(this._tree,e);}entries(){return new i(this,t$1)}forEach(e){for(let[t,n]of this)e(t,n,this);}fuzzyGet(e,t){return o$1(this._tree,e,t)}get(e){let t=c$1(this._tree,e);return t===void 0?void 0:t.get(``)}has(e){return c$1(this._tree,e)?.has(``)??false}keys(){return new i(this,n)}set(e,t){if(typeof e!=`string`)throw Error(`key must be a string`);return this._size=void 0,l(this._tree,e).set(``,t),this}get size(){if(typeof this._size==`number`)return this._size;this._size=0;let e=this.entries();for(;!e.next().done;)this._size+=1;return this._size}update(e,t){if(typeof e!=`string`)throw Error(`key must be a string`);this._size=void 0;let n=l(this._tree,e);return n.set(``,t(n.get(``))),this}fetch(e,t){if(typeof e!=`string`)throw Error(`key must be a string`);this._size=void 0;let n=l(this._tree,e),r=n.get(``);return r===void 0&&n.set(``,r=t()),r}values(){return new i(this,r$1)}[Symbol.iterator](){return this.entries()}static from(e){let t=new a;for(let[n,r]of e)t.set(n,r);return t}static fromObject(e){return a.from(Object.entries(e))}};
11659
+
11660
+ const t=(e,t)=>e._idToShortId.has(t),r=/[\n\r\p{Z}\p{P}]+/u,a=(e,t)=>{e.includes(t)||e.push(t);},o=(e,t)=>{for(let n of t)e.includes(n)||e.push(n);},s=({score:e},{score:t})=>t-e,c=()=>new Map,d=(e,t)=>Object.hasOwn(e,t)?e[t]:void 0,f={or:(e,t)=>{for(let n of t.keys()){let r=e.get(n);if(r==null)e.set(n,t.get(n));else {let{score:e,terms:i,match:a}=t.get(n);r.score+=e,r.match=Object.assign(r.match,a),o(r.terms,i);}}return e},and:(e,t)=>{let n=new Map;for(let r of t.keys()){let i=e.get(r);if(i==null)continue;let{score:a,terms:s,match:c}=t.get(r);o(i.terms,s),n.set(r,{score:i.score+a,terms:i.terms,match:Object.assign(i.match,c)});}return n},and_not:(e,t)=>{for(let n of t.keys())e.delete(n);return e}},p=(e,t,n,r,i,a)=>{let{k:o,b:s,d:c}=a;return Math.log(1+(n-t+.5)/(t+.5))*(c+e*(o+1)/(e+o*(1-s+s*r/i)))},m=e=>(t,n,r)=>({term:t,fuzzy:typeof e.fuzzy==`function`?e.fuzzy(t,n,r):e.fuzzy??false,prefix:typeof e.prefix==`function`?e.prefix(t,n,r):e.prefix===true,termBoost:typeof e.boostTerm==`function`?e.boostTerm(t,n,r):1}),h=(e,t,n,r)=>{for(let i of Object.keys(e._fieldIds))if(e._fieldIds[i]===n){e._options.logger(`warn`,`SlimSearch: document with ID ${e._documentIds.get(t)} has changed before removal: term "${r}" was not present in field "${i}". Removing a document after it has changed can corrupt the index!`,`version_conflict`);return}},g=(e,t,n,r)=>{let i=e._index.fetch(r,c),a=i.get(t);if(a==null)a=new Map([[n,1]]),i.set(t,a);else {let e=a.get(n);a.set(n,(e??0)+1);}},_=(e,t,n,r)=>{if(!e._index.has(r)){h(e,n,t,r);return}let i=e._index.fetch(r,c),a=i.get(t),o=a?.get(n);!a||o==null?h(e,n,t,r):o<=1?a.size<=1?i.delete(t):a.delete(n):a.set(n,o-1),e._index.get(r).size===0&&e._index.delete(r);},v=(e,t,n,r,i)=>{let a=e._fieldLength.get(t);a??e._fieldLength.set(t,a=[]),a[n]=i;let o=(e._avgFieldLength[n]||0)*r+i;e._avgFieldLength[n]=o/(r+1);},y=(e,t)=>{let n=e._nextId;return e._idToShortId.set(t,n),e._documentIds.set(n,t),e._documentCount+=1,e._nextId+=1,n},b=(e,t,n)=>{let{storeFields:r,extractField:i}=e._options;if(r?.length===0)return;let a=e._storedFields.get(t);a??e._storedFields.set(t,a={});for(let e of r){let t=i(n,e);t!=null&&(a[e]=t);}},x=(e,n)=>{let{extractField:r,stringifyField:i,tokenize:a,processTerm:o,fields:s,idField:c}=e._options,l=r(n,c);if(l==null)throw Error(`SlimSearch: document does not have ID field "${c}"`);if(t(e,l))throw Error(`SlimSearch: duplicate ID ${l}`);let u=y(e,l);b(e,u,n);for(let t of s){let s=r(n,t);if(s==null)continue;let c=a(i(s,t),t),l=e._fieldIds[t],d=new Set(c).size;v(e,u,l,e._documentCount-1,d);for(let n of c){let r=o(n,t);if(Array.isArray(r))for(let t of r)g(e,l,u,t);else r&&g(e,l,u,r);}}},S=(e,t)=>{for(let n of t)x(e,n);},w={k:1.2,b:.7,d:.5},T={idField:`id`,extractField:(e,t)=>e[t],stringifyField:e=>e.toString(),tokenize:e=>e.split(r),processTerm:e=>e.toLowerCase(),fields:void 0,searchOptions:void 0,storeFields:[],logger:(e,t)=>{console?.[e]?.(t);},autoVacuum:true},E={combineWith:`or`,prefix:false,fuzzy:false,maxFuzzy:6,boost:{},weights:{fuzzy:.45,prefix:.375},bm25:w},D={combineWith:`and`,prefix:(e,t,n)=>t===n.length-1},O={batchSize:1e3,batchWait:10},k={minDirtFactor:.1,minDirtCount:20},A={...O,...k},M=Symbol(`*`),N=(e,t)=>{let n=new Map,r={...e._options.searchOptions,...t};for(let[t,i]of e._documentIds){let a=r.boostDocument?r.boostDocument(i,``,e._storedFields.get(t)):1;n.set(t,{score:a,terms:[],match:{}});}return n},P=(e,t=`or`)=>{if(e.length===0)return new Map;let n=t.toLowerCase();if(!(n in f))throw Error(`Invalid combination operator: ${t}`);return e.reduce(f[n])},F=(e,t,n,r,i,o,s,c,l,u=new Map)=>{if(o==null)return u;for(let f of Object.keys(s)){let m=s[f],h=e._fieldIds[f],g=o.get(h);if(g==null)continue;let v=g.size,y=e._avgFieldLength[h];for(let o of g.keys()){if(!e._documentIds.has(o)){_(e,h,o,n),--v;continue}let s=c?c(e._documentIds.get(o),n,e._storedFields.get(o)):1;if(!s)continue;let b=g.get(o),x=e._fieldLength.get(o)[h],S=p(b,v,e._documentCount,x,y,l),C=r*i*m*s*S,w=u.get(o);if(w){w.score+=C,a(w.terms,t);let e=d(w.match,n);e?e.push(f):w.match[n]=[f];}else u.set(o,{score:C,terms:[t],match:{[n]:[f]}});}}return u},I=(e,t,n)=>{let r={...e._options.searchOptions,...n},i=(r.fields??e._options.fields).reduce((e,t)=>(e[t]=d(r.boost,t)||1,e),{}),{boostDocument:a,weights:o,maxFuzzy:s,bm25:c}=r,{fuzzy:l,prefix:u}={...E.weights,...o},f=e._index.get(t.term),p=F(e,t.term,t.term,1,t.termBoost,f,i,a,c),m,h;if(t.prefix&&(m=e._index.atPrefix(t.term)),t.fuzzy){let n=t.fuzzy===true?.2:t.fuzzy,r=n<1?Math.min(s,Math.round(t.term.length*n)):n;r&&(h=e._index.fuzzyGet(t.term,r));}if(m)for(let[n,r]of m){let o=n.length-t.term.length;if(!o)continue;h?.delete(n);let s=u*n.length/(n.length+.3*o);F(e,t.term,n,s,t.termBoost,r,i,a,c,p);}if(h)for(let n of h.keys()){let[r,o]=h.get(n);if(!o)continue;let s=l*n.length/(n.length+o);F(e,t.term,n,s,t.termBoost,r,i,a,c,p);}return p},L=(e,t,n={})=>{if(t===M)return N(e,n);if(typeof t!=`string`){let r={...n,...t,queries:void 0},i=t.queries.map(t=>L(e,t,r));return P(i,r.combineWith)}let{tokenize:r,processTerm:i,searchOptions:a}=e._options,o={tokenize:r,processTerm:i,...a,...n},{tokenize:s,processTerm:c}=o,l=s(t).flatMap(e=>c(e)).filter(Boolean).map(m(o)).map(t=>I(e,t,o));return P(l,o.combineWith)},R=(e,t,n={})=>{let{searchOptions:r}=e._options,i={...r,...n},a=L(e,t,n),o=[];for(let[t,{score:n,terms:r,match:s}]of a){let a=r.length||1,c={id:e._documentIds.get(t),score:n*a,terms:Object.keys(s),queryTerms:r,match:s,...e._storedFields.get(t)};(i.filter==null||i.filter(c))&&o.push(c);}return t===M&&i.boostDocument==null||o.sort(s),o};var B=class{_options;_index;_documentCount;_documentIds;_idToShortId;_fieldIds;_fieldLength;_avgFieldLength;_nextId;_storedFields;_dirtCount;_currentVacuum;_enqueuedVacuum;_enqueuedVacuumConditions;constructor(t){if(!t?.fields)throw Error(`SlimSearch: option "fields" must be provided`);let n=t.autoVacuum==null||t.autoVacuum===true?A:t.autoVacuum;this._options={...T,...t,autoVacuum:n,searchOptions:{...E,...t.searchOptions},autoSuggestOptions:{...D,...t.autoSuggestOptions}},this._index=new p$1,this._documentCount=0,this._documentIds=new Map,this._idToShortId=new Map,this._fieldIds={},this._fieldLength=new Map,this._avgFieldLength=[],this._nextId=0,this._storedFields=new Map,this._dirtCount=0,this._currentVacuum=null,this._enqueuedVacuum=null,this._enqueuedVacuumConditions=k,this.addFields(this._options.fields);}get isVacuuming(){return this._currentVacuum!=null}get dirtCount(){return this._dirtCount}get dirtFactor(){return this._dirtCount/(1+this._documentCount+this._dirtCount)}get documentCount(){return this._documentCount}get termCount(){return this._index.size}toJSON(){let e=[];for(let[t,n]of this._index){let r={};for(let[e,t]of n)r[e]=Object.fromEntries(t);e.push([t,r]);}return {documentCount:this._documentCount,nextId:this._nextId,documentIds:Object.fromEntries(this._documentIds),fieldIds:this._fieldIds,fieldLength:Object.fromEntries(this._fieldLength),averageFieldLength:this._avgFieldLength,storedFields:Object.fromEntries(this._storedFields),dirtCount:this._dirtCount,index:e,version:2}}addFields(e){for(let t=0;t<e.length;t++)this._fieldIds[e[t]]=t;}};const H=e=>new B(e);
11339
11661
 
11340
11662
  /**
11341
11663
  * Generates a list of accent variants for a given term.
@@ -11377,7 +11699,7 @@ const generateAccentVariants = (term) => {
11377
11699
 
11378
11700
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
11379
11701
  // versions:
11380
- // protoc-gen-ts_proto v2.10.1
11702
+ // protoc-gen-ts_proto v2.18.0
11381
11703
  // protoc v4.23.4
11382
11704
  // source: src/stops/proto/v1/stops.proto
11383
11705
  /* eslint-disable */
@@ -11462,11 +11784,13 @@ const Stop = {
11462
11784
  if (message.lon !== undefined) {
11463
11785
  writer.uint32(37).float(message.lon);
11464
11786
  }
11465
- writer.uint32(42).fork();
11466
- for (const v of message.children) {
11467
- writer.uint32(v);
11787
+ if (message.children.length !== 0) {
11788
+ writer.uint32(42).fork();
11789
+ for (const v of message.children) {
11790
+ writer.uint32(v);
11791
+ }
11792
+ writer.join();
11468
11793
  }
11469
- writer.join();
11470
11794
  if (message.parent !== undefined) {
11471
11795
  writer.uint32(48).uint32(message.parent);
11472
11796
  }
@@ -11479,92 +11803,111 @@ const Stop = {
11479
11803
  return writer;
11480
11804
  },
11481
11805
  decode(input, length) {
11806
+ var _a;
11482
11807
  const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
11483
- const end = length === undefined ? reader.len : reader.pos + length;
11484
- const message = createBaseStop();
11485
- while (reader.pos < end) {
11486
- const tag = reader.uint32();
11487
- switch (tag >>> 3) {
11488
- case 1: {
11489
- if (tag !== 10) {
11490
- break;
11491
- }
11492
- message.name = reader.string();
11493
- continue;
11494
- }
11495
- case 2: {
11496
- if (tag !== 18) {
11497
- break;
11808
+ const previousRecursionDepth = (_a = reader.__tsProtoDecodeDepth) !== null && _a !== void 0 ? _a : 0;
11809
+ if (previousRecursionDepth >= 100) {
11810
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
11811
+ }
11812
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
11813
+ try {
11814
+ const end = length === undefined ? reader.len : reader.pos + length;
11815
+ const message = createBaseStop();
11816
+ while (reader.pos < end) {
11817
+ const tag = reader.uint32();
11818
+ switch (tag >>> 3) {
11819
+ case 1: {
11820
+ if (tag !== 10) {
11821
+ break;
11822
+ }
11823
+ message.name = reader.string();
11824
+ continue;
11498
11825
  }
11499
- message.sourceStopId = reader.string();
11500
- continue;
11501
- }
11502
- case 3: {
11503
- if (tag !== 29) {
11504
- break;
11826
+ case 2: {
11827
+ if (tag !== 18) {
11828
+ break;
11829
+ }
11830
+ message.sourceStopId = reader.string();
11831
+ continue;
11505
11832
  }
11506
- message.lat = reader.float();
11507
- continue;
11508
- }
11509
- case 4: {
11510
- if (tag !== 37) {
11511
- break;
11833
+ case 3: {
11834
+ if (tag !== 29) {
11835
+ break;
11836
+ }
11837
+ message.lat = reader.float();
11838
+ continue;
11512
11839
  }
11513
- message.lon = reader.float();
11514
- continue;
11515
- }
11516
- case 5: {
11517
- if (tag === 40) {
11518
- message.children.push(reader.uint32());
11840
+ case 4: {
11841
+ if (tag !== 37) {
11842
+ break;
11843
+ }
11844
+ message.lon = reader.float();
11519
11845
  continue;
11520
11846
  }
11521
- if (tag === 42) {
11522
- const end2 = reader.uint32() + reader.pos;
11523
- while (reader.pos < end2) {
11847
+ case 5: {
11848
+ if (tag === 40) {
11524
11849
  message.children.push(reader.uint32());
11850
+ continue;
11851
+ }
11852
+ if (tag === 42) {
11853
+ const end2 = reader.uint32() + reader.pos;
11854
+ while (reader.pos < end2) {
11855
+ message.children.push(reader.uint32());
11856
+ }
11857
+ continue;
11525
11858
  }
11859
+ break;
11860
+ }
11861
+ case 6: {
11862
+ if (tag !== 48) {
11863
+ break;
11864
+ }
11865
+ message.parent = reader.uint32();
11526
11866
  continue;
11527
11867
  }
11528
- break;
11529
- }
11530
- case 6: {
11531
- if (tag !== 48) {
11532
- break;
11868
+ case 7: {
11869
+ if (tag !== 56) {
11870
+ break;
11871
+ }
11872
+ message.locationType = reader.int32();
11873
+ continue;
11533
11874
  }
11534
- message.parent = reader.uint32();
11535
- continue;
11536
- }
11537
- case 7: {
11538
- if (tag !== 56) {
11539
- break;
11875
+ case 8: {
11876
+ if (tag !== 66) {
11877
+ break;
11878
+ }
11879
+ message.platform = reader.string();
11880
+ continue;
11540
11881
  }
11541
- message.locationType = reader.int32();
11542
- continue;
11543
11882
  }
11544
- case 8: {
11545
- if (tag !== 66) {
11546
- break;
11547
- }
11548
- message.platform = reader.string();
11549
- continue;
11883
+ if ((tag & 7) === 4 || tag === 0) {
11884
+ break;
11550
11885
  }
11886
+ reader.skip(tag & 7);
11551
11887
  }
11552
- if ((tag & 7) === 4 || tag === 0) {
11553
- break;
11554
- }
11555
- reader.skip(tag & 7);
11888
+ return message;
11889
+ }
11890
+ finally {
11891
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
11556
11892
  }
11557
- return message;
11558
11893
  },
11559
11894
  fromJSON(object) {
11560
11895
  return {
11561
11896
  name: isSet$1(object.name) ? globalThis.String(object.name) : "",
11562
- sourceStopId: isSet$1(object.sourceStopId) ? globalThis.String(object.sourceStopId) : undefined,
11897
+ sourceStopId: isSet$1(object.sourceStopId)
11898
+ ? globalThis.String(object.sourceStopId)
11899
+ : isSet$1(object.source_stop_id)
11900
+ ? globalThis.String(object.source_stop_id)
11901
+ : undefined,
11563
11902
  lat: isSet$1(object.lat) ? globalThis.Number(object.lat) : undefined,
11564
11903
  lon: isSet$1(object.lon) ? globalThis.Number(object.lon) : undefined,
11565
11904
  children: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.children) ? object.children.map((e) => globalThis.Number(e)) : [],
11566
11905
  parent: isSet$1(object.parent) ? globalThis.Number(object.parent) : undefined,
11567
- locationType: isSet$1(object.locationType) ? locationTypeFromJSON(object.locationType) : 0,
11906
+ locationType: isSet$1(object.locationType)
11907
+ ? locationTypeFromJSON(object.locationType)
11908
+ : isSet$1(object.location_type)
11909
+ ? locationTypeFromJSON(object.location_type)
11910
+ : 0,
11568
11911
  platform: isSet$1(object.platform) ? globalThis.String(object.platform) : undefined,
11569
11912
  };
11570
11913
  },
@@ -11578,10 +11921,10 @@ const Stop = {
11578
11921
  obj.sourceStopId = message.sourceStopId;
11579
11922
  }
11580
11923
  if (message.lat !== undefined) {
11581
- obj.lat = message.lat;
11924
+ obj.lat = floatToJson(message.lat);
11582
11925
  }
11583
11926
  if (message.lon !== undefined) {
11584
- obj.lon = message.lon;
11927
+ obj.lon = floatToJson(message.lon);
11585
11928
  }
11586
11929
  if ((_a = message.children) === null || _a === void 0 ? void 0 : _a.length) {
11587
11930
  obj.children = message.children.map((e) => Math.round(e));
@@ -11625,26 +11968,37 @@ const StopsMap = {
11625
11968
  return writer;
11626
11969
  },
11627
11970
  decode(input, length) {
11971
+ var _a;
11628
11972
  const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
11629
- const end = length === undefined ? reader.len : reader.pos + length;
11630
- const message = createBaseStopsMap();
11631
- while (reader.pos < end) {
11632
- const tag = reader.uint32();
11633
- switch (tag >>> 3) {
11634
- case 2: {
11635
- if (tag !== 18) {
11636
- break;
11973
+ const previousRecursionDepth = (_a = reader.__tsProtoDecodeDepth) !== null && _a !== void 0 ? _a : 0;
11974
+ if (previousRecursionDepth >= 100) {
11975
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
11976
+ }
11977
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
11978
+ try {
11979
+ const end = length === undefined ? reader.len : reader.pos + length;
11980
+ const message = createBaseStopsMap();
11981
+ while (reader.pos < end) {
11982
+ const tag = reader.uint32();
11983
+ switch (tag >>> 3) {
11984
+ case 2: {
11985
+ if (tag !== 18) {
11986
+ break;
11987
+ }
11988
+ message.stops.push(Stop.decode(reader, reader.uint32()));
11989
+ continue;
11637
11990
  }
11638
- message.stops.push(Stop.decode(reader, reader.uint32()));
11639
- continue;
11640
11991
  }
11992
+ if ((tag & 7) === 4 || tag === 0) {
11993
+ break;
11994
+ }
11995
+ reader.skip(tag & 7);
11641
11996
  }
11642
- if ((tag & 7) === 4 || tag === 0) {
11643
- break;
11644
- }
11645
- reader.skip(tag & 7);
11997
+ return message;
11998
+ }
11999
+ finally {
12000
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
11646
12001
  }
11647
- return message;
11648
12002
  },
11649
12003
  fromJSON(object) {
11650
12004
  return { stops: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.stops) ? object.stops.map((e) => Stop.fromJSON(e)) : [] };
@@ -11667,6 +12021,9 @@ const StopsMap = {
11667
12021
  return message;
11668
12022
  },
11669
12023
  };
12024
+ function floatToJson(value) {
12025
+ return typeof value === "number" && !globalThis.Number.isFinite(value) ? globalThis.String(value) : value;
12026
+ }
11670
12027
  function isSet$1(value) {
11671
12028
  return value !== null && value !== undefined;
11672
12029
  }
@@ -11772,14 +12129,14 @@ class StopsIndex {
11772
12129
  });
11773
12130
  }
11774
12131
  }
11775
- this.textIndex = at({
12132
+ this.textIndex = H({
11776
12133
  fields: ['name'],
11777
12134
  storeFields: ['id'],
11778
12135
  searchOptions: { prefix: true, fuzzy: 0.2 },
11779
12136
  processTerm: generateAccentVariants,
11780
12137
  });
11781
12138
  const stopsArray = Array.from(stopsSet.values());
11782
- j(this.textIndex, stopsArray);
12139
+ S(this.textIndex, stopsArray);
11783
12140
  this.geoIndex = new KDBush(this.stopPoints.length);
11784
12141
  for (let i = 0; i < this.stopPoints.length; i++) {
11785
12142
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -11826,7 +12183,7 @@ class StopsIndex {
11826
12183
  * @returns An array of Stop objects that match the search query.
11827
12184
  */
11828
12185
  findStopsByName(query, maxResults = 5) {
11829
- const results = ut(this.textIndex, query).map((result) => this.stops[result.id]);
12186
+ const results = R(this.textIndex, query).map((result) => this.stops[result.id]);
11830
12187
  return results.slice(0, maxResults);
11831
12188
  }
11832
12189
  /**
@@ -11895,7 +12252,7 @@ class StopsIndex {
11895
12252
 
11896
12253
  // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
11897
12254
  // versions:
11898
- // protoc-gen-ts_proto v2.10.1
12255
+ // protoc-gen-ts_proto v2.18.0
11899
12256
  // protoc v4.23.4
11900
12257
  // source: src/timetable/proto/v1/timetable.proto
11901
12258
  /* eslint-disable */
@@ -12058,56 +12415,77 @@ const Route$1 = {
12058
12415
  return writer;
12059
12416
  },
12060
12417
  decode(input, length) {
12418
+ var _a;
12061
12419
  const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
12062
- const end = length === undefined ? reader.len : reader.pos + length;
12063
- const message = createBaseRoute();
12064
- while (reader.pos < end) {
12065
- const tag = reader.uint32();
12066
- switch (tag >>> 3) {
12067
- case 1: {
12068
- if (tag !== 10) {
12069
- break;
12420
+ const previousRecursionDepth = (_a = reader.__tsProtoDecodeDepth) !== null && _a !== void 0 ? _a : 0;
12421
+ if (previousRecursionDepth >= 100) {
12422
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
12423
+ }
12424
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
12425
+ try {
12426
+ const end = length === undefined ? reader.len : reader.pos + length;
12427
+ const message = createBaseRoute();
12428
+ while (reader.pos < end) {
12429
+ const tag = reader.uint32();
12430
+ switch (tag >>> 3) {
12431
+ case 1: {
12432
+ if (tag !== 10) {
12433
+ break;
12434
+ }
12435
+ message.stopTimes = reader.bytes();
12436
+ continue;
12070
12437
  }
12071
- message.stopTimes = reader.bytes();
12072
- continue;
12073
- }
12074
- case 2: {
12075
- if (tag !== 18) {
12076
- break;
12438
+ case 2: {
12439
+ if (tag !== 18) {
12440
+ break;
12441
+ }
12442
+ message.pickupDropOffTypes = reader.bytes();
12443
+ continue;
12077
12444
  }
12078
- message.pickupDropOffTypes = reader.bytes();
12079
- continue;
12080
- }
12081
- case 3: {
12082
- if (tag !== 26) {
12083
- break;
12445
+ case 3: {
12446
+ if (tag !== 26) {
12447
+ break;
12448
+ }
12449
+ message.stops = reader.bytes();
12450
+ continue;
12084
12451
  }
12085
- message.stops = reader.bytes();
12086
- continue;
12087
- }
12088
- case 4: {
12089
- if (tag !== 32) {
12090
- break;
12452
+ case 4: {
12453
+ if (tag !== 32) {
12454
+ break;
12455
+ }
12456
+ message.serviceRouteId = reader.uint32();
12457
+ continue;
12091
12458
  }
12092
- message.serviceRouteId = reader.uint32();
12093
- continue;
12094
12459
  }
12460
+ if ((tag & 7) === 4 || tag === 0) {
12461
+ break;
12462
+ }
12463
+ reader.skip(tag & 7);
12095
12464
  }
12096
- if ((tag & 7) === 4 || tag === 0) {
12097
- break;
12098
- }
12099
- reader.skip(tag & 7);
12465
+ return message;
12466
+ }
12467
+ finally {
12468
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
12100
12469
  }
12101
- return message;
12102
12470
  },
12103
12471
  fromJSON(object) {
12104
12472
  return {
12105
- stopTimes: isSet(object.stopTimes) ? bytesFromBase64(object.stopTimes) : new Uint8Array(0),
12473
+ stopTimes: isSet(object.stopTimes)
12474
+ ? bytesFromBase64(object.stopTimes)
12475
+ : isSet(object.stop_times)
12476
+ ? bytesFromBase64(object.stop_times)
12477
+ : new Uint8Array(0),
12106
12478
  pickupDropOffTypes: isSet(object.pickupDropOffTypes)
12107
12479
  ? bytesFromBase64(object.pickupDropOffTypes)
12108
- : new Uint8Array(0),
12480
+ : isSet(object.pickup_drop_off_types)
12481
+ ? bytesFromBase64(object.pickup_drop_off_types)
12482
+ : new Uint8Array(0),
12109
12483
  stops: isSet(object.stops) ? bytesFromBase64(object.stops) : new Uint8Array(0),
12110
- serviceRouteId: isSet(object.serviceRouteId) ? globalThis.Number(object.serviceRouteId) : 0,
12484
+ serviceRouteId: isSet(object.serviceRouteId)
12485
+ ? globalThis.Number(object.serviceRouteId)
12486
+ : isSet(object.service_route_id)
12487
+ ? globalThis.Number(object.service_route_id)
12488
+ : 0,
12111
12489
  };
12112
12490
  },
12113
12491
  toJSON(message) {
@@ -12156,46 +12534,61 @@ const Transfer = {
12156
12534
  return writer;
12157
12535
  },
12158
12536
  decode(input, length) {
12537
+ var _a;
12159
12538
  const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
12160
- const end = length === undefined ? reader.len : reader.pos + length;
12161
- const message = createBaseTransfer();
12162
- while (reader.pos < end) {
12163
- const tag = reader.uint32();
12164
- switch (tag >>> 3) {
12165
- case 1: {
12166
- if (tag !== 8) {
12167
- break;
12539
+ const previousRecursionDepth = (_a = reader.__tsProtoDecodeDepth) !== null && _a !== void 0 ? _a : 0;
12540
+ if (previousRecursionDepth >= 100) {
12541
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
12542
+ }
12543
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
12544
+ try {
12545
+ const end = length === undefined ? reader.len : reader.pos + length;
12546
+ const message = createBaseTransfer();
12547
+ while (reader.pos < end) {
12548
+ const tag = reader.uint32();
12549
+ switch (tag >>> 3) {
12550
+ case 1: {
12551
+ if (tag !== 8) {
12552
+ break;
12553
+ }
12554
+ message.destination = reader.uint32();
12555
+ continue;
12168
12556
  }
12169
- message.destination = reader.uint32();
12170
- continue;
12171
- }
12172
- case 2: {
12173
- if (tag !== 16) {
12174
- break;
12557
+ case 2: {
12558
+ if (tag !== 16) {
12559
+ break;
12560
+ }
12561
+ message.type = reader.int32();
12562
+ continue;
12175
12563
  }
12176
- message.type = reader.int32();
12177
- continue;
12178
- }
12179
- case 3: {
12180
- if (tag !== 24) {
12181
- break;
12564
+ case 3: {
12565
+ if (tag !== 24) {
12566
+ break;
12567
+ }
12568
+ message.minTransferTime = reader.uint32();
12569
+ continue;
12182
12570
  }
12183
- message.minTransferTime = reader.uint32();
12184
- continue;
12185
12571
  }
12572
+ if ((tag & 7) === 4 || tag === 0) {
12573
+ break;
12574
+ }
12575
+ reader.skip(tag & 7);
12186
12576
  }
12187
- if ((tag & 7) === 4 || tag === 0) {
12188
- break;
12189
- }
12190
- reader.skip(tag & 7);
12577
+ return message;
12578
+ }
12579
+ finally {
12580
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
12191
12581
  }
12192
- return message;
12193
12582
  },
12194
12583
  fromJSON(object) {
12195
12584
  return {
12196
12585
  destination: isSet(object.destination) ? globalThis.Number(object.destination) : 0,
12197
12586
  type: isSet(object.type) ? transferTypeFromJSON(object.type) : 0,
12198
- minTransferTime: isSet(object.minTransferTime) ? globalThis.Number(object.minTransferTime) : undefined,
12587
+ minTransferTime: isSet(object.minTransferTime)
12588
+ ? globalThis.Number(object.minTransferTime)
12589
+ : isSet(object.min_transfer_time)
12590
+ ? globalThis.Number(object.min_transfer_time)
12591
+ : undefined,
12199
12592
  };
12200
12593
  },
12201
12594
  toJSON(message) {
@@ -12240,46 +12633,69 @@ const TripStop = {
12240
12633
  return writer;
12241
12634
  },
12242
12635
  decode(input, length) {
12636
+ var _a;
12243
12637
  const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
12244
- const end = length === undefined ? reader.len : reader.pos + length;
12245
- const message = createBaseTripStop();
12246
- while (reader.pos < end) {
12247
- const tag = reader.uint32();
12248
- switch (tag >>> 3) {
12249
- case 1: {
12250
- if (tag !== 8) {
12251
- break;
12638
+ const previousRecursionDepth = (_a = reader.__tsProtoDecodeDepth) !== null && _a !== void 0 ? _a : 0;
12639
+ if (previousRecursionDepth >= 100) {
12640
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
12641
+ }
12642
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
12643
+ try {
12644
+ const end = length === undefined ? reader.len : reader.pos + length;
12645
+ const message = createBaseTripStop();
12646
+ while (reader.pos < end) {
12647
+ const tag = reader.uint32();
12648
+ switch (tag >>> 3) {
12649
+ case 1: {
12650
+ if (tag !== 8) {
12651
+ break;
12652
+ }
12653
+ message.stopIndex = reader.uint32();
12654
+ continue;
12252
12655
  }
12253
- message.stopIndex = reader.uint32();
12254
- continue;
12255
- }
12256
- case 2: {
12257
- if (tag !== 16) {
12258
- break;
12656
+ case 2: {
12657
+ if (tag !== 16) {
12658
+ break;
12659
+ }
12660
+ message.routeId = reader.uint32();
12661
+ continue;
12259
12662
  }
12260
- message.routeId = reader.uint32();
12261
- continue;
12262
- }
12263
- case 3: {
12264
- if (tag !== 24) {
12265
- break;
12663
+ case 3: {
12664
+ if (tag !== 24) {
12665
+ break;
12666
+ }
12667
+ message.tripIndex = reader.uint32();
12668
+ continue;
12266
12669
  }
12267
- message.tripIndex = reader.uint32();
12268
- continue;
12269
12670
  }
12671
+ if ((tag & 7) === 4 || tag === 0) {
12672
+ break;
12673
+ }
12674
+ reader.skip(tag & 7);
12270
12675
  }
12271
- if ((tag & 7) === 4 || tag === 0) {
12272
- break;
12273
- }
12274
- reader.skip(tag & 7);
12676
+ return message;
12677
+ }
12678
+ finally {
12679
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
12275
12680
  }
12276
- return message;
12277
12681
  },
12278
12682
  fromJSON(object) {
12279
12683
  return {
12280
- stopIndex: isSet(object.stopIndex) ? globalThis.Number(object.stopIndex) : 0,
12281
- routeId: isSet(object.routeId) ? globalThis.Number(object.routeId) : 0,
12282
- tripIndex: isSet(object.tripIndex) ? globalThis.Number(object.tripIndex) : 0,
12684
+ stopIndex: isSet(object.stopIndex)
12685
+ ? globalThis.Number(object.stopIndex)
12686
+ : isSet(object.stop_index)
12687
+ ? globalThis.Number(object.stop_index)
12688
+ : 0,
12689
+ routeId: isSet(object.routeId)
12690
+ ? globalThis.Number(object.routeId)
12691
+ : isSet(object.route_id)
12692
+ ? globalThis.Number(object.route_id)
12693
+ : 0,
12694
+ tripIndex: isSet(object.tripIndex)
12695
+ ? globalThis.Number(object.tripIndex)
12696
+ : isSet(object.trip_index)
12697
+ ? globalThis.Number(object.trip_index)
12698
+ : 0,
12283
12699
  };
12284
12700
  },
12285
12701
  toJSON(message) {
@@ -12321,33 +12737,44 @@ const TripTransferEntry = {
12321
12737
  return writer;
12322
12738
  },
12323
12739
  decode(input, length) {
12740
+ var _a;
12324
12741
  const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
12325
- const end = length === undefined ? reader.len : reader.pos + length;
12326
- const message = createBaseTripTransferEntry();
12327
- while (reader.pos < end) {
12328
- const tag = reader.uint32();
12329
- switch (tag >>> 3) {
12330
- case 1: {
12331
- if (tag !== 10) {
12332
- break;
12742
+ const previousRecursionDepth = (_a = reader.__tsProtoDecodeDepth) !== null && _a !== void 0 ? _a : 0;
12743
+ if (previousRecursionDepth >= 100) {
12744
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
12745
+ }
12746
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
12747
+ try {
12748
+ const end = length === undefined ? reader.len : reader.pos + length;
12749
+ const message = createBaseTripTransferEntry();
12750
+ while (reader.pos < end) {
12751
+ const tag = reader.uint32();
12752
+ switch (tag >>> 3) {
12753
+ case 1: {
12754
+ if (tag !== 10) {
12755
+ break;
12756
+ }
12757
+ message.origin = TripStop.decode(reader, reader.uint32());
12758
+ continue;
12333
12759
  }
12334
- message.origin = TripStop.decode(reader, reader.uint32());
12335
- continue;
12336
- }
12337
- case 2: {
12338
- if (tag !== 18) {
12339
- break;
12760
+ case 2: {
12761
+ if (tag !== 18) {
12762
+ break;
12763
+ }
12764
+ message.destinations.push(TripStop.decode(reader, reader.uint32()));
12765
+ continue;
12340
12766
  }
12341
- message.destinations.push(TripStop.decode(reader, reader.uint32()));
12342
- continue;
12343
12767
  }
12768
+ if ((tag & 7) === 4 || tag === 0) {
12769
+ break;
12770
+ }
12771
+ reader.skip(tag & 7);
12344
12772
  }
12345
- if ((tag & 7) === 4 || tag === 0) {
12346
- break;
12347
- }
12348
- reader.skip(tag & 7);
12773
+ return message;
12774
+ }
12775
+ finally {
12776
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
12349
12777
  }
12350
- return message;
12351
12778
  },
12352
12779
  fromJSON(object) {
12353
12780
  return {
@@ -12386,51 +12813,64 @@ function createBaseStopAdjacency() {
12386
12813
  }
12387
12814
  const StopAdjacency = {
12388
12815
  encode(message, writer = new BinaryWriter()) {
12389
- writer.uint32(10).fork();
12390
- for (const v of message.routes) {
12391
- writer.uint32(v);
12816
+ if (message.routes.length !== 0) {
12817
+ writer.uint32(10).fork();
12818
+ for (const v of message.routes) {
12819
+ writer.uint32(v);
12820
+ }
12821
+ writer.join();
12392
12822
  }
12393
- writer.join();
12394
12823
  for (const v of message.transfers) {
12395
12824
  Transfer.encode(v, writer.uint32(18).fork()).join();
12396
12825
  }
12397
12826
  return writer;
12398
12827
  },
12399
12828
  decode(input, length) {
12829
+ var _a;
12400
12830
  const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
12401
- const end = length === undefined ? reader.len : reader.pos + length;
12402
- const message = createBaseStopAdjacency();
12403
- while (reader.pos < end) {
12404
- const tag = reader.uint32();
12405
- switch (tag >>> 3) {
12406
- case 1: {
12407
- if (tag === 8) {
12408
- message.routes.push(reader.uint32());
12409
- continue;
12410
- }
12411
- if (tag === 10) {
12412
- const end2 = reader.uint32() + reader.pos;
12413
- while (reader.pos < end2) {
12831
+ const previousRecursionDepth = (_a = reader.__tsProtoDecodeDepth) !== null && _a !== void 0 ? _a : 0;
12832
+ if (previousRecursionDepth >= 100) {
12833
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
12834
+ }
12835
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
12836
+ try {
12837
+ const end = length === undefined ? reader.len : reader.pos + length;
12838
+ const message = createBaseStopAdjacency();
12839
+ while (reader.pos < end) {
12840
+ const tag = reader.uint32();
12841
+ switch (tag >>> 3) {
12842
+ case 1: {
12843
+ if (tag === 8) {
12414
12844
  message.routes.push(reader.uint32());
12845
+ continue;
12846
+ }
12847
+ if (tag === 10) {
12848
+ const end2 = reader.uint32() + reader.pos;
12849
+ while (reader.pos < end2) {
12850
+ message.routes.push(reader.uint32());
12851
+ }
12852
+ continue;
12415
12853
  }
12854
+ break;
12855
+ }
12856
+ case 2: {
12857
+ if (tag !== 18) {
12858
+ break;
12859
+ }
12860
+ message.transfers.push(Transfer.decode(reader, reader.uint32()));
12416
12861
  continue;
12417
12862
  }
12418
- break;
12419
12863
  }
12420
- case 2: {
12421
- if (tag !== 18) {
12422
- break;
12423
- }
12424
- message.transfers.push(Transfer.decode(reader, reader.uint32()));
12425
- continue;
12864
+ if ((tag & 7) === 4 || tag === 0) {
12865
+ break;
12426
12866
  }
12867
+ reader.skip(tag & 7);
12427
12868
  }
12428
- if ((tag & 7) === 4 || tag === 0) {
12429
- break;
12430
- }
12431
- reader.skip(tag & 7);
12869
+ return message;
12870
+ }
12871
+ finally {
12872
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
12432
12873
  }
12433
- return message;
12434
12874
  },
12435
12875
  fromJSON(object) {
12436
12876
  return {
@@ -12473,55 +12913,68 @@ const ServiceRoute = {
12473
12913
  if (message.name !== "") {
12474
12914
  writer.uint32(18).string(message.name);
12475
12915
  }
12476
- writer.uint32(26).fork();
12477
- for (const v of message.routes) {
12478
- writer.uint32(v);
12916
+ if (message.routes.length !== 0) {
12917
+ writer.uint32(26).fork();
12918
+ for (const v of message.routes) {
12919
+ writer.uint32(v);
12920
+ }
12921
+ writer.join();
12479
12922
  }
12480
- writer.join();
12481
12923
  return writer;
12482
12924
  },
12483
12925
  decode(input, length) {
12926
+ var _a;
12484
12927
  const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
12485
- const end = length === undefined ? reader.len : reader.pos + length;
12486
- const message = createBaseServiceRoute();
12487
- while (reader.pos < end) {
12488
- const tag = reader.uint32();
12489
- switch (tag >>> 3) {
12490
- case 1: {
12491
- if (tag !== 8) {
12492
- break;
12493
- }
12494
- message.type = reader.int32();
12495
- continue;
12496
- }
12497
- case 2: {
12498
- if (tag !== 18) {
12499
- break;
12928
+ const previousRecursionDepth = (_a = reader.__tsProtoDecodeDepth) !== null && _a !== void 0 ? _a : 0;
12929
+ if (previousRecursionDepth >= 100) {
12930
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
12931
+ }
12932
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
12933
+ try {
12934
+ const end = length === undefined ? reader.len : reader.pos + length;
12935
+ const message = createBaseServiceRoute();
12936
+ while (reader.pos < end) {
12937
+ const tag = reader.uint32();
12938
+ switch (tag >>> 3) {
12939
+ case 1: {
12940
+ if (tag !== 8) {
12941
+ break;
12942
+ }
12943
+ message.type = reader.int32();
12944
+ continue;
12500
12945
  }
12501
- message.name = reader.string();
12502
- continue;
12503
- }
12504
- case 3: {
12505
- if (tag === 24) {
12506
- message.routes.push(reader.uint32());
12946
+ case 2: {
12947
+ if (tag !== 18) {
12948
+ break;
12949
+ }
12950
+ message.name = reader.string();
12507
12951
  continue;
12508
12952
  }
12509
- if (tag === 26) {
12510
- const end2 = reader.uint32() + reader.pos;
12511
- while (reader.pos < end2) {
12953
+ case 3: {
12954
+ if (tag === 24) {
12512
12955
  message.routes.push(reader.uint32());
12956
+ continue;
12513
12957
  }
12514
- continue;
12958
+ if (tag === 26) {
12959
+ const end2 = reader.uint32() + reader.pos;
12960
+ while (reader.pos < end2) {
12961
+ message.routes.push(reader.uint32());
12962
+ }
12963
+ continue;
12964
+ }
12965
+ break;
12515
12966
  }
12967
+ }
12968
+ if ((tag & 7) === 4 || tag === 0) {
12516
12969
  break;
12517
12970
  }
12971
+ reader.skip(tag & 7);
12518
12972
  }
12519
- if ((tag & 7) === 4 || tag === 0) {
12520
- break;
12521
- }
12522
- reader.skip(tag & 7);
12973
+ return message;
12974
+ }
12975
+ finally {
12976
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
12523
12977
  }
12524
- return message;
12525
12978
  },
12526
12979
  fromJSON(object) {
12527
12980
  return {
@@ -12585,72 +13038,93 @@ const Timetable$1 = {
12585
13038
  return writer;
12586
13039
  },
12587
13040
  decode(input, length) {
13041
+ var _a;
12588
13042
  const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
12589
- const end = length === undefined ? reader.len : reader.pos + length;
12590
- const message = createBaseTimetable();
12591
- while (reader.pos < end) {
12592
- const tag = reader.uint32();
12593
- switch (tag >>> 3) {
12594
- case 1: {
12595
- if (tag !== 10) {
12596
- break;
13043
+ const previousRecursionDepth = (_a = reader.__tsProtoDecodeDepth) !== null && _a !== void 0 ? _a : 0;
13044
+ if (previousRecursionDepth >= 100) {
13045
+ throw new globalThis.Error("protobuf decode recursion limit exceeded");
13046
+ }
13047
+ reader.__tsProtoDecodeDepth = previousRecursionDepth + 1;
13048
+ try {
13049
+ const end = length === undefined ? reader.len : reader.pos + length;
13050
+ const message = createBaseTimetable();
13051
+ while (reader.pos < end) {
13052
+ const tag = reader.uint32();
13053
+ switch (tag >>> 3) {
13054
+ case 1: {
13055
+ if (tag !== 10) {
13056
+ break;
13057
+ }
13058
+ message.stopsAdjacency.push(StopAdjacency.decode(reader, reader.uint32()));
13059
+ continue;
12597
13060
  }
12598
- message.stopsAdjacency.push(StopAdjacency.decode(reader, reader.uint32()));
12599
- continue;
12600
- }
12601
- case 2: {
12602
- if (tag !== 18) {
12603
- break;
13061
+ case 2: {
13062
+ if (tag !== 18) {
13063
+ break;
13064
+ }
13065
+ message.routesAdjacency.push(Route$1.decode(reader, reader.uint32()));
13066
+ continue;
12604
13067
  }
12605
- message.routesAdjacency.push(Route$1.decode(reader, reader.uint32()));
12606
- continue;
12607
- }
12608
- case 3: {
12609
- if (tag !== 26) {
12610
- break;
13068
+ case 3: {
13069
+ if (tag !== 26) {
13070
+ break;
13071
+ }
13072
+ message.serviceRoutes.push(ServiceRoute.decode(reader, reader.uint32()));
13073
+ continue;
12611
13074
  }
12612
- message.serviceRoutes.push(ServiceRoute.decode(reader, reader.uint32()));
12613
- continue;
12614
- }
12615
- case 4: {
12616
- if (tag !== 34) {
12617
- break;
13075
+ case 4: {
13076
+ if (tag !== 34) {
13077
+ break;
13078
+ }
13079
+ message.tripContinuations.push(TripTransferEntry.decode(reader, reader.uint32()));
13080
+ continue;
12618
13081
  }
12619
- message.tripContinuations.push(TripTransferEntry.decode(reader, reader.uint32()));
12620
- continue;
12621
- }
12622
- case 5: {
12623
- if (tag !== 42) {
12624
- break;
13082
+ case 5: {
13083
+ if (tag !== 42) {
13084
+ break;
13085
+ }
13086
+ message.guaranteedTripTransfers.push(TripTransferEntry.decode(reader, reader.uint32()));
13087
+ continue;
12625
13088
  }
12626
- message.guaranteedTripTransfers.push(TripTransferEntry.decode(reader, reader.uint32()));
12627
- continue;
12628
13089
  }
13090
+ if ((tag & 7) === 4 || tag === 0) {
13091
+ break;
13092
+ }
13093
+ reader.skip(tag & 7);
12629
13094
  }
12630
- if ((tag & 7) === 4 || tag === 0) {
12631
- break;
12632
- }
12633
- reader.skip(tag & 7);
13095
+ return message;
13096
+ }
13097
+ finally {
13098
+ reader.__tsProtoDecodeDepth = previousRecursionDepth;
12634
13099
  }
12635
- return message;
12636
13100
  },
12637
13101
  fromJSON(object) {
12638
13102
  return {
12639
13103
  stopsAdjacency: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.stopsAdjacency)
12640
13104
  ? object.stopsAdjacency.map((e) => StopAdjacency.fromJSON(e))
12641
- : [],
13105
+ : globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.stops_adjacency)
13106
+ ? object.stops_adjacency.map((e) => StopAdjacency.fromJSON(e))
13107
+ : [],
12642
13108
  routesAdjacency: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.routesAdjacency)
12643
13109
  ? object.routesAdjacency.map((e) => Route$1.fromJSON(e))
12644
- : [],
13110
+ : globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.routes_adjacency)
13111
+ ? object.routes_adjacency.map((e) => Route$1.fromJSON(e))
13112
+ : [],
12645
13113
  serviceRoutes: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.serviceRoutes)
12646
13114
  ? object.serviceRoutes.map((e) => ServiceRoute.fromJSON(e))
12647
- : [],
13115
+ : globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.service_routes)
13116
+ ? object.service_routes.map((e) => ServiceRoute.fromJSON(e))
13117
+ : [],
12648
13118
  tripContinuations: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.tripContinuations)
12649
13119
  ? object.tripContinuations.map((e) => TripTransferEntry.fromJSON(e))
12650
- : [],
13120
+ : globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.trip_continuations)
13121
+ ? object.trip_continuations.map((e) => TripTransferEntry.fromJSON(e))
13122
+ : [],
12651
13123
  guaranteedTripTransfers: globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.guaranteedTripTransfers)
12652
13124
  ? object.guaranteedTripTransfers.map((e) => TripTransferEntry.fromJSON(e))
12653
- : [],
13125
+ : globalThis.Array.isArray(object === null || object === void 0 ? void 0 : object.guaranteed_trip_transfers)
13126
+ ? object.guaranteed_trip_transfers.map((e) => TripTransferEntry.fromJSON(e))
13127
+ : [],
12654
13128
  };
12655
13129
  },
12656
13130
  toJSON(message) {
@@ -13717,8 +14191,8 @@ const normalize_columns_array = function (columns) {
13717
14191
  const column = columns[i];
13718
14192
  if (column === undefined || column === null || column === false) {
13719
14193
  normalizedColumns[i] = { disabled: true };
13720
- } else if (typeof column === "string") {
13721
- normalizedColumns[i] = { name: column };
14194
+ } else if (typeof column === "string" || typeof column === "number") {
14195
+ normalizedColumns[i] = { name: `${column}` };
13722
14196
  } else if (is_object(column)) {
13723
14197
  if (typeof column.name !== "string") {
13724
14198
  throw new CsvError("CSV_OPTION_COLUMNS_MISSING_NAME", [
@@ -13788,7 +14262,7 @@ class ResizeableBuffer {
13788
14262
  }
13789
14263
  toString(encoding) {
13790
14264
  if (encoding) {
13791
- return this.buf.slice(0, this.length).toString(encoding);
14265
+ return this.buf.toString(encoding, 0, this.length);
13792
14266
  } else {
13793
14267
  return Uint8Array.prototype.slice.call(this.buf.slice(0, this.length));
13794
14268
  }
@@ -13801,22 +14275,67 @@ class ResizeableBuffer {
13801
14275
  }
13802
14276
  }
13803
14277
 
13804
- // white space characters
13805
- // https://en.wikipedia.org/wiki/Whitespace_character
13806
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Character_Classes#Types
13807
- // \f\n\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff
13808
- const np = 12;
13809
- const cr$1 = 13; // `\r`, carriage return, 0x0D in hexadécimal, 13 in decimal
13810
- const nl$1 = 10; // `\n`, newline, 0x0A in hexadecimal, 10 in decimal
13811
- const space = 32;
13812
- const tab = 9;
13813
-
13814
14278
  const init_state = function (options) {
14279
+ // ECMAScript WhiteSpace + LineTerminator codepoints, encoded under
14280
+ // `options.encoding`. Aligns trimming with `String.prototype.trim()`.
14281
+ // https://tc39.es/ecma262/#sec-white-space
14282
+ // https://tc39.es/ecma262/#sec-line-terminators
14283
+ //
14284
+ // Codepoints unrepresentable in the target encoding are dropped: Node's
14285
+ // Buffer substitutes them with `?` (0x3F), and including those would cause
14286
+ // literal `?` bytes in the input to be trimmed under `latin1`/`ascii`.
14287
+ const timchars = [
14288
+ // Basic Latin
14289
+ 0x0020, // [Space](https://www.fileformat.info/info/unicode/char/0020/index.htm)
14290
+ 0x0009, // [CHARACTER TABULATION (HT)](https://www.fileformat.info/info/unicode/char/0009/index.htm)
14291
+ 0x000a, // [LINE FEED (LF)](https://www.fileformat.info/info/unicode/char/000a/index.htm)
14292
+ 0x000d, // [CARRIAGE RETURN (CR)](https://www.fileformat.info/info/unicode/char/000d/index.htm)
14293
+ 0x000c, // [FORM FEED (FF)](https://www.fileformat.info/info/unicode/char/000c/index.htm)
14294
+ 0x000b, // [LINE TABULATION (VT)](https://www.fileformat.info/info/unicode/char/000b/index.htm)
14295
+ // Latin-1 Supplement
14296
+ 0x00a0, // [NO-BREAK SPACE (NBSP)](https://www.fileformat.info/info/unicode/char/00a0/index.htm)
14297
+ // Ogham
14298
+ 0x1680, // [OGHAM SPACE MARK](https://www.fileformat.info/info/unicode/char/1680/index.htm)
14299
+ // General Punctuation
14300
+ 0x2000, // [EN QUAD](https://www.fileformat.info/info/unicode/char/2000/index.htm)
14301
+ 0x2001, // [EM QUAD](https://www.fileformat.info/info/unicode/char/2001/index.htm)
14302
+ 0x2002, // [EN SPACE](https://www.fileformat.info/info/unicode/char/2002/index.htm)
14303
+ 0x2003, // [EM SPACE](https://www.fileformat.info/info/unicode/char/2003/index.htm)
14304
+ 0x2004, // [THREE-PER-EM SPACE](https://www.fileformat.info/info/unicode/char/2004/index.htm)
14305
+ 0x2005, // [FOUR-PER-EM SPACE](https://www.fileformat.info/info/unicode/char/2005/index.htm)
14306
+ 0x2006, // [SIX-PER-EM SPACE](https://www.fileformat.info/info/unicode/char/2006/index.htm)
14307
+ 0x2007, // [FIGURE SPACE](https://www.fileformat.info/info/unicode/char/2007/index.htm)
14308
+ 0x2008, // [PUNCTUATION SPACE](https://www.fileformat.info/info/unicode/char/2008/index.htm)
14309
+ 0x2009, // [THIN SPACE](https://www.fileformat.info/info/unicode/char/2009/index.htm)
14310
+ 0x200a, // [HAIR SPACE](https://www.fileformat.info/info/unicode/char/200a/index.htm)
14311
+ 0x2028, // [LINE SEPARATOR](https://www.fileformat.info/info/unicode/char/2028/index.htm)
14312
+ 0x2029, // [PARAGRAPH SEPARATOR](https://www.fileformat.info/info/unicode/char/2029/index.htm)
14313
+ 0x202f, // [NARROW NO-BREAK SPACE (NNBSP)](https://www.fileformat.info/info/unicode/char/202f/index.htm)
14314
+ 0x205f, // [MEDIUM MATHEMATICAL SPACE (MMSP)](https://www.fileformat.info/info/unicode/char/205f/index.htm)
14315
+ 0x3000, // [IDEOGRAPHIC SPACE](https://www.fileformat.info/info/unicode/char/3000/index.htm)
14316
+ 0xfeff, // [ZERO WIDTH NO-BREAK SPACE (BOM)](https://www.fileformat.info/info/unicode/char/feff/index.htm)
14317
+ ].reduce((acc, codepoint) => {
14318
+ const encoded = Buffer.from(
14319
+ String.fromCharCode(codepoint),
14320
+ options.encoding,
14321
+ );
14322
+ if (codepoint !== 0x3f && encoded.length === 1 && encoded[0] === 0x3f) {
14323
+ return acc;
14324
+ }
14325
+ acc.push(encoded);
14326
+ return acc;
14327
+ }, []);
14328
+ // First-byte lookup table for `__isCharTrimable`. Non-whitespace bytes
14329
+ // (the common case) bail out in O(1) without scanning every timchar.
14330
+ const timcharFirstBytes = new Uint8Array(256);
14331
+ for (const t of timchars) timcharFirstBytes[t[0]] = 1;
13815
14332
  return {
13816
14333
  bomSkipped: false,
13817
14334
  bufBytesStart: 0,
13818
14335
  castField: options.cast_function,
13819
14336
  commenting: false,
14337
+ delimiterBufPrevious: undefined,
14338
+ delimiterDiscovered: false,
13820
14339
  // Current error encountered by a record
13821
14340
  error: undefined,
13822
14341
  enabled: options.from_line === 1,
@@ -13835,9 +14354,15 @@ const init_state = function (options) {
13835
14354
  // Skip if the remaining buffer smaller than comment
13836
14355
  options.comment !== null ? options.comment.length : 0,
13837
14356
  // Skip if the remaining buffer can be delimiter
13838
- ...options.delimiter.map((delimiter) => delimiter.length),
14357
+ ...(options.delimiter
14358
+ ? options.delimiter.map((delimiter) => delimiter.length)
14359
+ : []),
14360
+ // Auto discovery of delimiter is limited to 1 character
14361
+ options.delimiter_auto ? 1 : 0,
13839
14362
  // Skip if the remaining buffer can be escape sequence
13840
14363
  options.quote !== null ? options.quote.length : 0,
14364
+ // Skip if the remaining buffer can be a multi-byte trim character
14365
+ ...timchars.map((t) => t.length),
13841
14366
  ),
13842
14367
  previousBuf: undefined,
13843
14368
  quoting: false,
@@ -13856,13 +14381,8 @@ const init_state = function (options) {
13856
14381
  ],
13857
14382
  wasQuoting: false,
13858
14383
  wasRowDelimiter: false,
13859
- timchars: [
13860
- Buffer.from(Buffer.from([cr$1], "utf8").toString(), options.encoding),
13861
- Buffer.from(Buffer.from([nl$1], "utf8").toString(), options.encoding),
13862
- Buffer.from(Buffer.from([np], "utf8").toString(), options.encoding),
13863
- Buffer.from(Buffer.from([space], "utf8").toString(), options.encoding),
13864
- Buffer.from(Buffer.from([tab], "utf8").toString(), options.encoding),
13865
- ],
14384
+ timchars: timchars,
14385
+ timcharFirstBytes: timcharFirstBytes,
13866
14386
  };
13867
14387
  };
13868
14388
 
@@ -14060,25 +14580,95 @@ const normalize_options = function (opts) {
14060
14580
  options,
14061
14581
  );
14062
14582
  }
14063
- // Normalize option `delimiter`
14064
- const delimiter_json = JSON.stringify(options.delimiter);
14065
- if (!Array.isArray(options.delimiter))
14066
- options.delimiter = [options.delimiter];
14067
- if (options.delimiter.length === 0) {
14583
+ // Normalize option `delimiter_auto`
14584
+ if (
14585
+ options.delimiter_auto === undefined ||
14586
+ options.delimiter_auto === null ||
14587
+ options.delimiter_auto === false
14588
+ ) {
14589
+ options.delimiter_auto = false;
14590
+ } else if (options.delimiter_auto === true) {
14591
+ options.delimiter_auto = {};
14592
+ } else if (!is_object(options.delimiter_auto)) {
14068
14593
  throw new CsvError(
14069
- "CSV_INVALID_OPTION_DELIMITER",
14594
+ "CSV_INVALID_OPTION_DELIMITER_AUTO",
14070
14595
  [
14071
- "Invalid option delimiter:",
14072
- "delimiter must be a non empty string or buffer or array of string|buffer,",
14073
- `got ${delimiter_json}`,
14596
+ "Invalid option delimiter_auto:",
14597
+ "delimiter_auto must be a boolean or a configuration object,",
14598
+ `got ${JSON.stringify(options.delimiter_auto)}`,
14074
14599
  ],
14075
14600
  options,
14076
14601
  );
14077
14602
  }
14078
- options.delimiter = options.delimiter.map(function (delimiter) {
14079
- if (delimiter === undefined || delimiter === null || delimiter === false) {
14080
- return Buffer.from(",", options.encoding);
14603
+ if (options.delimiter_auto) {
14604
+ if (options.delimiter_auto.preferred === undefined)
14605
+ options.delimiter_auto.preferred = {
14606
+ [",".charCodeAt(0)]: 1.8,
14607
+ ["\t".charCodeAt(0)]: 1.8,
14608
+ [";".charCodeAt(0)]: 1.6,
14609
+ [" ".charCodeAt(0)]: 1.6,
14610
+ [":".charCodeAt(0)]: 1.5,
14611
+ [".".charCodeAt(0)]: 1.4,
14612
+ ["/".charCodeAt(0)]: 1.4,
14613
+ };
14614
+ else if (!is_object(options.delimiter_auto.preferred)) {
14615
+ throw new CsvError(
14616
+ "CSV_INVALID_OPTION_DELIMITER_AUTO",
14617
+ [
14618
+ "Invalid option delimiter_auto:",
14619
+ "preferred must be an object,",
14620
+ `got ${JSON.stringify(options.delimiter_auto.preferred)}`,
14621
+ ],
14622
+ options,
14623
+ );
14624
+ }
14625
+ if (options.delimiter_auto.score === undefined)
14626
+ options.delimiter_auto.score = (info, options) => {
14627
+ return (
14628
+ (info.total - info.std) * (options.preferred[info.char_code] || 1)
14629
+ );
14630
+ };
14631
+ else if (typeof options.delimiter_auto.score !== "function") {
14632
+ throw new CsvError(
14633
+ "CSV_INVALID_OPTION_DELIMITER_AUTO",
14634
+ [
14635
+ "Invalid option delimiter_auto:",
14636
+ "score must be a function,",
14637
+ `got ${JSON.stringify(options.delimiter_auto.score)}`,
14638
+ ],
14639
+ options,
14640
+ );
14641
+ }
14642
+ if (options.delimiter_auto.size === undefined)
14643
+ options.delimiter_auto.size = 2048;
14644
+ else if (typeof options.delimiter_auto.size !== "number") {
14645
+ throw new CsvError(
14646
+ "CSV_INVALID_OPTION_DELIMITER_AUTO",
14647
+ [
14648
+ "Invalid option delimiter_auto:",
14649
+ "size must be a number,",
14650
+ `got ${JSON.stringify(options.delimiter_auto.size)}`,
14651
+ ],
14652
+ options,
14653
+ );
14654
+ }
14655
+ }
14656
+ // Normalize option `delimiter`
14657
+ const delimiter_json = JSON.stringify(options.delimiter);
14658
+ if (options.delimiter_auto !== false) {
14659
+ options.delimiter = [];
14660
+ }
14661
+ if (!Array.isArray(options.delimiter)) {
14662
+ if (
14663
+ options.delimiter === undefined ||
14664
+ options.delimiter === null ||
14665
+ options.delimiter === false
14666
+ ) {
14667
+ options.delimiter = Buffer.from(",", options.encoding);
14081
14668
  }
14669
+ options.delimiter = [options.delimiter];
14670
+ }
14671
+ options.delimiter = options.delimiter.map(function (delimiter) {
14082
14672
  if (typeof delimiter === "string") {
14083
14673
  delimiter = Buffer.from(delimiter, options.encoding);
14084
14674
  }
@@ -14535,6 +15125,67 @@ const normalize_options = function (opts) {
14535
15125
  return options;
14536
15126
  };
14537
15127
 
15128
+ // Discussed in [issue #400](https://github.com/adaltas/node-csv/issues/400)
15129
+ // See https://github.com/python/cpython/blob/ea1b1c579f600cc85d145c60862b2e6b98701b24/Lib/csv.py#L349
15130
+ const delimiter_discover = function (records, options) {
15131
+ // Normalize the configuration
15132
+ if (!options) {
15133
+ ({ delimiter_auto: options } = normalize_options({ delimiter_auto: true }));
15134
+ }
15135
+ // Convert String to Buffer
15136
+ if (typeof records === "string") {
15137
+ records = Buffer.from(records);
15138
+ }
15139
+ // Convert Buffer to an array of records
15140
+ if (Buffer.isBuffer(records)) {
15141
+ records = ((data) => {
15142
+ const records = [];
15143
+ const parser = transform({ delimiter: [] });
15144
+ const push = (record) => records.push(record);
15145
+ const close = () => {};
15146
+ const error = parser.parse(data, true, push, close);
15147
+ if (error !== undefined) throw error;
15148
+ return records;
15149
+ })(records);
15150
+ }
15151
+ // Info array initialization, 127 entries, one per char code
15152
+ const info = Array(127)
15153
+ .fill()
15154
+ .map(() => ({ lines: [] }));
15155
+ // Traverse each records, count occurences per char code
15156
+ records.map(([record], line) => {
15157
+ for (let i = 0, l = record.length; i < l; i++) {
15158
+ // Count the character frequency
15159
+ const code = record.charCodeAt(i);
15160
+ if (info[code].lines[line] === undefined) info[code].lines[line] = 0;
15161
+ info[code].lines[line]++;
15162
+ }
15163
+ });
15164
+ // Traverse each char code, compute the score
15165
+ info.map((info, i) => {
15166
+ info.char_code = i;
15167
+ info.std = std(info.lines);
15168
+ info.total = info.lines.reduce((acc, val) => acc + val, 0);
15169
+ info.preferred = !!options.preferred[i];
15170
+ info.score = options.score(info, options);
15171
+ });
15172
+ // Extract the dominant character
15173
+ const result = info.reduce(
15174
+ (acc, info) => (acc.score > info.score ? acc : info),
15175
+ {},
15176
+ );
15177
+ return String.fromCharCode(result.char_code);
15178
+ };
15179
+
15180
+ const std = function (array) {
15181
+ const n = array.length;
15182
+ if (n === 0) return 0;
15183
+ const mean = array.reduce((a, b) => a + b) / n;
15184
+ return Math.sqrt(
15185
+ array.map((x) => Math.pow(x - mean, 2)).reduce((a, b) => a + b) / n,
15186
+ );
15187
+ };
15188
+
14538
15189
  const isRecordEmpty = function (record) {
14539
15190
  return record.every(
14540
15191
  (field) =>
@@ -14560,6 +15211,7 @@ const boms = {
14560
15211
  const transform = function (original_options = {}) {
14561
15212
  const info = {
14562
15213
  bytes: 0,
15214
+ bytes_records: 0,
14563
15215
  comment_lines: 0,
14564
15216
  empty_lines: 0,
14565
15217
  invalid_field_length: 0,
@@ -14601,6 +15253,7 @@ const transform = function (original_options = {}) {
14601
15253
  const {
14602
15254
  bom,
14603
15255
  comment_no_infix,
15256
+ delimiter_auto,
14604
15257
  encoding,
14605
15258
  from_line,
14606
15259
  ltrim,
@@ -14613,7 +15266,45 @@ const transform = function (original_options = {}) {
14613
15266
  to_line,
14614
15267
  } = this.options;
14615
15268
  let { comment, escape, quote, record_delimiter } = this.options;
14616
- const { bomSkipped, previousBuf, rawBuffer, escapeIsQuote } = this.state;
15269
+ const {
15270
+ bomSkipped,
15271
+ delimiterDiscovered,
15272
+ delimiterBufPrevious,
15273
+ rawBuffer,
15274
+ escapeIsQuote,
15275
+ } = this.state;
15276
+ // Automatic delimiter discovery
15277
+ if (!delimiterDiscovered && delimiter_auto) {
15278
+ let delimiterBuf;
15279
+ if (delimiterBufPrevious === undefined) {
15280
+ delimiterBuf = nextBuf;
15281
+ } else if (
15282
+ delimiterBufPrevious !== undefined &&
15283
+ nextBuf === undefined
15284
+ ) {
15285
+ delimiterBuf = delimiterBufPrevious;
15286
+ } else {
15287
+ delimiterBuf = Buffer.concat([delimiterBufPrevious, nextBuf]);
15288
+ }
15289
+ // Ensure that nextBuf is not concatenated a second time during buffer reconciliation
15290
+ nextBuf = undefined;
15291
+ // this.delimiterBufPrevious = delimiterBuf;
15292
+ if (end || delimiterBuf.length > delimiter_auto.size) {
15293
+ this.options.delimiter = [
15294
+ Buffer.from(
15295
+ delimiter_discover(delimiterBuf, this.options.delimiter_auto),
15296
+ ),
15297
+ ];
15298
+ this.state.previousBuf = delimiterBuf;
15299
+ this.state.delimiterBufPrevious = undefined;
15300
+ this.state.delimiterDiscovered = true;
15301
+ } else {
15302
+ this.state.delimiterBufPrevious = delimiterBuf;
15303
+ return;
15304
+ }
15305
+ }
15306
+ // Previous buffers reconciliation
15307
+ const { previousBuf } = this.state;
14617
15308
  let buf;
14618
15309
  if (previousBuf === undefined) {
14619
15310
  if (nextBuf === undefined) {
@@ -14837,7 +15528,7 @@ const transform = function (original_options = {}) {
14837
15528
  this.info.comment_lines++;
14838
15529
  // Skip full comment line
14839
15530
  } else {
14840
- // Activate records emition if above from_line
15531
+ // Activate records emission if above from_line
14841
15532
  if (
14842
15533
  this.state.enabled === false &&
14843
15534
  this.info.lines +
@@ -15088,7 +15779,7 @@ const transform = function (original_options = {}) {
15088
15779
  // Turn duplicate columns into an array
15089
15780
  if (
15090
15781
  group_columns_by_name === true &&
15091
- obj[columns[i].name] !== undefined
15782
+ Object.hasOwn(obj, columns[i].name)
15092
15783
  ) {
15093
15784
  if (Array.isArray(obj[columns[i].name])) {
15094
15785
  obj[columns[i].name] = obj[columns[i].name].concat(record[i]);
@@ -15096,7 +15787,12 @@ const transform = function (original_options = {}) {
15096
15787
  obj[columns[i].name] = [obj[columns[i].name], record[i]];
15097
15788
  }
15098
15789
  } else {
15099
- obj[columns[i].name] = record[i];
15790
+ Object.defineProperty(obj, columns[i].name, {
15791
+ value: record[i],
15792
+ enumerable: true,
15793
+ writable: true,
15794
+ configurable: true,
15795
+ });
15100
15796
  }
15101
15797
  }
15102
15798
  // Without objname (default)
@@ -15235,6 +15931,7 @@ const transform = function (original_options = {}) {
15235
15931
  return;
15236
15932
  }
15237
15933
  }
15934
+ this.info.bytes_records += this.info.bytes;
15238
15935
  push(record);
15239
15936
  },
15240
15937
  // Return a tuple with the error and the casted value
@@ -15267,30 +15964,6 @@ const transform = function (original_options = {}) {
15267
15964
  }
15268
15965
  return [undefined, field];
15269
15966
  },
15270
- // Helper to test if a character is a space or a line delimiter
15271
- __isCharTrimable: function (buf, pos) {
15272
- const isTrim = (buf, pos) => {
15273
- const { timchars } = this.state;
15274
- loop1: for (let i = 0; i < timchars.length; i++) {
15275
- const timchar = timchars[i];
15276
- for (let j = 0; j < timchar.length; j++) {
15277
- if (timchar[j] !== buf[pos + j]) continue loop1;
15278
- }
15279
- return timchar.length;
15280
- }
15281
- return 0;
15282
- };
15283
- return isTrim(buf, pos);
15284
- },
15285
- // Keep it in case we implement the `cast_int` option
15286
- // __isInt(value){
15287
- // // return Number.isInteger(parseInt(value))
15288
- // // return !isNaN( parseInt( obj ) );
15289
- // return /^(\-|\+)?[1-9][0-9]*$/.test(value)
15290
- // }
15291
- __isFloat: function (value) {
15292
- return value - parseFloat(value) + 1 >= 0; // Borrowed from jquery
15293
- },
15294
15967
  __compareBytes: function (sourceBuf, targetBuf, targetPos, firstByte) {
15295
15968
  if (sourceBuf[0] !== firstByte) return 0;
15296
15969
  const sourceLength = sourceBuf.length;
@@ -15299,6 +15972,22 @@ const transform = function (original_options = {}) {
15299
15972
  }
15300
15973
  return sourceLength;
15301
15974
  },
15975
+ // Helper to test if a character is trimable
15976
+ __isCharTrimable: function (buf, pos) {
15977
+ const { timchars, timcharFirstBytes } = this.state;
15978
+ // Fast bail-out: non-whitespace bytes (the common case) are rejected
15979
+ // without scanning the full timchar list.
15980
+ const first = buf[pos];
15981
+ if (first === undefined || timcharFirstBytes[first] === 0) return 0;
15982
+ loop1: for (let i = 0; i < timchars.length; i++) {
15983
+ const timchar = timchars[i];
15984
+ for (let j = 0; j < timchar.length; j++) {
15985
+ if (timchar[j] !== buf[pos + j]) continue loop1;
15986
+ }
15987
+ return timchar.length;
15988
+ }
15989
+ return 0;
15990
+ },
15302
15991
  __isDelimiter: function (buf, pos, chr) {
15303
15992
  const { delimiter, ignore_last_delimiters } = this.options;
15304
15993
  if (
@@ -15324,24 +16013,6 @@ const transform = function (original_options = {}) {
15324
16013
  }
15325
16014
  return 0;
15326
16015
  },
15327
- __isRecordDelimiter: function (chr, buf, pos) {
15328
- const { record_delimiter } = this.options;
15329
- const recordDelimiterLength = record_delimiter.length;
15330
- loop1: for (let i = 0; i < recordDelimiterLength; i++) {
15331
- const rd = record_delimiter[i];
15332
- const rdLength = rd.length;
15333
- if (rd[0] !== chr) {
15334
- continue;
15335
- }
15336
- for (let j = 1; j < rdLength; j++) {
15337
- if (rd[j] !== buf[pos + j]) {
15338
- continue loop1;
15339
- }
15340
- }
15341
- return rd.length;
15342
- }
15343
- return 0;
15344
- },
15345
16016
  __isEscape: function (buf, pos, chr) {
15346
16017
  const { escape } = this.options;
15347
16018
  if (escape === null) return false;
@@ -15356,6 +16027,15 @@ const transform = function (original_options = {}) {
15356
16027
  }
15357
16028
  return false;
15358
16029
  },
16030
+ __isFloat: function (value) {
16031
+ return value - parseFloat(value) + 1 >= 0; // Borrowed from jquery
16032
+ },
16033
+ // Keep it in case we implement the `cast_int` option
16034
+ // __isInt(value){
16035
+ // // return Number.isInteger(parseInt(value))
16036
+ // // return !isNaN( parseInt( obj ) );
16037
+ // return /^(\-|\+)?[1-9][0-9]*$/.test(value)
16038
+ // }
15359
16039
  __isQuote: function (buf, pos) {
15360
16040
  const { quote } = this.options;
15361
16041
  if (quote === null) return false;
@@ -15367,6 +16047,24 @@ const transform = function (original_options = {}) {
15367
16047
  }
15368
16048
  return true;
15369
16049
  },
16050
+ __isRecordDelimiter: function (chr, buf, pos) {
16051
+ const { record_delimiter } = this.options;
16052
+ const recordDelimiterLength = record_delimiter.length;
16053
+ loop1: for (let i = 0; i < recordDelimiterLength; i++) {
16054
+ const rd = record_delimiter[i];
16055
+ const rdLength = rd.length;
16056
+ if (rd[0] !== chr) {
16057
+ continue;
16058
+ }
16059
+ for (let j = 1; j < rdLength; j++) {
16060
+ if (rd[j] !== buf[pos + j]) {
16061
+ continue loop1;
16062
+ }
16063
+ }
16064
+ return rd.length;
16065
+ }
16066
+ return 0;
16067
+ },
15370
16068
  __autoDiscoverRecordDelimiter: function (buf, pos) {
15371
16069
  const { encoding } = this.options;
15372
16070
  // Note, we don't need to cache this information in state,
@@ -15422,6 +16120,7 @@ const transform = function (original_options = {}) {
15422
16120
  const { columns, raw, encoding } = this.options;
15423
16121
  return {
15424
16122
  ...this.__infoDataSet(),
16123
+ bytes_records: this.info.bytes,
15425
16124
  error: this.state.error,
15426
16125
  header: columns === true,
15427
16126
  index: this.state.record.length,
@@ -15431,8 +16130,11 @@ const transform = function (original_options = {}) {
15431
16130
  __infoField: function () {
15432
16131
  const { columns } = this.options;
15433
16132
  const isColumns = Array.isArray(columns);
16133
+ // Bytes records are only incremented when all records'fields are parsed
16134
+ const bytes_records = this.info.bytes_records;
15434
16135
  return {
15435
16136
  ...this.__infoRecord(),
16137
+ bytes_records: bytes_records,
15436
16138
  column:
15437
16139
  isColumns === true
15438
16140
  ? columns.length > this.state.record.length
@@ -15543,14 +16245,21 @@ const parse = function () {
15543
16245
  const parser = new Parser(options);
15544
16246
  if (callback) {
15545
16247
  const records =
15546
- options === undefined || options.objname === undefined ? [] : {};
16248
+ options === undefined || options.objname === undefined
16249
+ ? []
16250
+ : Object.create(null);
15547
16251
  parser.on("readable", function () {
15548
16252
  let record;
15549
16253
  while ((record = this.read()) !== null) {
15550
16254
  if (options === undefined || options.objname === undefined) {
15551
16255
  records.push(record);
15552
16256
  } else {
15553
- records[record[0]] = record[1];
16257
+ Object.assign(records, {
16258
+ [record[0]]: record[1],
16259
+ // writable: true,
16260
+ // enumerable: true,
16261
+ // configurable: true
16262
+ });
15554
16263
  }
15555
16264
  }
15556
16265
  });
@@ -15566,7 +16275,7 @@ const parse = function () {
15566
16275
  parser.write(data);
15567
16276
  parser.end();
15568
16277
  };
15569
- // Support Deno, Rollup doesnt provide a shim for setImmediate
16278
+ // Support Deno, Rollup doesn't provide a shim for setImmediate
15570
16279
  if (typeof setImmediate === "function") {
15571
16280
  setImmediate(writer);
15572
16281
  } else {