opfs-worker 0.2.6 → 0.3.0

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/index.cjs CHANGED
@@ -1,9 +1,9 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("comlink"),n=require("./helpers-FvdHLObV.cjs"),o=`/**
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("comlink"),n=require("./helpers-FvdHLObV.cjs"),i=`/**
2
2
  * @license
3
3
  * Copyright 2019 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- const H = Symbol("Comlink.proxy"), R = Symbol("Comlink.endpoint"), B = Symbol("Comlink.releaseProxy"), D = Symbol("Comlink.finalizer"), E = Symbol("Comlink.thrown"), $ = (e) => typeof e == "object" && e !== null || typeof e == "function", W = {
6
+ const H = Symbol("Comlink.proxy"), R = Symbol("Comlink.endpoint"), B = Symbol("Comlink.releaseProxy"), A = Symbol("Comlink.finalizer"), E = Symbol("Comlink.thrown"), $ = (e) => typeof e == "object" && e !== null || typeof e == "function", W = {
7
7
  canHandle: (e) => $(e) && e[H],
8
8
  serialize(e) {
9
9
  const { port1: t, port2: r } = new MessageChannel();
@@ -46,7 +46,7 @@ function I(e, t = globalThis, r = ["*"]) {
46
46
  console.warn(\`Invalid origin '\${i.origin}' for comlink proxy\`);
47
47
  return;
48
48
  }
49
- const { id: a, type: s, path: o } = Object.assign({ path: [] }, i.data), l = (i.data.argumentList || []).map(y);
49
+ const { id: a, type: s, path: o } = Object.assign({ path: [] }, i.data), l = (i.data.argumentList || []).map(d);
50
50
  let h;
51
51
  try {
52
52
  const u = o.slice(0, -1).reduce((f, g) => f[g], e), w = o.reduce((f, g) => f[g], e);
@@ -55,7 +55,7 @@ function I(e, t = globalThis, r = ["*"]) {
55
55
  h = w;
56
56
  break;
57
57
  case "SET":
58
- u[o.slice(-1)[0]] = y(i.data.value), h = !0;
58
+ u[o.slice(-1)[0]] = d(i.data.value), h = !0;
59
59
  break;
60
60
  case "APPLY":
61
61
  h = w.apply(u, l);
@@ -82,10 +82,10 @@ function I(e, t = globalThis, r = ["*"]) {
82
82
  h = { value: u, [E]: 0 };
83
83
  }
84
84
  Promise.resolve(h).catch((u) => ({ value: u, [E]: 0 })).then((u) => {
85
- const [w, f] = A(u);
86
- t.postMessage(Object.assign(Object.assign({}, w), { id: a }), f), s === "RELEASE" && (t.removeEventListener("message", n), L(t), D in e && typeof e[D] == "function" && e[D]());
85
+ const [w, f] = D(u);
86
+ t.postMessage(Object.assign(Object.assign({}, w), { id: a }), f), s === "RELEASE" && (t.removeEventListener("message", n), L(t), A in e && typeof e[A] == "function" && e[A]());
87
87
  }).catch((u) => {
88
- const [w, f] = A({
88
+ const [w, f] = D({
89
89
  value: new TypeError("Unserializable return value"),
90
90
  [E]: 0
91
91
  });
@@ -112,14 +112,14 @@ function Y(e, t) {
112
112
  } finally {
113
113
  r.delete(a.id);
114
114
  }
115
- }), M(e, r, [], t);
115
+ }), x(e, r, [], t);
116
116
  }
117
117
  function p(e) {
118
118
  if (e)
119
119
  throw new Error("Proxy has been released and is not useable");
120
120
  }
121
121
  function U(e) {
122
- return d(e, /* @__PURE__ */ new Map(), {
122
+ return y(e, /* @__PURE__ */ new Map(), {
123
123
  type: "RELEASE"
124
124
  }).then(() => {
125
125
  L(e);
@@ -136,7 +136,7 @@ function X(e, t) {
136
136
  function q(e) {
137
137
  S && S.unregister(e);
138
138
  }
139
- function M(e, t, r = [], n = function() {
139
+ function x(e, t, r = [], n = function() {
140
140
  }) {
141
141
  let i = !1;
142
142
  const a = new Proxy(n, {
@@ -148,47 +148,47 @@ function M(e, t, r = [], n = function() {
148
148
  if (o === "then") {
149
149
  if (r.length === 0)
150
150
  return { then: () => a };
151
- const l = d(e, t, {
151
+ const l = y(e, t, {
152
152
  type: "GET",
153
153
  path: r.map((h) => h.toString())
154
- }).then(y);
154
+ }).then(d);
155
155
  return l.then.bind(l);
156
156
  }
157
- return M(e, t, [...r, o]);
157
+ return x(e, t, [...r, o]);
158
158
  },
159
159
  set(s, o, l) {
160
160
  p(i);
161
- const [h, u] = A(l);
162
- return d(e, t, {
161
+ const [h, u] = D(l);
162
+ return y(e, t, {
163
163
  type: "SET",
164
164
  path: [...r, o].map((w) => w.toString()),
165
165
  value: h
166
- }, u).then(y);
166
+ }, u).then(d);
167
167
  },
168
168
  apply(s, o, l) {
169
169
  p(i);
170
170
  const h = r[r.length - 1];
171
171
  if (h === R)
172
- return d(e, t, {
172
+ return y(e, t, {
173
173
  type: "ENDPOINT"
174
- }).then(y);
174
+ }).then(d);
175
175
  if (h === "bind")
176
- return M(e, t, r.slice(0, -1));
177
- const [u, w] = N(l);
178
- return d(e, t, {
176
+ return x(e, t, r.slice(0, -1));
177
+ const [u, w] = v(l);
178
+ return y(e, t, {
179
179
  type: "APPLY",
180
180
  path: r.map((f) => f.toString()),
181
181
  argumentList: u
182
- }, w).then(y);
182
+ }, w).then(d);
183
183
  },
184
184
  construct(s, o) {
185
185
  p(i);
186
- const [l, h] = N(o);
187
- return d(e, t, {
186
+ const [l, h] = v(o);
187
+ return y(e, t, {
188
188
  type: "CONSTRUCT",
189
189
  path: r.map((u) => u.toString()),
190
190
  argumentList: l
191
- }, h).then(y);
191
+ }, h).then(d);
192
192
  }
193
193
  });
194
194
  return X(a, e), a;
@@ -196,8 +196,8 @@ function M(e, t, r = [], n = function() {
196
196
  function K(e) {
197
197
  return Array.prototype.concat.apply([], e);
198
198
  }
199
- function N(e) {
200
- const t = e.map(A);
199
+ function v(e) {
200
+ const t = e.map(D);
201
201
  return [t.map((r) => r[0]), K(t.map((r) => r[1]))];
202
202
  }
203
203
  const _ = /* @__PURE__ */ new WeakMap();
@@ -207,7 +207,7 @@ function J(e, t) {
207
207
  function Q(e) {
208
208
  return Object.assign(e, { [H]: !0 });
209
209
  }
210
- function A(e) {
210
+ function D(e) {
211
211
  for (const [t, r] of z)
212
212
  if (r.canHandle(e)) {
213
213
  const [n, i] = r.serialize(e);
@@ -228,7 +228,7 @@ function A(e) {
228
228
  _.get(e) || []
229
229
  ];
230
230
  }
231
- function y(e) {
231
+ function d(e) {
232
232
  switch (e.type) {
233
233
  case "HANDLER":
234
234
  return z.get(e.name).deserialize(e.value);
@@ -236,7 +236,7 @@ function y(e) {
236
236
  return e.value;
237
237
  }
238
238
  }
239
- function d(e, t, r, n) {
239
+ function y(e, t, r, n) {
240
240
  return new Promise((i) => {
241
241
  const a = Z();
242
242
  t.set(a, i), e.start && e.start(), e.postMessage(Object.assign({ id: a }, r), n);
@@ -255,17 +255,17 @@ class tt extends c {
255
255
  super("OPFS is not supported in this browser", "OPFS_NOT_SUPPORTED");
256
256
  }
257
257
  }
258
- class T extends c {
258
+ class C extends c {
259
259
  constructor() {
260
260
  super("OPFS is not mounted", "OPFS_NOT_MOUNTED");
261
261
  }
262
262
  }
263
- class k extends c {
263
+ class N extends c {
264
264
  constructor(t, r) {
265
265
  super(t, "INVALID_PATH", r);
266
266
  }
267
267
  }
268
- class O extends c {
268
+ class b extends c {
269
269
  constructor(t) {
270
270
  super(\`File not found: \${t}\`, "FILE_NOT_FOUND", t);
271
271
  }
@@ -353,15 +353,15 @@ function m(e) {
353
353
  function P(e) {
354
354
  return typeof e == "string" ? e ?? "/" : \`/\${e.join("/")}\`;
355
355
  }
356
- function b(e) {
356
+ function T(e) {
357
357
  const t = m(e);
358
358
  return t[t.length - 1] || "";
359
359
  }
360
- function x(e) {
360
+ function O(e) {
361
361
  const t = m(e);
362
362
  return t.pop(), P(t);
363
363
  }
364
- function C(e) {
364
+ function M(e) {
365
365
  return !e || e === "/" ? "/" : e.startsWith("/") ? e : \`/\${e}\`;
366
366
  }
367
367
  function ct(e) {
@@ -388,7 +388,7 @@ async function ht(e) {
388
388
  t.close();
389
389
  }
390
390
  }
391
- async function v(e, t, r, n = {}) {
391
+ async function k(e, t, r, n = {}) {
392
392
  let i = null;
393
393
  try {
394
394
  i = await e.createSyncAccessHandle();
@@ -419,8 +419,6 @@ async function ft(e) {
419
419
  class wt {
420
420
  /** Root directory handle for the file system */
421
421
  root = null;
422
- /** Watch event callback */
423
- watchCallback = null;
424
422
  /** Map of watched paths to their last known state */
425
423
  watchers = /* @__PURE__ */ new Map();
426
424
  /** Interval handle for polling watched paths */
@@ -429,11 +427,14 @@ class wt {
429
427
  scanning = !1;
430
428
  /** Promise to prevent concurrent mount operations */
431
429
  mountingPromise = null;
430
+ /** BroadcastChannel instance for sending events */
431
+ broadcastChannel = null;
432
432
  /** Configuration options */
433
433
  options = {
434
434
  watchInterval: 1e3,
435
435
  maxFileSize: 50 * 1024 * 1024,
436
- hashAlgorithm: null
436
+ hashAlgorithm: null,
437
+ broadcastChannel: "opfs-worker"
437
438
  };
438
439
  /**
439
440
  * Notify about internal changes to the file system
@@ -445,7 +446,7 @@ class wt {
445
446
  * @param type - The type of change (create, change, delete)
446
447
  */
447
448
  async notifyChange(t) {
448
- if (!this.watchCallback)
449
+ if (!this.options.broadcastChannel)
449
450
  return;
450
451
  let r;
451
452
  if (this.options.hashAlgorithm && !t.isDirectory && t.type !== "removed")
@@ -455,24 +456,29 @@ class wt {
455
456
  } catch (n) {
456
457
  console.warn(\`Failed to calculate hash for \${t.path}:\`, n);
457
458
  }
458
- this.watchCallback({
459
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
460
- ...t,
461
- ...r && { hash: r }
462
- });
459
+ try {
460
+ this.broadcastChannel || (this.broadcastChannel = new BroadcastChannel(this.options.broadcastChannel));
461
+ const n = {
462
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
463
+ ...t,
464
+ ...r && { hash: r }
465
+ };
466
+ this.broadcastChannel.postMessage(n);
467
+ } catch (n) {
468
+ console.warn("Failed to send event via BroadcastChannel:", n);
469
+ }
463
470
  }
464
471
  /**
465
472
  * Creates a new OPFSFileSystem instance
466
473
  *
467
- * @param watchCallback - Optional callback for file change events
468
474
  * @param options - Optional configuration options
469
475
  * @param options.watchInterval - Polling interval in milliseconds for file watching
470
476
  * @param options.hashAlgorithm - Hash algorithm for file hashing
471
477
  * @param options.maxFileSize - Maximum file size for hashing in bytes (default: 50MB)
472
478
  * @throws {OPFSError} If OPFS is not supported in the current browser
473
479
  */
474
- constructor(t, r) {
475
- ot(), t && (this.watchCallback = t), r && this.setOptions(r), this.mount("/");
480
+ constructor(t) {
481
+ ot(), t && this.setOptions(t), this.mount("/");
476
482
  }
477
483
  /**
478
484
  * Initialize the file system within a given directory
@@ -508,14 +514,6 @@ class wt {
508
514
  }
509
515
  }), this.mountingPromise;
510
516
  }
511
- /**
512
- * Set the watch callback for file change events
513
- *
514
- * @param callback - The callback function to invoke when files change
515
- */
516
- setWatchCallback(t) {
517
- this.watchCallback = t;
518
- }
519
517
  /**
520
518
  * Update configuration options
521
519
  *
@@ -523,9 +521,10 @@ class wt {
523
521
  * @param options.watchInterval - Polling interval in milliseconds for file watching
524
522
  * @param options.hashAlgorithm - Hash algorithm for file hashing
525
523
  * @param options.maxFileSize - Maximum file size for hashing in bytes
524
+ * @param options.broadcastChannel - Custom name for the broadcast channel
526
525
  */
527
526
  setOptions(t) {
528
- t.watchInterval !== void 0 && (this.options.watchInterval = t.watchInterval), t.hashAlgorithm !== void 0 && (this.options.hashAlgorithm = t.hashAlgorithm), t.maxFileSize !== void 0 && (this.options.maxFileSize = t.maxFileSize);
527
+ t.watchInterval !== void 0 && (this.options.watchInterval = t.watchInterval), 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);
529
528
  }
530
529
  /**
531
530
  * Automatically mount the OPFS root if not already mounted
@@ -565,7 +564,7 @@ class wt {
565
564
  */
566
565
  async getDirectoryHandle(t, r = !1, n = this.root) {
567
566
  if (!n)
568
- throw new T();
567
+ throw new C();
569
568
  const i = Array.isArray(t) ? t : m(t);
570
569
  let a = n;
571
570
  for (const s of i)
@@ -593,10 +592,10 @@ class wt {
593
592
  */
594
593
  async getFileHandle(t, r = !1, n = this.root) {
595
594
  if (!n)
596
- throw new T();
595
+ throw new C();
597
596
  const i = m(t);
598
597
  if (i.length === 0)
599
- throw new k("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
598
+ throw new N("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
600
599
  const a = i.pop();
601
600
  return (await this.getDirectoryHandle(i, r, n)).getFileHandle(a, { create: r });
602
601
  }
@@ -647,7 +646,7 @@ class wt {
647
646
  const n = await this.getFileHandle(t, !1), i = await ht(n);
648
647
  return r === "binary" ? i : rt(i, r);
649
648
  } catch (n) {
650
- throw console.error(n), new O(t);
649
+ throw console.error(n), new b(t);
651
650
  }
652
651
  }
653
652
  /**
@@ -678,7 +677,7 @@ class wt {
678
677
  async writeFile(t, r, n) {
679
678
  await this.ensureMounted();
680
679
  const i = await this.getFileHandle(t, !0);
681
- await v(i, r, n, { truncate: !0 }), await this.notifyChange({ path: t, type: "changed", isDirectory: !1 });
680
+ await k(i, r, n, { truncate: !0 }), await this.notifyChange({ path: t, type: "changed", isDirectory: !1 });
682
681
  }
683
682
  /**
684
683
  * Append data to a file
@@ -705,7 +704,7 @@ class wt {
705
704
  async appendFile(t, r, n) {
706
705
  await this.ensureMounted();
707
706
  const i = await this.getFileHandle(t, !0);
708
- await v(i, r, n, { append: !0 }), await this.notifyChange({ path: t, type: "changed", isDirectory: !1 });
707
+ await k(i, r, n, { append: !0 }), await this.notifyChange({ path: t, type: "changed", isDirectory: !1 });
709
708
  }
710
709
  /**
711
710
  * Create a directory
@@ -730,7 +729,7 @@ class wt {
730
729
  */
731
730
  async mkdir(t, r) {
732
731
  if (await this.ensureMounted(), !this.root)
733
- throw new T();
732
+ throw new C();
734
733
  const n = r?.recursive ?? !1, i = m(t);
735
734
  let a = this.root;
736
735
  for (let s = 0; s < i.length; s++) {
@@ -778,7 +777,7 @@ class wt {
778
777
  isFile: !1,
779
778
  isDirectory: !0
780
779
  };
781
- const r = b(t), n = await this.getDirectoryHandle(x(t), !1), i = this.options.hashAlgorithm !== null;
780
+ const r = T(t), n = await this.getDirectoryHandle(O(t), !1), i = this.options.hashAlgorithm !== null;
782
781
  try {
783
782
  const s = await (await n.getFileHandle(r, { create: !1 })).getFile(), o = {
784
783
  kind: "file",
@@ -852,10 +851,10 @@ class wt {
852
851
  async exists(t) {
853
852
  if (await this.ensureMounted(), t === "/")
854
853
  return !0;
855
- const r = b(t);
854
+ const r = T(t);
856
855
  let n = null;
857
856
  try {
858
- n = await this.getDirectoryHandle(x(t), !1);
857
+ n = await this.getDirectoryHandle(O(t), !1);
859
858
  } catch (i) {
860
859
  throw (i.name === "NotFoundError" || i.name === "TypeMismatchError") && (n = null), i;
861
860
  }
@@ -936,10 +935,10 @@ class wt {
936
935
  const n = r?.recursive ?? !1, i = r?.force ?? !1;
937
936
  if (t === "/")
938
937
  throw new c("Cannot remove root directory", "EROOT");
939
- const a = b(t);
938
+ const a = T(t);
940
939
  if (!a)
941
- throw new k("Invalid path", t);
942
- const s = await this.getDirectoryHandle(x(t), !1);
940
+ throw new N("Invalid path", t);
941
+ const s = await this.getDirectoryHandle(O(t), !1);
943
942
  try {
944
943
  await s.removeEntry(a, { recursive: n });
945
944
  } catch (o) {
@@ -973,7 +972,7 @@ class wt {
973
972
  try {
974
973
  const r = ct(t);
975
974
  if (!await this.exists(r))
976
- throw new O(r);
975
+ throw new b(r);
977
976
  return r;
978
977
  } catch (r) {
979
978
  throw r instanceof c ? r : new c(\`Failed to resolve path: \${t}\`, "REALPATH_FAILED");
@@ -999,7 +998,7 @@ class wt {
999
998
  await this.ensureMounted();
1000
999
  try {
1001
1000
  if (!await this.exists(t))
1002
- throw new O(t);
1001
+ throw new b(t);
1003
1002
  await this.copy(t, r, { recursive: !0 }), await this.remove(t, { recursive: !0 }), await this.notifyChange({ path: t, type: "removed", isDirectory: !1 }), await this.notifyChange({ path: r, type: "added", isDirectory: !1 });
1004
1003
  } catch (n) {
1005
1004
  throw n instanceof c ? n : new c(\`Failed to rename from \${t} to \${r}\`, "RENAME_FAILED");
@@ -1061,7 +1060,7 @@ class wt {
1061
1060
  */
1062
1061
  async watch(t) {
1063
1062
  await this.ensureMounted();
1064
- const r = C(t), n = await this.buildSnapshot(r);
1063
+ const r = M(t), n = await this.buildSnapshot(r);
1065
1064
  this.watchers.set(r, n), this.watchTimer || (this.watchTimer = setInterval(() => {
1066
1065
  this.scanWatches();
1067
1066
  }, this.options.watchInterval));
@@ -1070,9 +1069,18 @@ class wt {
1070
1069
  * Stop watching a previously watched path
1071
1070
  */
1072
1071
  unwatch(t) {
1073
- const r = C(t);
1072
+ const r = M(t);
1074
1073
  this.watchers.delete(r), this.watchers.size === 0 && this.watchTimer && (clearInterval(this.watchTimer), this.watchTimer = null);
1075
1074
  }
1075
+ /**
1076
+ * Dispose of resources and clean up the file system instance
1077
+ *
1078
+ * This method should be called when the file system instance is no longer needed
1079
+ * to properly clean up resources like the broadcast channel and watch timers.
1080
+ */
1081
+ dispose() {
1082
+ this.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.watchTimer && (clearInterval(this.watchTimer), this.watchTimer = null), this.watchers.clear();
1083
+ }
1076
1084
  async buildSnapshot(t) {
1077
1085
  const r = /* @__PURE__ */ new Map(), n = async (i) => {
1078
1086
  const a = await this.stat(i);
@@ -1100,10 +1108,13 @@ class wt {
1100
1108
  }
1101
1109
  for (const [i, a] of n) {
1102
1110
  const s = r.get(i);
1103
- s ? (s.mtime !== a.mtime || s.size !== a.size) && await this.notifyChange({ path: i, type: "changed", isDirectory: !1 }) : await this.notifyChange({ path: i, type: "added", isDirectory: !1 });
1111
+ s ? (s.mtime !== a.mtime || s.size !== a.size) && await this.notifyChange({ path: i, type: "changed", isDirectory: a.isDirectory }) : await this.notifyChange({ path: i, type: "added", isDirectory: a.isDirectory });
1104
1112
  }
1105
1113
  for (const i of r.keys())
1106
- n.has(i) || await this.notifyChange({ path: i, type: "removed", isDirectory: !1 });
1114
+ if (!n.has(i)) {
1115
+ const a = r.get(i);
1116
+ await this.notifyChange({ path: i, type: "removed", isDirectory: a?.isDirectory ?? !1 });
1117
+ }
1107
1118
  this.watchers.set(t, n);
1108
1119
  })
1109
1120
  );
@@ -1145,7 +1156,7 @@ class wt {
1145
1156
  try {
1146
1157
  (r?.cleanBefore ?? !1) && await this.clear("/");
1147
1158
  for (const [i, a] of t) {
1148
- const s = C(i);
1159
+ const s = M(i);
1149
1160
  let o;
1150
1161
  a instanceof Blob ? o = await ft(a) : o = a, await this.writeFile(s, o);
1151
1162
  }
@@ -1156,6 +1167,6 @@ class wt {
1156
1167
  }
1157
1168
  }
1158
1169
  typeof self < "u" && self.constructor.name === "DedicatedWorkerGlobalScope" && I(new wt());
1159
- //# sourceMappingURL=worker-CHy3JxL1.js.map
1160
- `,i=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",o],{type:"text/javascript;charset=utf-8"});function s(r){let t;try{if(t=i&&(self.URL||self.webkitURL).createObjectURL(i),!t)throw"";const e=new Worker(t,{type:"module",name:r?.name});return e.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),e}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(o),{type:"module",name:r?.name})}}function c(r,t){const e=a.wrap(new s);return r&&e.setWatchCallback(r?a.proxy(r):()=>{}),t&&e.setOptions(t),e}exports.DirectoryNotFoundError=n.DirectoryNotFoundError;exports.FileNotFoundError=n.FileNotFoundError;exports.OPFSError=n.OPFSError;exports.OPFSNotMountedError=n.OPFSNotMountedError;exports.OPFSNotSupportedError=n.OPFSNotSupportedError;exports.PathError=n.PathError;exports.PermissionError=n.PermissionError;exports.StorageError=n.StorageError;exports.TimeoutError=n.TimeoutError;exports.basename=n.basename;exports.calculateFileHash=n.calculateFileHash;exports.checkOPFSSupport=n.checkOPFSSupport;exports.convertBlobToUint8Array=n.convertBlobToUint8Array;exports.createBuffer=n.createBuffer;exports.decodeBuffer=n.decodeBuffer;exports.dirname=n.dirname;exports.encodeString=n.encodeString;exports.extname=n.extname;exports.joinPath=n.joinPath;exports.normalizePath=n.normalizePath;exports.readFileData=n.readFileData;exports.resolvePath=n.resolvePath;exports.splitPath=n.splitPath;exports.writeFileData=n.writeFileData;exports.createWorker=c;
1170
+ //# sourceMappingURL=worker-DvdTp4yb.js.map
1171
+ `,a=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",i],{type:"text/javascript;charset=utf-8"});function s(e){let t;try{if(t=a&&(self.URL||self.webkitURL).createObjectURL(a),!t)throw"";const r=new Worker(t,{type:"module",name:e?.name});return r.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),r}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(i),{type:"module",name:e?.name})}}function c(e){const t=o.wrap(new s);return e&&t.setOptions(e),t}exports.DirectoryNotFoundError=n.DirectoryNotFoundError;exports.FileNotFoundError=n.FileNotFoundError;exports.OPFSError=n.OPFSError;exports.OPFSNotMountedError=n.OPFSNotMountedError;exports.OPFSNotSupportedError=n.OPFSNotSupportedError;exports.PathError=n.PathError;exports.PermissionError=n.PermissionError;exports.StorageError=n.StorageError;exports.TimeoutError=n.TimeoutError;exports.basename=n.basename;exports.calculateFileHash=n.calculateFileHash;exports.checkOPFSSupport=n.checkOPFSSupport;exports.convertBlobToUint8Array=n.convertBlobToUint8Array;exports.createBuffer=n.createBuffer;exports.decodeBuffer=n.decodeBuffer;exports.dirname=n.dirname;exports.encodeString=n.encodeString;exports.extname=n.extname;exports.joinPath=n.joinPath;exports.normalizePath=n.normalizePath;exports.readFileData=n.readFileData;exports.resolvePath=n.resolvePath;exports.splitPath=n.splitPath;exports.writeFileData=n.writeFileData;exports.createWorker=c;
1161
1172
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import { wrap, proxy } from 'comlink';\n\nimport WorkerCtor from './worker?worker&inline';\n\nimport type { OPFSWorker, RemoteOPFSWorker, WatchEvent, OPFSOptions } from './types';\n\nexport * from './types';\nexport * from './utils/errors';\nexport * from './utils/helpers';\nexport * from './utils/encoder';\n\n/**\n * Creates a new file system instance with inline worker\n * @param watchCallback - Optional callback for file change events\n * @param options - Optional configuration options\n * @returns Promise resolving to the file system interface\n */\nexport function createWorker(\n watchCallback?: (event: WatchEvent) => void,\n options?: OPFSOptions\n): RemoteOPFSWorker {\n const wrapped = wrap<OPFSWorker>(new WorkerCtor());\n \n // Set up watch callback and options if provided\n if (watchCallback) {\n wrapped.setWatchCallback(\n watchCallback ? proxy(watchCallback) : () => {}, \n );\n }\n \n if (options) {\n wrapped.setOptions(options);\n }\n \n return wrapped;\n}\n"],"names":["createWorker","watchCallback","options","wrapped","wrap","WorkerCtor","proxy"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qdAiBO,SAASA,EACZC,EACAC,EACgB,CAChB,MAAMC,EAAUC,EAAAA,KAAiB,IAAIC,CAAY,EAGjD,OAAIJ,GACAE,EAAQ,iBACJF,EAAgBK,EAAAA,MAAML,CAAa,EAAI,IAAM,CAAC,CAAA,EAIlDC,GACAC,EAAQ,WAAWD,CAAO,EAGvBC,CACX"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import { wrap, proxy } from 'comlink';\n\nimport WorkerCtor from './worker?worker&inline';\n\nimport type { OPFSWorker, RemoteOPFSWorker, WatchEvent, OPFSOptions } from './types';\n\nexport * from './types';\nexport * from './utils/errors';\nexport * from './utils/helpers';\nexport * from './utils/encoder';\n\n/**\n * Creates a new file system instance with inline worker\n * @param options - Optional configuration options\n * @returns Promise resolving to the file system interface\n */\nexport function createWorker(\n options?: OPFSOptions\n): RemoteOPFSWorker {\n const wrapped = wrap<OPFSWorker>(new WorkerCtor());\n \n // Set up options if provided\n if (options) {\n wrapped.setOptions(options);\n }\n \n return wrapped;\n}\n"],"names":["createWorker","options","wrapped","wrap","WorkerCtor"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qdAgBO,SAASA,EACZC,EACgB,CAChB,MAAMC,EAAUC,EAAAA,KAAiB,IAAIC,CAAY,EAGjD,OAAIH,GACAC,EAAQ,WAAWD,CAAO,EAGvBC,CACX"}
package/dist/index.d.ts CHANGED
@@ -1,13 +1,12 @@
1
- import type { RemoteOPFSWorker, WatchEvent, OPFSOptions } from './types';
1
+ import type { RemoteOPFSWorker, OPFSOptions } from './types';
2
2
  export * from './types';
3
3
  export * from './utils/errors';
4
4
  export * from './utils/helpers';
5
5
  export * from './utils/encoder';
6
6
  /**
7
7
  * Creates a new file system instance with inline worker
8
- * @param watchCallback - Optional callback for file change events
9
8
  * @param options - Optional configuration options
10
9
  * @returns Promise resolving to the file system interface
11
10
  */
12
- export declare function createWorker(watchCallback?: (event: WatchEvent) => void, options?: OPFSOptions): RemoteOPFSWorker;
11
+ export declare function createWorker(options?: OPFSOptions): RemoteOPFSWorker;
13
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAc,gBAAgB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAErF,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAEhC;;;;;GAKG;AACH,wBAAgB,YAAY,CACxB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,EAC3C,OAAO,CAAC,EAAE,WAAW,GACtB,gBAAgB,CAelB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAc,gBAAgB,EAAc,WAAW,EAAE,MAAM,SAAS,CAAC;AAErF,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAEhC;;;;GAIG;AACH,wBAAgB,YAAY,CACxB,OAAO,CAAC,EAAE,WAAW,GACtB,gBAAgB,CASlB"}