@amritk/nish-aarch64-linux 0.34.1 → 0.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/INSTALL.md +22 -13
  2. package/bin/nish +0 -0
  3. package/docs/AI.md +86 -16
  4. package/package.json +1 -1
  5. package/runtime/async.d.mts +49 -0
  6. package/runtime/async.mjs +27 -0
  7. package/runtime/nish.d.ts +4681 -427
  8. package/runtime/nish.h +6 -2
  9. package/runtime/nish.mjs +4 -0
  10. package/runtime/runtime-net.c +22 -0
  11. package/runtime/runtime-shm.c +93 -2
  12. package/runtime/vite.d.ts +30 -0
  13. package/runtime/vite.mjs +150 -0
  14. package/scripts/build.sh +108 -13
  15. package/std/README.md +131 -131
  16. package/std/base64.ts +34 -5
  17. package/std/bytes.ts +258 -42
  18. package/std/cli-args.ts +296 -70
  19. package/std/cli-flags.ts +184 -19
  20. package/std/cli.ts +475 -54
  21. package/std/collections.ts +121 -23
  22. package/std/compress/checksum.ts +44 -14
  23. package/std/compress/deflate.ts +224 -111
  24. package/std/compress/gzip.ts +217 -53
  25. package/std/compress/zlib.ts +63 -7
  26. package/std/crypto/aes.ts +80 -9
  27. package/std/crypto/base64url.ts +22 -0
  28. package/std/crypto/bcrypt-batch.ts +88 -21
  29. package/std/crypto/bcrypt.ts +60 -0
  30. package/std/crypto/chacha20poly1305.ts +53 -0
  31. package/std/crypto/ct.ts +32 -13
  32. package/std/crypto/ed25519.ts +47 -0
  33. package/std/crypto/hkdf.ts +198 -13
  34. package/std/crypto/hmac.ts +235 -31
  35. package/std/crypto/jwt.ts +192 -63
  36. package/std/crypto/p256.ts +159 -16
  37. package/std/crypto/p384.ts +28 -3
  38. package/std/crypto/pki-roots.ts +32 -2
  39. package/std/crypto/pki.ts +81 -15
  40. package/std/crypto/rsa.ts +33 -3
  41. package/std/crypto/sha1.ts +3 -0
  42. package/std/crypto/sha256.ts +24 -1
  43. package/std/crypto/sha512.ts +99 -14
  44. package/std/crypto/x25519.ts +152 -14
  45. package/std/crypto/x509-random.ts +10 -0
  46. package/std/crypto/x509.ts +67 -7
  47. package/std/json-equal.ts +19 -0
  48. package/std/json-format.ts +112 -13
  49. package/std/json-number.ts +64 -14
  50. package/std/json-pointer.ts +23 -1
  51. package/std/json-tokenizer.ts +100 -29
  52. package/std/json-typed.ts +713 -66
  53. package/std/json-value.ts +400 -124
  54. package/std/json.ts +138 -10
  55. package/std/map.ts +25 -7
  56. package/std/math.ts +36 -4
  57. package/std/net/buffer-pool.ts +42 -11
  58. package/std/net/dns-config.ts +109 -23
  59. package/std/net/dns-message.ts +62 -7
  60. package/std/net/dns-resolver.ts +247 -53
  61. package/std/net/dns.ts +203 -35
  62. package/std/net/fetch.ts +151 -61
  63. package/std/net/handler.ts +278 -80
  64. package/std/net/hpack.ts +262 -52
  65. package/std/net/http-compress.ts +125 -15
  66. package/std/net/http-fields.ts +85 -9
  67. package/std/net/http1-client-codec.ts +100 -19
  68. package/std/net/http1-codec.ts +297 -77
  69. package/std/net/http1-server.ts +430 -94
  70. package/std/net/http2-frame.ts +272 -35
  71. package/std/net/http2-tls.ts +135 -34
  72. package/std/net/http2.ts +247 -106
  73. package/std/net/http3-frame.ts +154 -17
  74. package/std/net/http3-server.ts +275 -101
  75. package/std/net/http3.ts +307 -115
  76. package/std/net/outbound.ts +37 -3
  77. package/std/net/postgres-carrier.ts +144 -8
  78. package/std/net/postgres.ts +801 -112
  79. package/std/net/prefork.ts +164 -31
  80. package/std/net/qpack.ts +105 -18
  81. package/std/net/quic-conn-ack.ts +59 -12
  82. package/std/net/quic-conn-cid.ts +124 -27
  83. package/std/net/quic-conn-params.ts +70 -10
  84. package/std/net/quic-datagram.ts +43 -3
  85. package/std/net/quic-frame.ts +286 -12
  86. package/std/net/quic-listener.ts +101 -32
  87. package/std/net/quic-packet.ts +302 -21
  88. package/std/net/quic-recovery.ts +264 -52
  89. package/std/net/quic-stream.ts +353 -91
  90. package/std/net/quic.ts +1124 -201
  91. package/std/net/router.ts +87 -40
  92. package/std/net/tls/client.ts +166 -51
  93. package/std/net/tls/codec.ts +413 -56
  94. package/std/net/tls/record-client.ts +110 -55
  95. package/std/net/tls/record-server.ts +159 -59
  96. package/std/net/tls/record.ts +109 -12
  97. package/std/net/tls/schedule.ts +235 -26
  98. package/std/net/tls/ticket.ts +159 -40
  99. package/std/net/tls/verify.ts +49 -3
  100. package/std/net/tls-tcp.ts +250 -45
  101. package/std/net/tls.ts +221 -59
  102. package/std/net/upstream.ts +81 -45
  103. package/std/net/url.ts +97 -13
  104. package/std/net/websocket.ts +122 -12
  105. package/std/net/webtransport.ts +220 -89
  106. package/std/pair.ts +10 -2
  107. package/std/random.ts +34 -9
  108. package/std/regex.ts +352 -198
  109. package/std/region.ts +70 -15
  110. package/std/secret.ts +52 -11
  111. package/std/sort.ts +17 -2
  112. package/std/sqlite.ts +256 -35
  113. package/std/sync/ring.ts +430 -40
  114. package/std/sync/shm.ts +222 -15
  115. package/std/term-io.ts +137 -64
  116. package/std/term-pixels.ts +144 -19
  117. package/std/term-probe.ts +66 -25
  118. package/std/term-rate.ts +128 -57
  119. package/std/term.ts +332 -121
  120. package/std/testing.ts +130 -32
  121. package/std/text.ts +73 -7
  122. package/std/threads.ts +229 -41
  123. package/std/yaml-json.ts +94 -82
  124. package/std/yaml-lines.ts +47 -15
  125. package/std/yaml-write.ts +24 -16
  126. 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
- /** The methods the table knows, `methodBytes[methodStart[m] .. methodEnd[m])`, compared exactly (RFC 9110 §9.1). */
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
- /** An empty table. Panics, naming the field, on a limit outside the range `RouterLimits` gives it. */
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
- /** How many nodes the tree has, the root included: the most one `match` visits. */
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
- /** How many `[start, end)` pairs `route` answers: its parameters, and one more for a final `*`. */
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
- /** How many nodes the last `match` visited. */
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
- /** The index of `method` among the methods the table knows, or -1. */
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)) {