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