@amritk/nish-aarch64-linux 0.44.0 → 0.46.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 +3 -1
  2. package/bin/nish +0 -0
  3. package/docs/AI.md +18 -16
  4. package/package.json +1 -1
  5. package/runtime/core/numbers.mjs +3 -1
  6. package/runtime/core/strings.mjs +90 -38
  7. package/runtime/core.d.ts +8 -0
  8. package/runtime/core.mjs +16 -0
  9. package/runtime/nish.d.ts +88 -5
  10. package/runtime/nish.h +10 -0
  11. package/runtime/nish.mjs +5 -0
  12. package/runtime/runtime-host.c +15 -0
  13. package/runtime/runtime-net.c +223 -4
  14. package/runtime/runtime-os.c +15 -1
  15. package/runtime/runtime-uring.c +291 -31
  16. package/runtime/sqlite/nish-sqlite.c +301 -128
  17. package/std/README.md +15 -15
  18. package/std/array.ts +10 -2
  19. package/std/bytes.ts +239 -26
  20. package/std/cli-args.ts +1072 -606
  21. package/std/cli-flags.ts +180 -98
  22. package/std/cli.ts +21 -13
  23. package/std/collections.ts +245 -127
  24. package/std/compress/checksum.ts +32 -37
  25. package/std/compress/deflate.ts +1102 -542
  26. package/std/compress/gzip.ts +290 -145
  27. package/std/compress/zlib.ts +57 -21
  28. package/std/crypto/aes.ts +153 -75
  29. package/std/crypto/base64url.ts +84 -61
  30. package/std/crypto/bcrypt-batch.ts +164 -90
  31. package/std/crypto/bcrypt.ts +185 -107
  32. package/std/crypto/chacha20poly1305.ts +84 -68
  33. package/std/crypto/ct.ts +9 -7
  34. package/std/crypto/ed25519.ts +64 -27
  35. package/std/crypto/hkdf.ts +105 -63
  36. package/std/crypto/hmac.ts +95 -89
  37. package/std/crypto/jwt.ts +248 -126
  38. package/std/crypto/p256.ts +758 -444
  39. package/std/crypto/p384.ts +20 -13
  40. package/std/crypto/pki-roots.ts +95 -38
  41. package/std/crypto/pki.ts +164 -60
  42. package/std/crypto/rsa.ts +266 -223
  43. package/std/crypto/scram.ts +3 -4
  44. package/std/crypto/sha1.ts +107 -65
  45. package/std/crypto/sha256.ts +502 -422
  46. package/std/crypto/sha512.ts +204 -135
  47. package/std/crypto/x509-random.ts +9 -3
  48. package/std/crypto/x509.ts +331 -171
  49. package/std/json-equal.ts +35 -19
  50. package/std/json-format.ts +215 -108
  51. package/std/json-number.ts +126 -72
  52. package/std/json-pointer.ts +42 -13
  53. package/std/json-tokenizer.ts +498 -307
  54. package/std/json-typed.ts +115 -36
  55. package/std/json-value.ts +341 -152
  56. package/std/json.ts +300 -158
  57. package/std/net/buffer-pool.ts +17 -7
  58. package/std/net/dns-config.ts +427 -236
  59. package/std/net/dns-message.ts +114 -47
  60. package/std/net/dns-resolver.ts +736 -237
  61. package/std/net/dns.ts +205 -52
  62. package/std/net/fetch.ts +320 -184
  63. package/std/net/grpc.ts +948 -0
  64. package/std/net/handler.ts +1315 -222
  65. package/std/net/hpack.ts +395 -180
  66. package/std/net/http-compress.ts +502 -65
  67. package/std/net/http-fields.ts +85 -49
  68. package/std/net/http-server.ts +1764 -602
  69. package/std/net/http1-client-codec.ts +372 -161
  70. package/std/net/http1-codec.ts +665 -331
  71. package/std/net/http1-server.ts +660 -278
  72. package/std/net/http2-cleartext.ts +165 -95
  73. package/std/net/http2-frame.ts +232 -89
  74. package/std/net/http2-tls.ts +42 -12
  75. package/std/net/http2.ts +327 -101
  76. package/std/net/http3-frame.ts +68 -33
  77. package/std/net/http3-server.ts +647 -192
  78. package/std/net/http3.ts +667 -189
  79. package/std/net/oidc.ts +63 -24
  80. package/std/net/outbound.ts +207 -142
  81. package/std/net/postgres-async.ts +1165 -443
  82. package/std/net/postgres-carrier.ts +575 -372
  83. package/std/net/postgres.ts +1459 -559
  84. package/std/net/prefork.ts +254 -98
  85. package/std/net/protobuf.ts +1017 -0
  86. package/std/net/qpack.ts +143 -92
  87. package/std/net/quic-conn-ack.ts +50 -18
  88. package/std/net/quic-conn-cid.ts +66 -26
  89. package/std/net/quic-conn-params.ts +13 -7
  90. package/std/net/quic-datagram.ts +90 -27
  91. package/std/net/quic-frame.ts +225 -124
  92. package/std/net/quic-listener.ts +197 -89
  93. package/std/net/quic-packet.ts +289 -163
  94. package/std/net/quic-recovery.ts +279 -128
  95. package/std/net/quic-stream.ts +466 -167
  96. package/std/net/quic.ts +568 -257
  97. package/std/net/router.ts +450 -99
  98. package/std/net/serve.ts +651 -232
  99. package/std/net/static.ts +1458 -0
  100. package/std/net/tls/client.ts +140 -45
  101. package/std/net/tls/codec.ts +510 -260
  102. package/std/net/tls/record-client.ts +268 -76
  103. package/std/net/tls/record-server.ts +236 -79
  104. package/std/net/tls/record.ts +173 -47
  105. package/std/net/tls/schedule.ts +58 -39
  106. package/std/net/tls/ticket.ts +295 -103
  107. package/std/net/tls/verify.ts +1 -1
  108. package/std/net/tls-tcp.ts +218 -75
  109. package/std/net/tls.ts +260 -152
  110. package/std/net/upstream.ts +283 -86
  111. package/std/net/url.ts +277 -102
  112. package/std/net/websocket.ts +370 -186
  113. package/std/net/webtransport.ts +755 -436
  114. package/std/regex.ts +1659 -829
  115. package/std/sqlite.ts +171 -0
  116. package/std/sync/ring.ts +320 -156
  117. package/std/sync/shm.ts +53 -6
  118. package/std/text.ts +205 -124
  119. package/std/threads.ts +22 -2
package/std/json-equal.ts CHANGED
@@ -102,25 +102,33 @@ const jsonEqualSortedMembers = (doc: JsonDocument, v: i32, keys: string[]): i32[
102
102
  order.push(i)
103
103
  spare.push(i)
104
104
  }
105
- // A document holds at most 2^22 values, so the widths below never come
106
- // near overflowing.
105
+ // `lo`, `mid` and `width` all lie in `0..n` with `n` an `i32`, so each sum
106
+ // and double below is under 2^32 and cannot wrap in `u32`; past `n` it is
107
+ // clamped to `n`, as the merge needs.
107
108
  let width: i32 = 1
108
109
  while (width < n) {
109
110
  let lo: i32 = 0
110
111
  while (lo < n) {
111
- const mid: i32 = lo + width < n ? lo + width : n
112
- const hi: i32 = mid + width < n ? mid + width : n
112
+ const midWide: u32 = toU32(lo) + toU32(width)
113
+ const mid: i32 = midWide < toU32(n) ? toI32(midWide) : n
114
+ const hiWide: u32 = toU32(mid) + toU32(width)
115
+ const hi: i32 = hiWide < toU32(n) ? toI32(hiWide) : n
113
116
  let i: i32 = lo
114
117
  let j: i32 = mid
115
118
  for (let k: i32 = lo; k < hi; k++) {
116
119
  const left: i32 = jsonEqualAt(order, i)
117
120
  const right: i32 = jsonEqualAt(order, j)
118
- const takeLeft: boolean =
119
- i < mid && (j >= hi || !jsonEqualBefore(jsonEqualKeyAt(keys, right), jsonEqualKeyAt(keys, left)))
120
- jsonEqualSetAt(spare, k, takeLeft ? left : right)
121
- if (takeLeft) {
121
+ if (
122
+ i < mid &&
123
+ (j >= hi || !jsonEqualBefore(jsonEqualKeyAt(keys, right), jsonEqualKeyAt(keys, left)))
124
+ ) {
125
+ jsonEqualSetAt(spare, k, left)
122
126
  i += 1
123
- } else {
127
+ } else if (j < hi) {
128
+ // Always true here: `k - lo` members are taken, `(i - lo) + (j - mid)`
129
+ // of them, and `k < hi`, so a run whose left half is spent has a right
130
+ // member left.
131
+ jsonEqualSetAt(spare, k, right)
124
132
  j += 1
125
133
  }
126
134
  }
@@ -129,7 +137,8 @@ const jsonEqualSortedMembers = (doc: JsonDocument, v: i32, keys: string[]): i32[
129
137
  const done: i32[] = spare
130
138
  spare = order
131
139
  order = done
132
- width = width * 2
140
+ const doubled: u32 = toU32(width) * 2
141
+ width = doubled < toU32(n) ? toI32(doubled) : n
133
142
  }
134
143
  return order
135
144
  }
@@ -156,9 +165,13 @@ export const jsonEqual = (da: JsonDocument, a: i32, db: JsonDocument, b: i32): b
156
165
  const left: i32[] = [a]
157
166
  const right: i32[] = [b]
158
167
  while (left.length > 0) {
159
- const x: i32 = jsonEqualAt(left, toI32(left.length) - 1)
160
- const y: i32 = jsonEqualAt(right, toI32(right.length) - 1)
168
+ const x: i32 = left[left.length - 1]
161
169
  left.pop()
170
+ // Never taken: the two stacks are pushed in pairs, so they empty together.
171
+ if (right.length === 0) {
172
+ return false
173
+ }
174
+ const y: i32 = right[right.length - 1]
162
175
  right.pop()
163
176
  const kind: i32 = da.kind(x)
164
177
  if (kind === JSON_VALUE_NONE || kind !== db.kind(y)) {
@@ -238,11 +251,14 @@ const jsonEqualCanonicalText = (doc: JsonDocument, v: i32): string => {
238
251
  const tasks: i32[] = [v]
239
252
  const keyStack: string[] = []
240
253
  while (tasks.length > 0) {
241
- const x: i32 = jsonEqualAt(tasks, toI32(tasks.length) - 1)
254
+ const x: i32 = tasks[tasks.length - 1]
242
255
  tasks.pop()
243
256
  if (x === JSON_EQUAL_KEY_TASK) {
244
- jsonEqualPutText(out, jsonEqualKeyAt(keyStack, toI32(keyStack.length) - 1))
245
- keyStack.pop()
257
+ // Each key task is pushed with its key, so the key stack holds one here.
258
+ if (keyStack.length > 0) {
259
+ jsonEqualPutText(out, keyStack[keyStack.length - 1])
260
+ keyStack.pop()
261
+ }
246
262
  continue
247
263
  }
248
264
  const kind: i32 = doc.kind(x)
@@ -258,8 +274,8 @@ const jsonEqualCanonicalText = (doc: JsonDocument, v: i32): string => {
258
274
  } else if (kind === JSON_VALUE_ARRAY) {
259
275
  const n: i32 = doc.length(x)
260
276
  jsonEqualPut(out, `a${n}:`)
261
- for (let i: i32 = n - 1; i >= 0; i--) {
262
- tasks.push(doc.at(x, i))
277
+ for (let i: i32 = n; i > 0; i--) {
278
+ tasks.push(doc.at(x, i - 1))
263
279
  }
264
280
  } else {
265
281
  const n: i32 = doc.length(x)
@@ -267,8 +283,8 @@ const jsonEqualCanonicalText = (doc: JsonDocument, v: i32): string => {
267
283
  const keys: string[] = []
268
284
  const order: i32[] = jsonEqualSortedMembers(doc, x, keys)
269
285
  // Pushed last member first, each value before its key, so the key pops first.
270
- for (let i: i32 = n - 1; i >= 0; i--) {
271
- const m: i32 = jsonEqualAt(order, i)
286
+ for (let i: i32 = n; i > 0; i--) {
287
+ const m: i32 = jsonEqualAt(order, i - 1)
272
288
  tasks.push(doc.at(x, m))
273
289
  tasks.push(JSON_EQUAL_KEY_TASK)
274
290
  keyStack.push(jsonEqualKeyAt(keys, m))