@vite-hub/workspace 0.0.4 → 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 (127) hide show
  1. package/README.md +225 -58
  2. package/dist/{ai-CjxvGqM0.d.ts → ai-BW2ZhizI.d.ts} +22 -7
  3. package/dist/{ai-BqCC8BpY.js → ai-BZyLwULx.js} +147 -66
  4. package/dist/ai.d.ts +2 -2
  5. package/dist/ai.js +1 -1
  6. package/dist/{asset-registry-8QI3ML3K.js → asset-registry-DfBV5kmw.js} +3 -2
  7. package/dist/association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js +19 -0
  8. package/dist/blob-database.d.ts +521 -0
  9. package/dist/blob-database.js +601 -0
  10. package/dist/cloudflare.d.ts +5 -6
  11. package/dist/cloudflare.js +1 -1
  12. package/dist/config-B7dmzDX3.js +1112 -0
  13. package/dist/{config-DE9xlaIw.d.ts → config-DLKdaFWN.d.ts} +1 -2
  14. package/dist/error-diagnostics-A_8Kp-48.js +116 -0
  15. package/dist/error-diagnostics-DY5GP47p.js +96 -0
  16. package/dist/events-7EBoeIPd-A2RUkJi5-BxrICQ17.js +354 -0
  17. package/dist/events-CRaLy7U3-3PNNp5WZ-Gv9nd0cH.js +214 -0
  18. package/dist/events-CeChclTf-CX-gD8oy-4aL2j6V-.js +527 -0
  19. package/dist/feed-DsC7Vws1-M_de2nSK-tKc0Pwo8.js +248 -0
  20. package/dist/feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js +179 -0
  21. package/dist/file-C0_aPWSS.js +26 -0
  22. package/dist/file-metadata-CxDy-E2H.js +58 -0
  23. package/dist/{files-Q6xZjDHA.js → files-C7Px8uaC.js} +3 -3
  24. package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +2278 -0
  25. package/dist/{github-DHnjxQIX.js → github-CPxHtFB7.js} +16 -23
  26. package/dist/github-DtncTfmv-Du2S8lGF.js +4159 -0
  27. package/dist/gitlab-BoDm8-BC-xzZsW9eW.js +2530 -0
  28. package/dist/glob--XcLlcml.js +22 -0
  29. package/dist/glob--kNYDbfU.js +30 -0
  30. package/dist/graphql-DG5aJBT3-DceyFYdM-C4saqX37.js +489 -0
  31. package/dist/{host-DJH8cuoU.js → host-CFnrTXTK.js} +97 -41
  32. package/dist/{hosted-RPeJOCFz.js → hosted-acMA5XyL.js} +102 -19
  33. package/dist/hosted-vercel-blob-DKntsHaf.js +12603 -0
  34. package/dist/hosted-vercel-blob.d.ts +5 -6
  35. package/dist/hosted-vercel-blob.js +1 -1
  36. package/dist/hosted.d.ts +6 -7
  37. package/dist/hosted.js +1 -1
  38. package/dist/index.d.ts +57 -36
  39. package/dist/index.js +56 -56
  40. package/dist/inspect-BoObD2cJ.js +167 -0
  41. package/dist/internal/path.d.ts +2 -0
  42. package/dist/internal/path.js +2 -0
  43. package/dist/lifecycle-BwZ7c9hb.js +596 -0
  44. package/dist/loader.d.ts +5 -6
  45. package/dist/loader.js +3 -2
  46. package/dist/mcp-resources-BREFCmtn.js +39 -0
  47. package/dist/memory-BbwOqDXl.js +248 -0
  48. package/dist/metadata-target-DZEZQGHA.js +1588 -0
  49. package/dist/mountx.d.ts +4 -6
  50. package/dist/mountx.js +10 -8
  51. package/dist/nitro.d.ts +1 -1
  52. package/dist/nitro.js +1 -1
  53. package/dist/nuxt.d.ts +13 -12
  54. package/dist/nuxt.js +4 -8
  55. package/dist/operations-BcpWr41m.js +159 -0
  56. package/dist/operations-CGqY1XeG.js +965 -0
  57. package/dist/operations-DnOwKsJT.d.ts +136 -0
  58. package/dist/operations.d.ts +53 -0
  59. package/dist/operations.js +2 -0
  60. package/dist/path-CNAwN7pw.js +114 -0
  61. package/dist/path-DrSIenjj.js +59 -0
  62. package/dist/path-zHxQUbqa.d.ts +9 -0
  63. package/dist/plugins-DqQ8b4T5.d.ts +10 -0
  64. package/dist/provider-kXjfli9u.js +1457 -0
  65. package/dist/providers/github/store.d.ts +3 -5
  66. package/dist/providers/github/store.js +1 -1
  67. package/dist/{registry-D3yzt8HQ.js → registry-Bp-8UUfG.js} +9 -7
  68. package/dist/{registry-Uj6IVxes.d.ts → registry-Cg1TJVVZ.d.ts} +1 -2
  69. package/dist/{request-execution-B-dSFlGB.js → request-execution-Dk9rY-Yh.js} +19 -19
  70. package/dist/{chunk-2rV9d50f.js → rolldown-runtime-B4iAMlE-.js} +2 -2
  71. package/dist/runtime/assets.d.ts +3 -5
  72. package/dist/runtime/assets.js +7 -6
  73. package/dist/runtime/empty-assets-registry.d.ts +1 -2
  74. package/dist/runtime/empty-registry.d.ts +1 -2
  75. package/dist/runtime/state.d.ts +3 -3
  76. package/dist/runtime/state.js +6 -6
  77. package/dist/runtime/workspace.d.ts +1 -1
  78. package/dist/runtime/workspace.js +1 -1
  79. package/dist/runtime.d.ts +51 -17
  80. package/dist/runtime.js +320 -60
  81. package/dist/{search-BpiCF2Tw.js → search-CrTmXj5h.js} +10 -9
  82. package/dist/server-BNQ-Nbjj.js +290 -0
  83. package/dist/server.d.ts +22 -34
  84. package/dist/server.js +2 -328
  85. package/dist/shared-DalXdP0i.js +2158 -0
  86. package/dist/source-metadata.d.ts +6 -7
  87. package/dist/source-metadata.js +7 -7
  88. package/dist/{state-tYcRWEh2.d.ts → state-B8zbLi5t.d.ts} +3 -3
  89. package/dist/store-CXgmu-uw.js +1729 -0
  90. package/dist/{sync-DnTQwt8r.js → sync-CN6ec-5M.js} +61 -41
  91. package/dist/templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js +125 -0
  92. package/dist/test.d.ts +1 -1
  93. package/dist/test.js +1 -1
  94. package/dist/{token-CVzURBxC.js → token-CO62GglH.js} +3 -3
  95. package/dist/{types-CYuwjJ4V.d.ts → types-DeK9GIxy.d.ts} +256 -24
  96. package/dist/{use-BTNDR5Rd.js → use-BQj7nSz6.js} +82 -41
  97. package/dist/{use-BiHzt0xA.d.ts → use-DhwhbAVV.d.ts} +16 -11
  98. package/dist/utils-Blrh4N2n.js +545 -0
  99. package/dist/vite-BEvgU2GY.js +20909 -0
  100. package/dist/vite-CcZmMQ7S.d.ts +476 -0
  101. package/dist/vite.d.ts +2 -2
  102. package/dist/vite.js +2 -2
  103. package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +1565 -0
  104. package/dist/{workspace-Dq08Yn72.js → workspace-6pxkOuxr.js} +361 -230
  105. package/dist/{workspace-Xddf4G1B.d.ts → workspace-BWJQBK1u.d.ts} +4 -3
  106. package/package.json +89 -55
  107. package/dist/collections/client.d.ts +0 -39
  108. package/dist/collections/client.js +0 -137
  109. package/dist/collections.d.ts +0 -59
  110. package/dist/collections.js +0 -159
  111. package/dist/config-Bc3c4Su1.js +0 -7904
  112. package/dist/config-CHLLWklZ.js +0 -36
  113. package/dist/file-Bc1X7pco.js +0 -23
  114. package/dist/glob-CEZKeZFC.js +0 -18
  115. package/dist/hosted-vercel-blob-d6C8ND5j.js +0 -23580
  116. package/dist/lifecycle-LrL3sA4n.js +0 -316
  117. package/dist/metadata-target-B0tOmVW7.js +0 -717
  118. package/dist/path-Cp59koVz.js +0 -139
  119. package/dist/provider-B1yLjCJJ.js +0 -746
  120. package/dist/publish.d.ts +0 -35
  121. package/dist/publish.js +0 -112
  122. package/dist/runtime-options-BsPSv5O7.js +0 -13
  123. package/dist/runtime-type-iEE6BjQJ.js +0 -34
  124. package/dist/shared-DTR1Hhma.js +0 -331
  125. package/dist/store-Dt_Jyys3.js +0 -608
  126. package/dist/vite-BptCrpv2.js +0 -4526
  127. package/dist/vite-CtA9guIM.d.ts +0 -66
@@ -0,0 +1,248 @@
1
+ import { n as assertWorkspaceDigest, o as workspaceConflictError, s as workspaceError } from "./path-DrSIenjj.js";
2
+ import { a as isExcludedWorkspacePath, f as sha256, l as normalizeWorkspacePath, o as isWorkspaceBytes } from "./path-CNAwN7pw.js";
3
+ import { r as workspaceStoreTarget } from "./target-D4Bqb1eH.js";
4
+ import { t as copyJsonFileMetadata } from "./file-metadata-CxDy-E2H.js";
5
+ import { t as createWorkspaceGlobMatcher } from "./glob--kNYDbfU.js";
6
+ //#region ../internal/src/owned-paths.ts
7
+ /** Every Blob path that ViteHub writes for itself starts with this prefix. */
8
+ const vitehubOwnedPrefix = "_vitehub/";
9
+ //#endregion
10
+ //#region src/storage/memory.ts
11
+ function now() {
12
+ return Date.now();
13
+ }
14
+ var MemoryWorkspaceStore = class MemoryWorkspaceStore {
15
+ [workspaceStoreTarget]() {
16
+ return { provider: "memory" };
17
+ }
18
+ #nodes = /* @__PURE__ */ new Map([["", {
19
+ type: "directory",
20
+ mtime: now()
21
+ }]]);
22
+ #meta = /* @__PURE__ */ new Map();
23
+ #baseline;
24
+ #mutationQueue = Promise.resolve();
25
+ fork() {
26
+ const fork = new MemoryWorkspaceStore();
27
+ fork.#nodes = structuredClone(this.#nodes);
28
+ fork.#meta = structuredClone(this.#meta);
29
+ fork.#baseline = structuredClone(this.#baseline);
30
+ return fork;
31
+ }
32
+ async readFile(path) {
33
+ const normalized = normalizeWorkspacePath(path);
34
+ const node = this.#nodes.get(normalized);
35
+ if (!node || node.type !== "file") return void 0;
36
+ return {
37
+ path: normalized,
38
+ content: isWorkspaceBytes(node.content) ? new Uint8Array(node.content) : node.content || "",
39
+ mediaType: node.mediaType,
40
+ metadata: structuredClone(node.metadata)
41
+ };
42
+ }
43
+ async writeFile(path, file) {
44
+ await this.#mutate(() => this.#writeFile(path, file));
45
+ }
46
+ async writeFileConditional(path, file, ifDigest) {
47
+ await this.#mutate(async () => {
48
+ const normalized = normalizeWorkspacePath(path);
49
+ const current = this.#nodes.get(normalized);
50
+ assertWorkspaceDigest(normalized, ifDigest, current?.type === "file" ? (await this.#entry(normalized, current)).digest : void 0);
51
+ this.#writeFile(normalized, file);
52
+ });
53
+ }
54
+ async list(prefix = "", options = {}) {
55
+ const normalizedPrefix = normalizeWorkspacePath(prefix);
56
+ const result = [];
57
+ for (const [path, node] of this.#nodes) {
58
+ if (!path || path === normalizedPrefix) continue;
59
+ if (isExcludedWorkspacePath(path, options.exclude)) continue;
60
+ if (normalizedPrefix && !path.startsWith(`${normalizedPrefix}/`)) continue;
61
+ if (!options.recursive && normalizeWorkspacePath(path.slice(normalizedPrefix.length)).replace(/^\//, "").includes("/")) continue;
62
+ result.push(await this.#entry(path, node));
63
+ }
64
+ return result.sort((a, b) => a.path.localeCompare(b.path));
65
+ }
66
+ async glob(pattern, options = {}) {
67
+ const { cwd, matches } = createWorkspaceGlobMatcher(pattern, options);
68
+ return (await this.list(cwd, { recursive: true })).filter((entry) => entry.type === "file" && matches(entry.path));
69
+ }
70
+ async stat(path) {
71
+ const normalized = normalizeWorkspacePath(path);
72
+ const node = this.#nodes.get(normalized);
73
+ return node ? {
74
+ ...await this.#entry(normalized, node),
75
+ revision: node.revision
76
+ } : void 0;
77
+ }
78
+ async mkdir(path, _options = {}) {
79
+ await this.#mutate(() => {
80
+ const normalized = normalizeWorkspacePath(path);
81
+ const existing = this.#nodes.get(normalized);
82
+ const recursive = _options.recursive ?? true;
83
+ if (existing) {
84
+ if (!recursive || existing.type === "file") throw workspaceError(`[vitehub] Workspace path already exists: ${path}.`);
85
+ return;
86
+ }
87
+ if (recursive) this.#ensureParents(normalized);
88
+ else {
89
+ const separator = normalized.lastIndexOf("/");
90
+ const parent = separator === -1 ? "" : normalized.slice(0, separator);
91
+ if (parent && this.#nodes.get(parent)?.type !== "directory") throw workspaceError(`[vitehub] Workspace parent does not exist: ${path}.`);
92
+ }
93
+ this.#nodes.set(normalized, {
94
+ type: "directory",
95
+ mtime: now()
96
+ });
97
+ });
98
+ }
99
+ async rm(path, options = {}) {
100
+ await this.#mutate(async () => {
101
+ const normalized = normalizeWorkspacePath(path);
102
+ const node = this.#nodes.get(normalized);
103
+ if (options.ifDigest !== void 0) {
104
+ const actual = node?.type === "file" ? (await this.#entry(normalized, node)).digest : void 0;
105
+ if (options.ifDigest === null ? node !== void 0 : actual !== options.ifDigest) throw workspaceConflictError(path, options.ifDigest, actual);
106
+ }
107
+ if (!node) {
108
+ if (options.force) return;
109
+ throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
110
+ }
111
+ if (node.type === "directory" && !options.recursive) {
112
+ for (const key of this.#nodes.keys()) if (key.startsWith(`${normalized}/`)) throw workspaceError(`[vitehub] Workspace directory is not empty: ${path}.`);
113
+ }
114
+ for (const key of this.#nodes.keys()) if (key === normalized || key.startsWith(`${normalized}/`)) this.#nodes.delete(key);
115
+ });
116
+ }
117
+ async removeEmptyDirectory(path) {
118
+ await this.#mutate(() => {
119
+ const normalized = normalizeWorkspacePath(path);
120
+ if (!normalized) return;
121
+ if (this.#nodes.get(normalized)?.type !== "directory") return;
122
+ for (const key of this.#nodes.keys()) if (key.startsWith(`${normalized}/`)) throw workspaceError(`[vitehub] Workspace directory is not empty: ${path}.`);
123
+ this.#nodes.delete(normalized);
124
+ });
125
+ }
126
+ async snapshot(options = {}) {
127
+ const snapshot = await this.#createSnapshot(options.name);
128
+ this.#baseline = snapshot;
129
+ return snapshot;
130
+ }
131
+ async diff(options = {}) {
132
+ const from = options.from || this.#baseline;
133
+ const to = await this.#createSnapshot();
134
+ const entries = [];
135
+ const keys = /* @__PURE__ */ new Set([...Object.keys(from?.entries || {}), ...Object.keys(to.entries)]);
136
+ for (const path of [...keys].sort()) {
137
+ const before = from && Object.hasOwn(from.entries, path) ? from.entries[path] : void 0;
138
+ const after = Object.hasOwn(to.entries, path) ? to.entries[path] : void 0;
139
+ if (!before && after) entries.push({
140
+ path,
141
+ type: "added",
142
+ after
143
+ });
144
+ else if (before && !after) entries.push({
145
+ path,
146
+ type: "removed",
147
+ before
148
+ });
149
+ 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({
150
+ path,
151
+ type: "modified",
152
+ before,
153
+ after
154
+ });
155
+ }
156
+ return {
157
+ from: from?.id,
158
+ to: to.id,
159
+ entries
160
+ };
161
+ }
162
+ async getMeta(key) {
163
+ return this.#meta.get(key);
164
+ }
165
+ async setMeta(key, value) {
166
+ this.#meta.set(key, value);
167
+ }
168
+ #writeFile(path, file) {
169
+ file = {
170
+ ...file,
171
+ metadata: copyJsonFileMetadata(path, file.metadata)
172
+ };
173
+ const normalized = normalizeWorkspacePath(path);
174
+ if (this.#nodes.get(normalized)?.type === "directory") throw workspaceError(`[vitehub] Cannot write a file over directory: ${normalized}.`);
175
+ this.#ensureParents(normalized);
176
+ this.#nodes.set(normalized, {
177
+ type: "file",
178
+ content: isWorkspaceBytes(file.content) ? new Uint8Array(file.content) : file.content,
179
+ revision: crypto.randomUUID(),
180
+ mediaType: file.mediaType,
181
+ metadata: structuredClone(file.metadata),
182
+ mtime: now()
183
+ });
184
+ }
185
+ #mutate(operation) {
186
+ const result = this.#mutationQueue.then(operation);
187
+ this.#mutationQueue = result.then(() => void 0, () => void 0);
188
+ return result;
189
+ }
190
+ #ensureParents(path) {
191
+ const parts = normalizeWorkspacePath(path).split("/").filter(Boolean);
192
+ for (let index = 1; index < parts.length; index++) {
193
+ const dir = parts.slice(0, index).join("/");
194
+ const node = this.#nodes.get(dir);
195
+ if (node?.type === "file") throw workspaceError(`[vitehub] Workspace parent is not a directory: ${path}.`);
196
+ if (!node) this.#nodes.set(dir, {
197
+ type: "directory",
198
+ mtime: now()
199
+ });
200
+ }
201
+ }
202
+ async #entry(path, node) {
203
+ const content = node.content || "";
204
+ const size = node.type === "file" ? typeof content === "string" ? new TextEncoder().encode(content).byteLength : content.byteLength : void 0;
205
+ return {
206
+ path,
207
+ type: node.type,
208
+ size,
209
+ mtime: node.mtime,
210
+ mediaType: node.mediaType,
211
+ metadata: structuredClone(node.metadata),
212
+ digest: node.type === "file" ? node.digest ??= await sha256(content) : void 0
213
+ };
214
+ }
215
+ async #createSnapshot(name) {
216
+ const entries = Object.create(null);
217
+ for (const [path, node] of this.#nodes) {
218
+ if (!path) continue;
219
+ const entry = await this.#entry(path, node);
220
+ entries[path] = {
221
+ type: entry.type,
222
+ digest: entry.digest,
223
+ metadata: entry.metadata,
224
+ size: entry.size
225
+ };
226
+ }
227
+ return {
228
+ id: await sha256({
229
+ name,
230
+ entries,
231
+ createdAt: Date.now()
232
+ }),
233
+ name,
234
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
235
+ entries
236
+ };
237
+ }
238
+ };
239
+ function createMemoryWorkspaceStore() {
240
+ return new MemoryWorkspaceStore();
241
+ }
242
+ /** Internal copy for Store adapters that publish draft mutations only after validation. */
243
+ function forkMemoryWorkspaceStore(store) {
244
+ if (!(store instanceof MemoryWorkspaceStore)) throw workspaceError("[vitehub] Only memory Workspace Stores can be forked.");
245
+ return store.fork();
246
+ }
247
+ //#endregion
248
+ export { forkMemoryWorkspaceStore as n, vitehubOwnedPrefix as r, createMemoryWorkspaceStore as t };