@glodon-aiot/bot-client-sdk 3.26.0-alpha.8 → 3.26.0-alpha.9
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 +108 -96
- package/dist/es/Config.mjs +63 -85
- package/dist/es/builtinTools/browserRuntime/BrowserCommandRunner.mjs +201 -0
- package/dist/es/builtinTools/browserRuntime/PythonRunner.mjs +356 -0
- package/dist/es/builtinTools/browserRuntime/WorkspaceBashFs.mjs +350 -0
- package/dist/es/builtinTools/browserRuntime/assets.mjs +9 -0
- package/dist/es/builtinTools/browserRuntime/loadBash.mjs +17 -0
- package/dist/es/builtinTools/browserRuntime/pyodideRunner.py.mjs +96 -0
- package/dist/es/builtinTools/browserRuntime/pyodideWorker.mjs +242 -0
- package/dist/es/builtinTools/command.mjs +56 -0
- package/dist/es/builtinTools/constants.mjs +10 -0
- package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +244 -0
- package/dist/es/builtinTools/overview.mjs +77 -0
- package/dist/es/builtinTools/paths.mjs +63 -0
- package/dist/es/builtinTools/schemas.mjs +216 -0
- package/dist/es/builtinTools/tools.mjs +471 -0
- package/dist/es/index.mjs +49 -48
- package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +193 -103
- package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +117 -132
- package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +132 -97
- package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +32 -28
- package/dist/es/localFiles/constants.mjs +1 -1
- package/dist/es/localFiles/host/connectHostBridge.mjs +37 -34
- package/dist/es/localFiles/host/protocol.mjs +6 -5
- package/dist/es/localFiles/host/sandboxClient.mjs +324 -0
- package/dist/es/localFiles/host/sandboxFrames.mjs +21 -0
- package/dist/es/localFiles/schemas.mjs +45 -60
- package/dist/es/localFiles/validate.mjs +37 -37
- package/dist/es/localFiles/workspace/LocalWorkspace.mjs +71 -52
- package/dist/es/package.json.mjs +38 -29
- package/dist/lib/index.js +374 -10
- package/dist/src/Config.d.ts +2 -2
- package/dist/src/builtinTools/browserRuntime/BrowserCommandRunner.d.ts +26 -0
- package/dist/src/builtinTools/browserRuntime/PythonRunner.d.ts +67 -0
- package/dist/src/builtinTools/browserRuntime/WorkspaceBashFs.d.ts +51 -0
- package/dist/src/builtinTools/browserRuntime/assets.d.ts +13 -0
- package/dist/src/builtinTools/browserRuntime/loadBash.d.ts +3 -0
- package/dist/src/builtinTools/browserRuntime/pyodideWorker.d.ts +44 -0
- package/dist/src/builtinTools/command.d.ts +28 -0
- package/dist/src/builtinTools/constants.d.ts +17 -0
- package/dist/src/builtinTools/createBuiltinToolsPlugin.d.ts +11 -0
- package/dist/src/builtinTools/overview.d.ts +5 -0
- package/dist/src/builtinTools/paths.d.ts +15 -0
- package/dist/src/builtinTools/schemas.d.ts +3 -0
- package/dist/src/builtinTools/tools.d.ts +60 -0
- package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +4 -1
- package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +28 -15
- package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +4 -1
- package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +14 -0
- package/dist/src/localFiles/adapters/fsaTypes.d.ts +2 -0
- package/dist/src/localFiles/constants.d.ts +2 -1
- package/dist/src/localFiles/host/protocol.d.ts +21 -14
- package/dist/src/localFiles/host/sandboxClient.d.ts +62 -0
- package/dist/src/localFiles/host/sandboxFrames.d.ts +9 -0
- package/dist/src/localFiles/index.d.ts +3 -2
- package/dist/src/localFiles/schemas.d.ts +2 -3
- package/dist/src/localFiles/types.d.ts +14 -1
- package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +12 -0
- package/package.json +13 -4
- package/dist/es/localFiles/createLocalPythonPlugin.mjs +0 -196
|
@@ -1,169 +1,154 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var m = (n, t) => {
|
|
5
|
-
if (t = Symbol[n])
|
|
1
|
+
var p = Object.defineProperty;
|
|
2
|
+
var m = (r, t) => {
|
|
3
|
+
if (t = Symbol[r])
|
|
6
4
|
return t;
|
|
7
|
-
throw Error("Symbol." +
|
|
5
|
+
throw Error("Symbol." + r + " is not defined");
|
|
8
6
|
};
|
|
9
|
-
var u = (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (h)
|
|
13
|
-
for (var e of h(t))
|
|
14
|
-
x.call(t, e) && u(n, e, t[e]);
|
|
15
|
-
return n;
|
|
16
|
-
};
|
|
17
|
-
var p = (n, t, e) => (u(n, typeof t != "symbol" ? t + "" : t, e), e);
|
|
18
|
-
var y = (n, t, e) => new Promise((r, s) => {
|
|
7
|
+
var u = (r, t, e) => t in r ? p(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
|
|
8
|
+
var l = (r, t, e) => (u(r, typeof t != "symbol" ? t + "" : t, e), e);
|
|
9
|
+
var n = (r, t, e) => new Promise((s, a) => {
|
|
19
10
|
var o = (i) => {
|
|
20
11
|
try {
|
|
21
|
-
|
|
22
|
-
} catch (
|
|
23
|
-
|
|
12
|
+
y(e.next(i));
|
|
13
|
+
} catch (c) {
|
|
14
|
+
a(c);
|
|
24
15
|
}
|
|
25
|
-
},
|
|
16
|
+
}, d = (i) => {
|
|
26
17
|
try {
|
|
27
|
-
|
|
28
|
-
} catch (
|
|
29
|
-
|
|
18
|
+
y(e.throw(i));
|
|
19
|
+
} catch (c) {
|
|
20
|
+
a(c);
|
|
30
21
|
}
|
|
31
|
-
},
|
|
32
|
-
|
|
22
|
+
}, y = (i) => i.done ? s(i.value) : Promise.resolve(i.value).then(o, d);
|
|
23
|
+
y((e = e.apply(r, t)).next());
|
|
33
24
|
});
|
|
34
|
-
var
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
37
|
-
import {
|
|
38
|
-
|
|
39
|
-
function
|
|
40
|
-
|
|
41
|
-
for (let r = 0; r < n.length; r += 32768)
|
|
42
|
-
t += String.fromCharCode(...n.subarray(r, r + 32768));
|
|
43
|
-
return btoa(t);
|
|
44
|
-
}
|
|
45
|
-
function O(n) {
|
|
46
|
-
const t = atob(n), e = new Uint8Array(t.length);
|
|
47
|
-
for (let r = 0; r < t.length; r++)
|
|
48
|
-
e[r] = t.charCodeAt(r);
|
|
49
|
-
return e;
|
|
50
|
-
}
|
|
51
|
-
function E(n, t) {
|
|
52
|
-
const e = n && typeof n == "object" ? n : {}, r = e.kind === "directory" ? "directory" : "file", s = {
|
|
25
|
+
var f = (r, t, e) => (t = r[m("asyncIterator")]) ? t.call(r) : (r = r[m("iterator")](), t = {}, e = (s, a) => (a = r[s]) && (t[s] = (o) => new Promise((d, y, i) => (o = a.call(r, o), i = o.done, Promise.resolve(o.value).then((c) => d({ value: c, done: i }), y)))), e("next"), e("return"), t);
|
|
26
|
+
import { throwIfAborted as g } from "../errors.mjs";
|
|
27
|
+
import { SandboxClient as v } from "../host/sandboxClient.mjs";
|
|
28
|
+
import { SANDBOX_PROTOCOL as A } from "../host/protocol.mjs";
|
|
29
|
+
import { domError as w, toChunks as M } from "./WorkspaceFileAdapter.mjs";
|
|
30
|
+
function x(r, t) {
|
|
31
|
+
const e = r && typeof r == "object" ? r : {}, s = e.kind === "directory" ? "directory" : "file", a = {
|
|
53
32
|
name: typeof e.name == "string" && e.name ? e.name : t,
|
|
54
|
-
kind:
|
|
33
|
+
kind: s
|
|
55
34
|
};
|
|
56
|
-
return
|
|
35
|
+
return s === "file" && typeof e.size == "number" && (a.size = e.size), typeof e.lastModified == "number" && (a.lastModified = e.lastModified), a;
|
|
57
36
|
}
|
|
58
37
|
class S {
|
|
59
|
-
constructor(t, e = "") {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
this
|
|
38
|
+
constructor(t, e = "", s = new v()) {
|
|
39
|
+
l(this, "displayName");
|
|
40
|
+
l(this, "capabilities", /* @__PURE__ */ new Set());
|
|
41
|
+
l(this, "sandboxVersion");
|
|
42
|
+
l(this, "sandboxProtocol");
|
|
43
|
+
l(this, "sandbox");
|
|
44
|
+
this.displayName = e, this.sandbox = s;
|
|
64
45
|
}
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
if (clearTimeout(e.timer), this.pending.delete(t.id), t.ok === !1) {
|
|
69
|
-
e.reject(f(t.name || "NotAllowedError", t.message || t.name || "NotAllowedError"));
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
e.resolve(t);
|
|
73
|
-
}
|
|
46
|
+
setCapabilities(t, e = {}) {
|
|
47
|
+
const s = Array.isArray(t) ? t.filter((a) => typeof a == "string") : [];
|
|
48
|
+
this.capabilities = new Set(s), this.sandboxVersion = typeof e.version == "string" ? e.version : void 0;
|
|
74
49
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
resolve: (C) => {
|
|
88
|
-
r == null || r.removeEventListener("abort", d), c(C);
|
|
89
|
-
},
|
|
90
|
-
reject: a,
|
|
91
|
-
timer: i
|
|
92
|
-
}), this.view.postMessage(b({
|
|
93
|
-
channel: M,
|
|
94
|
-
id: o,
|
|
95
|
-
op: t
|
|
96
|
-
}, e));
|
|
97
|
-
});
|
|
50
|
+
applySandbox(t) {
|
|
51
|
+
this.sandboxProtocol = t == null ? void 0 : t.protocol, this.sandbox.apply(t);
|
|
52
|
+
}
|
|
53
|
+
/** 沙箱已就绪且协议为 2 时,命令走直连。 */
|
|
54
|
+
get canExec() {
|
|
55
|
+
return this.sandbox.ready;
|
|
56
|
+
}
|
|
57
|
+
get protocolMismatch() {
|
|
58
|
+
return this.sandboxProtocol !== void 0 && this.sandboxProtocol !== A;
|
|
59
|
+
}
|
|
60
|
+
unavailableMessage() {
|
|
61
|
+
return this.sandbox.unavailableMessage();
|
|
98
62
|
}
|
|
99
63
|
stat(t) {
|
|
100
|
-
return
|
|
101
|
-
const e = yield this.
|
|
102
|
-
|
|
103
|
-
});
|
|
104
|
-
return E(e.entry, t.split("/").pop() || this.displayName);
|
|
64
|
+
return n(this, null, function* () {
|
|
65
|
+
const e = yield this.sandbox.stat(t);
|
|
66
|
+
return x(e.entry, t.split("/").pop() || this.displayName);
|
|
105
67
|
});
|
|
106
68
|
}
|
|
107
69
|
listEntries(t, e) {
|
|
108
|
-
return
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
70
|
+
return n(this, null, function* () {
|
|
71
|
+
const s = yield this.sandbox.list(t, e);
|
|
72
|
+
return (Array.isArray(s.entries) ? s.entries : []).map((o) => x(o, ""));
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
readFile(t, e) {
|
|
76
|
+
return n(this, null, function* () {
|
|
77
|
+
var a;
|
|
78
|
+
const s = yield this.sandbox.read(t, (a = e == null ? void 0 : e.offset) != null ? a : 0, e == null ? void 0 : e.maxBytes);
|
|
79
|
+
return new Blob([s]);
|
|
113
80
|
});
|
|
114
81
|
}
|
|
115
|
-
|
|
116
|
-
return
|
|
117
|
-
|
|
118
|
-
const e = yield this.call("read", {
|
|
119
|
-
path: t
|
|
120
|
-
}), r = O((s = e.contentBase64) != null ? s : "");
|
|
121
|
-
return new Blob([r]);
|
|
82
|
+
createDirectory(t) {
|
|
83
|
+
return n(this, null, function* () {
|
|
84
|
+
yield this.sandbox.mkdir(t);
|
|
122
85
|
});
|
|
123
86
|
}
|
|
124
|
-
|
|
125
|
-
return
|
|
126
|
-
|
|
127
|
-
|
|
87
|
+
remove(s) {
|
|
88
|
+
return n(this, arguments, function* (t, e = {}) {
|
|
89
|
+
yield this.sandbox.remove(t, e.recursive === !0);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
move(t, e) {
|
|
93
|
+
return n(this, null, function* () {
|
|
94
|
+
yield this.sandbox.move(t, e);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
exec(t) {
|
|
98
|
+
return n(this, null, function* () {
|
|
99
|
+
const e = yield this.sandbox.exec({
|
|
100
|
+
op: "exec",
|
|
101
|
+
cwd: t.cwd,
|
|
102
|
+
command: t.command,
|
|
103
|
+
argv: t.argv,
|
|
104
|
+
timeoutMs: t.timeoutMs
|
|
105
|
+
}, t.signal, t.onOutput);
|
|
106
|
+
if (e.timedOut)
|
|
107
|
+
throw w("AbortError", "命令运行超时。");
|
|
108
|
+
return e;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
runPython(t, e, s, a) {
|
|
112
|
+
return n(this, null, function* () {
|
|
113
|
+
return this.sandbox.exec({
|
|
114
|
+
op: "run_python",
|
|
128
115
|
path: t,
|
|
129
116
|
args: e,
|
|
130
|
-
timeoutMs:
|
|
131
|
-
},
|
|
132
|
-
return {
|
|
133
|
-
exitCode: typeof o.exitCode == "number" ? o.exitCode : 1,
|
|
134
|
-
timedOut: o.timedOut === !0,
|
|
135
|
-
stdout: (c = o.stdout) != null ? c : "",
|
|
136
|
-
stderr: (a = o.stderr) != null ? a : ""
|
|
137
|
-
};
|
|
117
|
+
timeoutMs: s
|
|
118
|
+
}, a);
|
|
138
119
|
});
|
|
139
120
|
}
|
|
140
|
-
writeFile(
|
|
141
|
-
return
|
|
142
|
-
|
|
121
|
+
writeFile(a, o) {
|
|
122
|
+
return n(this, arguments, function* (t, e, s = {}) {
|
|
123
|
+
if (typeof e == "string") {
|
|
124
|
+
yield this.sandbox.write(t, new TextEncoder().encode(e), s.createDirectories === !0, s.signal);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (e instanceof Uint8Array) {
|
|
128
|
+
yield this.sandbox.write(t, e, s.createDirectories === !0, s.signal);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const d = [];
|
|
143
132
|
try {
|
|
144
|
-
for (var
|
|
145
|
-
const
|
|
146
|
-
|
|
133
|
+
for (var N = f(M(e)), z, L, F; z = !(L = yield N.next()).done; z = !1) {
|
|
134
|
+
const b = L.value;
|
|
135
|
+
g(s.signal), d.push(b);
|
|
147
136
|
}
|
|
148
|
-
} catch (
|
|
149
|
-
|
|
137
|
+
} catch (L) {
|
|
138
|
+
F = [L];
|
|
150
139
|
} finally {
|
|
151
140
|
try {
|
|
152
|
-
|
|
141
|
+
z && (L = N.return) && (yield L.call(N));
|
|
153
142
|
} finally {
|
|
154
|
-
if (
|
|
155
|
-
throw
|
|
143
|
+
if (F)
|
|
144
|
+
throw F[0];
|
|
156
145
|
}
|
|
157
146
|
}
|
|
158
|
-
const
|
|
159
|
-
let
|
|
160
|
-
|
|
161
|
-
i.set(
|
|
162
|
-
}), yield this.
|
|
163
|
-
path: t,
|
|
164
|
-
contentBase64: v(i),
|
|
165
|
-
createDirectories: r.createDirectories === !0
|
|
166
|
-
}, r.signal);
|
|
147
|
+
const y = d.reduce((b, h) => b + h.byteLength, 0), i = new Uint8Array(y);
|
|
148
|
+
let c = 0;
|
|
149
|
+
d.forEach((b) => {
|
|
150
|
+
i.set(b, c), c += b.byteLength;
|
|
151
|
+
}), yield this.sandbox.write(t, i, s.createDirectories === !0, s.signal);
|
|
167
152
|
});
|
|
168
153
|
}
|
|
169
154
|
}
|
|
@@ -1,161 +1,196 @@
|
|
|
1
|
-
var
|
|
2
|
-
var g = (
|
|
3
|
-
if (
|
|
4
|
-
return
|
|
5
|
-
throw Error("Symbol." +
|
|
1
|
+
var M = Object.defineProperty;
|
|
2
|
+
var g = (n, r) => {
|
|
3
|
+
if (r = Symbol[n])
|
|
4
|
+
return r;
|
|
5
|
+
throw Error("Symbol." + n + " is not defined");
|
|
6
6
|
};
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var i = (
|
|
7
|
+
var N = (n, r, e) => r in n ? M(n, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[r] = e;
|
|
8
|
+
var k = (n, r, e) => (N(n, typeof r != "symbol" ? r + "" : r, e), e);
|
|
9
|
+
var h = (n, r, e) => new Promise((o, t) => {
|
|
10
|
+
var i = (c) => {
|
|
11
11
|
try {
|
|
12
|
-
|
|
13
|
-
} catch (
|
|
14
|
-
|
|
12
|
+
s(e.next(c));
|
|
13
|
+
} catch (l) {
|
|
14
|
+
t(l);
|
|
15
15
|
}
|
|
16
|
-
},
|
|
16
|
+
}, d = (c) => {
|
|
17
17
|
try {
|
|
18
|
-
|
|
19
|
-
} catch (
|
|
20
|
-
|
|
18
|
+
s(e.throw(c));
|
|
19
|
+
} catch (l) {
|
|
20
|
+
t(l);
|
|
21
21
|
}
|
|
22
|
-
},
|
|
23
|
-
|
|
22
|
+
}, s = (c) => c.done ? o(c.value) : Promise.resolve(c.value).then(i, d);
|
|
23
|
+
s((e = e.apply(n, r)).next());
|
|
24
24
|
});
|
|
25
|
-
var
|
|
26
|
-
import { domError as
|
|
27
|
-
import { throwIfAborted as
|
|
28
|
-
import { splitPath as
|
|
29
|
-
function
|
|
25
|
+
var E = (n, r, e) => (r = n[g("asyncIterator")]) ? r.call(n) : (n = n[g("iterator")](), r = {}, e = (o, t) => (t = n[o]) && (r[o] = (i) => new Promise((d, s, c) => (i = t.call(n, i), c = i.done, Promise.resolve(i.value).then((l) => d({ value: l, done: c }), s)))), e("next"), e("return"), r);
|
|
26
|
+
import { domError as a, toChunks as b, isSameOrInside as I } from "./WorkspaceFileAdapter.mjs";
|
|
27
|
+
import { throwIfAborted as p } from "../errors.mjs";
|
|
28
|
+
import { splitPath as f } from "../security/pathPolicy.mjs";
|
|
29
|
+
function D() {
|
|
30
30
|
return {
|
|
31
31
|
kind: "directory",
|
|
32
32
|
children: /* @__PURE__ */ new Map()
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
class x {
|
|
36
|
-
constructor(
|
|
37
|
-
|
|
38
|
-
this.displayName =
|
|
36
|
+
constructor(r = {}, e = "memory-workspace") {
|
|
37
|
+
k(this, "root", D());
|
|
38
|
+
this.displayName = e, Object.entries(r).forEach(([o, t]) => this.seed(o, t));
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
41
|
* 直接写入文件(含中间目录),用于构造测试数据或模拟外部修改。
|
|
42
42
|
* 以 `/` 结尾的路径表示创建空目录。
|
|
43
43
|
*/
|
|
44
|
-
seed(
|
|
45
|
-
const
|
|
46
|
-
if (
|
|
47
|
-
this.resolveDirectory(
|
|
44
|
+
seed(r, e = "", o = Date.now()) {
|
|
45
|
+
const t = r.split("/").filter(Boolean);
|
|
46
|
+
if (r.endsWith("/")) {
|
|
47
|
+
this.resolveDirectory(t, !0);
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
|
-
const i =
|
|
50
|
+
const i = t.pop();
|
|
51
51
|
if (!i)
|
|
52
52
|
return;
|
|
53
|
-
const
|
|
54
|
-
|
|
53
|
+
const d = this.resolveDirectory(t, !0), s = typeof e == "string" ? new TextEncoder().encode(e) : e;
|
|
54
|
+
d.children.set(i, {
|
|
55
55
|
kind: "file",
|
|
56
|
-
data:
|
|
57
|
-
lastModified:
|
|
56
|
+
data: s,
|
|
57
|
+
lastModified: o
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
|
-
resolveDirectory(
|
|
61
|
-
let
|
|
62
|
-
for (const
|
|
63
|
-
let i =
|
|
60
|
+
resolveDirectory(r, e = !1) {
|
|
61
|
+
let o = this.root;
|
|
62
|
+
for (const t of r) {
|
|
63
|
+
let i = o.children.get(t);
|
|
64
64
|
if (!i) {
|
|
65
|
-
if (!
|
|
66
|
-
throw
|
|
67
|
-
i =
|
|
65
|
+
if (!e)
|
|
66
|
+
throw a("NotFoundError");
|
|
67
|
+
i = D(), o.children.set(t, i);
|
|
68
68
|
}
|
|
69
69
|
if (i.kind !== "directory")
|
|
70
|
-
throw
|
|
71
|
-
|
|
70
|
+
throw a("TypeMismatchError");
|
|
71
|
+
o = i;
|
|
72
72
|
}
|
|
73
|
-
return
|
|
73
|
+
return o;
|
|
74
74
|
}
|
|
75
|
-
resolveNode(
|
|
76
|
-
const
|
|
77
|
-
if (
|
|
75
|
+
resolveNode(r) {
|
|
76
|
+
const e = f(r), o = e.pop();
|
|
77
|
+
if (o === void 0)
|
|
78
78
|
return this.root;
|
|
79
|
-
const
|
|
80
|
-
if (!
|
|
81
|
-
throw
|
|
82
|
-
return
|
|
79
|
+
const t = this.resolveDirectory(e).children.get(o);
|
|
80
|
+
if (!t)
|
|
81
|
+
throw a("NotFoundError");
|
|
82
|
+
return t;
|
|
83
83
|
}
|
|
84
|
-
stat(
|
|
85
|
-
return
|
|
86
|
-
var
|
|
87
|
-
const
|
|
88
|
-
return
|
|
89
|
-
name:
|
|
84
|
+
stat(r) {
|
|
85
|
+
return h(this, null, function* () {
|
|
86
|
+
var t;
|
|
87
|
+
const e = this.resolveNode(r), o = (t = f(r).pop()) != null ? t : this.displayName;
|
|
88
|
+
return e.kind === "directory" ? {
|
|
89
|
+
name: o,
|
|
90
90
|
kind: "directory"
|
|
91
91
|
} : {
|
|
92
|
-
name:
|
|
92
|
+
name: o,
|
|
93
93
|
kind: "file",
|
|
94
|
-
size:
|
|
95
|
-
lastModified:
|
|
94
|
+
size: e.data.byteLength,
|
|
95
|
+
lastModified: e.lastModified
|
|
96
96
|
};
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
|
-
listEntries(
|
|
100
|
-
return
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
return Array.from(
|
|
104
|
-
name:
|
|
99
|
+
listEntries(r, e) {
|
|
100
|
+
return h(this, null, function* () {
|
|
101
|
+
p(e);
|
|
102
|
+
const o = this.resolveDirectory(f(r));
|
|
103
|
+
return Array.from(o.children.entries()).map(([t, i]) => i.kind === "directory" ? {
|
|
104
|
+
name: t,
|
|
105
105
|
kind: "directory"
|
|
106
106
|
} : {
|
|
107
|
-
name:
|
|
107
|
+
name: t,
|
|
108
108
|
kind: "file",
|
|
109
109
|
size: i.data.byteLength,
|
|
110
110
|
lastModified: i.lastModified
|
|
111
111
|
});
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
|
-
readFile(
|
|
115
|
-
return
|
|
116
|
-
const
|
|
117
|
-
if (
|
|
118
|
-
throw
|
|
119
|
-
return new Blob([
|
|
114
|
+
readFile(r) {
|
|
115
|
+
return h(this, null, function* () {
|
|
116
|
+
const e = this.resolveNode(r);
|
|
117
|
+
if (e.kind !== "file")
|
|
118
|
+
throw a("TypeMismatchError");
|
|
119
|
+
return new Blob([e.data]);
|
|
120
120
|
});
|
|
121
121
|
}
|
|
122
|
-
writeFile(
|
|
123
|
-
return
|
|
124
|
-
const
|
|
125
|
-
if (!
|
|
126
|
-
throw
|
|
127
|
-
const
|
|
128
|
-
if ((
|
|
129
|
-
throw
|
|
130
|
-
const
|
|
122
|
+
writeFile(t, i) {
|
|
123
|
+
return h(this, arguments, function* (r, e, o = {}) {
|
|
124
|
+
const d = f(r), s = d.pop();
|
|
125
|
+
if (!s)
|
|
126
|
+
throw a("TypeMismatchError");
|
|
127
|
+
const c = this.resolveDirectory(d, o.createDirectories), l = c.children.get(s);
|
|
128
|
+
if ((l == null ? void 0 : l.kind) === "directory")
|
|
129
|
+
throw a("TypeMismatchError");
|
|
130
|
+
const y = [];
|
|
131
131
|
let u = 0;
|
|
132
132
|
try {
|
|
133
|
-
for (var
|
|
134
|
-
const
|
|
135
|
-
|
|
133
|
+
for (var O = E(b(e)), W, j, C; W = !(j = yield O.next()).done; W = !1) {
|
|
134
|
+
const m = j.value;
|
|
135
|
+
p(o.signal), y.push(m), u += m.byteLength;
|
|
136
136
|
}
|
|
137
|
-
} catch (
|
|
138
|
-
|
|
137
|
+
} catch (j) {
|
|
138
|
+
C = [j];
|
|
139
139
|
} finally {
|
|
140
140
|
try {
|
|
141
|
-
|
|
141
|
+
W && (j = O.return) && (yield j.call(O));
|
|
142
142
|
} finally {
|
|
143
|
-
if (
|
|
144
|
-
throw
|
|
143
|
+
if (C)
|
|
144
|
+
throw C[0];
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
|
-
|
|
148
|
-
const
|
|
147
|
+
p(o.signal);
|
|
148
|
+
const v = new Uint8Array(u);
|
|
149
149
|
let w = 0;
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}),
|
|
150
|
+
y.forEach((m) => {
|
|
151
|
+
v.set(m, w), w += m.byteLength;
|
|
152
|
+
}), c.children.set(s, {
|
|
153
153
|
kind: "file",
|
|
154
|
-
data:
|
|
154
|
+
data: v,
|
|
155
155
|
lastModified: Date.now()
|
|
156
156
|
});
|
|
157
157
|
});
|
|
158
158
|
}
|
|
159
|
+
createDirectory(r) {
|
|
160
|
+
return h(this, null, function* () {
|
|
161
|
+
this.resolveDirectory(f(r), !0);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
remove(o) {
|
|
165
|
+
return h(this, arguments, function* (r, e = {}) {
|
|
166
|
+
const t = f(r), i = t.pop();
|
|
167
|
+
if (i === void 0)
|
|
168
|
+
throw a("InvalidModificationError");
|
|
169
|
+
const d = this.resolveDirectory(t), s = d.children.get(i);
|
|
170
|
+
if (!s)
|
|
171
|
+
throw a("NotFoundError");
|
|
172
|
+
if (s.kind === "directory" && s.children.size > 0 && !e.recursive)
|
|
173
|
+
throw a("InvalidModificationError");
|
|
174
|
+
d.children.delete(i);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
move(r, e) {
|
|
178
|
+
return h(this, null, function* () {
|
|
179
|
+
const o = f(r), t = f(e), i = o.pop(), d = t.pop();
|
|
180
|
+
if (i === void 0 || d === void 0)
|
|
181
|
+
throw a("InvalidModificationError");
|
|
182
|
+
const s = this.resolveDirectory(o), c = s.children.get(i);
|
|
183
|
+
if (!c)
|
|
184
|
+
throw a("NotFoundError");
|
|
185
|
+
const l = this.resolveDirectory(t);
|
|
186
|
+
if (I(r, e))
|
|
187
|
+
throw a("InvalidModificationError");
|
|
188
|
+
const y = l.children.get(d);
|
|
189
|
+
if (y && (y.kind === "directory" || c.kind === "directory"))
|
|
190
|
+
throw a("InvalidModificationError");
|
|
191
|
+
s.children.delete(i), l.children.set(d, c);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
159
194
|
}
|
|
160
195
|
export {
|
|
161
196
|
x as MemoryWorkspaceAdapter
|