@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.
@@ -154,6 +154,16 @@ export interface FileSystem {
154
154
  readonly watches?: WatchFileSystem;
155
155
  }
156
156
 
157
+ /** One ready subscription returned by a batched owner drain. */
158
+ export type WatchDrainEntry =
159
+ | { readonly id: number; readonly batch: WatchBatch }
160
+ | { readonly id: number; readonly errno: number };
161
+
162
+ export interface WatchDrainResult {
163
+ readonly entries: readonly WatchDrainEntry[];
164
+ readonly more: boolean;
165
+ }
166
+
157
167
  /** The opener's filesystem session owns each subscription; session close releases them all. */
158
168
  export interface WatchFileSystem {
159
169
  /** The root's watch cells. Index 3 counts committed watch records. */
@@ -161,8 +171,12 @@ export interface WatchFileSystem {
161
171
  readonly revoked: boolean;
162
172
  /** True when watches are served remotely (attach mode); disables local-generation short-circuit. */
163
173
  readonly remote?: boolean;
174
+ /** True when `drain()` is currently supported by the active backend role. Defaults to `typeof drain === "function"`. */
175
+ readonly canDrain?: boolean;
164
176
  /** Throws FilesystemError. */
165
177
  open(handle: FileHandle, recursive: boolean): number;
166
178
  read(id: number): WatchBatch;
179
+ /** Optional batched drain of ready watches for this session in one round trip. */
180
+ drain?(): WatchDrainResult;
167
181
  close(id: number): void;
168
182
  }
package/core/wasi.ts CHANGED
@@ -498,6 +498,7 @@ export class Wasi {
498
498
  watch_open: this.watchOpen.bind(this),
499
499
  watch_ready: () => (this.watches?.ready() ? 1 : 0),
500
500
  watch_read: this.watchRead.bind(this),
501
+ watch_next: this.watchNext.bind(this),
501
502
  watch_close: (id: number) => this.watches?.close(id >>> 0) ?? EBADF,
502
503
  };
503
504
  const out: WebAssembly.Imports = Object.create(null);
@@ -690,16 +691,37 @@ export class Wasi {
690
691
  }
691
692
 
692
693
  private watchRead(id: number, buf: number, len: number, out: number): number {
694
+ return this.writeWatch(id >>> 0, buf, len, out, -1);
695
+ }
696
+
697
+ private watchNext(outId: number, buf: number, len: number, out: number): number {
698
+ return this.writeWatch(-1, buf, len, out, outId >>> 0);
699
+ }
700
+
701
+ private writeWatch(id: number, buf: number, len: number, out: number, outId: number): number {
693
702
  buf >>>= 0;
694
703
  len >>>= 0;
695
704
  out >>>= 0;
696
705
  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;
706
+ if ((outId >= 0 && outId + 4 > size) || buf + len > size || out + 4 > size) return EFAULT;
707
+ if (
708
+ (len > 0 && buf < out + 4 && out < buf + len) ||
709
+ (outId >= 0 &&
710
+ ((outId < out + 4 && out < outId + 4) || (len > 0 && buf < outId + 4 && outId < buf + len)))
711
+ )
712
+ return EINVAL;
713
+ if (outId >= 0) this.view().setUint32(outId, 0, true);
714
+ const result = id >= 0 ? this.watches?.read(id, len) : this.watches?.readNext(len);
715
+ if (!result) return id >= 0 ? EBADF : 6;
700
716
  if (result.kind === "error") return result.errno;
717
+ const view = this.view();
718
+ if (outId >= 0) view.setUint32(outId, "id" in result ? result.id : 0, true);
719
+ if (result.kind === "watch_error") {
720
+ view.setUint32(out, 0, true);
721
+ return result.errno;
722
+ }
701
723
  if (result.kind === "short") {
702
- this.view().setUint32(out, result.needed, true);
724
+ view.setUint32(out, result.needed, true);
703
725
  return ENOBUFS;
704
726
  }
705
727
  // Reacquire after the service round trip; another thread may have grown shared memory.
package/dist/core/wasi.js CHANGED
@@ -350,6 +350,7 @@ export class Wasi {
350
350
  watch_open: this.watchOpen.bind(this),
351
351
  watch_ready: () => this.watches?.ready() ? 1 : 0,
352
352
  watch_read: this.watchRead.bind(this),
353
+ watch_next: this.watchNext.bind(this),
353
354
  watch_close: (id) => this.watches?.close(id >>> 0) ?? EBADF
354
355
  };
355
356
  const out = Object.create(null);
@@ -517,19 +518,36 @@ export class Wasi {
517
518
  return SUCCESS;
518
519
  }
519
520
  watchRead(id, buf, len, out) {
521
+ return this.writeWatch(id >>> 0, buf, len, out, -1);
522
+ }
523
+ watchNext(outId, buf, len, out) {
524
+ return this.writeWatch(-1, buf, len, out, outId >>> 0);
525
+ }
526
+ writeWatch(id, buf, len, out, outId) {
520
527
  buf >>>= 0;
521
528
  len >>>= 0;
522
529
  out >>>= 0;
523
530
  const size = this.bytes().length;
524
- if (buf + len > size || out + 4 > size)
531
+ if (outId >= 0 && outId + 4 > size || buf + len > size || out + 4 > size)
525
532
  return EFAULT;
526
- const result = this.watches?.read(id >>> 0, len);
533
+ 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))
534
+ return EINVAL;
535
+ if (outId >= 0)
536
+ this.view().setUint32(outId, 0, true);
537
+ const result = id >= 0 ? this.watches?.read(id, len) : this.watches?.readNext(len);
527
538
  if (!result)
528
- return EBADF;
539
+ return id >= 0 ? EBADF : 6;
529
540
  if (result.kind === "error")
530
541
  return result.errno;
542
+ const view = this.view();
543
+ if (outId >= 0)
544
+ view.setUint32(outId, "id" in result ? result.id : 0, true);
545
+ if (result.kind === "watch_error") {
546
+ view.setUint32(out, 0, true);
547
+ return result.errno;
548
+ }
531
549
  if (result.kind === "short") {
532
- this.view().setUint32(out, result.needed, true);
550
+ view.setUint32(out, result.needed, true);
533
551
  return ENOBUFS;
534
552
  }
535
553
  const bytes = this.bytes();
package/dist/fs/client.js CHANGED
@@ -429,7 +429,7 @@ function preparationFailed(completion) {
429
429
  const state = completion?.cells[0];
430
430
  return state === State.Failed || state === State.Cancelled;
431
431
  }
432
- function clientWatches(cells, revoked, remote, call) {
432
+ function clientWatches(cells, revoked, remote, canDrain, call) {
433
433
  return {
434
434
  get cells() {
435
435
  return cells();
@@ -440,8 +440,12 @@ function clientWatches(cells, revoked, remote, call) {
440
440
  get remote() {
441
441
  return remote();
442
442
  },
443
+ get canDrain() {
444
+ return canDrain();
445
+ },
443
446
  open: (handle, recursive) => call("watchOpen", [handle, recursive]),
444
447
  read: (id) => call("watchRead", [id]),
448
+ drain: () => call("watchDrain", []),
445
449
  close: (id) => {
446
450
  call("watchClose", [id]);
447
451
  }
@@ -515,7 +519,7 @@ export class FilesystemClient {
515
519
  this.resident = new ResidentAttachment(connection.residentPublication, this.revoked);
516
520
  this.section = new FilesystemTransportSection(connection, this.requests.memory, this.revoked);
517
521
  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));
522
+ this.watches = clientWatches(() => this.shared.watch.cells, this.revoked, () => this.shared.isDirectDisabled(), () => !this.shared.isWatchDrainDisabled(), (operation, args) => this.call(operation, args));
519
523
  connection.port.onmessage = ({ data }) => {
520
524
  if (data.segment)
521
525
  this.attachSegment(data.segment, data.buffer);
@@ -1,9 +1,12 @@
1
- import { FilesystemError } from "../core/filesystem.js";
1
+ import {
2
+ FilesystemError
3
+ } from "../core/filesystem.js";
2
4
  import {
3
5
  arrayAppend,
4
6
  atomicsLoad,
5
7
  MapConstructor,
6
8
  mapDelete,
9
+ mapFirst,
7
10
  mapForEach,
8
11
  mapGet,
9
12
  mapSet,
@@ -12,6 +15,7 @@ import {
12
15
  const EAGAIN = 6;
13
16
  const EBADF = 8;
14
17
  const ECANCELED = 11;
18
+ const ENOTSUP = 58;
15
19
  const CHANGE = 1;
16
20
  const RENAME = 2;
17
21
  const OVERFLOW = 3;
@@ -22,147 +26,316 @@ const END = { kind: "records", records: [], length: 0 };
22
26
  function failure(errno) {
23
27
  return { kind: "error", errno };
24
28
  }
29
+ function watchError(id, errno) {
30
+ return { kind: "watch_error", id, errno };
31
+ }
32
+ function nextOf(id, result) {
33
+ return result.kind === "error" ? watchError(id, result.errno) : { ...result, id };
34
+ }
35
+ function rotate(map, watch) {
36
+ mapDelete(map, watch.id);
37
+ mapSet(map, watch.id, watch);
38
+ }
25
39
 
26
40
  export class GuestWatchTable {
27
- fs;
28
- watches = new MapConstructor;
29
- nextId = 1;
30
- revocationNotified = false;
41
+ #fs;
42
+ #watches;
43
+ #byService;
44
+ #buffered;
45
+ #errored;
46
+ #ended;
47
+ #nextId = 1;
48
+ #revocationNotified = false;
49
+ #activeCount = 0;
50
+ #observedGen = 0;
51
+ #observedCount = 0;
52
+ #tableObserved;
53
+ #drainMore = false;
54
+ #noDrain = false;
55
+ #flip = false;
31
56
  constructor(fs) {
32
- this.fs = fs;
57
+ this.#fs = fs;
58
+ this.drop();
33
59
  }
34
60
  get word() {
35
- return this.fs.cells;
61
+ return this.#fs.cells;
36
62
  }
37
63
  get active() {
38
- let active = false;
39
- mapForEach(this.watches, (watch) => {
40
- if (!watch.ended)
41
- active = true;
42
- });
43
- return active;
64
+ return this.#activeCount > 0;
65
+ }
66
+ #useDrain() {
67
+ if (typeof this.#fs.drain !== "function" || this.#noDrain)
68
+ return false;
69
+ if (this.#fs.canDrain === false) {
70
+ this.#tableObserved = undefined;
71
+ this.#drainMore = false;
72
+ return false;
73
+ }
74
+ return true;
75
+ }
76
+ #allObserved(generation) {
77
+ return this.#observedCount === this.#activeCount && this.#observedGen === generation || this.#useDrain() && !this.#drainMore && this.#tableObserved === generation;
44
78
  }
45
79
  pending() {
46
- if (this.fs.revoked)
47
- return !!this.fs.remote && !this.revocationNotified && this.active;
48
- return this.hasPending(false);
80
+ if (this.#fs.revoked)
81
+ return !!this.#fs.remote && !this.#revocationNotified && this.#activeCount > 0;
82
+ return this.#activeCount > 0 && (mapSize(this.#buffered) > 0 || mapSize(this.#errored) > 0 || !this.#allObserved(atomicsLoad(this.#fs.cells, 3)));
49
83
  }
50
84
  ready() {
51
- if (!mapSize(this.watches))
85
+ if (!mapSize(this.#watches))
52
86
  return false;
53
- return this.fs.revoked || this.hasPending(true);
54
- }
55
- hasPending(includeEnded) {
56
- const generation = atomicsLoad(this.fs.cells, 3);
57
- let pending = false;
58
- mapForEach(this.watches, (watch) => {
59
- if (watch.ended ? includeEnded : watch.head < watch.queue.length || watch.observed !== generation)
60
- pending = true;
61
- });
62
- return pending;
87
+ return this.#fs.revoked || mapSize(this.#buffered) > 0 || mapSize(this.#errored) > 0 || mapSize(this.#ended) > 0 || this.#activeCount > 0 && !this.#allObserved(atomicsLoad(this.#fs.cells, 3));
88
+ }
89
+ #setObserved(watch, generation) {
90
+ if (watch.observed === generation)
91
+ return;
92
+ if (!watch.ended) {
93
+ if (watch.observed === this.#observedGen)
94
+ this.#observedCount--;
95
+ if (generation !== this.#observedGen) {
96
+ this.#observedGen = generation;
97
+ this.#observedCount = 1;
98
+ } else
99
+ this.#observedCount++;
100
+ }
101
+ watch.observed = generation;
102
+ }
103
+ #markEnded(watch) {
104
+ if (watch.ended)
105
+ return;
106
+ watch.ended = true;
107
+ this.#activeCount--;
108
+ if (watch.observed === this.#observedGen)
109
+ this.#observedCount--;
110
+ watch.errno = 0;
111
+ mapDelete(this.#buffered, watch.id);
112
+ mapDelete(this.#errored, watch.id);
113
+ mapSet(this.#ended, watch.id, watch);
63
114
  }
64
115
  open(handle, recursive) {
65
- if (this.nextId > LAST_ID)
116
+ if (this.#nextId > LAST_ID)
66
117
  throw new FilesystemError(EAGAIN, "watch ids exhausted");
67
- const observed = atomicsLoad(this.fs.cells, 3);
68
- const service = this.fs.open(handle, recursive);
69
- const id = this.nextId++;
70
- mapSet(this.watches, id, { service, observed, queue: [], head: 0, ended: false });
118
+ const observed = atomicsLoad(this.#fs.cells, 3);
119
+ const service = this.#fs.open(handle, recursive);
120
+ const id = this.#nextId++;
121
+ const watch = { id, service, observed: NaN, queue: [], head: 0, ended: false, errno: 0 };
122
+ mapSet(this.#watches, id, watch);
123
+ mapSet(this.#byService, service, watch);
124
+ this.#activeCount++;
125
+ this.#setObserved(watch, observed);
71
126
  return id;
72
127
  }
73
128
  read(id, capacity) {
74
- const watch = mapGet(this.watches, id);
129
+ const watch = mapGet(this.#watches, id);
75
130
  if (!watch)
76
131
  return failure(EBADF);
77
132
  if (watch.ended)
78
133
  return END;
79
- if (watch.head === watch.queue.length) {
80
- const refused = this.refill(watch);
81
- if (refused)
82
- return refused;
134
+ if (watch.head < watch.queue.length)
135
+ return this.#takeFrom(watch, capacity);
136
+ const force = watch.errno !== 0;
137
+ if (force) {
138
+ watch.errno = 0;
139
+ mapDelete(this.#errored, id);
140
+ }
141
+ return this.#refillSingle(watch, force) ?? this.#takeFrom(watch, capacity);
142
+ }
143
+ readNext(capacity) {
144
+ if (!mapSize(this.#watches))
145
+ return failure(EAGAIN);
146
+ if (this.#fs.revoked) {
147
+ if (this.#fs.remote)
148
+ this.#revocationNotified = true;
149
+ const first = mapFirst(this.#watches);
150
+ rotate(this.#watches, first);
151
+ return watchError(first.id, ECANCELED);
152
+ }
153
+ if (this.#useDrain() && (mapSize(this.#buffered) || mapSize(this.#errored) || !this.#drainService()))
154
+ return this.#takeNextReady(capacity);
155
+ return this.#readNextFallback(capacity);
156
+ }
157
+ #takeNextReady(capacity) {
158
+ const buffered = mapFirst(this.#buffered);
159
+ if (buffered) {
160
+ const read = this.#takeFrom(buffered, capacity);
161
+ if (buffered.head < buffered.queue.length)
162
+ rotate(this.#buffered, buffered);
163
+ return nextOf(buffered.id, read);
83
164
  }
84
- return take(watch, capacity);
165
+ const ended = mapFirst(this.#ended);
166
+ const errored = mapFirst(this.#errored);
167
+ const pick = this.#flip ? ended ?? errored : errored ?? ended;
168
+ if (!pick)
169
+ return failure(EAGAIN);
170
+ this.#flip = !pick.ended;
171
+ if (pick.ended) {
172
+ rotate(this.#ended, pick);
173
+ return nextOf(pick.id, END);
174
+ }
175
+ const errno = pick.errno;
176
+ pick.errno = 0;
177
+ if (pick.observed === this.#observedGen)
178
+ this.#observedCount--;
179
+ pick.observed = NaN;
180
+ this.#drainMore = true;
181
+ mapDelete(this.#errored, pick.id);
182
+ return watchError(pick.id, errno);
183
+ }
184
+ #readNextFallback(capacity) {
185
+ let result;
186
+ let reported;
187
+ mapForEach(this.#watches, (watch) => {
188
+ if (result)
189
+ return;
190
+ try {
191
+ const read = this.read(watch.id, capacity);
192
+ if (read.kind !== "error" || read.errno !== EAGAIN) {
193
+ result = nextOf(watch.id, read);
194
+ reported = watch;
195
+ }
196
+ } catch (error) {
197
+ if (!(error instanceof FilesystemError))
198
+ throw error;
199
+ result = watchError(watch.id, error.errno);
200
+ reported = watch;
201
+ }
202
+ });
203
+ if (reported)
204
+ rotate(this.#watches, reported);
205
+ return result ?? failure(EAGAIN);
85
206
  }
86
207
  close(id) {
87
- const watch = mapGet(this.watches, id);
208
+ const watch = mapGet(this.#watches, id);
88
209
  if (!watch)
89
210
  return EBADF;
90
- if (!this.fs.revoked)
91
- this.closeService(watch.service);
92
- mapDelete(this.watches, id);
93
- return 0;
94
- }
95
- closeService(service) {
96
- try {
97
- this.fs.close(service);
98
- } catch (error) {
99
- if (!(error instanceof FilesystemError) || error.errno !== ECANCELED)
100
- throw error;
211
+ if (!this.#fs.revoked) {
212
+ try {
213
+ this.#fs.close(watch.service);
214
+ } catch (error) {
215
+ if (!(error instanceof FilesystemError) || error.errno !== ECANCELED)
216
+ throw error;
217
+ }
218
+ }
219
+ if (!watch.ended) {
220
+ this.#activeCount--;
221
+ if (watch.observed === this.#observedGen)
222
+ this.#observedCount--;
101
223
  }
224
+ mapDelete(this.#buffered, id);
225
+ mapDelete(this.#errored, id);
226
+ mapDelete(this.#ended, id);
227
+ mapDelete(this.#watches, id);
228
+ mapDelete(this.#byService, watch.service);
229
+ if (!mapSize(this.#watches)) {
230
+ this.#tableObserved = undefined;
231
+ this.#drainMore = false;
232
+ }
233
+ return 0;
102
234
  }
103
235
  drop() {
104
- this.watches = new MapConstructor;
236
+ this.#watches = new MapConstructor;
237
+ this.#byService = new MapConstructor;
238
+ this.#buffered = new MapConstructor;
239
+ this.#errored = new MapConstructor;
240
+ this.#ended = new MapConstructor;
241
+ this.#activeCount = this.#observedCount = 0;
242
+ this.#tableObserved = undefined;
243
+ this.#drainMore = false;
105
244
  }
106
- refill(watch) {
107
- if (this.fs.revoked) {
108
- if (this.fs.remote)
109
- this.revocationNotified = true;
110
- return failure(ECANCELED);
245
+ #applyBatch(watch, batch, generation) {
246
+ if (batch.kind === "closed") {
247
+ this.#markEnded(watch);
248
+ return true;
111
249
  }
112
- const generation = atomicsLoad(this.fs.cells, 3);
113
- if (!this.fs.remote && generation === watch.observed)
114
- return failure(EAGAIN);
115
- const previous = watch.observed;
116
- watch.observed = generation;
117
- let batch;
250
+ this.#setObserved(watch, generation);
251
+ watch.queue = encodeBatch(batch);
252
+ watch.head = 0;
253
+ if (watch.queue.length)
254
+ mapSet(this.#buffered, watch.id, watch);
255
+ return false;
256
+ }
257
+ #drainService() {
258
+ const generation = atomicsLoad(this.#fs.cells, 3);
259
+ if (!this.#drainMore && this.#allObserved(generation))
260
+ return false;
261
+ const previous = this.#tableObserved;
262
+ this.#tableObserved = generation;
263
+ let drained;
118
264
  try {
119
- batch = this.fs.read(watch.service);
265
+ drained = this.#fs.drain();
120
266
  } catch (error) {
121
- watch.observed = previous;
267
+ if (error instanceof FilesystemError && error.errno === ENOTSUP) {
268
+ this.#tableObserved = undefined;
269
+ this.#drainMore = false;
270
+ if (this.#fs.canDrain === undefined)
271
+ this.#noDrain = true;
272
+ return true;
273
+ }
274
+ this.#tableObserved = previous;
122
275
  throw error;
123
276
  }
124
- if (batch.kind === "closed") {
125
- watch.ended = true;
126
- return END;
277
+ this.#drainMore = drained.more;
278
+ for (let index = 0;index < drained.entries.length; index++) {
279
+ const entry = drained.entries[index];
280
+ const watch = mapGet(this.#byService, entry.id);
281
+ if (!watch || watch.ended)
282
+ continue;
283
+ if ("errno" in entry) {
284
+ watch.errno = entry.errno;
285
+ mapSet(this.#errored, watch.id, watch);
286
+ } else {
287
+ this.#applyBatch(watch, entry.batch, generation);
288
+ }
127
289
  }
128
- watch.queue = encodeBatch(batch);
129
- watch.head = 0;
290
+ return false;
291
+ }
292
+ #refillSingle(watch, force) {
293
+ if (this.#fs.revoked) {
294
+ if (this.#fs.remote)
295
+ this.#revocationNotified = true;
296
+ return failure(ECANCELED);
297
+ }
298
+ const generation = atomicsLoad(this.#fs.cells, 3);
299
+ if (!force && !this.#fs.remote && (generation === watch.observed || this.#useDrain() && !this.#drainMore && generation === this.#tableObserved))
300
+ return failure(EAGAIN);
301
+ if (this.#applyBatch(watch, this.#fs.read(watch.service), generation))
302
+ return END;
130
303
  if (!watch.queue.length)
131
304
  return failure(EAGAIN);
132
305
  }
133
- }
134
- function take(watch, capacity) {
135
- const records = [];
136
- let length = 0;
137
- while (watch.head < watch.queue.length) {
138
- const record = watch.queue[watch.head];
139
- if (length + record.length > capacity)
140
- break;
141
- arrayAppend(records, record);
142
- length += record.length;
143
- watch.head++;
144
- if (record[0] === OVERFLOW)
145
- watch.ended = true;
146
- }
147
- if (!length)
148
- return { kind: "short", needed: watch.queue[watch.head].length };
149
- if (watch.head === watch.queue.length) {
150
- watch.queue = [];
151
- watch.head = 0;
306
+ #takeFrom(watch, capacity) {
307
+ const records = [];
308
+ let length = 0;
309
+ while (watch.head < watch.queue.length) {
310
+ const record = watch.queue[watch.head];
311
+ if (length + record.length > capacity)
312
+ break;
313
+ arrayAppend(records, record);
314
+ length += record.length;
315
+ watch.head++;
316
+ if (record[0] === OVERFLOW)
317
+ this.#markEnded(watch);
318
+ }
319
+ if (!length)
320
+ return { kind: "short", needed: watch.queue[watch.head].length };
321
+ if (watch.head === watch.queue.length) {
322
+ watch.queue = [];
323
+ watch.head = 0;
324
+ mapDelete(this.#buffered, watch.id);
325
+ }
326
+ return { kind: "records", records, length };
152
327
  }
153
- return { kind: "records", records, length };
154
328
  }
155
329
  function encodeBatch(batch) {
156
330
  if (batch.kind === "overflow")
157
331
  return [encodeRecord(OVERFLOW, null)];
158
332
  const records = [];
159
- for (let index = 0;index < batch.events.length; index++)
160
- arrayAppend(records, encodeEvent(batch.events[index]));
333
+ for (let index = 0;index < batch.events.length; index++) {
334
+ const event = batch.events[index];
335
+ arrayAppend(records, encodeRecord(event.type === "change" ? CHANGE : RENAME, event.name));
336
+ }
161
337
  return records;
162
338
  }
163
- function encodeEvent(event) {
164
- return encodeRecord(event.type === "change" ? CHANGE : RENAME, event.name);
165
- }
166
339
  function encodeRecord(type, name) {
167
340
  const bytes = name === null ? undefined : encoder.encode(name);
168
341
  const size = bytes ? bytes.length : 0;