@amritk/nish-aarch64-linux 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 (119) hide show
  1. package/INSTALL.md +6 -1
  2. package/bin/nish +0 -0
  3. package/docs/AI.md +9 -2
  4. package/package.json +1 -1
  5. package/runtime/nish.d.ts +4612 -430
  6. package/runtime/vite.d.ts +30 -0
  7. package/runtime/vite.mjs +150 -0
  8. package/scripts/build.sh +108 -13
  9. package/std/base64.ts +34 -5
  10. package/std/bytes.ts +256 -40
  11. package/std/cli-args.ts +296 -70
  12. package/std/cli-flags.ts +184 -19
  13. package/std/cli.ts +475 -54
  14. package/std/collections.ts +121 -23
  15. package/std/compress/checksum.ts +44 -14
  16. package/std/compress/deflate.ts +224 -111
  17. package/std/compress/gzip.ts +217 -53
  18. package/std/compress/zlib.ts +63 -7
  19. package/std/crypto/aes.ts +80 -9
  20. package/std/crypto/base64url.ts +22 -0
  21. package/std/crypto/bcrypt-batch.ts +88 -21
  22. package/std/crypto/bcrypt.ts +60 -0
  23. package/std/crypto/chacha20poly1305.ts +53 -0
  24. package/std/crypto/ct.ts +32 -13
  25. package/std/crypto/ed25519.ts +47 -0
  26. package/std/crypto/hkdf.ts +198 -13
  27. package/std/crypto/hmac.ts +235 -31
  28. package/std/crypto/jwt.ts +192 -63
  29. package/std/crypto/p256.ts +159 -16
  30. package/std/crypto/p384.ts +28 -3
  31. package/std/crypto/pki-roots.ts +32 -2
  32. package/std/crypto/pki.ts +81 -15
  33. package/std/crypto/rsa.ts +33 -3
  34. package/std/crypto/sha1.ts +3 -0
  35. package/std/crypto/sha256.ts +24 -1
  36. package/std/crypto/sha512.ts +99 -14
  37. package/std/crypto/x25519.ts +152 -14
  38. package/std/crypto/x509-random.ts +10 -0
  39. package/std/crypto/x509.ts +67 -7
  40. package/std/json-equal.ts +19 -0
  41. package/std/json-format.ts +112 -13
  42. package/std/json-number.ts +64 -14
  43. package/std/json-pointer.ts +23 -1
  44. package/std/json-tokenizer.ts +100 -29
  45. package/std/json-typed.ts +713 -66
  46. package/std/json-value.ts +400 -124
  47. package/std/json.ts +138 -10
  48. package/std/map.ts +25 -7
  49. package/std/math.ts +36 -4
  50. package/std/net/buffer-pool.ts +42 -11
  51. package/std/net/dns-config.ts +109 -23
  52. package/std/net/dns-message.ts +62 -7
  53. package/std/net/dns-resolver.ts +247 -53
  54. package/std/net/dns.ts +203 -35
  55. package/std/net/fetch.ts +151 -61
  56. package/std/net/handler.ts +278 -80
  57. package/std/net/hpack.ts +262 -52
  58. package/std/net/http-compress.ts +125 -15
  59. package/std/net/http-fields.ts +85 -9
  60. package/std/net/http1-client-codec.ts +100 -19
  61. package/std/net/http1-codec.ts +235 -27
  62. package/std/net/http1-server.ts +343 -85
  63. package/std/net/http2-frame.ts +272 -35
  64. package/std/net/http2-tls.ts +135 -34
  65. package/std/net/http2.ts +247 -106
  66. package/std/net/http3-frame.ts +154 -17
  67. package/std/net/http3-server.ts +246 -96
  68. package/std/net/http3.ts +307 -115
  69. package/std/net/outbound.ts +37 -3
  70. package/std/net/postgres-carrier.ts +144 -8
  71. package/std/net/postgres.ts +723 -103
  72. package/std/net/prefork.ts +164 -31
  73. package/std/net/qpack.ts +105 -18
  74. package/std/net/quic-conn-ack.ts +59 -12
  75. package/std/net/quic-conn-cid.ts +124 -27
  76. package/std/net/quic-conn-params.ts +70 -10
  77. package/std/net/quic-datagram.ts +43 -3
  78. package/std/net/quic-frame.ts +286 -12
  79. package/std/net/quic-listener.ts +101 -32
  80. package/std/net/quic-packet.ts +302 -21
  81. package/std/net/quic-recovery.ts +228 -44
  82. package/std/net/quic-stream.ts +353 -91
  83. package/std/net/quic.ts +489 -171
  84. package/std/net/router.ts +87 -40
  85. package/std/net/tls/client.ts +166 -51
  86. package/std/net/tls/codec.ts +413 -56
  87. package/std/net/tls/record-client.ts +110 -55
  88. package/std/net/tls/record-server.ts +159 -59
  89. package/std/net/tls/record.ts +109 -12
  90. package/std/net/tls/schedule.ts +235 -26
  91. package/std/net/tls/ticket.ts +159 -40
  92. package/std/net/tls/verify.ts +49 -3
  93. package/std/net/tls-tcp.ts +250 -45
  94. package/std/net/tls.ts +221 -59
  95. package/std/net/upstream.ts +81 -45
  96. package/std/net/url.ts +97 -13
  97. package/std/net/websocket.ts +122 -12
  98. package/std/net/webtransport.ts +220 -89
  99. package/std/pair.ts +10 -2
  100. package/std/random.ts +34 -9
  101. package/std/regex.ts +352 -198
  102. package/std/region.ts +70 -15
  103. package/std/secret.ts +52 -11
  104. package/std/sort.ts +17 -2
  105. package/std/sqlite.ts +256 -35
  106. package/std/sync/ring.ts +205 -35
  107. package/std/sync/shm.ts +194 -16
  108. package/std/term-io.ts +137 -64
  109. package/std/term-pixels.ts +144 -19
  110. package/std/term-probe.ts +66 -25
  111. package/std/term-rate.ts +128 -57
  112. package/std/term.ts +332 -121
  113. package/std/testing.ts +130 -32
  114. package/std/text.ts +73 -7
  115. package/std/threads.ts +229 -41
  116. package/std/yaml-json.ts +94 -82
  117. package/std/yaml-lines.ts +47 -15
  118. package/std/yaml-write.ts +24 -16
  119. package/std/yaml.ts +764 -384
@@ -386,6 +386,15 @@ const http1ClientPutField = (out: u8[], at: i32, names: string[], values: string
386
386
  * here; a `Connection` that lists `upgrade`, which only
387
387
  * `http1UpgradeRequestHead` may write; and a `bodyLength` below -2. Answers
388
388
  * `HTTP1_NO_ROOM` when it is well formed but does not fit. Either way `out` is untouched.
389
+ *
390
+ * @param out The buffer the head is written into; nothing outside the head's bytes changes.
391
+ * @param at The index in `out` the request line starts at; a negative one answers `HTTP1_NO_ROOM`.
392
+ * @param method The request method, a token such as `GET`, written as given.
393
+ * @param target The request target in the form the method may send, written as given.
394
+ * @param names The field names, matched case-insensitively; exactly one is `Host`, which is written first, and the rest follow in order.
395
+ * @param values The value of each field in `names`, at the same index.
396
+ * @param bodyLength The body's length in bytes, or `HTTP1_CHUNKED` (-1) or `HTTP1_NO_BODY` (-2).
397
+ * @returns The index in `out` just past the empty line, or `HTTP1_REFUSED` or `HTTP1_NO_ROOM`.
389
398
  */
390
399
  export const http1WriteRequestHead = (
391
400
  out: u8[],
@@ -448,8 +457,15 @@ const http1ClientPutHead = (
448
457
  }
449
458
 
450
459
  /**
451
- * `http1WriteRequestHead`'s head in an array of its own, or `null` for
452
- * everything it refuses.
460
+ * `http1WriteRequestHead`'s head in an array of its own, sized to fit, so
461
+ * there is no room to run out of.
462
+ *
463
+ * @param method The request method, a token such as `GET`.
464
+ * @param target The request target in the form the method may send.
465
+ * @param names The field names; exactly one is `Host`, which is written first, and the rest follow in order.
466
+ * @param values The value of each field in `names`, at the same index.
467
+ * @param bodyLength The body's length in bytes, or `HTTP1_CHUNKED` (-1) or `HTTP1_NO_BODY` (-2).
468
+ * @returns The head, ending in the empty line, or `null` for everything `http1WriteRequestHead` refuses and for a head over 1 GiB.
453
469
  */
454
470
  export const http1RequestHead = (
455
471
  method: string,
@@ -468,6 +484,13 @@ export const http1RequestHead = (
468
484
  * `Connection` among the caller's fields, which would contradict the two this
469
485
  * writes. A response to it is read after `expect(false, false)` and then
470
486
  * `expectUpgrade()`, so that its 101 answers `HTTP1_UPGRADE`.
487
+ *
488
+ * @param method The request method, a token; a WebSocket handshake sends `GET`.
489
+ * @param target The request target in the form the method may send.
490
+ * @param names The caller's field names; exactly one is `Host`, which is written first, and the rest follow in order, before the two upgrade fields.
491
+ * @param values The value of each field in `names`, at the same index.
492
+ * @param upgrade The protocol asked for, one token such as `websocket`; an empty one answers `null`.
493
+ * @returns The head, ending in the empty line, or `null` when any of the above is refused or the head is over 1 GiB.
471
494
  */
472
495
  export const http1UpgradeRequestHead = (
473
496
  method: string,
@@ -545,64 +568,81 @@ export class Http1ResponseParser {
545
568
  * `fieldName`, `fieldValue`, `reasonText` and `header` answer in either mode.
546
569
  */
547
570
  names: string[]
571
+ /** The field values, each beside its name in `names`. */
548
572
  values: string[]
549
573
  /**
550
574
  * The response's reason phrase and kept fields, copied: `head[reasonStart ..
551
575
  * reasonEnd)` is the reason, and field `i` is `head[spans[4i] ..
552
576
  * spans[4i + 1])`, its name in lowercase, then `head[spans[4i + 2] ..
553
577
  * spans[4i + 3])`, its value. Both arrays are reused from response to response.
578
+ * @internal
554
579
  */
555
580
  head: u8[]
581
+ /** @internal Parser state the module's `http1Client` helpers read and write. */
556
582
  spans: i32[]
557
583
  /** The buffer the last `HTTP1_BODY`'s bytes are in, at `bodyOff`, `bodyLen` long. */
558
584
  body: u8[]
559
585
  /** What was wrong, once `next()` said `HTTP1_ERROR`; for a log. */
560
586
  errorText: string = ""
561
- /** The bytes fed and not yet consumed are `buf[start .. end)`. */
587
+ /** The bytes fed and not yet consumed are `buf[start .. end)`. @internal */
562
588
  buf: u8[]
563
589
 
564
590
  // --- limits, the caller's --------------------------------------------------
591
+ /** The most body bytes a response may carry, de-chunked; past it the parser refuses. */
565
592
  maxBody: i64 = 0
566
593
  /** The declared body length, or -1 when the response has none or is chunked or read until close. */
567
594
  contentLength: i64 = -1
568
- /** Bytes left in a length-delimited body or in the current chunk. */
595
+ /** Bytes left in a length-delimited body or in the current chunk. @internal */
569
596
  left: i64 = 0
570
597
  /** De-chunked body bytes so far, against `maxBody`. */
571
598
  bodyTotal: i64 = 0
599
+ /** @internal Parser state the module's `http1Client` helpers read and write. */
572
600
  maxStatusLine: i32 = 0
601
+ /** @internal Parser state the module's `http1Client` helpers read and write. */
573
602
  maxHeaderBytes: i32 = 0
603
+ /** @internal Parser state the module's `http1Client` helpers read and write. */
574
604
  maxHeaders: i32 = 0
605
+ /** @internal Parser state the module's `http1Client` helpers read and write. */
575
606
  maxTrailerBytes: i32 = 0
576
607
 
577
608
  /** The status code of the response last read. */
578
609
  status: i32 = 0
579
610
  /** The minor version: 0 for HTTP/1.0, 1 for HTTP/1.1 and anything above it. */
580
611
  minor: i32 = 1
612
+ /** Where the last `HTTP1_BODY`'s bytes start in `body`. */
581
613
  bodyOff: i32 = 0
614
+ /** How many bytes the last `HTTP1_BODY` holds. */
582
615
  bodyLen: i32 = 0
583
616
  /** Why `next()` said `HTTP1_ERROR`: one of the `HTTP1_E_` codes. */
584
617
  error: i32 = 0
585
618
 
586
619
  // --- internal --------------------------------------------------------------
620
+ /** @internal Parser state the module's `http1Client` helpers read and write. */
587
621
  start: i32 = 0
622
+ /** @internal Parser state the module's `http1Client` helpers read and write. */
588
623
  end: i32 = 0
589
- /** Where the search for the next LF resumes, so a line fed a byte at a time is scanned once. */
624
+ /** Where the search for the next LF resumes, so a line fed a byte at a time is scanned once. @internal */
590
625
  scan: i32 = 0
626
+ /** @internal Parser state the module's `http1Client` helpers read and write. */
591
627
  state: i32 = 0
592
- /** Bytes of the header or trailer section so far, against its limit. */
628
+ /** Bytes of the header or trailer section so far, against its limit. @internal */
593
629
  sectionBytes: i32 = 0
594
- /** Field lines of the response so far, its trailers included, against `maxHeaders`. */
630
+ /** Field lines of the response so far, its trailers included, against `maxHeaders`. @internal */
595
631
  fieldCount: i32 = 0
596
- /** Interim responses before this request's final one, against `HTTP1_MAX_INFORMATIONAL`. */
632
+ /** Interim responses before this request's final one, against `HTTP1_MAX_INFORMATIONAL`. @internal */
597
633
  informational: i32 = 0
598
- /** The line `http1ClientTakeLine` found is `buf[lineStart .. lineEnd)`, its CRLF dropped. */
634
+ /** The line `http1ClientTakeLine` found is `buf[lineStart .. lineEnd)`, its CRLF dropped. @internal */
599
635
  lineStart: i32 = 0
636
+ /** @internal Parser state the module's `http1Client` helpers read and write. */
600
637
  lineEnd: i32 = 0
601
638
 
639
+ /** Whether the response's body is chunked. */
602
640
  chunked: boolean = false
641
+ /** @internal Parser state the module's `http1Client` helpers read and write. */
603
642
  persistent: boolean = false
604
- /** What `expect` said of the request this response answers. */
643
+ /** What `expect` said of the request this response answers: whether it was a HEAD. */
605
644
  wasHead: boolean = false
645
+ /** What `expect` said of the request this response answers: whether it was a CONNECT. */
606
646
  wasConnect: boolean = false
607
647
  /** Whether `expectUpgrade` said the request asked to switch protocols. */
608
648
  wasUpgrade: boolean = false
@@ -610,15 +650,23 @@ export class Http1ResponseParser {
610
650
  closed: boolean = false
611
651
  /** Whether `names`, `values` and `reason` are filled; `fieldsAsSpans()` clears it. */
612
652
  keepStrings: boolean = true
613
- /** Bytes of `head` in use, and the fields recorded in `spans`. */
653
+ /** Bytes of `head` in use, and the fields recorded in `spans`. @internal */
614
654
  headUsed: i32 = 0
655
+ /** @internal Parser state the module's `http1Client` helpers read and write. */
615
656
  spanCount: i32 = 0
657
+ /** @internal Parser state the module's `http1Client` helpers read and write. */
616
658
  reasonStart: i32 = 0
659
+ /** @internal Parser state the module's `http1Client` helpers read and write. */
617
660
  reasonEnd: i32 = 0
618
661
 
619
662
  /**
620
663
  * Each `i32` limit is clamped into 0 to 2^30 and `maxBody` into 0 to 2^53,
621
664
  * so that the sums the parser makes of them cannot overflow.
665
+ * @param maxStatusLine The longest status line accepted, in bytes.
666
+ * @param maxHeaderBytes The most bytes the header section may take.
667
+ * @param maxHeaders The most field lines a response may carry, trailers included.
668
+ * @param maxBody The most body bytes a response may carry, de-chunked.
669
+ * @param maxTrailerBytes The most bytes the trailer section may take.
622
670
  */
623
671
  constructor(maxStatusLine: i32, maxHeaderBytes: i32, maxHeaders: i32, maxBody: i64, maxTrailerBytes: i32) {
624
672
  this.maxStatusLine = http1ClientClamp(maxStatusLine)
@@ -682,6 +730,8 @@ export class Http1ResponseParser {
682
730
  * parser waits for a response's first status line, and the parser forgets it
683
731
  * after that response's `HTTP1_END`; anywhere else it does nothing, so a
684
732
  * pipelining caller says it once per response, after the last one's end.
733
+ * @param methodWasHead Whether the request was a HEAD, so the response has no body.
734
+ * @param wasConnect Whether the request was a CONNECT, so a 2xx opens a tunnel.
685
735
  */
686
736
  expect(methodWasHead: boolean, wasConnect: boolean): void {
687
737
  if (this.state === HTTP1_CLIENT_S_STATUS_LINE && this.informational === 0) {
@@ -712,6 +762,9 @@ export class Http1ResponseParser {
712
762
  * Appends `data[off .. off + len)` to the input. A window outside `data`
713
763
  * panics. After `finish()`, or once the parser has closed or refused, the
714
764
  * input is dropped; in a tunnel it is kept for `tunnelBytes()`.
765
+ * @param data The bytes read from the connection.
766
+ * @param off Where the new bytes start in `data`.
767
+ * @param len How many bytes to append.
715
768
  */
716
769
  feed(data: u8[], off: i32, len: i32): void {
717
770
  const size: i32 = toI32(data.length)
@@ -736,7 +789,10 @@ export class Http1ResponseParser {
736
789
  this.closed = true
737
790
  }
738
791
 
739
- /** The next event the input holds; see the module comment. */
792
+ /**
793
+ * The next event the input holds; see the module comment.
794
+ * @returns An `HTTP1_` event, `HTTP1_NEED_MORE` when the input runs out.
795
+ */
740
796
  next(): i32 {
741
797
  const event: i32 = http1ClientNext(this)
742
798
  if (event !== HTTP1_NEED_MORE || !this.closed) {
@@ -757,12 +813,17 @@ export class Http1ResponseParser {
757
813
  * ended (RFC 9112 §9.3): a 1.1 response unless `Connection` lists `close`,
758
814
  * a 1.0 response only when it lists `keep-alive`, and never one read until
759
815
  * close, a tunnel or an error.
816
+ * @returns Whether the connection may be reused.
760
817
  */
761
818
  keepAlive(): boolean {
762
819
  return this.persistent
763
820
  }
764
821
 
765
- /** The value of the first field named `name` (any case), or `null`. */
822
+ /**
823
+ * The value of the first field named `name` (any case).
824
+ * @param name The field name to look for.
825
+ * @returns The field's value, OWS trimmed, or `null` when the response has no such field.
826
+ */
766
827
  header(name: string): string | null {
767
828
  for (let i: i32 = 0; i < this.spanCount; i += 1) {
768
829
  if (http1ClientHeadSameWord(this.head, this.spans[i * 4], this.spans[i * 4 + 1], name)) {
@@ -772,12 +833,19 @@ export class Http1ResponseParser {
772
833
  return null
773
834
  }
774
835
 
775
- /** How many fields the response last read has; trailers are not kept. */
836
+ /**
837
+ * How many fields the response last read has; trailers are not kept.
838
+ * @returns The number of fields, which `fieldName` and `fieldValue` index.
839
+ */
776
840
  fields(): i32 {
777
841
  return this.spanCount
778
842
  }
779
843
 
780
- /** Field `i`'s name, in lowercase, as a fresh string; "" past the last field. */
844
+ /**
845
+ * Field `i`'s name, in lowercase, as a fresh string.
846
+ * @param i The field's index, from 0 to below `fields()`.
847
+ * @returns The name, or "" past the last field.
848
+ */
781
849
  fieldName(i: i32): string {
782
850
  if (i < 0 || i >= this.spanCount) {
783
851
  return ""
@@ -785,7 +853,11 @@ export class Http1ResponseParser {
785
853
  return http1Text(this.head, this.spans[i * 4], this.spans[i * 4 + 1], false)
786
854
  }
787
855
 
788
- /** Field `i`'s value, OWS trimmed, as a fresh string; "" past the last field. */
856
+ /**
857
+ * Field `i`'s value, OWS trimmed, as a fresh string.
858
+ * @param i The field's index, from 0 to below `fields()`.
859
+ * @returns The value, or "" past the last field.
860
+ */
789
861
  fieldValue(i: i32): string {
790
862
  if (i < 0 || i >= this.spanCount) {
791
863
  return ""
@@ -793,7 +865,10 @@ export class Http1ResponseParser {
793
865
  return http1Text(this.head, this.spans[i * 4 + 2], this.spans[i * 4 + 3], false)
794
866
  }
795
867
 
796
- /** The reason phrase, as a fresh string. */
868
+ /**
869
+ * The reason phrase, as a fresh string.
870
+ * @returns The reason phrase of the response last read, "" when it had none.
871
+ */
797
872
  reasonText(): string {
798
873
  if (this.reasonEnd <= this.reasonStart) {
799
874
  return ""
@@ -801,12 +876,18 @@ export class Http1ResponseParser {
801
876
  return http1Text(this.head, this.reasonStart, this.reasonEnd, false)
802
877
  }
803
878
 
804
- /** How many bytes were fed and not consumed yet. */
879
+ /**
880
+ * How many bytes were fed and not consumed yet.
881
+ * @returns The count of unread input bytes.
882
+ */
805
883
  buffered(): i32 {
806
884
  return this.end - this.start
807
885
  }
808
886
 
809
- /** In a tunnel: every byte fed past the response head, as a fresh array. */
887
+ /**
888
+ * In a tunnel: every byte fed past the response head, as a fresh array.
889
+ * @returns The bytes, or an empty array outside a tunnel.
890
+ */
810
891
  tunnelBytes(): u8[] {
811
892
  let n: i32 = this.end - this.start
812
893
  if (n < 0 || this.state !== HTTP1_CLIENT_S_TUNNEL) {