@vite-hub/workspace 0.0.4 → 0.3.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 (137) hide show
  1. package/README.md +339 -115
  2. package/dist/abort-BCwpdrN0.js +32 -0
  3. package/dist/{asset-registry-8QI3ML3K.js → asset-registry-DfBV5kmw.js} +3 -2
  4. package/dist/blob-database.d.ts +474 -0
  5. package/dist/blob-database.js +608 -0
  6. package/dist/checkout.d.ts +128 -0
  7. package/dist/checkout.js +849 -0
  8. package/dist/cloudflare.d.ts +6 -7
  9. package/dist/cloudflare.js +1 -1
  10. package/dist/config-B-863EgC.js +15 -0
  11. package/dist/config-BAgL2dtB.js +1076 -0
  12. package/dist/{config-DE9xlaIw.d.ts → config-BQKcPawI.d.ts} +1 -2
  13. package/dist/discard-CNNtCozM.js +8 -0
  14. package/dist/durability.d.ts +22 -0
  15. package/dist/durability.js +70 -0
  16. package/dist/error-diagnostics-CtKjGtGb.js +188 -0
  17. package/dist/error-diagnostics-DSkCJC_L.js +266 -0
  18. package/dist/file-2pFYNtsU.js +22 -0
  19. package/dist/{files-Q6xZjDHA.js → files-BOo4SbwE.js} +3 -3
  20. package/dist/files.d.ts +38 -0
  21. package/dist/files.js +6 -0
  22. package/dist/{github-DHnjxQIX.js → github-CrYp4v8k.js} +44 -24
  23. package/dist/glob-B8YGvTrZ.js +21 -0
  24. package/dist/glob-Cjxms1t7.js +30 -0
  25. package/dist/{host-DJH8cuoU.js → host-BFBpXn0N.js} +144 -77
  26. package/dist/{hosted-RPeJOCFz.js → hosted-KcUR_jPv.js} +303 -97
  27. package/dist/hosted-vercel-blob-B3-wRdUm.js +410 -0
  28. package/dist/hosted-vercel-blob.d.ts +6 -7
  29. package/dist/hosted-vercel-blob.js +1 -1
  30. package/dist/hosted.d.ts +10 -9
  31. package/dist/hosted.js +2 -2
  32. package/dist/index.d.ts +26 -47
  33. package/dist/index.js +30 -100
  34. package/dist/internal/path.d.ts +2 -0
  35. package/dist/internal/path.js +2 -0
  36. package/dist/lifecycle-B-enk_4A.js +596 -0
  37. package/dist/lineage.d.ts +26 -0
  38. package/dist/lineage.js +76 -0
  39. package/dist/loader.d.ts +5 -6
  40. package/dist/loader.js +3 -2
  41. package/dist/mcp-resources-DF0F5rcL.js +39 -0
  42. package/dist/memory-BOexthyW.js +247 -0
  43. package/dist/metadata-target-CWz6KHKq.js +1589 -0
  44. package/dist/object-Da1zyPCR.js +11 -0
  45. package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
  46. package/dist/operations-C6FpR8Rr.js +389 -0
  47. package/dist/operations-CE2drFih.js +1234 -0
  48. package/dist/operations.d.ts +90 -0
  49. package/dist/operations.js +3 -0
  50. package/dist/path--wrT_Azm.js +113 -0
  51. package/dist/path-AxMho1wo.d.ts +7 -0
  52. package/dist/path-DrSIenjj.js +59 -0
  53. package/dist/path-zHxQUbqa.d.ts +9 -0
  54. package/dist/plugins-C8C0auoW.d.ts +10 -0
  55. package/dist/provider-9s4Ufkm5.js +1479 -0
  56. package/dist/providers/github/store.d.ts +3 -5
  57. package/dist/providers/github/store.js +1 -1
  58. package/dist/registry-B3BBm4Ts.d.ts +19 -0
  59. package/dist/{registry-D3yzt8HQ.js → registry-CNphafBx.js} +60 -23
  60. package/dist/registry-CYNN623b.d.ts +9 -0
  61. package/dist/request-scope-Dw5n8bMC.js +83 -0
  62. package/dist/results-DgkZUmTL.js +8 -0
  63. package/dist/{chunk-2rV9d50f.js → rolldown-runtime-rQ84J-ij.js} +3 -4
  64. package/dist/runtime/assets.d.ts +3 -5
  65. package/dist/runtime/assets.js +7 -6
  66. package/dist/runtime/empty-assets-registry.d.ts +1 -2
  67. package/dist/runtime/empty-registry.d.ts +2 -2
  68. package/dist/runtime/registry.d.ts +2 -0
  69. package/dist/runtime/registry.js +23 -0
  70. package/dist/runtime/request.d.ts +4 -0
  71. package/dist/runtime/request.js +8 -0
  72. package/dist/runtime/state.d.ts +5 -4
  73. package/dist/runtime/state.js +8 -18
  74. package/dist/runtime/workspace.d.ts +1 -1
  75. package/dist/runtime/workspace.js +1 -1
  76. package/dist/runtime.d.ts +52 -17
  77. package/dist/runtime.js +324 -67
  78. package/dist/{search-BpiCF2Tw.js → search-C_RfoM2j.js} +10 -9
  79. package/dist/server-8tGltlGz.js +303 -0
  80. package/dist/server.d.ts +36 -39
  81. package/dist/server.js +2 -328
  82. package/dist/shared-B3_EUk89.js +848 -0
  83. package/dist/source-metadata.d.ts +10 -7
  84. package/dist/source-metadata.js +12 -12
  85. package/dist/state-BISnUf1s.d.ts +35 -0
  86. package/dist/{ai-BqCC8BpY.js → state-DbrW-njQ.js} +237 -114
  87. package/dist/store-ybhyD38Z.js +1873 -0
  88. package/dist/{sync-DnTQwt8r.js → sync-CCD_VYC8.js} +61 -41
  89. package/dist/target-jWhTdIuF.js +89 -0
  90. package/dist/test.d.ts +1 -1
  91. package/dist/test.js +1 -1
  92. package/dist/{types-CYuwjJ4V.d.ts → types-BbtwmBZ5.d.ts} +321 -35
  93. package/dist/use-C6lV3-wC.d.ts +321 -0
  94. package/dist/{use-BTNDR5Rd.js → use-CSpT5W87.js} +141 -107
  95. package/dist/utils-CgMZCHsX.js +616 -0
  96. package/dist/vite.d.ts +585 -2
  97. package/dist/vite.js +21369 -2
  98. package/dist/workspace-CYB2xZ1T.d.ts +7 -0
  99. package/dist/{workspace-Dq08Yn72.js → workspace-sPWn2Jxj.js} +441 -225
  100. package/package.json +97 -72
  101. package/dist/ai-CjxvGqM0.d.ts +0 -162
  102. package/dist/ai.d.ts +0 -3
  103. package/dist/ai.js +0 -2
  104. package/dist/collections/client.d.ts +0 -39
  105. package/dist/collections/client.js +0 -137
  106. package/dist/collections.d.ts +0 -59
  107. package/dist/collections.js +0 -159
  108. package/dist/config-Bc3c4Su1.js +0 -7904
  109. package/dist/config-CHLLWklZ.js +0 -36
  110. package/dist/file-Bc1X7pco.js +0 -23
  111. package/dist/glob-CEZKeZFC.js +0 -18
  112. package/dist/hosted-vercel-blob-d6C8ND5j.js +0 -23580
  113. package/dist/lifecycle-LrL3sA4n.js +0 -316
  114. package/dist/metadata-target-B0tOmVW7.js +0 -717
  115. package/dist/mountx.d.ts +0 -10
  116. package/dist/mountx.js +0 -143
  117. package/dist/nitro.d.ts +0 -2
  118. package/dist/nitro.js +0 -2
  119. package/dist/nuxt.d.ts +0 -26
  120. package/dist/nuxt.js +0 -42
  121. package/dist/path-Cp59koVz.js +0 -139
  122. package/dist/provider-B1yLjCJJ.js +0 -746
  123. package/dist/publish.d.ts +0 -35
  124. package/dist/publish.js +0 -112
  125. package/dist/registry-Uj6IVxes.d.ts +0 -11
  126. package/dist/request-execution-B-dSFlGB.js +0 -84
  127. package/dist/runtime-options-BsPSv5O7.js +0 -13
  128. package/dist/runtime-type-iEE6BjQJ.js +0 -34
  129. package/dist/shared-DTR1Hhma.js +0 -331
  130. package/dist/state-tYcRWEh2.d.ts +0 -26
  131. package/dist/store-Dt_Jyys3.js +0 -608
  132. package/dist/target-D4Bqb1eH.js +0 -11
  133. package/dist/token-CVzURBxC.js +0 -61
  134. package/dist/use-BiHzt0xA.d.ts +0 -103
  135. package/dist/vite-BptCrpv2.js +0 -4526
  136. package/dist/vite-CtA9guIM.d.ts +0 -66
  137. package/dist/workspace-Xddf4G1B.d.ts +0 -6
@@ -0,0 +1,76 @@
1
+ import { createHash } from "node:crypto";
2
+ import { parse } from "yaml";
3
+ //#region src/lineage.ts
4
+ /** The digest that `derivedFrom.digest` holds: `sha256-` and the hex SHA-256 of the file bytes. */
5
+ function lineageDigest(bytes) {
6
+ return `sha256-${createHash("sha256").update(bytes).digest("hex")}`;
7
+ }
8
+ const frontmatter = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/;
9
+ const markdown = /* @__PURE__ */ new Set([
10
+ "markdown",
11
+ "md",
12
+ "mdx"
13
+ ]);
14
+ function derivedFrom(parsed) {
15
+ const value = Object(parsed) === parsed ? Reflect.get(Object(parsed), "derivedFrom") : void 0;
16
+ if (Object(value) !== value) return void 0;
17
+ const path = Reflect.get(Object(value), "path");
18
+ const digest = Reflect.get(Object(value), "digest");
19
+ return typeof path === "string" && path && typeof digest === "string" && digest ? {
20
+ digest,
21
+ path
22
+ } : void 0;
23
+ }
24
+ function parsed(parse, source) {
25
+ try {
26
+ return derivedFrom(parse(source));
27
+ } catch {
28
+ return;
29
+ }
30
+ }
31
+ /**
32
+ * Reads `derivedFrom` of a file: the YAML frontmatter of Markdown (`.md`, `.markdown`, `.mdx`),
33
+ * a YAML file (`.yaml`, `.yml`), or the top-level key of a JSON file (`.json`).
34
+ * Returns undefined for other files and for files without it.
35
+ */
36
+ function readDerivedFrom(path, bytes) {
37
+ const extension = path.slice(path.lastIndexOf(".") + 1).toLowerCase();
38
+ if (extension !== "json" && extension !== "yaml" && extension !== "yml" && !markdown.has(extension)) return void 0;
39
+ let text;
40
+ try {
41
+ text = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
42
+ } catch {
43
+ return;
44
+ }
45
+ if (extension === "json") return parsed(JSON.parse, text);
46
+ if (extension === "yaml" || extension === "yml") return parsed(parse, text);
47
+ const head = frontmatter.exec(text);
48
+ return head ? parsed(parse, head[1]) : void 0;
49
+ }
50
+ /** The derived files of a file set whose source changed or is gone, sorted by path. */
51
+ function staleDerivedFiles(files) {
52
+ const stale = [];
53
+ for (const [path, bytes] of files) {
54
+ const derivedFrom = readDerivedFrom(path, bytes);
55
+ if (!derivedFrom) continue;
56
+ const source = files.get(derivedFrom.path);
57
+ if (!source) {
58
+ stale.push({
59
+ derivedFrom,
60
+ path,
61
+ reason: "missing"
62
+ });
63
+ continue;
64
+ }
65
+ const sourceDigest = lineageDigest(source);
66
+ if (sourceDigest !== derivedFrom.digest) stale.push({
67
+ derivedFrom,
68
+ path,
69
+ reason: "changed",
70
+ sourceDigest
71
+ });
72
+ }
73
+ return stale.sort((left, right) => left.path < right.path ? -1 : 1);
74
+ }
75
+ //#endregion
76
+ export { lineageDigest, readDerivedFrom, staleDerivedFiles };
package/dist/loader.d.ts CHANGED
@@ -1,17 +1,16 @@
1
- import { M as WorkspaceContent, Ot as WorkspaceSourceItem, X as WorkspaceLoader } from "./types-CYuwjJ4V.js";
2
-
1
+ import { N as WorkspaceContent, Xt as WorkspaceSourceItem, ut as WorkspaceLoader } from "./types-BbtwmBZ5.js";
3
2
  //#region src/loaders/files.d.ts
4
3
  interface FilesLoaderOptions {
5
4
  include?: string | string[];
6
5
  exclude?: string | string[];
7
6
  transform?: (item: WorkspaceSourceItem) => WorkspaceContent | WorkspaceSourceItem | Promise<WorkspaceContent | WorkspaceSourceItem>;
8
7
  }
9
- declare function files(options?: FilesLoaderOptions): WorkspaceLoader;
8
+ export declare function files(options?: FilesLoaderOptions): WorkspaceLoader;
10
9
  //#endregion
11
10
  //#region src/loaders/json.d.ts
12
- declare function json(options?: FilesLoaderOptions): WorkspaceLoader;
11
+ export declare function json(options?: FilesLoaderOptions): WorkspaceLoader;
13
12
  //#endregion
14
13
  //#region src/loaders/text.d.ts
15
- declare function text(options?: FilesLoaderOptions): WorkspaceLoader;
14
+ export declare function text(options?: FilesLoaderOptions): WorkspaceLoader;
16
15
  //#endregion
17
- export { type FilesLoaderOptions, files, json, text };
16
+ export type { FilesLoaderOptions };
package/dist/loader.js CHANGED
@@ -1,11 +1,12 @@
1
- import { t as files } from "./files-Q6xZjDHA.js";
1
+ import { o as isWorkspaceBytes } from "./path--wrT_Azm.js";
2
+ import { t as files } from "./files-BOo4SbwE.js";
2
3
  //#region src/loaders/json.ts
3
4
  function json(options = {}) {
4
5
  return files({
5
6
  ...options,
6
7
  transform: async (item) => {
7
8
  const transformed = options.transform ? await options.transform(item) : item;
8
- if (typeof transformed === "string" || transformed instanceof Uint8Array) return transformed;
9
+ if (typeof transformed === "string" || isWorkspaceBytes(transformed)) return transformed;
9
10
  return {
10
11
  ...transformed,
11
12
  mediaType: transformed.mediaType || "application/json"
@@ -0,0 +1,39 @@
1
+ import { n as __exportAll } from "./rolldown-runtime-rQ84J-ij.js";
2
+ import { t as normalizeSafeWorkspacePath } from "./path-DrSIenjj.js";
3
+ import { b as markLiveWorkspaceSource, d as withWorkspaceRuntimeOptions, f as prepareWorkspaceSource, u as ownSourceOption } from "./config-BAgL2dtB.js";
4
+ import { mcpResources } from "@vite-hub/source/mcp";
5
+ //#region src/sources/mcp-resources.ts
6
+ var mcp_resources_exports = /* @__PURE__ */ __exportAll({ mcpResources: () => mcpResources$1 });
7
+ function mcpResources$1(options) {
8
+ const livePaths = {};
9
+ const baseSource = mcpResources({
10
+ ...options,
11
+ cache: ownSourceOption(options, "cache")
12
+ });
13
+ const source = withWorkspaceRuntimeOptions({
14
+ ...baseSource,
15
+ async prepare(ctx) {
16
+ await prepareWorkspaceSource(baseSource, ctx);
17
+ const mountPath = resolveMountPath(ownSourceOption(options, "mount"), ctx);
18
+ const keys = await baseSource.getKeys(ctx);
19
+ resetLivePaths(livePaths, mountPath, keys);
20
+ }
21
+ }, {
22
+ ...options,
23
+ materialize: ownSourceOption(options, "materialize") || (ownSourceOption(options, "sync") ? "none" : "lazy")
24
+ });
25
+ return markLiveWorkspaceSource(source, livePaths);
26
+ }
27
+ function resolveMountPath(mount, ctx) {
28
+ const explicit = typeof mount === "string" ? mount : mount && ownSourceOption(mount, "path");
29
+ return normalizeSafeWorkspacePath(explicit ?? ctx.mountPath ?? ctx.source ?? "", { allowEmpty: true });
30
+ }
31
+ function resetLivePaths(paths, mountPath, keys) {
32
+ for (const path of Object.keys(paths)) delete paths[path];
33
+ for (const key of keys) {
34
+ const path = normalizeSafeWorkspacePath(`${mountPath}/${key}`.replace(/\/+/g, "/"), { allowEmpty: false });
35
+ paths[path] = key;
36
+ }
37
+ }
38
+ //#endregion
39
+ export { mcp_resources_exports as n, mcpResources$1 as t };
@@ -0,0 +1,247 @@
1
+ import { n as assertWorkspaceDigest, o as workspaceConflictError, s as workspaceError } from "./path-DrSIenjj.js";
2
+ import { o as copyJsonFileMetadata, r as workspaceStoreTarget } from "./target-jWhTdIuF.js";
3
+ import { a as isExcludedWorkspacePath, f as sha256, l as normalizeWorkspacePath, o as isWorkspaceBytes } from "./path--wrT_Azm.js";
4
+ import { t as createWorkspaceGlobMatcher } from "./glob-Cjxms1t7.js";
5
+ //#region ../internal/src/owned-paths.ts
6
+ /** Every Blob path that ViteHub writes for itself starts with this prefix. */
7
+ const vitehubOwnedPrefix = "_vitehub/";
8
+ //#endregion
9
+ //#region src/storage/memory.ts
10
+ function now() {
11
+ return Date.now();
12
+ }
13
+ var MemoryWorkspaceStore = class MemoryWorkspaceStore {
14
+ [workspaceStoreTarget]() {
15
+ return { provider: "memory" };
16
+ }
17
+ #nodes = /* @__PURE__ */ new Map([["", {
18
+ type: "directory",
19
+ mtime: now()
20
+ }]]);
21
+ #meta = /* @__PURE__ */ new Map();
22
+ #baseline;
23
+ #mutationQueue = Promise.resolve();
24
+ fork() {
25
+ const fork = new MemoryWorkspaceStore();
26
+ fork.#nodes = structuredClone(this.#nodes);
27
+ fork.#meta = structuredClone(this.#meta);
28
+ fork.#baseline = structuredClone(this.#baseline);
29
+ return fork;
30
+ }
31
+ async readFile(path) {
32
+ const normalized = normalizeWorkspacePath(path);
33
+ const node = this.#nodes.get(normalized);
34
+ if (!node || node.type !== "file") return void 0;
35
+ return {
36
+ path: normalized,
37
+ content: isWorkspaceBytes(node.content) ? new Uint8Array(node.content) : node.content || "",
38
+ mediaType: node.mediaType,
39
+ metadata: structuredClone(node.metadata)
40
+ };
41
+ }
42
+ async writeFile(path, file) {
43
+ await this.#mutate(() => this.#writeFile(path, file));
44
+ }
45
+ async writeFileConditional(path, file, ifDigest) {
46
+ await this.#mutate(async () => {
47
+ const normalized = normalizeWorkspacePath(path);
48
+ const current = this.#nodes.get(normalized);
49
+ assertWorkspaceDigest(normalized, ifDigest, current?.type === "file" ? (await this.#entry(normalized, current)).digest : void 0);
50
+ this.#writeFile(normalized, file);
51
+ });
52
+ }
53
+ async list(prefix = "", options = {}) {
54
+ const normalizedPrefix = normalizeWorkspacePath(prefix);
55
+ const result = [];
56
+ for (const [path, node] of this.#nodes) {
57
+ if (!path || path === normalizedPrefix) continue;
58
+ if (isExcludedWorkspacePath(path, options.exclude)) continue;
59
+ if (normalizedPrefix && !path.startsWith(`${normalizedPrefix}/`)) continue;
60
+ if (!options.recursive && normalizeWorkspacePath(path.slice(normalizedPrefix.length)).replace(/^\//, "").includes("/")) continue;
61
+ result.push(await this.#entry(path, node));
62
+ }
63
+ return result.sort((a, b) => a.path.localeCompare(b.path));
64
+ }
65
+ async glob(pattern, options = {}) {
66
+ const { cwd, matches } = createWorkspaceGlobMatcher(pattern, options);
67
+ return (await this.list(cwd, { recursive: true })).filter((entry) => entry.type === "file" && matches(entry.path));
68
+ }
69
+ async stat(path) {
70
+ const normalized = normalizeWorkspacePath(path);
71
+ const node = this.#nodes.get(normalized);
72
+ return node ? {
73
+ ...await this.#entry(normalized, node),
74
+ revision: node.revision
75
+ } : void 0;
76
+ }
77
+ async mkdir(path, _options = {}) {
78
+ await this.#mutate(() => {
79
+ const normalized = normalizeWorkspacePath(path);
80
+ const existing = this.#nodes.get(normalized);
81
+ const recursive = _options.recursive ?? true;
82
+ if (existing) {
83
+ if (!recursive || existing.type === "file") throw workspaceError(`[vitehub] Workspace path already exists: ${path}.`);
84
+ return;
85
+ }
86
+ if (recursive) this.#ensureParents(normalized);
87
+ else {
88
+ const separator = normalized.lastIndexOf("/");
89
+ const parent = separator === -1 ? "" : normalized.slice(0, separator);
90
+ if (parent && this.#nodes.get(parent)?.type !== "directory") throw workspaceError(`[vitehub] Workspace parent does not exist: ${path}.`);
91
+ }
92
+ this.#nodes.set(normalized, {
93
+ type: "directory",
94
+ mtime: now()
95
+ });
96
+ });
97
+ }
98
+ async rm(path, options = {}) {
99
+ await this.#mutate(async () => {
100
+ const normalized = normalizeWorkspacePath(path);
101
+ const node = this.#nodes.get(normalized);
102
+ if (options.ifDigest !== void 0) {
103
+ const actual = node?.type === "file" ? (await this.#entry(normalized, node)).digest : void 0;
104
+ if (options.ifDigest === null ? node !== void 0 : actual !== options.ifDigest) throw workspaceConflictError(path, options.ifDigest, actual);
105
+ }
106
+ if (!node) {
107
+ if (options.force) return;
108
+ throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
109
+ }
110
+ if (node.type === "directory" && !options.recursive) {
111
+ for (const key of this.#nodes.keys()) if (key.startsWith(`${normalized}/`)) throw workspaceError(`[vitehub] Workspace directory is not empty: ${path}.`);
112
+ }
113
+ for (const key of this.#nodes.keys()) if (key === normalized || key.startsWith(`${normalized}/`)) this.#nodes.delete(key);
114
+ });
115
+ }
116
+ async removeEmptyDirectory(path) {
117
+ await this.#mutate(() => {
118
+ const normalized = normalizeWorkspacePath(path);
119
+ if (!normalized) return;
120
+ if (this.#nodes.get(normalized)?.type !== "directory") return;
121
+ for (const key of this.#nodes.keys()) if (key.startsWith(`${normalized}/`)) throw workspaceError(`[vitehub] Workspace directory is not empty: ${path}.`);
122
+ this.#nodes.delete(normalized);
123
+ });
124
+ }
125
+ async snapshot(options = {}) {
126
+ const snapshot = await this.#createSnapshot(options.name);
127
+ this.#baseline = snapshot;
128
+ return snapshot;
129
+ }
130
+ async diff(options = {}) {
131
+ const from = options.from || this.#baseline;
132
+ const to = await this.#createSnapshot();
133
+ const entries = [];
134
+ const keys = /* @__PURE__ */ new Set([...Object.keys(from?.entries || {}), ...Object.keys(to.entries)]);
135
+ for (const path of [...keys].sort()) {
136
+ const before = from && Object.hasOwn(from.entries, path) ? from.entries[path] : void 0;
137
+ const after = Object.hasOwn(to.entries, path) ? to.entries[path] : void 0;
138
+ if (!before && after) entries.push({
139
+ path,
140
+ type: "added",
141
+ after
142
+ });
143
+ else if (before && !after) entries.push({
144
+ path,
145
+ type: "removed",
146
+ before
147
+ });
148
+ 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({
149
+ path,
150
+ type: "modified",
151
+ before,
152
+ after
153
+ });
154
+ }
155
+ return {
156
+ from: from?.id,
157
+ to: to.id,
158
+ entries
159
+ };
160
+ }
161
+ async getMeta(key) {
162
+ return this.#meta.get(key);
163
+ }
164
+ async setMeta(key, value) {
165
+ this.#meta.set(key, value);
166
+ }
167
+ #writeFile(path, file) {
168
+ file = {
169
+ ...file,
170
+ metadata: copyJsonFileMetadata(path, file.metadata)
171
+ };
172
+ const normalized = normalizeWorkspacePath(path);
173
+ if (this.#nodes.get(normalized)?.type === "directory") throw workspaceError(`[vitehub] Cannot write a file over directory: ${normalized}.`);
174
+ this.#ensureParents(normalized);
175
+ this.#nodes.set(normalized, {
176
+ type: "file",
177
+ content: isWorkspaceBytes(file.content) ? new Uint8Array(file.content) : file.content,
178
+ revision: crypto.randomUUID(),
179
+ mediaType: file.mediaType,
180
+ metadata: structuredClone(file.metadata),
181
+ mtime: now()
182
+ });
183
+ }
184
+ #mutate(operation) {
185
+ const result = this.#mutationQueue.then(operation);
186
+ this.#mutationQueue = result.then(() => void 0, () => void 0);
187
+ return result;
188
+ }
189
+ #ensureParents(path) {
190
+ const parts = normalizeWorkspacePath(path).split("/").filter(Boolean);
191
+ for (let index = 1; index < parts.length; index++) {
192
+ const dir = parts.slice(0, index).join("/");
193
+ const node = this.#nodes.get(dir);
194
+ if (node?.type === "file") throw workspaceError(`[vitehub] Workspace parent is not a directory: ${path}.`);
195
+ if (!node) this.#nodes.set(dir, {
196
+ type: "directory",
197
+ mtime: now()
198
+ });
199
+ }
200
+ }
201
+ async #entry(path, node) {
202
+ const content = node.content || "";
203
+ const size = node.type === "file" ? typeof content === "string" ? new TextEncoder().encode(content).byteLength : content.byteLength : void 0;
204
+ return {
205
+ path,
206
+ type: node.type,
207
+ size,
208
+ mtime: node.mtime,
209
+ mediaType: node.mediaType,
210
+ metadata: structuredClone(node.metadata),
211
+ digest: node.type === "file" ? node.digest ??= await sha256(content) : void 0
212
+ };
213
+ }
214
+ async #createSnapshot(name) {
215
+ const entries = Object.create(null);
216
+ for (const [path, node] of this.#nodes) {
217
+ if (!path) continue;
218
+ const entry = await this.#entry(path, node);
219
+ entries[path] = {
220
+ type: entry.type,
221
+ digest: entry.digest,
222
+ metadata: entry.metadata,
223
+ size: entry.size
224
+ };
225
+ }
226
+ return {
227
+ id: await sha256({
228
+ name,
229
+ entries,
230
+ createdAt: Date.now()
231
+ }),
232
+ name,
233
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
234
+ entries
235
+ };
236
+ }
237
+ };
238
+ function createMemoryWorkspaceStore() {
239
+ return new MemoryWorkspaceStore();
240
+ }
241
+ /** Internal copy for Store adapters that publish draft mutations only after validation. */
242
+ function forkMemoryWorkspaceStore(store) {
243
+ if (!(store instanceof MemoryWorkspaceStore)) throw workspaceError("[vitehub] Only memory Workspace Stores can be forked.");
244
+ return store.fork();
245
+ }
246
+ //#endregion
247
+ export { forkMemoryWorkspaceStore as n, vitehubOwnedPrefix as r, createMemoryWorkspaceStore as t };