nish 0.35.0 → 0.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/docs/AI.md +9 -2
  2. package/docs/INSTALL.md +6 -1
  3. package/package.json +15 -5
  4. package/runtime/nish.d.ts +4612 -430
  5. package/runtime/vite.d.ts +30 -0
  6. package/runtime/vite.mjs +150 -0
  7. package/scripts/build.sh +108 -13
  8. package/std/base64.ts +34 -5
  9. package/std/bytes.ts +256 -40
  10. package/std/cli-args.ts +296 -70
  11. package/std/cli-flags.ts +184 -19
  12. package/std/cli.ts +475 -54
  13. package/std/collections.ts +121 -23
  14. package/std/compress/checksum.ts +44 -14
  15. package/std/compress/deflate.ts +224 -111
  16. package/std/compress/gzip.ts +217 -53
  17. package/std/compress/zlib.ts +63 -7
  18. package/std/crypto/aes.ts +80 -9
  19. package/std/crypto/base64url.ts +22 -0
  20. package/std/crypto/bcrypt-batch.ts +88 -21
  21. package/std/crypto/bcrypt.ts +60 -0
  22. package/std/crypto/chacha20poly1305.ts +53 -0
  23. package/std/crypto/ct.ts +32 -13
  24. package/std/crypto/ed25519.ts +47 -0
  25. package/std/crypto/hkdf.ts +198 -13
  26. package/std/crypto/hmac.ts +235 -31
  27. package/std/crypto/jwt.ts +192 -63
  28. package/std/crypto/p256.ts +159 -16
  29. package/std/crypto/p384.ts +28 -3
  30. package/std/crypto/pki-roots.ts +32 -2
  31. package/std/crypto/pki.ts +81 -15
  32. package/std/crypto/rsa.ts +33 -3
  33. package/std/crypto/sha1.ts +3 -0
  34. package/std/crypto/sha256.ts +24 -1
  35. package/std/crypto/sha512.ts +99 -14
  36. package/std/crypto/x25519.ts +152 -14
  37. package/std/crypto/x509-random.ts +10 -0
  38. package/std/crypto/x509.ts +67 -7
  39. package/std/json-equal.ts +19 -0
  40. package/std/json-format.ts +112 -13
  41. package/std/json-number.ts +64 -14
  42. package/std/json-pointer.ts +23 -1
  43. package/std/json-tokenizer.ts +100 -29
  44. package/std/json-typed.ts +713 -66
  45. package/std/json-value.ts +400 -124
  46. package/std/json.ts +138 -10
  47. package/std/map.ts +25 -7
  48. package/std/math.ts +36 -4
  49. package/std/net/buffer-pool.ts +42 -11
  50. package/std/net/dns-config.ts +109 -23
  51. package/std/net/dns-message.ts +62 -7
  52. package/std/net/dns-resolver.ts +247 -53
  53. package/std/net/dns.ts +203 -35
  54. package/std/net/fetch.ts +151 -61
  55. package/std/net/handler.ts +278 -80
  56. package/std/net/hpack.ts +262 -52
  57. package/std/net/http-compress.ts +125 -15
  58. package/std/net/http-fields.ts +85 -9
  59. package/std/net/http1-client-codec.ts +100 -19
  60. package/std/net/http1-codec.ts +235 -27
  61. package/std/net/http1-server.ts +343 -85
  62. package/std/net/http2-frame.ts +272 -35
  63. package/std/net/http2-tls.ts +135 -34
  64. package/std/net/http2.ts +247 -106
  65. package/std/net/http3-frame.ts +154 -17
  66. package/std/net/http3-server.ts +246 -96
  67. package/std/net/http3.ts +307 -115
  68. package/std/net/outbound.ts +37 -3
  69. package/std/net/postgres-carrier.ts +144 -8
  70. package/std/net/postgres.ts +723 -103
  71. package/std/net/prefork.ts +164 -31
  72. package/std/net/qpack.ts +105 -18
  73. package/std/net/quic-conn-ack.ts +59 -12
  74. package/std/net/quic-conn-cid.ts +124 -27
  75. package/std/net/quic-conn-params.ts +70 -10
  76. package/std/net/quic-datagram.ts +43 -3
  77. package/std/net/quic-frame.ts +286 -12
  78. package/std/net/quic-listener.ts +101 -32
  79. package/std/net/quic-packet.ts +302 -21
  80. package/std/net/quic-recovery.ts +228 -44
  81. package/std/net/quic-stream.ts +353 -91
  82. package/std/net/quic.ts +489 -171
  83. package/std/net/router.ts +87 -40
  84. package/std/net/tls/client.ts +166 -51
  85. package/std/net/tls/codec.ts +413 -56
  86. package/std/net/tls/record-client.ts +110 -55
  87. package/std/net/tls/record-server.ts +159 -59
  88. package/std/net/tls/record.ts +109 -12
  89. package/std/net/tls/schedule.ts +235 -26
  90. package/std/net/tls/ticket.ts +159 -40
  91. package/std/net/tls/verify.ts +49 -3
  92. package/std/net/tls-tcp.ts +250 -45
  93. package/std/net/tls.ts +221 -59
  94. package/std/net/upstream.ts +81 -45
  95. package/std/net/url.ts +97 -13
  96. package/std/net/websocket.ts +122 -12
  97. package/std/net/webtransport.ts +220 -89
  98. package/std/pair.ts +10 -2
  99. package/std/random.ts +34 -9
  100. package/std/regex.ts +352 -198
  101. package/std/region.ts +70 -15
  102. package/std/secret.ts +52 -11
  103. package/std/sort.ts +17 -2
  104. package/std/sqlite.ts +256 -35
  105. package/std/sync/ring.ts +205 -35
  106. package/std/sync/shm.ts +194 -16
  107. package/std/term-io.ts +137 -64
  108. package/std/term-pixels.ts +144 -19
  109. package/std/term-probe.ts +66 -25
  110. package/std/term-rate.ts +128 -57
  111. package/std/term.ts +332 -121
  112. package/std/testing.ts +130 -32
  113. package/std/text.ts +73 -7
  114. package/std/threads.ts +229 -41
  115. package/std/yaml-json.ts +94 -82
  116. package/std/yaml-lines.ts +47 -15
  117. package/std/yaml-write.ts +24 -16
  118. package/std/yaml.ts +764 -384
package/std/term-rate.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * `std/term-rate` — how fast the link to the terminal is, measured from frames
2
+ * `nish/term-rate` — how fast the link to the terminal is, measured from frames
3
3
  * sent and acknowledged, and the frame rate and drawing detail a program keeps
4
4
  * to under it.
5
5
  *
@@ -10,6 +10,17 @@
10
10
  * (`RateDecision`). Every time is an `f64` count of milliseconds on the
11
11
  * caller's clock, as `FixedStep`'s is in `nish/term`.
12
12
  *
13
+ * import { RateController, RateOptions } from "nish/term-rate"
14
+ *
15
+ * const rate = new RateController(new RateOptions())
16
+ * // each turn of the loop, at nowMs:
17
+ * rate.tick(nowMs)
18
+ * if (rate.mayDraw(nowMs)) {
19
+ * // draw as rate.decision() says, then write the frame and `CSI 5 n`
20
+ * rate.frameSent(bytes, costNs, nowMs)
21
+ * }
22
+ * // for each `CSI 0 n` read back: rate.ackReceived(nowMs)
23
+ *
13
24
  * **The acknowledgement.** A frame is acknowledged when the terminal answers a
14
25
  * status query sent right after it: the terminal answers in order, so the
15
26
  * answer means every byte before it has been read and drawn. The query to send
@@ -325,84 +336,113 @@ export class TermStats {
325
336
  */
326
337
  export class RateController {
327
338
  /** The tiers allowed, fastest first, ending at 5. */
328
- tiers: i32[]
329
- /** Paces frames at `tier`. */
339
+ private tiers: i32[]
340
+ /**
341
+ * Paces frames at `tier`.
342
+ * @internal Used by `termIoWait` in term-io.ts.
343
+ */
330
344
  pacer: FixedStep
331
345
  /** When the tier or step last changed. */
332
- changedMs: f64
346
+ private changedMs: f64
333
347
  /** When the loads went over budget and stayed, or -1. */
334
- overSinceMs: f64
348
+ private overSinceMs: f64
335
349
  /** When the next step up came within its margin and stayed, or -1. */
336
- underSinceMs: f64
350
+ private underSinceMs: f64
337
351
  /** The send times of the unacknowledged frames, oldest at `head`. */
338
352
  sentMs: f64[]
339
353
  /** Their byte counts. */
340
- sentBytes: i32[]
354
+ private sentBytes: i32[]
341
355
  /** When the last acknowledgement arrived, or -1. */
342
- lastAckMs: f64
343
- /** The smoothed round trip, in milliseconds. */
356
+ private lastAckMs: f64
357
+ /**
358
+ * The smoothed round trip, in milliseconds.
359
+ * @internal Used by `Terminal` in term-io.ts.
360
+ */
344
361
  rttMs: f64
345
- /** The link's latency without bytes: the least, over the kept trips, of the round trip less the bytes' time. */
362
+ /**
363
+ * The link's latency without bytes: the least, over the kept trips, of the round trip less the bytes' time.
364
+ */
346
365
  baseRttMs: f64
347
366
  /** The latency as last worked out while the bandwidth was known, held once its samples age out. */
348
- heldLatencyMs: f64
349
- /** The round trips of the probe and of the latest frames sent onto an idle link, `rateTripCount` at most. */
367
+ private heldLatencyMs: f64
368
+ /**
369
+ * The round trips of the probe and of the latest frames sent onto an idle link, `rateTripCount` at most.
370
+ */
350
371
  tripMs: f64[]
351
372
  /** Their byte counts, 0 for the probe. */
352
- tripBytes: f64[]
373
+ private tripBytes: f64[]
353
374
  /** The bytes a second each of the latest answers proves at least, its bytes over its round trip. */
354
- floorPerSec: f64[]
375
+ private floorPerSec: f64[]
355
376
  /** The smoothed bytes of an answered frame, for the bandwidth. */
356
- ackBytes: f64
377
+ private ackBytes: f64
357
378
  /** The smoothed time the link spent on an answered frame, in milliseconds, for the bandwidth. */
358
- ackBusyMs: f64
379
+ private ackBusyMs: f64
359
380
  /**
360
381
  * The bytes a second delivered: `ackBytes` over `ackBusyMs`, at least the most of `floorPerSec`, which alone is a lower
361
382
  * bound. Samples older than `rateFreshMs` still count here while trips agree with them, but no decision uses them.
362
383
  */
363
384
  bytesPerSec: f64
364
385
  /** When the bandwidth was last sampled, by a frame that waited behind another or by two trips. */
365
- rateAtMs: f64
386
+ private rateAtMs: f64
366
387
  /** The quickest kept trip, or the round trip with none kept, when the bandwidth was last sampled: at least the latency then. */
367
- rateQuickMs: f64
388
+ private rateQuickMs: f64
368
389
  /** When frames were last given up on, while `stale` waits for their late answers. */
369
- staleSinceMs: f64
390
+ private staleSinceMs: f64
370
391
  /** The smoothed frame cost, in milliseconds. */
371
- costMs: f64
392
+ private costMs: f64
372
393
  /** The smoothed bytes per frame. */
373
- frameBytes: f64
374
- current: RateDecision
375
- measured: TermStats
376
- /** The least tier detail is cut to keep: the floor tier under `RATE_FIRST`, 5 under `DETAIL_FIRST`. */
394
+ private frameBytes: f64
395
+ private current: RateDecision
396
+ private measured: TermStats
397
+ /**
398
+ * The least tier detail is cut to keep: the floor tier under `RATE_FIRST`, 5 under `DETAIL_FIRST`.
399
+ */
377
400
  floorFps: i32
378
- /** The least tier above which `RATE_FIRST` keeps full detail. */
401
+ /**
402
+ * The least tier above which `RATE_FIRST` keeps full detail.
403
+ * @internal Nothing reads it.
404
+ */
379
405
  minTier: i32
406
+ /**
407
+ * What gives way first, `RATE_FIRST` or `DETAIL_FIRST`, from the options.
408
+ */
380
409
  prefer: i32
410
+ /**
411
+ * How many frames may await their acknowledgement at once: 1 or 2.
412
+ */
381
413
  maxUnacked: i32
382
- /** The fixed frame rate, or 0 when the controller chooses. */
414
+ /**
415
+ * The fixed frame rate, or 0 when the controller chooses.
416
+ * @internal Used by `Terminal` in term-io.ts.
417
+ */
383
418
  fixedFps: i32
384
419
  /** The frame rate in force. */
385
- tier: i32
420
+ private tier: i32
386
421
  /** The detail step in force, 0 (full detail) to `rateMaxLevel`. */
387
- level: i32
422
+ private level: i32
388
423
  /** The oldest unacknowledged frame's index in `sentMs`. */
389
- head: i32
390
- dropped: i32
391
- lost: i32
392
- /** Frames given up on whose answers may still come: the next answers are theirs, and no frame is drawn meanwhile. */
424
+ private head: i32
425
+ private dropped: i32
426
+ private lost: i32
427
+ /**
428
+ * Frames given up on whose answers may still come: the next answers are theirs, and no frame is drawn meanwhile.
429
+ * @internal Used by `Terminal` in term-io.ts.
430
+ */
393
431
  stale: i32
394
432
  /** Where the next trip goes in `tripMs` once it is full. */
395
- tripNext: i32
433
+ private tripNext: i32
396
434
  /** How many trips in a row have contradicted the aged bandwidth sample. */
397
- contradicted: i32
435
+ private contradicted: i32
398
436
  /** Where the next goes in `floorPerSec` once it is full. */
399
- floorNext: i32
437
+ private floorNext: i32
400
438
  /** Whether a frame has been asked for, so the pacer's clock runs. */
401
- paced: boolean
402
- /** Whether a round trip, from the probe or an answer, is known. */
439
+ private paced: boolean
440
+ /**
441
+ * Whether a round trip, from the probe or an answer, is known.
442
+ */
403
443
  haveRtt: boolean
404
444
  /** Whether a frame has been acknowledged, so decisions can start. */
405
- haveAck: boolean
445
+ private haveAck: boolean
406
446
  /**
407
447
  * Whether the bandwidth is known, so decisions may use it: sampled by a
408
448
  * frame that waited behind another or two trips of different sizes, within
@@ -411,9 +451,13 @@ export class RateController {
411
451
  */
412
452
  haveRate: boolean
413
453
  /** Whether a frame has been sent, so cost and size are known. */
414
- haveFrame: boolean
454
+ private haveFrame: boolean
415
455
 
416
- /** A controller for `options`, read once. */
456
+ /**
457
+ * A controller for `options`, read once.
458
+ *
459
+ * @param options The rate limits, preference and hints to run with; changing it later changes nothing.
460
+ */
417
461
  constructor(options: RateOptions) {
418
462
  this.prefer = options.prefer === DETAIL_FIRST ? DETAIL_FIRST : RATE_FIRST
419
463
  this.maxUnacked = options.maxUnacked >= 2 ? 2 : 1
@@ -497,7 +541,11 @@ export class RateController {
497
541
  this.publish()
498
542
  }
499
543
 
500
- /** Frames sent and not yet acknowledged. */
544
+ /**
545
+ * Frames sent and not yet acknowledged.
546
+ *
547
+ * @returns How many frames await their acknowledgement, from 0.
548
+ */
501
549
  unacked(): i32 {
502
550
  return toI32(this.sentMs.length) - this.head
503
551
  }
@@ -509,6 +557,9 @@ export class RateController {
509
557
  * limit, or while the answers to frames given up on may still come, is
510
558
  * counted as dropped, and the next waits for the next step. A time that is
511
559
  * not a finite number is refused.
560
+ *
561
+ * @param nowMs The time now, in milliseconds on the clock every call uses.
562
+ * @returns True when the program should draw and send a frame now.
512
563
  */
513
564
  mayDraw(nowMs: f64): boolean {
514
565
  if (!rateFinite(nowMs)) {
@@ -536,6 +587,10 @@ export class RateController {
536
587
  * sent at `nowMs`. A call whose time is not a finite number is ignored; a
537
588
  * cost that is not a finite number or is negative is not measured, and
538
589
  * negative bytes count as none.
590
+ *
591
+ * @param bytes The frame's size in bytes as written.
592
+ * @param costNs How long the frame took to build, in nanoseconds.
593
+ * @param nowMs When it was sent, in milliseconds on the clock every call uses.
539
594
  */
540
595
  frameSent(bytes: i32, costNs: f64, nowMs: f64): void {
541
596
  if (!rateFinite(nowMs)) {
@@ -571,6 +626,8 @@ export class RateController {
571
626
  * since the terminal answers in order. One with no frame waiting (a stray
572
627
  * answer) is ignored, and one whose time is not a finite number answers its
573
628
  * frame and measures nothing.
629
+ *
630
+ * @param nowMs When the acknowledgement was read, in milliseconds on the clock every call uses.
574
631
  */
575
632
  ackReceived(nowMs: f64): void {
576
633
  if (this.stale > 0) {
@@ -641,7 +698,7 @@ export class RateController {
641
698
  * one size measure nothing here, so small frames cannot drag the bandwidth
642
699
  * down to their round trip.
643
700
  */
644
- measureTrip(rtt: f64, bytes: f64): void {
701
+ private measureTrip(rtt: f64, bytes: f64): void {
645
702
  let quickest: i32 = -1
646
703
  for (let i: i32 = 0; i < toI32(this.tripMs.length); i++) {
647
704
  if (quickest < 0 || this.tripMs[i] < this.tripMs[quickest]) {
@@ -670,7 +727,7 @@ export class RateController {
670
727
  }
671
728
 
672
729
  /** The link spent `busyMs` on `bytes`: one sample of the bandwidth. */
673
- measureRate(bytes: f64, busyMs: f64): void {
730
+ private measureRate(bytes: f64, busyMs: f64): void {
674
731
  // A sample after the last aged out starts afresh, so a link that narrowed meanwhile is not averaged with its old rate.
675
732
  const first: boolean = this.ackBusyMs <= 0.0 || !this.haveRate
676
733
  this.rateAtMs = this.lastAckMs
@@ -694,7 +751,7 @@ export class RateController {
694
751
  * bytes over its whole round trip count the latency as bytes' time, and on
695
752
  * a far link that reads the bandwidth several times too low.
696
753
  */
697
- updateRate(): void {
754
+ private updateRate(): void {
698
755
  let rate: f64 = this.ackBusyMs > 0.0 ? (this.ackBytes * 1000.0) / this.ackBusyMs : 0.0
699
756
  this.haveRate = rate > 0.0 && this.lastAckMs - this.rateAtMs <= rateFreshMs
700
757
  for (let i: i32 = 0; i < toI32(this.floorPerSec.length); i++) {
@@ -709,7 +766,7 @@ export class RateController {
709
766
  * Stop deciding on the bandwidth once no sample is newer than `rateFreshMs`
710
767
  * at `nowMs`. The figure stays in `bytesPerSec` until a sample replaces it or a trip contradicts it.
711
768
  */
712
- ageRate(nowMs: f64): void {
769
+ private ageRate(nowMs: f64): void {
713
770
  if (this.haveRate && nowMs - this.rateAtMs > rateFreshMs) {
714
771
  this.heldLatencyMs = this.baseRttMs
715
772
  this.haveRate = false
@@ -727,7 +784,7 @@ export class RateController {
727
784
  * every frame sent before the answer ahead of it would look waited. The bandwidth never comes from the latency on an idle link, so
728
785
  * neither can drag the other down.
729
786
  */
730
- leastLatency(): f64 {
787
+ private leastLatency(): f64 {
731
788
  let least: f64 = -1.0
732
789
  for (let i: i32 = 0; i < toI32(this.tripMs.length); i++) {
733
790
  const bytes: f64 = this.tripBytes[i]
@@ -754,7 +811,7 @@ export class RateController {
754
811
  * there; more lengthens all of it, so detail is not restored on a link that
755
812
  * may not carry it.
756
813
  */
757
- fixedPart(rtt: f64, scale: f64): f64 {
814
+ private fixedPart(rtt: f64, scale: f64): f64 {
758
815
  if (!this.haveRate) {
759
816
  if (scale >= 1.0) {
760
817
  return 0.0
@@ -777,7 +834,7 @@ export class RateController {
777
834
  * `nowMs` lets a frame long unanswered count as a round trip at least that
778
835
  * long. A load not yet measured counts as 0.
779
836
  */
780
- load(fps: i32, level: i32, nowMs: f64): f64 {
837
+ private load(fps: i32, level: i32, nowMs: f64): f64 {
781
838
  const scale: f64 = rateLevelScale(this.level, level)
782
839
  const rate: f64 = toF64(fps)
783
840
  let worst: f64 = 0.0
@@ -802,7 +859,7 @@ export class RateController {
802
859
  }
803
860
 
804
861
  /** The fastest allowed tier slower than `fps` and no slower than `least`, or `least`. */
805
- slowerTier(fps: i32, least: i32): i32 {
862
+ private slowerTier(fps: i32, least: i32): i32 {
806
863
  for (const t of this.tiers) {
807
864
  if (t < fps && t >= least) {
808
865
  return t
@@ -812,7 +869,7 @@ export class RateController {
812
869
  }
813
870
 
814
871
  /** The slowest allowed tier faster than `fps`, or `fps` at the top. */
815
- fasterTier(fps: i32): i32 {
872
+ private fasterTier(fps: i32): i32 {
816
873
  let faster: i32 = fps
817
874
  for (const t of this.tiers) {
818
875
  if (t > fps) {
@@ -823,7 +880,7 @@ export class RateController {
823
880
  }
824
881
 
825
882
  /** Move to `fps` at detail step `level` at `nowMs`, rescaling the frame averages to the step. */
826
- moveTo(fps: i32, level: i32, nowMs: f64): void {
883
+ private moveTo(fps: i32, level: i32, nowMs: f64): void {
827
884
  if (level !== this.level) {
828
885
  const scale: f64 = rateLevelScale(this.level, level)
829
886
  this.costMs = this.costMs * scale
@@ -842,7 +899,7 @@ export class RateController {
842
899
  }
843
900
 
844
901
  /** One step down the path at `nowMs`, when over budget: fewer frames, or less detail. */
845
- stepDown(nowMs: f64): void {
902
+ private stepDown(nowMs: f64): void {
846
903
  const least: i32 = this.tiers[this.tiers.length - 1]
847
904
  if (this.tier > this.floorFps) {
848
905
  // Straight to the fastest tier down to the floor that fits.
@@ -872,7 +929,7 @@ export class RateController {
872
929
  * the descent backwards: tiers below the floor first, then detail, then
873
930
  * tiers above it.
874
931
  */
875
- stepUp(): i32 {
932
+ private stepUp(): i32 {
876
933
  if (this.tier < this.floorFps || (this.level === 0 && this.tier < this.tiers[0])) {
877
934
  return this.fasterTier(this.tier) * 8 + this.level
878
935
  }
@@ -887,6 +944,8 @@ export class RateController {
887
944
  * detail, restore it or rise, at most one change, with the hysteresis the
888
945
  * module header describes. Nothing is decided before the first
889
946
  * acknowledgement, nor at a fixed rate.
947
+ *
948
+ * @param nowMs The time now, in milliseconds on the clock every call uses.
890
949
  */
891
950
  tick(nowMs: f64): void {
892
951
  if (!rateFinite(nowMs)) {
@@ -912,7 +971,7 @@ export class RateController {
912
971
  }
913
972
 
914
973
  /** `tick`'s choosing, past its guards. */
915
- decide(nowMs: f64): void {
974
+ private decide(nowMs: f64): void {
916
975
  const settled: boolean = nowMs - this.changedMs >= rateSettleMs
917
976
  if (this.load(this.tier, this.level, nowMs) > 1.0) {
918
977
  this.underSinceMs = -1.0
@@ -939,7 +998,7 @@ export class RateController {
939
998
  }
940
999
 
941
1000
  /** Copy the state into `current` and `measured`. */
942
- publish(): void {
1001
+ private publish(): void {
943
1002
  const d: RateDecision = this.current
944
1003
  d.fps = this.tier
945
1004
  d.resolutionDivisor = this.level >= 2 ? 4 : this.level + 1
@@ -956,12 +1015,20 @@ export class RateController {
956
1015
  s.lost = this.lost
957
1016
  }
958
1017
 
959
- /** How to draw the next frame, as of the last `tick`. */
1018
+ /**
1019
+ * How to draw the next frame, as of the last `tick`.
1020
+ *
1021
+ * @returns The frame rate, resolution divisor, richest backend and palette to draw with.
1022
+ */
960
1023
  decision(): RateDecision {
961
1024
  return this.current
962
1025
  }
963
1026
 
964
- /** What has been measured, as of the last `tick`. */
1027
+ /**
1028
+ * What has been measured, as of the last `tick`.
1029
+ *
1030
+ * @returns The rate, round trip, throughput, frame cost and frames dropped, unacknowledged and lost.
1031
+ */
965
1032
  stats(): TermStats {
966
1033
  return this.measured
967
1034
  }
@@ -991,6 +1058,10 @@ const rateBackendName = (cap: i32): string => {
991
1058
  * Write `stats` as two short lines, inverse, into `corner` (a `CORNER_*`) of
992
1059
  * `screen`: the rate, round trip and kilobytes a second, then the frame cost,
993
1060
  * the frames dropped and the backend cap. A screen too small clips them.
1061
+ *
1062
+ * @param screen The screen to draw on, before it is flushed.
1063
+ * @param stats What to show, such as `RateController.stats()`.
1064
+ * @param corner Which corner, one of the `CORNER_` constants.
994
1065
  */
995
1066
  export const drawStatsOverlay = (screen: Screen, stats: TermStats, corner: i32): void => {
996
1067
  const top: string = `${stats.tier}fps ${rateWhole(stats.rttMs)}ms ${rateWhole(stats.bytesPerSec / 1000.0)}kB/s`