@vite-hub/workspace 0.1.0 → 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 (134) hide show
  1. package/README.md +164 -107
  2. package/dist/abort-BCwpdrN0.js +32 -0
  3. package/dist/blob-database.d.ts +70 -117
  4. package/dist/blob-database.js +48 -41
  5. package/dist/checkout.d.ts +128 -0
  6. package/dist/checkout.js +849 -0
  7. package/dist/cloudflare.d.ts +2 -2
  8. package/dist/cloudflare.js +1 -1
  9. package/dist/config-B-863EgC.js +15 -0
  10. package/dist/{config-B7dmzDX3.js → config-BAgL2dtB.js} +48 -84
  11. package/dist/{config-DLKdaFWN.d.ts → config-BQKcPawI.d.ts} +1 -1
  12. package/dist/discard-CNNtCozM.js +8 -0
  13. package/dist/durability.d.ts +22 -0
  14. package/dist/durability.js +70 -0
  15. package/dist/error-diagnostics-CtKjGtGb.js +188 -0
  16. package/dist/error-diagnostics-DSkCJC_L.js +266 -0
  17. package/dist/file-2pFYNtsU.js +22 -0
  18. package/dist/{files-C7Px8uaC.js → files-BOo4SbwE.js} +2 -2
  19. package/dist/files.d.ts +38 -0
  20. package/dist/files.js +6 -0
  21. package/dist/{github-CPxHtFB7.js → github-CrYp4v8k.js} +32 -5
  22. package/dist/{glob--XcLlcml.js → glob-B8YGvTrZ.js} +4 -5
  23. package/dist/{glob--kNYDbfU.js → glob-Cjxms1t7.js} +1 -1
  24. package/dist/{host-CFnrTXTK.js → host-BFBpXn0N.js} +58 -47
  25. package/dist/{hosted-acMA5XyL.js → hosted-KcUR_jPv.js} +216 -93
  26. package/dist/hosted-vercel-blob-B3-wRdUm.js +410 -0
  27. package/dist/hosted-vercel-blob.d.ts +2 -2
  28. package/dist/hosted-vercel-blob.js +1 -1
  29. package/dist/hosted.d.ts +5 -3
  30. package/dist/hosted.js +2 -2
  31. package/dist/index.d.ts +9 -51
  32. package/dist/index.js +21 -91
  33. package/dist/{lifecycle-BwZ7c9hb.js → lifecycle-B-enk_4A.js} +8 -8
  34. package/dist/lineage.d.ts +26 -0
  35. package/dist/lineage.js +76 -0
  36. package/dist/loader.d.ts +1 -1
  37. package/dist/loader.js +2 -2
  38. package/dist/{mcp-resources-BREFCmtn.js → mcp-resources-DF0F5rcL.js} +2 -2
  39. package/dist/{memory-BbwOqDXl.js → memory-BOexthyW.js} +3 -4
  40. package/dist/{metadata-target-DZEZQGHA.js → metadata-target-CWz6KHKq.js} +17 -16
  41. package/dist/object-Da1zyPCR.js +11 -0
  42. package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
  43. package/dist/operations-C6FpR8Rr.js +389 -0
  44. package/dist/operations-CE2drFih.js +1234 -0
  45. package/dist/operations.d.ts +41 -4
  46. package/dist/operations.js +3 -2
  47. package/dist/{path-CNAwN7pw.js → path--wrT_Azm.js} +2 -3
  48. package/dist/path-AxMho1wo.d.ts +7 -0
  49. package/dist/{plugins-DqQ8b4T5.d.ts → plugins-C8C0auoW.d.ts} +1 -1
  50. package/dist/{provider-kXjfli9u.js → provider-9s4Ufkm5.js} +104 -82
  51. package/dist/providers/github/store.d.ts +1 -1
  52. package/dist/providers/github/store.js +1 -1
  53. package/dist/registry-B3BBm4Ts.d.ts +19 -0
  54. package/dist/{registry-Bp-8UUfG.js → registry-CNphafBx.js} +55 -20
  55. package/dist/registry-CYNN623b.d.ts +9 -0
  56. package/dist/request-scope-Dw5n8bMC.js +83 -0
  57. package/dist/results-DgkZUmTL.js +8 -0
  58. package/dist/{rolldown-runtime-B4iAMlE-.js → rolldown-runtime-rQ84J-ij.js} +2 -3
  59. package/dist/runtime/assets.d.ts +1 -1
  60. package/dist/runtime/assets.js +3 -3
  61. package/dist/runtime/empty-assets-registry.d.ts +1 -1
  62. package/dist/runtime/empty-registry.d.ts +2 -1
  63. package/dist/runtime/registry.d.ts +2 -0
  64. package/dist/runtime/registry.js +23 -0
  65. package/dist/runtime/request.d.ts +4 -0
  66. package/dist/runtime/request.js +8 -0
  67. package/dist/runtime/state.d.ts +5 -4
  68. package/dist/runtime/state.js +8 -18
  69. package/dist/runtime/workspace.d.ts +1 -1
  70. package/dist/runtime/workspace.js +1 -1
  71. package/dist/runtime.d.ts +9 -8
  72. package/dist/runtime.js +23 -26
  73. package/dist/{search-CrTmXj5h.js → search-C_RfoM2j.js} +2 -2
  74. package/dist/{server-BNQ-Nbjj.js → server-8tGltlGz.js} +53 -40
  75. package/dist/server.d.ts +17 -8
  76. package/dist/server.js +1 -1
  77. package/dist/shared-B3_EUk89.js +848 -0
  78. package/dist/source-metadata.d.ts +6 -2
  79. package/dist/source-metadata.js +8 -8
  80. package/dist/state-BISnUf1s.d.ts +35 -0
  81. package/dist/{ai-BZyLwULx.js → state-DbrW-njQ.js} +96 -54
  82. package/dist/{store-CXgmu-uw.js → store-ybhyD38Z.js} +250 -106
  83. package/dist/{sync-CN6ec-5M.js → sync-CCD_VYC8.js} +4 -4
  84. package/dist/target-jWhTdIuF.js +89 -0
  85. package/dist/test.d.ts +1 -1
  86. package/dist/test.js +1 -1
  87. package/dist/{types-DeK9GIxy.d.ts → types-BbtwmBZ5.d.ts} +68 -14
  88. package/dist/use-C6lV3-wC.d.ts +321 -0
  89. package/dist/{use-BQj7nSz6.js → use-CSpT5W87.js} +75 -82
  90. package/dist/{utils-Blrh4N2n.js → utils-CgMZCHsX.js} +112 -41
  91. package/dist/vite.d.ts +585 -2
  92. package/dist/vite.js +21368 -1
  93. package/dist/{workspace-BWJQBK1u.d.ts → workspace-CYB2xZ1T.d.ts} +1 -1
  94. package/dist/{workspace-6pxkOuxr.js → workspace-sPWn2Jxj.js} +125 -40
  95. package/package.json +46 -55
  96. package/dist/ai-BW2ZhizI.d.ts +0 -177
  97. package/dist/ai.d.ts +0 -3
  98. package/dist/ai.js +0 -2
  99. package/dist/association-Cm0dUTDU-CDDhJnIh-Cv3bWnVb.js +0 -19
  100. package/dist/error-diagnostics-A_8Kp-48.js +0 -116
  101. package/dist/error-diagnostics-DY5GP47p.js +0 -96
  102. package/dist/events-7EBoeIPd-A2RUkJi5-BxrICQ17.js +0 -354
  103. package/dist/events-CRaLy7U3-3PNNp5WZ-Gv9nd0cH.js +0 -214
  104. package/dist/events-CeChclTf-CX-gD8oy-4aL2j6V-.js +0 -527
  105. package/dist/feed-DsC7Vws1-M_de2nSK-tKc0Pwo8.js +0 -248
  106. package/dist/feed-Dyf730Ys-D0HgBba6-BUnCa5gS.js +0 -179
  107. package/dist/file-C0_aPWSS.js +0 -26
  108. package/dist/file-metadata-CxDy-E2H.js +0 -58
  109. package/dist/forgejo-BN8ItCfl-Bbn4vhDd.js +0 -2278
  110. package/dist/github-DtncTfmv-Du2S8lGF.js +0 -4159
  111. package/dist/gitlab-BoDm8-BC-xzZsW9eW.js +0 -2530
  112. package/dist/graphql-DG5aJBT3-DceyFYdM-C4saqX37.js +0 -489
  113. package/dist/hosted-vercel-blob-DKntsHaf.js +0 -12603
  114. package/dist/inspect-BoObD2cJ.js +0 -167
  115. package/dist/mountx.d.ts +0 -8
  116. package/dist/mountx.js +0 -145
  117. package/dist/nitro.d.ts +0 -2
  118. package/dist/nitro.js +0 -2
  119. package/dist/nuxt.d.ts +0 -27
  120. package/dist/nuxt.js +0 -38
  121. package/dist/operations-BcpWr41m.js +0 -159
  122. package/dist/operations-CGqY1XeG.js +0 -965
  123. package/dist/operations-DnOwKsJT.d.ts +0 -136
  124. package/dist/registry-Cg1TJVVZ.d.ts +0 -10
  125. package/dist/request-execution-Dk9rY-Yh.js +0 -84
  126. package/dist/shared-DalXdP0i.js +0 -2158
  127. package/dist/state-B8zbLi5t.d.ts +0 -26
  128. package/dist/target-D4Bqb1eH.js +0 -11
  129. package/dist/templates-Bn8a-pd2-D9DhJEVD-CBfXNRzz.js +0 -125
  130. package/dist/token-CO62GglH.js +0 -61
  131. package/dist/use-DhwhbAVV.d.ts +0 -108
  132. package/dist/vite-BEvgU2GY.js +0 -20909
  133. package/dist/vite-CcZmMQ7S.d.ts +0 -476
  134. package/dist/webhooks-DgHwxxYz-D1V2LOr1-azofFOiP.js +0 -1565
package/dist/index.js CHANGED
@@ -1,22 +1,19 @@
1
- import { n as __exportAll } from "./rolldown-runtime-B4iAMlE-.js";
1
+ import { n as __exportAll } from "./rolldown-runtime-rQ84J-ij.js";
2
2
  import { r as isWorkspaceConflict, s as workspaceError, t as normalizeSafeWorkspacePath } from "./path-DrSIenjj.js";
3
- import { n as resolveWorkspaceStoreTarget } from "./target-D4Bqb1eH.js";
4
- import { t as createWorkspaceTools } from "./ai-BZyLwULx.js";
5
- import { d as withWorkspaceRuntimeOptions, m as fetch, u as ownSourceOption } from "./config-B7dmzDX3.js";
6
- import { t as workspaceErrorDiagnostics } from "./error-diagnostics-DY5GP47p.js";
7
- import { g as registerWorkspacePlugin, h as resolveWorkspaceAutoCommit } from "./utils-Blrh4N2n.js";
8
- import { t as createWorkspace } from "./workspace-6pxkOuxr.js";
9
- import { t as file } from "./file-C0_aPWSS.js";
10
- import { t as github } from "./github-CPxHtFB7.js";
11
- import { t as glob } from "./glob--XcLlcml.js";
12
- import { t as mcpResources } from "./mcp-resources-BREFCmtn.js";
13
- import { r as resolveRegisteredWorkspaceDefinition } from "./registry-Bp-8UUfG.js";
14
- import { t as useWorkspace } from "./use-BQj7nSz6.js";
15
- import { invalidateWorkspaceStore } from "./runtime/state.js";
16
- import { hasRuntimeType } from "@vite-hub/runtime/internal/runtime-type";
17
- import { array, sourceIgnores } from "@vite-hub/source";
3
+ import { i as assertWorkspaceRules, n as resolveWorkspaceStoreTarget } from "./target-jWhTdIuF.js";
4
+ import { t as workspaceErrorDiagnostics } from "./error-diagnostics-CtKjGtGb.js";
5
+ import { g as registerWorkspacePlugin, h as resolveWorkspaceAutoCommit } from "./utils-CgMZCHsX.js";
6
+ import { t as createWorkspace } from "./workspace-sPWn2Jxj.js";
7
+ import { m as fetch } from "./config-BAgL2dtB.js";
8
+ import { r as resolveRegisteredWorkspaceDefinition } from "./registry-CNphafBx.js";
9
+ import { r as useWorkspaceFiles } from "./use-CSpT5W87.js";
10
+ import { r as withFileSourceOptions, t as file } from "./file-2pFYNtsU.js";
11
+ import { t as github } from "./github-CrYp4v8k.js";
12
+ import { t as glob } from "./glob-B8YGvTrZ.js";
13
+ import { t as mcpResources } from "./mcp-resources-DF0F5rcL.js";
14
+ import { a as createWorkspaceTools, i as useWorkspace, t as invalidateWorkspaceStore } from "./state-DbrW-njQ.js";
18
15
  import { lookup } from "mrmime";
19
- import { markdown as markdown$1 } from "@vite-hub/source/markdown";
16
+ import { markdown as markdown$1, sourceIgnores } from "@vite-hub/source";
20
17
  //#region src/core/define.ts
21
18
  const workspaceDefinitionKeys = /* @__PURE__ */ new Set([
22
19
  "bindings",
@@ -39,6 +36,8 @@ function defineWorkspace(definition) {
39
36
  if (!definition || typeof definition !== "object") throw workspaceErrorDiagnostics.WORKSPACE_R0016({ message: "[vitehub] defineWorkspace requires a workspace definition." });
40
37
  if ("name" in definition) throw workspaceErrorDiagnostics.WORKSPACE_R0017({ message: "[vitehub] Workspace names are inferred from definition filenames." });
41
38
  assertWorkspaceDefinitionKeys(definition);
39
+ assertWorkspaceRules(definition.rules);
40
+ for (const plugin of definition.plugins ?? []) assertWorkspaceRules(plugin?.rules);
42
41
  return definition;
43
42
  }
44
43
  //#endregion
@@ -71,13 +70,7 @@ function custom(source) {
71
70
  //#endregion
72
71
  //#region src/sources/markdown.ts
73
72
  function markdown(options) {
74
- const workspacePath = Object.hasOwn(options, "workspacePath") && options.workspacePath ? options.workspacePath : Object.hasOwn(options, "path") && options.path ? options.path : "";
75
- const key = normalizeSafeWorkspacePath(workspacePath);
76
- const source = markdown$1(options);
77
- return {
78
- ...withWorkspaceRuntimeOptions(source, options),
79
- probeKeys: ownSourceOption(options, "probeKeys") || [key]
80
- };
73
+ return withFileSourceOptions(markdown$1(options), options);
81
74
  }
82
75
  //#endregion
83
76
  //#region src/sources/index.ts
@@ -90,33 +83,6 @@ var sources_exports = /* @__PURE__ */ __exportAll({
90
83
  markdown: () => markdown,
91
84
  mcpResources: () => mcpResources
92
85
  });
93
- //#endregion
94
- //#region src/collection.ts
95
- async function openWorkspace(input) {
96
- if (hasRuntimeType(input, "function")) return await input();
97
- if (hasRuntimeType(input, "string")) return useWorkspace(input);
98
- return input;
99
- }
100
- function workspaceFile(options) {
101
- const { path, schema, workspace: input, ...query } = options;
102
- const load = async ({ signal }) => {
103
- const workspace = await openWorkspace(input);
104
- const stat = await workspace.fs.stat(path);
105
- if (stat.type !== "file") throw workspaceErrorDiagnostics.WORKSPACE_R0010({ path });
106
- const raw = await workspace.fs.readFile(path, { encoding: "utf8" });
107
- signal?.throwIfAborted();
108
- const items = JSON.parse(raw);
109
- if (!Array.isArray(items)) throw workspaceErrorDiagnostics.WORKSPACE_R0011({ path });
110
- return {
111
- digest: stat.digest || void 0,
112
- items
113
- };
114
- };
115
- return schema ? array(load, {
116
- ...query,
117
- schema
118
- }) : array(load, query);
119
- }
120
86
  const modelWorkspaceGlobPatternLimits = Object.freeze({
121
87
  maxBytes: 2048,
122
88
  maxComplexity: 1024,
@@ -140,40 +106,8 @@ function boundedUtf8Bytes(value, limit) {
140
106
  }
141
107
  return bytes;
142
108
  }
143
- function findClosingBrace(pattern, opening) {
144
- let depth = 0;
145
- for (let index = opening; index < pattern.length; index++) {
146
- if (pattern[index] === "\\") {
147
- index++;
148
- continue;
149
- }
150
- if (pattern[index] === "{") depth++;
151
- else if (pattern[index] === "}" && --depth === 0) return index;
152
- }
153
- return -1;
154
- }
155
- function splitBraceParts(content, separator) {
156
- const parts = [];
157
- let depth = 0;
158
- let start = 0;
159
- for (let index = 0; index < content.length; index++) {
160
- if (content[index] === "\\") {
161
- index++;
162
- continue;
163
- }
164
- if (content[index] === "{") depth++;
165
- else if (content[index] === "}") depth--;
166
- else if (depth === 0 && content.startsWith(separator, index)) {
167
- parts.push(content.slice(start, index));
168
- index += separator.length - 1;
169
- start = index + 1;
170
- }
171
- }
172
- parts.push(content.slice(start));
173
- return parts;
174
- }
175
109
  function sequenceComplexity(content, limit) {
176
- const parts = splitBraceParts(content, "..");
110
+ const parts = content.split("..");
177
111
  if (parts.length < 2 || parts.length > 3) return void 0;
178
112
  const [rawStart, rawEnd, rawStep] = parts;
179
113
  const numeric = /^-?\d+$/;
@@ -193,18 +127,14 @@ function sequenceComplexity(content, limit) {
193
127
  function patternComplexity(pattern, limit) {
194
128
  let complexity = 1;
195
129
  for (let index = 0; index < pattern.length; index++) {
196
- if (pattern[index] === "\\") {
197
- index++;
198
- continue;
199
- }
200
130
  if (pattern[index] === "}") return limit + 1;
201
131
  if (pattern[index] !== "{") continue;
202
- const closing = findClosingBrace(pattern, index);
132
+ const closing = pattern.indexOf("}", index + 1);
203
133
  if (closing === -1) return limit + 1;
204
134
  const content = pattern.slice(index + 1, closing);
205
135
  if (!content) return limit + 1;
206
136
  if (content.includes("{") || content.includes("}")) return limit + 1;
207
- const alternatives = splitBraceParts(content, ",");
137
+ const alternatives = content.split(",");
208
138
  let braceComplexity;
209
139
  if (alternatives.length > 1) {
210
140
  braceComplexity = 0;
@@ -236,4 +166,4 @@ function assertModelWorkspaceGlobPattern(pattern, limits = modelWorkspaceGlobPat
236
166
  }
237
167
  }
238
168
  //#endregion
239
- export { assertModelWorkspaceGlobPattern, createWorkspace, createWorkspaceTools, custom, defineWorkspace, fetch, file, github, glob, invalidateWorkspaceStore, isWorkspaceConflict, markdown, mcpResources, modelWorkspaceGlobPatternLimits, normalizeSafeWorkspacePath, registerWorkspacePlugin, resolveRegisteredWorkspaceDefinition, resolveWorkspaceAutoCommit, resolveWorkspaceStoreTarget, sources_exports as source, sourceIgnores, useWorkspace, workspaceFile };
169
+ export { assertModelWorkspaceGlobPattern, createWorkspace, createWorkspaceTools, custom, defineWorkspace, fetch, file, github, glob, invalidateWorkspaceStore, isWorkspaceConflict, markdown, mcpResources, modelWorkspaceGlobPatternLimits, normalizeSafeWorkspacePath, registerWorkspacePlugin, resolveRegisteredWorkspaceDefinition, resolveWorkspaceAutoCommit, resolveWorkspaceStoreTarget, sources_exports as source, sourceIgnores, useWorkspace, useWorkspaceFiles };
@@ -1,13 +1,13 @@
1
- import { n as __exportAll } from "./rolldown-runtime-B4iAMlE-.js";
1
+ import { n as __exportAll } from "./rolldown-runtime-rQ84J-ij.js";
2
2
  import { s as workspaceError } from "./path-DrSIenjj.js";
3
- import { f as sha256, l as normalizeWorkspacePath, t as contentStreamChunks } from "./path-CNAwN7pw.js";
4
- import { a as normalizeWorkspaceSources, c as sourceMountIntersectsPath, f as prepareWorkspaceSource, n as createSourceContext } from "./config-B7dmzDX3.js";
5
- import { s as invalidateWorkspaceSourceMaterialization } from "./workspace-6pxkOuxr.js";
6
- import { A as removeWorkspaceOwnedFile, C as withWorkspaceStoreMutation, D as readWorkspaceFileOwner, M as registerWorkspaceStoreAlias, N as workspaceStoreIdentity, O as recordWorkspaceFileOwner, _ as reconcileRemovedStartupSources, d as invalidateSourceSnapshot, j as withWorkspaceFileCheckpoint, k as removeWorkspaceFileOwner, m as readCurrentSourceSnapshot, y as sourceSnapshotOwnsAnyPath } from "./metadata-target-DZEZQGHA.js";
3
+ import { f as sha256, l as normalizeWorkspacePath, t as contentStreamChunks } from "./path--wrT_Azm.js";
4
+ import { s as invalidateWorkspaceSourceMaterialization } from "./workspace-sPWn2Jxj.js";
5
+ import { a as normalizeWorkspaceSources, c as sourceMountIntersectsPath, f as prepareWorkspaceSource, n as createSourceContext } from "./config-BAgL2dtB.js";
6
+ import { A as removeWorkspaceOwnedFile, C as withWorkspaceStoreMutation, D as readWorkspaceFileOwner, M as registerWorkspaceStoreAlias, N as workspaceStoreIdentity, O as recordWorkspaceFileOwner, _ as reconcileRemovedStartupSources, d as invalidateSourceSnapshot, j as withWorkspaceFileCheckpoint, k as removeWorkspaceFileOwner, m as readCurrentSourceSnapshot, y as sourceSnapshotOwnsAnyPath } from "./metadata-target-CWz6KHKq.js";
7
7
  import { n as useWorkspaceAssets } from "./asset-registry-DfBV5kmw.js";
8
- import { t as files } from "./files-C7Px8uaC.js";
9
- import { createHash } from "node:crypto";
8
+ import { t as files } from "./files-BOo4SbwE.js";
10
9
  import { getViteHubErrorShape } from "@vite-hub/runtime";
10
+ import { createHash } from "node:crypto";
11
11
  //#region src/lifecycle.ts
12
12
  var lifecycle_exports = /* @__PURE__ */ __exportAll({ syncWorkspaceDefinition: () => syncWorkspaceDefinition });
13
13
  const buildSourcesMetaKey = (workspace) => `workspace:${encodeURIComponent(workspace)}:build-sources`;
@@ -466,7 +466,7 @@ async function syncRuntimeBuildAssets(definition, store, currentSources, abortSi
466
466
  return bundledBuildSources;
467
467
  }
468
468
  async function hasCompleteBundledBuildSource(definition, store, source, bundledPaths, bundledFiles, bundledSourceByPath, abortSignal) {
469
- const probeKeys = source.source.probeKeys;
469
+ const probeKeys = source.probeKeys;
470
470
  if (!probeKeys?.length) {
471
471
  const paths = bundledFiles?.filter((file) => file.metadata?.source === source.key).map((file) => file.path) ?? [];
472
472
  const sourcePaths = await tryListBuildSourcePaths(definition, store, source, abortSignal);
@@ -0,0 +1,26 @@
1
+ //#region src/lineage.d.ts
2
+ /** Where a derived file, such as a translation, came from: a Workspace path and the SHA-256 of its bytes then. */
3
+ export interface WorkspaceDerivedFrom {
4
+ path: string;
5
+ digest: string;
6
+ }
7
+ /** A derived file whose source changed or is gone since it was made. */
8
+ export interface WorkspaceStaleFile {
9
+ path: string;
10
+ derivedFrom: WorkspaceDerivedFrom;
11
+ /** `changed`: the source has other bytes now. `missing`: the source is gone. */
12
+ reason: "changed" | "missing";
13
+ /** The digest of the source now. Write it as `derivedFrom.digest` after you update the file. */
14
+ sourceDigest?: string;
15
+ }
16
+ /** The digest that `derivedFrom.digest` holds: `sha256-` and the hex SHA-256 of the file bytes. */
17
+ export declare function lineageDigest(bytes: Uint8Array): string;
18
+ /**
19
+ * Reads `derivedFrom` of a file: the YAML frontmatter of Markdown (`.md`, `.markdown`, `.mdx`),
20
+ * a YAML file (`.yaml`, `.yml`), or the top-level key of a JSON file (`.json`).
21
+ * Returns undefined for other files and for files without it.
22
+ */
23
+ export declare function readDerivedFrom(path: string, bytes: Uint8Array): WorkspaceDerivedFrom | undefined;
24
+ /** The derived files of a file set whose source changed or is gone, sorted by path. */
25
+ export declare function staleDerivedFiles(files: ReadonlyMap<string, Uint8Array>): WorkspaceStaleFile[];
26
+ //#endregion
@@ -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,4 +1,4 @@
1
- import { M as WorkspaceContent, Yt as WorkspaceSourceItem, lt as WorkspaceLoader } from "./types-DeK9GIxy.js";
1
+ import { N as WorkspaceContent, Xt as WorkspaceSourceItem, ut as WorkspaceLoader } from "./types-BbtwmBZ5.js";
2
2
  //#region src/loaders/files.d.ts
3
3
  interface FilesLoaderOptions {
4
4
  include?: string | string[];
package/dist/loader.js CHANGED
@@ -1,5 +1,5 @@
1
- import { o as isWorkspaceBytes } from "./path-CNAwN7pw.js";
2
- import { t as files } from "./files-C7Px8uaC.js";
1
+ import { o as isWorkspaceBytes } from "./path--wrT_Azm.js";
2
+ import { t as files } from "./files-BOo4SbwE.js";
3
3
  //#region src/loaders/json.ts
4
4
  function json(options = {}) {
5
5
  return files({
@@ -1,6 +1,6 @@
1
- import { n as __exportAll } from "./rolldown-runtime-B4iAMlE-.js";
1
+ import { n as __exportAll } from "./rolldown-runtime-rQ84J-ij.js";
2
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-B7dmzDX3.js";
3
+ import { b as markLiveWorkspaceSource, d as withWorkspaceRuntimeOptions, f as prepareWorkspaceSource, u as ownSourceOption } from "./config-BAgL2dtB.js";
4
4
  import { mcpResources } from "@vite-hub/source/mcp";
5
5
  //#region src/sources/mcp-resources.ts
6
6
  var mcp_resources_exports = /* @__PURE__ */ __exportAll({ mcpResources: () => mcpResources$1 });
@@ -1,8 +1,7 @@
1
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";
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";
6
5
  //#region ../internal/src/owned-paths.ts
7
6
  /** Every Blob path that ViteHub writes for itself starts with this prefix. */
8
7
  const vitehubOwnedPrefix = "_vitehub/";
@@ -1,12 +1,11 @@
1
1
  import { s as workspaceError, t as normalizeSafeWorkspacePath } from "./path-DrSIenjj.js";
2
- import { f as sha256, i as decodeFile, l as normalizeWorkspacePath, n as contentStreamToBytes, o as isWorkspaceBytes, t as contentStreamChunks } from "./path-CNAwN7pw.js";
3
- import { n as resolveWorkspaceStoreTarget, t as forwardWorkspaceStoreTarget } from "./target-D4Bqb1eH.js";
4
- import { a as normalizeWorkspaceSources, c as sourceMountIntersectsPath, f as prepareWorkspaceSource, n as createSourceContext, s as sourceMountContainsPath } from "./config-B7dmzDX3.js";
5
- import { t as copyJsonFileMetadata } from "./file-metadata-CxDy-E2H.js";
6
- import { t as searchText } from "./search-CrTmXj5h.js";
2
+ import { n as resolveWorkspaceStoreTarget, o as copyJsonFileMetadata, t as forwardWorkspaceStoreTarget } from "./target-jWhTdIuF.js";
3
+ import { f as sha256, i as decodeFile, l as normalizeWorkspacePath, n as contentStreamToBytes, o as isWorkspaceBytes, t as contentStreamChunks } from "./path--wrT_Azm.js";
4
+ import { t as workspaceErrorDiagnostics } from "./error-diagnostics-CtKjGtGb.js";
5
+ import { t as searchText } from "./search-C_RfoM2j.js";
6
+ import { a as normalizeWorkspaceSources, c as sourceMountIntersectsPath, f as prepareWorkspaceSource, n as createSourceContext, s as sourceMountContainsPath } from "./config-BAgL2dtB.js";
7
7
  import { posix } from "node:path";
8
8
  import { createHash } from "node:crypto";
9
- import { hasRuntimeType } from "@vite-hub/runtime/internal/runtime-type";
10
9
  //#region src/storage/identity.ts
11
10
  const aliases = /* @__PURE__ */ new WeakMap();
12
11
  const stableIdentities = /* @__PURE__ */ new WeakSet();
@@ -106,7 +105,7 @@ async function readWorkspaceFileOwner(store, path, retireInvalidRemoval = false)
106
105
  }
107
106
  if (Object.hasOwn(owner, "removing") && owner.removing === true) {
108
107
  const current = await store.stat(path);
109
- if (current?.type === "file" && (!Object.hasOwn(owner, "revision") || !owner.revision || !current.revision)) throw new Error(`[vitehub] Cannot retry interrupted removal without a file revision: ${path}. Inspect the file and remove it explicitly if cleanup is still needed.`);
108
+ if (current?.type === "file" && (!Object.hasOwn(owner, "revision") || !owner.revision || !current.revision)) throw workspaceErrorDiagnostics.WORKSPACE_R0074({ message: `[vitehub] Cannot retry interrupted removal without a file revision: ${path}. Inspect the file and remove it explicitly if cleanup is still needed.` });
110
109
  const remaining = current?.type === "file" ? await store.readFile(path) : void 0;
111
110
  if (current?.type !== "file" || !Object.hasOwn(owner, "revision") || current.revision !== owner.revision || !Object.hasOwn(owner, "digest") || !owner.digest || !remaining || await sha256(remaining.content) !== owner.digest) {
112
111
  if (retireInvalidRemoval) await removeWorkspaceFileOwner(store, path);
@@ -363,13 +362,14 @@ async function invalidateSourceSnapshot(store, workspace, sourceKey) {
363
362
  status: "updating"
364
363
  });
365
364
  }
366
- async function hasCurrentSourceSnapshot(store, workspace, source, verifyOwnership = false, activeSources = []) {
365
+ async function hasCurrentSourceSnapshot(store, workspace, source, verifyOwnership = false, activeSources = [], path) {
367
366
  const configHash = await sourceConfigHash(source, store);
368
367
  const meta = await readSourceSnapshotMetadata(store, workspace, source.key, source);
369
368
  if (meta?.status !== "ready" || meta.configHash !== configHash) return false;
370
369
  if (verifyOwnership === "workspace") {
371
370
  if (Object.keys(meta.items || {}).length === 0 && meta.ownsMount !== false && meta.mountPath && (await store.stat(meta.mountPath))?.type !== "directory") return false;
372
- for (const path of Object.keys(meta.items || {})) {
371
+ const paths = path === void 0 ? Object.keys(meta.items || {}) : Object.hasOwn(meta.items || {}, path) ? [path] : [];
372
+ for (const path of paths) {
373
373
  const file = await store.readFile(path);
374
374
  if (!file) return false;
375
375
  const inlineOwner = file.metadata?.workspaceSourceOwner;
@@ -380,12 +380,13 @@ async function hasCurrentSourceSnapshot(store, workspace, source, verifyOwnershi
380
380
  }
381
381
  return true;
382
382
  }
383
- return !verifyOwnership || await snapshotHasCurrentOwners(store, workspace, source, meta, activeSources);
383
+ return !verifyOwnership || await snapshotHasCurrentOwners(store, workspace, source, meta, activeSources, path);
384
384
  }
385
- async function snapshotHasCurrentOwners(store, workspace, source, meta, activeSources = []) {
385
+ async function snapshotHasCurrentOwners(store, workspace, source, meta, activeSources = [], path) {
386
386
  if (Object.keys(meta.items || {}).length === 0 && meta.mountPath && (await store.stat(meta.mountPath))?.type !== "directory") return false;
387
- const listed = source.mountPath ? new Map((await store.list(source.mountPath, { recursive: true })).map((entry) => [entry.path, entry])) : void 0;
388
- for (const path of Object.keys(meta.items || {})) {
387
+ const listed = path === void 0 && source.mountPath ? new Map((await store.list(source.mountPath, { recursive: true })).map((entry) => [entry.path, entry])) : void 0;
388
+ const paths = path === void 0 ? Object.keys(meta.items || {}) : Object.hasOwn(meta.items || {}, path) ? [path] : [];
389
+ for (const path of paths) {
389
390
  const stat = listed?.get(path) ?? await store.stat(path);
390
391
  if (await materializedFileHasCurrentOwner(store, workspace, source.key, path, stat)) continue;
391
392
  const owner = await readWorkspaceFileOwner(store, path);
@@ -863,7 +864,7 @@ async function writeStartupIndex(store, key, value) {
863
864
  await store.setMeta(key, value);
864
865
  }
865
866
  function isMaterializedStartupSource(value) {
866
- if (!hasRuntimeType(value, "object") || value === null) return false;
867
+ if (typeof value !== "object" || value === null) return false;
867
868
  const source = value;
868
869
  return readStringMeta(source, "key") !== void 0 && readStringMeta(source, "mountPath") !== void 0;
869
870
  }
@@ -1578,8 +1579,8 @@ function forwardWorkspaceMetadataView(source, target, filterEntries) {
1578
1579
  });
1579
1580
  }
1580
1581
  function metadataTargetResolver(source) {
1581
- if (source === null || !(hasRuntimeType(source, "object") || hasRuntimeType(source, "function"))) return void 0;
1582
- return metadataTargetResolvers.get(source) ?? ("fs" in source && source.fs !== null && hasRuntimeType(source.fs, "object") ? facadeMetadataTargets.get(source.fs) : void 0);
1582
+ if (source === null || !(typeof source === "object" || typeof source === "function")) return void 0;
1583
+ return metadataTargetResolvers.get(source) ?? ("fs" in source && source.fs !== null && typeof source.fs === "object" ? facadeMetadataTargets.get(source.fs) : void 0);
1583
1584
  }
1584
1585
  function resolveWorkspaceMetadataMutationTarget(target) {
1585
1586
  return privateMetadataTargets.get(target) ?? target;
@@ -0,0 +1,11 @@
1
+ //#region ../internal/src/object.ts
2
+ /** A non-null object that is not an array. Functions do not pass. */
3
+ function isRecord(value) {
4
+ return typeof value === "object" && value !== null && !Array.isArray(value);
5
+ }
6
+ /** A non-null object or a function that is not an array. */
7
+ function isRecordOrFunction(value) {
8
+ return Object(value) === value && !Array.isArray(value);
9
+ }
10
+ //#endregion
11
+ export { isRecordOrFunction as n, isRecord as t };