@waffle-os/runtime 0.0.154 → 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.
@@ -864,6 +864,34 @@ export class FilesystemService {
864
864
  held.release();
865
865
  return held.batch;
866
866
  }
867
+ if (operation === "watchDrain") {
868
+ if (this.backend.watchDrain) {
869
+ const register = (held) => {
870
+ if (cancelled()) {
871
+ held.rollback();
872
+ throw new FilesystemError(11);
873
+ }
874
+ if (held.hasEvents)
875
+ session.watchTransactions.set(requestId, {
876
+ cancel: held.rollback,
877
+ release: held.release
878
+ });
879
+ else
880
+ held.release();
881
+ return { entries: held.entries, more: held.more };
882
+ };
883
+ const draining = this.backend.watchDrain(session.connection.owner, cancelled);
884
+ return draining instanceof Promise ? this.trackRequestWork(session, draining).then(register) : register(draining);
885
+ }
886
+ if (!this.watchService)
887
+ return { entries: [], more: false };
888
+ const held = this.watchService.drainHeld(session.connection.owner);
889
+ if (held.hasEvents)
890
+ session.watchTransactions.set(requestId, { cancel: held.rollback, release: held.release });
891
+ else
892
+ held.release();
893
+ return { entries: held.entries, more: held.more };
894
+ }
867
895
  if (operation === "watchClose") {
868
896
  if (this.backend.watchClose) {
869
897
  this.backend.watchClose(session.connection.owner, a);
package/dist/fs/shared.js CHANGED
@@ -68,6 +68,7 @@ const PINNED_PAGES = 29;
68
68
  export const CLIENT_MODE = 30;
69
69
  export const CLIENT_MODE_NO_DIRECT_IO = 1;
70
70
  export const CLIENT_MODE_NO_CLIENT_CACHE = 2;
71
+ export const CLIENT_MODE_NO_WATCH_DRAIN = 4;
71
72
  const MODE = 12;
72
73
  const FILE_SIZE = 1;
73
74
  const MTIME = 2;
@@ -222,6 +223,9 @@ export class SharedFilesystemState {
222
223
  isClientCacheDisabled() {
223
224
  return (atomicsLoad(this.cells, CLIENT_MODE) & CLIENT_MODE_NO_CLIENT_CACHE) !== 0;
224
225
  }
226
+ isWatchDrainDisabled() {
227
+ return (atomicsLoad(this.cells, CLIENT_MODE) & CLIENT_MODE_NO_WATCH_DRAIN) !== 0;
228
+ }
225
229
  resetForRemount(retainedSegments = []) {
226
230
  Atomics.store(this.cells, GLOBAL_LOCK, 0);
227
231
  Atomics.store(this.cells, USED_PAGES, 0);
@@ -14,17 +14,116 @@ export function restoreTime(time) {
14
14
  function validTime(value) {
15
15
  return typeof value === "string" && /^(0|[1-9][0-9]{0,19})$/.test(value) && BigInt(value) <= MAX_FILE_TIME;
16
16
  }
17
+ const NODE_KEYS = new Set([
18
+ "ino",
19
+ "kind",
20
+ "atime",
21
+ "mtime",
22
+ "ctime",
23
+ "mode",
24
+ "size",
25
+ "children",
26
+ "data",
27
+ "target",
28
+ "identity"
29
+ ]);
30
+ function isPlainObject(value) {
31
+ if (!value || typeof value !== "object")
32
+ return false;
33
+ const proto = Object.getPrototypeOf(value);
34
+ return proto === Object.prototype || proto === null;
35
+ }
36
+ function cloneStoredIdentity(value) {
37
+ if (!isPlainObject(value))
38
+ return;
39
+ const keys = Object.keys(value);
40
+ if (keys.length !== 4 || typeof value.format !== "string" || typeof value.workspace !== "string" || typeof value.id !== "string" || typeof value.version !== "string")
41
+ return;
42
+ return {
43
+ format: value.format,
44
+ workspace: value.workspace,
45
+ id: value.id,
46
+ version: value.version
47
+ };
48
+ }
49
+ function clonePersistedNode(node) {
50
+ if (!isPlainObject(node))
51
+ return structuredClone(node);
52
+ const keys = Object.keys(node);
53
+ for (let i = 0;i < keys.length; i++) {
54
+ if (!NODE_KEYS.has(keys[i]))
55
+ return structuredClone(node);
56
+ }
57
+ if (typeof node.ino !== "number" || typeof node.kind !== "string" || typeof node.atime !== "string" || typeof node.mtime !== "string" || typeof node.ctime !== "string" || typeof node.size !== "number" || node.mode !== undefined && typeof node.mode !== "number" || node.data !== undefined && typeof node.data !== "string" || node.target !== undefined && typeof node.target !== "string")
58
+ return structuredClone(node);
59
+ let identity;
60
+ if (node.identity !== undefined) {
61
+ identity = cloneStoredIdentity(node.identity);
62
+ if (!identity)
63
+ return structuredClone(node);
64
+ }
65
+ let children;
66
+ if (node.children !== undefined) {
67
+ if (!Array.isArray(node.children))
68
+ return structuredClone(node);
69
+ children = Array.from({ length: node.children.length });
70
+ for (let i = 0;i < node.children.length; i++) {
71
+ const entry = node.children[i];
72
+ if (!Array.isArray(entry) || entry.length !== 2 || typeof entry[0] !== "string" || typeof entry[1] !== "number")
73
+ return structuredClone(node);
74
+ children[i] = [entry[0], entry[1]];
75
+ }
76
+ }
77
+ const copy = {
78
+ ino: node.ino,
79
+ kind: node.kind,
80
+ atime: node.atime,
81
+ mtime: node.mtime,
82
+ ctime: node.ctime,
83
+ size: node.size
84
+ };
85
+ if ("mode" in node)
86
+ copy.mode = node.mode;
87
+ if ("data" in node)
88
+ copy.data = node.data;
89
+ if ("target" in node)
90
+ copy.target = node.target;
91
+ if ("children" in node)
92
+ copy.children = children;
93
+ if ("identity" in node)
94
+ copy.identity = identity;
95
+ return copy;
96
+ }
97
+ function cloneNumberArray(values) {
98
+ if (!Array.isArray(values))
99
+ return structuredClone(values);
100
+ for (let i = 0;i < values.length; i++) {
101
+ if (typeof values[i] !== "number")
102
+ return structuredClone(values);
103
+ }
104
+ return values.slice();
105
+ }
106
+ function cloneStringArray(values) {
107
+ if (!Array.isArray(values))
108
+ return structuredClone(values);
109
+ for (let i = 0;i < values.length; i++) {
110
+ if (typeof values[i] !== "string")
111
+ return structuredClone(values);
112
+ }
113
+ return values.slice();
114
+ }
17
115
  export function snapshotBatch(batch) {
116
+ const data = new Map;
117
+ for (const [key, bytes] of batch.data)
118
+ data.set(key, new Uint8Array(bytes));
18
119
  return {
19
- ...structuredClone({
20
- generation: batch.generation,
21
- root: batch.root,
22
- upserts: batch.upserts,
23
- removes: batch.removes,
24
- retainedData: batch.retainedData
25
- }),
120
+ generation: batch.generation,
121
+ root: batch.root,
122
+ upserts: Array.isArray(batch.upserts) ? batch.upserts.map(clonePersistedNode) : structuredClone(batch.upserts),
123
+ removes: cloneNumberArray(batch.removes),
124
+ ...batch.retainedData !== undefined ? { retainedData: cloneStringArray(batch.retainedData) } : {},
26
125
  ...batch.publication ? { publication: snapshotPublicationCheckpoint(batch.publication) } : {},
27
- data: new Map(Array.from(batch.data, ([key, bytes]) => [key, new Uint8Array(bytes)]))
126
+ data
28
127
  };
29
128
  }
30
129
  function invalid() {
@@ -4,6 +4,7 @@ import { WatchIndex } from "./watch-index.js";
4
4
  import { WatchRouting } from "./watch-routing.js";
5
5
  import { WatchSubscriptions } from "./watch-subscriptions.js";
6
6
  import { WATCH_CAPACITY } from "./watch-ring.js";
7
+ const MAX_DRAIN_ITEMS = 128;
7
8
 
8
9
  export class WatchService {
9
10
  backend;
@@ -89,6 +90,95 @@ export class WatchService {
89
90
  held.release();
90
91
  }
91
92
  }
93
+ drainHeld(owner) {
94
+ return this.backend.shared.mutate(undefined, undefined, () => this.collectDrain(owner));
95
+ }
96
+ collectDrain(owner) {
97
+ this.drain();
98
+ const state = { entries: [], held: [], events: 0, items: 0, more: false };
99
+ try {
100
+ this.subscriptions.forReady(owner, (id) => this.collectDrainWatch(owner, id, state));
101
+ } catch (error) {
102
+ for (let i = state.held.length - 1;i >= 0; i--)
103
+ state.held[i].rollback();
104
+ throw error;
105
+ }
106
+ return this.finishDrain(state);
107
+ }
108
+ collectDrainWatch(owner, id, state) {
109
+ const denied = this.drainAccess(owner, id);
110
+ if (denied !== undefined) {
111
+ if (state.entries.length > 0 && state.items + 1 > MAX_DRAIN_ITEMS) {
112
+ state.more = true;
113
+ return false;
114
+ }
115
+ state.items++;
116
+ state.entries.push({ id, errno: denied });
117
+ return true;
118
+ }
119
+ const overflowed = this.subscriptions.overflowed(owner, id);
120
+ const queued = overflowed ? 0 : this.subscriptions.queuedCount(owner, id);
121
+ if (!overflowed && queued === 0)
122
+ return true;
123
+ const cost = overflowed ? 1 : queued;
124
+ if (state.entries.length > 0 && state.items + cost > MAX_DRAIN_ITEMS) {
125
+ state.more = true;
126
+ return false;
127
+ }
128
+ const item = this.subscriptions.batch(owner, id, state.held.length > 0);
129
+ if (!item) {
130
+ state.more = true;
131
+ return false;
132
+ }
133
+ if (item.batch.kind === "events" && !item.batch.events.length) {
134
+ item.release();
135
+ return true;
136
+ }
137
+ if (item.batch.events.length) {
138
+ state.events += item.batch.events.length;
139
+ state.items += item.batch.events.length;
140
+ state.held.push(item);
141
+ } else {
142
+ state.items++;
143
+ item.release();
144
+ }
145
+ state.entries.push({ id, batch: item.batch });
146
+ return true;
147
+ }
148
+ drainAccess(owner, id) {
149
+ if (this.incomplete || this.subscriptions.overflowed(owner, id))
150
+ return;
151
+ try {
152
+ this.access(this.subscriptions.root(owner, id));
153
+ return;
154
+ } catch (error) {
155
+ if (error instanceof FilesystemError)
156
+ return error.errno;
157
+ throw error;
158
+ }
159
+ }
160
+ finishDrain(state) {
161
+ let settled = false;
162
+ const settle = (rollback) => {
163
+ if (settled)
164
+ return;
165
+ settled = true;
166
+ if (rollback) {
167
+ for (let i = state.held.length - 1;i >= 0; i--)
168
+ state.held[i].rollback();
169
+ } else {
170
+ for (const item of state.held)
171
+ item.release();
172
+ }
173
+ };
174
+ return {
175
+ entries: state.entries,
176
+ more: state.more,
177
+ hasEvents: state.events > 0,
178
+ release: () => settle(false),
179
+ rollback: () => settle(true)
180
+ };
181
+ }
92
182
  close(owner, id) {
93
183
  let directory = false;
94
184
  try {
@@ -228,8 +318,13 @@ export class WatchService {
228
318
  }
229
319
  if (!this.index.has(record.file))
230
320
  return;
231
- if (record.kind === "metadata")
232
- this.index.upsert(record.file, record.mode, this.index.metadata(record.file).directory);
321
+ if (record.kind === "metadata") {
322
+ const directory = this.index.metadata(record.file).directory;
323
+ this.index.upsert(record.file, record.mode, directory);
324
+ const required = directory ? 320 : 256;
325
+ const inaccessible = (record.mode & required) !== required;
326
+ this.subscriptions.forRoot(record.file, (owner, id) => this.subscriptions.setInaccessible(owner, id, inaccessible));
327
+ }
233
328
  this.deliver(record.file, "change");
234
329
  }
235
330
  target(file, type) {
@@ -5,12 +5,16 @@ import { WatchIdIndex, watchId, setWatchId } from "./watch-id-index.js";
5
5
  import { WatchIndex } from "./watch-index.js";
6
6
  import { WatchNames } from "./watch-names.js";
7
7
  import { WATCH_CAPACITY } from "./watch-ring.js";
8
- const WIDTH = 48;
8
+ const WIDTH = 56;
9
9
  const EVENT = 32;
10
10
  const HEAD = 20;
11
11
  const TAIL = 24;
12
12
  const COUNT = 28;
13
+ const READY_NEXT = 48;
14
+ const READY_PREV = 52;
13
15
  const OVERFLOW = 2;
16
+ const READY = 4;
17
+ const INACCESSIBLE = 8;
14
18
  const NULL_NAME = 4294967295;
15
19
 
16
20
  export class WatchSubscriptions {
@@ -19,6 +23,7 @@ export class WatchSubscriptions {
19
23
  records;
20
24
  ids;
21
25
  owners;
26
+ readyOwners;
22
27
  events;
23
28
  names;
24
29
  tail = 0;
@@ -34,6 +39,7 @@ export class WatchSubscriptions {
34
39
  this.records = new WatchArena(account);
35
40
  this.ids = new WatchIdIndex(account);
36
41
  this.owners = new WatchIdIndex(account);
42
+ this.readyOwners = new WatchIdIndex(account);
37
43
  this.events = new WatchArena(account, "events");
38
44
  this.names = new WatchNames(account, 12288, "events");
39
45
  }
@@ -67,18 +73,23 @@ export class WatchSubscriptions {
67
73
  const record = this.records.stage(slot * WIDTH);
68
74
  let lookup;
69
75
  let owners;
76
+ let readyOwners;
70
77
  try {
71
78
  lookup = this.ids.stage();
72
- if (!this.owners.get(BigInt(owner)))
79
+ if (!this.owners.get(BigInt(owner))) {
73
80
  owners = this.owners.stage();
81
+ readyOwners = this.readyOwners.stage();
82
+ }
74
83
  this.index.pin(root);
75
84
  record.commit();
76
85
  lookup.commit();
77
86
  owners?.commit();
87
+ readyOwners?.commit();
78
88
  } catch (error) {
79
89
  record.cancel();
80
90
  lookup?.cancel();
81
91
  owners?.cancel();
92
+ readyOwners?.cancel();
82
93
  throw error;
83
94
  }
84
95
  const at = (slot - 1) * WIDTH;
@@ -100,19 +111,109 @@ export class WatchSubscriptions {
100
111
  }
101
112
  attach(slot, root, owner) {
102
113
  const at = (slot - 1) * WIDTH;
103
- const ownerHead = this.owners.get(BigInt(owner));
114
+ const ownerKey = BigInt(owner);
115
+ const ownerHead = this.owners.get(ownerKey);
104
116
  const rootHead = this.index.watchHead(root);
105
117
  this.records.view.setUint32(at + 32, ownerHead, true);
106
118
  this.records.view.setUint32(at + 40, rootHead, true);
107
119
  if (ownerHead) {
108
120
  this.records.view.setUint32((ownerHead - 1) * WIDTH + 36, slot, true);
109
- this.owners.set(BigInt(owner), slot);
110
- } else
111
- this.owners.add(BigInt(owner), slot);
121
+ this.owners.set(ownerKey, slot);
122
+ } else {
123
+ this.owners.add(ownerKey, slot);
124
+ this.readyOwners.add(ownerKey, 0);
125
+ }
112
126
  if (rootHead)
113
127
  this.records.view.setUint32((rootHead - 1) * WIDTH + 44, slot, true);
114
128
  this.index.setWatchHead(root, slot);
115
129
  }
130
+ markReady(slot, owner) {
131
+ const at = (slot - 1) * WIDTH;
132
+ const view = this.records.view;
133
+ const flags = view.getUint32(at + 16, true);
134
+ if (flags & READY)
135
+ return;
136
+ view.setUint32(at + 16, flags | READY, true);
137
+ const ownerKey = BigInt(owner);
138
+ const head = this.readyOwners.get(ownerKey);
139
+ if (!head) {
140
+ view.setUint32(at + READY_NEXT, slot, true);
141
+ view.setUint32(at + READY_PREV, slot, true);
142
+ this.readyOwners.set(ownerKey, slot);
143
+ return;
144
+ }
145
+ const headAt = (head - 1) * WIDTH;
146
+ const tail = view.getUint32(headAt + READY_PREV, true);
147
+ view.setUint32(at + READY_NEXT, head, true);
148
+ view.setUint32(at + READY_PREV, tail, true);
149
+ view.setUint32((tail - 1) * WIDTH + READY_NEXT, slot, true);
150
+ view.setUint32(headAt + READY_PREV, slot, true);
151
+ }
152
+ unmarkReady(slot, owner) {
153
+ const at = (slot - 1) * WIDTH;
154
+ const view = this.records.view;
155
+ const flags = view.getUint32(at + 16, true);
156
+ if (!(flags & READY))
157
+ return;
158
+ view.setUint32(at + 16, flags & ~READY, true);
159
+ const next = view.getUint32(at + READY_NEXT, true);
160
+ const previous = view.getUint32(at + READY_PREV, true);
161
+ const ownerKey = BigInt(owner);
162
+ if (next === slot) {
163
+ this.readyOwners.set(ownerKey, 0);
164
+ } else {
165
+ view.setUint32((previous - 1) * WIDTH + READY_NEXT, next, true);
166
+ view.setUint32((next - 1) * WIDTH + READY_PREV, previous, true);
167
+ if (this.readyOwners.get(ownerKey) === slot)
168
+ this.readyOwners.set(ownerKey, next);
169
+ }
170
+ view.setUint32(at + READY_NEXT, 0, true);
171
+ view.setUint32(at + READY_PREV, 0, true);
172
+ }
173
+ setInaccessible(owner, id, inaccessible) {
174
+ const at = this.at(owner, id);
175
+ const slot = at / WIDTH + 1;
176
+ const view = this.records.view;
177
+ const flags = view.getUint32(at + 16, true);
178
+ if (inaccessible) {
179
+ view.setUint32(at + 16, flags | INACCESSIBLE, true);
180
+ this.markReady(slot, owner);
181
+ return;
182
+ }
183
+ if (!(flags & INACCESSIBLE))
184
+ return;
185
+ view.setUint32(at + 16, flags & ~INACCESSIBLE, true);
186
+ if (!(flags & OVERFLOW) && !view.getUint32(at + COUNT, true))
187
+ this.unmarkReady(slot, owner);
188
+ }
189
+ forReady(owner, visit) {
190
+ const ownerKey = BigInt(owner);
191
+ const start = this.readyOwners.get(ownerKey);
192
+ if (!start)
193
+ return;
194
+ const last = this.records.view.getUint32((start - 1) * WIDTH + READY_PREV, true);
195
+ let slot = start;
196
+ while (slot) {
197
+ const at = (slot - 1) * WIDTH;
198
+ const done = slot === last;
199
+ const next = this.records.view.getUint32(at + READY_NEXT, true);
200
+ const keepGoing = visit(this.records.view.getFloat64(at, true));
201
+ if (keepGoing === false)
202
+ return;
203
+ if (this.records.view.getUint32(at + 16, true) & READY && next !== slot) {
204
+ this.readyOwners.set(ownerKey, next);
205
+ }
206
+ if (done)
207
+ return;
208
+ slot = next;
209
+ }
210
+ }
211
+ queuedCount(owner, id) {
212
+ const at = this.at(owner, id);
213
+ if (this.records.view.getUint32(at + 16, true) & OVERFLOW)
214
+ return 0;
215
+ return this.records.view.getUint32(at + COUNT, true);
216
+ }
116
217
  root(owner, id) {
117
218
  const at = this.at(owner, id);
118
219
  return this.index.id(this.records.view.getUint32(at + 12, true));
@@ -149,6 +250,7 @@ export class WatchSubscriptions {
149
250
  return this.overflow(owner, id);
150
251
  try {
151
252
  this.append(at, event);
253
+ this.markReady(at / WIDTH + 1, owner);
152
254
  } catch (error) {
153
255
  if (!(error instanceof FilesystemError) || error.errno !== 6 && error.errno !== 48)
154
256
  throw error;
@@ -217,7 +319,7 @@ export class WatchSubscriptions {
217
319
  name: length === NULL_NAME ? null : this.names.read(view.getUint32(at + 28, true), length)
218
320
  };
219
321
  }
220
- batch(owner, id) {
322
+ batch(owner, id, deferOnBudget = false) {
221
323
  const at = this.at(owner, id);
222
324
  if (this.records.view.getUint32(at + 16, true) & OVERFLOW)
223
325
  return { batch: { kind: "overflow", events: [] }, release() {}, rollback() {} };
@@ -235,6 +337,8 @@ export class WatchSubscriptions {
235
337
  } catch (error) {
236
338
  if (!(error instanceof FilesystemError) || error.errno !== 6)
237
339
  throw error;
340
+ if (deferOnBudget)
341
+ return;
238
342
  this.overflow(owner, id);
239
343
  return { batch: { kind: "overflow", events: [] }, release() {}, rollback() {} };
240
344
  }
@@ -251,6 +355,8 @@ export class WatchSubscriptions {
251
355
  this.records.view.setUint32(at + HEAD, 0, true);
252
356
  this.records.view.setUint32(at + TAIL, 0, true);
253
357
  this.records.view.setUint32(at + COUNT, 0, true);
358
+ if (!(this.records.view.getUint32(at + 16, true) & (OVERFLOW | INACCESSIBLE)))
359
+ this.unmarkReady(at / WIDTH + 1, owner);
254
360
  let held = true;
255
361
  const settle = (rollback) => {
256
362
  if (!held)
@@ -285,6 +391,7 @@ export class WatchSubscriptions {
285
391
  if (!current)
286
392
  this.records.view.setUint32(at + TAIL, last, true);
287
393
  this.records.view.setUint32(at + COUNT, current + count, true);
394
+ this.markReady(at / WIDTH + 1, owner);
288
395
  return true;
289
396
  }
290
397
  releaseEvents(first) {
@@ -308,6 +415,7 @@ export class WatchSubscriptions {
308
415
  this.records.view.setUint32(at + TAIL, 0, true);
309
416
  this.records.view.setUint32(at + COUNT, 0, true);
310
417
  this.records.view.setUint32(at + 16, this.records.view.getUint32(at + 16, true) | OVERFLOW, true);
418
+ this.markReady(at / WIDTH + 1, owner);
311
419
  }
312
420
  close(owner, id) {
313
421
  if (!this.slot(id))
@@ -327,6 +435,7 @@ export class WatchSubscriptions {
327
435
  this.records.close();
328
436
  this.ids.close();
329
437
  this.owners.close();
438
+ this.readyOwners.close();
330
439
  this.tail = this.free = 0;
331
440
  if (!this.queued)
332
441
  this.resetEvents();
@@ -334,6 +443,7 @@ export class WatchSubscriptions {
334
443
  return true;
335
444
  }
336
445
  detach(slot, root, owner) {
446
+ this.unmarkReady(slot, owner);
337
447
  const at = (slot - 1) * WIDTH;
338
448
  const ownerNext = this.records.view.getUint32(at + 32, true);
339
449
  const ownerPrevious = this.records.view.getUint32(at + 36, true);
@@ -343,8 +453,10 @@ export class WatchSubscriptions {
343
453
  this.records.view.setUint32((ownerPrevious - 1) * WIDTH + 32, ownerNext, true);
344
454
  else if (ownerNext)
345
455
  this.owners.set(BigInt(owner), ownerNext);
346
- else
456
+ else {
347
457
  this.owners.delete(BigInt(owner));
458
+ this.readyOwners.delete(BigInt(owner));
459
+ }
348
460
  if (ownerNext)
349
461
  this.records.view.setUint32((ownerNext - 1) * WIDTH + 36, ownerPrevious, true);
350
462
  if (rootPrevious)
@@ -375,6 +487,7 @@ export class WatchSubscriptions {
375
487
  this.records.close();
376
488
  this.ids.close();
377
489
  this.owners.close();
490
+ this.readyOwners.close();
378
491
  this.events.close();
379
492
  this.names.close();
380
493
  }
@@ -29,7 +29,12 @@ export const MapConstructor = Map;
29
29
  const mapGetMethod = Map.prototype.get, mapSetMethod = Map.prototype.set;
30
30
  const mapHasMethod = Map.prototype.has, mapDeleteMethod = Map.prototype.delete;
31
31
  const mapForEachMethod = Map.prototype.forEach;
32
+ const mapValuesMethod = Map.prototype.values;
33
+ const mapIteratorNext = objectGetPrototypeOf(new MapConstructor().values()).next;
32
34
  const mapSizeGetter = descriptor(Map.prototype, "size").get;
35
+ export function mapFirst(map) {
36
+ return apply(mapIteratorNext, apply(mapValuesMethod, map, []), []).value;
37
+ }
33
38
  export function mapGet(map, key) {
34
39
  return apply(mapGetMethod, map, [key]);
35
40
  }
@@ -19,6 +19,7 @@ export {
19
19
  mapSet,
20
20
  mapHas,
21
21
  mapDelete,
22
+ mapFirst,
22
23
  mapSize,
23
24
  mapForEach,
24
25
  objectDefineProperty,
@@ -1 +1 @@
1
- {"commit":"d5c6dc5f37fb4cbbf8b40f3d82741cb9e00cdfff","buildToolsSha256":"b617652c1601f8722bb85c3a688a1fca4985b53f2c2066c10c76c2e693081137","optimizerSourceSha256":"34c4a040f3cf639f039823880822c6541c384c9b4eaa116d27dda8d9cb5c9f9e"}
1
+ {"commit":"b2cbaa1b6b80ccf3d082d6cb6af8075e2b607006","buildToolsSha256":"b617652c1601f8722bb85c3a688a1fca4985b53f2c2066c10c76c2e693081137","optimizerSourceSha256":"34c4a040f3cf639f039823880822c6541c384c9b4eaa116d27dda8d9cb5c9f9e"}
package/fs/backend.ts CHANGED
@@ -55,6 +55,12 @@ export interface FilesystemBackend {
55
55
  ):
56
56
  | import("./watch-subscriptions.js").HeldWatchBatch
57
57
  | Promise<import("./watch-subscriptions.js").HeldWatchBatch>;
58
+ watchDrain?(
59
+ owner: number,
60
+ cancelled: () => boolean,
61
+ ):
62
+ | import("./watch-service.js").HeldWatchDrain
63
+ | Promise<import("./watch-service.js").HeldWatchDrain>;
58
64
  watchClose?(owner: number, watchId: number): void;
59
65
  closeWatchOwner?(owner: number): void;
60
66
  /** Called in FilesystemService.request() finally after finishResult() to settle provisional pins. */
package/fs/client.ts CHANGED
@@ -501,6 +501,7 @@ function clientWatches(
501
501
  cells: () => Int32Array,
502
502
  revoked: () => boolean,
503
503
  remote: () => boolean,
504
+ canDrain: () => boolean,
504
505
  call: (operation: string, args: unknown[]) => any,
505
506
  ): WatchFileSystem {
506
507
  return {
@@ -513,8 +514,12 @@ function clientWatches(
513
514
  get remote() {
514
515
  return remote();
515
516
  },
517
+ get canDrain() {
518
+ return canDrain();
519
+ },
516
520
  open: (handle, recursive) => call("watchOpen", [handle, recursive]),
517
521
  read: (id) => call("watchRead", [id]),
522
+ drain: () => call("watchDrain", []),
518
523
  close: (id) => {
519
524
  call("watchClose", [id]);
520
525
  },
@@ -648,6 +653,7 @@ export class FilesystemClient implements FileSystem {
648
653
  () => this.shared.watch.cells,
649
654
  this.revoked,
650
655
  () => this.shared.isDirectDisabled(),
656
+ () => !this.shared.isWatchDrainDisabled(),
651
657
  (operation, args) => this.call(operation, args),
652
658
  );
653
659
  connection.port.onmessage = ({ data }) => {