@vite-hub/workspace 0.6.0 → 0.7.0

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 +5 -5
  2. package/dist/{asset-registry-0CdRAjIV.js → asset-registry-DJyE42kr.js} +1 -1
  3. package/dist/blob-database.d.ts +1 -1
  4. package/dist/blob-database.js +6 -6
  5. package/dist/checkout.js +2 -2
  6. package/dist/cloudflare.d.ts +1 -1
  7. package/dist/cloudflare.js +1 -1
  8. package/dist/{config-jo5QgE1w.js → config--ZzAvhMp.js} +14 -9
  9. package/dist/{config-DeA287c0.d.ts → config-DF6sqKXB.d.ts} +1 -1
  10. package/dist/durability.d.ts +1 -1
  11. package/dist/durability.js +2 -2
  12. package/dist/{error-diagnostics-B4me-ouV.js → error-diagnostics-CHgE8TQM.js} +16 -0
  13. package/dist/{error-diagnostics-kKXseq8d.js → error-diagnostics-CsiNo_oI.js} +3 -3
  14. package/dist/{file-BrNAXQgY.js → file-DQ5-TBTD.js} +1 -1
  15. package/dist/{file-metadata-Bpsvjw_X.js → file-metadata-Dqpldj0h.js} +7 -2
  16. package/dist/{files--z2dLC5z.js → files-D1UkSjzX.js} +2 -2
  17. package/dist/files.d.ts +5 -5
  18. package/dist/files.js +5 -5
  19. package/dist/{github-k--_LCrX.js → github-BECfOMaw.js} +4 -4
  20. package/dist/{glob-BreFjNAV.js → glob-BIg9O4yY.js} +2 -2
  21. package/dist/{glob-BEutagp1.js → glob-BIsxLusH.js} +1 -1
  22. package/dist/{host-C8yZizfk.js → host-BYBRcSnh.js} +7 -7
  23. package/dist/hosted-vercel-blob.d.ts +1 -1
  24. package/dist/hosted-vercel-blob.js +464 -1
  25. package/dist/hosted.d.ts +1 -1
  26. package/dist/hosted.js +917 -1
  27. package/dist/index.d.ts +6 -7
  28. package/dist/index.js +13 -13
  29. package/dist/internal/path.js +108 -1
  30. package/dist/internal/workspace.d.ts +2 -3
  31. package/dist/internal/workspace.js +2 -2
  32. package/dist/{lifecycle-IReZfi0b.js → lifecycle-BK7WNfcP.js} +8 -8
  33. package/dist/loader.d.ts +1 -1
  34. package/dist/loader.js +2 -2
  35. package/dist/{mcp-resources-DeJnbOaw.js → mcp-resources-F4SJF4_P.js} +2 -2
  36. package/dist/{memory-BlSRrBH1.js → memory-BCZl_ZsJ.js} +26 -4
  37. package/dist/{metadata-target-CaGLY4ay.js → metadata-target-DPGF6L68.js} +59 -24
  38. package/dist/{operation-definition-CqZkx1Rm.d.ts → operations-BALFFdKj.d.ts} +1 -0
  39. package/dist/{operations-BIaK_uYG.js → operations-DJ_7W0gs.js} +8 -7
  40. package/dist/operations.d.ts +2 -2
  41. package/dist/operations.js +1327 -2
  42. package/dist/{path-Bb9OIc_F.js → path-DYHw5KNk.js} +11 -3
  43. package/dist/plugins-BYxsPDBH.d.ts +12 -0
  44. package/dist/{provider-CN14ewvx.js → provider-fcI7kJ5k.js} +256 -70
  45. package/dist/providers/github/store.d.ts +1 -1
  46. package/dist/providers/github/store.js +1994 -1
  47. package/dist/{registry-BbUg9vJB.js → registry-CFeUQsja.js} +3 -3
  48. package/dist/{registry-B0g19sdy.d.ts → registry-h1-cT-cE.d.ts} +1 -1
  49. package/dist/{registry-s2Ob9PeX.d.ts → registry-hnARUKNF.d.ts} +2 -2
  50. package/dist/replacement-CVZVsflC.js +76 -0
  51. package/dist/{request-scope-CXCI_wCb.js → request-scope-jH4H0Sbm.js} +3 -1
  52. package/dist/{rule-keys-BLEbi1h5.js → rule-keys-xMpiTLq1.js} +1 -1
  53. package/dist/{rules-BPDXypZV.js → rules-DYQCKYdt.js} +4 -4
  54. package/dist/runtime/assets.d.ts +1 -1
  55. package/dist/runtime/assets.js +4 -4
  56. package/dist/runtime/empty-assets-registry.d.ts +1 -1
  57. package/dist/runtime/empty-registry.d.ts +2 -2
  58. package/dist/runtime/registry.d.ts +1 -1
  59. package/dist/runtime/request.js +1 -1
  60. package/dist/runtime/state.d.ts +17 -6
  61. package/dist/runtime/state.js +7 -7
  62. package/dist/runtime/workspace.d.ts +1 -1
  63. package/dist/runtime/workspace.js +1 -1
  64. package/dist/runtime.d.ts +8 -8
  65. package/dist/runtime.js +38 -23
  66. package/dist/{search-C_nVorq7.js → search-CG6UNOtn.js} +1 -1
  67. package/dist/server.d.ts +2 -2
  68. package/dist/server.js +301 -1
  69. package/dist/{shared-C20Wh1mp.js → shared-PFnkYidS.js} +59 -21
  70. package/dist/source-metadata.d.ts +2 -2
  71. package/dist/source-metadata.js +3 -3
  72. package/dist/{sync-BBfR4g5y.js → sync-CUkCuP_g.js} +5 -5
  73. package/dist/test.d.ts +1 -1
  74. package/dist/test.js +1 -1
  75. package/dist/{types-Bel5IDmF.d.ts → types-BnSUug2v.d.ts} +13 -1
  76. package/dist/{use-D0DyTMxM.js → use-BCMkT-kC.js} +15 -51
  77. package/dist/{use-CpphIBof.d.ts → use-CJ5rdIrW.d.ts} +1 -1
  78. package/dist/{use-tools-CHduR5k6.js → use-tools-CcXs2hFA.js} +4 -4
  79. package/dist/{use-tools-CAK10LTc.d.ts → use-tools-DFVqZwgc.d.ts} +2 -2
  80. package/dist/{utils-DXP9xfXo.js → utils-Bv1NBg8r.js} +5 -5
  81. package/dist/vite.d.ts +2 -2
  82. package/dist/vite.js +368 -62
  83. package/dist/{workspace-BOuxrZrP.d.ts → workspace-B6QreLJd.d.ts} +1 -1
  84. package/dist/{workspace-CLuPkyZR.js → workspace-D1m00MCM.js} +340 -104
  85. package/dist/workspace-inspection-scanner-BlJ8bCAB.js +140 -0
  86. package/package.json +12 -12
  87. package/dist/errors-CnFDXxeJ.d.ts +0 -4
  88. package/dist/hosted-8BTKAtMX.js +0 -883
  89. package/dist/hosted-vercel-blob-B6kygYqn.js +0 -408
  90. package/dist/operations-DS1C4uXd.js +0 -1308
  91. package/dist/path-CuYE8-X6.js +0 -57
  92. package/dist/plugins-CLc32jvL.d.ts +0 -8
  93. package/dist/server-aa1a4rkV.js +0 -301
  94. package/dist/state-BdDfBtOR.d.ts +0 -17
  95. package/dist/store-cx3OqNTi.js +0 -1971
@@ -1 +1,464 @@
1
- export { t as configureHostedVercelBlobWorkspaceRuntime, n as installHostedVercelBlobWorkspaceRuntime } from "./hosted-vercel-blob-B6kygYqn.js";
1
+ import { d as setWorkspaceHostedStoreLoader, l as ownedBlobPrefix, o as resolveRuntimeVercelBlobWorkspaceStore, s as resolveVercelBlobWorkspaceStore, u as getWorkspaceHostedStoreLoader } from "./provider-fcI7kJ5k.js";
2
+ import { i as workspaceConflict, normalizeSafeWorkspacePath, o as workspaceError } from "./internal/path.js";
3
+ import { a as isExcludedWorkspacePath, c as normalizeSafeWorkspacePattern, f as sha256, l as normalizeWorkspacePath, r as contentToBytes } from "./path-DYHw5KNk.js";
4
+ import { t as createWorkspaceGlobMatcher } from "./glob-BIg9O4yY.js";
5
+ import { r as diffSnapshots, t as createCurrentSnapshotFromStore } from "./utils-Bv1NBg8r.js";
6
+ import { a as provideWorkspaceStoreTarget } from "./vitehub-grants-Co713QTg.js";
7
+ import { a as replacementRecoveryError, i as replaceStorePath } from "./replacement-CVZVsflC.js";
8
+ import { t as workspaceErrorDiagnostics } from "./error-diagnostics-CHgE8TQM.js";
9
+ import { t as isRecord } from "./object-CAK6UYR5.js";
10
+ import { n as setWorkspaceRuntimeConfig } from "./config-CsgNNVAI.js";
11
+ import { resolve } from "node:path";
12
+ // src/providers/vercel/blob-store.ts
13
+ const fileMutations = /* @__PURE__ */ new Map();
14
+ async function serializeFileMutation(key, mutate) {
15
+ const pending = (fileMutations.get(key) || Promise.resolve()).catch(() => {}).then(mutate);
16
+ fileMutations.set(key, pending);
17
+ try {
18
+ await pending;
19
+ } finally {
20
+ if (fileMutations.get(key) === pending) fileMutations.delete(key);
21
+ }
22
+ }
23
+ function invalidBlobListResponse() {
24
+ throw workspaceErrorDiagnostics.WORKSPACE_R0033({ message: "Unexpected Vercel Blob list response." });
25
+ }
26
+ function parseBlobListResponse(value) {
27
+ if (!isRecord(value) || !Array.isArray(value.blobs)) invalidBlobListResponse();
28
+ const items = value.blobs.map((item) => {
29
+ if (!isRecord(item)) invalidBlobListResponse();
30
+ const pathname = item.pathname;
31
+ const size = item.size;
32
+ const uploadedAt = item.uploadedAt;
33
+ if (typeof pathname !== "string" || !pathname) invalidBlobListResponse();
34
+ if (size !== void 0 && (typeof size !== "number" || !Number.isFinite(size) || size < 0)) invalidBlobListResponse();
35
+ if (uploadedAt !== void 0 && (!(uploadedAt instanceof Date) || Number.isNaN(uploadedAt.getTime()))) invalidBlobListResponse();
36
+ return {
37
+ key: pathname,
38
+ lastModified: uploadedAt instanceof Date ? uploadedAt.getTime() : void 0,
39
+ size: typeof size === "number" ? size : void 0
40
+ };
41
+ });
42
+ const cursor = value.cursor;
43
+ const hasMore = value.hasMore;
44
+ if (cursor !== void 0 && typeof cursor !== "string") invalidBlobListResponse();
45
+ if (hasMore !== void 0 && typeof hasMore !== "boolean") invalidBlobListResponse();
46
+ if (hasMore === true && !cursor) invalidBlobListResponse();
47
+ return {
48
+ cursor: cursor === void 0 ? void 0 : cursor,
49
+ hasMore: hasMore === void 0 ? void 0 : hasMore,
50
+ items
51
+ };
52
+ }
53
+ function joinBlobPath(...parts) {
54
+ return parts.map((part) => normalizeWorkspacePath(part)).filter(Boolean).join("/");
55
+ }
56
+ function contentType(path, fallback) {
57
+ if (fallback) return fallback;
58
+ if (path.endsWith(".json")) return "application/json; charset=utf-8";
59
+ if (path.endsWith(".md") || path.endsWith(".txt")) return "text/plain; charset=utf-8";
60
+ }
61
+ function auth(options) {
62
+ return options.token ? { token: options.token } : {};
63
+ }
64
+ function isNotFoundError(error) {
65
+ return Object(error).code === "NotFound";
66
+ }
67
+ async function createVercelBlobClient(options) {
68
+ const blob = await importVercelBlobPeer();
69
+ const access = options.access || "private";
70
+ return {
71
+ isMissing(error) {
72
+ return error instanceof blob.BlobNotFoundError;
73
+ },
74
+ async delete(key) {
75
+ await blob.del(key, auth(options));
76
+ },
77
+ async download(key) {
78
+ try {
79
+ const readKey = access === "public" ? `${key}?vitehubCacheBust=${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}` : key;
80
+ const result = await blob.get(readKey, {
81
+ access,
82
+ headers: { "cache-control": "no-cache, no-store" },
83
+ useCache: false,
84
+ ...auth(options)
85
+ });
86
+ if (!result) return void 0;
87
+ if (result.statusCode !== 200) throw workspaceErrorDiagnostics.WORKSPACE_R0033({ message: `Unexpected Vercel Blob response: ${result.statusCode}.` });
88
+ return await new Response(result.stream, { headers: result.blob.contentType ? { "content-type": result.blob.contentType } : void 0 }).blob();
89
+ } catch (error) {
90
+ if (isNotFoundError(error)) return void 0;
91
+ throw error;
92
+ }
93
+ },
94
+ async head(key) {
95
+ const result = await blob.head(key, auth(options)).catch((error) => {
96
+ if (error instanceof blob.BlobNotFoundError) return void 0;
97
+ throw error;
98
+ });
99
+ if (!result) return void 0;
100
+ return {
101
+ key: result.pathname,
102
+ lastModified: result.uploadedAt.getTime(),
103
+ size: result.size,
104
+ type: result.contentType
105
+ };
106
+ },
107
+ async list(optionsInput) {
108
+ return { ...parseBlobListResponse(await blob.list({
109
+ ...optionsInput,
110
+ ...auth(options)
111
+ })) };
112
+ },
113
+ async upload(key, body, uploadOptions = {}) {
114
+ await blob.put(key, body, {
115
+ access,
116
+ addRandomSuffix: false,
117
+ allowOverwrite: true,
118
+ contentType: uploadOptions.contentType,
119
+ ...auth(options)
120
+ });
121
+ }
122
+ };
123
+ }
124
+ async function importVercelBlobPeer() {
125
+ const testImport = globalThis.__vitehubWorkspaceImportVercelBlobPeer;
126
+ return testImport ? await testImport() : (await import("@vite-hub/blob/internal/vercel-blob")).vercelBlob;
127
+ }
128
+ var VercelBlobWorkspaceStore = class {
129
+ #baseline;
130
+ #options;
131
+ #files;
132
+ #root;
133
+ #legacyRoot;
134
+ constructor(options, workspaceName) {
135
+ this.#options = resolveRuntimeVercelBlobWorkspaceStore(options, typeof process !== "undefined" ? process.env : {});
136
+ this.#root = joinBlobPath(ownedBlobPrefix("workspaces", this.#options.prefix, "Workspace"), workspaceName);
137
+ const legacyPrefix = this.#options.prefix ?? ".vitehub/workspaces";
138
+ this.#legacyRoot = joinBlobPath(legacyPrefix, workspaceName);
139
+ provideWorkspaceStoreTarget(this, () => ({
140
+ provider: "vercel",
141
+ hasFileDescendants: async (path) => {
142
+ const normalized = normalizeSafeWorkspacePath(path);
143
+ return [...(await this.#removalTargets(normalized, true)).keys()].some((key) => key !== this.#fileKey(normalized) && key !== this.#legacyFileKey(normalized));
144
+ }
145
+ }));
146
+ }
147
+ #fileKey(path, options = {}) {
148
+ return joinBlobPath(this.#root, "files", normalizeSafeWorkspacePath(path, { allowEmpty: options.allowEmpty }));
149
+ }
150
+ #legacyFileKey(path, options = {}) {
151
+ return joinBlobPath(this.#legacyRoot, "files", normalizeSafeWorkspacePath(path, { allowEmpty: options.allowEmpty }));
152
+ }
153
+ async #client() {
154
+ this.#files ||= createVercelBlobClient(this.#options).catch((error) => {
155
+ this.#files = void 0;
156
+ throw error;
157
+ });
158
+ return await this.#files;
159
+ }
160
+ #metaKey(key) {
161
+ return joinBlobPath(this.#root, ".vitehub/meta", normalizeSafeWorkspacePath(key.endsWith(".json") ? key : `${key}.json`));
162
+ }
163
+ #fileAttributesKey(path) {
164
+ return joinBlobPath(this.#root, ".vitehub/file-attributes", `${normalizeSafeWorkspacePath(path)}.json`);
165
+ }
166
+ #legacyFileAttributesKey(path) {
167
+ return joinBlobPath(this.#legacyRoot, ".vitehub/file-attributes", `${normalizeSafeWorkspacePath(path)}.json`);
168
+ }
169
+ #snapshotKey(id) {
170
+ return joinBlobPath(this.#root, ".vitehub/snapshots", `${id}.json`);
171
+ }
172
+ #legacyMetaKey(key) {
173
+ return joinBlobPath(this.#legacyRoot, ".vitehub/meta", normalizeSafeWorkspacePath(key.endsWith(".json") ? key : `${key}.json`));
174
+ }
175
+ async readFile(path) {
176
+ const normalized = normalizeSafeWorkspacePath(path);
177
+ const pathname = this.#fileKey(normalized);
178
+ let attributesPath = this.#fileAttributesKey(normalized);
179
+ let file = await (await this.#client()).download(pathname);
180
+ if (!file && this.#legacyRoot !== this.#root) {
181
+ attributesPath = this.#legacyFileAttributesKey(normalized);
182
+ file = await (await this.#client()).download(this.#legacyFileKey(normalized));
183
+ }
184
+ if (!file) return void 0;
185
+ const bytes = await file.arrayBuffer();
186
+ const attributes = await this.#readJson(attributesPath);
187
+ return {
188
+ content: new Uint8Array(bytes),
189
+ ...typeof attributes?.mediaType === "string" ? { mediaType: attributes.mediaType } : {},
190
+ ...attributes?.metadata && typeof attributes.metadata === "object" && !Array.isArray(attributes.metadata) ? { metadata: attributes.metadata } : {},
191
+ path: normalized
192
+ };
193
+ }
194
+ async writeFile(path, file) {
195
+ const normalized = normalizeSafeWorkspacePath(path);
196
+ await serializeFileMutation(this.#fileKey(normalized), async () => {
197
+ const attributes = {
198
+ ...file.mediaType ? { mediaType: file.mediaType } : {},
199
+ ...file.metadata ? { metadata: file.metadata } : {}
200
+ };
201
+ const serializedAttributes = Object.keys(attributes).length > 0 ? JSON.stringify(attributes) : void 0;
202
+ const client = await this.#client();
203
+ const fileKey = this.#fileKey(normalized);
204
+ const attributesKey = this.#fileAttributesKey(normalized);
205
+ const [previousFile, previousAttributes] = await Promise.all([client.download(fileKey), client.download(attributesKey)]);
206
+ await client.upload(fileKey, new Blob([contentToBytes(file.content)]), { contentType: contentType(normalized, file.mediaType) });
207
+ try {
208
+ if (serializedAttributes !== void 0) await client.upload(attributesKey, serializedAttributes, { contentType: "application/json; charset=utf-8" });
209
+ else await client.delete(attributesKey).catch((error) => {
210
+ if (!client.isMissing(error)) throw error;
211
+ });
212
+ } catch (error) {
213
+ const restore = async (key, previous) => {
214
+ if (previous) await client.upload(key, previous, { contentType: previous.type });
215
+ else await client.delete(key);
216
+ };
217
+ const failures = (await Promise.allSettled([restore(fileKey, previousFile), restore(attributesKey, previousAttributes)])).filter((result) => result.status === "rejected").map((result) => result.reason);
218
+ if (failures.length) throw new AggregateError([error, ...failures], "Vercel Blob write failed and rollback could not complete.");
219
+ throw error;
220
+ }
221
+ });
222
+ }
223
+ async list(prefix = "", options = {}) {
224
+ const normalizedPrefix = normalizeSafeWorkspacePath(prefix, { allowEmpty: true });
225
+ const filePrefix = this.#fileKey(normalizedPrefix, { allowEmpty: true });
226
+ const currentBase = `${this.#fileKey("", { allowEmpty: true })}/`;
227
+ const legacyBase = `${this.#legacyFileKey("", { allowEmpty: true })}/`;
228
+ const files = await this.#listBlobs(normalizedPrefix ? `${filePrefix}/` : currentBase);
229
+ const legacyFiles = this.#legacyRoot === this.#root ? [] : await this.#listBlobs(normalizedPrefix ? `${this.#legacyFileKey(normalizedPrefix, { allowEmpty: true })}/` : legacyBase);
230
+ const attributeKeys = /* @__PURE__ */ new Set();
231
+ if (files.length || legacyFiles.length) {
232
+ for (const blob of await this.#listBlobs(`${joinBlobPath(this.#root, ".vitehub/file-attributes", normalizedPrefix)}/`)) attributeKeys.add(blob.key);
233
+ if (this.#legacyRoot !== this.#root) for (const blob of await this.#listBlobs(`${joinBlobPath(this.#legacyRoot, ".vitehub/file-attributes", normalizedPrefix)}/`)) attributeKeys.add(blob.key);
234
+ }
235
+ const entries = /* @__PURE__ */ new Map();
236
+ const entryAttributes = /* @__PURE__ */ new Map();
237
+ for (const blob of [...legacyFiles, ...files]) {
238
+ const base = blob.key.startsWith(currentBase) ? currentBase : legacyBase;
239
+ const path = normalizeWorkspacePath(blob.key.slice(base.length));
240
+ if (!path) continue;
241
+ if (isExcludedWorkspacePath(path, options.exclude)) continue;
242
+ if (normalizedPrefix && !path.startsWith(`${normalizedPrefix}/`)) continue;
243
+ const relative = normalizedPrefix ? path.slice(normalizedPrefix.length + 1) : path;
244
+ if (!options.recursive && relative.includes("/")) {
245
+ const child = relative.split("/")[0];
246
+ const directory = normalizedPrefix ? `${normalizedPrefix}/${child}` : child;
247
+ entries.set(directory, {
248
+ path: directory,
249
+ type: "directory"
250
+ });
251
+ continue;
252
+ }
253
+ const attributesPath = base === currentBase ? this.#fileAttributesKey(path) : this.#legacyFileAttributesKey(path);
254
+ entryAttributes.set(path, attributesPath);
255
+ entries.set(path, {
256
+ mtime: blob.lastModified,
257
+ path,
258
+ size: blob.size,
259
+ type: "file"
260
+ });
261
+ if (options.recursive) {
262
+ const parts = path.split("/");
263
+ for (let index = 1; index < parts.length; index++) {
264
+ const dir = parts.slice(0, index).join("/");
265
+ if (isExcludedWorkspacePath(dir, options.exclude)) continue;
266
+ entries.set(dir, {
267
+ path: dir,
268
+ type: "directory"
269
+ });
270
+ }
271
+ }
272
+ }
273
+ const pendingAttributes = [...entryAttributes].filter(([path, key]) => entries.get(path)?.type === "file" && attributeKeys.has(key));
274
+ for (let index = 0; index < pendingAttributes.length; index += 8) await Promise.all(pendingAttributes.slice(index, index + 8).map(async ([path, key]) => {
275
+ const attributes = await this.#readJson(key);
276
+ const entry = entries.get(path);
277
+ if (typeof attributes?.mediaType === "string") entry.mediaType = attributes.mediaType;
278
+ if (attributes?.metadata && typeof attributes.metadata === "object" && !Array.isArray(attributes.metadata)) entry.metadata = attributes.metadata;
279
+ }));
280
+ return [...entries.values()].sort((a, b) => a.path.localeCompare(b.path));
281
+ }
282
+ async glob(pattern, options = {}) {
283
+ const patterns = Array.isArray(pattern) ? pattern.map(normalizeSafeWorkspacePattern) : normalizeSafeWorkspacePattern(pattern);
284
+ const { cwd, matches } = createWorkspaceGlobMatcher(patterns, options);
285
+ return (await this.list(cwd, { recursive: true })).filter((entry) => entry.type === "file" && matches(entry.path));
286
+ }
287
+ async stat(path) {
288
+ const normalized = normalizeSafeWorkspacePath(path);
289
+ const file = await this.readFile(normalized);
290
+ if (file) {
291
+ const bytes = contentToBytes(file.content);
292
+ return {
293
+ digest: await sha256(bytes),
294
+ ...file.mediaType ? { mediaType: file.mediaType } : {},
295
+ ...file.metadata ? { metadata: file.metadata } : {},
296
+ path: normalized,
297
+ size: bytes.byteLength,
298
+ type: "file"
299
+ };
300
+ }
301
+ return (await this.list(normalized, { recursive: false })).length ? {
302
+ path: normalized,
303
+ type: "directory"
304
+ } : void 0;
305
+ }
306
+ async mkdir(path, _options = {}) {
307
+ normalizeSafeWorkspacePath(path);
308
+ }
309
+ async rm(path, options = {}) {
310
+ const normalized = normalizeSafeWorkspacePath(path);
311
+ if (options.ifDigest !== void 0) throw workspaceConflict(`[vitehub] Vercel Blob does not support atomic conditional removal for: ${path}.`, { conditionalRemovalUnsupported: true });
312
+ const targets = await this.#removalTargets(normalized, options.recursive ?? false);
313
+ if (!targets.size) {
314
+ if (options.force) return;
315
+ throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
316
+ }
317
+ const client = await this.#client();
318
+ await Promise.all([...targets].map(([fileKey, attributesKey]) => serializeFileMutation(fileKey, async () => {
319
+ await client.delete(fileKey);
320
+ await client.delete(attributesKey);
321
+ })));
322
+ }
323
+ async [replaceStorePath]({ path, files, removeTree }) {
324
+ if (!removeTree) return await this.writeFile(path, files[0]);
325
+ const client = await this.#client();
326
+ const targets = await this.#removalTargets(normalizeSafeWorkspacePath(path), true);
327
+ const incoming = new Set(files.map((file) => this.#fileKey(file.path)));
328
+ for (const file of files) targets.set(this.#fileKey(file.path), this.#fileAttributesKey(file.path));
329
+ const previous = /* @__PURE__ */ new Map();
330
+ for (const [fileKey, attributesKey] of targets) {
331
+ previous.set(fileKey, await client.download(fileKey));
332
+ previous.set(attributesKey, await client.download(attributesKey));
333
+ }
334
+ const touched = /* @__PURE__ */ new Set();
335
+ try {
336
+ for (const file of files) {
337
+ touched.add(this.#fileKey(file.path));
338
+ touched.add(this.#fileAttributesKey(file.path));
339
+ await this.writeFile(file.path, file);
340
+ }
341
+ for (const [fileKey, attributesKey] of targets) {
342
+ if (incoming.has(fileKey)) continue;
343
+ await serializeFileMutation(fileKey, async () => {
344
+ touched.add(fileKey);
345
+ await client.delete(fileKey);
346
+ touched.add(attributesKey);
347
+ await client.delete(attributesKey);
348
+ });
349
+ }
350
+ } catch (error) {
351
+ const failures = [];
352
+ for (const key of touched) {
353
+ const blob = previous.get(key);
354
+ try {
355
+ if (blob) await client.upload(key, blob, { contentType: blob.type });
356
+ else await client.delete(key);
357
+ } catch (failure) {
358
+ failures.push(failure);
359
+ }
360
+ }
361
+ if (failures.length) throw replacementRecoveryError(path, error, failures);
362
+ throw error;
363
+ }
364
+ }
365
+ async #removalTargets(normalized, recursive) {
366
+ const client = await this.#client();
367
+ const targets = /* @__PURE__ */ new Map();
368
+ const fileKeys = [this.#fileKey(normalized)];
369
+ if (this.#legacyRoot !== this.#root) fileKeys.push(this.#legacyFileKey(normalized));
370
+ for (const key of fileKeys) {
371
+ const attributesKey = key === this.#fileKey(normalized) ? this.#fileAttributesKey(normalized) : this.#legacyFileAttributesKey(normalized);
372
+ if (await client.head(key) || await client.head(attributesKey)) targets.set(key, attributesKey);
373
+ }
374
+ if (recursive) {
375
+ const prefixes = [`${this.#fileKey(normalized)}/`];
376
+ if (this.#legacyRoot !== this.#root) prefixes.push(`${this.#legacyFileKey(normalized)}/`);
377
+ for (const prefix of prefixes) for (const blob of await this.#listBlobs(prefix)) if (!targets.has(blob.key)) {
378
+ const path = normalizeWorkspacePath(blob.key.slice(prefix.length));
379
+ const attributesKey = prefix.startsWith(this.#fileKey("", { allowEmpty: true })) ? this.#fileAttributesKey(joinBlobPath(normalized, path)) : this.#legacyFileAttributesKey(joinBlobPath(normalized, path));
380
+ targets.set(blob.key, attributesKey);
381
+ }
382
+ }
383
+ if (recursive) for (const root of /* @__PURE__ */ new Set([this.#root, this.#legacyRoot])) {
384
+ const prefix = `${joinBlobPath(root, ".vitehub/file-attributes", normalized)}/`;
385
+ for (const blob of await this.#listBlobs(prefix)) {
386
+ if (!blob.key.endsWith(".json")) continue;
387
+ const relative = blob.key.slice(prefix.length, -5);
388
+ targets.set(joinBlobPath(root, "files", normalized, relative), blob.key);
389
+ }
390
+ }
391
+ return targets;
392
+ }
393
+ async snapshot(options = {}) {
394
+ const snapshot = await createCurrentSnapshotFromStore(this, options.name);
395
+ await (await this.#client()).upload(this.#snapshotKey(snapshot.id), JSON.stringify(snapshot), { contentType: "application/json; charset=utf-8" });
396
+ this.#baseline = snapshot;
397
+ return snapshot;
398
+ }
399
+ async diff(options = {}) {
400
+ const from = options.from || this.#baseline;
401
+ const to = await createCurrentSnapshotFromStore(this);
402
+ return diffSnapshots(from, to);
403
+ }
404
+ async getMeta(key) {
405
+ return await this.#readJson(this.#metaKey(key), this.#legacyMetaKey(key));
406
+ }
407
+ async setMeta(key, value) {
408
+ if (value === void 0) {
409
+ const client = await this.#client();
410
+ await Promise.all([this.#metaKey(key), this.#legacyMetaKey(key)].map((pathname) => client.delete(pathname).catch((error) => {
411
+ if (!client.isMissing(error)) throw error;
412
+ })));
413
+ return;
414
+ }
415
+ await (await this.#client()).upload(this.#metaKey(key), JSON.stringify(value), { contentType: "application/json; charset=utf-8" });
416
+ }
417
+ async #listBlobs(prefix) {
418
+ const blobs = [];
419
+ const seenCursors = /* @__PURE__ */ new Set();
420
+ let cursor;
421
+ let hasMore = true;
422
+ do {
423
+ if (cursor && seenCursors.has(cursor)) throw workspaceError("[vitehub] Vercel Blob pagination returned a repeated cursor.");
424
+ if (cursor) seenCursors.add(cursor);
425
+ const result = await (await this.#client()).list({
426
+ cursor,
427
+ limit: 1e3,
428
+ prefix
429
+ });
430
+ blobs.push(...result.items);
431
+ cursor = result.cursor;
432
+ hasMore = result.hasMore ?? Boolean(cursor);
433
+ } while (cursor && hasMore);
434
+ return blobs;
435
+ }
436
+ async #readJson(pathname, fallback) {
437
+ let file = await (await this.#client()).download(pathname);
438
+ if (!file && fallback) file = await (await this.#client()).download(fallback);
439
+ return file ? JSON.parse(await file.text()) : void 0;
440
+ }
441
+ };
442
+ function createVercelBlobWorkspaceStore(options, workspaceName) {
443
+ return new VercelBlobWorkspaceStore(options, workspaceName);
444
+ }
445
+ // src/hosted-vercel-blob.ts
446
+ function installHostedVercelBlobWorkspaceRuntime() {
447
+ const existingWorkspaceHostedStoreLoader = getWorkspaceHostedStoreLoader();
448
+ setWorkspaceHostedStoreLoader((storeOptions, workspaceName) => {
449
+ if (storeOptions.driver === "vercel") return createVercelBlobWorkspaceStore(storeOptions, workspaceName);
450
+ return existingWorkspaceHostedStoreLoader?.(storeOptions, workspaceName);
451
+ });
452
+ }
453
+ function configureHostedVercelBlobWorkspaceRuntime(options = {}) {
454
+ const root = resolve(process.cwd(), options.root || ".vitehub/workspaces");
455
+ const config = {
456
+ assets: options.assets,
457
+ root,
458
+ store: resolveVercelBlobWorkspaceStore(options.store, options.env)
459
+ };
460
+ installHostedVercelBlobWorkspaceRuntime();
461
+ setWorkspaceRuntimeConfig(config);
462
+ return config;
463
+ }
464
+ export { configureHostedVercelBlobWorkspaceRuntime, installHostedVercelBlobWorkspaceRuntime };
package/dist/hosted.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { T as VercelBlobWorkspaceStoreOptions, s as GitHubWorkspaceStoreOptions, t as CloudflareArtifactsWorkspaceStoreOptions, v as ResolvedWorkspaceModuleOptions } from "./types-Bel5IDmF.js";
1
+ import { T as VercelBlobWorkspaceStoreOptions, s as GitHubWorkspaceStoreOptions, t as CloudflareArtifactsWorkspaceStoreOptions, v as ResolvedWorkspaceModuleOptions } from "./types-BnSUug2v.js";
2
2
  export type HostedWorkspaceRuntimeStoreOptions = Partial<CloudflareArtifactsWorkspaceStoreOptions> | (Partial<GitHubWorkspaceStoreOptions> & {
3
3
  driver: "github";
4
4
  }) | (Partial<VercelBlobWorkspaceStoreOptions> & {