@vite-hub/workspace 0.0.0 → 0.0.1

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 (47) hide show
  1. package/README.md +89 -1
  2. package/dist/ai-Bk3LLnit.js +352 -0
  3. package/dist/ai.d.ts +86 -0
  4. package/dist/ai.js +2 -0
  5. package/dist/asset-registry-CMuQbyvl.js +14 -0
  6. package/dist/chunk-DrSxFLj_.js +14 -0
  7. package/dist/cloudflare-env-DL94Uvpz.js +12 -0
  8. package/dist/config-CvS-7sre.js +49 -0
  9. package/dist/errors-BUL8SoFS.js +21 -0
  10. package/dist/files-DbsIjBya.js +50 -0
  11. package/dist/index.d.ts +150 -0
  12. package/dist/index.js +656 -0
  13. package/dist/lifecycle-uD82JeGh.js +92 -0
  14. package/dist/loader.d.ts +17 -0
  15. package/dist/loader.js +22 -0
  16. package/dist/module-8LZUMEXC.js +922 -0
  17. package/dist/nitro.d.ts +31 -0
  18. package/dist/nitro.js +2 -0
  19. package/dist/path-BVv9OXhg.js +63 -0
  20. package/dist/provider-BZuKAV4e.js +494 -0
  21. package/dist/providers/cloudflare/artifacts-store.d.ts +6 -0
  22. package/dist/providers/cloudflare/artifacts-store.js +384 -0
  23. package/dist/providers/vercel/blob-store.d.ts +6 -0
  24. package/dist/providers/vercel/blob-store.js +176 -0
  25. package/dist/publish.d.ts +34 -0
  26. package/dist/publish.js +206 -0
  27. package/dist/registry-Cnr0NoKv.js +932 -0
  28. package/dist/registry-D4Qzq26I.d.ts +10 -0
  29. package/dist/runtime/assets.d.ts +11 -0
  30. package/dist/runtime/assets.js +138 -0
  31. package/dist/runtime/empty-assets-registry.d.ts +6 -0
  32. package/dist/runtime/empty-assets-registry.js +4 -0
  33. package/dist/runtime/empty-registry.d.ts +6 -0
  34. package/dist/runtime/empty-registry.js +4 -0
  35. package/dist/runtime/nitro-plugin.d.ts +6 -0
  36. package/dist/runtime/nitro-plugin.js +14 -0
  37. package/dist/runtime/state.d.ts +21 -0
  38. package/dist/runtime/state.js +12 -0
  39. package/dist/sandbox-DtGXCWRq.js +198 -0
  40. package/dist/search-DtaEyjpO.js +39 -0
  41. package/dist/test.d.ts +2 -0
  42. package/dist/test.js +2 -0
  43. package/dist/types-CwNcWTdt.d.ts +378 -0
  44. package/dist/utils-BtAm_K5P.js +51 -0
  45. package/dist/vite.d.ts +22 -0
  46. package/dist/vite.js +131 -0
  47. package/package.json +101 -5
@@ -0,0 +1,31 @@
1
+ import { V as WorkspaceModuleOptions, h as ResolvedWorkspaceModuleOptions } from "./types-CwNcWTdt.js";
2
+
3
+ //#region src/hosts/nitro/module.d.ts
4
+ interface WorkspaceNitroModule {
5
+ name: string;
6
+ setup(this: void, nitro: unknown): void | Promise<void>;
7
+ }
8
+ declare function workspaceNitro(options?: false | WorkspaceModuleOptions): WorkspaceNitroModule;
9
+ declare const workspaceNitroModule: WorkspaceNitroModule;
10
+ declare module "nitro/types" {
11
+ interface NitroConfig {
12
+ workspace?: false | WorkspaceModuleOptions;
13
+ }
14
+ interface NitroOptions {
15
+ workspace?: false | WorkspaceModuleOptions;
16
+ cloudflare?: {
17
+ wrangler?: {
18
+ artifacts?: Array<{
19
+ binding: string;
20
+ namespace: string;
21
+ }>;
22
+ };
23
+ };
24
+ }
25
+ interface NitroRuntimeConfig {
26
+ hosting?: string;
27
+ workspace?: false | ResolvedWorkspaceModuleOptions;
28
+ }
29
+ }
30
+ //#endregion
31
+ export { WorkspaceNitroModule, workspaceNitroModule as default, workspaceNitro };
package/dist/nitro.js ADDED
@@ -0,0 +1,2 @@
1
+ import { n as workspaceNitroModule, t as workspaceNitro } from "./module-8LZUMEXC.js";
2
+ export { workspaceNitroModule as default, workspaceNitro };
@@ -0,0 +1,63 @@
1
+ import { t as __exportAll } from "./chunk-DrSxFLj_.js";
2
+ import { r as WorkspacePathError } from "./errors-BUL8SoFS.js";
3
+ import { relative, resolve, sep } from "node:path";
4
+ import { createHash } from "node:crypto";
5
+ import { minimatch } from "minimatch";
6
+ //#region src/core/path.ts
7
+ var path_exports = /* @__PURE__ */ __exportAll({
8
+ contentToBytes: () => contentToBytes,
9
+ decodeFile: () => decodeFile,
10
+ matchesAny: () => matchesAny,
11
+ normalizeSafeWorkspacePath: () => normalizeSafeWorkspacePath,
12
+ normalizeSafeWorkspacePattern: () => normalizeSafeWorkspacePattern,
13
+ normalizeWorkspacePath: () => normalizeWorkspacePath,
14
+ resolveInside: () => resolveInside,
15
+ sha256: () => sha256
16
+ });
17
+ function normalizeWorkspacePath(path = "") {
18
+ return path.replace(/\\/g, "/").replace(/^\/+/, "").replace(/\/+$/, "");
19
+ }
20
+ function normalizeSafeWorkspacePath(path = "", options = {}) {
21
+ const raw = path.replace(/\\/g, "/");
22
+ const normalized = normalizeWorkspacePath(path);
23
+ const parts = normalized.split("/").filter(Boolean);
24
+ if (!options.allowEmpty && !normalized) throw new WorkspacePathError(path);
25
+ if (raw.startsWith("/") || parts.some((part) => part === "." || part === "..")) throw new WorkspacePathError(path);
26
+ if (!options.allowReserved && (parts[0] === ".git" || parts[0] === ".vitehub")) throw new WorkspacePathError(path);
27
+ return normalized;
28
+ }
29
+ function normalizeSafeWorkspacePattern(pattern) {
30
+ return normalizeSafeWorkspacePath(pattern, {
31
+ allowEmpty: true,
32
+ pattern: true
33
+ });
34
+ }
35
+ function resolveInside(root, path = "") {
36
+ const resolvedRoot = resolve(root);
37
+ const resolved = resolve(resolvedRoot, normalizeWorkspacePath(path));
38
+ const rel = relative(resolvedRoot, resolved);
39
+ if (rel.startsWith("..") || rel === ".." || rel.includes(`..${sep}`) || rel === "") {
40
+ if (rel === "") return resolved;
41
+ throw new WorkspacePathError(path);
42
+ }
43
+ return resolved;
44
+ }
45
+ function matchesAny(path, patterns) {
46
+ if (!patterns) return true;
47
+ const list = Array.isArray(patterns) ? patterns : [patterns];
48
+ const normalizedPath = normalizeWorkspacePath(path);
49
+ return list.some((pattern) => minimatch(normalizedPath, normalizeWorkspacePath(pattern), { dot: true }));
50
+ }
51
+ function contentToBytes(content) {
52
+ return typeof content === "string" ? new TextEncoder().encode(content) : content;
53
+ }
54
+ function decodeFile(content, options) {
55
+ if (options?.encoding === "binary") return content;
56
+ return typeof content === "string" ? content : new TextDecoder().decode(content);
57
+ }
58
+ async function sha256(input) {
59
+ const bytes = contentToBytes(typeof input === "string" || input instanceof Uint8Array ? input : JSON.stringify(input));
60
+ return createHash("sha256").update(bytes).digest("hex");
61
+ }
62
+ //#endregion
63
+ export { normalizeSafeWorkspacePattern as a, resolveInside as c, normalizeSafeWorkspacePath as i, sha256 as l, decodeFile as n, normalizeWorkspacePath as o, matchesAny as r, path_exports as s, contentToBytes as t };
@@ -0,0 +1,494 @@
1
+ import { t as WorkspaceError } from "./errors-BUL8SoFS.js";
2
+ import { c as resolveInside, l as sha256, o as normalizeWorkspacePath, r as matchesAny, t as contentToBytes } from "./path-BVv9OXhg.js";
3
+ import { resolve } from "node:path";
4
+ import { defu } from "defu";
5
+ //#region ../internal/src/env.ts
6
+ function trimmed(value) {
7
+ return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
8
+ }
9
+ function readEnv(env, ...names) {
10
+ for (const name of names) {
11
+ const value = trimmed(env[name]);
12
+ if (value) return value;
13
+ }
14
+ }
15
+ //#endregion
16
+ //#region src/runtime/config.ts
17
+ let workspaceRuntimeConfig = false;
18
+ function setWorkspaceRuntimeConfig(config) {
19
+ workspaceRuntimeConfig = config;
20
+ }
21
+ function getWorkspaceRuntimeConfig() {
22
+ return workspaceRuntimeConfig;
23
+ }
24
+ //#endregion
25
+ //#region src/runtime/hosted-store-loader.ts
26
+ let workspaceHostedStoreLoader;
27
+ function setWorkspaceHostedStoreLoader(loader) {
28
+ workspaceHostedStoreLoader = loader;
29
+ }
30
+ function getWorkspaceHostedStoreLoader() {
31
+ return workspaceHostedStoreLoader;
32
+ }
33
+ //#endregion
34
+ //#region src/storage/local.ts
35
+ async function walk(root, current = root) {
36
+ const { readdir } = await import("node:fs/promises");
37
+ const { relative } = await import("node:path");
38
+ const entries = [];
39
+ const dirents = await readdir(current, { withFileTypes: true }).catch((error) => {
40
+ if (error.code === "ENOENT") return [];
41
+ throw error;
42
+ });
43
+ for (const dirent of dirents) {
44
+ const absolute = `${current}/${dirent.name}`;
45
+ const path = normalizeWorkspacePath(relative(root, absolute));
46
+ const { stat, readFile } = await import("node:fs/promises");
47
+ const info = await stat(absolute).catch((error) => {
48
+ if (error.code === "ENOENT") return void 0;
49
+ throw error;
50
+ });
51
+ if (!info) continue;
52
+ if (dirent.isDirectory()) {
53
+ entries.push({
54
+ path,
55
+ type: "directory",
56
+ mtime: info.mtimeMs
57
+ });
58
+ entries.push(...await walk(root, absolute));
59
+ continue;
60
+ }
61
+ if (dirent.isFile()) {
62
+ const bytes = await readFile(absolute);
63
+ entries.push({
64
+ path,
65
+ type: "file",
66
+ size: info.size,
67
+ mtime: info.mtimeMs,
68
+ digest: await sha256(bytes)
69
+ });
70
+ }
71
+ }
72
+ return entries;
73
+ }
74
+ var LocalWorkspaceStore = class {
75
+ #baseline;
76
+ #files = /* @__PURE__ */ new Map();
77
+ #meta = /* @__PURE__ */ new Map();
78
+ #metaLoaded = false;
79
+ #metaPath;
80
+ constructor(root) {
81
+ this.root = root;
82
+ this.#metaPath = `${root}.meta.json`;
83
+ }
84
+ async readFile(path) {
85
+ const { readFile } = await import("node:fs/promises");
86
+ const bytes = await readFile(resolveInside(this.root, path)).catch((error) => {
87
+ if (error.code === "ENOENT") return void 0;
88
+ throw error;
89
+ });
90
+ if (!bytes) return void 0;
91
+ const normalized = normalizeWorkspacePath(path);
92
+ const metadata = this.#files.get(normalized);
93
+ return {
94
+ path: normalized,
95
+ content: new Uint8Array(bytes),
96
+ mediaType: metadata?.mediaType,
97
+ metadata: metadata?.metadata
98
+ };
99
+ }
100
+ async writeFile(path, file) {
101
+ const { dirname } = await import("node:path");
102
+ const { mkdir, writeFile } = await import("node:fs/promises");
103
+ const absolute = resolveInside(this.root, path);
104
+ await mkdir(dirname(absolute), { recursive: true });
105
+ await writeFile(absolute, contentToBytes(file.content));
106
+ this.#files.set(normalizeWorkspacePath(path), {
107
+ mediaType: file.mediaType,
108
+ metadata: file.metadata
109
+ });
110
+ }
111
+ async list(prefix = "", options = {}) {
112
+ const normalizedPrefix = normalizeWorkspacePath(prefix);
113
+ return (await walk(this.root)).filter((entry) => {
114
+ if (!normalizedPrefix) return options.recursive || !entry.path.includes("/");
115
+ if (entry.path === normalizedPrefix) return false;
116
+ if (!entry.path.startsWith(`${normalizedPrefix}/`)) return false;
117
+ return options.recursive || !entry.path.slice(normalizedPrefix.length + 1).includes("/");
118
+ }).map((entry) => ({
119
+ ...entry,
120
+ mediaType: entry.type === "file" ? this.#files.get(entry.path)?.mediaType : entry.mediaType
121
+ })).sort((a, b) => a.path.localeCompare(b.path));
122
+ }
123
+ async glob(pattern, _options = {}) {
124
+ const patterns = Array.isArray(pattern) ? pattern : [pattern];
125
+ return (await this.list("", { recursive: true })).filter((entry) => entry.type === "file" && patterns.some((item) => matchesAny(entry.path, item)));
126
+ }
127
+ async stat(path) {
128
+ const { readFile, stat } = await import("node:fs/promises");
129
+ const normalized = normalizeWorkspacePath(path);
130
+ const absolute = resolveInside(this.root, normalized);
131
+ const info = await stat(absolute).catch((error) => {
132
+ if (error.code === "ENOENT") return void 0;
133
+ throw error;
134
+ });
135
+ if (!info) return void 0;
136
+ return {
137
+ path: normalized,
138
+ type: info.isDirectory() ? "directory" : "file",
139
+ size: info.isFile() ? info.size : void 0,
140
+ mtime: info.mtimeMs,
141
+ mediaType: info.isFile() ? this.#files.get(normalized)?.mediaType : void 0,
142
+ digest: info.isFile() ? await sha256(await readFile(absolute)) : void 0
143
+ };
144
+ }
145
+ async mkdir(path, options = {}) {
146
+ const { mkdir } = await import("node:fs/promises");
147
+ await mkdir(resolveInside(this.root, path), { recursive: options.recursive ?? true });
148
+ }
149
+ async rm(path, options = {}) {
150
+ const { rm } = await import("node:fs/promises");
151
+ const normalized = normalizeWorkspacePath(path);
152
+ await rm(resolveInside(this.root, path), {
153
+ recursive: options.recursive ?? false,
154
+ force: options.force ?? false
155
+ }).catch((error) => {
156
+ if (error.code === "ENOENT" && options.force) return;
157
+ throw error;
158
+ });
159
+ for (const key of this.#files.keys()) if (key === normalized || key.startsWith(`${normalized}/`)) this.#files.delete(key);
160
+ }
161
+ async snapshot(options = {}) {
162
+ const { mkdir } = await import("node:fs/promises");
163
+ await mkdir(this.root, { recursive: true });
164
+ const snapshot = await this.#createSnapshot(options.name);
165
+ this.#baseline = snapshot;
166
+ return snapshot;
167
+ }
168
+ async diff(options = {}) {
169
+ const from = options.from || this.#baseline;
170
+ const to = await this.#createSnapshot();
171
+ const entries = [];
172
+ const keys = new Set([...Object.keys(from?.entries || {}), ...Object.keys(to.entries)]);
173
+ for (const path of [...keys].sort()) {
174
+ const before = from?.entries[path];
175
+ const after = to.entries[path];
176
+ if (!before && after) entries.push({
177
+ path,
178
+ type: "added",
179
+ after
180
+ });
181
+ else if (before && !after) entries.push({
182
+ path,
183
+ type: "removed",
184
+ before
185
+ });
186
+ else if (before && after && (before.digest !== after.digest || before.type !== after.type || before.size !== after.size)) entries.push({
187
+ path,
188
+ type: "modified",
189
+ before,
190
+ after
191
+ });
192
+ }
193
+ return {
194
+ from: from?.id,
195
+ to: to.id,
196
+ entries
197
+ };
198
+ }
199
+ async getMeta(key) {
200
+ await this.#loadMeta();
201
+ return this.#meta.get(key);
202
+ }
203
+ async setMeta(key, value) {
204
+ await this.#loadMeta();
205
+ this.#meta.set(key, value);
206
+ await this.#writeMeta();
207
+ }
208
+ async #createSnapshot(name) {
209
+ const entries = {};
210
+ for (const entry of await this.list("", { recursive: true })) entries[entry.path] = {
211
+ type: entry.type,
212
+ digest: entry.digest,
213
+ size: entry.size
214
+ };
215
+ return {
216
+ id: await sha256({
217
+ name,
218
+ entries,
219
+ createdAt: Date.now()
220
+ }),
221
+ name,
222
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
223
+ entries
224
+ };
225
+ }
226
+ async #loadMeta() {
227
+ if (this.#metaLoaded) return;
228
+ this.#metaLoaded = true;
229
+ const { readFile } = await import("node:fs/promises");
230
+ const content = await readFile(this.#metaPath, "utf8").catch((error) => {
231
+ if (error.code === "ENOENT") return void 0;
232
+ throw error;
233
+ });
234
+ if (!content) return;
235
+ const value = JSON.parse(content);
236
+ if (!value || typeof value !== "object" || Array.isArray(value)) return;
237
+ this.#meta = new Map(Object.entries(value));
238
+ }
239
+ async #writeMeta() {
240
+ const { dirname } = await import("node:path");
241
+ const { mkdir, writeFile } = await import("node:fs/promises");
242
+ await mkdir(dirname(this.#metaPath), { recursive: true });
243
+ await writeFile(this.#metaPath, JSON.stringify(Object.fromEntries(this.#meta), null, 2));
244
+ }
245
+ };
246
+ function createLocalWorkspaceStore(root) {
247
+ if (!root) throw new WorkspaceError("[vitehub] Local workspace store requires a root directory.");
248
+ return new LocalWorkspaceStore(root);
249
+ }
250
+ //#endregion
251
+ //#region src/storage/memory.ts
252
+ function now() {
253
+ return Date.now();
254
+ }
255
+ var MemoryWorkspaceStore = class {
256
+ #nodes = new Map([["", {
257
+ type: "directory",
258
+ mtime: now()
259
+ }]]);
260
+ #meta = /* @__PURE__ */ new Map();
261
+ #baseline;
262
+ async readFile(path) {
263
+ const normalized = normalizeWorkspacePath(path);
264
+ const node = this.#nodes.get(normalized);
265
+ if (!node || node.type !== "file") return void 0;
266
+ return {
267
+ path: normalized,
268
+ content: node.content || "",
269
+ mediaType: node.mediaType,
270
+ metadata: node.metadata
271
+ };
272
+ }
273
+ async writeFile(path, file) {
274
+ const normalized = normalizeWorkspacePath(path);
275
+ this.#ensureParents(normalized);
276
+ this.#nodes.set(normalized, {
277
+ type: "file",
278
+ content: file.content,
279
+ mediaType: file.mediaType,
280
+ metadata: file.metadata,
281
+ mtime: now()
282
+ });
283
+ }
284
+ async list(prefix = "", options = {}) {
285
+ const normalizedPrefix = normalizeWorkspacePath(prefix);
286
+ const result = [];
287
+ for (const [path, node] of this.#nodes) {
288
+ if (!path || path === normalizedPrefix) continue;
289
+ if (normalizedPrefix && !path.startsWith(`${normalizedPrefix}/`)) continue;
290
+ if (!options.recursive && normalizeWorkspacePath(path.slice(normalizedPrefix.length)).replace(/^\//, "").includes("/")) continue;
291
+ result.push(await this.#entry(path, node));
292
+ }
293
+ return result.sort((a, b) => a.path.localeCompare(b.path));
294
+ }
295
+ async glob(pattern, _options = {}) {
296
+ const entries = await this.list("", { recursive: true });
297
+ const patterns = Array.isArray(pattern) ? pattern : [pattern];
298
+ return entries.filter((entry) => entry.type === "file" && patterns.some((item) => matchesAny(entry.path, item)));
299
+ }
300
+ async stat(path) {
301
+ const normalized = normalizeWorkspacePath(path);
302
+ const node = this.#nodes.get(normalized);
303
+ return node ? await this.#entry(normalized, node) : void 0;
304
+ }
305
+ async mkdir(path, _options = {}) {
306
+ const normalized = normalizeWorkspacePath(path);
307
+ this.#ensureParents(normalized);
308
+ this.#nodes.set(normalized, {
309
+ type: "directory",
310
+ mtime: now()
311
+ });
312
+ }
313
+ async rm(path, options = {}) {
314
+ const normalized = normalizeWorkspacePath(path);
315
+ const node = this.#nodes.get(normalized);
316
+ if (!node) {
317
+ if (options.force) return;
318
+ throw new WorkspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
319
+ }
320
+ if (node.type === "directory" && !options.recursive) {
321
+ for (const key of this.#nodes.keys()) if (key.startsWith(`${normalized}/`)) throw new WorkspaceError(`[vitehub] Workspace directory is not empty: ${path}.`);
322
+ }
323
+ for (const key of this.#nodes.keys()) if (key === normalized || key.startsWith(`${normalized}/`)) this.#nodes.delete(key);
324
+ }
325
+ async snapshot(options = {}) {
326
+ const snapshot = await this.#createSnapshot(options.name);
327
+ this.#baseline = snapshot;
328
+ return snapshot;
329
+ }
330
+ async diff(options = {}) {
331
+ const from = options.from || this.#baseline;
332
+ const to = await this.#createSnapshot();
333
+ const entries = [];
334
+ const keys = new Set([...Object.keys(from?.entries || {}), ...Object.keys(to.entries)]);
335
+ for (const path of [...keys].sort()) {
336
+ const before = from?.entries[path];
337
+ const after = to.entries[path];
338
+ if (!before && after) entries.push({
339
+ path,
340
+ type: "added",
341
+ after
342
+ });
343
+ else if (before && !after) entries.push({
344
+ path,
345
+ type: "removed",
346
+ before
347
+ });
348
+ else if (before && after && (before.digest !== after.digest || before.type !== after.type || before.size !== after.size)) entries.push({
349
+ path,
350
+ type: "modified",
351
+ before,
352
+ after
353
+ });
354
+ }
355
+ return {
356
+ from: from?.id,
357
+ to: to.id,
358
+ entries
359
+ };
360
+ }
361
+ async getMeta(key) {
362
+ return this.#meta.get(key);
363
+ }
364
+ async setMeta(key, value) {
365
+ this.#meta.set(key, value);
366
+ }
367
+ #ensureParents(path) {
368
+ const parts = normalizeWorkspacePath(path).split("/").filter(Boolean);
369
+ for (let index = 1; index < parts.length; index++) {
370
+ const dir = parts.slice(0, index).join("/");
371
+ if (!this.#nodes.has(dir)) this.#nodes.set(dir, {
372
+ type: "directory",
373
+ mtime: now()
374
+ });
375
+ }
376
+ }
377
+ async #entry(path, node) {
378
+ const content = node.content || "";
379
+ const size = node.type === "file" ? typeof content === "string" ? new TextEncoder().encode(content).byteLength : content.byteLength : void 0;
380
+ return {
381
+ path,
382
+ type: node.type,
383
+ size,
384
+ mtime: node.mtime,
385
+ mediaType: node.mediaType,
386
+ digest: node.type === "file" ? await sha256(content) : void 0
387
+ };
388
+ }
389
+ async #createSnapshot(name) {
390
+ const entries = {};
391
+ for (const [path, node] of this.#nodes) {
392
+ if (!path) continue;
393
+ const entry = await this.#entry(path, node);
394
+ entries[path] = {
395
+ type: entry.type,
396
+ digest: entry.digest,
397
+ size: entry.size
398
+ };
399
+ }
400
+ return {
401
+ id: await sha256({
402
+ name,
403
+ entries,
404
+ createdAt: Date.now()
405
+ }),
406
+ name,
407
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
408
+ entries
409
+ };
410
+ }
411
+ };
412
+ function createMemoryWorkspaceStore() {
413
+ return new MemoryWorkspaceStore();
414
+ }
415
+ //#endregion
416
+ //#region src/storage/provider.ts
417
+ const MASKED_WORKSPACE_RUNTIME_VALUE = "********";
418
+ function workspaceRepoName(name) {
419
+ return name ? name.replace(/[^a-zA-Z0-9_.-]/g, "-") : void 0;
420
+ }
421
+ function resolveCloudflareArtifactsStore(config = {}, env = process.env) {
422
+ const repoPrefix = trimmed(config.repoPrefix) ?? readEnv(env, "WORKSPACE_ARTIFACTS_REPO_PREFIX", "VITEHUB_WORKSPACE_ARTIFACTS_REPO_PREFIX") ?? "vitehub-workspace-";
423
+ const repo = trimmed(config.repo) ?? workspaceRepoName(readEnv(env, "WORKSPACE_ARTIFACTS_REPO", "VITEHUB_WORKSPACE_ARTIFACTS_REPO"));
424
+ return defu({
425
+ binding: trimmed(config.binding) ?? readEnv(env, "WORKSPACE_ARTIFACTS_BINDING", "VITEHUB_WORKSPACE_ARTIFACTS_BINDING"),
426
+ branch: trimmed(config.branch) ?? readEnv(env, "WORKSPACE_ARTIFACTS_BRANCH", "VITEHUB_WORKSPACE_ARTIFACTS_BRANCH"),
427
+ namespace: trimmed(config.namespace) ?? readEnv(env, "WORKSPACE_ARTIFACTS_NAMESPACE", "VITEHUB_WORKSPACE_ARTIFACTS_NAMESPACE"),
428
+ repo,
429
+ repoPrefix
430
+ }, {
431
+ binding: "WORKSPACE_ARTIFACTS",
432
+ branch: "main",
433
+ namespace: "vitehub",
434
+ provider: "cloudflare-artifacts"
435
+ });
436
+ }
437
+ function resolveVercelBlobWorkspaceStore(config = {}, env = process.env) {
438
+ return {
439
+ access: config.access ?? "private",
440
+ prefix: trimmed(config.prefix) ?? readEnv(env, "WORKSPACE_BLOB_PREFIX", "VITEHUB_WORKSPACE_BLOB_PREFIX") ?? ".vitehub/workspaces",
441
+ provider: "vercel-blob",
442
+ token: MASKED_WORKSPACE_RUNTIME_VALUE
443
+ };
444
+ }
445
+ function hasVercelWorkspaceBlobEnv(env) {
446
+ return Boolean(readEnv(env, "BLOB_READ_WRITE_TOKEN"));
447
+ }
448
+ function normalizeWorkspaceStoreOptions(store, input = {}) {
449
+ if (store && "readFile" in store) return;
450
+ if (input.dev && !store) return { provider: "local" };
451
+ const env = input.env || process.env;
452
+ const hosting = input.hosting || "";
453
+ if (store?.provider === "cloudflare-artifacts") return resolveCloudflareArtifactsStore(store, env);
454
+ if (store?.provider === "memory") return store;
455
+ if (store?.provider === "vercel-blob") return resolveVercelBlobWorkspaceStore(store, env);
456
+ if (store?.provider === "local" || store?.root) return defu(store, { provider: "local" });
457
+ if (store && "provider" in store) throw new WorkspaceError(`[vitehub] Unsupported workspace store provider: ${String(store.provider)}.`);
458
+ if (hosting.includes("cloudflare")) return { provider: "memory" };
459
+ if (hasVercelWorkspaceBlobEnv(env)) return resolveVercelBlobWorkspaceStore({}, env);
460
+ if (hosting.includes("vercel")) return { provider: "memory" };
461
+ return { provider: "local" };
462
+ }
463
+ function createWorkspaceStoreFromProvider(definition) {
464
+ if (definition.store && "readFile" in definition.store) return definition.store;
465
+ const rootDir = definition.rootDir || process.cwd();
466
+ const runtimeConfig = getWorkspaceRuntimeConfig();
467
+ const runtimeStore = runtimeConfig ? runtimeConfig.store : void 0;
468
+ const store = normalizeWorkspaceStoreOptions(definition.store || runtimeStore, {
469
+ env: typeof process !== "undefined" ? process.env : {},
470
+ hosting: typeof process !== "undefined" ? process.env.VITEHUB_HOSTING || process.env.NITRO_PRESET : void 0,
471
+ rootDir,
472
+ runtime: true
473
+ });
474
+ if (store?.provider === "memory") return createMemoryWorkspaceStore();
475
+ if (store?.provider === "cloudflare-artifacts" || store?.provider === "vercel-blob") {
476
+ const loader = getWorkspaceHostedStoreLoader();
477
+ if (!loader) throw new WorkspaceError(`[vitehub] Hosted workspace store "${store.provider}" is not available in this runtime.`);
478
+ return loader(store, definition.name);
479
+ }
480
+ return createLocalWorkspaceStore(store?.root ? resolve(rootDir, store.root) : runtimeConfig ? resolve(runtimeConfig.root, definition.name) : resolve(rootDir, ".vitehub/workspaces", definition.name));
481
+ }
482
+ function isMaskedWorkspaceRuntimeValue(value) {
483
+ return !value || value === "********";
484
+ }
485
+ function resolveRuntimeVercelBlobWorkspaceStore(config, env) {
486
+ const token = readEnv(env, "BLOB_READ_WRITE_TOKEN");
487
+ if (isMaskedWorkspaceRuntimeValue(token)) throw new Error("Missing runtime environment variable `BLOB_READ_WRITE_TOKEN` for Vercel workspace Blob storage.");
488
+ return {
489
+ ...config,
490
+ token
491
+ };
492
+ }
493
+ //#endregion
494
+ export { getWorkspaceHostedStoreLoader as a, setWorkspaceRuntimeConfig as c, createMemoryWorkspaceStore as i, normalizeWorkspaceStoreOptions as n, setWorkspaceHostedStoreLoader as o, resolveRuntimeVercelBlobWorkspaceStore as r, getWorkspaceRuntimeConfig as s, createWorkspaceStoreFromProvider as t };
@@ -0,0 +1,6 @@
1
+ import { ct as WorkspaceStore, t as CloudflareArtifactsWorkspaceStoreOptions } from "../../types-CwNcWTdt.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 };