opfs-worker 0.2.3 → 0.2.4
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/README.md +5 -3
- package/dist/assets/worker-DCm4BiWM.js.map +1 -0
- package/dist/index.cjs +79 -59
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +99 -79
- package/dist/index.js.map +1 -1
- package/dist/raw.cjs +1 -1
- package/dist/raw.cjs.map +1 -1
- package/dist/raw.js +48 -28
- package/dist/raw.js.map +1 -1
- package/dist/worker.d.ts +10 -0
- package/dist/worker.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/assets/worker-CRHhlrlS.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { wrap as i, proxy as o } from "comlink";
|
|
2
|
-
import { D as
|
|
2
|
+
import { D as d, F as u, O as p, b as w, a as y, P as m, c as g, S as v, T as E, e as S, k as F, d as b, l as P, h as x, o as T, f as I, m as A, g as O, j as _, n as C, i as D, r as k, s as U, w as R } from "./helpers-Co-qCBmA.js";
|
|
3
3
|
const a = `/**
|
|
4
4
|
* @license
|
|
5
5
|
* Copyright 2019 Google LLC
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
|
-
const H = Symbol("Comlink.proxy"), R = Symbol("Comlink.endpoint"), B = Symbol("Comlink.releaseProxy"),
|
|
8
|
+
const H = Symbol("Comlink.proxy"), R = Symbol("Comlink.endpoint"), B = Symbol("Comlink.releaseProxy"), I = Symbol("Comlink.finalizer"), p = Symbol("Comlink.thrown"), $ = (t) => typeof t == "object" && t !== null || typeof t == "function", W = {
|
|
9
9
|
canHandle: (t) => $(t) && t[H],
|
|
10
10
|
serialize(t) {
|
|
11
11
|
const { port1: e, port2: r } = new MessageChannel();
|
|
12
|
-
return
|
|
12
|
+
return O(t, e), [r, [r]];
|
|
13
13
|
},
|
|
14
14
|
deserialize(t) {
|
|
15
15
|
return t.start(), Y(t);
|
|
@@ -40,7 +40,7 @@ function V(t, e) {
|
|
|
40
40
|
return !0;
|
|
41
41
|
return !1;
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function O(t, e = globalThis, r = ["*"]) {
|
|
44
44
|
e.addEventListener("message", function a(n) {
|
|
45
45
|
if (!n || !n.data)
|
|
46
46
|
return;
|
|
@@ -48,7 +48,7 @@ function x(t, e = globalThis, r = ["*"]) {
|
|
|
48
48
|
console.warn(\`Invalid origin '\${n.origin}' for comlink proxy\`);
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
|
-
const { id: i, type: o, path: s } = Object.assign({ path: [] }, n.data), l = (n.data.argumentList || []).map(
|
|
51
|
+
const { id: i, type: o, path: s } = Object.assign({ path: [] }, n.data), l = (n.data.argumentList || []).map(y);
|
|
52
52
|
let u;
|
|
53
53
|
try {
|
|
54
54
|
const f = s.slice(0, -1).reduce((h, g) => h[g], t), w = s.reduce((h, g) => h[g], t);
|
|
@@ -57,7 +57,7 @@ function x(t, e = globalThis, r = ["*"]) {
|
|
|
57
57
|
u = w;
|
|
58
58
|
break;
|
|
59
59
|
case "SET":
|
|
60
|
-
f[s.slice(-1)[0]] =
|
|
60
|
+
f[s.slice(-1)[0]] = y(n.data.value), u = !0;
|
|
61
61
|
break;
|
|
62
62
|
case "APPLY":
|
|
63
63
|
u = w.apply(f, l);
|
|
@@ -71,7 +71,7 @@ function x(t, e = globalThis, r = ["*"]) {
|
|
|
71
71
|
case "ENDPOINT":
|
|
72
72
|
{
|
|
73
73
|
const { port1: h, port2: g } = new MessageChannel();
|
|
74
|
-
|
|
74
|
+
O(t, g), u = J(h, [h]);
|
|
75
75
|
}
|
|
76
76
|
break;
|
|
77
77
|
case "RELEASE":
|
|
@@ -85,7 +85,7 @@ function x(t, e = globalThis, r = ["*"]) {
|
|
|
85
85
|
}
|
|
86
86
|
Promise.resolve(u).catch((f) => ({ value: f, [p]: 0 })).then((f) => {
|
|
87
87
|
const [w, h] = A(f);
|
|
88
|
-
e.postMessage(Object.assign(Object.assign({}, w), { id: i }), h), o === "RELEASE" && (e.removeEventListener("message", a), L(e),
|
|
88
|
+
e.postMessage(Object.assign(Object.assign({}, w), { id: i }), h), o === "RELEASE" && (e.removeEventListener("message", a), L(e), I in t && typeof t[I] == "function" && t[I]());
|
|
89
89
|
}).catch((f) => {
|
|
90
90
|
const [w, h] = A({
|
|
91
91
|
value: new TypeError("Unserializable return value"),
|
|
@@ -114,14 +114,14 @@ function Y(t, e) {
|
|
|
114
114
|
} finally {
|
|
115
115
|
r.delete(i.id);
|
|
116
116
|
}
|
|
117
|
-
}),
|
|
117
|
+
}), P(t, r, [], e);
|
|
118
118
|
}
|
|
119
119
|
function E(t) {
|
|
120
120
|
if (t)
|
|
121
121
|
throw new Error("Proxy has been released and is not useable");
|
|
122
122
|
}
|
|
123
123
|
function z(t) {
|
|
124
|
-
return
|
|
124
|
+
return d(t, /* @__PURE__ */ new Map(), {
|
|
125
125
|
type: "RELEASE"
|
|
126
126
|
}).then(() => {
|
|
127
127
|
L(t);
|
|
@@ -138,7 +138,7 @@ function X(t, e) {
|
|
|
138
138
|
function q(t) {
|
|
139
139
|
S && S.unregister(t);
|
|
140
140
|
}
|
|
141
|
-
function
|
|
141
|
+
function P(t, e, r = [], a = function() {
|
|
142
142
|
}) {
|
|
143
143
|
let n = !1;
|
|
144
144
|
const i = new Proxy(a, {
|
|
@@ -150,47 +150,47 @@ function O(t, e, r = [], a = function() {
|
|
|
150
150
|
if (s === "then") {
|
|
151
151
|
if (r.length === 0)
|
|
152
152
|
return { then: () => i };
|
|
153
|
-
const l =
|
|
153
|
+
const l = d(t, e, {
|
|
154
154
|
type: "GET",
|
|
155
155
|
path: r.map((u) => u.toString())
|
|
156
|
-
}).then(
|
|
156
|
+
}).then(y);
|
|
157
157
|
return l.then.bind(l);
|
|
158
158
|
}
|
|
159
|
-
return
|
|
159
|
+
return P(t, e, [...r, s]);
|
|
160
160
|
},
|
|
161
161
|
set(o, s, l) {
|
|
162
162
|
E(n);
|
|
163
163
|
const [u, f] = A(l);
|
|
164
|
-
return
|
|
164
|
+
return d(t, e, {
|
|
165
165
|
type: "SET",
|
|
166
166
|
path: [...r, s].map((w) => w.toString()),
|
|
167
167
|
value: u
|
|
168
|
-
}, f).then(
|
|
168
|
+
}, f).then(y);
|
|
169
169
|
},
|
|
170
170
|
apply(o, s, l) {
|
|
171
171
|
E(n);
|
|
172
172
|
const u = r[r.length - 1];
|
|
173
173
|
if (u === R)
|
|
174
|
-
return
|
|
174
|
+
return d(t, e, {
|
|
175
175
|
type: "ENDPOINT"
|
|
176
|
-
}).then(
|
|
176
|
+
}).then(y);
|
|
177
177
|
if (u === "bind")
|
|
178
|
-
return
|
|
179
|
-
const [f, w] =
|
|
180
|
-
return
|
|
178
|
+
return P(t, e, r.slice(0, -1));
|
|
179
|
+
const [f, w] = k(l);
|
|
180
|
+
return d(t, e, {
|
|
181
181
|
type: "APPLY",
|
|
182
182
|
path: r.map((h) => h.toString()),
|
|
183
183
|
argumentList: f
|
|
184
|
-
}, w).then(
|
|
184
|
+
}, w).then(y);
|
|
185
185
|
},
|
|
186
186
|
construct(o, s) {
|
|
187
187
|
E(n);
|
|
188
|
-
const [l, u] =
|
|
189
|
-
return
|
|
188
|
+
const [l, u] = k(s);
|
|
189
|
+
return d(t, e, {
|
|
190
190
|
type: "CONSTRUCT",
|
|
191
191
|
path: r.map((f) => f.toString()),
|
|
192
192
|
argumentList: l
|
|
193
|
-
}, u).then(
|
|
193
|
+
}, u).then(y);
|
|
194
194
|
}
|
|
195
195
|
});
|
|
196
196
|
return X(i, t), i;
|
|
@@ -198,7 +198,7 @@ function O(t, e, r = [], a = function() {
|
|
|
198
198
|
function K(t) {
|
|
199
199
|
return Array.prototype.concat.apply([], t);
|
|
200
200
|
}
|
|
201
|
-
function
|
|
201
|
+
function k(t) {
|
|
202
202
|
const e = t.map(A);
|
|
203
203
|
return [e.map((r) => r[0]), K(e.map((r) => r[1]))];
|
|
204
204
|
}
|
|
@@ -230,7 +230,7 @@ function A(t) {
|
|
|
230
230
|
_.get(t) || []
|
|
231
231
|
];
|
|
232
232
|
}
|
|
233
|
-
function
|
|
233
|
+
function y(t) {
|
|
234
234
|
switch (t.type) {
|
|
235
235
|
case "HANDLER":
|
|
236
236
|
return U.get(t.name).deserialize(t.value);
|
|
@@ -238,7 +238,7 @@ function d(t) {
|
|
|
238
238
|
return t.value;
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
|
-
function
|
|
241
|
+
function d(t, e, r, a) {
|
|
242
242
|
return new Promise((n) => {
|
|
243
243
|
const i = Z();
|
|
244
244
|
e.set(i, n), t.start && t.start(), t.postMessage(Object.assign({ id: i }, r), a);
|
|
@@ -257,17 +257,17 @@ class ee extends c {
|
|
|
257
257
|
super("OPFS is not supported in this browser", "OPFS_NOT_SUPPORTED");
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
|
-
class
|
|
260
|
+
class T extends c {
|
|
261
261
|
constructor() {
|
|
262
262
|
super("OPFS is not mounted", "OPFS_NOT_MOUNTED");
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
|
-
class
|
|
265
|
+
class v extends c {
|
|
266
266
|
constructor(e, r) {
|
|
267
267
|
super(e, "INVALID_PATH", r);
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
|
-
class
|
|
270
|
+
class D extends c {
|
|
271
271
|
constructor(e) {
|
|
272
272
|
super(\`File not found: \${e}\`, "FILE_NOT_FOUND", e);
|
|
273
273
|
}
|
|
@@ -352,18 +352,18 @@ function oe() {
|
|
|
352
352
|
function m(t) {
|
|
353
353
|
return Array.isArray(t) ? t : t.split("/").filter(Boolean);
|
|
354
354
|
}
|
|
355
|
-
function
|
|
355
|
+
function x(t) {
|
|
356
356
|
return typeof t == "string" ? t ?? "/" : \`/\${t.join("/")}\`;
|
|
357
357
|
}
|
|
358
|
-
function
|
|
358
|
+
function b(t) {
|
|
359
359
|
const e = m(t);
|
|
360
360
|
return e[e.length - 1] || "";
|
|
361
361
|
}
|
|
362
|
-
function
|
|
362
|
+
function M(t) {
|
|
363
363
|
const e = m(t);
|
|
364
|
-
return e.pop(),
|
|
364
|
+
return e.pop(), x(e);
|
|
365
365
|
}
|
|
366
|
-
function
|
|
366
|
+
function C(t) {
|
|
367
367
|
return !t || t === "/" ? "/" : t.startsWith("/") ? t : \`/\${t}\`;
|
|
368
368
|
}
|
|
369
369
|
function ce(t) {
|
|
@@ -376,7 +376,7 @@ function ce(t) {
|
|
|
376
376
|
r.pop();
|
|
377
377
|
} else
|
|
378
378
|
r.push(a);
|
|
379
|
-
return
|
|
379
|
+
return x(r);
|
|
380
380
|
}
|
|
381
381
|
function le(t, e = "utf-8") {
|
|
382
382
|
return typeof t == "string" ? te(t, e) : t instanceof Uint8Array ? t : new Uint8Array(t);
|
|
@@ -390,7 +390,7 @@ async function ue(t) {
|
|
|
390
390
|
e.close();
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
|
-
async function
|
|
393
|
+
async function N(t, e, r, a = {}) {
|
|
394
394
|
let n = null;
|
|
395
395
|
try {
|
|
396
396
|
n = await t.createSyncAccessHandle();
|
|
@@ -435,6 +435,21 @@ class we {
|
|
|
435
435
|
scanning = !1;
|
|
436
436
|
/** Promise to prevent concurrent mount operations */
|
|
437
437
|
mountingPromise = null;
|
|
438
|
+
/**
|
|
439
|
+
* Notify about internal changes to the file system
|
|
440
|
+
*
|
|
441
|
+
* This method is called by internal operations to notify clients about
|
|
442
|
+
* changes, even when no specific paths are being watched.
|
|
443
|
+
*
|
|
444
|
+
* @param path - The path that was changed
|
|
445
|
+
* @param type - The type of change (create, change, delete)
|
|
446
|
+
*/
|
|
447
|
+
notifyInternalChange(e, r) {
|
|
448
|
+
this.watchCallback && this.watchCallback({
|
|
449
|
+
path: e,
|
|
450
|
+
type: r
|
|
451
|
+
});
|
|
452
|
+
}
|
|
438
453
|
/**
|
|
439
454
|
* Creates a new OPFSFileSystem instance
|
|
440
455
|
*
|
|
@@ -526,7 +541,7 @@ class we {
|
|
|
526
541
|
*/
|
|
527
542
|
async getDirectoryHandle(e, r = !1, a = this.root) {
|
|
528
543
|
if (!a)
|
|
529
|
-
throw new
|
|
544
|
+
throw new T();
|
|
530
545
|
const n = Array.isArray(e) ? e : m(e);
|
|
531
546
|
let i = a;
|
|
532
547
|
for (const o of n)
|
|
@@ -554,10 +569,10 @@ class we {
|
|
|
554
569
|
*/
|
|
555
570
|
async getFileHandle(e, r = !1, a = this.root) {
|
|
556
571
|
if (!a)
|
|
557
|
-
throw new
|
|
572
|
+
throw new T();
|
|
558
573
|
const n = m(e);
|
|
559
574
|
if (n.length === 0)
|
|
560
|
-
throw new
|
|
575
|
+
throw new v("Path must not be empty", Array.isArray(e) ? e.join("/") : e);
|
|
561
576
|
const i = n.pop();
|
|
562
577
|
return (await this.getDirectoryHandle(n, r, a)).getFileHandle(i, { create: r });
|
|
563
578
|
}
|
|
@@ -626,7 +641,7 @@ class we {
|
|
|
626
641
|
const a = await this.getFileHandle(e, !1), n = await ue(a);
|
|
627
642
|
return r === "binary" ? n : re(n, r);
|
|
628
643
|
} catch (a) {
|
|
629
|
-
throw console.error(a), new
|
|
644
|
+
throw console.error(a), new D(e);
|
|
630
645
|
}
|
|
631
646
|
}
|
|
632
647
|
/**
|
|
@@ -657,7 +672,7 @@ class we {
|
|
|
657
672
|
async writeFile(e, r, a) {
|
|
658
673
|
await this.ensureMounted();
|
|
659
674
|
const n = await this.getFileHandle(e, !0);
|
|
660
|
-
await
|
|
675
|
+
await N(n, r, a, { truncate: !0 }), this.notifyInternalChange(e, "change");
|
|
661
676
|
}
|
|
662
677
|
/**
|
|
663
678
|
* Append data to a file
|
|
@@ -684,7 +699,7 @@ class we {
|
|
|
684
699
|
async appendFile(e, r, a) {
|
|
685
700
|
await this.ensureMounted();
|
|
686
701
|
const n = await this.getFileHandle(e, !0);
|
|
687
|
-
await
|
|
702
|
+
await N(n, r, a, { append: !0 }), this.notifyInternalChange(e, "change");
|
|
688
703
|
}
|
|
689
704
|
/**
|
|
690
705
|
* Create a directory
|
|
@@ -709,7 +724,7 @@ class we {
|
|
|
709
724
|
*/
|
|
710
725
|
async mkdir(e, r) {
|
|
711
726
|
if (await this.ensureMounted(), !this.root)
|
|
712
|
-
throw new
|
|
727
|
+
throw new T();
|
|
713
728
|
const a = r?.recursive ?? !1, n = m(e);
|
|
714
729
|
let i = this.root;
|
|
715
730
|
for (let o = 0; o < n.length; o++) {
|
|
@@ -718,11 +733,12 @@ class we {
|
|
|
718
733
|
i = await i.getDirectoryHandle(s, { create: a || o === n.length - 1 });
|
|
719
734
|
} catch (l) {
|
|
720
735
|
throw l.name === "NotFoundError" ? new c(
|
|
721
|
-
\`Parent directory does not exist: \${
|
|
736
|
+
\`Parent directory does not exist: \${x(n.slice(0, o + 1))}\`,
|
|
722
737
|
"ENOENT"
|
|
723
738
|
) : l.name === "TypeMismatchError" ? new c(\`Path segment is not a directory: \${s}\`, "ENOTDIR") : new c("Failed to create directory", "MKDIR_FAILED");
|
|
724
739
|
}
|
|
725
740
|
}
|
|
741
|
+
this.notifyInternalChange(e, "create");
|
|
726
742
|
}
|
|
727
743
|
/**
|
|
728
744
|
* Get file or directory stats
|
|
@@ -763,7 +779,7 @@ class we {
|
|
|
763
779
|
isFile: !1,
|
|
764
780
|
isDirectory: !0
|
|
765
781
|
};
|
|
766
|
-
const a =
|
|
782
|
+
const a = b(e), n = await this.getDirectoryHandle(M(e), !1), i = r?.includeHash ?? !1, o = r?.hashAlgorithm ?? "SHA-1";
|
|
767
783
|
try {
|
|
768
784
|
const l = await (await n.getFileHandle(a, { create: !1 })).getFile(), u = {
|
|
769
785
|
kind: "file",
|
|
@@ -837,10 +853,10 @@ class we {
|
|
|
837
853
|
async exists(e) {
|
|
838
854
|
if (await this.ensureMounted(), e === "/")
|
|
839
855
|
return !0;
|
|
840
|
-
const r =
|
|
856
|
+
const r = b(e);
|
|
841
857
|
let a = null;
|
|
842
858
|
try {
|
|
843
|
-
a = await this.getDirectoryHandle(
|
|
859
|
+
a = await this.getDirectoryHandle(M(e), !1);
|
|
844
860
|
} catch (n) {
|
|
845
861
|
throw (n.name === "NotFoundError" || n.name === "TypeMismatchError") && (a = null), n;
|
|
846
862
|
}
|
|
@@ -887,6 +903,7 @@ class we {
|
|
|
887
903
|
const n = \`\${e === "/" ? "" : e}/\${a.name}\`;
|
|
888
904
|
await this.remove(n, { recursive: !0 });
|
|
889
905
|
}
|
|
906
|
+
this.notifyInternalChange(e, "change");
|
|
890
907
|
} catch (r) {
|
|
891
908
|
throw r instanceof c ? r : new c(\`Failed to clear directory: \${e}\`, "CLEAR_FAILED");
|
|
892
909
|
}
|
|
@@ -920,10 +937,10 @@ class we {
|
|
|
920
937
|
const a = r?.recursive ?? !1, n = r?.force ?? !1;
|
|
921
938
|
if (e === "/")
|
|
922
939
|
throw new c("Cannot remove root directory", "EROOT");
|
|
923
|
-
const i =
|
|
940
|
+
const i = b(e);
|
|
924
941
|
if (!i)
|
|
925
|
-
throw new
|
|
926
|
-
const o = await this.getDirectoryHandle(
|
|
942
|
+
throw new v("Invalid path", e);
|
|
943
|
+
const o = await this.getDirectoryHandle(M(e), !1);
|
|
927
944
|
try {
|
|
928
945
|
await o.removeEntry(i, { recursive: a });
|
|
929
946
|
} catch (s) {
|
|
@@ -932,6 +949,7 @@ class we {
|
|
|
932
949
|
throw new c(\`No such file or directory: \${e}\`, "ENOENT");
|
|
933
950
|
} else throw s.name === "InvalidModificationError" ? new c(\`Directory not empty: \${e}. Use recursive option to force removal.\`, "ENOTEMPTY") : s.name === "TypeMismatchError" && !a ? new c(\`Cannot remove directory without recursive option: \${e}\`, "EISDIR") : new c(\`Failed to remove path: \${e}\`, "RM_FAILED");
|
|
934
951
|
}
|
|
952
|
+
this.notifyInternalChange(e, "delete");
|
|
935
953
|
}
|
|
936
954
|
/**
|
|
937
955
|
* Resolve a path to an absolute path
|
|
@@ -956,7 +974,7 @@ class we {
|
|
|
956
974
|
try {
|
|
957
975
|
const r = ce(e);
|
|
958
976
|
if (!await this.exists(r))
|
|
959
|
-
throw new
|
|
977
|
+
throw new D(r);
|
|
960
978
|
return r;
|
|
961
979
|
} catch (r) {
|
|
962
980
|
throw r instanceof c ? r : new c(\`Failed to resolve path: \${e}\`, "REALPATH_FAILED");
|
|
@@ -982,8 +1000,8 @@ class we {
|
|
|
982
1000
|
await this.ensureMounted();
|
|
983
1001
|
try {
|
|
984
1002
|
if (!await this.exists(e))
|
|
985
|
-
throw new
|
|
986
|
-
await this.copy(e, r, { recursive: !0 }), await this.remove(e, { recursive: !0 });
|
|
1003
|
+
throw new D(e);
|
|
1004
|
+
await this.copy(e, r, { recursive: !0 }), await this.remove(e, { recursive: !0 }), this.notifyInternalChange(e, "delete"), this.notifyInternalChange(r, "create");
|
|
987
1005
|
} catch (a) {
|
|
988
1006
|
throw a instanceof c ? a : new c(\`Failed to rename from \${e} to \${r}\`, "RENAME_FAILED");
|
|
989
1007
|
}
|
|
@@ -1034,6 +1052,7 @@ class we {
|
|
|
1034
1052
|
await this.copy(w, h, { recursive: !0, force: i });
|
|
1035
1053
|
}
|
|
1036
1054
|
}
|
|
1055
|
+
this.notifyInternalChange(r, "create");
|
|
1037
1056
|
} catch (n) {
|
|
1038
1057
|
throw n instanceof c ? n : new c(\`Failed to copy from \${e} to \${r}\`, "CP_FAILED");
|
|
1039
1058
|
}
|
|
@@ -1043,7 +1062,7 @@ class we {
|
|
|
1043
1062
|
*/
|
|
1044
1063
|
async watch(e) {
|
|
1045
1064
|
await this.ensureMounted();
|
|
1046
|
-
const r =
|
|
1065
|
+
const r = C(e), a = await this.buildSnapshot(r);
|
|
1047
1066
|
this.watchers.set(r, a), this.watchTimer || (this.watchTimer = setInterval(() => {
|
|
1048
1067
|
this.scanWatches();
|
|
1049
1068
|
}, this.watchInterval));
|
|
@@ -1052,7 +1071,7 @@ class we {
|
|
|
1052
1071
|
* Stop watching a previously watched path
|
|
1053
1072
|
*/
|
|
1054
1073
|
unwatch(e) {
|
|
1055
|
-
const r =
|
|
1074
|
+
const r = C(e);
|
|
1056
1075
|
this.watchers.delete(r), this.watchers.size === 0 && this.watchTimer && (clearInterval(this.watchTimer), this.watchTimer = null);
|
|
1057
1076
|
}
|
|
1058
1077
|
async buildSnapshot(e) {
|
|
@@ -1131,46 +1150,47 @@ class we {
|
|
|
1131
1150
|
try {
|
|
1132
1151
|
(r?.cleanBefore ?? !1) && await this.clear("/");
|
|
1133
1152
|
for (const [n, i] of e) {
|
|
1134
|
-
const o =
|
|
1153
|
+
const o = C(n);
|
|
1135
1154
|
let s;
|
|
1136
1155
|
i instanceof Blob ? s = await he(i) : s = i, await this.writeFile(o, s);
|
|
1137
1156
|
}
|
|
1157
|
+
this.notifyInternalChange("/", "change");
|
|
1138
1158
|
} catch (a) {
|
|
1139
1159
|
throw a instanceof c ? a : new c("Failed to sync file system", "SYNC_FAILED");
|
|
1140
1160
|
}
|
|
1141
1161
|
}
|
|
1142
1162
|
}
|
|
1143
|
-
typeof self < "u" && self.constructor.name === "DedicatedWorkerGlobalScope" &&
|
|
1144
|
-
//# sourceMappingURL=worker-
|
|
1163
|
+
typeof self < "u" && self.constructor.name === "DedicatedWorkerGlobalScope" && O(new we());
|
|
1164
|
+
//# sourceMappingURL=worker-DCm4BiWM.js.map
|
|
1145
1165
|
`, r = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", a], { type: "text/javascript;charset=utf-8" });
|
|
1146
|
-
function s(
|
|
1166
|
+
function s(t) {
|
|
1147
1167
|
let n;
|
|
1148
1168
|
try {
|
|
1149
1169
|
if (n = r && (self.URL || self.webkitURL).createObjectURL(r), !n) throw "";
|
|
1150
|
-
const
|
|
1170
|
+
const e = new Worker(n, {
|
|
1151
1171
|
type: "module",
|
|
1152
|
-
name:
|
|
1172
|
+
name: t?.name
|
|
1153
1173
|
});
|
|
1154
|
-
return
|
|
1174
|
+
return e.addEventListener("error", () => {
|
|
1155
1175
|
(self.URL || self.webkitURL).revokeObjectURL(n);
|
|
1156
|
-
}),
|
|
1176
|
+
}), e;
|
|
1157
1177
|
} catch {
|
|
1158
1178
|
return new Worker(
|
|
1159
1179
|
"data:text/javascript;charset=utf-8," + encodeURIComponent(a),
|
|
1160
1180
|
{
|
|
1161
1181
|
type: "module",
|
|
1162
|
-
name:
|
|
1182
|
+
name: t?.name
|
|
1163
1183
|
}
|
|
1164
1184
|
);
|
|
1165
1185
|
}
|
|
1166
1186
|
}
|
|
1167
|
-
function l(
|
|
1168
|
-
const
|
|
1169
|
-
return
|
|
1187
|
+
function l(t, n) {
|
|
1188
|
+
const e = i(new s());
|
|
1189
|
+
return t && e.setWatchCallback(o(t), n), e;
|
|
1170
1190
|
}
|
|
1171
1191
|
export {
|
|
1172
|
-
|
|
1173
|
-
|
|
1192
|
+
d as DirectoryNotFoundError,
|
|
1193
|
+
u as FileNotFoundError,
|
|
1174
1194
|
p as OPFSError,
|
|
1175
1195
|
w as OPFSNotMountedError,
|
|
1176
1196
|
y as OPFSNotSupportedError,
|
|
@@ -1184,15 +1204,15 @@ export {
|
|
|
1184
1204
|
P as convertBlobToUint8Array,
|
|
1185
1205
|
x as createBuffer,
|
|
1186
1206
|
l as createWorker,
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1207
|
+
T as decodeBuffer,
|
|
1208
|
+
I as dirname,
|
|
1209
|
+
A as encodeString,
|
|
1210
|
+
O as extname,
|
|
1191
1211
|
_ as joinPath,
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1212
|
+
C as normalizePath,
|
|
1213
|
+
D as readFileData,
|
|
1214
|
+
k as resolvePath,
|
|
1195
1215
|
U as splitPath,
|
|
1196
|
-
|
|
1216
|
+
R as writeFileData
|
|
1197
1217
|
};
|
|
1198
1218
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { wrap, proxy } from 'comlink';\n\nimport WorkerCtor from './worker?worker&inline';\n\nimport type { OPFSWorker, RemoteOPFSWorker, WatchEvent } 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 watchOptions - Optional configuration for watching\n * @returns Promise resolving to the file system interface\n */\nexport function createWorker(\n watchCallback?: (event: WatchEvent) => void,\n watchOptions?: { watchInterval?: number }\n): RemoteOPFSWorker {\n const wrapped = wrap<OPFSWorker>(new WorkerCtor());\n \n // Set up watch callback if provided\n if (watchCallback) {\n wrapped.setWatchCallback(proxy(watchCallback), watchOptions);\n }\n \n return wrapped;\n}\n"],"names":["createWorker","watchCallback","watchOptions","wrapped","wrap","WorkerCtor","proxy"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { wrap, proxy } from 'comlink';\n\nimport WorkerCtor from './worker?worker&inline';\n\nimport type { OPFSWorker, RemoteOPFSWorker, WatchEvent } 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 watchOptions - Optional configuration for watching\n * @returns Promise resolving to the file system interface\n */\nexport function createWorker(\n watchCallback?: (event: WatchEvent) => void,\n watchOptions?: { watchInterval?: number }\n): RemoteOPFSWorker {\n const wrapped = wrap<OPFSWorker>(new WorkerCtor());\n \n // Set up watch callback if provided\n if (watchCallback) {\n wrapped.setWatchCallback(proxy(watchCallback), watchOptions);\n }\n \n return wrapped;\n}\n"],"names":["createWorker","watchCallback","watchOptions","wrapped","wrap","WorkerCtor","proxy"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBO,SAASA,EACZC,GACAC,GACgB;AAChB,QAAMC,IAAUC,EAAiB,IAAIC,GAAY;AAGjD,SAAIJ,KACAE,EAAQ,iBAAiBG,EAAML,CAAa,GAAGC,CAAY,GAGxDC;AACX;"}
|
package/dist/raw.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("comlink"),a=require("./helpers-hEpet7x7.cjs");class
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("comlink"),a=require("./helpers-hEpet7x7.cjs");class f{root=null;watchCallback=null;watchers=new Map;watchTimer=null;watchInterval=1e3;scanning=!1;mountingPromise=null;notifyInternalChange(t,e){this.watchCallback&&this.watchCallback({path:t,type:e})}constructor(t,e){a.checkOPFSSupport(),t&&(this.watchCallback=t,e?.watchInterval&&(this.watchInterval=e.watchInterval)),this.mount("/")}async mount(t="/"){return this.mountingPromise&&await this.mountingPromise,this.mountingPromise=new Promise(async(e,i)=>{this.root=null;try{const r=await navigator.storage.getDirectory();t==="/"?this.root=r:this.root=await this.getDirectoryHandle(t,!0,r),e(!0)}catch(r){console.error(r),i(new a.OPFSError("Failed to initialize OPFS","INIT_FAILED"))}finally{this.mountingPromise=null}}),this.mountingPromise}setWatchCallback(t,e){this.watchCallback=t,e?.watchInterval&&(this.watchInterval=e.watchInterval)}async ensureMounted(){if(!this.root){if(this.mountingPromise){await this.mountingPromise;return}throw new a.OPFSError("OPFS not mounted","NOT_MOUNTED")}}async getDirectoryHandle(t,e=!1,i=this.root){if(!i)throw new a.OPFSNotMountedError;const r=Array.isArray(t)?t:a.splitPath(t);let n=i;for(const o of r)n=await n.getDirectoryHandle(o,{create:e});return n}async getFileHandle(t,e=!1,i=this.root){if(!i)throw new a.OPFSNotMountedError;const r=a.splitPath(t);if(r.length===0)throw new a.PathError("Path must not be empty",Array.isArray(t)?t.join("/"):t);const n=r.pop();return(await this.getDirectoryHandle(r,e,i)).getFileHandle(n,{create:e})}async index(t){const e=new Map,i=async r=>{const n=await this.readdir(r,{withFileTypes:!0});for(const o of n){const s=`${r==="/"?"":r}/${o.name}`;try{const c=await this.stat(s,t);e.set(s,c),c.isDirectory&&await i(s)}catch(c){console.warn(`Skipping broken entry: ${s}`,c)}}};return e.set("/",{kind:"directory",size:0,mtime:new Date(0).toISOString(),ctime:new Date(0).toISOString(),isFile:!1,isDirectory:!0}),await i("/"),e}async readFile(t,e="utf-8"){await this.ensureMounted();try{const i=await this.getFileHandle(t,!1),r=await a.readFileData(i);return e==="binary"?r:a.decodeBuffer(r,e)}catch(i){throw console.error(i),new a.FileNotFoundError(t)}}async writeFile(t,e,i){await this.ensureMounted();const r=await this.getFileHandle(t,!0);await a.writeFileData(r,e,i,{truncate:!0}),this.notifyInternalChange(t,"change")}async appendFile(t,e,i){await this.ensureMounted();const r=await this.getFileHandle(t,!0);await a.writeFileData(r,e,i,{append:!0}),this.notifyInternalChange(t,"change")}async mkdir(t,e){if(await this.ensureMounted(),!this.root)throw new a.OPFSNotMountedError;const i=e?.recursive??!1,r=a.splitPath(t);let n=this.root;for(let o=0;o<r.length;o++){const s=r[o];try{n=await n.getDirectoryHandle(s,{create:i||o===r.length-1})}catch(c){throw c.name==="NotFoundError"?new a.OPFSError(`Parent directory does not exist: ${a.joinPath(r.slice(0,o+1))}`,"ENOENT"):c.name==="TypeMismatchError"?new a.OPFSError(`Path segment is not a directory: ${s}`,"ENOTDIR"):new a.OPFSError("Failed to create directory","MKDIR_FAILED")}}this.notifyInternalChange(t,"create")}async stat(t,e){if(await this.ensureMounted(),t==="/")return{kind:"directory",size:0,mtime:new Date(0).toISOString(),ctime:new Date(0).toISOString(),isFile:!1,isDirectory:!0};const i=a.basename(t),r=await this.getDirectoryHandle(a.dirname(t),!1),n=e?.includeHash??!1,o=e?.hashAlgorithm??"SHA-1";try{const c=await(await r.getFileHandle(i,{create:!1})).getFile(),l={kind:"file",size:c.size,mtime:new Date(c.lastModified).toISOString(),ctime:new Date(c.lastModified).toISOString(),isFile:!0,isDirectory:!1};if(n)try{const h=new Uint8Array(await c.arrayBuffer()),w=await a.calculateFileHash(h,o);l.hash=w}catch(h){console.warn(`Failed to calculate hash for ${t}:`,h)}return l}catch(s){if(s.name!=="TypeMismatchError"&&s.name!=="NotFoundError")throw new a.OPFSError("Failed to stat (file)","STAT_FAILED")}try{return await r.getDirectoryHandle(i,{create:!1}),{kind:"directory",size:0,mtime:new Date(0).toISOString(),ctime:new Date(0).toISOString(),isFile:!1,isDirectory:!0}}catch(s){throw s.name==="NotFoundError"?new a.OPFSError(`No such file or directory: ${t}`,"ENOENT"):new a.OPFSError("Failed to stat (directory)","STAT_FAILED")}}async readdir(t,e){await this.ensureMounted();const i=e?.withFileTypes??!1,r=await this.getDirectoryHandle(t,!1);if(i){const n=[];for await(const[o,s]of r.entries()){const c=s.kind==="file";n.push({name:o,kind:s.kind,isFile:c,isDirectory:!c})}return n}else{const n=[];for await(const[o]of r.entries())n.push(o);return n}}async exists(t){if(await this.ensureMounted(),t==="/")return!0;const e=a.basename(t);let i=null;try{i=await this.getDirectoryHandle(a.dirname(t),!1)}catch(r){throw(r.name==="NotFoundError"||r.name==="TypeMismatchError")&&(i=null),r}if(!i||!e)return!1;try{return await i.getFileHandle(e,{create:!1}),!0}catch(r){if(r.name!=="NotFoundError"&&r.name!=="TypeMismatchError")throw r}try{return await i.getDirectoryHandle(e,{create:!1}),!0}catch(r){if(r.name!=="NotFoundError"&&r.name!=="TypeMismatchError")throw r}return!1}async clear(t="/"){await this.ensureMounted();try{const e=await this.readdir(t,{withFileTypes:!0});for(const i of e){const r=`${t==="/"?"":t}/${i.name}`;await this.remove(r,{recursive:!0})}this.notifyInternalChange(t,"change")}catch(e){throw e instanceof a.OPFSError?e:new a.OPFSError(`Failed to clear directory: ${t}`,"CLEAR_FAILED")}}async remove(t,e){await this.ensureMounted();const i=e?.recursive??!1,r=e?.force??!1;if(t==="/")throw new a.OPFSError("Cannot remove root directory","EROOT");const n=a.basename(t);if(!n)throw new a.PathError("Invalid path",t);const o=await this.getDirectoryHandle(a.dirname(t),!1);try{await o.removeEntry(n,{recursive:i})}catch(s){if(s.name==="NotFoundError"){if(!r)throw new a.OPFSError(`No such file or directory: ${t}`,"ENOENT")}else throw s.name==="InvalidModificationError"?new a.OPFSError(`Directory not empty: ${t}. Use recursive option to force removal.`,"ENOTEMPTY"):s.name==="TypeMismatchError"&&!i?new a.OPFSError(`Cannot remove directory without recursive option: ${t}`,"EISDIR"):new a.OPFSError(`Failed to remove path: ${t}`,"RM_FAILED")}this.notifyInternalChange(t,"delete")}async realpath(t){await this.ensureMounted();try{const e=a.resolvePath(t);if(!await this.exists(e))throw new a.FileNotFoundError(e);return e}catch(e){throw e instanceof a.OPFSError?e:new a.OPFSError(`Failed to resolve path: ${t}`,"REALPATH_FAILED")}}async rename(t,e){await this.ensureMounted();try{if(!await this.exists(t))throw new a.FileNotFoundError(t);await this.copy(t,e,{recursive:!0}),await this.remove(t,{recursive:!0}),this.notifyInternalChange(t,"delete"),this.notifyInternalChange(e,"create")}catch(i){throw i instanceof a.OPFSError?i:new a.OPFSError(`Failed to rename from ${t} to ${e}`,"RENAME_FAILED")}}async copy(t,e,i){await this.ensureMounted();try{const r=i?.recursive??!1,n=i?.force??!0;if(!await this.exists(t))throw new a.OPFSError(`Source does not exist: ${t}`,"ENOENT");if(await this.exists(e)&&!n)throw new a.OPFSError(`Destination already exists: ${e}`,"EEXIST");if((await this.stat(t)).isFile){const l=await this.readFile(t,"binary");await this.writeFile(e,l)}else{if(!r)throw new a.OPFSError(`Cannot copy directory without recursive option: ${t}`,"EISDIR");await this.mkdir(e,{recursive:!0});const l=await this.readdir(t,{withFileTypes:!0});for(const h of l){const w=`${t}/${h.name}`,u=`${e}/${h.name}`;await this.copy(w,u,{recursive:!0,force:n})}}this.notifyInternalChange(e,"create")}catch(r){throw r instanceof a.OPFSError?r:new a.OPFSError(`Failed to copy from ${t} to ${e}`,"CP_FAILED")}}async watch(t){await this.ensureMounted();const e=a.normalizePath(t),i=await this.buildSnapshot(e);this.watchers.set(e,i),this.watchTimer||(this.watchTimer=setInterval(()=>{this.scanWatches()},this.watchInterval))}unwatch(t){const e=a.normalizePath(t);this.watchers.delete(e),this.watchers.size===0&&this.watchTimer&&(clearInterval(this.watchTimer),this.watchTimer=null)}async buildSnapshot(t){const e=new Map,i=async r=>{const n=await this.stat(r);if(e.set(r,n),n.isDirectory){const o=await this.readdir(r,{withFileTypes:!0});for(const s of o){const c=`${r==="/"?"":r}/${s.name}`;await i(c)}}};return await i(t),e}async scanWatches(){if(!this.scanning){this.scanning=!0;try{await Promise.all([...this.watchers.entries()].map(async([t,e])=>{let i;try{i=await this.buildSnapshot(t)}catch{i=new Map}const r=[];for(const[n,o]of i){const s=e.get(n);s?(s.mtime!==o.mtime||s.size!==o.size)&&r.push({path:n,type:"change"}):r.push({path:n,type:"create"})}for(const n of e.keys())i.has(n)||r.push({path:n,type:"delete"});if(r.length&&this.watchCallback)for(const n of r)this.watchCallback(n);this.watchers.set(t,i)}))}finally{this.scanning=!1}}}async sync(t,e){await this.ensureMounted();try{(e?.cleanBefore??!1)&&await this.clear("/");for(const[r,n]of t){const o=a.normalizePath(r);let s;n instanceof Blob?s=await a.convertBlobToUint8Array(n):s=n,await this.writeFile(o,s)}this.notifyInternalChange("/","change")}catch(i){throw i instanceof a.OPFSError?i:new a.OPFSError("Failed to sync file system","SYNC_FAILED")}}}typeof self<"u"&&self.constructor.name==="DedicatedWorkerGlobalScope"&&d.expose(new f);exports.OPFSWorker=f;
|
|
2
2
|
//# sourceMappingURL=raw.cjs.map
|