@vite-hub/workspace 0.0.3 → 0.1.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 (129) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +236 -58
  3. package/dist/{ai-nmHdzjCM.d.ts → ai-BW2ZhizI.d.ts} +22 -7
  4. package/dist/{ai-Ce3PtWFW.js → ai-BZyLwULx.js} +147 -66
  5. package/dist/ai.d.ts +2 -2
  6. package/dist/ai.js +1 -1
  7. package/dist/{asset-registry-CaG9b7tf.js → asset-registry-DfBV5kmw.js} +3 -2
  8. package/dist/association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js +19 -0
  9. package/dist/blob-database.d.ts +521 -0
  10. package/dist/blob-database.js +601 -0
  11. package/dist/cloudflare.d.ts +5 -6
  12. package/dist/cloudflare.js +1 -1
  13. package/dist/config-B7dmzDX3.js +1112 -0
  14. package/dist/{config-3I1BnsdO.d.ts → config-DLKdaFWN.d.ts} +1 -2
  15. package/dist/error-diagnostics-A_8Kp-48.js +116 -0
  16. package/dist/error-diagnostics-DY5GP47p.js +96 -0
  17. package/dist/events-7EBoeIPd-A2RUkJi5-BxrICQ17.js +354 -0
  18. package/dist/events-CRaLy7U3-3PNNp5WZ-Gv9nd0cH.js +214 -0
  19. package/dist/events-CeChclTf-CX-gD8oy-4aL2j6V-.js +527 -0
  20. package/dist/feed-DsC7Vws1-M_de2nSK-tKc0Pwo8.js +248 -0
  21. package/dist/feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js +179 -0
  22. package/dist/file-C0_aPWSS.js +26 -0
  23. package/dist/file-metadata-CxDy-E2H.js +58 -0
  24. package/dist/{files-QRV55OCx.js → files-C7Px8uaC.js} +21 -10
  25. package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +2278 -0
  26. package/dist/{github-CfA5vpJ5.js → github-CPxHtFB7.js} +36 -34
  27. package/dist/github-DtncTfmv-Du2S8lGF.js +4159 -0
  28. package/dist/gitlab-BoDm8-BC-xzZsW9eW.js +2530 -0
  29. package/dist/glob--XcLlcml.js +22 -0
  30. package/dist/glob--kNYDbfU.js +30 -0
  31. package/dist/graphql-DG5aJBT3-DceyFYdM-C4saqX37.js +489 -0
  32. package/dist/host-CFnrTXTK.js +1086 -0
  33. package/dist/{hosted-C1-tTTTf.js → hosted-acMA5XyL.js} +216 -43
  34. package/dist/hosted-vercel-blob-DKntsHaf.js +12603 -0
  35. package/dist/hosted-vercel-blob.d.ts +5 -6
  36. package/dist/hosted-vercel-blob.js +1 -1
  37. package/dist/hosted.d.ts +6 -7
  38. package/dist/hosted.js +1 -1
  39. package/dist/index.d.ts +76 -64
  40. package/dist/index.js +162 -457
  41. package/dist/inspect-BoObD2cJ.js +167 -0
  42. package/dist/internal/path.d.ts +2 -0
  43. package/dist/internal/path.js +2 -0
  44. package/dist/lifecycle-BwZ7c9hb.js +596 -0
  45. package/dist/loader.d.ts +5 -6
  46. package/dist/loader.js +3 -2
  47. package/dist/mcp-resources-BREFCmtn.js +39 -0
  48. package/dist/memory-BbwOqDXl.js +248 -0
  49. package/dist/metadata-target-DZEZQGHA.js +1588 -0
  50. package/dist/mountx.d.ts +4 -6
  51. package/dist/mountx.js +10 -8
  52. package/dist/nitro.d.ts +1 -1
  53. package/dist/nitro.js +1 -1
  54. package/dist/nuxt.d.ts +13 -12
  55. package/dist/nuxt.js +10 -8
  56. package/dist/operations-BcpWr41m.js +159 -0
  57. package/dist/operations-CGqY1XeG.js +965 -0
  58. package/dist/operations-DnOwKsJT.d.ts +136 -0
  59. package/dist/operations.d.ts +53 -0
  60. package/dist/operations.js +2 -0
  61. package/dist/{path-CNI6wKIU.js → path-CNAwN7pw.js} +34 -35
  62. package/dist/path-DrSIenjj.js +59 -0
  63. package/dist/path-zHxQUbqa.d.ts +9 -0
  64. package/dist/plugins-DqQ8b4T5.d.ts +10 -0
  65. package/dist/provider-kXjfli9u.js +1457 -0
  66. package/dist/providers/github/store.d.ts +3 -5
  67. package/dist/providers/github/store.js +1 -1
  68. package/dist/registry-Bp-8UUfG.js +129 -0
  69. package/dist/{registry-BIQVCBWI.d.ts → registry-Cg1TJVVZ.d.ts} +3 -4
  70. package/dist/{request-execution-u9mgUXKX.js → request-execution-Dk9rY-Yh.js} +24 -20
  71. package/dist/rolldown-runtime-B4iAMlE-.js +35 -0
  72. package/dist/runtime/assets.d.ts +3 -5
  73. package/dist/runtime/assets.js +9 -6
  74. package/dist/runtime/empty-assets-registry.d.ts +1 -2
  75. package/dist/runtime/empty-registry.d.ts +1 -2
  76. package/dist/runtime/state.d.ts +4 -4
  77. package/dist/runtime/state.js +10 -7
  78. package/dist/runtime/workspace.d.ts +1 -1
  79. package/dist/runtime/workspace.js +1 -1
  80. package/dist/runtime.d.ts +84 -15
  81. package/dist/runtime.js +561 -108
  82. package/dist/{search-C4REyHj9.js → search-CrTmXj5h.js} +10 -9
  83. package/dist/server-BNQ-Nbjj.js +290 -0
  84. package/dist/server.d.ts +22 -34
  85. package/dist/server.js +2 -355
  86. package/dist/shared-DalXdP0i.js +2158 -0
  87. package/dist/source-metadata.d.ts +7 -1
  88. package/dist/source-metadata.js +34 -2
  89. package/dist/{state-TTqa3x3Y.d.ts → state-B8zbLi5t.d.ts} +14 -13
  90. package/dist/store-CXgmu-uw.js +1729 -0
  91. package/dist/{sync-DiuDmSGk.js → sync-CN6ec-5M.js} +62 -41
  92. package/dist/templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js +125 -0
  93. package/dist/test.d.ts +1 -1
  94. package/dist/test.js +1 -1
  95. package/dist/token-CO62GglH.js +61 -0
  96. package/dist/{types-60Yn149G.d.ts → types-DeK9GIxy.d.ts} +348 -49
  97. package/dist/{use-CsV3oIxH.js → use-BQj7nSz6.js} +200 -45
  98. package/dist/{use-CUFSnFCS.d.ts → use-DhwhbAVV.d.ts} +34 -12
  99. package/dist/utils-Blrh4N2n.js +545 -0
  100. package/dist/vite-BEvgU2GY.js +20909 -0
  101. package/dist/vite-CcZmMQ7S.d.ts +476 -0
  102. package/dist/vite.d.ts +2 -50
  103. package/dist/vite.js +2 -2
  104. package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +1565 -0
  105. package/dist/workspace-6pxkOuxr.js +1286 -0
  106. package/dist/workspace-BWJQBK1u.d.ts +7 -0
  107. package/package.json +90 -59
  108. package/dist/chunk-8H4AJuhK.js +0 -14
  109. package/dist/collections/client.d.ts +0 -39
  110. package/dist/collections/client.js +0 -137
  111. package/dist/collections.d.ts +0 -59
  112. package/dist/collections.js +0 -159
  113. package/dist/config-CDoyls2X.js +0 -30
  114. package/dist/config-CZLO0m9h.js +0 -7811
  115. package/dist/file-CHfsZpso.js +0 -23
  116. package/dist/glob-D0vD_wRY.js +0 -17
  117. package/dist/host-CAnbugpI.js +0 -370
  118. package/dist/hosted-vercel-blob-CWBILDVo.js +0 -257
  119. package/dist/lifecycle-BYoa9hVb.js +0 -176
  120. package/dist/provider-C3_elpEh.js +0 -599
  121. package/dist/publish.d.ts +0 -35
  122. package/dist/publish.js +0 -112
  123. package/dist/registry-CqyDTW9Y.js +0 -74
  124. package/dist/runtime-options-BsPSv5O7.js +0 -13
  125. package/dist/shared-jfogBrd5.js +0 -273
  126. package/dist/store-Bs1SLh55.js +0 -414
  127. package/dist/vite-tbfDxtlu.js +0 -2191
  128. package/dist/workspace-66SKyiec.d.ts +0 -6
  129. package/dist/workspace-C4k92Ow8.js +0 -1460
@@ -1,414 +0,0 @@
1
- import { a as matchesAny, c as normalizeWorkspacePath, d as sha256, n as contentStreamToBytes, o as normalizeSafeWorkspacePath, p as workspaceError, s as normalizeSafeWorkspacePattern } from "./path-CNI6wKIU.js";
2
- import { r as workspaceStoreTarget } from "./target-D4Bqb1eH.js";
3
- 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-jfogBrd5.js";
4
- import { posix } from "node:path";
5
- //#region src/storage/utils.ts
6
- async function createCurrentSnapshotFromStore(store, name) {
7
- return await createSnapshotFromEntries(await store.list("", { recursive: true }), name);
8
- }
9
- async function createSnapshotFromEntries(entries, name) {
10
- const snapshotEntries = {};
11
- for (const entry of entries) snapshotEntries[entry.path] = {
12
- digest: entry.digest,
13
- metadata: entry.metadata,
14
- size: entry.size,
15
- type: entry.type
16
- };
17
- return {
18
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
19
- entries: snapshotEntries,
20
- id: await sha256({
21
- entries: snapshotEntries,
22
- name,
23
- createdAt: Date.now()
24
- }),
25
- name
26
- };
27
- }
28
- function diffSnapshots(from, to) {
29
- const entries = [];
30
- const keys = new Set([...Object.keys(from?.entries || {}), ...Object.keys(to.entries)]);
31
- for (const path of [...keys].sort()) {
32
- const before = from?.entries[path];
33
- const after = to.entries[path];
34
- if (!before && after) entries.push({
35
- path,
36
- type: "added",
37
- after
38
- });
39
- else if (before && !after) entries.push({
40
- path,
41
- type: "removed",
42
- before
43
- });
44
- 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({
45
- path,
46
- type: "modified",
47
- before,
48
- after
49
- });
50
- }
51
- return {
52
- from: from?.id,
53
- to: to.id,
54
- entries
55
- };
56
- }
57
- //#endregion
58
- //#region src/providers/github/store.ts
59
- function isReservedWorkspacePath(path) {
60
- const root = normalizeWorkspacePath(path).split("/")[0];
61
- return root === ".git" || root === ".vitehub";
62
- }
63
- function contentLength(content) {
64
- return typeof content === "string" ? new TextEncoder().encode(content).byteLength : content.byteLength;
65
- }
66
- function gitHubFileMetadata(entry) {
67
- return entry.mode === "120000" || entry.mode === "100755" ? { gitMode: entry.mode } : void 0;
68
- }
69
- function gitHubFileMode(metadata) {
70
- return metadata?.gitMode === "120000" || metadata?.gitMode === "100755" ? metadata.gitMode : "100644";
71
- }
72
- function inheritedGitHubFileMetadata(file, current) {
73
- if (file.metadata) return file.metadata;
74
- return current?.metadata?.gitMode === "100755" ? current.metadata : void 0;
75
- }
76
- function parentDirectories(path) {
77
- const parts = normalizeWorkspacePath(path).split("/").filter(Boolean);
78
- const directories = [];
79
- for (let index = 1; index < parts.length; index++) directories.push(parts.slice(0, index).join("/"));
80
- return directories;
81
- }
82
- function resolveSymlinkTarget(path, bytes) {
83
- const target = gitSymlinkTargetFromBytes(bytes);
84
- if (!target || target.startsWith("/")) return;
85
- const base = path.split("/").slice(0, -1).join("/");
86
- const resolved = posix.normalize(base ? `${base}/${target}` : target);
87
- if (!resolved || resolved === "." || resolved === ".." || resolved.startsWith("../")) return;
88
- return normalizeSafeWorkspacePath(resolved);
89
- }
90
- function gitSymlinkTargetFromBytes(bytes) {
91
- return new TextDecoder().decode(bytes).replace(/\0/g, "");
92
- }
93
- var GitHubWorkspaceStore = class {
94
- workspaceName;
95
- #baseline;
96
- #baselineRefSha;
97
- #baselineTreeSha;
98
- #branch;
99
- #dirty = false;
100
- #files = /* @__PURE__ */ new Map();
101
- #ready;
102
- #remoteFiles = /* @__PURE__ */ new Map();
103
- #repository;
104
- #root;
105
- #token;
106
- constructor(options, workspaceName) {
107
- this.workspaceName = workspaceName;
108
- this.#repository = requireGitHubOption("store", "a repository", resolveGitHubRepositoryOption(options));
109
- this.#branch = resolveGitHubBranchOption(options);
110
- this.#root = resolveGitHubRootOption(options, workspaceName);
111
- this.#token = requireGitHubOption("store", "a token", resolveGitHubTokenOption(options));
112
- }
113
- [workspaceStoreTarget]() {
114
- return {
115
- provider: "github",
116
- branch: this.#branch,
117
- repository: this.#repository
118
- };
119
- }
120
- async readFile(path) {
121
- const normalized = normalizeSafeWorkspacePath(path);
122
- await this.#ensure({ refresh: true });
123
- return await this.#readWorkspaceFile(normalized);
124
- }
125
- async writeFile(path, file) {
126
- const normalized = normalizeSafeWorkspacePath(path);
127
- await this.#ensure({ refresh: false });
128
- const current = this.#files.get(normalized);
129
- const metadata = inheritedGitHubFileMetadata(file, current);
130
- const content = gitHubFileMode(metadata) === "120000" && typeof metadata?.symlinkTarget === "string" ? metadata.symlinkTarget : file.content;
131
- const update = await createGitHubFileUpdate(normalized, this.#root, content);
132
- if (current?.gitSha === update.gitSha) {
133
- if (gitHubFileMode(current.metadata) !== gitHubFileMode(metadata)) this.#dirty = true;
134
- this.#files.set(normalized, {
135
- ...current,
136
- mediaType: file.mediaType,
137
- metadata,
138
- size: contentLength(content)
139
- });
140
- return;
141
- }
142
- await createGitHubBlob({
143
- bytes: update.bytes,
144
- kind: "store",
145
- repository: this.#repository,
146
- token: this.#token
147
- });
148
- this.#files.set(normalized, {
149
- gitSha: update.gitSha,
150
- mediaType: file.mediaType,
151
- metadata,
152
- path: normalized,
153
- size: contentLength(content)
154
- });
155
- this.#dirty = true;
156
- }
157
- async writeFileStream(path, file) {
158
- const content = await contentStreamToBytes(file.content);
159
- await this.writeFile(path, {
160
- path: file.path,
161
- content,
162
- mediaType: file.mediaType,
163
- metadata: file.metadata
164
- });
165
- return {
166
- digest: await gitBlobSha(content),
167
- mediaType: file.mediaType,
168
- path: normalizeSafeWorkspacePath(path),
169
- size: content.byteLength,
170
- type: "file"
171
- };
172
- }
173
- async list(prefix = "", options = {}) {
174
- const normalizedPrefix = normalizeSafeWorkspacePath(prefix, { allowEmpty: true });
175
- await this.#ensure({ refresh: true });
176
- return await this.#listEntries(normalizedPrefix, options);
177
- }
178
- async glob(pattern, _options = {}) {
179
- const patterns = Array.isArray(pattern) ? pattern.map(normalizeSafeWorkspacePattern) : normalizeSafeWorkspacePattern(pattern);
180
- return (await this.list("", { recursive: true })).filter((entry) => entry.type === "file" && matchesAny(entry.path, patterns));
181
- }
182
- async stat(path) {
183
- const normalized = normalizeSafeWorkspacePath(path);
184
- await this.#ensure({ refresh: true });
185
- const file = this.#files.get(normalized);
186
- if (file && !isReservedWorkspacePath(normalized)) return this.#fileEntry(file);
187
- if (this.#directoryExists(normalized)) return {
188
- path: normalized,
189
- type: "directory"
190
- };
191
- }
192
- async mkdir(path, _options = {}) {
193
- normalizeSafeWorkspacePath(path);
194
- }
195
- async rm(path, options = {}) {
196
- const normalized = normalizeSafeWorkspacePath(path);
197
- await this.#ensure({ refresh: false });
198
- if (this.#files.get(normalized) && !isReservedWorkspacePath(normalized)) {
199
- this.#files.delete(normalized);
200
- this.#dirty = true;
201
- return;
202
- }
203
- const children = this.#publicDescendants(normalized);
204
- if (!(children.length > 0)) {
205
- if (options.force) return;
206
- throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
207
- }
208
- if (children.length && !options.recursive) throw workspaceError(`[vitehub] Workspace directory is not empty: ${path}.`);
209
- for (const child of children) this.#files.delete(child);
210
- this.#dirty = true;
211
- }
212
- async snapshot(options = {}) {
213
- await this.#ensure({ refresh: false });
214
- const snapshot = await createSnapshotFromEntries(await this.#listEntries("", { recursive: true }), options.name);
215
- if (!this.#dirty) {
216
- this.#baseline = snapshot;
217
- return snapshot;
218
- }
219
- const remote = await readGitHubBranchState({
220
- branch: this.#branch,
221
- kind: "store",
222
- repository: this.#repository,
223
- root: this.#root,
224
- token: this.#token
225
- });
226
- 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.`);
227
- this.#remoteFiles = remote.files;
228
- this.#baselineRefSha = remote.refSha;
229
- this.#baselineTreeSha = remote.treeSha;
230
- const changedFiles = [...this.#files.values()].filter((file) => {
231
- const remote = this.#remoteFiles.get(file.path);
232
- return remote?.sha !== file.gitSha || (remote.mode || "100644") !== gitHubFileMode(file.metadata);
233
- });
234
- const deletePaths = [...this.#remoteFiles].filter(([path]) => !this.#files.has(path)).map(([, entry]) => entry.path);
235
- if (!changedFiles.length && !deletePaths.length) {
236
- this.#dirty = false;
237
- this.#baseline = snapshot;
238
- return snapshot;
239
- }
240
- const files = changedFiles.map((file) => {
241
- return {
242
- bytes: file.bytes,
243
- fullPath: joinGitPath(this.#root, file.path),
244
- gitSha: file.gitSha,
245
- mode: gitHubFileMode(file.metadata)
246
- };
247
- });
248
- const commit = await commitGitHubChanges({
249
- baseTreeSha: this.#baselineTreeSha,
250
- branch: this.#branch,
251
- branchExists: remote.branchExists,
252
- deletePaths,
253
- files,
254
- message: options.name || "chore: update workspace snapshot",
255
- parentSha: this.#baselineRefSha,
256
- repository: this.#repository,
257
- token: this.#token
258
- });
259
- this.#dirty = false;
260
- this.#baselineRefSha = commit.commitSha;
261
- this.#baselineTreeSha = commit.treeSha;
262
- this.#remoteFiles = this.#toRemoteFiles();
263
- this.#baseline = {
264
- ...snapshot,
265
- id: commit.commitSha
266
- };
267
- return this.#baseline;
268
- }
269
- async diff(options = {}) {
270
- await this.#ensure({ refresh: true });
271
- return diffSnapshots(options.from || this.#baseline, await createSnapshotFromEntries(await this.#listEntries("", { recursive: true })));
272
- }
273
- async getMeta(key) {
274
- await this.#ensure({ refresh: true });
275
- const file = await this.#readWorkspaceFile(this.#metaPath(key));
276
- if (!file) return void 0;
277
- return JSON.parse(new TextDecoder().decode(file.bytes));
278
- }
279
- async setMeta(key, value) {
280
- const path = this.#metaPath(key);
281
- const content = JSON.stringify(value);
282
- const bytes = new TextEncoder().encode(content);
283
- await this.#ensure({ refresh: false });
284
- this.#files.set(path, {
285
- bytes,
286
- gitSha: await gitBlobSha(bytes),
287
- path,
288
- size: bytes.byteLength
289
- });
290
- this.#dirty = true;
291
- }
292
- async #ensure(options) {
293
- const wasReady = !!this.#ready;
294
- this.#ready ||= this.#load();
295
- await this.#ready;
296
- if (wasReady && options.refresh && !this.#dirty) await this.#load();
297
- }
298
- async #load() {
299
- const remote = await readGitHubBranchState({
300
- branch: this.#branch,
301
- kind: "store",
302
- repository: this.#repository,
303
- root: this.#root,
304
- token: this.#token
305
- });
306
- this.#baselineRefSha = remote.refSha;
307
- this.#baselineTreeSha = remote.treeSha;
308
- this.#remoteFiles = remote.files;
309
- if (!this.#dirty) {
310
- this.#files = new Map([...remote.files].map(([path, entry]) => [path, {
311
- gitSha: entry.sha,
312
- metadata: gitHubFileMetadata(entry),
313
- path,
314
- size: entry.size
315
- }]));
316
- this.#baseline = await createSnapshotFromEntries(await this.#listEntries("", { recursive: true }), "github-workspace-store-load");
317
- }
318
- }
319
- async #readWorkspaceFile(path, seen = /* @__PURE__ */ new Set()) {
320
- const current = this.#files.get(path);
321
- if (!current) return void 0;
322
- const currentBytes = await this.#readFileBytes(current);
323
- if (gitHubFileMode(current.metadata) === "120000" && !seen.has(path)) {
324
- const target = resolveSymlinkTarget(path, currentBytes);
325
- if (target && this.#files.has(target)) {
326
- seen.add(path);
327
- const resolved = await this.#readWorkspaceFile(target, seen);
328
- if (resolved) return {
329
- ...resolved,
330
- mediaType: current.mediaType ?? resolved.mediaType,
331
- metadata: await this.#fileMetadata(current) ?? resolved.metadata,
332
- path
333
- };
334
- }
335
- }
336
- return {
337
- content: currentBytes,
338
- bytes: currentBytes,
339
- mediaType: current.mediaType,
340
- metadata: await this.#fileMetadata(current),
341
- path
342
- };
343
- }
344
- async #readFileBytes(file) {
345
- if (!file.bytes) {
346
- file.bytes = await readGitHubBlob({
347
- kind: "store",
348
- repository: this.#repository,
349
- sha: file.gitSha,
350
- token: this.#token
351
- });
352
- file.size = file.bytes.byteLength;
353
- }
354
- return file.bytes;
355
- }
356
- async #fileMetadata(file) {
357
- if (gitHubFileMode(file.metadata) !== "120000" || typeof file.metadata?.symlinkTarget === "string") return file.metadata;
358
- return {
359
- ...file.metadata,
360
- symlinkTarget: gitSymlinkTargetFromBytes(await this.#readFileBytes(file))
361
- };
362
- }
363
- async #listEntries(prefix, options) {
364
- const entries = /* @__PURE__ */ new Map();
365
- for (const file of this.#files.values()) {
366
- if (isReservedWorkspacePath(file.path)) continue;
367
- for (const dir of parentDirectories(file.path)) if (this.#entryInPrefix(dir, prefix, options)) entries.set(dir, {
368
- path: dir,
369
- type: "directory"
370
- });
371
- if (this.#entryInPrefix(file.path, prefix, options)) entries.set(file.path, await this.#fileEntry(file));
372
- }
373
- return [...entries.values()].sort((a, b) => a.path.localeCompare(b.path));
374
- }
375
- #entryInPrefix(path, prefix, options) {
376
- if (!prefix) return options.recursive || !path.includes("/");
377
- if (path === prefix) return false;
378
- if (!path.startsWith(`${prefix}/`)) return false;
379
- return options.recursive || !path.slice(prefix.length + 1).includes("/");
380
- }
381
- async #fileEntry(file) {
382
- return {
383
- digest: file.gitSha,
384
- mediaType: file.mediaType,
385
- metadata: await this.#fileMetadata(file),
386
- path: file.path,
387
- size: file.size,
388
- type: "file"
389
- };
390
- }
391
- #directoryExists(path) {
392
- return this.#publicDescendants(path).length > 0;
393
- }
394
- #publicDescendants(path) {
395
- return [...this.#files.keys()].filter((key) => !isReservedWorkspacePath(key) && key.startsWith(`${path}/`));
396
- }
397
- #metaPath(key) {
398
- return normalizeSafeWorkspacePath(`.vitehub/meta/${normalizeSafeWorkspacePath(key.endsWith(".json") ? key : `${key}.json`, { allowReserved: true })}`, { allowReserved: true });
399
- }
400
- #toRemoteFiles() {
401
- return new Map([...this.#files.values()].map((file) => [file.path, {
402
- path: joinGitPath(this.#root, file.path),
403
- sha: file.gitSha,
404
- size: file.size,
405
- type: "blob",
406
- mode: gitHubFileMode(file.metadata)
407
- }]));
408
- }
409
- };
410
- function createGitHubWorkspaceStore(options, workspaceName) {
411
- return new GitHubWorkspaceStore(options, workspaceName);
412
- }
413
- //#endregion
414
- export { diffSnapshots as i, createCurrentSnapshotFromStore as n, createSnapshotFromEntries as r, createGitHubWorkspaceStore as t };