@vite-hub/workspace 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +236 -58
- package/dist/{ai-nmHdzjCM.d.ts → ai-BW2ZhizI.d.ts} +22 -7
- package/dist/{ai-Ce3PtWFW.js → ai-BZyLwULx.js} +147 -66
- package/dist/ai.d.ts +2 -2
- package/dist/ai.js +1 -1
- package/dist/{asset-registry-CaG9b7tf.js → asset-registry-DfBV5kmw.js} +3 -2
- package/dist/association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js +19 -0
- package/dist/blob-database.d.ts +521 -0
- package/dist/blob-database.js +601 -0
- package/dist/cloudflare.d.ts +5 -6
- package/dist/cloudflare.js +1 -1
- package/dist/config-B7dmzDX3.js +1112 -0
- package/dist/{config-3I1BnsdO.d.ts → config-DLKdaFWN.d.ts} +1 -2
- package/dist/error-diagnostics-A_8Kp-48.js +116 -0
- package/dist/error-diagnostics-DY5GP47p.js +96 -0
- package/dist/events-7EBoeIPd-A2RUkJi5-BxrICQ17.js +354 -0
- package/dist/events-CRaLy7U3-3PNNp5WZ-Gv9nd0cH.js +214 -0
- package/dist/events-CeChclTf-CX-gD8oy-4aL2j6V-.js +527 -0
- package/dist/feed-DsC7Vws1-M_de2nSK-tKc0Pwo8.js +248 -0
- package/dist/feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js +179 -0
- package/dist/file-C0_aPWSS.js +26 -0
- package/dist/file-metadata-CxDy-E2H.js +58 -0
- package/dist/{files-QRV55OCx.js → files-C7Px8uaC.js} +21 -10
- package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +2278 -0
- package/dist/{github-CfA5vpJ5.js → github-CPxHtFB7.js} +36 -34
- package/dist/github-DtncTfmv-Du2S8lGF.js +4159 -0
- package/dist/gitlab-BoDm8-BC-xzZsW9eW.js +2530 -0
- package/dist/glob--XcLlcml.js +22 -0
- package/dist/glob--kNYDbfU.js +30 -0
- package/dist/graphql-DG5aJBT3-DceyFYdM-C4saqX37.js +489 -0
- package/dist/host-CFnrTXTK.js +1086 -0
- package/dist/{hosted-C1-tTTTf.js → hosted-acMA5XyL.js} +216 -43
- package/dist/hosted-vercel-blob-DKntsHaf.js +12603 -0
- package/dist/hosted-vercel-blob.d.ts +5 -6
- package/dist/hosted-vercel-blob.js +1 -1
- package/dist/hosted.d.ts +6 -7
- package/dist/hosted.js +1 -1
- package/dist/index.d.ts +76 -64
- package/dist/index.js +162 -457
- package/dist/inspect-BoObD2cJ.js +167 -0
- package/dist/internal/path.d.ts +2 -0
- package/dist/internal/path.js +2 -0
- package/dist/lifecycle-BwZ7c9hb.js +596 -0
- package/dist/loader.d.ts +5 -6
- package/dist/loader.js +3 -2
- package/dist/mcp-resources-BREFCmtn.js +39 -0
- package/dist/memory-BbwOqDXl.js +248 -0
- package/dist/metadata-target-DZEZQGHA.js +1588 -0
- package/dist/mountx.d.ts +4 -6
- package/dist/mountx.js +10 -8
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +1 -1
- package/dist/nuxt.d.ts +13 -12
- package/dist/nuxt.js +10 -8
- package/dist/operations-BcpWr41m.js +159 -0
- package/dist/operations-CGqY1XeG.js +965 -0
- package/dist/operations-DnOwKsJT.d.ts +136 -0
- package/dist/operations.d.ts +53 -0
- package/dist/operations.js +2 -0
- package/dist/{path-CNI6wKIU.js → path-CNAwN7pw.js} +34 -35
- package/dist/path-DrSIenjj.js +59 -0
- package/dist/path-zHxQUbqa.d.ts +9 -0
- package/dist/plugins-DqQ8b4T5.d.ts +10 -0
- package/dist/provider-kXjfli9u.js +1457 -0
- package/dist/providers/github/store.d.ts +3 -5
- package/dist/providers/github/store.js +1 -1
- package/dist/registry-Bp-8UUfG.js +129 -0
- package/dist/{registry-BIQVCBWI.d.ts → registry-Cg1TJVVZ.d.ts} +3 -4
- package/dist/{request-execution-u9mgUXKX.js → request-execution-Dk9rY-Yh.js} +24 -20
- package/dist/rolldown-runtime-B4iAMlE-.js +35 -0
- package/dist/runtime/assets.d.ts +3 -5
- package/dist/runtime/assets.js +9 -6
- package/dist/runtime/empty-assets-registry.d.ts +1 -2
- package/dist/runtime/empty-registry.d.ts +1 -2
- package/dist/runtime/state.d.ts +4 -4
- package/dist/runtime/state.js +10 -7
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime.d.ts +84 -15
- package/dist/runtime.js +561 -108
- package/dist/{search-C4REyHj9.js → search-CrTmXj5h.js} +10 -9
- package/dist/server-BNQ-Nbjj.js +290 -0
- package/dist/server.d.ts +22 -34
- package/dist/server.js +2 -355
- package/dist/shared-DalXdP0i.js +2158 -0
- package/dist/source-metadata.d.ts +7 -1
- package/dist/source-metadata.js +34 -2
- package/dist/{state-TTqa3x3Y.d.ts → state-B8zbLi5t.d.ts} +14 -13
- package/dist/store-CXgmu-uw.js +1729 -0
- package/dist/{sync-DiuDmSGk.js → sync-CN6ec-5M.js} +62 -41
- package/dist/templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js +125 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/token-CO62GglH.js +61 -0
- package/dist/{types-60Yn149G.d.ts → types-DeK9GIxy.d.ts} +348 -49
- package/dist/{use-CsV3oIxH.js → use-BQj7nSz6.js} +200 -45
- package/dist/{use-CUFSnFCS.d.ts → use-DhwhbAVV.d.ts} +34 -12
- package/dist/utils-Blrh4N2n.js +545 -0
- package/dist/vite-BEvgU2GY.js +20909 -0
- package/dist/vite-CcZmMQ7S.d.ts +476 -0
- package/dist/vite.d.ts +2 -50
- package/dist/vite.js +2 -2
- package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +1565 -0
- package/dist/workspace-6pxkOuxr.js +1286 -0
- package/dist/workspace-BWJQBK1u.d.ts +7 -0
- package/package.json +90 -59
- package/dist/chunk-8H4AJuhK.js +0 -14
- package/dist/collections/client.d.ts +0 -39
- package/dist/collections/client.js +0 -137
- package/dist/collections.d.ts +0 -59
- package/dist/collections.js +0 -159
- package/dist/config-CDoyls2X.js +0 -30
- package/dist/config-CZLO0m9h.js +0 -7811
- package/dist/file-CHfsZpso.js +0 -23
- package/dist/glob-D0vD_wRY.js +0 -17
- package/dist/host-CAnbugpI.js +0 -370
- package/dist/hosted-vercel-blob-CWBILDVo.js +0 -257
- package/dist/lifecycle-BYoa9hVb.js +0 -176
- package/dist/provider-C3_elpEh.js +0 -599
- package/dist/publish.d.ts +0 -35
- package/dist/publish.js +0 -112
- package/dist/registry-CqyDTW9Y.js +0 -74
- package/dist/runtime-options-BsPSv5O7.js +0 -13
- package/dist/shared-jfogBrd5.js +0 -273
- package/dist/store-Bs1SLh55.js +0 -414
- package/dist/vite-tbfDxtlu.js +0 -2191
- package/dist/workspace-66SKyiec.d.ts +0 -6
- package/dist/workspace-C4k92Ow8.js +0 -1460
package/dist/file-CHfsZpso.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { t as __exportAll } from "./chunk-8H4AJuhK.js";
|
|
2
|
-
import { o as normalizeSafeWorkspacePath } from "./path-CNI6wKIU.js";
|
|
3
|
-
import { t as withWorkspaceRuntimeOptions } from "./runtime-options-BsPSv5O7.js";
|
|
4
|
-
import { file } from "@vite-hub/source";
|
|
5
|
-
//#region src/sources/file.ts
|
|
6
|
-
var file_exports = /* @__PURE__ */ __exportAll({ file: () => file$1 });
|
|
7
|
-
function file$1(input) {
|
|
8
|
-
const options = typeof input === "string" ? { path: input } : input;
|
|
9
|
-
const key = normalizeSafeWorkspacePath(options.workspacePath || options.path || "");
|
|
10
|
-
const mount = typeof options.mount === "object" && options.mount && !("path" in options.mount) ? {
|
|
11
|
-
...options.mount,
|
|
12
|
-
path: ""
|
|
13
|
-
} : options.mount ?? "";
|
|
14
|
-
return {
|
|
15
|
-
...withWorkspaceRuntimeOptions(file(options), {
|
|
16
|
-
...options,
|
|
17
|
-
mount
|
|
18
|
-
}),
|
|
19
|
-
probeKeys: options.probeKeys || [key]
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
//#endregion
|
|
23
|
-
export { file_exports as n, file$1 as t };
|
package/dist/glob-D0vD_wRY.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { t as __exportAll } from "./chunk-8H4AJuhK.js";
|
|
2
|
-
import { t as withWorkspaceRuntimeOptions } from "./runtime-options-BsPSv5O7.js";
|
|
3
|
-
import { glob } from "@vite-hub/source";
|
|
4
|
-
//#region src/sources/glob.ts
|
|
5
|
-
var glob_exports = /* @__PURE__ */ __exportAll({ glob: () => glob$1 });
|
|
6
|
-
function glob$1(options) {
|
|
7
|
-
return withWorkspaceRuntimeOptions(glob({
|
|
8
|
-
...options,
|
|
9
|
-
keyCache: options.keyCache ?? !isLazySource(options)
|
|
10
|
-
}), options);
|
|
11
|
-
}
|
|
12
|
-
function isLazySource(options) {
|
|
13
|
-
if (options.materialize === "lazy") return true;
|
|
14
|
-
return typeof options.mount === "object" && options.mount?.materialize === "lazy";
|
|
15
|
-
}
|
|
16
|
-
//#endregion
|
|
17
|
-
export { glob_exports as n, glob$1 as t };
|
package/dist/host-CAnbugpI.js
DELETED
|
@@ -1,370 +0,0 @@
|
|
|
1
|
-
import { c as normalizeWorkspacePath, d as sha256, i as decodeFile, o as normalizeSafeWorkspacePath, p as workspaceError, r as contentToBytes } from "./path-CNI6wKIU.js";
|
|
2
|
-
import { i as diffSnapshots, r as createSnapshotFromEntries } from "./store-Bs1SLh55.js";
|
|
3
|
-
import { _ as scopedSearchQuery, f as assertDiffInsideSessionPaths, g as isMissingWorkspacePathError, h as filterSessionEntries, m as filterSessionDiff, p as assertPathInSessionScope } from "./workspace-C4k92Ow8.js";
|
|
4
|
-
import { posix } from "node:path";
|
|
5
|
-
import { normalizeExecutionAuthority } from "@vite-hub/runtime";
|
|
6
|
-
//#region src/session/host.ts
|
|
7
|
-
function normalizeTarget(target = "/workspace") {
|
|
8
|
-
const normalized = posix.resolve("/", target.replace(/\\/g, "/"));
|
|
9
|
-
if (normalized === "/") throw workspaceError("[vitehub] Workspace session target cannot be the host root.");
|
|
10
|
-
return normalized;
|
|
11
|
-
}
|
|
12
|
-
function normalizeSearchRoot(path) {
|
|
13
|
-
const normalized = posix.normalize(path.replace(/\\/g, "/"));
|
|
14
|
-
return normalized === "." ? "" : normalizeSafeWorkspacePath(normalized, { allowEmpty: true });
|
|
15
|
-
}
|
|
16
|
-
function toHostPath(root, path = "") {
|
|
17
|
-
const normalized = normalizeSafeWorkspacePath(path, { allowEmpty: true });
|
|
18
|
-
return normalized ? posix.join(root, normalized) : root;
|
|
19
|
-
}
|
|
20
|
-
function toHostCwd(root, cwd) {
|
|
21
|
-
if (cwd === void 0) return root;
|
|
22
|
-
if (!posix.isAbsolute(cwd)) return toHostPath(root, cwd);
|
|
23
|
-
const normalized = posix.normalize(cwd);
|
|
24
|
-
if (normalized === root || normalized.startsWith(`${root}/`)) return normalized;
|
|
25
|
-
if (normalized === "/workspace" || normalized.startsWith("/workspace/")) return toHostPath(root, normalized.slice(10));
|
|
26
|
-
throw workspaceError(`[vitehub] Workspace exec cwd must stay inside ${root}: ${cwd}.`);
|
|
27
|
-
}
|
|
28
|
-
function fromHostPath(root, path) {
|
|
29
|
-
const normalizedRoot = root.replace(/\/+$/, "");
|
|
30
|
-
const normalizedPath = posix.resolve(root, path).replace(/\/+$/, "");
|
|
31
|
-
if (normalizedPath === normalizedRoot) return "";
|
|
32
|
-
if (!normalizedPath.startsWith(`${normalizedRoot}/`)) throw workspaceError(`[vitehub] Workspace host returned a path outside ${root}: ${path}.`);
|
|
33
|
-
return normalizeWorkspacePath(normalizedPath.slice(normalizedRoot.length + 1));
|
|
34
|
-
}
|
|
35
|
-
function isGitSymlinkEntry(entry) {
|
|
36
|
-
return entry.metadata?.gitMode === "120000";
|
|
37
|
-
}
|
|
38
|
-
function hasSymlinkParent(path, symlinks) {
|
|
39
|
-
let parent = posix.dirname(path);
|
|
40
|
-
while (parent && parent !== "." && parent !== "/") {
|
|
41
|
-
if (symlinks.has(parent)) return true;
|
|
42
|
-
parent = posix.dirname(parent);
|
|
43
|
-
}
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
function isSafeHostSymlink(root, path, target) {
|
|
47
|
-
if (posix.isAbsolute(target)) return false;
|
|
48
|
-
const resolved = posix.resolve(posix.dirname(toHostPath(root, path)), target);
|
|
49
|
-
return resolved === root || resolved.startsWith(`${root}/`);
|
|
50
|
-
}
|
|
51
|
-
async function assertNoHostSymlinkParent(host, root, target) {
|
|
52
|
-
const path = fromHostPath(root, target);
|
|
53
|
-
if (hasSymlinkParent(path, new Set((await listHostEntries(host, root, "", true)).filter(isGitSymlinkEntry).map((entry) => entry.path)))) throw workspaceError(`[vitehub] Workspace host path crosses a symlink parent: ${path}.`);
|
|
54
|
-
}
|
|
55
|
-
function toWorkspaceEntry(root, entry) {
|
|
56
|
-
return {
|
|
57
|
-
metadata: entry.type === "symlink" ? { gitMode: "120000" } : void 0,
|
|
58
|
-
path: fromHostPath(root, entry.path),
|
|
59
|
-
size: entry.size,
|
|
60
|
-
type: entry.type === "directory" ? "directory" : "file"
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
async function ensureHostParent(host, path) {
|
|
64
|
-
const parent = posix.dirname(path);
|
|
65
|
-
if (parent && parent !== "." && parent !== "/") await host.files.mkdir(parent, { recursive: true });
|
|
66
|
-
}
|
|
67
|
-
async function readHostSymlinkTarget(host, root, path) {
|
|
68
|
-
const result = await host.exec("readlink", [fromHostPath(root, path)], { cwd: root });
|
|
69
|
-
if (result.code !== 0) throw workspaceError(`[vitehub] Failed to read workspace symlink: ${path}.`, { cause: new Error(result.stderr || "readlink failed") });
|
|
70
|
-
return result.stdout.replace(/\n$/, "");
|
|
71
|
-
}
|
|
72
|
-
async function writeHostSymlink(host, root, path, target) {
|
|
73
|
-
await host.files.remove(path).catch(() => void 0);
|
|
74
|
-
const result = await host.exec("ln", [
|
|
75
|
-
"-s",
|
|
76
|
-
target,
|
|
77
|
-
fromHostPath(root, path)
|
|
78
|
-
], { cwd: root });
|
|
79
|
-
if (result.code !== 0) throw workspaceError(`[vitehub] Failed to create workspace symlink: ${path}. ${result.stderr || "ln failed"}`);
|
|
80
|
-
}
|
|
81
|
-
async function readHostFile(host, root, path) {
|
|
82
|
-
if (!await host.files.exists(path)) return void 0;
|
|
83
|
-
const content = await host.files.read(path);
|
|
84
|
-
return content ? {
|
|
85
|
-
content,
|
|
86
|
-
path: fromHostPath(root, path)
|
|
87
|
-
} : void 0;
|
|
88
|
-
}
|
|
89
|
-
async function listHostEntries(host, root, path = "", recursive = false) {
|
|
90
|
-
const entries = await host.files.list(toHostPath(root, path), { recursive });
|
|
91
|
-
return (await Promise.all(entries.map(async (entry) => {
|
|
92
|
-
const workspaceEntry = toWorkspaceEntry(root, entry);
|
|
93
|
-
if (workspaceEntry.type !== "file" || isGitSymlinkEntry(workspaceEntry)) return workspaceEntry;
|
|
94
|
-
return (await host.exec("test", ["-x", fromHostPath(root, entry.path)], { cwd: root })).code === 0 ? {
|
|
95
|
-
...workspaceEntry,
|
|
96
|
-
metadata: {
|
|
97
|
-
...workspaceEntry.metadata,
|
|
98
|
-
gitMode: "100755"
|
|
99
|
-
}
|
|
100
|
-
} : workspaceEntry;
|
|
101
|
-
}))).filter((entry) => entry.path && entry.path !== ".git" && !entry.path.startsWith(".git/")).sort((left, right) => left.path.localeCompare(right.path));
|
|
102
|
-
}
|
|
103
|
-
async function makeHostFileExecutable(host, root, path) {
|
|
104
|
-
const result = await host.exec("chmod", ["+x", fromHostPath(root, path)], { cwd: root });
|
|
105
|
-
if (result.code !== 0) throw workspaceError(`[vitehub] Failed to preserve executable Workspace file: ${path}. ${result.stderr || "chmod failed"}`);
|
|
106
|
-
}
|
|
107
|
-
async function snapshotHost(host, root, name) {
|
|
108
|
-
return (await captureHostState(host, root, name)).snapshot;
|
|
109
|
-
}
|
|
110
|
-
async function captureHostState(host, root, name) {
|
|
111
|
-
const entries = await listHostEntries(host, root, "", true);
|
|
112
|
-
const contents = /* @__PURE__ */ new Map();
|
|
113
|
-
return {
|
|
114
|
-
contents,
|
|
115
|
-
snapshot: await createSnapshotFromEntries(await Promise.all(entries.map(async (entry) => {
|
|
116
|
-
if (entry.type !== "file") return entry;
|
|
117
|
-
const content = isGitSymlinkEntry(entry) ? await readHostSymlinkTarget(host, root, toHostPath(root, entry.path)) : await host.files.read(toHostPath(root, entry.path));
|
|
118
|
-
if (content === null) throw workspaceError(`[vitehub] Workspace host file disappeared while snapshotting: ${entry.path}.`);
|
|
119
|
-
contents.set(entry.path, content);
|
|
120
|
-
return {
|
|
121
|
-
...entry,
|
|
122
|
-
digest: await sha256(content),
|
|
123
|
-
size: contentToBytes(content).byteLength
|
|
124
|
-
};
|
|
125
|
-
})), name)
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
async function restoreAttachedHost(host, root, diff, state) {
|
|
129
|
-
const changed = [...new Set(diff.entries.map((entry) => entry.path))];
|
|
130
|
-
for (const path of changed.sort((left, right) => right.length - left.length)) await host.files.remove(toHostPath(root, path), { recursive: true }).catch(() => void 0);
|
|
131
|
-
const baselineEntries = changed.map((path) => [path, state.snapshot.entries[path]]).filter((entry) => Boolean(entry[1])).sort(([left], [right]) => left.split("/").length - right.split("/").length);
|
|
132
|
-
for (const [path, entry] of baselineEntries) {
|
|
133
|
-
const target = toHostPath(root, path);
|
|
134
|
-
if (entry.type === "directory") {
|
|
135
|
-
await host.files.mkdir(target, { recursive: true });
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
const content = state.contents.get(path);
|
|
139
|
-
if (content === void 0) continue;
|
|
140
|
-
await ensureHostParent(host, target);
|
|
141
|
-
if (entry.metadata?.gitMode === "120000") await writeHostSymlink(host, root, target, String(content));
|
|
142
|
-
else {
|
|
143
|
-
await host.files.write(target, contentToBytes(content));
|
|
144
|
-
if (entry.metadata?.gitMode === "100755") await makeHostFileExecutable(host, root, target);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
async function resetHostWorkspaceRoot(host, root) {
|
|
149
|
-
await host.files.remove(root, { recursive: true }).catch(() => void 0);
|
|
150
|
-
await host.files.mkdir(root, { recursive: true });
|
|
151
|
-
}
|
|
152
|
-
function normalizeSessionPaths(options) {
|
|
153
|
-
const paths = [...new Set((options?.paths || []).map((path) => normalizeSafeWorkspacePath(path, {
|
|
154
|
-
allowEmpty: true,
|
|
155
|
-
allowReserved: true
|
|
156
|
-
})))];
|
|
157
|
-
if (!paths.length || paths.includes("")) return void 0;
|
|
158
|
-
return paths.sort((left, right) => left.length - right.length || left.localeCompare(right));
|
|
159
|
-
}
|
|
160
|
-
async function sessionEntries(workspace, options) {
|
|
161
|
-
const paths = normalizeSessionPaths(options);
|
|
162
|
-
if (!paths) return await workspace.list("", { recursive: true });
|
|
163
|
-
const entries = /* @__PURE__ */ new Map();
|
|
164
|
-
for (const path of paths) {
|
|
165
|
-
const stat = await workspace.stat(path).catch((error) => {
|
|
166
|
-
if (isMissingWorkspacePathError(error)) return void 0;
|
|
167
|
-
throw error;
|
|
168
|
-
});
|
|
169
|
-
if (!stat) continue;
|
|
170
|
-
entries.set(stat.path, stat);
|
|
171
|
-
if (stat.type === "directory") for (const entry of await workspace.list(path, { recursive: true })) entries.set(entry.path, entry);
|
|
172
|
-
}
|
|
173
|
-
return [...entries.values()].sort((left, right) => left.path.localeCompare(right.path));
|
|
174
|
-
}
|
|
175
|
-
async function materializeWorkspace(workspace, host, root, options) {
|
|
176
|
-
await resetHostWorkspaceRoot(host, root);
|
|
177
|
-
const entries = await sessionEntries(workspace, options);
|
|
178
|
-
const symlinks = new Set(entries.filter(isGitSymlinkEntry).map((entry) => entry.path));
|
|
179
|
-
const nested = entries.find((entry) => hasSymlinkParent(entry.path, symlinks));
|
|
180
|
-
if (nested) throw workspaceError(`[vitehub] Workspace path crosses a symlink parent: ${nested.path}.`);
|
|
181
|
-
for (const entry of entries.filter((entry) => entry.type === "directory")) await host.files.mkdir(toHostPath(root, entry.path), { recursive: true });
|
|
182
|
-
for (const entry of entries) {
|
|
183
|
-
if (entry.type !== "file") continue;
|
|
184
|
-
const target = toHostPath(root, entry.path);
|
|
185
|
-
await ensureHostParent(host, target);
|
|
186
|
-
if (isGitSymlinkEntry(entry)) {
|
|
187
|
-
const symlinkTarget = typeof entry.metadata?.symlinkTarget === "string" ? entry.metadata.symlinkTarget : new TextDecoder().decode(contentToBytes(await workspace.readFile(entry.path, { encoding: "binary" })));
|
|
188
|
-
if (isSafeHostSymlink(root, entry.path, symlinkTarget)) await writeHostSymlink(host, root, target, symlinkTarget);
|
|
189
|
-
else await host.files.write(target, contentToBytes(symlinkTarget));
|
|
190
|
-
} else {
|
|
191
|
-
await host.files.write(target, contentToBytes(await workspace.readFile(entry.path, { encoding: "binary" })));
|
|
192
|
-
if (entry.metadata?.gitMode === "100755") await makeHostFileExecutable(host, root, target);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return await snapshotHost(host, root, "host-open");
|
|
196
|
-
}
|
|
197
|
-
async function commitHostChanges(host, root, workspace, diff, mediaTypes, message) {
|
|
198
|
-
for (const entry of diff.entries) {
|
|
199
|
-
if (entry.after?.type === "directory") {
|
|
200
|
-
if (entry.before?.type === "file") await workspace.rm(entry.path, { force: true });
|
|
201
|
-
await workspace.mkdir(entry.path, { recursive: true });
|
|
202
|
-
continue;
|
|
203
|
-
}
|
|
204
|
-
if (entry.type === "removed") {
|
|
205
|
-
await workspace.rm(entry.path, {
|
|
206
|
-
force: true,
|
|
207
|
-
recursive: true
|
|
208
|
-
});
|
|
209
|
-
continue;
|
|
210
|
-
}
|
|
211
|
-
if (entry.after?.type !== "file") continue;
|
|
212
|
-
if (entry.before?.type === "directory") await workspace.rm(entry.path, {
|
|
213
|
-
force: true,
|
|
214
|
-
recursive: true
|
|
215
|
-
});
|
|
216
|
-
const before = entry.before?.type === "file" ? await workspace.stat(entry.path).catch(() => void 0) : void 0;
|
|
217
|
-
const target = toHostPath(root, entry.path);
|
|
218
|
-
const symlinkTarget = entry.after.metadata?.gitMode === "120000" ? await readHostSymlinkTarget(host, root, target) : void 0;
|
|
219
|
-
const file = symlinkTarget === void 0 ? await readHostFile(host, root, target) : isSafeHostSymlink(root, entry.path, symlinkTarget) ? {
|
|
220
|
-
content: symlinkTarget,
|
|
221
|
-
metadata: entry.after.metadata,
|
|
222
|
-
path: entry.path
|
|
223
|
-
} : {
|
|
224
|
-
content: symlinkTarget,
|
|
225
|
-
path: entry.path
|
|
226
|
-
};
|
|
227
|
-
if (file) await workspace.writeFile(entry.path, file.content, {
|
|
228
|
-
mediaType: file.mediaType || mediaTypes.get(entry.path) || before?.mediaType,
|
|
229
|
-
metadata: symlinkTarget === void 0 ? entry.after.metadata : file.metadata
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
await workspace.snapshot({ name: message || "host-commit" });
|
|
233
|
-
}
|
|
234
|
-
async function createHostedWorkspaceSession(workspace, options) {
|
|
235
|
-
const host = options.host;
|
|
236
|
-
let executionAuthority;
|
|
237
|
-
try {
|
|
238
|
-
executionAuthority = normalizeExecutionAuthority(host.executionAuthority);
|
|
239
|
-
} catch {
|
|
240
|
-
throw new TypeError("[vitehub] Workspace session host must declare executionAuthority.");
|
|
241
|
-
}
|
|
242
|
-
const root = normalizeTarget(options.target);
|
|
243
|
-
const sessionPaths = normalizeSessionPaths(options);
|
|
244
|
-
let closed = false;
|
|
245
|
-
let attachedState = options.attach ? await captureHostState(host, root, "host-attach") : void 0;
|
|
246
|
-
let baseline = attachedState?.snapshot || await materializeWorkspace(workspace, host, root, options);
|
|
247
|
-
const mediaTypes = /* @__PURE__ */ new Map();
|
|
248
|
-
function assertOpen() {
|
|
249
|
-
if (closed) throw workspaceError("[vitehub] Workspace host session is already closed.");
|
|
250
|
-
}
|
|
251
|
-
async function currentDiff() {
|
|
252
|
-
assertOpen();
|
|
253
|
-
return diffSnapshots(baseline, await snapshotHost(host, root));
|
|
254
|
-
}
|
|
255
|
-
return {
|
|
256
|
-
executionAuthority,
|
|
257
|
-
async readFile(path, readOptions) {
|
|
258
|
-
assertOpen();
|
|
259
|
-
const file = await readHostFile(host, root, toHostPath(root, assertPathInSessionScope(normalizeSafeWorkspacePath(path), sessionPaths, { masked: true })));
|
|
260
|
-
if (!file) throw workspaceError(`[vitehub] Workspace file does not exist: ${path}.`);
|
|
261
|
-
return decodeFile(file.content, readOptions);
|
|
262
|
-
},
|
|
263
|
-
async writeFile(path, content, writeOptions) {
|
|
264
|
-
assertOpen();
|
|
265
|
-
const target = toHostPath(root, assertPathInSessionScope(normalizeSafeWorkspacePath(path), sessionPaths));
|
|
266
|
-
await assertNoHostSymlinkParent(host, root, target);
|
|
267
|
-
await ensureHostParent(host, target);
|
|
268
|
-
await host.files.remove(target, { recursive: true }).catch(() => void 0);
|
|
269
|
-
const symlinkTarget = writeOptions?.metadata?.gitMode === "120000" ? new TextDecoder().decode(contentToBytes(content)) : void 0;
|
|
270
|
-
if (symlinkTarget !== void 0 && isSafeHostSymlink(root, fromHostPath(root, target), symlinkTarget)) await writeHostSymlink(host, root, target, symlinkTarget);
|
|
271
|
-
else {
|
|
272
|
-
await host.files.write(target, contentToBytes(content));
|
|
273
|
-
const workspacePath = fromHostPath(root, target);
|
|
274
|
-
if (writeOptions?.metadata?.gitMode === "100755" || baseline.entries[workspacePath]?.metadata?.gitMode === "100755") await makeHostFileExecutable(host, root, target);
|
|
275
|
-
}
|
|
276
|
-
const workspacePath = fromHostPath(root, target);
|
|
277
|
-
if (writeOptions?.mediaType) mediaTypes.set(workspacePath, writeOptions.mediaType);
|
|
278
|
-
else mediaTypes.delete(workspacePath);
|
|
279
|
-
},
|
|
280
|
-
async mkdir(path, mkdirOptions = {}) {
|
|
281
|
-
assertOpen();
|
|
282
|
-
const hostTarget = toHostPath(root, assertPathInSessionScope(normalizeSafeWorkspacePath(path, { allowEmpty: true }), sessionPaths, { mkdir: true }));
|
|
283
|
-
await assertNoHostSymlinkParent(host, root, hostTarget);
|
|
284
|
-
await host.files.mkdir(hostTarget, { recursive: mkdirOptions.recursive });
|
|
285
|
-
},
|
|
286
|
-
async rm(path, rmOptions) {
|
|
287
|
-
assertOpen();
|
|
288
|
-
const workspacePath = assertPathInSessionScope(normalizeSafeWorkspacePath(path), sessionPaths);
|
|
289
|
-
const target = toHostPath(root, workspacePath);
|
|
290
|
-
await assertNoHostSymlinkParent(host, root, target);
|
|
291
|
-
await host.files.remove(target, { recursive: rmOptions?.recursive });
|
|
292
|
-
mediaTypes.delete(normalizeWorkspacePath(workspacePath));
|
|
293
|
-
},
|
|
294
|
-
async list(path = "", listOptions = {}) {
|
|
295
|
-
assertOpen();
|
|
296
|
-
return filterSessionEntries(await listHostEntries(host, root, path, listOptions.recursive), sessionPaths);
|
|
297
|
-
},
|
|
298
|
-
async glob(pattern, globOptions) {
|
|
299
|
-
assertOpen();
|
|
300
|
-
const patterns = Array.isArray(pattern) ? pattern : [pattern];
|
|
301
|
-
const cwd = normalizeSearchRoot(globOptions?.cwd || "");
|
|
302
|
-
const { matchesAny } = await import("./path-CNI6wKIU.js").then((n) => n.l);
|
|
303
|
-
return filterSessionEntries(await listHostEntries(host, root, "", true), sessionPaths).filter((entry) => {
|
|
304
|
-
if (entry.type !== "file") return false;
|
|
305
|
-
if (!cwd) return patterns.some((item) => matchesAny(entry.path, item));
|
|
306
|
-
if (!entry.path.startsWith(`${cwd}/`)) return false;
|
|
307
|
-
const relative = entry.path.slice(cwd.length + 1);
|
|
308
|
-
return patterns.some((item) => matchesAny(relative, item));
|
|
309
|
-
});
|
|
310
|
-
},
|
|
311
|
-
async search(query) {
|
|
312
|
-
assertOpen();
|
|
313
|
-
const { searchText } = await import("./search-C4REyHj9.js").then((n) => n.n);
|
|
314
|
-
const scoped = scopedSearchQuery(query, sessionPaths, normalizeSearchRoot);
|
|
315
|
-
if (!scoped) return [];
|
|
316
|
-
const scopedSearchRoots = [...new Set((scoped.paths?.length ? scoped.paths : [scoped.cwd || ""]).map(normalizeSearchRoot))].filter(Boolean);
|
|
317
|
-
const limit = scoped.limit ?? 100;
|
|
318
|
-
const hits = [];
|
|
319
|
-
for (const entry of filterSessionEntries(await listHostEntries(host, root, "", true), sessionPaths).filter((item) => item.type === "file")) {
|
|
320
|
-
if (scopedSearchRoots.length && !scopedSearchRoots.some((path) => entry.path === path || entry.path.startsWith(`${path}/`))) continue;
|
|
321
|
-
const content = await host.files.read(toHostPath(root, entry.path));
|
|
322
|
-
if (content === null) continue;
|
|
323
|
-
const text = new TextDecoder().decode(content);
|
|
324
|
-
hits.push(...searchText(entry.path, text, {
|
|
325
|
-
...scoped,
|
|
326
|
-
limit: limit - hits.length
|
|
327
|
-
}));
|
|
328
|
-
if (hits.length >= limit) break;
|
|
329
|
-
}
|
|
330
|
-
return hits;
|
|
331
|
-
},
|
|
332
|
-
async diff() {
|
|
333
|
-
return filterSessionDiff(await currentDiff(), sessionPaths);
|
|
334
|
-
},
|
|
335
|
-
async commit(commitOptions) {
|
|
336
|
-
const diff = await currentDiff();
|
|
337
|
-
if (!diff.entries.length) return;
|
|
338
|
-
assertDiffInsideSessionPaths(diff, sessionPaths);
|
|
339
|
-
await commitHostChanges(host, root, workspace, diff, mediaTypes, commitOptions?.message);
|
|
340
|
-
if (options.attach) {
|
|
341
|
-
attachedState = await captureHostState(host, root, commitOptions?.message || "host-commit");
|
|
342
|
-
baseline = attachedState.snapshot;
|
|
343
|
-
} else baseline = await snapshotHost(host, root, commitOptions?.message || "host-commit");
|
|
344
|
-
},
|
|
345
|
-
async exec(command, args = [], execOptions = {}) {
|
|
346
|
-
assertOpen();
|
|
347
|
-
const result = await host.exec(command, args, {
|
|
348
|
-
cwd: toHostCwd(root, execOptions.cwd),
|
|
349
|
-
env: execOptions.env,
|
|
350
|
-
signal: execOptions.abortSignal,
|
|
351
|
-
timeout: execOptions.timeout
|
|
352
|
-
});
|
|
353
|
-
return {
|
|
354
|
-
args,
|
|
355
|
-
command,
|
|
356
|
-
exitCode: result.code,
|
|
357
|
-
stderr: result.stderr,
|
|
358
|
-
stdout: result.stdout
|
|
359
|
-
};
|
|
360
|
-
},
|
|
361
|
-
async close() {
|
|
362
|
-
if (closed) return;
|
|
363
|
-
if (options.attach && attachedState) await restoreAttachedHost(host, root, filterSessionDiff(diffSnapshots(baseline, await snapshotHost(host, root)), sessionPaths), attachedState);
|
|
364
|
-
closed = true;
|
|
365
|
-
if (!options.attach) await materializeWorkspace(workspace, host, root, options);
|
|
366
|
-
}
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
//#endregion
|
|
370
|
-
export { createHostedWorkspaceSession };
|
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
import { a as matchesAny, c as normalizeWorkspacePath, d as sha256, o as normalizeSafeWorkspacePath, p as workspaceError, r as contentToBytes, s as normalizeSafeWorkspacePattern } from "./path-CNI6wKIU.js";
|
|
2
|
-
import { a as resolveRuntimeVercelBlobWorkspaceStore, c as getWorkspaceHostedStoreLoader, d as setWorkspaceRuntimeConfig, l as setWorkspaceHostedStoreLoader, o as resolveVercelBlobWorkspaceStore } from "./provider-C3_elpEh.js";
|
|
3
|
-
import { i as diffSnapshots, r as createSnapshotFromEntries } from "./store-Bs1SLh55.js";
|
|
4
|
-
import { resolve } from "node:path";
|
|
5
|
-
//#region src/providers/vercel/blob-store.ts
|
|
6
|
-
function joinBlobPath(...parts) {
|
|
7
|
-
return parts.map((part) => normalizeWorkspacePath(part)).filter(Boolean).join("/");
|
|
8
|
-
}
|
|
9
|
-
function contentType(path, fallback) {
|
|
10
|
-
if (fallback) return fallback;
|
|
11
|
-
if (path.endsWith(".json")) return "application/json; charset=utf-8";
|
|
12
|
-
if (path.endsWith(".md") || path.endsWith(".txt")) return "text/plain; charset=utf-8";
|
|
13
|
-
}
|
|
14
|
-
function auth(options) {
|
|
15
|
-
return options.token ? { token: options.token } : {};
|
|
16
|
-
}
|
|
17
|
-
async function createVercelBlobClient(options) {
|
|
18
|
-
const blob = await importVercelBlobPeer();
|
|
19
|
-
const access = options.access || "private";
|
|
20
|
-
return {
|
|
21
|
-
async delete(key) {
|
|
22
|
-
await blob.del(key, auth(options));
|
|
23
|
-
},
|
|
24
|
-
async download(key) {
|
|
25
|
-
const result = await blob.get(key, {
|
|
26
|
-
access,
|
|
27
|
-
...auth(options)
|
|
28
|
-
});
|
|
29
|
-
if (!result || result.statusCode !== 200 || !result.stream) throw Object.assign(/* @__PURE__ */ new Error("not found"), { code: "NotFound" });
|
|
30
|
-
return await new Response(result.stream, { headers: result.blob.contentType ? { "content-type": result.blob.contentType } : void 0 }).blob();
|
|
31
|
-
},
|
|
32
|
-
async head(key) {
|
|
33
|
-
const result = await blob.head(key, auth(options));
|
|
34
|
-
return {
|
|
35
|
-
key: result.pathname,
|
|
36
|
-
lastModified: result.uploadedAt.getTime(),
|
|
37
|
-
size: result.size,
|
|
38
|
-
type: result.contentType
|
|
39
|
-
};
|
|
40
|
-
},
|
|
41
|
-
async list(optionsInput) {
|
|
42
|
-
const result = await blob.list({
|
|
43
|
-
...optionsInput,
|
|
44
|
-
...auth(options)
|
|
45
|
-
});
|
|
46
|
-
return {
|
|
47
|
-
cursor: result.cursor,
|
|
48
|
-
items: result.blobs.map((item) => ({
|
|
49
|
-
key: item.pathname,
|
|
50
|
-
lastModified: item.uploadedAt?.getTime(),
|
|
51
|
-
size: item.size
|
|
52
|
-
}))
|
|
53
|
-
};
|
|
54
|
-
},
|
|
55
|
-
async upload(key, body, uploadOptions = {}) {
|
|
56
|
-
await blob.put(key, body, {
|
|
57
|
-
access,
|
|
58
|
-
addRandomSuffix: false,
|
|
59
|
-
allowOverwrite: true,
|
|
60
|
-
contentType: uploadOptions.contentType,
|
|
61
|
-
...auth(options)
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
const vercelBlobPeerSpecifier = "@vercel/blob";
|
|
67
|
-
async function importVercelBlobPeer() {
|
|
68
|
-
try {
|
|
69
|
-
const testImport = globalThis.__vitehubWorkspaceImportVercelBlobPeer;
|
|
70
|
-
if (testImport) return await testImport();
|
|
71
|
-
return await import(vercelBlobPeerSpecifier);
|
|
72
|
-
} catch (error) {
|
|
73
|
-
handleVercelBlobImportError(error);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function handleVercelBlobImportError(error) {
|
|
77
|
-
if (isMissingVercelBlobError(error)) throw workspaceError("[vitehub] @vercel/blob is required for the Vercel Blob Workspace Store. Package: @vercel/blob.", { cause: error });
|
|
78
|
-
throw error;
|
|
79
|
-
}
|
|
80
|
-
function isMissingVercelBlobError(error) {
|
|
81
|
-
if (!(error instanceof Error)) return false;
|
|
82
|
-
const code = error.code;
|
|
83
|
-
if (code !== "ERR_MODULE_NOT_FOUND" && code !== "MODULE_NOT_FOUND") return false;
|
|
84
|
-
return error.message.includes("Cannot find package '@vercel/blob'") || error.message.includes("Cannot find module '@vercel/blob'");
|
|
85
|
-
}
|
|
86
|
-
var VercelBlobWorkspaceStore = class {
|
|
87
|
-
workspaceName;
|
|
88
|
-
#baseline;
|
|
89
|
-
#options;
|
|
90
|
-
#files;
|
|
91
|
-
constructor(options, workspaceName) {
|
|
92
|
-
this.workspaceName = workspaceName;
|
|
93
|
-
this.#options = resolveRuntimeVercelBlobWorkspaceStore(options, typeof process !== "undefined" ? process.env : {});
|
|
94
|
-
}
|
|
95
|
-
get #root() {
|
|
96
|
-
return joinBlobPath(this.#options.prefix || ".vitehub/workspaces", this.workspaceName);
|
|
97
|
-
}
|
|
98
|
-
#fileKey(path, options = {}) {
|
|
99
|
-
return joinBlobPath(this.#root, "files", normalizeSafeWorkspacePath(path, { allowEmpty: options.allowEmpty }));
|
|
100
|
-
}
|
|
101
|
-
async #client() {
|
|
102
|
-
this.#files ||= createVercelBlobClient(this.#options);
|
|
103
|
-
return await this.#files;
|
|
104
|
-
}
|
|
105
|
-
#metaKey(key) {
|
|
106
|
-
return joinBlobPath(this.#root, ".vitehub/meta", normalizeSafeWorkspacePath(key.endsWith(".json") ? key : `${key}.json`));
|
|
107
|
-
}
|
|
108
|
-
#snapshotKey(id) {
|
|
109
|
-
return joinBlobPath(this.#root, ".vitehub/snapshots", `${id}.json`);
|
|
110
|
-
}
|
|
111
|
-
async readFile(path) {
|
|
112
|
-
const normalized = normalizeSafeWorkspacePath(path);
|
|
113
|
-
const pathname = this.#fileKey(normalized);
|
|
114
|
-
const file = await (await this.#client()).download(pathname).catch(() => null);
|
|
115
|
-
if (!file) return void 0;
|
|
116
|
-
const bytes = await file.arrayBuffer();
|
|
117
|
-
return {
|
|
118
|
-
path: normalized,
|
|
119
|
-
content: new Uint8Array(bytes)
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
async writeFile(path, file) {
|
|
123
|
-
const normalized = normalizeSafeWorkspacePath(path);
|
|
124
|
-
await (await this.#client()).upload(this.#fileKey(normalized), new Blob([contentToBytes(file.content)]), { contentType: contentType(normalized, file.mediaType) });
|
|
125
|
-
}
|
|
126
|
-
async list(prefix = "", options = {}) {
|
|
127
|
-
const normalizedPrefix = normalizeSafeWorkspacePath(prefix, { allowEmpty: true });
|
|
128
|
-
const filePrefix = this.#fileKey(normalizedPrefix, { allowEmpty: true });
|
|
129
|
-
const files = await this.#listBlobs(normalizedPrefix ? `${filePrefix}/` : `${this.#fileKey("", { allowEmpty: true })}/`);
|
|
130
|
-
const entries = /* @__PURE__ */ new Map();
|
|
131
|
-
for (const blob of files) {
|
|
132
|
-
const path = normalizeWorkspacePath(blob.key.slice(`${this.#fileKey("", { allowEmpty: true })}/`.length));
|
|
133
|
-
if (!path) continue;
|
|
134
|
-
if (normalizedPrefix && !path.startsWith(`${normalizedPrefix}/`)) continue;
|
|
135
|
-
if (!options.recursive && normalizedPrefix && path.slice(normalizedPrefix.length + 1).includes("/")) continue;
|
|
136
|
-
if (!options.recursive && !normalizedPrefix && path.includes("/")) {
|
|
137
|
-
entries.set(path.split("/")[0], {
|
|
138
|
-
path: path.split("/")[0],
|
|
139
|
-
type: "directory"
|
|
140
|
-
});
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
entries.set(path, {
|
|
144
|
-
mtime: blob.lastModified,
|
|
145
|
-
path,
|
|
146
|
-
size: blob.size,
|
|
147
|
-
type: "file"
|
|
148
|
-
});
|
|
149
|
-
if (options.recursive) {
|
|
150
|
-
const parts = path.split("/");
|
|
151
|
-
for (let index = 1; index < parts.length; index++) {
|
|
152
|
-
const dir = parts.slice(0, index).join("/");
|
|
153
|
-
entries.set(dir, {
|
|
154
|
-
path: dir,
|
|
155
|
-
type: "directory"
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
return [...entries.values()].sort((a, b) => a.path.localeCompare(b.path));
|
|
161
|
-
}
|
|
162
|
-
async glob(pattern, _options = {}) {
|
|
163
|
-
const patterns = Array.isArray(pattern) ? pattern.map(normalizeSafeWorkspacePattern) : normalizeSafeWorkspacePattern(pattern);
|
|
164
|
-
return (await this.list("", { recursive: true })).filter((entry) => entry.type === "file" && matchesAny(entry.path, patterns));
|
|
165
|
-
}
|
|
166
|
-
async stat(path) {
|
|
167
|
-
const normalized = normalizeSafeWorkspacePath(path);
|
|
168
|
-
const file = await this.readFile(normalized);
|
|
169
|
-
if (file) {
|
|
170
|
-
const bytes = contentToBytes(file.content);
|
|
171
|
-
return {
|
|
172
|
-
digest: await sha256(bytes),
|
|
173
|
-
path: normalized,
|
|
174
|
-
size: bytes.byteLength,
|
|
175
|
-
type: "file"
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
return (await this.list(normalized, { recursive: false })).length ? {
|
|
179
|
-
path: normalized,
|
|
180
|
-
type: "directory"
|
|
181
|
-
} : void 0;
|
|
182
|
-
}
|
|
183
|
-
async mkdir(path, _options = {}) {
|
|
184
|
-
normalizeSafeWorkspacePath(path);
|
|
185
|
-
}
|
|
186
|
-
async rm(path, options = {}) {
|
|
187
|
-
const normalized = normalizeSafeWorkspacePath(path);
|
|
188
|
-
const client = await this.#client();
|
|
189
|
-
const targets = [];
|
|
190
|
-
if (await client.head(this.#fileKey(normalized)).catch(() => null)) targets.push(this.#fileKey(normalized));
|
|
191
|
-
else if (options.recursive) for (const blob of await this.#listBlobs(`${this.#fileKey(normalized)}/`)) targets.push(blob.key);
|
|
192
|
-
if (!targets.length) {
|
|
193
|
-
if (options.force) return;
|
|
194
|
-
throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
|
|
195
|
-
}
|
|
196
|
-
await Promise.all(targets.map((target) => client.delete(target)));
|
|
197
|
-
}
|
|
198
|
-
async snapshot(options = {}) {
|
|
199
|
-
const snapshot = await createSnapshotFromEntries(await this.list("", { recursive: true }), options.name);
|
|
200
|
-
await (await this.#client()).upload(this.#snapshotKey(snapshot.id), JSON.stringify(snapshot), { contentType: "application/json; charset=utf-8" });
|
|
201
|
-
this.#baseline = snapshot;
|
|
202
|
-
return snapshot;
|
|
203
|
-
}
|
|
204
|
-
async diff(options = {}) {
|
|
205
|
-
return diffSnapshots(options.from || this.#baseline, await createSnapshotFromEntries(await this.list("", { recursive: true })));
|
|
206
|
-
}
|
|
207
|
-
async getMeta(key) {
|
|
208
|
-
return await this.#readJson(this.#metaKey(key));
|
|
209
|
-
}
|
|
210
|
-
async setMeta(key, value) {
|
|
211
|
-
await (await this.#client()).upload(this.#metaKey(key), JSON.stringify(value), { contentType: "application/json; charset=utf-8" });
|
|
212
|
-
}
|
|
213
|
-
async #listBlobs(prefix) {
|
|
214
|
-
const blobs = [];
|
|
215
|
-
let cursor;
|
|
216
|
-
do {
|
|
217
|
-
const result = await (await this.#client()).list({
|
|
218
|
-
cursor,
|
|
219
|
-
limit: 1e3,
|
|
220
|
-
prefix
|
|
221
|
-
});
|
|
222
|
-
blobs.push(...result.items);
|
|
223
|
-
cursor = result.cursor;
|
|
224
|
-
} while (cursor);
|
|
225
|
-
return blobs;
|
|
226
|
-
}
|
|
227
|
-
async #readJson(pathname) {
|
|
228
|
-
const file = await (await this.#client()).download(pathname).catch(() => null);
|
|
229
|
-
return file ? JSON.parse(await file.text()) : void 0;
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
function createVercelBlobWorkspaceStore(options, workspaceName) {
|
|
233
|
-
return new VercelBlobWorkspaceStore(options, workspaceName);
|
|
234
|
-
}
|
|
235
|
-
//#endregion
|
|
236
|
-
//#region src/hosted-vercel-blob.ts
|
|
237
|
-
function installHostedVercelBlobWorkspaceRuntime() {
|
|
238
|
-
const existingWorkspaceHostedStoreLoader = getWorkspaceHostedStoreLoader();
|
|
239
|
-
setWorkspaceHostedStoreLoader((storeOptions, workspaceName) => {
|
|
240
|
-
if (storeOptions.provider === "vercel-blob") return createVercelBlobWorkspaceStore(storeOptions, workspaceName);
|
|
241
|
-
if (existingWorkspaceHostedStoreLoader) return existingWorkspaceHostedStoreLoader(storeOptions, workspaceName);
|
|
242
|
-
throw workspaceError("[vitehub] Vercel Blob hosted workspace runtime cannot load unsupported hosted store.");
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
function configureHostedVercelBlobWorkspaceRuntime(options = {}) {
|
|
246
|
-
const root = resolve(process.cwd(), options.root || ".vitehub/workspaces");
|
|
247
|
-
const config = {
|
|
248
|
-
assets: options.assets,
|
|
249
|
-
root,
|
|
250
|
-
store: resolveVercelBlobWorkspaceStore(options.store, options.env)
|
|
251
|
-
};
|
|
252
|
-
installHostedVercelBlobWorkspaceRuntime();
|
|
253
|
-
setWorkspaceRuntimeConfig(config);
|
|
254
|
-
return config;
|
|
255
|
-
}
|
|
256
|
-
//#endregion
|
|
257
|
-
export { installHostedVercelBlobWorkspaceRuntime as n, configureHostedVercelBlobWorkspaceRuntime as t };
|