opfs-worker 1.3.2 → 2.1.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.
Files changed (149) hide show
  1. package/README.md +64 -458
  2. package/dist/BaseOPFS-BPw9AIQ-.cjs +4 -0
  3. package/dist/BaseOPFS-BPw9AIQ-.cjs.map +1 -0
  4. package/dist/BaseOPFS-Cylz6ijk.js +2036 -0
  5. package/dist/BaseOPFS-Cylz6ijk.js.map +1 -0
  6. package/dist/OPFSAsync-BKSAJJeh.js +124 -0
  7. package/dist/OPFSAsync-BKSAJJeh.js.map +1 -0
  8. package/dist/OPFSAsync-s2P7y3sw.cjs +2 -0
  9. package/dist/OPFSAsync-s2P7y3sw.cjs.map +1 -0
  10. package/dist/OPFSFacade-DePnNRgt.cjs +2 -0
  11. package/dist/OPFSFacade-DePnNRgt.cjs.map +1 -0
  12. package/dist/OPFSFacade-XohWlHuu.js +281 -0
  13. package/dist/OPFSFacade-XohWlHuu.js.map +1 -0
  14. package/dist/OPFSSync-C7KBepe_.cjs +2 -0
  15. package/dist/OPFSSync-C7KBepe_.cjs.map +1 -0
  16. package/dist/OPFSSync-CsSQkpk5.js +208 -0
  17. package/dist/OPFSSync-CsSQkpk5.js.map +1 -0
  18. package/dist/assets/dedicated.worker-nY3tK4zi.js.map +1 -0
  19. package/dist/{worker.d.ts → core/BaseOPFS.d.ts} +34 -300
  20. package/dist/core/BaseOPFS.d.ts.map +1 -0
  21. package/dist/core/OPFSAsync.d.ts +55 -0
  22. package/dist/core/OPFSAsync.d.ts.map +1 -0
  23. package/dist/core/OPFSSync.d.ts +54 -0
  24. package/dist/core/OPFSSync.d.ts.map +1 -0
  25. package/dist/createOPFSAsync-BwKDmHsy.cjs +2 -0
  26. package/dist/createOPFSAsync-BwKDmHsy.cjs.map +1 -0
  27. package/dist/createOPFSAsync-Y4Mg6qte.js +10 -0
  28. package/dist/createOPFSAsync-Y4Mg6qte.js.map +1 -0
  29. package/dist/createOPFSDedicated-CsnV6MLP.js +2333 -0
  30. package/dist/createOPFSDedicated-CsnV6MLP.js.map +1 -0
  31. package/dist/createOPFSDedicated-pKTRWLdz.cjs +2283 -0
  32. package/dist/createOPFSDedicated-pKTRWLdz.cjs.map +1 -0
  33. package/dist/createOPFSShared-CGdd__PH.js +23 -0
  34. package/dist/createOPFSShared-CGdd__PH.js.map +1 -0
  35. package/dist/createOPFSShared-CskROt7U.cjs +2 -0
  36. package/dist/createOPFSShared-CskROt7U.cjs.map +1 -0
  37. package/dist/dedicated.worker.js +2281 -0
  38. package/dist/dedicated.worker.js.map +1 -0
  39. package/dist/{facade.d.ts → facade/OPFSFacade.d.ts} +35 -10
  40. package/dist/facade/OPFSFacade.d.ts.map +1 -0
  41. package/dist/facade/createOPFSAsync.d.ts +16 -0
  42. package/dist/facade/createOPFSAsync.d.ts.map +1 -0
  43. package/dist/facade/createOPFSDedicated.d.ts +17 -0
  44. package/dist/facade/createOPFSDedicated.d.ts.map +1 -0
  45. package/dist/facade/createOPFSShared.d.ts +24 -0
  46. package/dist/facade/createOPFSShared.d.ts.map +1 -0
  47. package/dist/index.async.cjs +2 -0
  48. package/dist/index.async.cjs.map +1 -0
  49. package/dist/index.async.d.ts +10 -0
  50. package/dist/index.async.d.ts.map +1 -0
  51. package/dist/index.async.js +55 -0
  52. package/dist/index.async.js.map +1 -0
  53. package/dist/index.cjs +1 -2466
  54. package/dist/index.cjs.map +1 -1
  55. package/dist/index.d.ts +15 -7
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +61 -2799
  58. package/dist/index.js.map +1 -1
  59. package/dist/index.pure.cjs +2 -0
  60. package/dist/index.pure.cjs.map +1 -0
  61. package/dist/index.pure.d.ts +8 -0
  62. package/dist/index.pure.d.ts.map +1 -0
  63. package/dist/index.pure.js +53 -0
  64. package/dist/index.pure.js.map +1 -0
  65. package/dist/index.sharedworker.cjs +2 -0
  66. package/dist/index.sharedworker.cjs.map +1 -0
  67. package/dist/index.sharedworker.d.ts +11 -0
  68. package/dist/index.sharedworker.d.ts.map +1 -0
  69. package/dist/index.sharedworker.js +55 -0
  70. package/dist/index.sharedworker.js.map +1 -0
  71. package/dist/index.sync.cjs +2 -0
  72. package/dist/index.sync.cjs.map +1 -0
  73. package/dist/index.sync.d.ts +11 -0
  74. package/dist/index.sync.d.ts.map +1 -0
  75. package/dist/index.sync.js +55 -0
  76. package/dist/index.sync.js.map +1 -0
  77. package/dist/shared.worker.js +2166 -0
  78. package/dist/shared.worker.js.map +1 -0
  79. package/dist/types.d.ts +9 -4
  80. package/dist/types.d.ts.map +1 -1
  81. package/dist/utils/helpers.d.ts +11 -1
  82. package/dist/utils/helpers.d.ts.map +1 -1
  83. package/dist/worker/createDedicatedWorker.d.ts +30 -0
  84. package/dist/worker/createDedicatedWorker.d.ts.map +1 -0
  85. package/dist/worker/createSharedWorker.d.ts +37 -0
  86. package/dist/worker/createSharedWorker.d.ts.map +1 -0
  87. package/dist/worker/dedicated.worker.d.ts +2 -0
  88. package/dist/worker/dedicated.worker.d.ts.map +1 -0
  89. package/dist/worker/shared.worker.d.ts +2 -0
  90. package/dist/worker/shared.worker.d.ts.map +1 -0
  91. package/docs/README.md +30 -0
  92. package/docs/api/backend.md +36 -0
  93. package/docs/api/create.md +82 -0
  94. package/docs/api/facade.md +52 -0
  95. package/docs/choosing-a-mode.md +41 -0
  96. package/docs/file-descriptors.md +695 -0
  97. package/docs/guides/async.md +36 -0
  98. package/docs/guides/dedicated.md +76 -0
  99. package/docs/guides/hashing.md +34 -0
  100. package/docs/guides/pure.md +46 -0
  101. package/docs/guides/sharedworker.md +57 -0
  102. package/docs/guides/streaming.md +51 -0
  103. package/docs/guides/watching.md +35 -0
  104. package/docs/migration.md +41 -0
  105. package/docs/types.md +246 -0
  106. package/package.json +55 -10
  107. package/src/core/BaseOPFS.ts +951 -0
  108. package/src/core/OPFSAsync.ts +248 -0
  109. package/src/core/OPFSSync.ts +460 -0
  110. package/src/facade/OPFSFacade.ts +489 -0
  111. package/src/facade/createOPFSAsync.ts +22 -0
  112. package/src/facade/createOPFSDedicated.ts +23 -0
  113. package/src/facade/createOPFSShared.ts +30 -0
  114. package/src/index.async.ts +11 -0
  115. package/src/index.pure.ts +8 -0
  116. package/src/index.sharedworker.ts +12 -0
  117. package/src/index.sync.ts +12 -0
  118. package/src/index.ts +44 -0
  119. package/src/types.ts +103 -0
  120. package/src/utils/encoder.ts +205 -0
  121. package/src/utils/errors.ts +297 -0
  122. package/src/utils/helpers.ts +465 -0
  123. package/src/worker/createDedicatedWorker.ts +74 -0
  124. package/src/worker/createSharedWorker.ts +67 -0
  125. package/src/worker/dedicated.worker.ts +13 -0
  126. package/src/worker/shared.worker.ts +17 -0
  127. package/dist/assets/worker-1Wh1cr7P.js.map +0 -1
  128. package/dist/assets/worker-BeJaVyBV.js.map +0 -1
  129. package/dist/assets/worker-DYYLzR1Y.js.map +0 -1
  130. package/dist/facade.d.ts.map +0 -1
  131. package/dist/helpers-BuGfPAg0.js +0 -1439
  132. package/dist/helpers-BuGfPAg0.js.map +0 -1
  133. package/dist/helpers-CF7A2WQG.cjs +0 -4
  134. package/dist/helpers-CF7A2WQG.cjs.map +0 -1
  135. package/dist/helpers-CIiblZ8d.cjs +0 -4
  136. package/dist/helpers-CIiblZ8d.cjs.map +0 -1
  137. package/dist/helpers-CKOebsbw.js +0 -1423
  138. package/dist/helpers-CKOebsbw.js.map +0 -1
  139. package/dist/helpers-Ca2c767K.js +0 -1427
  140. package/dist/helpers-Ca2c767K.js.map +0 -1
  141. package/dist/helpers-Dwc92hv9.cjs +0 -4
  142. package/dist/helpers-Dwc92hv9.cjs.map +0 -1
  143. package/dist/raw.cjs +0 -2
  144. package/dist/raw.cjs.map +0 -1
  145. package/dist/raw.d.ts +0 -13
  146. package/dist/raw.d.ts.map +0 -1
  147. package/dist/raw.js +0 -1001
  148. package/dist/raw.js.map +0 -1
  149. package/dist/worker.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -1,2802 +1,64 @@
1
- import { wrap as u } from "comlink";
2
- import { i as h, d as l, e as c } from "./helpers-Ca2c767K.js";
3
- import { A as E, M as S, D as P, E as O, F, j as A, c as T, I as R, h as C, O as I, a as D, f as $, g as _, P as N, b as k, S as z, V as M, W as j, o as L, B as W, z as U, K as H, l as B, C as G, y as Y, k as q, L as V, p as Z, x as J, u as X, n as K, m as Q, t as nn, r as tn, q as en, G as rn, v as sn, J as an, s as on, H as cn, w as hn } from "./helpers-Ca2c767K.js";
4
- const f = `/**
5
- * @license
6
- * Copyright 2019 Google LLC
7
- * SPDX-License-Identifier: Apache-2.0
8
- */
9
- const bt = Symbol("Comlink.proxy"), Ht = Symbol("Comlink.endpoint"), Wt = Symbol("Comlink.releaseProxy"), X = Symbol("Comlink.finalizer"), _ = Symbol("Comlink.thrown"), Ot = (s) => typeof s == "object" && s !== null || typeof s == "function", jt = {
10
- canHandle: (s) => Ot(s) && s[bt],
11
- serialize(s) {
12
- const { port1: t, port2: e } = new MessageChannel();
13
- return ot(s, t), [e, [e]];
14
- },
15
- deserialize(s) {
16
- return s.start(), Gt(s);
17
- }
18
- }, _t = {
19
- canHandle: (s) => Ot(s) && _ in s,
20
- serialize({ value: s }) {
21
- let t;
22
- return s instanceof Error ? t = {
23
- isError: !0,
24
- value: {
25
- message: s.message,
26
- name: s.name,
27
- stack: s.stack
28
- }
29
- } : t = { isError: !1, value: s }, [t, []];
30
- },
31
- deserialize(s) {
32
- throw s.isError ? Object.assign(new Error(s.value.message), s.value) : s.value;
33
- }
34
- }, Dt = /* @__PURE__ */ new Map([
35
- ["proxy", jt],
36
- ["throw", _t]
37
- ]);
38
- function Ut(s, t) {
39
- for (const e of s)
40
- if (t === e || e === "*" || e instanceof RegExp && e.test(t))
41
- return !0;
42
- return !1;
43
- }
44
- function ot(s, t = globalThis, e = ["*"]) {
45
- t.addEventListener("message", function n(r) {
46
- if (!r || !r.data)
47
- return;
48
- if (!Ut(e, r.origin)) {
49
- console.warn(\`Invalid origin '\${r.origin}' for comlink proxy\`);
50
- return;
51
- }
52
- const { id: i, type: o, path: a } = Object.assign({ path: [] }, r.data), l = (r.data.argumentList || []).map(C);
53
- let h;
54
- try {
55
- const c = a.slice(0, -1).reduce((u, d) => u[d], s), f = a.reduce((u, d) => u[d], s);
56
- switch (o) {
57
- case "GET":
58
- h = f;
59
- break;
60
- case "SET":
61
- c[a.slice(-1)[0]] = C(r.data.value), h = !0;
62
- break;
63
- case "APPLY":
64
- h = f.apply(c, l);
65
- break;
66
- case "CONSTRUCT":
67
- {
68
- const u = new f(...l);
69
- h = Zt(u);
70
- }
71
- break;
72
- case "ENDPOINT":
73
- {
74
- const { port1: u, port2: d } = new MessageChannel();
75
- ot(s, d), h = U(u, [u]);
76
- }
77
- break;
78
- case "RELEASE":
79
- h = void 0;
80
- break;
81
- default:
82
- return;
83
- }
84
- } catch (c) {
85
- h = { value: c, [_]: 0 };
86
- }
87
- Promise.resolve(h).catch((c) => ({ value: c, [_]: 0 })).then((c) => {
88
- const [f, u] = V(c);
89
- t.postMessage(Object.assign(Object.assign({}, f), { id: i }), u), o === "RELEASE" && (t.removeEventListener("message", n), vt(t), X in s && typeof s[X] == "function" && s[X]());
90
- }).catch((c) => {
91
- const [f, u] = V({
92
- value: new TypeError("Unserializable return value"),
93
- [_]: 0
94
- });
95
- t.postMessage(Object.assign(Object.assign({}, f), { id: i }), u);
96
- });
97
- }), t.start && t.start();
98
- }
99
- function Bt(s) {
100
- return s.constructor.name === "MessagePort";
101
- }
102
- function vt(s) {
103
- Bt(s) && s.close();
104
- }
105
- function Gt(s, t) {
106
- const e = /* @__PURE__ */ new Map();
107
- return s.addEventListener("message", function(r) {
108
- const { data: i } = r;
109
- if (!i || !i.id)
110
- return;
111
- const o = e.get(i.id);
112
- if (o)
113
- try {
114
- o(i);
115
- } finally {
116
- e.delete(i.id);
117
- }
118
- }), st(s, e, [], t);
119
- }
120
- function H(s) {
121
- if (s)
122
- throw new Error("Proxy has been released and is not useable");
123
- }
124
- function At(s) {
125
- return F(s, /* @__PURE__ */ new Map(), {
126
- type: "RELEASE"
127
- }).then(() => {
128
- vt(s);
129
- });
130
- }
131
- const G = /* @__PURE__ */ new WeakMap(), q = "FinalizationRegistry" in globalThis && new FinalizationRegistry((s) => {
132
- const t = (G.get(s) || 0) - 1;
133
- G.set(s, t), t === 0 && At(s);
134
- });
135
- function qt(s, t) {
136
- const e = (G.get(t) || 0) + 1;
137
- G.set(t, e), q && q.register(s, t, s);
138
- }
139
- function Vt(s) {
140
- q && q.unregister(s);
141
- }
142
- function st(s, t, e = [], n = function() {
143
- }) {
144
- let r = !1;
145
- const i = new Proxy(n, {
146
- get(o, a) {
147
- if (H(r), a === Wt)
148
- return () => {
149
- Vt(i), At(s), t.clear(), r = !0;
150
- };
151
- if (a === "then") {
152
- if (e.length === 0)
153
- return { then: () => i };
154
- const l = F(s, t, {
155
- type: "GET",
156
- path: e.map((h) => h.toString())
157
- }).then(C);
158
- return l.then.bind(l);
159
- }
160
- return st(s, t, [...e, a]);
161
- },
162
- set(o, a, l) {
163
- H(r);
164
- const [h, c] = V(l);
165
- return F(s, t, {
166
- type: "SET",
167
- path: [...e, a].map((f) => f.toString()),
168
- value: h
169
- }, c).then(C);
170
- },
171
- apply(o, a, l) {
172
- H(r);
173
- const h = e[e.length - 1];
174
- if (h === Ht)
175
- return F(s, t, {
176
- type: "ENDPOINT"
177
- }).then(C);
178
- if (h === "bind")
179
- return st(s, t, e.slice(0, -1));
180
- const [c, f] = ht(l);
181
- return F(s, t, {
182
- type: "APPLY",
183
- path: e.map((u) => u.toString()),
184
- argumentList: c
185
- }, f).then(C);
186
- },
187
- construct(o, a) {
188
- H(r);
189
- const [l, h] = ht(a);
190
- return F(s, t, {
191
- type: "CONSTRUCT",
192
- path: e.map((c) => c.toString()),
193
- argumentList: l
194
- }, h).then(C);
195
- }
196
- });
197
- return qt(i, s), i;
198
- }
199
- function Yt(s) {
200
- return Array.prototype.concat.apply([], s);
201
- }
202
- function ht(s) {
203
- const t = s.map(V);
204
- return [t.map((e) => e[0]), Yt(t.map((e) => e[1]))];
205
- }
206
- const Nt = /* @__PURE__ */ new WeakMap();
207
- function U(s, t) {
208
- return Nt.set(s, t), s;
209
- }
210
- function Zt(s) {
211
- return Object.assign(s, { [bt]: !0 });
212
- }
213
- function V(s) {
214
- for (const [t, e] of Dt)
215
- if (e.canHandle(s)) {
216
- const [n, r] = e.serialize(s);
217
- return [
218
- {
219
- type: "HANDLER",
220
- name: t,
221
- value: n
222
- },
223
- r
224
- ];
225
- }
226
- return [
227
- {
228
- type: "RAW",
229
- value: s
230
- },
231
- Nt.get(s) || []
232
- ];
233
- }
234
- function C(s) {
235
- switch (s.type) {
236
- case "HANDLER":
237
- return Dt.get(s.name).deserialize(s.value);
238
- case "RAW":
239
- return s.value;
240
- }
241
- }
242
- function F(s, t, e, n) {
243
- return new Promise((r) => {
244
- const i = Xt();
245
- t.set(i, r), s.start && s.start(), s.postMessage(Object.assign({ id: i }, e), n);
246
- });
247
- }
248
- function Xt() {
249
- return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
250
- }
251
- var D = /* @__PURE__ */ ((s) => (s.Added = "added", s.Changed = "changed", s.Removed = "removed", s))(D || {});
252
- const Jt = {
253
- ENOENT: -2,
254
- // No such file or directory
255
- EISDIR: -21,
256
- // Is a directory
257
- ENOTDIR: -20,
258
- // Not a directory
259
- EACCES: -13,
260
- // Permission denied
261
- EEXIST: -17,
262
- // File exists
263
- ENOTEMPTY: -39,
264
- // Directory not empty
265
- EINVAL: -22,
266
- // Invalid argument
267
- EIO: -5,
268
- // I/O error
269
- ENOSPC: -28,
270
- // No space left on device
271
- EBUSY: -16,
272
- // Device or resource busy
273
- EINTR: -4,
274
- // Interrupted system call
275
- ENOTSUP: -95,
276
- // Operation not supported
277
- ERANGE: -34,
278
- // Result too large
279
- EBADF: -9,
280
- // Bad file descriptor
281
- EROOT: -1
282
- // Custom: Cannot remove root directory
283
- };
284
- class w extends Error {
285
- errno;
286
- syscall;
287
- path;
288
- constructor(t, e, n, r, i) {
289
- super(t, { cause: i }), this.name = e, this.errno = Jt[e] || -1, this.path = n, this.syscall = r;
290
- }
291
- }
292
- class Qt extends w {
293
- constructor(t) {
294
- super("OPFS is not supported in this browser", "ENOTSUP", void 0, void 0, t);
295
- }
296
- }
297
- class Kt extends w {
298
- constructor(t, e, n) {
299
- super(t, "INVALID_PATH", e, "access", n);
300
- }
301
- }
302
- class R extends w {
303
- constructor(t, e, n) {
304
- const r = {
305
- file: \`File not found: \${e}\`,
306
- directory: \`Directory not found: \${e}\`,
307
- source: \`Source does not exist: \${e}\`
308
- };
309
- super(r[t], "ENOENT", e, "access", n);
310
- }
311
- }
312
- class te extends w {
313
- constructor(t, e, n) {
314
- super(\`Permission denied for \${e} on: \${t}\`, "EACCES", t, e, n);
315
- }
316
- }
317
- class ee extends w {
318
- constructor(t, e, n) {
319
- super(t, "ENOSPC", e, "write", n);
320
- }
321
- }
322
- class se extends w {
323
- constructor(t, e) {
324
- super(\`File is busy: \${t}\`, "EBUSY", t, "open", e);
325
- }
326
- }
327
- class nt extends w {
328
- constructor(t, e, n) {
329
- const r = t === "directory" ? \`Is a directory: \${e}\` : \`Not a directory: \${e}\`, i = t === "directory" ? "EISDIR" : "ENOTDIR";
330
- super(r, i, e, "access", n);
331
- }
332
- }
333
- class N extends w {
334
- constructor(t, e, n, r) {
335
- const i = {
336
- argument: "EINVAL",
337
- format: "INVALID_FORMAT",
338
- descriptor: "EBADF",
339
- overflow: "ERANGE"
340
- };
341
- super(e, i[t], n, "validate", r);
342
- }
343
- }
344
- class ne extends w {
345
- constructor(t, e) {
346
- super(\`Operation aborted: \${t}\`, "EINTR", t, "interrupt", e);
347
- }
348
- }
349
- class ut extends w {
350
- constructor(t, e, n) {
351
- super(t, "EIO", e, "io", n);
352
- }
353
- }
354
- class Ct extends w {
355
- constructor(t, e) {
356
- super(\`Operation not supported: \${t}\`, "ENOTSUP", t, "operation", e);
357
- }
358
- }
359
- class rt extends w {
360
- constructor(t, e, n) {
361
- const r = {
362
- RM_FAILED: \`Failed to remove entry: \${e}\`,
363
- ENOTEMPTY: \`Directory not empty: \${e}. Use recursive option to force removal.\`,
364
- EROOT: "Cannot remove root directory"
365
- };
366
- super(r[t] || \`Directory operation failed: \${e}\`, t, e, "unlink", n);
367
- }
368
- }
369
- class re extends w {
370
- constructor(t, e) {
371
- super("Failed to initialize OPFS", "INIT_FAILED", t, "init", e);
372
- }
373
- }
374
- class J extends w {
375
- constructor(t, e, n) {
376
- super(\`Failed to \${t}: \${e}\`, \`\${t.toUpperCase()}_FAILED\`, e, t, n);
377
- }
378
- }
379
- class Q extends w {
380
- constructor(t, e) {
381
- super(\`Destination already exists: \${t}\`, "EEXIST", t, "open", e);
382
- }
383
- }
384
- function W(s, t, e, n) {
385
- const r = \`\${s.toUpperCase()}_FAILED\`;
386
- return new w(\`Failed to \${s} file descriptor: \${t}\`, r, e, s, n);
387
- }
388
- function v(s, t) {
389
- const e = t?.path, n = t?.isDirectory, r = t?.existenceType ?? "file", i = t?.operation;
390
- switch (s.name) {
391
- case "InvalidStateError":
392
- return new se(e || "unknown", s);
393
- case "QuotaExceededError":
394
- return new ee(\`No space left on device: \${e || "unknown"}\`, e, s);
395
- case "NotFoundError":
396
- return new R(r, e, s);
397
- case "TypeMismatchError":
398
- return n !== void 0 ? n ? new nt("directory", e || "unknown", s) : new nt("file", e || "unknown", s) : new N("argument", \`Type mismatch: \${e || "unknown"}\`, e, s);
399
- case "NotAllowedError":
400
- case "SecurityError":
401
- return new te(e, "unknown", s);
402
- case "InvalidModificationError":
403
- return i === "remove" ? new rt("ENOTEMPTY", e, s) : new N("argument", \`Invalid modification: \${e || "unknown"}\`, e, s);
404
- case "AbortError":
405
- return new ne(e || "unknown", s);
406
- case "OperationError":
407
- return new ut(\`Operation failed: \${e || "unknown"}\`, e, s);
408
- case "TypeError":
409
- return new Ct(e || "unknown", s);
410
- default:
411
- return i === "remove" ? new rt("RM_FAILED", e, s) : new ut(\`I/O error: \${e || "unknown"}\`, e, s);
412
- }
413
- }
414
- const Ft = (s, t, e) => {
415
- const n = s instanceof RegExp ? ft(s, e) : s, r = t instanceof RegExp ? ft(t, e) : t, i = n !== null && r != null && ie(n, r, e);
416
- return i && {
417
- start: i[0],
418
- end: i[1],
419
- pre: e.slice(0, i[0]),
420
- body: e.slice(i[0] + n.length, i[1]),
421
- post: e.slice(i[1] + r.length)
422
- };
423
- }, ft = (s, t) => {
424
- const e = t.match(s);
425
- return e ? e[0] : null;
426
- }, ie = (s, t, e) => {
427
- let n, r, i, o, a, l = e.indexOf(s), h = e.indexOf(t, l + 1), c = l;
428
- if (l >= 0 && h > 0) {
429
- if (s === t)
430
- return [l, h];
431
- for (n = [], i = e.length; c >= 0 && !a; ) {
432
- if (c === l)
433
- n.push(c), l = e.indexOf(s, c + 1);
434
- else if (n.length === 1) {
435
- const f = n.pop();
436
- f !== void 0 && (a = [f, h]);
437
- } else
438
- r = n.pop(), r !== void 0 && r < i && (i = r, o = h), h = e.indexOf(t, c + 1);
439
- c = l < h && l >= 0 ? l : h;
440
- }
441
- n.length && o !== void 0 && (a = [i, o]);
442
- }
443
- return a;
444
- }, $t = "\\0SLASH" + Math.random() + "\\0", Mt = "\\0OPEN" + Math.random() + "\\0", at = "\\0CLOSE" + Math.random() + "\\0", Tt = "\\0COMMA" + Math.random() + "\\0", Pt = "\\0PERIOD" + Math.random() + "\\0", oe = new RegExp($t, "g"), ae = new RegExp(Mt, "g"), ce = new RegExp(at, "g"), le = new RegExp(Tt, "g"), he = new RegExp(Pt, "g"), ue = /\\\\\\\\/g, fe = /\\\\{/g, de = /\\\\}/g, pe = /\\\\,/g, ge = /\\\\./g;
445
- function K(s) {
446
- return isNaN(s) ? s.charCodeAt(0) : parseInt(s, 10);
447
- }
448
- function we(s) {
449
- return s.replace(ue, $t).replace(fe, Mt).replace(de, at).replace(pe, Tt).replace(ge, Pt);
450
- }
451
- function me(s) {
452
- return s.replace(oe, "\\\\").replace(ae, "{").replace(ce, "}").replace(le, ",").replace(he, ".");
453
- }
454
- function Rt(s) {
455
- if (!s)
456
- return [""];
457
- const t = [], e = Ft("{", "}", s);
458
- if (!e)
459
- return s.split(",");
460
- const { pre: n, body: r, post: i } = e, o = n.split(",");
461
- o[o.length - 1] += "{" + r + "}";
462
- const a = Rt(i);
463
- return i.length && (o[o.length - 1] += a.shift(), o.push.apply(o, a)), t.push.apply(t, o), t;
464
- }
465
- function ye(s) {
466
- return s ? (s.slice(0, 2) === "{}" && (s = "\\\\{\\\\}" + s.slice(2)), k(we(s), !0).map(me)) : [];
467
- }
468
- function Ee(s) {
469
- return "{" + s + "}";
470
- }
471
- function Se(s) {
472
- return /^-?0\\d/.test(s);
473
- }
474
- function xe(s, t) {
475
- return s <= t;
476
- }
477
- function be(s, t) {
478
- return s >= t;
479
- }
480
- function k(s, t) {
481
- const e = [], n = Ft("{", "}", s);
482
- if (!n)
483
- return [s];
484
- const r = n.pre, i = n.post.length ? k(n.post, !1) : [""];
485
- if (/\\$$/.test(n.pre))
486
- for (let o = 0; o < i.length; o++) {
487
- const a = r + "{" + n.body + "}" + i[o];
488
- e.push(a);
489
- }
490
- else {
491
- 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;
492
- if (!l && !h)
493
- return n.post.match(/,(?!,).*\\}/) ? (s = n.pre + "{" + n.body + at + n.post, k(s)) : [s];
494
- let c;
495
- if (l)
496
- c = n.body.split(/\\.\\./);
497
- else if (c = Rt(n.body), c.length === 1 && c[0] !== void 0 && (c = k(c[0], !1).map(Ee), c.length === 1))
498
- return i.map((u) => n.pre + c[0] + u);
499
- let f;
500
- if (l && c[0] !== void 0 && c[1] !== void 0) {
501
- const u = K(c[0]), d = K(c[1]), g = Math.max(c[0].length, c[1].length);
502
- let p = c.length === 3 && c[2] !== void 0 ? Math.abs(K(c[2])) : 1, S = xe;
503
- d < u && (p *= -1, S = be);
504
- const M = c.some(Se);
505
- f = [];
506
- for (let x = u; S(x, d); x += p) {
507
- let m;
508
- if (a)
509
- m = String.fromCharCode(x), m === "\\\\" && (m = "");
510
- else if (m = String(x), M) {
511
- const T = g - m.length;
512
- if (T > 0) {
513
- const z = new Array(T + 1).join("0");
514
- x < 0 ? m = "-" + z + m.slice(1) : m = z + m;
515
- }
516
- }
517
- f.push(m);
518
- }
519
- } else {
520
- f = [];
521
- for (let u = 0; u < c.length; u++)
522
- f.push.apply(f, k(c[u], !1));
523
- }
524
- for (let u = 0; u < f.length; u++)
525
- for (let d = 0; d < i.length; d++) {
526
- const g = r + f[u] + i[d];
527
- (!t || l || g) && e.push(g);
528
- }
529
- }
530
- return e;
531
- }
532
- const Oe = 1024 * 64, Y = (s) => {
533
- if (typeof s != "string")
534
- throw new TypeError("invalid pattern");
535
- if (s.length > Oe)
536
- throw new TypeError("pattern is too long");
537
- }, De = {
538
- "[:alnum:]": ["\\\\p{L}\\\\p{Nl}\\\\p{Nd}", !0],
539
- "[:alpha:]": ["\\\\p{L}\\\\p{Nl}", !0],
540
- "[:ascii:]": ["\\\\x00-\\\\x7f", !1],
541
- "[:blank:]": ["\\\\p{Zs}\\\\t", !0],
542
- "[:cntrl:]": ["\\\\p{Cc}", !0],
543
- "[:digit:]": ["\\\\p{Nd}", !0],
544
- "[:graph:]": ["\\\\p{Z}\\\\p{C}", !0, !0],
545
- "[:lower:]": ["\\\\p{Ll}", !0],
546
- "[:print:]": ["\\\\p{C}", !0],
547
- "[:punct:]": ["\\\\p{P}", !0],
548
- "[:space:]": ["\\\\p{Z}\\\\t\\\\r\\\\n\\\\v\\\\f", !0],
549
- "[:upper:]": ["\\\\p{Lu}", !0],
550
- "[:word:]": ["\\\\p{L}\\\\p{Nl}\\\\p{Nd}\\\\p{Pc}", !0],
551
- "[:xdigit:]": ["A-Fa-f0-9", !1]
552
- }, P = (s) => s.replace(/[[\\]\\\\-]/g, "\\\\$&"), ve = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&"), dt = (s) => s.join(""), Ae = (s, t) => {
553
- const e = t;
554
- if (s.charAt(e) !== "[")
555
- throw new Error("not in a brace expression");
556
- const n = [], r = [];
557
- let i = e + 1, o = !1, a = !1, l = !1, h = !1, c = e, f = "";
558
- t: for (; i < s.length; ) {
559
- const p = s.charAt(i);
560
- if ((p === "!" || p === "^") && i === e + 1) {
561
- h = !0, i++;
562
- continue;
563
- }
564
- if (p === "]" && o && !l) {
565
- c = i + 1;
566
- break;
567
- }
568
- if (o = !0, p === "\\\\" && !l) {
569
- l = !0, i++;
570
- continue;
571
- }
572
- if (p === "[" && !l) {
573
- for (const [S, [A, M, x]] of Object.entries(De))
574
- if (s.startsWith(S, i)) {
575
- if (f)
576
- return ["$.", !1, s.length - e, !0];
577
- i += S.length, x ? r.push(A) : n.push(A), a = a || M;
578
- continue t;
579
- }
580
- }
581
- if (l = !1, f) {
582
- p > f ? n.push(P(f) + "-" + P(p)) : p === f && n.push(P(p)), f = "", i++;
583
- continue;
584
- }
585
- if (s.startsWith("-]", i + 1)) {
586
- n.push(P(p + "-")), i += 2;
587
- continue;
588
- }
589
- if (s.startsWith("-", i + 1)) {
590
- f = p, i += 2;
591
- continue;
592
- }
593
- n.push(P(p)), i++;
594
- }
595
- if (c < i)
596
- return ["", !1, 0, !1];
597
- if (!n.length && !r.length)
598
- return ["$.", !1, s.length - e, !0];
599
- if (r.length === 0 && n.length === 1 && /^\\\\?.$/.test(n[0]) && !h) {
600
- const p = n[0].length === 2 ? n[0].slice(-1) : n[0];
601
- return [ve(p), !1, c - e, !1];
602
- }
603
- const u = "[" + (h ? "^" : "") + dt(n) + "]", d = "[" + (h ? "" : "^") + dt(r) + "]";
604
- return [n.length && r.length ? "(" + u + "|" + d + ")" : n.length ? u : d, a, c - e, !0];
605
- }, I = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/\\[([^\\/\\\\])\\]/g, "$1") : s.replace(/((?!\\\\).|^)\\[([^\\/\\\\])\\]/g, "$1$2").replace(/\\\\([^\\/])/g, "$1"), Ne = /* @__PURE__ */ new Set(["!", "?", "+", "*", "@"]), pt = (s) => Ne.has(s), Ce = "(?!(?:^|/)\\\\.\\\\.?(?:$|/))", j = "(?!\\\\.)", Fe = /* @__PURE__ */ new Set(["[", "."]), $e = /* @__PURE__ */ new Set(["..", "."]), Me = new Set("().*{}+?[]^$\\\\!"), Te = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&"), ct = "[^/]", gt = ct + "*?", wt = ct + "+?";
606
- class E {
607
- type;
608
- #s;
609
- #n;
610
- #i = !1;
611
- #t = [];
612
- #e;
613
- #o;
614
- #c;
615
- #a = !1;
616
- #r;
617
- #l;
618
- // set to true if it's an extglob with no children
619
- // (which really means one child of '')
620
- #u = !1;
621
- constructor(t, e, n = {}) {
622
- this.type = t, t && (this.#n = !0), this.#e = e, this.#s = this.#e ? this.#e.#s : this, this.#r = this.#s === this ? n : this.#s.#r, this.#c = this.#s === this ? [] : this.#s.#c, t === "!" && !this.#s.#a && this.#c.push(this), this.#o = this.#e ? this.#e.#t.length : 0;
623
- }
624
- get hasMagic() {
625
- if (this.#n !== void 0)
626
- return this.#n;
627
- for (const t of this.#t)
628
- if (typeof t != "string" && (t.type || t.hasMagic))
629
- return this.#n = !0;
630
- return this.#n;
631
- }
632
- // reconstructs the pattern
633
- toString() {
634
- return this.#l !== void 0 ? this.#l : this.type ? this.#l = this.type + "(" + this.#t.map((t) => String(t)).join("|") + ")" : this.#l = this.#t.map((t) => String(t)).join("");
635
- }
636
- #d() {
637
- if (this !== this.#s)
638
- throw new Error("should only call on root");
639
- if (this.#a)
640
- return this;
641
- this.toString(), this.#a = !0;
642
- let t;
643
- for (; t = this.#c.pop(); ) {
644
- if (t.type !== "!")
645
- continue;
646
- let e = t, n = e.#e;
647
- for (; n; ) {
648
- for (let r = e.#o + 1; !n.type && r < n.#t.length; r++)
649
- for (const i of t.#t) {
650
- if (typeof i == "string")
651
- throw new Error("string part in extglob AST??");
652
- i.copyIn(n.#t[r]);
653
- }
654
- e = n, n = e.#e;
655
- }
656
- }
657
- return this;
658
- }
659
- push(...t) {
660
- for (const e of t)
661
- if (e !== "") {
662
- if (typeof e != "string" && !(e instanceof E && e.#e === this))
663
- throw new Error("invalid part: " + e);
664
- this.#t.push(e);
665
- }
666
- }
667
- toJSON() {
668
- const t = this.type === null ? this.#t.slice().map((e) => typeof e == "string" ? e : e.toJSON()) : [this.type, ...this.#t.map((e) => e.toJSON())];
669
- return this.isStart() && !this.type && t.unshift([]), this.isEnd() && (this === this.#s || this.#s.#a && this.#e?.type === "!") && t.push({}), t;
670
- }
671
- isStart() {
672
- if (this.#s === this)
673
- return !0;
674
- if (!this.#e?.isStart())
675
- return !1;
676
- if (this.#o === 0)
677
- return !0;
678
- const t = this.#e;
679
- for (let e = 0; e < this.#o; e++) {
680
- const n = t.#t[e];
681
- if (!(n instanceof E && n.type === "!"))
682
- return !1;
683
- }
684
- return !0;
685
- }
686
- isEnd() {
687
- if (this.#s === this || this.#e?.type === "!")
688
- return !0;
689
- if (!this.#e?.isEnd())
690
- return !1;
691
- if (!this.type)
692
- return this.#e?.isEnd();
693
- const t = this.#e ? this.#e.#t.length : 0;
694
- return this.#o === t - 1;
695
- }
696
- copyIn(t) {
697
- typeof t == "string" ? this.push(t) : this.push(t.clone(this));
698
- }
699
- clone(t) {
700
- const e = new E(this.type, t);
701
- for (const n of this.#t)
702
- e.copyIn(n);
703
- return e;
704
- }
705
- static #h(t, e, n, r) {
706
- let i = !1, o = !1, a = -1, l = !1;
707
- if (e.type === null) {
708
- let d = n, g = "";
709
- for (; d < t.length; ) {
710
- const p = t.charAt(d++);
711
- if (i || p === "\\\\") {
712
- i = !i, g += p;
713
- continue;
714
- }
715
- if (o) {
716
- d === a + 1 ? (p === "^" || p === "!") && (l = !0) : p === "]" && !(d === a + 2 && l) && (o = !1), g += p;
717
- continue;
718
- } else if (p === "[") {
719
- o = !0, a = d, l = !1, g += p;
720
- continue;
721
- }
722
- if (!r.noext && pt(p) && t.charAt(d) === "(") {
723
- e.push(g), g = "";
724
- const S = new E(p, e);
725
- d = E.#h(t, S, d, r), e.push(S);
726
- continue;
727
- }
728
- g += p;
729
- }
730
- return e.push(g), d;
731
- }
732
- let h = n + 1, c = new E(null, e);
733
- const f = [];
734
- let u = "";
735
- for (; h < t.length; ) {
736
- const d = t.charAt(h++);
737
- if (i || d === "\\\\") {
738
- i = !i, u += d;
739
- continue;
740
- }
741
- if (o) {
742
- h === a + 1 ? (d === "^" || d === "!") && (l = !0) : d === "]" && !(h === a + 2 && l) && (o = !1), u += d;
743
- continue;
744
- } else if (d === "[") {
745
- o = !0, a = h, l = !1, u += d;
746
- continue;
747
- }
748
- if (pt(d) && t.charAt(h) === "(") {
749
- c.push(u), u = "";
750
- const g = new E(d, c);
751
- c.push(g), h = E.#h(t, g, h, r);
752
- continue;
753
- }
754
- if (d === "|") {
755
- c.push(u), u = "", f.push(c), c = new E(null, e);
756
- continue;
757
- }
758
- if (d === ")")
759
- return u === "" && e.#t.length === 0 && (e.#u = !0), c.push(u), u = "", e.push(...f, c), h;
760
- u += d;
761
- }
762
- return e.type = null, e.#n = void 0, e.#t = [t.substring(n - 1)], h;
763
- }
764
- static fromGlob(t, e = {}) {
765
- const n = new E(null, void 0, e);
766
- return E.#h(t, n, 0, e), n;
767
- }
768
- // returns the regular expression if there's magic, or the unescaped
769
- // string if not.
770
- toMMPattern() {
771
- if (this !== this.#s)
772
- return this.#s.toMMPattern();
773
- const t = this.toString(), [e, n, r, i] = this.toRegExpSource();
774
- if (!(r || this.#n || this.#r.nocase && !this.#r.nocaseMagicOnly && t.toUpperCase() !== t.toLowerCase()))
775
- return n;
776
- const a = (this.#r.nocase ? "i" : "") + (i ? "u" : "");
777
- return Object.assign(new RegExp(\`^\${e}$\`, a), {
778
- _src: e,
779
- _glob: t
780
- });
781
- }
782
- get options() {
783
- return this.#r;
784
- }
785
- // returns the string match, the regexp source, whether there's magic
786
- // in the regexp (so a regular expression is required) and whether or
787
- // not the uflag is needed for the regular expression (for posix classes)
788
- // TODO: instead of injecting the start/end at this point, just return
789
- // the BODY of the regexp, along with the start/end portions suitable
790
- // for binding the start/end in either a joined full-path makeRe context
791
- // (where we bind to (^|/), or a standalone matchPart context (where
792
- // we bind to ^, and not /). Otherwise slashes get duped!
793
- //
794
- // In part-matching mode, the start is:
795
- // - if not isStart: nothing
796
- // - if traversal possible, but not allowed: ^(?!\\.\\.?$)
797
- // - if dots allowed or not possible: ^
798
- // - if dots possible and not allowed: ^(?!\\.)
799
- // end is:
800
- // - if not isEnd(): nothing
801
- // - else: $
802
- //
803
- // In full-path matching mode, we put the slash at the START of the
804
- // pattern, so start is:
805
- // - if first pattern: same as part-matching mode
806
- // - if not isStart(): nothing
807
- // - if traversal possible, but not allowed: /(?!\\.\\.?(?:$|/))
808
- // - if dots allowed or not possible: /
809
- // - if dots possible and not allowed: /(?!\\.)
810
- // end is:
811
- // - if last pattern, same as part-matching mode
812
- // - else nothing
813
- //
814
- // Always put the (?:$|/) on negated tails, though, because that has to be
815
- // there to bind the end of the negated pattern portion, and it's easier to
816
- // just stick it in now rather than try to inject it later in the middle of
817
- // the pattern.
818
- //
819
- // We can just always return the same end, and leave it up to the caller
820
- // to know whether it's going to be used joined or in parts.
821
- // And, if the start is adjusted slightly, can do the same there:
822
- // - if not isStart: nothing
823
- // - if traversal possible, but not allowed: (?:/|^)(?!\\.\\.?$)
824
- // - if dots allowed or not possible: (?:/|^)
825
- // - if dots possible and not allowed: (?:/|^)(?!\\.)
826
- //
827
- // But it's better to have a simpler binding without a conditional, for
828
- // performance, so probably better to return both start options.
829
- //
830
- // Then the caller just ignores the end if it's not the first pattern,
831
- // and the start always gets applied.
832
- //
833
- // But that's always going to be $ if it's the ending pattern, or nothing,
834
- // so the caller can just attach $ at the end of the pattern when building.
835
- //
836
- // So the todo is:
837
- // - better detect what kind of start is needed
838
- // - return both flavors of starting pattern
839
- // - attach $ at the end of the pattern when creating the actual RegExp
840
- //
841
- // Ah, but wait, no, that all only applies to the root when the first pattern
842
- // is not an extglob. If the first pattern IS an extglob, then we need all
843
- // that dot prevention biz to live in the extglob portions, because eg
844
- // +(*|.x*) can match .xy but not .yx.
845
- //
846
- // So, return the two flavors if it's #root and the first child is not an
847
- // AST, otherwise leave it to the child AST to handle it, and there,
848
- // use the (?:^|/) style of start binding.
849
- //
850
- // Even simplified further:
851
- // - Since the start for a join is eg /(?!\\.) and the start for a part
852
- // is ^(?!\\.), we can just prepend (?!\\.) to the pattern (either root
853
- // or start or whatever) and prepend ^ or / at the Regexp construction.
854
- toRegExpSource(t) {
855
- const e = t ?? !!this.#r.dot;
856
- if (this.#s === this && this.#d(), !this.type) {
857
- const l = this.isStart() && this.isEnd(), h = this.#t.map((d) => {
858
- const [g, p, S, A] = typeof d == "string" ? E.#p(d, this.#n, l) : d.toRegExpSource(t);
859
- return this.#n = this.#n || S, this.#i = this.#i || A, g;
860
- }).join("");
861
- let c = "";
862
- if (this.isStart() && typeof this.#t[0] == "string" && !(this.#t.length === 1 && $e.has(this.#t[0]))) {
863
- const g = Fe, p = (
864
- // dots are allowed, and the pattern starts with [ or .
865
- e && g.has(h.charAt(0)) || // the pattern starts with \\., and then [ or .
866
- h.startsWith("\\\\.") && g.has(h.charAt(2)) || // the pattern starts with \\.\\., and then [ or .
867
- h.startsWith("\\\\.\\\\.") && g.has(h.charAt(4))
868
- ), S = !e && !t && g.has(h.charAt(0));
869
- c = p ? Ce : S ? j : "";
870
- }
871
- let f = "";
872
- return this.isEnd() && this.#s.#a && this.#e?.type === "!" && (f = "(?:$|\\\\/)"), [
873
- c + h + f,
874
- I(h),
875
- this.#n = !!this.#n,
876
- this.#i
877
- ];
878
- }
879
- const n = this.type === "*" || this.type === "+", r = this.type === "!" ? "(?:(?!(?:" : "(?:";
880
- let i = this.#f(e);
881
- if (this.isStart() && this.isEnd() && !i && this.type !== "!") {
882
- const l = this.toString();
883
- return this.#t = [l], this.type = null, this.#n = void 0, [l, I(this.toString()), !1, !1];
884
- }
885
- let o = !n || t || e || !j ? "" : this.#f(!0);
886
- o === i && (o = ""), o && (i = \`(?:\${i})(?:\${o})*?\`);
887
- let a = "";
888
- if (this.type === "!" && this.#u)
889
- a = (this.isStart() && !e ? j : "") + wt;
890
- else {
891
- const l = this.type === "!" ? (
892
- // !() must match something,but !(x) can match ''
893
- "))" + (this.isStart() && !e && !t ? j : "") + gt + ")"
894
- ) : this.type === "@" ? ")" : this.type === "?" ? ")?" : this.type === "+" && o ? ")" : this.type === "*" && o ? ")?" : \`)\${this.type}\`;
895
- a = r + i + l;
896
- }
897
- return [
898
- a,
899
- I(i),
900
- this.#n = !!this.#n,
901
- this.#i
902
- ];
903
- }
904
- #f(t) {
905
- return this.#t.map((e) => {
906
- if (typeof e == "string")
907
- throw new Error("string type in extglob ast??");
908
- const [n, r, i, o] = e.toRegExpSource(t);
909
- return this.#i = this.#i || o, n;
910
- }).filter((e) => !(this.isStart() && this.isEnd()) || !!e).join("|");
911
- }
912
- static #p(t, e, n = !1) {
913
- let r = !1, i = "", o = !1;
914
- for (let a = 0; a < t.length; a++) {
915
- const l = t.charAt(a);
916
- if (r) {
917
- r = !1, i += (Me.has(l) ? "\\\\" : "") + l;
918
- continue;
919
- }
920
- if (l === "\\\\") {
921
- a === t.length - 1 ? i += "\\\\\\\\" : r = !0;
922
- continue;
923
- }
924
- if (l === "[") {
925
- const [h, c, f, u] = Ae(t, a);
926
- if (f) {
927
- i += h, o = o || c, a += f - 1, e = e || u;
928
- continue;
929
- }
930
- }
931
- if (l === "*") {
932
- n && t === "*" ? i += wt : i += gt, e = !0;
933
- continue;
934
- }
935
- if (l === "?") {
936
- i += ct, e = !0;
937
- continue;
938
- }
939
- i += Te(l);
940
- }
941
- return [i, I(t), !!e, o];
942
- }
943
- }
944
- const Pe = (s, { windowsPathsNoEscape: t = !1 } = {}) => t ? s.replace(/[?*()[\\]]/g, "[$&]") : s.replace(/[?*()[\\]\\\\]/g, "\\\\$&"), y = (s, t, e = {}) => (Y(t), !e.nocomment && t.charAt(0) === "#" ? !1 : new Z(t, e).match(s)), Re = /^\\*+([^+@!?\\*\\[\\(]*)$/, ke = (s) => (t) => !t.startsWith(".") && t.endsWith(s), Ie = (s) => (t) => t.endsWith(s), Le = (s) => (s = s.toLowerCase(), (t) => !t.startsWith(".") && t.toLowerCase().endsWith(s)), ze = (s) => (s = s.toLowerCase(), (t) => t.toLowerCase().endsWith(s)), He = /^\\*+\\.\\*+$/, We = (s) => !s.startsWith(".") && s.includes("."), je = (s) => s !== "." && s !== ".." && s.includes("."), _e = /^\\.\\*+$/, Ue = (s) => s !== "." && s !== ".." && s.startsWith("."), Be = /^\\*+$/, Ge = (s) => s.length !== 0 && !s.startsWith("."), qe = (s) => s.length !== 0 && s !== "." && s !== "..", Ve = /^\\?+([^+@!?\\*\\[\\(]*)?$/, Ye = ([s, t = ""]) => {
945
- const e = kt([s]);
946
- return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
947
- }, Ze = ([s, t = ""]) => {
948
- const e = It([s]);
949
- return t ? (t = t.toLowerCase(), (n) => e(n) && n.toLowerCase().endsWith(t)) : e;
950
- }, Xe = ([s, t = ""]) => {
951
- const e = It([s]);
952
- return t ? (n) => e(n) && n.endsWith(t) : e;
953
- }, Je = ([s, t = ""]) => {
954
- const e = kt([s]);
955
- return t ? (n) => e(n) && n.endsWith(t) : e;
956
- }, kt = ([s]) => {
957
- const t = s.length;
958
- return (e) => e.length === t && !e.startsWith(".");
959
- }, It = ([s]) => {
960
- const t = s.length;
961
- return (e) => e.length === t && e !== "." && e !== "..";
962
- }, Lt = typeof process == "object" && process ? typeof process.env == "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix", mt = {
963
- win32: { sep: "\\\\" },
964
- posix: { sep: "/" }
965
- }, Qe = Lt === "win32" ? mt.win32.sep : mt.posix.sep;
966
- y.sep = Qe;
967
- const O = Symbol("globstar **");
968
- y.GLOBSTAR = O;
969
- const Ke = "[^/]", ts = Ke + "*?", es = "(?:(?!(?:\\\\/|^)(?:\\\\.{1,2})($|\\\\/)).)*?", ss = "(?:(?!(?:\\\\/|^)\\\\.).)*?", ns = (s, t = {}) => (e) => y(e, s, t);
970
- y.filter = ns;
971
- const b = (s, t = {}) => Object.assign({}, s, t), rs = (s) => {
972
- if (!s || typeof s != "object" || !Object.keys(s).length)
973
- return y;
974
- const t = y;
975
- return Object.assign((n, r, i = {}) => t(n, r, b(s, i)), {
976
- Minimatch: class extends t.Minimatch {
977
- constructor(r, i = {}) {
978
- super(r, b(s, i));
979
- }
980
- static defaults(r) {
981
- return t.defaults(b(s, r)).Minimatch;
982
- }
983
- },
984
- AST: class extends t.AST {
985
- /* c8 ignore start */
986
- constructor(r, i, o = {}) {
987
- super(r, i, b(s, o));
988
- }
989
- /* c8 ignore stop */
990
- static fromGlob(r, i = {}) {
991
- return t.AST.fromGlob(r, b(s, i));
992
- }
993
- },
994
- unescape: (n, r = {}) => t.unescape(n, b(s, r)),
995
- escape: (n, r = {}) => t.escape(n, b(s, r)),
996
- filter: (n, r = {}) => t.filter(n, b(s, r)),
997
- defaults: (n) => t.defaults(b(s, n)),
998
- makeRe: (n, r = {}) => t.makeRe(n, b(s, r)),
999
- braceExpand: (n, r = {}) => t.braceExpand(n, b(s, r)),
1000
- match: (n, r, i = {}) => t.match(n, r, b(s, i)),
1001
- sep: t.sep,
1002
- GLOBSTAR: O
1003
- });
1004
- };
1005
- y.defaults = rs;
1006
- const zt = (s, t = {}) => (Y(s), t.nobrace || !/\\{(?:(?!\\{).)*\\}/.test(s) ? [s] : ye(s));
1007
- y.braceExpand = zt;
1008
- const is = (s, t = {}) => new Z(s, t).makeRe();
1009
- y.makeRe = is;
1010
- const os = (s, t, e = {}) => {
1011
- const n = new Z(t, e);
1012
- return s = s.filter((r) => n.match(r)), n.options.nonull && !s.length && s.push(t), s;
1013
- };
1014
- y.match = os;
1015
- const yt = /[?*]|[+@!]\\(.*?\\)|\\[|\\]/, as = (s) => s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, "\\\\$&");
1016
- class Z {
1017
- options;
1018
- set;
1019
- pattern;
1020
- windowsPathsNoEscape;
1021
- nonegate;
1022
- negate;
1023
- comment;
1024
- empty;
1025
- preserveMultipleSlashes;
1026
- partial;
1027
- globSet;
1028
- globParts;
1029
- nocase;
1030
- isWindows;
1031
- platform;
1032
- windowsNoMagicRoot;
1033
- regexp;
1034
- constructor(t, e = {}) {
1035
- Y(t), e = e || {}, this.options = e, this.pattern = t, this.platform = e.platform || Lt, 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();
1036
- }
1037
- hasMagic() {
1038
- if (this.options.magicalBraces && this.set.length > 1)
1039
- return !0;
1040
- for (const t of this.set)
1041
- for (const e of t)
1042
- if (typeof e != "string")
1043
- return !0;
1044
- return !1;
1045
- }
1046
- debug(...t) {
1047
- }
1048
- make() {
1049
- const t = this.pattern, e = this.options;
1050
- if (!e.nocomment && t.charAt(0) === "#") {
1051
- this.comment = !0;
1052
- return;
1053
- }
1054
- if (!t) {
1055
- this.empty = !0;
1056
- return;
1057
- }
1058
- this.parseNegate(), this.globSet = [...new Set(this.braceExpand())], e.debug && (this.debug = (...i) => console.error(...i)), this.debug(this.pattern, this.globSet);
1059
- const n = this.globSet.map((i) => this.slashSplit(i));
1060
- this.globParts = this.preprocess(n), this.debug(this.pattern, this.globParts);
1061
- let r = this.globParts.map((i, o, a) => {
1062
- if (this.isWindows && this.windowsNoMagicRoot) {
1063
- const l = i[0] === "" && i[1] === "" && (i[2] === "?" || !yt.test(i[2])) && !yt.test(i[3]), h = /^[a-z]:/i.test(i[0]);
1064
- if (l)
1065
- return [...i.slice(0, 4), ...i.slice(4).map((c) => this.parse(c))];
1066
- if (h)
1067
- return [i[0], ...i.slice(1).map((c) => this.parse(c))];
1068
- }
1069
- return i.map((l) => this.parse(l));
1070
- });
1071
- if (this.debug(this.pattern, r), this.set = r.filter((i) => i.indexOf(!1) === -1), this.isWindows)
1072
- for (let i = 0; i < this.set.length; i++) {
1073
- const o = this.set[i];
1074
- o[0] === "" && o[1] === "" && this.globParts[i][2] === "?" && typeof o[3] == "string" && /^[a-z]:$/i.test(o[3]) && (o[2] = "?");
1075
- }
1076
- this.debug(this.pattern, this.set);
1077
- }
1078
- // various transforms to equivalent pattern sets that are
1079
- // faster to process in a filesystem walk. The goal is to
1080
- // eliminate what we can, and push all ** patterns as far
1081
- // to the right as possible, even if it increases the number
1082
- // of patterns that we have to process.
1083
- preprocess(t) {
1084
- if (this.options.noglobstar)
1085
- for (let n = 0; n < t.length; n++)
1086
- for (let r = 0; r < t[n].length; r++)
1087
- t[n][r] === "**" && (t[n][r] = "*");
1088
- const { optimizationLevel: e = 1 } = this.options;
1089
- return e >= 2 ? (t = this.firstPhasePreProcess(t), t = this.secondPhasePreProcess(t)) : e >= 1 ? t = this.levelOneOptimize(t) : t = this.adjascentGlobstarOptimize(t), t;
1090
- }
1091
- // just get rid of adjascent ** portions
1092
- adjascentGlobstarOptimize(t) {
1093
- return t.map((e) => {
1094
- let n = -1;
1095
- for (; (n = e.indexOf("**", n + 1)) !== -1; ) {
1096
- let r = n;
1097
- for (; e[r + 1] === "**"; )
1098
- r++;
1099
- r !== n && e.splice(n, r - n);
1100
- }
1101
- return e;
1102
- });
1103
- }
1104
- // get rid of adjascent ** and resolve .. portions
1105
- levelOneOptimize(t) {
1106
- return t.map((e) => (e = e.reduce((n, r) => {
1107
- const i = n[n.length - 1];
1108
- return r === "**" && i === "**" ? n : r === ".." && i && i !== ".." && i !== "." && i !== "**" ? (n.pop(), n) : (n.push(r), n);
1109
- }, []), e.length === 0 ? [""] : e));
1110
- }
1111
- levelTwoFileOptimize(t) {
1112
- Array.isArray(t) || (t = this.slashSplit(t));
1113
- let e = !1;
1114
- do {
1115
- if (e = !1, !this.preserveMultipleSlashes) {
1116
- for (let r = 1; r < t.length - 1; r++) {
1117
- const i = t[r];
1118
- r === 1 && i === "" && t[0] === "" || (i === "." || i === "") && (e = !0, t.splice(r, 1), r--);
1119
- }
1120
- t[0] === "." && t.length === 2 && (t[1] === "." || t[1] === "") && (e = !0, t.pop());
1121
- }
1122
- let n = 0;
1123
- for (; (n = t.indexOf("..", n + 1)) !== -1; ) {
1124
- const r = t[n - 1];
1125
- r && r !== "." && r !== ".." && r !== "**" && (e = !0, t.splice(n - 1, 2), n -= 2);
1126
- }
1127
- } while (e);
1128
- return t.length === 0 ? [""] : t;
1129
- }
1130
- // First phase: single-pattern processing
1131
- // <pre> is 1 or more portions
1132
- // <rest> is 1 or more portions
1133
- // <p> is any portion other than ., .., '', or **
1134
- // <e> is . or ''
1135
- //
1136
- // **/.. is *brutal* for filesystem walking performance, because
1137
- // it effectively resets the recursive walk each time it occurs,
1138
- // and ** cannot be reduced out by a .. pattern part like a regexp
1139
- // or most strings (other than .., ., and '') can be.
1140
- //
1141
- // <pre>/**/../<p>/<p>/<rest> -> {<pre>/../<p>/<p>/<rest>,<pre>/**/<p>/<p>/<rest>}
1142
- // <pre>/<e>/<rest> -> <pre>/<rest>
1143
- // <pre>/<p>/../<rest> -> <pre>/<rest>
1144
- // **/**/<rest> -> **/<rest>
1145
- //
1146
- // **/*/<rest> -> */**/<rest> <== not valid because ** doesn't follow
1147
- // this WOULD be allowed if ** did follow symlinks, or * didn't
1148
- firstPhasePreProcess(t) {
1149
- let e = !1;
1150
- do {
1151
- e = !1;
1152
- for (let n of t) {
1153
- let r = -1;
1154
- for (; (r = n.indexOf("**", r + 1)) !== -1; ) {
1155
- let o = r;
1156
- for (; n[o + 1] === "**"; )
1157
- o++;
1158
- o > r && n.splice(r + 1, o - r);
1159
- let a = n[r + 1];
1160
- const l = n[r + 2], h = n[r + 3];
1161
- if (a !== ".." || !l || l === "." || l === ".." || !h || h === "." || h === "..")
1162
- continue;
1163
- e = !0, n.splice(r, 1);
1164
- const c = n.slice(0);
1165
- c[r] = "**", t.push(c), r--;
1166
- }
1167
- if (!this.preserveMultipleSlashes) {
1168
- for (let o = 1; o < n.length - 1; o++) {
1169
- const a = n[o];
1170
- o === 1 && a === "" && n[0] === "" || (a === "." || a === "") && (e = !0, n.splice(o, 1), o--);
1171
- }
1172
- n[0] === "." && n.length === 2 && (n[1] === "." || n[1] === "") && (e = !0, n.pop());
1173
- }
1174
- let i = 0;
1175
- for (; (i = n.indexOf("..", i + 1)) !== -1; ) {
1176
- const o = n[i - 1];
1177
- if (o && o !== "." && o !== ".." && o !== "**") {
1178
- e = !0;
1179
- const l = i === 1 && n[i + 1] === "**" ? ["."] : [];
1180
- n.splice(i - 1, 2, ...l), n.length === 0 && n.push(""), i -= 2;
1181
- }
1182
- }
1183
- }
1184
- } while (e);
1185
- return t;
1186
- }
1187
- // second phase: multi-pattern dedupes
1188
- // {<pre>/*/<rest>,<pre>/<p>/<rest>} -> <pre>/*/<rest>
1189
- // {<pre>/<rest>,<pre>/<rest>} -> <pre>/<rest>
1190
- // {<pre>/**/<rest>,<pre>/<rest>} -> <pre>/**/<rest>
1191
- //
1192
- // {<pre>/**/<rest>,<pre>/**/<p>/<rest>} -> <pre>/**/<rest>
1193
- // ^-- not valid because ** doens't follow symlinks
1194
- secondPhasePreProcess(t) {
1195
- for (let e = 0; e < t.length - 1; e++)
1196
- for (let n = e + 1; n < t.length; n++) {
1197
- const r = this.partsMatch(t[e], t[n], !this.preserveMultipleSlashes);
1198
- if (r) {
1199
- t[e] = [], t[n] = r;
1200
- break;
1201
- }
1202
- }
1203
- return t.filter((e) => e.length);
1204
- }
1205
- partsMatch(t, e, n = !1) {
1206
- let r = 0, i = 0, o = [], a = "";
1207
- for (; r < t.length && i < e.length; )
1208
- if (t[r] === e[i])
1209
- o.push(a === "b" ? e[i] : t[r]), r++, i++;
1210
- else if (n && t[r] === "**" && e[i] === t[r + 1])
1211
- o.push(t[r]), r++;
1212
- else if (n && e[i] === "**" && t[r] === e[i + 1])
1213
- o.push(e[i]), i++;
1214
- else if (t[r] === "*" && e[i] && (this.options.dot || !e[i].startsWith(".")) && e[i] !== "**") {
1215
- if (a === "b")
1216
- return !1;
1217
- a = "a", o.push(t[r]), r++, i++;
1218
- } else if (e[i] === "*" && t[r] && (this.options.dot || !t[r].startsWith(".")) && t[r] !== "**") {
1219
- if (a === "a")
1220
- return !1;
1221
- a = "b", o.push(e[i]), r++, i++;
1222
- } else
1223
- return !1;
1224
- return t.length === e.length && o;
1225
- }
1226
- parseNegate() {
1227
- if (this.nonegate)
1228
- return;
1229
- const t = this.pattern;
1230
- let e = !1, n = 0;
1231
- for (let r = 0; r < t.length && t.charAt(r) === "!"; r++)
1232
- e = !e, n++;
1233
- n && (this.pattern = t.slice(n)), this.negate = e;
1234
- }
1235
- // set partial to true to test if, for example,
1236
- // "/a/b" matches the start of "/*/b/*/d"
1237
- // Partial means, if you run out of file before you run
1238
- // out of pattern, then that's fine, as long as all
1239
- // the parts match.
1240
- matchOne(t, e, n = !1) {
1241
- const r = this.options;
1242
- if (this.isWindows) {
1243
- 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]), M = !A && e[0] === "" && e[1] === "" && e[2] === "?" && typeof e[3] == "string" && /^[a-z]:$/i.test(e[3]), x = S ? 3 : p ? 0 : void 0, m = M ? 3 : A ? 0 : void 0;
1244
- if (typeof x == "number" && typeof m == "number") {
1245
- const [T, z] = [t[x], e[m]];
1246
- T.toLowerCase() === z.toLowerCase() && (e[m] = T, m > x ? e = e.slice(m) : x > m && (t = t.slice(x)));
1247
- }
1248
- }
1249
- const { optimizationLevel: i = 1 } = this.options;
1250
- i >= 2 && (t = this.levelTwoFileOptimize(t)), this.debug("matchOne", this, { file: t, pattern: e }), this.debug("matchOne", t.length, e.length);
1251
- for (var o = 0, a = 0, l = t.length, h = e.length; o < l && a < h; o++, a++) {
1252
- this.debug("matchOne loop");
1253
- var c = e[a], f = t[o];
1254
- if (this.debug(e, c, f), c === !1)
1255
- return !1;
1256
- if (c === O) {
1257
- this.debug("GLOBSTAR", [e, c, f]);
1258
- var u = o, d = a + 1;
1259
- if (d === h) {
1260
- for (this.debug("** at the end"); o < l; o++)
1261
- if (t[o] === "." || t[o] === ".." || !r.dot && t[o].charAt(0) === ".")
1262
- return !1;
1263
- return !0;
1264
- }
1265
- for (; u < l; ) {
1266
- var g = t[u];
1267
- if (this.debug(\`
1268
- globstar while\`, t, u, e, d, g), this.matchOne(t.slice(u), e.slice(d), n))
1269
- return this.debug("globstar found match!", u, l, g), !0;
1270
- if (g === "." || g === ".." || !r.dot && g.charAt(0) === ".") {
1271
- this.debug("dot detected!", t, u, e, d);
1272
- break;
1273
- }
1274
- this.debug("globstar swallow a segment, and continue"), u++;
1275
- }
1276
- return !!(n && (this.debug(\`
1277
- >>> no match, partial?\`, t, u, e, d), u === l));
1278
- }
1279
- let p;
1280
- if (typeof c == "string" ? (p = f === c, this.debug("string match", c, f, p)) : (p = c.test(f), this.debug("pattern match", c, f, p)), !p)
1281
- return !1;
1282
- }
1283
- if (o === l && a === h)
1284
- return !0;
1285
- if (o === l)
1286
- return n;
1287
- if (a === h)
1288
- return o === l - 1 && t[o] === "";
1289
- throw new Error("wtf?");
1290
- }
1291
- braceExpand() {
1292
- return zt(this.pattern, this.options);
1293
- }
1294
- parse(t) {
1295
- Y(t);
1296
- const e = this.options;
1297
- if (t === "**")
1298
- return O;
1299
- if (t === "")
1300
- return "";
1301
- let n, r = null;
1302
- (n = t.match(Be)) ? r = e.dot ? qe : Ge : (n = t.match(Re)) ? r = (e.nocase ? e.dot ? ze : Le : e.dot ? Ie : ke)(n[1]) : (n = t.match(Ve)) ? r = (e.nocase ? e.dot ? Ze : Ye : e.dot ? Xe : Je)(n) : (n = t.match(He)) ? r = e.dot ? je : We : (n = t.match(_e)) && (r = Ue);
1303
- const i = E.fromGlob(t, this.options).toMMPattern();
1304
- return r && typeof i == "object" && Reflect.defineProperty(i, "test", { value: r }), i;
1305
- }
1306
- makeRe() {
1307
- if (this.regexp || this.regexp === !1)
1308
- return this.regexp;
1309
- const t = this.set;
1310
- if (!t.length)
1311
- return this.regexp = !1, this.regexp;
1312
- const e = this.options, n = e.noglobstar ? ts : e.dot ? es : ss, r = new Set(e.nocase ? ["i"] : []);
1313
- let i = t.map((l) => {
1314
- const h = l.map((c) => {
1315
- if (c instanceof RegExp)
1316
- for (const f of c.flags.split(""))
1317
- r.add(f);
1318
- return typeof c == "string" ? as(c) : c === O ? O : c._src;
1319
- });
1320
- return h.forEach((c, f) => {
1321
- const u = h[f + 1], d = h[f - 1];
1322
- c !== O || d === O || (d === void 0 ? u !== void 0 && u !== O ? h[f + 1] = "(?:\\\\/|" + n + "\\\\/)?" + u : h[f] = n : u === void 0 ? h[f - 1] = d + "(?:\\\\/|" + n + ")?" : u !== O && (h[f - 1] = d + "(?:\\\\/|\\\\/" + n + "\\\\/)" + u, h[f + 1] = O));
1323
- }), h.filter((c) => c !== O).join("/");
1324
- }).join("|");
1325
- const [o, a] = t.length > 1 ? ["(?:", ")"] : ["", ""];
1326
- i = "^" + o + i + a + "$", this.negate && (i = "^(?!" + i + ").+$");
1327
- try {
1328
- this.regexp = new RegExp(i, [...r].join(""));
1329
- } catch {
1330
- this.regexp = !1;
1331
- }
1332
- return this.regexp;
1333
- }
1334
- slashSplit(t) {
1335
- return this.preserveMultipleSlashes ? t.split("/") : this.isWindows && /^\\/\\/[^\\/]+/.test(t) ? ["", ...t.split(/\\/+/)] : t.split(/\\/+/);
1336
- }
1337
- match(t, e = this.partial) {
1338
- if (this.debug("match", t, this.pattern), this.comment)
1339
- return !1;
1340
- if (this.empty)
1341
- return t === "";
1342
- if (t === "/" && e)
1343
- return !0;
1344
- const n = this.options;
1345
- this.isWindows && (t = t.split("\\\\").join("/"));
1346
- const r = this.slashSplit(t);
1347
- this.debug(this.pattern, "split", r);
1348
- const i = this.set;
1349
- this.debug(this.pattern, "set", i);
1350
- let o = r[r.length - 1];
1351
- if (!o)
1352
- for (let a = r.length - 2; !o && a >= 0; a--)
1353
- o = r[a];
1354
- for (let a = 0; a < i.length; a++) {
1355
- const l = i[a];
1356
- let h = r;
1357
- if (n.matchBase && l.length === 1 && (h = [o]), this.matchOne(h, l, e))
1358
- return n.flipNegate ? !0 : !this.negate;
1359
- }
1360
- return n.flipNegate ? !1 : this.negate;
1361
- }
1362
- static defaults(t) {
1363
- return y.defaults(t).Minimatch;
1364
- }
1365
- }
1366
- y.AST = E;
1367
- y.Minimatch = Z;
1368
- y.escape = Pe;
1369
- y.unescape = I;
1370
- function cs() {
1371
- if (!("storage" in navigator) || !("getDirectory" in navigator.storage))
1372
- throw new Qt();
1373
- }
1374
- async function L(s, t, e) {
1375
- return typeof navigator < "u" && navigator.locks?.request ? navigator.locks.request(\`opfs:\${s.replace(/\\/+/g, "/")}\`, { mode: t }, e) : e();
1376
- }
1377
- function $(s) {
1378
- return Array.isArray(s) ? s : (s.startsWith("~/") ? s.slice(2) : s).split("/").filter(Boolean);
1379
- }
1380
- function lt(s) {
1381
- return typeof s == "string" ? s ?? "/" : \`/\${s.join("/")}\`;
1382
- }
1383
- function it(s) {
1384
- const t = $(s);
1385
- return t[t.length - 1] || "";
1386
- }
1387
- function tt(s) {
1388
- const t = $(s);
1389
- return t.pop(), lt(t);
1390
- }
1391
- function B(s) {
1392
- return !s || s === "/" ? "/" : s.startsWith("~/") ? \`/\${s.slice(2)}\` : s.startsWith("/") ? s : \`/\${s}\`;
1393
- }
1394
- function ls(s, t = !1) {
1395
- return s = s.replace(/\\/$/, ""), t && !s.includes("*") ? \`\${s}/**\` : s;
1396
- }
1397
- function et(s, t) {
1398
- return y(s, t, {
1399
- dot: !0,
1400
- matchBase: !0
1401
- });
1402
- }
1403
- function Et(s) {
1404
- const t = B(s), e = $(t), n = [];
1405
- for (const r of e)
1406
- if (!(r === "." || r === ""))
1407
- if (r === "..") {
1408
- if (n.length === 0)
1409
- continue;
1410
- n.pop();
1411
- } else
1412
- n.push(r);
1413
- return lt(n);
1414
- }
1415
- async function hs(s, t = "SHA-1", e = 50 * 1024 * 1024) {
1416
- if (s instanceof File && (s = await s.arrayBuffer()), s.byteLength > e)
1417
- throw new Error(\`File size \${s.byteLength} bytes exceeds maximum allowed size \${e} bytes\`);
1418
- const n = new Uint8Array(s), r = await crypto.subtle.digest(t, n);
1419
- return Array.from(new Uint8Array(r)).map((o) => o.toString(16).padStart(2, "0")).join("");
1420
- }
1421
- async function us(s) {
1422
- const t = await s.arrayBuffer();
1423
- return new Uint8Array(t);
1424
- }
1425
- async function fs(s, t, e = {}) {
1426
- const n = it(t);
1427
- return L(t, "exclusive", async () => {
1428
- const r = e.recursive ?? !1, i = e.force ?? !1;
1429
- try {
1430
- await s.removeEntry(n, { recursive: r });
1431
- } catch (o) {
1432
- if (o.name === "NotFoundError" && i)
1433
- return;
1434
- const a = o.name === "TypeMismatchError" && !r;
1435
- throw v(o, {
1436
- path: t,
1437
- operation: "remove",
1438
- isDirectory: a
1439
- });
1440
- }
1441
- });
1442
- }
1443
- function St(s, t, e, n) {
1444
- if (!Number.isInteger(t) || !Number.isInteger(e))
1445
- throw new N("argument", "Invalid offset or length");
1446
- if (t < 0 || e < 0)
1447
- throw new N("argument", "Negative offset or length not allowed");
1448
- if (t + e > s)
1449
- throw new N("overflow", "Operation would overflow buffer");
1450
- if (n != null && (!Number.isInteger(n) || n < 0))
1451
- throw new N("argument", "Invalid position");
1452
- }
1453
- function xt(s, t, e) {
1454
- try {
1455
- t.flush(), t.close();
1456
- } catch (n) {
1457
- console.warn(\`Warning: Failed to properly close file descriptor \${s} (\${e}):\`, n);
1458
- }
1459
- }
1460
- function ds(s, t, e) {
1461
- if (s >= e)
1462
- return { isEOF: !0, actualLength: 0 };
1463
- const n = Math.min(t, e - s);
1464
- return n <= 0 ? { isEOF: !0, actualLength: 0 } : { isEOF: !1, actualLength: n };
1465
- }
1466
- async function ps(s, t) {
1467
- try {
1468
- return await s.createSyncAccessHandle();
1469
- } catch (e) {
1470
- throw v(e, { path: t, isDirectory: !1 });
1471
- }
1472
- }
1473
- class gs {
1474
- /** Root directory handle for the file system */
1475
- root;
1476
- /** Map of watched paths and options */
1477
- watchers = /* @__PURE__ */ new Map();
1478
- /** Promise to prevent concurrent mount operations */
1479
- mountingPromise = null;
1480
- /** BroadcastChannel instance for sending events */
1481
- broadcastChannel = null;
1482
- /** Configuration options */
1483
- options = {
1484
- root: "/",
1485
- namespace: "",
1486
- maxFileSize: 50 * 1024 * 1024,
1487
- hashAlgorithm: "etag",
1488
- broadcastChannel: "opfs-worker"
1489
- };
1490
- /** Map of open file descriptors to their metadata */
1491
- openFiles = /* @__PURE__ */ new Map();
1492
- /** Next available file descriptor number */
1493
- nextFd = 1;
1494
- /**
1495
- * Get file info by descriptor with validation
1496
- * @private
1497
- */
1498
- _getFileDescriptor(t) {
1499
- const e = this.openFiles.get(t);
1500
- if (!e)
1501
- throw new N("descriptor", \`Invalid file descriptor: \${t}\`);
1502
- return e;
1503
- }
1504
- /**
1505
- * Notify about internal changes to the file system
1506
- *
1507
- * This method is called by internal operations to notify clients about
1508
- * changes, even when no specific paths are being watched.
1509
- *
1510
- * @param event - The event describing the change
1511
- */
1512
- async notifyChange(t) {
1513
- if (!this.options.broadcastChannel)
1514
- return;
1515
- const e = t.path;
1516
- if (![...this.watchers.values()].some((i) => et(e, i.pattern) && i.include.some((o) => o && et(e, o)) && !i.exclude.some((o) => o && et(e, o))))
1517
- return;
1518
- let r;
1519
- if (this.options.hashAlgorithm)
1520
- try {
1521
- r = (await this.stat(e)).hash;
1522
- } catch {
1523
- }
1524
- try {
1525
- this.broadcastChannel || (this.broadcastChannel = new BroadcastChannel(this.options.broadcastChannel));
1526
- const i = {
1527
- namespace: this.options.namespace,
1528
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1529
- ...t,
1530
- ...r && { hash: r }
1531
- };
1532
- this.broadcastChannel.postMessage(i);
1533
- } catch (i) {
1534
- console.warn("Failed to send event via BroadcastChannel:", i);
1535
- }
1536
- }
1537
- /**
1538
- * Creates a new OPFSFileSystem instance
1539
- *
1540
- * @param options - Optional configuration options
1541
- * @param options.root - Root path for the file system (default: '/')
1542
- * @param options.watchInterval - Polling interval in milliseconds for file watching
1543
- * @param options.hashAlgorithm - Hash algorithm for file hashing
1544
- * @param options.maxFileSize - Maximum file size for hashing in bytes (default: 50MB)
1545
- * @throws {OPFSError} If OPFS is not supported in the current browser
1546
- */
1547
- constructor(t) {
1548
- cs(), t && this.setOptions(t);
1549
- }
1550
- /**
1551
- * Initialize the file system within a given directory
1552
- *
1553
- * This method sets up the root directory for all subsequent operations.
1554
- * If no root is specified, it will use the OPFS root directory.
1555
- *
1556
- * @returns Promise that resolves to true if initialization was successful
1557
- * @throws {OPFSError} If initialization fails
1558
- *
1559
- * @example
1560
- * \`\`\`typescript
1561
- * const fs = new OPFSFileSystem();
1562
- *
1563
- * // Use OPFS root (default)
1564
- * await fs.mount();
1565
- *
1566
- * // Use custom directory
1567
- * await fs.mount('/my-app');
1568
- * \`\`\`
1569
- */
1570
- async mount() {
1571
- const t = this.options.root;
1572
- return this.mountingPromise && await this.mountingPromise, this.mountingPromise = new Promise(async (e, n) => {
1573
- try {
1574
- const r = await navigator.storage.getDirectory();
1575
- this.root = t === "/" ? r : await this.getDirectoryHandle(t, !0, r), e(!0);
1576
- } catch (r) {
1577
- n(new re(t, r));
1578
- } finally {
1579
- this.mountingPromise = null;
1580
- }
1581
- }), this.mountingPromise;
1582
- }
1583
- /**
1584
- * Update configuration options
1585
- *
1586
- * @param options - Configuration options to update
1587
- * @param options.root - Root path for the file system
1588
- * @param options.watchInterval - Polling interval in milliseconds for file watching
1589
- * @param options.hashAlgorithm - Hash algorithm for file hashing
1590
- * @param options.maxFileSize - Maximum file size for hashing in bytes
1591
- * @param options.broadcastChannel - Custom name for the broadcast channel
1592
- */
1593
- async setOptions(t) {
1594
- 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 = B(t.root), this.options.namespace || (this.options.namespace = \`opfs-worker:\${this.options.root}\`), await this.mount());
1595
- }
1596
- /**
1597
- * Get a directory handle from a path
1598
- *
1599
- * Navigates through the directory structure to find or create a directory
1600
- * at the specified path.
1601
- *
1602
- * @param path - The path to the directory (string or array of segments)
1603
- * @param create - Whether to create the directory if it doesn't exist (default: false)
1604
- * @param from - The directory to start from (default: root directory)
1605
- * @returns Promise that resolves to the directory handle
1606
- * @throws {OPFSError} If the directory cannot be accessed or created
1607
- *
1608
- * @example
1609
- * \`\`\`typescript
1610
- * const docsDir = await fs.getDirectoryHandle('/users/john/documents', true);
1611
- * const docsDir2 = await fs.getDirectoryHandle(['users', 'john', 'documents'], true);
1612
- * \`\`\`
1613
- */
1614
- async getDirectoryHandle(t, e = !1, n = this.root) {
1615
- const r = Array.isArray(t) ? t : $(t);
1616
- let i = n;
1617
- for (const o of r)
1618
- i = await i.getDirectoryHandle(o, { create: e });
1619
- return i;
1620
- }
1621
- /**
1622
- * Get a file handle from a path
1623
- *
1624
- * Navigates to the parent directory and retrieves or creates a file handle
1625
- * for the specified file path.
1626
- *
1627
- * @param path - The path to the file (string or array of segments)
1628
- * @param create - Whether to create the file if it doesn't exist (default: false)
1629
- * @param _from - The directory to start from (default: root directory)
1630
- * @returns Promise that resolves to the file handle
1631
- * @throws {PathError} If the path is empty
1632
- * @throws {OPFSError} If the file cannot be accessed or created
1633
- *
1634
- * @example
1635
- * \`\`\`typescript
1636
- * const fileHandle = await fs.getFileHandle('/config/settings.json', true);
1637
- * const fileHandle2 = await fs.getFileHandle(['config', 'settings.json'], true);
1638
- * \`\`\`
1639
- */
1640
- async getFileHandle(t, e = !1, n = this.root) {
1641
- const r = $(t);
1642
- if (r.length === 0)
1643
- throw new Kt("Path must not be empty", Array.isArray(t) ? t.join("/") : t);
1644
- const i = r.pop();
1645
- return (await this.getDirectoryHandle(r, e, n)).getFileHandle(i, { create: e });
1646
- }
1647
- /**
1648
- * Get a complete index of all files and directories in the file system
1649
- *
1650
- * This method recursively traverses the entire file system and returns
1651
- * a Map containing FileStat objects for every file and directory.
1652
- *
1653
- * @returns Promise that resolves to a Map of paths to FileStat objects
1654
- * @throws {OPFSError} If the file system is not mounted
1655
- *
1656
- * @example
1657
- * \`\`\`typescript
1658
- * const index = await fs.index();
1659
- * const fileStats = index.get('/data/config.json');
1660
- * if (fileStats) {
1661
- * console.log(\`File size: \${fileStats.size} bytes\`);
1662
- * if (fileStats.hash) console.log(\`Hash: \${fileStats.hash}\`);
1663
- * }
1664
- * \`\`\`
1665
- */
1666
- async index() {
1667
- const t = /* @__PURE__ */ new Map(), e = async (n) => {
1668
- const r = await this.readDir(n);
1669
- for (const i of r) {
1670
- const o = \`\${n === "/" ? "" : n}/\${i.name}\`;
1671
- try {
1672
- const a = await this.stat(o);
1673
- t.set(o, a), a.isDirectory && await e(o);
1674
- } catch (a) {
1675
- console.warn(\`Skipping broken entry: \${o}\`, a);
1676
- }
1677
- }
1678
- };
1679
- return t.set("/", {
1680
- kind: "directory",
1681
- size: 0,
1682
- mtime: (/* @__PURE__ */ new Date(0)).toISOString(),
1683
- ctime: (/* @__PURE__ */ new Date(0)).toISOString(),
1684
- isFile: !1,
1685
- isDirectory: !0
1686
- }), await e("/"), t;
1687
- }
1688
- /**
1689
- * Read a file from the file system
1690
- *
1691
- * Reads the contents of a file and returns it as binary data.
1692
- *
1693
- * @param path - The path to the file to read
1694
- * @returns Promise that resolves to the file contents as Uint8Array
1695
- * @throws {FileNotFoundError} If the file does not exist
1696
- * @throws {OPFSError} If reading the file fails
1697
- *
1698
- * @example
1699
- * \`\`\`typescript
1700
- * // Read as binary data
1701
- * const content = await fs.readFile('/config/settings.json');
1702
- *
1703
- * // Read binary file
1704
- * const binaryData = await fs.readFile('/images/logo.png');
1705
- * \`\`\`
1706
- */
1707
- async readFile(t) {
1708
- await this.mount();
1709
- try {
1710
- return await L(t, "shared", async () => {
1711
- const e = await this.open(t);
1712
- try {
1713
- const { size: n } = await this.fstat(e), r = new Uint8Array(n);
1714
- return n > 0 && await this.read(e, r, 0, n, 0), U(r, [r.buffer]);
1715
- } finally {
1716
- await this.close(e);
1717
- }
1718
- });
1719
- } catch (e) {
1720
- throw new R("file", t, e);
1721
- }
1722
- }
1723
- /**
1724
- * Write data to a file
1725
- *
1726
- * Creates or overwrites a file with the specified binary data. If the file already
1727
- * exists, it will be truncated before writing.
1728
- *
1729
- * @param path - The path to the file to write
1730
- * @param data - The binary data to write to the file (Uint8Array or ArrayBuffer)
1731
- * @returns Promise that resolves when the write operation is complete
1732
- * @throws {OPFSError} If writing the file fails
1733
- *
1734
- * @example
1735
- * \`\`\`typescript
1736
- * // Write binary data
1737
- * const binaryData = new Uint8Array([1, 2, 3, 4, 5]);
1738
- * await fs.writeFile('/data/binary.dat', binaryData);
1739
- *
1740
- * // Write from ArrayBuffer
1741
- * const arrayBuffer = new ArrayBuffer(10);
1742
- * await fs.writeFile('/data/buffer.dat', arrayBuffer);
1743
- * \`\`\`
1744
- */
1745
- async writeFile(t, e) {
1746
- await this.mount();
1747
- const n = e instanceof Uint8Array ? e : new Uint8Array(e);
1748
- await L(t, "exclusive", async () => {
1749
- const r = await this.exists(t), i = await this.open(t, { create: !0, truncate: !0 });
1750
- try {
1751
- await this.write(i, n, 0, n.length, null, !1), await this.fsync(i);
1752
- } finally {
1753
- await this.close(i);
1754
- }
1755
- await this.notifyChange({ path: t, type: r ? D.Changed : D.Added, isDirectory: !1 });
1756
- });
1757
- }
1758
- /**
1759
- * Append data to a file
1760
- *
1761
- * Adds binary data to the end of an existing file. If the file doesn't exist,
1762
- * it will be created.
1763
- *
1764
- * @param path - The path to the file to append to
1765
- * @param data - The binary data to append to the file (Uint8Array or ArrayBuffer)
1766
- * @returns Promise that resolves when the append operation is complete
1767
- * @throws {OPFSError} If appending to the file fails
1768
- *
1769
- * @example
1770
- * \`\`\`typescript
1771
- * // Append binary data
1772
- * const additionalData = new Uint8Array([6, 7, 8]);
1773
- * await fs.appendFile('/data/binary.dat', additionalData);
1774
- *
1775
- * // Append from ArrayBuffer
1776
- * const arrayBuffer = new ArrayBuffer(5);
1777
- * await fs.appendFile('/data/buffer.dat', arrayBuffer);
1778
- * \`\`\`
1779
- */
1780
- async appendFile(t, e) {
1781
- await this.mount();
1782
- const n = e instanceof Uint8Array ? e : new Uint8Array(e);
1783
- await L(t, "exclusive", async () => {
1784
- const r = await this.open(t, { create: !0 });
1785
- try {
1786
- const { size: i } = await this.fstat(r);
1787
- await this.write(r, n, 0, n.length, i, !1), await this.fsync(r);
1788
- } finally {
1789
- await this.close(r);
1790
- }
1791
- await this.notifyChange({ path: t, type: D.Changed, isDirectory: !1 });
1792
- });
1793
- }
1794
- /**
1795
- * Create a directory
1796
- *
1797
- * Creates a new directory at the specified path. If the recursive option
1798
- * is enabled, parent directories will be created as needed.
1799
- *
1800
- * @param path - The path where the directory should be created
1801
- * @param options - Options for directory creation
1802
- * @param options.recursive - Whether to create parent directories if they don't exist (default: false)
1803
- * @returns Promise that resolves when the directory is created
1804
- * @throws {OPFSError} If the directory cannot be created
1805
- *
1806
- * @example
1807
- * \`\`\`typescript
1808
- * // Create a single directory
1809
- * await fs.mkdir('/users/john');
1810
- *
1811
- * // Create nested directories
1812
- * await fs.mkdir('/users/john/documents/projects', { recursive: true });
1813
- * \`\`\`
1814
- */
1815
- async mkdir(t, e) {
1816
- await this.mount();
1817
- const n = e?.recursive ?? !1, r = $(t);
1818
- let i = this.root;
1819
- for (let o = 0; o < r.length; o++) {
1820
- const a = r[o];
1821
- try {
1822
- i = await i.getDirectoryHandle(a, { create: n || o === r.length - 1 });
1823
- } catch (l) {
1824
- throw l.name === "NotFoundError" ? v(l, {
1825
- path: lt(r.slice(0, o + 1)),
1826
- existenceType: "directory"
1827
- }) : l.name === "TypeMismatchError" ? v(l, { path: a, isDirectory: !1 }) : new J("create directory", a, l);
1828
- }
1829
- }
1830
- await this.notifyChange({ path: t, type: D.Added, isDirectory: !0 });
1831
- }
1832
- /**
1833
- * Get file or directory statistics
1834
- *
1835
- * Returns detailed information about a file or directory, including
1836
- * size, modification time, and optionally a hash of the file content.
1837
- *
1838
- * @param path - The path to the file or directory
1839
- * @returns Promise that resolves to FileStat object
1840
- * @throws {OPFSError} If the path does not exist or cannot be accessed
1841
- *
1842
- * @example
1843
- * \`\`\`typescript
1844
- * const stats = await fs.stat('/data/config.json');
1845
- * console.log(\`File size: \${stats.size} bytes\`);
1846
- * console.log(\`Last modified: \${stats.mtime}\`);
1847
- *
1848
- * // If hashing is enabled, hash will be included
1849
- * if (stats.hash) {
1850
- * console.log(\`Hash: \${stats.hash}\`);
1851
- * }
1852
- * \`\`\`
1853
- */
1854
- async stat(t) {
1855
- if (await this.mount(), t === "/")
1856
- return {
1857
- kind: "directory",
1858
- size: 0,
1859
- mtime: (/* @__PURE__ */ new Date(0)).toISOString(),
1860
- ctime: (/* @__PURE__ */ new Date(0)).toISOString(),
1861
- isFile: !1,
1862
- isDirectory: !0
1863
- };
1864
- const e = it(t);
1865
- let n;
1866
- try {
1867
- n = await this.getDirectoryHandle(tt(t), !1);
1868
- const r = this.options.hashAlgorithm, o = await (await n.getFileHandle(e, { create: !1 })).getFile(), a = {
1869
- kind: "file",
1870
- size: o.size,
1871
- mtime: new Date(o.lastModified).toISOString(),
1872
- ctime: new Date(o.lastModified).toISOString(),
1873
- isFile: !0,
1874
- isDirectory: !1
1875
- };
1876
- if (r === "etag")
1877
- a.hash = \`\${o.lastModified.toString(36)}-\${o.size.toString(36)}\`;
1878
- else if (typeof r == "string")
1879
- try {
1880
- const l = await hs(o, r, this.options.maxFileSize);
1881
- a.hash = l;
1882
- } catch (l) {
1883
- console.warn(\`Failed to calculate hash for \${t}:\`, l);
1884
- }
1885
- return a;
1886
- } catch (r) {
1887
- if (r.name === "NotFoundError")
1888
- throw new R("file", t, r);
1889
- if (r.name !== "TypeMismatchError")
1890
- throw new J("stat", t, r);
1891
- }
1892
- try {
1893
- return await n.getDirectoryHandle(e, { create: !1 }), {
1894
- kind: "directory",
1895
- size: 0,
1896
- mtime: (/* @__PURE__ */ new Date(0)).toISOString(),
1897
- ctime: (/* @__PURE__ */ new Date(0)).toISOString(),
1898
- isFile: !1,
1899
- isDirectory: !0
1900
- };
1901
- } catch (r) {
1902
- throw new J("stat", t, r);
1903
- }
1904
- }
1905
- /**
1906
- * Read a directory's contents
1907
- *
1908
- * Lists all files and subdirectories within the specified directory.
1909
- *
1910
- * @param path - The path to the directory to read
1911
- * @returns Promise that resolves to an array of detailed file/directory information
1912
- * @throws {OPFSError} If the directory does not exist or cannot be accessed
1913
- *
1914
- * @example
1915
- * \`\`\`typescript
1916
- * // Get detailed information about files and directories
1917
- * const detailed = await fs.readDir('/users/john/documents');
1918
- * detailed.forEach(item => {
1919
- * console.log(\`\${item.name} - \${item.isFile ? 'file' : 'directory'}\`);
1920
- * });
1921
- * \`\`\`
1922
- */
1923
- async readDir(t) {
1924
- await this.mount();
1925
- const e = await this.getDirectoryHandle(t, !1), n = [];
1926
- for await (const [r, i] of e.entries()) {
1927
- const o = i.kind === "file";
1928
- n.push({
1929
- name: r,
1930
- kind: i.kind,
1931
- isFile: o,
1932
- isDirectory: !o
1933
- });
1934
- }
1935
- return n;
1936
- }
1937
- /**
1938
- * Check if a file or directory exists
1939
- *
1940
- * Verifies if a file or directory exists at the specified path.
1941
- *
1942
- * @param path - The path to check
1943
- * @returns Promise that resolves to true if the file or directory exists, false otherwise
1944
- *
1945
- * @example
1946
- * \`\`\`typescript
1947
- * const exists = await fs.exists('/config/settings.json');
1948
- * console.log(\`File exists: \${exists}\`);
1949
- * \`\`\`
1950
- */
1951
- async exists(t) {
1952
- if (await this.mount(), t === "/")
1953
- return !0;
1954
- const e = it(t);
1955
- let n = null;
1956
- try {
1957
- n = await this.getDirectoryHandle(tt(t), !1);
1958
- } catch (r) {
1959
- if (n = null, r.name !== "NotFoundError" && r.name !== "TypeMismatchError")
1960
- throw r;
1961
- }
1962
- if (!n || !e)
1963
- return !1;
1964
- try {
1965
- return await n.getFileHandle(e, { create: !1 }), !0;
1966
- } catch (r) {
1967
- if (r.name !== "NotFoundError" && r.name !== "TypeMismatchError")
1968
- throw r;
1969
- try {
1970
- return await n.getDirectoryHandle(e, { create: !1 }), !0;
1971
- } catch (i) {
1972
- if (i.name !== "NotFoundError" && i.name !== "TypeMismatchError")
1973
- throw i;
1974
- return !1;
1975
- }
1976
- }
1977
- }
1978
- /**
1979
- * Clear all contents of a directory without removing the directory itself
1980
- *
1981
- * Removes all files and subdirectories within the specified directory,
1982
- * but keeps the directory itself.
1983
- *
1984
- * @param path - The path to the directory to clear (default: '/')
1985
- * @returns Promise that resolves when all contents are removed
1986
- * @throws {OPFSError} If the operation fails
1987
- *
1988
- * @example
1989
- * \`\`\`typescript
1990
- * // Clear root directory contents
1991
- * await fs.clear('/');
1992
- *
1993
- * // Clear specific directory contents
1994
- * await fs.clear('/data');
1995
- * \`\`\`
1996
- */
1997
- async clear(t = "/") {
1998
- await this.mount();
1999
- try {
2000
- const e = await this.readDir(t);
2001
- for (const n of e) {
2002
- const r = \`\${t === "/" ? "" : t}/\${n.name}\`;
2003
- await this.remove(r, { recursive: !0 });
2004
- }
2005
- await this.notifyChange({ path: t, type: D.Changed, isDirectory: !0 });
2006
- } catch (e) {
2007
- throw e instanceof w ? e : v(e, { path: t, isDirectory: !0 });
2008
- }
2009
- }
2010
- /**
2011
- * Remove files and directories
2012
- *
2013
- * Removes files and directories. Similar to Node.js fs.rm().
2014
- *
2015
- * @param path - The path to remove
2016
- * @param options - Options for removal
2017
- * @param options.recursive - Whether to remove directories and their contents recursively (default: false)
2018
- * @param options.force - Whether to ignore errors if the path doesn't exist (default: false)
2019
- * @returns Promise that resolves when the removal is complete
2020
- * @throws {OPFSError} If the removal fails
2021
- *
2022
- * @example
2023
- * \`\`\`typescript
2024
- * // Remove a file
2025
- * await fs.rm('/path/to/file.txt');
2026
- *
2027
- * // Remove a directory and all its contents
2028
- * await fs.rm('/path/to/directory', { recursive: true });
2029
- *
2030
- * // Remove with force (ignore if doesn't exist)
2031
- * await fs.rm('/maybe/exists', { force: true });
2032
- * \`\`\`
2033
- */
2034
- async remove(t, e) {
2035
- if (await this.mount(), t === "/")
2036
- throw new rt("EROOT", t);
2037
- const { recursive: n = !1, force: r = !1 } = e || {}, i = await this.getDirectoryHandle(tt(t), !1), o = await this.stat(t);
2038
- await fs(i, t, { recursive: n, force: r }), await this.notifyChange({ path: t, type: D.Removed, isDirectory: o.isDirectory });
2039
- }
2040
- /**
2041
- * Resolve a path to an absolute path
2042
- *
2043
- * Resolves relative paths and normalizes path segments (like '..' and '.').
2044
- * Similar to Node.js fs.realpath() but without symlink resolution since OPFS doesn't support symlinks.
2045
- *
2046
- * @param path - The path to resolve
2047
- * @returns Promise that resolves to the absolute normalized path
2048
- * @throws {FileNotFoundError} If the path does not exist
2049
- * @throws {OPFSError} If path resolution fails
2050
- *
2051
- * @example
2052
- * \`\`\`typescript
2053
- * // Resolve relative path
2054
- * const absolute = await fs.realpath('./config/../data/file.txt');
2055
- * console.log(absolute); // '/data/file.txt'
2056
- * \`\`\`
2057
- */
2058
- async realpath(t) {
2059
- await this.mount();
2060
- try {
2061
- const e = Et(t);
2062
- if (!await this.exists(e))
2063
- throw new R("file", e);
2064
- return e;
2065
- } catch (e) {
2066
- throw e instanceof w ? e : v(e, { path: t });
2067
- }
2068
- }
2069
- /**
2070
- * Rename a file or directory
2071
- *
2072
- * Changes the name of a file or directory. If the target path already exists,
2073
- * it will be replaced only if overwrite option is enabled.
2074
- *
2075
- * @param oldPath - The current path of the file or directory
2076
- * @param newPath - The new path for the file or directory
2077
- * @param options - Options for renaming
2078
- * @param options.overwrite - Whether to overwrite existing files (default: false)
2079
- * @returns Promise that resolves when the rename operation is complete
2080
- * @throws {OPFSError} If the rename operation fails
2081
- *
2082
- * @example
2083
- * \`\`\`typescript
2084
- * // Basic rename (fails if target exists)
2085
- * await fs.rename('/old/path/file.txt', '/new/path/renamed.txt');
2086
- *
2087
- * // Rename with overwrite
2088
- * await fs.rename('/old/path/file.txt', '/new/path/renamed.txt', { overwrite: true });
2089
- * \`\`\`
2090
- */
2091
- async rename(t, e, n) {
2092
- await this.mount();
2093
- try {
2094
- const r = n?.overwrite ?? !1, i = await this.stat(t);
2095
- if (await this.exists(e) && !r)
2096
- throw new Q(e);
2097
- await this.copy(t, e, { recursive: !0, overwrite: r }), await this.remove(t, { recursive: !0 }), await this.notifyChange({ path: t, type: D.Removed, isDirectory: i.isDirectory }), await this.notifyChange({ path: e, type: D.Added, isDirectory: i.isDirectory });
2098
- } catch (r) {
2099
- throw r instanceof w ? r : v(r, { path: t });
2100
- }
2101
- }
2102
- /**
2103
- * Copy files and directories
2104
- *
2105
- * Copies files and directories. Similar to Node.js fs.cp().
2106
- *
2107
- * @param source - The source path to copy from
2108
- * @param destination - The destination path to copy to
2109
- * @param options - Options for copying
2110
- * @param options.recursive - Whether to copy directories recursively (default: false)
2111
- * @param options.overwrite - Whether to overwrite existing files (default: true)
2112
- * @returns Promise that resolves when the copy operation is complete
2113
- * @throws {OPFSError} If the copy operation fails
2114
- *
2115
- * @example
2116
- * \`\`\`typescript
2117
- * // Copy a file
2118
- * await fs.copy('/source/file.txt', '/dest/file.txt');
2119
- *
2120
- * // Copy a directory and all its contents
2121
- * await fs.copy('/source/dir', '/dest/dir', { recursive: true });
2122
- *
2123
- * // Copy without overwriting existing files
2124
- * await fs.copy('/source', '/dest', { recursive: true, overwrite: false });
2125
- * \`\`\`
2126
- */
2127
- async copy(t, e, n) {
2128
- await this.mount();
2129
- try {
2130
- const r = n?.recursive ?? !1, i = n?.overwrite ?? !0;
2131
- if (!await this.exists(t))
2132
- throw new R("source", t);
2133
- if (await this.exists(e) && !i)
2134
- throw new Q(e);
2135
- if ((await this.stat(t)).isFile) {
2136
- const h = await this.readFile(t);
2137
- await this.writeFile(e, h);
2138
- } else {
2139
- if (!r)
2140
- throw new nt("directory", t);
2141
- await this.mkdir(e, { recursive: !0 });
2142
- const h = await this.readDir(t);
2143
- for (const c of h) {
2144
- const f = \`\${t}/\${c.name}\`, u = \`\${e}/\${c.name}\`;
2145
- await this.copy(f, u, { recursive: !0, overwrite: i });
2146
- }
2147
- }
2148
- } catch (r) {
2149
- throw r instanceof w ? r : v(r, { path: t });
2150
- }
2151
- }
2152
- /**
2153
- * Start watching a file or directory for changes
2154
- *
2155
- * @param path - The path to watch (minimatch syntax allowed)
2156
- * @param options - Watch options
2157
- * @param options.recursive - Whether to watch recursively (default: true)
2158
- * @param options.exclude - Glob pattern(s) to exclude (minimatch).
2159
- * @returns Promise that resolves when watching starts
2160
- *
2161
- * @example
2162
- * \`\`\`typescript
2163
- * // Watch entire directory tree recursively (default)
2164
- * await fs.watch('/data');
2165
- *
2166
- * // Watch only immediate children (shallow)
2167
- * await fs.watch('/data', { recursive: false });
2168
- *
2169
- * // Watch a single file
2170
- * await fs.watch('/config.json', { recursive: false });
2171
- *
2172
- * // Watch all json files but not in dist directory
2173
- * await fs.watch('/**\\/*.json', { recursive: false, exclude: ['dist/**'] });
2174
- *
2175
- * \`\`\`
2176
- */
2177
- async watch(t, e) {
2178
- if (!this.options.broadcastChannel)
2179
- throw new Ct("This instance is not configured to send events. Please specify options.broadcastChannel to enable watching.");
2180
- const n = {
2181
- pattern: ls(t, e?.recursive ?? !0),
2182
- include: Array.isArray(e?.include) ? e.include : [e?.include ?? "**"],
2183
- exclude: Array.isArray(e?.exclude) ? e.exclude : [e?.exclude ?? ""]
2184
- };
2185
- this.watchers.set(t, n);
2186
- }
2187
- /**
2188
- * Stop watching a previously watched path
2189
- */
2190
- unwatch(t) {
2191
- this.watchers.delete(t);
2192
- }
2193
- /**
2194
- * Open a file and return a file descriptor
2195
- *
2196
- * @param path - The path to the file to open
2197
- * @param options - Options for opening the file
2198
- * @param options.create - Whether to create the file if it doesn't exist (default: false)
2199
- * @param options.exclusive - If true and create is true, fails if file already exists (default: false)
2200
- * Note: This is best-effort in OPFS, not fully atomic due to browser limitations
2201
- * @param options.truncate - Whether to truncate the file to zero length (default: false)
2202
- * @returns Promise that resolves to a file descriptor number
2203
- * @throws {OPFSError} If opening the file fails
2204
- *
2205
- * @example
2206
- * \`\`\`typescript
2207
- * // Open existing file for reading
2208
- * const fd = await fs.open('/data/config.json');
2209
- *
2210
- * // Create new file for writing
2211
- * const fd = await fs.open('/data/new.txt', { create: true });
2212
- *
2213
- * // Create file exclusively (fails if exists)
2214
- * const fd = await fs.open('/data/unique.txt', { create: true, exclusive: true });
2215
- *
2216
- * // Open and truncate file
2217
- * const fd = await fs.open('/data/log.txt', { create: true, truncate: true });
2218
- * \`\`\`
2219
- */
2220
- async open(t, e) {
2221
- await this.mount();
2222
- const { create: n = !1, exclusive: r = !1, truncate: i = !1 } = e || {}, o = B(Et(t));
2223
- try {
2224
- return n && r ? await L(o, "exclusive", async () => {
2225
- if (await this.exists(o))
2226
- throw new Q(o);
2227
- return this._openFile(o, n, i);
2228
- }) : await this._openFile(o, n, i);
2229
- } catch (a) {
2230
- if (a instanceof w)
2231
- throw a;
2232
- const l = a && a.name === "TypeMismatchError";
2233
- throw v(a, {
2234
- path: o,
2235
- isDirectory: !!l
2236
- });
2237
- }
2238
- }
2239
- /**
2240
- * Internal method to open a file (without locking)
2241
- * @private
2242
- */
2243
- async _openFile(t, e, n) {
2244
- const r = await this.getFileHandle(t, e);
2245
- try {
2246
- await r.getFile();
2247
- } catch (a) {
2248
- throw v(a, { path: t, isDirectory: !0 });
2249
- }
2250
- const i = await ps(r, t);
2251
- n && (i.truncate(0), i.flush());
2252
- const o = this.nextFd++;
2253
- return this.openFiles.set(o, {
2254
- path: t,
2255
- fileHandle: r,
2256
- syncHandle: i,
2257
- position: 0
2258
- }), o;
2259
- }
2260
- /**
2261
- * Close a file descriptor
2262
- *
2263
- * @param fd - The file descriptor to close
2264
- * @returns Promise that resolves when the file descriptor is closed
2265
- * @throws {OPFSError} If the file descriptor is invalid or closing fails
2266
- *
2267
- * @example
2268
- * \`\`\`typescript
2269
- * const fd = await fs.open('/data/file.txt');
2270
- * // ... use the file descriptor ...
2271
- * await fs.close(fd);
2272
- * \`\`\`
2273
- */
2274
- async close(t) {
2275
- const e = this._getFileDescriptor(t);
2276
- xt(t, e.syncHandle, e.path), this.openFiles.delete(t);
2277
- }
2278
- /**
2279
- * Read data from a file descriptor
2280
- *
2281
- * @param fd - The file descriptor to read from
2282
- * @param buffer - The buffer to read data into
2283
- * @param offset - The offset in the buffer to start writing at
2284
- * @param length - The number of bytes to read
2285
- * @param position - The position in the file to read from (null for current position)
2286
- * @returns Promise that resolves to the number of bytes read and the modified buffer
2287
- * @throws {OPFSError} If the file descriptor is invalid or reading fails
2288
- *
2289
- * @note This method uses Comlink.transfer() to efficiently pass the buffer as a Transferable Object,
2290
- * ensuring zero-copy performance across Web Worker boundaries.
2291
- *
2292
- * @example
2293
- * \`\`\`typescript
2294
- * const fd = await fs.open('/data/file.txt');
2295
- * const buffer = new Uint8Array(1024);
2296
- * const { bytesRead, buffer: modifiedBuffer } = await fs.read(fd, buffer, 0, 1024, null);
2297
- * console.log(\`Read \${bytesRead} bytes\`);
2298
- * // Use modifiedBuffer which contains the actual data
2299
- * await fs.close(fd);
2300
- * \`\`\`
2301
- */
2302
- async read(t, e, n, r, i) {
2303
- const o = this._getFileDescriptor(t);
2304
- St(e.length, n, r, i);
2305
- try {
2306
- const a = i ?? o.position, l = o.syncHandle.getSize(), { isEOF: h, actualLength: c } = ds(a, r, l);
2307
- if (h)
2308
- return U({ bytesRead: 0, buffer: e }, [e.buffer]);
2309
- const f = e.subarray(n, n + c), u = o.syncHandle.read(f, { at: a });
2310
- return i == null && (o.position = a + u), U({ bytesRead: u, buffer: e }, [e.buffer]);
2311
- } catch (a) {
2312
- throw W("read", t, o.path, a);
2313
- }
2314
- }
2315
- /**
2316
- * Write data to a file descriptor
2317
- *
2318
- * @param fd - The file descriptor to write to
2319
- * @param buffer - The buffer containing data to write
2320
- * @param offset - The offset in the buffer to start reading from (default: 0)
2321
- * @param length - The number of bytes to write (default: entire buffer)
2322
- * @param position - The position in the file to write to (null/undefined for current position)
2323
- * @param emitEvent - Whether to emit a change event (default: true)
2324
- * @returns Promise that resolves to the number of bytes written
2325
- * @throws {OPFSError} If the file descriptor is invalid or writing fails
2326
- *
2327
- * @example
2328
- * \`\`\`typescript
2329
- * const fd = await fs.open('/data/file.txt', { create: true });
2330
- * const data = new TextEncoder().encode('Hello, World!');
2331
- * const bytesWritten = await fs.write(fd, data, 0, data.length, null);
2332
- * console.log(\`Wrote \${bytesWritten} bytes\`);
2333
- * await fs.close(fd);
2334
- * \`\`\`
2335
- */
2336
- async write(t, e, n = 0, r, i, o = !0) {
2337
- const a = this._getFileDescriptor(t), l = r ?? e.length - n;
2338
- St(e.length, n, l, i);
2339
- try {
2340
- const h = i ?? a.position, c = e.subarray(n, n + l), f = a.syncHandle.write(c, { at: h });
2341
- return (i == null || i === a.position) && (a.position = h + f), o && await this.notifyChange({ path: a.path, type: D.Changed, isDirectory: !1 }), f;
2342
- } catch (h) {
2343
- throw W("write", t, a.path, h);
2344
- }
2345
- }
2346
- /**
2347
- * Get file status information by file descriptor
2348
- *
2349
- * @param fd - The file descriptor
2350
- * @returns Promise that resolves to FileStat object
2351
- * @throws {OPFSError} If the file descriptor is invalid
2352
- *
2353
- * @example
2354
- * \`\`\`typescript
2355
- * const fd = await fs.open('/data/file.txt');
2356
- * const stats = await fs.fstat(fd);
2357
- * console.log(\`File size: \${stats.size} bytes\`);
2358
- * console.log(\`Last modified: \${stats.mtime}\`);
2359
- *
2360
- * // If hashing is enabled, hash will be included
2361
- * if (stats.hash) {
2362
- * console.log(\`Hash: \${stats.hash}\`);
2363
- * }
2364
- * \`\`\`
2365
- */
2366
- async fstat(t) {
2367
- const e = this._getFileDescriptor(t);
2368
- return this.stat(e.path);
2369
- }
2370
- /**
2371
- * Truncate file to specified size
2372
- *
2373
- * @param fd - The file descriptor
2374
- * @param size - The new size of the file (default: 0)
2375
- * @returns Promise that resolves when truncation is complete
2376
- * @throws {OPFSError} If the file descriptor is invalid or truncation fails
2377
- *
2378
- * @example
2379
- * \`\`\`typescript
2380
- * const fd = await fs.open('/data/file.txt', { create: true });
2381
- * await fs.truncate(fd, 100); // Truncate to 100 bytes
2382
- * \`\`\`
2383
- */
2384
- async ftruncate(t, e = 0) {
2385
- const n = this._getFileDescriptor(t);
2386
- if (e < 0 || !Number.isInteger(e))
2387
- throw new N("argument", "Invalid size");
2388
- try {
2389
- n.syncHandle.truncate(e), n.syncHandle.flush(), n.position > e && (n.position = e), await this.notifyChange({ path: n.path, type: D.Changed, isDirectory: !1 });
2390
- } catch (r) {
2391
- throw W("truncate", t, n.path, r);
2392
- }
2393
- }
2394
- /**
2395
- * Synchronize file data to storage (fsync equivalent)
2396
- *
2397
- * @param fd - The file descriptor
2398
- * @returns Promise that resolves when synchronization is complete
2399
- * @throws {OPFSError} If the file descriptor is invalid or sync fails
2400
- *
2401
- * @example
2402
- * \`\`\`typescript
2403
- * const fd = await fs.open('/data/file.txt', { create: true });
2404
- * await fs.write(fd, data);
2405
- * await fs.fsync(fd); // Ensure data is written to storage
2406
- * \`\`\`
2407
- */
2408
- async fsync(t) {
2409
- const e = this._getFileDescriptor(t);
2410
- try {
2411
- e.syncHandle.flush();
2412
- } catch (n) {
2413
- throw W("sync", t, e.path, n);
2414
- }
2415
- }
2416
- /**
2417
- * Dispose of resources and clean up the file system instance
2418
- *
2419
- * This method should be called when the file system instance is no longer needed
2420
- * to properly clean up resources like the broadcast channel and watch timers.
2421
- */
2422
- dispose() {
2423
- this.broadcastChannel && (this.broadcastChannel.close(), this.broadcastChannel = null), this.watchers.clear();
2424
- for (const [t, e] of this.openFiles)
2425
- xt(t, e.syncHandle, e.path);
2426
- this.openFiles.clear(), this.nextFd = 1;
2427
- }
2428
- /**
2429
- * Synchronize the file system with external data
2430
- *
2431
- * Syncs the file system with an array of entries containing paths and data.
2432
- * This is useful for importing data from external sources or syncing with remote data.
2433
- *
2434
- * @param entries - Array of [path, data] tuples to sync
2435
- * @returns Promise that resolves when synchronization is complete
2436
- * @throws {OPFSError} If the synchronization fails
2437
- *
2438
- * @example
2439
- * \`\`\`typescript
2440
- * // Sync with external data
2441
- * const entries: [string, string | Uint8Array | Blob][] = [
2442
- * ['/config.json', JSON.stringify({ theme: 'dark' })],
2443
- * ['/data/binary.dat', new Uint8Array([1, 2, 3, 4])],
2444
- * ['/upload.txt', new Blob(['file content'], { type: 'text/plain' })]
2445
- * ];
2446
- *
2447
- * // Sync without clearing existing files
2448
- * await fs.sync(entries);
2449
- *
2450
- * // Clean file system and then sync
2451
- * await fs.sync(entries, { cleanBefore: true });
2452
- * \`\`\`
2453
- */
2454
- async createIndex(t) {
2455
- await this.mount();
2456
- try {
2457
- for (const [e, n] of t) {
2458
- const r = B(e);
2459
- let i;
2460
- n instanceof Blob ? i = await us(n) : typeof n == "string" ? i = new TextEncoder().encode(n) : i = n, await this.writeFile(r, i);
2461
- }
2462
- } catch (e) {
2463
- throw e instanceof w ? e : v(e);
2464
- }
2465
- }
2466
- }
2467
- typeof globalThis < "u" && globalThis.constructor.name === "DedicatedWorkerGlobalScope" && ot(new gs());
2468
- //# sourceMappingURL=worker-DYYLzR1Y.js.map
2469
- `, p = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", f], { type: "text/javascript;charset=utf-8" });
2470
- function m(a) {
2471
- let n;
2472
- try {
2473
- if (n = p && (self.URL || self.webkitURL).createObjectURL(p), !n) throw "";
2474
- const t = new Worker(n, {
2475
- type: "module",
2476
- name: a?.name
2477
- });
2478
- return t.addEventListener("error", () => {
2479
- (self.URL || self.webkitURL).revokeObjectURL(n);
2480
- }), t;
2481
- } catch {
2482
- return new Worker(
2483
- "data:text/javascript;charset=utf-8," + encodeURIComponent(f),
2484
- {
2485
- type: "module",
2486
- name: a?.name
2487
- }
2488
- );
2489
- }
2490
- }
2491
- function i(a) {
2492
- return a instanceof URL ? a.pathname : a;
2493
- }
2494
- class y {
2495
- #n;
2496
- #t;
2497
- promises = this;
2498
- constructor(n) {
2499
- this.#t = new m(), this.#n = u(this.#t), n && (n.broadcastChannel && n.broadcastChannel instanceof BroadcastChannel && (n.broadcastChannel = n.broadcastChannel.name), this.setOptions(n));
2500
- }
2501
- /**
2502
- * Start watching a file or directory for changes
2503
- */
2504
- watch(n, t) {
2505
- const e = i(n);
2506
- return this.#n.watch(e, t), () => this.unwatch(e);
2507
- }
2508
- /**
2509
- * Stop watching a previously watched path
2510
- */
2511
- unwatch(n) {
2512
- const t = i(n);
2513
- this.#n.unwatch(t);
2514
- }
2515
- /**
2516
- * Update configuration options
2517
- */
2518
- async setOptions(n) {
2519
- return this.#n.setOptions(n);
2520
- }
2521
- /**
2522
- * Get a complete index of all files and directories in the file system
2523
- */
2524
- async index() {
2525
- return this.#n.index();
2526
- }
2527
- // Implementation
2528
- async readFile(n, t) {
2529
- const e = i(n);
2530
- let r;
2531
- typeof t == "string" ? r = t : t && typeof t == "object" && (r = t.encoding);
2532
- const s = await this.#n.readFile(e);
2533
- return r || (r = h(e) ? "binary" : "utf-8"), r === "binary" ? s : l(s, r);
2534
- }
2535
- /**
2536
- * Write data to a file
2537
- */
2538
- async writeFile(n, t, e) {
2539
- const r = i(n);
2540
- let s;
2541
- typeof e == "string" ? s = e : e && typeof e == "object" && (s = e.encoding), s || (s = typeof t != "string" || h(r) ? "binary" : "utf-8");
2542
- const o = typeof t == "string" ? c(t, s) : t instanceof Uint8Array ? t : new Uint8Array(t);
2543
- return this.#n.writeFile(r, o);
2544
- }
2545
- /**
2546
- * Append data to a file
2547
- */
2548
- async appendFile(n, t, e) {
2549
- const r = i(n);
2550
- e || (e = typeof t != "string" || h(r) ? "binary" : "utf-8");
2551
- const s = typeof t == "string" ? c(t, e) : t instanceof Uint8Array ? t : new Uint8Array(t);
2552
- return this.#n.appendFile(r, s);
2553
- }
2554
- /**
2555
- * Create a directory
2556
- */
2557
- async mkdir(n, t) {
2558
- const e = i(n);
2559
- let r;
2560
- return typeof t == "number" ? r = { recursive: !1 } : r = t, this.#n.mkdir(e, r);
2561
- }
2562
- /**
2563
- * Get file or directory statistics
2564
- */
2565
- async stat(n) {
2566
- const t = i(n);
2567
- return this.#n.stat(t);
2568
- }
2569
- /**
2570
- * Read a directory's contents
2571
- */
2572
- async readDir(n) {
2573
- const t = i(n);
2574
- return this.#n.readDir(t);
2575
- }
2576
- /**
2577
- * Check if a file or directory exists
2578
- */
2579
- async exists(n) {
2580
- const t = i(n);
2581
- return this.#n.exists(t);
2582
- }
2583
- /**
2584
- * Clear all contents of a directory without removing the directory itself
2585
- */
2586
- async clear(n) {
2587
- const t = n ? i(n) : void 0;
2588
- return this.#n.clear(t);
2589
- }
2590
- /**
2591
- * Remove files and directories
2592
- */
2593
- async remove(n, t) {
2594
- const e = i(n);
2595
- return this.#n.remove(e, t);
2596
- }
2597
- /**
2598
- * Alias for remove() for NodeJS like API compatibility
2599
- */
2600
- async unlink(n) {
2601
- return this.remove(n);
2602
- }
2603
- /**
2604
- * Alias for remove() for NodeJS like API compatibility
2605
- */
2606
- async rm(n, t) {
2607
- return this.remove(n, t);
2608
- }
2609
- /**
2610
- * Alias for remove() for NodeJS like API compatibility
2611
- */
2612
- async rmdir(n) {
2613
- return this.remove(n);
2614
- }
2615
- /**
2616
- * Alias for readDir() for NodeJS like API compatibility
2617
- */
2618
- async readdir(n, t) {
2619
- return this.readDir(n);
2620
- }
2621
- /**
2622
- * Alias for stat() for NodeJS like API compatibility
2623
- */
2624
- async lstat(n) {
2625
- return this.stat(n);
2626
- }
2627
- /**
2628
- * Note: OPFS doesn't support file modes, so this is a no-op and exists only for compatibility with tools like isomorphic-git
2629
- */
2630
- async chmod(n, t) {
2631
- return Promise.resolve();
2632
- }
2633
- /**
2634
- * Resolve a path to an absolute path
2635
- */
2636
- async realpath(n) {
2637
- const t = i(n);
2638
- return this.#n.realpath(t);
2639
- }
2640
- /**
2641
- * Rename a file or directory
2642
- */
2643
- async rename(n, t, e) {
2644
- const r = i(n), s = i(t);
2645
- return this.#n.rename(r, s, e);
2646
- }
2647
- /**
2648
- * Copy files and directories
2649
- */
2650
- async copy(n, t, e) {
2651
- const r = i(n), s = i(t);
2652
- return this.#n.copy(r, s, e);
2653
- }
2654
- /**
2655
- * Open a file and return a file descriptor
2656
- */
2657
- async open(n, t) {
2658
- const e = i(n);
2659
- return this.#n.open(e, t);
2660
- }
2661
- /**
2662
- * Close a file descriptor
2663
- */
2664
- async close(n) {
2665
- return this.#n.close(n);
2666
- }
2667
- /**
2668
- * Read data from a file descriptor
2669
- *
2670
- * This method requires special handling due to Comlink transfer requirements.
2671
- * The buffer is transferred to the worker and back, so the original buffer
2672
- * becomes unusable after the call.
2673
- */
2674
- async read(n, t, e, r, s) {
2675
- const { bytesRead: o, buffer: d } = await this.#n.read(
2676
- n,
2677
- // Temp buffer to preserve the original buffer
2678
- new Uint8Array(r),
2679
- 0,
2680
- r,
2681
- s
2682
- );
2683
- return o > 0 && t.set(d.subarray(0, o), e), { bytesRead: o, buffer: t };
2684
- }
2685
- /**
2686
- * Write data to a file descriptor
2687
- */
2688
- async write(n, t, e, r, s, o) {
2689
- return this.#n.write(n, t, e, r, s, o);
2690
- }
2691
- /**
2692
- * Get file status information by file descriptor
2693
- */
2694
- async fstat(n) {
2695
- return this.#n.fstat(n);
2696
- }
2697
- /**
2698
- * Truncate file to specified size
2699
- */
2700
- async ftruncate(n, t) {
2701
- return this.#n.ftruncate(n, t);
2702
- }
2703
- /**
2704
- * Synchronize file data to storage (fsync equivalent)
2705
- */
2706
- async fsync(n) {
2707
- return this.#n.fsync(n);
2708
- }
2709
- /**
2710
- * Synchronize the file system with external data
2711
- */
2712
- async createIndex(n) {
2713
- const t = n.map(([e, r]) => [i(e), r]);
2714
- return this.#n.createIndex(t);
2715
- }
2716
- /**
2717
- * Read a file as text with automatic encoding detection
2718
- */
2719
- async readText(n, t = "utf-8") {
2720
- const e = i(n), r = await this.#n.readFile(e);
2721
- return l(r, t);
2722
- }
2723
- /**
2724
- * Write text to a file with specified encoding
2725
- */
2726
- async writeText(n, t, e = "utf-8") {
2727
- const r = i(n), s = c(t, e);
2728
- return this.#n.writeFile(r, s);
2729
- }
2730
- /**
2731
- * Append text to a file with specified encoding
2732
- */
2733
- async appendText(n, t, e = "utf-8") {
2734
- const r = i(n), s = c(t, e);
2735
- return this.#n.appendFile(r, s);
2736
- }
2737
- /**
2738
- * Dispose of resources, detach the worker and clean up the file system instance
2739
- */
2740
- dispose() {
2741
- const n = this.#n, t = this.#t;
2742
- (async () => {
2743
- try {
2744
- await n.dispose();
2745
- } finally {
2746
- t.terminate();
2747
- }
2748
- })();
2749
- }
2750
- }
2751
- function b(a) {
2752
- return new y(a);
2753
- }
1
+ import { A as e, K as s, B as o, D as t, E as i, F as c, g as n, c as E, I as S, f as l, O as F, a as O, d, e as m, P as p, b as P, S as f, V as h, W as y, k as x, x as u, v as A, H as B, i as v, y as I, u as N, h as b, J as g, N as D, l as k, M as z, t as H, L, q as T, j as W, m as M, p as R, o as j, n as q, z as w, r as C, G as V, s as _, C as G, w as J } from "./BaseOPFS-Cylz6ijk.js";
2
+ import { O as U } from "./OPFSSync-CsSQkpk5.js";
3
+ import { O as Y, O as Q } from "./OPFSFacade-XohWlHuu.js";
4
+ import { c as $, c as aa, c as ra } from "./createOPFSDedicated-CsnV6MLP.js";
5
+ import { O as sa } from "./OPFSAsync-BKSAJJeh.js";
6
+ import { c as ta } from "./createOPFSAsync-Y4Mg6qte.js";
7
+ import { c as ca } from "./createOPFSShared-CGdd__PH.js";
2754
8
  export {
2755
- E as AlreadyExistsError,
2756
- S as BINARY_FILE_EXTENSIONS,
2757
- P as DirectoryOperationError,
2758
- O as ExistenceError,
2759
- F as FileBusyError,
2760
- A as FileSystemOperationError,
2761
- T as FileTypeError,
2762
- R as IOError,
2763
- C as InitializationFailedError,
2764
- I as OPFSError,
2765
- y as OPFSFileSystem,
2766
- D as OPFSNotSupportedError,
2767
- $ as OperationAbortedError,
2768
- _ as OperationNotSupportedError,
2769
- N as PathError,
2770
- k as PermissionError,
2771
- z as StorageError,
2772
- M as ValidationError,
2773
- j as WatchEventType,
2774
- L as basename,
2775
- W as buffersEqual,
2776
- U as calculateFileHash,
2777
- H as calculateReadLength,
2778
- B as checkOPFSSupport,
2779
- G as convertBlobToUint8Array,
2780
- Y as createBuffer,
2781
- q as createFDError,
2782
- V as createSyncHandleSafe,
2783
- b as createWorker,
2784
- l as decodeBuffer,
2785
- Z as dirname,
2786
- c as encodeString,
2787
- J as extname,
2788
- h as isBinaryFileExtension,
2789
- X as isPathExcluded,
2790
- K as joinPath,
2791
- Q as mapDomError,
2792
- nn as matchMinimatch,
2793
- tn as normalizeMinimatch,
2794
- en as normalizePath,
2795
- rn as removeEntry,
2796
- sn as resolvePath,
2797
- an as safeCloseSyncHandle,
2798
- on as splitPath,
2799
- cn as validateReadWriteArgs,
2800
- hn as withLock
9
+ e as AlreadyExistsError,
10
+ s as BINARY_FILE_EXTENSIONS,
11
+ o as BaseOPFS,
12
+ t as DirectoryOperationError,
13
+ i as ExistenceError,
14
+ c as FileBusyError,
15
+ n as FileSystemOperationError,
16
+ E as FileTypeError,
17
+ S as IOError,
18
+ l as InitializationFailedError,
19
+ sa as OPFSAsync,
20
+ F as OPFSError,
21
+ Y as OPFSFacade,
22
+ Q as OPFSFileSystem,
23
+ O as OPFSNotSupportedError,
24
+ U as OPFSSync,
25
+ d as OperationAbortedError,
26
+ m as OperationNotSupportedError,
27
+ p as PathError,
28
+ P as PermissionError,
29
+ f as StorageError,
30
+ h as ValidationError,
31
+ y as WatchEventType,
32
+ x as basename,
33
+ u as buffersEqual,
34
+ A as calculateFileHash,
35
+ B as calculateReadLength,
36
+ v as checkOPFSSupport,
37
+ I as convertBlobToUint8Array,
38
+ N as createBuffer,
39
+ b as createFDError,
40
+ $ as createOPFS,
41
+ ta as createOPFSAsync,
42
+ aa as createOPFSDedicated,
43
+ ca as createOPFSShared,
44
+ g as createSyncHandleSafe,
45
+ ra as createWorker,
46
+ D as decodeBuffer,
47
+ k as dirname,
48
+ z as encodeString,
49
+ H as extname,
50
+ L as isBinaryFileExtension,
51
+ T as isPathExcluded,
52
+ W as joinPath,
53
+ M as mapDomError,
54
+ R as matchMinimatch,
55
+ j as normalizeMinimatch,
56
+ q as normalizePath,
57
+ w as removeEntry,
58
+ C as resolvePath,
59
+ V as safeCloseSyncHandle,
60
+ _ as splitPath,
61
+ G as validateReadWriteArgs,
62
+ J as withLock
2801
63
  };
2802
64
  //# sourceMappingURL=index.js.map