@vite-hub/workspace 0.0.0 → 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 +262 -1
- package/dist/ai-Cztw4eLk.js +472 -0
- package/dist/ai-hFdsvDHC.d.ts +162 -0
- package/dist/ai.d.ts +3 -0
- package/dist/ai.js +2 -0
- package/dist/artifacts-store-BAV9jZpd.js +555 -0
- package/dist/asset-registry-CaG9b7tf.js +19 -0
- package/dist/chunk-8H4AJuhK.js +14 -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-xy0le-_U.js +51 -0
- 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 +185 -0
- package/dist/index.js +541 -0
- package/dist/lifecycle-Lhk3dAMt.js +176 -0
- package/dist/loader.d.ts +17 -0
- package/dist/loader.js +22 -0
- package/dist/nitro.d.ts +2 -0
- package/dist/nitro.js +2 -0
- package/dist/nuxt.d.ts +26 -0
- package/dist/nuxt.js +36 -0
- package/dist/path-CNI6wKIU.js +115 -0
- package/dist/provider-CeQciesl.js +599 -0
- package/dist/providers/cloudflare/artifacts-store.d.ts +6 -0
- package/dist/providers/cloudflare/artifacts-store.js +2 -0
- 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 +6 -0
- package/dist/providers/vercel/blob-store.js +235 -0
- package/dist/publish.d.ts +35 -0
- package/dist/publish.js +112 -0
- package/dist/registry-C7DMdBXN.js +74 -0
- package/dist/registry-CoC9JxVt.d.ts +11 -0
- package/dist/request-execution-C8qRcReq.js +80 -0
- package/dist/runtime/assets.d.ts +12 -0
- package/dist/runtime/assets.js +138 -0
- package/dist/runtime/empty-assets-registry.d.ts +6 -0
- package/dist/runtime/empty-assets-registry.js +4 -0
- package/dist/runtime/empty-registry.d.ts +6 -0
- package/dist/runtime/empty-registry.js +4 -0
- package/dist/runtime/state.d.ts +4 -0
- package/dist/runtime/state.js +15 -0
- 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-C4REyHj9.js +39 -0
- 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 +2 -0
- package/dist/test.js +2 -0
- 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-BPdaCyI6.js +55 -0
- package/dist/vite-NWC9mFjI.js +1882 -0
- package/dist/vite.d.ts +50 -0
- package/dist/vite.js +2 -0
- package/dist/workspace-f2DBLmPZ.d.ts +6 -0
- package/dist/workspace-n4wBmdaM.js +1476 -0
- package/package.json +197 -5
package/dist/publish.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
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
|
+
import { dirname, resolve } from "node:path";
|
|
5
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
6
|
+
//#region src/publishers/manifest.ts
|
|
7
|
+
function manifest(options = {}) {
|
|
8
|
+
return {
|
|
9
|
+
name: "manifest",
|
|
10
|
+
async publish(ctx) {
|
|
11
|
+
const path = resolve(ctx.rootDir, options.path || `.vitehub/workspaces/${ctx.workspace.name}.json`);
|
|
12
|
+
const entries = await ctx.store.list("", { recursive: true });
|
|
13
|
+
await mkdir(dirname(path), { recursive: true });
|
|
14
|
+
await writeFile(path, `${JSON.stringify({
|
|
15
|
+
name: ctx.workspace.name,
|
|
16
|
+
entries
|
|
17
|
+
}, null, 2)}\n`);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/publishers/github.ts
|
|
23
|
+
function resolveMessage(options, ctx) {
|
|
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
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async function readFiles(ctx, root) {
|
|
40
|
+
const entries = await ctx.store.list("", { recursive: true });
|
|
41
|
+
return await Promise.all(entries.filter(isWorkspaceFileEntry).map(async (entry) => {
|
|
42
|
+
const file = await ctx.store.readFile(entry.path);
|
|
43
|
+
if (!file) throw workspaceError(`[vitehub] Workspace file disappeared before GitHub publish: ${entry.path}.`);
|
|
44
|
+
const update = await createGitHubFileUpdate(entry.path, root, file.content);
|
|
45
|
+
return {
|
|
46
|
+
...file,
|
|
47
|
+
path: normalizeWorkspacePath(entry.path),
|
|
48
|
+
...update
|
|
49
|
+
};
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
function github(options = {}) {
|
|
53
|
+
return {
|
|
54
|
+
name: "github",
|
|
55
|
+
async publish(ctx) {
|
|
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.`);
|
|
62
|
+
const files = await readFiles(ctx, root);
|
|
63
|
+
const nextPaths = new Set(files.map((file) => file.path));
|
|
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
|
|
71
|
+
});
|
|
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
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/publishers/types.ts
|
|
92
|
+
function types(options = {}) {
|
|
93
|
+
return {
|
|
94
|
+
name: "types",
|
|
95
|
+
async publish(ctx) {
|
|
96
|
+
const path = resolve(ctx.rootDir, options.path || `.vitehub/workspaces/${ctx.workspace.name}.d.ts`);
|
|
97
|
+
await mkdir(dirname(path), { recursive: true });
|
|
98
|
+
await writeFile(path, `declare module "#vitehub/workspaces/${ctx.workspace.name}" {\n const manifest: { name: ${JSON.stringify(ctx.workspace.name)}, entries: Array<{ path: string, type: "file" | "directory" }> }\n export default manifest\n}\n`);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/publishers/virtual-module.ts
|
|
104
|
+
function virtualModule(options) {
|
|
105
|
+
return {
|
|
106
|
+
name: `virtual-module:${options.id}`,
|
|
107
|
+
clientSafe: options.includeContent === true,
|
|
108
|
+
async publish() {}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
//#endregion
|
|
112
|
+
export { github, manifest, types, virtualModule };
|
|
@@ -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 };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { F as WorkspaceDefinitionInput, P as WorkspaceDefinition } from "./types-DHkae7Cb.js";
|
|
2
|
+
|
|
3
|
+
//#region src/core/registry.d.ts
|
|
4
|
+
type WorkspaceRegistryModule = {
|
|
5
|
+
default?: WorkspaceDefinitionInput;
|
|
6
|
+
};
|
|
7
|
+
type WorkspaceRegistry = Record<string, () => Promise<WorkspaceRegistryModule>>;
|
|
8
|
+
declare function registerWorkspace(name: string, definition: WorkspaceDefinitionInput): void;
|
|
9
|
+
declare function resolveRegisteredWorkspaceDefinition(name: string): Promise<WorkspaceDefinition>;
|
|
10
|
+
//#endregion
|
|
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 };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { D as WorkspaceAssets, j as WorkspaceContent } from "../types-DHkae7Cb.js";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime/assets.d.ts
|
|
4
|
+
interface WorkspaceAssetFile {
|
|
5
|
+
load: () => Promise<WorkspaceContent>;
|
|
6
|
+
mediaType?: string;
|
|
7
|
+
metadata?: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
type WorkspaceAssetFiles<TKey extends string = string> = Record<TKey, WorkspaceAssetFile>;
|
|
10
|
+
declare function createWorkspaceAssets<TKey extends string = string>(files: WorkspaceAssetFiles<TKey>): WorkspaceAssets<TKey>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { createWorkspaceAssets };
|
|
@@ -0,0 +1,138 @@
|
|
|
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";
|
|
3
|
+
//#region src/runtime/assets.ts
|
|
4
|
+
function createMissingPathError(path) {
|
|
5
|
+
return workspaceError(`[vitehub] Workspace file does not exist: ${path}.`);
|
|
6
|
+
}
|
|
7
|
+
function createPathMap(files) {
|
|
8
|
+
const map = /* @__PURE__ */ new Map();
|
|
9
|
+
for (const path of Object.keys(files)) map.set(normalizeSafeWorkspacePath(path), files[path]);
|
|
10
|
+
return map;
|
|
11
|
+
}
|
|
12
|
+
function createDirectorySet(paths) {
|
|
13
|
+
const directories = /* @__PURE__ */ new Set();
|
|
14
|
+
for (const path of paths) {
|
|
15
|
+
const segments = normalizeWorkspacePath(path).split("/").filter(Boolean);
|
|
16
|
+
for (let index = 1; index < segments.length; index++) directories.add(segments.slice(0, index).join("/"));
|
|
17
|
+
}
|
|
18
|
+
return directories;
|
|
19
|
+
}
|
|
20
|
+
function contentSize(content) {
|
|
21
|
+
return typeof content === "string" ? new TextEncoder().encode(content).byteLength : content.byteLength;
|
|
22
|
+
}
|
|
23
|
+
function normalizeAssetPath(path = "") {
|
|
24
|
+
return normalizeSafeWorkspacePath(path, { allowEmpty: true });
|
|
25
|
+
}
|
|
26
|
+
function isNestedUnder(path, prefix) {
|
|
27
|
+
return !prefix || path.startsWith(`${prefix}/`);
|
|
28
|
+
}
|
|
29
|
+
function createWorkspaceAssets(files) {
|
|
30
|
+
const pathMap = createPathMap(files);
|
|
31
|
+
const paths = [...pathMap.keys()].sort();
|
|
32
|
+
const directorySet = createDirectorySet(paths);
|
|
33
|
+
const contentCache = /* @__PURE__ */ new Map();
|
|
34
|
+
const statCache = /* @__PURE__ */ new Map();
|
|
35
|
+
async function readContent(path) {
|
|
36
|
+
const entry = pathMap.get(path);
|
|
37
|
+
if (!entry) throw createMissingPathError(path);
|
|
38
|
+
const cached = contentCache.get(path);
|
|
39
|
+
if (cached) return await cached;
|
|
40
|
+
const next = entry.load();
|
|
41
|
+
contentCache.set(path, next);
|
|
42
|
+
return await next;
|
|
43
|
+
}
|
|
44
|
+
async function statFile(path) {
|
|
45
|
+
const cached = statCache.get(path);
|
|
46
|
+
if (cached) return await cached;
|
|
47
|
+
const entry = pathMap.get(path);
|
|
48
|
+
if (!entry) throw createMissingPathError(path);
|
|
49
|
+
const next = (async () => {
|
|
50
|
+
const content = await readContent(path);
|
|
51
|
+
return {
|
|
52
|
+
digest: await sha256(content),
|
|
53
|
+
mediaType: entry.mediaType,
|
|
54
|
+
metadata: entry.metadata,
|
|
55
|
+
path,
|
|
56
|
+
size: contentSize(content),
|
|
57
|
+
type: "file"
|
|
58
|
+
};
|
|
59
|
+
})();
|
|
60
|
+
statCache.set(path, next);
|
|
61
|
+
return await next;
|
|
62
|
+
}
|
|
63
|
+
async function statPath(path) {
|
|
64
|
+
if (pathMap.has(path)) return await statFile(path);
|
|
65
|
+
if (!path || directorySet.has(path)) return {
|
|
66
|
+
path,
|
|
67
|
+
type: "directory"
|
|
68
|
+
};
|
|
69
|
+
throw createMissingPathError(path);
|
|
70
|
+
}
|
|
71
|
+
function createDirectoryEntry(path) {
|
|
72
|
+
return {
|
|
73
|
+
path,
|
|
74
|
+
type: "directory"
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
async function listEntries(prefix = "", options = {}) {
|
|
78
|
+
const normalizedPrefix = normalizeAssetPath(prefix);
|
|
79
|
+
const result = /* @__PURE__ */ new Map();
|
|
80
|
+
for (const directory of directorySet) {
|
|
81
|
+
if (directory === normalizedPrefix) continue;
|
|
82
|
+
if (normalizedPrefix && !isNestedUnder(directory, normalizedPrefix)) continue;
|
|
83
|
+
if (!options.recursive && normalizeWorkspacePath(directory.slice(normalizedPrefix.length)).replace(/^\//, "").includes("/")) continue;
|
|
84
|
+
result.set(directory, createDirectoryEntry(directory));
|
|
85
|
+
}
|
|
86
|
+
for (const path of paths) {
|
|
87
|
+
if (path === normalizedPrefix) continue;
|
|
88
|
+
if (normalizedPrefix && !isNestedUnder(path, normalizedPrefix)) continue;
|
|
89
|
+
if (!options.recursive && normalizeWorkspacePath(path.slice(normalizedPrefix.length)).replace(/^\//, "").includes("/")) continue;
|
|
90
|
+
result.set(path, await statFile(path));
|
|
91
|
+
}
|
|
92
|
+
return [...result.values()].sort((left, right) => left.path.localeCompare(right.path));
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
async readFile(path, options) {
|
|
96
|
+
return decodeFile(await readContent(normalizeAssetPath(path)), options);
|
|
97
|
+
},
|
|
98
|
+
async stat(path) {
|
|
99
|
+
return await statPath(normalizeAssetPath(path));
|
|
100
|
+
},
|
|
101
|
+
async exists(path) {
|
|
102
|
+
try {
|
|
103
|
+
await statPath(normalizeAssetPath(path));
|
|
104
|
+
return true;
|
|
105
|
+
} catch (error) {
|
|
106
|
+
if (isWorkspaceError(error)) return false;
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
async list(path, options) {
|
|
111
|
+
return await listEntries(path || "", options);
|
|
112
|
+
},
|
|
113
|
+
async glob(pattern, _options = {}) {
|
|
114
|
+
const entries = await listEntries("", { recursive: true });
|
|
115
|
+
const patterns = Array.isArray(pattern) ? pattern : [pattern];
|
|
116
|
+
return entries.filter((entry) => entry.type === "file" && patterns.some((item) => matchesAny(entry.path, item)));
|
|
117
|
+
},
|
|
118
|
+
async search(query) {
|
|
119
|
+
const result = [];
|
|
120
|
+
const limit = query.limit ?? 100;
|
|
121
|
+
const entries = await listEntries("", { recursive: true });
|
|
122
|
+
for (const entry of entries) {
|
|
123
|
+
if (entry.type !== "file") continue;
|
|
124
|
+
if (query.paths?.length && !query.paths.some((path) => entry.path === path || entry.path.startsWith(`${path}/`))) continue;
|
|
125
|
+
const content = await readContent(entry.path);
|
|
126
|
+
const text = typeof content === "string" ? content : new TextDecoder().decode(content);
|
|
127
|
+
result.push(...searchText(entry.path, text, {
|
|
128
|
+
...query,
|
|
129
|
+
limit: limit - result.length
|
|
130
|
+
}));
|
|
131
|
+
if (result.length >= limit) break;
|
|
132
|
+
}
|
|
133
|
+
return result.slice(0, limit);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
138
|
+
export { createWorkspaceAssets };
|
|
@@ -0,0 +1,4 @@
|
|
|
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 };
|
|
@@ -0,0 +1,15 @@
|
|
|
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";
|
|
7
|
+
//#region src/runtime/state.ts
|
|
8
|
+
function setWorkspaceRuntimeRegistry(registry) {
|
|
9
|
+
setWorkspaceRegistry(registry);
|
|
10
|
+
}
|
|
11
|
+
function setWorkspaceRuntimeAssetsRegistry(registry) {
|
|
12
|
+
setWorkspaceAssetsRegistry(registry);
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
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 };
|