@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/server.js
CHANGED
|
@@ -1,355 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
|
|
3
|
-
import { t as useWorkspace } from "./use-CsV3oIxH.js";
|
|
4
|
-
import { getWorkspaceCollectionItem, queryWorkspaceCollection, workspaceCollectionEmpty } from "./collections.js";
|
|
5
|
-
import { getViteHubErrorShape } from "@vite-hub/runtime";
|
|
6
|
-
import { lookup } from "mrmime";
|
|
7
|
-
import { createError, defineEventHandler, getQuery, getRouterParam } from "h3";
|
|
8
|
-
//#region src/server.ts
|
|
9
|
-
const workspaceDevRoute = "/__vitehub/workspace/dev";
|
|
10
|
-
const workspaceDevHeader = "x-vitehub-workspace-dev";
|
|
11
|
-
const workspaceDevHeaderValue = "1";
|
|
12
|
-
const workspaceDevTokenHeader = "x-vitehub-dev-token";
|
|
13
|
-
function hasWorkspaceCommitRules(definition) {
|
|
14
|
-
return [...Object.values(definition.rules || {}), ...(definition.plugins || []).flatMap((plugin) => Object.values(plugin.rules || {}))].some((rule) => rule.commit !== void 0);
|
|
15
|
-
}
|
|
16
|
-
const workspaceDevTokensKey = Symbol.for("vitehub.workspace.devTokens");
|
|
17
|
-
function workspaceDevTokens() {
|
|
18
|
-
const scope = globalThis;
|
|
19
|
-
scope[workspaceDevTokensKey] ??= /* @__PURE__ */ new Map();
|
|
20
|
-
return scope[workspaceDevTokensKey];
|
|
21
|
-
}
|
|
22
|
-
function workspaceDevTokenServerId(port) {
|
|
23
|
-
return `${process.pid}:${port ?? "unknown"}`;
|
|
24
|
-
}
|
|
25
|
-
async function workspaceDevTokenRoot(rootDir, options = {}) {
|
|
26
|
-
const [{ createHash }, { tmpdir }, { join, resolve }] = await Promise.all([
|
|
27
|
-
import("node:crypto"),
|
|
28
|
-
import("node:os"),
|
|
29
|
-
import("node:path")
|
|
30
|
-
]);
|
|
31
|
-
const resolvedRoot = resolve(rootDir);
|
|
32
|
-
const rootKey = createHash("sha256").update(resolvedRoot).digest("hex");
|
|
33
|
-
const serverKey = createHash("sha256").update(options.serverId || "default").digest("hex");
|
|
34
|
-
return {
|
|
35
|
-
file: join(tmpdir(), "vitehub-workspace-dev", rootKey, serverKey, "dev-token"),
|
|
36
|
-
key: `${rootKey}:${serverKey}`,
|
|
37
|
-
legacyFile: join(resolvedRoot, ".vitehub", "dev-token")
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
function headerValue(headers, name) {
|
|
41
|
-
if (headers instanceof Headers) return headers.get(name) || void 0;
|
|
42
|
-
const value = headers[name];
|
|
43
|
-
return Array.isArray(value) ? value[0] : value;
|
|
44
|
-
}
|
|
45
|
-
function randomToken() {
|
|
46
|
-
return [...globalThis.crypto.getRandomValues(new Uint8Array(32))].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
47
|
-
}
|
|
48
|
-
async function refreshWorkspaceDevToken(rootDir, options = {}) {
|
|
49
|
-
const token = randomToken();
|
|
50
|
-
const tokenRoot = await workspaceDevTokenRoot(rootDir, options);
|
|
51
|
-
workspaceDevTokens().set(tokenRoot.key, token);
|
|
52
|
-
const [{ mkdir, rm, writeFile }, { dirname }] = await Promise.all([import("node:fs/promises"), import("node:path")]);
|
|
53
|
-
const file = tokenRoot.file;
|
|
54
|
-
await mkdir(dirname(file), {
|
|
55
|
-
mode: 448,
|
|
56
|
-
recursive: true
|
|
57
|
-
});
|
|
58
|
-
await rm(tokenRoot.legacyFile, { force: true });
|
|
59
|
-
await writeFile(file, `${token}\n`, { mode: 384 });
|
|
60
|
-
return token;
|
|
61
|
-
}
|
|
62
|
-
async function ensureWorkspaceDevToken(rootDir, options = {}) {
|
|
63
|
-
return workspaceDevTokens().get((await workspaceDevTokenRoot(rootDir, options)).key) || await refreshWorkspaceDevToken(rootDir, options);
|
|
64
|
-
}
|
|
65
|
-
async function readWorkspaceDevToken(rootDir, options = {}) {
|
|
66
|
-
try {
|
|
67
|
-
const { readFile } = await import("node:fs/promises");
|
|
68
|
-
return (await readFile((await workspaceDevTokenRoot(rootDir, options)).file, "utf8")).trim() || void 0;
|
|
69
|
-
} catch (error) {
|
|
70
|
-
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") return;
|
|
71
|
-
throw error;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
async function validateWorkspaceDevToken(rootDir, headers, options = {}) {
|
|
75
|
-
const token = headerValue(headers, workspaceDevTokenHeader);
|
|
76
|
-
return typeof token === "string" && token === await ensureWorkspaceDevToken(rootDir, options);
|
|
77
|
-
}
|
|
78
|
-
async function resolveWorkspace(workspace) {
|
|
79
|
-
if (typeof workspace === "string") return useWorkspace(workspace);
|
|
80
|
-
if (typeof workspace === "function") return await workspace();
|
|
81
|
-
return workspace;
|
|
82
|
-
}
|
|
83
|
-
function resolveWorkspaceFilePath(path, root) {
|
|
84
|
-
const normalizedPath = normalizeSafeWorkspacePath(path, { allowEmpty: false });
|
|
85
|
-
if (!root) return normalizedPath;
|
|
86
|
-
return `${normalizeSafeWorkspacePath(root, { allowEmpty: false })}/${normalizedPath}`;
|
|
87
|
-
}
|
|
88
|
-
function resolveContentType(path, mediaType, contentTypes) {
|
|
89
|
-
if (mediaType) return mediaType;
|
|
90
|
-
if (contentTypes?.[path]) return contentTypes[path];
|
|
91
|
-
const extension = path.includes(".") ? `.${path.split(".").at(-1)}` : "";
|
|
92
|
-
if (extension && contentTypes?.[extension]) return contentTypes[extension];
|
|
93
|
-
return lookup(path) || "application/octet-stream";
|
|
94
|
-
}
|
|
95
|
-
function isNotFoundError(error) {
|
|
96
|
-
const code = getViteHubErrorShape(error)?.code;
|
|
97
|
-
return code === "WORKSPACE_NOT_FOUND" || code === "WORKSPACE_PATH_INVALID" || error instanceof Error && error.message.includes("Workspace file does not exist:") || error instanceof Error && error.message.includes("Workspace path does not exist:");
|
|
98
|
-
}
|
|
99
|
-
var WorkspaceCollectionRequestError = class extends Error {};
|
|
100
|
-
function collectionQueryValue(query, key) {
|
|
101
|
-
const value = query[key];
|
|
102
|
-
if (value === void 0) return;
|
|
103
|
-
if (Array.isArray(value)) throw new WorkspaceCollectionRequestError(`Workspace collection query parameter "${key}" must have one value.`);
|
|
104
|
-
return value;
|
|
105
|
-
}
|
|
106
|
-
function collectionLimit(query) {
|
|
107
|
-
const value = collectionQueryValue(query, "limit");
|
|
108
|
-
if (value === void 0) return;
|
|
109
|
-
if (!/^\d+$/.test(value)) throw new WorkspaceCollectionRequestError("Workspace collection limit must be a positive integer.");
|
|
110
|
-
const limit = Number(value);
|
|
111
|
-
if (!Number.isSafeInteger(limit) || limit < 1) throw new WorkspaceCollectionRequestError("Workspace collection limit must be a positive integer.");
|
|
112
|
-
return limit;
|
|
113
|
-
}
|
|
114
|
-
function collectionFilters(query, allowed) {
|
|
115
|
-
const filters = {};
|
|
116
|
-
const allowedFields = new Set(allowed || []);
|
|
117
|
-
for (const [key, value] of Object.entries(query)) {
|
|
118
|
-
if (!key.startsWith("filter.") && !key.startsWith("empty.")) continue;
|
|
119
|
-
const empty = key.startsWith("empty.");
|
|
120
|
-
const field = key.slice(empty ? 6 : 7);
|
|
121
|
-
if (!allowedFields.has(field)) throw new WorkspaceCollectionRequestError(`Workspace collection filter "${field}" is not allowed.`);
|
|
122
|
-
if (empty) {
|
|
123
|
-
if (value !== "true") throw new WorkspaceCollectionRequestError(`Workspace collection empty filter "${field}" must be true.`);
|
|
124
|
-
filters[field] = workspaceCollectionEmpty;
|
|
125
|
-
continue;
|
|
126
|
-
}
|
|
127
|
-
filters[field] = (Array.isArray(value) ? value : [value]).map((item) => item.trim());
|
|
128
|
-
}
|
|
129
|
-
return filters;
|
|
130
|
-
}
|
|
131
|
-
function parseWorkspaceCollectionQuery(query, options) {
|
|
132
|
-
for (const key of Object.keys(query)) if (![
|
|
133
|
-
"cursor",
|
|
134
|
-
"limit",
|
|
135
|
-
"search",
|
|
136
|
-
"value"
|
|
137
|
-
].includes(key) && !key.startsWith("filter.") && !key.startsWith("empty.")) throw new WorkspaceCollectionRequestError(`Workspace collection query parameter "${key}" is not allowed.`);
|
|
138
|
-
const itemValue = collectionQueryValue(query, "value");
|
|
139
|
-
if (itemValue !== void 0 && !options.item) throw new WorkspaceCollectionRequestError("Workspace collection item lookup is not enabled.");
|
|
140
|
-
const search = collectionQueryValue(query, "search");
|
|
141
|
-
if (search && !options.searchFields?.length) throw new WorkspaceCollectionRequestError("Workspace collection search is not enabled.");
|
|
142
|
-
return {
|
|
143
|
-
itemValue,
|
|
144
|
-
page: {
|
|
145
|
-
cursor: collectionQueryValue(query, "cursor"),
|
|
146
|
-
facets: options.facets,
|
|
147
|
-
filters: collectionFilters(query, options.filters),
|
|
148
|
-
limit: collectionLimit(query),
|
|
149
|
-
search,
|
|
150
|
-
searchFields: options.searchFields,
|
|
151
|
-
select: options.select,
|
|
152
|
-
sort: options.sort
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
function workspaceSessionStarter(input) {
|
|
157
|
-
return input && typeof input === "object" && typeof input.startSession === "function" ? input : void 0;
|
|
158
|
-
}
|
|
159
|
-
function workspaceSourceMaterializer(input) {
|
|
160
|
-
return input && typeof input === "object" && typeof input.materializeSources === "function" ? input.materializeSources.bind(input) : void 0;
|
|
161
|
-
}
|
|
162
|
-
async function withWorkspaceDevProgress(onProgress, event, fn) {
|
|
163
|
-
const startedAt = Date.now();
|
|
164
|
-
await onProgress?.({
|
|
165
|
-
data: event.data,
|
|
166
|
-
id: event.id,
|
|
167
|
-
label: event.label,
|
|
168
|
-
status: "started"
|
|
169
|
-
});
|
|
170
|
-
try {
|
|
171
|
-
const result = await fn();
|
|
172
|
-
await onProgress?.({
|
|
173
|
-
data: event.data,
|
|
174
|
-
durationMs: Date.now() - startedAt,
|
|
175
|
-
id: event.id,
|
|
176
|
-
label: event.label,
|
|
177
|
-
status: "completed"
|
|
178
|
-
});
|
|
179
|
-
return result;
|
|
180
|
-
} catch (error) {
|
|
181
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
182
|
-
await onProgress?.({
|
|
183
|
-
data: {
|
|
184
|
-
...event.data,
|
|
185
|
-
error: message
|
|
186
|
-
},
|
|
187
|
-
durationMs: Date.now() - startedAt,
|
|
188
|
-
error: message,
|
|
189
|
-
id: event.id,
|
|
190
|
-
label: event.label,
|
|
191
|
-
status: "failed"
|
|
192
|
-
});
|
|
193
|
-
throw error;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
async function materializeWorkspaceDevSources(workspace, input) {
|
|
197
|
-
const materialize = workspaceSourceMaterializer(workspace) ?? workspaceSourceMaterializer(workspace.fs);
|
|
198
|
-
if (!materialize) return;
|
|
199
|
-
const paths = input.paths?.length ? input.paths : [""];
|
|
200
|
-
await withWorkspaceDevProgress(input.onProgress, {
|
|
201
|
-
data: { paths },
|
|
202
|
-
id: "workspace.dev.materialize",
|
|
203
|
-
label: "Materializing workspace sources"
|
|
204
|
-
}, async () => {
|
|
205
|
-
await Promise.all(paths.map(async (path) => {
|
|
206
|
-
await materialize({
|
|
207
|
-
abortSignal: input.abortSignal,
|
|
208
|
-
onProgress: async (event) => await input.onProgress?.({
|
|
209
|
-
data: { ...event },
|
|
210
|
-
durationMs: event.durationMs,
|
|
211
|
-
error: event.error,
|
|
212
|
-
id: `workspace.dev.materialize.${event.source}`,
|
|
213
|
-
label: `Materializing source ${event.source}`,
|
|
214
|
-
status: event.status
|
|
215
|
-
}),
|
|
216
|
-
path
|
|
217
|
-
}).catch((error) => {
|
|
218
|
-
if (path && isNotFoundError(error)) return;
|
|
219
|
-
throw error;
|
|
220
|
-
});
|
|
221
|
-
}));
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
async function readWorkspaceFileResponse(options) {
|
|
225
|
-
let filePath;
|
|
226
|
-
try {
|
|
227
|
-
filePath = resolveWorkspaceFilePath(options.path, options.root);
|
|
228
|
-
if (!matchesAny(filePath, options.allow)) throw createError({
|
|
229
|
-
statusCode: 404,
|
|
230
|
-
statusMessage: "Workspace file not found."
|
|
231
|
-
});
|
|
232
|
-
} catch (error) {
|
|
233
|
-
if (isNotFoundError(error)) throw createError({
|
|
234
|
-
statusCode: 404,
|
|
235
|
-
statusMessage: "Workspace file not found."
|
|
236
|
-
});
|
|
237
|
-
throw error;
|
|
238
|
-
}
|
|
239
|
-
const workspace = await resolveWorkspace(options.workspace);
|
|
240
|
-
try {
|
|
241
|
-
const [content, stat] = await Promise.all([workspace.fs.readFile(filePath, { encoding: "binary" }), workspace.fs.stat(filePath)]);
|
|
242
|
-
if (stat.type !== "file") throw createError({
|
|
243
|
-
statusCode: 404,
|
|
244
|
-
statusMessage: "Workspace file not found."
|
|
245
|
-
});
|
|
246
|
-
const headers = new Headers(options.headers);
|
|
247
|
-
headers.set("content-type", resolveContentType(filePath, stat.mediaType, options.contentTypes));
|
|
248
|
-
headers.set("x-content-type-options", "nosniff");
|
|
249
|
-
if (options.cacheControl) headers.set("cache-control", options.cacheControl);
|
|
250
|
-
return new Response(content, { headers });
|
|
251
|
-
} catch (error) {
|
|
252
|
-
if (isNotFoundError(error)) throw createError({
|
|
253
|
-
statusCode: 404,
|
|
254
|
-
statusMessage: "Workspace file not found."
|
|
255
|
-
});
|
|
256
|
-
throw error;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
function defineWorkspaceFileHandler(options) {
|
|
260
|
-
return defineEventHandler((event) => {
|
|
261
|
-
const path = getRouterParam(event, options.param || "path") || "";
|
|
262
|
-
return readWorkspaceFileResponse({
|
|
263
|
-
...options,
|
|
264
|
-
path
|
|
265
|
-
});
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
function defineWorkspaceCollectionHandler(options) {
|
|
269
|
-
return defineEventHandler(async (event) => {
|
|
270
|
-
try {
|
|
271
|
-
const parsed = parseWorkspaceCollectionQuery(getQuery(event), options);
|
|
272
|
-
if (parsed.itemValue !== void 0 && options.item) return await getWorkspaceCollectionItem({
|
|
273
|
-
...options,
|
|
274
|
-
query: {
|
|
275
|
-
key: options.item.key,
|
|
276
|
-
select: options.item.select,
|
|
277
|
-
value: parsed.itemValue
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
return await queryWorkspaceCollection({
|
|
281
|
-
...options,
|
|
282
|
-
query: parsed.page
|
|
283
|
-
});
|
|
284
|
-
} catch (error) {
|
|
285
|
-
if (error instanceof WorkspaceCollectionRequestError) throw createError({
|
|
286
|
-
cause: error,
|
|
287
|
-
statusCode: 400,
|
|
288
|
-
statusMessage: error.message
|
|
289
|
-
});
|
|
290
|
-
if (getViteHubErrorShape(error)?.code === "WORKSPACE_COLLECTION_CURSOR_INVALID") {
|
|
291
|
-
const reason = getViteHubErrorShape(error)?.details?.reason;
|
|
292
|
-
throw createError({
|
|
293
|
-
cause: error,
|
|
294
|
-
statusCode: reason === "stale" ? 409 : 400,
|
|
295
|
-
statusMessage: error instanceof Error ? error.message : "Invalid workspace collection cursor."
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
if (isNotFoundError(error)) throw createError({
|
|
299
|
-
cause: error,
|
|
300
|
-
statusCode: 404,
|
|
301
|
-
statusMessage: "Workspace collection not found."
|
|
302
|
-
});
|
|
303
|
-
throw createError({
|
|
304
|
-
cause: error,
|
|
305
|
-
statusCode: 500,
|
|
306
|
-
statusMessage: "Workspace collection query failed."
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
async function runWorkspaceDevCommand(input) {
|
|
312
|
-
const command = input.command.trim();
|
|
313
|
-
if (!command) throw new Error("Workspace Dev command cannot be empty.");
|
|
314
|
-
const definition = input.definition;
|
|
315
|
-
const workspace = typeof input.workspace === "string" ? await useWorkspace(input.workspace, definition ? {
|
|
316
|
-
definition,
|
|
317
|
-
mode: "write"
|
|
318
|
-
} : { mode: "write" }) : input.workspace;
|
|
319
|
-
const starter = workspaceSessionStarter(workspace) ?? workspaceSessionStarter(workspace.fs);
|
|
320
|
-
const startSession = starter?.startSession.bind(starter);
|
|
321
|
-
if (!startSession) throw new Error("Workspace Dev command requires a Workspace Session.");
|
|
322
|
-
await materializeWorkspaceDevSources(workspace, input);
|
|
323
|
-
const session = await withWorkspaceDevProgress(input.onProgress, {
|
|
324
|
-
data: { paths: input.paths ?? null },
|
|
325
|
-
id: "workspace.dev.start-session",
|
|
326
|
-
label: "Starting workspace session"
|
|
327
|
-
}, async () => await startSession({
|
|
328
|
-
host: input.host,
|
|
329
|
-
paths: input.paths
|
|
330
|
-
}));
|
|
331
|
-
const execOptions = {
|
|
332
|
-
abortSignal: input.abortSignal,
|
|
333
|
-
timeout: input.timeout
|
|
334
|
-
};
|
|
335
|
-
let result;
|
|
336
|
-
try {
|
|
337
|
-
result = input.args ? await session.exec(command, input.args, execOptions) : await session.exec("sh", ["-lc", command], execOptions);
|
|
338
|
-
const diff = result.exitCode === 0 ? await session.diff() : void 0;
|
|
339
|
-
if (diff?.entries.length) {
|
|
340
|
-
const commit = definition ? resolveWorkspaceAutoCommit(definition, diff) : void 0;
|
|
341
|
-
if (!definition || !hasWorkspaceCommitRules(definition) || commit) await session.commit({ message: commit?.message || "workspace dev command" });
|
|
342
|
-
}
|
|
343
|
-
} catch (error) {
|
|
344
|
-
try {
|
|
345
|
-
await session.close();
|
|
346
|
-
} catch (closeError) {
|
|
347
|
-
throw new AggregateError([error, closeError], "[vitehub] Workspace Dev command failed and session cleanup also failed.");
|
|
348
|
-
}
|
|
349
|
-
throw error;
|
|
350
|
-
}
|
|
351
|
-
await session.close();
|
|
352
|
-
return result;
|
|
353
|
-
}
|
|
354
|
-
//#endregion
|
|
355
|
-
export { defineWorkspaceCollectionHandler, defineWorkspaceFileHandler, ensureWorkspaceDevToken, readWorkspaceDevToken, readWorkspaceFileResponse, refreshWorkspaceDevToken, runWorkspaceDevCommand, validateWorkspaceDevToken, workspaceDevHeader, workspaceDevHeaderValue, workspaceDevRoute, workspaceDevTokenHeader, workspaceDevTokenServerId };
|
|
1
|
+
import { a as refreshWorkspaceDevToken, c as workspaceDevHeader, d as workspaceDevTokenHeader, f as workspaceDevTokenServerId, i as readWorkspaceFileResponse, l as workspaceDevHeaderValue, n as ensureWorkspaceDevToken, o as runWorkspaceDevCommand, r as readWorkspaceDevToken, s as validateWorkspaceDevToken, t as defineWorkspaceFileHandler, u as workspaceDevRoute } from "./server-BNQ-Nbjj.js";
|
|
2
|
+
export { defineWorkspaceFileHandler, ensureWorkspaceDevToken, readWorkspaceDevToken, readWorkspaceFileResponse, refreshWorkspaceDevToken, runWorkspaceDevCommand, validateWorkspaceDevToken, workspaceDevHeader, workspaceDevHeaderValue, workspaceDevRoute, workspaceDevTokenHeader, workspaceDevTokenServerId };
|