nish 0.44.0 → 0.45.1
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/README.md +1 -1
- package/docs/AI.md +18 -16
- package/package.json +5 -5
- package/runtime/core/numbers.mjs +3 -1
- package/runtime/core/strings.mjs +90 -38
- package/runtime/core.d.ts +8 -0
- package/runtime/core.mjs +16 -0
- package/runtime/nish.d.ts +47 -5
- package/runtime/nish.mjs +4 -0
- package/std/README.md +3 -3
- package/std/array.ts +10 -2
- package/std/bytes.ts +239 -26
- package/std/cli-args.ts +1072 -606
- package/std/cli-flags.ts +180 -98
- package/std/cli.ts +21 -13
- package/std/collections.ts +245 -127
- package/std/compress/checksum.ts +32 -37
- package/std/compress/deflate.ts +1102 -542
- package/std/compress/gzip.ts +290 -145
- package/std/compress/zlib.ts +57 -21
- package/std/crypto/aes.ts +153 -75
- package/std/crypto/base64url.ts +84 -61
- package/std/crypto/bcrypt-batch.ts +164 -90
- package/std/crypto/bcrypt.ts +185 -107
- package/std/crypto/chacha20poly1305.ts +84 -68
- package/std/crypto/ct.ts +9 -7
- package/std/crypto/ed25519.ts +64 -27
- package/std/crypto/hkdf.ts +105 -63
- package/std/crypto/hmac.ts +95 -89
- package/std/crypto/jwt.ts +248 -126
- package/std/crypto/p256.ts +758 -444
- package/std/crypto/p384.ts +20 -13
- package/std/crypto/pki-roots.ts +95 -38
- package/std/crypto/pki.ts +164 -60
- package/std/crypto/rsa.ts +266 -223
- package/std/crypto/scram.ts +3 -4
- package/std/crypto/sha1.ts +107 -65
- package/std/crypto/sha256.ts +502 -422
- package/std/crypto/sha512.ts +204 -135
- package/std/crypto/x509-random.ts +9 -3
- package/std/crypto/x509.ts +331 -171
- package/std/json-equal.ts +35 -19
- package/std/json-format.ts +215 -108
- package/std/json-number.ts +126 -72
- package/std/json-pointer.ts +42 -13
- package/std/json-tokenizer.ts +498 -307
- package/std/json-typed.ts +115 -36
- package/std/json-value.ts +341 -152
- package/std/json.ts +300 -158
- package/std/net/buffer-pool.ts +17 -7
- package/std/net/dns-config.ts +427 -236
- package/std/net/dns-message.ts +114 -47
- package/std/net/dns-resolver.ts +736 -237
- package/std/net/dns.ts +205 -52
- package/std/net/fetch.ts +320 -184
- package/std/net/grpc.ts +948 -0
- package/std/net/handler.ts +1275 -217
- package/std/net/hpack.ts +395 -180
- package/std/net/http-compress.ts +502 -65
- package/std/net/http-fields.ts +85 -49
- package/std/net/http-server.ts +1764 -602
- package/std/net/http1-client-codec.ts +372 -161
- package/std/net/http1-codec.ts +665 -331
- package/std/net/http1-server.ts +660 -278
- package/std/net/http2-cleartext.ts +165 -95
- package/std/net/http2-frame.ts +232 -89
- package/std/net/http2-tls.ts +42 -12
- package/std/net/http2.ts +327 -101
- package/std/net/http3-frame.ts +68 -33
- package/std/net/http3-server.ts +647 -192
- package/std/net/http3.ts +667 -189
- package/std/net/oidc.ts +63 -24
- package/std/net/outbound.ts +207 -142
- package/std/net/postgres-async.ts +1165 -443
- package/std/net/postgres-carrier.ts +575 -372
- package/std/net/postgres.ts +1459 -559
- package/std/net/prefork.ts +254 -98
- package/std/net/protobuf.ts +1017 -0
- package/std/net/qpack.ts +143 -92
- package/std/net/quic-conn-ack.ts +50 -18
- package/std/net/quic-conn-cid.ts +66 -26
- package/std/net/quic-conn-params.ts +13 -7
- package/std/net/quic-datagram.ts +90 -27
- package/std/net/quic-frame.ts +225 -124
- package/std/net/quic-listener.ts +197 -89
- package/std/net/quic-packet.ts +289 -163
- package/std/net/quic-recovery.ts +279 -128
- package/std/net/quic-stream.ts +466 -167
- package/std/net/quic.ts +568 -257
- package/std/net/router.ts +450 -99
- package/std/net/serve.ts +651 -232
- package/std/net/static.ts +1458 -0
- package/std/net/tls/client.ts +140 -45
- package/std/net/tls/codec.ts +510 -260
- package/std/net/tls/record-client.ts +268 -76
- package/std/net/tls/record-server.ts +236 -79
- package/std/net/tls/record.ts +173 -47
- package/std/net/tls/schedule.ts +58 -39
- package/std/net/tls/ticket.ts +295 -103
- package/std/net/tls/verify.ts +1 -1
- package/std/net/tls-tcp.ts +218 -75
- package/std/net/tls.ts +260 -152
- package/std/net/upstream.ts +283 -86
- package/std/net/url.ts +277 -102
- package/std/net/websocket.ts +370 -186
- package/std/net/webtransport.ts +755 -436
- package/std/regex.ts +1659 -829
- package/std/sync/ring.ts +320 -156
- package/std/sync/shm.ts +53 -6
- package/std/text.ts +205 -124
- package/std/threads.ts +22 -2
package/std/sync/shm.ts
CHANGED
|
@@ -90,7 +90,7 @@ declare function nishshm_read(h: i32, at: i32, dst: u8[], n: u64, off: u64, len:
|
|
|
90
90
|
declare function nishshm_write(h: i32, at: i32, src: readonly u8[], n: u64, off: u64, len: u64): void
|
|
91
91
|
declare function nishshm_wait_i32(h: i32, at: i32, expected: i32, timeoutMs: i32): i32
|
|
92
92
|
declare function nishshm_wake(h: i32, at: i32, count: i32): i32
|
|
93
|
-
declare function strerror(errnum: i32): string
|
|
93
|
+
declare function strerror(errnum: i32): string | null
|
|
94
94
|
|
|
95
95
|
// The window intrinsics (`src/shm-window.ts`): each body is a call of itself,
|
|
96
96
|
// which the compiler replaces with `nishshm_lend` or `nishshm_give_back`. They
|
|
@@ -149,18 +149,54 @@ export class ShmError {
|
|
|
149
149
|
*/
|
|
150
150
|
constructor(code: i32) {
|
|
151
151
|
this.code = code
|
|
152
|
-
|
|
152
|
+
// POSIX lets `strerror` answer NULL, so the type says so and the code
|
|
153
|
+
// stands in for the text rather than stop the program over a message.
|
|
154
|
+
const text = code === 95 ? "not supported on this platform" : strerror(code)
|
|
155
|
+
this.message = text === null ? `error ${code}` : text
|
|
153
156
|
}
|
|
154
157
|
}
|
|
155
158
|
|
|
159
|
+
/**
|
|
160
|
+
* The errno a failed runtime call answered, negated back to positive. The
|
|
161
|
+
* negation wraps through `u32`, so a stray `-2147483648` from C stays itself
|
|
162
|
+
* instead of overflowing; the runtime only answers small errnos.
|
|
163
|
+
*/
|
|
164
|
+
const shmErrno = (rc: i32): i32 => toI32(toU32(0) - toU32(rc))
|
|
165
|
+
|
|
156
166
|
/** `Ok()` for 0, the error for a negated errno. */
|
|
157
167
|
const shmDone = (rc: i32): Result<void, ShmError> => {
|
|
158
168
|
if (rc < 0) {
|
|
159
|
-
return Err(new ShmError(
|
|
169
|
+
return Err(new ShmError(shmErrno(rc)))
|
|
160
170
|
}
|
|
161
171
|
return Ok()
|
|
162
172
|
}
|
|
163
173
|
|
|
174
|
+
/**
|
|
175
|
+
* Whether `name` keeps `createRegion`'s rules: 1 to 30 of
|
|
176
|
+
* `A-Z a-z 0-9 . _ -`, not starting with `.`. The runtime checks them too;
|
|
177
|
+
* checking here answers a NUL byte as `SHM_INVALID` before C would read it.
|
|
178
|
+
*/
|
|
179
|
+
const shmNameOk = (name: string): boolean => {
|
|
180
|
+
const n: i32 = toI32(name.length)
|
|
181
|
+
if (n < 1 || n > 30) {
|
|
182
|
+
return false
|
|
183
|
+
}
|
|
184
|
+
for (let i: i32 = 0; i < n; i++) {
|
|
185
|
+
const c: i32 = toI32(name.charCodeAt(i))
|
|
186
|
+
const ok =
|
|
187
|
+
(c >= 65 && c <= 90) ||
|
|
188
|
+
(c >= 97 && c <= 122) ||
|
|
189
|
+
(c >= 48 && c <= 57) ||
|
|
190
|
+
c === 46 ||
|
|
191
|
+
c === 95 ||
|
|
192
|
+
c === 45
|
|
193
|
+
if (!ok || (i === 0 && c === 46)) {
|
|
194
|
+
return false
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return true
|
|
198
|
+
}
|
|
199
|
+
|
|
164
200
|
/**
|
|
165
201
|
* Creates the region `name`, `bytes` long and zeroed, mode 0600, and maps it.
|
|
166
202
|
* `SHM_EXISTS` when the name is taken: unlink a stale one first.
|
|
@@ -175,9 +211,12 @@ const shmDone = (rc: i32): Result<void, ShmError> => {
|
|
|
175
211
|
* system gave
|
|
176
212
|
*/
|
|
177
213
|
export const createRegion = (name: string, bytes: i32): Result<SharedRegion, ShmError> => {
|
|
214
|
+
if (!shmNameOk(name)) {
|
|
215
|
+
return Err(new ShmError(SHM_INVALID))
|
|
216
|
+
}
|
|
178
217
|
const h: i32 = nishshm_create(name, bytes)
|
|
179
218
|
if (h < 0) {
|
|
180
|
-
return Err(new ShmError(
|
|
219
|
+
return Err(new ShmError(shmErrno(h)))
|
|
181
220
|
}
|
|
182
221
|
return Ok(new SharedRegion(h))
|
|
183
222
|
}
|
|
@@ -196,9 +235,12 @@ export const createRegion = (name: string, bytes: i32): Result<SharedRegion, Shm
|
|
|
196
235
|
* system gave
|
|
197
236
|
*/
|
|
198
237
|
export const openRegion = (name: string): Result<SharedRegion, ShmError> => {
|
|
238
|
+
if (!shmNameOk(name)) {
|
|
239
|
+
return Err(new ShmError(SHM_INVALID))
|
|
240
|
+
}
|
|
199
241
|
const h: i32 = nishshm_open(name)
|
|
200
242
|
if (h < 0) {
|
|
201
|
-
return Err(new ShmError(
|
|
243
|
+
return Err(new ShmError(shmErrno(h)))
|
|
202
244
|
}
|
|
203
245
|
return Ok(new SharedRegion(h))
|
|
204
246
|
}
|
|
@@ -211,7 +253,12 @@ export const openRegion = (name: string): Result<SharedRegion, ShmError> => {
|
|
|
211
253
|
* @returns `Ok()` once the name is gone, or the `ShmError`: `SHM_NOT_FOUND`,
|
|
212
254
|
* `SHM_INVALID`, code 95 on wasi, or the errno the system gave
|
|
213
255
|
*/
|
|
214
|
-
export const unlinkRegion = (name: string): Result<void, ShmError> =>
|
|
256
|
+
export const unlinkRegion = (name: string): Result<void, ShmError> => {
|
|
257
|
+
if (!shmNameOk(name)) {
|
|
258
|
+
return Err(new ShmError(SHM_INVALID))
|
|
259
|
+
}
|
|
260
|
+
return shmDone(nishshm_unlink(name))
|
|
261
|
+
}
|
|
215
262
|
|
|
216
263
|
/**
|
|
217
264
|
* A fence of `order`, for the accesses around it: C11's
|