@waffle-os/runtime 0.0.153 → 0.0.155

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 (61) hide show
  1. package/browser/net/helper.ts +114 -19
  2. package/browser/net/ring.ts +18 -6
  3. package/browser/net/runtime.ts +2 -2
  4. package/browser/notification-relay.ts +105 -18
  5. package/browser/notification-wait.ts +45 -4
  6. package/browser/notification-worker.ts +169 -76
  7. package/browser/preview.ts +15 -2
  8. package/core/filesystem.ts +18 -0
  9. package/core/wasi.ts +75 -4
  10. package/dist/browser/net/helper.js +83 -18
  11. package/dist/browser/net/ring.js +6 -5
  12. package/dist/browser/net/runtime.js +2 -2
  13. package/dist/browser/notification-relay.js +78 -15
  14. package/dist/browser/notification-wait.js +37 -5
  15. package/dist/browser/notification-worker.js +146 -67
  16. package/dist/core/wasi.js +62 -4
  17. package/dist/fs/backend.js +7 -0
  18. package/dist/fs/client.js +75 -17
  19. package/dist/fs/dirty-admission.js +15 -8
  20. package/dist/fs/guest-watch.js +267 -94
  21. package/dist/fs/indexeddb-chunks.js +88 -11
  22. package/dist/fs/indexeddb.js +366 -110
  23. package/dist/fs/memory.js +106 -20
  24. package/dist/fs/multitab-backend.js +291 -74
  25. package/dist/fs/multitab-protocol.js +1 -0
  26. package/dist/fs/persistent.js +70 -16
  27. package/dist/fs/protocol.js +15 -7
  28. package/dist/fs/publication-attachment.js +9 -7
  29. package/dist/fs/service.js +62 -9
  30. package/dist/fs/shared.js +100 -6
  31. package/dist/fs/storage.js +107 -8
  32. package/dist/fs/watch-service.js +97 -2
  33. package/dist/fs/watch-subscriptions.js +121 -8
  34. package/dist/proc/command-stdio.js +1 -1
  35. package/dist/proc/intrinsics/core.js +5 -0
  36. package/dist/proc/intrinsics.js +1 -0
  37. package/dist/tooling/program/program-transformer.json +1 -1
  38. package/fs/backend.ts +17 -0
  39. package/fs/client.ts +99 -16
  40. package/fs/dirty-admission.ts +22 -7
  41. package/fs/guest-watch.ts +299 -103
  42. package/fs/indexeddb-chunks.ts +103 -9
  43. package/fs/indexeddb.ts +477 -121
  44. package/fs/memory.ts +120 -19
  45. package/fs/multitab-backend.ts +440 -95
  46. package/fs/multitab-protocol.ts +1 -0
  47. package/fs/persistent.ts +88 -16
  48. package/fs/protocol.ts +26 -7
  49. package/fs/publication-attachment.ts +9 -7
  50. package/fs/service.ts +62 -7
  51. package/fs/shared.ts +110 -8
  52. package/fs/storage.ts +128 -10
  53. package/fs/watch-service.ts +110 -3
  54. package/fs/watch-subscriptions.ts +115 -7
  55. package/package.json +1 -1
  56. package/proc/command-stdio.ts +1 -1
  57. package/proc/intrinsics/core.ts +7 -0
  58. package/proc/intrinsics.ts +1 -0
  59. package/testing/idle-workspace-cancellation-browser.ts +22 -13
  60. package/testing/indexeddb-storage-browser.ts +564 -1
  61. package/tooling/program/program-transformer.json +1 -1
package/dist/fs/memory.js CHANGED
@@ -75,6 +75,12 @@ function expandTreeLink(child, path, start, options, expansions, targetEnd) {
75
75
  targetEnd: target.length + (targetEnd > start ? 1 + targetEnd - start : 0)
76
76
  };
77
77
  }
78
+ function climbedBase(base, aboveStart) {
79
+ return aboveStart && base === "start" ? "lost" : base;
80
+ }
81
+ function restartedBase(base, options) {
82
+ return options.rooted ? "root" : base;
83
+ }
78
84
  export function walkTree(root, path, options) {
79
85
  const error = treePathError(path, options.pathUnits, options.pathBytes);
80
86
  if (error)
@@ -83,6 +89,7 @@ export function walkTree(root, path, options) {
83
89
  const names = [];
84
90
  let node = root;
85
91
  let parent;
92
+ let base = "start";
86
93
  let name = "", terminalDot = false, expansions = 0, targetEnd = 0, start = 0;
87
94
  while (start < path.length) {
88
95
  let end = path.indexOf("/", start);
@@ -103,9 +110,11 @@ export function walkTree(root, path, options) {
103
110
  if (part === ".")
104
111
  continue;
105
112
  if (part === "..") {
106
- const up = dirs.pop() ?? climbAbove(node, root, options);
113
+ const popped = dirs.pop();
114
+ const up = popped ?? climbAbove(node, root, options);
107
115
  if (typeof up === "number")
108
116
  return up;
117
+ base = climbedBase(base, popped === undefined && up !== node);
109
118
  node = up;
110
119
  names.pop();
111
120
  parent = undefined;
@@ -120,6 +129,7 @@ export function walkTree(root, path, options) {
120
129
  if (!child)
121
130
  return {
122
131
  canonicalPath: "/" + names.concat(part).join("/"),
132
+ base,
123
133
  parent,
124
134
  name,
125
135
  node: undefined,
@@ -132,6 +142,7 @@ export function walkTree(root, path, options) {
132
142
  if (link?.absolute) {
133
143
  dirs.length = 0;
134
144
  names.length = 0;
145
+ base = restartedBase(base, options);
135
146
  }
136
147
  if (link) {
137
148
  expansions++;
@@ -151,7 +162,26 @@ export function walkTree(root, path, options) {
151
162
  const trailingSlash = path.endsWith("/");
152
163
  if (trailingSlash && node.kind !== "dir")
153
164
  return 54;
154
- return { parent, name, node, trailingSlash, terminalDot, canonicalPath: "/" + names.join("/") };
165
+ return {
166
+ parent,
167
+ name,
168
+ node,
169
+ trailingSlash,
170
+ terminalDot,
171
+ canonicalPath: "/" + names.join("/"),
172
+ base
173
+ };
174
+ }
175
+ function joinBelow(prefix, below) {
176
+ if (typeof prefix === "number" || below === "/")
177
+ return prefix;
178
+ return (prefix === "/" ? "" : prefix) + below;
179
+ }
180
+ function childName(parent, child) {
181
+ for (const [name, entry] of parent.children)
182
+ if (entry === child)
183
+ return name;
184
+ return;
155
185
  }
156
186
  function namespacePlan(edits = [], created = [], forgotten = [], links = []) {
157
187
  return {
@@ -204,7 +234,20 @@ export function decode(data) {
204
234
  export class MemFS {
205
235
  root;
206
236
  onChange;
237
+ onDirEntryDelta;
207
238
  onLinkChange;
239
+ setChild(parent, name, child) {
240
+ const existed = parent.children.has(name);
241
+ parent.children.set(name, child);
242
+ if (!existed)
243
+ this.onDirEntryDelta?.(parent, 64 + name.length * 2);
244
+ }
245
+ deleteChild(parent, name) {
246
+ const deleted = parent.children.delete(name);
247
+ if (deleted)
248
+ this.onDirEntryDelta?.(parent, -(64 + name.length * 2));
249
+ return deleted;
250
+ }
208
251
  changed(node) {
209
252
  this.onChange?.(node);
210
253
  }
@@ -289,12 +332,18 @@ export class MemFS {
289
332
  this.handles.delete(handle);
290
333
  if (node.kind === "dir") {
291
334
  this.removedDirectories.add(node);
292
- for (const child of node.children.values()) {
335
+ const trackDelta = this.onDirEntryDelta !== undefined;
336
+ let delta = 0;
337
+ for (const [name, child] of node.children) {
338
+ if (trackDelta)
339
+ delta -= 64 + name.length * 2;
293
340
  this.changeLinkCount(child, -1);
294
341
  this.forget(child);
295
342
  }
296
343
  this.directoryPages(node).clear();
297
344
  node.children.clear();
345
+ if (delta)
346
+ this.onDirEntryDelta?.(node, delta);
298
347
  }
299
348
  }
300
349
  nodeForHandle(handle) {
@@ -381,7 +430,21 @@ export class MemFS {
381
430
  return this.walk(this.handle(this.root), path.replace(/^\/+/, "") || ".", true, followFinal);
382
431
  }
383
432
  walk(directory, path, clampRoot, followFinal, pathBytes, rooted = false) {
384
- const resolved = walkTree(this.directory(directory), path, {
433
+ const resolved = this.walkNodes(this.directory(directory), path, clampRoot, followFinal, pathBytes, rooted);
434
+ if (typeof resolved === "number")
435
+ return resolved;
436
+ return {
437
+ canonicalPath: resolved.canonicalPath,
438
+ base: resolved.base,
439
+ name: resolved.name,
440
+ trailingSlash: resolved.trailingSlash,
441
+ terminalDot: resolved.terminalDot,
442
+ parent: resolved.parent ? this.handle(resolved.parent) : undefined,
443
+ node: resolved.node ? this.handle(resolved.node) : undefined
444
+ };
445
+ }
446
+ walkNodes(start, path, clampRoot, followFinal, pathBytes, rooted = false) {
447
+ return walkTree(start, path, {
385
448
  clampRoot,
386
449
  followFinal,
387
450
  pathBytes,
@@ -393,16 +456,39 @@ export class MemFS {
393
456
  return child;
394
457
  }
395
458
  });
459
+ }
460
+ realpath(directory, path, rooted = false) {
461
+ if (path.startsWith("/"))
462
+ return 63;
463
+ const start = this.directory(directory);
464
+ const resolved = this.walkNodes(start, path, false, true, undefined, rooted);
396
465
  if (typeof resolved === "number")
397
466
  return resolved;
398
- return {
399
- canonicalPath: resolved.canonicalPath,
400
- name: resolved.name,
401
- trailingSlash: resolved.trailingSlash,
402
- terminalDot: resolved.terminalDot,
403
- parent: resolved.parent ? this.handle(resolved.parent) : undefined,
404
- node: resolved.node ? this.handle(resolved.node) : undefined
405
- };
467
+ if (resolved.node === undefined)
468
+ return 44;
469
+ if (!rooted)
470
+ return resolved.canonicalPath.slice(1) || ".";
471
+ if (resolved.base === "root" || resolved.base === "start" && start === this.root)
472
+ return resolved.canonicalPath;
473
+ if (resolved.base === "start")
474
+ return joinBelow(this.pathOf(start), resolved.canonicalPath);
475
+ if (resolved.node.kind === "dir")
476
+ return this.pathOf(resolved.node);
477
+ return joinBelow(this.pathOf(resolved.parent), "/" + resolved.name);
478
+ }
479
+ pathOf(dir) {
480
+ const names = [];
481
+ for (let at = dir;at !== this.root; ) {
482
+ const parent = this.liveParent(at);
483
+ if (typeof parent === "number")
484
+ return parent === 63 ? 44 : parent;
485
+ const name = childName(parent, at);
486
+ if (name === undefined)
487
+ return 44;
488
+ names.push(name);
489
+ at = parent;
490
+ }
491
+ return "/" + names.reverse().join("/");
406
492
  }
407
493
  symlink(path, target) {
408
494
  const prepared = this.planSymlink(path, target, 4);
@@ -567,7 +653,7 @@ export class MemFS {
567
653
  const node = kind === "file" ? newFile() : kind === "socket" ? newSocket() : newDir();
568
654
  this.directoryPages(parent).reserve(1);
569
655
  this.pageEntry(parent, path.name, node);
570
- parent.children.set(path.name, node);
656
+ this.setChild(parent, path.name, node);
571
657
  this.changeLinkCount(node, 1);
572
658
  this.onLinkChange?.(node, 1);
573
659
  modified(parent, node.ctime);
@@ -675,7 +761,7 @@ export class MemFS {
675
761
  return parent;
676
762
  this.directoryPages(parent).reserve(1);
677
763
  this.pageEntry(parent, to.name, node);
678
- parent.children.set(to.name, node);
764
+ this.setChild(parent, to.name, node);
679
765
  this.changeLinkCount(node, 1);
680
766
  this.onLinkChange?.(node, 1);
681
767
  const time = fileTimeNow();
@@ -703,7 +789,7 @@ export class MemFS {
703
789
  if ((parent.mode & 192) !== 192)
704
790
  return 2;
705
791
  this.pageEntry(parent, path.name, undefined);
706
- parent.children.delete(path.name);
792
+ this.deleteChild(parent, path.name);
707
793
  this.changeLinkCount(node, -1);
708
794
  this.onLinkChange?.(node, -1);
709
795
  const time = fileTimeNow();
@@ -746,11 +832,11 @@ export class MemFS {
746
832
  this.directoryPages(parent).reserve(1);
747
833
  this.pageEntry(sourceParent, from.name, undefined);
748
834
  this.pageEntry(parent, to.name, node);
749
- sourceParent.children.delete(from.name);
835
+ this.deleteChild(sourceParent, from.name);
750
836
  const time = fileTimeNow();
751
837
  modified(sourceParent, time);
752
838
  node.ctime = time;
753
- parent.children.set(to.name, node);
839
+ this.setChild(parent, to.name, node);
754
840
  if (node.kind === "dir")
755
841
  this.directoryParents.set(node, parent);
756
842
  if (target) {
@@ -983,9 +1069,9 @@ export class MemFS {
983
1069
  if (edge.after)
984
1070
  this.changeLinkCount(edge.after, 1);
985
1071
  if (edge.after)
986
- edge.parent.children.set(edge.name, edge.after);
1072
+ this.setChild(edge.parent, edge.name, edge.after);
987
1073
  else
988
- edge.parent.children.delete(edge.name);
1074
+ this.deleteChild(edge.parent, edge.name);
989
1075
  if (edge.after?.kind === "dir")
990
1076
  this.directoryParents.set(edge.after, edge.parent);
991
1077
  if (edge.after && created.has(edge.after))
@@ -1079,7 +1165,7 @@ export class MemFS {
1079
1165
  return false;
1080
1166
  const { parent, name, node } = edge;
1081
1167
  this.pageEntry(parent, name, undefined);
1082
- const removed = parent.children.delete(name);
1168
+ const removed = this.deleteChild(parent, name);
1083
1169
  if (removed) {
1084
1170
  this.changeLinkCount(node, -1);
1085
1171
  this.onLinkChange?.(node, -1);