nish 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.
Files changed (129) hide show
  1. package/docs/AI.md +50 -4
  2. package/docs/INSTALL.md +73 -59
  3. package/package.json +19 -5
  4. package/runtime/async.d.mts +2 -0
  5. package/runtime/async.mjs +7 -0
  6. package/runtime/nish.d.ts +4849 -430
  7. package/runtime/nish.h +25 -0
  8. package/runtime/page.d.ts +53 -0
  9. package/runtime/page.mjs +146 -0
  10. package/runtime/runtime-async.c +557 -0
  11. package/runtime/runtime-wasm.c +63 -7
  12. package/runtime/vite.d.ts +30 -0
  13. package/runtime/vite.mjs +150 -0
  14. package/scripts/build.sh +252 -15
  15. package/scripts/fuzz.sh +1 -0
  16. package/scripts/undocumented.txt +14 -0
  17. package/std/README.md +107 -82
  18. package/std/base64.ts +34 -5
  19. package/std/bytes.ts +279 -59
  20. package/std/cli-args.ts +296 -70
  21. package/std/cli-flags.ts +184 -19
  22. package/std/cli.ts +475 -54
  23. package/std/collections.ts +121 -23
  24. package/std/compress/checksum.ts +44 -14
  25. package/std/compress/deflate.ts +224 -111
  26. package/std/compress/gzip.ts +217 -53
  27. package/std/compress/zlib.ts +63 -7
  28. package/std/crypto/aes.ts +128 -52
  29. package/std/crypto/base64url.ts +29 -5
  30. package/std/crypto/bcrypt-batch.ts +101 -34
  31. package/std/crypto/bcrypt.ts +93 -27
  32. package/std/crypto/chacha20poly1305.ts +69 -14
  33. package/std/crypto/ct.ts +32 -13
  34. package/std/crypto/ed25519.ts +66 -16
  35. package/std/crypto/hkdf.ts +198 -13
  36. package/std/crypto/hmac.ts +242 -37
  37. package/std/crypto/jwt.ts +204 -72
  38. package/std/crypto/p256.ts +222 -72
  39. package/std/crypto/p384.ts +51 -23
  40. package/std/crypto/pki-roots.ts +32 -2
  41. package/std/crypto/pki.ts +99 -30
  42. package/std/crypto/rsa.ts +56 -22
  43. package/std/crypto/sha1.ts +3 -0
  44. package/std/crypto/sha256.ts +24 -1
  45. package/std/crypto/sha512.ts +99 -14
  46. package/std/crypto/x25519.ts +163 -24
  47. package/std/crypto/x509-random.ts +10 -0
  48. package/std/crypto/x509.ts +133 -66
  49. package/std/host/ring.ts +124 -0
  50. package/std/json-equal.ts +31 -11
  51. package/std/json-format.ts +112 -13
  52. package/std/json-number.ts +76 -26
  53. package/std/json-pointer.ts +23 -1
  54. package/std/json-tokenizer.ts +126 -51
  55. package/std/json-typed.ts +757 -96
  56. package/std/json-value.ts +438 -157
  57. package/std/json.ts +170 -38
  58. package/std/map.ts +25 -7
  59. package/std/math.ts +36 -4
  60. package/std/net/buffer-pool.ts +42 -11
  61. package/std/net/dns-config.ts +109 -23
  62. package/std/net/dns-message.ts +62 -7
  63. package/std/net/dns-resolver.ts +247 -53
  64. package/std/net/dns.ts +203 -35
  65. package/std/net/fetch.ts +1267 -290
  66. package/std/net/handler.ts +296 -80
  67. package/std/net/hpack.ts +290 -77
  68. package/std/net/http-compress.ts +152 -36
  69. package/std/net/http-fields.ts +85 -9
  70. package/std/net/http1-client-codec.ts +129 -44
  71. package/std/net/http1-codec.ts +279 -114
  72. package/std/net/http1-server.ts +409 -139
  73. package/std/net/http2-frame.ts +289 -51
  74. package/std/net/http2-tls.ts +152 -49
  75. package/std/net/http2.ts +314 -160
  76. package/std/net/http3-frame.ts +165 -27
  77. package/std/net/http3-server.ts +282 -131
  78. package/std/net/http3.ts +377 -173
  79. package/std/net/outbound.ts +37 -3
  80. package/std/net/postgres-carrier.ts +144 -8
  81. package/std/net/postgres.ts +898 -260
  82. package/std/net/prefork.ts +202 -65
  83. package/std/net/qpack.ts +120 -32
  84. package/std/net/quic-conn-ack.ts +60 -12
  85. package/std/net/quic-conn-cid.ts +135 -27
  86. package/std/net/quic-conn-params.ts +109 -22
  87. package/std/net/quic-datagram.ts +50 -3
  88. package/std/net/quic-frame.ts +333 -23
  89. package/std/net/quic-listener.ts +161 -75
  90. package/std/net/quic-packet.ts +373 -73
  91. package/std/net/quic-recovery.ts +287 -65
  92. package/std/net/quic-stream.ts +436 -146
  93. package/std/net/quic.ts +693 -323
  94. package/std/net/router.ts +87 -40
  95. package/std/net/tls/client.ts +167 -51
  96. package/std/net/tls/codec.ts +494 -68
  97. package/std/net/tls/record-client.ts +140 -73
  98. package/std/net/tls/record-server.ts +233 -105
  99. package/std/net/tls/record.ts +142 -36
  100. package/std/net/tls/schedule.ts +235 -26
  101. package/std/net/tls/ticket.ts +161 -40
  102. package/std/net/tls/verify.ts +57 -10
  103. package/std/net/tls-tcp.ts +308 -95
  104. package/std/net/tls.ts +276 -102
  105. package/std/net/upstream.ts +81 -45
  106. package/std/net/url.ts +109 -22
  107. package/std/net/websocket.ts +140 -26
  108. package/std/net/webtransport.ts +243 -106
  109. package/std/pair.ts +10 -2
  110. package/std/random.ts +42 -15
  111. package/std/regex.ts +422 -257
  112. package/std/region.ts +70 -15
  113. package/std/secret.ts +52 -11
  114. package/std/sort.ts +17 -2
  115. package/std/sqlite.ts +256 -35
  116. package/std/sync/ring.ts +229 -56
  117. package/std/sync/shm.ts +203 -23
  118. package/std/term-io.ts +154 -78
  119. package/std/term-pixels.ts +144 -19
  120. package/std/term-probe.ts +77 -35
  121. package/std/term-rate.ts +199 -118
  122. package/std/term.ts +400 -175
  123. package/std/testing.ts +130 -32
  124. package/std/text.ts +84 -17
  125. package/std/threads.ts +248 -56
  126. package/std/yaml-json.ts +111 -97
  127. package/std/yaml-lines.ts +47 -15
  128. package/std/yaml-write.ts +45 -30
  129. package/std/yaml.ts +764 -384
package/std/yaml-write.ts CHANGED
@@ -23,20 +23,27 @@
23
23
  * as its text, which the core schema reads as an integer or a float. The text
24
24
  * ends with a line break.
25
25
  *
26
- * **A string is plain unless it could read as something else.** It is written
27
- * double-quoted when it is empty; when it reads as null, a boolean or a number
28
- * under YAML 1.2 or YAML 1.1 (`~`, `null`, `yes`, `on`, `y`, `true` in any
29
- * case; anything starting with a digit, or a sign or `.` and then a digit;
30
- * `.inf` and `.nan`, signed or not); when it starts with an indicator (`@`, `` ` ``, `\`, `*`,
31
- * `&`, `!`, `|`, `>`, `%`, `'`, `"`, `#`, `,`, `[`, `]`, `{`, `}`, or `-`, `?`
32
- * or `:` before a space or the end) or with `---` or `...`; when it holds
33
- * `: ` or ` #` or ends in `:`; when it starts or ends with a space; when it
34
- * holds a control character, a line break, U+2028, U+2029, U+FEFF, U+FFFE or
35
- * U+FFFF; and, as a key, when it is `<<`, which YAML reads as a merge key.
36
- * Keys and values follow the same rule. A quoted string escapes `"`, `\` and
37
- * every character just listed, so it stays on one line. A key whose written
38
- * form runs past the 1024 bytes YAML allows an implicit key is written as an
39
- * explicit one, `? key` and then `: value`.
26
+ * **A string is plain unless it could read as something else.**
27
+ *
28
+ * It is written double-quoted
29
+ * - when it is empty;
30
+ * - when it reads as null, a boolean or a number under YAML 1.2 or YAML 1.1
31
+ * (`~`, `null`, `yes`, `on`, `y`, `true` in any case; anything starting with
32
+ * a digit, or a sign or `.` and then a digit; `.inf` and `.nan`, signed or
33
+ * not);
34
+ * - when it starts with an indicator (`@`, `` ` ``, `\`, `*`, `&`, `!`, `|`,
35
+ * `>`, `%`, `'`, `"`, `#`, `,`, `[`, `]`, `{`, `}`, or `-`, `?` or `:` before
36
+ * a space or the end) or with `---` or `...`;
37
+ * - when it holds `: ` or ` #` or ends in `:`;
38
+ * - when it starts or ends with a space;
39
+ * - when it holds a control character, a line break, U+2028, U+2029, U+FEFF,
40
+ * U+FFFE or U+FFFF;
41
+ * - and, as a key, when it is `<<`, which YAML reads as a merge key.
42
+ *
43
+ * Keys and values follow the same rule. A quoted string escapes `"`, `\` and
44
+ * every character just listed, so it stays on one line. A key whose written
45
+ * form runs past the 1024 bytes YAML allows an implicit key is written as an
46
+ * explicit one, `? key` and then `: value`.
40
47
  *
41
48
  * **What it answers.** The YAML text, or `""` when `v` names no value or the
42
49
  * tree nests deeper than `JSON_WRITER_MAX_DEPTH` collections, the limit
@@ -224,9 +231,13 @@ const yamlWriteLength = (text: string, quoted: boolean): i32 => {
224
231
 
225
232
  /** Writes one JSON value as block YAML, byte by byte, into `out`. */
226
233
  class YamlWriter {
227
- doc: JsonDocument
234
+ private doc: JsonDocument
235
+ /** @internal Used by `stringifyYaml`. */
228
236
  out: u8[]
229
- /** Whether a collection nested past `JSON_WRITER_MAX_DEPTH`. */
237
+ /**
238
+ * Whether a collection nested past `JSON_WRITER_MAX_DEPTH`.
239
+ * @internal Used by `stringifyYaml`.
240
+ */
230
241
  tooDeep: boolean = false
231
242
 
232
243
  constructor(doc: JsonDocument) {
@@ -234,38 +245,38 @@ class YamlWriter {
234
245
  this.out = []
235
246
  }
236
247
 
237
- byte(c: i32): void {
248
+ private byte(c: i32): void {
238
249
  this.out.push(toU8(c))
239
250
  }
240
251
 
241
252
  /** Writes the bytes of `text` from `from` up to `to`. */
242
- bytes(text: string, from: i32, to: i32): void {
253
+ private bytes(text: string, from: i32, to: i32): void {
243
254
  for (let i: i32 = from; i < to; i += 1) {
244
255
  this.byte(yamlWriteByte(text, i))
245
256
  }
246
257
  }
247
258
 
248
- text(text: string): void {
259
+ private text(text: string): void {
249
260
  const from: i32 = 0
250
261
  this.bytes(text, from, toI32(text.length))
251
262
  }
252
263
 
253
264
  /** Writes `count` spaces. */
254
- spaces(count: i32): void {
265
+ private spaces(count: i32): void {
255
266
  for (let i: i32 = 0; i < count; i += 1) {
256
267
  this.byte(YAML_WRITE_SPACE)
257
268
  }
258
269
  }
259
270
 
260
271
  /** Writes `\xXX` for byte `c`. */
261
- hex(c: i32): void {
272
+ private hex(c: i32): void {
262
273
  this.text("\\x")
263
274
  this.byte(yamlWriteByte(YAML_WRITE_HEX, c >> 4))
264
275
  this.byte(yamlWriteByte(YAML_WRITE_HEX, c & 15))
265
276
  }
266
277
 
267
278
  /** Writes the escape for the `length` bytes at `i`, a character yamlWriteEscapedLength names. */
268
- escape(text: string, i: i32, length: i32): void {
279
+ private escape(text: string, i: i32, length: i32): void {
269
280
  const c: i32 = yamlWriteByte(text, i)
270
281
  const second: i32 = yamlWriteByte(text, i + 1)
271
282
  const third: i32 = yamlWriteByte(text, i + 2)
@@ -289,7 +300,7 @@ class YamlWriter {
289
300
  }
290
301
 
291
302
  /** Writes `text` as a double-quoted scalar on one line. */
292
- quoted(text: string): void {
303
+ private quoted(text: string): void {
293
304
  const n: i32 = toI32(text.length)
294
305
  this.byte(YAML_WRITE_QUOTE)
295
306
  let i: i32 = 0
@@ -312,7 +323,7 @@ class YamlWriter {
312
323
  }
313
324
 
314
325
  /** Writes `text` as a scalar: plain when that reads back as the same string, double-quoted otherwise. */
315
- string(text: string, quoted: boolean): void {
326
+ private string(text: string, quoted: boolean): void {
316
327
  if (quoted) {
317
328
  this.quoted(text)
318
329
  } else {
@@ -321,13 +332,13 @@ class YamlWriter {
321
332
  }
322
333
 
323
334
  /** Whether `v` is a collection with members, which takes lines of its own. */
324
- isBlock(v: JsonValue): boolean {
335
+ private isBlock(v: JsonValue): boolean {
325
336
  const kind: i32 = this.doc.kind(v)
326
337
  return (kind === JSON_VALUE_ARRAY || kind === JSON_VALUE_OBJECT) && this.doc.length(v) > 0
327
338
  }
328
339
 
329
340
  /** Writes `v` on one line: a scalar, `{}` or `[]`. */
330
- inline(v: JsonValue): void {
341
+ private inline(v: JsonValue): void {
331
342
  const doc: JsonDocument = this.doc
332
343
  const kind: i32 = doc.kind(v)
333
344
  if (kind === JSON_VALUE_NULL) {
@@ -349,6 +360,7 @@ class YamlWriter {
349
360
  /**
350
361
  * Writes `v` starting at column `indent`, where the line has already reached
351
362
  * it, and ends its last line; `depth` is how many collections hold it.
363
+ * @internal Called by `stringifyYaml`.
352
364
  */
353
365
  node(v: JsonValue, indent: i32, depth: i32): void {
354
366
  const doc: JsonDocument = this.doc
@@ -397,10 +409,13 @@ class YamlWriter {
397
409
  }
398
410
 
399
411
  /**
400
- * `v` of `doc` as block YAML text that `parseYaml` reads back as the same
401
- * tree; `""` when `v` names no value or nests deeper than
402
- * `JSON_WRITER_MAX_DEPTH` collections. See the module comment for the rule
403
- * that quotes a string.
412
+ * A value as block YAML text that `parseYaml` reads back as the same tree. See
413
+ * the module comment for the rule that quotes a string.
414
+ *
415
+ * @param doc The document that holds `v`.
416
+ * @param v The value to write, usually the document's root.
417
+ * @returns The text, ending in a line break; `""` when `v` names no value or nests deeper than
418
+ * `JSON_WRITER_MAX_DEPTH` collections.
404
419
  */
405
420
  export const stringifyYaml = (doc: JsonDocument, v: JsonValue): string => {
406
421
  if (doc.kind(v) === JSON_VALUE_NONE) {