@amritk/nish-x86_64-linux 0.36.0 → 0.38.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 (103) hide show
  1. package/INSTALL.md +92 -71
  2. package/bin/nish +0 -0
  3. package/docs/AI.md +75 -14
  4. package/package.json +1 -1
  5. package/runtime/async.d.mts +2 -0
  6. package/runtime/async.mjs +7 -0
  7. package/runtime/core/arrays.d.ts +4 -0
  8. package/runtime/core/arrays.mjs +33 -0
  9. package/runtime/nish.d.ts +1045 -512
  10. package/runtime/nish.h +53 -6
  11. package/runtime/page.d.ts +53 -0
  12. package/runtime/page.mjs +146 -0
  13. package/runtime/runtime-async.c +740 -0
  14. package/runtime/runtime-cross.c +2 -1
  15. package/runtime/runtime-region.c +85 -7
  16. package/runtime/runtime-text.c +1068 -0
  17. package/runtime/runtime-wasm.c +65 -9
  18. package/runtime/runtime.c +50 -961
  19. package/runtime/vite.mjs +48 -11
  20. package/scripts/build.sh +231 -31
  21. package/std/LICENSE-fdlibm +8 -0
  22. package/std/README.md +109 -82
  23. package/std/array.ts +266 -0
  24. package/std/bytes.ts +23 -19
  25. package/std/compress/checksum.ts +1 -1
  26. package/std/crypto/aes.ts +48 -43
  27. package/std/crypto/base64url.ts +7 -5
  28. package/std/crypto/bcrypt-batch.ts +13 -13
  29. package/std/crypto/bcrypt.ts +33 -27
  30. package/std/crypto/chacha20poly1305.ts +16 -14
  31. package/std/crypto/ed25519.ts +19 -16
  32. package/std/crypto/hmac.ts +7 -6
  33. package/std/crypto/jwt.ts +23 -20
  34. package/std/crypto/p256.ts +63 -56
  35. package/std/crypto/p384.ts +23 -20
  36. package/std/crypto/pki.ts +18 -15
  37. package/std/crypto/rsa.ts +23 -19
  38. package/std/crypto/x25519.ts +11 -10
  39. package/std/crypto/x509.ts +69 -62
  40. package/std/host/ring.ts +124 -0
  41. package/std/host/text.ts +86 -0
  42. package/std/json-equal.ts +12 -11
  43. package/std/json-number.ts +12 -12
  44. package/std/json-tokenizer.ts +26 -22
  45. package/std/json-typed.ts +92 -78
  46. package/std/json-value.ts +38 -33
  47. package/std/json.ts +32 -28
  48. package/std/math.ts +743 -41
  49. package/std/net/dns-resolver.ts +46 -6
  50. package/std/net/dns.ts +50 -13
  51. package/std/net/fetch.ts +1744 -295
  52. package/std/net/handler.ts +30 -0
  53. package/std/net/hpack.ts +29 -26
  54. package/std/net/http-compress.ts +42 -28
  55. package/std/net/http-fields.ts +19 -4
  56. package/std/net/http1-client-codec.ts +29 -25
  57. package/std/net/http1-codec.ts +62 -91
  58. package/std/net/http1-server.ts +79 -57
  59. package/std/net/http2-frame.ts +17 -16
  60. package/std/net/http2-tls.ts +17 -15
  61. package/std/net/http2.ts +67 -54
  62. package/std/net/http3-frame.ts +11 -10
  63. package/std/net/http3-server.ts +36 -35
  64. package/std/net/http3.ts +70 -58
  65. package/std/net/postgres-async.ts +1005 -0
  66. package/std/net/postgres.ts +185 -164
  67. package/std/net/prefork.ts +38 -34
  68. package/std/net/qpack.ts +15 -14
  69. package/std/net/quic-conn-ack.ts +1 -0
  70. package/std/net/quic-conn-cid.ts +11 -0
  71. package/std/net/quic-conn-params.ts +41 -14
  72. package/std/net/quic-datagram.ts +7 -0
  73. package/std/net/quic-frame.ts +48 -12
  74. package/std/net/quic-listener.ts +61 -44
  75. package/std/net/quic-packet.ts +71 -52
  76. package/std/net/quic-recovery.ts +59 -21
  77. package/std/net/quic-stream.ts +83 -55
  78. package/std/net/quic.ts +204 -152
  79. package/std/net/serve.ts +763 -0
  80. package/std/net/tls/client.ts +1 -0
  81. package/std/net/tls/codec.ts +81 -12
  82. package/std/net/tls/record-client.ts +30 -18
  83. package/std/net/tls/record-server.ts +74 -46
  84. package/std/net/tls/record.ts +33 -24
  85. package/std/net/tls/ticket.ts +2 -0
  86. package/std/net/tls/verify.ts +8 -7
  87. package/std/net/tls-tcp.ts +58 -50
  88. package/std/net/tls.ts +55 -43
  89. package/std/net/url.ts +12 -9
  90. package/std/net/websocket.ts +23 -19
  91. package/std/net/webtransport.ts +24 -18
  92. package/std/random.ts +8 -6
  93. package/std/regex.ts +70 -59
  94. package/std/sync/ring.ts +24 -21
  95. package/std/sync/shm.ts +9 -7
  96. package/std/term-io.ts +17 -14
  97. package/std/term-probe.ts +11 -10
  98. package/std/term-rate.ts +71 -61
  99. package/std/term.ts +73 -59
  100. package/std/text.ts +242 -15
  101. package/std/threads.ts +19 -15
  102. package/std/yaml-json.ts +17 -15
  103. package/std/yaml-write.ts +21 -14
@@ -30,18 +30,22 @@
30
30
  * event = conn.next();
31
31
  * }
32
32
  *
33
- * **Events.** `next()` answers `PG_READY` once, when the server has
34
- * authenticated the connection and is ready for queries; `PG_DESCRIBED` when a
35
- * prepared statement has been described (`columns` and `columnType(c)` say
36
- * what its rows hold, `columns` is 0 when it returns none); `PG_ROW` for each
37
- * row, its columns as windows into the input buffer (`colStart(c)`,
38
- * `colLength(c)`, -1 for NULL); `PG_COMPLETE` when an execution has finished
39
- * (`tagIs("UPDATE")`, `tagRows()`); `PG_ERROR` when a statement in the current
40
- * group failed (`lastError`); `PG_NOTICE` for a notice (`lastNotice`);
41
- * `PG_GROUP_DONE` when a group has been answered to its end (`groupFailed`,
42
- * `txStatus`); and `PG_FAILED`, final: the connection broke a rule or the
43
- * server ended it, `failure` says which and `lastError` holds the server's
44
- * reason when it gave one. `PG_NEED_MORE` asks for more input.
33
+ * **Events.**
34
+ *
35
+ * `next()` answers `PG_READY` once, when the server has authenticated the
36
+ * connection and is ready for queries; `PG_DESCRIBED` when a prepared statement
37
+ * has been described (`columns` and `columnType(c)` say what its rows hold,
38
+ * `columns` is 0 when it returns none); `PG_ROW` for each row, its columns as
39
+ * windows into the input buffer (`colStart(c)`, `colLength(c)`, -1 for NULL);
40
+ * `PG_COMPLETE` when an execution has finished (`tagIs("UPDATE")`,
41
+ * `tagRows()`); `PG_ERROR` when a statement in the current group failed
42
+ * (`lastError`); `PG_NOTICE` for a notice (`lastNotice`); `PG_GROUP_DONE` when
43
+ * a group has been answered to its end (`groupFailed`, `txStatus`); and
44
+ * `PG_FAILED`, final: the connection broke a rule or the server ended it,
45
+ * `failure` says which and `lastError` holds the server's reason when it gave
46
+ * one.
47
+ *
48
+ * `PG_NEED_MORE` asks for more input.
45
49
  *
46
50
  * **Windows and buffers.** A column's window, the tag `tagIs` and `tagRows`
47
51
  * read are valid until the next `next()`,
@@ -58,93 +62,101 @@
58
62
  * In a failed group, `PG_DESCRIBED` comes once for each `prepare` the server
59
63
  * parsed before the error: a program that counts them knows which statements
60
64
  * exist (named ones last past the group) and which must be prepared again.
61
- * Up to `maxInFlight` groups may wait for their answers at once; `canSend()`
62
- * says whether another may start, and the builder calls refuse (and write
63
- * nothing) when it may not. Nothing waits for a round trip that the protocol
64
- * does not need: a program prepares a statement and executes it in the same
65
- * flight.
66
65
  *
67
- * **Text results, no copies.** Every parameter is in text format unless it
68
- * is one of the binary integer arrays below, and every result column is text
69
- * unless the bind asks otherwise. A row is read where it
70
- * lies in the input buffer: `next()` frames each message once, validates its
71
- * layout, and records each column's start and length in two reused arrays, so
72
- * a row costs no allocation. `int`, `bool`, `isNull` and `PgText.timestamp`
73
- * decode a column in place; `PgArrayWalker` walks a one-dimensional `text[]`
74
- * in place. `columnText(c)` is the one that allocates, a string. An array
75
- * parameter is a text array literal too: `paramIntArray` writes an `int8[]`
76
- * from an `i64[]` window, and `arrayStart`, `arrayElement`, `arrayInt`,
77
- * `arrayNull` and `arrayEnd` build an array one element at a time into the
78
- * Bind, so a list needs no string built first. A program whose element was
79
- * refused for room can drop the whole bind, unsent, with `bindCancel`.
66
+ * Up to `maxInFlight` groups may wait for their answers at once; `canSend()`
67
+ * says whether another may start, and the builder calls refuse (and write
68
+ * nothing) when it may not. Nothing waits for a round trip that the protocol
69
+ * does not need: a program prepares a statement and executes it in the same
70
+ * flight.
71
+ *
72
+ * **Text results, no copies.** Every parameter is in text format unless it is
73
+ * one of the binary integer arrays below, and every result column is text
74
+ * unless the bind asks otherwise. A row is read where it lies in the input
75
+ * buffer: `next()` frames each message once, validates its layout, and records
76
+ * each column's start and length in two reused arrays, so a row costs no
77
+ * allocation. `int`, `bool`, `isNull` and `PgText.timestamp` decode a column in
78
+ * place; `PgArrayWalker` walks a one-dimensional `text[]` in place.
79
+ * `columnText(c)` is the one that allocates, a string.
80
+ *
81
+ * An array parameter is a text array literal too: `paramIntArray` writes an
82
+ * `int8[]` from an `i64[]` window, and `arrayStart`, `arrayElement`,
83
+ * `arrayInt`, `arrayNull` and `arrayEnd` build an array one element at a time
84
+ * into the Bind, so a list needs no string built first. A program whose element
85
+ * was refused for room can drop the whole bind, unsent, with `bindCancel`.
80
86
  *
81
87
  * **Binary integer arrays.** `paramInt4Array` and `paramInt8Array` send an
82
- * `i64[]` window as an `int4[]` or `int8[]` in PostgreSQL's binary layout:
83
- * four or eight bytes an element and no digits to write or parse, which the
84
- * benchmark (`bench/postgres/arrays.mjs`) measured at about a tenth of the
85
- * text encoder's client CPU, and at 1,000 elements a 51% cut in the server's
86
- * on `unnest` for `int8[]`, 30% for `int4[]`.
87
- * `binaryArrayStart(oid)`, `binaryArrayInt` and `binaryArrayNull` build one
88
- * element at a time, NULLs included, and `arrayEnd` closes it. The Bind's
89
- * format codes stay a single zero word while every parameter is text; the
90
- * first binary one makes `bindEnd` write a code for each, so an all-text bind
91
- * costs nothing more. An `int4` element outside `int4` panics rather than
92
- * wrapping. The element type must match the statement's parameter: the server
93
- * answers a mismatch with `ErrorResponse` (42804) for that execution, and the
94
- * connection goes on.
88
+ * `i64[]` window as an `int4[]` or `int8[]` in PostgreSQL's binary layout: four
89
+ * or eight bytes an element and no digits to write or parse, which the
90
+ * benchmark (`bench/postgres/arrays.mjs`) measured at about a tenth of the text
91
+ * encoder's client CPU, and at 1,000 elements a 51% cut in the server's on
92
+ * `unnest` for `int8[]`, 30% for `int4[]`. `binaryArrayStart(oid)`,
93
+ * `binaryArrayInt` and `binaryArrayNull` build one element at a time, NULLs
94
+ * included, and `arrayEnd` closes it.
95
+ *
96
+ * The Bind's format codes stay a single zero word while every parameter is
97
+ * text; the first binary one makes `bindEnd` write a code for each, so an
98
+ * all-text bind costs nothing more. An `int4` element outside `int4` panics
99
+ * rather than wrapping. The element type must match the statement's parameter:
100
+ * the server answers a mismatch with `ErrorResponse` (42804) for that
101
+ * execution, and the connection goes on.
95
102
  *
96
103
  * **Binary results.** A bind opened with `bindStartBinary` instead of
97
- * `bindStart` asks for every result column in binary format: an `int8` is
98
- * eight bytes, a `timestamptz` eight bytes of microseconds since 2000, a
99
- * `bool` one byte, so there is nothing to parse and less on the wire.
100
- * `binaryInt`, `binaryBool` and `binaryFloat` read them in place, and
101
- * `PgBinary`'s `timestamp` and `iso` write a time as `PgText.timestamp` does.
102
- * A `text` column is the same bytes in either format, so `columnText` and the
103
- * column windows read it unchanged. The program knows which of its binds
104
- * asked for which, and reads each execution's rows with the matching
105
- * decoders. A `PgBatcher` with `binary` set opens each batch this way and
106
- * reads its routing ordinal with `binaryInt`, so its rows are binary too.
107
- * `PgBinaryArray` walks a one-dimensional `int2[]`, `int4[]` or `int8[]`
108
- * column in its binary layout, and refuses any other array (a `text[]` or a
109
- * multi-dimensional one among them).
104
+ * `bindStart` asks for every result column in binary format: an `int8` is eight
105
+ * bytes, a `timestamptz` eight bytes of microseconds since 2000, a `bool` one
106
+ * byte, so there is nothing to parse and less on the wire. `binaryInt`,
107
+ * `binaryBool` and `binaryFloat` read them in place, and `PgBinary`'s
108
+ * `timestamp` and `iso` write a time as `PgText.timestamp` does. A `text`
109
+ * column is the same bytes in either format, so `columnText` and the column
110
+ * windows read it unchanged.
110
111
  *
111
- * **Authentication.** SCRAM-SHA-256 (RFC 5802, RFC 7677) or none (`trust`).
112
- * The password arrives as a `Secret<u8[]>`; the connection keeps a copy in a
113
- * holder that is wiped as soon as the proof is computed, or when the
114
- * connection fails or is disposed. The server's signature is checked in
115
- * constant time before `AuthenticationOk` is believed, and an
116
- * `AuthenticationOk` that skips the end of an exchange SCRAM began is refused.
117
- * Cleartext and MD5 passwords, and SASL mechanisms other than SCRAM-SHA-256,
118
- * are refused: with no TLS here the first sends the password as it is, and the
119
- * second is a hash any eavesdropper can replay. The password's bytes are used
120
- * as they are, without SASLprep (RFC 4013): an ASCII password works, and a
121
- * non-ASCII one works only when it is already in the form SASLprep would give
122
- * (PostgreSQL itself falls back to the raw bytes when it cannot prepare one).
123
- * `docs/security/postgres.md` is the record.
112
+ * The program knows which of its binds asked for which, and reads each
113
+ * execution's rows with the matching decoders. A `PgBatcher` with `binary` set
114
+ * opens each batch this way and reads its routing ordinal with `binaryInt`, so
115
+ * its rows are binary too. `PgBinaryArray` walks a one-dimensional `int2[]`,
116
+ * `int4[]` or `int8[]` column in its binary layout, and refuses any other array
117
+ * (a `text[]` or a multi-dimensional one among them).
118
+ *
119
+ * **Authentication.** SCRAM-SHA-256 (RFC 5802, RFC 7677) or none (`trust`). The
120
+ * password arrives as a `Secret<u8[]>`; the connection keeps a copy in a holder
121
+ * that is wiped as soon as the proof is computed, or when the connection fails
122
+ * or is disposed. The server's signature is checked in constant time before
123
+ * `AuthenticationOk` is believed, and an `AuthenticationOk` that skips the end
124
+ * of an exchange SCRAM began is refused.
125
+ *
126
+ * Cleartext and MD5 passwords, and SASL mechanisms other than SCRAM-SHA-256,
127
+ * are refused: with no TLS here the first sends the password as it is, and the
128
+ * second is a hash any eavesdropper can replay. The password's bytes are used
129
+ * as they are, without SASLprep (RFC 4013): an ASCII password works, and a
130
+ * non-ASCII one works only when it is already in the form SASLprep would give
131
+ * (PostgreSQL itself falls back to the raw bytes when it cannot prepare one).
132
+ * `docs/security/postgres.md` is the record.
124
133
  *
125
134
  * **Caps.** `PgConfig` bounds what a server can make the client hold: the
126
135
  * longest message (`maxMessage`), the widest row (`maxColumns`) and the SCRAM
127
136
  * iteration count (`minIterations`, `maxIterations`); and what a program can
128
- * queue unsent (`maxOutput`), past which a builder call answers false. A
129
- * message longer than the cap, a length below 4, a layout that does not add
130
- * up, a message the protocol does not allow at that point (COPY among them),
131
- * an encoding other than UTF-8, and a `DateStyle` other than ISO or a
132
- * `TimeZone` other than UTC (at startup or after a `SET`), each fail the
133
- * connection with their own `failure` code. The constructor panics on a cap
134
- * out of range, as on a missing user or a short nonce.
137
+ * queue unsent (`maxOutput`), past which a builder call answers false.
138
+ *
139
+ * A message longer than the cap, a length below 4, a layout that does not add
140
+ * up, a message the protocol does not allow at that point (COPY among them), an
141
+ * encoding other than UTF-8, and a `DateStyle` other than ISO or a `TimeZone`
142
+ * other than UTC (at startup or after a `SET`), each fail the connection with
143
+ * their own `failure` code. The constructor panics on a cap out of range, as on
144
+ * a missing user or a short nonce.
135
145
  *
136
146
  * **Pools.** `PgPool` holds up to `size` connections to one server and a FIFO
137
147
  * queue of up to `queueSize` requests, still sans-IO: `wanted()` names a slot
138
148
  * that needs a socket, `connect(slot, nonce)` starts its connection, and the
139
- * program moves its bytes as above through `connection(slot)`. A request is a
140
- * ticket from `request()`; `dispatch()` gives the oldest to the ready
141
- * connection with the fewest groups in flight (or, with `PgConfig.pack`, to the
142
- * first ready one with room, so a burst fills few connections in fuller
143
- * writes), the program builds its group and ends it with `send()`, and `next(slot)` reads that connection's events with
144
- * `ticket` naming the request. Statements given to `register` are prepared on
145
- * each connection ahead of its first request. A connection that fails reports
146
- * `PG_LOST` for each request it took, then `PG_FAILED`; the program closes the
147
- * socket and the slot is built again on its next use.
149
+ * program moves its bytes as above through `connection(slot)`.
150
+ *
151
+ * A request is a ticket from `request()`; `dispatch()` gives the oldest to the
152
+ * ready connection with the fewest groups in flight (or, with `PgConfig.pack`,
153
+ * to the first ready one with room, so a burst fills few connections in fuller
154
+ * writes), the program builds its group and ends it with `send()`, and
155
+ * `next(slot)` reads that connection's events with `ticket` naming the request.
156
+ * Statements given to `register` are prepared on each connection ahead of its
157
+ * first request. A connection that fails reports `PG_LOST` for each request it
158
+ * took, then `PG_FAILED`; the program closes the socket and the slot is built
159
+ * again on its next use.
148
160
  *
149
161
  * **Carrier.** `PgCarrier`, in `nish/net/postgres-carrier`, moves a pool's
150
162
  * bytes on an `HttpHandler`'s loop, so a route handler queries without
@@ -153,23 +165,25 @@
153
165
  *
154
166
  * **Batching.** `PgBatcher` turns many reads of one row shape by key — a user
155
167
  * by id, an article by slug — into one execution of a statement over
156
- * `unnest($1) with ordinality`. `addInt` or `addText` queues a request's key
157
- * and tag; `take(conn)` binds the oldest waiting, each distinct key once (past
158
- * `PG_BATCH_PROBES` slots of its table probe, a key is bound again), up
159
- * to `maxRequests` and `maxBytes`, and answers a run's handle; `row`, `end`
160
- * and `fail` take that execution's events (a handle already answered makes
161
- * them a no-op counted in `stray`, so a server's late event cannot panic),
162
- * routing each row by its ordinal (checked first: a server's ordinal is
163
- * refused before it routes anything), and `next(run)` answers
164
- * `PG_BATCH_ROW`, then `PG_BATCH_DONE`, `PG_BATCH_MISSING` or
165
- * `PG_BATCH_FAILED`, for each request. The statement orders its rows by
166
- * ordinal, so a key's last events come as soon as a later key's row does;
167
- * with `sorted` false it does not (no Sort node, when `orderBy` is ""), rows
168
- * are answered in whatever order they come, and every last event waits for
169
- * the execution's end. It reads no clock, and the batcher
170
- * itself allocates only in its constructor (the connection's output buffer a
171
- * take writes into may still grow, up to its `maxOutput`); when to take is
172
- * the program's.
168
+ * `unnest($1) with ordinality`.
169
+ *
170
+ * `addInt` or `addText` queues a request's key and tag; `take(conn)` binds the
171
+ * oldest waiting, each distinct key once (past `PG_BATCH_PROBES` slots of its
172
+ * table probe, a key is bound again), up to `maxRequests` and `maxBytes`, and
173
+ * answers a run's handle; `row`, `end` and `fail` take that execution's events
174
+ * (a handle already answered makes them a no-op counted in `stray`, so a
175
+ * server's late event cannot panic), routing each row by its ordinal (checked
176
+ * first: a server's ordinal is refused before it routes anything), and
177
+ * `next(run)` answers `PG_BATCH_ROW`, then `PG_BATCH_DONE`, `PG_BATCH_MISSING`
178
+ * or `PG_BATCH_FAILED`, for each request.
179
+ *
180
+ * The statement orders its rows by ordinal, so a key's last events come as soon
181
+ * as a later key's row does; with `sorted` false it does not (no Sort node,
182
+ * when `orderBy` is ""), rows are answered in whatever order they come, and
183
+ * every last event waits for the execution's end. It reads no clock, and the
184
+ * batcher itself allocates only in its constructor (the connection's output
185
+ * buffer a take writes into may still grow, up to its `maxOutput`); when to
186
+ * take is the program's.
173
187
  *
174
188
  * **Batch timing.** `PgBatchClock` is one answer to when: given the time in
175
189
  * microseconds, `check(now, inFlight)` says a batch is due once
@@ -1041,16 +1055,17 @@ export class PgBinary {
1041
1055
 
1042
1056
  /**
1043
1057
  * A walk over a one-dimensional `int2[]`, `int4[]` or `int8[]` column in
1044
- * PostgreSQL's binary array layout, in place: `begin` the column, then
1045
- * `next()` until `PG_ARRAY_END` or `PG_ARRAY_BAD`, and `int()` decodes the
1046
- * current element through `binary`. The header is `ndim`, `hasnull` and the
1047
- * element OID, then for `ndim` 1 the dimension's length and lower bound (the
1048
- * bound is read and not used); each element is a length word and its bytes,
1049
- * and a NULL is a length of -1 with no bytes. `ndim` 0 is the empty array.
1050
- * Every refusal sets `binary.failed`: an `ndim` above 1, another element
1051
- * type, an element whose length is not its type's size, a NULL when
1052
- * `hasnull` is 0, a column cut short, or bytes after the last element. The
1053
- * walk allocates nothing, and it reads nothing outside the column.
1058
+ * PostgreSQL's binary array layout, in place: `begin` the column, then `next()`
1059
+ * until `PG_ARRAY_END` or `PG_ARRAY_BAD`, and `int()` decodes the current
1060
+ * element through `binary`. The header is `ndim`, `hasnull` and the element
1061
+ * OID, then for `ndim` 1 the dimension's length and lower bound (the bound is
1062
+ * read and not used); each element is a length word and its bytes, and a NULL
1063
+ * is a length of -1 with no bytes. `ndim` 0 is the empty array.
1064
+ *
1065
+ * Every refusal sets `binary.failed`: an `ndim` above 1, another element type,
1066
+ * an element whose length is not its type's size, a NULL when `hasnull` is 0, a
1067
+ * column cut short, or bytes after the last element. The walk allocates
1068
+ * nothing, and it reads nothing outside the column.
1054
1069
  */
1055
1070
  export class PgBinaryArray {
1056
1071
  /** The number of elements the header gives: 0 for an empty array. */
@@ -2612,9 +2627,9 @@ export class PgConnection {
2612
2627
  }
2613
2628
 
2614
2629
  /**
2615
- * A `text[]` parameter: every element quoted, `"` and `\` escaped, so no
2616
- * element reads as NULL (build one with `arrayNull` for that). Panics while
2617
- * an array parameter is open.
2630
+ * A `text[]` parameter: every element quoted, with each double quote and
2631
+ * backslash escaped by a backslash, so no element reads as NULL (build one
2632
+ * with `arrayNull` for that). Panics while an array parameter is open.
2618
2633
  * @param items The elements, in order; read now, not kept. Empty sends `{}`.
2619
2634
  * @returns True when it was written; false, and nothing written, as every
2620
2635
  * `param...` call is.
@@ -3755,10 +3770,13 @@ const PG_LOW32: i64 = 4294967295
3755
3770
  * The batcher's table hash of an int8 key, 31 bits: the high half times an
3756
3771
  * odd constant xored into the low half, then MurmurHash3's 32-bit finalizer,
3757
3772
  * whose unsigned multiplies wrap by definition. Every step is a bijection on
3758
- * 32 bits, so keys of one high half never collide, and the finalizer spreads
3759
- * a dense run of ids over the whole table: runs that would land on one
3760
- * another's slots under a near-identity hash do not merge into one cluster
3761
- * longer than `PG_BATCH_PROBES`.
3773
+ * 32 bits, so keys of one high half get distinct 32-bit hashes; the last
3774
+ * `>> 1` drops their lowest bit, so at most two such keys share a 31-bit hash.
3775
+ * The finalizer spreads a dense run of ids over the whole table: runs that
3776
+ * would land on one another's slots under a near-identity hash do not merge
3777
+ * into one cluster longer than `PG_BATCH_PROBES`. Keys of different high
3778
+ * halves can be built to share one hash; each costs up to
3779
+ * `PG_BATCH_PROBES` probes.
3762
3780
  */
3763
3781
  const pgIntHash = (key: i64): i32 => {
3764
3782
  const lo: u32 = toU32(key & PG_LOW32)
@@ -3872,39 +3890,41 @@ class PgBatchRun {
3872
3890
  }
3873
3891
 
3874
3892
  /**
3875
- * Batches keyed reads of one statement shape, sans-IO like `PgConnection`:
3876
- * it reads no clock and makes no socket. Each request is a key and the
3877
- * caller's `tag`, queued by `addInt` or `addText`. When a connection is free,
3878
- * `take(conn)` binds up to `maxRequests` of them, and up to `maxBytes` of
3879
- * keys, as one execution of `sql`, each distinct key once (a key whose
3880
- * probe of the batcher's table passes 1024 slots, which takes keys chosen to
3881
- * collide, is bound again and answered the same), and answers the
3882
- * execution's run handle. Each `PG_ROW` of that execution goes to
3883
- * `row(run, conn)`, its `PG_COMPLETE` to `end(run)`, and an error or a lost
3884
- * connection to `fail(run)`; after each, `next(run)` answers events until
3885
- * `PG_BATCH_NONE`, `tag` naming the request each is about. Every row goes to
3886
- * every request for its key, and every request gets one last event:
3887
- * `PG_BATCH_DONE`, `PG_BATCH_MISSING` or `PG_BATCH_FAILED`. Sorted (the
3888
- * default), rows come in key order and a key's last events come as soon as
3889
- * a later key's row does; with `sorted` false, rows come in any order, each
3890
- * answered at once, and every last event waits for `end` or `fail`, then
3891
- * comes in key order. A batch with
3892
- * `binary` set comes in binary format: its rows are read with the binary
3893
- * decoders, `binaryInt` for each ordinal, and the caller's `binary.failed`
3894
- * is left as it was.
3893
+ * Batches keyed reads of one statement shape, sans-IO like `PgConnection`: it
3894
+ * reads no clock and makes no socket. Each request is a key and the caller's
3895
+ * `tag`, queued by `addInt` or `addText`. When a connection is free,
3896
+ * `take(conn)` binds up to `maxRequests` of them, and up to `maxBytes` of keys,
3897
+ * as one execution of `sql`, each distinct key once (a key whose probe of the
3898
+ * batcher's table passes 1024 slots, which takes keys chosen to collide, is
3899
+ * bound again and answered the same), and answers the execution's run handle.
3895
3900
  *
3896
- * Nothing outlives its execution: a run is free again once the events
3897
- * `end` or `fail` owe are answered, and its handle is then spent. What the
3898
- * server or the network can send after that — a second `PG_COMPLETE`, a row
3899
- * or an error after one, a lost connection — goes to a spent handle, and
3900
- * `row`, `end` and `fail` count it in `stray` and do nothing, even once
3901
- * `take` has given the run out again under a new handle. The ordinal each
3902
- * row carries comes from the server and is checked before it routes
3903
- * anything. What panics is only the program's own misuse: a handle out of
3904
- * the range `take` can give (-1 or any negative, or `runs` * 2^20 or more),
3905
- * or `row`, `end` or `fail` before `next(run)` has answered `PG_BATCH_NONE`
3906
- * for the event before. A handle in that range that `take` never gave is
3907
- * spent like any other: counted in `stray`, not a panic.
3901
+ * Each `PG_ROW` of that execution goes to `row(run, conn)`, its `PG_COMPLETE`
3902
+ * to `end(run)`, and an error or a lost connection to `fail(run)`; after each,
3903
+ * `next(run)` answers events until `PG_BATCH_NONE`, `tag` naming the request
3904
+ * each is about. Every row goes to every request for its key, and every request
3905
+ * gets one last event: `PG_BATCH_DONE`, `PG_BATCH_MISSING` or
3906
+ * `PG_BATCH_FAILED`.
3907
+ *
3908
+ * Sorted (the default), rows come in key order and a key's last events come as
3909
+ * soon as a later key's row does; with `sorted` false, rows come in any order,
3910
+ * each answered at once, and every last event waits for `end` or `fail`, then
3911
+ * comes in key order. A batch with `binary` set comes in binary format: its
3912
+ * rows are read with the binary decoders, `binaryInt` for each ordinal, and the
3913
+ * caller's `binary.failed` is left as it was.
3914
+ *
3915
+ * Nothing outlives its execution: a run is free again once the events `end` or
3916
+ * `fail` owe are answered, and its handle is then spent. What the server or the
3917
+ * network can send after that — a second `PG_COMPLETE`, a row or an error after
3918
+ * one, a lost connection — goes to a spent handle, and `row`, `end` and `fail`
3919
+ * count it in `stray` and do nothing, even once `take` has given the run out
3920
+ * again under a new handle. The ordinal each row carries comes from the server
3921
+ * and is checked before it routes anything.
3922
+ *
3923
+ * What panics is only the program's own misuse: a handle out of the range
3924
+ * `take` can give (-1 or any negative, or `runs` * 2^20 or more), or `row`,
3925
+ * `end` or `fail` before `next(run)` has answered `PG_BATCH_NONE` for the event
3926
+ * before. A handle in that range that `take` never gave is spent like any
3927
+ * other: counted in `stray`, not a panic.
3908
3928
  */
3909
3929
  export class PgBatcher {
3910
3930
  /** The prepared statement's name. */
@@ -5136,20 +5156,21 @@ const pgPortValue = (text: string): i32 => {
5136
5156
  }
5137
5157
 
5138
5158
  /**
5139
- * The target a `postgres://` or `postgresql://` URL names, as libpq reads
5140
- * one: `postgres://[user[:password]@][host][:port][/dbname][?key=value&...]`.
5141
- * The host, the port and every query key and value are percent-decoded, so a
5142
- * socket directory is written `%2Ftmp` or passed as `?host=/tmp`; a `host` or
5143
- * `port` in the query overrides the authority's, and other keys are ignored.
5144
- * The user, password and database are not read here, but a bad escape in them
5145
- * still refuses the URL. A `%` without two hex digits after it, `%00`, or a
5146
- * part that decodes to bytes that are not UTF-8 is `PG_TARGET_BAD_ESCAPE`.
5159
+ * The target a `postgres://` or `postgresql://` URL names, as libpq reads one:
5160
+ * `postgres://[user[:password]@][host][:port][/dbname][?key=value&...]`. The
5161
+ * host, the port and every query key and value are percent-decoded, so a socket
5162
+ * directory is written `%2Ftmp` or passed as `?host=/tmp`; a `host` or `port`
5163
+ * in the query overrides the authority's, and other keys are ignored. The user,
5164
+ * password and database are not read here, but a bad escape in them still
5165
+ * refuses the URL. A `%` without two hex digits after it, `%00`, or a part that
5166
+ * decodes to bytes that are not UTF-8 is `PG_TARGET_BAD_ESCAPE`.
5167
+ *
5147
5168
  * The user information ends at the first `@`, as in libpq; a raw `@` after a
5148
- * `?` or after that first `@` in the authority, or a raw NUL byte anywhere,
5149
- * is `PG_TARGET_BAD_HOST`, as is a URL with no host anywhere, where libpq
5150
- * would use its default socket directory. An empty port or query value is
5151
- * refused, where libpq would take it as unset.
5152
- * The decoded host is then resolved as `pgTarget` resolves one.
5169
+ * `?` or after that first `@` in the authority, or a raw NUL byte anywhere, is
5170
+ * `PG_TARGET_BAD_HOST`, as is a URL with no host anywhere, where libpq would
5171
+ * use its default socket directory. An empty port or query value is refused,
5172
+ * where libpq would take it as unset. The decoded host is then resolved as
5173
+ * `pgTarget` resolves one.
5153
5174
  *
5154
5175
  * @param url The URL; any user or password it holds is not kept in the target.
5155
5176
  * @returns The target; read `failure` before anything else.
@@ -41,36 +41,39 @@
41
41
  * a callback. With `serviceWorker` set, every other worker gets a pair to that
42
42
  * worker. The ends go through `spawnWithFds`, from descriptor 3 in a fixed
43
43
  * order: the supervisor channel, then a worker's service channel, or in the
44
- * service worker its end to each other worker by index, skipping its own. Where
45
- * they landed rides in `--nish-prefork-channels=` just before the worker flag,
46
- * and `preforkSupervisorChannel`, `preforkServiceChannel` and
47
- * `preforkServiceChannelOf` read it back. A pair cannot be handed to a worker
48
- * already running, so service channels make the workers one group: when any of
49
- * them exits, the supervisor sends the rest SIGTERM (SIGKILL after `graceMs`),
50
- * and once none is left, starts them all again on fresh pairs, after the
51
- * backoff of the one that exited first. No worker keeps an end whose peer is
52
- * gone longer than that. With `restart` off nothing is signalled; a worker sees
53
- * its peer's exit as a hang-up.
44
+ * service worker its end to each other worker by index, skipping its own.
54
45
  *
55
- * **Listeners and pinning.** With `listenPort` set (0 or above), the
56
- * supervisor binds one `SO_REUSEPORT` listener per worker itself, in index
57
- * order, keeps them for its whole run and hands listener `k` to every start of
58
- * worker `k` after the channel ends; `preforkListener(args)` answers it in the
59
- * worker (`--nish-prefork-listener=`, before the channels flag), so a worker
60
- * serves that descriptor instead of binding its own. Port 0 binds the first
61
- * listener anywhere and the rest to its port. With `pin` on as well, each
62
- * listener steers by CPU (`tcpListenFlags`' flag 4): the kernel hands a
63
- * connection that arrived on CPU `k` to listener `k`, and a worker that is
64
- * restarted takes the same listener, so the order holds across restarts,
65
- * which it would not if each worker bound its own. `pin` alone makes each
66
- * worker call `setCpuAffinity(k)` before `preforkWith` answers it, so worker
67
- * `k` runs on CPU `k` only; a worker the kernel refuses (CPU `k` outside the
68
- * process's mask) says so on stderr and runs unpinned. More workers than
69
- * `availableParallelism()` is refused with a panic, since a worker past the
70
- * last CPU would be pinned nowhere and, steered, handed nothing. Pinning and
71
- * steering are Linux's: elsewhere the supervisor says once that the workers
72
- * run unpinned, and the listeners are plain `SO_REUSEPORT` ones. Both are off
73
- * by default.
46
+ * Where they landed rides in `--nish-prefork-channels=` just before the worker
47
+ * flag, and `preforkSupervisorChannel`, `preforkServiceChannel` and
48
+ * `preforkServiceChannelOf` read it back. A pair cannot be handed to a worker
49
+ * already running, so service channels make the workers one group: when any of
50
+ * them exits, the supervisor sends the rest SIGTERM (SIGKILL after `graceMs`),
51
+ * and once none is left, starts them all again on fresh pairs, after the
52
+ * backoff of the one that exited first. No worker keeps an end whose peer is
53
+ * gone longer than that. With `restart` off nothing is signalled; a worker sees
54
+ * its peer's exit as a hang-up.
55
+ *
56
+ * **Listeners and pinning.** With `listenPort` set (0 or above), the supervisor
57
+ * binds one `SO_REUSEPORT` listener per worker itself, in index order, keeps
58
+ * them for its whole run and hands listener `k` to every start of worker `k`
59
+ * after the channel ends; `preforkListener(args)` answers it in the worker
60
+ * (`--nish-prefork-listener=`, before the channels flag), so a worker serves
61
+ * that descriptor instead of binding its own. Port 0 binds the first listener
62
+ * anywhere and the rest to its port.
63
+ *
64
+ * With `pin` on as well, each listener steers by CPU (`tcpListenFlags`' flag
65
+ * 4): the kernel hands a connection that arrived on CPU `k` to listener `k`,
66
+ * and a worker that is restarted takes the same listener, so the order holds
67
+ * across restarts, which it would not if each worker bound its own. `pin` alone
68
+ * makes each worker call `setCpuAffinity(k)` before `preforkWith` answers it,
69
+ * so worker `k` runs on CPU `k` only; a worker the kernel refuses (CPU `k`
70
+ * outside the process's mask) says so on stderr and runs unpinned.
71
+ *
72
+ * More workers than `availableParallelism()` is refused with a panic, since a
73
+ * worker past the last CPU would be pinned nowhere and, steered, handed
74
+ * nothing. Pinning and steering are Linux's: elsewhere the supervisor says once
75
+ * that the workers run unpinned, and the listeners are plain `SO_REUSEPORT`
76
+ * ones. Both are off by default.
74
77
  *
75
78
  * **How many.** `NISH_WORKERS` when it is a positive whole number, else
76
79
  * `PreforkConfig.workers` when that is positive, else
@@ -908,11 +911,12 @@ export const preforkWith = (args: string[], config: PreforkConfig): i32 => {
908
911
  * error. The callback reads what is waiting, since an end left readable wakes
909
912
  * the loop again at once, and may write back, but never closes `fd`: the
910
913
  * supervisor closes it after a hang-up, when the worker is reaped and when it
911
- * stops, and a restarted worker comes with a new one. Panics, besides, when
912
- * `serviceWorker` is not below the worker count or the count is above 64 with
913
- * a service worker (63 with `listenPort`), the most `spawnWithFds` hands one
914
- * child; when `pin`, on Linux, asks for more workers than
915
- * `availableParallelism()`; and, through `preforkInvalid`, on seqpacket
914
+ * stops, and a restarted worker comes with a new one.
915
+ *
916
+ * Panics, besides, when `serviceWorker` is not below the worker count or the
917
+ * count is above 64 with a service worker (63 with `listenPort`), the most
918
+ * `spawnWithFds` hands one child; when `pin`, on Linux, asks for more workers
919
+ * than `availableParallelism()`; and, through `preforkInvalid`, on seqpacket
916
920
  * channels off Linux. A listener that cannot bind answers
917
921
  * `PREFORK_SPAWN_FAILED` before any worker starts.
918
922
  *
package/std/net/qpack.ts CHANGED
@@ -31,20 +31,21 @@
31
31
  * block on (§2.1.2) and nothing to acknowledge (§4.4.1).
32
32
  *
33
33
  * **What is refused.** `QpackDecoder.decode` answers QPACK_DECOMPRESSION_FAILED
34
- * for a section that ends inside a representation, an integer past 2^62 - 1
35
- * (or padded past the nine continuation bytes such an integer needs), a
36
- * non-zero Required Insert Count (§4.5.1.1), a negative Base (§4.5.1.2), any
37
- * reference to the dynamic table, relative or post-Base (§2.2.3), a static
38
- * index past 98, and Huffman padding that is not EOS's prefix or an EOS inside
39
- * a string. `receiveEncoderStream` answers QPACK_ENCODER_STREAM_ERROR for a Set
40
- * Dynamic Table Capacity above 0 (§4.3.1), any Insert (§3.2.2: every entry is
41
- * larger than the table) and any Duplicate (§2.2.3: there is nothing to
42
- * duplicate). The encoder's `receiveDecoderStream` answers
43
- * QPACK_DECODER_STREAM_ERROR for a Section Acknowledgment (§4.4.1: no section
44
- * it sent needs one), any Insert Count Increment (§4.4.3: it has inserted
45
- * nothing) and a stream ID past 2^62 - 1. Each of those is a connection error,
46
- * so each is sticky: the same answer comes back from every later call without
47
- * reading anything, and `reason` says which rule it was (`QPACK_REASON_*`).
34
+ * for a section that ends inside a representation, an integer past 2^62 - 1 (or
35
+ * padded past the nine continuation bytes such an integer needs), a non-zero
36
+ * Required Insert Count (§4.5.1.1), a negative Base (§4.5.1.2), any reference
37
+ * to the dynamic table, relative or post-Base (§2.2.3), a static index past 98,
38
+ * and Huffman padding that is not EOS's prefix or an EOS inside a string.
39
+ *
40
+ * `receiveEncoderStream` answers QPACK_ENCODER_STREAM_ERROR for a Set Dynamic
41
+ * Table Capacity above 0 (§4.3.1), any Insert (§3.2.2: every entry is larger
42
+ * than the table) and any Duplicate (§2.2.3: there is nothing to duplicate).
43
+ * The encoder's `receiveDecoderStream` answers QPACK_DECODER_STREAM_ERROR for a
44
+ * Section Acknowledgment (§4.4.1: no section it sent needs one), any Insert
45
+ * Count Increment (§4.4.3: it has inserted nothing) and a stream ID past
46
+ * 2^62 - 1. Each of those is a connection error, so each is sticky: the same answer
47
+ * comes back from every later call without reading anything, and `reason` says
48
+ * which rule it was (`QPACK_REASON_*`).
48
49
  *
49
50
  * **What is accepted.** A Set Dynamic Table Capacity of 0 on the encoder
50
51
  * stream, and a Stream Cancellation on the decoder stream, read a byte at a
@@ -47,6 +47,7 @@ export class QuicAckRanges {
47
47
  /** Every packet number at or below this is answered as already received; -1 until a range is dropped. */
48
48
  floor: i64 = -1
49
49
  private ranges: i64[]
50
+ /** How many disjoint ranges are held, at most `QUIC_ACK_MAX_RANGES`. */
50
51
  count: i32 = 0
51
52
  /** Whether an ack-eliciting packet arrived since the last `pushAck`. */
52
53
  ackPending: boolean = false