@waffle-os/runtime 0.0.147 → 0.0.148

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 (48) hide show
  1. package/browser/filesystem-backend.ts +26 -5
  2. package/browser/fs-worker.ts +5 -2
  3. package/browser/shared-fs.ts +93 -10
  4. package/core/filesystem.ts +2 -0
  5. package/dist/browser/filesystem-backend.js +19 -2
  6. package/dist/browser/fs-worker.js +7 -2
  7. package/dist/browser/shared-fs.js +77 -8
  8. package/dist/fs/client.js +82 -21
  9. package/dist/fs/directory-pages.js +22 -7
  10. package/dist/fs/guest-watch.js +9 -3
  11. package/dist/fs/idle-database.js +1 -1
  12. package/dist/fs/idle-owner.js +35 -4
  13. package/dist/fs/indexeddb.js +322 -63
  14. package/dist/fs/memory.js +18 -9
  15. package/dist/fs/multitab-backend.js +5065 -0
  16. package/dist/fs/multitab-protocol.js +301 -0
  17. package/dist/fs/opfs.js +21 -0
  18. package/dist/fs/persistent.js +70 -1
  19. package/dist/fs/protocol.js +1 -1
  20. package/dist/fs/service.js +266 -86
  21. package/dist/fs/shared.js +45 -0
  22. package/dist/fs/vfs.js +26 -8
  23. package/dist/fs/watch-ring.js +7 -3
  24. package/dist/proc/command-stdio.js +56 -1
  25. package/dist/runtime.js +4 -2
  26. package/dist/tooling/program/program-transformer.json +1 -1
  27. package/fs/backend.ts +36 -0
  28. package/fs/client.ts +81 -19
  29. package/fs/directory-pages.ts +40 -6
  30. package/fs/guest-watch.ts +8 -3
  31. package/fs/idle-database.ts +1 -0
  32. package/fs/idle-owner.ts +48 -12
  33. package/fs/indexeddb.ts +396 -78
  34. package/fs/memory.ts +33 -9
  35. package/fs/multitab-backend.ts +6870 -0
  36. package/fs/multitab-protocol.ts +655 -0
  37. package/fs/opfs.ts +21 -0
  38. package/fs/persistent.ts +70 -1
  39. package/fs/protocol.ts +1 -1
  40. package/fs/service.ts +314 -109
  41. package/fs/shared.ts +45 -0
  42. package/fs/storage.ts +3 -0
  43. package/fs/vfs.ts +44 -15
  44. package/fs/watch-ring.ts +5 -2
  45. package/package.json +1 -1
  46. package/proc/command-stdio.ts +72 -2
  47. package/runtime.ts +12 -3
  48. package/tooling/program/program-transformer.json +1 -1
package/fs/memory.ts CHANGED
@@ -355,12 +355,27 @@ export class MemFS implements FileSystem {
355
355
  if (node) pages.set({ name, ino: node.ino, kind: nodeKind(node) });
356
356
  else pages.delete(name);
357
357
  }
358
- readdirPage(handle: FileHandle, cookie: bigint, byteLength: number): Uint8Array {
358
+ readdirPage(
359
+ handle: FileHandle,
360
+ cookie: bigint,
361
+ byteLength: number,
362
+ cookieTag?: bigint,
363
+ maxBytes?: number,
364
+ hardCapBytes?: number,
365
+ ): Uint8Array {
359
366
  checkDirectoryPage(cookie, byteLength);
360
367
  const node = this.directory(handle);
361
368
  this.require(node, 4);
362
369
  const parent = this.directoryParents.get(node) ?? node;
363
- return this.directoryPages(node).page(cookie, byteLength, node.ino, parent.ino);
370
+ return this.directoryPages(node).page(
371
+ cookie,
372
+ byteLength,
373
+ node.ino,
374
+ parent.ino,
375
+ cookieTag,
376
+ maxBytes,
377
+ hardCapBytes,
378
+ );
364
379
  }
365
380
  private linkCounts = new WeakMap<Node, number>();
366
381
 
@@ -637,18 +652,23 @@ export class MemFS implements FileSystem {
637
652
  this.changed(node);
638
653
  return 0;
639
654
  }
640
- readdir(handle: FileHandle): DirectoryEntry[] {
655
+ forEachDirEntry(handle: FileHandle, visit: (entry: DirectoryEntry) => void): void {
641
656
  const node = this.directory(handle);
642
657
  this.require(node, 4);
643
658
  const parent = this.directoryParents.get(node) ?? node;
644
- const entry = (name: string, node: Node): DirectoryEntry => ({
659
+ const entry = (name: string, item: Node): DirectoryEntry => ({
645
660
  name,
646
- ino: node.ino,
647
- kind: nodeKind(node),
661
+ ino: item.ino,
662
+ kind: nodeKind(item),
648
663
  });
649
- const list = [entry(".", node), entry("..", parent)];
664
+ visit(entry(".", node));
665
+ visit(entry("..", parent));
666
+ for (const [name, child] of node.children) visit(entry(name, child));
667
+ }
668
+ readdir(handle: FileHandle): DirectoryEntry[] {
669
+ const list: DirectoryEntry[] = [];
650
670
  // One list per call, not one list per entry or cookie. No file buffers cross the boundary.
651
- for (const [name, child] of node.children) list.push(entry(name, child));
671
+ this.forEachDirEntry(handle, (entry) => list.push(entry));
652
672
  return list;
653
673
  }
654
674
  private parentOf(path: ResolvedPath): DirNode | number {
@@ -1261,10 +1281,11 @@ export class MemFS implements FileSystem {
1261
1281
  }
1262
1282
 
1263
1283
  /** Every regular file under `dir`, as absolute paths, sorted. */
1264
- listFiles(dir = "/"): string[] {
1284
+ collectBoundedFilePaths(dir = "/", onFile?: (path: string) => void): string[] {
1265
1285
  const out: string[] = [];
1266
1286
  const walk = (node: Node, path: string) => {
1267
1287
  if (node.kind === "file") {
1288
+ onFile?.(path);
1268
1289
  out.push(path);
1269
1290
  return;
1270
1291
  }
@@ -1281,6 +1302,9 @@ export class MemFS implements FileSystem {
1281
1302
  if (start.node !== undefined) walk(this.nodeForHandle(start.node), start.canonicalPath);
1282
1303
  return out.sort();
1283
1304
  }
1305
+ listFiles(dir = "/"): string[] {
1306
+ return this.collectBoundedFilePaths(dir);
1307
+ }
1284
1308
  }
1285
1309
 
1286
1310
  /** Grow a file's buffer geometrically so many small writes stay linear. */