@vite-hub/workspace 0.0.1 → 0.0.3

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 (95) hide show
  1. package/README.md +225 -17
  2. package/dist/{ai-Bk3LLnit.js → ai-Ce3PtWFW.js} +160 -29
  3. package/dist/ai-nmHdzjCM.d.ts +162 -0
  4. package/dist/ai.d.ts +2 -85
  5. package/dist/ai.js +1 -1
  6. package/dist/asset-registry-CaG9b7tf.js +19 -0
  7. package/dist/cloudflare.d.ts +18 -0
  8. package/dist/cloudflare.js +2 -0
  9. package/dist/collections/client.d.ts +39 -0
  10. package/dist/collections/client.js +137 -0
  11. package/dist/collections.d.ts +59 -0
  12. package/dist/collections.js +159 -0
  13. package/dist/config-3I1BnsdO.d.ts +28 -0
  14. package/dist/config-CDoyls2X.js +30 -0
  15. package/dist/config-CZLO0m9h.js +7811 -0
  16. package/dist/file-CHfsZpso.js +23 -0
  17. package/dist/{files-DbsIjBya.js → files-QRV55OCx.js} +6 -5
  18. package/dist/github-CfA5vpJ5.js +189 -0
  19. package/dist/glob-D0vD_wRY.js +17 -0
  20. package/dist/host-CAnbugpI.js +370 -0
  21. package/dist/hosted-C1-tTTTf.js +581 -0
  22. package/dist/{providers/vercel/blob-store.js → hosted-vercel-blob-CWBILDVo.js} +100 -19
  23. package/dist/hosted-vercel-blob.d.ts +15 -0
  24. package/dist/hosted-vercel-blob.js +2 -0
  25. package/dist/hosted.d.ts +18 -0
  26. package/dist/hosted.js +2 -0
  27. package/dist/index.d.ts +129 -102
  28. package/dist/index.js +477 -599
  29. package/dist/lifecycle-BYoa9hVb.js +176 -0
  30. package/dist/loader.d.ts +1 -1
  31. package/dist/loader.js +1 -1
  32. package/dist/mountx.d.ts +10 -0
  33. package/dist/mountx.js +143 -0
  34. package/dist/nitro.d.ts +2 -31
  35. package/dist/nitro.js +2 -2
  36. package/dist/nuxt.d.ts +26 -0
  37. package/dist/nuxt.js +36 -0
  38. package/dist/path-CNI6wKIU.js +115 -0
  39. package/dist/{provider-BZuKAV4e.js → provider-C3_elpEh.js} +142 -37
  40. package/dist/providers/github/store.d.ts +6 -0
  41. package/dist/providers/github/store.js +2 -0
  42. package/dist/publish.d.ts +3 -2
  43. package/dist/publish.js +48 -142
  44. package/dist/{registry-D4Qzq26I.d.ts → registry-BIQVCBWI.d.ts} +3 -2
  45. package/dist/registry-CqyDTW9Y.js +74 -0
  46. package/dist/request-execution-u9mgUXKX.js +80 -0
  47. package/dist/runtime/assets.d.ts +2 -1
  48. package/dist/runtime/assets.js +5 -5
  49. package/dist/runtime/empty-assets-registry.d.ts +1 -1
  50. package/dist/runtime/empty-registry.d.ts +1 -1
  51. package/dist/runtime/state.d.ts +4 -21
  52. package/dist/runtime/state.js +7 -4
  53. package/dist/runtime/workspace.d.ts +2 -0
  54. package/dist/runtime/workspace.js +2 -0
  55. package/dist/runtime-options-BsPSv5O7.js +13 -0
  56. package/dist/runtime.d.ts +38 -0
  57. package/dist/runtime.js +626 -0
  58. package/dist/{search-DtaEyjpO.js → search-C4REyHj9.js} +2 -2
  59. package/dist/server.d.ts +65 -0
  60. package/dist/server.js +355 -0
  61. package/dist/shared-jfogBrd5.js +273 -0
  62. package/dist/source-metadata.d.ts +2 -0
  63. package/dist/source-metadata.js +2 -0
  64. package/dist/state-TTqa3x3Y.d.ts +25 -0
  65. package/dist/store-Bs1SLh55.js +414 -0
  66. package/dist/sync-DiuDmSGk.js +269 -0
  67. package/dist/target-D4Bqb1eH.js +11 -0
  68. package/dist/test.d.ts +1 -1
  69. package/dist/test.js +1 -1
  70. package/dist/types-60Yn149G.d.ts +612 -0
  71. package/dist/use-CUFSnFCS.d.ts +86 -0
  72. package/dist/use-CsV3oIxH.js +336 -0
  73. package/dist/vite-tbfDxtlu.js +2191 -0
  74. package/dist/vite.d.ts +33 -5
  75. package/dist/vite.js +2 -131
  76. package/dist/workspace-66SKyiec.d.ts +6 -0
  77. package/dist/workspace-C4k92Ow8.js +1460 -0
  78. package/package.json +143 -62
  79. package/dist/asset-registry-CMuQbyvl.js +0 -14
  80. package/dist/cloudflare-env-DL94Uvpz.js +0 -12
  81. package/dist/config-CvS-7sre.js +0 -49
  82. package/dist/errors-BUL8SoFS.js +0 -21
  83. package/dist/lifecycle-uD82JeGh.js +0 -92
  84. package/dist/module-8LZUMEXC.js +0 -922
  85. package/dist/path-BVv9OXhg.js +0 -63
  86. package/dist/providers/cloudflare/artifacts-store.d.ts +0 -6
  87. package/dist/providers/cloudflare/artifacts-store.js +0 -384
  88. package/dist/providers/vercel/blob-store.d.ts +0 -6
  89. package/dist/registry-Cnr0NoKv.js +0 -932
  90. package/dist/runtime/nitro-plugin.d.ts +0 -6
  91. package/dist/runtime/nitro-plugin.js +0 -14
  92. package/dist/sandbox-DtGXCWRq.js +0 -198
  93. package/dist/types-CwNcWTdt.d.ts +0 -378
  94. package/dist/utils-BtAm_K5P.js +0 -51
  95. /package/dist/{chunk-DrSxFLj_.js → chunk-8H4AJuhK.js} +0 -0
@@ -1,6 +0,0 @@
1
- import { definePlugin } from "nitro";
2
-
3
- //#region src/runtime/nitro-plugin.d.ts
4
- declare const workspaceNitroPlugin: ReturnType<typeof definePlugin>;
5
- //#endregion
6
- export { workspaceNitroPlugin as default };
@@ -1,14 +0,0 @@
1
- import { c as setWorkspaceRuntimeConfig } from "../provider-BZuKAV4e.js";
2
- import { setWorkspaceRuntimeAssetsRegistry, setWorkspaceRuntimeRegistry } from "./state.js";
3
- import workspaceAssetsRegistry from "#vitehub-workspace-assets-registry";
4
- import workspaceRegistry from "#vitehub-workspace-registry";
5
- import { definePlugin } from "nitro";
6
- import { useRuntimeConfig } from "nitro/runtime-config";
7
- //#region src/runtime/nitro-plugin.ts
8
- const workspaceNitroPlugin = definePlugin(() => {
9
- setWorkspaceRuntimeConfig(useRuntimeConfig().workspace || false);
10
- setWorkspaceRuntimeRegistry(workspaceRegistry);
11
- setWorkspaceRuntimeAssetsRegistry(workspaceAssetsRegistry);
12
- });
13
- //#endregion
14
- export { workspaceNitroPlugin as default };
@@ -1,198 +0,0 @@
1
- import { t as WorkspaceError } from "./errors-BUL8SoFS.js";
2
- import { i as normalizeSafeWorkspacePath, l as sha256, n as decodeFile, o as normalizeWorkspacePath, t as contentToBytes } from "./path-BVv9OXhg.js";
3
- import { n as diffSnapshots, t as createSnapshotFromEntries } from "./utils-BtAm_K5P.js";
4
- import { posix } from "node:path";
5
- //#region src/session/sandbox.ts
6
- const sandboxCwd = "/workspace";
7
- const sandboxPackageSpecifier = "@vite-hub/sandbox";
8
- const sandboxRuntimeStateSpecifier = "@vite-hub/sandbox/runtime/state";
9
- function normalizeSearchRoot(path) {
10
- const normalized = posix.normalize(path.replace(/\\/g, "/"));
11
- return normalized === "." ? "" : normalizeSafeWorkspacePath(normalized, { allowEmpty: true });
12
- }
13
- function toSandboxPath(path = "") {
14
- const normalized = normalizeSafeWorkspacePath(path, { allowEmpty: true });
15
- return normalized ? posix.join(sandboxCwd, normalized) : sandboxCwd;
16
- }
17
- function fromSandboxPath(path) {
18
- const normalizedRoot = sandboxCwd.replace(/\/+$/, "");
19
- const normalizedPath = path.replace(/\/+$/, "");
20
- if (normalizedPath === normalizedRoot) return "";
21
- if (!normalizedPath.startsWith(`${normalizedRoot}/`)) return normalizeWorkspacePath(normalizedPath);
22
- return normalizeWorkspacePath(normalizedPath.slice(normalizedRoot.length + 1));
23
- }
24
- function toWorkspaceEntry(entry) {
25
- return {
26
- path: fromSandboxPath(entry.path),
27
- size: entry.size,
28
- type: entry.type
29
- };
30
- }
31
- async function ensureSandboxParent(sandbox, path) {
32
- const parent = posix.dirname(path);
33
- if (parent && parent !== "." && parent !== "/") await sandbox.mkdir(parent, { recursive: true });
34
- }
35
- async function readSandboxFile(sandbox, path) {
36
- if (!await sandbox.exists(path)) return void 0;
37
- return {
38
- content: await sandbox.readFile(path, { encoding: "binary" }),
39
- path: fromSandboxPath(path)
40
- };
41
- }
42
- async function listSandboxEntries(sandbox, path = "", recursive = false) {
43
- const root = toSandboxPath(path);
44
- return (await sandbox.listFiles(root, { recursive })).map(toWorkspaceEntry).filter((entry) => entry.path).sort((left, right) => left.path.localeCompare(right.path));
45
- }
46
- async function snapshotSandbox(sandbox, name) {
47
- const entries = await listSandboxEntries(sandbox, "", true);
48
- return await createSnapshotFromEntries(await Promise.all(entries.map(async (entry) => {
49
- if (entry.type !== "file") return entry;
50
- const content = await sandbox.readFile(toSandboxPath(entry.path), { encoding: "binary" });
51
- return {
52
- ...entry,
53
- digest: await sha256(content),
54
- size: contentToBytes(content).byteLength
55
- };
56
- })), name);
57
- }
58
- async function resetSandboxWorkspaceRoot(sandbox) {
59
- const result = await sandbox.exec("rm", ["-rf", sandboxCwd]);
60
- if (!result.ok) throw new WorkspaceError(`[vitehub] Failed to reset sandbox workspace root: ${result.stderr || "rm failed"}`);
61
- await sandbox.mkdir(sandboxCwd, { recursive: true });
62
- }
63
- async function materializeWorkspace(workspace, sandbox) {
64
- await resetSandboxWorkspaceRoot(sandbox);
65
- const entries = await workspace.list("", { recursive: true });
66
- for (const entry of entries.filter((entry) => entry.type === "directory")) await sandbox.mkdir(toSandboxPath(entry.path), { recursive: true });
67
- for (const entry of entries) {
68
- if (entry.type !== "file") continue;
69
- const content = await workspace.readFile(entry.path, { encoding: "binary" });
70
- const target = toSandboxPath(entry.path);
71
- await ensureSandboxParent(sandbox, target);
72
- await sandbox.writeFile(target, content);
73
- }
74
- return await snapshotSandbox(sandbox, "sandbox-open");
75
- }
76
- async function commitSandboxChanges(sandbox, workspace, diff, mediaTypes) {
77
- for (const entry of diff.entries) {
78
- if (entry.after?.type === "directory") {
79
- if (entry.before?.type === "file") await workspace.rm(entry.path, { force: true });
80
- await workspace.mkdir(entry.path, { recursive: true });
81
- continue;
82
- }
83
- if (entry.type === "removed") {
84
- await workspace.rm(entry.path, {
85
- force: true,
86
- recursive: true
87
- });
88
- continue;
89
- }
90
- if (entry.after?.type === "file") {
91
- if (entry.before?.type === "directory") await workspace.rm(entry.path, {
92
- force: true,
93
- recursive: true
94
- });
95
- const before = entry.before?.type === "file" ? await workspace.stat(entry.path).catch(() => void 0) : void 0;
96
- const file = await readSandboxFile(sandbox, toSandboxPath(entry.path));
97
- if (file) await workspace.writeFile(entry.path, file.content, { mediaType: file.mediaType || mediaTypes.get(entry.path) || before?.mediaType });
98
- }
99
- }
100
- await workspace.snapshot({ name: "sandbox-commit" });
101
- }
102
- async function createSandboxWorkspaceSession(definition, workspace) {
103
- const sandboxPackage = await import(
104
- /* @vite-ignore */
105
- sandboxPackageSpecifier
106
- ).catch((error) => {
107
- throw new WorkspaceError(`[vitehub] Sandbox workspace runtime requires @vite-hub/sandbox. ${error instanceof Error ? error.message : String(error)}`);
108
- });
109
- const sandboxConfig = (await import(
110
- /* @vite-ignore */
111
- sandboxRuntimeStateSpecifier
112
- )).getSandboxRuntimeConfig();
113
- if (!sandboxConfig) throw new WorkspaceError("[vitehub] Workspace runtime `sandbox` requires app-level `sandbox` config.");
114
- const sandbox = await sandboxPackage.createSandboxWithConfig(sandboxConfig);
115
- let baseline = await materializeWorkspace(workspace, sandbox);
116
- const mediaTypes = /* @__PURE__ */ new Map();
117
- let closed = false;
118
- function assertOpen() {
119
- if (closed) throw new WorkspaceError("[vitehub] Workspace sandbox session is already closed.");
120
- }
121
- async function currentDiff() {
122
- assertOpen();
123
- return diffSnapshots(baseline, await snapshotSandbox(sandbox));
124
- }
125
- return {
126
- async readFile(path, options) {
127
- assertOpen();
128
- const file = await readSandboxFile(sandbox, toSandboxPath(path));
129
- if (!file) throw new WorkspaceError(`[vitehub] Workspace file does not exist: ${path}.`);
130
- return decodeFile(file.content, options);
131
- },
132
- async writeFile(path, content, options) {
133
- assertOpen();
134
- const target = toSandboxPath(path);
135
- await ensureSandboxParent(sandbox, target);
136
- await sandbox.writeFile(target, content);
137
- const workspacePath = fromSandboxPath(target);
138
- if (options?.mediaType) mediaTypes.set(workspacePath, options.mediaType);
139
- else mediaTypes.delete(workspacePath);
140
- },
141
- async list(path = "", options = {}) {
142
- assertOpen();
143
- return await listSandboxEntries(sandbox, path, options.recursive);
144
- },
145
- async glob(pattern, _options = {}) {
146
- assertOpen();
147
- const patterns = Array.isArray(pattern) ? pattern : [pattern];
148
- const { matchesAny } = await import("./path-BVv9OXhg.js").then((n) => n.s);
149
- return (await listSandboxEntries(sandbox, "", true)).filter((entry) => entry.type === "file" && patterns.some((item) => matchesAny(entry.path, item)));
150
- },
151
- async search(query) {
152
- assertOpen();
153
- const { searchText } = await import("./search-DtaEyjpO.js").then((n) => n.n);
154
- const scopedSearchRoots = [...new Set((query.paths?.length ? query.paths : [query.cwd || ""]).map(normalizeSearchRoot))].filter(Boolean);
155
- const limit = query.limit ?? 100;
156
- const hits = [];
157
- for (const entry of (await listSandboxEntries(sandbox, "", true)).filter((item) => item.type === "file")) {
158
- if (scopedSearchRoots.length && !scopedSearchRoots.some((path) => entry.path === path || entry.path.startsWith(`${path}/`))) continue;
159
- const text = await sandbox.readFile(toSandboxPath(entry.path));
160
- hits.push(...searchText(entry.path, text, {
161
- ...query,
162
- limit: limit - hits.length
163
- }));
164
- if (hits.length >= limit) break;
165
- }
166
- return hits;
167
- },
168
- async diff() {
169
- return await currentDiff();
170
- },
171
- async commit(options) {
172
- await commitSandboxChanges(sandbox, workspace, await currentDiff(), mediaTypes);
173
- baseline = await snapshotSandbox(sandbox, options?.message || "sandbox-commit");
174
- },
175
- async exec(command, args = [], options = {}) {
176
- assertOpen();
177
- const result = await sandbox.exec(command, args, {
178
- cwd: options.cwd || sandboxCwd,
179
- env: options.env,
180
- timeout: options.timeout
181
- });
182
- return {
183
- args,
184
- command,
185
- exitCode: result.code ?? 0,
186
- stderr: result.stderr,
187
- stdout: result.stdout
188
- };
189
- },
190
- async close() {
191
- if (closed) return;
192
- closed = true;
193
- if (sandbox.provider === "vercel") await sandbox.stop().catch(() => {});
194
- }
195
- };
196
- }
197
- //#endregion
198
- export { createSandboxWorkspaceSession };
@@ -1,378 +0,0 @@
1
- //#region src/core/types.d.ts
2
- type WorkspaceContent = string | Uint8Array;
3
- interface ReadFileOptions {
4
- encoding?: "utf8" | "binary";
5
- }
6
- type ReadFileResult<TOptions extends ReadFileOptions | undefined = undefined> = TOptions extends {
7
- encoding: "binary";
8
- } ? Uint8Array : string;
9
- interface WriteFileOptions {
10
- mediaType?: string;
11
- }
12
- interface ListOptions {
13
- recursive?: boolean;
14
- }
15
- interface GlobOptions {
16
- cwd?: string;
17
- }
18
- interface WorkspaceSearchQuery {
19
- pattern: string;
20
- cwd?: string;
21
- paths?: string[];
22
- regex?: boolean;
23
- caseSensitive?: boolean;
24
- limit?: number;
25
- }
26
- interface WorkspaceSearchHit {
27
- path: string;
28
- line: number;
29
- column: number;
30
- text: string;
31
- }
32
- interface MkdirOptions {
33
- recursive?: boolean;
34
- }
35
- interface RmOptions {
36
- recursive?: boolean;
37
- force?: boolean;
38
- }
39
- type WorkspaceWriteOperation = "writeFile" | "mkdir" | "rm";
40
- type WorkspaceWriteMode = boolean | "create" | "update" | "delete";
41
- interface WorkspaceWriteInput {
42
- workspace: string;
43
- operation: WorkspaceWriteOperation;
44
- path: string;
45
- content?: WorkspaceContent;
46
- mediaType?: string;
47
- previous?: WorkspaceStat;
48
- rule?: ResolvedWorkspaceRule;
49
- }
50
- type WorkspaceWriteValidatorResult = boolean | void | WorkspaceWriteInput;
51
- type WorkspaceWriteValidator = (input: WorkspaceWriteInput) => WorkspaceWriteValidatorResult | Promise<WorkspaceWriteValidatorResult>;
52
- interface WorkspaceRule {
53
- commit?: boolean | string;
54
- read?: boolean;
55
- write?: WorkspaceWriteMode;
56
- maxBytes?: number | `${number}kb` | `${number}mb`;
57
- mediaType?: string | string[];
58
- validate?: WorkspaceWriteValidator | WorkspaceWriteValidator[];
59
- }
60
- type WorkspaceRules = Record<string, WorkspaceRule>;
61
- interface ResolvedWorkspaceRule extends Omit<WorkspaceRule, "maxBytes" | "validate"> {
62
- maxBytes?: number;
63
- pattern: string;
64
- validate: WorkspaceWriteValidator[];
65
- }
66
- interface WorkspaceHookContext extends WorkspaceWriteInput {}
67
- interface WorkspaceHooks {
68
- "write:before"?: WorkspaceWriteHook | WorkspaceWriteHook[];
69
- "write:validate"?: WorkspaceWriteHook | WorkspaceWriteHook[];
70
- "write:after"?: WorkspaceWriteHook | WorkspaceWriteHook[];
71
- "write:error"?: WorkspaceWriteErrorHook | WorkspaceWriteErrorHook[];
72
- }
73
- type WorkspaceWriteHook = (ctx: WorkspaceHookContext) => void | Promise<void>;
74
- type WorkspaceWriteErrorHook = (ctx: WorkspaceHookContext & {
75
- error: unknown;
76
- }) => void | Promise<void>;
77
- interface WorkspacePlugin {
78
- id: string;
79
- rules?: WorkspaceRules;
80
- hooks?: WorkspaceHooks;
81
- }
82
- interface SnapshotOptions {
83
- name?: string;
84
- }
85
- interface DiffOptions {
86
- from?: WorkspaceSnapshot;
87
- }
88
- interface WorkspaceSyncOptions {
89
- force?: boolean;
90
- }
91
- interface WorkspaceSessionOptions {
92
- runtime?: never;
93
- sandbox?: never;
94
- }
95
- type WorkspaceMountMode = "read-only" | "read-write" | "copy-on-write";
96
- interface WorkspaceMountOptions {
97
- mode: WorkspaceMountMode;
98
- target?: string;
99
- }
100
- interface WorkspaceMount {
101
- workspace: Workspace;
102
- mode: WorkspaceMountMode;
103
- target: string;
104
- diff(): Promise<WorkspaceDiff>;
105
- commit(options?: {
106
- message?: string;
107
- }): Promise<void>;
108
- export(): Promise<WorkspaceSnapshot>;
109
- }
110
- interface ExecOptions {
111
- cwd?: string;
112
- env?: Record<string, string>;
113
- timeout?: number;
114
- }
115
- interface ExecResult {
116
- command: string;
117
- args: string[];
118
- exitCode: number;
119
- stdout: string;
120
- stderr: string;
121
- }
122
- interface WorkspaceSession {
123
- readFile<TOptions extends ReadFileOptions | undefined = undefined>(path: string, options?: TOptions): Promise<ReadFileResult<TOptions>>;
124
- writeFile(path: string, content: WorkspaceContent, options?: WriteFileOptions): Promise<void>;
125
- list(path?: string, options?: ListOptions): Promise<WorkspaceEntry[]>;
126
- glob(pattern: string | string[], options?: GlobOptions): Promise<WorkspaceEntry[]>;
127
- search(query: WorkspaceSearchQuery): Promise<WorkspaceSearchHit[]>;
128
- diff(): Promise<WorkspaceDiff>;
129
- commit(options?: {
130
- message?: string;
131
- }): Promise<void>;
132
- exec(command: string, args?: string[], options?: ExecOptions): Promise<ExecResult>;
133
- tools?: {
134
- aiSdk?(): Promise<Record<string, unknown>>;
135
- };
136
- close(): Promise<void>;
137
- }
138
- declare global {
139
- interface ViteHubWorkspaceNameMap {}
140
- interface ViteHubWorkspaceAssetMap {}
141
- }
142
- interface WorkspaceNameMap extends ViteHubWorkspaceNameMap {}
143
- type WorkspaceName = [keyof ViteHubWorkspaceNameMap] extends [never] ? string : Extract<keyof ViteHubWorkspaceNameMap, string>;
144
- type WorkspaceAssetPath<Name extends WorkspaceName = WorkspaceName> = Name extends keyof ViteHubWorkspaceAssetMap ? Extract<ViteHubWorkspaceAssetMap[Name], string> : string;
145
- interface WorkspaceAssets<TKey extends string = string> {
146
- readFile<TOptions extends ReadFileOptions | undefined = undefined>(path: TKey, options?: TOptions): Promise<ReadFileResult<TOptions>>;
147
- stat(path: TKey): Promise<WorkspaceStat>;
148
- exists(path: TKey): Promise<boolean>;
149
- list(path?: TKey | (string & {}) | "", options?: ListOptions): Promise<WorkspaceEntry[]>;
150
- glob(pattern: TKey | (string & {}) | Array<TKey | (string & {})>, options?: GlobOptions): Promise<WorkspaceEntry[]>;
151
- search(query: WorkspaceSearchQuery): Promise<WorkspaceSearchHit[]>;
152
- materializeSources?(options?: WorkspaceMaterializeSourcesOptions): Promise<WorkspaceMaterializeSourcesResult>;
153
- }
154
- type WorkspaceAssetsRegistry = Record<string, WorkspaceAssets>;
155
- interface WorkspaceFile {
156
- path: string;
157
- content: WorkspaceContent;
158
- mediaType?: string;
159
- metadata?: Record<string, unknown>;
160
- }
161
- interface WorkspaceEntry {
162
- path: string;
163
- type: "file" | "directory";
164
- size?: number;
165
- mtime?: number;
166
- mediaType?: string;
167
- digest?: string;
168
- }
169
- interface WorkspaceStat extends WorkspaceEntry {
170
- type: "file" | "directory";
171
- }
172
- interface WorkspaceSnapshot {
173
- id: string;
174
- name?: string;
175
- createdAt: string;
176
- entries: Record<string, {
177
- type: "file" | "directory";
178
- digest?: string;
179
- size?: number;
180
- }>;
181
- }
182
- interface WorkspaceDiffEntry {
183
- path: string;
184
- type: "added" | "modified" | "removed";
185
- before?: WorkspaceSnapshot["entries"][string];
186
- after?: WorkspaceSnapshot["entries"][string];
187
- }
188
- interface WorkspaceDiff {
189
- from?: string;
190
- to: string;
191
- entries: WorkspaceDiffEntry[];
192
- }
193
- interface WorkspaceAutoCommitPlan {
194
- message: string;
195
- paths: string[];
196
- }
197
- interface WorkspaceStore {
198
- readFile(path: string): Promise<WorkspaceFile | undefined>;
199
- writeFile(path: string, file: WorkspaceFile): Promise<void>;
200
- list(prefix?: string, options?: ListOptions): Promise<WorkspaceEntry[]>;
201
- glob(pattern: string | string[], options?: GlobOptions): Promise<WorkspaceEntry[]>;
202
- stat(path: string): Promise<WorkspaceStat | undefined>;
203
- mkdir(path: string, options?: MkdirOptions): Promise<void>;
204
- rm(path: string, options?: RmOptions): Promise<void>;
205
- snapshot(options?: SnapshotOptions): Promise<WorkspaceSnapshot>;
206
- diff(options?: DiffOptions): Promise<WorkspaceDiff>;
207
- getMeta?(key: string): Promise<unknown>;
208
- setMeta?(key: string, value: unknown): Promise<void>;
209
- }
210
- interface SourceContext {
211
- rootDir: string;
212
- sourceRootDir?: string;
213
- workspace: string;
214
- }
215
- type WorkspaceMaterializeMode = "build" | "lazy";
216
- type WorkspaceValidateMode = false | "request";
217
- interface WorkspaceCacheOptions {
218
- maxAge?: number;
219
- }
220
- interface WorkspaceSourceMountOptions {
221
- path?: string;
222
- materialize?: WorkspaceMaterializeMode;
223
- cache?: false | WorkspaceCacheOptions;
224
- validate?: WorkspaceValidateMode;
225
- }
226
- type WorkspaceSourceMount = string | WorkspaceSourceMountOptions;
227
- interface WorkspaceSourceItem {
228
- key: string;
229
- path?: string;
230
- content?: WorkspaceContent;
231
- data?: unknown;
232
- mediaType?: string;
233
- metadata?: Record<string, unknown>;
234
- }
235
- interface WorkspaceSource {
236
- mount?: WorkspaceSourceMount;
237
- materialize?: WorkspaceMaterializeMode;
238
- cache?: false | WorkspaceCacheOptions;
239
- validate?: WorkspaceValidateMode;
240
- fingerprint?: unknown;
241
- prepare?(ctx: SourceContext): Promise<void>;
242
- getKeys(ctx: SourceContext): Promise<string[]>;
243
- getItem(key: string, ctx: SourceContext): Promise<WorkspaceSourceItem>;
244
- getItems?(ctx: SourceContext): Promise<WorkspaceSourceItem[]>;
245
- getMeta?(key: string, ctx: SourceContext): Promise<Record<string, unknown> | undefined>;
246
- search?(query: WorkspaceSearchQuery, ctx: SourceContext): Promise<WorkspaceSearchHit[]>;
247
- watch?: unknown[];
248
- }
249
- interface WorkspaceLoaderSource extends WorkspaceSource {
250
- key: string;
251
- }
252
- interface LoaderContext {
253
- workspace: string;
254
- rootDir: string;
255
- sourceRootDir?: string;
256
- sources: WorkspaceLoaderSource[];
257
- store: WorkspaceStore;
258
- parseData(input: {
259
- id: string;
260
- data: unknown;
261
- filePath?: string;
262
- }): Promise<unknown>;
263
- generateDigest(input: unknown): string;
264
- logger: Logger;
265
- watcher?: unknown;
266
- }
267
- interface WorkspaceLoader {
268
- name: string;
269
- schema?: unknown;
270
- load(ctx: LoaderContext): Promise<void>;
271
- }
272
- interface PublishContext {
273
- workspace: WorkspaceDefinition;
274
- store: WorkspaceStore;
275
- rootDir: string;
276
- snapshot?: WorkspaceSnapshot;
277
- }
278
- interface WorkspacePublisher {
279
- name: string;
280
- clientSafe?: boolean;
281
- publish(ctx: PublishContext): Promise<void>;
282
- }
283
- interface Logger {
284
- debug(...args: unknown[]): void;
285
- info(...args: unknown[]): void;
286
- warn(...args: unknown[]): void;
287
- error(...args: unknown[]): void;
288
- }
289
- interface LocalWorkspaceStoreOptions {
290
- provider?: "local";
291
- root?: string;
292
- }
293
- interface MemoryWorkspaceStoreOptions {
294
- provider: "memory";
295
- }
296
- interface CloudflareArtifactsWorkspaceStoreOptions {
297
- provider: "cloudflare-artifacts";
298
- binding?: string;
299
- namespace?: string;
300
- repo?: string;
301
- repoPrefix?: string;
302
- branch?: string;
303
- }
304
- interface VercelBlobWorkspaceStoreOptions {
305
- provider: "vercel-blob";
306
- token?: string;
307
- prefix?: string;
308
- access?: "private" | "public";
309
- }
310
- type WorkspaceStoreOptions = LocalWorkspaceStoreOptions | MemoryWorkspaceStoreOptions | CloudflareArtifactsWorkspaceStoreOptions | VercelBlobWorkspaceStoreOptions | WorkspaceStore;
311
- interface WorkspaceDefinition {
312
- name: string;
313
- rootDir?: string;
314
- sourceRootDir?: string;
315
- runtime?: "sandbox";
316
- store?: WorkspaceStoreOptions;
317
- sources?: Record<string, WorkspaceSource>;
318
- loaders?: WorkspaceLoader[];
319
- publish?: WorkspacePublisher[];
320
- plugins?: WorkspacePlugin[];
321
- rules?: WorkspaceRules;
322
- hooks?: WorkspaceHooks;
323
- }
324
- type WorkspaceDefinitionInput = Omit<WorkspaceDefinition, "name"> & {
325
- name?: never;
326
- };
327
- interface WorkspaceModuleOptions {
328
- root?: string;
329
- assets?: boolean | string[];
330
- store?: WorkspaceStoreOptions;
331
- }
332
- interface ResolvedWorkspaceModuleOptions {
333
- root: string;
334
- assets?: boolean | string[];
335
- store: Exclude<WorkspaceStoreOptions, WorkspaceStore>;
336
- }
337
- interface Workspace {
338
- name: string;
339
- sync(options?: WorkspaceSyncOptions): Promise<void>;
340
- materializeSources?(options?: WorkspaceMaterializeSourcesOptions): Promise<WorkspaceMaterializeSourcesResult>;
341
- readFile<TOptions extends ReadFileOptions | undefined = undefined>(path: string, options?: TOptions): Promise<ReadFileResult<TOptions>>;
342
- writeFile(path: string, content: WorkspaceContent, options?: WriteFileOptions): Promise<void>;
343
- list(path?: string, options?: ListOptions): Promise<WorkspaceEntry[]>;
344
- glob(pattern: string | string[], options?: GlobOptions): Promise<WorkspaceEntry[]>;
345
- search(query: WorkspaceSearchQuery): Promise<WorkspaceSearchHit[]>;
346
- stat(path: string): Promise<WorkspaceStat>;
347
- exists(path: string): Promise<boolean>;
348
- mkdir(path: string, options?: MkdirOptions): Promise<void>;
349
- rm(path: string, options?: RmOptions): Promise<void>;
350
- snapshot(options?: SnapshotOptions): Promise<WorkspaceSnapshot>;
351
- diff(options?: DiffOptions): Promise<WorkspaceDiff>;
352
- startSession(options?: WorkspaceSessionOptions): Promise<WorkspaceSession>;
353
- mount(options?: WorkspaceMountOptions): WorkspaceMount;
354
- }
355
- interface WorkspaceSourceMaterializationStatus {
356
- source: string;
357
- mountPath: string;
358
- status: "lazy" | "updating" | "ready" | "error";
359
- commit?: string;
360
- materializedAt?: string;
361
- files?: number;
362
- bytes?: number;
363
- error?: string;
364
- }
365
- interface WorkspaceMaterializeSourcesOptions {
366
- sources?: string[];
367
- path?: string;
368
- }
369
- interface WorkspaceMaterializeSourcesResult {
370
- bytes: number;
371
- directories: number;
372
- durationMs: number;
373
- files: number;
374
- path: string;
375
- sources: WorkspaceSourceMaterializationStatus[];
376
- }
377
- //#endregion
378
- export { WorkspaceSession as $, WorkspaceDiff as A, WorkspaceMaterializeSourcesResult as B, WorkspaceAssets as C, WorkspaceContent as D, WorkspaceCacheOptions as E, WorkspaceHooks as F, WorkspaceName as G, WorkspaceMount as H, WorkspaceLoader as I, WorkspacePublisher as J, WorkspaceNameMap as K, WorkspaceLoaderSource as L, WorkspaceEntry as M, WorkspaceFile as N, WorkspaceDefinition as O, WorkspaceHookContext as P, WorkspaceSearchQuery as Q, WorkspaceMaterializeMode as R, WorkspaceAssetPath as S, WorkspaceAutoCommitPlan as T, WorkspaceMountMode as U, WorkspaceModuleOptions as V, WorkspaceMountOptions as W, WorkspaceRules as X, WorkspaceRule as Y, WorkspaceSearchHit as Z, RmOptions as _, WorkspaceWriteValidator as _t, GlobOptions as a, WorkspaceSourceMount as at, VercelBlobWorkspaceStoreOptions as b, LocalWorkspaceStoreOptions as c, WorkspaceStore as ct, MkdirOptions as d, WorkspaceValidateMode as dt, WorkspaceSessionOptions as et, PublishContext as f, WorkspaceWriteErrorHook as ft, ResolvedWorkspaceRule as g, WorkspaceWriteOperation as gt, ResolvedWorkspaceModuleOptions as h, WorkspaceWriteMode as ht, ExecResult as i, WorkspaceSourceMaterializationStatus as it, WorkspaceDiffEntry as j, WorkspaceDefinitionInput as k, Logger as l, WorkspaceStoreOptions as lt, ReadFileResult as m, WorkspaceWriteInput as mt, DiffOptions as n, WorkspaceSource as nt, ListOptions as o, WorkspaceSourceMountOptions as ot, ReadFileOptions as p, WorkspaceWriteHook as pt, WorkspacePlugin as q, ExecOptions as r, WorkspaceSourceItem as rt, LoaderContext as s, WorkspaceStat as st, CloudflareArtifactsWorkspaceStoreOptions as t, WorkspaceSnapshot as tt, MemoryWorkspaceStoreOptions as u, WorkspaceSyncOptions as ut, SnapshotOptions as v, WorkspaceWriteValidatorResult as vt, WorkspaceAssetsRegistry as w, Workspace as x, SourceContext as y, WriteFileOptions as yt, WorkspaceMaterializeSourcesOptions as z };
@@ -1,51 +0,0 @@
1
- import { l as sha256 } from "./path-BVv9OXhg.js";
2
- //#region src/storage/utils.ts
3
- async function createSnapshotFromEntries(entries, name) {
4
- const snapshotEntries = {};
5
- for (const entry of entries) snapshotEntries[entry.path] = {
6
- digest: entry.digest,
7
- size: entry.size,
8
- type: entry.type
9
- };
10
- return {
11
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
12
- entries: snapshotEntries,
13
- id: await sha256({
14
- entries: snapshotEntries,
15
- name,
16
- createdAt: Date.now()
17
- }),
18
- name
19
- };
20
- }
21
- function diffSnapshots(from, to) {
22
- const entries = [];
23
- const keys = new Set([...Object.keys(from?.entries || {}), ...Object.keys(to.entries)]);
24
- for (const path of [...keys].sort()) {
25
- const before = from?.entries[path];
26
- const after = to.entries[path];
27
- if (!before && after) entries.push({
28
- path,
29
- type: "added",
30
- after
31
- });
32
- else if (before && !after) entries.push({
33
- path,
34
- type: "removed",
35
- before
36
- });
37
- else if (before && after && (before.digest !== after.digest || before.type !== after.type || before.size !== after.size)) entries.push({
38
- path,
39
- type: "modified",
40
- before,
41
- after
42
- });
43
- }
44
- return {
45
- from: from?.id,
46
- to: to.id,
47
- entries
48
- };
49
- }
50
- //#endregion
51
- export { diffSnapshots as n, createSnapshotFromEntries as t };
File without changes