@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.
- package/README.md +225 -58
- package/dist/{ai-CjxvGqM0.d.ts → ai-BW2ZhizI.d.ts} +22 -7
- package/dist/{ai-BqCC8BpY.js → ai-BZyLwULx.js} +147 -66
- package/dist/ai.d.ts +2 -2
- package/dist/ai.js +1 -1
- package/dist/{asset-registry-8QI3ML3K.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-DE9xlaIw.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-Q6xZjDHA.js → files-C7Px8uaC.js} +3 -3
- package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +2278 -0
- package/dist/{github-DHnjxQIX.js → github-CPxHtFB7.js} +16 -23
- 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-DJH8cuoU.js → host-CFnrTXTK.js} +97 -41
- package/dist/{hosted-RPeJOCFz.js → hosted-acMA5XyL.js} +102 -19
- 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 +57 -36
- package/dist/index.js +56 -56
- 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 +4 -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-CNAwN7pw.js +114 -0
- 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-D3yzt8HQ.js → registry-Bp-8UUfG.js} +9 -7
- package/dist/{registry-Uj6IVxes.d.ts → registry-Cg1TJVVZ.d.ts} +1 -2
- package/dist/{request-execution-B-dSFlGB.js → request-execution-Dk9rY-Yh.js} +19 -19
- package/dist/{chunk-2rV9d50f.js → rolldown-runtime-B4iAMlE-.js} +2 -2
- package/dist/runtime/assets.d.ts +3 -5
- package/dist/runtime/assets.js +7 -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 +3 -3
- package/dist/runtime/state.js +6 -6
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime.d.ts +51 -17
- package/dist/runtime.js +320 -60
- package/dist/{search-BpiCF2Tw.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 -328
- package/dist/shared-DalXdP0i.js +2158 -0
- package/dist/source-metadata.d.ts +6 -7
- package/dist/source-metadata.js +7 -7
- package/dist/{state-tYcRWEh2.d.ts → state-B8zbLi5t.d.ts} +3 -3
- package/dist/store-CXgmu-uw.js +1729 -0
- package/dist/{sync-DnTQwt8r.js → sync-CN6ec-5M.js} +61 -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-CVzURBxC.js → token-CO62GglH.js} +3 -3
- package/dist/{types-CYuwjJ4V.d.ts → types-DeK9GIxy.d.ts} +256 -24
- package/dist/{use-BTNDR5Rd.js → use-BQj7nSz6.js} +82 -41
- package/dist/{use-BiHzt0xA.d.ts → use-DhwhbAVV.d.ts} +16 -11
- 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 -2
- package/dist/vite.js +2 -2
- package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +1565 -0
- package/dist/{workspace-Dq08Yn72.js → workspace-6pxkOuxr.js} +361 -230
- package/dist/{workspace-Xddf4G1B.d.ts → workspace-BWJQBK1u.d.ts} +4 -3
- package/package.json +89 -55
- 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-Bc3c4Su1.js +0 -7904
- package/dist/config-CHLLWklZ.js +0 -36
- package/dist/file-Bc1X7pco.js +0 -23
- package/dist/glob-CEZKeZFC.js +0 -18
- package/dist/hosted-vercel-blob-d6C8ND5j.js +0 -23580
- package/dist/lifecycle-LrL3sA4n.js +0 -316
- package/dist/metadata-target-B0tOmVW7.js +0 -717
- package/dist/path-Cp59koVz.js +0 -139
- package/dist/provider-B1yLjCJJ.js +0 -746
- package/dist/publish.d.ts +0 -35
- package/dist/publish.js +0 -112
- package/dist/runtime-options-BsPSv5O7.js +0 -13
- package/dist/runtime-type-iEE6BjQJ.js +0 -34
- package/dist/shared-DTR1Hhma.js +0 -331
- package/dist/store-Dt_Jyys3.js +0 -608
- package/dist/vite-BptCrpv2.js +0 -4526
- package/dist/vite-CtA9guIM.d.ts +0 -66
package/dist/mountx.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
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
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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
|
|
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 {
|
|
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-
|
|
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 {
|
|
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
|
-
|
|
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, r as setWorkspaceVitePluginHosting, t as createWorkspaceNitroConfig } from "./vite-
|
|
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,18 +9,12 @@ 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);
|
|
20
14
|
let resolvedNitroHosting;
|
|
21
15
|
const plugins = Array.isArray(nuxt.options.vite.plugins) ? nuxt.options.vite.plugins : [];
|
|
22
16
|
if (!plugins.some(isWorkspaceVitePlugin)) plugins.push(hubWorkspace({
|
|
23
|
-
...workspaceOptions
|
|
17
|
+
...workspaceOptions,
|
|
24
18
|
hosting: () => resolvedNitroHosting
|
|
25
19
|
}));
|
|
26
20
|
for (const plugin of plugins) if (isWorkspaceVitePlugin(plugin)) setWorkspaceVitePluginHosting(plugin, () => resolvedNitroHosting);
|
|
@@ -32,6 +26,8 @@ function viteHubWorkspaceNuxtModule(options = {}, nuxt) {
|
|
|
32
26
|
aliases: nuxt.options.alias,
|
|
33
27
|
command: nuxt.options.dev ? "serve" : "build",
|
|
34
28
|
nitro: nitroConfig,
|
|
29
|
+
plugins: nuxt.options.vite?.plugins,
|
|
30
|
+
serverDirs: resolveNuxtServerDirs(nuxt.options),
|
|
35
31
|
viteRoot: nuxt.options.srcDir || rootDir,
|
|
36
32
|
workspace: workspaceOptions
|
|
37
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 };
|