@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.
Files changed (129) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +236 -58
  3. package/dist/{ai-nmHdzjCM.d.ts → ai-BW2ZhizI.d.ts} +22 -7
  4. package/dist/{ai-Ce3PtWFW.js → ai-BZyLwULx.js} +147 -66
  5. package/dist/ai.d.ts +2 -2
  6. package/dist/ai.js +1 -1
  7. package/dist/{asset-registry-CaG9b7tf.js → asset-registry-DfBV5kmw.js} +3 -2
  8. package/dist/association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js +19 -0
  9. package/dist/blob-database.d.ts +521 -0
  10. package/dist/blob-database.js +601 -0
  11. package/dist/cloudflare.d.ts +5 -6
  12. package/dist/cloudflare.js +1 -1
  13. package/dist/config-B7dmzDX3.js +1112 -0
  14. package/dist/{config-3I1BnsdO.d.ts → config-DLKdaFWN.d.ts} +1 -2
  15. package/dist/error-diagnostics-A_8Kp-48.js +116 -0
  16. package/dist/error-diagnostics-DY5GP47p.js +96 -0
  17. package/dist/events-7EBoeIPd-A2RUkJi5-BxrICQ17.js +354 -0
  18. package/dist/events-CRaLy7U3-3PNNp5WZ-Gv9nd0cH.js +214 -0
  19. package/dist/events-CeChclTf-CX-gD8oy-4aL2j6V-.js +527 -0
  20. package/dist/feed-DsC7Vws1-M_de2nSK-tKc0Pwo8.js +248 -0
  21. package/dist/feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js +179 -0
  22. package/dist/file-C0_aPWSS.js +26 -0
  23. package/dist/file-metadata-CxDy-E2H.js +58 -0
  24. package/dist/{files-QRV55OCx.js → files-C7Px8uaC.js} +21 -10
  25. package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +2278 -0
  26. package/dist/{github-CfA5vpJ5.js → github-CPxHtFB7.js} +36 -34
  27. package/dist/github-DtncTfmv-Du2S8lGF.js +4159 -0
  28. package/dist/gitlab-BoDm8-BC-xzZsW9eW.js +2530 -0
  29. package/dist/glob--XcLlcml.js +22 -0
  30. package/dist/glob--kNYDbfU.js +30 -0
  31. package/dist/graphql-DG5aJBT3-DceyFYdM-C4saqX37.js +489 -0
  32. package/dist/host-CFnrTXTK.js +1086 -0
  33. package/dist/{hosted-C1-tTTTf.js → hosted-acMA5XyL.js} +216 -43
  34. package/dist/hosted-vercel-blob-DKntsHaf.js +12603 -0
  35. package/dist/hosted-vercel-blob.d.ts +5 -6
  36. package/dist/hosted-vercel-blob.js +1 -1
  37. package/dist/hosted.d.ts +6 -7
  38. package/dist/hosted.js +1 -1
  39. package/dist/index.d.ts +76 -64
  40. package/dist/index.js +162 -457
  41. package/dist/inspect-BoObD2cJ.js +167 -0
  42. package/dist/internal/path.d.ts +2 -0
  43. package/dist/internal/path.js +2 -0
  44. package/dist/lifecycle-BwZ7c9hb.js +596 -0
  45. package/dist/loader.d.ts +5 -6
  46. package/dist/loader.js +3 -2
  47. package/dist/mcp-resources-BREFCmtn.js +39 -0
  48. package/dist/memory-BbwOqDXl.js +248 -0
  49. package/dist/metadata-target-DZEZQGHA.js +1588 -0
  50. package/dist/mountx.d.ts +4 -6
  51. package/dist/mountx.js +10 -8
  52. package/dist/nitro.d.ts +1 -1
  53. package/dist/nitro.js +1 -1
  54. package/dist/nuxt.d.ts +13 -12
  55. package/dist/nuxt.js +10 -8
  56. package/dist/operations-BcpWr41m.js +159 -0
  57. package/dist/operations-CGqY1XeG.js +965 -0
  58. package/dist/operations-DnOwKsJT.d.ts +136 -0
  59. package/dist/operations.d.ts +53 -0
  60. package/dist/operations.js +2 -0
  61. package/dist/{path-CNI6wKIU.js → path-CNAwN7pw.js} +34 -35
  62. package/dist/path-DrSIenjj.js +59 -0
  63. package/dist/path-zHxQUbqa.d.ts +9 -0
  64. package/dist/plugins-DqQ8b4T5.d.ts +10 -0
  65. package/dist/provider-kXjfli9u.js +1457 -0
  66. package/dist/providers/github/store.d.ts +3 -5
  67. package/dist/providers/github/store.js +1 -1
  68. package/dist/registry-Bp-8UUfG.js +129 -0
  69. package/dist/{registry-BIQVCBWI.d.ts → registry-Cg1TJVVZ.d.ts} +3 -4
  70. package/dist/{request-execution-u9mgUXKX.js → request-execution-Dk9rY-Yh.js} +24 -20
  71. package/dist/rolldown-runtime-B4iAMlE-.js +35 -0
  72. package/dist/runtime/assets.d.ts +3 -5
  73. package/dist/runtime/assets.js +9 -6
  74. package/dist/runtime/empty-assets-registry.d.ts +1 -2
  75. package/dist/runtime/empty-registry.d.ts +1 -2
  76. package/dist/runtime/state.d.ts +4 -4
  77. package/dist/runtime/state.js +10 -7
  78. package/dist/runtime/workspace.d.ts +1 -1
  79. package/dist/runtime/workspace.js +1 -1
  80. package/dist/runtime.d.ts +84 -15
  81. package/dist/runtime.js +561 -108
  82. package/dist/{search-C4REyHj9.js → search-CrTmXj5h.js} +10 -9
  83. package/dist/server-BNQ-Nbjj.js +290 -0
  84. package/dist/server.d.ts +22 -34
  85. package/dist/server.js +2 -355
  86. package/dist/shared-DalXdP0i.js +2158 -0
  87. package/dist/source-metadata.d.ts +7 -1
  88. package/dist/source-metadata.js +34 -2
  89. package/dist/{state-TTqa3x3Y.d.ts → state-B8zbLi5t.d.ts} +14 -13
  90. package/dist/store-CXgmu-uw.js +1729 -0
  91. package/dist/{sync-DiuDmSGk.js → sync-CN6ec-5M.js} +62 -41
  92. package/dist/templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js +125 -0
  93. package/dist/test.d.ts +1 -1
  94. package/dist/test.js +1 -1
  95. package/dist/token-CO62GglH.js +61 -0
  96. package/dist/{types-60Yn149G.d.ts → types-DeK9GIxy.d.ts} +348 -49
  97. package/dist/{use-CsV3oIxH.js → use-BQj7nSz6.js} +200 -45
  98. package/dist/{use-CUFSnFCS.d.ts → use-DhwhbAVV.d.ts} +34 -12
  99. package/dist/utils-Blrh4N2n.js +545 -0
  100. package/dist/vite-BEvgU2GY.js +20909 -0
  101. package/dist/vite-CcZmMQ7S.d.ts +476 -0
  102. package/dist/vite.d.ts +2 -50
  103. package/dist/vite.js +2 -2
  104. package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +1565 -0
  105. package/dist/workspace-6pxkOuxr.js +1286 -0
  106. package/dist/workspace-BWJQBK1u.d.ts +7 -0
  107. package/package.json +90 -59
  108. package/dist/chunk-8H4AJuhK.js +0 -14
  109. package/dist/collections/client.d.ts +0 -39
  110. package/dist/collections/client.js +0 -137
  111. package/dist/collections.d.ts +0 -59
  112. package/dist/collections.js +0 -159
  113. package/dist/config-CDoyls2X.js +0 -30
  114. package/dist/config-CZLO0m9h.js +0 -7811
  115. package/dist/file-CHfsZpso.js +0 -23
  116. package/dist/glob-D0vD_wRY.js +0 -17
  117. package/dist/host-CAnbugpI.js +0 -370
  118. package/dist/hosted-vercel-blob-CWBILDVo.js +0 -257
  119. package/dist/lifecycle-BYoa9hVb.js +0 -176
  120. package/dist/provider-C3_elpEh.js +0 -599
  121. package/dist/publish.d.ts +0 -35
  122. package/dist/publish.js +0 -112
  123. package/dist/registry-CqyDTW9Y.js +0 -74
  124. package/dist/runtime-options-BsPSv5O7.js +0 -13
  125. package/dist/shared-jfogBrd5.js +0 -273
  126. package/dist/store-Bs1SLh55.js +0 -414
  127. package/dist/vite-tbfDxtlu.js +0 -2191
  128. package/dist/workspace-66SKyiec.d.ts +0 -6
  129. package/dist/workspace-C4k92Ow8.js +0 -1460
package/dist/mountx.d.ts CHANGED
@@ -1,10 +1,8 @@
1
- import { ht as WorkspaceSession } from "./types-60Yn149G.js";
1
+ import { Rt as WorkspaceSession } from "./types-DeK9GIxy.js";
2
2
  import { FsDriver } from "mountx";
3
-
4
3
  //#region src/mountx.d.ts
5
- interface WorkspaceMountXDriverOptions {
4
+ export interface WorkspaceMountXDriverOptions {
6
5
  readOnly?: boolean;
7
6
  }
8
- declare function createWorkspaceDriver(session: WorkspaceSession, options?: WorkspaceMountXDriverOptions): FsDriver;
9
- //#endregion
10
- export { WorkspaceMountXDriverOptions, createWorkspaceDriver };
7
+ export declare function createWorkspaceDriver(session: WorkspaceSession, options?: WorkspaceMountXDriverOptions): FsDriver;
8
+ //#endregion
package/dist/mountx.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { o as isWorkspaceBytes } from "./path-CNAwN7pw.js";
2
+ import { t as workspaceErrorDiagnostics } from "./error-diagnostics-DY5GP47p.js";
1
3
  import { posix } from "node:path";
2
4
  import { createUnstorageDriver } from "mountx/drivers/unstorage";
3
5
  //#region src/mountx.ts
@@ -8,7 +10,7 @@ function pathToKey(path) {
8
10
  return path.split("/").join(":");
9
11
  }
10
12
  function valueToBytes(value) {
11
- if (value instanceof Uint8Array) return value;
13
+ if (isWorkspaceBytes(value)) return value;
12
14
  if (value instanceof ArrayBuffer) return new Uint8Array(value);
13
15
  if (ArrayBuffer.isView(value)) return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
14
16
  return new TextEncoder().encode(typeof value === "string" ? value : JSON.stringify(value));
@@ -20,7 +22,7 @@ async function findEntry(session, path) {
20
22
  }
21
23
  function assertProjectablePath(path) {
22
24
  const invalidName = path.split("/").find((segment) => segment.includes(":") || segment.includes("?") || segment.endsWith("$"));
23
- if (invalidName) throw Object.assign(/* @__PURE__ */ new Error(`Workspace filename is not representable as an unstorage key: ${invalidName}`), {
25
+ if (invalidName) throw Object.assign(workspaceErrorDiagnostics.WORKSPACE_R0031({ message: `Workspace filename is not representable as an unstorage key: ${invalidName}` }), {
24
26
  code: "EINVAL",
25
27
  path
26
28
  });
@@ -28,7 +30,7 @@ function assertProjectablePath(path) {
28
30
  function assertProjectableEntry(entry) {
29
31
  if (entry) assertProjectablePath(entry.path);
30
32
  if (entry?.metadata?.gitMode !== "120000") return entry;
31
- throw Object.assign(/* @__PURE__ */ new Error(`MountX cannot project Workspace symlink semantics: ${entry.path}`), {
33
+ throw Object.assign(workspaceErrorDiagnostics.WORKSPACE_R0032({ message: `MountX cannot project Workspace symlink semantics: ${entry.path}` }), {
32
34
  code: "ENOTSUP",
33
35
  path: entry.path
34
36
  });
@@ -64,20 +66,20 @@ function createWorkspaceStorage(session, readOnly) {
64
66
  async hasItem(key) {
65
67
  return assertProjectableEntry(await findEntry(session, keyToPath(key)))?.type === "file";
66
68
  },
67
- ...readOnly ? {} : {
69
+ ...!readOnly ? {
68
70
  async removeItem(key) {
69
71
  await session.rm(keyToPath(key), { force: true });
70
72
  },
71
73
  async setItemRaw(key, value) {
72
74
  const path = keyToPath(key);
73
75
  const entry = assertProjectableEntry(await findEntry(session, path));
74
- const writeOptions = value instanceof Uint8Array ? writeOptionsByValue.get(value) : void 0;
76
+ const writeOptions = isWorkspaceBytes(value) ? writeOptionsByValue.get(value) : void 0;
75
77
  await session.writeFile(path, valueToBytes(value), writeOptions ?? {
76
78
  mediaType: entry?.mediaType,
77
79
  metadata: entry?.metadata
78
80
  });
79
81
  }
80
- }
82
+ } : void 0
81
83
  };
82
84
  }
83
85
  function createWorkspaceDriver(session, options = {}) {
@@ -94,7 +96,7 @@ function createWorkspaceDriver(session, options = {}) {
94
96
  assertProjectablePath(path);
95
97
  return await projectStats(path, await driver.stat(path));
96
98
  }
97
- const singlePathMethods = new Set([
99
+ const singlePathMethods = /* @__PURE__ */ new Set([
98
100
  "chmod",
99
101
  "chown",
100
102
  "lchown",
@@ -108,7 +110,7 @@ function createWorkspaceDriver(session, options = {}) {
108
110
  "unlink",
109
111
  "utimes"
110
112
  ]);
111
- const twoPathMethods = new Set(["link", "rename"]);
113
+ const twoPathMethods = /* @__PURE__ */ new Set(["link", "rename"]);
112
114
  return new Proxy(driver, { get(target, property) {
113
115
  if (property === "stat" || property === "lstat") return stat;
114
116
  const value = Reflect.get(target, property, target);
package/dist/nitro.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { NitroConfig, WorkspaceNitroConfigOptions, createWorkspaceNitroConfig } from "./vite.js";
1
+ import { _ as createWorkspaceNitroConfig, m as WorkspaceNitroConfigOptions, p as NitroConfig } from "./vite-CcZmMQ7S.js";
2
2
  export { type NitroConfig, type WorkspaceNitroConfigOptions, createWorkspaceNitroConfig };
package/dist/nitro.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as createWorkspaceNitroConfig } from "./vite-tbfDxtlu.js";
1
+ import { t as createWorkspaceNitroConfig } from "./vite-BEvgU2GY.js";
2
2
  export { createWorkspaceNitroConfig };
package/dist/nuxt.d.ts CHANGED
@@ -1,26 +1,27 @@
1
- import { nt as WorkspaceModuleOptions } from "./types-60Yn149G.js";
2
-
1
+ import { xt as WorkspaceModuleOptions } from "./types-DeK9GIxy.js";
3
2
  //#region src/nuxt.d.ts
4
- interface WorkspaceNuxtModuleOptions extends WorkspaceModuleOptions {}
3
+ export interface WorkspaceNuxtModuleOptions extends WorkspaceModuleOptions {}
5
4
  type NuxtLike = {
6
5
  hook?: (name: "nitro:config", handler: (nitroConfig: Record<string, unknown>) => void | Promise<void>) => void;
7
6
  options: {
8
7
  alias?: Record<string, string>;
9
8
  dev?: boolean;
10
- imports?: {
11
- imports?: Array<{
12
- from: string;
13
- name: string;
14
- }>;
15
- };
16
9
  rootDir?: string;
10
+ serverDir?: string;
17
11
  srcDir?: string;
12
+ _layers?: ReadonlyArray<{
13
+ config?: {
14
+ rootDir?: string;
15
+ serverDir?: string;
16
+ srcDir?: string;
17
+ };
18
+ cwd?: string;
19
+ }>;
18
20
  vite?: {
19
21
  plugins?: unknown[];
20
22
  workspace?: false | WorkspaceModuleOptions;
21
23
  };
22
24
  };
23
25
  };
24
- declare function viteHubWorkspaceNuxtModule(options?: WorkspaceNuxtModuleOptions, nuxt?: NuxtLike): void;
25
- //#endregion
26
- export { WorkspaceNuxtModuleOptions, viteHubWorkspaceNuxtModule as default };
26
+ export default function viteHubWorkspaceNuxtModule(options?: WorkspaceNuxtModuleOptions, nuxt?: NuxtLike): void;
27
+ //#endregion
package/dist/nuxt.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as hubWorkspace, t as createWorkspaceNitroConfig } from "./vite-tbfDxtlu.js";
1
+ import { c as resolveNuxtServerDirs, n as hubWorkspace, r as setWorkspaceVitePluginHosting, t as createWorkspaceNitroConfig } from "./vite-BEvgU2GY.js";
2
2
  //#region src/nuxt.ts
3
3
  function isWorkspaceVitePlugin(value) {
4
4
  return Boolean(value && typeof value === "object" && value.name === "@vite-hub/workspace/vite");
@@ -9,23 +9,25 @@ function resolveWorkspaceOptions(options, viteOptions) {
9
9
  }
10
10
  function viteHubWorkspaceNuxtModule(options = {}, nuxt) {
11
11
  if (!nuxt) return;
12
- nuxt.options.imports ??= {};
13
- nuxt.options.imports.imports ??= [];
14
- for (const name of ["useWorkspaceCollection", "useWorkspaceCollectionItem"]) if (!nuxt.options.imports.imports.some((entry) => entry.name === name)) nuxt.options.imports.imports.push({
15
- from: "@vite-hub/workspace/collections/client",
16
- name
17
- });
18
12
  nuxt.options.vite ??= {};
19
13
  const workspaceOptions = resolveWorkspaceOptions(options, nuxt.options.vite.workspace);
14
+ let resolvedNitroHosting;
20
15
  const plugins = Array.isArray(nuxt.options.vite.plugins) ? nuxt.options.vite.plugins : [];
21
- if (!plugins.some(isWorkspaceVitePlugin)) plugins.push(hubWorkspace(workspaceOptions === false ? void 0 : workspaceOptions));
16
+ if (!plugins.some(isWorkspaceVitePlugin)) plugins.push(hubWorkspace({
17
+ ...workspaceOptions,
18
+ hosting: () => resolvedNitroHosting
19
+ }));
20
+ for (const plugin of plugins) if (isWorkspaceVitePlugin(plugin)) setWorkspaceVitePluginHosting(plugin, () => resolvedNitroHosting);
22
21
  nuxt.options.vite.plugins = plugins;
23
22
  nuxt.hook?.("nitro:config", async (nitroConfig) => {
23
+ resolvedNitroHosting = typeof nitroConfig.preset === "string" ? nitroConfig.preset : void 0;
24
24
  const rootDir = nuxt.options.rootDir || process.cwd();
25
25
  const nitro = await createWorkspaceNitroConfig({
26
26
  aliases: nuxt.options.alias,
27
27
  command: nuxt.options.dev ? "serve" : "build",
28
28
  nitro: nitroConfig,
29
+ plugins: nuxt.options.vite?.plugins,
30
+ serverDirs: resolveNuxtServerDirs(nuxt.options),
29
31
  viteRoot: nuxt.options.srcDir || rootDir,
30
32
  workspace: workspaceOptions
31
33
  });
@@ -0,0 +1,159 @@
1
+ import { t as useWorkspace } from "./use-BQj7nSz6.js";
2
+ import { t as redactInspectionText } from "./inspect-BoObD2cJ.js";
3
+ import { hasRuntimeType } from "@vite-hub/runtime/internal/runtime-type";
4
+ //#region src/runtime/operations.ts
5
+ const invalidRequestCodes = /* @__PURE__ */ new Set([
6
+ "WORKSPACE_PATH_INVALID",
7
+ "WORKSPACE_R0070",
8
+ "WORKSPACE_R0071"
9
+ ]);
10
+ /** A history read failure with its HTTP status. */
11
+ var WorkspaceOperationError = class extends Error {
12
+ code;
13
+ status;
14
+ constructor(code, status, message) {
15
+ super(message);
16
+ this.code = code;
17
+ this.status = status;
18
+ this.name = "WorkspaceOperationError";
19
+ }
20
+ };
21
+ /** Reads the code of a ViteHub error or a Workspace diagnostic. */
22
+ function errorCode(error) {
23
+ const code = Object(error) === error ? Reflect.get(Object(error), "code") : void 0;
24
+ return hasRuntimeType(code, "string") ? code : void 0;
25
+ }
26
+ function isoTime(value) {
27
+ const time = Date.parse(value);
28
+ return Number.isNaN(time) ? value : new Date(time).toISOString();
29
+ }
30
+ function describeRevision(revision) {
31
+ const author = revision.metadata?.author;
32
+ const result = {
33
+ ...revision,
34
+ createdAt: isoTime(revision.createdAt)
35
+ };
36
+ if (hasRuntimeType(author, "string") && author) result.author = author;
37
+ return result;
38
+ }
39
+ function describeFile(entry) {
40
+ const result = { path: entry.path };
41
+ if (entry.size !== void 0) result.size = entry.size;
42
+ if (entry.mediaType !== void 0) result.mediaType = entry.mediaType;
43
+ if (entry.digest !== void 0) result.digest = entry.digest;
44
+ return result;
45
+ }
46
+ function encodeContent(bytes) {
47
+ try {
48
+ return {
49
+ content: new TextDecoder("utf-8", { fatal: true }).decode(bytes),
50
+ encoding: "utf8"
51
+ };
52
+ } catch {
53
+ let binary = "";
54
+ for (let index = 0; index < bytes.length; index += 32768) binary += String.fromCharCode(...bytes.subarray(index, index + 32768));
55
+ return {
56
+ content: btoa(binary),
57
+ encoding: "base64"
58
+ };
59
+ }
60
+ }
61
+ async function listHistory(workspace, history, request) {
62
+ const limit = request.limit ?? 20;
63
+ if (request.ref !== void 0) {
64
+ const page = await history.list({
65
+ cursor: request.cursor,
66
+ limit,
67
+ ref: request.ref
68
+ });
69
+ return {
70
+ workspace,
71
+ ref: request.ref,
72
+ revisions: page.revisions.map(describeRevision),
73
+ cursor: page.cursor,
74
+ more: Boolean(page.cursor)
75
+ };
76
+ }
77
+ const pages = await Promise.all((await history.refs()).map(async (ref) => await history.list({
78
+ limit,
79
+ ref: ref.name
80
+ })));
81
+ const revisions = pages.flatMap((page) => page.revisions).map(describeRevision).sort((left, right) => Date.parse(right.createdAt) - Date.parse(left.createdAt));
82
+ return {
83
+ workspace,
84
+ revisions: revisions.slice(0, limit),
85
+ more: revisions.length > limit || pages.some((page) => page.cursor)
86
+ };
87
+ }
88
+ async function showRevision(workspace, history, request) {
89
+ const ref = (await history.refs()).find((entry) => entry.name === request.target);
90
+ let view;
91
+ try {
92
+ view = await history.open(ref ? ref.head.id : request.target);
93
+ } catch (error) {
94
+ if (errorCode(error) !== "WORKSPACE_NOT_FOUND") throw error;
95
+ throw new WorkspaceOperationError("WORKSPACE_NOT_FOUND", 404, `Workspace "${workspace}" has no ref or revision "${request.target}". Run \`vitehub workspace refs ${workspace}\` to list refs.`);
96
+ }
97
+ const revision = describeRevision(view.revision);
98
+ if (request.path === void 0) return {
99
+ workspace,
100
+ revision,
101
+ files: (await view.list("", { recursive: true })).filter((entry) => entry.type === "file").map(describeFile)
102
+ };
103
+ let stat;
104
+ try {
105
+ stat = await view.stat(request.path);
106
+ } catch (error) {
107
+ if (errorCode(error) !== "WORKSPACE_NOT_FOUND") throw error;
108
+ throw new WorkspaceOperationError("WORKSPACE_NOT_FOUND", 404, `Revision ${revision.id} has no path "${request.path}".`);
109
+ }
110
+ if (stat.type === "directory") {
111
+ const files = (await view.list(stat.path, { recursive: true })).filter((entry) => entry.type === "file").map(describeFile);
112
+ return {
113
+ workspace,
114
+ revision,
115
+ path: stat.path,
116
+ files
117
+ };
118
+ }
119
+ const bytes = await view.readFile(stat.path, { encoding: "binary" });
120
+ return {
121
+ workspace,
122
+ revision,
123
+ path: stat.path,
124
+ file: {
125
+ ...describeFile(stat),
126
+ ...encodeContent(bytes)
127
+ }
128
+ };
129
+ }
130
+ async function runWorkspaceOperation(operation, input) {
131
+ try {
132
+ if (operation === "history" && "cursor" in input && input.cursor !== void 0 && input.ref === void 0) throw new WorkspaceOperationError("WORKSPACE_HISTORY_INVALID", 400, "The cursor belongs to one ref. Pass the same ref.");
133
+ const { history } = useWorkspace(input.workspace);
134
+ if (operation === "refs") {
135
+ const refs = await history.refs();
136
+ return {
137
+ workspace: input.workspace,
138
+ refs: refs.map((ref) => ({
139
+ name: ref.name,
140
+ head: describeRevision(ref.head)
141
+ }))
142
+ };
143
+ }
144
+ if (operation === "history") return await listHistory(input.workspace, history, input);
145
+ return await showRevision(input.workspace, history, input);
146
+ } catch (error) {
147
+ throw describeFailure(input.workspace, error);
148
+ }
149
+ }
150
+ function describeFailure(workspace, error) {
151
+ if (error instanceof WorkspaceOperationError) return new WorkspaceOperationError(error.code, error.status, redactInspectionText(error.message));
152
+ const code = errorCode(error);
153
+ if (code === "WORKSPACE_R0069") return new WorkspaceOperationError(code, 409, `Workspace "${workspace}" has no retained history because its Store does not keep revisions. Use the Blob + Database Store, createBlobDatabaseWorkspaceStore() from @vite-hub/workspace/blob-database, to keep refs and revisions.`);
154
+ if (code === "WORKSPACE_NOT_FOUND" && error instanceof Error && error.message.includes(`Workspace "${workspace}" is not registered.`)) return new WorkspaceOperationError(code, 404, `Unknown Workspace: ${workspace}.`);
155
+ const status = code === "WORKSPACE_NOT_FOUND" ? 404 : code && invalidRequestCodes.has(code) ? 400 : 500;
156
+ return new WorkspaceOperationError(code ?? "WORKSPACE_HISTORY_FAILED", status, redactInspectionText(error instanceof Error ? error.message : String(error)));
157
+ }
158
+ //#endregion
159
+ export { runWorkspaceOperation };