@amritk/nish-aarch64-linux 0.35.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 +73 -59
- package/bin/nish +0 -0
- package/docs/AI.md +50 -4
- package/package.json +1 -1
- package/runtime/async.d.mts +2 -0
- package/runtime/async.mjs +7 -0
- package/runtime/nish.d.ts +4849 -430
- 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/runtime/vite.d.ts +30 -0
- package/runtime/vite.mjs +150 -0
- package/scripts/build.sh +252 -15
- package/std/README.md +107 -82
- package/std/base64.ts +34 -5
- package/std/bytes.ts +279 -59
- package/std/cli-args.ts +296 -70
- package/std/cli-flags.ts +184 -19
- package/std/cli.ts +475 -54
- package/std/collections.ts +121 -23
- package/std/compress/checksum.ts +44 -14
- package/std/compress/deflate.ts +224 -111
- package/std/compress/gzip.ts +217 -53
- package/std/compress/zlib.ts +63 -7
- package/std/crypto/aes.ts +128 -52
- package/std/crypto/base64url.ts +29 -5
- package/std/crypto/bcrypt-batch.ts +101 -34
- package/std/crypto/bcrypt.ts +93 -27
- package/std/crypto/chacha20poly1305.ts +69 -14
- package/std/crypto/ct.ts +32 -13
- package/std/crypto/ed25519.ts +66 -16
- package/std/crypto/hkdf.ts +198 -13
- package/std/crypto/hmac.ts +242 -37
- package/std/crypto/jwt.ts +204 -72
- package/std/crypto/p256.ts +222 -72
- package/std/crypto/p384.ts +51 -23
- package/std/crypto/pki-roots.ts +32 -2
- package/std/crypto/pki.ts +99 -30
- package/std/crypto/rsa.ts +56 -22
- package/std/crypto/sha1.ts +3 -0
- package/std/crypto/sha256.ts +24 -1
- package/std/crypto/sha512.ts +99 -14
- package/std/crypto/x25519.ts +163 -24
- package/std/crypto/x509-random.ts +10 -0
- package/std/crypto/x509.ts +133 -66
- package/std/host/ring.ts +124 -0
- package/std/json-equal.ts +31 -11
- package/std/json-format.ts +112 -13
- package/std/json-number.ts +76 -26
- package/std/json-pointer.ts +23 -1
- package/std/json-tokenizer.ts +126 -51
- package/std/json-typed.ts +757 -96
- package/std/json-value.ts +438 -157
- package/std/json.ts +170 -38
- package/std/map.ts +25 -7
- package/std/math.ts +36 -4
- package/std/net/buffer-pool.ts +42 -11
- package/std/net/dns-config.ts +109 -23
- package/std/net/dns-message.ts +62 -7
- package/std/net/dns-resolver.ts +247 -53
- package/std/net/dns.ts +203 -35
- package/std/net/fetch.ts +1267 -290
- package/std/net/handler.ts +296 -80
- package/std/net/hpack.ts +290 -77
- package/std/net/http-compress.ts +152 -36
- package/std/net/http-fields.ts +85 -9
- package/std/net/http1-client-codec.ts +129 -44
- package/std/net/http1-codec.ts +279 -114
- package/std/net/http1-server.ts +409 -139
- package/std/net/http2-frame.ts +289 -51
- package/std/net/http2-tls.ts +152 -49
- package/std/net/http2.ts +314 -160
- package/std/net/http3-frame.ts +165 -27
- package/std/net/http3-server.ts +282 -131
- package/std/net/http3.ts +377 -173
- package/std/net/outbound.ts +37 -3
- package/std/net/postgres-carrier.ts +144 -8
- package/std/net/postgres.ts +898 -260
- package/std/net/prefork.ts +202 -65
- package/std/net/qpack.ts +120 -32
- package/std/net/quic-conn-ack.ts +60 -12
- package/std/net/quic-conn-cid.ts +135 -27
- package/std/net/quic-conn-params.ts +109 -22
- package/std/net/quic-datagram.ts +50 -3
- package/std/net/quic-frame.ts +333 -23
- package/std/net/quic-listener.ts +161 -75
- package/std/net/quic-packet.ts +373 -73
- package/std/net/quic-recovery.ts +287 -65
- package/std/net/quic-stream.ts +436 -146
- package/std/net/quic.ts +693 -323
- package/std/net/router.ts +87 -40
- package/std/net/tls/client.ts +167 -51
- package/std/net/tls/codec.ts +494 -68
- package/std/net/tls/record-client.ts +140 -73
- package/std/net/tls/record-server.ts +233 -105
- package/std/net/tls/record.ts +142 -36
- package/std/net/tls/schedule.ts +235 -26
- package/std/net/tls/ticket.ts +161 -40
- package/std/net/tls/verify.ts +57 -10
- package/std/net/tls-tcp.ts +308 -95
- package/std/net/tls.ts +276 -102
- package/std/net/upstream.ts +81 -45
- package/std/net/url.ts +109 -22
- package/std/net/websocket.ts +140 -26
- package/std/net/webtransport.ts +243 -106
- package/std/pair.ts +10 -2
- package/std/random.ts +42 -15
- package/std/regex.ts +422 -257
- package/std/region.ts +70 -15
- package/std/secret.ts +52 -11
- package/std/sort.ts +17 -2
- package/std/sqlite.ts +256 -35
- package/std/sync/ring.ts +229 -56
- package/std/sync/shm.ts +203 -23
- package/std/term-io.ts +154 -78
- package/std/term-pixels.ts +144 -19
- package/std/term-probe.ts +77 -35
- package/std/term-rate.ts +199 -118
- package/std/term.ts +400 -175
- package/std/testing.ts +130 -32
- package/std/text.ts +84 -17
- package/std/threads.ts +248 -56
- package/std/yaml-json.ts +111 -97
- package/std/yaml-lines.ts +47 -15
- package/std/yaml-write.ts +45 -30
- package/std/yaml.ts +764 -384
package/std/net/router.ts
CHANGED
|
@@ -103,55 +103,73 @@ export class RouterLimits {
|
|
|
103
103
|
export class Router {
|
|
104
104
|
// References, then 32-bit fields: the order the layout packs without padding.
|
|
105
105
|
/** Per node: its first literal child, or -1; siblings chain through `nextSibling`. */
|
|
106
|
-
firstChild: i32[]
|
|
106
|
+
private firstChild: i32[]
|
|
107
107
|
/** Per node: the next literal child of its parent, or -1. */
|
|
108
|
-
nextSibling: i32[]
|
|
108
|
+
private nextSibling: i32[]
|
|
109
109
|
/** Per node: its literal label, `labels[labelStart .. labelEnd)`; empty for a parameter or `*` node. */
|
|
110
|
-
labelStart: i32[]
|
|
111
|
-
labelEnd: i32[]
|
|
110
|
+
private labelStart: i32[]
|
|
111
|
+
private labelEnd: i32[]
|
|
112
112
|
/** Per node: its parameter child, or -1; one per node, since names take no part in matching. */
|
|
113
|
-
paramChild: i32[]
|
|
113
|
+
private paramChild: i32[]
|
|
114
114
|
/** Per node: its `*` child, or -1. */
|
|
115
|
-
wildChild: i32[]
|
|
115
|
+
private wildChild: i32[]
|
|
116
116
|
/** Per node: the first route ending there, or -1; routes chain through `endpointNext`. */
|
|
117
|
-
firstEndpoint: i32[]
|
|
117
|
+
private firstEndpoint: i32[]
|
|
118
118
|
/** Every literal label, back to back. */
|
|
119
|
-
labels: u8[]
|
|
119
|
+
private labels: u8[]
|
|
120
120
|
/** Per route: its method's index into `methodStart`, the next route ending at its node, and its parameter pairs. */
|
|
121
|
-
routeMethod: i32[]
|
|
122
|
-
endpointNext: i32[]
|
|
123
|
-
routeParams: i32[]
|
|
124
|
-
/**
|
|
121
|
+
private routeMethod: i32[]
|
|
122
|
+
private endpointNext: i32[]
|
|
123
|
+
private routeParams: i32[]
|
|
124
|
+
/**
|
|
125
|
+
* The methods the table knows, `methodBytes[methodStart[m] .. methodEnd[m])`, compared exactly (RFC 9110 §9.1).
|
|
126
|
+
* @internal Read by std/net/handler.ts, which matches a path against each known method to build a 405's `Allow` value.
|
|
127
|
+
*/
|
|
125
128
|
methodBytes: u8[]
|
|
129
|
+
/**
|
|
130
|
+
* Where method `m`'s bytes start in `methodBytes`.
|
|
131
|
+
* @internal Read by std/net/handler.ts to match a path under each known method for `Allow`, and under GET for a HEAD.
|
|
132
|
+
*/
|
|
126
133
|
methodStart: i32[]
|
|
134
|
+
/**
|
|
135
|
+
* Where method `m`'s bytes end in `methodBytes`.
|
|
136
|
+
* @internal Read by std/net/handler.ts beside `methodStart`, for the same matches.
|
|
137
|
+
*/
|
|
127
138
|
methodEnd: i32[]
|
|
128
139
|
/** `match`'s scratch, sized by the constructor: each segment's span, then the pairs found so far. */
|
|
129
|
-
segStart: i32[]
|
|
130
|
-
segEnd: i32[]
|
|
131
|
-
found: i32[]
|
|
140
|
+
private segStart: i32[]
|
|
141
|
+
private segEnd: i32[]
|
|
142
|
+
private found: i32[]
|
|
132
143
|
/** `add`'s scratch: each pattern segment's kind and span in the pattern. */
|
|
133
|
-
patKind: i32[]
|
|
134
|
-
patStart: i32[]
|
|
135
|
-
patEnd: i32[]
|
|
144
|
+
private patKind: i32[]
|
|
145
|
+
private patStart: i32[]
|
|
146
|
+
private patEnd: i32[]
|
|
136
147
|
/** The limits, copied out of the `RouterLimits` the table was made with. */
|
|
137
|
-
maxPatternBytes: i32 = 0
|
|
138
|
-
maxSegments: i32 = 0
|
|
148
|
+
private maxPatternBytes: i32 = 0
|
|
149
|
+
private maxSegments: i32 = 0
|
|
150
|
+
/**
|
|
151
|
+
* The most parameters one pattern may have, a final `*` counted.
|
|
152
|
+
* @internal Read by std/net/handler.ts to size the scratch `params` array it hands `match`.
|
|
153
|
+
*/
|
|
139
154
|
maxParams: i32 = 0
|
|
140
|
-
maxRoutes: i32 = 0
|
|
141
|
-
maxMethods: i32 = 0
|
|
155
|
+
private maxRoutes: i32 = 0
|
|
156
|
+
private maxMethods: i32 = 0
|
|
142
157
|
/** The most segments any route has: a path is split no further than one past it. */
|
|
143
|
-
deepest: i32 = 0
|
|
158
|
+
private deepest: i32 = 0
|
|
144
159
|
/** During a match: how many segments the path has, where it ends, the method's index, and the pairs in `found`. */
|
|
145
|
-
segments: i32 = 0
|
|
146
|
-
pathEnd: i32 = 0
|
|
147
|
-
wanted: i32 = 0
|
|
148
|
-
foundCount: i32 = 0
|
|
160
|
+
private segments: i32 = 0
|
|
161
|
+
private pathEnd: i32 = 0
|
|
162
|
+
private wanted: i32 = 0
|
|
163
|
+
private foundCount: i32 = 0
|
|
149
164
|
/** During a match: whether a route of another method ended at the path's end. */
|
|
150
|
-
otherMethod: boolean = false
|
|
165
|
+
private otherMethod: boolean = false
|
|
151
166
|
/** The nodes the last `match` visited: never more than `nodeCount()`, which the tests pin. */
|
|
152
|
-
visited: i32 = 0
|
|
167
|
+
private visited: i32 = 0
|
|
153
168
|
|
|
154
|
-
/**
|
|
169
|
+
/**
|
|
170
|
+
* An empty table. Panics, naming the field, on a limit outside the range `RouterLimits` gives it.
|
|
171
|
+
* @param limits the caps, copied out here, so changing them later has no effect on this table
|
|
172
|
+
*/
|
|
155
173
|
constructor(limits: RouterLimits) {
|
|
156
174
|
routerLimit("maxPatternBytes", limits.maxPatternBytes, 1, 65536)
|
|
157
175
|
routerLimit("maxSegments", limits.maxSegments, 1, 256)
|
|
@@ -186,16 +204,23 @@ export class Router {
|
|
|
186
204
|
}
|
|
187
205
|
|
|
188
206
|
/** How many routes the table holds; the next `add` answers this index. */
|
|
189
|
-
routes(): i32 {
|
|
207
|
+
private routes(): i32 {
|
|
190
208
|
return toI32(this.routeMethod.length)
|
|
191
209
|
}
|
|
192
210
|
|
|
193
|
-
/**
|
|
211
|
+
/**
|
|
212
|
+
* How many nodes the tree has, the root included: the most one `match` visits.
|
|
213
|
+
* @returns the node count, which grows only as `add` makes new segments
|
|
214
|
+
*/
|
|
194
215
|
nodeCount(): i32 {
|
|
195
216
|
return toI32(this.firstChild.length)
|
|
196
217
|
}
|
|
197
218
|
|
|
198
|
-
/**
|
|
219
|
+
/**
|
|
220
|
+
* How many `[start, end)` pairs `route` answers: its parameters, and one more for a final `*`.
|
|
221
|
+
* @param route a route index `add` answered; panics on one the table does not hold
|
|
222
|
+
* @returns how many pairs `match` writes to `params` for that route, so half the slots it needs
|
|
223
|
+
*/
|
|
199
224
|
paramCount(route: i32): i32 {
|
|
200
225
|
if (route < 0 || route >= this.routes()) {
|
|
201
226
|
panic(`Router.paramCount: route ${route} is not in a table of ${this.routes()}`)
|
|
@@ -203,7 +228,10 @@ export class Router {
|
|
|
203
228
|
return this.routeParams[route]
|
|
204
229
|
}
|
|
205
230
|
|
|
206
|
-
/**
|
|
231
|
+
/**
|
|
232
|
+
* How many nodes the last `match` visited.
|
|
233
|
+
* @returns the visit count, never more than `nodeCount()`, which the tests use to pin a lookup's cost
|
|
234
|
+
*/
|
|
207
235
|
lastVisited(): i32 {
|
|
208
236
|
return this.visited
|
|
209
237
|
}
|
|
@@ -212,6 +240,9 @@ export class Router {
|
|
|
212
240
|
* Adds the route `method pattern` and answers its index, counting from 0, or
|
|
213
241
|
* a negative `ROUTER_*` code; a refused pattern adds nothing. Whether a
|
|
214
242
|
* pattern is refused never depends on the order routes were added in.
|
|
243
|
+
* @param method the method the route answers, an HTTP token of 1 to 32 bytes such as `"GET"`
|
|
244
|
+
* @param pattern the path pattern, starting with `/`, with `:name` parameters and an optional final `*`
|
|
245
|
+
* @returns the new route's index, which `match` answers for it, or a negative `ROUTER_*` code
|
|
215
246
|
*/
|
|
216
247
|
add(method: string, pattern: string): i32 {
|
|
217
248
|
const methodLength: i32 = toI32(method.length)
|
|
@@ -291,7 +322,7 @@ export class Router {
|
|
|
291
322
|
* Splits `pattern`, which starts with `/`, into `patKind`/`patStart`/`patEnd`
|
|
292
323
|
* and answers how many segments it has, or the code that refuses it.
|
|
293
324
|
*/
|
|
294
|
-
splitPattern(pattern: string): i32 {
|
|
325
|
+
private splitPattern(pattern: string): i32 {
|
|
295
326
|
const length: i32 = toI32(pattern.length)
|
|
296
327
|
let count: i32 = 0
|
|
297
328
|
let start: i32 = 1
|
|
@@ -333,7 +364,7 @@ export class Router {
|
|
|
333
364
|
}
|
|
334
365
|
|
|
335
366
|
/** The child of `node` that pattern segment `k` leads to, or -1. */
|
|
336
|
-
childFor(node: i32, pattern: string, k: i32): i32 {
|
|
367
|
+
private childFor(node: i32, pattern: string, k: i32): i32 {
|
|
337
368
|
const kind: i32 = this.patKind[k]
|
|
338
369
|
if (kind === ROUTER_PARAM) {
|
|
339
370
|
return this.paramChild[node]
|
|
@@ -353,7 +384,7 @@ export class Router {
|
|
|
353
384
|
}
|
|
354
385
|
|
|
355
386
|
/** Adds the child of `node` that pattern segment `k` leads to, and answers it. */
|
|
356
|
-
addChild(node: i32, pattern: string, k: i32): i32 {
|
|
387
|
+
private addChild(node: i32, pattern: string, k: i32): i32 {
|
|
357
388
|
const child: i32 = this.nodeCount()
|
|
358
389
|
const kind: i32 = this.patKind[k]
|
|
359
390
|
const at: i32 = toI32(this.labels.length)
|
|
@@ -379,7 +410,10 @@ export class Router {
|
|
|
379
410
|
return child
|
|
380
411
|
}
|
|
381
412
|
|
|
382
|
-
/**
|
|
413
|
+
/**
|
|
414
|
+
* The index of `method` among the methods the table knows, or -1.
|
|
415
|
+
* @internal Called by std/net/handler.ts to find GET's index, so a HEAD on a GET-only path routes as GET.
|
|
416
|
+
*/
|
|
383
417
|
methodIndex(method: string): i32 {
|
|
384
418
|
const length: i32 = toI32(method.length)
|
|
385
419
|
for (let m: i32 = 0; m < toI32(this.methodStart.length); m++) {
|
|
@@ -397,6 +431,14 @@ export class Router {
|
|
|
397
431
|
* `params` as `[start, end)` offsets into `target`, two slots each, in the
|
|
398
432
|
* pattern's order, and a final `*` as one more pair; on a refusal `params`
|
|
399
433
|
* is untouched. Panics on a range outside its array.
|
|
434
|
+
* @param method the buffer holding the request's method
|
|
435
|
+
* @param mStart where the method starts in `method`
|
|
436
|
+
* @param mEnd where the method ends in `method`
|
|
437
|
+
* @param target the buffer holding the request target, which may be the same buffer as `method`
|
|
438
|
+
* @param tStart where the target starts in `target`
|
|
439
|
+
* @param tEnd where the target ends in `target`, the query included
|
|
440
|
+
* @param params the caller's scratch for the parameter pairs, two slots for each pair
|
|
441
|
+
* @returns the matched route's index, or `ROUTER_NOT_FOUND`, `ROUTER_METHOD_NOT_ALLOWED` or `ROUTER_TOO_MANY_PARAMS`
|
|
400
442
|
*/
|
|
401
443
|
match(method: u8[], mStart: i32, mEnd: i32, target: u8[], tStart: i32, tEnd: i32, params: i32[]): i32 {
|
|
402
444
|
if (mStart < 0 || mEnd < mStart || mEnd > toI32(method.length)) {
|
|
@@ -464,7 +506,7 @@ export class Router {
|
|
|
464
506
|
* that reaches a route wins, and a branch that does not is left with the
|
|
465
507
|
* pairs it pushed popped.
|
|
466
508
|
*/
|
|
467
|
-
walk(target: u8[], node: i32, depth: i32): i32 {
|
|
509
|
+
private walk(target: u8[], node: i32, depth: i32): i32 {
|
|
468
510
|
this.visited += 1
|
|
469
511
|
if (depth === this.segments) {
|
|
470
512
|
return this.endpointFor(node)
|
|
@@ -511,7 +553,7 @@ export class Router {
|
|
|
511
553
|
}
|
|
512
554
|
|
|
513
555
|
/** The route of the wanted method ending at `node`, or -1, noting a route of another method there. */
|
|
514
|
-
endpointFor(node: i32): i32 {
|
|
556
|
+
private endpointFor(node: i32): i32 {
|
|
515
557
|
for (let e: i32 = this.firstEndpoint[node]; e >= 0; e = this.endpointNext[e]) {
|
|
516
558
|
if (this.routeMethod[e] === this.wanted) {
|
|
517
559
|
return e
|
|
@@ -530,6 +572,11 @@ export class Router {
|
|
|
530
572
|
* stays `+`: a space spelled `+` is the query's form encoding, not the path's.
|
|
531
573
|
* The output may hold any byte, NUL and `/` included. Panics on a range
|
|
532
574
|
* outside `target`.
|
|
575
|
+
* @param target the buffer the range points into, usually the request head
|
|
576
|
+
* @param start where the raw parameter starts in `target`
|
|
577
|
+
* @param end where the raw parameter ends in `target`
|
|
578
|
+
* @param out where the decoded bytes go, from index 0; the caller's buffer
|
|
579
|
+
* @returns how many decoded bytes were written, or `ROUTER_BAD_ESCAPE` or `ROUTER_NO_ROOM`
|
|
533
580
|
*/
|
|
534
581
|
export const routerDecode = (target: u8[], start: i32, end: i32, out: u8[]): i32 => {
|
|
535
582
|
if (start < 0 || end < start || end > toI32(target.length)) {
|