@waffle-os/runtime 0.0.151 → 0.0.153

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.
@@ -340,6 +340,12 @@ export type PeerMessage =
340
340
  readonly totalBytes: number;
341
341
  readonly chunk: Uint8Array;
342
342
  }
343
+ | {
344
+ readonly kind: "chunk-abort";
345
+ readonly hostTerm: string;
346
+ readonly sessionId: string;
347
+ readonly uploadId: string;
348
+ }
343
349
  | {
344
350
  readonly kind: "chunk-get";
345
351
  readonly hostTerm: string;
@@ -378,6 +384,7 @@ export type PeerMessage =
378
384
  readonly pendingWatchAcks?: readonly (readonly [number, boolean])[];
379
385
  readonly pendingUnpins?: readonly number[];
380
386
  readonly pendingWatchCloses?: readonly number[];
387
+ readonly pendingUploadAborts?: readonly string[];
381
388
  }
382
389
  | {
383
390
  readonly kind: "pong";
@@ -389,6 +396,7 @@ export type PeerMessage =
389
396
  readonly settledWatchAcks?: readonly number[];
390
397
  readonly settledUnpins?: readonly number[];
391
398
  readonly settledWatchCloses?: readonly number[];
399
+ readonly settledUploadAborts?: readonly string[];
392
400
  readonly creditLimit: PeerCreditLimit;
393
401
  readonly hostState: HostHealthState;
394
402
  }
@@ -430,6 +438,7 @@ export type PeerMessage =
430
438
  readonly watchAcks?: readonly number[];
431
439
  readonly unpins?: readonly number[];
432
440
  readonly watchCloses?: readonly number[];
441
+ readonly uploadAborts?: readonly string[];
433
442
  }
434
443
  | {
435
444
  readonly kind: "detach";
@@ -534,6 +543,8 @@ export function isPeerMessage(value: unknown): value is PeerMessage {
534
543
  typeof value.totalBytes === "number" &&
535
544
  value.chunk instanceof Uint8Array
536
545
  );
546
+ case "chunk-abort":
547
+ return typeof value.uploadId === "string";
537
548
  case "chunk-get":
538
549
  return (
539
550
  typeof value.reqId === "number" &&
package/fs/service.ts CHANGED
@@ -1169,18 +1169,40 @@ export class FilesystemService {
1169
1169
  return;
1170
1170
  }
1171
1171
  if (operation === "flush" || operation === "sync") {
1172
- const flushing = this.backend.flush?.(
1173
- operation === "sync" ? a : typeof a === "string" ? a : undefined,
1174
- );
1175
- return this.trackRequestWork(session, Promise.resolve(flushing)).then(() =>
1176
- this.finishResult(session, id, operation, operation === "sync" ? 0 : undefined),
1172
+ const target = operation === "sync" ? a : typeof a === "string" ? a : undefined;
1173
+ if (operation === "sync") this.backend.retain(a);
1174
+ let flushing: Promise<void> | undefined;
1175
+ try {
1176
+ flushing = this.backend.flush?.(target);
1177
+ } catch (error) {
1178
+ if (operation === "sync") this.backend.release(a);
1179
+ throw error;
1180
+ }
1181
+ return this.trackRequestWork(session, Promise.resolve(flushing)).then(
1182
+ () => {
1183
+ if (operation === "sync") this.backend.release(a);
1184
+ return this.finishResult(session, id, operation, operation === "sync" ? 0 : undefined);
1185
+ },
1186
+ (error) => {
1187
+ if (operation === "sync") this.backend.release(a);
1188
+ throw error;
1189
+ },
1177
1190
  );
1178
1191
  }
1179
1192
  if (operation === "resolve" && session.socketScope && this.backend instanceof MemoryBackend) {
1180
1193
  const result = this.backend.fs.resolveSocket(a, b, c === true);
1181
1194
  return this.finishResult(session, id, operation, result, args);
1182
1195
  }
1183
- const result = this.backend.execute(operation, args, data);
1196
+ const isCancelled = () => {
1197
+ const pending = session.pending.get(id);
1198
+ return (
1199
+ !pending ||
1200
+ sessionRevoked(session) ||
1201
+ !this.sessions.has(session) ||
1202
+ requestCancelled(pending)
1203
+ );
1204
+ };
1205
+ const result = this.backend.execute(operation, args, data, isCancelled);
1184
1206
  if (result instanceof Promise)
1185
1207
  return this.trackRequestWork(session, result).then((value) =>
1186
1208
  this.finishResult(session, id, operation, value, args),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waffle-os/runtime",
3
- "version": "0.0.151",
3
+ "version": "0.0.153",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/ShaulLavo/waffle.git",
@@ -26,6 +26,12 @@ export interface CommandOptions {
26
26
  * stops them as `kill()` would once the first process has its outcome, which the result keeps.
27
27
  */
28
28
  readonly onLeaderExit?: CommandLeaderExit;
29
+ /**
30
+ * Present the standard descriptors Waffle provides (captured stdout and stderr, and stdin
31
+ * when it reads end of file) as a terminal. By default they are pipes, as a captured command
32
+ * sees on Unix: `isatty` is false. Stdin from a byte array or stream is always a pipe.
33
+ */
34
+ readonly terminal?: boolean;
29
35
  readonly args?: readonly string[];
30
36
  readonly cwd?: string;
31
37
  readonly env?: Readonly<Record<string, string>>;
@@ -94,6 +100,8 @@ function snapshot(executable: string, options: CommandOptions): CommandOptions {
94
100
  if (!path(executable)) throw new TypeError("Command executable must be an absolute path");
95
101
  const { args, cwd = "/", env, stdin, stdout, stderr, deadlineMs } = options;
96
102
  const { programs, onLeaderExit } = policies(options);
103
+ const { terminal = false } = options;
104
+ if (typeof terminal !== "boolean") throw new TypeError("Command terminal must be a boolean");
97
105
  if (!path(cwd)) throw new TypeError("Command cwd must be an absolute path");
98
106
  if (args !== undefined && !Array.isArray(args)) throw new TypeError("Invalid command args");
99
107
  const argv = Array.from(args ?? []);
@@ -121,6 +129,7 @@ function snapshot(executable: string, options: CommandOptions): CommandOptions {
121
129
  filesystem: "runtime-root",
122
130
  programs,
123
131
  onLeaderExit,
132
+ terminal,
124
133
  args: argv,
125
134
  cwd,
126
135
  env: Object.fromEntries(entries),
@@ -1 +1 @@
1
- {"commit":"da522cacff05cf6f18e820967a2e0f52d2f19680","buildToolsSha256":"b617652c1601f8722bb85c3a688a1fca4985b53f2c2066c10c76c2e693081137","optimizerSourceSha256":"34c4a040f3cf639f039823880822c6541c384c9b4eaa116d27dda8d9cb5c9f9e"}
1
+ {"commit":"5dcc58a08c0c1b3044dc6d47b4c13b688d70fa6d","buildToolsSha256":"b617652c1601f8722bb85c3a688a1fca4985b53f2c2066c10c76c2e693081137","optimizerSourceSha256":"34c4a040f3cf639f039823880822c6541c384c9b4eaa116d27dda8d9cb5c9f9e"}