opfs-worker 1.2.2 → 1.2.3

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 x, transfer as u } from "comlink";
2
- import { O as o, o as m, g as A, n as g, s as F, P as C, w as y, F as D, j as b, h as E, k as p, u as H, y as $, r as v, l as T, C as O, A as S, z as I, B as N, f, x as P } from "./helpers-CkNHswLp.js";
3
- class _ {
1
+ import { expose as A, transfer as m } from "comlink";
2
+ import { O as o, o as g, g as C, n as F, s as p, P as b, w as f, F as E, j as H, W as l, h as v, k as D, u as $, y as T, r as S, l as O, C as N, A as I, z as x, B as P, f as u, x as _ } from "./helpers-BXhw_-Ar.js";
3
+ class k {
4
4
  /** Root directory handle for the file system */
5
5
  root;
6
6
  /** Map of watched paths and options */
@@ -44,7 +44,7 @@ class _ {
44
44
  if (!this.options.broadcastChannel)
45
45
  return;
46
46
  const e = t.path;
47
- if (![...this.watchers.values()].some((r) => m(e, r.pattern) && r.include.some((s) => s && m(e, s)) && !r.exclude.some((s) => s && m(e, s))))
47
+ if (![...this.watchers.values()].some((r) => g(e, r.pattern) && r.include.some((s) => s && g(e, s)) && !r.exclude.some((s) => s && g(e, s))))
48
48
  return;
49
49
  let a;
50
50
  if (this.options.hashAlgorithm)
@@ -76,7 +76,7 @@ class _ {
76
76
  * @throws {OPFSError} If OPFS is not supported in the current browser
77
77
  */
78
78
  constructor(t) {
79
- A(), t && this.setOptions(t);
79
+ C(), t && this.setOptions(t);
80
80
  }
81
81
  /**
82
82
  * Initialize the file system within a given directory
@@ -123,7 +123,7 @@ class _ {
123
123
  * @param options.broadcastChannel - Custom name for the broadcast channel
124
124
  */
125
125
  async setOptions(t) {
126
- t.hashAlgorithm !== void 0 && (this.options.hashAlgorithm = t.hashAlgorithm), t.maxFileSize !== void 0 && (this.options.maxFileSize = t.maxFileSize), t.broadcastChannel !== void 0 && (this.broadcastChannel && this.options.broadcastChannel !== t.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.options.broadcastChannel = t.broadcastChannel), t.namespace && (this.options.namespace = t.namespace), t.root !== void 0 && (this.options.root = g(t.root), this.options.namespace || (this.options.namespace = `opfs-worker:${this.options.root}`), await this.mount());
126
+ t.hashAlgorithm !== void 0 && (this.options.hashAlgorithm = t.hashAlgorithm), t.maxFileSize !== void 0 && (this.options.maxFileSize = t.maxFileSize), t.broadcastChannel !== void 0 && (this.broadcastChannel && this.options.broadcastChannel !== t.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.options.broadcastChannel = t.broadcastChannel), t.namespace && (this.options.namespace = t.namespace), t.root !== void 0 && (this.options.root = F(t.root), this.options.namespace || (this.options.namespace = `opfs-worker:${this.options.root}`), await this.mount());
127
127
  }
128
128
  /**
129
129
  * Get a directory handle from a path
@@ -144,7 +144,7 @@ class _ {
144
144
  * ```
145
145
  */
146
146
  async getDirectoryHandle(t, e = !1, i = this.root) {
147
- const a = Array.isArray(t) ? t : F(t);
147
+ const a = Array.isArray(t) ? t : p(t);
148
148
  let r = i;
149
149
  for (const s of a)
150
150
  r = await r.getDirectoryHandle(s, { create: e });
@@ -170,9 +170,9 @@ class _ {
170
170
  * ```
171
171
  */
172
172
  async getFileHandle(t, e = !1, i = this.root) {
173
- const a = F(t);
173
+ const a = p(t);
174
174
  if (a.length === 0)
175
- throw new C("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
175
+ throw new b("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
176
176
  const r = a.pop();
177
177
  return (await this.getDirectoryHandle(a, e, i)).getFileHandle(r, { create: e });
178
178
  }
@@ -239,17 +239,17 @@ class _ {
239
239
  async readFile(t) {
240
240
  await this.mount();
241
241
  try {
242
- return await y(t, "shared", async () => {
242
+ return await f(t, "shared", async () => {
243
243
  const e = await this.open(t);
244
244
  try {
245
245
  const { size: i } = await this.fstat(e), a = new Uint8Array(i);
246
- return i > 0 && await this.read(e, a, 0, i, 0), u(a, [a.buffer]);
246
+ return i > 0 && await this.read(e, a, 0, i, 0), m(a, [a.buffer]);
247
247
  } finally {
248
248
  await this.close(e);
249
249
  }
250
250
  });
251
251
  } catch (e) {
252
- throw new D(t, e);
252
+ throw new E(t, e);
253
253
  }
254
254
  }
255
255
  /**
@@ -277,14 +277,14 @@ class _ {
277
277
  async writeFile(t, e) {
278
278
  await this.mount();
279
279
  const i = e instanceof Uint8Array ? e : new Uint8Array(e);
280
- await y(t, "exclusive", async () => {
280
+ await f(t, "exclusive", async () => {
281
281
  const a = await this.exists(t), r = await this.open(t, { create: !0, truncate: !0 });
282
282
  try {
283
283
  await this.write(r, i, 0, i.length, null, !1), await this.fsync(r);
284
284
  } finally {
285
285
  await this.close(r);
286
286
  }
287
- await this.notifyChange({ path: t, type: a ? "changed" : "added", isDirectory: !1 });
287
+ await this.notifyChange({ path: t, type: a ? l.Changed : l.Added, isDirectory: !1 });
288
288
  });
289
289
  }
290
290
  /**
@@ -312,7 +312,7 @@ class _ {
312
312
  async appendFile(t, e) {
313
313
  await this.mount();
314
314
  const i = e instanceof Uint8Array ? e : new Uint8Array(e);
315
- await y(t, "exclusive", async () => {
315
+ await f(t, "exclusive", async () => {
316
316
  const a = await this.open(t, { create: !0 });
317
317
  try {
318
318
  const { size: r } = await this.fstat(a);
@@ -320,7 +320,7 @@ class _ {
320
320
  } finally {
321
321
  await this.close(a);
322
322
  }
323
- await this.notifyChange({ path: t, type: "changed", isDirectory: !1 });
323
+ await this.notifyChange({ path: t, type: l.Changed, isDirectory: !1 });
324
324
  });
325
325
  }
326
326
  /**
@@ -346,7 +346,7 @@ class _ {
346
346
  */
347
347
  async mkdir(t, e) {
348
348
  await this.mount();
349
- const i = e?.recursive ?? !1, a = F(t);
349
+ const i = e?.recursive ?? !1, a = p(t);
350
350
  let r = this.root;
351
351
  for (let s = 0; s < a.length; s++) {
352
352
  const n = a[s];
@@ -354,14 +354,14 @@ class _ {
354
354
  r = await r.getDirectoryHandle(n, { create: i || s === a.length - 1 });
355
355
  } catch (c) {
356
356
  throw c.name === "NotFoundError" ? new o(
357
- `Parent directory does not exist: ${b(a.slice(0, s + 1))}`,
357
+ `Parent directory does not exist: ${H(a.slice(0, s + 1))}`,
358
358
  "ENOENT",
359
359
  void 0,
360
360
  c
361
361
  ) : c.name === "TypeMismatchError" ? new o(`Path segment is not a directory: ${n}`, "ENOTDIR", void 0, c) : new o("Failed to create directory", "MKDIR_FAILED", void 0, c);
362
362
  }
363
363
  }
364
- await this.notifyChange({ path: t, type: "added", isDirectory: !0 });
364
+ await this.notifyChange({ path: t, type: l.Added, isDirectory: !0 });
365
365
  }
366
366
  /**
367
367
  * Get file or directory statistics
@@ -395,7 +395,7 @@ class _ {
395
395
  isFile: !1,
396
396
  isDirectory: !0
397
397
  };
398
- const e = E(t), i = await this.getDirectoryHandle(p(t), !1), a = this.options.hashAlgorithm !== null;
398
+ const e = v(t), i = await this.getDirectoryHandle(D(t), !1), a = this.options.hashAlgorithm !== null;
399
399
  try {
400
400
  const s = await (await i.getFileHandle(e, { create: !1 })).getFile(), n = {
401
401
  kind: "file",
@@ -407,7 +407,7 @@ class _ {
407
407
  };
408
408
  if (a && this.options.hashAlgorithm)
409
409
  try {
410
- const c = await H(s, this.options.hashAlgorithm, this.options.maxFileSize);
410
+ const c = await $(s, this.options.hashAlgorithm, this.options.maxFileSize);
411
411
  n.hash = c;
412
412
  } catch (c) {
413
413
  console.warn(`Failed to calculate hash for ${t}:`, c);
@@ -479,10 +479,10 @@ class _ {
479
479
  async exists(t) {
480
480
  if (await this.mount(), t === "/")
481
481
  return !0;
482
- const e = E(t);
482
+ const e = v(t);
483
483
  let i = null;
484
484
  try {
485
- i = await this.getDirectoryHandle(p(t), !1);
485
+ i = await this.getDirectoryHandle(D(t), !1);
486
486
  } catch (a) {
487
487
  if (i = null, a.name !== "NotFoundError" && a.name !== "TypeMismatchError")
488
488
  throw a;
@@ -530,7 +530,7 @@ class _ {
530
530
  const a = `${t === "/" ? "" : t}/${i.name}`;
531
531
  await this.remove(a, { recursive: !0 });
532
532
  }
533
- await this.notifyChange({ path: t, type: "changed", isDirectory: !0 });
533
+ await this.notifyChange({ path: t, type: l.Changed, isDirectory: !0 });
534
534
  } catch (e) {
535
535
  throw e instanceof o ? e : new o(`Failed to clear directory: ${t}`, "CLEAR_FAILED", void 0, e);
536
536
  }
@@ -562,8 +562,8 @@ class _ {
562
562
  async remove(t, e) {
563
563
  if (await this.mount(), t === "/")
564
564
  throw new o("Cannot remove root directory", "EROOT");
565
- const { recursive: i = !1, force: a = !1 } = e || {}, r = await this.getDirectoryHandle(p(t), !1), s = await this.stat(t);
566
- await $(r, t, { recursive: i, force: a }), await this.notifyChange({ path: t, type: "removed", isDirectory: s.isDirectory });
565
+ const { recursive: i = !1, force: a = !1 } = e || {}, r = await this.getDirectoryHandle(D(t), !1), s = await this.stat(t);
566
+ await T(r, t, { recursive: i, force: a }), await this.notifyChange({ path: t, type: l.Removed, isDirectory: s.isDirectory });
567
567
  }
568
568
  /**
569
569
  * Resolve a path to an absolute path
@@ -586,9 +586,9 @@ class _ {
586
586
  async realpath(t) {
587
587
  await this.mount();
588
588
  try {
589
- const e = v(t);
589
+ const e = S(t);
590
590
  if (!await this.exists(e))
591
- throw new D(e);
591
+ throw new E(e);
592
592
  return e;
593
593
  } catch (e) {
594
594
  throw e instanceof o ? e : new o(`Failed to resolve path: ${t}`, "REALPATH_FAILED", void 0, e);
@@ -622,7 +622,7 @@ class _ {
622
622
  const a = i?.overwrite ?? !1, r = await this.stat(t);
623
623
  if (await this.exists(e) && !a)
624
624
  throw new o(`Destination already exists: ${e}`, "EEXIST", void 0);
625
- await this.copy(t, e, { recursive: !0, overwrite: a }), await this.remove(t, { recursive: !0 }), await this.notifyChange({ path: t, type: "removed", isDirectory: r.isDirectory }), await this.notifyChange({ path: e, type: "added", isDirectory: r.isDirectory });
625
+ await this.copy(t, e, { recursive: !0, overwrite: a }), await this.remove(t, { recursive: !0 }), await this.notifyChange({ path: t, type: l.Removed, isDirectory: r.isDirectory }), await this.notifyChange({ path: e, type: l.Added, isDirectory: r.isDirectory });
626
626
  } catch (a) {
627
627
  throw a instanceof o ? a : new o(`Failed to rename from ${t} to ${e}`, "RENAME_FAILED", void 0, a);
628
628
  }
@@ -668,9 +668,9 @@ class _ {
668
668
  throw new o(`Cannot copy directory without recursive option: ${t}`, "EISDIR", void 0);
669
669
  await this.mkdir(e, { recursive: !0 });
670
670
  const h = await this.readDir(t);
671
- for (const l of h) {
672
- const w = `${t}/${l.name}`, d = `${e}/${l.name}`;
673
- await this.copy(w, d, { recursive: !0, overwrite: r });
671
+ for (const w of h) {
672
+ const d = `${t}/${w.name}`, y = `${e}/${w.name}`;
673
+ await this.copy(d, y, { recursive: !0, overwrite: r });
674
674
  }
675
675
  }
676
676
  } catch (a) {
@@ -706,7 +706,7 @@ class _ {
706
706
  if (!this.options.broadcastChannel)
707
707
  throw new o("This instance is not configured to send events. Please specify options.broadcastChannel to enable watching.", "ENOENT");
708
708
  const i = {
709
- pattern: T(t, e?.recursive ?? !0),
709
+ pattern: O(t, e?.recursive ?? !0),
710
710
  include: Array.isArray(e?.include) ? e.include : [e?.include ?? "**"],
711
711
  exclude: Array.isArray(e?.exclude) ? e.exclude : [e?.exclude ?? ""]
712
712
  };
@@ -747,9 +747,9 @@ class _ {
747
747
  */
748
748
  async open(t, e) {
749
749
  await this.mount();
750
- const { create: i = !1, exclusive: a = !1, truncate: r = !1 } = e || {}, s = g(v(t));
750
+ const { create: i = !1, exclusive: a = !1, truncate: r = !1 } = e || {}, s = F(S(t));
751
751
  try {
752
- return i && a ? await y(s, "exclusive", async () => {
752
+ return i && a ? await f(s, "exclusive", async () => {
753
753
  if (await this.exists(s))
754
754
  throw new o(`File already exists: ${s}`, "EEXIST", s);
755
755
  return this._openFile(s, i, r);
@@ -769,7 +769,7 @@ class _ {
769
769
  } catch (n) {
770
770
  throw n.name === "TypeMismatchError" ? new o(`Is a directory: ${t}`, "EISDIR", t) : n;
771
771
  }
772
- const r = await O(a, t);
772
+ const r = await N(a, t);
773
773
  i && (r.truncate(0), r.flush());
774
774
  const s = this.nextFd++;
775
775
  return this.openFiles.set(s, {
@@ -795,7 +795,7 @@ class _ {
795
795
  */
796
796
  async close(t) {
797
797
  const e = this._getFileDescriptor(t);
798
- S(t, e.syncHandle, e.path), this.openFiles.delete(t);
798
+ I(t, e.syncHandle, e.path), this.openFiles.delete(t);
799
799
  }
800
800
  /**
801
801
  * Read data from a file descriptor
@@ -823,15 +823,15 @@ class _ {
823
823
  */
824
824
  async read(t, e, i, a, r) {
825
825
  const s = this._getFileDescriptor(t);
826
- I(e.length, i, a, r);
826
+ x(e.length, i, a, r);
827
827
  try {
828
- const n = r ?? s.position, c = s.syncHandle.getSize(), { isEOF: h, actualLength: l } = N(n, a, c);
828
+ const n = r ?? s.position, c = s.syncHandle.getSize(), { isEOF: h, actualLength: w } = P(n, a, c);
829
829
  if (h)
830
- return u({ bytesRead: 0, buffer: e }, [e.buffer]);
831
- const w = e.subarray(i, i + l), d = s.syncHandle.read(w, { at: n });
832
- return r == null && (s.position = n + d), u({ bytesRead: d, buffer: e }, [e.buffer]);
830
+ return m({ bytesRead: 0, buffer: e }, [e.buffer]);
831
+ const d = e.subarray(i, i + w), y = s.syncHandle.read(d, { at: n });
832
+ return r == null && (s.position = n + y), m({ bytesRead: y, buffer: e }, [e.buffer]);
833
833
  } catch (n) {
834
- throw f("read", t, s.path, n);
834
+ throw u("read", t, s.path, n);
835
835
  }
836
836
  }
837
837
  /**
@@ -857,12 +857,12 @@ class _ {
857
857
  */
858
858
  async write(t, e, i = 0, a, r, s = !0) {
859
859
  const n = this._getFileDescriptor(t), c = a ?? e.length - i;
860
- I(e.length, i, c, r);
860
+ x(e.length, i, c, r);
861
861
  try {
862
- const h = r ?? n.position, l = e.subarray(i, i + c), w = n.syncHandle.write(l, { at: h });
863
- return (r == null || r === n.position) && (n.position = h + w), s && await this.notifyChange({ path: n.path, type: "changed", isDirectory: !1 }), w;
862
+ const h = r ?? n.position, w = e.subarray(i, i + c), d = n.syncHandle.write(w, { at: h });
863
+ return (r == null || r === n.position) && (n.position = h + d), s && await this.notifyChange({ path: n.path, type: l.Changed, isDirectory: !1 }), d;
864
864
  } catch (h) {
865
- throw f("write", t, n.path, h);
865
+ throw u("write", t, n.path, h);
866
866
  }
867
867
  }
868
868
  /**
@@ -908,9 +908,9 @@ class _ {
908
908
  if (e < 0 || !Number.isInteger(e))
909
909
  throw new o("Invalid size", "EINVAL");
910
910
  try {
911
- i.syncHandle.truncate(e), i.syncHandle.flush(), i.position > e && (i.position = e), await this.notifyChange({ path: i.path, type: "changed", isDirectory: !1 });
911
+ i.syncHandle.truncate(e), i.syncHandle.flush(), i.position > e && (i.position = e), await this.notifyChange({ path: i.path, type: l.Changed, isDirectory: !1 });
912
912
  } catch (a) {
913
- throw f("truncate", t, i.path, a);
913
+ throw u("truncate", t, i.path, a);
914
914
  }
915
915
  }
916
916
  /**
@@ -932,7 +932,7 @@ class _ {
932
932
  try {
933
933
  e.syncHandle.flush();
934
934
  } catch (i) {
935
- throw f("sync", t, e.path, i);
935
+ throw u("sync", t, e.path, i);
936
936
  }
937
937
  }
938
938
  /**
@@ -944,7 +944,7 @@ class _ {
944
944
  dispose() {
945
945
  this.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.watchers.clear();
946
946
  for (const [t, e] of this.openFiles)
947
- S(t, e.syncHandle, e.path);
947
+ I(t, e.syncHandle, e.path);
948
948
  this.openFiles.clear(), this.nextFd = 1;
949
949
  }
950
950
  /**
@@ -979,17 +979,17 @@ class _ {
979
979
  await this.mount();
980
980
  try {
981
981
  for (const [e, i] of t) {
982
- const a = g(e);
982
+ const a = F(e);
983
983
  let r;
984
- i instanceof Blob ? r = await P(i) : typeof i == "string" ? r = new TextEncoder().encode(i) : r = i, await this.writeFile(a, r);
984
+ i instanceof Blob ? r = await _(i) : typeof i == "string" ? r = new TextEncoder().encode(i) : r = i, await this.writeFile(a, r);
985
985
  }
986
986
  } catch (e) {
987
987
  throw e instanceof o ? e : new o("Failed to sync file system", "SYNC_FAILED", void 0, e);
988
988
  }
989
989
  }
990
990
  }
991
- typeof globalThis < "u" && globalThis.constructor.name === "DedicatedWorkerGlobalScope" && x(new _());
991
+ typeof globalThis < "u" && globalThis.constructor.name === "DedicatedWorkerGlobalScope" && A(new k());
992
992
  export {
993
- _ as OPFSWorker
993
+ k as OPFSWorker
994
994
  };
995
995
  //# sourceMappingURL=raw.js.map