@amritk/nish-aarch64-linux 0.36.0 → 0.37.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 (87) hide show
  1. package/INSTALL.md +67 -58
  2. package/bin/nish +0 -0
  3. package/docs/AI.md +43 -4
  4. package/package.json +1 -1
  5. package/runtime/async.d.mts +2 -0
  6. package/runtime/async.mjs +7 -0
  7. package/runtime/nish.d.ts +736 -499
  8. package/runtime/nish.h +25 -0
  9. package/runtime/page.d.ts +53 -0
  10. package/runtime/page.mjs +146 -0
  11. package/runtime/runtime-async.c +557 -0
  12. package/runtime/runtime-wasm.c +63 -7
  13. package/scripts/build.sh +147 -5
  14. package/std/README.md +107 -82
  15. package/std/bytes.ts +23 -19
  16. package/std/compress/checksum.ts +1 -1
  17. package/std/crypto/aes.ts +48 -43
  18. package/std/crypto/base64url.ts +7 -5
  19. package/std/crypto/bcrypt-batch.ts +13 -13
  20. package/std/crypto/bcrypt.ts +33 -27
  21. package/std/crypto/chacha20poly1305.ts +16 -14
  22. package/std/crypto/ed25519.ts +19 -16
  23. package/std/crypto/hmac.ts +7 -6
  24. package/std/crypto/jwt.ts +23 -20
  25. package/std/crypto/p256.ts +63 -56
  26. package/std/crypto/p384.ts +23 -20
  27. package/std/crypto/pki.ts +18 -15
  28. package/std/crypto/rsa.ts +23 -19
  29. package/std/crypto/x25519.ts +11 -10
  30. package/std/crypto/x509.ts +69 -62
  31. package/std/host/ring.ts +124 -0
  32. package/std/json-equal.ts +12 -11
  33. package/std/json-number.ts +12 -12
  34. package/std/json-tokenizer.ts +26 -22
  35. package/std/json-typed.ts +92 -78
  36. package/std/json-value.ts +38 -33
  37. package/std/json.ts +32 -28
  38. package/std/net/fetch.ts +1117 -230
  39. package/std/net/handler.ts +18 -0
  40. package/std/net/hpack.ts +29 -26
  41. package/std/net/http-compress.ts +27 -21
  42. package/std/net/http1-client-codec.ts +29 -25
  43. package/std/net/http1-codec.ts +44 -87
  44. package/std/net/http1-server.ts +66 -54
  45. package/std/net/http2-frame.ts +17 -16
  46. package/std/net/http2-tls.ts +17 -15
  47. package/std/net/http2.ts +67 -54
  48. package/std/net/http3-frame.ts +11 -10
  49. package/std/net/http3-server.ts +36 -35
  50. package/std/net/http3.ts +70 -58
  51. package/std/net/postgres.ts +178 -160
  52. package/std/net/prefork.ts +38 -34
  53. package/std/net/qpack.ts +15 -14
  54. package/std/net/quic-conn-ack.ts +1 -0
  55. package/std/net/quic-conn-cid.ts +11 -0
  56. package/std/net/quic-conn-params.ts +41 -14
  57. package/std/net/quic-datagram.ts +7 -0
  58. package/std/net/quic-frame.ts +48 -12
  59. package/std/net/quic-listener.ts +61 -44
  60. package/std/net/quic-packet.ts +71 -52
  61. package/std/net/quic-recovery.ts +59 -21
  62. package/std/net/quic-stream.ts +83 -55
  63. package/std/net/quic.ts +204 -152
  64. package/std/net/tls/client.ts +1 -0
  65. package/std/net/tls/codec.ts +81 -12
  66. package/std/net/tls/record-client.ts +30 -18
  67. package/std/net/tls/record-server.ts +74 -46
  68. package/std/net/tls/record.ts +33 -24
  69. package/std/net/tls/ticket.ts +2 -0
  70. package/std/net/tls/verify.ts +8 -7
  71. package/std/net/tls-tcp.ts +58 -50
  72. package/std/net/tls.ts +55 -43
  73. package/std/net/url.ts +12 -9
  74. package/std/net/websocket.ts +23 -19
  75. package/std/net/webtransport.ts +24 -18
  76. package/std/random.ts +8 -6
  77. package/std/regex.ts +70 -59
  78. package/std/sync/ring.ts +24 -21
  79. package/std/sync/shm.ts +9 -7
  80. package/std/term-io.ts +17 -14
  81. package/std/term-probe.ts +11 -10
  82. package/std/term-rate.ts +71 -61
  83. package/std/term.ts +73 -59
  84. package/std/text.ts +11 -10
  85. package/std/threads.ts +19 -15
  86. package/std/yaml-json.ts +17 -15
  87. package/std/yaml-write.ts +21 -14
package/std/net/http3.ts CHANGED
@@ -38,19 +38,24 @@
38
38
  * }
39
39
  * }
40
40
  *
41
- * **Events.** `next()` reads the streams the QUIC connection has news for and
42
- * answers the first thing that means something to the program: `H3_REQUEST`
43
- * (a request's field section, in `fields`), `H3_DATA` (a piece of its body, a
44
- * window onto `data` valid until the next call), `H3_TRAILERS`, `H3_END` (the
45
- * request ended, and its `content-length`, if any, matched), `H3_RESET` (the
46
- * stream is gone: the client reset it or stopped it, or it broke a rule that
47
- * resets it — `errorCode` says which, `resetByPeer` who), `H3_WRITABLE` (a
48
- * stream whose write was held back can take more), `H3_GOAWAY` (the client is
49
- * going away; `lastStreamId` is its push ID), and `H3_ERROR`, final: the
50
- * connection broke a rule, it is closed with `errorCode`, and every later call
51
- * answers it again. `H3_NEED_MORE` asks for more datagrams. A request's events
52
- * come in order — REQUEST, DATA…, TRAILERS, END — and after `H3_RESET` its
53
- * stream has no more.
41
+ * **Events.**
42
+ *
43
+ * `next()` reads the streams the QUIC connection has news for and answers the
44
+ * first thing that means something to the program:
45
+ * - `H3_REQUEST` (a request's field section, in `fields`),
46
+ * - `H3_DATA` (a piece of its body, a window onto `data` valid until the next
47
+ * call),
48
+ * - `H3_TRAILERS`,
49
+ * - `H3_END` (the request ended, and its `content-length`, if any, matched),
50
+ * - `H3_RESET` (the stream is gone: the client reset it or stopped it, or it
51
+ * broke a rule that resets it — `errorCode` says which, `resetByPeer` who),
52
+ * - `H3_WRITABLE` (a stream whose write was held back can take more),
53
+ * - `H3_GOAWAY` (the client is going away; `lastStreamId` is its push ID),
54
+ * - and `H3_ERROR`, final: the connection broke a rule, it is closed with
55
+ * `errorCode`, and every later call answers it again.
56
+ *
57
+ * `H3_NEED_MORE` asks for more datagrams. A request's events come in order —
58
+ * REQUEST, DATA…, TRAILERS, END — and after `H3_RESET` its stream has no more.
54
59
  *
55
60
  * **Back-pressure** is QUIC's flow control. A body is read only as the
56
61
  * program calls `next()`, `bodyChunk` bytes at most at a time, and QUIC gives
@@ -71,29 +76,34 @@
71
76
  * A unidirectional stream of a type it does not know is asked to stop
72
77
  * (H3_STREAM_CREATION_ERROR) and read to its end (§6.2).
73
78
  *
74
- * **What it refuses.** A connection error closes the QUIC connection with
75
- * the code: a second control, encoder or decoder stream, or a push stream
76
- * from a client (H3_STREAM_CREATION_ERROR, §6.2.1, §6.2.2); a control stream
77
- * whose first frame is not SETTINGS (H3_MISSING_SETTINGS); the end, reset or
78
- * STOP_SENDING of any critical stream, either side's (H3_CLOSED_CRITICAL_STREAM);
79
- * a frame where it may not be — DATA or HEADERS on the control stream, a
80
- * control frame on a request stream, a second SETTINGS, DATA before HEADERS,
81
- * anything but the end after trailers, any PUSH_PROMISE from a client, and an
82
- * HTTP/2 type HTTP/3 reserves (H3_FRAME_UNEXPECTED, §7.2.8); a frame cut off
83
- * by its stream's end or a payload of the wrong length (H3_FRAME_ERROR, §7.1);
84
- * a SETTINGS frame `nish/net/http3-frame` refuses (H3_SETTINGS_ERROR); a
85
- * GOAWAY whose push ID rose, a MAX_PUSH_ID that fell, a CANCEL_PUSH past the
86
- * push IDs allowed (H3_ID_ERROR, §5.2, §7.2.7, §7.2.3); a control frame past
87
- * `H3_CONTROL_FRAME_MAX` (H3_EXCESSIVE_LOAD); and QPACK's three. A stream
88
- * error resets one request, both ways, and the connection lives: a field
89
- * section `nish/net/http-fields` refuses, and a body that disagrees with
90
- * `content-length` (H3_MESSAGE_ERROR, §4.1.2); a request stream that ends
91
- * before its HEADERS (H3_REQUEST_INCOMPLETE, §4.1.1); a request on a stream at
92
- * or past the ID of the GOAWAY this side sent (H3_REQUEST_REJECTED, §5.2).
93
- * A request whose field section is longer than `maxFieldSectionSize` — the
94
- * frame, or the section once decoded — is answered with a 431, never reaches
95
- * the program, and its stream is asked to stop with H3_NO_ERROR (§4.2.2,
96
- * §4.1.2).
79
+ * **What it refuses.**
80
+ *
81
+ * A connection error closes the QUIC connection with the code:
82
+ * - a second control, encoder or decoder stream, or a push stream from a client
83
+ * (H3_STREAM_CREATION_ERROR, §6.2.1, §6.2.2);
84
+ * - a control stream whose first frame is not SETTINGS (H3_MISSING_SETTINGS);
85
+ * - the end, reset or STOP_SENDING of any critical stream, either side's
86
+ * (H3_CLOSED_CRITICAL_STREAM);
87
+ * - a frame where it may not be — DATA or HEADERS on the control stream, a
88
+ * control frame on a request stream, a second SETTINGS, DATA before HEADERS,
89
+ * anything but the end after trailers, any PUSH_PROMISE from a client, and an
90
+ * HTTP/2 type HTTP/3 reserves (H3_FRAME_UNEXPECTED, §7.2.8);
91
+ * - a frame cut off by its stream's end or a payload of the wrong length
92
+ * (H3_FRAME_ERROR, §7.1);
93
+ * - a SETTINGS frame `nish/net/http3-frame` refuses (H3_SETTINGS_ERROR);
94
+ * - a GOAWAY whose push ID rose, a MAX_PUSH_ID that fell, a CANCEL_PUSH past
95
+ * the push IDs allowed (H3_ID_ERROR, §5.2, §7.2.7, §7.2.3);
96
+ * - a control frame past `H3_CONTROL_FRAME_MAX` (H3_EXCESSIVE_LOAD);
97
+ * - and QPACK's three.
98
+ *
99
+ * A stream error resets one request, both ways, and the connection lives: a
100
+ * field section `nish/net/http-fields` refuses, and a body that disagrees with
101
+ * `content-length` (H3_MESSAGE_ERROR, §4.1.2); a request stream that ends
102
+ * before its HEADERS (H3_REQUEST_INCOMPLETE, §4.1.1); a request on a stream at
103
+ * or past the ID of the GOAWAY this side sent (H3_REQUEST_REJECTED, §5.2). A
104
+ * request whose field section is longer than `maxFieldSectionSize` — the frame,
105
+ * or the section once decoded — is answered with a 431, never reaches the
106
+ * program, and its stream is asked to stop with H3_NO_ERROR (§4.2.2, §4.1.2).
97
107
  *
98
108
  * **No server push.** It never sends PUSH_PROMISE; a client's MAX_PUSH_ID is
99
109
  * allowed, checked and ignored.
@@ -109,28 +119,30 @@
109
119
  * counters saturate, and the lookup of a stream's state is the QUIC
110
120
  * connection's own hash index (`QuicStreams.slotOf`), never a scan.
111
121
  *
112
- * **Extended CONNECT and WebTransport.** With `extendedConnect` the
113
- * connection sends SETTINGS_ENABLE_CONNECT_PROTOCOL 1 and a request may carry
114
- * `:protocol` (RFC 9220); without it `:protocol` is malformed,
115
- * H3_MESSAGE_ERROR. `webtransportSessions` above 0 turns that on and also
116
- * sends SETTINGS_H3_DATAGRAM 1, draft-02's SETTINGS_ENABLE_WEBTRANSPORT 1 and
117
- * draft-07's SETTINGS_WEBTRANSPORT_MAX_SESSIONS, and `nish/net/webtransport`
118
- * runs its sessions on top: a request then waits for the client's SETTINGS
119
- * (draft-02 §3.1), and a stream that opens with WebTransport's unidirectional
120
- * type (0x54) or bidirectional signal (0x41) is read as far as its session ID,
121
- * held unread and named in `H3_STREAM` until the program calls
122
- * `acceptStream` (its bytes then come as H3_DATA, H3_END, H3_RESET and
123
- * H3_STOPPED, and `writeStream` writes them as they are) or `refuseStream`.
124
- * `openStream` opens one of this side's; `writeDataWhole` writes a capsule;
125
- * a GOAWAY still lets a session's new stream in, and `H3_DROPPED` names a
126
- * request stream that ended before its request reached the program. The
127
- * client's SETTINGS_ENABLE_CONNECT_PROTOCOL and SETTINGS_H3_DATAGRAM must be
128
- * 0 or 1 (H3_SETTINGS_ERROR), a session ID that is no client-initiated
129
- * bidirectional stream is H3_ID_ERROR, and the signal anywhere but a stream's
130
- * start is H3_FRAME_ERROR. Holding every request, not only an extended
131
- * CONNECT, until the client's SETTINGS keeps a decoded field section from
132
- * having to be held per stream; it costs a request only when the client's
133
- * control stream is lost or reordered.
122
+ * **Extended CONNECT and WebTransport.** With `extendedConnect` the connection
123
+ * sends SETTINGS_ENABLE_CONNECT_PROTOCOL 1 and a request may carry `:protocol`
124
+ * (RFC 9220); without it `:protocol` is malformed, H3_MESSAGE_ERROR.
125
+ *
126
+ * `webtransportSessions` above 0 turns that on and also sends
127
+ * SETTINGS_H3_DATAGRAM 1, draft-02's SETTINGS_ENABLE_WEBTRANSPORT 1 and
128
+ * draft-07's SETTINGS_WEBTRANSPORT_MAX_SESSIONS, and `nish/net/webtransport`
129
+ * runs its sessions on top: a request then waits for the client's SETTINGS
130
+ * (draft-02 §3.1), and a stream that opens with WebTransport's unidirectional
131
+ * type (0x54) or bidirectional signal (0x41) is read as far as its session ID,
132
+ * held unread and named in `H3_STREAM` until the program calls `acceptStream`
133
+ * (its bytes then come as H3_DATA, H3_END, H3_RESET and H3_STOPPED, and
134
+ * `writeStream` writes them as they are) or `refuseStream`.
135
+ *
136
+ * `openStream` opens one of this side's; `writeDataWhole` writes a capsule; a
137
+ * GOAWAY still lets a session's new stream in, and `H3_DROPPED` names a request
138
+ * stream that ended before its request reached the program. The client's
139
+ * SETTINGS_ENABLE_CONNECT_PROTOCOL and SETTINGS_H3_DATAGRAM must be 0 or 1
140
+ * (H3_SETTINGS_ERROR), a session ID that is no client-initiated bidirectional
141
+ * stream is H3_ID_ERROR, and the signal anywhere but a stream's start is
142
+ * H3_FRAME_ERROR. Holding every request, not only an extended CONNECT, until
143
+ * the client's SETTINGS keeps a decoded field section from having to be held
144
+ * per stream; it costs a request only when the client's control stream is lost
145
+ * or reordered.
134
146
  *
135
147
  * Private helpers share the importing program's flat symbol namespace
136
148
  * (`docs/wp26-stdlib.md` §3e), which is why each one carries the module's name.
@@ -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.
@@ -3872,39 +3887,41 @@ class PgBatchRun {
3872
3887
  }
3873
3888
 
3874
3889
  /**
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.
3890
+ * Batches keyed reads of one statement shape, sans-IO like `PgConnection`: it
3891
+ * reads no clock and makes no socket. Each request is a key and the caller's
3892
+ * `tag`, queued by `addInt` or `addText`. When a connection is free,
3893
+ * `take(conn)` binds up to `maxRequests` of them, and up to `maxBytes` of keys,
3894
+ * as one execution of `sql`, each distinct key once (a key whose probe of the
3895
+ * batcher's table passes 1024 slots, which takes keys chosen to collide, is
3896
+ * bound again and answered the same), and answers the execution's run handle.
3895
3897
  *
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.
3898
+ * Each `PG_ROW` of that execution goes to `row(run, conn)`, its `PG_COMPLETE`
3899
+ * to `end(run)`, and an error or a lost connection to `fail(run)`; after each,
3900
+ * `next(run)` answers events until `PG_BATCH_NONE`, `tag` naming the request
3901
+ * each is about. Every row goes to every request for its key, and every request
3902
+ * gets one last event: `PG_BATCH_DONE`, `PG_BATCH_MISSING` or
3903
+ * `PG_BATCH_FAILED`.
3904
+ *
3905
+ * Sorted (the default), rows come in key order and a key's last events come as
3906
+ * soon as a later key's row does; with `sorted` false, rows come in any order,
3907
+ * each answered at once, and every last event waits for `end` or `fail`, then
3908
+ * comes in key order. A batch with `binary` set comes in binary format: its
3909
+ * rows are read with the binary decoders, `binaryInt` for each ordinal, and the
3910
+ * caller's `binary.failed` is left as it was.
3911
+ *
3912
+ * Nothing outlives its execution: a run is free again once the events `end` or
3913
+ * `fail` owe are answered, and its handle is then spent. What the server or the
3914
+ * network can send after that — a second `PG_COMPLETE`, a row or an error after
3915
+ * one, a lost connection — goes to a spent handle, and `row`, `end` and `fail`
3916
+ * count it in `stray` and do nothing, even once `take` has given the run out
3917
+ * again under a new handle. The ordinal each row carries comes from the server
3918
+ * and is checked before it routes anything.
3919
+ *
3920
+ * What panics is only the program's own misuse: a handle out of the range
3921
+ * `take` can give (-1 or any negative, or `runs` * 2^20 or more), or `row`,
3922
+ * `end` or `fail` before `next(run)` has answered `PG_BATCH_NONE` for the event
3923
+ * before. A handle in that range that `take` never gave is spent like any
3924
+ * other: counted in `stray`, not a panic.
3908
3925
  */
3909
3926
  export class PgBatcher {
3910
3927
  /** The prepared statement's name. */
@@ -5136,20 +5153,21 @@ const pgPortValue = (text: string): i32 => {
5136
5153
  }
5137
5154
 
5138
5155
  /**
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`.
5156
+ * The target a `postgres://` or `postgresql://` URL names, as libpq reads one:
5157
+ * `postgres://[user[:password]@][host][:port][/dbname][?key=value&...]`. The
5158
+ * host, the port and every query key and value are percent-decoded, so a socket
5159
+ * directory is written `%2Ftmp` or passed as `?host=/tmp`; a `host` or `port`
5160
+ * in the query overrides the authority's, and other keys are ignored. The user,
5161
+ * password and database are not read here, but a bad escape in them still
5162
+ * refuses the URL. A `%` without two hex digits after it, `%00`, or a part that
5163
+ * decodes to bytes that are not UTF-8 is `PG_TARGET_BAD_ESCAPE`.
5164
+ *
5147
5165
  * 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.
5166
+ * `?` or after that first `@` in the authority, or a raw NUL byte anywhere, is
5167
+ * `PG_TARGET_BAD_HOST`, as is a URL with no host anywhere, where libpq would
5168
+ * use its default socket directory. An empty port or query value is refused,
5169
+ * where libpq would take it as unset. The decoded host is then resolved as
5170
+ * `pgTarget` resolves one.
5153
5171
  *
5154
5172
  * @param url The URL; any user or password it holds is not kept in the target.
5155
5173
  * @returns The target; read `failure` before anything else.