@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.
Files changed (84) hide show
  1. package/README.md +262 -1
  2. package/dist/ai-Cztw4eLk.js +472 -0
  3. package/dist/ai-hFdsvDHC.d.ts +162 -0
  4. package/dist/ai.d.ts +3 -0
  5. package/dist/ai.js +2 -0
  6. package/dist/artifacts-store-BAV9jZpd.js +555 -0
  7. package/dist/asset-registry-CaG9b7tf.js +19 -0
  8. package/dist/chunk-8H4AJuhK.js +14 -0
  9. package/dist/cli.d.ts +31 -0
  10. package/dist/cli.js +303 -0
  11. package/dist/cloudflare-env-CKxUs2fa.js +20 -0
  12. package/dist/cloudflare.d.ts +16 -0
  13. package/dist/cloudflare.js +3 -0
  14. package/dist/collections/client.d.ts +39 -0
  15. package/dist/collections/client.js +137 -0
  16. package/dist/collections.d.ts +59 -0
  17. package/dist/collections.js +159 -0
  18. package/dist/config--r5unwPc.js +7811 -0
  19. package/dist/config-Ca5DM8fF.d.ts +28 -0
  20. package/dist/config-DCQ6y30R.js +30 -0
  21. package/dist/file-B2q9NE18.js +24 -0
  22. package/dist/files-xy0le-_U.js +51 -0
  23. package/dist/github-lIO6-2sH.js +194 -0
  24. package/dist/glob-DeH0dzZX.js +23 -0
  25. package/dist/host-I-_vDs05.js +370 -0
  26. package/dist/hosted-vercel-blob.d.ts +15 -0
  27. package/dist/hosted-vercel-blob.js +26 -0
  28. package/dist/hosted.d.ts +18 -0
  29. package/dist/hosted.js +30 -0
  30. package/dist/index.d.ts +185 -0
  31. package/dist/index.js +541 -0
  32. package/dist/lifecycle-Lhk3dAMt.js +176 -0
  33. package/dist/loader.d.ts +17 -0
  34. package/dist/loader.js +22 -0
  35. package/dist/nitro.d.ts +2 -0
  36. package/dist/nitro.js +2 -0
  37. package/dist/nuxt.d.ts +26 -0
  38. package/dist/nuxt.js +36 -0
  39. package/dist/path-CNI6wKIU.js +115 -0
  40. package/dist/provider-CeQciesl.js +599 -0
  41. package/dist/providers/cloudflare/artifacts-store.d.ts +6 -0
  42. package/dist/providers/cloudflare/artifacts-store.js +2 -0
  43. package/dist/providers/github/store.d.ts +6 -0
  44. package/dist/providers/github/store.js +362 -0
  45. package/dist/providers/vercel/blob-store.d.ts +6 -0
  46. package/dist/providers/vercel/blob-store.js +235 -0
  47. package/dist/publish.d.ts +35 -0
  48. package/dist/publish.js +112 -0
  49. package/dist/registry-C7DMdBXN.js +74 -0
  50. package/dist/registry-CoC9JxVt.d.ts +11 -0
  51. package/dist/request-execution-C8qRcReq.js +80 -0
  52. package/dist/runtime/assets.d.ts +12 -0
  53. package/dist/runtime/assets.js +138 -0
  54. package/dist/runtime/empty-assets-registry.d.ts +6 -0
  55. package/dist/runtime/empty-assets-registry.js +4 -0
  56. package/dist/runtime/empty-registry.d.ts +6 -0
  57. package/dist/runtime/empty-registry.js +4 -0
  58. package/dist/runtime/state.d.ts +4 -0
  59. package/dist/runtime/state.js +15 -0
  60. package/dist/runtime/workspace.d.ts +2 -0
  61. package/dist/runtime/workspace.js +2 -0
  62. package/dist/runtime.d.ts +38 -0
  63. package/dist/runtime.js +643 -0
  64. package/dist/search-C4REyHj9.js +39 -0
  65. package/dist/server.d.ts +65 -0
  66. package/dist/server.js +355 -0
  67. package/dist/shared-BRycRSbo.js +255 -0
  68. package/dist/source-metadata.d.ts +2 -0
  69. package/dist/source-metadata.js +2 -0
  70. package/dist/state-DSAHEsq6.d.ts +25 -0
  71. package/dist/sync-DO42ypji.js +269 -0
  72. package/dist/target-D4Bqb1eH.js +11 -0
  73. package/dist/test.d.ts +2 -0
  74. package/dist/test.js +2 -0
  75. package/dist/types-DHkae7Cb.d.ts +628 -0
  76. package/dist/use-D16tf8Ph.d.ts +86 -0
  77. package/dist/use-d_PlAdOu.js +353 -0
  78. package/dist/utils-BPdaCyI6.js +55 -0
  79. package/dist/vite-NWC9mFjI.js +1882 -0
  80. package/dist/vite.d.ts +50 -0
  81. package/dist/vite.js +2 -0
  82. package/dist/workspace-f2DBLmPZ.d.ts +6 -0
  83. package/dist/workspace-n4wBmdaM.js +1476 -0
  84. package/package.json +197 -5
@@ -0,0 +1,599 @@
1
+ import { a as matchesAny, c as normalizeWorkspacePath, d as sha256, p as workspaceError, r as contentToBytes, t as contentStreamChunks, u as resolveInside } from "./path-CNI6wKIU.js";
2
+ import { createGitHubWorkspaceStore } from "./providers/github/store.js";
3
+ import { resolve } from "node:path";
4
+ import { createHash, randomUUID } from "node:crypto";
5
+ import { defu } from "defu";
6
+ import { createReadStream, createWriteStream } from "node:fs";
7
+ import { Readable, Transform } from "node:stream";
8
+ import { pipeline } from "node:stream/promises";
9
+ //#region ../internal/src/env.ts
10
+ function trimmed(value) {
11
+ return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
12
+ }
13
+ function readEnv(env, ...names) {
14
+ for (const name of names) {
15
+ const value = trimmed(env[name]);
16
+ if (value) return value;
17
+ }
18
+ }
19
+ //#endregion
20
+ //#region src/runtime/config.ts
21
+ const workspaceRuntimeConfigKey = Symbol.for("vitehub.workspace.runtimeConfig");
22
+ function workspaceRuntimeConfigGlobal() {
23
+ const scope = globalThis;
24
+ scope[workspaceRuntimeConfigKey] ??= false;
25
+ return scope;
26
+ }
27
+ function setWorkspaceRuntimeConfig(config) {
28
+ workspaceRuntimeConfigGlobal()[workspaceRuntimeConfigKey] = config;
29
+ }
30
+ function getWorkspaceRuntimeConfig() {
31
+ return workspaceRuntimeConfigGlobal()[workspaceRuntimeConfigKey] ?? false;
32
+ }
33
+ //#endregion
34
+ //#region src/runtime/hosted-store-loader.ts
35
+ const workspaceHostedStoreLoaderKey = Symbol.for("vitehub.workspace.hostedStoreLoader");
36
+ function workspaceHostedStoreLoaderGlobal() {
37
+ return globalThis;
38
+ }
39
+ function setWorkspaceHostedStoreLoader(loader) {
40
+ workspaceHostedStoreLoaderGlobal()[workspaceHostedStoreLoaderKey] = loader;
41
+ }
42
+ function getWorkspaceHostedStoreLoader() {
43
+ return workspaceHostedStoreLoaderGlobal()[workspaceHostedStoreLoaderKey];
44
+ }
45
+ //#endregion
46
+ //#region src/storage/local.ts
47
+ async function walk(root, current = root) {
48
+ const { readdir } = await import("node:fs/promises");
49
+ const { relative } = await import("node:path");
50
+ const entries = [];
51
+ const dirents = await readdir(current, { withFileTypes: true }).catch((error) => {
52
+ if (error.code === "ENOENT") return [];
53
+ throw error;
54
+ });
55
+ for (const dirent of dirents) {
56
+ const absolute = `${current}/${dirent.name}`;
57
+ const path = normalizeWorkspacePath(relative(root, absolute));
58
+ const { stat } = await import("node:fs/promises");
59
+ const info = await stat(absolute).catch((error) => {
60
+ if (error.code === "ENOENT") return void 0;
61
+ throw error;
62
+ });
63
+ if (!info) continue;
64
+ if (dirent.isDirectory()) {
65
+ entries.push({
66
+ path,
67
+ type: "directory",
68
+ mtime: info.mtimeMs
69
+ });
70
+ entries.push(...await walk(root, absolute));
71
+ continue;
72
+ }
73
+ if (dirent.isFile()) entries.push({
74
+ path,
75
+ type: "file",
76
+ size: info.size,
77
+ mtime: info.mtimeMs,
78
+ digest: await fileDigest(absolute)
79
+ });
80
+ }
81
+ return entries;
82
+ }
83
+ async function fileDigest(path) {
84
+ return await new Promise((resolve, reject) => {
85
+ const hash = createHash("sha256");
86
+ const stream = createReadStream(path);
87
+ stream.on("data", (chunk) => hash.update(chunk));
88
+ stream.on("error", reject);
89
+ stream.on("end", () => resolve(hash.digest("hex")));
90
+ });
91
+ }
92
+ var LocalWorkspaceStore = class {
93
+ root;
94
+ #baseline;
95
+ #files = /* @__PURE__ */ new Map();
96
+ #meta = /* @__PURE__ */ new Map();
97
+ #metaLoaded = false;
98
+ #metaPath;
99
+ constructor(root) {
100
+ this.root = root;
101
+ this.#metaPath = `${root}.meta.json`;
102
+ }
103
+ async readFile(path) {
104
+ const { readFile } = await import("node:fs/promises");
105
+ const bytes = await readFile(resolveInside(this.root, path)).catch((error) => {
106
+ if (error.code === "ENOENT") return void 0;
107
+ throw error;
108
+ });
109
+ if (!bytes) return void 0;
110
+ const normalized = normalizeWorkspacePath(path);
111
+ const metadata = this.#files.get(normalized);
112
+ return {
113
+ path: normalized,
114
+ content: new Uint8Array(bytes),
115
+ mediaType: metadata?.mediaType,
116
+ metadata: metadata?.metadata
117
+ };
118
+ }
119
+ async writeFile(path, file) {
120
+ const { dirname } = await import("node:path");
121
+ const { mkdir, writeFile } = await import("node:fs/promises");
122
+ const absolute = resolveInside(this.root, path);
123
+ const normalized = normalizeWorkspacePath(path);
124
+ const bytes = contentToBytes(file.content);
125
+ const digest = await sha256(bytes);
126
+ const existing = await this.stat(normalized);
127
+ if (existing?.type === "file" && existing.digest === digest) {
128
+ this.#files.set(normalized, {
129
+ mediaType: file.mediaType,
130
+ metadata: file.metadata
131
+ });
132
+ return;
133
+ }
134
+ await mkdir(dirname(absolute), { recursive: true });
135
+ await writeFile(absolute, bytes);
136
+ this.#files.set(normalized, {
137
+ mediaType: file.mediaType,
138
+ metadata: file.metadata
139
+ });
140
+ }
141
+ async writeFileStream(path, file) {
142
+ const { dirname } = await import("node:path");
143
+ const { mkdir, rename, rm } = await import("node:fs/promises");
144
+ const normalized = normalizeWorkspacePath(path);
145
+ const absolute = resolveInside(this.root, path);
146
+ const temp = `${absolute}.${process.pid}.${Date.now()}.tmp`;
147
+ const hash = createHash("sha256");
148
+ let size = 0;
149
+ await mkdir(dirname(absolute), { recursive: true });
150
+ try {
151
+ const hashing = new Transform({ transform(chunk, _encoding, callback) {
152
+ hash.update(chunk);
153
+ size += chunk.byteLength;
154
+ callback(void 0, chunk);
155
+ } });
156
+ await pipeline(Readable.from(contentStreamChunks(file.content)), hashing, createWriteStream(temp));
157
+ const digest = hash.digest("hex");
158
+ const existing = await this.stat(normalized);
159
+ if (existing?.type === "file" && existing.digest === digest) {
160
+ await rm(temp, { force: true });
161
+ this.#files.set(normalized, {
162
+ mediaType: file.mediaType,
163
+ metadata: file.metadata
164
+ });
165
+ return {
166
+ ...existing,
167
+ mediaType: file.mediaType,
168
+ metadata: file.metadata,
169
+ size,
170
+ digest
171
+ };
172
+ }
173
+ await rename(temp, absolute);
174
+ this.#files.set(normalized, {
175
+ mediaType: file.mediaType,
176
+ metadata: file.metadata
177
+ });
178
+ return {
179
+ path: normalized,
180
+ type: "file",
181
+ size,
182
+ mediaType: file.mediaType,
183
+ metadata: file.metadata,
184
+ digest
185
+ };
186
+ } catch (error) {
187
+ await rm(temp, { force: true }).catch(() => void 0);
188
+ throw error;
189
+ }
190
+ }
191
+ async list(prefix = "", options = {}) {
192
+ const normalizedPrefix = normalizeWorkspacePath(prefix);
193
+ return (await walk(this.root)).filter((entry) => {
194
+ if (!normalizedPrefix) return options.recursive || !entry.path.includes("/");
195
+ if (entry.path === normalizedPrefix) return false;
196
+ if (!entry.path.startsWith(`${normalizedPrefix}/`)) return false;
197
+ return options.recursive || !entry.path.slice(normalizedPrefix.length + 1).includes("/");
198
+ }).map((entry) => ({
199
+ ...entry,
200
+ mediaType: entry.type === "file" ? this.#files.get(entry.path)?.mediaType : entry.mediaType,
201
+ metadata: entry.type === "file" ? this.#files.get(entry.path)?.metadata : entry.metadata
202
+ })).sort((a, b) => a.path.localeCompare(b.path));
203
+ }
204
+ async glob(pattern, _options = {}) {
205
+ const patterns = Array.isArray(pattern) ? pattern : [pattern];
206
+ return (await this.list("", { recursive: true })).filter((entry) => entry.type === "file" && patterns.some((item) => matchesAny(entry.path, item)));
207
+ }
208
+ async stat(path) {
209
+ const { stat } = await import("node:fs/promises");
210
+ const normalized = normalizeWorkspacePath(path);
211
+ const absolute = resolveInside(this.root, normalized);
212
+ const info = await stat(absolute).catch((error) => {
213
+ if (error.code === "ENOENT") return void 0;
214
+ throw error;
215
+ });
216
+ if (!info) return void 0;
217
+ return {
218
+ path: normalized,
219
+ type: info.isDirectory() ? "directory" : "file",
220
+ size: info.isFile() ? info.size : void 0,
221
+ mtime: info.mtimeMs,
222
+ mediaType: info.isFile() ? this.#files.get(normalized)?.mediaType : void 0,
223
+ metadata: info.isFile() ? this.#files.get(normalized)?.metadata : void 0,
224
+ digest: info.isFile() ? await fileDigest(absolute) : void 0
225
+ };
226
+ }
227
+ async mkdir(path, options = {}) {
228
+ const { mkdir } = await import("node:fs/promises");
229
+ await mkdir(resolveInside(this.root, path), { recursive: options.recursive ?? true });
230
+ }
231
+ async rm(path, options = {}) {
232
+ const { rm } = await import("node:fs/promises");
233
+ const normalized = normalizeWorkspacePath(path);
234
+ await rm(resolveInside(this.root, path), {
235
+ recursive: options.recursive ?? false,
236
+ force: options.force ?? false
237
+ }).catch((error) => {
238
+ if (error.code === "ENOENT" && options.force) return;
239
+ throw error;
240
+ });
241
+ for (const key of this.#files.keys()) if (key === normalized || key.startsWith(`${normalized}/`)) this.#files.delete(key);
242
+ }
243
+ async snapshot(options = {}) {
244
+ const { mkdir } = await import("node:fs/promises");
245
+ await mkdir(this.root, { recursive: true });
246
+ const snapshot = await this.#createSnapshot(options.name);
247
+ this.#baseline = snapshot;
248
+ return snapshot;
249
+ }
250
+ async diff(options = {}) {
251
+ const from = options.from || this.#baseline;
252
+ const to = await this.#createSnapshot();
253
+ const entries = [];
254
+ const keys = new Set([...Object.keys(from?.entries || {}), ...Object.keys(to.entries)]);
255
+ for (const path of [...keys].sort()) {
256
+ const before = from?.entries[path];
257
+ const after = to.entries[path];
258
+ if (!before && after) entries.push({
259
+ path,
260
+ type: "added",
261
+ after
262
+ });
263
+ else if (before && !after) entries.push({
264
+ path,
265
+ type: "removed",
266
+ before
267
+ });
268
+ else if (before && after && (before.digest !== after.digest || before.type !== after.type || before.size !== after.size || JSON.stringify(before.metadata) !== JSON.stringify(after.metadata))) entries.push({
269
+ path,
270
+ type: "modified",
271
+ before,
272
+ after
273
+ });
274
+ }
275
+ return {
276
+ from: from?.id,
277
+ to: to.id,
278
+ entries
279
+ };
280
+ }
281
+ async getMeta(key) {
282
+ await this.#loadMeta();
283
+ return this.#meta.get(key);
284
+ }
285
+ async setMeta(key, value) {
286
+ await this.#loadMeta();
287
+ this.#meta.set(key, value);
288
+ await this.#writeMeta();
289
+ }
290
+ async #createSnapshot(name) {
291
+ const entries = {};
292
+ for (const entry of await this.list("", { recursive: true })) entries[entry.path] = {
293
+ type: entry.type,
294
+ digest: entry.digest,
295
+ metadata: entry.metadata,
296
+ size: entry.size
297
+ };
298
+ return {
299
+ id: await sha256({
300
+ name,
301
+ entries,
302
+ createdAt: Date.now()
303
+ }),
304
+ name,
305
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
306
+ entries
307
+ };
308
+ }
309
+ async #loadMeta() {
310
+ if (this.#metaLoaded) return;
311
+ this.#metaLoaded = true;
312
+ const { readFile } = await import("node:fs/promises");
313
+ const content = await readFile(this.#metaPath, "utf8").catch((error) => {
314
+ if (error.code === "ENOENT") return void 0;
315
+ throw error;
316
+ });
317
+ if (!content) return;
318
+ const value = JSON.parse(content);
319
+ if (!value || typeof value !== "object" || Array.isArray(value)) return;
320
+ this.#meta = new Map(Object.entries(value));
321
+ }
322
+ async #writeMeta() {
323
+ const { dirname } = await import("node:path");
324
+ const { mkdir, rename, rm, writeFile } = await import("node:fs/promises");
325
+ const temp = `${this.#metaPath}.${randomUUID()}.tmp`;
326
+ await mkdir(dirname(this.#metaPath), { recursive: true });
327
+ try {
328
+ await writeFile(temp, JSON.stringify(Object.fromEntries(this.#meta), null, 2));
329
+ await rename(temp, this.#metaPath);
330
+ } catch (error) {
331
+ await rm(temp, { force: true }).catch(() => void 0);
332
+ throw error;
333
+ }
334
+ }
335
+ };
336
+ function createLocalWorkspaceStore(root) {
337
+ if (!root) throw workspaceError("[vitehub] Local workspace store requires a root directory.");
338
+ return new LocalWorkspaceStore(root);
339
+ }
340
+ //#endregion
341
+ //#region src/storage/memory.ts
342
+ function now() {
343
+ return Date.now();
344
+ }
345
+ var MemoryWorkspaceStore = class {
346
+ #nodes = new Map([["", {
347
+ type: "directory",
348
+ mtime: now()
349
+ }]]);
350
+ #meta = /* @__PURE__ */ new Map();
351
+ #baseline;
352
+ async readFile(path) {
353
+ const normalized = normalizeWorkspacePath(path);
354
+ const node = this.#nodes.get(normalized);
355
+ if (!node || node.type !== "file") return void 0;
356
+ return {
357
+ path: normalized,
358
+ content: node.content || "",
359
+ mediaType: node.mediaType,
360
+ metadata: node.metadata
361
+ };
362
+ }
363
+ async writeFile(path, file) {
364
+ const normalized = normalizeWorkspacePath(path);
365
+ this.#ensureParents(normalized);
366
+ this.#nodes.set(normalized, {
367
+ type: "file",
368
+ content: file.content,
369
+ mediaType: file.mediaType,
370
+ metadata: file.metadata,
371
+ mtime: now()
372
+ });
373
+ }
374
+ async list(prefix = "", options = {}) {
375
+ const normalizedPrefix = normalizeWorkspacePath(prefix);
376
+ const result = [];
377
+ for (const [path, node] of this.#nodes) {
378
+ if (!path || path === normalizedPrefix) continue;
379
+ if (normalizedPrefix && !path.startsWith(`${normalizedPrefix}/`)) continue;
380
+ if (!options.recursive && normalizeWorkspacePath(path.slice(normalizedPrefix.length)).replace(/^\//, "").includes("/")) continue;
381
+ result.push(await this.#entry(path, node));
382
+ }
383
+ return result.sort((a, b) => a.path.localeCompare(b.path));
384
+ }
385
+ async glob(pattern, _options = {}) {
386
+ const entries = await this.list("", { recursive: true });
387
+ const patterns = Array.isArray(pattern) ? pattern : [pattern];
388
+ return entries.filter((entry) => entry.type === "file" && patterns.some((item) => matchesAny(entry.path, item)));
389
+ }
390
+ async stat(path) {
391
+ const normalized = normalizeWorkspacePath(path);
392
+ const node = this.#nodes.get(normalized);
393
+ return node ? await this.#entry(normalized, node) : void 0;
394
+ }
395
+ async mkdir(path, _options = {}) {
396
+ const normalized = normalizeWorkspacePath(path);
397
+ this.#ensureParents(normalized);
398
+ this.#nodes.set(normalized, {
399
+ type: "directory",
400
+ mtime: now()
401
+ });
402
+ }
403
+ async rm(path, options = {}) {
404
+ const normalized = normalizeWorkspacePath(path);
405
+ const node = this.#nodes.get(normalized);
406
+ if (!node) {
407
+ if (options.force) return;
408
+ throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
409
+ }
410
+ if (node.type === "directory" && !options.recursive) {
411
+ for (const key of this.#nodes.keys()) if (key.startsWith(`${normalized}/`)) throw workspaceError(`[vitehub] Workspace directory is not empty: ${path}.`);
412
+ }
413
+ for (const key of this.#nodes.keys()) if (key === normalized || key.startsWith(`${normalized}/`)) this.#nodes.delete(key);
414
+ }
415
+ async snapshot(options = {}) {
416
+ const snapshot = await this.#createSnapshot(options.name);
417
+ this.#baseline = snapshot;
418
+ return snapshot;
419
+ }
420
+ async diff(options = {}) {
421
+ const from = options.from || this.#baseline;
422
+ const to = await this.#createSnapshot();
423
+ const entries = [];
424
+ const keys = new Set([...Object.keys(from?.entries || {}), ...Object.keys(to.entries)]);
425
+ for (const path of [...keys].sort()) {
426
+ const before = from?.entries[path];
427
+ const after = to.entries[path];
428
+ if (!before && after) entries.push({
429
+ path,
430
+ type: "added",
431
+ after
432
+ });
433
+ else if (before && !after) entries.push({
434
+ path,
435
+ type: "removed",
436
+ before
437
+ });
438
+ else if (before && after && (before.digest !== after.digest || before.type !== after.type || before.size !== after.size || JSON.stringify(before.metadata) !== JSON.stringify(after.metadata))) entries.push({
439
+ path,
440
+ type: "modified",
441
+ before,
442
+ after
443
+ });
444
+ }
445
+ return {
446
+ from: from?.id,
447
+ to: to.id,
448
+ entries
449
+ };
450
+ }
451
+ async getMeta(key) {
452
+ return this.#meta.get(key);
453
+ }
454
+ async setMeta(key, value) {
455
+ this.#meta.set(key, value);
456
+ }
457
+ #ensureParents(path) {
458
+ const parts = normalizeWorkspacePath(path).split("/").filter(Boolean);
459
+ for (let index = 1; index < parts.length; index++) {
460
+ const dir = parts.slice(0, index).join("/");
461
+ if (!this.#nodes.has(dir)) this.#nodes.set(dir, {
462
+ type: "directory",
463
+ mtime: now()
464
+ });
465
+ }
466
+ }
467
+ async #entry(path, node) {
468
+ const content = node.content || "";
469
+ const size = node.type === "file" ? typeof content === "string" ? new TextEncoder().encode(content).byteLength : content.byteLength : void 0;
470
+ return {
471
+ path,
472
+ type: node.type,
473
+ size,
474
+ mtime: node.mtime,
475
+ mediaType: node.mediaType,
476
+ metadata: node.metadata,
477
+ digest: node.type === "file" ? await sha256(content) : void 0
478
+ };
479
+ }
480
+ async #createSnapshot(name) {
481
+ const entries = {};
482
+ for (const [path, node] of this.#nodes) {
483
+ if (!path) continue;
484
+ const entry = await this.#entry(path, node);
485
+ entries[path] = {
486
+ type: entry.type,
487
+ digest: entry.digest,
488
+ metadata: entry.metadata,
489
+ size: entry.size
490
+ };
491
+ }
492
+ return {
493
+ id: await sha256({
494
+ name,
495
+ entries,
496
+ createdAt: Date.now()
497
+ }),
498
+ name,
499
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
500
+ entries
501
+ };
502
+ }
503
+ };
504
+ function createMemoryWorkspaceStore() {
505
+ return new MemoryWorkspaceStore();
506
+ }
507
+ //#endregion
508
+ //#region src/storage/provider.ts
509
+ const MASKED_WORKSPACE_RUNTIME_VALUE = "********";
510
+ function workspaceRepoName(name) {
511
+ return name ? name.replace(/[^a-zA-Z0-9_.-]/g, "-") : void 0;
512
+ }
513
+ function gitHubWorkspaceOption(value) {
514
+ return typeof value === "function" ? value : trimmed(value);
515
+ }
516
+ function resolveCloudflareArtifactsStore(config = {}, env = process.env) {
517
+ const repoPrefix = trimmed(config.repoPrefix) ?? readEnv(env, "WORKSPACE_ARTIFACTS_REPO_PREFIX", "VITEHUB_WORKSPACE_ARTIFACTS_REPO_PREFIX") ?? "vitehub-workspace-";
518
+ const repo = trimmed(config.repo) ?? workspaceRepoName(readEnv(env, "WORKSPACE_ARTIFACTS_REPO", "VITEHUB_WORKSPACE_ARTIFACTS_REPO"));
519
+ return defu({
520
+ binding: trimmed(config.binding) ?? readEnv(env, "WORKSPACE_ARTIFACTS_BINDING", "VITEHUB_WORKSPACE_ARTIFACTS_BINDING"),
521
+ branch: trimmed(config.branch) ?? readEnv(env, "WORKSPACE_ARTIFACTS_BRANCH", "VITEHUB_WORKSPACE_ARTIFACTS_BRANCH"),
522
+ namespace: trimmed(config.namespace) ?? readEnv(env, "WORKSPACE_ARTIFACTS_NAMESPACE", "VITEHUB_WORKSPACE_ARTIFACTS_NAMESPACE"),
523
+ repo,
524
+ repoPrefix
525
+ }, {
526
+ binding: "WORKSPACE_ARTIFACTS",
527
+ namespace: "vitehub",
528
+ provider: "cloudflare-artifacts"
529
+ });
530
+ }
531
+ function resolveVercelBlobWorkspaceStore(config = {}, env = process.env) {
532
+ return {
533
+ access: config.access ?? "private",
534
+ prefix: trimmed(config.prefix) ?? readEnv(env, "WORKSPACE_BLOB_PREFIX", "VITEHUB_WORKSPACE_BLOB_PREFIX") ?? ".vitehub/workspaces",
535
+ provider: "vercel-blob",
536
+ token: MASKED_WORKSPACE_RUNTIME_VALUE
537
+ };
538
+ }
539
+ function resolveGitHubWorkspaceStore(config = {}, env = process.env, input = {}) {
540
+ return {
541
+ branch: gitHubWorkspaceOption(config.branch) ?? readEnv(env, "WORKSPACE_GITHUB_BRANCH", "VITEHUB_WORKSPACE_GITHUB_BRANCH", "GITHUB_BRANCH") ?? "main",
542
+ provider: "github",
543
+ repository: gitHubWorkspaceOption(config.repository) ?? gitHubWorkspaceOption(config.repo) ?? readEnv(env, "WORKSPACE_GITHUB_REPOSITORY", "VITEHUB_WORKSPACE_GITHUB_REPOSITORY", "GITHUB_REPOSITORY"),
544
+ root: gitHubWorkspaceOption(config.root) ?? readEnv(env, "WORKSPACE_GITHUB_ROOT", "VITEHUB_WORKSPACE_GITHUB_ROOT") ?? ".vitehub/workspaces/<workspace>",
545
+ token: input.runtime ? gitHubWorkspaceOption(config.token) ?? "********" : MASKED_WORKSPACE_RUNTIME_VALUE
546
+ };
547
+ }
548
+ function hasVercelWorkspaceBlobEnv(env) {
549
+ return Boolean(readEnv(env, "BLOB_READ_WRITE_TOKEN"));
550
+ }
551
+ function normalizeWorkspaceStoreOptions(store, input = {}) {
552
+ if (store && "readFile" in store) return;
553
+ if (input.dev && !store) return { provider: "local" };
554
+ const env = input.env || process.env;
555
+ const hosting = input.hosting || "";
556
+ if (store?.provider === "cloudflare-artifacts") return resolveCloudflareArtifactsStore(store, env);
557
+ if (store?.provider === "github") return resolveGitHubWorkspaceStore(store, env, input);
558
+ if (store?.provider === "memory") return store;
559
+ if (store?.provider === "vercel-blob") return resolveVercelBlobWorkspaceStore(store, env);
560
+ if (store?.provider === "local" || store?.root) return defu(store, { provider: "local" });
561
+ if (store && "provider" in store) throw workspaceError(`[vitehub] Unsupported workspace store provider: ${String(store.provider)}.`);
562
+ if (hosting.includes("cloudflare")) return { provider: "memory" };
563
+ if (hasVercelWorkspaceBlobEnv(env)) return resolveVercelBlobWorkspaceStore({}, env);
564
+ if (hosting.includes("vercel")) return { provider: "memory" };
565
+ return { provider: "local" };
566
+ }
567
+ function createWorkspaceStoreFromProvider(definition) {
568
+ if (definition.store && "readFile" in definition.store) return definition.store;
569
+ const rootDir = definition.rootDir || process.cwd();
570
+ const runtimeConfig = getWorkspaceRuntimeConfig();
571
+ const runtimeStore = runtimeConfig ? runtimeConfig.store : void 0;
572
+ const store = normalizeWorkspaceStoreOptions(definition.store || runtimeStore, {
573
+ env: typeof process !== "undefined" ? process.env : {},
574
+ hosting: typeof process !== "undefined" ? process.env.VITEHUB_HOSTING : void 0,
575
+ rootDir,
576
+ runtime: true
577
+ });
578
+ if (store?.provider === "memory") return createMemoryWorkspaceStore();
579
+ if (store?.provider === "cloudflare-artifacts" || store?.provider === "github" || store?.provider === "vercel-blob") {
580
+ const loader = getWorkspaceHostedStoreLoader();
581
+ if (!loader && store.provider === "github") return createGitHubWorkspaceStore(store, definition.name);
582
+ if (!loader) throw workspaceError(`[vitehub] Hosted workspace store "${store.provider}" is not available in this runtime.`);
583
+ return loader(store, definition.name);
584
+ }
585
+ return createLocalWorkspaceStore(store?.root ? resolve(rootDir, store.root) : runtimeConfig ? resolve(runtimeConfig.root, definition.name) : resolve(rootDir, ".vitehub/workspaces", definition.name));
586
+ }
587
+ function isMaskedWorkspaceRuntimeValue(value) {
588
+ return !value || value === "********";
589
+ }
590
+ function resolveRuntimeVercelBlobWorkspaceStore(config, env) {
591
+ const token = readEnv(env, "BLOB_READ_WRITE_TOKEN");
592
+ if (isMaskedWorkspaceRuntimeValue(token)) throw new Error("Missing runtime environment variable `BLOB_READ_WRITE_TOKEN` for Vercel workspace Blob storage.");
593
+ return {
594
+ ...config,
595
+ token
596
+ };
597
+ }
598
+ //#endregion
599
+ export { resolveRuntimeVercelBlobWorkspaceStore as a, getWorkspaceHostedStoreLoader as c, setWorkspaceRuntimeConfig as d, resolveGitHubWorkspaceStore as i, setWorkspaceHostedStoreLoader as l, normalizeWorkspaceStoreOptions as n, resolveVercelBlobWorkspaceStore as o, resolveCloudflareArtifactsStore as r, createMemoryWorkspaceStore as s, createWorkspaceStoreFromProvider as t, getWorkspaceRuntimeConfig as u };
@@ -0,0 +1,6 @@
1
+ import { Zt as WorkspaceStore, t as CloudflareArtifactsWorkspaceStoreOptions } from "../../types-DHkae7Cb.js";
2
+
3
+ //#region src/providers/cloudflare/artifacts-store.d.ts
4
+ declare function createCloudflareArtifactsWorkspaceStore(options: CloudflareArtifactsWorkspaceStoreOptions, workspaceName: string): WorkspaceStore;
5
+ //#endregion
6
+ export { createCloudflareArtifactsWorkspaceStore };
@@ -0,0 +1,2 @@
1
+ import { t as createCloudflareArtifactsWorkspaceStore } from "../../artifacts-store-BAV9jZpd.js";
2
+ export { createCloudflareArtifactsWorkspaceStore };
@@ -0,0 +1,6 @@
1
+ import { Zt as WorkspaceStore, o as GitHubWorkspaceStoreOptions } from "../../types-DHkae7Cb.js";
2
+
3
+ //#region src/providers/github/store.d.ts
4
+ declare function createGitHubWorkspaceStore(options: GitHubWorkspaceStoreOptions, workspaceName: string): WorkspaceStore;
5
+ //#endregion
6
+ export { createGitHubWorkspaceStore };