opfs-worker 0.2.4 → 0.2.5

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.
package/dist/raw.js CHANGED
@@ -1,6 +1,6 @@
1
- import { expose as D } from "comlink";
2
- import { d as v, O as o, b as f, s as u, P as F, i as S, o as T, F as y, w as E, j as p, e as d, f as m, k as M, r as H, n as g, l as $ } from "./helpers-Co-qCBmA.js";
3
- class N {
1
+ import { expose as p } from "comlink";
2
+ import { d as S, O as n, b as l, s as w, P as g, i as I, o as v, F as f, w as F, j as T, e as y, f as u, k as M, r as A, n as d, l as $ } from "./helpers-3TGPHd1h.js";
3
+ class O {
4
4
  /** Root directory handle for the file system */
5
5
  root = null;
6
6
  /** Watch event callback */
@@ -15,6 +15,8 @@ class N {
15
15
  scanning = !1;
16
16
  /** Promise to prevent concurrent mount operations */
17
17
  mountingPromise = null;
18
+ /** Hash algorithm for file hashing (null means no hashing) */
19
+ hashAlgorithm = null;
18
20
  /**
19
21
  * Notify about internal changes to the file system
20
22
  *
@@ -24,21 +26,34 @@ class N {
24
26
  * @param path - The path that was changed
25
27
  * @param type - The type of change (create, change, delete)
26
28
  */
27
- notifyInternalChange(t, e) {
28
- this.watchCallback && this.watchCallback({
29
- path: t,
30
- type: e
29
+ async notifyChange(t) {
30
+ if (!this.watchCallback)
31
+ return;
32
+ let e;
33
+ if (this.hashAlgorithm && !t.isDirectory && t.type !== "removed")
34
+ try {
35
+ const i = await this.stat(t.path);
36
+ i.isFile && i.hash && (e = i.hash);
37
+ } catch (i) {
38
+ console.warn(`Failed to calculate hash for ${t.path}:`, i);
39
+ }
40
+ this.watchCallback({
41
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
42
+ ...t,
43
+ ...e && { hash: e }
31
44
  });
32
45
  }
33
46
  /**
34
47
  * Creates a new OPFSFileSystem instance
35
48
  *
36
49
  * @param watchCallback - Optional callback for file change events
37
- * @param watchOptions - Optional configuration for watching
50
+ * @param options - Optional configuration options
51
+ * @param options.watchInterval - Polling interval in milliseconds for file watching
52
+ * @param options.hashAlgorithm - Hash algorithm for file hashing
38
53
  * @throws {OPFSError} If OPFS is not supported in the current browser
39
54
  */
40
55
  constructor(t, e) {
41
- v(), t && (this.watchCallback = t, e?.watchInterval && (this.watchInterval = e.watchInterval)), this.mount("/");
56
+ S(), t && (this.watchCallback = t), e && this.setOptions(e), this.mount("/");
42
57
  }
43
58
  /**
44
59
  * Initialize the file system within a given directory
@@ -68,7 +83,7 @@ class N {
68
83
  const r = await navigator.storage.getDirectory();
69
84
  t === "/" ? this.root = r : this.root = await this.getDirectoryHandle(t, !0, r), e(!0);
70
85
  } catch (r) {
71
- console.error(r), i(new o("Failed to initialize OPFS", "INIT_FAILED"));
86
+ console.error(r), i(new n("Failed to initialize OPFS", "INIT_FAILED"));
72
87
  } finally {
73
88
  this.mountingPromise = null;
74
89
  }
@@ -78,10 +93,19 @@ class N {
78
93
  * Set the watch callback for file change events
79
94
  *
80
95
  * @param callback - The callback function to invoke when files change
81
- * @param options - Optional configuration for watching
82
96
  */
83
- setWatchCallback(t, e) {
84
- this.watchCallback = t, e?.watchInterval && (this.watchInterval = e.watchInterval);
97
+ setWatchCallback(t) {
98
+ this.watchCallback = t;
99
+ }
100
+ /**
101
+ * Set configuration options for the file system
102
+ *
103
+ * @param options - Configuration options to update
104
+ * @param options.watchInterval - Polling interval in milliseconds for file watching
105
+ * @param options.hashAlgorithm - Hash algorithm for file hashing
106
+ */
107
+ setOptions(t) {
108
+ t.watchInterval !== void 0 && (this.watchInterval = t.watchInterval), t.hashAlgorithm !== void 0 && (this.hashAlgorithm = t.hashAlgorithm);
85
109
  }
86
110
  /**
87
111
  * Automatically mount the OPFS root if not already mounted
@@ -98,7 +122,7 @@ class N {
98
122
  await this.mountingPromise;
99
123
  return;
100
124
  }
101
- throw new o("OPFS not mounted", "NOT_MOUNTED");
125
+ throw new n("OPFS not mounted", "NOT_MOUNTED");
102
126
  }
103
127
  }
104
128
  /**
@@ -121,11 +145,11 @@ class N {
121
145
  */
122
146
  async getDirectoryHandle(t, e = !1, i = this.root) {
123
147
  if (!i)
124
- throw new f();
125
- const r = Array.isArray(t) ? t : u(t);
148
+ throw new l();
149
+ const r = Array.isArray(t) ? t : w(t);
126
150
  let a = i;
127
- for (const n of r)
128
- a = await a.getDirectoryHandle(n, { create: e });
151
+ for (const s of r)
152
+ a = await a.getDirectoryHandle(s, { create: e });
129
153
  return a;
130
154
  }
131
155
  /**
@@ -149,43 +173,25 @@ class N {
149
173
  */
150
174
  async getFileHandle(t, e = !1, i = this.root) {
151
175
  if (!i)
152
- throw new f();
153
- const r = u(t);
176
+ throw new l();
177
+ const r = w(t);
154
178
  if (r.length === 0)
155
- throw new F("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
179
+ throw new g("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
156
180
  const a = r.pop();
157
181
  return (await this.getDirectoryHandle(r, e, i)).getFileHandle(a, { create: e });
158
182
  }
159
183
  /**
160
- * Recursively list all files and directories with their stats
184
+ * Get a complete index of all files and directories in the file system
161
185
  *
162
- * Traverses the entire file system starting from the root and returns
163
- * a Map containing all paths and their corresponding file statistics.
186
+ * This method recursively traverses the entire file system and returns
187
+ * a Map containing FileStat objects for every file and directory.
164
188
  *
165
- * @param options - Options for indexing
166
- * @param options.includeHash - Whether to calculate file hash (default: false)
167
- * @param options.hashAlgorithm - Hash algorithm to use (default: 'SHA-1', fastest)
168
- * @returns Promise that resolves to a Map of path => FileStat
169
- * @throws {OPFSError} If the indexing operation fails
189
+ * @returns Promise that resolves to a Map of paths to FileStat objects
190
+ * @throws {OPFSError} If the file system is not mounted
170
191
  *
171
192
  * @example
172
193
  * ```typescript
173
- * // Basic index without hash
174
194
  * const index = await fs.index();
175
- *
176
- * // Index with file hash
177
- * const indexWithHash = await fs.index({
178
- * includeHash: true,
179
- * hashAlgorithm: 'SHA-1'
180
- * });
181
- *
182
- * // Iterate through all files and directories
183
- * for (const [path, stat] of index) {
184
- * console.log(`${path}: ${stat.isFile ? 'file' : 'directory'} (${stat.size} bytes)`);
185
- * if (stat.hash) console.log(` Hash: ${stat.hash}`);
186
- * }
187
- *
188
- * // Get specific file stats
189
195
  * const fileStats = index.get('/data/config.json');
190
196
  * if (fileStats) {
191
197
  * console.log(`File size: ${fileStats.size} bytes`);
@@ -193,35 +199,35 @@ class N {
193
199
  * }
194
200
  * ```
195
201
  */
196
- async index(t) {
197
- const e = /* @__PURE__ */ new Map(), i = async (r) => {
198
- const a = await this.readdir(r, { withFileTypes: !0 });
199
- for (const n of a) {
200
- const s = `${r === "/" ? "" : r}/${n.name}`;
202
+ async index() {
203
+ const t = /* @__PURE__ */ new Map(), e = async (i) => {
204
+ const r = await this.readdir(i, { withFileTypes: !0 });
205
+ for (const a of r) {
206
+ const s = `${i === "/" ? "" : i}/${a.name}`;
201
207
  try {
202
- const c = await this.stat(s, t);
203
- e.set(s, c), c.isDirectory && await i(s);
204
- } catch (c) {
205
- console.warn(`Skipping broken entry: ${s}`, c);
208
+ const o = await this.stat(s);
209
+ t.set(s, o), o.isDirectory && await e(s);
210
+ } catch (o) {
211
+ console.warn(`Skipping broken entry: ${s}`, o);
206
212
  }
207
213
  }
208
214
  };
209
- return e.set("/", {
215
+ return t.set("/", {
210
216
  kind: "directory",
211
217
  size: 0,
212
218
  mtime: (/* @__PURE__ */ new Date(0)).toISOString(),
213
219
  ctime: (/* @__PURE__ */ new Date(0)).toISOString(),
214
220
  isFile: !1,
215
221
  isDirectory: !0
216
- }), await i("/"), e;
222
+ }), await e("/"), t;
217
223
  }
218
224
  async readFile(t, e = "utf-8") {
219
225
  await this.ensureMounted();
220
226
  try {
221
- const i = await this.getFileHandle(t, !1), r = await S(i);
222
- return e === "binary" ? r : T(r, e);
227
+ const i = await this.getFileHandle(t, !1), r = await I(i);
228
+ return e === "binary" ? r : v(r, e);
223
229
  } catch (i) {
224
- throw console.error(i), new y(t);
230
+ throw console.error(i), new f(t);
225
231
  }
226
232
  }
227
233
  /**
@@ -252,7 +258,7 @@ class N {
252
258
  async writeFile(t, e, i) {
253
259
  await this.ensureMounted();
254
260
  const r = await this.getFileHandle(t, !0);
255
- await E(r, e, i, { truncate: !0 }), this.notifyInternalChange(t, "change");
261
+ await F(r, e, i, { truncate: !0 }), await this.notifyChange({ path: t, type: "changed", isDirectory: !1 });
256
262
  }
257
263
  /**
258
264
  * Append data to a file
@@ -279,7 +285,7 @@ class N {
279
285
  async appendFile(t, e, i) {
280
286
  await this.ensureMounted();
281
287
  const r = await this.getFileHandle(t, !0);
282
- await E(r, e, i, { append: !0 }), this.notifyInternalChange(t, "change");
288
+ await F(r, e, i, { append: !0 }), await this.notifyChange({ path: t, type: "changed", isDirectory: !1 });
283
289
  }
284
290
  /**
285
291
  * Create a directory
@@ -304,52 +310,45 @@ class N {
304
310
  */
305
311
  async mkdir(t, e) {
306
312
  if (await this.ensureMounted(), !this.root)
307
- throw new f();
308
- const i = e?.recursive ?? !1, r = u(t);
313
+ throw new l();
314
+ const i = e?.recursive ?? !1, r = w(t);
309
315
  let a = this.root;
310
- for (let n = 0; n < r.length; n++) {
311
- const s = r[n];
316
+ for (let s = 0; s < r.length; s++) {
317
+ const o = r[s];
312
318
  try {
313
- a = await a.getDirectoryHandle(s, { create: i || n === r.length - 1 });
319
+ a = await a.getDirectoryHandle(o, { create: i || s === r.length - 1 });
314
320
  } catch (c) {
315
- throw c.name === "NotFoundError" ? new o(
316
- `Parent directory does not exist: ${p(r.slice(0, n + 1))}`,
321
+ throw c.name === "NotFoundError" ? new n(
322
+ `Parent directory does not exist: ${T(r.slice(0, s + 1))}`,
317
323
  "ENOENT"
318
- ) : c.name === "TypeMismatchError" ? new o(`Path segment is not a directory: ${s}`, "ENOTDIR") : new o("Failed to create directory", "MKDIR_FAILED");
324
+ ) : c.name === "TypeMismatchError" ? new n(`Path segment is not a directory: ${o}`, "ENOTDIR") : new n("Failed to create directory", "MKDIR_FAILED");
319
325
  }
320
326
  }
321
- this.notifyInternalChange(t, "create");
327
+ await this.notifyChange({ path: t, type: "added", isDirectory: !0 });
322
328
  }
323
329
  /**
324
- * Get file or directory stats
330
+ * Get file or directory statistics
325
331
  *
326
- * Retrieves metadata about a file or directory, including size, modification time,
327
- * type information, and optionally file hashes.
332
+ * Returns detailed information about a file or directory, including
333
+ * size, modification time, and optionally a hash of the file content.
328
334
  *
329
335
  * @param path - The path to the file or directory
330
- * @param options - Options for stat operation
331
- * @param options.includeHash - Whether to calculate file hash (default: false, only for files)
332
- * @param options.hashAlgorithm - Hash algorithm to use (default: 'SHA-1', fastest)
333
- * @returns Promise that resolves to file/directory statistics
334
- * @throws {OPFSError} If the file or directory does not exist or cannot be accessed
336
+ * @returns Promise that resolves to FileStat object
337
+ * @throws {OPFSError} If the path does not exist or cannot be accessed
335
338
  *
336
339
  * @example
337
340
  * ```typescript
338
- * // Basic stats
339
- * const stats = await fs.stat('/config/settings.json');
341
+ * const stats = await fs.stat('/data/config.json');
340
342
  * console.log(`File size: ${stats.size} bytes`);
341
- * console.log(`Is file: ${stats.isFile}`);
342
- * console.log(`Modified: ${stats.mtime}`);
343
- *
344
- * // Stats with hash (SHA-1 is fastest)
345
- * const statsWithHash = await fs.stat('/config/settings.json', {
346
- * includeHash: true,
347
- * hashAlgorithm: 'SHA-1'
348
- * });
349
- * console.log(`Hash: ${statsWithHash.hash}`);
343
+ * console.log(`Last modified: ${stats.mtime}`);
344
+ *
345
+ * // If hashing is enabled, hash will be included
346
+ * if (stats.hash) {
347
+ * console.log(`Hash: ${stats.hash}`);
348
+ * }
350
349
  * ```
351
350
  */
352
- async stat(t, e) {
351
+ async stat(t) {
353
352
  if (await this.ensureMounted(), t === "/")
354
353
  return {
355
354
  kind: "directory",
@@ -359,30 +358,30 @@ class N {
359
358
  isFile: !1,
360
359
  isDirectory: !0
361
360
  };
362
- const i = d(t), r = await this.getDirectoryHandle(m(t), !1), a = e?.includeHash ?? !1, n = e?.hashAlgorithm ?? "SHA-1";
361
+ const e = y(t), i = await this.getDirectoryHandle(u(t), !1), r = this.hashAlgorithm !== null;
363
362
  try {
364
- const c = await (await r.getFileHandle(i, { create: !1 })).getFile(), l = {
363
+ const s = await (await i.getFileHandle(e, { create: !1 })).getFile(), o = {
365
364
  kind: "file",
366
- size: c.size,
367
- mtime: new Date(c.lastModified).toISOString(),
368
- ctime: new Date(c.lastModified).toISOString(),
365
+ size: s.size,
366
+ mtime: new Date(s.lastModified).toISOString(),
367
+ ctime: new Date(s.lastModified).toISOString(),
369
368
  isFile: !0,
370
369
  isDirectory: !1
371
370
  };
372
- if (a)
371
+ if (r && this.hashAlgorithm)
373
372
  try {
374
- const h = new Uint8Array(await c.arrayBuffer()), w = await M(h, n);
375
- l.hash = w;
376
- } catch (h) {
377
- console.warn(`Failed to calculate hash for ${t}:`, h);
373
+ const c = await M(s, this.hashAlgorithm);
374
+ o.hash = c;
375
+ } catch (c) {
376
+ console.warn(`Failed to calculate hash for ${t}:`, c);
378
377
  }
379
- return l;
380
- } catch (s) {
381
- if (s.name !== "TypeMismatchError" && s.name !== "NotFoundError")
382
- throw new o("Failed to stat (file)", "STAT_FAILED");
378
+ return o;
379
+ } catch (a) {
380
+ if (a.name !== "TypeMismatchError" && a.name !== "NotFoundError")
381
+ throw new n("Failed to stat (file)", "STAT_FAILED");
383
382
  }
384
383
  try {
385
- return await r.getDirectoryHandle(i, { create: !1 }), {
384
+ return await i.getDirectoryHandle(e, { create: !1 }), {
386
385
  kind: "directory",
387
386
  size: 0,
388
387
  mtime: (/* @__PURE__ */ new Date(0)).toISOString(),
@@ -390,8 +389,8 @@ class N {
390
389
  isFile: !1,
391
390
  isDirectory: !0
392
391
  };
393
- } catch (s) {
394
- throw s.name === "NotFoundError" ? new o(`No such file or directory: ${t}`, "ENOENT") : new o("Failed to stat (directory)", "STAT_FAILED");
392
+ } catch (a) {
393
+ throw a.name === "NotFoundError" ? new n(`No such file or directory: ${t}`, "ENOENT") : new n("Failed to stat (directory)", "STAT_FAILED");
395
394
  }
396
395
  }
397
396
  async readdir(t, e) {
@@ -399,11 +398,11 @@ class N {
399
398
  const i = e?.withFileTypes ?? !1, r = await this.getDirectoryHandle(t, !1);
400
399
  if (i) {
401
400
  const a = [];
402
- for await (const [n, s] of r.entries()) {
403
- const c = s.kind === "file";
401
+ for await (const [s, o] of r.entries()) {
402
+ const c = o.kind === "file";
404
403
  a.push({
405
- name: n,
406
- kind: s.kind,
404
+ name: s,
405
+ kind: o.kind,
407
406
  isFile: c,
408
407
  isDirectory: !c
409
408
  });
@@ -411,8 +410,8 @@ class N {
411
410
  return a;
412
411
  } else {
413
412
  const a = [];
414
- for await (const [n] of r.entries())
415
- a.push(n);
413
+ for await (const [s] of r.entries())
414
+ a.push(s);
416
415
  return a;
417
416
  }
418
417
  }
@@ -433,10 +432,10 @@ class N {
433
432
  async exists(t) {
434
433
  if (await this.ensureMounted(), t === "/")
435
434
  return !0;
436
- const e = d(t);
435
+ const e = y(t);
437
436
  let i = null;
438
437
  try {
439
- i = await this.getDirectoryHandle(m(t), !1);
438
+ i = await this.getDirectoryHandle(u(t), !1);
440
439
  } catch (r) {
441
440
  throw (r.name === "NotFoundError" || r.name === "TypeMismatchError") && (i = null), r;
442
441
  }
@@ -483,9 +482,9 @@ class N {
483
482
  const r = `${t === "/" ? "" : t}/${i.name}`;
484
483
  await this.remove(r, { recursive: !0 });
485
484
  }
486
- this.notifyInternalChange(t, "change");
485
+ await this.notifyChange({ path: t, type: "changed", isDirectory: !0 });
487
486
  } catch (e) {
488
- throw e instanceof o ? e : new o(`Failed to clear directory: ${t}`, "CLEAR_FAILED");
487
+ throw e instanceof n ? e : new n(`Failed to clear directory: ${t}`, "CLEAR_FAILED");
489
488
  }
490
489
  }
491
490
  /**
@@ -516,20 +515,20 @@ class N {
516
515
  await this.ensureMounted();
517
516
  const i = e?.recursive ?? !1, r = e?.force ?? !1;
518
517
  if (t === "/")
519
- throw new o("Cannot remove root directory", "EROOT");
520
- const a = d(t);
518
+ throw new n("Cannot remove root directory", "EROOT");
519
+ const a = y(t);
521
520
  if (!a)
522
- throw new F("Invalid path", t);
523
- const n = await this.getDirectoryHandle(m(t), !1);
521
+ throw new g("Invalid path", t);
522
+ const s = await this.getDirectoryHandle(u(t), !1);
524
523
  try {
525
- await n.removeEntry(a, { recursive: i });
526
- } catch (s) {
527
- if (s.name === "NotFoundError") {
524
+ await s.removeEntry(a, { recursive: i });
525
+ } catch (o) {
526
+ if (o.name === "NotFoundError") {
528
527
  if (!r)
529
- throw new o(`No such file or directory: ${t}`, "ENOENT");
530
- } else throw s.name === "InvalidModificationError" ? new o(`Directory not empty: ${t}. Use recursive option to force removal.`, "ENOTEMPTY") : s.name === "TypeMismatchError" && !i ? new o(`Cannot remove directory without recursive option: ${t}`, "EISDIR") : new o(`Failed to remove path: ${t}`, "RM_FAILED");
528
+ throw new n(`No such file or directory: ${t}`, "ENOENT");
529
+ } else throw o.name === "InvalidModificationError" ? new n(`Directory not empty: ${t}. Use recursive option to force removal.`, "ENOTEMPTY") : o.name === "TypeMismatchError" && !i ? new n(`Cannot remove directory without recursive option: ${t}`, "EISDIR") : new n(`Failed to remove path: ${t}`, "RM_FAILED");
531
530
  }
532
- this.notifyInternalChange(t, "delete");
531
+ await this.notifyChange({ path: t, type: "removed", isDirectory: !1 });
533
532
  }
534
533
  /**
535
534
  * Resolve a path to an absolute path
@@ -552,12 +551,12 @@ class N {
552
551
  async realpath(t) {
553
552
  await this.ensureMounted();
554
553
  try {
555
- const e = H(t);
554
+ const e = A(t);
556
555
  if (!await this.exists(e))
557
- throw new y(e);
556
+ throw new f(e);
558
557
  return e;
559
558
  } catch (e) {
560
- throw e instanceof o ? e : new o(`Failed to resolve path: ${t}`, "REALPATH_FAILED");
559
+ throw e instanceof n ? e : new n(`Failed to resolve path: ${t}`, "REALPATH_FAILED");
561
560
  }
562
561
  }
563
562
  /**
@@ -580,10 +579,10 @@ class N {
580
579
  await this.ensureMounted();
581
580
  try {
582
581
  if (!await this.exists(t))
583
- throw new y(t);
584
- await this.copy(t, e, { recursive: !0 }), await this.remove(t, { recursive: !0 }), this.notifyInternalChange(t, "delete"), this.notifyInternalChange(e, "create");
582
+ throw new f(t);
583
+ await this.copy(t, e, { recursive: !0 }), await this.remove(t, { recursive: !0 }), await this.notifyChange({ path: t, type: "removed", isDirectory: !1 }), await this.notifyChange({ path: e, type: "added", isDirectory: !1 });
585
584
  } catch (i) {
586
- throw i instanceof o ? i : new o(`Failed to rename from ${t} to ${e}`, "RENAME_FAILED");
585
+ throw i instanceof n ? i : new n(`Failed to rename from ${t} to ${e}`, "RENAME_FAILED");
587
586
  }
588
587
  }
589
588
  /**
@@ -616,25 +615,25 @@ class N {
616
615
  try {
617
616
  const r = i?.recursive ?? !1, a = i?.force ?? !0;
618
617
  if (!await this.exists(t))
619
- throw new o(`Source does not exist: ${t}`, "ENOENT");
618
+ throw new n(`Source does not exist: ${t}`, "ENOENT");
620
619
  if (await this.exists(e) && !a)
621
- throw new o(`Destination already exists: ${e}`, "EEXIST");
620
+ throw new n(`Destination already exists: ${e}`, "EEXIST");
622
621
  if ((await this.stat(t)).isFile) {
623
- const l = await this.readFile(t, "binary");
624
- await this.writeFile(e, l);
622
+ const h = await this.readFile(t, "binary");
623
+ await this.writeFile(e, h);
625
624
  } else {
626
625
  if (!r)
627
- throw new o(`Cannot copy directory without recursive option: ${t}`, "EISDIR");
626
+ throw new n(`Cannot copy directory without recursive option: ${t}`, "EISDIR");
628
627
  await this.mkdir(e, { recursive: !0 });
629
- const l = await this.readdir(t, { withFileTypes: !0 });
630
- for (const h of l) {
631
- const w = `${t}/${h.name}`, I = `${e}/${h.name}`;
632
- await this.copy(w, I, { recursive: !0, force: a });
628
+ const h = await this.readdir(t, { withFileTypes: !0 });
629
+ for (const m of h) {
630
+ const D = `${t}/${m.name}`, E = `${e}/${m.name}`;
631
+ await this.copy(D, E, { recursive: !0, force: a });
633
632
  }
634
633
  }
635
- this.notifyInternalChange(e, "create");
634
+ await this.notifyChange({ path: e, type: "added", isDirectory: !1 });
636
635
  } catch (r) {
637
- throw r instanceof o ? r : new o(`Failed to copy from ${t} to ${e}`, "CP_FAILED");
636
+ throw r instanceof n ? r : new n(`Failed to copy from ${t} to ${e}`, "CP_FAILED");
638
637
  }
639
638
  }
640
639
  /**
@@ -642,7 +641,7 @@ class N {
642
641
  */
643
642
  async watch(t) {
644
643
  await this.ensureMounted();
645
- const e = g(t), i = await this.buildSnapshot(e);
644
+ const e = d(t), i = await this.buildSnapshot(e);
646
645
  this.watchers.set(e, i), this.watchTimer || (this.watchTimer = setInterval(() => {
647
646
  this.scanWatches();
648
647
  }, this.watchInterval));
@@ -651,16 +650,16 @@ class N {
651
650
  * Stop watching a previously watched path
652
651
  */
653
652
  unwatch(t) {
654
- const e = g(t);
653
+ const e = d(t);
655
654
  this.watchers.delete(e), this.watchers.size === 0 && this.watchTimer && (clearInterval(this.watchTimer), this.watchTimer = null);
656
655
  }
657
656
  async buildSnapshot(t) {
658
657
  const e = /* @__PURE__ */ new Map(), i = async (r) => {
659
658
  const a = await this.stat(r);
660
659
  if (e.set(r, a), a.isDirectory) {
661
- const n = await this.readdir(r, { withFileTypes: !0 });
662
- for (const s of n) {
663
- const c = `${r === "/" ? "" : r}/${s.name}`;
660
+ const s = await this.readdir(r, { withFileTypes: !0 });
661
+ for (const o of s) {
662
+ const c = `${r === "/" ? "" : r}/${o.name}`;
664
663
  await i(c);
665
664
  }
666
665
  }
@@ -679,16 +678,12 @@ class N {
679
678
  } catch {
680
679
  i = /* @__PURE__ */ new Map();
681
680
  }
682
- const r = [];
683
- for (const [a, n] of i) {
684
- const s = e.get(a);
685
- s ? (s.mtime !== n.mtime || s.size !== n.size) && r.push({ path: a, type: "change" }) : r.push({ path: a, type: "create" });
681
+ for (const [r, a] of i) {
682
+ const s = e.get(r);
683
+ s ? (s.mtime !== a.mtime || s.size !== a.size) && await this.notifyChange({ path: r, type: "changed", isDirectory: !1 }) : await this.notifyChange({ path: r, type: "added", isDirectory: !1 });
686
684
  }
687
- for (const a of e.keys())
688
- i.has(a) || r.push({ path: a, type: "delete" });
689
- if (r.length && this.watchCallback)
690
- for (const a of r)
691
- this.watchCallback(a);
685
+ for (const r of e.keys())
686
+ i.has(r) || await this.notifyChange({ path: r, type: "removed", isDirectory: !1 });
692
687
  this.watchers.set(t, i);
693
688
  })
694
689
  );
@@ -730,18 +725,18 @@ class N {
730
725
  try {
731
726
  (e?.cleanBefore ?? !1) && await this.clear("/");
732
727
  for (const [r, a] of t) {
733
- const n = g(r);
734
- let s;
735
- a instanceof Blob ? s = await $(a) : s = a, await this.writeFile(n, s);
728
+ const s = d(r);
729
+ let o;
730
+ a instanceof Blob ? o = await $(a) : o = a, await this.writeFile(s, o);
736
731
  }
737
- this.notifyInternalChange("/", "change");
732
+ await this.notifyChange({ path: "/", type: "changed", isDirectory: !0 });
738
733
  } catch (i) {
739
- throw i instanceof o ? i : new o("Failed to sync file system", "SYNC_FAILED");
734
+ throw i instanceof n ? i : new n("Failed to sync file system", "SYNC_FAILED");
740
735
  }
741
736
  }
742
737
  }
743
- typeof self < "u" && self.constructor.name === "DedicatedWorkerGlobalScope" && D(new N());
738
+ typeof self < "u" && self.constructor.name === "DedicatedWorkerGlobalScope" && p(new O());
744
739
  export {
745
- N as OPFSWorker
740
+ O as OPFSWorker
746
741
  };
747
742
  //# sourceMappingURL=raw.js.map