nish 0.42.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 +11 -5
- package/docs/AI.md +287 -129
- package/package.json +9 -9
- package/runtime/core/numbers.mjs +3 -1
- package/runtime/core/strings.mjs +90 -38
- package/runtime/core.d.ts +24 -0
- package/runtime/core.mjs +21 -0
- package/runtime/nish.d.ts +167 -24
- package/runtime/nish.mjs +7 -1
- package/runtime/runtime-cross.c +9 -0
- package/runtime/runtime-net.c +51 -13
- package/runtime/runtime-region.c +13 -0
- package/runtime/runtime-text.c +11 -0
- package/runtime/runtime-uring.c +83 -25
- package/runtime/runtime-wasm.c +3 -0
- package/runtime/runtime.c +329 -6
- package/runtime/sqlite/README.md +16 -3
- package/runtime/sqlite/nish-sqlite.c +940 -29
- package/scripts/build.sh +111 -29
- package/skills/writing-nish/SKILL.md +12 -4
- package/std/README.md +6 -6
- 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 +163 -39
- 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 +141 -0
- package/std/crypto/sha1.ts +157 -57
- 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/host/ring.ts +1 -1
- package/std/host/text.ts +1 -1
- 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 +1276 -218
- 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 -603
- package/std/net/http1-client-codec.ts +372 -161
- package/std/net/http1-codec.ts +665 -331
- package/std/net/http1-server.ts +881 -269
- 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 +672 -206
- package/std/net/http3.ts +669 -191
- package/std/net/oidc.ts +63 -24
- package/std/net/outbound.ts +207 -142
- package/std/net/postgres-async.ts +1223 -470
- package/std/net/postgres-carrier.ts +575 -372
- package/std/net/postgres.ts +1521 -632
- 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 +104 -22
- 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 +324 -121
- package/std/net/quic-listener.ts +206 -91
- 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 +584 -258
- package/std/net/router.ts +450 -99
- package/std/net/serve.ts +661 -240
- 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 +532 -209
- package/std/net/webtransport.ts +755 -436
- package/std/regex.ts +1659 -829
- package/std/sqlite.ts +325 -0
- package/std/sync/ring.ts +320 -156
- package/std/sync/shm.ts +53 -6
- package/std/text.ts +285 -135
- package/std/threads.ts +22 -2
package/std/net/http-fields.ts
CHANGED
|
@@ -195,11 +195,14 @@ export const httpFieldValueValid = (value: u8[]): boolean => {
|
|
|
195
195
|
return false
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
|
-
|
|
198
|
+
// `n` is the length, so only an empty value, which has no edges to hold
|
|
199
|
+
// whitespace, takes this branch; the test is what proves the two indexes.
|
|
200
|
+
const lastAt: i32 = n - 1
|
|
201
|
+
if (lastAt < 0 || lastAt >= toI32(value.length) || toI32(value.length) < 1) {
|
|
199
202
|
return true
|
|
200
203
|
}
|
|
201
204
|
const first: i32 = toI32(value[0])
|
|
202
|
-
const last: i32 = toI32(value[
|
|
205
|
+
const last: i32 = toI32(value[lastAt])
|
|
203
206
|
return first !== 32 && first !== 9 && last !== 32 && last !== 9
|
|
204
207
|
}
|
|
205
208
|
|
|
@@ -303,7 +306,7 @@ const httpFieldsSameHost = (bytes: u8[], other: u8[]): boolean => {
|
|
|
303
306
|
|
|
304
307
|
/** The pseudo-header bit `name` is, 0 for a regular field, -1 for a name that starts with a colon and is none of them. */
|
|
305
308
|
const httpFieldsPseudoOf = (name: u8[]): i32 => {
|
|
306
|
-
if (toI32(name.length)
|
|
309
|
+
if (toI32(name.length) < 1 || toI32(name[0]) !== 58) {
|
|
307
310
|
return 0
|
|
308
311
|
}
|
|
309
312
|
if (httpFieldIs(name, ":method")) {
|
|
@@ -352,7 +355,8 @@ const httpFieldsStatusOf = (value: u8[]): i32 => {
|
|
|
352
355
|
if (digit < 0 || digit > 9) {
|
|
353
356
|
return -1
|
|
354
357
|
}
|
|
355
|
-
|
|
358
|
+
// Three digits are at most 999, so the unsigned sum cannot leave an `i32`.
|
|
359
|
+
code = toI32(toU32(code) * 10 + toU32(digit))
|
|
356
360
|
}
|
|
357
361
|
return code >= 100 && code <= 599 ? code : -1
|
|
358
362
|
}
|
|
@@ -369,7 +373,9 @@ const httpFieldsLengthOf = (value: u8[]): i64 => {
|
|
|
369
373
|
if (digit < 0 || digit > 9) {
|
|
370
374
|
return toI64(-1)
|
|
371
375
|
}
|
|
372
|
-
|
|
376
|
+
// At most eighteen digits stay below 10^18, so the unsigned sum cannot
|
|
377
|
+
// leave an `i64`.
|
|
378
|
+
length = toI64(toU64(length) * toU64(10) + toU64(digit))
|
|
373
379
|
}
|
|
374
380
|
return length
|
|
375
381
|
}
|
|
@@ -704,19 +710,45 @@ export const HTTP_DATE_LAST_SECOND: i64 = 253402300799
|
|
|
704
710
|
/** The day names from Sunday, then the month names from January, three letters each. */
|
|
705
711
|
const HTTP_FIELDS_DATE_NAMES: string = "SunMonTueWedThuFriSatJanFebMarAprMayJunJulAugSepOctNovDec"
|
|
706
712
|
|
|
707
|
-
/**
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
713
|
+
/**
|
|
714
|
+
* Writes `b` at `out[at + k]`. Its one caller, `httpDateWrite`, has checked
|
|
715
|
+
* `0 <= at` and `at + HTTP_DATE_SIZE <= out.length` before the first write,
|
|
716
|
+
* and every `k` it passes is a constant from 0 to 28, under `HTTP_DATE_SIZE`:
|
|
717
|
+
* so `at + k` is inside `out`, the u32 sum does not wrap and the test always
|
|
718
|
+
* holds. The test is what proves the index; nothing is allocated, and a byte
|
|
719
|
+
* it skipped would show in the `httpDateWrite` round trips `tests/run.js`
|
|
720
|
+
* pins byte for byte (`tests/link/net_http_date`). The skip is unreachable by
|
|
721
|
+
* that room check in `httpDateWrite`, which the prover does not carry across
|
|
722
|
+
* the call, so the test stays.
|
|
723
|
+
*/
|
|
724
|
+
const httpFieldsPut = (out: u8[], at: i32, k: i32, b: u32): void => {
|
|
725
|
+
const pos: i32 = toI32(toU32(at) + toU32(k))
|
|
726
|
+
if (pos >= 0 && pos < toI32(out.length)) {
|
|
727
|
+
out[pos] = toU8(b)
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
/**
|
|
732
|
+
* Writes the three letters at `HTTP_FIELDS_DATE_NAMES[3 * index ..)` at
|
|
733
|
+
* `out[at + k ..)`. `httpDateWrite` passes a weekday, `(days + 4) % 7`, so 0
|
|
734
|
+
* to 6, or `6 + month` with `month` 1 to 12 by the 153-day rule, so 7 to 18:
|
|
735
|
+
* `3 * index + 2` is at most 56, under the table's 57 letters, and the test
|
|
736
|
+
* always holds. It is what proves the index.
|
|
737
|
+
*/
|
|
738
|
+
const httpFieldsPutName = (out: u8[], at: i32, k: i32, index: u32): void => {
|
|
739
|
+
const names: string = HTTP_FIELDS_DATE_NAMES
|
|
740
|
+
for (let d: u32 = 0; d < 3; d++) {
|
|
741
|
+
const pos: i32 = toI32(index * 3 + d)
|
|
742
|
+
if (pos >= 0 && pos < toI32(names.length)) {
|
|
743
|
+
httpFieldsPut(out, at, toI32(toU32(k) + d), toU32(names.charCodeAt(pos)))
|
|
744
|
+
}
|
|
711
745
|
}
|
|
712
746
|
}
|
|
713
747
|
|
|
714
|
-
/** Writes `n`, 0 to 99, as two digits at `out[at ..)`. */
|
|
715
|
-
const httpFieldsPutTwo = (out: u8[], at: i32, n:
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
out[at] = toU8(48 + tens)
|
|
719
|
-
out[at + 1] = toU8(48 + ones)
|
|
748
|
+
/** Writes `n`, 0 to 99, as two digits at `out[at + k ..)`. */
|
|
749
|
+
const httpFieldsPutTwo = (out: u8[], at: i32, k: i32, n: u32): void => {
|
|
750
|
+
httpFieldsPut(out, at, k, toU32(48) + n / 10)
|
|
751
|
+
httpFieldsPut(out, at, toI32(toU32(k) + toU32(1)), toU32(48) + (n % 10))
|
|
720
752
|
}
|
|
721
753
|
|
|
722
754
|
/**
|
|
@@ -732,8 +764,8 @@ const httpFieldsPutTwo = (out: u8[], at: i32, n: i32): void => {
|
|
|
732
764
|
* its author donated to the public domain: days are counted from 0000-03-01,
|
|
733
765
|
* so a leap day is the last day of its year and a 400-year era is always
|
|
734
766
|
* 146,097 days long. Every step
|
|
735
|
-
* is `
|
|
736
|
-
*
|
|
767
|
+
* is `u64` arithmetic on numbers that never wrap, so `--number-mode f64`
|
|
768
|
+
* writes the same bytes.
|
|
737
769
|
*
|
|
738
770
|
* @param out the buffer to write into; its length is not changed
|
|
739
771
|
* @param at the index in `out` where the date's first letter goes
|
|
@@ -750,39 +782,43 @@ export const httpDateWrite = (out: u8[], at: i32, seconds: i64): i32 => {
|
|
|
750
782
|
) {
|
|
751
783
|
return -1
|
|
752
784
|
}
|
|
753
|
-
|
|
754
|
-
|
|
785
|
+
// The test above keeps `seconds` far below 2^63, so every step is `u64`
|
|
786
|
+
// arithmetic on numbers that neither wrap nor go below 0.
|
|
787
|
+
const total: u64 = toU64(seconds)
|
|
788
|
+
const days: u64 = total / 86400
|
|
789
|
+
const inDay: u32 = toU32(total % 86400)
|
|
755
790
|
// 1970-01-01 was a Thursday, and 0 is Sunday.
|
|
756
|
-
const weekday:
|
|
791
|
+
const weekday: u32 = toU32((days + 4) % 7)
|
|
757
792
|
// From 0000-03-01 to 1970-01-01 is 719,468 days.
|
|
758
|
-
const z:
|
|
759
|
-
const era:
|
|
760
|
-
const dayOfEra:
|
|
761
|
-
const yearOfEra:
|
|
762
|
-
const dayOfYear:
|
|
793
|
+
const z: u64 = days + 719468
|
|
794
|
+
const era: u64 = z / 146097
|
|
795
|
+
const dayOfEra: u64 = z - era * 146097
|
|
796
|
+
const yearOfEra: u64 = (dayOfEra - dayOfEra / 1460 + dayOfEra / 36524 - dayOfEra / 146096) / 365
|
|
797
|
+
const dayOfYear: u64 = dayOfEra - (365 * yearOfEra + yearOfEra / 4 - yearOfEra / 100)
|
|
763
798
|
// Months from March, each 30 or 31 days by the 153-day rule.
|
|
764
|
-
const marchMonth:
|
|
765
|
-
const day:
|
|
766
|
-
const month:
|
|
767
|
-
const year:
|
|
768
|
-
httpFieldsPutName(out, at, weekday)
|
|
769
|
-
out
|
|
770
|
-
out
|
|
771
|
-
httpFieldsPutTwo(out, at
|
|
772
|
-
out
|
|
773
|
-
httpFieldsPutName(out, at
|
|
774
|
-
out
|
|
775
|
-
httpFieldsPutTwo(out, at
|
|
776
|
-
httpFieldsPutTwo(out, at
|
|
777
|
-
out
|
|
778
|
-
httpFieldsPutTwo(out, at
|
|
779
|
-
out
|
|
780
|
-
httpFieldsPutTwo(out, at
|
|
781
|
-
out
|
|
782
|
-
httpFieldsPutTwo(out, at
|
|
783
|
-
out
|
|
784
|
-
out
|
|
785
|
-
out
|
|
786
|
-
out
|
|
787
|
-
|
|
799
|
+
const marchMonth: u64 = (5 * dayOfYear + 2) / 153
|
|
800
|
+
const day: u32 = toU32(dayOfYear - (153 * marchMonth + 2) / 5 + 1)
|
|
801
|
+
const month: u32 = toU32(marchMonth < 10 ? marchMonth + 3 : marchMonth - 9)
|
|
802
|
+
const year: u32 = toU32(yearOfEra + era * 400) + (month <= 2 ? 1 : 0)
|
|
803
|
+
httpFieldsPutName(out, at, 0, weekday)
|
|
804
|
+
httpFieldsPut(out, at, 3, 44)
|
|
805
|
+
httpFieldsPut(out, at, 4, 32)
|
|
806
|
+
httpFieldsPutTwo(out, at, 5, day)
|
|
807
|
+
httpFieldsPut(out, at, 7, 32)
|
|
808
|
+
httpFieldsPutName(out, at, 8, 6 + month)
|
|
809
|
+
httpFieldsPut(out, at, 11, 32)
|
|
810
|
+
httpFieldsPutTwo(out, at, 12, year / 100)
|
|
811
|
+
httpFieldsPutTwo(out, at, 14, year % 100)
|
|
812
|
+
httpFieldsPut(out, at, 16, 32)
|
|
813
|
+
httpFieldsPutTwo(out, at, 17, inDay / 3600)
|
|
814
|
+
httpFieldsPut(out, at, 19, 58)
|
|
815
|
+
httpFieldsPutTwo(out, at, 20, (inDay / 60) % 60)
|
|
816
|
+
httpFieldsPut(out, at, 22, 58)
|
|
817
|
+
httpFieldsPutTwo(out, at, 23, inDay % 60)
|
|
818
|
+
httpFieldsPut(out, at, 25, 32)
|
|
819
|
+
httpFieldsPut(out, at, 26, 71)
|
|
820
|
+
httpFieldsPut(out, at, 27, 77)
|
|
821
|
+
httpFieldsPut(out, at, 28, 84)
|
|
822
|
+
// The date fits in `out` from `at`, so the end is at most its length.
|
|
823
|
+
return toI32(toU32(at) + toU32(HTTP_DATE_SIZE))
|
|
788
824
|
}
|