opfs-worker 0.5.1 → 1.0.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/assets/worker-XHCzp1qX.js.map +1 -0
- package/dist/{helpers-DcIl7KL0.js → helpers-CTCvNFs1.js} +42 -42
- package/dist/{helpers-DcIl7KL0.js.map → helpers-CTCvNFs1.js.map} +1 -1
- package/dist/{helpers-BfBe8lFJ.cjs → helpers-Cvjm0f_r.cjs} +3 -3
- package/dist/{helpers-BfBe8lFJ.cjs.map → helpers-Cvjm0f_r.cjs.map} +1 -1
- package/dist/index.cjs +93 -83
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +97 -87
- package/dist/index.js.map +1 -1
- package/dist/raw.cjs +1 -1
- package/dist/raw.cjs.map +1 -1
- package/dist/raw.js +97 -87
- package/dist/raw.js.map +1 -1
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/encoder.d.ts +2 -1
- package/dist/utils/encoder.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts +2 -1
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/worker.d.ts +14 -7
- package/dist/worker.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/assets/worker-DYhMhDRt.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { wrap as i } from "comlink";
|
|
2
|
-
import { B as p, D as f, F as d, O as u, b as g, a as m, P as w, c as y, S as b, T as v, e as x, t as S, q as E, d as
|
|
2
|
+
import { B as p, D as f, F as d, O as u, b as g, a as m, P as w, c as y, S as b, T as v, e as x, t as S, q as E, d as P, u as A, l as F, y as O, f as C, x as T, k as R, i as $, h as _, j as D, m as I, g as j, n as N, o as M, v as k, r as L, s as z, w as W, p as U } from "./helpers-CTCvNFs1.js";
|
|
3
3
|
const r = `/**
|
|
4
4
|
* @license
|
|
5
5
|
* Copyright 2019 Google LLC
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
|
-
const ut = Symbol("Comlink.proxy"), Dt = Symbol("Comlink.endpoint"), Nt = Symbol("Comlink.releaseProxy"), U = Symbol("Comlink.finalizer"), L = Symbol("Comlink.thrown"), ft = (s) => typeof s == "object" && s !== null || typeof s == "function",
|
|
8
|
+
const ut = Symbol("Comlink.proxy"), Dt = Symbol("Comlink.endpoint"), Nt = Symbol("Comlink.releaseProxy"), U = Symbol("Comlink.finalizer"), L = Symbol("Comlink.thrown"), ft = (s) => typeof s == "object" && s !== null || typeof s == "function", Tt = {
|
|
9
9
|
canHandle: (s) => ft(s) && s[ut],
|
|
10
10
|
serialize(s) {
|
|
11
11
|
const { port1: t, port2: e } = new MessageChannel();
|
|
@@ -14,7 +14,7 @@ const ut = Symbol("Comlink.proxy"), Dt = Symbol("Comlink.endpoint"), Nt = Symbol
|
|
|
14
14
|
deserialize(s) {
|
|
15
15
|
return s.start(), Pt(s);
|
|
16
16
|
}
|
|
17
|
-
},
|
|
17
|
+
}, Ft = {
|
|
18
18
|
canHandle: (s) => ft(s) && L in s,
|
|
19
19
|
serialize({ value: s }) {
|
|
20
20
|
let t;
|
|
@@ -31,8 +31,8 @@ const ut = Symbol("Comlink.proxy"), Dt = Symbol("Comlink.endpoint"), Nt = Symbol
|
|
|
31
31
|
throw s.isError ? Object.assign(new Error(s.value.message), s.value) : s.value;
|
|
32
32
|
}
|
|
33
33
|
}, dt = /* @__PURE__ */ new Map([
|
|
34
|
-
["proxy",
|
|
35
|
-
["throw",
|
|
34
|
+
["proxy", Tt],
|
|
35
|
+
["throw", Ft]
|
|
36
36
|
]);
|
|
37
37
|
function Mt(s, t) {
|
|
38
38
|
for (const e of s)
|
|
@@ -298,13 +298,12 @@ function _t(s, t = "utf-8") {
|
|
|
298
298
|
case "utf-8":
|
|
299
299
|
return new TextDecoder().decode(s);
|
|
300
300
|
case "utf16le":
|
|
301
|
+
case "utf-16le":
|
|
301
302
|
case "ucs2":
|
|
302
303
|
case "ucs-2":
|
|
303
304
|
return Gt(s);
|
|
304
305
|
case "latin1":
|
|
305
306
|
return String.fromCharCode(...s);
|
|
306
|
-
case "binary":
|
|
307
|
-
return String.fromCharCode(...s);
|
|
308
307
|
case "ascii":
|
|
309
308
|
return String.fromCharCode(...s.map((e) => e & 127));
|
|
310
309
|
case "base64":
|
|
@@ -370,17 +369,17 @@ const wt = (s, t, e) => {
|
|
|
370
369
|
n.length && o !== void 0 && (a = [r, o]);
|
|
371
370
|
}
|
|
372
371
|
return a;
|
|
373
|
-
}, yt = "\\0SLASH" + Math.random() + "\\0", Et = "\\0OPEN" + Math.random() + "\\0", K = "\\0CLOSE" + Math.random() + "\\0", St = "\\0COMMA" + Math.random() + "\\0",
|
|
372
|
+
}, yt = "\\0SLASH" + Math.random() + "\\0", Et = "\\0OPEN" + Math.random() + "\\0", K = "\\0CLOSE" + Math.random() + "\\0", St = "\\0COMMA" + Math.random() + "\\0", xt = "\\0PERIOD" + Math.random() + "\\0", Yt = new RegExp(yt, "g"), Zt = new RegExp(Et, "g"), Jt = new RegExp(K, "g"), Kt = new RegExp(St, "g"), Qt = new RegExp(xt, "g"), te = /\\\\\\\\/g, ee = /\\\\{/g, se = /\\\\}/g, ne = /\\\\,/g, ie = /\\\\./g;
|
|
374
373
|
function B(s) {
|
|
375
374
|
return isNaN(s) ? s.charCodeAt(0) : parseInt(s, 10);
|
|
376
375
|
}
|
|
377
376
|
function re(s) {
|
|
378
|
-
return s.replace(te, yt).replace(ee, Et).replace(se, K).replace(ne, St).replace(ie,
|
|
377
|
+
return s.replace(te, yt).replace(ee, Et).replace(se, K).replace(ne, St).replace(ie, xt);
|
|
379
378
|
}
|
|
380
379
|
function oe(s) {
|
|
381
380
|
return s.replace(Yt, "\\\\").replace(Zt, "{").replace(Jt, "}").replace(Kt, ",").replace(Qt, ".");
|
|
382
381
|
}
|
|
383
|
-
function
|
|
382
|
+
function bt(s) {
|
|
384
383
|
if (!s)
|
|
385
384
|
return [""];
|
|
386
385
|
const t = [], e = wt("{", "}", s);
|
|
@@ -388,7 +387,7 @@ function xt(s) {
|
|
|
388
387
|
return s.split(",");
|
|
389
388
|
const { pre: n, body: i, post: r } = e, o = n.split(",");
|
|
390
389
|
o[o.length - 1] += "{" + i + "}";
|
|
391
|
-
const a =
|
|
390
|
+
const a = bt(r);
|
|
392
391
|
return r.length && (o[o.length - 1] += a.shift(), o.push.apply(o, a)), t.push.apply(t, o), t;
|
|
393
392
|
}
|
|
394
393
|
function ae(s) {
|
|
@@ -423,7 +422,7 @@ function M(s, t) {
|
|
|
423
422
|
let c;
|
|
424
423
|
if (l)
|
|
425
424
|
c = n.body.split(/\\.\\./);
|
|
426
|
-
else if (c =
|
|
425
|
+
else if (c = bt(n.body), c.length === 1 && c[0] !== void 0 && (c = M(c[0], !1).map(ce), c.length === 1))
|
|
427
426
|
return r.map((u) => n.pre + c[0] + u);
|
|
428
427
|
let f;
|
|
429
428
|
if (l && c[0] !== void 0 && c[1] !== void 0) {
|
|
@@ -432,15 +431,15 @@ function M(s, t) {
|
|
|
432
431
|
d < u && (p *= -1, S = ue);
|
|
433
432
|
const N = c.some(le);
|
|
434
433
|
f = [];
|
|
435
|
-
for (let
|
|
434
|
+
for (let x = u; S(x, d); x += p) {
|
|
436
435
|
let w;
|
|
437
436
|
if (a)
|
|
438
|
-
w = String.fromCharCode(
|
|
439
|
-
else if (w = String(
|
|
440
|
-
const
|
|
441
|
-
if (
|
|
442
|
-
const P = new Array(
|
|
443
|
-
|
|
437
|
+
w = String.fromCharCode(x), w === "\\\\" && (w = "");
|
|
438
|
+
else if (w = String(x), N) {
|
|
439
|
+
const T = m - w.length;
|
|
440
|
+
if (T > 0) {
|
|
441
|
+
const P = new Array(T + 1).join("0");
|
|
442
|
+
x < 0 ? w = "-" + P + w.slice(1) : w = P + w;
|
|
444
443
|
}
|
|
445
444
|
}
|
|
446
445
|
f.push(w);
|
|
@@ -478,7 +477,7 @@ const fe = 1024 * 64, W = (s) => {
|
|
|
478
477
|
"[:upper:]": ["\\\\p{Lu}", !0],
|
|
479
478
|
"[:word:]": ["\\\\p{L}\\\\p{Nl}\\\\p{Nd}\\\\p{Pc}", !0],
|
|
480
479
|
"[:xdigit:]": ["A-Fa-f0-9", !1]
|
|
481
|
-
},
|
|
480
|
+
}, F = (s) => s.replace(/[[\\]\\\\-]/g, "\\\\$&"), pe = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&"), it = (s) => s.join(""), ge = (s, t) => {
|
|
482
481
|
const e = t;
|
|
483
482
|
if (s.charAt(e) !== "[")
|
|
484
483
|
throw new Error("not in a brace expression");
|
|
@@ -499,27 +498,27 @@ const fe = 1024 * 64, W = (s) => {
|
|
|
499
498
|
continue;
|
|
500
499
|
}
|
|
501
500
|
if (p === "[" && !l) {
|
|
502
|
-
for (const [S, [
|
|
501
|
+
for (const [S, [A, N, x]] of Object.entries(de))
|
|
503
502
|
if (s.startsWith(S, r)) {
|
|
504
503
|
if (f)
|
|
505
504
|
return ["$.", !1, s.length - e, !0];
|
|
506
|
-
r += S.length,
|
|
505
|
+
r += S.length, x ? i.push(A) : n.push(A), a = a || N;
|
|
507
506
|
continue t;
|
|
508
507
|
}
|
|
509
508
|
}
|
|
510
509
|
if (l = !1, f) {
|
|
511
|
-
p > f ? n.push(
|
|
510
|
+
p > f ? n.push(F(f) + "-" + F(p)) : p === f && n.push(F(p)), f = "", r++;
|
|
512
511
|
continue;
|
|
513
512
|
}
|
|
514
513
|
if (s.startsWith("-]", r + 1)) {
|
|
515
|
-
n.push(
|
|
514
|
+
n.push(F(p + "-")), r += 2;
|
|
516
515
|
continue;
|
|
517
516
|
}
|
|
518
517
|
if (s.startsWith("-", r + 1)) {
|
|
519
518
|
f = p, r += 2;
|
|
520
519
|
continue;
|
|
521
520
|
}
|
|
522
|
-
n.push(
|
|
521
|
+
n.push(F(p)), r++;
|
|
523
522
|
}
|
|
524
523
|
if (c < r)
|
|
525
524
|
return ["", !1, 0, !1];
|
|
@@ -531,7 +530,7 @@ const fe = 1024 * 64, W = (s) => {
|
|
|
531
530
|
}
|
|
532
531
|
const u = "[" + (h ? "^" : "") + it(n) + "]", d = "[" + (h ? "" : "^") + it(i) + "]";
|
|
533
532
|
return [n.length && i.length ? "(" + u + "|" + d + ")" : n.length ? u : d, a, c - e, !0];
|
|
534
|
-
}, $ = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/\\[([^\\/\\\\])\\]/g, "$1") : s.replace(/((?!\\\\).|^)\\[([^\\/\\\\])\\]/g, "$1$2").replace(/\\\\([^\\/])/g, "$1"), me = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]), rt = (s) => me.has(s), we = "(?!(?:^|/)\\\\.\\\\.?(?:$|/))", k = "(?!\\\\.)", ye = /* @__PURE__ */ new Set(["[", "."]), Ee = /* @__PURE__ */ new Set(["..", "."]), Se = new Set("().*{}+?[]^$\\\\!"),
|
|
533
|
+
}, $ = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/\\[([^\\/\\\\])\\]/g, "$1") : s.replace(/((?!\\\\).|^)\\[([^\\/\\\\])\\]/g, "$1$2").replace(/\\\\([^\\/])/g, "$1"), me = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]), rt = (s) => me.has(s), we = "(?!(?:^|/)\\\\.\\\\.?(?:$|/))", k = "(?!\\\\.)", ye = /* @__PURE__ */ new Set(["[", "."]), Ee = /* @__PURE__ */ new Set(["..", "."]), Se = new Set("().*{}+?[]^$\\\\!"), xe = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&"), Q = "[^/]", ot = Q + "*?", at = Q + "+?";
|
|
535
534
|
class E {
|
|
536
535
|
type;
|
|
537
536
|
#s;
|
|
@@ -784,8 +783,8 @@ class E {
|
|
|
784
783
|
const e = t ?? !!this.#i.dot;
|
|
785
784
|
if (this.#s === this && this.#d(), !this.type) {
|
|
786
785
|
const l = this.isStart() && this.isEnd(), h = this.#t.map((d) => {
|
|
787
|
-
const [m, p, S,
|
|
788
|
-
return this.#n = this.#n || S, this.#r = this.#r ||
|
|
786
|
+
const [m, p, S, A] = typeof d == "string" ? E.#p(d, this.#n, l) : d.toRegExpSource(t);
|
|
787
|
+
return this.#n = this.#n || S, this.#r = this.#r || A, m;
|
|
789
788
|
}).join("");
|
|
790
789
|
let c = "";
|
|
791
790
|
if (this.isStart() && typeof this.#t[0] == "string" && !(this.#t.length === 1 && Ee.has(this.#t[0]))) {
|
|
@@ -865,27 +864,27 @@ class E {
|
|
|
865
864
|
r += Q, e = !0;
|
|
866
865
|
continue;
|
|
867
866
|
}
|
|
868
|
-
r +=
|
|
867
|
+
r += xe(l);
|
|
869
868
|
}
|
|
870
869
|
return [r, $(t), !!e, o];
|
|
871
870
|
}
|
|
872
871
|
}
|
|
873
|
-
const
|
|
874
|
-
const e =
|
|
872
|
+
const be = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/[?*()[\\]]/g, "[$&]") : s.replace(/[?*()[\\]\\\\]/g, "\\\\$&"), y = (s, t, e = {}) => (W(t), !e.nocomment && t.charAt(0) === "#" ? !1 : new j(t, e).match(s)), ve = /^\\*+([^+@!?\\*\\[\\(]*)$/, Ae = (s) => (t) => !t.startsWith(".") && t.endsWith(s), Ce = (s) => (t) => t.endsWith(s), Oe = (s) => (s = s.toLowerCase(), (t) => !t.startsWith(".") && t.toLowerCase().endsWith(s)), De = (s) => (s = s.toLowerCase(), (t) => t.toLowerCase().endsWith(s)), Ne = /^\\*+\\.\\*+$/, Te = (s) => !s.startsWith(".") && s.includes("."), Fe = (s) => s !== "." && s !== ".." && s.includes("."), Me = /^\\.\\*+$/, $e = (s) => s !== "." && s !== ".." && s.startsWith("."), Pe = /^\\*+$/, Re = (s) => s.length !== 0 && !s.startsWith("."), ke = (s) => s.length !== 0 && s !== "." && s !== "..", Le = /^\\?+([^+@!?\\*\\[\\(]*)?$/, Ie = ([s, t = ""]) => {
|
|
873
|
+
const e = vt([s]);
|
|
875
874
|
return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
|
|
876
875
|
}, ze = ([s, t = ""]) => {
|
|
877
|
-
const e =
|
|
876
|
+
const e = At([s]);
|
|
878
877
|
return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
|
|
879
878
|
}, He = ([s, t = ""]) => {
|
|
880
|
-
const e =
|
|
879
|
+
const e = At([s]);
|
|
881
880
|
return t ? (n) => e(n) && n.endsWith(t) : e;
|
|
882
881
|
}, We = ([s, t = ""]) => {
|
|
883
|
-
const e =
|
|
882
|
+
const e = vt([s]);
|
|
884
883
|
return t ? (n) => e(n) && n.endsWith(t) : e;
|
|
885
|
-
},
|
|
884
|
+
}, vt = ([s]) => {
|
|
886
885
|
const t = s.length;
|
|
887
886
|
return (e) => e.length === t && !e.startsWith(".");
|
|
888
|
-
},
|
|
887
|
+
}, At = ([s]) => {
|
|
889
888
|
const t = s.length;
|
|
890
889
|
return (e) => e.length === t && e !== "." && e !== "..";
|
|
891
890
|
}, Ct = typeof process == "object" && process ? typeof process.env == "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix", ct = {
|
|
@@ -893,42 +892,42 @@ const xe = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/[?*()[\\
|
|
|
893
892
|
posix: { sep: "/" }
|
|
894
893
|
}, je = Ct === "win32" ? ct.win32.sep : ct.posix.sep;
|
|
895
894
|
y.sep = je;
|
|
896
|
-
const
|
|
897
|
-
y.GLOBSTAR =
|
|
895
|
+
const v = Symbol("globstar **");
|
|
896
|
+
y.GLOBSTAR = v;
|
|
898
897
|
const Ue = "[^/]", _e = Ue + "*?", Be = "(?:(?!(?:\\\\/|^)(?:\\\\.{1,2})($|\\\\/)).)*?", Ge = "(?:(?!(?:\\\\/|^)\\\\.).)*?", qe = (s, t = {}) => (e) => y(e, s, t);
|
|
899
898
|
y.filter = qe;
|
|
900
|
-
const
|
|
899
|
+
const b = (s, t = {}) => Object.assign({}, s, t), Ve = (s) => {
|
|
901
900
|
if (!s || typeof s != "object" || !Object.keys(s).length)
|
|
902
901
|
return y;
|
|
903
902
|
const t = y;
|
|
904
|
-
return Object.assign((n, i, r = {}) => t(n, i,
|
|
903
|
+
return Object.assign((n, i, r = {}) => t(n, i, b(s, r)), {
|
|
905
904
|
Minimatch: class extends t.Minimatch {
|
|
906
905
|
constructor(i, r = {}) {
|
|
907
|
-
super(i,
|
|
906
|
+
super(i, b(s, r));
|
|
908
907
|
}
|
|
909
908
|
static defaults(i) {
|
|
910
|
-
return t.defaults(
|
|
909
|
+
return t.defaults(b(s, i)).Minimatch;
|
|
911
910
|
}
|
|
912
911
|
},
|
|
913
912
|
AST: class extends t.AST {
|
|
914
913
|
/* c8 ignore start */
|
|
915
914
|
constructor(i, r, o = {}) {
|
|
916
|
-
super(i, r,
|
|
915
|
+
super(i, r, b(s, o));
|
|
917
916
|
}
|
|
918
917
|
/* c8 ignore stop */
|
|
919
918
|
static fromGlob(i, r = {}) {
|
|
920
|
-
return t.AST.fromGlob(i,
|
|
919
|
+
return t.AST.fromGlob(i, b(s, r));
|
|
921
920
|
}
|
|
922
921
|
},
|
|
923
|
-
unescape: (n, i = {}) => t.unescape(n,
|
|
924
|
-
escape: (n, i = {}) => t.escape(n,
|
|
925
|
-
filter: (n, i = {}) => t.filter(n,
|
|
926
|
-
defaults: (n) => t.defaults(
|
|
927
|
-
makeRe: (n, i = {}) => t.makeRe(n,
|
|
928
|
-
braceExpand: (n, i = {}) => t.braceExpand(n,
|
|
929
|
-
match: (n, i, r = {}) => t.match(n, i,
|
|
922
|
+
unescape: (n, i = {}) => t.unescape(n, b(s, i)),
|
|
923
|
+
escape: (n, i = {}) => t.escape(n, b(s, i)),
|
|
924
|
+
filter: (n, i = {}) => t.filter(n, b(s, i)),
|
|
925
|
+
defaults: (n) => t.defaults(b(s, n)),
|
|
926
|
+
makeRe: (n, i = {}) => t.makeRe(n, b(s, i)),
|
|
927
|
+
braceExpand: (n, i = {}) => t.braceExpand(n, b(s, i)),
|
|
928
|
+
match: (n, i, r = {}) => t.match(n, i, b(s, r)),
|
|
930
929
|
sep: t.sep,
|
|
931
|
-
GLOBSTAR:
|
|
930
|
+
GLOBSTAR: v
|
|
932
931
|
});
|
|
933
932
|
};
|
|
934
933
|
y.defaults = Ve;
|
|
@@ -1169,10 +1168,10 @@ class j {
|
|
|
1169
1168
|
matchOne(t, e, n = !1) {
|
|
1170
1169
|
const i = this.options;
|
|
1171
1170
|
if (this.isWindows) {
|
|
1172
|
-
const p = typeof t[0] == "string" && /^[a-z]:$/i.test(t[0]), S = !p && t[0] === "" && t[1] === "" && t[2] === "?" && /^[a-z]:$/i.test(t[3]),
|
|
1173
|
-
if (typeof
|
|
1174
|
-
const [
|
|
1175
|
-
|
|
1171
|
+
const p = typeof t[0] == "string" && /^[a-z]:$/i.test(t[0]), S = !p && t[0] === "" && t[1] === "" && t[2] === "?" && /^[a-z]:$/i.test(t[3]), A = typeof e[0] == "string" && /^[a-z]:$/i.test(e[0]), N = !A && e[0] === "" && e[1] === "" && e[2] === "?" && typeof e[3] == "string" && /^[a-z]:$/i.test(e[3]), x = S ? 3 : p ? 0 : void 0, w = N ? 3 : A ? 0 : void 0;
|
|
1172
|
+
if (typeof x == "number" && typeof w == "number") {
|
|
1173
|
+
const [T, P] = [t[x], e[w]];
|
|
1174
|
+
T.toLowerCase() === P.toLowerCase() && (e[w] = T, w > x ? e = e.slice(w) : x > w && (t = t.slice(x)));
|
|
1176
1175
|
}
|
|
1177
1176
|
}
|
|
1178
1177
|
const { optimizationLevel: r = 1 } = this.options;
|
|
@@ -1182,7 +1181,7 @@ class j {
|
|
|
1182
1181
|
var c = e[a], f = t[o];
|
|
1183
1182
|
if (this.debug(e, c, f), c === !1)
|
|
1184
1183
|
return !1;
|
|
1185
|
-
if (c ===
|
|
1184
|
+
if (c === v) {
|
|
1186
1185
|
this.debug("GLOBSTAR", [e, c, f]);
|
|
1187
1186
|
var u = o, d = a + 1;
|
|
1188
1187
|
if (d === h) {
|
|
@@ -1224,11 +1223,11 @@ globstar while\`, t, u, e, d, m), this.matchOne(t.slice(u), e.slice(d), n))
|
|
|
1224
1223
|
W(t);
|
|
1225
1224
|
const e = this.options;
|
|
1226
1225
|
if (t === "**")
|
|
1227
|
-
return
|
|
1226
|
+
return v;
|
|
1228
1227
|
if (t === "")
|
|
1229
1228
|
return "";
|
|
1230
1229
|
let n, i = null;
|
|
1231
|
-
(n = t.match(Pe)) ? i = e.dot ? ke : Re : (n = t.match(
|
|
1230
|
+
(n = t.match(Pe)) ? i = e.dot ? ke : Re : (n = t.match(ve)) ? i = (e.nocase ? e.dot ? De : Oe : e.dot ? Ce : Ae)(n[1]) : (n = t.match(Le)) ? i = (e.nocase ? e.dot ? ze : Ie : e.dot ? He : We)(n) : (n = t.match(Ne)) ? i = e.dot ? Fe : Te : (n = t.match(Me)) && (i = $e);
|
|
1232
1231
|
const r = E.fromGlob(t, this.options).toMMPattern();
|
|
1233
1232
|
return i && typeof r == "object" && Reflect.defineProperty(r, "test", { value: i }), r;
|
|
1234
1233
|
}
|
|
@@ -1244,12 +1243,12 @@ globstar while\`, t, u, e, d, m), this.matchOne(t.slice(u), e.slice(d), n))
|
|
|
1244
1243
|
if (c instanceof RegExp)
|
|
1245
1244
|
for (const f of c.flags.split(""))
|
|
1246
1245
|
i.add(f);
|
|
1247
|
-
return typeof c == "string" ? Ze(c) : c ===
|
|
1246
|
+
return typeof c == "string" ? Ze(c) : c === v ? v : c._src;
|
|
1248
1247
|
});
|
|
1249
1248
|
return h.forEach((c, f) => {
|
|
1250
1249
|
const u = h[f + 1], d = h[f - 1];
|
|
1251
|
-
c !==
|
|
1252
|
-
}), h.filter((c) => c !==
|
|
1250
|
+
c !== v || d === v || (d === void 0 ? u !== void 0 && u !== v ? h[f + 1] = "(?:\\\\/|" + n + "\\\\/)?" + u : h[f] = n : u === void 0 ? h[f - 1] = d + "(?:\\\\/|" + n + ")?" : u !== v && (h[f - 1] = d + "(?:\\\\/|\\\\/" + n + "\\\\/)" + u, h[f + 1] = v));
|
|
1251
|
+
}), h.filter((c) => c !== v).join("/");
|
|
1253
1252
|
}).join("|");
|
|
1254
1253
|
const [o, a] = t.length > 1 ? ["(?:", ")"] : ["", ""];
|
|
1255
1254
|
r = "^" + o + r + a + "$", this.negate && (r = "^(?!" + r + ").+$");
|
|
@@ -1294,7 +1293,7 @@ globstar while\`, t, u, e, d, m), this.matchOne(t.slice(u), e.slice(d), n))
|
|
|
1294
1293
|
}
|
|
1295
1294
|
y.AST = E;
|
|
1296
1295
|
y.Minimatch = j;
|
|
1297
|
-
y.escape =
|
|
1296
|
+
y.escape = be;
|
|
1298
1297
|
y.unescape = $;
|
|
1299
1298
|
const Je = [
|
|
1300
1299
|
// Images
|
|
@@ -1448,6 +1447,7 @@ async function rs(s, t, e = {}) {
|
|
|
1448
1447
|
const n = Y(t);
|
|
1449
1448
|
return tt(t, "exclusive", async () => {
|
|
1450
1449
|
const i = e.recursive ?? !1, r = e.force ?? !1;
|
|
1450
|
+
e.useTrash;
|
|
1451
1451
|
try {
|
|
1452
1452
|
await s.removeEntry(n, { recursive: i });
|
|
1453
1453
|
} catch (o) {
|
|
@@ -1460,7 +1460,7 @@ async function rs(s, t, e = {}) {
|
|
|
1460
1460
|
}
|
|
1461
1461
|
class os {
|
|
1462
1462
|
/** Root directory handle for the file system */
|
|
1463
|
-
root
|
|
1463
|
+
root;
|
|
1464
1464
|
/** Map of watched paths and options */
|
|
1465
1465
|
watchers = /* @__PURE__ */ new Map();
|
|
1466
1466
|
/** Promise to prevent concurrent mount operations */
|
|
@@ -1543,13 +1543,14 @@ class os {
|
|
|
1543
1543
|
* await fs.mount('/my-app');
|
|
1544
1544
|
* \`\`\`
|
|
1545
1545
|
*/
|
|
1546
|
-
async mount(
|
|
1547
|
-
|
|
1546
|
+
async mount() {
|
|
1547
|
+
const t = this.options.root;
|
|
1548
|
+
return this.mountingPromise && await this.mountingPromise, this.mountingPromise = new Promise(async (e, n) => {
|
|
1548
1549
|
try {
|
|
1549
1550
|
const i = await navigator.storage.getDirectory();
|
|
1550
|
-
t === "/" ?
|
|
1551
|
-
} catch {
|
|
1552
|
-
n(new g("Failed to initialize OPFS", "INIT_FAILED"));
|
|
1551
|
+
this.root = t === "/" ? i : await this.getDirectoryHandle(t, !0, i), e(!0);
|
|
1552
|
+
} catch (i) {
|
|
1553
|
+
n(new g("Failed to initialize OPFS", "INIT_FAILED", t, i));
|
|
1553
1554
|
} finally {
|
|
1554
1555
|
this.mountingPromise = null;
|
|
1555
1556
|
}
|
|
@@ -1566,7 +1567,7 @@ class os {
|
|
|
1566
1567
|
* @param options.broadcastChannel - Custom name for the broadcast channel
|
|
1567
1568
|
*/
|
|
1568
1569
|
async setOptions(t) {
|
|
1569
|
-
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 = t.root, this.options.namespace || (this.options.namespace = \`opfs-worker:\${this.options.root}\`), await this.mount(
|
|
1570
|
+
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 = Z(t.root), this.options.namespace || (this.options.namespace = \`opfs-worker:\${this.options.root}\`), await this.mount());
|
|
1570
1571
|
}
|
|
1571
1572
|
/**
|
|
1572
1573
|
* Get a directory handle from a path
|
|
@@ -1663,7 +1664,7 @@ class os {
|
|
|
1663
1664
|
async readFile(t, e) {
|
|
1664
1665
|
await this.mount(), e || (e = G(t) ? "binary" : "utf-8");
|
|
1665
1666
|
try {
|
|
1666
|
-
const n = await this.getFileHandle(t, !1), i = await ss(n, t);
|
|
1667
|
+
const n = await this.getFileHandle(t, !1, this.root), i = await ss(n, t);
|
|
1667
1668
|
return e === "binary" ? i : _t(i, e);
|
|
1668
1669
|
} catch (n) {
|
|
1669
1670
|
throw new _(t, n);
|
|
@@ -1964,8 +1965,8 @@ class os {
|
|
|
1964
1965
|
async remove(t, e) {
|
|
1965
1966
|
if (await this.mount(), t === "/")
|
|
1966
1967
|
throw new g("Cannot remove root directory", "EROOT");
|
|
1967
|
-
const n = await this.getDirectoryHandle(q(t), !1);
|
|
1968
|
-
await rs(
|
|
1968
|
+
const { recursive: n = !1, force: i = !1 } = e || {}, r = await this.getDirectoryHandle(q(t), !1);
|
|
1969
|
+
await rs(r, t, { recursive: n, force: i }), await this.notifyChange({ path: t, type: "removed", isDirectory: !1 });
|
|
1969
1970
|
}
|
|
1970
1971
|
/**
|
|
1971
1972
|
* Resolve a path to an absolute path
|
|
@@ -2000,26 +2001,35 @@ class os {
|
|
|
2000
2001
|
* Rename a file or directory
|
|
2001
2002
|
*
|
|
2002
2003
|
* Changes the name of a file or directory. If the target path already exists,
|
|
2003
|
-
* it will be replaced.
|
|
2004
|
+
* it will be replaced only if overwrite option is enabled.
|
|
2004
2005
|
*
|
|
2005
2006
|
* @param oldPath - The current path of the file or directory
|
|
2006
2007
|
* @param newPath - The new path for the file or directory
|
|
2008
|
+
* @param options - Options for renaming
|
|
2009
|
+
* @param options.overwrite - Whether to overwrite existing files (default: false)
|
|
2007
2010
|
* @returns Promise that resolves when the rename operation is complete
|
|
2008
2011
|
* @throws {OPFSError} If the rename operation fails
|
|
2009
2012
|
*
|
|
2010
2013
|
* @example
|
|
2011
2014
|
* \`\`\`typescript
|
|
2015
|
+
* // Basic rename (fails if target exists)
|
|
2012
2016
|
* await fs.rename('/old/path/file.txt', '/new/path/renamed.txt');
|
|
2017
|
+
*
|
|
2018
|
+
* // Rename with overwrite
|
|
2019
|
+
* await fs.rename('/old/path/file.txt', '/new/path/renamed.txt', { overwrite: true });
|
|
2013
2020
|
* \`\`\`
|
|
2014
2021
|
*/
|
|
2015
|
-
async rename(t, e) {
|
|
2022
|
+
async rename(t, e, n) {
|
|
2016
2023
|
await this.mount();
|
|
2017
2024
|
try {
|
|
2025
|
+
const i = n?.overwrite ?? !1;
|
|
2018
2026
|
if (!await this.exists(t))
|
|
2019
2027
|
throw new _(t);
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2028
|
+
if (await this.exists(e) && !i)
|
|
2029
|
+
throw new g(\`Destination already exists: \${e}\`, "EEXIST", void 0);
|
|
2030
|
+
await this.copy(t, e, { recursive: !0, overwrite: i }), await this.remove(t, { recursive: !0 }), await this.notifyChange({ path: t, type: "removed", isDirectory: !1 }), await this.notifyChange({ path: e, type: "added", isDirectory: !1 });
|
|
2031
|
+
} catch (i) {
|
|
2032
|
+
throw i instanceof g ? i : new g(\`Failed to rename from \${t} to \${e}\`, "RENAME_FAILED", void 0, i);
|
|
2023
2033
|
}
|
|
2024
2034
|
}
|
|
2025
2035
|
/**
|
|
@@ -2031,7 +2041,7 @@ class os {
|
|
|
2031
2041
|
* @param destination - The destination path to copy to
|
|
2032
2042
|
* @param options - Options for copying
|
|
2033
2043
|
* @param options.recursive - Whether to copy directories recursively (default: false)
|
|
2034
|
-
* @param options.
|
|
2044
|
+
* @param options.overwrite - Whether to overwrite existing files (default: true)
|
|
2035
2045
|
* @returns Promise that resolves when the copy operation is complete
|
|
2036
2046
|
* @throws {OPFSError} If the copy operation fails
|
|
2037
2047
|
*
|
|
@@ -2044,13 +2054,13 @@ class os {
|
|
|
2044
2054
|
* await fs.copy('/source/dir', '/dest/dir', { recursive: true });
|
|
2045
2055
|
*
|
|
2046
2056
|
* // Copy without overwriting existing files
|
|
2047
|
-
* await fs.copy('/source', '/dest', { recursive: true,
|
|
2057
|
+
* await fs.copy('/source', '/dest', { recursive: true, overwrite: false });
|
|
2048
2058
|
* \`\`\`
|
|
2049
2059
|
*/
|
|
2050
2060
|
async copy(t, e, n) {
|
|
2051
2061
|
await this.mount();
|
|
2052
2062
|
try {
|
|
2053
|
-
const i = n?.recursive ?? !1, r = n?.
|
|
2063
|
+
const i = n?.recursive ?? !1, r = n?.overwrite ?? !0;
|
|
2054
2064
|
if (!await this.exists(t))
|
|
2055
2065
|
throw new g(\`Source does not exist: \${t}\`, "ENOENT", void 0);
|
|
2056
2066
|
if (await this.exists(e) && !r)
|
|
@@ -2065,7 +2075,7 @@ class os {
|
|
|
2065
2075
|
const h = await this.readDir(t);
|
|
2066
2076
|
for (const c of h) {
|
|
2067
2077
|
const f = \`\${t}/\${c.name}\`, u = \`\${e}/\${c.name}\`;
|
|
2068
|
-
await this.copy(f, u, { recursive: !0,
|
|
2078
|
+
await this.copy(f, u, { recursive: !0, overwrite: r });
|
|
2069
2079
|
}
|
|
2070
2080
|
}
|
|
2071
2081
|
} catch (i) {
|
|
@@ -2165,7 +2175,7 @@ class os {
|
|
|
2165
2175
|
}
|
|
2166
2176
|
}
|
|
2167
2177
|
typeof globalThis < "u" && globalThis.constructor.name === "DedicatedWorkerGlobalScope" && J(new os());
|
|
2168
|
-
//# sourceMappingURL=worker-
|
|
2178
|
+
//# sourceMappingURL=worker-XHCzp1qX.js.map
|
|
2169
2179
|
`, s = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", r], { type: "text/javascript;charset=utf-8" });
|
|
2170
2180
|
function o(n) {
|
|
2171
2181
|
let t;
|
|
@@ -2206,8 +2216,8 @@ export {
|
|
|
2206
2216
|
x as basename,
|
|
2207
2217
|
S as buffersEqual,
|
|
2208
2218
|
E as calculateFileHash,
|
|
2209
|
-
|
|
2210
|
-
|
|
2219
|
+
P as checkOPFSSupport,
|
|
2220
|
+
A as convertBlobToUint8Array,
|
|
2211
2221
|
F as createBuffer,
|
|
2212
2222
|
h as createWorker,
|
|
2213
2223
|
O as decodeBuffer,
|
|
@@ -2224,7 +2234,7 @@ export {
|
|
|
2224
2234
|
k as removeEntry,
|
|
2225
2235
|
L as resolvePath,
|
|
2226
2236
|
z as splitPath,
|
|
2227
|
-
|
|
2228
|
-
|
|
2237
|
+
W as withLock,
|
|
2238
|
+
U as writeFileData
|
|
2229
2239
|
};
|
|
2230
2240
|
//# 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 } from 'comlink';\n\nimport WorkerCtor from './worker?worker&inline';\n\nimport type { OPFSOptions, OPFSWorker, RemoteOPFSWorker } 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 async function createWorker(\n options?: OPFSOptions\n): Promise<RemoteOPFSWorker> {\n const wrapped = wrap<OPFSWorker>(new WorkerCtor());\n\n // Set up options if provided\n if (options) {\n // We can't pass a BroadcastChannel instance to the worker, so we need to convert it to a string first\n if (options.broadcastChannel && options.broadcastChannel instanceof BroadcastChannel) {\n options.broadcastChannel = options.broadcastChannel.name;\n }\n\n await wrapped.setOptions(options);\n }\n\n return wrapped;\n}\n"],"names":["createWorker","options","wrapped","wrap","WorkerCtor"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { wrap } from 'comlink';\n\nimport WorkerCtor from './worker?worker&inline';\n\nimport type { OPFSOptions, OPFSWorker, RemoteOPFSWorker } 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 async function createWorker(\n options?: OPFSOptions\n): Promise<RemoteOPFSWorker> {\n const wrapped = wrap<OPFSWorker>(new WorkerCtor());\n\n // Set up options if provided\n if (options) {\n // We can't pass a BroadcastChannel instance to the worker, so we need to convert it to a string first\n if (options.broadcastChannel && options.broadcastChannel instanceof BroadcastChannel) {\n options.broadcastChannel = options.broadcastChannel.name;\n }\n\n await wrapped.setOptions(options);\n }\n\n return wrapped;\n}\n"],"names":["createWorker","options","wrapped","wrap","WorkerCtor"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA,eAAsBA,EAClBC,GACyB;AACzB,QAAMC,IAAUC,EAAiB,IAAIC,GAAY;AAGjD,SAAIH,MAEIA,EAAQ,oBAAoBA,EAAQ,4BAA4B,qBAChEA,EAAQ,mBAAmBA,EAAQ,iBAAiB,OAGxD,MAAMC,EAAQ,WAAWD,CAAO,IAG7BC;AACX;"}
|
package/dist/raw.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("comlink"),i=require("./helpers-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("comlink"),i=require("./helpers-Cvjm0f_r.cjs");class w{root;watchers=new Map;mountingPromise=null;broadcastChannel=null;options={root:"/",namespace:"",maxFileSize:50*1024*1024,hashAlgorithm:null,broadcastChannel:"opfs-worker"};async notifyChange(t){if(!this.options.broadcastChannel)return;const e=t.path;if(![...this.watchers.values()].some(s=>i.matchMinimatch(e,s.pattern)&&s.include.some(o=>o&&i.matchMinimatch(e,o))&&!s.exclude.some(o=>o&&i.matchMinimatch(e,o))))return;let r;if(this.options.hashAlgorithm)try{r=(await this.stat(e)).hash}catch{}try{this.broadcastChannel||(this.broadcastChannel=new BroadcastChannel(this.options.broadcastChannel));const s={namespace:this.options.namespace,timestamp:new Date().toISOString(),...t,...r&&{hash:r}};this.broadcastChannel.postMessage(s)}catch(s){console.warn("Failed to send event via BroadcastChannel:",s)}}constructor(t){i.checkOPFSSupport(),t&&this.setOptions(t)}async mount(){const t=this.options.root;return this.mountingPromise&&await this.mountingPromise,this.mountingPromise=new Promise(async(e,a)=>{try{const r=await navigator.storage.getDirectory();this.root=t==="/"?r:await this.getDirectoryHandle(t,!0,r),e(!0)}catch(r){a(new i.OPFSError("Failed to initialize OPFS","INIT_FAILED",t,r))}finally{this.mountingPromise=null}}),this.mountingPromise}async setOptions(t){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=i.normalizePath(t.root),this.options.namespace||(this.options.namespace=`opfs-worker:${this.options.root}`),await this.mount())}async getDirectoryHandle(t,e=!1,a=this.root){const r=Array.isArray(t)?t:i.splitPath(t);let s=a;for(const o of r)s=await s.getDirectoryHandle(o,{create:e});return s}async getFileHandle(t,e=!1,a=this.root){const r=i.splitPath(t);if(r.length===0)throw new i.PathError("Path must not be empty",Array.isArray(t)?t.join("/"):t);const s=r.pop();return(await this.getDirectoryHandle(r,e,a)).getFileHandle(s,{create:e})}async index(){const t=new Map,e=async a=>{const r=await this.readDir(a);for(const s of r){const o=`${a==="/"?"":a}/${s.name}`;try{const n=await this.stat(o);t.set(o,n),n.isDirectory&&await e(o)}catch(n){console.warn(`Skipping broken entry: ${o}`,n)}}};return t.set("/",{kind:"directory",size:0,mtime:new Date(0).toISOString(),ctime:new Date(0).toISOString(),isFile:!1,isDirectory:!0}),await e("/"),t}async readFile(t,e){await this.mount(),e||(e=i.isBinaryFileExtension(t)?"binary":"utf-8");try{const a=await this.getFileHandle(t,!1,this.root),r=await i.readFileData(a,t);return e==="binary"?r:i.decodeBuffer(r,e)}catch(a){throw new i.FileNotFoundError(t,a)}}async writeFile(t,e,a){await this.mount();const r=await this.exists(t),s=await this.getFileHandle(t,!0);a||(a=typeof e!="string"||i.isBinaryFileExtension(t)?"binary":"utf-8"),await i.writeFileData(s,e,a,t),r?await this.notifyChange({path:t,type:"changed",isDirectory:!1}):await this.notifyChange({path:t,type:"added",isDirectory:!1})}async appendFile(t,e,a){await this.mount();const r=await this.getFileHandle(t,!0);a||(a=typeof e!="string"||i.isBinaryFileExtension(t)?"binary":"utf-8"),await i.writeFileData(r,e,a,t,{append:!0}),await this.notifyChange({path:t,type:"changed",isDirectory:!1})}async mkdir(t,e){await this.mount();const a=e?.recursive??!1,r=i.splitPath(t);let s=this.root;for(let o=0;o<r.length;o++){const n=r[o];try{s=await s.getDirectoryHandle(n,{create:a||o===r.length-1})}catch(c){throw c.name==="NotFoundError"?new i.OPFSError(`Parent directory does not exist: ${i.joinPath(r.slice(0,o+1))}`,"ENOENT",void 0,c):c.name==="TypeMismatchError"?new i.OPFSError(`Path segment is not a directory: ${n}`,"ENOTDIR",void 0,c):new i.OPFSError("Failed to create directory","MKDIR_FAILED",void 0,c)}}await this.notifyChange({path:t,type:"added",isDirectory:!0})}async stat(t){if(await this.mount(),t==="/")return{kind:"directory",size:0,mtime:new Date(0).toISOString(),ctime:new Date(0).toISOString(),isFile:!1,isDirectory:!0};const e=i.basename(t),a=await this.getDirectoryHandle(i.dirname(t),!1),r=this.options.hashAlgorithm!==null;try{const o=await(await a.getFileHandle(e,{create:!1})).getFile(),n={kind:"file",size:o.size,mtime:new Date(o.lastModified).toISOString(),ctime:new Date(o.lastModified).toISOString(),isFile:!0,isDirectory:!1};if(r&&this.options.hashAlgorithm)try{const c=await i.calculateFileHash(o,this.options.hashAlgorithm,this.options.maxFileSize);n.hash=c}catch(c){console.warn(`Failed to calculate hash for ${t}:`,c)}return n}catch(s){if(s.name!=="TypeMismatchError"&&s.name!=="NotFoundError")throw new i.OPFSError("Failed to stat (file)","STAT_FAILED",void 0,s)}try{return await a.getDirectoryHandle(e,{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 i.OPFSError(`No such file or directory: ${t}`,"ENOENT",void 0,s):new i.OPFSError("Failed to stat (directory)","STAT_FAILED",void 0,s)}}async readDir(t){await this.mount();const e=await this.getDirectoryHandle(t,!1),a=[];for await(const[r,s]of e.entries()){const o=s.kind==="file";a.push({name:r,kind:s.kind,isFile:o,isDirectory:!o})}return a}async exists(t){if(await this.mount(),t==="/")return!0;const e=i.basename(t);let a=null;try{a=await this.getDirectoryHandle(i.dirname(t),!1)}catch(r){throw(r.name==="NotFoundError"||r.name==="TypeMismatchError")&&(a=null),r}if(!a||!e)return!1;try{return await a.getFileHandle(e,{create:!1}),!0}catch(r){if(r.name!=="NotFoundError"&&r.name!=="TypeMismatchError")throw r;try{return await a.getDirectoryHandle(e,{create:!1}),!0}catch(s){if(s.name!=="NotFoundError"&&s.name!=="TypeMismatchError")throw s;return!1}}}async clear(t="/"){await this.mount();try{const e=await this.readDir(t);for(const a of e){const r=`${t==="/"?"":t}/${a.name}`;await this.remove(r,{recursive:!0})}await this.notifyChange({path:t,type:"changed",isDirectory:!0})}catch(e){throw e instanceof i.OPFSError?e:new i.OPFSError(`Failed to clear directory: ${t}`,"CLEAR_FAILED",void 0,e)}}async remove(t,e){if(await this.mount(),t==="/")throw new i.OPFSError("Cannot remove root directory","EROOT");const{recursive:a=!1,force:r=!1}=e||{},s=await this.getDirectoryHandle(i.dirname(t),!1);await i.removeEntry(s,t,{recursive:a,force:r}),await this.notifyChange({path:t,type:"removed",isDirectory:!1})}async realpath(t){await this.mount();try{const e=i.resolvePath(t);if(!await this.exists(e))throw new i.FileNotFoundError(e);return e}catch(e){throw e instanceof i.OPFSError?e:new i.OPFSError(`Failed to resolve path: ${t}`,"REALPATH_FAILED",void 0,e)}}async rename(t,e,a){await this.mount();try{const r=a?.overwrite??!1;if(!await this.exists(t))throw new i.FileNotFoundError(t);if(await this.exists(e)&&!r)throw new i.OPFSError(`Destination already exists: ${e}`,"EEXIST",void 0);await this.copy(t,e,{recursive:!0,overwrite:r}),await this.remove(t,{recursive:!0}),await this.notifyChange({path:t,type:"removed",isDirectory:!1}),await this.notifyChange({path:e,type:"added",isDirectory:!1})}catch(r){throw r instanceof i.OPFSError?r:new i.OPFSError(`Failed to rename from ${t} to ${e}`,"RENAME_FAILED",void 0,r)}}async copy(t,e,a){await this.mount();try{const r=a?.recursive??!1,s=a?.overwrite??!0;if(!await this.exists(t))throw new i.OPFSError(`Source does not exist: ${t}`,"ENOENT",void 0);if(await this.exists(e)&&!s)throw new i.OPFSError(`Destination already exists: ${e}`,"EEXIST",void 0);if((await this.stat(t)).isFile){const l=await this.readFile(t,"binary");await this.writeFile(e,l)}else{if(!r)throw new i.OPFSError(`Cannot copy directory without recursive option: ${t}`,"EISDIR",void 0);await this.mkdir(e,{recursive:!0});const l=await this.readDir(t);for(const h of l){const d=`${t}/${h.name}`,f=`${e}/${h.name}`;await this.copy(d,f,{recursive:!0,overwrite:s})}}}catch(r){throw r instanceof i.OPFSError?r:new i.OPFSError(`Failed to copy from ${t} to ${e}`,"CP_FAILED",void 0,r)}}async watch(t,e){if(!this.options.broadcastChannel)throw new i.OPFSError("This instance is not configured to send events. Please specify options.broadcastChannel to enable watching.","ENOENT");const a={pattern:i.normalizeMinimatch(t,e?.recursive??!0),include:Array.isArray(e?.include)?e.include:[e?.include??"**"],exclude:Array.isArray(e?.exclude)?e.exclude:[e?.exclude??""]};this.watchers.set(t,a)}unwatch(t){this.watchers.delete(t)}dispose(){this.broadcastChannel&&(this.broadcastChannel.close(),this.broadcastChannel=null),this.watchers.clear()}async sync(t,e){await this.mount();try{(e?.cleanBefore??!1)&&await this.clear("/");for(const[r,s]of t){const o=i.normalizePath(r);let n;s instanceof Blob?n=await i.convertBlobToUint8Array(s):n=s,await this.writeFile(o,n)}}catch(a){throw a instanceof i.OPFSError?a:new i.OPFSError("Failed to sync file system","SYNC_FAILED",void 0,a)}}}typeof globalThis<"u"&&globalThis.constructor.name==="DedicatedWorkerGlobalScope"&&m.expose(new w);exports.OPFSWorker=w;
|
|
2
2
|
//# sourceMappingURL=raw.cjs.map
|