@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,362 @@
1
+ import { a as matchesAny, c as normalizeWorkspacePath, n as contentStreamToBytes, o as normalizeSafeWorkspacePath, p as workspaceError, s as normalizeSafeWorkspacePattern } from "../../path-CNI6wKIU.js";
2
+ import { n as createSnapshotFromEntries, r as diffSnapshots } from "../../utils-BPdaCyI6.js";
3
+ import { r as workspaceStoreTarget } from "../../target-D4Bqb1eH.js";
4
+ import { c as readGitHubBlob, d as resolveGitHubBranchOption, h as resolveGitHubTokenOption, i as gitBlobSha, l as readGitHubBranchState, m as resolveGitHubRootOption, n as createGitHubBlob, o as joinGitPath, p as resolveGitHubRepositoryOption, r as createGitHubFileUpdate, t as commitGitHubChanges, u as requireGitHubOption } from "../../shared-BRycRSbo.js";
5
+ import { posix } from "node:path";
6
+ //#region src/providers/github/store.ts
7
+ function isReservedWorkspacePath(path) {
8
+ const root = normalizeWorkspacePath(path).split("/")[0];
9
+ return root === ".git" || root === ".vitehub";
10
+ }
11
+ function contentLength(content) {
12
+ return typeof content === "string" ? new TextEncoder().encode(content).byteLength : content.byteLength;
13
+ }
14
+ function gitHubFileMetadata(entry) {
15
+ return entry.mode === "120000" || entry.mode === "100755" ? { gitMode: entry.mode } : void 0;
16
+ }
17
+ function gitHubFileMode(metadata) {
18
+ return metadata?.gitMode === "120000" || metadata?.gitMode === "100755" ? metadata.gitMode : "100644";
19
+ }
20
+ function inheritedGitHubFileMetadata(file, current) {
21
+ if (file.metadata) return file.metadata;
22
+ return current?.metadata?.gitMode === "100755" ? current.metadata : void 0;
23
+ }
24
+ function parentDirectories(path) {
25
+ const parts = normalizeWorkspacePath(path).split("/").filter(Boolean);
26
+ const directories = [];
27
+ for (let index = 1; index < parts.length; index++) directories.push(parts.slice(0, index).join("/"));
28
+ return directories;
29
+ }
30
+ function resolveSymlinkTarget(path, bytes) {
31
+ const target = gitSymlinkTargetFromBytes(bytes);
32
+ if (!target || target.startsWith("/")) return;
33
+ const base = path.split("/").slice(0, -1).join("/");
34
+ const resolved = posix.normalize(base ? `${base}/${target}` : target);
35
+ if (!resolved || resolved === "." || resolved === ".." || resolved.startsWith("../")) return;
36
+ return normalizeSafeWorkspacePath(resolved);
37
+ }
38
+ function gitSymlinkTargetFromBytes(bytes) {
39
+ return new TextDecoder().decode(bytes).replace(/\0/g, "");
40
+ }
41
+ var GitHubWorkspaceStore = class {
42
+ workspaceName;
43
+ #baseline;
44
+ #baselineRefSha;
45
+ #baselineTreeSha;
46
+ #branch;
47
+ #dirty = false;
48
+ #files = /* @__PURE__ */ new Map();
49
+ #ready;
50
+ #remoteFiles = /* @__PURE__ */ new Map();
51
+ #repository;
52
+ #root;
53
+ #token;
54
+ constructor(options, workspaceName) {
55
+ this.workspaceName = workspaceName;
56
+ this.#repository = requireGitHubOption("store", "a repository", resolveGitHubRepositoryOption(options));
57
+ this.#branch = resolveGitHubBranchOption(options);
58
+ this.#root = resolveGitHubRootOption(options, workspaceName);
59
+ this.#token = requireGitHubOption("store", "a token", resolveGitHubTokenOption(options));
60
+ }
61
+ [workspaceStoreTarget]() {
62
+ return {
63
+ provider: "github",
64
+ branch: this.#branch,
65
+ repository: this.#repository
66
+ };
67
+ }
68
+ async readFile(path) {
69
+ const normalized = normalizeSafeWorkspacePath(path);
70
+ await this.#ensure({ refresh: true });
71
+ return await this.#readWorkspaceFile(normalized);
72
+ }
73
+ async writeFile(path, file) {
74
+ const normalized = normalizeSafeWorkspacePath(path);
75
+ await this.#ensure({ refresh: false });
76
+ const current = this.#files.get(normalized);
77
+ const metadata = inheritedGitHubFileMetadata(file, current);
78
+ const content = gitHubFileMode(metadata) === "120000" && typeof metadata?.symlinkTarget === "string" ? metadata.symlinkTarget : file.content;
79
+ const update = await createGitHubFileUpdate(normalized, this.#root, content);
80
+ if (current?.gitSha === update.gitSha) {
81
+ if (gitHubFileMode(current.metadata) !== gitHubFileMode(metadata)) this.#dirty = true;
82
+ this.#files.set(normalized, {
83
+ ...current,
84
+ mediaType: file.mediaType,
85
+ metadata,
86
+ size: contentLength(content)
87
+ });
88
+ return;
89
+ }
90
+ await createGitHubBlob({
91
+ bytes: update.bytes,
92
+ kind: "store",
93
+ repository: this.#repository,
94
+ token: this.#token
95
+ });
96
+ this.#files.set(normalized, {
97
+ gitSha: update.gitSha,
98
+ mediaType: file.mediaType,
99
+ metadata,
100
+ path: normalized,
101
+ size: contentLength(content)
102
+ });
103
+ this.#dirty = true;
104
+ }
105
+ async writeFileStream(path, file) {
106
+ const content = await contentStreamToBytes(file.content);
107
+ await this.writeFile(path, {
108
+ path: file.path,
109
+ content,
110
+ mediaType: file.mediaType,
111
+ metadata: file.metadata
112
+ });
113
+ return {
114
+ digest: await gitBlobSha(content),
115
+ mediaType: file.mediaType,
116
+ path: normalizeSafeWorkspacePath(path),
117
+ size: content.byteLength,
118
+ type: "file"
119
+ };
120
+ }
121
+ async list(prefix = "", options = {}) {
122
+ const normalizedPrefix = normalizeSafeWorkspacePath(prefix, { allowEmpty: true });
123
+ await this.#ensure({ refresh: true });
124
+ return await this.#listEntries(normalizedPrefix, options);
125
+ }
126
+ async glob(pattern, _options = {}) {
127
+ const patterns = Array.isArray(pattern) ? pattern.map(normalizeSafeWorkspacePattern) : normalizeSafeWorkspacePattern(pattern);
128
+ return (await this.list("", { recursive: true })).filter((entry) => entry.type === "file" && matchesAny(entry.path, patterns));
129
+ }
130
+ async stat(path) {
131
+ const normalized = normalizeSafeWorkspacePath(path);
132
+ await this.#ensure({ refresh: true });
133
+ const file = this.#files.get(normalized);
134
+ if (file && !isReservedWorkspacePath(normalized)) return this.#fileEntry(file);
135
+ if (this.#directoryExists(normalized)) return {
136
+ path: normalized,
137
+ type: "directory"
138
+ };
139
+ }
140
+ async mkdir(path, _options = {}) {
141
+ normalizeSafeWorkspacePath(path);
142
+ }
143
+ async rm(path, options = {}) {
144
+ const normalized = normalizeSafeWorkspacePath(path);
145
+ await this.#ensure({ refresh: false });
146
+ if (this.#files.get(normalized) && !isReservedWorkspacePath(normalized)) {
147
+ this.#files.delete(normalized);
148
+ this.#dirty = true;
149
+ return;
150
+ }
151
+ const children = this.#publicDescendants(normalized);
152
+ if (!(children.length > 0)) {
153
+ if (options.force) return;
154
+ throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
155
+ }
156
+ if (children.length && !options.recursive) throw workspaceError(`[vitehub] Workspace directory is not empty: ${path}.`);
157
+ for (const child of children) this.#files.delete(child);
158
+ this.#dirty = true;
159
+ }
160
+ async snapshot(options = {}) {
161
+ await this.#ensure({ refresh: false });
162
+ const snapshot = await createSnapshotFromEntries(await this.#listEntries("", { recursive: true }), options.name);
163
+ if (!this.#dirty) {
164
+ this.#baseline = snapshot;
165
+ return snapshot;
166
+ }
167
+ const remote = await readGitHubBranchState({
168
+ branch: this.#branch,
169
+ kind: "store",
170
+ repository: this.#repository,
171
+ root: this.#root,
172
+ token: this.#token
173
+ });
174
+ if (this.#baselineRefSha && remote.refSha !== this.#baselineRefSha) throw workspaceError(`[vitehub] GitHub Workspace Store conflict for ${this.#repository}@${this.#branch}: the branch changed after this Workspace Store loaded. Snapshotting requires a Workspace Store loaded from the current branch head.`);
175
+ this.#remoteFiles = remote.files;
176
+ this.#baselineRefSha = remote.refSha;
177
+ this.#baselineTreeSha = remote.treeSha;
178
+ const changedFiles = [...this.#files.values()].filter((file) => {
179
+ const remote = this.#remoteFiles.get(file.path);
180
+ return remote?.sha !== file.gitSha || (remote.mode || "100644") !== gitHubFileMode(file.metadata);
181
+ });
182
+ const deletePaths = [...this.#remoteFiles].filter(([path]) => !this.#files.has(path)).map(([, entry]) => entry.path);
183
+ if (!changedFiles.length && !deletePaths.length) {
184
+ this.#dirty = false;
185
+ this.#baseline = snapshot;
186
+ return snapshot;
187
+ }
188
+ const files = changedFiles.map((file) => {
189
+ return {
190
+ bytes: file.bytes,
191
+ fullPath: joinGitPath(this.#root, file.path),
192
+ gitSha: file.gitSha,
193
+ mode: gitHubFileMode(file.metadata)
194
+ };
195
+ });
196
+ const commit = await commitGitHubChanges({
197
+ baseTreeSha: this.#baselineTreeSha,
198
+ branch: this.#branch,
199
+ branchExists: remote.branchExists,
200
+ deletePaths,
201
+ files,
202
+ message: options.name || "chore: update workspace snapshot",
203
+ parentSha: this.#baselineRefSha,
204
+ repository: this.#repository,
205
+ token: this.#token
206
+ });
207
+ this.#dirty = false;
208
+ this.#baselineRefSha = commit.commitSha;
209
+ this.#baselineTreeSha = commit.treeSha;
210
+ this.#remoteFiles = this.#toRemoteFiles();
211
+ this.#baseline = {
212
+ ...snapshot,
213
+ id: commit.commitSha
214
+ };
215
+ return this.#baseline;
216
+ }
217
+ async diff(options = {}) {
218
+ await this.#ensure({ refresh: true });
219
+ return diffSnapshots(options.from || this.#baseline, await createSnapshotFromEntries(await this.#listEntries("", { recursive: true })));
220
+ }
221
+ async getMeta(key) {
222
+ await this.#ensure({ refresh: true });
223
+ const file = await this.#readWorkspaceFile(this.#metaPath(key));
224
+ if (!file) return void 0;
225
+ return JSON.parse(new TextDecoder().decode(file.bytes));
226
+ }
227
+ async setMeta(key, value) {
228
+ const path = this.#metaPath(key);
229
+ const content = JSON.stringify(value);
230
+ const bytes = new TextEncoder().encode(content);
231
+ await this.#ensure({ refresh: false });
232
+ this.#files.set(path, {
233
+ bytes,
234
+ gitSha: await gitBlobSha(bytes),
235
+ path,
236
+ size: bytes.byteLength
237
+ });
238
+ this.#dirty = true;
239
+ }
240
+ async #ensure(options) {
241
+ const wasReady = !!this.#ready;
242
+ this.#ready ||= this.#load();
243
+ await this.#ready;
244
+ if (wasReady && options.refresh && !this.#dirty) await this.#load();
245
+ }
246
+ async #load() {
247
+ const remote = await readGitHubBranchState({
248
+ branch: this.#branch,
249
+ kind: "store",
250
+ repository: this.#repository,
251
+ root: this.#root,
252
+ token: this.#token
253
+ });
254
+ this.#baselineRefSha = remote.refSha;
255
+ this.#baselineTreeSha = remote.treeSha;
256
+ this.#remoteFiles = remote.files;
257
+ if (!this.#dirty) {
258
+ this.#files = new Map([...remote.files].map(([path, entry]) => [path, {
259
+ gitSha: entry.sha,
260
+ metadata: gitHubFileMetadata(entry),
261
+ path,
262
+ size: entry.size
263
+ }]));
264
+ this.#baseline = await createSnapshotFromEntries(await this.#listEntries("", { recursive: true }), "github-workspace-store-load");
265
+ }
266
+ }
267
+ async #readWorkspaceFile(path, seen = /* @__PURE__ */ new Set()) {
268
+ const current = this.#files.get(path);
269
+ if (!current) return void 0;
270
+ const currentBytes = await this.#readFileBytes(current);
271
+ if (gitHubFileMode(current.metadata) === "120000" && !seen.has(path)) {
272
+ const target = resolveSymlinkTarget(path, currentBytes);
273
+ if (target && this.#files.has(target)) {
274
+ seen.add(path);
275
+ const resolved = await this.#readWorkspaceFile(target, seen);
276
+ if (resolved) return {
277
+ ...resolved,
278
+ mediaType: current.mediaType ?? resolved.mediaType,
279
+ metadata: await this.#fileMetadata(current) ?? resolved.metadata,
280
+ path
281
+ };
282
+ }
283
+ }
284
+ return {
285
+ content: currentBytes,
286
+ bytes: currentBytes,
287
+ mediaType: current.mediaType,
288
+ metadata: await this.#fileMetadata(current),
289
+ path
290
+ };
291
+ }
292
+ async #readFileBytes(file) {
293
+ if (!file.bytes) {
294
+ file.bytes = await readGitHubBlob({
295
+ kind: "store",
296
+ repository: this.#repository,
297
+ sha: file.gitSha,
298
+ token: this.#token
299
+ });
300
+ file.size = file.bytes.byteLength;
301
+ }
302
+ return file.bytes;
303
+ }
304
+ async #fileMetadata(file) {
305
+ if (gitHubFileMode(file.metadata) !== "120000" || typeof file.metadata?.symlinkTarget === "string") return file.metadata;
306
+ return {
307
+ ...file.metadata,
308
+ symlinkTarget: gitSymlinkTargetFromBytes(await this.#readFileBytes(file))
309
+ };
310
+ }
311
+ async #listEntries(prefix, options) {
312
+ const entries = /* @__PURE__ */ new Map();
313
+ for (const file of this.#files.values()) {
314
+ if (isReservedWorkspacePath(file.path)) continue;
315
+ for (const dir of parentDirectories(file.path)) if (this.#entryInPrefix(dir, prefix, options)) entries.set(dir, {
316
+ path: dir,
317
+ type: "directory"
318
+ });
319
+ if (this.#entryInPrefix(file.path, prefix, options)) entries.set(file.path, await this.#fileEntry(file));
320
+ }
321
+ return [...entries.values()].sort((a, b) => a.path.localeCompare(b.path));
322
+ }
323
+ #entryInPrefix(path, prefix, options) {
324
+ if (!prefix) return options.recursive || !path.includes("/");
325
+ if (path === prefix) return false;
326
+ if (!path.startsWith(`${prefix}/`)) return false;
327
+ return options.recursive || !path.slice(prefix.length + 1).includes("/");
328
+ }
329
+ async #fileEntry(file) {
330
+ return {
331
+ digest: file.gitSha,
332
+ mediaType: file.mediaType,
333
+ metadata: await this.#fileMetadata(file),
334
+ path: file.path,
335
+ size: file.size,
336
+ type: "file"
337
+ };
338
+ }
339
+ #directoryExists(path) {
340
+ return this.#publicDescendants(path).length > 0;
341
+ }
342
+ #publicDescendants(path) {
343
+ return [...this.#files.keys()].filter((key) => !isReservedWorkspacePath(key) && key.startsWith(`${path}/`));
344
+ }
345
+ #metaPath(key) {
346
+ return normalizeSafeWorkspacePath(`.vitehub/meta/${normalizeSafeWorkspacePath(key.endsWith(".json") ? key : `${key}.json`, { allowReserved: true })}`, { allowReserved: true });
347
+ }
348
+ #toRemoteFiles() {
349
+ return new Map([...this.#files.values()].map((file) => [file.path, {
350
+ path: joinGitPath(this.#root, file.path),
351
+ sha: file.gitSha,
352
+ size: file.size,
353
+ type: "blob",
354
+ mode: gitHubFileMode(file.metadata)
355
+ }]));
356
+ }
357
+ };
358
+ function createGitHubWorkspaceStore(options, workspaceName) {
359
+ return new GitHubWorkspaceStore(options, workspaceName);
360
+ }
361
+ //#endregion
362
+ export { createGitHubWorkspaceStore };
@@ -0,0 +1,6 @@
1
+ import { Zt as WorkspaceStore, w as VercelBlobWorkspaceStoreOptions } from "../../types-DHkae7Cb.js";
2
+
3
+ //#region src/providers/vercel/blob-store.d.ts
4
+ declare function createVercelBlobWorkspaceStore(options: VercelBlobWorkspaceStoreOptions, workspaceName: string): WorkspaceStore;
5
+ //#endregion
6
+ export { createVercelBlobWorkspaceStore };
@@ -0,0 +1,235 @@
1
+ import { a as matchesAny, c as normalizeWorkspacePath, d as sha256, o as normalizeSafeWorkspacePath, p as workspaceError, r as contentToBytes, s as normalizeSafeWorkspacePattern } from "../../path-CNI6wKIU.js";
2
+ import { a as resolveRuntimeVercelBlobWorkspaceStore } from "../../provider-CeQciesl.js";
3
+ import { n as createSnapshotFromEntries, r as diffSnapshots } from "../../utils-BPdaCyI6.js";
4
+ //#region src/providers/vercel/blob-store.ts
5
+ function joinBlobPath(...parts) {
6
+ return parts.map((part) => normalizeWorkspacePath(part)).filter(Boolean).join("/");
7
+ }
8
+ function contentType(path, fallback) {
9
+ if (fallback) return fallback;
10
+ if (path.endsWith(".json")) return "application/json; charset=utf-8";
11
+ if (path.endsWith(".md") || path.endsWith(".txt")) return "text/plain; charset=utf-8";
12
+ }
13
+ function auth(options) {
14
+ return options.token ? { token: options.token } : {};
15
+ }
16
+ async function createVercelBlobClient(options) {
17
+ const blob = await importVercelBlobPeer();
18
+ const access = options.access || "private";
19
+ return {
20
+ async delete(key) {
21
+ await blob.del(key, auth(options));
22
+ },
23
+ async download(key) {
24
+ const result = await blob.get(key, {
25
+ access,
26
+ ...auth(options)
27
+ });
28
+ if (!result || result.statusCode !== 200 || !result.stream) throw Object.assign(/* @__PURE__ */ new Error("not found"), { code: "NotFound" });
29
+ return await new Response(result.stream, { headers: result.blob.contentType ? { "content-type": result.blob.contentType } : void 0 }).blob();
30
+ },
31
+ async head(key) {
32
+ const result = await blob.head(key, auth(options));
33
+ return {
34
+ key: result.pathname,
35
+ lastModified: result.uploadedAt.getTime(),
36
+ size: result.size,
37
+ type: result.contentType
38
+ };
39
+ },
40
+ async list(optionsInput) {
41
+ const result = await blob.list({
42
+ ...optionsInput,
43
+ ...auth(options)
44
+ });
45
+ return {
46
+ cursor: result.cursor,
47
+ items: result.blobs.map((item) => ({
48
+ key: item.pathname,
49
+ lastModified: item.uploadedAt?.getTime(),
50
+ size: item.size
51
+ }))
52
+ };
53
+ },
54
+ async upload(key, body, uploadOptions = {}) {
55
+ await blob.put(key, body, {
56
+ access,
57
+ addRandomSuffix: false,
58
+ allowOverwrite: true,
59
+ contentType: uploadOptions.contentType,
60
+ ...auth(options)
61
+ });
62
+ }
63
+ };
64
+ }
65
+ const vercelBlobPeerSpecifier = "@vercel/blob";
66
+ async function importVercelBlobPeer() {
67
+ try {
68
+ const testImport = globalThis.__vitehubWorkspaceImportVercelBlobPeer;
69
+ if (testImport) return await testImport();
70
+ return await import(vercelBlobPeerSpecifier);
71
+ } catch (error) {
72
+ handleVercelBlobImportError(error);
73
+ }
74
+ }
75
+ function handleVercelBlobImportError(error) {
76
+ if (isMissingVercelBlobError(error)) throw workspaceError("[vitehub] @vercel/blob is required for the Vercel Blob Workspace Store. Package: @vercel/blob.", { cause: error });
77
+ throw error;
78
+ }
79
+ function isMissingVercelBlobError(error) {
80
+ if (!(error instanceof Error)) return false;
81
+ const code = error.code;
82
+ if (code !== "ERR_MODULE_NOT_FOUND" && code !== "MODULE_NOT_FOUND") return false;
83
+ return error.message.includes("Cannot find package '@vercel/blob'") || error.message.includes("Cannot find module '@vercel/blob'");
84
+ }
85
+ var VercelBlobWorkspaceStore = class {
86
+ workspaceName;
87
+ #baseline;
88
+ #options;
89
+ #files;
90
+ constructor(options, workspaceName) {
91
+ this.workspaceName = workspaceName;
92
+ this.#options = resolveRuntimeVercelBlobWorkspaceStore(options, typeof process !== "undefined" ? process.env : {});
93
+ }
94
+ get #root() {
95
+ return joinBlobPath(this.#options.prefix || ".vitehub/workspaces", this.workspaceName);
96
+ }
97
+ #fileKey(path, options = {}) {
98
+ return joinBlobPath(this.#root, "files", normalizeSafeWorkspacePath(path, { allowEmpty: options.allowEmpty }));
99
+ }
100
+ async #client() {
101
+ this.#files ||= createVercelBlobClient(this.#options);
102
+ return await this.#files;
103
+ }
104
+ #metaKey(key) {
105
+ return joinBlobPath(this.#root, ".vitehub/meta", normalizeSafeWorkspacePath(key.endsWith(".json") ? key : `${key}.json`));
106
+ }
107
+ #snapshotKey(id) {
108
+ return joinBlobPath(this.#root, ".vitehub/snapshots", `${id}.json`);
109
+ }
110
+ async readFile(path) {
111
+ const normalized = normalizeSafeWorkspacePath(path);
112
+ const pathname = this.#fileKey(normalized);
113
+ const file = await (await this.#client()).download(pathname).catch(() => null);
114
+ if (!file) return void 0;
115
+ const bytes = await file.arrayBuffer();
116
+ return {
117
+ path: normalized,
118
+ content: new Uint8Array(bytes)
119
+ };
120
+ }
121
+ async writeFile(path, file) {
122
+ const normalized = normalizeSafeWorkspacePath(path);
123
+ await (await this.#client()).upload(this.#fileKey(normalized), new Blob([contentToBytes(file.content)]), { contentType: contentType(normalized, file.mediaType) });
124
+ }
125
+ async list(prefix = "", options = {}) {
126
+ const normalizedPrefix = normalizeSafeWorkspacePath(prefix, { allowEmpty: true });
127
+ const filePrefix = this.#fileKey(normalizedPrefix, { allowEmpty: true });
128
+ const files = await this.#listBlobs(normalizedPrefix ? `${filePrefix}/` : `${this.#fileKey("", { allowEmpty: true })}/`);
129
+ const entries = /* @__PURE__ */ new Map();
130
+ for (const blob of files) {
131
+ const path = normalizeWorkspacePath(blob.key.slice(`${this.#fileKey("", { allowEmpty: true })}/`.length));
132
+ if (!path) continue;
133
+ if (normalizedPrefix && !path.startsWith(`${normalizedPrefix}/`)) continue;
134
+ if (!options.recursive && normalizedPrefix && path.slice(normalizedPrefix.length + 1).includes("/")) continue;
135
+ if (!options.recursive && !normalizedPrefix && path.includes("/")) {
136
+ entries.set(path.split("/")[0], {
137
+ path: path.split("/")[0],
138
+ type: "directory"
139
+ });
140
+ continue;
141
+ }
142
+ entries.set(path, {
143
+ mtime: blob.lastModified,
144
+ path,
145
+ size: blob.size,
146
+ type: "file"
147
+ });
148
+ if (options.recursive) {
149
+ const parts = path.split("/");
150
+ for (let index = 1; index < parts.length; index++) {
151
+ const dir = parts.slice(0, index).join("/");
152
+ entries.set(dir, {
153
+ path: dir,
154
+ type: "directory"
155
+ });
156
+ }
157
+ }
158
+ }
159
+ return [...entries.values()].sort((a, b) => a.path.localeCompare(b.path));
160
+ }
161
+ async glob(pattern, _options = {}) {
162
+ const patterns = Array.isArray(pattern) ? pattern.map(normalizeSafeWorkspacePattern) : normalizeSafeWorkspacePattern(pattern);
163
+ return (await this.list("", { recursive: true })).filter((entry) => entry.type === "file" && matchesAny(entry.path, patterns));
164
+ }
165
+ async stat(path) {
166
+ const normalized = normalizeSafeWorkspacePath(path);
167
+ const file = await this.readFile(normalized);
168
+ if (file) {
169
+ const bytes = contentToBytes(file.content);
170
+ return {
171
+ digest: await sha256(bytes),
172
+ path: normalized,
173
+ size: bytes.byteLength,
174
+ type: "file"
175
+ };
176
+ }
177
+ return (await this.list(normalized, { recursive: false })).length ? {
178
+ path: normalized,
179
+ type: "directory"
180
+ } : void 0;
181
+ }
182
+ async mkdir(path, _options = {}) {
183
+ normalizeSafeWorkspacePath(path);
184
+ }
185
+ async rm(path, options = {}) {
186
+ const normalized = normalizeSafeWorkspacePath(path);
187
+ const client = await this.#client();
188
+ const targets = [];
189
+ if (await client.head(this.#fileKey(normalized)).catch(() => null)) targets.push(this.#fileKey(normalized));
190
+ else if (options.recursive) for (const blob of await this.#listBlobs(`${this.#fileKey(normalized)}/`)) targets.push(blob.key);
191
+ if (!targets.length) {
192
+ if (options.force) return;
193
+ throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
194
+ }
195
+ await Promise.all(targets.map((target) => client.delete(target)));
196
+ }
197
+ async snapshot(options = {}) {
198
+ const snapshot = await createSnapshotFromEntries(await this.list("", { recursive: true }), options.name);
199
+ await (await this.#client()).upload(this.#snapshotKey(snapshot.id), JSON.stringify(snapshot), { contentType: "application/json; charset=utf-8" });
200
+ this.#baseline = snapshot;
201
+ return snapshot;
202
+ }
203
+ async diff(options = {}) {
204
+ return diffSnapshots(options.from || this.#baseline, await createSnapshotFromEntries(await this.list("", { recursive: true })));
205
+ }
206
+ async getMeta(key) {
207
+ return await this.#readJson(this.#metaKey(key));
208
+ }
209
+ async setMeta(key, value) {
210
+ await (await this.#client()).upload(this.#metaKey(key), JSON.stringify(value), { contentType: "application/json; charset=utf-8" });
211
+ }
212
+ async #listBlobs(prefix) {
213
+ const blobs = [];
214
+ let cursor;
215
+ do {
216
+ const result = await (await this.#client()).list({
217
+ cursor,
218
+ limit: 1e3,
219
+ prefix
220
+ });
221
+ blobs.push(...result.items);
222
+ cursor = result.cursor;
223
+ } while (cursor);
224
+ return blobs;
225
+ }
226
+ async #readJson(pathname) {
227
+ const file = await (await this.#client()).download(pathname).catch(() => null);
228
+ return file ? JSON.parse(await file.text()) : void 0;
229
+ }
230
+ };
231
+ function createVercelBlobWorkspaceStore(options, workspaceName) {
232
+ return new VercelBlobWorkspaceStore(options, workspaceName);
233
+ }
234
+ //#endregion
235
+ export { createVercelBlobWorkspaceStore };
@@ -0,0 +1,35 @@
1
+ import { a as GitHubWorkspaceOption, dt as WorkspacePublisher } from "./types-DHkae7Cb.js";
2
+
3
+ //#region src/publishers/manifest.d.ts
4
+ interface ManifestPublisherOptions {
5
+ path?: string;
6
+ }
7
+ declare function manifest(options?: ManifestPublisherOptions): WorkspacePublisher;
8
+ //#endregion
9
+ //#region src/publishers/github.d.ts
10
+ type GitHubPublisherOption = GitHubWorkspaceOption;
11
+ interface GitHubPublisherOptions {
12
+ branch?: GitHubPublisherOption;
13
+ deleteUntracked?: boolean;
14
+ message?: GitHubPublisherOption;
15
+ repo?: GitHubPublisherOption;
16
+ repository?: GitHubPublisherOption;
17
+ root?: GitHubPublisherOption;
18
+ token?: GitHubPublisherOption;
19
+ }
20
+ declare function github(options?: GitHubPublisherOptions): WorkspacePublisher;
21
+ //#endregion
22
+ //#region src/publishers/types.d.ts
23
+ interface TypesPublisherOptions {
24
+ path?: string;
25
+ }
26
+ declare function types(options?: TypesPublisherOptions): WorkspacePublisher;
27
+ //#endregion
28
+ //#region src/publishers/virtual-module.d.ts
29
+ interface VirtualModulePublisherOptions {
30
+ id: string;
31
+ includeContent?: boolean;
32
+ }
33
+ declare function virtualModule(options: VirtualModulePublisherOptions): WorkspacePublisher;
34
+ //#endregion
35
+ export { type GitHubPublisherOptions, type ManifestPublisherOptions, type TypesPublisherOptions, type VirtualModulePublisherOptions, github, manifest, types, virtualModule };