@struktoai/mirage-browser 0.0.2-alpha.0 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -127
- package/dist/aliyun-F2ORS3KZ.js +8 -0
- package/dist/backblaze-HOVWPSV7.js +8 -0
- package/dist/box-VJSE5N7P.js +8 -0
- package/dist/ceph-CQKQ4NWW.js +8 -0
- package/dist/chunk-2H4KUUFP.js +26 -0
- package/dist/chunk-2H4KUUFP.js.map +1 -0
- package/dist/chunk-32VC36P4.js +89 -0
- package/dist/chunk-32VC36P4.js.map +1 -0
- package/dist/{chunk-MSNVGH6T.js → chunk-4YJMDF2S.js} +2 -4
- package/dist/chunk-4YJMDF2S.js.map +1 -0
- package/dist/chunk-54NTYJEO.js +13 -0
- package/dist/chunk-54NTYJEO.js.map +1 -0
- package/dist/chunk-63GZEZW4.js +79 -0
- package/dist/chunk-63GZEZW4.js.map +1 -0
- package/dist/{chunk-UW3D2AF6.js → chunk-6K57U6CM.js} +2 -4
- package/dist/chunk-6K57U6CM.js.map +1 -0
- package/dist/chunk-72GY5B23.js +89 -0
- package/dist/chunk-72GY5B23.js.map +1 -0
- package/dist/{chunk-QYFCHCGX.js → chunk-ATLYBQSC.js} +14 -29
- package/dist/chunk-ATLYBQSC.js.map +1 -0
- package/dist/{chunk-ONQ5JGPR.js → chunk-BUXWUKN7.js} +9 -6
- package/dist/chunk-BUXWUKN7.js.map +1 -0
- package/dist/chunk-CAKSQ2LV.js +85 -0
- package/dist/chunk-CAKSQ2LV.js.map +1 -0
- package/dist/chunk-CO4FMKOF.js +89 -0
- package/dist/chunk-CO4FMKOF.js.map +1 -0
- package/dist/{chunk-5Q5GJUAF.js → chunk-D3JDGGKO.js} +19 -18
- package/dist/chunk-D3JDGGKO.js.map +1 -0
- package/dist/{chunk-DDM2Z7YA.js → chunk-D6HF462C.js} +2 -4
- package/dist/chunk-D6HF462C.js.map +1 -0
- package/dist/{chunk-27UVUTJH.js → chunk-EH2BN4JC.js} +34 -3
- package/dist/chunk-EH2BN4JC.js.map +1 -0
- package/dist/chunk-EUKHGXCE.js +89 -0
- package/dist/chunk-EUKHGXCE.js.map +1 -0
- package/dist/chunk-GHKX2BA3.js +89 -0
- package/dist/chunk-GHKX2BA3.js.map +1 -0
- package/dist/{chunk-FL7YLP7D.js → chunk-HGSTRD7H.js} +10 -8
- package/dist/chunk-HGSTRD7H.js.map +1 -0
- package/dist/chunk-HYUESAQS.js +24 -0
- package/dist/chunk-HYUESAQS.js.map +1 -0
- package/dist/{chunk-ZJ6ROCTP.js → chunk-INLL7LRM.js} +11 -14
- package/dist/chunk-INLL7LRM.js.map +1 -0
- package/dist/chunk-J54OBIJA.js +29 -0
- package/dist/chunk-J54OBIJA.js.map +1 -0
- package/dist/{chunk-DPC7QRYO.js → chunk-JCS5EG5A.js} +9 -6
- package/dist/chunk-JCS5EG5A.js.map +1 -0
- package/dist/chunk-JSAQMYPK.js +26 -0
- package/dist/chunk-JSAQMYPK.js.map +1 -0
- package/dist/{chunk-CZOTICOC.js → chunk-JVTKE6DB.js} +2 -4
- package/dist/chunk-JVTKE6DB.js.map +1 -0
- package/dist/{chunk-3PWPFOPS.js → chunk-MO5DGX42.js} +19 -18
- package/dist/chunk-MO5DGX42.js.map +1 -0
- package/dist/{chunk-LZRPA2P7.js → chunk-N43C6XFP.js} +9 -6
- package/dist/chunk-N43C6XFP.js.map +1 -0
- package/dist/chunk-NMZBJOFW.js +26 -0
- package/dist/chunk-NMZBJOFW.js.map +1 -0
- package/dist/chunk-O5ONB7QT.js +26 -0
- package/dist/chunk-O5ONB7QT.js.map +1 -0
- package/dist/{chunk-LSSB3AEW.js → chunk-RD7ED27I.js} +5 -12
- package/dist/chunk-RD7ED27I.js.map +1 -0
- package/dist/chunk-RJ4RR3BR.js +92 -0
- package/dist/chunk-RJ4RR3BR.js.map +1 -0
- package/dist/chunk-RJ5FBBL6.js +79 -0
- package/dist/chunk-RJ5FBBL6.js.map +1 -0
- package/dist/{chunk-SQQI4A6Y.js → chunk-RZRXEXHM.js} +2 -4
- package/dist/chunk-RZRXEXHM.js.map +1 -0
- package/dist/{chunk-CQJTW45B.js → chunk-SBAUYZJB.js} +2 -4
- package/dist/chunk-SBAUYZJB.js.map +1 -0
- package/dist/chunk-SJB2KXDM.js +2109 -0
- package/dist/chunk-SJB2KXDM.js.map +1 -0
- package/dist/{chunk-33SBWNB4.js → chunk-T43CZ3IZ.js} +9 -8
- package/dist/chunk-T43CZ3IZ.js.map +1 -0
- package/dist/{chunk-LG6GVNOL.js → chunk-TPFH5V4D.js} +2 -4
- package/dist/chunk-TPFH5V4D.js.map +1 -0
- package/dist/{chunk-LUDXUYIA.js → chunk-WEJGUCCL.js} +19 -18
- package/dist/chunk-WEJGUCCL.js.map +1 -0
- package/dist/{chunk-UFXEZ56G.js → chunk-WZ53HLH6.js} +18 -18
- package/dist/chunk-WZ53HLH6.js.map +1 -0
- package/dist/{chunk-VLFE4FGD.js → chunk-XFREXNA2.js} +2 -3
- package/dist/chunk-XFREXNA2.js.map +1 -0
- package/dist/chunk-YEDSFMWK.js +79 -0
- package/dist/chunk-YEDSFMWK.js.map +1 -0
- package/dist/chunk-YGRKFONX.js +26 -0
- package/dist/chunk-YGRKFONX.js.map +1 -0
- package/dist/config-7IZCGWKX.js +11 -0
- package/dist/config-AT74FARJ.js +11 -0
- package/dist/config-C2AYHACT.js +11 -0
- package/dist/{config-U4UI4OKA.js → config-ET26F632.js} +4 -2
- package/dist/config-GHJOYNM6.js +11 -0
- package/dist/config-L55UXIF4.js +11 -0
- package/dist/config-NV5WXP64.js +11 -0
- package/dist/config-V7BLK5WP.js +11 -0
- package/dist/digitalocean-KC7VIWZK.js +8 -0
- package/dist/discord-W3DSEXKN.js +7 -0
- package/dist/dropbox-GI273OVA.js +8 -0
- package/dist/gcs-WRQTU27E.js +8 -0
- package/dist/gdocs-EI2EFVKG.js +8 -0
- package/dist/gdrive-62HD67IP.js +8 -0
- package/dist/github-SWLYD3LS.js +7 -0
- package/dist/github_ci-7P7VGBKM.js +8 -0
- package/dist/gmail-B7HXHZ7D.js +8 -0
- package/dist/gsheets-OTBW2JWG.js +8 -0
- package/dist/gslides-MXSR4HRY.js +8 -0
- package/dist/index.d.ts +342 -166
- package/dist/index.js +264 -373
- package/dist/index.js.map +1 -1
- package/dist/langfuse-FWKU6E3F.js +7 -0
- package/dist/linear-SHVG3XVT.js +7 -0
- package/dist/minio-246KOHBJ.js +8 -0
- package/dist/mongodb-2ITJUDCF.js +7 -0
- package/dist/notion-BOBBSJSG.js +7 -0
- package/dist/oci-T7VREPQW.js +8 -0
- package/dist/opfs-3XNAXR5B.js +7 -0
- package/dist/qingstor-WIC27LS3.js +8 -0
- package/dist/qingstor-WIC27LS3.js.map +1 -0
- package/dist/r2-EAX6KHEI.js +8 -0
- package/dist/r2-EAX6KHEI.js.map +1 -0
- package/dist/{s3-A4XFE6QV.js → s3-GD2WKLWR.js} +2 -2
- package/dist/s3-GD2WKLWR.js.map +1 -0
- package/dist/scaleway-OVFRZBKW.js +8 -0
- package/dist/scaleway-OVFRZBKW.js.map +1 -0
- package/dist/seaweedfs-EOJVO432.js +8 -0
- package/dist/seaweedfs-EOJVO432.js.map +1 -0
- package/dist/slack-RNXMU5OC.js +7 -0
- package/dist/slack-RNXMU5OC.js.map +1 -0
- package/dist/supabase-VSUNLIJ6.js +8 -0
- package/dist/supabase-VSUNLIJ6.js.map +1 -0
- package/dist/tencent-YYM5WUVU.js +8 -0
- package/dist/tencent-YYM5WUVU.js.map +1 -0
- package/dist/trello-MNR3VPTT.js +7 -0
- package/dist/trello-MNR3VPTT.js.map +1 -0
- package/dist/wasabi-K5ANTZ2C.js +8 -0
- package/dist/wasabi-K5ANTZ2C.js.map +1 -0
- package/package.json +3 -3
- package/dist/box-Y2SJWAAO.js +0 -8
- package/dist/chunk-27UVUTJH.js.map +0 -1
- package/dist/chunk-33SBWNB4.js.map +0 -1
- package/dist/chunk-3PWPFOPS.js.map +0 -1
- package/dist/chunk-5Q5GJUAF.js.map +0 -1
- package/dist/chunk-7GZXXXAS.js +0 -24
- package/dist/chunk-7GZXXXAS.js.map +0 -1
- package/dist/chunk-B4SYG2FD.js +0 -24
- package/dist/chunk-B4SYG2FD.js.map +0 -1
- package/dist/chunk-BIZONEJC.js +0 -24
- package/dist/chunk-BIZONEJC.js.map +0 -1
- package/dist/chunk-CQJTW45B.js.map +0 -1
- package/dist/chunk-CZOTICOC.js.map +0 -1
- package/dist/chunk-DDM2Z7YA.js.map +0 -1
- package/dist/chunk-DPC7QRYO.js.map +0 -1
- package/dist/chunk-FL7YLP7D.js.map +0 -1
- package/dist/chunk-GFWWDQUZ.js +0 -24
- package/dist/chunk-GFWWDQUZ.js.map +0 -1
- package/dist/chunk-LG6GVNOL.js.map +0 -1
- package/dist/chunk-LSSB3AEW.js.map +0 -1
- package/dist/chunk-LUDXUYIA.js.map +0 -1
- package/dist/chunk-LZRPA2P7.js.map +0 -1
- package/dist/chunk-ML57VOCK.js +0 -7590
- package/dist/chunk-ML57VOCK.js.map +0 -1
- package/dist/chunk-MSNVGH6T.js.map +0 -1
- package/dist/chunk-NBWTZXH2.js +0 -27
- package/dist/chunk-NBWTZXH2.js.map +0 -1
- package/dist/chunk-ONQ5JGPR.js.map +0 -1
- package/dist/chunk-OPROOV6J.js +0 -24
- package/dist/chunk-OPROOV6J.js.map +0 -1
- package/dist/chunk-QARIHW3I.js +0 -23
- package/dist/chunk-QARIHW3I.js.map +0 -1
- package/dist/chunk-QYFCHCGX.js.map +0 -1
- package/dist/chunk-SQQI4A6Y.js.map +0 -1
- package/dist/chunk-UFXEZ56G.js.map +0 -1
- package/dist/chunk-UW3D2AF6.js.map +0 -1
- package/dist/chunk-VLFE4FGD.js.map +0 -1
- package/dist/chunk-XIURBEVZ.js +0 -24
- package/dist/chunk-XIURBEVZ.js.map +0 -1
- package/dist/chunk-ZJ6ROCTP.js.map +0 -1
- package/dist/config-4FABMWVK.js +0 -9
- package/dist/config-DGIUMGBB.js +0 -9
- package/dist/config-G3TTNXLY.js +0 -9
- package/dist/config-GPCEEKCB.js +0 -9
- package/dist/config-KQ5VR2KZ.js +0 -9
- package/dist/config-LPMMVXLS.js +0 -9
- package/dist/config-VZGK63Z5.js +0 -9
- package/dist/discord-RG6URXXS.js +0 -7
- package/dist/dropbox-P7SOL7GN.js +0 -8
- package/dist/gcs-2QHB4CBT.js +0 -8
- package/dist/gdocs-JNZTOZ33.js +0 -8
- package/dist/gdrive-6MEIVN2F.js +0 -8
- package/dist/github-M7WODJR2.js +0 -7
- package/dist/github_ci-4XELEFSZ.js +0 -8
- package/dist/gmail-AO6A3URH.js +0 -8
- package/dist/gsheets-RFOKXMOJ.js +0 -8
- package/dist/gslides-GTVZPLLB.js +0 -8
- package/dist/langfuse-CDOLELMB.js +0 -7
- package/dist/linear-SXOQGG6B.js +0 -7
- package/dist/mongodb-HA7FAKDJ.js +0 -7
- package/dist/notion-ANZNMM3L.js +0 -7
- package/dist/oci-ML5ZRVZ2.js +0 -8
- package/dist/opfs-57XFMWWE.js +0 -7
- package/dist/r2-56O4Q2J4.js +0 -8
- package/dist/slack-QA7H7WLM.js +0 -7
- package/dist/supabase-NNK2RWG3.js +0 -8
- package/dist/trello-H6PZT2IT.js +0 -7
- /package/dist/{box-Y2SJWAAO.js.map → aliyun-F2ORS3KZ.js.map} +0 -0
- /package/dist/{config-4FABMWVK.js.map → backblaze-HOVWPSV7.js.map} +0 -0
- /package/dist/{config-DGIUMGBB.js.map → box-VJSE5N7P.js.map} +0 -0
- /package/dist/{config-G3TTNXLY.js.map → ceph-CQKQ4NWW.js.map} +0 -0
- /package/dist/{config-GPCEEKCB.js.map → config-7IZCGWKX.js.map} +0 -0
- /package/dist/{config-KQ5VR2KZ.js.map → config-AT74FARJ.js.map} +0 -0
- /package/dist/{config-LPMMVXLS.js.map → config-C2AYHACT.js.map} +0 -0
- /package/dist/{config-U4UI4OKA.js.map → config-ET26F632.js.map} +0 -0
- /package/dist/{config-VZGK63Z5.js.map → config-GHJOYNM6.js.map} +0 -0
- /package/dist/{discord-RG6URXXS.js.map → config-L55UXIF4.js.map} +0 -0
- /package/dist/{dropbox-P7SOL7GN.js.map → config-NV5WXP64.js.map} +0 -0
- /package/dist/{gcs-2QHB4CBT.js.map → config-V7BLK5WP.js.map} +0 -0
- /package/dist/{gdocs-JNZTOZ33.js.map → digitalocean-KC7VIWZK.js.map} +0 -0
- /package/dist/{gdrive-6MEIVN2F.js.map → discord-W3DSEXKN.js.map} +0 -0
- /package/dist/{github-M7WODJR2.js.map → dropbox-GI273OVA.js.map} +0 -0
- /package/dist/{github_ci-4XELEFSZ.js.map → gcs-WRQTU27E.js.map} +0 -0
- /package/dist/{gmail-AO6A3URH.js.map → gdocs-EI2EFVKG.js.map} +0 -0
- /package/dist/{gsheets-RFOKXMOJ.js.map → gdrive-62HD67IP.js.map} +0 -0
- /package/dist/{gslides-GTVZPLLB.js.map → github-SWLYD3LS.js.map} +0 -0
- /package/dist/{langfuse-CDOLELMB.js.map → github_ci-7P7VGBKM.js.map} +0 -0
- /package/dist/{linear-SXOQGG6B.js.map → gmail-B7HXHZ7D.js.map} +0 -0
- /package/dist/{mongodb-HA7FAKDJ.js.map → gsheets-OTBW2JWG.js.map} +0 -0
- /package/dist/{notion-ANZNMM3L.js.map → gslides-MXSR4HRY.js.map} +0 -0
- /package/dist/{oci-ML5ZRVZ2.js.map → langfuse-FWKU6E3F.js.map} +0 -0
- /package/dist/{opfs-57XFMWWE.js.map → linear-SHVG3XVT.js.map} +0 -0
- /package/dist/{r2-56O4Q2J4.js.map → minio-246KOHBJ.js.map} +0 -0
- /package/dist/{s3-A4XFE6QV.js.map → mongodb-2ITJUDCF.js.map} +0 -0
- /package/dist/{slack-QA7H7WLM.js.map → notion-BOBBSJSG.js.map} +0 -0
- /package/dist/{supabase-NNK2RWG3.js.map → oci-T7VREPQW.js.map} +0 -0
- /package/dist/{trello-H6PZT2IT.js.map → opfs-3XNAXR5B.js.map} +0 -0
|
@@ -0,0 +1,2109 @@
|
|
|
1
|
+
// src/resource/opfs/opfs.ts
|
|
2
|
+
import {
|
|
3
|
+
ResourceName as ResourceName80,
|
|
4
|
+
lstripSlash
|
|
5
|
+
} from "@struktoai/mirage-core";
|
|
6
|
+
|
|
7
|
+
// src/accessor/opfs.ts
|
|
8
|
+
import { Accessor } from "@struktoai/mirage-core";
|
|
9
|
+
var OPFSAccessor = class extends Accessor {
|
|
10
|
+
provider;
|
|
11
|
+
constructor(provider) {
|
|
12
|
+
super();
|
|
13
|
+
this.provider = provider;
|
|
14
|
+
}
|
|
15
|
+
get rootHandle() {
|
|
16
|
+
return this.provider.requireHandle();
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// src/commands/builtin/opfs/index.ts
|
|
21
|
+
import { makeFiletypeCommands, ResourceName as ResourceName67 } from "@struktoai/mirage-core";
|
|
22
|
+
|
|
23
|
+
// src/core/opfs/read.ts
|
|
24
|
+
import { record, ResourceName } from "@struktoai/mirage-core";
|
|
25
|
+
import { enoent } from "@struktoai/mirage-core";
|
|
26
|
+
|
|
27
|
+
// src/core/opfs/utils.ts
|
|
28
|
+
import { norm, parent, gnuBasename } from "@struktoai/mirage-core";
|
|
29
|
+
function splitSegments(virtual) {
|
|
30
|
+
const parts = [];
|
|
31
|
+
for (const seg of virtual.split("/")) {
|
|
32
|
+
if (seg === "" || seg === ".") continue;
|
|
33
|
+
if (seg === "..") {
|
|
34
|
+
if (parts.length === 0) {
|
|
35
|
+
throw new Error(`path escapes root: ${virtual}`);
|
|
36
|
+
}
|
|
37
|
+
parts.pop();
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
parts.push(seg);
|
|
41
|
+
}
|
|
42
|
+
return parts;
|
|
43
|
+
}
|
|
44
|
+
async function resolveDirHandle(root, virtual, options = {}) {
|
|
45
|
+
const segs = splitSegments(virtual);
|
|
46
|
+
let handle = root;
|
|
47
|
+
for (const seg of segs) {
|
|
48
|
+
handle = await handle.getDirectoryHandle(seg, { create: options.create ?? false });
|
|
49
|
+
}
|
|
50
|
+
return handle;
|
|
51
|
+
}
|
|
52
|
+
async function resolveFileHandle(root, virtual, options = {}) {
|
|
53
|
+
const segs = splitSegments(virtual);
|
|
54
|
+
const fileName = segs.pop();
|
|
55
|
+
if (fileName === void 0) {
|
|
56
|
+
throw new Error(`not a file: ${virtual}`);
|
|
57
|
+
}
|
|
58
|
+
let dir = root;
|
|
59
|
+
for (const seg of segs) {
|
|
60
|
+
dir = await dir.getDirectoryHandle(seg, { create: options.create ?? false });
|
|
61
|
+
}
|
|
62
|
+
return dir.getFileHandle(fileName, { create: options.create ?? false });
|
|
63
|
+
}
|
|
64
|
+
async function resolveParentDirHandle(root, virtual, options = {}) {
|
|
65
|
+
const segs = splitSegments(virtual);
|
|
66
|
+
const name = segs.pop();
|
|
67
|
+
if (name === void 0) {
|
|
68
|
+
throw new Error(`no parent directory: ${virtual}`);
|
|
69
|
+
}
|
|
70
|
+
let dir = root;
|
|
71
|
+
for (const seg of segs) {
|
|
72
|
+
dir = await dir.getDirectoryHandle(seg, { create: options.create ?? false });
|
|
73
|
+
}
|
|
74
|
+
return [dir, name];
|
|
75
|
+
}
|
|
76
|
+
function isNotFound(err) {
|
|
77
|
+
if (err instanceof DOMException) {
|
|
78
|
+
return err.name === "NotFoundError";
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
function toWritableChunk(data) {
|
|
83
|
+
const copy2 = new Uint8Array(data.byteLength);
|
|
84
|
+
copy2.set(data);
|
|
85
|
+
return new Blob([copy2]);
|
|
86
|
+
}
|
|
87
|
+
async function* iterEntries(dir) {
|
|
88
|
+
const iter = dir.entries();
|
|
89
|
+
for await (const [name, handle] of iter) {
|
|
90
|
+
yield [name, handle];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// src/core/opfs/read.ts
|
|
95
|
+
async function read(accessor, path) {
|
|
96
|
+
const root = accessor.rootHandle;
|
|
97
|
+
const start = performance.now();
|
|
98
|
+
const virtual = path.stripPrefix;
|
|
99
|
+
let handle;
|
|
100
|
+
try {
|
|
101
|
+
handle = await resolveFileHandle(root, virtual, { create: false });
|
|
102
|
+
} catch (err) {
|
|
103
|
+
if (isNotFound(err)) throw enoent(path);
|
|
104
|
+
throw err;
|
|
105
|
+
}
|
|
106
|
+
const file = await handle.getFile();
|
|
107
|
+
const bytes = new Uint8Array(await file.arrayBuffer());
|
|
108
|
+
record("read", virtual, ResourceName.OPFS, bytes.byteLength, start);
|
|
109
|
+
return bytes;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// src/core/opfs/stat.ts
|
|
113
|
+
import { FileStat, FileType, guessType } from "@struktoai/mirage-core";
|
|
114
|
+
import { enoent as enoent2 } from "@struktoai/mirage-core";
|
|
115
|
+
async function stat(accessor, p) {
|
|
116
|
+
const root = accessor.rootHandle;
|
|
117
|
+
const virtual = p.stripPrefix;
|
|
118
|
+
const segs = splitSegments(virtual);
|
|
119
|
+
const last = segs.at(-1);
|
|
120
|
+
if (last === void 0) {
|
|
121
|
+
return new FileStat({
|
|
122
|
+
name: "/",
|
|
123
|
+
size: null,
|
|
124
|
+
modified: null,
|
|
125
|
+
type: FileType.DIRECTORY
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
const name = last;
|
|
129
|
+
let parentDir;
|
|
130
|
+
let entryName;
|
|
131
|
+
try {
|
|
132
|
+
;
|
|
133
|
+
[parentDir, entryName] = await resolveParentDirHandle(root, virtual, { create: false });
|
|
134
|
+
} catch (err) {
|
|
135
|
+
if (isNotFound(err)) throw enoent2(p);
|
|
136
|
+
throw err;
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
const fileHandle = await parentDir.getFileHandle(entryName, { create: false });
|
|
140
|
+
const file = await fileHandle.getFile();
|
|
141
|
+
const modified = new Date(file.lastModified).toISOString();
|
|
142
|
+
return new FileStat({
|
|
143
|
+
name,
|
|
144
|
+
size: file.size,
|
|
145
|
+
modified,
|
|
146
|
+
fingerprint: modified,
|
|
147
|
+
type: guessType(name)
|
|
148
|
+
});
|
|
149
|
+
} catch (err) {
|
|
150
|
+
if (!isNotFound(err) && !(err instanceof DOMException && err.name === "TypeMismatchError")) {
|
|
151
|
+
throw err;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
await resolveDirHandle(root, virtual, { create: false });
|
|
156
|
+
return new FileStat({
|
|
157
|
+
name,
|
|
158
|
+
size: null,
|
|
159
|
+
modified: null,
|
|
160
|
+
type: FileType.DIRECTORY
|
|
161
|
+
});
|
|
162
|
+
} catch (err) {
|
|
163
|
+
if (isNotFound(err)) throw enoent2(p);
|
|
164
|
+
throw err;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// src/commands/builtin/opfs/awk.ts
|
|
169
|
+
import { ResourceName as ResourceName3, awkGeneric, command, specOf } from "@struktoai/mirage-core";
|
|
170
|
+
|
|
171
|
+
// src/core/opfs/stream.ts
|
|
172
|
+
import { recordStream, ResourceName as ResourceName2 } from "@struktoai/mirage-core";
|
|
173
|
+
import { enoent as enoent3 } from "@struktoai/mirage-core";
|
|
174
|
+
async function* stream(accessor, path) {
|
|
175
|
+
const root = accessor.rootHandle;
|
|
176
|
+
const virtual = path.stripPrefix;
|
|
177
|
+
let handle;
|
|
178
|
+
try {
|
|
179
|
+
handle = await resolveFileHandle(root, virtual, { create: false });
|
|
180
|
+
} catch (err) {
|
|
181
|
+
if (isNotFound(err)) throw enoent3(path);
|
|
182
|
+
throw err;
|
|
183
|
+
}
|
|
184
|
+
const file = await handle.getFile();
|
|
185
|
+
const rec = recordStream("read", virtual, ResourceName2.OPFS);
|
|
186
|
+
const reader = file.stream().getReader();
|
|
187
|
+
for (; ; ) {
|
|
188
|
+
const { value, done } = await reader.read();
|
|
189
|
+
if (done) break;
|
|
190
|
+
if (rec !== null) rec.bytes += value.byteLength;
|
|
191
|
+
yield value;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// src/commands/builtin/opfs/awk.ts
|
|
196
|
+
var OPFS_AWK = command({
|
|
197
|
+
name: "awk",
|
|
198
|
+
resource: ResourceName3.OPFS,
|
|
199
|
+
spec: specOf("awk"),
|
|
200
|
+
fn: (accessor, paths, texts, opts) => awkGeneric(paths, texts, opts, (p) => stream(accessor, p))
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// src/commands/builtin/opfs/base64_cmd.ts
|
|
204
|
+
import { ResourceName as ResourceName4, command as command2, specOf as specOf2, base64Generic } from "@struktoai/mirage-core";
|
|
205
|
+
var OPFS_BASE64 = command2({
|
|
206
|
+
name: "base64",
|
|
207
|
+
resource: ResourceName4.OPFS,
|
|
208
|
+
spec: specOf2("base64"),
|
|
209
|
+
fn: (accessor, paths, _texts, opts) => base64Generic(paths, opts, (p) => stream(accessor, p))
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
// src/commands/builtin/opfs/basename.ts
|
|
213
|
+
import { ResourceName as ResourceName5, command as command3, specOf as specOf3, basenameFn } from "@struktoai/mirage-core";
|
|
214
|
+
var OPFS_BASENAME = command3({
|
|
215
|
+
name: "basename",
|
|
216
|
+
resource: ResourceName5.OPFS,
|
|
217
|
+
spec: specOf3("basename"),
|
|
218
|
+
fn: basenameFn
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// src/commands/builtin/opfs/cat/cat.ts
|
|
222
|
+
import {
|
|
223
|
+
ResourceName as ResourceName6,
|
|
224
|
+
catGeneric,
|
|
225
|
+
catProvisionGeneric,
|
|
226
|
+
command as command4,
|
|
227
|
+
concatAggregate,
|
|
228
|
+
specOf as specOf4
|
|
229
|
+
} from "@struktoai/mirage-core";
|
|
230
|
+
var OPFS_CAT = command4({
|
|
231
|
+
name: "cat",
|
|
232
|
+
resource: ResourceName6.OPFS,
|
|
233
|
+
spec: specOf4("cat"),
|
|
234
|
+
fn: (accessor, paths, texts, opts) => catGeneric(
|
|
235
|
+
paths,
|
|
236
|
+
texts,
|
|
237
|
+
opts,
|
|
238
|
+
(p) => stat(accessor, p),
|
|
239
|
+
(p) => stream(accessor, p)
|
|
240
|
+
),
|
|
241
|
+
provision: (accessor, paths, _texts, _opts) => catProvisionGeneric(paths, (p) => stat(accessor, p)),
|
|
242
|
+
aggregate: concatAggregate
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// src/commands/builtin/opfs/cmp.ts
|
|
246
|
+
import { ResourceName as ResourceName7, command as command5, specOf as specOf5, cmpGeneric } from "@struktoai/mirage-core";
|
|
247
|
+
var OPFS_CMP = command5({
|
|
248
|
+
name: "cmp",
|
|
249
|
+
resource: ResourceName7.OPFS,
|
|
250
|
+
spec: specOf5("cmp"),
|
|
251
|
+
fn: (accessor, paths, _texts, opts) => cmpGeneric(paths, opts, (p) => stream(accessor, p))
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
// src/commands/builtin/opfs/column.ts
|
|
255
|
+
import { ResourceName as ResourceName8, command as command6, specOf as specOf6, columnGeneric } from "@struktoai/mirage-core";
|
|
256
|
+
var OPFS_COLUMN = command6({
|
|
257
|
+
name: "column",
|
|
258
|
+
resource: ResourceName8.OPFS,
|
|
259
|
+
spec: specOf6("column"),
|
|
260
|
+
fn: (accessor, paths, _texts, opts) => columnGeneric(paths, opts, (p) => stream(accessor, p))
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
// src/commands/builtin/opfs/comm.ts
|
|
264
|
+
import { ResourceName as ResourceName9, command as command7, specOf as specOf7, commGeneric } from "@struktoai/mirage-core";
|
|
265
|
+
var OPFS_COMM = command7({
|
|
266
|
+
name: "comm",
|
|
267
|
+
resource: ResourceName9.OPFS,
|
|
268
|
+
spec: specOf7("comm"),
|
|
269
|
+
fn: (accessor, paths, _texts, opts) => commGeneric(paths, opts, (p) => stream(accessor, p))
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
// src/commands/builtin/opfs/cp.ts
|
|
273
|
+
import {
|
|
274
|
+
IOResult,
|
|
275
|
+
ResourceName as ResourceName10,
|
|
276
|
+
command as command8,
|
|
277
|
+
cpGeneric,
|
|
278
|
+
specOf as specOf8
|
|
279
|
+
} from "@struktoai/mirage-core";
|
|
280
|
+
|
|
281
|
+
// src/core/opfs/copy.ts
|
|
282
|
+
async function copy(accessor, src, dst) {
|
|
283
|
+
const root = accessor.rootHandle;
|
|
284
|
+
let srcHandle;
|
|
285
|
+
try {
|
|
286
|
+
srcHandle = await resolveFileHandle(root, src.stripPrefix, { create: false });
|
|
287
|
+
} catch (err) {
|
|
288
|
+
if (isNotFound(err)) throw new Error(`file not found: ${src.stripPrefix}`);
|
|
289
|
+
throw err;
|
|
290
|
+
}
|
|
291
|
+
const file = await srcHandle.getFile();
|
|
292
|
+
const data = new Uint8Array(await file.arrayBuffer());
|
|
293
|
+
const dstHandle = await resolveFileHandle(root, dst.stripPrefix, { create: true });
|
|
294
|
+
const writable = await dstHandle.createWritable();
|
|
295
|
+
await writable.write(toWritableChunk(data));
|
|
296
|
+
await writable.close();
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// src/core/opfs/find.ts
|
|
300
|
+
import { buildTree, keep } from "@struktoai/mirage-core";
|
|
301
|
+
async function walk(ctx, dir, current, depth) {
|
|
302
|
+
const opts = ctx.options;
|
|
303
|
+
if (opts.maxDepth !== null && opts.maxDepth !== void 0 && depth > opts.maxDepth) return;
|
|
304
|
+
let iter;
|
|
305
|
+
try {
|
|
306
|
+
iter = iterEntries(dir);
|
|
307
|
+
} catch {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
for await (const [entryName, handle] of iter) {
|
|
311
|
+
const kind = handle.kind === "directory" ? "d" : "f";
|
|
312
|
+
const entryPath = current === "/" ? `/${entryName}` : `${current}/${entryName}`;
|
|
313
|
+
const entryDepth = depth + 1;
|
|
314
|
+
let accept = true;
|
|
315
|
+
if (opts.maxDepth !== null && opts.maxDepth !== void 0 && entryDepth > opts.maxDepth) {
|
|
316
|
+
accept = false;
|
|
317
|
+
}
|
|
318
|
+
let isEmpty = null;
|
|
319
|
+
if (accept && opts.empty === true) {
|
|
320
|
+
try {
|
|
321
|
+
if (kind === "f") {
|
|
322
|
+
isEmpty = (await handle.getFile()).size === 0;
|
|
323
|
+
} else {
|
|
324
|
+
isEmpty = true;
|
|
325
|
+
for await (const _child of iterEntries(handle)) {
|
|
326
|
+
void _child;
|
|
327
|
+
isEmpty = false;
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
} catch {
|
|
332
|
+
isEmpty = null;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
if (accept && !keep(
|
|
336
|
+
{ key: entryPath, name: entryName, kind, depth: entryDepth, isEmpty },
|
|
337
|
+
ctx.tree,
|
|
338
|
+
opts.minDepth
|
|
339
|
+
)) {
|
|
340
|
+
accept = false;
|
|
341
|
+
}
|
|
342
|
+
if (accept && kind === "f" && (opts.minSize !== null || opts.maxSize !== null || opts.mtimeMin !== null || opts.mtimeMax !== null)) {
|
|
343
|
+
try {
|
|
344
|
+
const fh = await dir.getFileHandle(entryName, { create: false });
|
|
345
|
+
const file = await fh.getFile();
|
|
346
|
+
if (opts.minSize !== null && opts.minSize !== void 0 && file.size < opts.minSize)
|
|
347
|
+
accept = false;
|
|
348
|
+
if (opts.maxSize !== null && opts.maxSize !== void 0 && file.size > opts.maxSize)
|
|
349
|
+
accept = false;
|
|
350
|
+
if (accept && (opts.mtimeMin !== void 0 || opts.mtimeMax !== void 0)) {
|
|
351
|
+
const mtime = file.lastModified / 1e3;
|
|
352
|
+
if (opts.mtimeMin !== null && opts.mtimeMin !== void 0 && mtime < opts.mtimeMin)
|
|
353
|
+
accept = false;
|
|
354
|
+
if (opts.mtimeMax !== null && opts.mtimeMax !== void 0 && mtime > opts.mtimeMax)
|
|
355
|
+
accept = false;
|
|
356
|
+
}
|
|
357
|
+
} catch {
|
|
358
|
+
accept = false;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
if (accept) ctx.results.push(entryPath);
|
|
362
|
+
if (kind === "d") {
|
|
363
|
+
try {
|
|
364
|
+
const child = await dir.getDirectoryHandle(entryName, { create: false });
|
|
365
|
+
await walk(ctx, child, entryPath, depth + 1);
|
|
366
|
+
} catch {
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
async function find(accessor, p, options = {}) {
|
|
372
|
+
const root = accessor.rootHandle;
|
|
373
|
+
const virtual = norm(p.stripPrefix);
|
|
374
|
+
const results = [];
|
|
375
|
+
const tree = options.tree ?? buildTree({
|
|
376
|
+
name: options.name,
|
|
377
|
+
iname: options.iname,
|
|
378
|
+
pathPattern: options.pathPattern,
|
|
379
|
+
type: options.type,
|
|
380
|
+
nameExclude: options.nameExclude,
|
|
381
|
+
orNames: options.orNames,
|
|
382
|
+
empty: options.empty
|
|
383
|
+
});
|
|
384
|
+
let dir;
|
|
385
|
+
try {
|
|
386
|
+
dir = await resolveDirHandle(root, virtual, { create: false });
|
|
387
|
+
} catch (err) {
|
|
388
|
+
if (isNotFound(err)) return results;
|
|
389
|
+
throw err;
|
|
390
|
+
}
|
|
391
|
+
if (virtual !== "/" && (options.maxDepth == null || options.maxDepth >= 0)) {
|
|
392
|
+
let rootEmpty = null;
|
|
393
|
+
if (options.empty === true) {
|
|
394
|
+
rootEmpty = true;
|
|
395
|
+
for await (const _child of iterEntries(dir)) {
|
|
396
|
+
void _child;
|
|
397
|
+
rootEmpty = false;
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
if (keep(
|
|
402
|
+
{
|
|
403
|
+
key: virtual,
|
|
404
|
+
name: virtual.slice(virtual.lastIndexOf("/") + 1),
|
|
405
|
+
kind: "d",
|
|
406
|
+
depth: 0,
|
|
407
|
+
isEmpty: rootEmpty
|
|
408
|
+
},
|
|
409
|
+
tree,
|
|
410
|
+
options.minDepth
|
|
411
|
+
)) {
|
|
412
|
+
results.push(virtual);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
await walk({ options, tree, results }, dir, virtual, 0);
|
|
416
|
+
results.sort();
|
|
417
|
+
return results;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// src/commands/builtin/opfs/cp.ts
|
|
421
|
+
function cpCommand(accessor, paths, _texts, opts) {
|
|
422
|
+
if (paths.length < 2) {
|
|
423
|
+
return Promise.resolve([
|
|
424
|
+
null,
|
|
425
|
+
new IOResult({ exitCode: 1, stderr: new TextEncoder().encode("cp: missing operand\n") })
|
|
426
|
+
]);
|
|
427
|
+
}
|
|
428
|
+
const recursive = opts.flags.r === true || opts.flags.R === true || opts.flags.a === true;
|
|
429
|
+
return cpGeneric(
|
|
430
|
+
paths,
|
|
431
|
+
(src, target) => copy(accessor, src, target),
|
|
432
|
+
(src, options) => find(accessor, src, options),
|
|
433
|
+
(p) => stat(accessor, p),
|
|
434
|
+
recursive,
|
|
435
|
+
opts.flags.n === true,
|
|
436
|
+
opts.flags.v === true,
|
|
437
|
+
opts.index ?? void 0
|
|
438
|
+
);
|
|
439
|
+
}
|
|
440
|
+
var OPFS_CP = command8({
|
|
441
|
+
name: "cp",
|
|
442
|
+
resource: ResourceName10.OPFS,
|
|
443
|
+
spec: specOf8("cp"),
|
|
444
|
+
fn: cpCommand,
|
|
445
|
+
write: true
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
// src/commands/builtin/opfs/csplit.ts
|
|
449
|
+
import { ResourceName as ResourceName12, command as command9, specOf as specOf9, csplitGeneric } from "@struktoai/mirage-core";
|
|
450
|
+
|
|
451
|
+
// src/core/opfs/write.ts
|
|
452
|
+
import { record as record2, ResourceName as ResourceName11 } from "@struktoai/mirage-core";
|
|
453
|
+
async function writeBytes(accessor, p, data) {
|
|
454
|
+
const root = accessor.rootHandle;
|
|
455
|
+
const start = performance.now();
|
|
456
|
+
const virtual = p.stripPrefix;
|
|
457
|
+
const handle = await resolveFileHandle(root, virtual, { create: true });
|
|
458
|
+
const writable = await handle.createWritable();
|
|
459
|
+
await writable.write(toWritableChunk(data));
|
|
460
|
+
await writable.close();
|
|
461
|
+
record2("write", virtual, ResourceName11.OPFS, data.byteLength, start);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// src/commands/builtin/opfs/csplit.ts
|
|
465
|
+
var OPFS_CSPLIT = command9({
|
|
466
|
+
name: "csplit",
|
|
467
|
+
resource: ResourceName12.OPFS,
|
|
468
|
+
spec: specOf9("csplit"),
|
|
469
|
+
fn: (accessor, paths, texts, opts) => csplitGeneric(
|
|
470
|
+
paths,
|
|
471
|
+
texts,
|
|
472
|
+
opts,
|
|
473
|
+
(p) => stream(accessor, p),
|
|
474
|
+
(p, d) => writeBytes(accessor, p, d)
|
|
475
|
+
),
|
|
476
|
+
write: true
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
// src/commands/builtin/opfs/cut/cut.ts
|
|
480
|
+
import { ResourceName as ResourceName13, command as command10, cutGeneric, specOf as specOf10 } from "@struktoai/mirage-core";
|
|
481
|
+
var OPFS_CUT = command10({
|
|
482
|
+
name: "cut",
|
|
483
|
+
resource: ResourceName13.OPFS,
|
|
484
|
+
spec: specOf10("cut"),
|
|
485
|
+
fn: (accessor, paths, _texts, opts) => cutGeneric(paths, opts, (p) => stream(accessor, p))
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
// src/commands/builtin/opfs/diff.ts
|
|
489
|
+
import { ResourceName as ResourceName14, command as command11, diffGeneric, specOf as specOf11 } from "@struktoai/mirage-core";
|
|
490
|
+
var OPFS_DIFF = command11({
|
|
491
|
+
name: "diff",
|
|
492
|
+
resource: ResourceName14.OPFS,
|
|
493
|
+
spec: specOf11("diff"),
|
|
494
|
+
fn: (accessor, paths, _texts, opts) => diffGeneric(paths, opts, (p) => stream(accessor, p))
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
// src/commands/builtin/opfs/dirname.ts
|
|
498
|
+
import { ResourceName as ResourceName15, command as command12, specOf as specOf12, dirnameFn } from "@struktoai/mirage-core";
|
|
499
|
+
var OPFS_DIRNAME = command12({
|
|
500
|
+
name: "dirname",
|
|
501
|
+
resource: ResourceName15.OPFS,
|
|
502
|
+
spec: specOf12("dirname"),
|
|
503
|
+
fn: dirnameFn
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
// src/commands/builtin/opfs/du.ts
|
|
507
|
+
import { ResourceName as ResourceName16, command as command13, duGeneric, specOf as specOf13 } from "@struktoai/mirage-core";
|
|
508
|
+
|
|
509
|
+
// src/core/opfs/du.ts
|
|
510
|
+
async function walkSizes(dir) {
|
|
511
|
+
let total = 0;
|
|
512
|
+
for await (const [name, handle] of iterEntries(dir)) {
|
|
513
|
+
if (handle.kind === "file") {
|
|
514
|
+
try {
|
|
515
|
+
const fh = await dir.getFileHandle(name, { create: false });
|
|
516
|
+
const file = await fh.getFile();
|
|
517
|
+
total += file.size;
|
|
518
|
+
} catch {
|
|
519
|
+
}
|
|
520
|
+
} else {
|
|
521
|
+
try {
|
|
522
|
+
const child = await dir.getDirectoryHandle(name, { create: false });
|
|
523
|
+
total += await walkSizes(child);
|
|
524
|
+
} catch {
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
return total;
|
|
529
|
+
}
|
|
530
|
+
async function walkAll(dir, currentPath, entries) {
|
|
531
|
+
let total = 0;
|
|
532
|
+
for await (const [name, handle] of iterEntries(dir)) {
|
|
533
|
+
const childPath = currentPath === "/" ? `/${name}` : `${currentPath}/${name}`;
|
|
534
|
+
if (handle.kind === "file") {
|
|
535
|
+
try {
|
|
536
|
+
const fh = await dir.getFileHandle(name, { create: false });
|
|
537
|
+
const file = await fh.getFile();
|
|
538
|
+
entries.push([childPath, file.size]);
|
|
539
|
+
total += file.size;
|
|
540
|
+
} catch {
|
|
541
|
+
}
|
|
542
|
+
} else {
|
|
543
|
+
try {
|
|
544
|
+
const child = await dir.getDirectoryHandle(name, { create: false });
|
|
545
|
+
total += await walkAll(child, childPath, entries);
|
|
546
|
+
} catch {
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
return total;
|
|
551
|
+
}
|
|
552
|
+
async function sizeOfPath(root, virtual) {
|
|
553
|
+
try {
|
|
554
|
+
const [parentDir, name] = await resolveParentDirHandle(root, virtual, { create: false });
|
|
555
|
+
try {
|
|
556
|
+
const fh = await parentDir.getFileHandle(name, { create: false });
|
|
557
|
+
const file = await fh.getFile();
|
|
558
|
+
return file.size;
|
|
559
|
+
} catch (err) {
|
|
560
|
+
if (!isNotFound(err) && !(err instanceof DOMException && err.name === "TypeMismatchError")) {
|
|
561
|
+
throw err;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
const dir = await parentDir.getDirectoryHandle(name, { create: false });
|
|
565
|
+
return await walkSizes(dir);
|
|
566
|
+
} catch (err) {
|
|
567
|
+
if (isNotFound(err)) return 0;
|
|
568
|
+
if (err instanceof Error && err.message.startsWith("no parent directory")) {
|
|
569
|
+
try {
|
|
570
|
+
const rootDir = await resolveDirHandle(root, virtual, { create: false });
|
|
571
|
+
return await walkSizes(rootDir);
|
|
572
|
+
} catch {
|
|
573
|
+
return 0;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
throw err;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
async function du(accessor, p) {
|
|
580
|
+
return sizeOfPath(accessor.rootHandle, p.stripPrefix);
|
|
581
|
+
}
|
|
582
|
+
async function duAll(accessor, p) {
|
|
583
|
+
const root = accessor.rootHandle;
|
|
584
|
+
const virtual = norm(p.stripPrefix);
|
|
585
|
+
const entries = [];
|
|
586
|
+
try {
|
|
587
|
+
const [parentDir, name] = await resolveParentDirHandle(root, virtual, { create: false });
|
|
588
|
+
try {
|
|
589
|
+
const fh = await parentDir.getFileHandle(name, { create: false });
|
|
590
|
+
const file = await fh.getFile();
|
|
591
|
+
entries.push([virtual, file.size]);
|
|
592
|
+
return [entries, file.size];
|
|
593
|
+
} catch (err) {
|
|
594
|
+
if (!isNotFound(err) && !(err instanceof DOMException && err.name === "TypeMismatchError")) {
|
|
595
|
+
throw err;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
const dir = await parentDir.getDirectoryHandle(name, { create: false });
|
|
599
|
+
const total = await walkAll(dir, virtual, entries);
|
|
600
|
+
entries.sort((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0);
|
|
601
|
+
return [entries, total];
|
|
602
|
+
} catch (err) {
|
|
603
|
+
if (isNotFound(err)) return [entries, 0];
|
|
604
|
+
if (err instanceof Error && err.message.startsWith("no parent directory")) {
|
|
605
|
+
try {
|
|
606
|
+
const rootDir = await resolveDirHandle(root, virtual, { create: false });
|
|
607
|
+
const total = await walkAll(rootDir, virtual, entries);
|
|
608
|
+
entries.sort((a, b) => a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0);
|
|
609
|
+
return [entries, total];
|
|
610
|
+
} catch {
|
|
611
|
+
return [entries, 0];
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
throw err;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
// src/commands/builtin/opfs/du.ts
|
|
619
|
+
var OPFS_DU = command13({
|
|
620
|
+
name: "du",
|
|
621
|
+
resource: ResourceName16.OPFS,
|
|
622
|
+
spec: specOf13("du"),
|
|
623
|
+
fn: (accessor, paths, _texts, opts) => duGeneric(
|
|
624
|
+
paths,
|
|
625
|
+
opts,
|
|
626
|
+
(p) => du(accessor, p),
|
|
627
|
+
(p) => duAll(accessor, p)
|
|
628
|
+
)
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
// src/commands/builtin/opfs/expand.ts
|
|
632
|
+
import { ResourceName as ResourceName17, command as command14, specOf as specOf14, expandGeneric } from "@struktoai/mirage-core";
|
|
633
|
+
var OPFS_EXPAND = command14({
|
|
634
|
+
name: "expand",
|
|
635
|
+
resource: ResourceName17.OPFS,
|
|
636
|
+
spec: specOf14("expand"),
|
|
637
|
+
fn: (accessor, paths, _texts, opts) => expandGeneric(paths, opts, (p) => stream(accessor, p))
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
// src/commands/builtin/opfs/file/file.ts
|
|
641
|
+
import { ResourceName as ResourceName18, command as command15, fileGeneric, specOf as specOf15 } from "@struktoai/mirage-core";
|
|
642
|
+
var OPFS_FILE = command15({
|
|
643
|
+
name: "file",
|
|
644
|
+
resource: ResourceName18.OPFS,
|
|
645
|
+
spec: specOf15("file"),
|
|
646
|
+
fn: (accessor, paths, _texts, opts) => fileGeneric(
|
|
647
|
+
paths,
|
|
648
|
+
opts,
|
|
649
|
+
(p) => stat(accessor, p),
|
|
650
|
+
(p) => read(accessor, p)
|
|
651
|
+
)
|
|
652
|
+
});
|
|
653
|
+
|
|
654
|
+
// src/commands/builtin/opfs/find.ts
|
|
655
|
+
import { ResourceName as ResourceName19, command as command16, findGeneric, specOf as specOf16 } from "@struktoai/mirage-core";
|
|
656
|
+
var OPFS_FIND = command16({
|
|
657
|
+
name: "find",
|
|
658
|
+
resource: ResourceName19.OPFS,
|
|
659
|
+
spec: specOf16("find"),
|
|
660
|
+
fn: (accessor, paths, texts, opts) => findGeneric(paths, texts, opts, (root, options) => find(accessor, root, options))
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
// src/commands/builtin/opfs/fmt.ts
|
|
664
|
+
import {
|
|
665
|
+
ResourceName as ResourceName20,
|
|
666
|
+
command as command17,
|
|
667
|
+
fmtGeneric,
|
|
668
|
+
specOf as specOf17
|
|
669
|
+
} from "@struktoai/mirage-core";
|
|
670
|
+
async function fmtCommand(accessor, paths, _texts, opts) {
|
|
671
|
+
return fmtGeneric(paths, opts, (p) => stream(accessor, p));
|
|
672
|
+
}
|
|
673
|
+
var OPFS_FMT = command17({
|
|
674
|
+
name: "fmt",
|
|
675
|
+
resource: ResourceName20.OPFS,
|
|
676
|
+
spec: specOf17("fmt"),
|
|
677
|
+
fn: fmtCommand
|
|
678
|
+
});
|
|
679
|
+
|
|
680
|
+
// src/commands/builtin/opfs/fold.ts
|
|
681
|
+
import { ResourceName as ResourceName21, command as command18, specOf as specOf18, foldGeneric } from "@struktoai/mirage-core";
|
|
682
|
+
var OPFS_FOLD = command18({
|
|
683
|
+
name: "fold",
|
|
684
|
+
resource: ResourceName21.OPFS,
|
|
685
|
+
spec: specOf18("fold"),
|
|
686
|
+
fn: (accessor, paths, _texts, opts) => foldGeneric(paths, opts, (p) => stream(accessor, p))
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
// src/commands/builtin/opfs/grep/grep.ts
|
|
690
|
+
import { ResourceName as ResourceName22, command as command19, grepGeneric, prefixAggregate, specOf as specOf19 } from "@struktoai/mirage-core";
|
|
691
|
+
|
|
692
|
+
// src/core/opfs/readdir.ts
|
|
693
|
+
import { enotdir } from "@struktoai/mirage-core";
|
|
694
|
+
async function readdir(accessor, path) {
|
|
695
|
+
const root = accessor.rootHandle;
|
|
696
|
+
const virtual = path.pattern !== null ? path.directory : path.stripPrefix;
|
|
697
|
+
let dir;
|
|
698
|
+
try {
|
|
699
|
+
dir = await resolveDirHandle(root, virtual, { create: false });
|
|
700
|
+
} catch (err) {
|
|
701
|
+
if (isNotFound(err)) throw enotdir(path);
|
|
702
|
+
if (err instanceof DOMException && err.name === "TypeMismatchError") {
|
|
703
|
+
throw enotdir(path);
|
|
704
|
+
}
|
|
705
|
+
throw err;
|
|
706
|
+
}
|
|
707
|
+
const names = [];
|
|
708
|
+
for await (const [name] of iterEntries(dir)) {
|
|
709
|
+
names.push(name);
|
|
710
|
+
}
|
|
711
|
+
const base = norm(virtual);
|
|
712
|
+
const dirPrefix = base === "/" ? "/" : `${base}/`;
|
|
713
|
+
const mountPrefix = path.prefix;
|
|
714
|
+
return names.map((n) => `${mountPrefix}${dirPrefix}${n}`).sort();
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
// src/commands/builtin/opfs/grep/grep.ts
|
|
718
|
+
var OPFS_GREP = command19({
|
|
719
|
+
name: "grep",
|
|
720
|
+
resource: ResourceName22.OPFS,
|
|
721
|
+
spec: specOf19("grep"),
|
|
722
|
+
fn: (accessor, paths, texts, opts) => grepGeneric(
|
|
723
|
+
"grep",
|
|
724
|
+
paths,
|
|
725
|
+
texts,
|
|
726
|
+
opts,
|
|
727
|
+
(p) => stat(accessor, p),
|
|
728
|
+
(p) => readdir(accessor, p),
|
|
729
|
+
(p) => stream(accessor, p)
|
|
730
|
+
),
|
|
731
|
+
aggregate: prefixAggregate
|
|
732
|
+
});
|
|
733
|
+
|
|
734
|
+
// src/commands/builtin/opfs/gunzip.ts
|
|
735
|
+
import { ResourceName as ResourceName23, command as command20, specOf as specOf20, gunzipGeneric } from "@struktoai/mirage-core";
|
|
736
|
+
|
|
737
|
+
// src/core/opfs/unlink.ts
|
|
738
|
+
async function unlink(accessor, path) {
|
|
739
|
+
const root = accessor.rootHandle;
|
|
740
|
+
const virtual = path.stripPrefix;
|
|
741
|
+
let parentDir;
|
|
742
|
+
let name;
|
|
743
|
+
try {
|
|
744
|
+
;
|
|
745
|
+
[parentDir, name] = await resolveParentDirHandle(root, virtual, { create: false });
|
|
746
|
+
} catch (err) {
|
|
747
|
+
if (isNotFound(err)) return;
|
|
748
|
+
if (err instanceof Error && err.message.startsWith("no parent directory")) return;
|
|
749
|
+
throw err;
|
|
750
|
+
}
|
|
751
|
+
try {
|
|
752
|
+
await parentDir.removeEntry(name);
|
|
753
|
+
} catch (err) {
|
|
754
|
+
if (isNotFound(err)) return;
|
|
755
|
+
throw err;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
// src/commands/builtin/opfs/gunzip.ts
|
|
760
|
+
var OPFS_GUNZIP = command20({
|
|
761
|
+
name: "gunzip",
|
|
762
|
+
resource: ResourceName23.OPFS,
|
|
763
|
+
spec: specOf20("gunzip"),
|
|
764
|
+
fn: (accessor, paths, _texts, opts) => gunzipGeneric(
|
|
765
|
+
paths,
|
|
766
|
+
opts,
|
|
767
|
+
(p) => stream(accessor, p),
|
|
768
|
+
(p, d) => writeBytes(accessor, p, d),
|
|
769
|
+
(p) => unlink(accessor, p)
|
|
770
|
+
),
|
|
771
|
+
write: true
|
|
772
|
+
});
|
|
773
|
+
|
|
774
|
+
// src/commands/builtin/opfs/gzip.ts
|
|
775
|
+
import { ResourceName as ResourceName24, command as command21, specOf as specOf21, gzipGeneric } from "@struktoai/mirage-core";
|
|
776
|
+
var OPFS_GZIP = command21({
|
|
777
|
+
name: "gzip",
|
|
778
|
+
resource: ResourceName24.OPFS,
|
|
779
|
+
spec: specOf21("gzip"),
|
|
780
|
+
fn: (accessor, paths, _texts, opts) => gzipGeneric(
|
|
781
|
+
paths,
|
|
782
|
+
opts,
|
|
783
|
+
(p) => stream(accessor, p),
|
|
784
|
+
(p, d) => writeBytes(accessor, p, d),
|
|
785
|
+
(p) => unlink(accessor, p)
|
|
786
|
+
),
|
|
787
|
+
write: true
|
|
788
|
+
});
|
|
789
|
+
|
|
790
|
+
// src/commands/builtin/opfs/head/head.ts
|
|
791
|
+
import {
|
|
792
|
+
ResourceName as ResourceName25,
|
|
793
|
+
command as command22,
|
|
794
|
+
headGeneric,
|
|
795
|
+
headProvisionGeneric,
|
|
796
|
+
headerAggregate,
|
|
797
|
+
specOf as specOf22
|
|
798
|
+
} from "@struktoai/mirage-core";
|
|
799
|
+
var OPFS_HEAD = command22({
|
|
800
|
+
name: "head",
|
|
801
|
+
resource: ResourceName25.OPFS,
|
|
802
|
+
spec: specOf22("head"),
|
|
803
|
+
fn: (accessor, paths, texts, opts) => headGeneric(
|
|
804
|
+
paths,
|
|
805
|
+
texts,
|
|
806
|
+
opts,
|
|
807
|
+
(p) => stat(accessor, p),
|
|
808
|
+
(p) => stream(accessor, p)
|
|
809
|
+
),
|
|
810
|
+
provision: (accessor, paths, texts, opts) => headProvisionGeneric(paths, texts, opts, (p) => stat(accessor, p)),
|
|
811
|
+
aggregate: headerAggregate
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
// src/commands/builtin/opfs/iconv.ts
|
|
815
|
+
import { ResourceName as ResourceName26, command as command23, specOf as specOf23, iconvGeneric } from "@struktoai/mirage-core";
|
|
816
|
+
var OPFS_ICONV = command23({
|
|
817
|
+
name: "iconv",
|
|
818
|
+
resource: ResourceName26.OPFS,
|
|
819
|
+
spec: specOf23("iconv"),
|
|
820
|
+
fn: (accessor, paths, _texts, opts) => iconvGeneric(
|
|
821
|
+
paths,
|
|
822
|
+
opts,
|
|
823
|
+
(p) => stream(accessor, p),
|
|
824
|
+
(p, d) => writeBytes(accessor, p, d)
|
|
825
|
+
),
|
|
826
|
+
write: true
|
|
827
|
+
});
|
|
828
|
+
|
|
829
|
+
// src/commands/builtin/opfs/join.ts
|
|
830
|
+
import { ResourceName as ResourceName27, command as command24, specOf as specOf24, joinGeneric } from "@struktoai/mirage-core";
|
|
831
|
+
var OPFS_JOIN = command24({
|
|
832
|
+
name: "join",
|
|
833
|
+
resource: ResourceName27.OPFS,
|
|
834
|
+
spec: specOf24("join"),
|
|
835
|
+
fn: (accessor, paths, _texts, opts) => joinGeneric(paths, opts, (p) => stream(accessor, p))
|
|
836
|
+
});
|
|
837
|
+
|
|
838
|
+
// src/commands/builtin/opfs/jq.ts
|
|
839
|
+
import {
|
|
840
|
+
ResourceName as ResourceName28,
|
|
841
|
+
command as command25,
|
|
842
|
+
jqGeneric,
|
|
843
|
+
jqProvisionGeneric,
|
|
844
|
+
specOf as specOf25
|
|
845
|
+
} from "@struktoai/mirage-core";
|
|
846
|
+
var OPFS_JQ = command25({
|
|
847
|
+
name: "jq",
|
|
848
|
+
resource: ResourceName28.OPFS,
|
|
849
|
+
spec: specOf25("jq"),
|
|
850
|
+
fn: (accessor, paths, texts, opts) => jqGeneric(paths, texts, opts, (p) => stream(accessor, p)),
|
|
851
|
+
provision: (accessor, paths, texts, _opts) => jqProvisionGeneric(paths, texts, (p) => stat(accessor, p))
|
|
852
|
+
});
|
|
853
|
+
|
|
854
|
+
// src/commands/builtin/opfs/ln.ts
|
|
855
|
+
import {
|
|
856
|
+
IOResult as IOResult2,
|
|
857
|
+
ResourceName as ResourceName29,
|
|
858
|
+
command as command26,
|
|
859
|
+
materialize,
|
|
860
|
+
specOf as specOf26
|
|
861
|
+
} from "@struktoai/mirage-core";
|
|
862
|
+
|
|
863
|
+
// src/core/opfs/exists.ts
|
|
864
|
+
async function exists(accessor, path) {
|
|
865
|
+
const root = accessor.rootHandle;
|
|
866
|
+
const virtual = path.stripPrefix;
|
|
867
|
+
if (virtual === "/" || virtual === "") return true;
|
|
868
|
+
try {
|
|
869
|
+
const [parentDir, name] = await resolveParentDirHandle(root, virtual, { create: false });
|
|
870
|
+
try {
|
|
871
|
+
await parentDir.getFileHandle(name, { create: false });
|
|
872
|
+
return true;
|
|
873
|
+
} catch (err) {
|
|
874
|
+
if (!isNotFound(err) && !(err instanceof DOMException && err.name === "TypeMismatchError")) {
|
|
875
|
+
throw err;
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
try {
|
|
879
|
+
await parentDir.getDirectoryHandle(name, { create: false });
|
|
880
|
+
return true;
|
|
881
|
+
} catch (err) {
|
|
882
|
+
if (isNotFound(err) || err instanceof DOMException && err.name === "TypeMismatchError") {
|
|
883
|
+
return false;
|
|
884
|
+
}
|
|
885
|
+
throw err;
|
|
886
|
+
}
|
|
887
|
+
} catch (err) {
|
|
888
|
+
if (isNotFound(err)) return false;
|
|
889
|
+
if (err instanceof Error && err.message.startsWith("path escapes root")) return false;
|
|
890
|
+
if (err instanceof Error && err.message.startsWith("no parent directory")) {
|
|
891
|
+
try {
|
|
892
|
+
await resolveDirHandle(root, virtual, { create: false });
|
|
893
|
+
return true;
|
|
894
|
+
} catch {
|
|
895
|
+
return false;
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
throw err;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
// src/commands/builtin/opfs/ln.ts
|
|
903
|
+
var ENC = new TextEncoder();
|
|
904
|
+
async function lnCommand(accessor, paths, texts, opts) {
|
|
905
|
+
if (paths.length < 2) {
|
|
906
|
+
return [
|
|
907
|
+
null,
|
|
908
|
+
new IOResult2({ exitCode: 1, stderr: ENC.encode("ln: usage: ln [-s] [-f] source dest\n") })
|
|
909
|
+
];
|
|
910
|
+
}
|
|
911
|
+
const source = paths[0];
|
|
912
|
+
const dest = paths[1];
|
|
913
|
+
if (source === void 0 || dest === void 0) return [null, new IOResult2()];
|
|
914
|
+
if (opts.flags.n === true && await exists(accessor, dest)) {
|
|
915
|
+
return [null, new IOResult2()];
|
|
916
|
+
}
|
|
917
|
+
const data = await materialize(stream(accessor, source));
|
|
918
|
+
await writeBytes(accessor, dest, data);
|
|
919
|
+
const out = opts.flags.v === true ? ENC.encode(`'${source.original}' -> '${dest.original}'
|
|
920
|
+
`) : null;
|
|
921
|
+
return [out, new IOResult2({ writes: { [dest.stripPrefix]: data } })];
|
|
922
|
+
}
|
|
923
|
+
var OPFS_LN = command26({
|
|
924
|
+
name: "ln",
|
|
925
|
+
resource: ResourceName29.OPFS,
|
|
926
|
+
spec: specOf26("ln"),
|
|
927
|
+
fn: lnCommand,
|
|
928
|
+
write: true
|
|
929
|
+
});
|
|
930
|
+
|
|
931
|
+
// src/commands/builtin/opfs/look.ts
|
|
932
|
+
import { ResourceName as ResourceName30, command as command27, specOf as specOf27, lookGeneric } from "@struktoai/mirage-core";
|
|
933
|
+
var OPFS_LOOK = command27({
|
|
934
|
+
name: "look",
|
|
935
|
+
resource: ResourceName30.OPFS,
|
|
936
|
+
spec: specOf27("look"),
|
|
937
|
+
fn: (accessor, paths, texts, opts) => lookGeneric(paths, texts, opts, (p) => stream(accessor, p))
|
|
938
|
+
});
|
|
939
|
+
|
|
940
|
+
// src/commands/builtin/opfs/ls/ls.ts
|
|
941
|
+
import { ResourceName as ResourceName31, command as command28, lsGeneric, specOf as specOf28 } from "@struktoai/mirage-core";
|
|
942
|
+
var OPFS_LS = command28({
|
|
943
|
+
name: "ls",
|
|
944
|
+
resource: ResourceName31.OPFS,
|
|
945
|
+
spec: specOf28("ls"),
|
|
946
|
+
fn: (accessor, paths, _texts, opts) => lsGeneric(
|
|
947
|
+
paths,
|
|
948
|
+
opts,
|
|
949
|
+
(p) => readdir(accessor, p),
|
|
950
|
+
(p) => stat(accessor, p)
|
|
951
|
+
)
|
|
952
|
+
});
|
|
953
|
+
|
|
954
|
+
// src/commands/builtin/opfs/md5.ts
|
|
955
|
+
import { ResourceName as ResourceName32, command as command29, specOf as specOf29, md5Generic } from "@struktoai/mirage-core";
|
|
956
|
+
var OPFS_MD5 = command29({
|
|
957
|
+
name: "md5",
|
|
958
|
+
resource: ResourceName32.OPFS,
|
|
959
|
+
spec: specOf29("md5"),
|
|
960
|
+
fn: (accessor, paths, _texts, opts) => md5Generic(paths, opts, (p) => stream(accessor, p))
|
|
961
|
+
});
|
|
962
|
+
|
|
963
|
+
// src/commands/builtin/opfs/mkdir.ts
|
|
964
|
+
import {
|
|
965
|
+
IOResult as IOResult3,
|
|
966
|
+
ResourceName as ResourceName33,
|
|
967
|
+
command as command30,
|
|
968
|
+
specOf as specOf30
|
|
969
|
+
} from "@struktoai/mirage-core";
|
|
970
|
+
|
|
971
|
+
// src/core/opfs/mkdir.ts
|
|
972
|
+
async function mkdir(accessor, path, parents = false) {
|
|
973
|
+
const root = accessor.rootHandle;
|
|
974
|
+
const virtual = path.stripPrefix;
|
|
975
|
+
const segs = splitSegments(virtual);
|
|
976
|
+
if (segs.length === 0) return;
|
|
977
|
+
if (parents) {
|
|
978
|
+
await resolveDirHandle(root, virtual, { create: true });
|
|
979
|
+
return;
|
|
980
|
+
}
|
|
981
|
+
let parentDir;
|
|
982
|
+
let name;
|
|
983
|
+
try {
|
|
984
|
+
;
|
|
985
|
+
[parentDir, name] = await resolveParentDirHandle(root, virtual, { create: false });
|
|
986
|
+
} catch (err) {
|
|
987
|
+
if (isNotFound(err)) {
|
|
988
|
+
throw new Error(`parent directory does not exist: ${virtual}`);
|
|
989
|
+
}
|
|
990
|
+
throw err;
|
|
991
|
+
}
|
|
992
|
+
try {
|
|
993
|
+
await parentDir.getDirectoryHandle(name, { create: false });
|
|
994
|
+
return;
|
|
995
|
+
} catch (err) {
|
|
996
|
+
if (!isNotFound(err)) {
|
|
997
|
+
if (err instanceof DOMException && err.name === "TypeMismatchError") {
|
|
998
|
+
throw new Error(`path exists and is not a directory: ${virtual}`);
|
|
999
|
+
}
|
|
1000
|
+
throw err;
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
await parentDir.getDirectoryHandle(name, { create: true });
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
// src/commands/builtin/opfs/mkdir.ts
|
|
1007
|
+
async function mkdirCommand(accessor, paths, texts, opts) {
|
|
1008
|
+
const parents = opts.flags.p === true;
|
|
1009
|
+
if (paths.length === 0) {
|
|
1010
|
+
return [
|
|
1011
|
+
null,
|
|
1012
|
+
new IOResult3({
|
|
1013
|
+
exitCode: 1,
|
|
1014
|
+
stderr: new TextEncoder().encode("mkdir: missing operand\n")
|
|
1015
|
+
})
|
|
1016
|
+
];
|
|
1017
|
+
}
|
|
1018
|
+
for (const p of paths) {
|
|
1019
|
+
await mkdir(accessor, p, parents);
|
|
1020
|
+
}
|
|
1021
|
+
return [null, new IOResult3()];
|
|
1022
|
+
}
|
|
1023
|
+
var OPFS_MKDIR = command30({
|
|
1024
|
+
name: "mkdir",
|
|
1025
|
+
resource: ResourceName33.OPFS,
|
|
1026
|
+
spec: specOf30("mkdir"),
|
|
1027
|
+
fn: mkdirCommand,
|
|
1028
|
+
write: true
|
|
1029
|
+
});
|
|
1030
|
+
|
|
1031
|
+
// src/commands/builtin/opfs/mktemp.ts
|
|
1032
|
+
import { ResourceName as ResourceName34, command as command31, mktempGeneric, specOf as specOf31 } from "@struktoai/mirage-core";
|
|
1033
|
+
var OPFS_MKTEMP = command31({
|
|
1034
|
+
name: "mktemp",
|
|
1035
|
+
resource: ResourceName34.OPFS,
|
|
1036
|
+
spec: specOf31("mktemp"),
|
|
1037
|
+
fn: (accessor, _paths, texts, opts) => mktempGeneric(
|
|
1038
|
+
texts,
|
|
1039
|
+
opts,
|
|
1040
|
+
(p, parents) => mkdir(accessor, p, parents),
|
|
1041
|
+
(p, d) => writeBytes(accessor, p, d)
|
|
1042
|
+
),
|
|
1043
|
+
write: true
|
|
1044
|
+
});
|
|
1045
|
+
|
|
1046
|
+
// src/commands/builtin/opfs/mv.ts
|
|
1047
|
+
import {
|
|
1048
|
+
IOResult as IOResult4,
|
|
1049
|
+
ResourceName as ResourceName35,
|
|
1050
|
+
command as command32,
|
|
1051
|
+
mvGeneric,
|
|
1052
|
+
specOf as specOf32
|
|
1053
|
+
} from "@struktoai/mirage-core";
|
|
1054
|
+
|
|
1055
|
+
// src/core/opfs/rename.ts
|
|
1056
|
+
async function copyDirRecursive(root, srcPath, dstPath) {
|
|
1057
|
+
const srcDir = await resolveDirHandle(root, srcPath, { create: false });
|
|
1058
|
+
const dstDir = await resolveDirHandle(root, dstPath, { create: true });
|
|
1059
|
+
for await (const [name, handle] of iterEntries(srcDir)) {
|
|
1060
|
+
if (handle.kind === "file") {
|
|
1061
|
+
const srcFile = await srcDir.getFileHandle(name, { create: false });
|
|
1062
|
+
const file = await srcFile.getFile();
|
|
1063
|
+
const data = new Uint8Array(await file.arrayBuffer());
|
|
1064
|
+
const dstFile = await dstDir.getFileHandle(name, { create: true });
|
|
1065
|
+
const writable = await dstFile.createWritable();
|
|
1066
|
+
await writable.write(toWritableChunk(data));
|
|
1067
|
+
await writable.close();
|
|
1068
|
+
} else {
|
|
1069
|
+
await copyDirRecursive(root, `${srcPath}/${name}`, `${dstPath}/${name}`);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
async function rename(accessor, src, dst) {
|
|
1074
|
+
const root = accessor.rootHandle;
|
|
1075
|
+
const srcPath = src.stripPrefix;
|
|
1076
|
+
const dstPath = dst.stripPrefix;
|
|
1077
|
+
let srcParent;
|
|
1078
|
+
let srcName;
|
|
1079
|
+
try {
|
|
1080
|
+
;
|
|
1081
|
+
[srcParent, srcName] = await resolveParentDirHandle(root, srcPath, { create: false });
|
|
1082
|
+
} catch (err) {
|
|
1083
|
+
if (isNotFound(err)) throw new Error(`file or directory not found: ${srcPath}`);
|
|
1084
|
+
throw err;
|
|
1085
|
+
}
|
|
1086
|
+
let isFile = false;
|
|
1087
|
+
try {
|
|
1088
|
+
await srcParent.getFileHandle(srcName, { create: false });
|
|
1089
|
+
isFile = true;
|
|
1090
|
+
} catch (err) {
|
|
1091
|
+
if (!isNotFound(err) && !(err instanceof DOMException && err.name === "TypeMismatchError")) {
|
|
1092
|
+
throw err;
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
if (!isFile) {
|
|
1096
|
+
try {
|
|
1097
|
+
await srcParent.getDirectoryHandle(srcName, { create: false });
|
|
1098
|
+
} catch (err) {
|
|
1099
|
+
if (isNotFound(err)) throw new Error(`file or directory not found: ${srcPath}`);
|
|
1100
|
+
throw err;
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
if (isFile) {
|
|
1104
|
+
const srcFile = await resolveFileHandle(root, srcPath, { create: false });
|
|
1105
|
+
const file = await srcFile.getFile();
|
|
1106
|
+
const data = new Uint8Array(await file.arrayBuffer());
|
|
1107
|
+
const dstFile = await resolveFileHandle(root, dstPath, { create: true });
|
|
1108
|
+
const writable = await dstFile.createWritable();
|
|
1109
|
+
await writable.write(toWritableChunk(data));
|
|
1110
|
+
await writable.close();
|
|
1111
|
+
await srcParent.removeEntry(srcName);
|
|
1112
|
+
return;
|
|
1113
|
+
}
|
|
1114
|
+
await copyDirRecursive(root, srcPath, dstPath);
|
|
1115
|
+
await srcParent.removeEntry(srcName, { recursive: true });
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
// src/commands/builtin/opfs/mv.ts
|
|
1119
|
+
function mvCommand(accessor, paths, _texts, opts) {
|
|
1120
|
+
if (paths.length < 2) {
|
|
1121
|
+
return Promise.resolve([
|
|
1122
|
+
null,
|
|
1123
|
+
new IOResult4({ exitCode: 1, stderr: new TextEncoder().encode("mv: missing operand\n") })
|
|
1124
|
+
]);
|
|
1125
|
+
}
|
|
1126
|
+
return mvGeneric(
|
|
1127
|
+
paths,
|
|
1128
|
+
(src, target) => rename(accessor, src, target),
|
|
1129
|
+
(p) => stat(accessor, p),
|
|
1130
|
+
opts.flags.n === true,
|
|
1131
|
+
opts.flags.v === true,
|
|
1132
|
+
opts.index ?? void 0
|
|
1133
|
+
);
|
|
1134
|
+
}
|
|
1135
|
+
var OPFS_MV = command32({
|
|
1136
|
+
name: "mv",
|
|
1137
|
+
resource: ResourceName35.OPFS,
|
|
1138
|
+
spec: specOf32("mv"),
|
|
1139
|
+
fn: mvCommand,
|
|
1140
|
+
write: true
|
|
1141
|
+
});
|
|
1142
|
+
|
|
1143
|
+
// src/commands/builtin/opfs/nl.ts
|
|
1144
|
+
import { ResourceName as ResourceName36, command as command33, specOf as specOf33, nlGeneric } from "@struktoai/mirage-core";
|
|
1145
|
+
var OPFS_NL = command33({
|
|
1146
|
+
name: "nl",
|
|
1147
|
+
resource: ResourceName36.OPFS,
|
|
1148
|
+
spec: specOf33("nl"),
|
|
1149
|
+
fn: (accessor, paths, _texts, opts) => nlGeneric(paths, opts, (p) => stream(accessor, p))
|
|
1150
|
+
});
|
|
1151
|
+
|
|
1152
|
+
// src/commands/builtin/opfs/paste.ts
|
|
1153
|
+
import { ResourceName as ResourceName37, command as command34, specOf as specOf34, pasteGeneric } from "@struktoai/mirage-core";
|
|
1154
|
+
var OPFS_PASTE = command34({
|
|
1155
|
+
name: "paste",
|
|
1156
|
+
resource: ResourceName37.OPFS,
|
|
1157
|
+
spec: specOf34("paste"),
|
|
1158
|
+
fn: (accessor, paths, _texts, opts) => pasteGeneric(paths, opts, (p) => stream(accessor, p))
|
|
1159
|
+
});
|
|
1160
|
+
|
|
1161
|
+
// src/commands/builtin/opfs/patch.ts
|
|
1162
|
+
import { ResourceName as ResourceName38, command as command35, specOf as specOf35, patchGeneric } from "@struktoai/mirage-core";
|
|
1163
|
+
var OPFS_PATCH = command35({
|
|
1164
|
+
name: "patch",
|
|
1165
|
+
resource: ResourceName38.OPFS,
|
|
1166
|
+
spec: specOf35("patch"),
|
|
1167
|
+
fn: (accessor, paths, _texts, opts) => patchGeneric(
|
|
1168
|
+
paths,
|
|
1169
|
+
opts,
|
|
1170
|
+
(p) => stream(accessor, p),
|
|
1171
|
+
(p, d) => writeBytes(accessor, p, d)
|
|
1172
|
+
),
|
|
1173
|
+
write: true
|
|
1174
|
+
});
|
|
1175
|
+
|
|
1176
|
+
// src/commands/builtin/opfs/readlink.ts
|
|
1177
|
+
import {
|
|
1178
|
+
ResourceName as ResourceName39,
|
|
1179
|
+
command as command36,
|
|
1180
|
+
readlinkGeneric,
|
|
1181
|
+
specOf as specOf36
|
|
1182
|
+
} from "@struktoai/mirage-core";
|
|
1183
|
+
var OPFS_READLINK = command36({
|
|
1184
|
+
name: "readlink",
|
|
1185
|
+
resource: ResourceName39.OPFS,
|
|
1186
|
+
spec: specOf36("readlink"),
|
|
1187
|
+
fn: (_accessor, paths, texts, opts) => readlinkGeneric(paths, texts, opts)
|
|
1188
|
+
});
|
|
1189
|
+
|
|
1190
|
+
// src/commands/builtin/opfs/realpath.ts
|
|
1191
|
+
import { ResourceName as ResourceName40, command as command37, realpathGeneric, specOf as specOf37 } from "@struktoai/mirage-core";
|
|
1192
|
+
var OPFS_REALPATH = command37({
|
|
1193
|
+
name: "realpath",
|
|
1194
|
+
resource: ResourceName40.OPFS,
|
|
1195
|
+
spec: specOf37("realpath"),
|
|
1196
|
+
fn: (accessor, paths, texts, opts) => realpathGeneric(paths, texts, opts, (p) => stat(accessor, p))
|
|
1197
|
+
});
|
|
1198
|
+
|
|
1199
|
+
// src/commands/builtin/opfs/rev.ts
|
|
1200
|
+
import { ResourceName as ResourceName41, command as command38, specOf as specOf38, revGeneric } from "@struktoai/mirage-core";
|
|
1201
|
+
var OPFS_REV = command38({
|
|
1202
|
+
name: "rev",
|
|
1203
|
+
resource: ResourceName41.OPFS,
|
|
1204
|
+
spec: specOf38("rev"),
|
|
1205
|
+
fn: (accessor, paths, _texts, opts) => revGeneric(paths, opts, (p) => stream(accessor, p))
|
|
1206
|
+
});
|
|
1207
|
+
|
|
1208
|
+
// src/commands/builtin/opfs/rg.ts
|
|
1209
|
+
import { ResourceName as ResourceName42, command as command39, rgGeneric, specOf as specOf39 } from "@struktoai/mirage-core";
|
|
1210
|
+
var OPFS_RG = command39({
|
|
1211
|
+
name: "rg",
|
|
1212
|
+
resource: ResourceName42.OPFS,
|
|
1213
|
+
spec: specOf39("rg"),
|
|
1214
|
+
fn: (accessor, paths, texts, opts) => rgGeneric(
|
|
1215
|
+
paths,
|
|
1216
|
+
texts,
|
|
1217
|
+
opts,
|
|
1218
|
+
(p) => stat(accessor, p),
|
|
1219
|
+
(p) => readdir(accessor, p),
|
|
1220
|
+
(p) => stream(accessor, p)
|
|
1221
|
+
)
|
|
1222
|
+
});
|
|
1223
|
+
|
|
1224
|
+
// src/commands/builtin/opfs/rm.ts
|
|
1225
|
+
import {
|
|
1226
|
+
FileType as FileType2,
|
|
1227
|
+
IOResult as IOResult5,
|
|
1228
|
+
ResourceName as ResourceName43,
|
|
1229
|
+
command as command40,
|
|
1230
|
+
specOf as specOf40
|
|
1231
|
+
} from "@struktoai/mirage-core";
|
|
1232
|
+
|
|
1233
|
+
// src/core/opfs/rmdir.ts
|
|
1234
|
+
async function rmdir(accessor, path) {
|
|
1235
|
+
const root = accessor.rootHandle;
|
|
1236
|
+
const virtual = path.stripPrefix;
|
|
1237
|
+
let parentDir;
|
|
1238
|
+
let name;
|
|
1239
|
+
try {
|
|
1240
|
+
;
|
|
1241
|
+
[parentDir, name] = await resolveParentDirHandle(root, virtual, { create: false });
|
|
1242
|
+
} catch (err) {
|
|
1243
|
+
if (isNotFound(err)) return;
|
|
1244
|
+
if (err instanceof Error && err.message.startsWith("no parent directory")) return;
|
|
1245
|
+
throw err;
|
|
1246
|
+
}
|
|
1247
|
+
try {
|
|
1248
|
+
await parentDir.removeEntry(name, { recursive: false });
|
|
1249
|
+
} catch (err) {
|
|
1250
|
+
if (isNotFound(err)) return;
|
|
1251
|
+
throw err;
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
// src/core/opfs/rm.ts
|
|
1256
|
+
async function rmR(accessor, path) {
|
|
1257
|
+
const root = accessor.rootHandle;
|
|
1258
|
+
const virtual = path.stripPrefix;
|
|
1259
|
+
let parentDir;
|
|
1260
|
+
let name;
|
|
1261
|
+
try {
|
|
1262
|
+
;
|
|
1263
|
+
[parentDir, name] = await resolveParentDirHandle(root, virtual, { create: false });
|
|
1264
|
+
} catch (err) {
|
|
1265
|
+
if (isNotFound(err)) return;
|
|
1266
|
+
if (err instanceof Error && err.message.startsWith("no parent directory")) return;
|
|
1267
|
+
throw err;
|
|
1268
|
+
}
|
|
1269
|
+
try {
|
|
1270
|
+
await parentDir.removeEntry(name, { recursive: true });
|
|
1271
|
+
} catch (err) {
|
|
1272
|
+
if (isNotFound(err)) return;
|
|
1273
|
+
throw err;
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
// src/commands/builtin/opfs/rm.ts
|
|
1278
|
+
async function rmCommand(accessor, paths, texts, opts) {
|
|
1279
|
+
if (paths.length === 0) {
|
|
1280
|
+
return [
|
|
1281
|
+
null,
|
|
1282
|
+
new IOResult5({
|
|
1283
|
+
exitCode: 1,
|
|
1284
|
+
stderr: new TextEncoder().encode("rm: missing operand\n")
|
|
1285
|
+
})
|
|
1286
|
+
];
|
|
1287
|
+
}
|
|
1288
|
+
const recursive = opts.flags.r === true || opts.flags.R === true;
|
|
1289
|
+
for (const p of paths) {
|
|
1290
|
+
let isDir = false;
|
|
1291
|
+
try {
|
|
1292
|
+
const st = await stat(accessor, p);
|
|
1293
|
+
isDir = st.type === FileType2.DIRECTORY;
|
|
1294
|
+
} catch {
|
|
1295
|
+
isDir = false;
|
|
1296
|
+
}
|
|
1297
|
+
if (isDir) {
|
|
1298
|
+
if (recursive) {
|
|
1299
|
+
await rmR(accessor, p);
|
|
1300
|
+
} else {
|
|
1301
|
+
await rmdir(accessor, p);
|
|
1302
|
+
}
|
|
1303
|
+
} else {
|
|
1304
|
+
await unlink(accessor, p);
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
return [null, new IOResult5()];
|
|
1308
|
+
}
|
|
1309
|
+
var OPFS_RM = command40({
|
|
1310
|
+
name: "rm",
|
|
1311
|
+
resource: ResourceName43.OPFS,
|
|
1312
|
+
spec: specOf40("rm"),
|
|
1313
|
+
fn: rmCommand,
|
|
1314
|
+
write: true
|
|
1315
|
+
});
|
|
1316
|
+
|
|
1317
|
+
// src/commands/builtin/opfs/sed.ts
|
|
1318
|
+
import { ResourceName as ResourceName44, command as command41, specOf as specOf41, sedGeneric } from "@struktoai/mirage-core";
|
|
1319
|
+
var OPFS_SED = command41({
|
|
1320
|
+
name: "sed",
|
|
1321
|
+
resource: ResourceName44.OPFS,
|
|
1322
|
+
spec: specOf41("sed"),
|
|
1323
|
+
fn: (accessor, paths, texts, opts) => sedGeneric(
|
|
1324
|
+
paths,
|
|
1325
|
+
texts,
|
|
1326
|
+
opts,
|
|
1327
|
+
(p) => stream(accessor, p),
|
|
1328
|
+
(p, d) => writeBytes(accessor, p, d)
|
|
1329
|
+
)
|
|
1330
|
+
});
|
|
1331
|
+
|
|
1332
|
+
// src/commands/builtin/opfs/sha256sum.ts
|
|
1333
|
+
import { ResourceName as ResourceName45, command as command42, sha256sumGeneric, specOf as specOf42 } from "@struktoai/mirage-core";
|
|
1334
|
+
var OPFS_SHA256SUM = command42({
|
|
1335
|
+
name: "sha256sum",
|
|
1336
|
+
resource: ResourceName45.OPFS,
|
|
1337
|
+
spec: specOf42("sha256sum"),
|
|
1338
|
+
fn: (accessor, paths, _texts, opts) => sha256sumGeneric(paths, opts, (p) => stream(accessor, p))
|
|
1339
|
+
});
|
|
1340
|
+
|
|
1341
|
+
// src/commands/builtin/opfs/shuf.ts
|
|
1342
|
+
import { ResourceName as ResourceName46, command as command43, specOf as specOf43, shufGeneric } from "@struktoai/mirage-core";
|
|
1343
|
+
var OPFS_SHUF = command43({
|
|
1344
|
+
name: "shuf",
|
|
1345
|
+
resource: ResourceName46.OPFS,
|
|
1346
|
+
spec: specOf43("shuf"),
|
|
1347
|
+
fn: (accessor, paths, texts, opts) => shufGeneric(paths, texts, opts, (p) => stream(accessor, p))
|
|
1348
|
+
});
|
|
1349
|
+
|
|
1350
|
+
// src/commands/builtin/opfs/sort.ts
|
|
1351
|
+
import { ResourceName as ResourceName47, command as command44, specOf as specOf44, sortGeneric } from "@struktoai/mirage-core";
|
|
1352
|
+
var OPFS_SORT = command44({
|
|
1353
|
+
name: "sort",
|
|
1354
|
+
resource: ResourceName47.OPFS,
|
|
1355
|
+
spec: specOf44("sort"),
|
|
1356
|
+
fn: (accessor, paths, _texts, opts) => sortGeneric(paths, opts, (p) => stream(accessor, p))
|
|
1357
|
+
});
|
|
1358
|
+
|
|
1359
|
+
// src/commands/builtin/opfs/split.ts
|
|
1360
|
+
import { ResourceName as ResourceName48, command as command45, specOf as specOf45, splitGeneric } from "@struktoai/mirage-core";
|
|
1361
|
+
var OPFS_SPLIT = command45({
|
|
1362
|
+
name: "split",
|
|
1363
|
+
resource: ResourceName48.OPFS,
|
|
1364
|
+
spec: specOf45("split"),
|
|
1365
|
+
fn: (accessor, paths, _texts, opts) => splitGeneric(
|
|
1366
|
+
paths,
|
|
1367
|
+
opts,
|
|
1368
|
+
(p) => stream(accessor, p),
|
|
1369
|
+
(p, d) => writeBytes(accessor, p, d)
|
|
1370
|
+
),
|
|
1371
|
+
write: true
|
|
1372
|
+
});
|
|
1373
|
+
|
|
1374
|
+
// src/commands/builtin/opfs/stat/stat.ts
|
|
1375
|
+
import {
|
|
1376
|
+
ResourceName as ResourceName49,
|
|
1377
|
+
command as command46,
|
|
1378
|
+
specOf as specOf46,
|
|
1379
|
+
statGeneric,
|
|
1380
|
+
statProvisionGeneric
|
|
1381
|
+
} from "@struktoai/mirage-core";
|
|
1382
|
+
var OPFS_STAT = command46({
|
|
1383
|
+
name: "stat",
|
|
1384
|
+
resource: ResourceName49.OPFS,
|
|
1385
|
+
spec: specOf46("stat"),
|
|
1386
|
+
fn: (accessor, paths, _texts, opts) => statGeneric(paths, opts, (p) => stat(accessor, p)),
|
|
1387
|
+
provision: statProvisionGeneric
|
|
1388
|
+
});
|
|
1389
|
+
|
|
1390
|
+
// src/commands/builtin/opfs/strings.ts
|
|
1391
|
+
import { ResourceName as ResourceName50, command as command47, specOf as specOf47, stringsGeneric } from "@struktoai/mirage-core";
|
|
1392
|
+
var OPFS_STRINGS = command47({
|
|
1393
|
+
name: "strings",
|
|
1394
|
+
resource: ResourceName50.OPFS,
|
|
1395
|
+
spec: specOf47("strings"),
|
|
1396
|
+
fn: (accessor, paths, _texts, opts) => stringsGeneric(paths, opts, (p) => stream(accessor, p))
|
|
1397
|
+
});
|
|
1398
|
+
|
|
1399
|
+
// src/commands/builtin/opfs/tac.ts
|
|
1400
|
+
import { ResourceName as ResourceName51, command as command48, specOf as specOf48, tacGeneric } from "@struktoai/mirage-core";
|
|
1401
|
+
var OPFS_TAC = command48({
|
|
1402
|
+
name: "tac",
|
|
1403
|
+
resource: ResourceName51.OPFS,
|
|
1404
|
+
spec: specOf48("tac"),
|
|
1405
|
+
fn: (accessor, paths, _texts, opts) => tacGeneric(paths, opts, (p) => stream(accessor, p))
|
|
1406
|
+
});
|
|
1407
|
+
|
|
1408
|
+
// src/commands/builtin/opfs/tail/tail.ts
|
|
1409
|
+
import { ResourceName as ResourceName52, command as command49, headerAggregate as headerAggregate2, specOf as specOf49, tailGeneric } from "@struktoai/mirage-core";
|
|
1410
|
+
var OPFS_TAIL = command49({
|
|
1411
|
+
name: "tail",
|
|
1412
|
+
resource: ResourceName52.OPFS,
|
|
1413
|
+
spec: specOf49("tail"),
|
|
1414
|
+
fn: (accessor, paths, texts, opts) => tailGeneric(paths, texts, opts, (p) => stream(accessor, p)),
|
|
1415
|
+
aggregate: headerAggregate2
|
|
1416
|
+
});
|
|
1417
|
+
|
|
1418
|
+
// src/commands/builtin/opfs/tar.ts
|
|
1419
|
+
import { ResourceName as ResourceName53, command as command50, specOf as specOf50, tarGeneric } from "@struktoai/mirage-core";
|
|
1420
|
+
var OPFS_TAR = command50({
|
|
1421
|
+
name: "tar",
|
|
1422
|
+
resource: ResourceName53.OPFS,
|
|
1423
|
+
spec: specOf50("tar"),
|
|
1424
|
+
fn: (accessor, paths, _texts, opts) => tarGeneric(
|
|
1425
|
+
paths,
|
|
1426
|
+
opts,
|
|
1427
|
+
(p) => stream(accessor, p),
|
|
1428
|
+
(p, data) => writeBytes(accessor, p, data),
|
|
1429
|
+
(p) => mkdir(accessor, p)
|
|
1430
|
+
),
|
|
1431
|
+
write: true
|
|
1432
|
+
});
|
|
1433
|
+
|
|
1434
|
+
// src/commands/builtin/opfs/tee.ts
|
|
1435
|
+
import { ResourceName as ResourceName54, command as command51, specOf as specOf51, teeGeneric } from "@struktoai/mirage-core";
|
|
1436
|
+
var OPFS_TEE = command51({
|
|
1437
|
+
name: "tee",
|
|
1438
|
+
resource: ResourceName54.OPFS,
|
|
1439
|
+
spec: specOf51("tee"),
|
|
1440
|
+
fn: (accessor, paths, texts, opts) => teeGeneric(
|
|
1441
|
+
paths,
|
|
1442
|
+
texts,
|
|
1443
|
+
opts,
|
|
1444
|
+
(p) => stream(accessor, p),
|
|
1445
|
+
(p, d) => writeBytes(accessor, p, d)
|
|
1446
|
+
),
|
|
1447
|
+
write: true
|
|
1448
|
+
});
|
|
1449
|
+
|
|
1450
|
+
// src/commands/builtin/opfs/touch.ts
|
|
1451
|
+
import {
|
|
1452
|
+
IOResult as IOResult6,
|
|
1453
|
+
ResourceName as ResourceName55,
|
|
1454
|
+
command as command52,
|
|
1455
|
+
specOf as specOf52
|
|
1456
|
+
} from "@struktoai/mirage-core";
|
|
1457
|
+
var ENC2 = new TextEncoder();
|
|
1458
|
+
async function touchCommand(accessor, paths, texts, opts) {
|
|
1459
|
+
if (paths.length === 0) {
|
|
1460
|
+
return [null, new IOResult6({ exitCode: 1, stderr: ENC2.encode("touch: missing operand\n") })];
|
|
1461
|
+
}
|
|
1462
|
+
const createOnly = opts.flags.c === true;
|
|
1463
|
+
for (const p of paths) {
|
|
1464
|
+
if (createOnly) continue;
|
|
1465
|
+
if (!await exists(accessor, p)) {
|
|
1466
|
+
await writeBytes(accessor, p, new Uint8Array(0));
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
return [null, new IOResult6()];
|
|
1470
|
+
}
|
|
1471
|
+
var OPFS_TOUCH = command52({
|
|
1472
|
+
name: "touch",
|
|
1473
|
+
resource: ResourceName55.OPFS,
|
|
1474
|
+
spec: specOf52("touch"),
|
|
1475
|
+
fn: touchCommand,
|
|
1476
|
+
write: true
|
|
1477
|
+
});
|
|
1478
|
+
|
|
1479
|
+
// src/commands/builtin/opfs/tr.ts
|
|
1480
|
+
import { ResourceName as ResourceName56, command as command53, specOf as specOf53, trGeneric } from "@struktoai/mirage-core";
|
|
1481
|
+
var OPFS_TR = command53({
|
|
1482
|
+
name: "tr",
|
|
1483
|
+
resource: ResourceName56.OPFS,
|
|
1484
|
+
spec: specOf53("tr"),
|
|
1485
|
+
fn: (accessor, paths, texts, opts) => trGeneric(paths, texts, opts, (p) => stream(accessor, p))
|
|
1486
|
+
});
|
|
1487
|
+
|
|
1488
|
+
// src/commands/builtin/opfs/tree.ts
|
|
1489
|
+
import { ResourceName as ResourceName57, command as command54, specOf as specOf54, treeGeneric } from "@struktoai/mirage-core";
|
|
1490
|
+
var OPFS_TREE = command54({
|
|
1491
|
+
name: "tree",
|
|
1492
|
+
resource: ResourceName57.OPFS,
|
|
1493
|
+
spec: specOf54("tree"),
|
|
1494
|
+
fn: (accessor, paths, _texts, opts) => treeGeneric(
|
|
1495
|
+
paths,
|
|
1496
|
+
opts,
|
|
1497
|
+
(p) => readdir(accessor, p),
|
|
1498
|
+
(p) => stat(accessor, p)
|
|
1499
|
+
)
|
|
1500
|
+
});
|
|
1501
|
+
|
|
1502
|
+
// src/commands/builtin/opfs/tsort.ts
|
|
1503
|
+
import { ResourceName as ResourceName58, command as command55, specOf as specOf55, tsortGeneric } from "@struktoai/mirage-core";
|
|
1504
|
+
var OPFS_TSORT = command55({
|
|
1505
|
+
name: "tsort",
|
|
1506
|
+
resource: ResourceName58.OPFS,
|
|
1507
|
+
spec: specOf55("tsort"),
|
|
1508
|
+
fn: (accessor, paths, _texts, opts) => tsortGeneric(paths, opts, (p) => stream(accessor, p))
|
|
1509
|
+
});
|
|
1510
|
+
|
|
1511
|
+
// src/commands/builtin/opfs/unexpand.ts
|
|
1512
|
+
import { ResourceName as ResourceName59, command as command56, specOf as specOf56, unexpandGeneric } from "@struktoai/mirage-core";
|
|
1513
|
+
var OPFS_UNEXPAND = command56({
|
|
1514
|
+
name: "unexpand",
|
|
1515
|
+
resource: ResourceName59.OPFS,
|
|
1516
|
+
spec: specOf56("unexpand"),
|
|
1517
|
+
fn: (accessor, paths, _texts, opts) => unexpandGeneric(paths, opts, (p) => stream(accessor, p))
|
|
1518
|
+
});
|
|
1519
|
+
|
|
1520
|
+
// src/commands/builtin/opfs/uniq.ts
|
|
1521
|
+
import { ResourceName as ResourceName60, command as command57, specOf as specOf57, uniqGeneric } from "@struktoai/mirage-core";
|
|
1522
|
+
var OPFS_UNIQ = command57({
|
|
1523
|
+
name: "uniq",
|
|
1524
|
+
resource: ResourceName60.OPFS,
|
|
1525
|
+
spec: specOf57("uniq"),
|
|
1526
|
+
fn: (accessor, paths, _texts, opts) => uniqGeneric(paths, opts, (p) => stream(accessor, p))
|
|
1527
|
+
});
|
|
1528
|
+
|
|
1529
|
+
// src/commands/builtin/opfs/unzip.ts
|
|
1530
|
+
import { ResourceName as ResourceName61, command as command58, specOf as specOf58, unzipGeneric } from "@struktoai/mirage-core";
|
|
1531
|
+
var OPFS_UNZIP = command58({
|
|
1532
|
+
name: "unzip",
|
|
1533
|
+
resource: ResourceName61.OPFS,
|
|
1534
|
+
spec: specOf58("unzip"),
|
|
1535
|
+
fn: (accessor, paths, _texts, opts) => unzipGeneric(
|
|
1536
|
+
paths,
|
|
1537
|
+
opts,
|
|
1538
|
+
(p) => stream(accessor, p),
|
|
1539
|
+
(p, d) => writeBytes(accessor, p, d),
|
|
1540
|
+
(p, parents) => mkdir(accessor, p, parents)
|
|
1541
|
+
),
|
|
1542
|
+
write: true
|
|
1543
|
+
});
|
|
1544
|
+
|
|
1545
|
+
// src/commands/builtin/opfs/wc/wc.ts
|
|
1546
|
+
import { ResourceName as ResourceName62, command as command59, specOf as specOf59, wcAggregate, wcGeneric } from "@struktoai/mirage-core";
|
|
1547
|
+
var OPFS_WC = command59({
|
|
1548
|
+
name: "wc",
|
|
1549
|
+
resource: ResourceName62.OPFS,
|
|
1550
|
+
spec: specOf59("wc"),
|
|
1551
|
+
fn: (accessor, paths, texts, opts) => wcGeneric(paths, texts, opts, (p) => stream(accessor, p)),
|
|
1552
|
+
aggregate: wcAggregate
|
|
1553
|
+
});
|
|
1554
|
+
|
|
1555
|
+
// src/commands/builtin/opfs/xxd.ts
|
|
1556
|
+
import { ResourceName as ResourceName63, command as command60, specOf as specOf60, xxdGeneric } from "@struktoai/mirage-core";
|
|
1557
|
+
var OPFS_XXD = command60({
|
|
1558
|
+
name: "xxd",
|
|
1559
|
+
resource: ResourceName63.OPFS,
|
|
1560
|
+
spec: specOf60("xxd"),
|
|
1561
|
+
fn: (accessor, paths, _texts, opts) => xxdGeneric(paths, opts, (p) => stream(accessor, p))
|
|
1562
|
+
});
|
|
1563
|
+
|
|
1564
|
+
// src/commands/builtin/opfs/zcat.ts
|
|
1565
|
+
import { ResourceName as ResourceName64, command as command61, specOf as specOf61, zcatGeneric } from "@struktoai/mirage-core";
|
|
1566
|
+
var OPFS_ZCAT = command61({
|
|
1567
|
+
name: "zcat",
|
|
1568
|
+
resource: ResourceName64.OPFS,
|
|
1569
|
+
spec: specOf61("zcat"),
|
|
1570
|
+
fn: (accessor, paths, _texts, opts) => zcatGeneric(paths, opts, (p) => stream(accessor, p))
|
|
1571
|
+
});
|
|
1572
|
+
|
|
1573
|
+
// src/commands/builtin/opfs/zgrep.ts
|
|
1574
|
+
import { ResourceName as ResourceName65, command as command62, specOf as specOf62, zgrepGeneric } from "@struktoai/mirage-core";
|
|
1575
|
+
var OPFS_ZGREP = command62({
|
|
1576
|
+
name: "zgrep",
|
|
1577
|
+
resource: ResourceName65.OPFS,
|
|
1578
|
+
spec: specOf62("zgrep"),
|
|
1579
|
+
fn: (accessor, paths, texts, opts) => zgrepGeneric(paths, texts, opts, (p) => stream(accessor, p))
|
|
1580
|
+
});
|
|
1581
|
+
|
|
1582
|
+
// src/commands/builtin/opfs/zip_cmd.ts
|
|
1583
|
+
import { ResourceName as ResourceName66, command as command63, specOf as specOf63, zipGeneric } from "@struktoai/mirage-core";
|
|
1584
|
+
var OPFS_ZIP = command63({
|
|
1585
|
+
name: "zip",
|
|
1586
|
+
resource: ResourceName66.OPFS,
|
|
1587
|
+
spec: specOf63("zip"),
|
|
1588
|
+
fn: (accessor, paths, _texts, opts) => zipGeneric(
|
|
1589
|
+
paths,
|
|
1590
|
+
opts,
|
|
1591
|
+
(p) => stream(accessor, p),
|
|
1592
|
+
(p, d) => writeBytes(accessor, p, d)
|
|
1593
|
+
),
|
|
1594
|
+
write: true
|
|
1595
|
+
});
|
|
1596
|
+
|
|
1597
|
+
// src/commands/builtin/opfs/index.ts
|
|
1598
|
+
var OPFS_COMMANDS = [
|
|
1599
|
+
...makeFiletypeCommands({
|
|
1600
|
+
resource: ResourceName67.OPFS,
|
|
1601
|
+
readBytes: read,
|
|
1602
|
+
statEntry: stat
|
|
1603
|
+
}),
|
|
1604
|
+
...OPFS_AWK,
|
|
1605
|
+
...OPFS_BASE64,
|
|
1606
|
+
...OPFS_BASENAME,
|
|
1607
|
+
...OPFS_CAT,
|
|
1608
|
+
...OPFS_CMP,
|
|
1609
|
+
...OPFS_COLUMN,
|
|
1610
|
+
...OPFS_COMM,
|
|
1611
|
+
...OPFS_CP,
|
|
1612
|
+
...OPFS_CSPLIT,
|
|
1613
|
+
...OPFS_CUT,
|
|
1614
|
+
...OPFS_DIFF,
|
|
1615
|
+
...OPFS_DIRNAME,
|
|
1616
|
+
...OPFS_DU,
|
|
1617
|
+
...OPFS_EXPAND,
|
|
1618
|
+
...OPFS_FILE,
|
|
1619
|
+
...OPFS_FIND,
|
|
1620
|
+
...OPFS_FMT,
|
|
1621
|
+
...OPFS_FOLD,
|
|
1622
|
+
...OPFS_GREP,
|
|
1623
|
+
...OPFS_GUNZIP,
|
|
1624
|
+
...OPFS_GZIP,
|
|
1625
|
+
...OPFS_HEAD,
|
|
1626
|
+
...OPFS_ICONV,
|
|
1627
|
+
...OPFS_JOIN,
|
|
1628
|
+
...OPFS_JQ,
|
|
1629
|
+
...OPFS_LN,
|
|
1630
|
+
...OPFS_LOOK,
|
|
1631
|
+
...OPFS_LS,
|
|
1632
|
+
...OPFS_MD5,
|
|
1633
|
+
...OPFS_MKDIR,
|
|
1634
|
+
...OPFS_MKTEMP,
|
|
1635
|
+
...OPFS_MV,
|
|
1636
|
+
...OPFS_NL,
|
|
1637
|
+
...OPFS_PASTE,
|
|
1638
|
+
...OPFS_PATCH,
|
|
1639
|
+
...OPFS_READLINK,
|
|
1640
|
+
...OPFS_REALPATH,
|
|
1641
|
+
...OPFS_REV,
|
|
1642
|
+
...OPFS_RG,
|
|
1643
|
+
...OPFS_RM,
|
|
1644
|
+
...OPFS_SED,
|
|
1645
|
+
...OPFS_SHA256SUM,
|
|
1646
|
+
...OPFS_SHUF,
|
|
1647
|
+
...OPFS_SORT,
|
|
1648
|
+
...OPFS_SPLIT,
|
|
1649
|
+
...OPFS_STAT,
|
|
1650
|
+
...OPFS_STRINGS,
|
|
1651
|
+
...OPFS_TAC,
|
|
1652
|
+
...OPFS_TAIL,
|
|
1653
|
+
...OPFS_TAR,
|
|
1654
|
+
...OPFS_TEE,
|
|
1655
|
+
...OPFS_TOUCH,
|
|
1656
|
+
...OPFS_TR,
|
|
1657
|
+
...OPFS_TREE,
|
|
1658
|
+
...OPFS_TSORT,
|
|
1659
|
+
...OPFS_UNEXPAND,
|
|
1660
|
+
...OPFS_UNIQ,
|
|
1661
|
+
...OPFS_UNZIP,
|
|
1662
|
+
...OPFS_WC,
|
|
1663
|
+
...OPFS_XXD,
|
|
1664
|
+
...OPFS_ZCAT,
|
|
1665
|
+
...OPFS_ZGREP,
|
|
1666
|
+
...OPFS_ZIP
|
|
1667
|
+
];
|
|
1668
|
+
|
|
1669
|
+
// src/core/opfs/append.ts
|
|
1670
|
+
import { record as record3, ResourceName as ResourceName68 } from "@struktoai/mirage-core";
|
|
1671
|
+
async function appendBytes(accessor, p, data) {
|
|
1672
|
+
const root = accessor.rootHandle;
|
|
1673
|
+
const start = performance.now();
|
|
1674
|
+
const virtual = p.stripPrefix;
|
|
1675
|
+
const handle = await resolveFileHandle(root, virtual, { create: true });
|
|
1676
|
+
const existing = await handle.getFile();
|
|
1677
|
+
const existingBytes = new Uint8Array(await existing.arrayBuffer());
|
|
1678
|
+
const merged = new Uint8Array(existingBytes.byteLength + data.byteLength);
|
|
1679
|
+
merged.set(existingBytes, 0);
|
|
1680
|
+
merged.set(data, existingBytes.byteLength);
|
|
1681
|
+
const writable = await handle.createWritable();
|
|
1682
|
+
await writable.write(toWritableChunk(merged));
|
|
1683
|
+
await writable.close();
|
|
1684
|
+
record3("append", virtual, ResourceName68.OPFS, data.byteLength, start);
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
// src/core/opfs/glob.ts
|
|
1688
|
+
import { PathSpec } from "@struktoai/mirage-core";
|
|
1689
|
+
|
|
1690
|
+
// src/core/opfs/constants.ts
|
|
1691
|
+
var SCOPE_ERROR = 5e4;
|
|
1692
|
+
|
|
1693
|
+
// src/core/opfs/glob.ts
|
|
1694
|
+
import { fnmatch } from "@struktoai/mirage-core";
|
|
1695
|
+
import { gnuBasename as gnuBasename2 } from "@struktoai/mirage-core";
|
|
1696
|
+
async function resolveGlob(accessor, paths) {
|
|
1697
|
+
const result = [];
|
|
1698
|
+
for (const p of paths) {
|
|
1699
|
+
if (p.resolved) {
|
|
1700
|
+
result.push(p);
|
|
1701
|
+
} else if (p.pattern !== null) {
|
|
1702
|
+
const dirSpec = new PathSpec({
|
|
1703
|
+
original: p.directory,
|
|
1704
|
+
directory: p.directory,
|
|
1705
|
+
resolved: true,
|
|
1706
|
+
prefix: p.prefix
|
|
1707
|
+
});
|
|
1708
|
+
const entries = await readdir(accessor, dirSpec);
|
|
1709
|
+
const matched = [];
|
|
1710
|
+
for (const e of entries) {
|
|
1711
|
+
if (fnmatch(gnuBasename2(e), p.pattern)) {
|
|
1712
|
+
matched.push(
|
|
1713
|
+
new PathSpec({
|
|
1714
|
+
original: e,
|
|
1715
|
+
directory: p.directory,
|
|
1716
|
+
resolved: true,
|
|
1717
|
+
prefix: p.prefix
|
|
1718
|
+
})
|
|
1719
|
+
);
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
if (matched.length > SCOPE_ERROR) matched.length = SCOPE_ERROR;
|
|
1723
|
+
result.push(...matched);
|
|
1724
|
+
} else {
|
|
1725
|
+
result.push(p);
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
return result;
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
// src/core/opfs/truncate.ts
|
|
1732
|
+
async function truncate(accessor, path, length) {
|
|
1733
|
+
const root = accessor.rootHandle;
|
|
1734
|
+
const virtual = path.stripPrefix;
|
|
1735
|
+
let handle;
|
|
1736
|
+
let existing;
|
|
1737
|
+
try {
|
|
1738
|
+
handle = await resolveFileHandle(root, virtual, { create: false });
|
|
1739
|
+
const file = await handle.getFile();
|
|
1740
|
+
existing = new Uint8Array(await file.arrayBuffer());
|
|
1741
|
+
} catch (err) {
|
|
1742
|
+
if (isNotFound(err)) {
|
|
1743
|
+
handle = await resolveFileHandle(root, virtual, { create: true });
|
|
1744
|
+
existing = new Uint8Array();
|
|
1745
|
+
} else {
|
|
1746
|
+
throw err;
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
const out = new Uint8Array(length);
|
|
1750
|
+
out.set(existing.subarray(0, Math.min(existing.byteLength, length)));
|
|
1751
|
+
const writable = await handle.createWritable();
|
|
1752
|
+
await writable.write(toWritableChunk(out));
|
|
1753
|
+
await writable.close();
|
|
1754
|
+
}
|
|
1755
|
+
|
|
1756
|
+
// src/ops/opfs/append.ts
|
|
1757
|
+
import { ResourceName as ResourceName69 } from "@struktoai/mirage-core";
|
|
1758
|
+
var appendOp = {
|
|
1759
|
+
name: "append",
|
|
1760
|
+
resource: ResourceName69.OPFS,
|
|
1761
|
+
filetype: null,
|
|
1762
|
+
write: true,
|
|
1763
|
+
fn: (accessor, path, args) => {
|
|
1764
|
+
const data = args[0];
|
|
1765
|
+
if (!(data instanceof Uint8Array)) {
|
|
1766
|
+
throw new TypeError("append op requires a Uint8Array as the first arg");
|
|
1767
|
+
}
|
|
1768
|
+
return appendBytes(accessor, path, data);
|
|
1769
|
+
}
|
|
1770
|
+
};
|
|
1771
|
+
|
|
1772
|
+
// src/ops/opfs/create.ts
|
|
1773
|
+
import { ResourceName as ResourceName70 } from "@struktoai/mirage-core";
|
|
1774
|
+
|
|
1775
|
+
// src/core/opfs/create.ts
|
|
1776
|
+
function create(accessor, path) {
|
|
1777
|
+
return writeBytes(accessor, path, new Uint8Array());
|
|
1778
|
+
}
|
|
1779
|
+
|
|
1780
|
+
// src/ops/opfs/create.ts
|
|
1781
|
+
var createOp = {
|
|
1782
|
+
name: "create",
|
|
1783
|
+
resource: ResourceName70.OPFS,
|
|
1784
|
+
filetype: null,
|
|
1785
|
+
write: true,
|
|
1786
|
+
fn: (accessor, path) => create(accessor, path)
|
|
1787
|
+
};
|
|
1788
|
+
|
|
1789
|
+
// src/ops/opfs/mkdir.ts
|
|
1790
|
+
import { ResourceName as ResourceName71 } from "@struktoai/mirage-core";
|
|
1791
|
+
var mkdirOp = {
|
|
1792
|
+
name: "mkdir",
|
|
1793
|
+
resource: ResourceName71.OPFS,
|
|
1794
|
+
filetype: null,
|
|
1795
|
+
write: true,
|
|
1796
|
+
fn: (accessor, path) => mkdir(accessor, path, true)
|
|
1797
|
+
};
|
|
1798
|
+
|
|
1799
|
+
// src/ops/opfs/read.ts
|
|
1800
|
+
import { ResourceName as ResourceName72 } from "@struktoai/mirage-core";
|
|
1801
|
+
var readOp = {
|
|
1802
|
+
name: "read",
|
|
1803
|
+
resource: ResourceName72.OPFS,
|
|
1804
|
+
filetype: null,
|
|
1805
|
+
write: false,
|
|
1806
|
+
fn: (accessor, path) => read(accessor, path)
|
|
1807
|
+
};
|
|
1808
|
+
|
|
1809
|
+
// src/ops/opfs/readdir.ts
|
|
1810
|
+
import { ResourceName as ResourceName73 } from "@struktoai/mirage-core";
|
|
1811
|
+
var readdirOp = {
|
|
1812
|
+
name: "readdir",
|
|
1813
|
+
resource: ResourceName73.OPFS,
|
|
1814
|
+
filetype: null,
|
|
1815
|
+
write: false,
|
|
1816
|
+
fn: (accessor, path) => readdir(accessor, path)
|
|
1817
|
+
};
|
|
1818
|
+
|
|
1819
|
+
// src/ops/opfs/rename.ts
|
|
1820
|
+
import { ResourceName as ResourceName74 } from "@struktoai/mirage-core";
|
|
1821
|
+
var renameOp = {
|
|
1822
|
+
name: "rename",
|
|
1823
|
+
resource: ResourceName74.OPFS,
|
|
1824
|
+
filetype: null,
|
|
1825
|
+
write: true,
|
|
1826
|
+
fn: (accessor, path, args) => {
|
|
1827
|
+
const dst = args[0];
|
|
1828
|
+
if (dst === void 0 || dst === null || typeof dst !== "object" || !("original" in dst)) {
|
|
1829
|
+
throw new TypeError("rename op requires a PathSpec destination as the first arg");
|
|
1830
|
+
}
|
|
1831
|
+
return rename(accessor, path, dst);
|
|
1832
|
+
}
|
|
1833
|
+
};
|
|
1834
|
+
|
|
1835
|
+
// src/ops/opfs/rmdir.ts
|
|
1836
|
+
import { ResourceName as ResourceName75 } from "@struktoai/mirage-core";
|
|
1837
|
+
var rmdirOp = {
|
|
1838
|
+
name: "rmdir",
|
|
1839
|
+
resource: ResourceName75.OPFS,
|
|
1840
|
+
filetype: null,
|
|
1841
|
+
write: true,
|
|
1842
|
+
fn: (accessor, path) => rmdir(accessor, path)
|
|
1843
|
+
};
|
|
1844
|
+
|
|
1845
|
+
// src/ops/opfs/stat.ts
|
|
1846
|
+
import { ResourceName as ResourceName76 } from "@struktoai/mirage-core";
|
|
1847
|
+
var statOp = {
|
|
1848
|
+
name: "stat",
|
|
1849
|
+
resource: ResourceName76.OPFS,
|
|
1850
|
+
filetype: null,
|
|
1851
|
+
write: false,
|
|
1852
|
+
fn: (accessor, path) => stat(accessor, path)
|
|
1853
|
+
};
|
|
1854
|
+
|
|
1855
|
+
// src/ops/opfs/truncate.ts
|
|
1856
|
+
import { ResourceName as ResourceName77 } from "@struktoai/mirage-core";
|
|
1857
|
+
var truncateOp = {
|
|
1858
|
+
name: "truncate",
|
|
1859
|
+
resource: ResourceName77.OPFS,
|
|
1860
|
+
filetype: null,
|
|
1861
|
+
write: true,
|
|
1862
|
+
fn: (accessor, path, args) => {
|
|
1863
|
+
const length = args[0];
|
|
1864
|
+
if (typeof length !== "number") {
|
|
1865
|
+
throw new TypeError("truncate op requires a number length as the first arg");
|
|
1866
|
+
}
|
|
1867
|
+
return truncate(accessor, path, length);
|
|
1868
|
+
}
|
|
1869
|
+
};
|
|
1870
|
+
|
|
1871
|
+
// src/ops/opfs/unlink.ts
|
|
1872
|
+
import { ResourceName as ResourceName78 } from "@struktoai/mirage-core";
|
|
1873
|
+
var unlinkOp = {
|
|
1874
|
+
name: "unlink",
|
|
1875
|
+
resource: ResourceName78.OPFS,
|
|
1876
|
+
filetype: null,
|
|
1877
|
+
write: true,
|
|
1878
|
+
fn: (accessor, path) => unlink(accessor, path)
|
|
1879
|
+
};
|
|
1880
|
+
|
|
1881
|
+
// src/ops/opfs/write.ts
|
|
1882
|
+
import { ResourceName as ResourceName79 } from "@struktoai/mirage-core";
|
|
1883
|
+
var writeOp = {
|
|
1884
|
+
name: "write",
|
|
1885
|
+
resource: ResourceName79.OPFS,
|
|
1886
|
+
filetype: null,
|
|
1887
|
+
write: true,
|
|
1888
|
+
fn: (accessor, path, args) => {
|
|
1889
|
+
const data = args[0];
|
|
1890
|
+
if (!(data instanceof Uint8Array)) {
|
|
1891
|
+
throw new TypeError("write op requires a Uint8Array as the first arg");
|
|
1892
|
+
}
|
|
1893
|
+
return writeBytes(accessor, path, data);
|
|
1894
|
+
}
|
|
1895
|
+
};
|
|
1896
|
+
|
|
1897
|
+
// src/ops/opfs/index.ts
|
|
1898
|
+
var OPFS_OPS = [
|
|
1899
|
+
appendOp,
|
|
1900
|
+
createOp,
|
|
1901
|
+
mkdirOp,
|
|
1902
|
+
readOp,
|
|
1903
|
+
readdirOp,
|
|
1904
|
+
renameOp,
|
|
1905
|
+
rmdirOp,
|
|
1906
|
+
statOp,
|
|
1907
|
+
truncateOp,
|
|
1908
|
+
unlinkOp,
|
|
1909
|
+
writeOp
|
|
1910
|
+
];
|
|
1911
|
+
|
|
1912
|
+
// src/resource/opfs/prompt.ts
|
|
1913
|
+
var OPFS_PROMPT = `{prefix}
|
|
1914
|
+
Browser Origin Private File System. Persistent per-origin storage that survives page reloads.
|
|
1915
|
+
Standard commands: ls, cat, head, tail, grep, wc, find, tree, mkdir, touch, cp, mv, rm, tee.`;
|
|
1916
|
+
|
|
1917
|
+
// src/resource/opfs/opfs.ts
|
|
1918
|
+
async function walkFiles(dir, currentPath, files) {
|
|
1919
|
+
for await (const [name, handle] of iterEntries(dir)) {
|
|
1920
|
+
const childPath = currentPath === "" ? name : `${currentPath}/${name}`;
|
|
1921
|
+
if (handle.kind === "file") {
|
|
1922
|
+
const fh = await dir.getFileHandle(name, { create: false });
|
|
1923
|
+
const file = await fh.getFile();
|
|
1924
|
+
files[childPath] = new Uint8Array(await file.arrayBuffer());
|
|
1925
|
+
} else {
|
|
1926
|
+
const child = await dir.getDirectoryHandle(name, { create: false });
|
|
1927
|
+
await walkFiles(child, childPath, files);
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
async function walkDirs(dir, currentPath, dirs) {
|
|
1932
|
+
for await (const [name, handle] of iterEntries(dir)) {
|
|
1933
|
+
if (handle.kind !== "directory") continue;
|
|
1934
|
+
const childPath = currentPath === "" ? `/${name}` : `${currentPath}/${name}`;
|
|
1935
|
+
dirs.push(childPath);
|
|
1936
|
+
const child = await dir.getDirectoryHandle(name, { create: false });
|
|
1937
|
+
await walkDirs(child, childPath, dirs);
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
async function splitAndCreate(root, relativePath) {
|
|
1941
|
+
let handle = root;
|
|
1942
|
+
for (const seg of relativePath.split("/")) {
|
|
1943
|
+
if (seg === "" || seg === ".") continue;
|
|
1944
|
+
handle = await handle.getDirectoryHandle(seg, { create: true });
|
|
1945
|
+
}
|
|
1946
|
+
return handle;
|
|
1947
|
+
}
|
|
1948
|
+
var OPFSResource = class {
|
|
1949
|
+
kind = ResourceName80.OPFS;
|
|
1950
|
+
prompt = OPFS_PROMPT;
|
|
1951
|
+
rootName;
|
|
1952
|
+
accessor;
|
|
1953
|
+
rootHandle = null;
|
|
1954
|
+
openPromise = null;
|
|
1955
|
+
constructor(options = {}) {
|
|
1956
|
+
this.rootName = options.root ?? "";
|
|
1957
|
+
this.accessor = new OPFSAccessor(this);
|
|
1958
|
+
}
|
|
1959
|
+
open() {
|
|
1960
|
+
return this.ensureOpen().then(() => void 0);
|
|
1961
|
+
}
|
|
1962
|
+
close() {
|
|
1963
|
+
this.rootHandle = null;
|
|
1964
|
+
this.openPromise = null;
|
|
1965
|
+
return Promise.resolve();
|
|
1966
|
+
}
|
|
1967
|
+
/**
|
|
1968
|
+
* Lazily resolve to a usable root handle. Memoizes `navigator.storage`
|
|
1969
|
+
* traversal so the resource self-initializes on first method call without
|
|
1970
|
+
* relying on an external orchestrator.
|
|
1971
|
+
*/
|
|
1972
|
+
ensureOpen() {
|
|
1973
|
+
if (this.rootHandle !== null) return Promise.resolve(this.rootHandle);
|
|
1974
|
+
this.openPromise ??= (async () => {
|
|
1975
|
+
const origin = await navigator.storage.getDirectory();
|
|
1976
|
+
let handle = origin;
|
|
1977
|
+
for (const seg of this.rootName.split("/")) {
|
|
1978
|
+
if (seg === "" || seg === ".") continue;
|
|
1979
|
+
handle = await handle.getDirectoryHandle(seg, { create: true });
|
|
1980
|
+
}
|
|
1981
|
+
this.rootHandle = handle;
|
|
1982
|
+
return handle;
|
|
1983
|
+
})();
|
|
1984
|
+
return this.openPromise;
|
|
1985
|
+
}
|
|
1986
|
+
requireHandle() {
|
|
1987
|
+
if (this.rootHandle === null) {
|
|
1988
|
+
throw new Error("OPFSResource is not open \u2014 call open() first");
|
|
1989
|
+
}
|
|
1990
|
+
return this.rootHandle;
|
|
1991
|
+
}
|
|
1992
|
+
ops() {
|
|
1993
|
+
return OPFS_OPS;
|
|
1994
|
+
}
|
|
1995
|
+
commands() {
|
|
1996
|
+
return OPFS_COMMANDS;
|
|
1997
|
+
}
|
|
1998
|
+
async *streamPath(p) {
|
|
1999
|
+
await this.ensureOpen();
|
|
2000
|
+
yield* stream(this.accessor, p);
|
|
2001
|
+
}
|
|
2002
|
+
async readFile(p) {
|
|
2003
|
+
await this.ensureOpen();
|
|
2004
|
+
return read(this.accessor, p);
|
|
2005
|
+
}
|
|
2006
|
+
async writeFile(p, data) {
|
|
2007
|
+
await this.ensureOpen();
|
|
2008
|
+
return writeBytes(this.accessor, p, data);
|
|
2009
|
+
}
|
|
2010
|
+
async appendFile(p, data) {
|
|
2011
|
+
await this.ensureOpen();
|
|
2012
|
+
return appendBytes(this.accessor, p, data);
|
|
2013
|
+
}
|
|
2014
|
+
async readdir(p) {
|
|
2015
|
+
await this.ensureOpen();
|
|
2016
|
+
return readdir(this.accessor, p);
|
|
2017
|
+
}
|
|
2018
|
+
async stat(p) {
|
|
2019
|
+
await this.ensureOpen();
|
|
2020
|
+
return stat(this.accessor, p);
|
|
2021
|
+
}
|
|
2022
|
+
async exists(p) {
|
|
2023
|
+
await this.ensureOpen();
|
|
2024
|
+
return exists(this.accessor, p);
|
|
2025
|
+
}
|
|
2026
|
+
async mkdir(p, options) {
|
|
2027
|
+
await this.ensureOpen();
|
|
2028
|
+
return mkdir(this.accessor, p, options?.recursive === true);
|
|
2029
|
+
}
|
|
2030
|
+
async rmdir(p) {
|
|
2031
|
+
await this.ensureOpen();
|
|
2032
|
+
return rmdir(this.accessor, p);
|
|
2033
|
+
}
|
|
2034
|
+
async unlink(p) {
|
|
2035
|
+
await this.ensureOpen();
|
|
2036
|
+
return unlink(this.accessor, p);
|
|
2037
|
+
}
|
|
2038
|
+
async rename(src, dst) {
|
|
2039
|
+
await this.ensureOpen();
|
|
2040
|
+
return rename(this.accessor, src, dst);
|
|
2041
|
+
}
|
|
2042
|
+
async truncate(p, length) {
|
|
2043
|
+
await this.ensureOpen();
|
|
2044
|
+
return truncate(this.accessor, p, length);
|
|
2045
|
+
}
|
|
2046
|
+
async copy(src, dst) {
|
|
2047
|
+
await this.ensureOpen();
|
|
2048
|
+
return copy(this.accessor, src, dst);
|
|
2049
|
+
}
|
|
2050
|
+
async rmR(p) {
|
|
2051
|
+
await this.ensureOpen();
|
|
2052
|
+
return rmR(this.accessor, p);
|
|
2053
|
+
}
|
|
2054
|
+
async du(p) {
|
|
2055
|
+
await this.ensureOpen();
|
|
2056
|
+
return du(this.accessor, p);
|
|
2057
|
+
}
|
|
2058
|
+
async find(p, options = {}) {
|
|
2059
|
+
await this.ensureOpen();
|
|
2060
|
+
return find(this.accessor, p, options);
|
|
2061
|
+
}
|
|
2062
|
+
async glob(paths) {
|
|
2063
|
+
await this.ensureOpen();
|
|
2064
|
+
return resolveGlob(this.accessor, paths);
|
|
2065
|
+
}
|
|
2066
|
+
async getState() {
|
|
2067
|
+
const handle = await this.ensureOpen();
|
|
2068
|
+
const files = {};
|
|
2069
|
+
await walkFiles(handle, "", files);
|
|
2070
|
+
const dirs = [];
|
|
2071
|
+
await walkDirs(handle, "", dirs);
|
|
2072
|
+
dirs.sort();
|
|
2073
|
+
return {
|
|
2074
|
+
type: this.kind,
|
|
2075
|
+
files,
|
|
2076
|
+
dirs
|
|
2077
|
+
};
|
|
2078
|
+
}
|
|
2079
|
+
async loadState(state) {
|
|
2080
|
+
const handle = await this.ensureOpen();
|
|
2081
|
+
for (const dir of state.dirs) {
|
|
2082
|
+
const rel = lstripSlash(dir);
|
|
2083
|
+
if (rel === "") continue;
|
|
2084
|
+
await splitAndCreate(handle, rel);
|
|
2085
|
+
}
|
|
2086
|
+
for (const [rel, data] of Object.entries(state.files)) {
|
|
2087
|
+
const segs = rel.split("/").filter((s) => s !== "" && s !== ".");
|
|
2088
|
+
const fileName = segs.pop();
|
|
2089
|
+
if (fileName === void 0) continue;
|
|
2090
|
+
let dir = handle;
|
|
2091
|
+
for (const seg of segs) {
|
|
2092
|
+
dir = await dir.getDirectoryHandle(seg, { create: true });
|
|
2093
|
+
}
|
|
2094
|
+
const fh = await dir.getFileHandle(fileName, { create: true });
|
|
2095
|
+
const writable = await fh.createWritable();
|
|
2096
|
+
await writable.write(toWritableChunk(data));
|
|
2097
|
+
await writable.close();
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
};
|
|
2101
|
+
|
|
2102
|
+
export {
|
|
2103
|
+
OPFSAccessor,
|
|
2104
|
+
OPFS_COMMANDS,
|
|
2105
|
+
OPFS_OPS,
|
|
2106
|
+
OPFS_PROMPT,
|
|
2107
|
+
OPFSResource
|
|
2108
|
+
};
|
|
2109
|
+
//# sourceMappingURL=chunk-SJB2KXDM.js.map
|