@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.
- package/INSTALL.md +67 -58
- package/bin/nish +0 -0
- package/docs/AI.md +43 -4
- package/package.json +1 -1
- package/runtime/async.d.mts +2 -0
- package/runtime/async.mjs +7 -0
- package/runtime/nish.d.ts +736 -499
- package/runtime/nish.h +25 -0
- package/runtime/page.d.ts +53 -0
- package/runtime/page.mjs +146 -0
- package/runtime/runtime-async.c +557 -0
- package/runtime/runtime-wasm.c +63 -7
- package/scripts/build.sh +147 -5
- package/std/README.md +107 -82
- package/std/bytes.ts +23 -19
- package/std/compress/checksum.ts +1 -1
- package/std/crypto/aes.ts +48 -43
- package/std/crypto/base64url.ts +7 -5
- package/std/crypto/bcrypt-batch.ts +13 -13
- package/std/crypto/bcrypt.ts +33 -27
- package/std/crypto/chacha20poly1305.ts +16 -14
- package/std/crypto/ed25519.ts +19 -16
- package/std/crypto/hmac.ts +7 -6
- package/std/crypto/jwt.ts +23 -20
- package/std/crypto/p256.ts +63 -56
- package/std/crypto/p384.ts +23 -20
- package/std/crypto/pki.ts +18 -15
- package/std/crypto/rsa.ts +23 -19
- package/std/crypto/x25519.ts +11 -10
- package/std/crypto/x509.ts +69 -62
- package/std/host/ring.ts +124 -0
- package/std/json-equal.ts +12 -11
- package/std/json-number.ts +12 -12
- package/std/json-tokenizer.ts +26 -22
- package/std/json-typed.ts +92 -78
- package/std/json-value.ts +38 -33
- package/std/json.ts +32 -28
- package/std/net/fetch.ts +1117 -230
- package/std/net/handler.ts +18 -0
- package/std/net/hpack.ts +29 -26
- package/std/net/http-compress.ts +27 -21
- package/std/net/http1-client-codec.ts +29 -25
- package/std/net/http1-codec.ts +44 -87
- package/std/net/http1-server.ts +66 -54
- package/std/net/http2-frame.ts +17 -16
- package/std/net/http2-tls.ts +17 -15
- package/std/net/http2.ts +67 -54
- package/std/net/http3-frame.ts +11 -10
- package/std/net/http3-server.ts +36 -35
- package/std/net/http3.ts +70 -58
- package/std/net/postgres.ts +178 -160
- package/std/net/prefork.ts +38 -34
- package/std/net/qpack.ts +15 -14
- package/std/net/quic-conn-ack.ts +1 -0
- package/std/net/quic-conn-cid.ts +11 -0
- package/std/net/quic-conn-params.ts +41 -14
- package/std/net/quic-datagram.ts +7 -0
- package/std/net/quic-frame.ts +48 -12
- package/std/net/quic-listener.ts +61 -44
- package/std/net/quic-packet.ts +71 -52
- package/std/net/quic-recovery.ts +59 -21
- package/std/net/quic-stream.ts +83 -55
- package/std/net/quic.ts +204 -152
- package/std/net/tls/client.ts +1 -0
- package/std/net/tls/codec.ts +81 -12
- package/std/net/tls/record-client.ts +30 -18
- package/std/net/tls/record-server.ts +74 -46
- package/std/net/tls/record.ts +33 -24
- package/std/net/tls/ticket.ts +2 -0
- package/std/net/tls/verify.ts +8 -7
- package/std/net/tls-tcp.ts +58 -50
- package/std/net/tls.ts +55 -43
- package/std/net/url.ts +12 -9
- package/std/net/websocket.ts +23 -19
- package/std/net/webtransport.ts +24 -18
- package/std/random.ts +8 -6
- package/std/regex.ts +70 -59
- package/std/sync/ring.ts +24 -21
- package/std/sync/shm.ts +9 -7
- package/std/term-io.ts +17 -14
- package/std/term-probe.ts +11 -10
- package/std/term-rate.ts +71 -61
- package/std/term.ts +73 -59
- package/std/text.ts +11 -10
- package/std/threads.ts +19 -15
- package/std/yaml-json.ts +17 -15
- 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.**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
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.**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* a
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
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
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* draft-
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
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.
|
package/std/net/postgres.ts
CHANGED
|
@@ -30,18 +30,22 @@
|
|
|
30
30
|
* event = conn.next();
|
|
31
31
|
* }
|
|
32
32
|
*
|
|
33
|
-
* **Events.**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* (`
|
|
40
|
-
*
|
|
41
|
-
* `
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
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
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
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
|
-
*
|
|
84
|
-
* benchmark (`bench/postgres/arrays.mjs`) measured at about a tenth of the
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* `
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
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
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* `
|
|
101
|
-
* `
|
|
102
|
-
*
|
|
103
|
-
*
|
|
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
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
* `
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
* as
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
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.
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* `
|
|
133
|
-
*
|
|
134
|
-
*
|
|
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)`.
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
* `
|
|
147
|
-
*
|
|
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`.
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
* `
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
* the
|
|
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
|
-
*
|
|
1046
|
-
*
|
|
1047
|
-
*
|
|
1048
|
-
*
|
|
1049
|
-
*
|
|
1050
|
-
*
|
|
1051
|
-
*
|
|
1052
|
-
*
|
|
1053
|
-
*
|
|
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,
|
|
2616
|
-
* element reads as NULL (build one
|
|
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
|
-
*
|
|
3877
|
-
*
|
|
3878
|
-
* `take(conn)` binds up to `maxRequests` of them, and up to `maxBytes` of
|
|
3879
|
-
*
|
|
3880
|
-
*
|
|
3881
|
-
*
|
|
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
|
-
*
|
|
3897
|
-
* `end
|
|
3898
|
-
*
|
|
3899
|
-
*
|
|
3900
|
-
*
|
|
3901
|
-
* `
|
|
3902
|
-
*
|
|
3903
|
-
*
|
|
3904
|
-
*
|
|
3905
|
-
*
|
|
3906
|
-
*
|
|
3907
|
-
*
|
|
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
|
-
*
|
|
5141
|
-
*
|
|
5142
|
-
*
|
|
5143
|
-
*
|
|
5144
|
-
*
|
|
5145
|
-
*
|
|
5146
|
-
*
|
|
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
|
-
*
|
|
5150
|
-
*
|
|
5151
|
-
*
|
|
5152
|
-
*
|
|
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.
|