@waffle-os/runtime 0.0.154 → 0.0.156

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 (42) hide show
  1. package/core/filesystem.ts +22 -0
  2. package/core/wasi.ts +78 -5
  3. package/dist/core/filesystem.js +1 -0
  4. package/dist/core/wasi.js +71 -6
  5. package/dist/fs/backend.js +22 -1
  6. package/dist/fs/client.js +11 -3
  7. package/dist/fs/cold-read-cache.js +23 -0
  8. package/dist/fs/guest-watch.js +267 -94
  9. package/dist/fs/indexeddb-chunks.js +88 -11
  10. package/dist/fs/indexeddb.js +78 -14
  11. package/dist/fs/memory.js +17 -1
  12. package/dist/fs/multitab-backend.js +198 -64
  13. package/dist/fs/multitab-protocol.js +1 -0
  14. package/dist/fs/persistent.js +19 -1
  15. package/dist/fs/service.js +30 -1
  16. package/dist/fs/shared.js +4 -0
  17. package/dist/fs/storage.js +107 -8
  18. package/dist/fs/watch-service.js +97 -2
  19. package/dist/fs/watch-subscriptions.js +121 -8
  20. package/dist/proc/intrinsics/core.js +5 -0
  21. package/dist/proc/intrinsics.js +1 -0
  22. package/dist/tooling/program/program-transformer.json +1 -1
  23. package/fs/backend.ts +27 -1
  24. package/fs/client.ts +11 -0
  25. package/fs/cold-read-cache.ts +38 -0
  26. package/fs/guest-watch.ts +298 -102
  27. package/fs/indexeddb-chunks.ts +103 -9
  28. package/fs/indexeddb.ts +98 -11
  29. package/fs/memory.ts +18 -0
  30. package/fs/multitab-backend.ts +273 -72
  31. package/fs/multitab-protocol.ts +1 -0
  32. package/fs/persistent.ts +38 -1
  33. package/fs/service.ts +28 -0
  34. package/fs/shared.ts +4 -0
  35. package/fs/storage.ts +128 -10
  36. package/fs/watch-service.ts +110 -3
  37. package/fs/watch-subscriptions.ts +115 -7
  38. package/package.json +1 -1
  39. package/proc/intrinsics/core.ts +7 -0
  40. package/proc/intrinsics.ts +1 -0
  41. package/testing/indexeddb-storage-browser.ts +129 -0
  42. package/tooling/program/program-transformer.json +1 -1
@@ -11,6 +11,10 @@ export class FilesystemError extends Error {
11
11
 
12
12
  /** Opaque filesystem-owned identity. Open handles remain valid across rename and unlink. */
13
13
  export type FileHandle = number;
14
+ /** What `FileSystem.probe` looks for: a regular file or a directory. */
15
+ export type ProbeKind = "file" | "directory";
16
+ /** Most pathnames one `probe` call looks up. */
17
+ export const PROBE_PATH_LIMIT = 64;
14
18
  export interface FilePermissions {
15
19
  mode: number;
16
20
  modeSupported: number;
@@ -111,6 +115,10 @@ export interface FileSystem {
111
115
  * absolute path from the root; otherwise relative to `directory` ("." for itself). Positive
112
116
  * WASI errno on failure. */
113
117
  realpath(directory: FileHandle, path: string, rooted?: boolean): string | number;
118
+ /** The index of the first of `paths` that names a `kind` node, each looked up from `directory`
119
+ * with every link followed (a stat with the follow flag), or -1 when none does. A path that
120
+ * fails to resolve does not match. A bad `directory` throws a FilesystemError. */
121
+ probe(directory: FileHandle, paths: readonly string[], kind: ProbeKind, rooted?: boolean): number;
114
122
  symlink(path: ResolvedPath, target: string): number;
115
123
  readlink(handle: FileHandle): string;
116
124
  stat(handle: FileHandle): FileStat;
@@ -154,6 +162,16 @@ export interface FileSystem {
154
162
  readonly watches?: WatchFileSystem;
155
163
  }
156
164
 
165
+ /** One ready subscription returned by a batched owner drain. */
166
+ export type WatchDrainEntry =
167
+ | { readonly id: number; readonly batch: WatchBatch }
168
+ | { readonly id: number; readonly errno: number };
169
+
170
+ export interface WatchDrainResult {
171
+ readonly entries: readonly WatchDrainEntry[];
172
+ readonly more: boolean;
173
+ }
174
+
157
175
  /** The opener's filesystem session owns each subscription; session close releases them all. */
158
176
  export interface WatchFileSystem {
159
177
  /** The root's watch cells. Index 3 counts committed watch records. */
@@ -161,8 +179,12 @@ export interface WatchFileSystem {
161
179
  readonly revoked: boolean;
162
180
  /** True when watches are served remotely (attach mode); disables local-generation short-circuit. */
163
181
  readonly remote?: boolean;
182
+ /** True when `drain()` is currently supported by the active backend role. Defaults to `typeof drain === "function"`. */
183
+ readonly canDrain?: boolean;
164
184
  /** Throws FilesystemError. */
165
185
  open(handle: FileHandle, recursive: boolean): number;
166
186
  read(id: number): WatchBatch;
187
+ /** Optional batched drain of ready watches for this session in one round trip. */
188
+ drain?(): WatchDrainResult;
167
189
  close(id: number): void;
168
190
  }
package/core/wasi.ts CHANGED
@@ -41,10 +41,12 @@ import { withFileOffset } from "./open-file.js";
41
41
  import {
42
42
  FilesystemError,
43
43
  fileTimeNow,
44
+ PROBE_PATH_LIMIT,
44
45
  type FileHandle,
45
46
  type FileSystem,
46
47
  type FileStat,
47
48
  type FileTime,
49
+ type ProbeKind,
48
50
  type ResolvedPath,
49
51
  } from "./filesystem.js";
50
52
  import {
@@ -161,7 +163,7 @@ export interface WasiOptions {
161
163
  // replaces globalThis.performance and crypto with the runtime's polyfills, which call back into
162
164
  // bun.wasm, which calls clock_time_get / random_get here.
163
165
  const encoder = new TextEncoder();
164
- const decoder = new TextDecoder();
166
+ const decoder = new TextDecoder("utf-8", { ignoreBOM: true });
165
167
  const fatalDecoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
166
168
  const perfNow = performance.now.bind(performance);
167
169
  const timeOrigin = performance.timeOrigin;
@@ -198,6 +200,30 @@ function guestPathname(bytes: Uint8Array, ptr: number, len: number): string | un
198
200
  }
199
201
  }
200
202
 
203
+ /** `runtime_fs.path_probe` kinds: 1 a regular file, 2 a directory. */
204
+ const PROBE_KINDS: readonly (ProbeKind | undefined)[] = [undefined, "file", "directory"];
205
+
206
+ /** A path_probe list: one to PROBE_PATH_LIMIT pathnames, each ended by a NUL, exact UTF-8 bytes
207
+ * (a leading U+FEFF kept). Undefined for malformed UTF-8, a missing final NUL, an empty list or
208
+ * too many pathnames. */
209
+ function probePathnames(bytes: Uint8Array, ptr: number, len: number): string[] | undefined {
210
+ if (len === 0 || bytes[ptr + len - 1] !== 0) return undefined;
211
+ const end = ptr + len;
212
+ const paths: string[] = [];
213
+ let start = ptr;
214
+ for (let at = ptr; at < end; at++) {
215
+ if (bytes[at] !== 0) continue;
216
+ if (paths.length === PROBE_PATH_LIMIT) return undefined;
217
+ try {
218
+ paths.push(decodeBytes(bytes, start, at - start, fatalDecoder));
219
+ } catch {
220
+ return undefined;
221
+ }
222
+ start = at + 1;
223
+ }
224
+ return paths;
225
+ }
226
+
201
227
  function writeUtf8Prefix(target: string, output: Uint8Array): number {
202
228
  if (output.length === 0) return 0;
203
229
  // Browser encodeInto rejects resizable backing buffers, including fixed-length views.
@@ -495,9 +521,11 @@ export class Wasi {
495
521
  const filesystem: Record<string, (...args: never[]) => number> = {
496
522
  path_permissions_get: this.pathPermissions.bind(this),
497
523
  path_realpath: this.pathRealpath.bind(this),
524
+ path_probe: this.pathProbe.bind(this),
498
525
  watch_open: this.watchOpen.bind(this),
499
526
  watch_ready: () => (this.watches?.ready() ? 1 : 0),
500
527
  watch_read: this.watchRead.bind(this),
528
+ watch_next: this.watchNext.bind(this),
501
529
  watch_close: (id: number) => this.watches?.close(id >>> 0) ?? EBADF,
502
530
  };
503
531
  const out: WebAssembly.Imports = Object.create(null);
@@ -690,16 +718,37 @@ export class Wasi {
690
718
  }
691
719
 
692
720
  private watchRead(id: number, buf: number, len: number, out: number): number {
721
+ return this.writeWatch(id >>> 0, buf, len, out, -1);
722
+ }
723
+
724
+ private watchNext(outId: number, buf: number, len: number, out: number): number {
725
+ return this.writeWatch(-1, buf, len, out, outId >>> 0);
726
+ }
727
+
728
+ private writeWatch(id: number, buf: number, len: number, out: number, outId: number): number {
693
729
  buf >>>= 0;
694
730
  len >>>= 0;
695
731
  out >>>= 0;
696
732
  const size = this.bytes().length;
697
- if (buf + len > size || out + 4 > size) return EFAULT;
698
- const result = this.watches?.read(id >>> 0, len);
699
- if (!result) return EBADF;
733
+ if ((outId >= 0 && outId + 4 > size) || buf + len > size || out + 4 > size) return EFAULT;
734
+ if (
735
+ (len > 0 && buf < out + 4 && out < buf + len) ||
736
+ (outId >= 0 &&
737
+ ((outId < out + 4 && out < outId + 4) || (len > 0 && buf < outId + 4 && outId < buf + len)))
738
+ )
739
+ return EINVAL;
740
+ if (outId >= 0) this.view().setUint32(outId, 0, true);
741
+ const result = id >= 0 ? this.watches?.read(id, len) : this.watches?.readNext(len);
742
+ if (!result) return id >= 0 ? EBADF : 6;
700
743
  if (result.kind === "error") return result.errno;
744
+ const view = this.view();
745
+ if (outId >= 0) view.setUint32(outId, "id" in result ? result.id : 0, true);
746
+ if (result.kind === "watch_error") {
747
+ view.setUint32(out, 0, true);
748
+ return result.errno;
749
+ }
701
750
  if (result.kind === "short") {
702
- this.view().setUint32(out, result.needed, true);
751
+ view.setUint32(out, result.needed, true);
703
752
  return ENOBUFS;
704
753
  }
705
754
  // Reacquire after the service round trip; another thread may have grown shared memory.
@@ -751,6 +800,30 @@ export class Wasi {
751
800
  return SUCCESS;
752
801
  }
753
802
 
803
+ /** runtime_fs.path_probe: the index of the first NUL-terminated pathname in `ptr..ptr+len`
804
+ * that names a regular file (`kind` 1) or a directory (`kind` 2), each looked up from `fd` as
805
+ * path_filestat_get with the follow flag does, in one filesystem request. Writes the index, or
806
+ * 0xffffffff when none matches, to the u32 at `found`. See docs/host-abi.md. */
807
+ private pathProbe(fd: number, ptr: number, len: number, kind: number, found: number): number {
808
+ ptr >>>= 0;
809
+ len >>>= 0;
810
+ found >>>= 0;
811
+ const bytes = this.bytes();
812
+ if (ptr + len > bytes.length || found + 4 > bytes.length) return EFAULT;
813
+ const paths = probePathnames(bytes, ptr, len);
814
+ if (paths === undefined) return EINVAL;
815
+ const wanted = PROBE_KINDS[kind >>> 0];
816
+ if (wanted === undefined) return EINVAL;
817
+ const entry = this.descriptors.get(fd >>> 0);
818
+ if (!entry) return EBADF;
819
+ if (entry.resource.kind !== "directory") return ENOTDIR;
820
+ if (!(entry.rightsBase & RIGHT_PATH_FILESTAT_GET)) return ENOTCAPABLE;
821
+ const index = this.opts.fs.probe(entry.resource.handle, paths, wanted, this.rooted);
822
+ // Reacquire after the service round trip; another thread may have grown shared memory.
823
+ this.view().setUint32(found, index < 0 ? 0xffffffff : index, true);
824
+ return SUCCESS;
825
+ }
826
+
754
827
  private pathPermissions(
755
828
  fd: number,
756
829
  ptr: number,
@@ -5,6 +5,7 @@ export class FilesystemError extends Error {
5
5
  this.errno = errno;
6
6
  }
7
7
  }
8
+ export const PROBE_PATH_LIMIT = 64;
8
9
  export function permissionsFor(kind, mode) {
9
10
  const accessSupported = kind === "directory" ? 7 : 6;
10
11
  return {
package/dist/core/wasi.js CHANGED
@@ -37,7 +37,8 @@ import { controlLoad, controlWait } from "../proc/control.js";
37
37
  import { withFileOffset } from "./open-file.js";
38
38
  import {
39
39
  FilesystemError,
40
- fileTimeNow
40
+ fileTimeNow,
41
+ PROBE_PATH_LIMIT
41
42
  } from "./filesystem.js";
42
43
  import {
43
44
  DescriptorTable,
@@ -102,7 +103,7 @@ export class WasiExit extends ExecutionUnwind {
102
103
  }
103
104
  }
104
105
  const encoder = new TextEncoder;
105
- const decoder = new TextDecoder;
106
+ const decoder = new TextDecoder("utf-8", { ignoreBOM: true });
106
107
  const fatalDecoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
107
108
  const perfNow = performance.now.bind(performance);
108
109
  const timeOrigin = performance.timeOrigin;
@@ -126,6 +127,27 @@ function guestPathname(bytes, ptr, len) {
126
127
  return;
127
128
  }
128
129
  }
130
+ const PROBE_KINDS = [undefined, "file", "directory"];
131
+ function probePathnames(bytes, ptr, len) {
132
+ if (len === 0 || bytes[ptr + len - 1] !== 0)
133
+ return;
134
+ const end = ptr + len;
135
+ const paths = [];
136
+ let start = ptr;
137
+ for (let at = ptr;at < end; at++) {
138
+ if (bytes[at] !== 0)
139
+ continue;
140
+ if (paths.length === PROBE_PATH_LIMIT)
141
+ return;
142
+ try {
143
+ paths.push(decodeBytes(bytes, start, at - start, fatalDecoder));
144
+ } catch {
145
+ return;
146
+ }
147
+ start = at + 1;
148
+ }
149
+ return paths;
150
+ }
129
151
  function writeUtf8Prefix(target, output) {
130
152
  if (output.length === 0)
131
153
  return 0;
@@ -347,9 +369,11 @@ export class Wasi {
347
369
  const filesystem = {
348
370
  path_permissions_get: this.pathPermissions.bind(this),
349
371
  path_realpath: this.pathRealpath.bind(this),
372
+ path_probe: this.pathProbe.bind(this),
350
373
  watch_open: this.watchOpen.bind(this),
351
374
  watch_ready: () => this.watches?.ready() ? 1 : 0,
352
375
  watch_read: this.watchRead.bind(this),
376
+ watch_next: this.watchNext.bind(this),
353
377
  watch_close: (id) => this.watches?.close(id >>> 0) ?? EBADF
354
378
  };
355
379
  const out = Object.create(null);
@@ -517,19 +541,36 @@ export class Wasi {
517
541
  return SUCCESS;
518
542
  }
519
543
  watchRead(id, buf, len, out) {
544
+ return this.writeWatch(id >>> 0, buf, len, out, -1);
545
+ }
546
+ watchNext(outId, buf, len, out) {
547
+ return this.writeWatch(-1, buf, len, out, outId >>> 0);
548
+ }
549
+ writeWatch(id, buf, len, out, outId) {
520
550
  buf >>>= 0;
521
551
  len >>>= 0;
522
552
  out >>>= 0;
523
553
  const size = this.bytes().length;
524
- if (buf + len > size || out + 4 > size)
554
+ if (outId >= 0 && outId + 4 > size || buf + len > size || out + 4 > size)
525
555
  return EFAULT;
526
- const result = this.watches?.read(id >>> 0, len);
556
+ if (len > 0 && buf < out + 4 && out < buf + len || outId >= 0 && (outId < out + 4 && out < outId + 4 || len > 0 && buf < outId + 4 && outId < buf + len))
557
+ return EINVAL;
558
+ if (outId >= 0)
559
+ this.view().setUint32(outId, 0, true);
560
+ const result = id >= 0 ? this.watches?.read(id, len) : this.watches?.readNext(len);
527
561
  if (!result)
528
- return EBADF;
562
+ return id >= 0 ? EBADF : 6;
529
563
  if (result.kind === "error")
530
564
  return result.errno;
565
+ const view = this.view();
566
+ if (outId >= 0)
567
+ view.setUint32(outId, "id" in result ? result.id : 0, true);
568
+ if (result.kind === "watch_error") {
569
+ view.setUint32(out, 0, true);
570
+ return result.errno;
571
+ }
531
572
  if (result.kind === "short") {
532
- this.view().setUint32(out, result.needed, true);
573
+ view.setUint32(out, result.needed, true);
533
574
  return ENOBUFS;
534
575
  }
535
576
  const bytes = this.bytes();
@@ -573,6 +614,30 @@ export class Wasi {
573
614
  this.memory.range(buf, encoded.length).set(encoded);
574
615
  return SUCCESS;
575
616
  }
617
+ pathProbe(fd, ptr, len, kind, found) {
618
+ ptr >>>= 0;
619
+ len >>>= 0;
620
+ found >>>= 0;
621
+ const bytes = this.bytes();
622
+ if (ptr + len > bytes.length || found + 4 > bytes.length)
623
+ return EFAULT;
624
+ const paths = probePathnames(bytes, ptr, len);
625
+ if (paths === undefined)
626
+ return EINVAL;
627
+ const wanted = PROBE_KINDS[kind >>> 0];
628
+ if (wanted === undefined)
629
+ return EINVAL;
630
+ const entry = this.descriptors.get(fd >>> 0);
631
+ if (!entry)
632
+ return EBADF;
633
+ if (entry.resource.kind !== "directory")
634
+ return ENOTDIR;
635
+ if (!(entry.rightsBase & RIGHT_PATH_FILESTAT_GET))
636
+ return ENOTCAPABLE;
637
+ const index = this.opts.fs.probe(entry.resource.handle, paths, wanted, this.rooted);
638
+ this.view().setUint32(found, index < 0 ? 4294967295 : index, true);
639
+ return SUCCESS;
640
+ }
576
641
  pathPermissions(fd, ptr, len, flags, out) {
577
642
  if (flags !== 0)
578
643
  return ENOTSUP;
@@ -6,10 +6,28 @@ import {
6
6
  mutationValue
7
7
  } from "./publication.js";
8
8
  import { IdentityAllocator } from "./file-identity.js";
9
- import { fileTimeMs, fileTimeNow, msFileTime } from "../core/filesystem.js";
9
+ import {
10
+ fileTimeMs,
11
+ fileTimeNow,
12
+ msFileTime,
13
+ PROBE_PATH_LIMIT
14
+ } from "../core/filesystem.js";
10
15
  import { MemFS } from "./memory.js";
11
16
  import { FilesystemError } from "./protocol.js";
12
17
  import { SharedFilesystemState } from "./shared.js";
18
+ function probePaths(value) {
19
+ if (!Array.isArray(value) || value.length > PROBE_PATH_LIMIT)
20
+ throw new FilesystemError(28);
21
+ for (const path of value)
22
+ if (typeof path !== "string")
23
+ throw new FilesystemError(28);
24
+ return value;
25
+ }
26
+ function probeKind(value) {
27
+ if (value !== "file" && value !== "directory")
28
+ throw new FilesystemError(28);
29
+ return value;
30
+ }
13
31
  function sameTimes(left, right) {
14
32
  return left !== undefined && left.atime === right.atime && left.mtime === right.mtime && left.ctime === right.ctime;
15
33
  }
@@ -273,6 +291,9 @@ export class MemoryBackend {
273
291
  case "realpath":
274
292
  this.check(a, "directory");
275
293
  return this.fs.realpath(a, b, c === true);
294
+ case "probe":
295
+ this.check(a, "directory");
296
+ return this.fs.probe(a, probePaths(b), probeKind(c), args[3] === true);
276
297
  case "readlink":
277
298
  this.check(a);
278
299
  return this.fs.readlink(a);
package/dist/fs/client.js CHANGED
@@ -153,7 +153,8 @@ const PLAIN_REPLIES = new SetConstructor([
153
153
  "setTimes",
154
154
  "setMode",
155
155
  "read",
156
- "readlink"
156
+ "readlink",
157
+ "probe"
157
158
  ]);
158
159
 
159
160
  export class FilesystemCompletion {
@@ -429,7 +430,7 @@ function preparationFailed(completion) {
429
430
  const state = completion?.cells[0];
430
431
  return state === State.Failed || state === State.Cancelled;
431
432
  }
432
- function clientWatches(cells, revoked, remote, call) {
433
+ function clientWatches(cells, revoked, remote, canDrain, call) {
433
434
  return {
434
435
  get cells() {
435
436
  return cells();
@@ -440,8 +441,12 @@ function clientWatches(cells, revoked, remote, call) {
440
441
  get remote() {
441
442
  return remote();
442
443
  },
444
+ get canDrain() {
445
+ return canDrain();
446
+ },
443
447
  open: (handle, recursive) => call("watchOpen", [handle, recursive]),
444
448
  read: (id) => call("watchRead", [id]),
449
+ drain: () => call("watchDrain", []),
445
450
  close: (id) => {
446
451
  call("watchClose", [id]);
447
452
  }
@@ -515,7 +520,7 @@ export class FilesystemClient {
515
520
  this.resident = new ResidentAttachment(connection.residentPublication, this.revoked);
516
521
  this.section = new FilesystemTransportSection(connection, this.requests.memory, this.revoked);
517
522
  this.shared = new SharedFilesystemState(connection.shared, connection.maxBytes, connection.owner, connection.segments, this.section, connection.publication?.buffers);
518
- this.watches = clientWatches(() => this.shared.watch.cells, this.revoked, () => this.shared.isDirectDisabled(), (operation, args) => this.call(operation, args));
523
+ this.watches = clientWatches(() => this.shared.watch.cells, this.revoked, () => this.shared.isDirectDisabled(), () => !this.shared.isWatchDrainDisabled(), (operation, args) => this.call(operation, args));
519
524
  connection.port.onmessage = ({ data }) => {
520
525
  if (data.segment)
521
526
  this.attachSegment(data.segment, data.buffer);
@@ -2101,6 +2106,9 @@ export class FilesystemClient {
2101
2106
  return errno(error);
2102
2107
  }
2103
2108
  }
2109
+ probe(directory, paths, kind, rooted = false) {
2110
+ return this.call("probe", [directory, paths, kind, rooted]);
2111
+ }
2104
2112
  readlink(handle) {
2105
2113
  this.retain(handle);
2106
2114
  try {
@@ -1,14 +1,36 @@
1
1
  import { PAGE } from "./shared-capacity.js";
2
2
  const COLD_READ_CACHE_BYTES = 32 * 1024 * 1024;
3
3
  export const COLD_PAGE_OVERHEAD = 256;
4
+ const READAHEAD_PAGES = 16;
5
+ export const READAHEAD_BYTES = READAHEAD_PAGES * PAGE;
6
+ const STREAMS = 64;
4
7
 
5
8
  export class ColdReadCache {
6
9
  limit;
7
10
  pages = new Map;
11
+ ends = new Map;
8
12
  bytes = 0;
9
13
  constructor(limit = COLD_READ_CACHE_BYTES) {
10
14
  this.limit = limit;
11
15
  }
16
+ readWindow(key, offset, count, size) {
17
+ if (this.ends.get(key) !== offset)
18
+ return { offset, length: count };
19
+ const windowPages = Math.min(READAHEAD_PAGES, Math.floor(this.limit / 2 / (PAGE + COLD_PAGE_OVERHEAD)));
20
+ if (windowPages < 1)
21
+ return { offset, length: count };
22
+ const start = Math.floor(offset / PAGE) * PAGE;
23
+ const end = Math.min(size, start + windowPages * PAGE);
24
+ if (end < offset + count)
25
+ return { offset, length: count };
26
+ return { offset: start, length: end - start };
27
+ }
28
+ noteRead(key, end) {
29
+ this.ends.delete(key);
30
+ if (this.ends.size >= STREAMS)
31
+ this.ends.delete(this.ends.keys().next().value);
32
+ this.ends.set(key, end);
33
+ }
12
34
  read(key, offset, length) {
13
35
  const first = Math.floor(offset / PAGE);
14
36
  const last = Math.floor((offset + length - 1) / PAGE);
@@ -46,6 +68,7 @@ export class ColdReadCache {
46
68
  }
47
69
  clear() {
48
70
  this.pages.clear();
71
+ this.ends.clear();
49
72
  this.bytes = 0;
50
73
  }
51
74
  remove(name) {