@vite-hub/workspace 0.0.1 → 0.0.2
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 +190 -17
- package/dist/{ai-Bk3LLnit.js → ai-Cztw4eLk.js} +149 -29
- package/dist/ai-hFdsvDHC.d.ts +162 -0
- package/dist/ai.d.ts +2 -85
- package/dist/ai.js +1 -1
- package/dist/artifacts-store-BAV9jZpd.js +555 -0
- package/dist/asset-registry-CaG9b7tf.js +19 -0
- package/dist/cli.d.ts +31 -0
- package/dist/cli.js +303 -0
- package/dist/cloudflare-env-CKxUs2fa.js +20 -0
- package/dist/cloudflare.d.ts +16 -0
- package/dist/cloudflare.js +3 -0
- package/dist/collections/client.d.ts +39 -0
- package/dist/collections/client.js +137 -0
- package/dist/collections.d.ts +59 -0
- package/dist/collections.js +159 -0
- package/dist/config--r5unwPc.js +7811 -0
- package/dist/config-Ca5DM8fF.d.ts +28 -0
- package/dist/config-DCQ6y30R.js +30 -0
- package/dist/file-B2q9NE18.js +24 -0
- package/dist/{files-DbsIjBya.js → files-xy0le-_U.js} +6 -5
- package/dist/github-lIO6-2sH.js +194 -0
- package/dist/glob-DeH0dzZX.js +23 -0
- package/dist/host-I-_vDs05.js +370 -0
- package/dist/hosted-vercel-blob.d.ts +15 -0
- package/dist/hosted-vercel-blob.js +26 -0
- package/dist/hosted.d.ts +18 -0
- package/dist/hosted.js +30 -0
- package/dist/index.d.ts +137 -102
- package/dist/index.js +479 -594
- package/dist/lifecycle-Lhk3dAMt.js +176 -0
- package/dist/loader.d.ts +1 -1
- package/dist/loader.js +1 -1
- package/dist/nitro.d.ts +2 -31
- package/dist/nitro.js +2 -2
- package/dist/nuxt.d.ts +26 -0
- package/dist/nuxt.js +36 -0
- package/dist/path-CNI6wKIU.js +115 -0
- package/dist/{provider-BZuKAV4e.js → provider-CeQciesl.js} +142 -37
- package/dist/providers/cloudflare/artifacts-store.d.ts +1 -1
- package/dist/providers/cloudflare/artifacts-store.js +1 -383
- package/dist/providers/github/store.d.ts +6 -0
- package/dist/providers/github/store.js +362 -0
- package/dist/providers/vercel/blob-store.d.ts +1 -1
- package/dist/providers/vercel/blob-store.js +77 -18
- package/dist/publish.d.ts +3 -2
- package/dist/publish.js +48 -142
- package/dist/registry-C7DMdBXN.js +74 -0
- package/dist/{registry-D4Qzq26I.d.ts → registry-CoC9JxVt.d.ts} +3 -2
- package/dist/request-execution-C8qRcReq.js +80 -0
- package/dist/runtime/assets.d.ts +2 -1
- package/dist/runtime/assets.js +5 -5
- package/dist/runtime/empty-assets-registry.d.ts +1 -1
- package/dist/runtime/empty-registry.d.ts +1 -1
- package/dist/runtime/state.d.ts +4 -21
- package/dist/runtime/state.js +7 -4
- package/dist/runtime/workspace.d.ts +2 -0
- package/dist/runtime/workspace.js +2 -0
- package/dist/runtime.d.ts +38 -0
- package/dist/runtime.js +643 -0
- package/dist/{search-DtaEyjpO.js → search-C4REyHj9.js} +2 -2
- package/dist/server.d.ts +65 -0
- package/dist/server.js +355 -0
- package/dist/shared-BRycRSbo.js +255 -0
- package/dist/source-metadata.d.ts +2 -0
- package/dist/source-metadata.js +2 -0
- package/dist/state-DSAHEsq6.d.ts +25 -0
- package/dist/sync-DO42ypji.js +269 -0
- package/dist/target-D4Bqb1eH.js +11 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/types-DHkae7Cb.d.ts +628 -0
- package/dist/use-D16tf8Ph.d.ts +86 -0
- package/dist/use-d_PlAdOu.js +353 -0
- package/dist/{utils-BtAm_K5P.js → utils-BPdaCyI6.js} +7 -3
- package/dist/vite-NWC9mFjI.js +1882 -0
- package/dist/vite.d.ts +33 -5
- package/dist/vite.js +2 -131
- package/dist/workspace-f2DBLmPZ.d.ts +6 -0
- package/dist/workspace-n4wBmdaM.js +1476 -0
- package/package.json +158 -62
- package/dist/asset-registry-CMuQbyvl.js +0 -14
- package/dist/cloudflare-env-DL94Uvpz.js +0 -12
- package/dist/config-CvS-7sre.js +0 -49
- package/dist/errors-BUL8SoFS.js +0 -21
- package/dist/lifecycle-uD82JeGh.js +0 -92
- package/dist/module-8LZUMEXC.js +0 -922
- package/dist/path-BVv9OXhg.js +0 -63
- package/dist/registry-Cnr0NoKv.js +0 -932
- package/dist/runtime/nitro-plugin.d.ts +0 -6
- package/dist/runtime/nitro-plugin.js +0 -14
- package/dist/sandbox-DtGXCWRq.js +0 -198
- package/dist/types-CwNcWTdt.d.ts +0 -378
- /package/dist/{chunk-DrSxFLj_.js → chunk-8H4AJuhK.js} +0 -0
package/dist/publish.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { t as
|
|
1
|
+
import { c as normalizeWorkspacePath, p as workspaceError } from "./path-CNI6wKIU.js";
|
|
2
|
+
import { n as resolveWorkspaceStoreTarget } from "./target-D4Bqb1eH.js";
|
|
3
|
+
import { a as isWorkspaceFileEntry, d as resolveGitHubBranchOption, f as resolveGitHubOption, h as resolveGitHubTokenOption, l as readGitHubBranchState, m as resolveGitHubRootOption, p as resolveGitHubRepositoryOption, r as createGitHubFileUpdate, t as commitGitHubChanges, u as requireGitHubOption } from "./shared-BRycRSbo.js";
|
|
4
4
|
import { dirname, resolve } from "node:path";
|
|
5
5
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
6
6
|
//#region src/publishers/manifest.ts
|
|
@@ -20,163 +20,69 @@ function manifest(options = {}) {
|
|
|
20
20
|
}
|
|
21
21
|
//#endregion
|
|
22
22
|
//#region src/publishers/github.ts
|
|
23
|
-
function processEnv(...keys) {
|
|
24
|
-
const env = typeof process !== "undefined" ? process.env : void 0;
|
|
25
|
-
return keys.map((key) => env?.[key]).find((value) => typeof value === "string" && value.length > 0);
|
|
26
|
-
}
|
|
27
|
-
function resolveOption(value) {
|
|
28
|
-
return typeof value === "function" ? value() : value;
|
|
29
|
-
}
|
|
30
|
-
function requireOption(label, value) {
|
|
31
|
-
if (!value) throw new WorkspaceError(`[vitehub] GitHub workspace publisher requires ${label}.`);
|
|
32
|
-
return value;
|
|
33
|
-
}
|
|
34
|
-
function splitRepository(repository) {
|
|
35
|
-
const [owner, repo] = repository.split("/");
|
|
36
|
-
if (!owner || !repo) throw new WorkspaceError("[vitehub] GitHub workspace publisher requires a repository in owner/repo format.");
|
|
37
|
-
return {
|
|
38
|
-
owner,
|
|
39
|
-
repo
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function joinGitPath(...parts) {
|
|
43
|
-
return parts.join("/").replaceAll("\\", "/").split("/").filter(Boolean).join("/");
|
|
44
|
-
}
|
|
45
|
-
function workspacePathFromGitPath(path, root) {
|
|
46
|
-
const normalized = joinGitPath(path);
|
|
47
|
-
const normalizedRoot = joinGitPath(root);
|
|
48
|
-
if (!normalizedRoot) return normalizeWorkspacePath(normalized);
|
|
49
|
-
if (!normalized.startsWith(`${normalizedRoot}/`)) return void 0;
|
|
50
|
-
return normalizeWorkspacePath(normalized.slice(normalizedRoot.length + 1));
|
|
51
|
-
}
|
|
52
|
-
function isFileEntry(entry) {
|
|
53
|
-
return entry.type === "file";
|
|
54
|
-
}
|
|
55
|
-
function toHex(bytes) {
|
|
56
|
-
return [...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
57
|
-
}
|
|
58
|
-
async function gitBlobSha(bytes) {
|
|
59
|
-
const prefix = new TextEncoder().encode(`blob ${bytes.byteLength}\0`);
|
|
60
|
-
const input = new Uint8Array(prefix.byteLength + bytes.byteLength);
|
|
61
|
-
input.set(prefix);
|
|
62
|
-
input.set(bytes, prefix.byteLength);
|
|
63
|
-
return toHex(new Uint8Array(await globalThis.crypto.subtle.digest("SHA-1", input)));
|
|
64
|
-
}
|
|
65
|
-
function toBase64(bytes) {
|
|
66
|
-
let binary = "";
|
|
67
|
-
for (let index = 0; index < bytes.length; index += 32768) binary += String.fromCharCode(...bytes.subarray(index, index + 32768));
|
|
68
|
-
const encode = globalThis.btoa;
|
|
69
|
-
return encode ? encode(binary) : Buffer.from(bytes).toString("base64");
|
|
70
|
-
}
|
|
71
|
-
function resolveRepository(options) {
|
|
72
|
-
return resolveOption(options.repository) || resolveOption(options.repo) || processEnv("WORKSPACE_GITHUB_REPOSITORY", "VITEHUB_WORKSPACE_GITHUB_REPOSITORY", "GITHUB_REPOSITORY");
|
|
73
|
-
}
|
|
74
|
-
function resolveBranch(options) {
|
|
75
|
-
return resolveOption(options.branch) || processEnv("WORKSPACE_GITHUB_BRANCH", "VITEHUB_WORKSPACE_GITHUB_BRANCH", "GITHUB_BRANCH") || "main";
|
|
76
|
-
}
|
|
77
|
-
function resolveRoot(options, workspaceName) {
|
|
78
|
-
return resolveOption(options.root) || processEnv("WORKSPACE_GITHUB_ROOT", "VITEHUB_WORKSPACE_GITHUB_ROOT") || `.vitehub/workspaces/${workspaceName}`;
|
|
79
|
-
}
|
|
80
|
-
function resolveToken(options) {
|
|
81
|
-
return resolveOption(options.token) || getActiveCloudflareBinding("GITHUB_TOKEN") || processEnv("WORKSPACE_GITHUB_TOKEN", "VITEHUB_WORKSPACE_GITHUB_TOKEN", "GITHUB_TOKEN");
|
|
82
|
-
}
|
|
83
23
|
function resolveMessage(options, ctx) {
|
|
84
|
-
return ctx.snapshot?.name ||
|
|
24
|
+
return ctx.snapshot?.name || resolveGitHubOption(options.message) || "chore: update workspace snapshot";
|
|
25
|
+
}
|
|
26
|
+
async function resolveActiveGitHubStoreTarget(ctx) {
|
|
27
|
+
const target = await resolveWorkspaceStoreTarget(ctx.store);
|
|
28
|
+
if (target) return target.provider === "github" ? target : void 0;
|
|
29
|
+
const configuredStore = ctx.workspace.store;
|
|
30
|
+
if (configuredStore && "provider" in configuredStore && configuredStore.provider === "github") {
|
|
31
|
+
const repository = resolveGitHubRepositoryOption(configuredStore);
|
|
32
|
+
if (repository) return {
|
|
33
|
+
provider: "github",
|
|
34
|
+
branch: resolveGitHubBranchOption(configuredStore),
|
|
35
|
+
repository
|
|
36
|
+
};
|
|
37
|
+
}
|
|
85
38
|
}
|
|
86
39
|
async function readFiles(ctx, root) {
|
|
87
40
|
const entries = await ctx.store.list("", { recursive: true });
|
|
88
|
-
return await Promise.all(entries.filter(
|
|
41
|
+
return await Promise.all(entries.filter(isWorkspaceFileEntry).map(async (entry) => {
|
|
89
42
|
const file = await ctx.store.readFile(entry.path);
|
|
90
|
-
if (!file) throw
|
|
91
|
-
const
|
|
43
|
+
if (!file) throw workspaceError(`[vitehub] Workspace file disappeared before GitHub publish: ${entry.path}.`);
|
|
44
|
+
const update = await createGitHubFileUpdate(entry.path, root, file.content);
|
|
92
45
|
return {
|
|
93
46
|
...file,
|
|
94
|
-
bytes,
|
|
95
47
|
path: normalizeWorkspacePath(entry.path),
|
|
96
|
-
|
|
97
|
-
gitSha: await gitBlobSha(bytes)
|
|
48
|
+
...update
|
|
98
49
|
};
|
|
99
50
|
}));
|
|
100
51
|
}
|
|
101
|
-
async function requestGitHubJson(repo, token, path, init) {
|
|
102
|
-
const response = await fetch(`https://api.github.com${path}`, {
|
|
103
|
-
...init,
|
|
104
|
-
headers: {
|
|
105
|
-
accept: "application/vnd.github+json",
|
|
106
|
-
authorization: `Bearer ${token}`,
|
|
107
|
-
"content-type": "application/json",
|
|
108
|
-
"user-agent": "vitehub-workspace",
|
|
109
|
-
"x-github-api-version": "2022-11-28",
|
|
110
|
-
...init?.headers
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
if (!response.ok) throw new WorkspaceError(`[vitehub] GitHub workspace publisher request failed for ${repo}: ${response.status} ${response.statusText} ${await response.text().catch(() => "")}`);
|
|
114
|
-
return await response.json();
|
|
115
|
-
}
|
|
116
|
-
function findRemoteFiles(tree, root) {
|
|
117
|
-
if (tree.truncated) throw new WorkspaceError("[vitehub] GitHub workspace publisher could not compare the remote tree because GitHub returned a truncated tree.");
|
|
118
|
-
const files = /* @__PURE__ */ new Map();
|
|
119
|
-
for (const entry of tree.tree) {
|
|
120
|
-
if (entry.type !== "blob" || !entry.sha) continue;
|
|
121
|
-
const path = workspacePathFromGitPath(entry.path, root);
|
|
122
|
-
if (path) files.set(path, entry);
|
|
123
|
-
}
|
|
124
|
-
return files;
|
|
125
|
-
}
|
|
126
52
|
function github(options = {}) {
|
|
127
53
|
return {
|
|
128
54
|
name: "github",
|
|
129
55
|
async publish(ctx) {
|
|
130
|
-
const repository =
|
|
131
|
-
const branch =
|
|
132
|
-
const root =
|
|
133
|
-
const token =
|
|
56
|
+
const repository = requireGitHubOption("publisher", "a repository", resolveGitHubRepositoryOption(options));
|
|
57
|
+
const branch = resolveGitHubBranchOption(options);
|
|
58
|
+
const root = resolveGitHubRootOption(options, ctx.workspace.name);
|
|
59
|
+
const token = requireGitHubOption("publisher", "a token", resolveGitHubTokenOption(options));
|
|
60
|
+
const storeTarget = await resolveActiveGitHubStoreTarget(ctx);
|
|
61
|
+
if (!ctx.durable && storeTarget?.repository === repository && storeTarget.branch === branch) throw workspaceError(`[vitehub] GitHub publisher cannot publish to ${repository}@${branch} while it backs the active GitHub Workspace Store. Use workspace.snapshot() for that branch or configure the publisher to use a different repository or branch.`);
|
|
134
62
|
const files = await readFiles(ctx, root);
|
|
135
63
|
const nextPaths = new Set(files.map((file) => file.path));
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const deletedEntries = [...remoteFiles].filter(([path]) => !nextPaths.has(path)).map(([, entry]) => ({
|
|
144
|
-
mode: "100644",
|
|
145
|
-
path: entry.path,
|
|
146
|
-
sha: null,
|
|
147
|
-
type: "blob"
|
|
148
|
-
}));
|
|
149
|
-
if (!changedFiles.length && !deletedEntries.length) return;
|
|
150
|
-
const blobs = await Promise.all(changedFiles.map((file) => requestGitHubJson(repository, token, `/repos/${owner}/${repo}/git/blobs`, {
|
|
151
|
-
body: JSON.stringify({
|
|
152
|
-
content: toBase64(file.bytes),
|
|
153
|
-
encoding: "base64"
|
|
154
|
-
}),
|
|
155
|
-
method: "POST"
|
|
156
|
-
})));
|
|
157
|
-
const tree = await requestGitHubJson(repository, token, `/repos/${owner}/${repo}/git/trees`, {
|
|
158
|
-
body: JSON.stringify({
|
|
159
|
-
base_tree: current.tree.sha,
|
|
160
|
-
tree: [...changedFiles.map((file, index) => ({
|
|
161
|
-
mode: "100644",
|
|
162
|
-
path: file.fullPath,
|
|
163
|
-
sha: blobs[index].sha,
|
|
164
|
-
type: "blob"
|
|
165
|
-
})), ...deletedEntries]
|
|
166
|
-
}),
|
|
167
|
-
method: "POST"
|
|
168
|
-
});
|
|
169
|
-
const commit = await requestGitHubJson(repository, token, `/repos/${owner}/${repo}/git/commits`, {
|
|
170
|
-
body: JSON.stringify({
|
|
171
|
-
message: resolveMessage(options, ctx),
|
|
172
|
-
parents: [ref.object.sha],
|
|
173
|
-
tree: tree.sha
|
|
174
|
-
}),
|
|
175
|
-
method: "POST"
|
|
64
|
+
const remote = await readGitHubBranchState({
|
|
65
|
+
branch,
|
|
66
|
+
kind: "publisher",
|
|
67
|
+
paths: options.deleteUntracked === false ? files.map((file) => file.path) : void 0,
|
|
68
|
+
repository,
|
|
69
|
+
root,
|
|
70
|
+
token
|
|
176
71
|
});
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
72
|
+
const changedFiles = files.filter((file) => remote.files.get(file.path)?.sha !== file.gitSha);
|
|
73
|
+
const deletePaths = options.deleteUntracked === false ? [] : [...remote.files].filter(([path]) => !nextPaths.has(path)).map(([, entry]) => entry.path);
|
|
74
|
+
if (!changedFiles.length && !deletePaths.length) return;
|
|
75
|
+
await commitGitHubChanges({
|
|
76
|
+
baseTreeSha: remote.treeSha,
|
|
77
|
+
branch,
|
|
78
|
+
branchExists: remote.branchExists,
|
|
79
|
+
deletePaths,
|
|
80
|
+
files: changedFiles,
|
|
81
|
+
kind: "publisher",
|
|
82
|
+
message: resolveMessage(options, ctx),
|
|
83
|
+
parentSha: remote.refSha,
|
|
84
|
+
repository,
|
|
85
|
+
token
|
|
180
86
|
});
|
|
181
87
|
}
|
|
182
88
|
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { m as workspaceNotFoundError } from "./path-CNI6wKIU.js";
|
|
2
|
+
import { t as createWorkspace } from "./workspace-n4wBmdaM.js";
|
|
3
|
+
import runtimeRegistry from "#vitehub-workspace-registry";
|
|
4
|
+
//#region src/core/registry.ts
|
|
5
|
+
const workspaceRegistryStateKey = Symbol.for("vitehub.workspace.registryState");
|
|
6
|
+
function workspaceRegistryState() {
|
|
7
|
+
const scope = globalThis;
|
|
8
|
+
scope[workspaceRegistryStateKey] ??= {
|
|
9
|
+
loadedDefinitions: /* @__PURE__ */ new Map(),
|
|
10
|
+
loaders: runtimeRegistry,
|
|
11
|
+
registeredDefinitions: /* @__PURE__ */ new Map()
|
|
12
|
+
};
|
|
13
|
+
return scope[workspaceRegistryStateKey];
|
|
14
|
+
}
|
|
15
|
+
function pickWorkspaceFields(definition) {
|
|
16
|
+
const { __vitehubWorkspaceAgent: _agent, __vitehubWorkspaceAgentOptions: _agentOptions, description: _description, fallback: _fallback, instructions: _instructions, model: _model, name: _agentName, resolve: _resolve, run: _run, stepLimit: _stepLimit, workspace: _workspace, ...workspace } = definition;
|
|
17
|
+
return workspace;
|
|
18
|
+
}
|
|
19
|
+
function normalizeWorkspaceDefinition(name, definition) {
|
|
20
|
+
if (!definition) throw workspaceNotFoundError(name);
|
|
21
|
+
const workspaceAgentOptions = definition.__vitehubWorkspaceAgentOptions;
|
|
22
|
+
if (workspaceAgentOptions?.workspace) {
|
|
23
|
+
const injectedWorkspace = pickWorkspaceFields(definition);
|
|
24
|
+
const configuredWorkspace = typeof workspaceAgentOptions.workspace === "string" ? {} : workspaceAgentOptions.workspace;
|
|
25
|
+
const sources = mergeWorkspaceSources(injectedWorkspace.sources, configuredWorkspace.sources);
|
|
26
|
+
return {
|
|
27
|
+
...injectedWorkspace,
|
|
28
|
+
...configuredWorkspace,
|
|
29
|
+
...sources ? { sources } : {},
|
|
30
|
+
rootDir: configuredWorkspace.rootDir ?? injectedWorkspace.rootDir,
|
|
31
|
+
sourceRootDir: configuredWorkspace.sourceRootDir ?? injectedWorkspace.sourceRootDir,
|
|
32
|
+
name
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
if ("name" in definition) throw new TypeError(`[vitehub] Workspace definition "${name}" must not declare a name. Workspace names are inferred from filenames.`);
|
|
36
|
+
return {
|
|
37
|
+
...pickWorkspaceFields(definition),
|
|
38
|
+
name
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function mergeWorkspaceSources(injected, configured) {
|
|
42
|
+
if (!injected && !configured) return void 0;
|
|
43
|
+
return {
|
|
44
|
+
...injected,
|
|
45
|
+
...configured
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function registerWorkspace(name, definition) {
|
|
49
|
+
if (!name || typeof name !== "string") throw new TypeError("[vitehub] registerWorkspace requires a string name.");
|
|
50
|
+
workspaceRegistryState().registeredDefinitions.set(name, normalizeWorkspaceDefinition(name, definition));
|
|
51
|
+
}
|
|
52
|
+
function setWorkspaceRegistry(registry) {
|
|
53
|
+
const state = workspaceRegistryState();
|
|
54
|
+
state.loaders = registry;
|
|
55
|
+
state.loadedDefinitions.clear();
|
|
56
|
+
}
|
|
57
|
+
async function resolveWorkspaceDefinition(name) {
|
|
58
|
+
const state = workspaceRegistryState();
|
|
59
|
+
const existing = state.registeredDefinitions.get(name) || state.loadedDefinitions.get(name);
|
|
60
|
+
if (existing) return existing;
|
|
61
|
+
const load = state.loaders[name];
|
|
62
|
+
if (!load) throw workspaceNotFoundError(name);
|
|
63
|
+
const definition = normalizeWorkspaceDefinition(name, (await load()).default);
|
|
64
|
+
state.loadedDefinitions.set(name, definition);
|
|
65
|
+
return definition;
|
|
66
|
+
}
|
|
67
|
+
async function resolveRegisteredWorkspaceDefinition(name) {
|
|
68
|
+
return resolveWorkspaceDefinition(name);
|
|
69
|
+
}
|
|
70
|
+
async function useRegisteredWorkspace(name) {
|
|
71
|
+
return createWorkspace(await resolveWorkspaceDefinition(name));
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
export { useRegisteredWorkspace as a, setWorkspaceRegistry as i, registerWorkspace as n, resolveRegisteredWorkspaceDefinition as r, normalizeWorkspaceDefinition as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { F as WorkspaceDefinitionInput, P as WorkspaceDefinition } from "./types-DHkae7Cb.js";
|
|
2
2
|
|
|
3
3
|
//#region src/core/registry.d.ts
|
|
4
4
|
type WorkspaceRegistryModule = {
|
|
@@ -6,5 +6,6 @@ type WorkspaceRegistryModule = {
|
|
|
6
6
|
};
|
|
7
7
|
type WorkspaceRegistry = Record<string, () => Promise<WorkspaceRegistryModule>>;
|
|
8
8
|
declare function registerWorkspace(name: string, definition: WorkspaceDefinitionInput): void;
|
|
9
|
+
declare function resolveRegisteredWorkspaceDefinition(name: string): Promise<WorkspaceDefinition>;
|
|
9
10
|
//#endregion
|
|
10
|
-
export { registerWorkspace as n, WorkspaceRegistry as t };
|
|
11
|
+
export { registerWorkspace as n, resolveRegisteredWorkspaceDefinition as r, WorkspaceRegistry as t };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { a as normalizeWorkspaceSources, h as workspaceSourceRequestDescriptorPath, n as createSourceContext, p as getWorkspaceSourceRequestExecutor } from "./config--r5unwPc.js";
|
|
2
|
+
//#region src/sources/request-execution.ts
|
|
3
|
+
const sourceRequestExecutions = /* @__PURE__ */ new WeakMap();
|
|
4
|
+
function attachWorkspaceSourceRequestExecution(target, executor) {
|
|
5
|
+
if (!executor) return target;
|
|
6
|
+
sourceRequestExecutions.set(target, executor);
|
|
7
|
+
return target;
|
|
8
|
+
}
|
|
9
|
+
function getWorkspaceSourceRequestExecution(input) {
|
|
10
|
+
return sourceRequestExecutions.get(input);
|
|
11
|
+
}
|
|
12
|
+
function createWorkspaceSourceRequestExecution(definition, options = {}) {
|
|
13
|
+
const sources = normalizeWorkspaceSources(definition.sources).filter((source) => source.requestDescriptor && getWorkspaceSourceRequestExecutor(source.source)).filter((source) => sourceRequestVisible(source, options.selectedWorkspaceScope));
|
|
14
|
+
if (!sources.length) return void 0;
|
|
15
|
+
return { async executeSourceRequest(input) {
|
|
16
|
+
const matches = sources.filter((source) => {
|
|
17
|
+
const descriptor = source.requestDescriptor;
|
|
18
|
+
if (!descriptor || descriptor.method !== input.method) return false;
|
|
19
|
+
return sameRequestTarget(descriptor.url, input.url);
|
|
20
|
+
}).filter((source) => source.requestDescriptor && requestShapeMatches(source.requestDescriptor, input));
|
|
21
|
+
if (matches.length !== 1) throw new Error(matches.length > 1 ? "[vitehub] Source request is ambiguous; more than one visible Source matches this curl target." : "[vitehub] Source request is not visible in the selected workspace scope or does not match a declared Source target.");
|
|
22
|
+
const source = matches[0];
|
|
23
|
+
const executor = getWorkspaceSourceRequestExecutor(source.source);
|
|
24
|
+
if (!executor) throw new Error("[vitehub] Source request executor is unavailable.");
|
|
25
|
+
return await executor(input, createSourceContext(definition, {
|
|
26
|
+
key: source.key,
|
|
27
|
+
mountPath: source.mountPath
|
|
28
|
+
}, void 0, { selectedWorkspaceScope: options.selectedWorkspaceScope }));
|
|
29
|
+
} };
|
|
30
|
+
}
|
|
31
|
+
function sourceRequestVisible(source, scope) {
|
|
32
|
+
if (!scope || scope.all) return true;
|
|
33
|
+
const descriptorPath = workspaceSourceRequestDescriptorPath(source.key);
|
|
34
|
+
return Boolean(scope.paths?.some((path) => pathIntersects(path, descriptorPath)));
|
|
35
|
+
}
|
|
36
|
+
function pathContains(container, path) {
|
|
37
|
+
if (!container || !path) return container === path;
|
|
38
|
+
return path === container || path.startsWith(`${container}/`);
|
|
39
|
+
}
|
|
40
|
+
function pathIntersects(left, right) {
|
|
41
|
+
return pathContains(left, right) || pathContains(right, left);
|
|
42
|
+
}
|
|
43
|
+
function sameRequestTarget(left, right) {
|
|
44
|
+
const leftUrl = new URL(left);
|
|
45
|
+
const rightUrl = new URL(right);
|
|
46
|
+
return leftUrl.origin === rightUrl.origin && leftUrl.pathname === rightUrl.pathname;
|
|
47
|
+
}
|
|
48
|
+
function requestShapeMatches(descriptor, input) {
|
|
49
|
+
const request = descriptor.request;
|
|
50
|
+
if (request?.querySchema) return bodyShapeMatches(request, input);
|
|
51
|
+
if (!jsonEqual(queryFromUrl(new URL(input.url)) || {}, serializedQuery(request?.query) || {})) return false;
|
|
52
|
+
return bodyShapeMatches(request, input);
|
|
53
|
+
}
|
|
54
|
+
function bodyShapeMatches(request, input) {
|
|
55
|
+
if (request?.bodySchema) return true;
|
|
56
|
+
if (typeof request?.body !== "undefined") return jsonEqual(input.body, request.body);
|
|
57
|
+
return typeof input.body === "undefined";
|
|
58
|
+
}
|
|
59
|
+
function queryFromUrl(url) {
|
|
60
|
+
const query = {};
|
|
61
|
+
for (const key of new Set([...url.searchParams.keys()])) {
|
|
62
|
+
const values = url.searchParams.getAll(key);
|
|
63
|
+
query[key] = values.length > 1 ? values : values[0];
|
|
64
|
+
}
|
|
65
|
+
return Object.keys(query).length ? query : void 0;
|
|
66
|
+
}
|
|
67
|
+
function serializedQuery(query) {
|
|
68
|
+
if (!query) return void 0;
|
|
69
|
+
const params = new URLSearchParams();
|
|
70
|
+
for (const [key, value] of Object.entries(query)) {
|
|
71
|
+
const values = Array.isArray(value) ? value : [value];
|
|
72
|
+
for (const item of values) params.append(key, String(item));
|
|
73
|
+
}
|
|
74
|
+
return queryFromUrl(new URL(`https://vitehub.local/?${params}`));
|
|
75
|
+
}
|
|
76
|
+
function jsonEqual(left, right) {
|
|
77
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
80
|
+
export { createWorkspaceSourceRequestExecution as n, getWorkspaceSourceRequestExecution as r, attachWorkspaceSourceRequestExecution as t };
|
package/dist/runtime/assets.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { D as WorkspaceAssets, j as WorkspaceContent } from "../types-DHkae7Cb.js";
|
|
2
2
|
|
|
3
3
|
//#region src/runtime/assets.d.ts
|
|
4
4
|
interface WorkspaceAssetFile {
|
|
5
5
|
load: () => Promise<WorkspaceContent>;
|
|
6
6
|
mediaType?: string;
|
|
7
|
+
metadata?: Record<string, unknown>;
|
|
7
8
|
}
|
|
8
9
|
type WorkspaceAssetFiles<TKey extends string = string> = Record<TKey, WorkspaceAssetFile>;
|
|
9
10
|
declare function createWorkspaceAssets<TKey extends string = string>(files: WorkspaceAssetFiles<TKey>): WorkspaceAssets<TKey>;
|
package/dist/runtime/assets.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { t as searchText } from "../search-DtaEyjpO.js";
|
|
1
|
+
import { a as matchesAny, c as normalizeWorkspacePath, d as sha256, f as isWorkspaceError, i as decodeFile, o as normalizeSafeWorkspacePath, p as workspaceError } from "../path-CNI6wKIU.js";
|
|
2
|
+
import { t as searchText } from "../search-C4REyHj9.js";
|
|
4
3
|
//#region src/runtime/assets.ts
|
|
5
4
|
function createMissingPathError(path) {
|
|
6
|
-
return
|
|
5
|
+
return workspaceError(`[vitehub] Workspace file does not exist: ${path}.`);
|
|
7
6
|
}
|
|
8
7
|
function createPathMap(files) {
|
|
9
8
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -52,6 +51,7 @@ function createWorkspaceAssets(files) {
|
|
|
52
51
|
return {
|
|
53
52
|
digest: await sha256(content),
|
|
54
53
|
mediaType: entry.mediaType,
|
|
54
|
+
metadata: entry.metadata,
|
|
55
55
|
path,
|
|
56
56
|
size: contentSize(content),
|
|
57
57
|
type: "file"
|
|
@@ -103,7 +103,7 @@ function createWorkspaceAssets(files) {
|
|
|
103
103
|
await statPath(normalizeAssetPath(path));
|
|
104
104
|
return true;
|
|
105
105
|
} catch (error) {
|
|
106
|
-
if (error
|
|
106
|
+
if (isWorkspaceError(error)) return false;
|
|
107
107
|
throw error;
|
|
108
108
|
}
|
|
109
109
|
},
|
package/dist/runtime/state.d.ts
CHANGED
|
@@ -1,21 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare function resetWorkspaceStoreCache(): void;
|
|
6
|
-
//#endregion
|
|
7
|
-
//#region src/runtime/hosted-store-loader.d.ts
|
|
8
|
-
type HostedWorkspaceStoreOptions = CloudflareArtifactsWorkspaceStoreOptions | VercelBlobWorkspaceStoreOptions;
|
|
9
|
-
type WorkspaceHostedStoreLoader = (options: HostedWorkspaceStoreOptions, workspaceName: string) => WorkspaceStore;
|
|
10
|
-
declare function setWorkspaceHostedStoreLoader(loader: WorkspaceHostedStoreLoader | undefined): void;
|
|
11
|
-
declare function getWorkspaceHostedStoreLoader(): WorkspaceHostedStoreLoader | undefined;
|
|
12
|
-
//#endregion
|
|
13
|
-
//#region src/runtime/config.d.ts
|
|
14
|
-
declare function setWorkspaceRuntimeConfig(config: false | ResolvedWorkspaceModuleOptions): void;
|
|
15
|
-
declare function getWorkspaceRuntimeConfig(): false | ResolvedWorkspaceModuleOptions;
|
|
16
|
-
//#endregion
|
|
17
|
-
//#region src/runtime/state.d.ts
|
|
18
|
-
declare function setWorkspaceRuntimeRegistry(registry: WorkspaceRegistry): void;
|
|
19
|
-
declare function setWorkspaceRuntimeAssetsRegistry(registry: WorkspaceAssetsRegistry): void;
|
|
20
|
-
//#endregion
|
|
21
|
-
export { getWorkspaceHostedStoreLoader, getWorkspaceRuntimeConfig, resetWorkspaceStoreCache, setWorkspaceHostedStoreLoader, setWorkspaceRuntimeAssetsRegistry, setWorkspaceRuntimeConfig, setWorkspaceRuntimeRegistry };
|
|
1
|
+
import { p as useWorkspace, r as UseWorkspaceOptions, t as ReadonlyWorkspaceFacade, u as WritableWorkspaceFacade } from "../use-D16tf8Ph.js";
|
|
2
|
+
import { n as registerWorkspace, r as resolveRegisteredWorkspaceDefinition } from "../registry-CoC9JxVt.js";
|
|
3
|
+
import { c as setWorkspaceHostedStoreLoader, i as setActiveCloudflareEnv, l as getWorkspaceRuntimeConfig, n as setWorkspaceRuntimeRegistry, r as resetWorkspaceStoreCache, s as getWorkspaceHostedStoreLoader, t as setWorkspaceRuntimeAssetsRegistry, u as setWorkspaceRuntimeConfig } from "../state-DSAHEsq6.js";
|
|
4
|
+
export { type ReadonlyWorkspaceFacade, type UseWorkspaceOptions, type WritableWorkspaceFacade, getWorkspaceHostedStoreLoader, getWorkspaceRuntimeConfig, registerWorkspace, resetWorkspaceStoreCache, resolveRegisteredWorkspaceDefinition, setActiveCloudflareEnv, setWorkspaceHostedStoreLoader, setWorkspaceRuntimeAssetsRegistry, setWorkspaceRuntimeConfig, setWorkspaceRuntimeRegistry, useWorkspace };
|
package/dist/runtime/state.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { c as getWorkspaceHostedStoreLoader, d as setWorkspaceRuntimeConfig, l as setWorkspaceHostedStoreLoader, u as getWorkspaceRuntimeConfig } from "../provider-CeQciesl.js";
|
|
2
|
+
import { n as setActiveCloudflareEnv } from "../cloudflare-env-CKxUs2fa.js";
|
|
3
|
+
import { t as setWorkspaceAssetsRegistry } from "../asset-registry-CaG9b7tf.js";
|
|
4
|
+
import { n as resetWorkspaceStoreCache } from "../workspace-n4wBmdaM.js";
|
|
5
|
+
import { i as setWorkspaceRegistry, n as registerWorkspace, r as resolveRegisteredWorkspaceDefinition } from "../registry-C7DMdBXN.js";
|
|
6
|
+
import { t as useWorkspace } from "../use-d_PlAdOu.js";
|
|
4
7
|
//#region src/runtime/state.ts
|
|
5
8
|
function setWorkspaceRuntimeRegistry(registry) {
|
|
6
9
|
setWorkspaceRegistry(registry);
|
|
@@ -9,4 +12,4 @@ function setWorkspaceRuntimeAssetsRegistry(registry) {
|
|
|
9
12
|
setWorkspaceAssetsRegistry(registry);
|
|
10
13
|
}
|
|
11
14
|
//#endregion
|
|
12
|
-
export { getWorkspaceHostedStoreLoader, getWorkspaceRuntimeConfig, resetWorkspaceStoreCache, setWorkspaceHostedStoreLoader, setWorkspaceRuntimeAssetsRegistry, setWorkspaceRuntimeConfig, setWorkspaceRuntimeRegistry };
|
|
15
|
+
export { getWorkspaceHostedStoreLoader, getWorkspaceRuntimeConfig, registerWorkspace, resetWorkspaceStoreCache, resolveRegisteredWorkspaceDefinition, setActiveCloudflareEnv, setWorkspaceHostedStoreLoader, setWorkspaceRuntimeAssetsRegistry, setWorkspaceRuntimeConfig, setWorkspaceRuntimeRegistry, useWorkspace };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Bt as WorkspaceSourceResolutionInvocation, Nt as WorkspaceSourceRequestExecutionInput, P as WorkspaceDefinition, Pt as WorkspaceSourceRequestExecutionResult, _t as WorkspaceSelectedScope, ot as WorkspaceName, wt as WorkspaceSource } from "./types-DHkae7Cb.js";
|
|
2
|
+
import { p as useWorkspace, r as UseWorkspaceOptions, t as ReadonlyWorkspaceFacade, u as WritableWorkspaceFacade } from "./use-D16tf8Ph.js";
|
|
3
|
+
import { n as registerWorkspace, r as resolveRegisteredWorkspaceDefinition } from "./registry-CoC9JxVt.js";
|
|
4
|
+
import { a as HostedWorkspaceStoreOptions, c as setWorkspaceHostedStoreLoader, l as getWorkspaceRuntimeConfig, n as setWorkspaceRuntimeRegistry, o as WorkspaceHostedStoreLoader, r as resetWorkspaceStoreCache, s as getWorkspaceHostedStoreLoader, t as setWorkspaceRuntimeAssetsRegistry, u as setWorkspaceRuntimeConfig } from "./state-DSAHEsq6.js";
|
|
5
|
+
import { a as getWorkspaceSourceRequestDescriptor, i as workspaceSourceGrantPaths, n as normalizeWorkspaceSourceMetadata, o as isWorkspaceSourceRequestOnly, r as normalizeWorkspaceSourcesMetadata, s as workspaceSourceRequestDescriptorPath, t as WorkspaceSourceMetadata } from "./config-Ca5DM8fF.js";
|
|
6
|
+
|
|
7
|
+
//#region src/runtime/dependency-loaders.d.ts
|
|
8
|
+
interface WorkspaceDependencyRuntimeLoaders {
|
|
9
|
+
shellWorkspace: () => Promise<unknown>;
|
|
10
|
+
}
|
|
11
|
+
declare function setWorkspaceDependencyRuntimeLoaders(loaders: Partial<WorkspaceDependencyRuntimeLoaders> | undefined): void;
|
|
12
|
+
declare function getWorkspaceDependencyRuntimeLoaders(): WorkspaceDependencyRuntimeLoaders;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/sources/resolution.d.ts
|
|
15
|
+
interface WorkspaceSourceResolutionOptions {
|
|
16
|
+
invocation: WorkspaceSourceResolutionInvocation<object>;
|
|
17
|
+
overlay?: boolean;
|
|
18
|
+
selectedWorkspaceScope?: WorkspaceSelectedScope<string>;
|
|
19
|
+
}
|
|
20
|
+
interface WorkspaceSourceResolutionFacade<Name extends WorkspaceName = WorkspaceName> {
|
|
21
|
+
definition: WorkspaceDefinition;
|
|
22
|
+
workspace: ReadonlyWorkspaceFacade<Name>;
|
|
23
|
+
}
|
|
24
|
+
declare function hasWorkspaceSourceResolvers(definition: Pick<WorkspaceDefinition, "sources"> | undefined): boolean;
|
|
25
|
+
declare function resolveWorkspaceSources(definition: WorkspaceDefinition, options: WorkspaceSourceResolutionOptions): Promise<WorkspaceDefinition>;
|
|
26
|
+
declare function createWorkspaceSourceResolutionFacade<Name extends WorkspaceName = WorkspaceName>(workspace: ReadonlyWorkspaceFacade<Name>, definition: WorkspaceDefinition, options: WorkspaceSourceResolutionOptions): Promise<WorkspaceSourceResolutionFacade<Name>>;
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/sources/live.d.ts
|
|
29
|
+
declare function markLiveWorkspaceSource(source: WorkspaceSource, paths: Record<string, string>): WorkspaceSource;
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/sources/request-execution.d.ts
|
|
32
|
+
interface WorkspaceSourceRequestExecutionTarget {
|
|
33
|
+
executeSourceRequest(input: WorkspaceSourceRequestExecutionInput): Promise<WorkspaceSourceRequestExecutionResult>;
|
|
34
|
+
}
|
|
35
|
+
declare function attachWorkspaceSourceRequestExecution<T extends object>(target: T, executor: WorkspaceSourceRequestExecutionTarget | undefined): T;
|
|
36
|
+
declare function getWorkspaceSourceRequestExecution(input: object): WorkspaceSourceRequestExecutionTarget | undefined;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { type HostedWorkspaceStoreOptions, type ReadonlyWorkspaceFacade, type UseWorkspaceOptions, type WorkspaceDependencyRuntimeLoaders, type WorkspaceHostedStoreLoader, type WorkspaceSourceMetadata, type WorkspaceSourceResolutionFacade, type WorkspaceSourceResolutionOptions, type WritableWorkspaceFacade, attachWorkspaceSourceRequestExecution, createWorkspaceSourceResolutionFacade, getWorkspaceDependencyRuntimeLoaders, getWorkspaceHostedStoreLoader, getWorkspaceRuntimeConfig, getWorkspaceSourceRequestDescriptor, getWorkspaceSourceRequestExecution, hasWorkspaceSourceResolvers, isWorkspaceSourceRequestOnly, markLiveWorkspaceSource, normalizeWorkspaceSourceMetadata, normalizeWorkspaceSourcesMetadata, registerWorkspace, resetWorkspaceStoreCache, resolveRegisteredWorkspaceDefinition, resolveWorkspaceSources, setWorkspaceDependencyRuntimeLoaders, setWorkspaceHostedStoreLoader, setWorkspaceRuntimeAssetsRegistry, setWorkspaceRuntimeConfig, setWorkspaceRuntimeRegistry, useWorkspace, workspaceSourceGrantPaths, workspaceSourceRequestDescriptorPath };
|