@vite-hub/workspace 0.0.4 → 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.
Files changed (127) hide show
  1. package/README.md +225 -58
  2. package/dist/{ai-CjxvGqM0.d.ts → ai-BW2ZhizI.d.ts} +22 -7
  3. package/dist/{ai-BqCC8BpY.js → ai-BZyLwULx.js} +147 -66
  4. package/dist/ai.d.ts +2 -2
  5. package/dist/ai.js +1 -1
  6. package/dist/{asset-registry-8QI3ML3K.js → asset-registry-DfBV5kmw.js} +3 -2
  7. package/dist/association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js +19 -0
  8. package/dist/blob-database.d.ts +521 -0
  9. package/dist/blob-database.js +601 -0
  10. package/dist/cloudflare.d.ts +5 -6
  11. package/dist/cloudflare.js +1 -1
  12. package/dist/config-B7dmzDX3.js +1112 -0
  13. package/dist/{config-DE9xlaIw.d.ts → config-DLKdaFWN.d.ts} +1 -2
  14. package/dist/error-diagnostics-A_8Kp-48.js +116 -0
  15. package/dist/error-diagnostics-DY5GP47p.js +96 -0
  16. package/dist/events-7EBoeIPd-A2RUkJi5-BxrICQ17.js +354 -0
  17. package/dist/events-CRaLy7U3-3PNNp5WZ-Gv9nd0cH.js +214 -0
  18. package/dist/events-CeChclTf-CX-gD8oy-4aL2j6V-.js +527 -0
  19. package/dist/feed-DsC7Vws1-M_de2nSK-tKc0Pwo8.js +248 -0
  20. package/dist/feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js +179 -0
  21. package/dist/file-C0_aPWSS.js +26 -0
  22. package/dist/file-metadata-CxDy-E2H.js +58 -0
  23. package/dist/{files-Q6xZjDHA.js → files-C7Px8uaC.js} +3 -3
  24. package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +2278 -0
  25. package/dist/{github-DHnjxQIX.js → github-CPxHtFB7.js} +16 -23
  26. package/dist/github-DtncTfmv-Du2S8lGF.js +4159 -0
  27. package/dist/gitlab-BoDm8-BC-xzZsW9eW.js +2530 -0
  28. package/dist/glob--XcLlcml.js +22 -0
  29. package/dist/glob--kNYDbfU.js +30 -0
  30. package/dist/graphql-DG5aJBT3-DceyFYdM-C4saqX37.js +489 -0
  31. package/dist/{host-DJH8cuoU.js → host-CFnrTXTK.js} +97 -41
  32. package/dist/{hosted-RPeJOCFz.js → hosted-acMA5XyL.js} +102 -19
  33. package/dist/hosted-vercel-blob-DKntsHaf.js +12603 -0
  34. package/dist/hosted-vercel-blob.d.ts +5 -6
  35. package/dist/hosted-vercel-blob.js +1 -1
  36. package/dist/hosted.d.ts +6 -7
  37. package/dist/hosted.js +1 -1
  38. package/dist/index.d.ts +57 -36
  39. package/dist/index.js +56 -56
  40. package/dist/inspect-BoObD2cJ.js +167 -0
  41. package/dist/internal/path.d.ts +2 -0
  42. package/dist/internal/path.js +2 -0
  43. package/dist/lifecycle-BwZ7c9hb.js +596 -0
  44. package/dist/loader.d.ts +5 -6
  45. package/dist/loader.js +3 -2
  46. package/dist/mcp-resources-BREFCmtn.js +39 -0
  47. package/dist/memory-BbwOqDXl.js +248 -0
  48. package/dist/metadata-target-DZEZQGHA.js +1588 -0
  49. package/dist/mountx.d.ts +4 -6
  50. package/dist/mountx.js +10 -8
  51. package/dist/nitro.d.ts +1 -1
  52. package/dist/nitro.js +1 -1
  53. package/dist/nuxt.d.ts +13 -12
  54. package/dist/nuxt.js +4 -8
  55. package/dist/operations-BcpWr41m.js +159 -0
  56. package/dist/operations-CGqY1XeG.js +965 -0
  57. package/dist/operations-DnOwKsJT.d.ts +136 -0
  58. package/dist/operations.d.ts +53 -0
  59. package/dist/operations.js +2 -0
  60. package/dist/path-CNAwN7pw.js +114 -0
  61. package/dist/path-DrSIenjj.js +59 -0
  62. package/dist/path-zHxQUbqa.d.ts +9 -0
  63. package/dist/plugins-DqQ8b4T5.d.ts +10 -0
  64. package/dist/provider-kXjfli9u.js +1457 -0
  65. package/dist/providers/github/store.d.ts +3 -5
  66. package/dist/providers/github/store.js +1 -1
  67. package/dist/{registry-D3yzt8HQ.js → registry-Bp-8UUfG.js} +9 -7
  68. package/dist/{registry-Uj6IVxes.d.ts → registry-Cg1TJVVZ.d.ts} +1 -2
  69. package/dist/{request-execution-B-dSFlGB.js → request-execution-Dk9rY-Yh.js} +19 -19
  70. package/dist/{chunk-2rV9d50f.js → rolldown-runtime-B4iAMlE-.js} +2 -2
  71. package/dist/runtime/assets.d.ts +3 -5
  72. package/dist/runtime/assets.js +7 -6
  73. package/dist/runtime/empty-assets-registry.d.ts +1 -2
  74. package/dist/runtime/empty-registry.d.ts +1 -2
  75. package/dist/runtime/state.d.ts +3 -3
  76. package/dist/runtime/state.js +6 -6
  77. package/dist/runtime/workspace.d.ts +1 -1
  78. package/dist/runtime/workspace.js +1 -1
  79. package/dist/runtime.d.ts +51 -17
  80. package/dist/runtime.js +320 -60
  81. package/dist/{search-BpiCF2Tw.js → search-CrTmXj5h.js} +10 -9
  82. package/dist/server-BNQ-Nbjj.js +290 -0
  83. package/dist/server.d.ts +22 -34
  84. package/dist/server.js +2 -328
  85. package/dist/shared-DalXdP0i.js +2158 -0
  86. package/dist/source-metadata.d.ts +6 -7
  87. package/dist/source-metadata.js +7 -7
  88. package/dist/{state-tYcRWEh2.d.ts → state-B8zbLi5t.d.ts} +3 -3
  89. package/dist/store-CXgmu-uw.js +1729 -0
  90. package/dist/{sync-DnTQwt8r.js → sync-CN6ec-5M.js} +61 -41
  91. package/dist/templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js +125 -0
  92. package/dist/test.d.ts +1 -1
  93. package/dist/test.js +1 -1
  94. package/dist/{token-CVzURBxC.js → token-CO62GglH.js} +3 -3
  95. package/dist/{types-CYuwjJ4V.d.ts → types-DeK9GIxy.d.ts} +256 -24
  96. package/dist/{use-BTNDR5Rd.js → use-BQj7nSz6.js} +82 -41
  97. package/dist/{use-BiHzt0xA.d.ts → use-DhwhbAVV.d.ts} +16 -11
  98. package/dist/utils-Blrh4N2n.js +545 -0
  99. package/dist/vite-BEvgU2GY.js +20909 -0
  100. package/dist/vite-CcZmMQ7S.d.ts +476 -0
  101. package/dist/vite.d.ts +2 -2
  102. package/dist/vite.js +2 -2
  103. package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +1565 -0
  104. package/dist/{workspace-Dq08Yn72.js → workspace-6pxkOuxr.js} +361 -230
  105. package/dist/{workspace-Xddf4G1B.d.ts → workspace-BWJQBK1u.d.ts} +4 -3
  106. package/package.json +89 -55
  107. package/dist/collections/client.d.ts +0 -39
  108. package/dist/collections/client.js +0 -137
  109. package/dist/collections.d.ts +0 -59
  110. package/dist/collections.js +0 -159
  111. package/dist/config-Bc3c4Su1.js +0 -7904
  112. package/dist/config-CHLLWklZ.js +0 -36
  113. package/dist/file-Bc1X7pco.js +0 -23
  114. package/dist/glob-CEZKeZFC.js +0 -18
  115. package/dist/hosted-vercel-blob-d6C8ND5j.js +0 -23580
  116. package/dist/lifecycle-LrL3sA4n.js +0 -316
  117. package/dist/metadata-target-B0tOmVW7.js +0 -717
  118. package/dist/path-Cp59koVz.js +0 -139
  119. package/dist/provider-B1yLjCJJ.js +0 -746
  120. package/dist/publish.d.ts +0 -35
  121. package/dist/publish.js +0 -112
  122. package/dist/runtime-options-BsPSv5O7.js +0 -13
  123. package/dist/runtime-type-iEE6BjQJ.js +0 -34
  124. package/dist/shared-DTR1Hhma.js +0 -331
  125. package/dist/store-Dt_Jyys3.js +0 -608
  126. package/dist/vite-BptCrpv2.js +0 -4526
  127. package/dist/vite-CtA9guIM.d.ts +0 -66
@@ -1,10 +1,7 @@
1
- import { n as __exportAll } from "./chunk-2rV9d50f.js";
2
- import { l as normalizeWorkspacePath } from "./path-Cp59koVz.js";
1
+ import { n as __exportAll } from "./rolldown-runtime-B4iAMlE-.js";
2
+ import { l as normalizeWorkspacePath } from "./path-CNAwN7pw.js";
3
3
  //#region src/core/search.ts
4
- var search_exports = /* @__PURE__ */ __exportAll({
5
- searchText: () => searchText,
6
- toSearchRegExp: () => toSearchRegExp
7
- });
4
+ var search_exports = /* @__PURE__ */ __exportAll({ searchText: () => searchText });
8
5
  function toSearchRegExp(query) {
9
6
  const source = query.regex ? query.pattern : escapeRegExp(query.pattern);
10
7
  return new RegExp(source, query.caseSensitive ? "g" : "gi");
@@ -12,10 +9,12 @@ function toSearchRegExp(query) {
12
9
  function searchText(path, content, query) {
13
10
  const result = [];
14
11
  const expression = toSearchRegExp(query);
15
- const lines = content.split(/\r?\n/);
16
12
  const limit = query.limit ?? 100;
17
- for (let index = 0; index < lines.length && result.length < limit; index++) {
18
- const line = lines[index];
13
+ let start = 0;
14
+ for (let index = 0; start <= content.length && result.length < limit; index++) {
15
+ const newline = content.indexOf("\n", start);
16
+ const end = newline === -1 ? content.length : newline;
17
+ const line = content.slice(start, newline !== -1 && content[end - 1] === "\r" ? end - 1 : end);
19
18
  expression.lastIndex = 0;
20
19
  let match = expression.exec(line);
21
20
  while (match && result.length < limit) {
@@ -29,6 +28,8 @@ function searchText(path, content, query) {
29
28
  if (match[0] === "") expression.lastIndex += 1;
30
29
  match = expression.exec(line);
31
30
  }
31
+ if (newline === -1) break;
32
+ start = newline + 1;
32
33
  }
33
34
  return result;
34
35
  }
@@ -0,0 +1,290 @@
1
+ import { t as normalizeSafeWorkspacePath } from "./path-DrSIenjj.js";
2
+ import { s as matchesAny } from "./path-CNAwN7pw.js";
3
+ import { t as workspaceErrorDiagnostics } from "./error-diagnostics-DY5GP47p.js";
4
+ import { _ as workspaceDefinitionPlugins, h as resolveWorkspaceAutoCommit } from "./utils-Blrh4N2n.js";
5
+ import { r as withWorkspaceProgress } from "./host-CFnrTXTK.js";
6
+ import { t as useWorkspace } from "./use-BQj7nSz6.js";
7
+ import { hasRuntimeType } from "@vite-hub/runtime/internal/runtime-type";
8
+ import { getViteHubErrorShape } from "@vite-hub/runtime";
9
+ import { lookup } from "mrmime";
10
+ import { createError, defineEventHandler, getRouterParam } from "h3";
11
+ //#region ../internal/src/secret.ts
12
+ const secretEncoder = new TextEncoder();
13
+ /**
14
+ * Compares a request value with an expected secret in constant time for the length of `expected`. Returns `false`
15
+ * when either value is missing or empty. It uses no Node API, so it also runs in Worker runtimes.
16
+ */
17
+ function isViteHubSecretEqual(actual, expected) {
18
+ if (!actual || !expected) return false;
19
+ const left = secretEncoder.encode(actual);
20
+ const right = secretEncoder.encode(expected);
21
+ let difference = left.length ^ right.length;
22
+ for (let index = 0; index < right.length; index += 1) difference |= (left[index] ?? 0) ^ right[index];
23
+ return difference === 0;
24
+ }
25
+ //#endregion
26
+ //#region src/server.ts
27
+ const workspaceDevRoute = "/__vitehub/workspace/dev";
28
+ const workspaceDevHeader = "x-vitehub-workspace-dev";
29
+ const workspaceDevHeaderValue = "1";
30
+ const workspaceDevTokenHeader = "x-vitehub-dev-token";
31
+ function hasWorkspaceCommitRules(definition) {
32
+ return [...Object.values(definition.rules || {}), ...workspaceDefinitionPlugins(definition).flatMap((plugin) => Object.values(plugin.rules || {}))].some((rule) => rule.commit !== void 0);
33
+ }
34
+ const workspaceDevTokensKey = Symbol.for("vitehub.workspace.devTokens");
35
+ function workspaceDevTokens() {
36
+ const scope = globalThis;
37
+ scope[workspaceDevTokensKey] ??= /* @__PURE__ */ new Map();
38
+ return scope[workspaceDevTokensKey];
39
+ }
40
+ function workspaceDevTokenServerId(port) {
41
+ return `${process.pid}:${port ?? "unknown"}`;
42
+ }
43
+ async function workspaceDevTokenRoot(rootDir, options = {}) {
44
+ const [{ createHash }, { tmpdir }, { join, resolve }] = await Promise.all([
45
+ import("node:crypto"),
46
+ import("node:os"),
47
+ import("node:path")
48
+ ]);
49
+ const resolvedRoot = resolve(rootDir);
50
+ const rootKey = createHash("sha256").update(resolvedRoot).digest("hex");
51
+ const serverKey = createHash("sha256").update(options.serverId || "default").digest("hex");
52
+ return {
53
+ file: join(tmpdir(), "vitehub-workspace-dev", rootKey, serverKey, "dev-token"),
54
+ key: `${rootKey}:${serverKey}`
55
+ };
56
+ }
57
+ function headerValue(headers, name, expectedToken) {
58
+ try {
59
+ const prototype = Object.getPrototypeOf(headers);
60
+ const constructor = prototype ? Object.getOwnPropertyDescriptor(prototype, "constructor")?.value : void 0;
61
+ const constructorSource = hasRuntimeType(constructor, "function") ? Function.prototype.toString.call(constructor) : "";
62
+ const prototypeGet = prototype ? Object.getOwnPropertyDescriptor(prototype, "get")?.value : void 0;
63
+ const realmHeaders = typeof Headers === "function" ? Headers : void 0;
64
+ if (hasRuntimeType(constructor, "function") && Reflect.get(constructor, "name") === "Headers" && (constructor === realmHeaders || /^class\s+Headers\b/.test(constructorSource) && constructorSource.includes("#") || /^function\s+Headers\(\)\s*\{\s*\[native code\]\s*\}$/.test(constructorSource) || constructorSource.includes("webidl.brandCheck") || constructorSource.includes("#")) && Reflect.get(constructor, "prototype") === prototype && (() => {
65
+ try {
66
+ return headers instanceof constructor;
67
+ } catch {
68
+ return false;
69
+ }
70
+ })() && hasRuntimeType(prototypeGet, "function")) {
71
+ const get = typeof Headers === "function" ? Reflect.get(Headers.prototype, "get") : void 0;
72
+ for (const getter of [get, prototypeGet]) {
73
+ if (!hasRuntimeType(getter, "function")) continue;
74
+ try {
75
+ const value = Reflect.apply(getter, headers, [name]);
76
+ return hasRuntimeType(value, "string") && value ? value : void 0;
77
+ } catch {}
78
+ }
79
+ }
80
+ try {
81
+ const ownGet = Object.hasOwn(headers, "get") ? Reflect.get(headers, "get") : void 0;
82
+ if (hasRuntimeType(ownGet, "function")) {
83
+ const value = Reflect.apply(ownGet, headers, [name]);
84
+ return hasRuntimeType(value, "string") && value ? value : void 0;
85
+ }
86
+ if (!Object.hasOwn(headers, name)) return void 0;
87
+ const value = Reflect.get(headers, name);
88
+ if (Array.isArray(value)) return hasRuntimeType(value[0], "string") ? value[0] : void 0;
89
+ return hasRuntimeType(value, "string") ? value : void 0;
90
+ } catch {
91
+ return;
92
+ }
93
+ } catch {
94
+ return;
95
+ }
96
+ }
97
+ function randomToken() {
98
+ return [...globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32))].map((byte) => byte.toString(16).padStart(2, "0")).join("");
99
+ }
100
+ async function refreshWorkspaceDevToken(rootDir, options = {}) {
101
+ const token = randomToken();
102
+ const tokenRoot = await workspaceDevTokenRoot(rootDir, options);
103
+ workspaceDevTokens().set(tokenRoot.key, token);
104
+ const [{ mkdir, writeFile }, { dirname }] = await Promise.all([import("node:fs/promises"), import("node:path")]);
105
+ const file = tokenRoot.file;
106
+ await mkdir(dirname(file), {
107
+ mode: 448,
108
+ recursive: true
109
+ });
110
+ await writeFile(file, `${token}\n`, { mode: 384 });
111
+ return token;
112
+ }
113
+ async function ensureWorkspaceDevToken(rootDir, options = {}) {
114
+ return workspaceDevTokens().get((await workspaceDevTokenRoot(rootDir, options)).key) || await refreshWorkspaceDevToken(rootDir, options);
115
+ }
116
+ async function readWorkspaceDevToken(rootDir, options = {}) {
117
+ try {
118
+ const { readFile } = await import("node:fs/promises");
119
+ return (await readFile((await workspaceDevTokenRoot(rootDir, options)).file, "utf8")).trim() || void 0;
120
+ } catch (error) {
121
+ if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") return;
122
+ throw error;
123
+ }
124
+ }
125
+ async function validateWorkspaceDevToken(rootDir, headers, options = {}) {
126
+ const expectedToken = await ensureWorkspaceDevToken(rootDir, options);
127
+ return isViteHubSecretEqual(headerValue(headers, workspaceDevTokenHeader, expectedToken), expectedToken);
128
+ }
129
+ async function resolveWorkspace(workspace) {
130
+ if (typeof workspace === "string") return useWorkspace(workspace);
131
+ if (typeof workspace === "function") return await workspace();
132
+ return workspace;
133
+ }
134
+ function resolveWorkspaceFilePath(path, root) {
135
+ const normalizedPath = normalizeSafeWorkspacePath(path, { allowEmpty: false });
136
+ if (!root) return normalizedPath;
137
+ return `${normalizeSafeWorkspacePath(root, { allowEmpty: false })}/${normalizedPath}`;
138
+ }
139
+ function resolveContentType(path, mediaType, contentTypes) {
140
+ if (mediaType) return mediaType;
141
+ if (contentTypes && Object.hasOwn(contentTypes, path) && contentTypes[path]) return contentTypes[path];
142
+ const extension = path.includes(".") ? `.${path.split(".").at(-1)}` : "";
143
+ if (extension && contentTypes && Object.hasOwn(contentTypes, extension) && contentTypes[extension]) return contentTypes[extension];
144
+ return lookup(path) || "application/octet-stream";
145
+ }
146
+ function errorMessage(error) {
147
+ if (Object(error) !== error) return;
148
+ try {
149
+ const message = Object.getOwnPropertyDescriptor(error, "message")?.value;
150
+ return message === String(message) ? String(message) : void 0;
151
+ } catch {
152
+ return;
153
+ }
154
+ }
155
+ function isNotFoundError(error) {
156
+ const code = getViteHubErrorShape(error)?.code;
157
+ const message = errorMessage(error);
158
+ return code === "WORKSPACE_NOT_FOUND" || code === "WORKSPACE_PATH_INVALID" || message?.includes("Workspace file does not exist:") === true || message?.includes("Workspace path does not exist:") === true;
159
+ }
160
+ function workspaceSessionStarter(input) {
161
+ return input && typeof input === "object" && typeof input.startSession === "function" ? input : void 0;
162
+ }
163
+ function workspaceSourceMaterializer(input) {
164
+ return input && typeof input === "object" && typeof input.materializeSources === "function" ? input.materializeSources.bind(input) : void 0;
165
+ }
166
+ async function materializeWorkspaceDevSources(workspace, input) {
167
+ const materialize = workspaceSourceMaterializer(workspace) ?? workspaceSourceMaterializer(workspace.fs);
168
+ if (!materialize) return;
169
+ const paths = input.paths?.length ? input.paths : [""];
170
+ await withWorkspaceProgress(input.onProgress, {
171
+ data: { paths },
172
+ id: "workspace.dev.materialize",
173
+ label: "Materializing workspace sources"
174
+ }, async () => {
175
+ await Promise.all(paths.map(async (path) => {
176
+ await materialize({
177
+ abortSignal: input.abortSignal,
178
+ onProgress: async (event) => await input.onProgress?.({
179
+ data: { ...event },
180
+ durationMs: event.durationMs,
181
+ error: event.error,
182
+ id: `workspace.dev.materialize.${event.source}`,
183
+ label: `Materializing source ${event.source}`,
184
+ status: event.status
185
+ }),
186
+ path
187
+ }).catch((error) => {
188
+ if (path && isNotFoundError(error)) return;
189
+ throw error;
190
+ });
191
+ }));
192
+ });
193
+ }
194
+ async function readWorkspaceFileResponse(options) {
195
+ let filePath;
196
+ try {
197
+ filePath = resolveWorkspaceFilePath(options.path, options.root);
198
+ if (!matchesAny(filePath, options.allow)) throw createError({
199
+ statusCode: 404,
200
+ statusMessage: "Workspace file not found."
201
+ });
202
+ } catch (error) {
203
+ if (isNotFoundError(error)) throw createError({
204
+ statusCode: 404,
205
+ statusMessage: "Workspace file not found."
206
+ });
207
+ throw error;
208
+ }
209
+ const workspace = await resolveWorkspace(options.workspace);
210
+ try {
211
+ const [content, stat] = await Promise.all([workspace.fs.readFile(filePath, { encoding: "binary" }), workspace.fs.stat(filePath)]);
212
+ if (stat.type !== "file") throw createError({
213
+ statusCode: 404,
214
+ statusMessage: "Workspace file not found."
215
+ });
216
+ const headers = new Headers(options.headers);
217
+ headers.set("content-type", resolveContentType(filePath, stat.mediaType, options.contentTypes));
218
+ headers.set("x-content-type-options", "nosniff");
219
+ if (options.cacheControl) headers.set("cache-control", options.cacheControl);
220
+ return new Response(content, { headers });
221
+ } catch (error) {
222
+ if (isNotFoundError(error)) throw createError({
223
+ statusCode: 404,
224
+ statusMessage: "Workspace file not found."
225
+ });
226
+ throw error;
227
+ }
228
+ }
229
+ function defineWorkspaceFileHandler(options) {
230
+ return defineEventHandler((event) => {
231
+ const path = getRouterParam(event, options.param || "path") || "";
232
+ return readWorkspaceFileResponse({
233
+ ...options,
234
+ path
235
+ });
236
+ });
237
+ }
238
+ async function runWorkspaceDevCommand(input) {
239
+ const command = input.command.trim();
240
+ if (!command) throw workspaceErrorDiagnostics.WORKSPACE_R0040({ message: "Workspace Dev command cannot be empty." });
241
+ const definition = input.definition;
242
+ const workspace = typeof input.workspace === "string" ? await useWorkspace(input.workspace, definition ? {
243
+ definition,
244
+ mode: "write"
245
+ } : { mode: "write" }) : input.workspace;
246
+ const starter = workspaceSessionStarter(workspace) ?? workspaceSessionStarter(workspace.fs);
247
+ const startSession = starter?.startSession.bind(starter);
248
+ if (!startSession) throw workspaceErrorDiagnostics.WORKSPACE_R0041({ message: "Workspace Dev command requires a Workspace Session." });
249
+ await materializeWorkspaceDevSources(workspace, input);
250
+ let session;
251
+ const execOptions = {
252
+ abortSignal: input.abortSignal,
253
+ timeout: input.timeout
254
+ };
255
+ let result;
256
+ try {
257
+ await withWorkspaceProgress(input.onProgress, {
258
+ data: { paths: input.paths ?? null },
259
+ id: "workspace.dev.start-session",
260
+ label: "Starting workspace session"
261
+ }, async () => {
262
+ session = await startSession({
263
+ abortSignal: input.abortSignal,
264
+ host: input.host,
265
+ paths: input.paths
266
+ });
267
+ return session;
268
+ });
269
+ if (!session) throw workspaceErrorDiagnostics.WORKSPACE_R0042({ message: "Workspace Dev Session did not start." });
270
+ result = input.args ? await session.exec(command, input.args, execOptions) : await session.exec("sh", ["-lc", command], execOptions);
271
+ const diff = result.exitCode === 0 ? await session.diff() : void 0;
272
+ if (diff?.entries.length) {
273
+ const commit = definition ? resolveWorkspaceAutoCommit(definition, diff) : void 0;
274
+ if (!definition || !hasWorkspaceCommitRules(definition) || commit) await session.commit({ message: commit?.message || "workspace dev command" });
275
+ }
276
+ } catch (error) {
277
+ if (!session) throw error;
278
+ try {
279
+ await session.close();
280
+ } catch (closeError) {
281
+ throw new AggregateError([error, closeError], "[vitehub] Workspace Dev command failed and session cleanup also failed.");
282
+ }
283
+ throw error;
284
+ }
285
+ if (!session) throw workspaceErrorDiagnostics.WORKSPACE_R0043({ message: "Workspace Dev Session did not start." });
286
+ await session.close();
287
+ return result;
288
+ }
289
+ //#endregion
290
+ export { refreshWorkspaceDevToken as a, workspaceDevHeader as c, workspaceDevTokenHeader as d, workspaceDevTokenServerId as f, readWorkspaceFileResponse as i, workspaceDevHeaderValue as l, ensureWorkspaceDevToken as n, runWorkspaceDevCommand as o, isViteHubSecretEqual as p, readWorkspaceDevToken as r, validateWorkspaceDevToken as s, defineWorkspaceFileHandler as t, workspaceDevRoute as u };
package/dist/server.d.ts CHANGED
@@ -1,19 +1,17 @@
1
- import { F as WorkspaceDefinition, _t as WorkspaceSession, i as ExecResult, it as WorkspaceName, st as WorkspacePrepareSessionProgressEvent, vt as WorkspaceSessionHost, xt as WorkspaceSessionOptions } from "./types-CYuwjJ4V.js";
2
- import { i as ReadonlyWorkspaceFacade, m as WritableWorkspaceFacade } from "./use-BiHzt0xA.js";
3
- import { WorkspaceCollectionOptions, WorkspaceCollectionSort } from "./collections.js";
1
+ import { Et as WorkspacePrepareSessionProgressEvent, F as WorkspaceDefinition, Ht as WorkspaceSessionOptions, Rt as WorkspaceSession, St as WorkspaceName, i as ExecResult, zt as WorkspaceSessionHost } from "./types-DeK9GIxy.js";
2
+ import { i as ReadonlyWorkspaceFacade, m as WritableWorkspaceFacade } from "./use-DhwhbAVV.js";
4
3
  import { defineEventHandler } from "h3";
5
-
6
4
  //#region src/server.d.ts
7
- declare const workspaceDevRoute = "/__vitehub/workspace/dev";
8
- declare const workspaceDevHeader = "x-vitehub-workspace-dev";
9
- declare const workspaceDevHeaderValue = "1";
10
- declare const workspaceDevTokenHeader = "x-vitehub-dev-token";
5
+ export declare const workspaceDevRoute = "/__vitehub/workspace/dev";
6
+ export declare const workspaceDevHeader = "x-vitehub-workspace-dev";
7
+ export declare const workspaceDevHeaderValue = "1";
8
+ export declare const workspaceDevTokenHeader = "x-vitehub-dev-token";
11
9
  type WorkspaceInput<Name extends WorkspaceName> = Name | ReadonlyWorkspaceFacade<Name> | WritableWorkspaceFacade<Name> | (() => ReadonlyWorkspaceFacade<Name> | WritableWorkspaceFacade<Name> | Promise<ReadonlyWorkspaceFacade<Name> | WritableWorkspaceFacade<Name>>);
12
10
  type WorkspaceSessionStarter = {
13
11
  startSession(options?: WorkspaceSessionOptions): Promise<WorkspaceSession>;
14
12
  };
15
13
  type ResponseHeaders = ConstructorParameters<typeof Headers>[0];
16
- interface WorkspaceFileResponseOptions<Name extends WorkspaceName = WorkspaceName> {
14
+ export interface WorkspaceFileResponseOptions<Name extends WorkspaceName = WorkspaceName> {
17
15
  allow?: string[];
18
16
  cacheControl?: string;
19
17
  contentTypes?: Record<string, string>;
@@ -22,21 +20,10 @@ interface WorkspaceFileResponseOptions<Name extends WorkspaceName = WorkspaceNam
22
20
  root?: string;
23
21
  workspace: WorkspaceInput<Name>;
24
22
  }
25
- interface WorkspaceFileHandlerOptions<Name extends WorkspaceName = WorkspaceName> extends Omit<WorkspaceFileResponseOptions<Name>, "path"> {
23
+ export interface WorkspaceFileHandlerOptions<Name extends WorkspaceName = WorkspaceName> extends Omit<WorkspaceFileResponseOptions<Name>, "path"> {
26
24
  param?: string;
27
25
  }
28
- interface WorkspaceCollectionHandlerOptions<Name extends WorkspaceName = WorkspaceName> extends WorkspaceCollectionOptions<Name> {
29
- facets?: string[];
30
- filters?: string[];
31
- item?: {
32
- key: string;
33
- select?: string[];
34
- };
35
- searchFields?: string[];
36
- select?: string[];
37
- sort?: WorkspaceCollectionSort;
38
- }
39
- interface WorkspaceDevCommandInput<Name extends WorkspaceName = WorkspaceName> {
26
+ export interface WorkspaceDevCommandInput<Name extends WorkspaceName = WorkspaceName> {
40
27
  abortSignal?: AbortSignal;
41
28
  args?: string[];
42
29
  command: string;
@@ -49,17 +36,18 @@ interface WorkspaceDevCommandInput<Name extends WorkspaceName = WorkspaceName> {
49
36
  fs: ReadonlyWorkspaceFacade<Name>["fs"] & Partial<WorkspaceSessionStarter>;
50
37
  });
51
38
  }
52
- interface WorkspaceDevTokenOptions {
39
+ export interface WorkspaceDevTokenOptions {
53
40
  serverId?: string;
54
41
  }
55
- declare function workspaceDevTokenServerId(port?: number | string | null): string;
56
- declare function refreshWorkspaceDevToken(rootDir: string, options?: WorkspaceDevTokenOptions): Promise<string>;
57
- declare function ensureWorkspaceDevToken(rootDir: string, options?: WorkspaceDevTokenOptions): Promise<string>;
58
- declare function readWorkspaceDevToken(rootDir: string, options?: WorkspaceDevTokenOptions): Promise<string | undefined>;
59
- declare function validateWorkspaceDevToken(rootDir: string, headers: Headers | Record<string, string | string[] | undefined>, options?: WorkspaceDevTokenOptions): Promise<boolean>;
60
- declare function readWorkspaceFileResponse<Name extends WorkspaceName>(options: WorkspaceFileResponseOptions<Name>): Promise<Response>;
61
- declare function defineWorkspaceFileHandler<Name extends WorkspaceName>(options: WorkspaceFileHandlerOptions<Name>): ReturnType<typeof defineEventHandler>;
62
- declare function defineWorkspaceCollectionHandler<Name extends WorkspaceName>(options: WorkspaceCollectionHandlerOptions<Name>): ReturnType<typeof defineEventHandler>;
63
- declare function runWorkspaceDevCommand<Name extends WorkspaceName>(input: WorkspaceDevCommandInput<Name>): Promise<ExecResult>;
64
- //#endregion
65
- export { WorkspaceCollectionHandlerOptions, WorkspaceDevCommandInput, WorkspaceDevTokenOptions, WorkspaceFileHandlerOptions, WorkspaceFileResponseOptions, defineWorkspaceCollectionHandler, defineWorkspaceFileHandler, ensureWorkspaceDevToken, readWorkspaceDevToken, readWorkspaceFileResponse, refreshWorkspaceDevToken, runWorkspaceDevCommand, validateWorkspaceDevToken, workspaceDevHeader, workspaceDevHeaderValue, workspaceDevRoute, workspaceDevTokenHeader, workspaceDevTokenServerId };
42
+ export declare function workspaceDevTokenServerId(port?: number | string | null): string;
43
+ type WorkspaceDevHeaders = Headers | Record<string, string | string[] | undefined> | {
44
+ get(name: string): string | null;
45
+ };
46
+ export declare function refreshWorkspaceDevToken(rootDir: string, options?: WorkspaceDevTokenOptions): Promise<string>;
47
+ export declare function ensureWorkspaceDevToken(rootDir: string, options?: WorkspaceDevTokenOptions): Promise<string>;
48
+ export declare function readWorkspaceDevToken(rootDir: string, options?: WorkspaceDevTokenOptions): Promise<string | undefined>;
49
+ export declare function validateWorkspaceDevToken(rootDir: string, headers: WorkspaceDevHeaders, options?: WorkspaceDevTokenOptions): Promise<boolean>;
50
+ export declare function readWorkspaceFileResponse<Name extends WorkspaceName>(options: WorkspaceFileResponseOptions<Name>): Promise<Response>;
51
+ export declare function defineWorkspaceFileHandler<Name extends WorkspaceName>(options: WorkspaceFileHandlerOptions<Name>): ReturnType<typeof defineEventHandler>;
52
+ export declare function runWorkspaceDevCommand<Name extends WorkspaceName>(input: WorkspaceDevCommandInput<Name>): Promise<ExecResult>;
53
+ //#endregion