opfs-worker 1.0.1 → 1.2.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/README.md +38 -6
- package/dist/assets/worker-CLvhwwfc.js.map +1 -0
- package/dist/facade.d.ts +141 -0
- package/dist/facade.d.ts.map +1 -0
- package/dist/{helpers-CTCvNFs1.js → helpers-CkNHswLp.js} +412 -373
- package/dist/helpers-CkNHswLp.js.map +1 -0
- package/dist/helpers-TAynP0fb.cjs +4 -0
- package/dist/helpers-TAynP0fb.cjs.map +1 -0
- package/dist/index.cjs +641 -474
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +886 -522
- package/dist/index.js.map +1 -1
- package/dist/raw.cjs +1 -1
- package/dist/raw.cjs.map +1 -1
- package/dist/raw.d.ts +13 -0
- package/dist/raw.d.ts.map +1 -0
- package/dist/raw.js +331 -59
- package/dist/raw.js.map +1 -1
- package/dist/types.d.ts +8 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/encoder.d.ts +20 -2
- package/dist/utils/encoder.d.ts.map +1 -1
- package/dist/utils/errors.d.ts +23 -0
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts +42 -40
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/worker.d.ts +178 -31
- package/dist/worker.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/assets/worker-CccfxYdr.js.map +0 -1
- package/dist/helpers-CTCvNFs1.js.map +0 -1
- package/dist/helpers-Cvjm0f_r.cjs +0 -4
- package/dist/helpers-Cvjm0f_r.cjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("comlink"),e=require("./helpers-TAynP0fb.cjs"),c=`/**
|
|
2
2
|
* @license
|
|
3
3
|
* Copyright 2019 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
const
|
|
7
|
-
canHandle: (s) =>
|
|
6
|
+
const pt = Symbol("Comlink.proxy"), Ct = Symbol("Comlink.endpoint"), Tt = Symbol("Comlink.releaseProxy"), q = Symbol("Comlink.finalizer"), z = Symbol("Comlink.thrown"), gt = (s) => typeof s == "object" && s !== null || typeof s == "function", Mt = {
|
|
7
|
+
canHandle: (s) => gt(s) && s[pt],
|
|
8
8
|
serialize(s) {
|
|
9
9
|
const { port1: t, port2: e } = new MessageChannel();
|
|
10
|
-
return
|
|
10
|
+
return K(s, t), [e, [e]];
|
|
11
11
|
},
|
|
12
12
|
deserialize(s) {
|
|
13
|
-
return s.start(),
|
|
13
|
+
return s.start(), Rt(s);
|
|
14
14
|
}
|
|
15
|
-
},
|
|
16
|
-
canHandle: (s) =>
|
|
15
|
+
}, Pt = {
|
|
16
|
+
canHandle: (s) => gt(s) && z in s,
|
|
17
17
|
serialize({ value: s }) {
|
|
18
18
|
let t;
|
|
19
19
|
return s instanceof Error ? t = {
|
|
@@ -28,25 +28,25 @@ const ut = Symbol("Comlink.proxy"), Dt = Symbol("Comlink.endpoint"), Nt = Symbol
|
|
|
28
28
|
deserialize(s) {
|
|
29
29
|
throw s.isError ? Object.assign(new Error(s.value.message), s.value) : s.value;
|
|
30
30
|
}
|
|
31
|
-
},
|
|
32
|
-
["proxy",
|
|
33
|
-
["throw",
|
|
31
|
+
}, wt = /* @__PURE__ */ new Map([
|
|
32
|
+
["proxy", Mt],
|
|
33
|
+
["throw", Pt]
|
|
34
34
|
]);
|
|
35
|
-
function
|
|
35
|
+
function It(s, t) {
|
|
36
36
|
for (const e of s)
|
|
37
37
|
if (t === e || e === "*" || e instanceof RegExp && e.test(t))
|
|
38
38
|
return !0;
|
|
39
39
|
return !1;
|
|
40
40
|
}
|
|
41
|
-
function
|
|
41
|
+
function K(s, t = globalThis, e = ["*"]) {
|
|
42
42
|
t.addEventListener("message", function n(i) {
|
|
43
43
|
if (!i || !i.data)
|
|
44
44
|
return;
|
|
45
|
-
if (!
|
|
45
|
+
if (!It(e, i.origin)) {
|
|
46
46
|
console.warn(\`Invalid origin '\${i.origin}' for comlink proxy\`);
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
|
-
const { id: r, type: o, path: a } = Object.assign({ path: [] }, i.data), l = (i.data.argumentList || []).map(
|
|
49
|
+
const { id: r, type: o, path: a } = Object.assign({ path: [] }, i.data), l = (i.data.argumentList || []).map(F);
|
|
50
50
|
let h;
|
|
51
51
|
try {
|
|
52
52
|
const c = a.slice(0, -1).reduce((u, d) => u[d], s), f = a.reduce((u, d) => u[d], s);
|
|
@@ -55,7 +55,7 @@ function J(s, t = globalThis, e = ["*"]) {
|
|
|
55
55
|
h = f;
|
|
56
56
|
break;
|
|
57
57
|
case "SET":
|
|
58
|
-
c[a.slice(-1)[0]] =
|
|
58
|
+
c[a.slice(-1)[0]] = F(i.data.value), h = !0;
|
|
59
59
|
break;
|
|
60
60
|
case "APPLY":
|
|
61
61
|
h = f.apply(c, l);
|
|
@@ -63,13 +63,13 @@ function J(s, t = globalThis, e = ["*"]) {
|
|
|
63
63
|
case "CONSTRUCT":
|
|
64
64
|
{
|
|
65
65
|
const u = new f(...l);
|
|
66
|
-
h =
|
|
66
|
+
h = Wt(u);
|
|
67
67
|
}
|
|
68
68
|
break;
|
|
69
69
|
case "ENDPOINT":
|
|
70
70
|
{
|
|
71
71
|
const { port1: u, port2: d } = new MessageChannel();
|
|
72
|
-
|
|
72
|
+
K(s, d), h = H(u, [u]);
|
|
73
73
|
}
|
|
74
74
|
break;
|
|
75
75
|
case "RELEASE":
|
|
@@ -79,27 +79,27 @@ function J(s, t = globalThis, e = ["*"]) {
|
|
|
79
79
|
return;
|
|
80
80
|
}
|
|
81
81
|
} catch (c) {
|
|
82
|
-
h = { value: c, [
|
|
82
|
+
h = { value: c, [z]: 0 };
|
|
83
83
|
}
|
|
84
|
-
Promise.resolve(h).catch((c) => ({ value: c, [
|
|
85
|
-
const [f, u] =
|
|
86
|
-
t.postMessage(Object.assign(Object.assign({}, f), { id: r }), u), o === "RELEASE" && (t.removeEventListener("message", n),
|
|
84
|
+
Promise.resolve(h).catch((c) => ({ value: c, [z]: 0 })).then((c) => {
|
|
85
|
+
const [f, u] = B(c);
|
|
86
|
+
t.postMessage(Object.assign(Object.assign({}, f), { id: r }), u), o === "RELEASE" && (t.removeEventListener("message", n), yt(t), q in s && typeof s[q] == "function" && s[q]());
|
|
87
87
|
}).catch((c) => {
|
|
88
|
-
const [f, u] =
|
|
88
|
+
const [f, u] = B({
|
|
89
89
|
value: new TypeError("Unserializable return value"),
|
|
90
|
-
[
|
|
90
|
+
[z]: 0
|
|
91
91
|
});
|
|
92
92
|
t.postMessage(Object.assign(Object.assign({}, f), { id: r }), u);
|
|
93
93
|
});
|
|
94
94
|
}), t.start && t.start();
|
|
95
95
|
}
|
|
96
|
-
function
|
|
96
|
+
function kt(s) {
|
|
97
97
|
return s.constructor.name === "MessagePort";
|
|
98
98
|
}
|
|
99
|
-
function
|
|
100
|
-
|
|
99
|
+
function yt(s) {
|
|
100
|
+
kt(s) && s.close();
|
|
101
101
|
}
|
|
102
|
-
function
|
|
102
|
+
function Rt(s, t) {
|
|
103
103
|
const e = /* @__PURE__ */ new Map();
|
|
104
104
|
return s.addEventListener("message", function(i) {
|
|
105
105
|
const { data: r } = i;
|
|
@@ -112,103 +112,103 @@ function Pt(s, t) {
|
|
|
112
112
|
} finally {
|
|
113
113
|
e.delete(r.id);
|
|
114
114
|
}
|
|
115
|
-
}),
|
|
115
|
+
}), Z(s, e, [], t);
|
|
116
116
|
}
|
|
117
|
-
function
|
|
117
|
+
function k(s) {
|
|
118
118
|
if (s)
|
|
119
119
|
throw new Error("Proxy has been released and is not useable");
|
|
120
120
|
}
|
|
121
|
-
function
|
|
122
|
-
return
|
|
121
|
+
function mt(s) {
|
|
122
|
+
return N(s, /* @__PURE__ */ new Map(), {
|
|
123
123
|
type: "RELEASE"
|
|
124
124
|
}).then(() => {
|
|
125
|
-
|
|
125
|
+
yt(s);
|
|
126
126
|
});
|
|
127
127
|
}
|
|
128
|
-
const
|
|
129
|
-
const t = (
|
|
130
|
-
|
|
128
|
+
const _ = /* @__PURE__ */ new WeakMap(), j = "FinalizationRegistry" in globalThis && new FinalizationRegistry((s) => {
|
|
129
|
+
const t = (_.get(s) || 0) - 1;
|
|
130
|
+
_.set(s, t), t === 0 && mt(s);
|
|
131
131
|
});
|
|
132
|
-
function
|
|
133
|
-
const e = (
|
|
134
|
-
|
|
132
|
+
function Lt(s, t) {
|
|
133
|
+
const e = (_.get(t) || 0) + 1;
|
|
134
|
+
_.set(t, e), j && j.register(s, t, s);
|
|
135
135
|
}
|
|
136
|
-
function
|
|
137
|
-
|
|
136
|
+
function zt(s) {
|
|
137
|
+
j && j.unregister(s);
|
|
138
138
|
}
|
|
139
|
-
function
|
|
139
|
+
function Z(s, t, e = [], n = function() {
|
|
140
140
|
}) {
|
|
141
141
|
let i = !1;
|
|
142
142
|
const r = new Proxy(n, {
|
|
143
143
|
get(o, a) {
|
|
144
|
-
if (
|
|
144
|
+
if (k(i), a === Tt)
|
|
145
145
|
return () => {
|
|
146
|
-
|
|
146
|
+
zt(r), mt(s), t.clear(), i = !0;
|
|
147
147
|
};
|
|
148
148
|
if (a === "then") {
|
|
149
149
|
if (e.length === 0)
|
|
150
150
|
return { then: () => r };
|
|
151
|
-
const l =
|
|
151
|
+
const l = N(s, t, {
|
|
152
152
|
type: "GET",
|
|
153
153
|
path: e.map((h) => h.toString())
|
|
154
|
-
}).then(
|
|
154
|
+
}).then(F);
|
|
155
155
|
return l.then.bind(l);
|
|
156
156
|
}
|
|
157
|
-
return
|
|
157
|
+
return Z(s, t, [...e, a]);
|
|
158
158
|
},
|
|
159
159
|
set(o, a, l) {
|
|
160
|
-
|
|
161
|
-
const [h, c] =
|
|
162
|
-
return
|
|
160
|
+
k(i);
|
|
161
|
+
const [h, c] = B(l);
|
|
162
|
+
return N(s, t, {
|
|
163
163
|
type: "SET",
|
|
164
164
|
path: [...e, a].map((f) => f.toString()),
|
|
165
165
|
value: h
|
|
166
|
-
}, c).then(
|
|
166
|
+
}, c).then(F);
|
|
167
167
|
},
|
|
168
168
|
apply(o, a, l) {
|
|
169
|
-
|
|
169
|
+
k(i);
|
|
170
170
|
const h = e[e.length - 1];
|
|
171
|
-
if (h ===
|
|
172
|
-
return
|
|
171
|
+
if (h === Ct)
|
|
172
|
+
return N(s, t, {
|
|
173
173
|
type: "ENDPOINT"
|
|
174
|
-
}).then(
|
|
174
|
+
}).then(F);
|
|
175
175
|
if (h === "bind")
|
|
176
|
-
return
|
|
176
|
+
return Z(s, t, e.slice(0, -1));
|
|
177
177
|
const [c, f] = st(l);
|
|
178
|
-
return
|
|
178
|
+
return N(s, t, {
|
|
179
179
|
type: "APPLY",
|
|
180
180
|
path: e.map((u) => u.toString()),
|
|
181
181
|
argumentList: c
|
|
182
|
-
}, f).then(
|
|
182
|
+
}, f).then(F);
|
|
183
183
|
},
|
|
184
184
|
construct(o, a) {
|
|
185
|
-
|
|
185
|
+
k(i);
|
|
186
186
|
const [l, h] = st(a);
|
|
187
|
-
return
|
|
187
|
+
return N(s, t, {
|
|
188
188
|
type: "CONSTRUCT",
|
|
189
189
|
path: e.map((c) => c.toString()),
|
|
190
190
|
argumentList: l
|
|
191
|
-
}, h).then(
|
|
191
|
+
}, h).then(F);
|
|
192
192
|
}
|
|
193
193
|
});
|
|
194
|
-
return
|
|
194
|
+
return Lt(r, s), r;
|
|
195
195
|
}
|
|
196
|
-
function
|
|
196
|
+
function Ht(s) {
|
|
197
197
|
return Array.prototype.concat.apply([], s);
|
|
198
198
|
}
|
|
199
199
|
function st(s) {
|
|
200
|
-
const t = s.map(
|
|
201
|
-
return [t.map((e) => e[0]),
|
|
200
|
+
const t = s.map(B);
|
|
201
|
+
return [t.map((e) => e[0]), Ht(t.map((e) => e[1]))];
|
|
202
202
|
}
|
|
203
|
-
const
|
|
204
|
-
function
|
|
205
|
-
return
|
|
203
|
+
const Et = /* @__PURE__ */ new WeakMap();
|
|
204
|
+
function H(s, t) {
|
|
205
|
+
return Et.set(s, t), s;
|
|
206
206
|
}
|
|
207
|
-
function
|
|
208
|
-
return Object.assign(s, { [
|
|
207
|
+
function Wt(s) {
|
|
208
|
+
return Object.assign(s, { [pt]: !0 });
|
|
209
209
|
}
|
|
210
|
-
function
|
|
211
|
-
for (const [t, e] of
|
|
210
|
+
function B(s) {
|
|
211
|
+
for (const [t, e] of wt)
|
|
212
212
|
if (e.canHandle(s)) {
|
|
213
213
|
const [n, i] = e.serialize(s);
|
|
214
214
|
return [
|
|
@@ -225,120 +225,78 @@ function H(s) {
|
|
|
225
225
|
type: "RAW",
|
|
226
226
|
value: s
|
|
227
227
|
},
|
|
228
|
-
|
|
228
|
+
Et.get(s) || []
|
|
229
229
|
];
|
|
230
230
|
}
|
|
231
|
-
function
|
|
231
|
+
function F(s) {
|
|
232
232
|
switch (s.type) {
|
|
233
233
|
case "HANDLER":
|
|
234
|
-
return
|
|
234
|
+
return wt.get(s.name).deserialize(s.value);
|
|
235
235
|
case "RAW":
|
|
236
236
|
return s.value;
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
|
-
function
|
|
239
|
+
function N(s, t, e, n) {
|
|
240
240
|
return new Promise((i) => {
|
|
241
|
-
const r =
|
|
241
|
+
const r = _t();
|
|
242
242
|
t.set(r, i), s.start && s.start(), s.postMessage(Object.assign({ id: r }, e), n);
|
|
243
243
|
});
|
|
244
244
|
}
|
|
245
|
-
function
|
|
245
|
+
function _t() {
|
|
246
246
|
return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
|
|
247
247
|
}
|
|
248
|
-
class
|
|
248
|
+
class p extends Error {
|
|
249
249
|
constructor(t, e, n, i) {
|
|
250
250
|
super(t, { cause: i }), this.code = e, this.path = n, this.name = "OPFSError";
|
|
251
251
|
}
|
|
252
252
|
}
|
|
253
|
-
class
|
|
253
|
+
class jt extends p {
|
|
254
254
|
constructor(t) {
|
|
255
255
|
super("OPFS is not supported in this browser", "OPFS_NOT_SUPPORTED", void 0, t);
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
|
-
class
|
|
258
|
+
class Bt extends p {
|
|
259
259
|
constructor(t, e, n) {
|
|
260
260
|
super(t, "INVALID_PATH", e, n);
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
|
-
class
|
|
263
|
+
class nt extends p {
|
|
264
264
|
constructor(t, e) {
|
|
265
265
|
super(\`File not found: \${t}\`, "FILE_NOT_FOUND", t, e);
|
|
266
266
|
}
|
|
267
267
|
}
|
|
268
|
-
function
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
case "utf-8":
|
|
272
|
-
return new TextEncoder().encode(s);
|
|
273
|
-
case "utf16le":
|
|
274
|
-
case "ucs2":
|
|
275
|
-
case "ucs-2":
|
|
276
|
-
return Bt(s);
|
|
277
|
-
case "ascii":
|
|
278
|
-
return Vt(s);
|
|
279
|
-
case "latin1":
|
|
280
|
-
return qt(s);
|
|
281
|
-
case "binary":
|
|
282
|
-
return Uint8Array.from(s, (e) => e.charCodeAt(0));
|
|
283
|
-
case "base64":
|
|
284
|
-
return Uint8Array.from(atob(s), (e) => e.charCodeAt(0));
|
|
285
|
-
case "hex":
|
|
286
|
-
if (!/^[\\da-f]+$/i.test(s) || s.length % 2 !== 0)
|
|
287
|
-
throw new g("Invalid hex string", "INVALID_HEX_FORMAT");
|
|
288
|
-
return Uint8Array.from(s.match(/.{1,2}/g).map((e) => parseInt(e, 16)));
|
|
289
|
-
default:
|
|
290
|
-
return console.warn("Encoding not supported, falling back to UTF-8"), new TextEncoder().encode(s);
|
|
291
|
-
}
|
|
268
|
+
function R(s, t, e, n) {
|
|
269
|
+
const i = \`\${s.toUpperCase()}_FAILED\`;
|
|
270
|
+
return new p(\`Failed to \${s} file descriptor: \${t}\`, i, e, n);
|
|
292
271
|
}
|
|
293
|
-
function
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
case "
|
|
297
|
-
return new
|
|
298
|
-
case "
|
|
299
|
-
|
|
300
|
-
case "
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
case "
|
|
306
|
-
return
|
|
307
|
-
case "
|
|
308
|
-
return
|
|
309
|
-
case "
|
|
310
|
-
return
|
|
272
|
+
function Ut(s, t) {
|
|
273
|
+
const e = t?.path;
|
|
274
|
+
switch (s.name) {
|
|
275
|
+
case "InvalidStateError":
|
|
276
|
+
return new p(\`File is busy: \${e || "unknown"}\`, "EBUSY", e, s);
|
|
277
|
+
case "QuotaExceededError":
|
|
278
|
+
return new p(\`No space left on device: \${e || "unknown"}\`, "ENOSPC", e, s);
|
|
279
|
+
case "NotFoundError":
|
|
280
|
+
return new p(\`No such file or directory: \${e || "unknown"}\`, "ENOENT", e, s);
|
|
281
|
+
case "TypeMismatchError":
|
|
282
|
+
return new p(\`Is a directory: \${e || "unknown"}\`, "EISDIR", e, s);
|
|
283
|
+
case "NotAllowedError":
|
|
284
|
+
case "SecurityError":
|
|
285
|
+
return new p(\`Permission denied: \${e || "unknown"}\`, "EACCES", e, s);
|
|
286
|
+
case "InvalidModificationError":
|
|
287
|
+
return new p(\`Invalid modification: \${e || "unknown"}\`, "EINVAL", e, s);
|
|
288
|
+
case "AbortError":
|
|
289
|
+
return new p(\`Operation aborted: \${e || "unknown"}\`, "EINTR", e, s);
|
|
290
|
+
case "OperationError":
|
|
291
|
+
return new p(\`Operation failed: \${e || "unknown"}\`, "EIO", e, s);
|
|
292
|
+
case "TypeError":
|
|
293
|
+
return new p(\`Operation not supported: \${e || "unknown"}\`, "ENOTSUP", e, s);
|
|
311
294
|
default:
|
|
312
|
-
return
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
function Bt(s) {
|
|
316
|
-
const t = new Uint8Array(s.length * 2);
|
|
317
|
-
for (let e = 0; e < s.length; e++) {
|
|
318
|
-
const n = s.charCodeAt(e);
|
|
319
|
-
t[e * 2] = n & 255, t[e * 2 + 1] = n >> 8;
|
|
295
|
+
return new p(\`I/O error: \${e || "unknown"}\`, "EIO", e, s);
|
|
320
296
|
}
|
|
321
|
-
return t;
|
|
322
|
-
}
|
|
323
|
-
function Gt(s) {
|
|
324
|
-
s.length % 2 !== 0 && (console.warn("Invalid UTF-16LE buffer length, truncating last byte"), s = s.slice(0, s.length - 1));
|
|
325
|
-
const t = new Uint16Array(s.buffer, s.byteOffset, s.byteLength / 2);
|
|
326
|
-
return String.fromCharCode(...t);
|
|
327
|
-
}
|
|
328
|
-
function qt(s) {
|
|
329
|
-
const t = new Uint8Array(s.length);
|
|
330
|
-
for (let e = 0; e < s.length; e++)
|
|
331
|
-
t[e] = s.charCodeAt(e) & 255;
|
|
332
|
-
return t;
|
|
333
297
|
}
|
|
334
|
-
|
|
335
|
-
const
|
|
336
|
-
for (let e = 0; e < s.length; e++)
|
|
337
|
-
t[e] = s.charCodeAt(e) & 127;
|
|
338
|
-
return t;
|
|
339
|
-
}
|
|
340
|
-
const wt = (s, t, e) => {
|
|
341
|
-
const n = s instanceof RegExp ? nt(s, e) : s, i = t instanceof RegExp ? nt(t, e) : t, r = n !== null && i != null && Xt(n, i, e);
|
|
298
|
+
const St = (s, t, e) => {
|
|
299
|
+
const n = s instanceof RegExp ? it(s, e) : s, i = t instanceof RegExp ? it(t, e) : t, r = n !== null && i != null && Gt(n, i, e);
|
|
342
300
|
return r && {
|
|
343
301
|
start: r[0],
|
|
344
302
|
end: r[1],
|
|
@@ -346,10 +304,10 @@ const wt = (s, t, e) => {
|
|
|
346
304
|
body: e.slice(r[0] + n.length, r[1]),
|
|
347
305
|
post: e.slice(r[1] + i.length)
|
|
348
306
|
};
|
|
349
|
-
},
|
|
307
|
+
}, it = (s, t) => {
|
|
350
308
|
const e = t.match(s);
|
|
351
309
|
return e ? e[0] : null;
|
|
352
|
-
},
|
|
310
|
+
}, Gt = (s, t, e) => {
|
|
353
311
|
let n, i, r, o, a, l = e.indexOf(s), h = e.indexOf(t, l + 1), c = l;
|
|
354
312
|
if (l >= 0 && h > 0) {
|
|
355
313
|
if (s === t)
|
|
@@ -367,47 +325,47 @@ const wt = (s, t, e) => {
|
|
|
367
325
|
n.length && o !== void 0 && (a = [r, o]);
|
|
368
326
|
}
|
|
369
327
|
return a;
|
|
370
|
-
},
|
|
371
|
-
function
|
|
328
|
+
}, xt = "\\0SLASH" + Math.random() + "\\0", bt = "\\0OPEN" + Math.random() + "\\0", Q = "\\0CLOSE" + Math.random() + "\\0", vt = "\\0COMMA" + Math.random() + "\\0", At = "\\0PERIOD" + Math.random() + "\\0", qt = new RegExp(xt, "g"), Vt = new RegExp(bt, "g"), Xt = new RegExp(Q, "g"), Yt = new RegExp(vt, "g"), Zt = new RegExp(At, "g"), Jt = /\\\\\\\\/g, Kt = /\\\\{/g, Qt = /\\\\}/g, te = /\\\\,/g, ee = /\\\\./g;
|
|
329
|
+
function V(s) {
|
|
372
330
|
return isNaN(s) ? s.charCodeAt(0) : parseInt(s, 10);
|
|
373
331
|
}
|
|
374
|
-
function
|
|
375
|
-
return s.replace(
|
|
332
|
+
function se(s) {
|
|
333
|
+
return s.replace(Jt, xt).replace(Kt, bt).replace(Qt, Q).replace(te, vt).replace(ee, At);
|
|
376
334
|
}
|
|
377
|
-
function
|
|
378
|
-
return s.replace(
|
|
335
|
+
function ne(s) {
|
|
336
|
+
return s.replace(qt, "\\\\").replace(Vt, "{").replace(Xt, "}").replace(Yt, ",").replace(Zt, ".");
|
|
379
337
|
}
|
|
380
|
-
function
|
|
338
|
+
function Ft(s) {
|
|
381
339
|
if (!s)
|
|
382
340
|
return [""];
|
|
383
|
-
const t = [], e =
|
|
341
|
+
const t = [], e = St("{", "}", s);
|
|
384
342
|
if (!e)
|
|
385
343
|
return s.split(",");
|
|
386
344
|
const { pre: n, body: i, post: r } = e, o = n.split(",");
|
|
387
345
|
o[o.length - 1] += "{" + i + "}";
|
|
388
|
-
const a =
|
|
346
|
+
const a = Ft(r);
|
|
389
347
|
return r.length && (o[o.length - 1] += a.shift(), o.push.apply(o, a)), t.push.apply(t, o), t;
|
|
390
348
|
}
|
|
391
|
-
function
|
|
392
|
-
return s ? (s.slice(0, 2) === "{}" && (s = "\\\\{\\\\}" + s.slice(2)),
|
|
349
|
+
function ie(s) {
|
|
350
|
+
return s ? (s.slice(0, 2) === "{}" && (s = "\\\\{\\\\}" + s.slice(2)), T(se(s), !0).map(ne)) : [];
|
|
393
351
|
}
|
|
394
|
-
function
|
|
352
|
+
function re(s) {
|
|
395
353
|
return "{" + s + "}";
|
|
396
354
|
}
|
|
397
|
-
function
|
|
355
|
+
function oe(s) {
|
|
398
356
|
return /^-?0\\d/.test(s);
|
|
399
357
|
}
|
|
400
|
-
function
|
|
358
|
+
function ae(s, t) {
|
|
401
359
|
return s <= t;
|
|
402
360
|
}
|
|
403
|
-
function
|
|
361
|
+
function ce(s, t) {
|
|
404
362
|
return s >= t;
|
|
405
363
|
}
|
|
406
|
-
function
|
|
407
|
-
const e = [], n =
|
|
364
|
+
function T(s, t) {
|
|
365
|
+
const e = [], n = St("{", "}", s);
|
|
408
366
|
if (!n)
|
|
409
367
|
return [s];
|
|
410
|
-
const i = n.pre, r = n.post.length ?
|
|
368
|
+
const i = n.pre, r = n.post.length ? T(n.post, !1) : [""];
|
|
411
369
|
if (/\\$$/.test(n.pre))
|
|
412
370
|
for (let o = 0; o < r.length; o++) {
|
|
413
371
|
const a = i + "{" + n.body + "}" + r[o];
|
|
@@ -416,51 +374,51 @@ function M(s, t) {
|
|
|
416
374
|
else {
|
|
417
375
|
const o = /^-?\\d+\\.\\.-?\\d+(?:\\.\\.-?\\d+)?$/.test(n.body), a = /^[a-zA-Z]\\.\\.[a-zA-Z](?:\\.\\.-?\\d+)?$/.test(n.body), l = o || a, h = n.body.indexOf(",") >= 0;
|
|
418
376
|
if (!l && !h)
|
|
419
|
-
return n.post.match(/,(?!,).*\\}/) ? (s = n.pre + "{" + n.body +
|
|
377
|
+
return n.post.match(/,(?!,).*\\}/) ? (s = n.pre + "{" + n.body + Q + n.post, T(s)) : [s];
|
|
420
378
|
let c;
|
|
421
379
|
if (l)
|
|
422
380
|
c = n.body.split(/\\.\\./);
|
|
423
|
-
else if (c =
|
|
381
|
+
else if (c = Ft(n.body), c.length === 1 && c[0] !== void 0 && (c = T(c[0], !1).map(re), c.length === 1))
|
|
424
382
|
return r.map((u) => n.pre + c[0] + u);
|
|
425
383
|
let f;
|
|
426
384
|
if (l && c[0] !== void 0 && c[1] !== void 0) {
|
|
427
|
-
const u =
|
|
428
|
-
let
|
|
429
|
-
d < u && (
|
|
430
|
-
const
|
|
385
|
+
const u = V(c[0]), d = V(c[1]), w = Math.max(c[0].length, c[1].length);
|
|
386
|
+
let g = c.length === 3 && c[2] !== void 0 ? Math.abs(V(c[2])) : 1, S = ae;
|
|
387
|
+
d < u && (g *= -1, S = ce);
|
|
388
|
+
const O = c.some(oe);
|
|
431
389
|
f = [];
|
|
432
|
-
for (let x = u; S(x, d); x +=
|
|
433
|
-
let
|
|
390
|
+
for (let x = u; S(x, d); x += g) {
|
|
391
|
+
let y;
|
|
434
392
|
if (a)
|
|
435
|
-
|
|
436
|
-
else if (
|
|
437
|
-
const
|
|
438
|
-
if (
|
|
439
|
-
const
|
|
440
|
-
x < 0 ?
|
|
393
|
+
y = String.fromCharCode(x), y === "\\\\" && (y = "");
|
|
394
|
+
else if (y = String(x), O) {
|
|
395
|
+
const $ = w - y.length;
|
|
396
|
+
if ($ > 0) {
|
|
397
|
+
const I = new Array($ + 1).join("0");
|
|
398
|
+
x < 0 ? y = "-" + I + y.slice(1) : y = I + y;
|
|
441
399
|
}
|
|
442
400
|
}
|
|
443
|
-
f.push(
|
|
401
|
+
f.push(y);
|
|
444
402
|
}
|
|
445
403
|
} else {
|
|
446
404
|
f = [];
|
|
447
405
|
for (let u = 0; u < c.length; u++)
|
|
448
|
-
f.push.apply(f,
|
|
406
|
+
f.push.apply(f, T(c[u], !1));
|
|
449
407
|
}
|
|
450
408
|
for (let u = 0; u < f.length; u++)
|
|
451
409
|
for (let d = 0; d < r.length; d++) {
|
|
452
|
-
const
|
|
453
|
-
(!t || l ||
|
|
410
|
+
const w = i + f[u] + r[d];
|
|
411
|
+
(!t || l || w) && e.push(w);
|
|
454
412
|
}
|
|
455
413
|
}
|
|
456
414
|
return e;
|
|
457
415
|
}
|
|
458
|
-
const
|
|
416
|
+
const le = 1024 * 64, U = (s) => {
|
|
459
417
|
if (typeof s != "string")
|
|
460
418
|
throw new TypeError("invalid pattern");
|
|
461
|
-
if (s.length >
|
|
419
|
+
if (s.length > le)
|
|
462
420
|
throw new TypeError("pattern is too long");
|
|
463
|
-
},
|
|
421
|
+
}, he = {
|
|
464
422
|
"[:alnum:]": ["\\\\p{L}\\\\p{Nl}\\\\p{Nd}", !0],
|
|
465
423
|
"[:alpha:]": ["\\\\p{L}\\\\p{Nl}", !0],
|
|
466
424
|
"[:ascii:]": ["\\\\x00-\\\\x7f", !1],
|
|
@@ -475,60 +433,60 @@ const fe = 1024 * 64, W = (s) => {
|
|
|
475
433
|
"[:upper:]": ["\\\\p{Lu}", !0],
|
|
476
434
|
"[:word:]": ["\\\\p{L}\\\\p{Nl}\\\\p{Nd}\\\\p{Pc}", !0],
|
|
477
435
|
"[:xdigit:]": ["A-Fa-f0-9", !1]
|
|
478
|
-
},
|
|
436
|
+
}, C = (s) => s.replace(/[[\\]\\\\-]/g, "\\\\$&"), ue = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&"), rt = (s) => s.join(""), fe = (s, t) => {
|
|
479
437
|
const e = t;
|
|
480
438
|
if (s.charAt(e) !== "[")
|
|
481
439
|
throw new Error("not in a brace expression");
|
|
482
440
|
const n = [], i = [];
|
|
483
441
|
let r = e + 1, o = !1, a = !1, l = !1, h = !1, c = e, f = "";
|
|
484
442
|
t: for (; r < s.length; ) {
|
|
485
|
-
const
|
|
486
|
-
if ((
|
|
443
|
+
const g = s.charAt(r);
|
|
444
|
+
if ((g === "!" || g === "^") && r === e + 1) {
|
|
487
445
|
h = !0, r++;
|
|
488
446
|
continue;
|
|
489
447
|
}
|
|
490
|
-
if (
|
|
448
|
+
if (g === "]" && o && !l) {
|
|
491
449
|
c = r + 1;
|
|
492
450
|
break;
|
|
493
451
|
}
|
|
494
|
-
if (o = !0,
|
|
452
|
+
if (o = !0, g === "\\\\" && !l) {
|
|
495
453
|
l = !0, r++;
|
|
496
454
|
continue;
|
|
497
455
|
}
|
|
498
|
-
if (
|
|
499
|
-
for (const [S, [A,
|
|
456
|
+
if (g === "[" && !l) {
|
|
457
|
+
for (const [S, [A, O, x]] of Object.entries(he))
|
|
500
458
|
if (s.startsWith(S, r)) {
|
|
501
459
|
if (f)
|
|
502
460
|
return ["$.", !1, s.length - e, !0];
|
|
503
|
-
r += S.length, x ? i.push(A) : n.push(A), a = a ||
|
|
461
|
+
r += S.length, x ? i.push(A) : n.push(A), a = a || O;
|
|
504
462
|
continue t;
|
|
505
463
|
}
|
|
506
464
|
}
|
|
507
465
|
if (l = !1, f) {
|
|
508
|
-
|
|
466
|
+
g > f ? n.push(C(f) + "-" + C(g)) : g === f && n.push(C(g)), f = "", r++;
|
|
509
467
|
continue;
|
|
510
468
|
}
|
|
511
469
|
if (s.startsWith("-]", r + 1)) {
|
|
512
|
-
n.push(
|
|
470
|
+
n.push(C(g + "-")), r += 2;
|
|
513
471
|
continue;
|
|
514
472
|
}
|
|
515
473
|
if (s.startsWith("-", r + 1)) {
|
|
516
|
-
f =
|
|
474
|
+
f = g, r += 2;
|
|
517
475
|
continue;
|
|
518
476
|
}
|
|
519
|
-
n.push(
|
|
477
|
+
n.push(C(g)), r++;
|
|
520
478
|
}
|
|
521
479
|
if (c < r)
|
|
522
480
|
return ["", !1, 0, !1];
|
|
523
481
|
if (!n.length && !i.length)
|
|
524
482
|
return ["$.", !1, s.length - e, !0];
|
|
525
483
|
if (i.length === 0 && n.length === 1 && /^\\\\?.$/.test(n[0]) && !h) {
|
|
526
|
-
const
|
|
527
|
-
return [
|
|
484
|
+
const g = n[0].length === 2 ? n[0].slice(-1) : n[0];
|
|
485
|
+
return [ue(g), !1, c - e, !1];
|
|
528
486
|
}
|
|
529
|
-
const u = "[" + (h ? "^" : "") +
|
|
487
|
+
const u = "[" + (h ? "^" : "") + rt(n) + "]", d = "[" + (h ? "" : "^") + rt(i) + "]";
|
|
530
488
|
return [n.length && i.length ? "(" + u + "|" + d + ")" : n.length ? u : d, a, c - e, !0];
|
|
531
|
-
},
|
|
489
|
+
}, M = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/\\[([^\\/\\\\])\\]/g, "$1") : s.replace(/((?!\\\\).|^)\\[([^\\/\\\\])\\]/g, "$1$2").replace(/\\\\([^\\/])/g, "$1"), de = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]), ot = (s) => de.has(s), pe = "(?!(?:^|/)\\\\.\\\\.?(?:$|/))", L = "(?!\\\\.)", ge = /* @__PURE__ */ new Set(["[", "."]), we = /* @__PURE__ */ new Set(["..", "."]), ye = new Set("().*{}+?[]^$\\\\!"), me = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&"), tt = "[^/]", at = tt + "*?", ct = tt + "+?";
|
|
532
490
|
class E {
|
|
533
491
|
type;
|
|
534
492
|
#s;
|
|
@@ -631,29 +589,29 @@ class E {
|
|
|
631
589
|
static #h(t, e, n, i) {
|
|
632
590
|
let r = !1, o = !1, a = -1, l = !1;
|
|
633
591
|
if (e.type === null) {
|
|
634
|
-
let d = n,
|
|
592
|
+
let d = n, w = "";
|
|
635
593
|
for (; d < t.length; ) {
|
|
636
|
-
const
|
|
637
|
-
if (r ||
|
|
638
|
-
r = !r,
|
|
594
|
+
const g = t.charAt(d++);
|
|
595
|
+
if (r || g === "\\\\") {
|
|
596
|
+
r = !r, w += g;
|
|
639
597
|
continue;
|
|
640
598
|
}
|
|
641
599
|
if (o) {
|
|
642
|
-
d === a + 1 ? (
|
|
600
|
+
d === a + 1 ? (g === "^" || g === "!") && (l = !0) : g === "]" && !(d === a + 2 && l) && (o = !1), w += g;
|
|
643
601
|
continue;
|
|
644
|
-
} else if (
|
|
645
|
-
o = !0, a = d, l = !1,
|
|
602
|
+
} else if (g === "[") {
|
|
603
|
+
o = !0, a = d, l = !1, w += g;
|
|
646
604
|
continue;
|
|
647
605
|
}
|
|
648
|
-
if (!i.noext &&
|
|
649
|
-
e.push(
|
|
650
|
-
const S = new E(
|
|
606
|
+
if (!i.noext && ot(g) && t.charAt(d) === "(") {
|
|
607
|
+
e.push(w), w = "";
|
|
608
|
+
const S = new E(g, e);
|
|
651
609
|
d = E.#h(t, S, d, i), e.push(S);
|
|
652
610
|
continue;
|
|
653
611
|
}
|
|
654
|
-
|
|
612
|
+
w += g;
|
|
655
613
|
}
|
|
656
|
-
return e.push(
|
|
614
|
+
return e.push(w), d;
|
|
657
615
|
}
|
|
658
616
|
let h = n + 1, c = new E(null, e);
|
|
659
617
|
const f = [];
|
|
@@ -671,10 +629,10 @@ class E {
|
|
|
671
629
|
o = !0, a = h, l = !1, u += d;
|
|
672
630
|
continue;
|
|
673
631
|
}
|
|
674
|
-
if (
|
|
632
|
+
if (ot(d) && t.charAt(h) === "(") {
|
|
675
633
|
c.push(u), u = "";
|
|
676
|
-
const
|
|
677
|
-
c.push(
|
|
634
|
+
const w = new E(d, c);
|
|
635
|
+
c.push(w), h = E.#h(t, w, h, i);
|
|
678
636
|
continue;
|
|
679
637
|
}
|
|
680
638
|
if (d === "|") {
|
|
@@ -781,23 +739,23 @@ class E {
|
|
|
781
739
|
const e = t ?? !!this.#i.dot;
|
|
782
740
|
if (this.#s === this && this.#d(), !this.type) {
|
|
783
741
|
const l = this.isStart() && this.isEnd(), h = this.#t.map((d) => {
|
|
784
|
-
const [
|
|
785
|
-
return this.#n = this.#n || S, this.#r = this.#r || A,
|
|
742
|
+
const [w, g, S, A] = typeof d == "string" ? E.#p(d, this.#n, l) : d.toRegExpSource(t);
|
|
743
|
+
return this.#n = this.#n || S, this.#r = this.#r || A, w;
|
|
786
744
|
}).join("");
|
|
787
745
|
let c = "";
|
|
788
|
-
if (this.isStart() && typeof this.#t[0] == "string" && !(this.#t.length === 1 &&
|
|
789
|
-
const
|
|
746
|
+
if (this.isStart() && typeof this.#t[0] == "string" && !(this.#t.length === 1 && we.has(this.#t[0]))) {
|
|
747
|
+
const w = ge, g = (
|
|
790
748
|
// dots are allowed, and the pattern starts with [ or .
|
|
791
|
-
e &&
|
|
792
|
-
h.startsWith("\\\\.") &&
|
|
793
|
-
h.startsWith("\\\\.\\\\.") &&
|
|
794
|
-
), S = !e && !t &&
|
|
795
|
-
c =
|
|
749
|
+
e && w.has(h.charAt(0)) || // the pattern starts with \\., and then [ or .
|
|
750
|
+
h.startsWith("\\\\.") && w.has(h.charAt(2)) || // the pattern starts with \\.\\., and then [ or .
|
|
751
|
+
h.startsWith("\\\\.\\\\.") && w.has(h.charAt(4))
|
|
752
|
+
), S = !e && !t && w.has(h.charAt(0));
|
|
753
|
+
c = g ? pe : S ? L : "";
|
|
796
754
|
}
|
|
797
755
|
let f = "";
|
|
798
756
|
return this.isEnd() && this.#s.#a && this.#e?.type === "!" && (f = "(?:$|\\\\/)"), [
|
|
799
757
|
c + h + f,
|
|
800
|
-
|
|
758
|
+
M(h),
|
|
801
759
|
this.#n = !!this.#n,
|
|
802
760
|
this.#r
|
|
803
761
|
];
|
|
@@ -806,23 +764,23 @@ class E {
|
|
|
806
764
|
let r = this.#f(e);
|
|
807
765
|
if (this.isStart() && this.isEnd() && !r && this.type !== "!") {
|
|
808
766
|
const l = this.toString();
|
|
809
|
-
return this.#t = [l], this.type = null, this.#n = void 0, [l,
|
|
767
|
+
return this.#t = [l], this.type = null, this.#n = void 0, [l, M(this.toString()), !1, !1];
|
|
810
768
|
}
|
|
811
|
-
let o = !n || t || e || !
|
|
769
|
+
let o = !n || t || e || !L ? "" : this.#f(!0);
|
|
812
770
|
o === r && (o = ""), o && (r = \`(?:\${r})(?:\${o})*?\`);
|
|
813
771
|
let a = "";
|
|
814
772
|
if (this.type === "!" && this.#u)
|
|
815
|
-
a = (this.isStart() && !e ?
|
|
773
|
+
a = (this.isStart() && !e ? L : "") + ct;
|
|
816
774
|
else {
|
|
817
775
|
const l = this.type === "!" ? (
|
|
818
776
|
// !() must match something,but !(x) can match ''
|
|
819
|
-
"))" + (this.isStart() && !e && !t ?
|
|
777
|
+
"))" + (this.isStart() && !e && !t ? L : "") + at + ")"
|
|
820
778
|
) : this.type === "@" ? ")" : this.type === "?" ? ")?" : this.type === "+" && o ? ")" : this.type === "*" && o ? ")?" : \`)\${this.type}\`;
|
|
821
779
|
a = i + r + l;
|
|
822
780
|
}
|
|
823
781
|
return [
|
|
824
782
|
a,
|
|
825
|
-
|
|
783
|
+
M(r),
|
|
826
784
|
this.#n = !!this.#n,
|
|
827
785
|
this.#r
|
|
828
786
|
];
|
|
@@ -840,7 +798,7 @@ class E {
|
|
|
840
798
|
for (let a = 0; a < t.length; a++) {
|
|
841
799
|
const l = t.charAt(a);
|
|
842
800
|
if (i) {
|
|
843
|
-
i = !1, r += (
|
|
801
|
+
i = !1, r += (ye.has(l) ? "\\\\" : "") + l;
|
|
844
802
|
continue;
|
|
845
803
|
}
|
|
846
804
|
if (l === "\\\\") {
|
|
@@ -848,56 +806,56 @@ class E {
|
|
|
848
806
|
continue;
|
|
849
807
|
}
|
|
850
808
|
if (l === "[") {
|
|
851
|
-
const [h, c, f, u] =
|
|
809
|
+
const [h, c, f, u] = fe(t, a);
|
|
852
810
|
if (f) {
|
|
853
811
|
r += h, o = o || c, a += f - 1, e = e || u;
|
|
854
812
|
continue;
|
|
855
813
|
}
|
|
856
814
|
}
|
|
857
815
|
if (l === "*") {
|
|
858
|
-
n && t === "*" ? r +=
|
|
816
|
+
n && t === "*" ? r += ct : r += at, e = !0;
|
|
859
817
|
continue;
|
|
860
818
|
}
|
|
861
819
|
if (l === "?") {
|
|
862
|
-
r +=
|
|
820
|
+
r += tt, e = !0;
|
|
863
821
|
continue;
|
|
864
822
|
}
|
|
865
|
-
r +=
|
|
823
|
+
r += me(l);
|
|
866
824
|
}
|
|
867
|
-
return [r,
|
|
825
|
+
return [r, M(t), !!e, o];
|
|
868
826
|
}
|
|
869
827
|
}
|
|
870
|
-
const
|
|
871
|
-
const e =
|
|
828
|
+
const Ee = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/[?*()[\\]]/g, "[$&]") : s.replace(/[?*()[\\]\\\\]/g, "\\\\$&"), m = (s, t, e = {}) => (U(t), !e.nocomment && t.charAt(0) === "#" ? !1 : new G(t, e).match(s)), Se = /^\\*+([^+@!?\\*\\[\\(]*)$/, xe = (s) => (t) => !t.startsWith(".") && t.endsWith(s), be = (s) => (t) => t.endsWith(s), ve = (s) => (s = s.toLowerCase(), (t) => !t.startsWith(".") && t.toLowerCase().endsWith(s)), Ae = (s) => (s = s.toLowerCase(), (t) => t.toLowerCase().endsWith(s)), Fe = /^\\*+\\.\\*+$/, Ne = (s) => !s.startsWith(".") && s.includes("."), De = (s) => s !== "." && s !== ".." && s.includes("."), Oe = /^\\.\\*+$/, $e = (s) => s !== "." && s !== ".." && s.startsWith("."), Ce = /^\\*+$/, Te = (s) => s.length !== 0 && !s.startsWith("."), Me = (s) => s.length !== 0 && s !== "." && s !== "..", Pe = /^\\?+([^+@!?\\*\\[\\(]*)?$/, Ie = ([s, t = ""]) => {
|
|
829
|
+
const e = Nt([s]);
|
|
872
830
|
return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
|
|
873
|
-
},
|
|
874
|
-
const e =
|
|
831
|
+
}, ke = ([s, t = ""]) => {
|
|
832
|
+
const e = Dt([s]);
|
|
875
833
|
return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
|
|
876
|
-
},
|
|
877
|
-
const e =
|
|
834
|
+
}, Re = ([s, t = ""]) => {
|
|
835
|
+
const e = Dt([s]);
|
|
878
836
|
return t ? (n) => e(n) && n.endsWith(t) : e;
|
|
879
|
-
},
|
|
880
|
-
const e =
|
|
837
|
+
}, Le = ([s, t = ""]) => {
|
|
838
|
+
const e = Nt([s]);
|
|
881
839
|
return t ? (n) => e(n) && n.endsWith(t) : e;
|
|
882
|
-
},
|
|
840
|
+
}, Nt = ([s]) => {
|
|
883
841
|
const t = s.length;
|
|
884
842
|
return (e) => e.length === t && !e.startsWith(".");
|
|
885
|
-
},
|
|
843
|
+
}, Dt = ([s]) => {
|
|
886
844
|
const t = s.length;
|
|
887
845
|
return (e) => e.length === t && e !== "." && e !== "..";
|
|
888
|
-
},
|
|
846
|
+
}, Ot = typeof process == "object" && process ? typeof process.env == "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix", lt = {
|
|
889
847
|
win32: { sep: "\\\\" },
|
|
890
848
|
posix: { sep: "/" }
|
|
891
|
-
},
|
|
892
|
-
|
|
849
|
+
}, ze = Ot === "win32" ? lt.win32.sep : lt.posix.sep;
|
|
850
|
+
m.sep = ze;
|
|
893
851
|
const v = Symbol("globstar **");
|
|
894
|
-
|
|
895
|
-
const
|
|
896
|
-
|
|
897
|
-
const b = (s, t = {}) => Object.assign({}, s, t),
|
|
852
|
+
m.GLOBSTAR = v;
|
|
853
|
+
const He = "[^/]", We = He + "*?", _e = "(?:(?!(?:\\\\/|^)(?:\\\\.{1,2})($|\\\\/)).)*?", je = "(?:(?!(?:\\\\/|^)\\\\.).)*?", Be = (s, t = {}) => (e) => m(e, s, t);
|
|
854
|
+
m.filter = Be;
|
|
855
|
+
const b = (s, t = {}) => Object.assign({}, s, t), Ue = (s) => {
|
|
898
856
|
if (!s || typeof s != "object" || !Object.keys(s).length)
|
|
899
|
-
return
|
|
900
|
-
const t =
|
|
857
|
+
return m;
|
|
858
|
+
const t = m;
|
|
901
859
|
return Object.assign((n, i, r = {}) => t(n, i, b(s, r)), {
|
|
902
860
|
Minimatch: class extends t.Minimatch {
|
|
903
861
|
constructor(i, r = {}) {
|
|
@@ -928,18 +886,18 @@ const b = (s, t = {}) => Object.assign({}, s, t), Ve = (s) => {
|
|
|
928
886
|
GLOBSTAR: v
|
|
929
887
|
});
|
|
930
888
|
};
|
|
931
|
-
|
|
932
|
-
const
|
|
933
|
-
|
|
934
|
-
const
|
|
935
|
-
|
|
936
|
-
const
|
|
937
|
-
const n = new
|
|
889
|
+
m.defaults = Ue;
|
|
890
|
+
const $t = (s, t = {}) => (U(s), t.nobrace || !/\\{(?:(?!\\{).)*\\}/.test(s) ? [s] : ie(s));
|
|
891
|
+
m.braceExpand = $t;
|
|
892
|
+
const Ge = (s, t = {}) => new G(s, t).makeRe();
|
|
893
|
+
m.makeRe = Ge;
|
|
894
|
+
const qe = (s, t, e = {}) => {
|
|
895
|
+
const n = new G(t, e);
|
|
938
896
|
return s = s.filter((i) => n.match(i)), n.options.nonull && !s.length && s.push(t), s;
|
|
939
897
|
};
|
|
940
|
-
|
|
941
|
-
const
|
|
942
|
-
class
|
|
898
|
+
m.match = qe;
|
|
899
|
+
const ht = /[?*]|[+@!]\\(.*?\\)|\\[|\\]/, Ve = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&");
|
|
900
|
+
class G {
|
|
943
901
|
options;
|
|
944
902
|
set;
|
|
945
903
|
pattern;
|
|
@@ -958,7 +916,7 @@ class j {
|
|
|
958
916
|
windowsNoMagicRoot;
|
|
959
917
|
regexp;
|
|
960
918
|
constructor(t, e = {}) {
|
|
961
|
-
|
|
919
|
+
U(t), e = e || {}, this.options = e, this.pattern = t, this.platform = e.platform || Ot, this.isWindows = this.platform === "win32", this.windowsPathsNoEscape = !!e.windowsPathsNoEscape || e.allowWindowsEscape === !1, this.windowsPathsNoEscape && (this.pattern = this.pattern.replace(/\\\\/g, "/")), this.preserveMultipleSlashes = !!e.preserveMultipleSlashes, this.regexp = null, this.negate = !1, this.nonegate = !!e.nonegate, this.comment = !1, this.empty = !1, this.partial = !!e.partial, this.nocase = !!this.options.nocase, this.windowsNoMagicRoot = e.windowsNoMagicRoot !== void 0 ? e.windowsNoMagicRoot : !!(this.isWindows && this.nocase), this.globSet = [], this.globParts = [], this.set = [], this.make();
|
|
962
920
|
}
|
|
963
921
|
hasMagic() {
|
|
964
922
|
if (this.options.magicalBraces && this.set.length > 1)
|
|
@@ -986,7 +944,7 @@ class j {
|
|
|
986
944
|
this.globParts = this.preprocess(n), this.debug(this.pattern, this.globParts);
|
|
987
945
|
let i = this.globParts.map((r, o, a) => {
|
|
988
946
|
if (this.isWindows && this.windowsNoMagicRoot) {
|
|
989
|
-
const l = r[0] === "" && r[1] === "" && (r[2] === "?" || !
|
|
947
|
+
const l = r[0] === "" && r[1] === "" && (r[2] === "?" || !ht.test(r[2])) && !ht.test(r[3]), h = /^[a-z]:/i.test(r[0]);
|
|
990
948
|
if (l)
|
|
991
949
|
return [...r.slice(0, 4), ...r.slice(4).map((c) => this.parse(c))];
|
|
992
950
|
if (h)
|
|
@@ -1166,10 +1124,10 @@ class j {
|
|
|
1166
1124
|
matchOne(t, e, n = !1) {
|
|
1167
1125
|
const i = this.options;
|
|
1168
1126
|
if (this.isWindows) {
|
|
1169
|
-
const
|
|
1170
|
-
if (typeof x == "number" && typeof
|
|
1171
|
-
const [
|
|
1172
|
-
|
|
1127
|
+
const g = typeof t[0] == "string" && /^[a-z]:$/i.test(t[0]), S = !g && t[0] === "" && t[1] === "" && t[2] === "?" && /^[a-z]:$/i.test(t[3]), A = typeof e[0] == "string" && /^[a-z]:$/i.test(e[0]), O = !A && e[0] === "" && e[1] === "" && e[2] === "?" && typeof e[3] == "string" && /^[a-z]:$/i.test(e[3]), x = S ? 3 : g ? 0 : void 0, y = O ? 3 : A ? 0 : void 0;
|
|
1128
|
+
if (typeof x == "number" && typeof y == "number") {
|
|
1129
|
+
const [$, I] = [t[x], e[y]];
|
|
1130
|
+
$.toLowerCase() === I.toLowerCase() && (e[y] = $, y > x ? e = e.slice(y) : x > y && (t = t.slice(x)));
|
|
1173
1131
|
}
|
|
1174
1132
|
}
|
|
1175
1133
|
const { optimizationLevel: r = 1 } = this.options;
|
|
@@ -1189,11 +1147,11 @@ class j {
|
|
|
1189
1147
|
return !0;
|
|
1190
1148
|
}
|
|
1191
1149
|
for (; u < l; ) {
|
|
1192
|
-
var
|
|
1150
|
+
var w = t[u];
|
|
1193
1151
|
if (this.debug(\`
|
|
1194
|
-
globstar while\`, t, u, e, d,
|
|
1195
|
-
return this.debug("globstar found match!", u, l,
|
|
1196
|
-
if (
|
|
1152
|
+
globstar while\`, t, u, e, d, w), this.matchOne(t.slice(u), e.slice(d), n))
|
|
1153
|
+
return this.debug("globstar found match!", u, l, w), !0;
|
|
1154
|
+
if (w === "." || w === ".." || !i.dot && w.charAt(0) === ".") {
|
|
1197
1155
|
this.debug("dot detected!", t, u, e, d);
|
|
1198
1156
|
break;
|
|
1199
1157
|
}
|
|
@@ -1202,8 +1160,8 @@ globstar while\`, t, u, e, d, m), this.matchOne(t.slice(u), e.slice(d), n))
|
|
|
1202
1160
|
return !!(n && (this.debug(\`
|
|
1203
1161
|
>>> no match, partial?\`, t, u, e, d), u === l));
|
|
1204
1162
|
}
|
|
1205
|
-
let
|
|
1206
|
-
if (typeof c == "string" ? (
|
|
1163
|
+
let g;
|
|
1164
|
+
if (typeof c == "string" ? (g = f === c, this.debug("string match", c, f, g)) : (g = c.test(f), this.debug("pattern match", c, f, g)), !g)
|
|
1207
1165
|
return !1;
|
|
1208
1166
|
}
|
|
1209
1167
|
if (o === l && a === h)
|
|
@@ -1215,17 +1173,17 @@ globstar while\`, t, u, e, d, m), this.matchOne(t.slice(u), e.slice(d), n))
|
|
|
1215
1173
|
throw new Error("wtf?");
|
|
1216
1174
|
}
|
|
1217
1175
|
braceExpand() {
|
|
1218
|
-
return
|
|
1176
|
+
return $t(this.pattern, this.options);
|
|
1219
1177
|
}
|
|
1220
1178
|
parse(t) {
|
|
1221
|
-
|
|
1179
|
+
U(t);
|
|
1222
1180
|
const e = this.options;
|
|
1223
1181
|
if (t === "**")
|
|
1224
1182
|
return v;
|
|
1225
1183
|
if (t === "")
|
|
1226
1184
|
return "";
|
|
1227
1185
|
let n, i = null;
|
|
1228
|
-
(n = t.match(
|
|
1186
|
+
(n = t.match(Ce)) ? i = e.dot ? Me : Te : (n = t.match(Se)) ? i = (e.nocase ? e.dot ? Ae : ve : e.dot ? be : xe)(n[1]) : (n = t.match(Pe)) ? i = (e.nocase ? e.dot ? ke : Ie : e.dot ? Re : Le)(n) : (n = t.match(Fe)) ? i = e.dot ? De : Ne : (n = t.match(Oe)) && (i = $e);
|
|
1229
1187
|
const r = E.fromGlob(t, this.options).toMMPattern();
|
|
1230
1188
|
return i && typeof r == "object" && Reflect.defineProperty(r, "test", { value: i }), r;
|
|
1231
1189
|
}
|
|
@@ -1235,13 +1193,13 @@ globstar while\`, t, u, e, d, m), this.matchOne(t.slice(u), e.slice(d), n))
|
|
|
1235
1193
|
const t = this.set;
|
|
1236
1194
|
if (!t.length)
|
|
1237
1195
|
return this.regexp = !1, this.regexp;
|
|
1238
|
-
const e = this.options, n = e.noglobstar ?
|
|
1196
|
+
const e = this.options, n = e.noglobstar ? We : e.dot ? _e : je, i = new Set(e.nocase ? ["i"] : []);
|
|
1239
1197
|
let r = t.map((l) => {
|
|
1240
1198
|
const h = l.map((c) => {
|
|
1241
1199
|
if (c instanceof RegExp)
|
|
1242
1200
|
for (const f of c.flags.split(""))
|
|
1243
1201
|
i.add(f);
|
|
1244
|
-
return typeof c == "string" ?
|
|
1202
|
+
return typeof c == "string" ? Ve(c) : c === v ? v : c._src;
|
|
1245
1203
|
});
|
|
1246
1204
|
return h.forEach((c, f) => {
|
|
1247
1205
|
const u = h[f + 1], d = h[f - 1];
|
|
@@ -1286,82 +1244,19 @@ globstar while\`, t, u, e, d, m), this.matchOne(t.slice(u), e.slice(d), n))
|
|
|
1286
1244
|
return n.flipNegate ? !1 : this.negate;
|
|
1287
1245
|
}
|
|
1288
1246
|
static defaults(t) {
|
|
1289
|
-
return
|
|
1247
|
+
return m.defaults(t).Minimatch;
|
|
1290
1248
|
}
|
|
1291
1249
|
}
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
// Images
|
|
1298
|
-
".jpg",
|
|
1299
|
-
".jpeg",
|
|
1300
|
-
".png",
|
|
1301
|
-
".gif",
|
|
1302
|
-
".bmp",
|
|
1303
|
-
".webp",
|
|
1304
|
-
".svg",
|
|
1305
|
-
".ico",
|
|
1306
|
-
".tiff",
|
|
1307
|
-
".tga",
|
|
1308
|
-
// Audio
|
|
1309
|
-
".mp3",
|
|
1310
|
-
".wav",
|
|
1311
|
-
".ogg",
|
|
1312
|
-
".flac",
|
|
1313
|
-
".aac",
|
|
1314
|
-
".wma",
|
|
1315
|
-
".m4a",
|
|
1316
|
-
// Video
|
|
1317
|
-
".mp4",
|
|
1318
|
-
".avi",
|
|
1319
|
-
".mov",
|
|
1320
|
-
".wmv",
|
|
1321
|
-
".flv",
|
|
1322
|
-
".webm",
|
|
1323
|
-
".mkv",
|
|
1324
|
-
".m4v",
|
|
1325
|
-
// Documents
|
|
1326
|
-
".pdf",
|
|
1327
|
-
".doc",
|
|
1328
|
-
".docx",
|
|
1329
|
-
".xls",
|
|
1330
|
-
".xlsx",
|
|
1331
|
-
".ppt",
|
|
1332
|
-
".pptx",
|
|
1333
|
-
// Archives
|
|
1334
|
-
".zip",
|
|
1335
|
-
".rar",
|
|
1336
|
-
".7z",
|
|
1337
|
-
".tar",
|
|
1338
|
-
".gz",
|
|
1339
|
-
".bz2",
|
|
1340
|
-
// Executables
|
|
1341
|
-
".exe",
|
|
1342
|
-
".dll",
|
|
1343
|
-
".so",
|
|
1344
|
-
".dylib",
|
|
1345
|
-
".bin",
|
|
1346
|
-
// Other binary formats
|
|
1347
|
-
".dat",
|
|
1348
|
-
".db",
|
|
1349
|
-
".sqlite",
|
|
1350
|
-
".bin",
|
|
1351
|
-
".obj",
|
|
1352
|
-
".fbx",
|
|
1353
|
-
".3ds"
|
|
1354
|
-
];
|
|
1355
|
-
function G(s) {
|
|
1356
|
-
const t = s.toLowerCase().substring(s.lastIndexOf("."));
|
|
1357
|
-
return Je.includes(t);
|
|
1358
|
-
}
|
|
1359
|
-
function Ke() {
|
|
1250
|
+
m.AST = E;
|
|
1251
|
+
m.Minimatch = G;
|
|
1252
|
+
m.escape = Ee;
|
|
1253
|
+
m.unescape = M;
|
|
1254
|
+
function Xe() {
|
|
1360
1255
|
if (!("storage" in navigator) || !("getDirectory" in navigator.storage))
|
|
1361
|
-
throw new
|
|
1256
|
+
throw new jt();
|
|
1362
1257
|
}
|
|
1363
|
-
async function
|
|
1364
|
-
return typeof navigator < "u" && navigator.locks?.request ? navigator.locks.request(\`opfs:\${s.replace(/\\/+/g, "/")
|
|
1258
|
+
async function P(s, t, e) {
|
|
1259
|
+
return typeof navigator < "u" && navigator.locks?.request ? navigator.locks.request(\`opfs:\${s.replace(/\\/+/g, "/")}\`, { mode: t }, e) : e();
|
|
1365
1260
|
}
|
|
1366
1261
|
function D(s) {
|
|
1367
1262
|
return Array.isArray(s) ? s : (s.startsWith("~/") ? s.slice(2) : s).split("/").filter(Boolean);
|
|
@@ -1369,28 +1264,28 @@ function D(s) {
|
|
|
1369
1264
|
function et(s) {
|
|
1370
1265
|
return typeof s == "string" ? s ?? "/" : \`/\${s.join("/")}\`;
|
|
1371
1266
|
}
|
|
1372
|
-
function
|
|
1267
|
+
function J(s) {
|
|
1373
1268
|
const t = D(s);
|
|
1374
1269
|
return t[t.length - 1] || "";
|
|
1375
1270
|
}
|
|
1376
|
-
function
|
|
1271
|
+
function X(s) {
|
|
1377
1272
|
const t = D(s);
|
|
1378
1273
|
return t.pop(), et(t);
|
|
1379
1274
|
}
|
|
1380
|
-
function
|
|
1275
|
+
function W(s) {
|
|
1381
1276
|
return !s || s === "/" ? "/" : s.startsWith("~/") ? \`/\${s.slice(2)}\` : s.startsWith("/") ? s : \`/\${s}\`;
|
|
1382
1277
|
}
|
|
1383
|
-
function
|
|
1278
|
+
function Ye(s, t = !1) {
|
|
1384
1279
|
return s = s.replace(/\\/$/, ""), t && !s.includes("*") ? \`\${s}/**\` : s;
|
|
1385
1280
|
}
|
|
1386
|
-
function
|
|
1387
|
-
return
|
|
1281
|
+
function Y(s, t) {
|
|
1282
|
+
return m(s, t, {
|
|
1388
1283
|
dot: !0,
|
|
1389
1284
|
matchBase: !0
|
|
1390
1285
|
});
|
|
1391
1286
|
}
|
|
1392
|
-
function
|
|
1393
|
-
const t =
|
|
1287
|
+
function ut(s) {
|
|
1288
|
+
const t = W(s), e = D(t), n = [];
|
|
1394
1289
|
for (const i of e)
|
|
1395
1290
|
if (!(i === "." || i === ""))
|
|
1396
1291
|
if (i === "..") {
|
|
@@ -1401,49 +1296,19 @@ function ts(s) {
|
|
|
1401
1296
|
n.push(i);
|
|
1402
1297
|
return et(n);
|
|
1403
1298
|
}
|
|
1404
|
-
function
|
|
1405
|
-
return typeof s == "string" ? Ut(s, t) : s instanceof Uint8Array ? s : new Uint8Array(s);
|
|
1406
|
-
}
|
|
1407
|
-
async function ss(s, t) {
|
|
1408
|
-
return tt(t, "shared", async () => {
|
|
1409
|
-
const n = await (await s.getFile()).arrayBuffer();
|
|
1410
|
-
return new Uint8Array(n);
|
|
1411
|
-
});
|
|
1412
|
-
}
|
|
1413
|
-
async function ht(s, t, e, n, i = {}) {
|
|
1414
|
-
const r = async () => {
|
|
1415
|
-
let o = null;
|
|
1416
|
-
const a = i.append || !1, l = !a && (i.truncate ?? !0);
|
|
1417
|
-
try {
|
|
1418
|
-
o = await s.createSyncAccessHandle();
|
|
1419
|
-
const h = es(t, e), c = a ? o.getSize() : 0;
|
|
1420
|
-
o.write(h, { at: c }), l && o.truncate(h.byteLength), o.flush();
|
|
1421
|
-
} catch (h) {
|
|
1422
|
-
console.error(h);
|
|
1423
|
-
const c = a ? "append" : "write";
|
|
1424
|
-
throw new g(\`Failed to \${c} file\`, \`\${c.toUpperCase()}_FAILED\`, void 0, h);
|
|
1425
|
-
} finally {
|
|
1426
|
-
try {
|
|
1427
|
-
o?.close();
|
|
1428
|
-
} catch {
|
|
1429
|
-
}
|
|
1430
|
-
}
|
|
1431
|
-
};
|
|
1432
|
-
return n ? tt(n, "exclusive", r) : r();
|
|
1433
|
-
}
|
|
1434
|
-
async function ns(s, t = "SHA-1", e = 50 * 1024 * 1024) {
|
|
1299
|
+
async function Ze(s, t = "SHA-1", e = 50 * 1024 * 1024) {
|
|
1435
1300
|
if (s instanceof File && (s = await s.arrayBuffer()), s.byteLength > e)
|
|
1436
1301
|
throw new Error(\`File size \${s.byteLength} bytes exceeds maximum allowed size \${e} bytes\`);
|
|
1437
1302
|
const n = new Uint8Array(s), i = await crypto.subtle.digest(t, n);
|
|
1438
1303
|
return Array.from(new Uint8Array(i)).map((o) => o.toString(16).padStart(2, "0")).join("");
|
|
1439
1304
|
}
|
|
1440
|
-
async function
|
|
1305
|
+
async function Je(s) {
|
|
1441
1306
|
const t = await s.arrayBuffer();
|
|
1442
1307
|
return new Uint8Array(t);
|
|
1443
1308
|
}
|
|
1444
|
-
async function
|
|
1445
|
-
const n =
|
|
1446
|
-
return
|
|
1309
|
+
async function Ke(s, t, e = {}) {
|
|
1310
|
+
const n = J(t);
|
|
1311
|
+
return P(t, "exclusive", async () => {
|
|
1447
1312
|
const i = e.recursive ?? !1, r = e.force ?? !1;
|
|
1448
1313
|
e.useTrash;
|
|
1449
1314
|
try {
|
|
@@ -1451,12 +1316,42 @@ async function rs(s, t, e = {}) {
|
|
|
1451
1316
|
} catch (o) {
|
|
1452
1317
|
if (o.name === "NotFoundError") {
|
|
1453
1318
|
if (!r)
|
|
1454
|
-
throw new
|
|
1455
|
-
} else throw o.name === "InvalidModificationError" ? new
|
|
1319
|
+
throw new p(\`No such file or directory: \${t}\`, "ENOENT", void 0, o);
|
|
1320
|
+
} else throw o.name === "InvalidModificationError" ? new p(\`Directory not empty: \${t}. Use recursive option to force removal.\`, "ENOTEMPTY", void 0, o) : o.name === "TypeMismatchError" && !i ? new p(\`Cannot remove directory without recursive option: \${t}\`, "EISDIR", void 0, o) : new p(\`Failed to remove entry: \${t}\`, "RM_FAILED", void 0, o);
|
|
1456
1321
|
}
|
|
1457
1322
|
});
|
|
1458
1323
|
}
|
|
1459
|
-
|
|
1324
|
+
function ft(s, t, e, n) {
|
|
1325
|
+
if (!Number.isInteger(t) || !Number.isInteger(e))
|
|
1326
|
+
throw new p("Invalid offset or length", "EINVAL");
|
|
1327
|
+
if (t < 0 || e < 0)
|
|
1328
|
+
throw new p("Negative offset or length not allowed", "EINVAL");
|
|
1329
|
+
if (t + e > s)
|
|
1330
|
+
throw new p("Operation would overflow buffer", "ERANGE");
|
|
1331
|
+
if (n != null && (!Number.isInteger(n) || n < 0))
|
|
1332
|
+
throw new p("Invalid position", "EINVAL");
|
|
1333
|
+
}
|
|
1334
|
+
function dt(s, t, e) {
|
|
1335
|
+
try {
|
|
1336
|
+
t.flush(), t.close();
|
|
1337
|
+
} catch (n) {
|
|
1338
|
+
console.warn(\`Warning: Failed to properly close file descriptor \${s} (\${e}):\`, n);
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
function Qe(s, t, e) {
|
|
1342
|
+
if (s >= e)
|
|
1343
|
+
return { isEOF: !0, actualLength: 0 };
|
|
1344
|
+
const n = Math.min(t, e - s);
|
|
1345
|
+
return n <= 0 ? { isEOF: !0, actualLength: 0 } : { isEOF: !1, actualLength: n };
|
|
1346
|
+
}
|
|
1347
|
+
async function ts(s, t) {
|
|
1348
|
+
try {
|
|
1349
|
+
return await s.createSyncAccessHandle();
|
|
1350
|
+
} catch (e) {
|
|
1351
|
+
throw Ut(e, { path: t });
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
class es {
|
|
1460
1355
|
/** Root directory handle for the file system */
|
|
1461
1356
|
root;
|
|
1462
1357
|
/** Map of watched paths and options */
|
|
@@ -1470,9 +1365,23 @@ class os {
|
|
|
1470
1365
|
root: "/",
|
|
1471
1366
|
namespace: "",
|
|
1472
1367
|
maxFileSize: 50 * 1024 * 1024,
|
|
1473
|
-
hashAlgorithm:
|
|
1368
|
+
hashAlgorithm: !1,
|
|
1474
1369
|
broadcastChannel: "opfs-worker"
|
|
1475
1370
|
};
|
|
1371
|
+
/** Map of open file descriptors to their metadata */
|
|
1372
|
+
openFiles = /* @__PURE__ */ new Map();
|
|
1373
|
+
/** Next available file descriptor number */
|
|
1374
|
+
nextFd = 1;
|
|
1375
|
+
/**
|
|
1376
|
+
* Get file info by descriptor with validation
|
|
1377
|
+
* @private
|
|
1378
|
+
*/
|
|
1379
|
+
_getFileDescriptor(t) {
|
|
1380
|
+
const e = this.openFiles.get(t);
|
|
1381
|
+
if (!e)
|
|
1382
|
+
throw new p(\`Invalid file descriptor: \${t}\`, "EBADF");
|
|
1383
|
+
return e;
|
|
1384
|
+
}
|
|
1476
1385
|
/**
|
|
1477
1386
|
* Notify about internal changes to the file system
|
|
1478
1387
|
*
|
|
@@ -1486,7 +1395,7 @@ class os {
|
|
|
1486
1395
|
if (!this.options.broadcastChannel)
|
|
1487
1396
|
return;
|
|
1488
1397
|
const e = t.path;
|
|
1489
|
-
if (![...this.watchers.values()].some((r) =>
|
|
1398
|
+
if (![...this.watchers.values()].some((r) => Y(e, r.pattern) && r.include.some((o) => o && Y(e, o)) && !r.exclude.some((o) => o && Y(e, o))))
|
|
1490
1399
|
return;
|
|
1491
1400
|
let i;
|
|
1492
1401
|
if (this.options.hashAlgorithm)
|
|
@@ -1518,7 +1427,7 @@ class os {
|
|
|
1518
1427
|
* @throws {OPFSError} If OPFS is not supported in the current browser
|
|
1519
1428
|
*/
|
|
1520
1429
|
constructor(t) {
|
|
1521
|
-
|
|
1430
|
+
Xe(), t && this.setOptions(t);
|
|
1522
1431
|
}
|
|
1523
1432
|
/**
|
|
1524
1433
|
* Initialize the file system within a given directory
|
|
@@ -1548,7 +1457,7 @@ class os {
|
|
|
1548
1457
|
const i = await navigator.storage.getDirectory();
|
|
1549
1458
|
this.root = t === "/" ? i : await this.getDirectoryHandle(t, !0, i), e(!0);
|
|
1550
1459
|
} catch (i) {
|
|
1551
|
-
n(new
|
|
1460
|
+
n(new p("Failed to initialize OPFS", "INIT_FAILED", t, i));
|
|
1552
1461
|
} finally {
|
|
1553
1462
|
this.mountingPromise = null;
|
|
1554
1463
|
}
|
|
@@ -1565,7 +1474,7 @@ class os {
|
|
|
1565
1474
|
* @param options.broadcastChannel - Custom name for the broadcast channel
|
|
1566
1475
|
*/
|
|
1567
1476
|
async setOptions(t) {
|
|
1568
|
-
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 =
|
|
1477
|
+
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 = W(t.root), this.options.namespace || (this.options.namespace = \`opfs-worker:\${this.options.root}\`), await this.mount());
|
|
1569
1478
|
}
|
|
1570
1479
|
/**
|
|
1571
1480
|
* Get a directory handle from a path
|
|
@@ -1614,7 +1523,7 @@ class os {
|
|
|
1614
1523
|
async getFileHandle(t, e = !1, n = this.root) {
|
|
1615
1524
|
const i = D(t);
|
|
1616
1525
|
if (i.length === 0)
|
|
1617
|
-
throw new
|
|
1526
|
+
throw new Bt("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
|
|
1618
1527
|
const r = i.pop();
|
|
1619
1528
|
return (await this.getDirectoryHandle(i, e, n)).getFileHandle(r, { create: e });
|
|
1620
1529
|
}
|
|
@@ -1659,71 +1568,111 @@ class os {
|
|
|
1659
1568
|
isDirectory: !0
|
|
1660
1569
|
}), await e("/"), t;
|
|
1661
1570
|
}
|
|
1662
|
-
|
|
1663
|
-
|
|
1571
|
+
/**
|
|
1572
|
+
* Read a file from the file system
|
|
1573
|
+
*
|
|
1574
|
+
* Reads the contents of a file and returns it as binary data.
|
|
1575
|
+
*
|
|
1576
|
+
* @param path - The path to the file to read
|
|
1577
|
+
* @returns Promise that resolves to the file contents as Uint8Array
|
|
1578
|
+
* @throws {FileNotFoundError} If the file does not exist
|
|
1579
|
+
* @throws {OPFSError} If reading the file fails
|
|
1580
|
+
*
|
|
1581
|
+
* @example
|
|
1582
|
+
* \`\`\`typescript
|
|
1583
|
+
* // Read as binary data
|
|
1584
|
+
* const content = await fs.readFile('/config/settings.json');
|
|
1585
|
+
*
|
|
1586
|
+
* // Read binary file
|
|
1587
|
+
* const binaryData = await fs.readFile('/images/logo.png');
|
|
1588
|
+
* \`\`\`
|
|
1589
|
+
*/
|
|
1590
|
+
async readFile(t) {
|
|
1591
|
+
await this.mount();
|
|
1664
1592
|
try {
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1593
|
+
return await P(t, "shared", async () => {
|
|
1594
|
+
const e = await this.open(t);
|
|
1595
|
+
try {
|
|
1596
|
+
const { size: n } = await this.fstat(e), i = new Uint8Array(n);
|
|
1597
|
+
return n > 0 && await this.read(e, i, 0, n, 0), H(i, [i.buffer]);
|
|
1598
|
+
} finally {
|
|
1599
|
+
await this.close(e);
|
|
1600
|
+
}
|
|
1601
|
+
});
|
|
1602
|
+
} catch (e) {
|
|
1603
|
+
throw new nt(t, e);
|
|
1669
1604
|
}
|
|
1670
1605
|
}
|
|
1671
1606
|
/**
|
|
1672
1607
|
* Write data to a file
|
|
1673
1608
|
*
|
|
1674
|
-
* Creates or overwrites a file with the specified data. If the file already
|
|
1609
|
+
* Creates or overwrites a file with the specified binary data. If the file already
|
|
1675
1610
|
* exists, it will be truncated before writing.
|
|
1676
1611
|
*
|
|
1677
1612
|
* @param path - The path to the file to write
|
|
1678
|
-
* @param data - The data to write to the file (
|
|
1679
|
-
* @param encoding - The encoding to use when writing string data (default: 'utf-8')
|
|
1613
|
+
* @param data - The binary data to write to the file (Uint8Array or ArrayBuffer)
|
|
1680
1614
|
* @returns Promise that resolves when the write operation is complete
|
|
1681
1615
|
* @throws {OPFSError} If writing the file fails
|
|
1682
1616
|
*
|
|
1683
1617
|
* @example
|
|
1684
1618
|
* \`\`\`typescript
|
|
1685
|
-
* // Write text data
|
|
1686
|
-
* await fs.writeFile('/config/settings.json', JSON.stringify({ theme: 'dark' }));
|
|
1687
|
-
*
|
|
1688
1619
|
* // Write binary data
|
|
1689
1620
|
* const binaryData = new Uint8Array([1, 2, 3, 4, 5]);
|
|
1690
1621
|
* await fs.writeFile('/data/binary.dat', binaryData);
|
|
1691
1622
|
*
|
|
1692
|
-
* // Write
|
|
1693
|
-
*
|
|
1623
|
+
* // Write from ArrayBuffer
|
|
1624
|
+
* const arrayBuffer = new ArrayBuffer(10);
|
|
1625
|
+
* await fs.writeFile('/data/buffer.dat', arrayBuffer);
|
|
1694
1626
|
* \`\`\`
|
|
1695
1627
|
*/
|
|
1696
|
-
async writeFile(t, e
|
|
1628
|
+
async writeFile(t, e) {
|
|
1697
1629
|
await this.mount();
|
|
1698
|
-
const
|
|
1699
|
-
|
|
1630
|
+
const n = e instanceof Uint8Array ? e : new Uint8Array(e);
|
|
1631
|
+
await P(t, "exclusive", async () => {
|
|
1632
|
+
const i = await this.exists(t), r = await this.open(t, { create: !0, truncate: !0 });
|
|
1633
|
+
try {
|
|
1634
|
+
await this.write(r, n, 0, n.length, null, !1), await this.fsync(r);
|
|
1635
|
+
} finally {
|
|
1636
|
+
await this.close(r);
|
|
1637
|
+
}
|
|
1638
|
+
await this.notifyChange({ path: t, type: i ? "changed" : "added", isDirectory: !1 });
|
|
1639
|
+
});
|
|
1700
1640
|
}
|
|
1701
1641
|
/**
|
|
1702
1642
|
* Append data to a file
|
|
1703
1643
|
*
|
|
1704
|
-
* Adds data to the end of an existing file. If the file doesn't exist,
|
|
1644
|
+
* Adds binary data to the end of an existing file. If the file doesn't exist,
|
|
1705
1645
|
* it will be created.
|
|
1706
1646
|
*
|
|
1707
1647
|
* @param path - The path to the file to append to
|
|
1708
|
-
* @param data - The data to append to the file (
|
|
1709
|
-
* @param encoding - The encoding to use when appending string data (default: 'utf-8')
|
|
1648
|
+
* @param data - The binary data to append to the file (Uint8Array or ArrayBuffer)
|
|
1710
1649
|
* @returns Promise that resolves when the append operation is complete
|
|
1711
1650
|
* @throws {OPFSError} If appending to the file fails
|
|
1712
1651
|
*
|
|
1713
1652
|
* @example
|
|
1714
1653
|
* \`\`\`typescript
|
|
1715
|
-
* // Append text to a log file
|
|
1716
|
-
* await fs.appendFile('/logs/app.log', \`[\${new Date().toISOString()}] User logged in\\n\`);
|
|
1717
|
-
*
|
|
1718
1654
|
* // Append binary data
|
|
1719
1655
|
* const additionalData = new Uint8Array([6, 7, 8]);
|
|
1720
1656
|
* await fs.appendFile('/data/binary.dat', additionalData);
|
|
1657
|
+
*
|
|
1658
|
+
* // Append from ArrayBuffer
|
|
1659
|
+
* const arrayBuffer = new ArrayBuffer(5);
|
|
1660
|
+
* await fs.appendFile('/data/buffer.dat', arrayBuffer);
|
|
1721
1661
|
* \`\`\`
|
|
1722
1662
|
*/
|
|
1723
|
-
async appendFile(t, e
|
|
1663
|
+
async appendFile(t, e) {
|
|
1724
1664
|
await this.mount();
|
|
1725
|
-
const
|
|
1726
|
-
|
|
1665
|
+
const n = e instanceof Uint8Array ? e : new Uint8Array(e);
|
|
1666
|
+
await P(t, "exclusive", async () => {
|
|
1667
|
+
const i = await this.open(t, { create: !0 });
|
|
1668
|
+
try {
|
|
1669
|
+
const { size: r } = await this.fstat(i);
|
|
1670
|
+
await this.write(i, n, 0, n.length, r, !1), await this.fsync(i);
|
|
1671
|
+
} finally {
|
|
1672
|
+
await this.close(i);
|
|
1673
|
+
}
|
|
1674
|
+
await this.notifyChange({ path: t, type: "changed", isDirectory: !1 });
|
|
1675
|
+
});
|
|
1727
1676
|
}
|
|
1728
1677
|
/**
|
|
1729
1678
|
* Create a directory
|
|
@@ -1755,12 +1704,12 @@ class os {
|
|
|
1755
1704
|
try {
|
|
1756
1705
|
r = await r.getDirectoryHandle(a, { create: n || o === i.length - 1 });
|
|
1757
1706
|
} catch (l) {
|
|
1758
|
-
throw l.name === "NotFoundError" ? new
|
|
1707
|
+
throw l.name === "NotFoundError" ? new p(
|
|
1759
1708
|
\`Parent directory does not exist: \${et(i.slice(0, o + 1))}\`,
|
|
1760
1709
|
"ENOENT",
|
|
1761
1710
|
void 0,
|
|
1762
1711
|
l
|
|
1763
|
-
) : l.name === "TypeMismatchError" ? new
|
|
1712
|
+
) : l.name === "TypeMismatchError" ? new p(\`Path segment is not a directory: \${a}\`, "ENOTDIR", void 0, l) : new p("Failed to create directory", "MKDIR_FAILED", void 0, l);
|
|
1764
1713
|
}
|
|
1765
1714
|
}
|
|
1766
1715
|
await this.notifyChange({ path: t, type: "added", isDirectory: !0 });
|
|
@@ -1797,7 +1746,7 @@ class os {
|
|
|
1797
1746
|
isFile: !1,
|
|
1798
1747
|
isDirectory: !0
|
|
1799
1748
|
};
|
|
1800
|
-
const e =
|
|
1749
|
+
const e = J(t), n = await this.getDirectoryHandle(X(t), !1), i = this.options.hashAlgorithm !== null;
|
|
1801
1750
|
try {
|
|
1802
1751
|
const o = await (await n.getFileHandle(e, { create: !1 })).getFile(), a = {
|
|
1803
1752
|
kind: "file",
|
|
@@ -1809,7 +1758,7 @@ class os {
|
|
|
1809
1758
|
};
|
|
1810
1759
|
if (i && this.options.hashAlgorithm)
|
|
1811
1760
|
try {
|
|
1812
|
-
const l = await
|
|
1761
|
+
const l = await Ze(o, this.options.hashAlgorithm, this.options.maxFileSize);
|
|
1813
1762
|
a.hash = l;
|
|
1814
1763
|
} catch (l) {
|
|
1815
1764
|
console.warn(\`Failed to calculate hash for \${t}:\`, l);
|
|
@@ -1817,7 +1766,7 @@ class os {
|
|
|
1817
1766
|
return a;
|
|
1818
1767
|
} catch (r) {
|
|
1819
1768
|
if (r.name !== "TypeMismatchError" && r.name !== "NotFoundError")
|
|
1820
|
-
throw new
|
|
1769
|
+
throw new p("Failed to stat (file)", "STAT_FAILED", void 0, r);
|
|
1821
1770
|
}
|
|
1822
1771
|
try {
|
|
1823
1772
|
return await n.getDirectoryHandle(e, { create: !1 }), {
|
|
@@ -1829,7 +1778,7 @@ class os {
|
|
|
1829
1778
|
isDirectory: !0
|
|
1830
1779
|
};
|
|
1831
1780
|
} catch (r) {
|
|
1832
|
-
throw r.name === "NotFoundError" ? new
|
|
1781
|
+
throw r.name === "NotFoundError" ? new p(\`No such file or directory: \${t}\`, "ENOENT", void 0, r) : new p("Failed to stat (directory)", "STAT_FAILED", void 0, r);
|
|
1833
1782
|
}
|
|
1834
1783
|
}
|
|
1835
1784
|
/**
|
|
@@ -1881,10 +1830,10 @@ class os {
|
|
|
1881
1830
|
async exists(t) {
|
|
1882
1831
|
if (await this.mount(), t === "/")
|
|
1883
1832
|
return !0;
|
|
1884
|
-
const e =
|
|
1833
|
+
const e = J(t);
|
|
1885
1834
|
let n = null;
|
|
1886
1835
|
try {
|
|
1887
|
-
n = await this.getDirectoryHandle(
|
|
1836
|
+
n = await this.getDirectoryHandle(X(t), !1);
|
|
1888
1837
|
} catch (i) {
|
|
1889
1838
|
if (n = null, i.name !== "NotFoundError" && i.name !== "TypeMismatchError")
|
|
1890
1839
|
throw i;
|
|
@@ -1934,7 +1883,7 @@ class os {
|
|
|
1934
1883
|
}
|
|
1935
1884
|
await this.notifyChange({ path: t, type: "changed", isDirectory: !0 });
|
|
1936
1885
|
} catch (e) {
|
|
1937
|
-
throw e instanceof
|
|
1886
|
+
throw e instanceof p ? e : new p(\`Failed to clear directory: \${t}\`, "CLEAR_FAILED", void 0, e);
|
|
1938
1887
|
}
|
|
1939
1888
|
}
|
|
1940
1889
|
/**
|
|
@@ -1963,9 +1912,9 @@ class os {
|
|
|
1963
1912
|
*/
|
|
1964
1913
|
async remove(t, e) {
|
|
1965
1914
|
if (await this.mount(), t === "/")
|
|
1966
|
-
throw new
|
|
1967
|
-
const { recursive: n = !1, force: i = !1 } = e || {}, r = await this.getDirectoryHandle(
|
|
1968
|
-
await
|
|
1915
|
+
throw new p("Cannot remove root directory", "EROOT");
|
|
1916
|
+
const { recursive: n = !1, force: i = !1 } = e || {}, r = await this.getDirectoryHandle(X(t), !1), o = await this.stat(t);
|
|
1917
|
+
await Ke(r, t, { recursive: n, force: i }), await this.notifyChange({ path: t, type: "removed", isDirectory: o.isDirectory });
|
|
1969
1918
|
}
|
|
1970
1919
|
/**
|
|
1971
1920
|
* Resolve a path to an absolute path
|
|
@@ -1988,12 +1937,12 @@ class os {
|
|
|
1988
1937
|
async realpath(t) {
|
|
1989
1938
|
await this.mount();
|
|
1990
1939
|
try {
|
|
1991
|
-
const e =
|
|
1940
|
+
const e = ut(t);
|
|
1992
1941
|
if (!await this.exists(e))
|
|
1993
|
-
throw new
|
|
1942
|
+
throw new nt(e);
|
|
1994
1943
|
return e;
|
|
1995
1944
|
} catch (e) {
|
|
1996
|
-
throw e instanceof
|
|
1945
|
+
throw e instanceof p ? e : new p(\`Failed to resolve path: \${t}\`, "REALPATH_FAILED", void 0, e);
|
|
1997
1946
|
}
|
|
1998
1947
|
}
|
|
1999
1948
|
/**
|
|
@@ -2021,14 +1970,12 @@ class os {
|
|
|
2021
1970
|
async rename(t, e, n) {
|
|
2022
1971
|
await this.mount();
|
|
2023
1972
|
try {
|
|
2024
|
-
const i = n?.overwrite ?? !1;
|
|
2025
|
-
if (!await this.exists(t))
|
|
2026
|
-
throw new _(t);
|
|
1973
|
+
const i = n?.overwrite ?? !1, r = await this.stat(t);
|
|
2027
1974
|
if (await this.exists(e) && !i)
|
|
2028
|
-
throw new
|
|
2029
|
-
await this.copy(t, e, { recursive: !0, overwrite: i }), await this.remove(t, { recursive: !0 }), await this.notifyChange({ path: t, type: "removed", isDirectory:
|
|
1975
|
+
throw new p(\`Destination already exists: \${e}\`, "EEXIST", void 0);
|
|
1976
|
+
await this.copy(t, e, { recursive: !0, overwrite: i }), await this.remove(t, { recursive: !0 }), await this.notifyChange({ path: t, type: "removed", isDirectory: r.isDirectory }), await this.notifyChange({ path: e, type: "added", isDirectory: r.isDirectory });
|
|
2030
1977
|
} catch (i) {
|
|
2031
|
-
throw i instanceof
|
|
1978
|
+
throw i instanceof p ? i : new p(\`Failed to rename from \${t} to \${e}\`, "RENAME_FAILED", void 0, i);
|
|
2032
1979
|
}
|
|
2033
1980
|
}
|
|
2034
1981
|
/**
|
|
@@ -2061,15 +2008,15 @@ class os {
|
|
|
2061
2008
|
try {
|
|
2062
2009
|
const i = n?.recursive ?? !1, r = n?.overwrite ?? !0;
|
|
2063
2010
|
if (!await this.exists(t))
|
|
2064
|
-
throw new
|
|
2011
|
+
throw new p(\`Source does not exist: \${t}\`, "ENOENT", void 0);
|
|
2065
2012
|
if (await this.exists(e) && !r)
|
|
2066
|
-
throw new
|
|
2013
|
+
throw new p(\`Destination already exists: \${e}\`, "EEXIST", void 0);
|
|
2067
2014
|
if ((await this.stat(t)).isFile) {
|
|
2068
|
-
const h = await this.readFile(t
|
|
2015
|
+
const h = await this.readFile(t);
|
|
2069
2016
|
await this.writeFile(e, h);
|
|
2070
2017
|
} else {
|
|
2071
2018
|
if (!i)
|
|
2072
|
-
throw new
|
|
2019
|
+
throw new p(\`Cannot copy directory without recursive option: \${t}\`, "EISDIR", void 0);
|
|
2073
2020
|
await this.mkdir(e, { recursive: !0 });
|
|
2074
2021
|
const h = await this.readDir(t);
|
|
2075
2022
|
for (const c of h) {
|
|
@@ -2078,7 +2025,7 @@ class os {
|
|
|
2078
2025
|
}
|
|
2079
2026
|
}
|
|
2080
2027
|
} catch (i) {
|
|
2081
|
-
throw i instanceof
|
|
2028
|
+
throw i instanceof p ? i : new p(\`Failed to copy from \${t} to \${e}\`, "CP_FAILED", void 0, i);
|
|
2082
2029
|
}
|
|
2083
2030
|
}
|
|
2084
2031
|
/**
|
|
@@ -2108,9 +2055,9 @@ class os {
|
|
|
2108
2055
|
*/
|
|
2109
2056
|
async watch(t, e) {
|
|
2110
2057
|
if (!this.options.broadcastChannel)
|
|
2111
|
-
throw new
|
|
2058
|
+
throw new p("This instance is not configured to send events. Please specify options.broadcastChannel to enable watching.", "ENOENT");
|
|
2112
2059
|
const n = {
|
|
2113
|
-
pattern:
|
|
2060
|
+
pattern: Ye(t, e?.recursive ?? !0),
|
|
2114
2061
|
include: Array.isArray(e?.include) ? e.include : [e?.include ?? "**"],
|
|
2115
2062
|
exclude: Array.isArray(e?.exclude) ? e.exclude : [e?.exclude ?? ""]
|
|
2116
2063
|
};
|
|
@@ -2122,6 +2069,223 @@ class os {
|
|
|
2122
2069
|
unwatch(t) {
|
|
2123
2070
|
this.watchers.delete(t);
|
|
2124
2071
|
}
|
|
2072
|
+
/**
|
|
2073
|
+
* Open a file and return a file descriptor
|
|
2074
|
+
*
|
|
2075
|
+
* @param path - The path to the file to open
|
|
2076
|
+
* @param options - Options for opening the file
|
|
2077
|
+
* @param options.create - Whether to create the file if it doesn't exist (default: false)
|
|
2078
|
+
* @param options.exclusive - If true and create is true, fails if file already exists (default: false)
|
|
2079
|
+
* Note: This is best-effort in OPFS, not fully atomic due to browser limitations
|
|
2080
|
+
* @param options.truncate - Whether to truncate the file to zero length (default: false)
|
|
2081
|
+
* @returns Promise that resolves to a file descriptor number
|
|
2082
|
+
* @throws {OPFSError} If opening the file fails
|
|
2083
|
+
*
|
|
2084
|
+
* @example
|
|
2085
|
+
* \`\`\`typescript
|
|
2086
|
+
* // Open existing file for reading
|
|
2087
|
+
* const fd = await fs.open('/data/config.json');
|
|
2088
|
+
*
|
|
2089
|
+
* // Create new file for writing
|
|
2090
|
+
* const fd = await fs.open('/data/new.txt', { create: true });
|
|
2091
|
+
*
|
|
2092
|
+
* // Create file exclusively (fails if exists)
|
|
2093
|
+
* const fd = await fs.open('/data/unique.txt', { create: true, exclusive: true });
|
|
2094
|
+
*
|
|
2095
|
+
* // Open and truncate file
|
|
2096
|
+
* const fd = await fs.open('/data/log.txt', { create: true, truncate: true });
|
|
2097
|
+
* \`\`\`
|
|
2098
|
+
*/
|
|
2099
|
+
async open(t, e) {
|
|
2100
|
+
await this.mount();
|
|
2101
|
+
const { create: n = !1, exclusive: i = !1, truncate: r = !1 } = e || {}, o = W(ut(t));
|
|
2102
|
+
try {
|
|
2103
|
+
return n && i ? await P(o, "exclusive", async () => {
|
|
2104
|
+
if (await this.exists(o))
|
|
2105
|
+
throw new p(\`File already exists: \${o}\`, "EEXIST", o);
|
|
2106
|
+
return this._openFile(o, n, r);
|
|
2107
|
+
}) : await this._openFile(o, n, r);
|
|
2108
|
+
} catch (a) {
|
|
2109
|
+
throw a instanceof p ? a : new p(\`Failed to open file: \${o}\`, "OPEN_FAILED", o, a);
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2112
|
+
/**
|
|
2113
|
+
* Internal method to open a file (without locking)
|
|
2114
|
+
* @private
|
|
2115
|
+
*/
|
|
2116
|
+
async _openFile(t, e, n) {
|
|
2117
|
+
const i = await this.getFileHandle(t, e);
|
|
2118
|
+
try {
|
|
2119
|
+
await i.getFile();
|
|
2120
|
+
} catch (a) {
|
|
2121
|
+
throw a.name === "TypeMismatchError" ? new p(\`Is a directory: \${t}\`, "EISDIR", t) : a;
|
|
2122
|
+
}
|
|
2123
|
+
const r = await ts(i, t);
|
|
2124
|
+
n && (r.truncate(0), r.flush());
|
|
2125
|
+
const o = this.nextFd++;
|
|
2126
|
+
return this.openFiles.set(o, {
|
|
2127
|
+
path: t,
|
|
2128
|
+
fileHandle: i,
|
|
2129
|
+
syncHandle: r,
|
|
2130
|
+
position: 0
|
|
2131
|
+
}), o;
|
|
2132
|
+
}
|
|
2133
|
+
/**
|
|
2134
|
+
* Close a file descriptor
|
|
2135
|
+
*
|
|
2136
|
+
* @param fd - The file descriptor to close
|
|
2137
|
+
* @returns Promise that resolves when the file descriptor is closed
|
|
2138
|
+
* @throws {OPFSError} If the file descriptor is invalid or closing fails
|
|
2139
|
+
*
|
|
2140
|
+
* @example
|
|
2141
|
+
* \`\`\`typescript
|
|
2142
|
+
* const fd = await fs.open('/data/file.txt');
|
|
2143
|
+
* // ... use the file descriptor ...
|
|
2144
|
+
* await fs.close(fd);
|
|
2145
|
+
* \`\`\`
|
|
2146
|
+
*/
|
|
2147
|
+
async close(t) {
|
|
2148
|
+
const e = this._getFileDescriptor(t);
|
|
2149
|
+
dt(t, e.syncHandle, e.path), this.openFiles.delete(t);
|
|
2150
|
+
}
|
|
2151
|
+
/**
|
|
2152
|
+
* Read data from a file descriptor
|
|
2153
|
+
*
|
|
2154
|
+
* @param fd - The file descriptor to read from
|
|
2155
|
+
* @param buffer - The buffer to read data into
|
|
2156
|
+
* @param offset - The offset in the buffer to start writing at
|
|
2157
|
+
* @param length - The number of bytes to read
|
|
2158
|
+
* @param position - The position in the file to read from (null for current position)
|
|
2159
|
+
* @returns Promise that resolves to the number of bytes read and the modified buffer
|
|
2160
|
+
* @throws {OPFSError} If the file descriptor is invalid or reading fails
|
|
2161
|
+
*
|
|
2162
|
+
* @note This method uses Comlink.transfer() to efficiently pass the buffer as a Transferable Object,
|
|
2163
|
+
* ensuring zero-copy performance across Web Worker boundaries.
|
|
2164
|
+
*
|
|
2165
|
+
* @example
|
|
2166
|
+
* \`\`\`typescript
|
|
2167
|
+
* const fd = await fs.open('/data/file.txt');
|
|
2168
|
+
* const buffer = new Uint8Array(1024);
|
|
2169
|
+
* const { bytesRead, buffer: modifiedBuffer } = await fs.read(fd, buffer, 0, 1024, null);
|
|
2170
|
+
* console.log(\`Read \${bytesRead} bytes\`);
|
|
2171
|
+
* // Use modifiedBuffer which contains the actual data
|
|
2172
|
+
* await fs.close(fd);
|
|
2173
|
+
* \`\`\`
|
|
2174
|
+
*/
|
|
2175
|
+
async read(t, e, n, i, r) {
|
|
2176
|
+
const o = this._getFileDescriptor(t);
|
|
2177
|
+
ft(e.length, n, i, r);
|
|
2178
|
+
try {
|
|
2179
|
+
const a = r ?? o.position, l = o.syncHandle.getSize(), { isEOF: h, actualLength: c } = Qe(a, i, l);
|
|
2180
|
+
if (h)
|
|
2181
|
+
return H({ bytesRead: 0, buffer: e }, [e.buffer]);
|
|
2182
|
+
const f = e.subarray(n, n + c), u = o.syncHandle.read(f, { at: a });
|
|
2183
|
+
return r == null && (o.position = a + u), H({ bytesRead: u, buffer: e }, [e.buffer]);
|
|
2184
|
+
} catch (a) {
|
|
2185
|
+
throw R("read", t, o.path, a);
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
/**
|
|
2189
|
+
* Write data to a file descriptor
|
|
2190
|
+
*
|
|
2191
|
+
* @param fd - The file descriptor to write to
|
|
2192
|
+
* @param buffer - The buffer containing data to write
|
|
2193
|
+
* @param offset - The offset in the buffer to start reading from (default: 0)
|
|
2194
|
+
* @param length - The number of bytes to write (default: entire buffer)
|
|
2195
|
+
* @param position - The position in the file to write to (null/undefined for current position)
|
|
2196
|
+
* @param emitEvent - Whether to emit a change event (default: true)
|
|
2197
|
+
* @returns Promise that resolves to the number of bytes written
|
|
2198
|
+
* @throws {OPFSError} If the file descriptor is invalid or writing fails
|
|
2199
|
+
*
|
|
2200
|
+
* @example
|
|
2201
|
+
* \`\`\`typescript
|
|
2202
|
+
* const fd = await fs.open('/data/file.txt', { create: true });
|
|
2203
|
+
* const data = new TextEncoder().encode('Hello, World!');
|
|
2204
|
+
* const bytesWritten = await fs.write(fd, data, 0, data.length, null);
|
|
2205
|
+
* console.log(\`Wrote \${bytesWritten} bytes\`);
|
|
2206
|
+
* await fs.close(fd);
|
|
2207
|
+
* \`\`\`
|
|
2208
|
+
*/
|
|
2209
|
+
async write(t, e, n = 0, i, r, o = !0) {
|
|
2210
|
+
const a = this._getFileDescriptor(t), l = i ?? e.length - n;
|
|
2211
|
+
ft(e.length, n, l, r);
|
|
2212
|
+
try {
|
|
2213
|
+
const h = r ?? a.position, c = e.subarray(n, n + l), f = a.syncHandle.write(c, { at: h });
|
|
2214
|
+
return (r == null || r === a.position) && (a.position = h + f), o && await this.notifyChange({ path: a.path, type: "changed", isDirectory: !1 }), f;
|
|
2215
|
+
} catch (h) {
|
|
2216
|
+
throw R("write", t, a.path, h);
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
/**
|
|
2220
|
+
* Get file status information by file descriptor
|
|
2221
|
+
*
|
|
2222
|
+
* @param fd - The file descriptor
|
|
2223
|
+
* @returns Promise that resolves to FileStat object
|
|
2224
|
+
* @throws {OPFSError} If the file descriptor is invalid
|
|
2225
|
+
*
|
|
2226
|
+
* @example
|
|
2227
|
+
* \`\`\`typescript
|
|
2228
|
+
* const fd = await fs.open('/data/file.txt');
|
|
2229
|
+
* const stats = await fs.fstat(fd);
|
|
2230
|
+
* console.log(\`File size: \${stats.size} bytes\`);
|
|
2231
|
+
* console.log(\`Last modified: \${stats.mtime}\`);
|
|
2232
|
+
*
|
|
2233
|
+
* // If hashing is enabled, hash will be included
|
|
2234
|
+
* if (stats.hash) {
|
|
2235
|
+
* console.log(\`Hash: \${stats.hash}\`);
|
|
2236
|
+
* }
|
|
2237
|
+
* \`\`\`
|
|
2238
|
+
*/
|
|
2239
|
+
async fstat(t) {
|
|
2240
|
+
const e = this._getFileDescriptor(t);
|
|
2241
|
+
return this.stat(e.path);
|
|
2242
|
+
}
|
|
2243
|
+
/**
|
|
2244
|
+
* Truncate file to specified size
|
|
2245
|
+
*
|
|
2246
|
+
* @param fd - The file descriptor
|
|
2247
|
+
* @param size - The new size of the file (default: 0)
|
|
2248
|
+
* @returns Promise that resolves when truncation is complete
|
|
2249
|
+
* @throws {OPFSError} If the file descriptor is invalid or truncation fails
|
|
2250
|
+
*
|
|
2251
|
+
* @example
|
|
2252
|
+
* \`\`\`typescript
|
|
2253
|
+
* const fd = await fs.open('/data/file.txt', { create: true });
|
|
2254
|
+
* await fs.truncate(fd, 100); // Truncate to 100 bytes
|
|
2255
|
+
* \`\`\`
|
|
2256
|
+
*/
|
|
2257
|
+
async ftruncate(t, e = 0) {
|
|
2258
|
+
const n = this._getFileDescriptor(t);
|
|
2259
|
+
if (e < 0 || !Number.isInteger(e))
|
|
2260
|
+
throw new p("Invalid size", "EINVAL");
|
|
2261
|
+
try {
|
|
2262
|
+
n.syncHandle.truncate(e), n.syncHandle.flush(), n.position > e && (n.position = e), await this.notifyChange({ path: n.path, type: "changed", isDirectory: !1 });
|
|
2263
|
+
} catch (i) {
|
|
2264
|
+
throw R("truncate", t, n.path, i);
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
/**
|
|
2268
|
+
* Synchronize file data to storage (fsync equivalent)
|
|
2269
|
+
*
|
|
2270
|
+
* @param fd - The file descriptor
|
|
2271
|
+
* @returns Promise that resolves when synchronization is complete
|
|
2272
|
+
* @throws {OPFSError} If the file descriptor is invalid or sync fails
|
|
2273
|
+
*
|
|
2274
|
+
* @example
|
|
2275
|
+
* \`\`\`typescript
|
|
2276
|
+
* const fd = await fs.open('/data/file.txt', { create: true });
|
|
2277
|
+
* await fs.write(fd, data);
|
|
2278
|
+
* await fs.fsync(fd); // Ensure data is written to storage
|
|
2279
|
+
* \`\`\`
|
|
2280
|
+
*/
|
|
2281
|
+
async fsync(t) {
|
|
2282
|
+
const e = this._getFileDescriptor(t);
|
|
2283
|
+
try {
|
|
2284
|
+
e.syncHandle.flush();
|
|
2285
|
+
} catch (n) {
|
|
2286
|
+
throw R("sync", t, e.path, n);
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2125
2289
|
/**
|
|
2126
2290
|
* Dispose of resources and clean up the file system instance
|
|
2127
2291
|
*
|
|
@@ -2130,6 +2294,9 @@ class os {
|
|
|
2130
2294
|
*/
|
|
2131
2295
|
dispose() {
|
|
2132
2296
|
this.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.watchers.clear();
|
|
2297
|
+
for (const [t, e] of this.openFiles)
|
|
2298
|
+
dt(t, e.syncHandle, e.path);
|
|
2299
|
+
this.openFiles.clear(), this.nextFd = 1;
|
|
2133
2300
|
}
|
|
2134
2301
|
/**
|
|
2135
2302
|
* Synchronize the file system with external data
|
|
@@ -2164,16 +2331,16 @@ class os {
|
|
|
2164
2331
|
try {
|
|
2165
2332
|
(e?.cleanBefore ?? !1) && await this.clear("/");
|
|
2166
2333
|
for (const [i, r] of t) {
|
|
2167
|
-
const o =
|
|
2334
|
+
const o = W(i);
|
|
2168
2335
|
let a;
|
|
2169
|
-
r instanceof Blob ? a = await
|
|
2336
|
+
r instanceof Blob ? a = await Je(r) : typeof r == "string" ? a = new TextEncoder().encode(r) : a = r, await this.writeFile(o, a);
|
|
2170
2337
|
}
|
|
2171
2338
|
} catch (n) {
|
|
2172
|
-
throw n instanceof
|
|
2339
|
+
throw n instanceof p ? n : new p("Failed to sync file system", "SYNC_FAILED", void 0, n);
|
|
2173
2340
|
}
|
|
2174
2341
|
}
|
|
2175
2342
|
}
|
|
2176
|
-
typeof globalThis < "u" && globalThis.constructor.name === "DedicatedWorkerGlobalScope" &&
|
|
2177
|
-
//# sourceMappingURL=worker-
|
|
2178
|
-
`,
|
|
2343
|
+
typeof globalThis < "u" && globalThis.constructor.name === "DedicatedWorkerGlobalScope" && K(new es());
|
|
2344
|
+
//# sourceMappingURL=worker-CLvhwwfc.js.map
|
|
2345
|
+
`,h=typeof self<"u"&&self.Blob&&new Blob(["URL.revokeObjectURL(import.meta.url);",c],{type:"text/javascript;charset=utf-8"});function d(s){let n;try{if(n=h&&(self.URL||self.webkitURL).createObjectURL(h),!n)throw"";const t=new Worker(n,{type:"module",name:s?.name});return t.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(n)}),t}catch{return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(c),{type:"module",name:s?.name})}}class l{#n;constructor(n){const t=f.wrap(new d);this.#n=t,n&&(n.broadcastChannel&&n.broadcastChannel instanceof BroadcastChannel&&(n.broadcastChannel=n.broadcastChannel.name),this.setOptions(n))}async setOptions(n){return this.#n.setOptions(n)}async index(){return this.#n.index()}async readFile(n,t){const r=await this.#n.readFile(n);return t||(t=e.isBinaryFileExtension(n)?"binary":"utf-8"),t==="binary"?r:e.decodeBuffer(r,t)}async writeFile(n,t,r){r||(r=typeof t!="string"||e.isBinaryFileExtension(n)?"binary":"utf-8");const i=typeof t=="string"?e.encodeString(t,r):t instanceof Uint8Array?t:new Uint8Array(t);return this.#n.writeFile(n,i)}async appendFile(n,t,r){r||(r=typeof t!="string"||e.isBinaryFileExtension(n)?"binary":"utf-8");const i=typeof t=="string"?e.encodeString(t,r):t instanceof Uint8Array?t:new Uint8Array(t);return this.#n.appendFile(n,i)}async mkdir(n,t){return this.#n.mkdir(n,t)}async stat(n){return this.#n.stat(n)}async readDir(n){return this.#n.readDir(n)}async exists(n){return this.#n.exists(n)}async clear(n){return this.#n.clear(n)}async remove(n,t){return this.#n.remove(n,t)}async realpath(n){return this.#n.realpath(n)}async rename(n,t,r){return this.#n.rename(n,t,r)}async copy(n,t,r){return this.#n.copy(n,t,r)}watch(n,t){return this.#n.watch(n,t),()=>this.unwatch(n)}unwatch(n){this.#n.unwatch(n)}async open(n,t){return this.#n.open(n,t)}async close(n){return this.#n.close(n)}async read(n,t,r,i,o){const{bytesRead:a,buffer:p}=await this.#n.read(n,new Uint8Array(i),0,i,o);return a>0&&t.set(p.subarray(0,a),r),{bytesRead:a,buffer:t}}async write(n,t,r,i,o,a){return this.#n.write(n,t,r,i,o,a)}async fstat(n){return this.#n.fstat(n)}async ftruncate(n,t){return this.#n.ftruncate(n,t)}async fsync(n){return this.#n.fsync(n)}dispose(){this.#n.dispose()}async sync(n,t){return this.#n.sync(n,t)}async readText(n,t="utf-8"){const r=await this.#n.readFile(n);return e.decodeBuffer(r,t)}async writeText(n,t,r="utf-8"){const i=e.encodeString(t,r);return this.#n.writeFile(n,i)}async appendText(n,t,r="utf-8"){const i=e.encodeString(t,r);return this.#n.appendFile(n,i)}}function u(s){return new l(s)}exports.BINARY_FILE_EXTENSIONS=e.BINARY_FILE_EXTENSIONS;exports.DirectoryNotFoundError=e.DirectoryNotFoundError;exports.FileNotFoundError=e.FileNotFoundError;exports.OPFSError=e.OPFSError;exports.OPFSNotMountedError=e.OPFSNotMountedError;exports.OPFSNotSupportedError=e.OPFSNotSupportedError;exports.PathError=e.PathError;exports.PermissionError=e.PermissionError;exports.StorageError=e.StorageError;exports.TimeoutError=e.TimeoutError;exports.basename=e.basename;exports.buffersEqual=e.buffersEqual;exports.calculateFileHash=e.calculateFileHash;exports.calculateReadLength=e.calculateReadLength;exports.checkOPFSSupport=e.checkOPFSSupport;exports.convertBlobToUint8Array=e.convertBlobToUint8Array;exports.createBuffer=e.createBuffer;exports.createFDError=e.createFDError;exports.createSyncHandleSafe=e.createSyncHandleSafe;exports.decodeBuffer=e.decodeBuffer;exports.dirname=e.dirname;exports.encodeString=e.encodeString;exports.extname=e.extname;exports.isBinaryFileExtension=e.isBinaryFileExtension;exports.isPathExcluded=e.isPathExcluded;exports.joinPath=e.joinPath;exports.mapDomError=e.mapDomError;exports.matchMinimatch=e.matchMinimatch;exports.normalizeMinimatch=e.normalizeMinimatch;exports.normalizePath=e.normalizePath;exports.removeEntry=e.removeEntry;exports.resolvePath=e.resolvePath;exports.safeCloseSyncHandle=e.safeCloseSyncHandle;exports.splitPath=e.splitPath;exports.validateReadWriteArgs=e.validateReadWriteArgs;exports.withLock=e.withLock;exports.OPFSFileSystem=l;exports.createWorker=u;
|
|
2179
2346
|
//# sourceMappingURL=index.cjs.map
|