@amritk/nish-aarch64-linux 0.35.0 → 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 (119) hide show
  1. package/INSTALL.md +6 -1
  2. package/bin/nish +0 -0
  3. package/docs/AI.md +9 -2
  4. package/package.json +1 -1
  5. package/runtime/nish.d.ts +4612 -430
  6. package/runtime/vite.d.ts +30 -0
  7. package/runtime/vite.mjs +150 -0
  8. package/scripts/build.sh +108 -13
  9. package/std/base64.ts +34 -5
  10. package/std/bytes.ts +256 -40
  11. package/std/cli-args.ts +296 -70
  12. package/std/cli-flags.ts +184 -19
  13. package/std/cli.ts +475 -54
  14. package/std/collections.ts +121 -23
  15. package/std/compress/checksum.ts +44 -14
  16. package/std/compress/deflate.ts +224 -111
  17. package/std/compress/gzip.ts +217 -53
  18. package/std/compress/zlib.ts +63 -7
  19. package/std/crypto/aes.ts +80 -9
  20. package/std/crypto/base64url.ts +22 -0
  21. package/std/crypto/bcrypt-batch.ts +88 -21
  22. package/std/crypto/bcrypt.ts +60 -0
  23. package/std/crypto/chacha20poly1305.ts +53 -0
  24. package/std/crypto/ct.ts +32 -13
  25. package/std/crypto/ed25519.ts +47 -0
  26. package/std/crypto/hkdf.ts +198 -13
  27. package/std/crypto/hmac.ts +235 -31
  28. package/std/crypto/jwt.ts +192 -63
  29. package/std/crypto/p256.ts +159 -16
  30. package/std/crypto/p384.ts +28 -3
  31. package/std/crypto/pki-roots.ts +32 -2
  32. package/std/crypto/pki.ts +81 -15
  33. package/std/crypto/rsa.ts +33 -3
  34. package/std/crypto/sha1.ts +3 -0
  35. package/std/crypto/sha256.ts +24 -1
  36. package/std/crypto/sha512.ts +99 -14
  37. package/std/crypto/x25519.ts +152 -14
  38. package/std/crypto/x509-random.ts +10 -0
  39. package/std/crypto/x509.ts +67 -7
  40. package/std/json-equal.ts +19 -0
  41. package/std/json-format.ts +112 -13
  42. package/std/json-number.ts +64 -14
  43. package/std/json-pointer.ts +23 -1
  44. package/std/json-tokenizer.ts +100 -29
  45. package/std/json-typed.ts +713 -66
  46. package/std/json-value.ts +400 -124
  47. package/std/json.ts +138 -10
  48. package/std/map.ts +25 -7
  49. package/std/math.ts +36 -4
  50. package/std/net/buffer-pool.ts +42 -11
  51. package/std/net/dns-config.ts +109 -23
  52. package/std/net/dns-message.ts +62 -7
  53. package/std/net/dns-resolver.ts +247 -53
  54. package/std/net/dns.ts +203 -35
  55. package/std/net/fetch.ts +151 -61
  56. package/std/net/handler.ts +278 -80
  57. package/std/net/hpack.ts +262 -52
  58. package/std/net/http-compress.ts +125 -15
  59. package/std/net/http-fields.ts +85 -9
  60. package/std/net/http1-client-codec.ts +100 -19
  61. package/std/net/http1-codec.ts +235 -27
  62. package/std/net/http1-server.ts +343 -85
  63. package/std/net/http2-frame.ts +272 -35
  64. package/std/net/http2-tls.ts +135 -34
  65. package/std/net/http2.ts +247 -106
  66. package/std/net/http3-frame.ts +154 -17
  67. package/std/net/http3-server.ts +246 -96
  68. package/std/net/http3.ts +307 -115
  69. package/std/net/outbound.ts +37 -3
  70. package/std/net/postgres-carrier.ts +144 -8
  71. package/std/net/postgres.ts +723 -103
  72. package/std/net/prefork.ts +164 -31
  73. package/std/net/qpack.ts +105 -18
  74. package/std/net/quic-conn-ack.ts +59 -12
  75. package/std/net/quic-conn-cid.ts +124 -27
  76. package/std/net/quic-conn-params.ts +70 -10
  77. package/std/net/quic-datagram.ts +43 -3
  78. package/std/net/quic-frame.ts +286 -12
  79. package/std/net/quic-listener.ts +101 -32
  80. package/std/net/quic-packet.ts +302 -21
  81. package/std/net/quic-recovery.ts +228 -44
  82. package/std/net/quic-stream.ts +353 -91
  83. package/std/net/quic.ts +489 -171
  84. package/std/net/router.ts +87 -40
  85. package/std/net/tls/client.ts +166 -51
  86. package/std/net/tls/codec.ts +413 -56
  87. package/std/net/tls/record-client.ts +110 -55
  88. package/std/net/tls/record-server.ts +159 -59
  89. package/std/net/tls/record.ts +109 -12
  90. package/std/net/tls/schedule.ts +235 -26
  91. package/std/net/tls/ticket.ts +159 -40
  92. package/std/net/tls/verify.ts +49 -3
  93. package/std/net/tls-tcp.ts +250 -45
  94. package/std/net/tls.ts +221 -59
  95. package/std/net/upstream.ts +81 -45
  96. package/std/net/url.ts +97 -13
  97. package/std/net/websocket.ts +122 -12
  98. package/std/net/webtransport.ts +220 -89
  99. package/std/pair.ts +10 -2
  100. package/std/random.ts +34 -9
  101. package/std/regex.ts +352 -198
  102. package/std/region.ts +70 -15
  103. package/std/secret.ts +52 -11
  104. package/std/sort.ts +17 -2
  105. package/std/sqlite.ts +256 -35
  106. package/std/sync/ring.ts +205 -35
  107. package/std/sync/shm.ts +194 -16
  108. package/std/term-io.ts +137 -64
  109. package/std/term-pixels.ts +144 -19
  110. package/std/term-probe.ts +66 -25
  111. package/std/term-rate.ts +128 -57
  112. package/std/term.ts +332 -121
  113. package/std/testing.ts +130 -32
  114. package/std/text.ts +73 -7
  115. package/std/threads.ts +229 -41
  116. package/std/yaml-json.ts +94 -82
  117. package/std/yaml-lines.ts +47 -15
  118. package/std/yaml-write.ts +24 -16
  119. package/std/yaml.ts +764 -384
package/std/region.ts CHANGED
@@ -2,14 +2,28 @@
2
2
  * `nish:region` — memory a program frees when it says so (docs/LANGUAGE.md,
3
3
  * "Regions").
4
4
  *
5
- * import { Region, enterWith, free, regionWith } from "nish:region"
5
+ * import { Region, enter, free, regionWith } from "nish:region"
6
6
  *
7
- * const r: Region<Session> = regionWith(id, open)
8
- * const n: i32 = enterWith(r, out, serve)
9
- * free(r)
7
+ * class Session {
8
+ * hits: i32 = 0
9
+ * payload: u8[]
10
+ * constructor(size: i32) {
11
+ * this.payload = new Array<u8>(size)
12
+ * }
13
+ * }
10
14
  *
11
- * This file is the source behind the builtin module, and it is imported only
12
- * by that name: `nish/region` is refused, so there is one spelling for the
15
+ * const open = (size: i32): Session => new Session(size)
16
+ * const hit = (s: Session): i32 => {
17
+ * s.hits = s.hits + 1
18
+ * return s.hits
19
+ * }
20
+ *
21
+ * const r: Region<Session> = regionWith(16, open) // the Session lives in r
22
+ * const n: i32 = enter(r, hit) // 1: a number comes out
23
+ * free(r) // r is dead from here
24
+ *
25
+ * **This file is the source behind the builtin module**, and it is imported
26
+ * only by that name: `nish/region` is refused, so there is one spelling for the
13
27
  * checker's rules to be read under (`src/region-check.ts`). What is written
14
28
  * here is the meaning, over five intrinsics the compiler gives bodies of their
15
29
  * own (`src/emit-region.ts`), which swap the thread's arena for the region's
@@ -21,12 +35,12 @@
21
35
  * - `free(r)` gives the region's memory back. A handle used after it is
22
36
  * freed, or entered twice, or freed while entered, stops the program.
23
37
  *
24
- * A `Region<T>` is a handle, a 64-bit integer, and not a pointer: the root
38
+ * **A `Region<T>` is a handle**, a 64-bit integer, and not a pointer: the root
25
39
  * never leaves the region except through `enter`'s function, and that
26
40
  * function answers a scalar, so nothing outside a region can point into it.
27
41
  *
28
- * Under Node the module is answered by `runtime/nish.mjs`, where a region is
29
- * an entry in a table and `free` drops it.
42
+ * **Under Node the module is answered by `runtime/nish.mjs`**, where a region
43
+ * is an entry in a table and `free` drops it.
30
44
  */
31
45
 
32
46
  /**
@@ -35,7 +49,7 @@
35
49
  * read through `runtime/nish.d.ts`.
36
50
  */
37
51
  export class Region<T> {
38
- /** Never read: the compiler's type has no fields. */
52
+ /** @internal Never read: the compiler's type has no fields. */
39
53
  root: T | null = null
40
54
  }
41
55
 
@@ -59,21 +73,47 @@ const reopen = <T>(r: Region<T>): T => reopen(r)
59
73
  /** `nish_region_leave` with the root `reopen` gave. */
60
74
  const leave = <T>(r: Region<T>, root: T): void => leave(r, root)
61
75
 
62
- /** A new region, whose root is what `f` answers; everything `f` allocates is in it. */
76
+ /**
77
+ * A new region, whose root is what `f` answers; everything `f` allocates is in
78
+ * it.
79
+ *
80
+ * @param f builds the root. What it answers must be memory it allocated
81
+ * (NL2614), and the checker refuses it storing region memory anywhere
82
+ * outside the region (NL2609).
83
+ * @returns the handle to the new region, which holds its memory until `free`.
84
+ */
63
85
  export const region = <T>(f: () => T): Region<T> => {
64
86
  const h: i64 = handleNew()
65
87
  open(h)
66
88
  return close(h, f())
67
89
  }
68
90
 
69
- /** `region` with one argument for `f`, because the arrow `region` runs captures nothing. */
91
+ /**
92
+ * `region` with one argument for `f`, because the arrow `region` runs captures
93
+ * nothing.
94
+ *
95
+ * @param arg handed to `f`. It lives outside the region, so unless it is a
96
+ * number, `boolean`, `enum` or string literal `f` may not store it into
97
+ * region memory (NL2610).
98
+ * @param f builds the root from `arg`, under the same rules as `region`'s.
99
+ * @returns the handle to the new region, which holds its memory until `free`.
100
+ */
70
101
  export const regionWith = <A, T>(arg: A, f: (arg: A) => T): Region<T> => {
71
102
  const h: i64 = handleNew()
72
103
  open(h)
73
104
  return close(h, f(arg))
74
105
  }
75
106
 
76
- /** `f(root)`, allocating in the region: the one way to reach what a region holds. */
107
+ /**
108
+ * `f(root)`, allocating in the region: the one way to reach what a region holds.
109
+ *
110
+ * @param r the region to enter. A handle that is 0, freed, another thread's or
111
+ * already entered stops the program.
112
+ * @param f runs on the root, and everything it allocates lands in the region.
113
+ * It answers a number, a `boolean`, an `enum` or a `Region` (NL2611), so
114
+ * nothing it answers points into the region.
115
+ * @returns what `f` returns.
116
+ */
77
117
  export const enter = <T, R>(r: Region<T>, f: (root: T) => R): R => {
78
118
  const root: T = reopen(r)
79
119
  const result: R = f(root)
@@ -81,7 +121,15 @@ export const enter = <T, R>(r: Region<T>, f: (root: T) => R): R => {
81
121
  return result
82
122
  }
83
123
 
84
- /** `enter` with one argument for `f`. */
124
+ /**
125
+ * `enter` with one argument for `f`.
126
+ *
127
+ * @param r the region to enter, checked as `enter` checks it.
128
+ * @param arg handed to `f` after the root. It lives outside the region, under
129
+ * the same rule as `regionWith`'s `arg` (NL2610).
130
+ * @param f runs on the root and `arg`, under the same rules as `enter`'s.
131
+ * @returns what `f` returns.
132
+ */
85
133
  export const enterWith = <T, A, R>(r: Region<T>, arg: A, f: (root: T, arg: A) => R): R => {
86
134
  const root: T = reopen(r)
87
135
  const result: R = f(root, arg)
@@ -89,7 +137,14 @@ export const enterWith = <T, A, R>(r: Region<T>, arg: A, f: (root: T, arg: A) =>
89
137
  return result
90
138
  }
91
139
 
92
- /** Give the region's memory back. The handle is dead after it. The compiler writes the body. */
140
+ /**
141
+ * Give the region's memory back. The handle is dead after it. The compiler
142
+ * writes the body.
143
+ *
144
+ * @param _r the region to free. It and every copy of the handle are dead after
145
+ * this; freeing it again, or while it is entered, stops the program rather
146
+ * than freeing twice.
147
+ */
93
148
  export const free = <T>(_r: Region<T>): void => {
94
149
  // `nish_region_free`: see above.
95
150
  }
package/std/secret.ts CHANGED
@@ -2,14 +2,20 @@
2
2
  * `nish:secret` — key material, and the rules that keep it in
3
3
  * (docs/LANGUAGE.md, "Secrets").
4
4
  *
5
- * import { Secret, expose, secret, wipe } from "nish:secret"
5
+ * import { Secret, exposeWith, secret, wipe } from "nish:secret"
6
+ * import { hmacSha256 } from "nish/crypto/hmac"
6
7
  *
7
- * const key: Secret<u8[]> = secret(readKey())
8
- * const tag: u8[] = expose(key, (k: u8[]): u8[] => hmacSha256(k, message))
8
+ * const tag = (k: u8[], message: u8[]): u8[] => hmacSha256(k, message)
9
+ *
10
+ * const raw: u8[] = new Array<u8>(32)
11
+ * crypto.getRandomValues(raw)
12
+ * const key: Secret<u8[]> = secret(raw) // `raw` is moved: not read again
13
+ * const message: u8[] = [1, 2, 3]
14
+ * const mac: u8[] = exposeWith(key, message, tag)
9
15
  * wipe(key)
10
16
  *
11
- * This file is the source behind the builtin module, and it is imported only
12
- * by that name: `nish/secret` is refused, so there is one spelling for the
17
+ * **This file is the source behind the builtin module**, and it is imported
18
+ * only by that name: `nish/secret` is refused, so there is one spelling for the
13
19
  * checker's rules to be read under. What is written here is the meaning; what
14
20
  * makes a `Secret` worth having is in `src/secret.ts`, which knows this module
15
21
  * by its path and package:
@@ -25,8 +31,8 @@
25
31
  * - `wipe` is a volatile store of zeros over the value's whole storage,
26
32
  * which no optimiser may remove (`src/emit-secret.ts`).
27
33
  *
28
- * Under Node the module is answered by `runtime/shim.mjs`, where a `Secret` is
29
- * a plain wrapper and `wipe` zero-fills it.
34
+ * **Under Node the module is answered by `runtime/shim.mjs`**, where a
35
+ * `Secret` is a plain wrapper and `wipe` zero-fills it.
30
36
  */
31
37
 
32
38
  /**
@@ -34,21 +40,52 @@
34
40
  * every field is an integer. Made by `secret`, read only through `expose`.
35
41
  */
36
42
  export class Secret<T> {
37
- /** The wrapped value. Only this module reads or writes it (`src/secret.ts`). */
43
+ /** @internal Used by `expose` and `exposeWith`. The wrapped value. Only this module reads or writes it (`src/secret.ts`). */
38
44
  value: T
39
45
 
46
+ /**
47
+ * Wraps `value`. Only `secret` calls this: `new Secret` anywhere else is
48
+ * refused (NL2437).
49
+ *
50
+ * @param value the key material to hold, kept as it is, not copied.
51
+ */
40
52
  constructor(value: T) {
41
53
  this.value = value
42
54
  }
43
55
  }
44
56
 
45
- /** `value`, wrapped. The argument is moved: a local handed in is not read again. */
57
+ /**
58
+ * `value`, wrapped. The argument is moved: a local handed in is not read again.
59
+ *
60
+ * @param value the key material: an array of integers or a record whose every
61
+ * field is an integer, that nothing else holds (NL2512).
62
+ * @returns a `Secret` holding `value` itself, not a copy, so its storage is
63
+ * the storage `wipe` later zeroes.
64
+ */
46
65
  export const secret = <T>(value: T): Secret<T> => new Secret<T>(value)
47
66
 
48
- /** `f(value)`: the one way to compute with what a `Secret` holds. */
67
+ /**
68
+ * `f(value)`: the one way to compute with what a `Secret` holds.
69
+ *
70
+ * @param s the secret to read. It is not used up: it can be exposed again,
71
+ * and is still to be wiped.
72
+ * @param f the computation, handed the held value itself. The checker holds
73
+ * it to the rules in the module header: no I/O, no C, it does not keep the
74
+ * value, and its declared result type holds no `Secret`.
75
+ * @returns what `f` returns.
76
+ */
49
77
  export const expose = <T, R>(s: Secret<T>, f: (value: T) => R): R => f(s.value)
50
78
 
51
- /** `f(value, arg)`: `expose` with one more argument, because the arrow `expose` runs captures nothing. */
79
+ /**
80
+ * `f(value, arg)`: `expose` with one more argument, because the arrow `expose`
81
+ * runs captures nothing.
82
+ *
83
+ * @param s the secret to read, as for `expose`.
84
+ * @param arg handed to `f` as its second argument. `f` may read it but not
85
+ * write it.
86
+ * @param f the computation, under the same rules as `expose`'s.
87
+ * @returns what `f` returns.
88
+ */
52
89
  export const exposeWith = <T, A, R>(s: Secret<T>, arg: A, f: (value: T, arg: A) => R): R => f(s.value, arg)
53
90
 
54
91
  /**
@@ -56,6 +93,10 @@ export const exposeWith = <T, A, R>(s: Secret<T>, arg: A, f: (value: T, arg: A)
56
93
  * record of integers that `expose`'s function holds. Natively the compiler
57
94
  * gives each instance a body of its own, one volatile `llvm.memset`
58
95
  * (`src/emit-secret.ts`); this one is never emitted.
96
+ *
97
+ * @param _target what to zero: a `Secret`, never a nullable one (narrow it
98
+ * first), or an array or record of integers that `expose`'s function
99
+ * holds.
59
100
  */
60
101
  export const wipe = <T>(_target: T): void => {
61
102
  // Lowered by the compiler: see above.
package/std/sort.ts CHANGED
@@ -2,7 +2,13 @@
2
2
  * `std/sort` — `xs.sort(cmp)` on an array, in Nish: a stable merge sort,
3
3
  * compiled once per comparator.
4
4
  *
5
- * A program does not import this module. A `.sort(cmp)` call is what loads it
5
+ * export const main = (): i32 => {
6
+ * const xs: i32[] = [3, 1, 2];
7
+ * xs.sort((a, b) => a - b); // xs is now [1, 2, 3], and the call answers xs
8
+ * return xs[0];
9
+ * };
10
+ *
11
+ * **A program does not import this module.** A `.sort(cmp)` call is what loads it
6
12
  * (the checker's `importSort`), and the checker routes the call to `sortWith`
7
13
  * here. `cmp` is a compile-time function parameter, so each comparator is an
8
14
  * instantiation of its own whose body calls the comparator directly — there is
@@ -143,7 +149,16 @@ const mergePass = <T>(src: T[], dst: T[], cmp: (a: T, b: T) => number, n: i32, w
143
149
  }
144
150
  }
145
151
 
146
- /** `xs` sorted in place by `cmp`, stably, and answered: what `xs.sort(cmp)` compiles to. */
152
+ /**
153
+ * `xs` sorted in place by `cmp`, stably, and answered: what `xs.sort(cmp)`
154
+ * compiles to.
155
+ *
156
+ * @param xs the array to sort; its elements are rearranged in place.
157
+ * @param cmp compares an earlier element with a later one: a positive answer
158
+ * puts the later one first, and anything else, `NaN` and negative zero
159
+ * included, keeps their order.
160
+ * @returns `xs` itself, the same array the call was given, now sorted.
161
+ */
147
162
  export const sortWith = <T>(xs: T[], cmp: (a: T, b: T) => number): T[] => {
148
163
  const n: i32 = toI32(xs.length)
149
164
  if (n < 2) {