@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.
- package/README.md +339 -115
- package/dist/abort-BCwpdrN0.js +32 -0
- package/dist/{asset-registry-8QI3ML3K.js → asset-registry-DfBV5kmw.js} +3 -2
- package/dist/blob-database.d.ts +474 -0
- package/dist/blob-database.js +608 -0
- package/dist/checkout.d.ts +128 -0
- package/dist/checkout.js +849 -0
- package/dist/cloudflare.d.ts +6 -7
- package/dist/cloudflare.js +1 -1
- package/dist/config-B-863EgC.js +15 -0
- package/dist/config-BAgL2dtB.js +1076 -0
- package/dist/{config-DE9xlaIw.d.ts → config-BQKcPawI.d.ts} +1 -2
- package/dist/discard-CNNtCozM.js +8 -0
- package/dist/durability.d.ts +22 -0
- package/dist/durability.js +70 -0
- package/dist/error-diagnostics-CtKjGtGb.js +188 -0
- package/dist/error-diagnostics-DSkCJC_L.js +266 -0
- package/dist/file-2pFYNtsU.js +22 -0
- package/dist/{files-Q6xZjDHA.js → files-BOo4SbwE.js} +3 -3
- package/dist/files.d.ts +38 -0
- package/dist/files.js +6 -0
- package/dist/{github-DHnjxQIX.js → github-CrYp4v8k.js} +44 -24
- package/dist/glob-B8YGvTrZ.js +21 -0
- package/dist/glob-Cjxms1t7.js +30 -0
- package/dist/{host-DJH8cuoU.js → host-BFBpXn0N.js} +144 -77
- package/dist/{hosted-RPeJOCFz.js → hosted-KcUR_jPv.js} +303 -97
- package/dist/hosted-vercel-blob-B3-wRdUm.js +410 -0
- package/dist/hosted-vercel-blob.d.ts +6 -7
- package/dist/hosted-vercel-blob.js +1 -1
- package/dist/hosted.d.ts +10 -9
- package/dist/hosted.js +2 -2
- package/dist/index.d.ts +26 -47
- package/dist/index.js +30 -100
- package/dist/internal/path.d.ts +2 -0
- package/dist/internal/path.js +2 -0
- package/dist/lifecycle-B-enk_4A.js +596 -0
- package/dist/lineage.d.ts +26 -0
- package/dist/lineage.js +76 -0
- package/dist/loader.d.ts +5 -6
- package/dist/loader.js +3 -2
- package/dist/mcp-resources-DF0F5rcL.js +39 -0
- package/dist/memory-BOexthyW.js +247 -0
- package/dist/metadata-target-CWz6KHKq.js +1589 -0
- package/dist/object-Da1zyPCR.js +11 -0
- package/dist/operation-definition-8gOe-ubD.d.ts +234 -0
- package/dist/operations-C6FpR8Rr.js +389 -0
- package/dist/operations-CE2drFih.js +1234 -0
- package/dist/operations.d.ts +90 -0
- package/dist/operations.js +3 -0
- package/dist/path--wrT_Azm.js +113 -0
- package/dist/path-AxMho1wo.d.ts +7 -0
- package/dist/path-DrSIenjj.js +59 -0
- package/dist/path-zHxQUbqa.d.ts +9 -0
- package/dist/plugins-C8C0auoW.d.ts +10 -0
- package/dist/provider-9s4Ufkm5.js +1479 -0
- package/dist/providers/github/store.d.ts +3 -5
- package/dist/providers/github/store.js +1 -1
- package/dist/registry-B3BBm4Ts.d.ts +19 -0
- package/dist/{registry-D3yzt8HQ.js → registry-CNphafBx.js} +60 -23
- package/dist/registry-CYNN623b.d.ts +9 -0
- package/dist/request-scope-Dw5n8bMC.js +83 -0
- package/dist/results-DgkZUmTL.js +8 -0
- package/dist/{chunk-2rV9d50f.js → rolldown-runtime-rQ84J-ij.js} +3 -4
- package/dist/runtime/assets.d.ts +3 -5
- package/dist/runtime/assets.js +7 -6
- package/dist/runtime/empty-assets-registry.d.ts +1 -2
- package/dist/runtime/empty-registry.d.ts +2 -2
- package/dist/runtime/registry.d.ts +2 -0
- package/dist/runtime/registry.js +23 -0
- package/dist/runtime/request.d.ts +4 -0
- package/dist/runtime/request.js +8 -0
- package/dist/runtime/state.d.ts +5 -4
- package/dist/runtime/state.js +8 -18
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime.d.ts +52 -17
- package/dist/runtime.js +324 -67
- package/dist/{search-BpiCF2Tw.js → search-C_RfoM2j.js} +10 -9
- package/dist/server-8tGltlGz.js +303 -0
- package/dist/server.d.ts +36 -39
- package/dist/server.js +2 -328
- package/dist/shared-B3_EUk89.js +848 -0
- package/dist/source-metadata.d.ts +10 -7
- package/dist/source-metadata.js +12 -12
- package/dist/state-BISnUf1s.d.ts +35 -0
- package/dist/{ai-BqCC8BpY.js → state-DbrW-njQ.js} +237 -114
- package/dist/store-ybhyD38Z.js +1873 -0
- package/dist/{sync-DnTQwt8r.js → sync-CCD_VYC8.js} +61 -41
- package/dist/target-jWhTdIuF.js +89 -0
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/{types-CYuwjJ4V.d.ts → types-BbtwmBZ5.d.ts} +321 -35
- package/dist/use-C6lV3-wC.d.ts +321 -0
- package/dist/{use-BTNDR5Rd.js → use-CSpT5W87.js} +141 -107
- package/dist/utils-CgMZCHsX.js +616 -0
- package/dist/vite.d.ts +585 -2
- package/dist/vite.js +21369 -2
- package/dist/workspace-CYB2xZ1T.d.ts +7 -0
- package/dist/{workspace-Dq08Yn72.js → workspace-sPWn2Jxj.js} +441 -225
- package/package.json +97 -72
- package/dist/ai-CjxvGqM0.d.ts +0 -162
- package/dist/ai.d.ts +0 -3
- package/dist/ai.js +0 -2
- package/dist/collections/client.d.ts +0 -39
- package/dist/collections/client.js +0 -137
- package/dist/collections.d.ts +0 -59
- package/dist/collections.js +0 -159
- package/dist/config-Bc3c4Su1.js +0 -7904
- package/dist/config-CHLLWklZ.js +0 -36
- package/dist/file-Bc1X7pco.js +0 -23
- package/dist/glob-CEZKeZFC.js +0 -18
- package/dist/hosted-vercel-blob-d6C8ND5j.js +0 -23580
- package/dist/lifecycle-LrL3sA4n.js +0 -316
- package/dist/metadata-target-B0tOmVW7.js +0 -717
- package/dist/mountx.d.ts +0 -10
- package/dist/mountx.js +0 -143
- package/dist/nitro.d.ts +0 -2
- package/dist/nitro.js +0 -2
- package/dist/nuxt.d.ts +0 -26
- package/dist/nuxt.js +0 -42
- package/dist/path-Cp59koVz.js +0 -139
- package/dist/provider-B1yLjCJJ.js +0 -746
- package/dist/publish.d.ts +0 -35
- package/dist/publish.js +0 -112
- package/dist/registry-Uj6IVxes.d.ts +0 -11
- package/dist/request-execution-B-dSFlGB.js +0 -84
- package/dist/runtime-options-BsPSv5O7.js +0 -13
- package/dist/runtime-type-iEE6BjQJ.js +0 -34
- package/dist/shared-DTR1Hhma.js +0 -331
- package/dist/state-tYcRWEh2.d.ts +0 -26
- package/dist/store-Dt_Jyys3.js +0 -608
- package/dist/target-D4Bqb1eH.js +0 -11
- package/dist/token-CVzURBxC.js +0 -61
- package/dist/use-BiHzt0xA.d.ts +0 -103
- package/dist/vite-BptCrpv2.js +0 -4526
- package/dist/vite-CtA9guIM.d.ts +0 -66
- package/dist/workspace-Xddf4G1B.d.ts +0 -6
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { t as
|
|
8
|
-
import { t as
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
1
|
+
import { t as createMemoryWorkspaceStore } from "./memory-BOexthyW.js";
|
|
2
|
+
import { s as workspaceError, t as normalizeSafeWorkspacePath } from "./path-DrSIenjj.js";
|
|
3
|
+
import { o as copyJsonFileMetadata, t as forwardWorkspaceStoreTarget } from "./target-jWhTdIuF.js";
|
|
4
|
+
import { a as isExcludedWorkspacePath, f as sha256, i as decodeFile, l as normalizeWorkspacePath, n as contentStreamToBytes, r as contentToBytes, s as matchesAny } from "./path--wrT_Azm.js";
|
|
5
|
+
import { t as workspaceErrorDiagnostics } from "./error-diagnostics-CtKjGtGb.js";
|
|
6
|
+
import { d as normalizeHistoryRef, i as createWorkspaceHistory, l as historyConflict, m as createWorkspaceWritePolicy } from "./utils-CgMZCHsX.js";
|
|
7
|
+
import { t as createWorkspaceGlobMatcher } from "./glob-Cjxms1t7.js";
|
|
8
|
+
import { t as createWorkspaceStoreFromProvider } from "./provider-9s4Ufkm5.js";
|
|
9
|
+
import { n as forwardWorkspaceRevisionMaterializer } from "./store-ybhyD38Z.js";
|
|
10
|
+
import { t as searchText } from "./search-C_RfoM2j.js";
|
|
11
|
+
import { a as normalizeWorkspaceSources, c as sourceMountIntersectsPath, f as prepareWorkspaceSource, g as getWorkspaceSourceRequestExecutor, n as createSourceContext, s as sourceMountContainsPath, v as workspaceSourceRequestDescriptorPath, y as requestJsonEqual } from "./config-BAgL2dtB.js";
|
|
12
|
+
import { C as withWorkspaceStoreMutation, D as readWorkspaceFileOwner, _ as reconcileRemovedStartupSources, b as statVirtualSourcePath, c as workspaceInternalMetadataCapability, f as materializeWorkspaceSources, g as readSourceSnapshotPaths, h as readResolvedSourceFile, l as hasCurrentSourceSnapshot, m as readCurrentSourceSnapshot, n as createWorkspaceMetadataTarget, p as materializesCompleteSource, t as attachWorkspaceMetadataTarget, u as hasFreshSourceSnapshot, v as searchMaterializedStore } from "./metadata-target-CWz6KHKq.js";
|
|
13
|
+
import { n as trackStagedWrites } from "./request-scope-Dw5n8bMC.js";
|
|
11
14
|
import { noExecutionAuthority } from "@vite-hub/runtime";
|
|
12
15
|
//#region src/session/scope.ts
|
|
13
16
|
function isMissingWorkspacePathError(error) {
|
|
@@ -19,11 +22,8 @@ function pathInSessionScope(path, paths) {
|
|
|
19
22
|
function pathIntersectsSessionScope(path, paths) {
|
|
20
23
|
return pathInSessionScope(path, paths) || Boolean(paths?.some((scope) => scope.startsWith(`${path}/`)));
|
|
21
24
|
}
|
|
22
|
-
function mkdirPathInSessionScope(path, paths) {
|
|
23
|
-
return pathInSessionScope(path, paths) || Boolean(paths?.some((scope) => scope.startsWith(`${path}/`)));
|
|
24
|
-
}
|
|
25
25
|
function assertPathInSessionScope(path, paths, options = {}) {
|
|
26
|
-
if (!(options.mkdir ?
|
|
26
|
+
if (!(options.mkdir ? pathIntersectsSessionScope(path, paths) : pathInSessionScope(path, paths))) throw workspaceError(options.masked ? `[vitehub] Workspace file does not exist: ${path}.` : `[vitehub] Workspace session path ${path} is outside the session scope.`);
|
|
27
27
|
return path;
|
|
28
28
|
}
|
|
29
29
|
function assertDiffInsideSessionPaths(diff, paths) {
|
|
@@ -65,7 +65,7 @@ function scopedSearchQuery(query, paths, normalizePath) {
|
|
|
65
65
|
//#endregion
|
|
66
66
|
//#region src/session/basic.ts
|
|
67
67
|
function unsupportedExec() {
|
|
68
|
-
throw workspaceError("[vitehub] Workspace exec requires a
|
|
68
|
+
throw workspaceError("[vitehub] Workspace exec requires a Sandbox session host. Pass the active Sandbox session to workspace.startSession({ host }).");
|
|
69
69
|
}
|
|
70
70
|
function normalizeSessionPaths(options) {
|
|
71
71
|
const paths = [...new Set((options?.paths || []).map((path) => normalizeSafeWorkspacePath(path, {
|
|
@@ -83,6 +83,7 @@ function normalizeSessionPath(path = "", options = {}) {
|
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
85
|
async function createBasicWorkspaceSession(workspace, options) {
|
|
86
|
+
const writeBackDisabled = options?.writeBack === false;
|
|
86
87
|
const sessionPaths = normalizeSessionPaths(options);
|
|
87
88
|
const overlay = createMemoryWorkspaceStore();
|
|
88
89
|
const initialEntries = filterSessionEntries(await workspace.list("", { recursive: true }), sessionPaths);
|
|
@@ -134,22 +135,25 @@ async function createBasicWorkspaceSession(workspace, options) {
|
|
|
134
135
|
if (!scoped) return [];
|
|
135
136
|
const roots = (scoped.paths?.length ? scoped.paths : [scoped.cwd || ""]).map((path) => normalizeSessionPath(path, { allowEmpty: true }));
|
|
136
137
|
const hits = [];
|
|
138
|
+
const limit = scoped.limit ?? 100;
|
|
137
139
|
for (const entry of filterSessionEntries(await overlay.list("", { recursive: true }), sessionPaths).filter((entry) => entry.type === "file")) {
|
|
138
140
|
if (!roots.some((root) => !root || entry.path === root || entry.path.startsWith(`${root}/`))) continue;
|
|
139
141
|
const file = await overlay.readFile(entry.path);
|
|
140
142
|
if (!file) continue;
|
|
141
143
|
hits.push(...searchText(entry.path, decodeFile(file.content), {
|
|
142
144
|
...scoped,
|
|
143
|
-
limit:
|
|
145
|
+
limit: limit - hits.length
|
|
144
146
|
}));
|
|
145
|
-
if (hits.length >=
|
|
147
|
+
if (hits.length >= limit) break;
|
|
146
148
|
}
|
|
147
149
|
return hits;
|
|
148
150
|
},
|
|
149
151
|
async diff() {
|
|
152
|
+
if (writeBackDisabled) throw workspaceError("[vitehub] Workspace Session diff is unavailable when writeBack is false.");
|
|
150
153
|
return filterSessionDiff(await overlay.diff(), sessionPaths);
|
|
151
154
|
},
|
|
152
155
|
async commit(commitOptions) {
|
|
156
|
+
if (writeBackDisabled) throw workspaceError("[vitehub] Workspace Session commit is unavailable when writeBack is false.");
|
|
153
157
|
const diff = await overlay.diff();
|
|
154
158
|
assertDiffInsideSessionPaths(diff, sessionPaths);
|
|
155
159
|
assertDiffInsideSessionPaths(await workspace.diff(), sessionPaths);
|
|
@@ -184,141 +188,85 @@ async function createBasicWorkspaceSession(workspace, options) {
|
|
|
184
188
|
};
|
|
185
189
|
}
|
|
186
190
|
//#endregion
|
|
187
|
-
//#region src/
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const match = /^(\d+)(kb|mb)$/.exec(value.toLowerCase());
|
|
192
|
-
if (!match) throw new TypeError(`[vitehub] Invalid workspace rule maxBytes value "${value}".`);
|
|
193
|
-
const count = Number(match[1]);
|
|
194
|
-
return match[2] === "kb" ? count * 1024 : count * 1024 * 1024;
|
|
191
|
+
//#region src/sources/request-execution.ts
|
|
192
|
+
const sourceRequestExecutions = /* @__PURE__ */ new WeakMap();
|
|
193
|
+
function isWeakKey(value) {
|
|
194
|
+
return Object(value) === value;
|
|
195
195
|
}
|
|
196
|
-
function
|
|
197
|
-
if (
|
|
198
|
-
|
|
196
|
+
function attachWorkspaceSourceRequestExecution(target, executor) {
|
|
197
|
+
if (!executor) return target;
|
|
198
|
+
sourceRequestExecutions.set(target, executor);
|
|
199
|
+
return target;
|
|
199
200
|
}
|
|
200
|
-
function
|
|
201
|
-
return
|
|
202
|
-
|
|
203
|
-
"write:before": [...toArray(left["write:before"]), ...toArray(right["write:before"])],
|
|
204
|
-
"write:error": [...toArray(left["write:error"]), ...toArray(right["write:error"])],
|
|
205
|
-
"write:validate": [...toArray(left["write:validate"]), ...toArray(right["write:validate"])]
|
|
206
|
-
};
|
|
201
|
+
function getWorkspaceSourceRequestExecution(input) {
|
|
202
|
+
if (!isWeakKey(input)) return void 0;
|
|
203
|
+
return sourceRequestExecutions.get(input);
|
|
207
204
|
}
|
|
208
|
-
function
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
205
|
+
function createWorkspaceSourceRequestExecution(definition, options = {}) {
|
|
206
|
+
const sources = normalizeWorkspaceSources(definition.sources).filter((source) => source.requestDescriptor && getWorkspaceSourceRequestExecutor(source.source)).filter((source) => sourceRequestVisible(source, options.selectedWorkspaceScope));
|
|
207
|
+
if (!sources.length) return void 0;
|
|
208
|
+
return { async executeSourceRequest(input) {
|
|
209
|
+
const matches = sources.filter((source) => source.requestDescriptor && workspaceSourceRequestMatches(source.requestDescriptor, input));
|
|
210
|
+
if (matches.length !== 1) throw workspaceErrorDiagnostics.WORKSPACE_R0063({ message: matches.length > 1 ? "[vitehub] Source request is ambiguous; more than one visible Source matches this curl target." : "[vitehub] Source request is not visible in the selected workspace scope or does not match a declared Source target." });
|
|
211
|
+
const source = matches[0];
|
|
212
|
+
const executor = getWorkspaceSourceRequestExecutor(source.source);
|
|
213
|
+
if (!executor) throw workspaceErrorDiagnostics.WORKSPACE_R0064({ message: "[vitehub] Source request executor is unavailable." });
|
|
214
|
+
const contextOptions = {
|
|
215
|
+
...input.signal ? { abortSignal: input.signal } : {},
|
|
216
|
+
selectedWorkspaceScope: options.selectedWorkspaceScope
|
|
217
217
|
};
|
|
218
|
-
|
|
218
|
+
return await executor(input, createSourceContext(definition, {
|
|
219
|
+
key: source.key,
|
|
220
|
+
mountPath: source.mountPath
|
|
221
|
+
}, void 0, contextOptions));
|
|
222
|
+
} };
|
|
219
223
|
}
|
|
220
|
-
function
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
if (!plugin?.id) throw new TypeError("[vitehub] Workspace plugins require an id.");
|
|
225
|
-
rules = {
|
|
226
|
-
...rules,
|
|
227
|
-
...plugin.rules
|
|
228
|
-
};
|
|
229
|
-
hooks = mergeHooks(hooks, plugin.hooks);
|
|
230
|
-
}
|
|
231
|
-
rules = {
|
|
232
|
-
...rules,
|
|
233
|
-
...definition.rules
|
|
234
|
-
};
|
|
235
|
-
hooks = mergeHooks(hooks, definition.hooks);
|
|
236
|
-
return {
|
|
237
|
-
hooks,
|
|
238
|
-
rules: normalizeRules(rules)
|
|
239
|
-
};
|
|
224
|
+
function sourceRequestVisible(source, scope) {
|
|
225
|
+
if (!scope || scope.all) return true;
|
|
226
|
+
const descriptorPath = workspaceSourceRequestDescriptorPath(source.key);
|
|
227
|
+
return Boolean(scope.paths?.some((path) => pathIntersects(path, descriptorPath)));
|
|
240
228
|
}
|
|
241
|
-
function
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
for (const rule of policy.rules) {
|
|
245
|
-
const globstarDirectory = rule.pattern.endsWith("/**") ? rule.pattern.slice(0, -3) : void 0;
|
|
246
|
-
if (minimatch(normalized, rule.pattern, { dot: true }) || normalized === globstarDirectory) matched = rule;
|
|
247
|
-
}
|
|
248
|
-
return matched;
|
|
229
|
+
function pathContains(container, path) {
|
|
230
|
+
if (!container || !path) return container === path;
|
|
231
|
+
return path === container || path.startsWith(`${container}/`);
|
|
249
232
|
}
|
|
250
|
-
function
|
|
251
|
-
|
|
252
|
-
if (write === false) return false;
|
|
253
|
-
if (write === "delete") return operation === "rm";
|
|
254
|
-
if (write === "create") return operation !== "rm" && !exists;
|
|
255
|
-
if (write === "update") return operation === "writeFile" && exists;
|
|
256
|
-
return true;
|
|
233
|
+
function pathIntersects(left, right) {
|
|
234
|
+
return pathContains(left, right) || pathContains(right, left);
|
|
257
235
|
}
|
|
258
|
-
function
|
|
259
|
-
return
|
|
236
|
+
function workspaceSourceRequestMatches(descriptor, input) {
|
|
237
|
+
return descriptor.method === input.method && sameRequestTarget(descriptor.url, input.url) && requestShapeMatches(descriptor, input);
|
|
260
238
|
}
|
|
261
|
-
function
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
if (!writeAllowed(rule.write, input.operation, exists)) throw workspaceError(`[vitehub] Workspace rule "${rule.pattern}" does not allow ${input.operation} for ${input.path}.`);
|
|
266
|
-
if (rule.maxBytes !== void 0 && sizeOf(input.content) > rule.maxBytes) throw workspaceError(`[vitehub] Workspace rule "${rule.pattern}" limits writes to ${rule.maxBytes} bytes: ${input.path}.`);
|
|
267
|
-
if (rule.mediaType && input.mediaType) {
|
|
268
|
-
if (!(Array.isArray(rule.mediaType) ? rule.mediaType : [rule.mediaType]).includes(input.mediaType)) throw workspaceError(`[vitehub] Workspace rule "${rule.pattern}" does not allow media type ${input.mediaType}: ${input.path}.`);
|
|
269
|
-
}
|
|
239
|
+
function sameRequestTarget(left, right) {
|
|
240
|
+
const leftUrl = new URL(left);
|
|
241
|
+
const rightUrl = new URL(right);
|
|
242
|
+
return leftUrl.origin === rightUrl.origin && leftUrl.pathname === rightUrl.pathname;
|
|
270
243
|
}
|
|
271
|
-
|
|
272
|
-
|
|
244
|
+
function requestShapeMatches(descriptor, input) {
|
|
245
|
+
const request = descriptor.request;
|
|
246
|
+
if (request?.querySchema) return bodyShapeMatches(request, input);
|
|
247
|
+
if (!requestJsonEqual(queryFromUrl(new URL(input.url)) || {}, serializedQuery(request?.query) || {})) return false;
|
|
248
|
+
return bodyShapeMatches(request, input);
|
|
273
249
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
if (result === false) throw workspaceError(`[vitehub] Workspace validator rejected ${current.operation} for ${current.path}.`);
|
|
279
|
-
if (typeof result === "object" && result !== null) current = result;
|
|
280
|
-
}
|
|
281
|
-
return current;
|
|
250
|
+
function bodyShapeMatches(request, input) {
|
|
251
|
+
if (request?.bodySchema) return true;
|
|
252
|
+
if (request && "body" in request) return requestJsonEqual(input.body, request.body);
|
|
253
|
+
return input.body === void 0;
|
|
282
254
|
}
|
|
283
|
-
function
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
rule: matchRule(policy, input.path)
|
|
290
|
-
};
|
|
291
|
-
await runHooks(policy.hooks, "write:before", current);
|
|
292
|
-
assertRuleAllows(current);
|
|
293
|
-
if (current.rule?.validate.length) current = await runValidators(current.rule.validate, current);
|
|
294
|
-
await runHooks(policy.hooks, "write:validate", current);
|
|
295
|
-
return current;
|
|
296
|
-
},
|
|
297
|
-
async after(input) {
|
|
298
|
-
await runHooks(policy.hooks, "write:after", input);
|
|
299
|
-
},
|
|
300
|
-
async error(input, error) {
|
|
301
|
-
for (const hook of toArray(policy.hooks["write:error"])) await hook({
|
|
302
|
-
...input,
|
|
303
|
-
error
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
};
|
|
255
|
+
function queryFromUrl(url) {
|
|
256
|
+
const query = Object.fromEntries([...new Set(url.searchParams.keys())].map((key) => {
|
|
257
|
+
const values = url.searchParams.getAll(key);
|
|
258
|
+
return [key, values.length > 1 ? values : values[0]];
|
|
259
|
+
}));
|
|
260
|
+
return Object.keys(query).length ? query : void 0;
|
|
307
261
|
}
|
|
308
|
-
function
|
|
309
|
-
if (!
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
const rules = paths.map((path) => matchRule(policy, path));
|
|
317
|
-
if (!rules.length || rules.some((rule) => !rule?.commit)) return;
|
|
318
|
-
return {
|
|
319
|
-
message: rules.map((rule) => rule?.commit).find((commit) => typeof commit === "string" && commit.trim().length > 0)?.trim() || `chore: update ${definition.name} workspace`,
|
|
320
|
-
paths
|
|
321
|
-
};
|
|
262
|
+
function serializedQuery(query) {
|
|
263
|
+
if (!query) return void 0;
|
|
264
|
+
const params = new URLSearchParams();
|
|
265
|
+
for (const [key, value] of Object.entries(query)) {
|
|
266
|
+
const values = Array.isArray(value) ? value : [value];
|
|
267
|
+
for (const item of values) params.append(key, String(item));
|
|
268
|
+
}
|
|
269
|
+
return queryFromUrl(new URL(`https://vitehub.local/?${params}`));
|
|
322
270
|
}
|
|
323
271
|
//#endregion
|
|
324
272
|
//#region src/sources/resolver.ts
|
|
@@ -353,8 +301,12 @@ function createSourceResolution(source, workspacePath, sourcePath) {
|
|
|
353
301
|
}
|
|
354
302
|
//#endregion
|
|
355
303
|
//#region src/sources/sync-state.ts
|
|
356
|
-
function sourceSyncMetaKey(sourceKey) {
|
|
357
|
-
return `source:${sourceKey}:sync`;
|
|
304
|
+
function sourceSyncMetaKey(sourceKey, workspace) {
|
|
305
|
+
return workspace ? `workspace:${workspace}:source:${sourceKey}:sync` : `source:${sourceKey}:sync`;
|
|
306
|
+
}
|
|
307
|
+
/** Identifies the durable metadata record owned by Source Sync. */
|
|
308
|
+
function isWorkspaceSourceSyncMetaKey(key) {
|
|
309
|
+
return [key.toLowerCase(), normalizeWorkspacePath(key).toLowerCase()].some((form) => /^(?:workspace:.+:)?source:.*:sync$/.test(form));
|
|
358
310
|
}
|
|
359
311
|
function readWorkspaceSourceSyncState(value) {
|
|
360
312
|
if (!value || typeof value !== "object" || Array.isArray(value)) return;
|
|
@@ -366,9 +318,30 @@ function readWorkspaceSourceSyncState(value) {
|
|
|
366
318
|
const entry = state.paths[path];
|
|
367
319
|
if (!entry || typeof entry !== "object" || Array.isArray(entry)) return;
|
|
368
320
|
if (typeof entry.digest !== "string" || typeof entry.sourcePath !== "string") return;
|
|
321
|
+
if (entry.mountPath !== void 0 && typeof entry.mountPath !== "string") return;
|
|
322
|
+
}
|
|
323
|
+
if (state.claims !== void 0) {
|
|
324
|
+
if (!state.claims || typeof state.claims !== "object" || Array.isArray(state.claims)) return;
|
|
325
|
+
for (const [path, claims] of Object.entries(state.claims)) {
|
|
326
|
+
if (!state.paths[path] || !Array.isArray(claims) || claims.length === 0) return;
|
|
327
|
+
const mounts = /* @__PURE__ */ new Set();
|
|
328
|
+
for (const claim of claims) {
|
|
329
|
+
if (!claim || typeof claim !== "object" || Array.isArray(claim)) return;
|
|
330
|
+
if (typeof claim.digest !== "string" || typeof claim.sourcePath !== "string" || typeof claim.mountPath !== "string") return;
|
|
331
|
+
if (mounts.has(claim.mountPath)) return;
|
|
332
|
+
mounts.add(claim.mountPath);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
369
335
|
}
|
|
370
336
|
return state;
|
|
371
337
|
}
|
|
338
|
+
/** Legacy records contain one claim per path; new records retain overlapping mounts. */
|
|
339
|
+
function sourceSyncPathClaims(state, path) {
|
|
340
|
+
return state.claims?.[path] ?? [{
|
|
341
|
+
...state.paths[path],
|
|
342
|
+
mountPath: state.paths[path].mountPath ?? state.mountPath
|
|
343
|
+
}];
|
|
344
|
+
}
|
|
372
345
|
function workspaceSourceSyncStateEquals(left, right) {
|
|
373
346
|
if (!left) return false;
|
|
374
347
|
return JSON.stringify(canonicalSourceSyncState(left)) === JSON.stringify(canonicalSourceSyncState(right));
|
|
@@ -376,6 +349,7 @@ function workspaceSourceSyncStateEquals(left, right) {
|
|
|
376
349
|
function canonicalSourceSyncState(state) {
|
|
377
350
|
return {
|
|
378
351
|
configHash: state.configHash,
|
|
352
|
+
claims: state.claims,
|
|
379
353
|
mountPath: state.mountPath,
|
|
380
354
|
paths: Object.fromEntries(Object.entries(state.paths).sort(([left], [right]) => left.localeCompare(right))),
|
|
381
355
|
source: state.source
|
|
@@ -383,6 +357,25 @@ function canonicalSourceSyncState(state) {
|
|
|
383
357
|
}
|
|
384
358
|
//#endregion
|
|
385
359
|
//#region src/sources/view.ts
|
|
360
|
+
function assertPublicFileMetadata(path, metadata) {
|
|
361
|
+
metadata = copyJsonFileMetadata(path, metadata);
|
|
362
|
+
if (metadata && Object.hasOwn(metadata, "source")) throw workspaceError(`[vitehub] Invalid Workspace metadata for ${path}. metadata.source is reserved for Source materialization.`);
|
|
363
|
+
return metadata;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Proof that one Source view checked one normalized Workspace path for writes.
|
|
367
|
+
* Only `assertWritable` creates a grant. A grant is request-scoped. Do not persist it.
|
|
368
|
+
*/
|
|
369
|
+
var WorkspaceSourceWriteGrant = class {
|
|
370
|
+
#path;
|
|
371
|
+
constructor(path) {
|
|
372
|
+
this.#path = path;
|
|
373
|
+
Object.freeze(this);
|
|
374
|
+
}
|
|
375
|
+
get path() {
|
|
376
|
+
return this.#path;
|
|
377
|
+
}
|
|
378
|
+
};
|
|
386
379
|
const materializationByStore = /* @__PURE__ */ new WeakMap();
|
|
387
380
|
async function invalidateWorkspaceSourceMaterialization(definition, store, sourceKeys) {
|
|
388
381
|
const state = materializationByStore.get(store)?.get(definition);
|
|
@@ -421,6 +414,8 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
421
414
|
const descriptorSources = allSources.filter((source) => source.requestDescriptor);
|
|
422
415
|
const writePolicy = createWorkspaceWritePolicy(definition);
|
|
423
416
|
const prepareBySource = /* @__PURE__ */ new Map();
|
|
417
|
+
const priorPathsBySource = /* @__PURE__ */ new Map();
|
|
418
|
+
let removedSourceReconciliation;
|
|
424
419
|
const sourceContexts = /* @__PURE__ */ new Map();
|
|
425
420
|
let materializationByDefinition = materializationByStore.get(store);
|
|
426
421
|
if (!materializationByDefinition) {
|
|
@@ -435,8 +430,8 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
435
430
|
};
|
|
436
431
|
if (!materializationByDefinition.has(definition)) materializationByDefinition.set(definition, materializationState);
|
|
437
432
|
const { completedSources, generationBySource, materializedSources, pendingBySource } = materializationState;
|
|
433
|
+
const reusedStartupSources = /* @__PURE__ */ new Set();
|
|
438
434
|
const uncachedMaterializedSources = /* @__PURE__ */ new Set();
|
|
439
|
-
const persistsSourceSnapshots = Boolean(store.getMeta && store.setMeta);
|
|
440
435
|
function getSourceContext(source) {
|
|
441
436
|
let context = sourceContexts.get(source.key);
|
|
442
437
|
if (!context) {
|
|
@@ -521,18 +516,45 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
521
516
|
function usesLiveProvider(source) {
|
|
522
517
|
return Boolean(source.livePaths && source.materialize !== "startup");
|
|
523
518
|
}
|
|
524
|
-
function getLazySourcesForPath(path) {
|
|
525
|
-
|
|
519
|
+
async function getLazySourcesForPath(path) {
|
|
520
|
+
if (!removedSourceReconciliation && sources.some((source) => !source.mountPath && source.materialize === "startup" && source.source.name === "file" && source.probeKeys?.length)) removedSourceReconciliation = reconcileRemovedStartupSources(definition.name, store, allSources.filter((source) => source.materialize === "startup")).catch((error) => {
|
|
521
|
+
removedSourceReconciliation = void 0;
|
|
522
|
+
throw error;
|
|
523
|
+
});
|
|
524
|
+
await removedSourceReconciliation;
|
|
525
|
+
const normalized = normalizeWorkspacePath(path);
|
|
526
|
+
const intersects = (filePath) => !normalized || normalized === filePath || filePath.startsWith(`${normalized}/`);
|
|
527
|
+
const matched = [];
|
|
528
|
+
for (const source of sources) {
|
|
529
|
+
if (source.mountPath || source.materialize !== "startup" || source.source.name !== "file" || !source.probeKeys?.length) {
|
|
530
|
+
if (sourceMountIntersectsPath(source, normalized)) matched.push(source);
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
533
|
+
if (source.probeKeys.some((key) => intersects(normalizeWorkspacePath(key)))) {
|
|
534
|
+
matched.push(source);
|
|
535
|
+
continue;
|
|
536
|
+
}
|
|
537
|
+
let priorPaths = priorPathsBySource.get(source.key);
|
|
538
|
+
if (!priorPaths) {
|
|
539
|
+
priorPaths = readSourceSnapshotPaths(store, definition.name, source.key).catch((error) => {
|
|
540
|
+
priorPathsBySource.delete(source.key);
|
|
541
|
+
throw error;
|
|
542
|
+
});
|
|
543
|
+
priorPathsBySource.set(source.key, priorPaths);
|
|
544
|
+
}
|
|
545
|
+
if ((await priorPaths).some(intersects)) matched.push(source);
|
|
546
|
+
}
|
|
547
|
+
return matched;
|
|
526
548
|
}
|
|
527
|
-
async function ensurePrepared(sourceKey) {
|
|
549
|
+
async function ensurePrepared(sourceKey, path) {
|
|
528
550
|
const source = sources.find((item) => item.key === sourceKey);
|
|
529
551
|
if (!source) return;
|
|
530
552
|
if (source.materialize === "startup" && completedSources.has(sourceKey)) {
|
|
531
|
-
if (
|
|
553
|
+
if (await hasCurrentSourceSnapshot(store, definition.name, source, options.reuseStartupSnapshots, options.reuseStartupSnapshots ? sources : void 0, path)) return;
|
|
532
554
|
completedSources.delete(sourceKey);
|
|
533
555
|
}
|
|
534
|
-
if (source.materialize === "startup" && options.reuseStartupSnapshots && await hasCurrentSourceSnapshot(store, source)) {
|
|
535
|
-
|
|
556
|
+
if (source.materialize === "startup" && options.reuseStartupSnapshots && await hasCurrentSourceSnapshot(store, definition.name, source, true, sources, path)) {
|
|
557
|
+
reusedStartupSources.add(sourceKey);
|
|
536
558
|
return;
|
|
537
559
|
}
|
|
538
560
|
let pending = prepareBySource.get(sourceKey);
|
|
@@ -547,7 +569,7 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
547
569
|
}
|
|
548
570
|
async function materializeSerialized(options = {}) {
|
|
549
571
|
const requestedPath = normalizeWorkspacePath(options.path || "");
|
|
550
|
-
const selectedSources = allSources.filter((source) => source.materialize === "lazy" || source.materialize === "startup" || source.materialize === "build" && Boolean(requestedPath)).filter((source) => (
|
|
572
|
+
const selectedSources = allSources.filter((source) => source.materialize === "lazy" || source.materialize === "startup" || source.materialize === "build" && Boolean(requestedPath)).filter((source) => (options.sources === void 0 || options.sources.includes(source.key)) && sourceMountIntersectsPath(source, requestedPath));
|
|
551
573
|
const predecessors = selectedSources.flatMap((source) => {
|
|
552
574
|
const pending = pendingBySource.get(source.key);
|
|
553
575
|
return pending ? [pending.tail] : [];
|
|
@@ -575,7 +597,10 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
575
597
|
for (const source of selectedSources) {
|
|
576
598
|
if (!materializesCompleteSource(source, options)) continue;
|
|
577
599
|
materializedSources.delete(source.key);
|
|
578
|
-
if (source.materialize === "startup")
|
|
600
|
+
if (source.materialize === "startup") {
|
|
601
|
+
completedSources.delete(source.key);
|
|
602
|
+
reusedStartupSources.delete(source.key);
|
|
603
|
+
}
|
|
579
604
|
}
|
|
580
605
|
let result;
|
|
581
606
|
try {
|
|
@@ -617,9 +642,10 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
617
642
|
});
|
|
618
643
|
return await current;
|
|
619
644
|
}
|
|
620
|
-
async function ensureMaterialized(sourceKey) {
|
|
645
|
+
async function ensureMaterialized(sourceKey, verifyRootOwnership = true, path) {
|
|
621
646
|
const source = sources.find((item) => item.key === sourceKey);
|
|
622
647
|
if (!source) return;
|
|
648
|
+
const verifyOwnership = options.reuseStartupSnapshots ? true : verifyRootOwnership || source.mountPath || !sources.some((item) => !item.mountPath && item.materialize === "lazy") ? "workspace" : false;
|
|
623
649
|
const isUncachedLazySource = source.materialize === "lazy" && source.cache === false;
|
|
624
650
|
const pending = pendingBySource.get(sourceKey);
|
|
625
651
|
if (pending?.fullSource) {
|
|
@@ -633,13 +659,16 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
633
659
|
}
|
|
634
660
|
if (isUncachedLazySource ? uncachedMaterializedSources.has(sourceKey) : materializedSources.has(sourceKey)) {
|
|
635
661
|
const maxAge = source.cache && source.cache.maxAge;
|
|
636
|
-
if (source.materialize
|
|
662
|
+
if (source.materialize === "startup" ? await hasCurrentSourceSnapshot(store, definition.name, source, verifyOwnership, options.reuseStartupSnapshots ? sources : void 0, path) : !Number.isFinite(maxAge) || await hasFreshSourceSnapshot(store, definition.name, source)) return;
|
|
637
663
|
materializedSources.delete(sourceKey);
|
|
638
664
|
}
|
|
639
|
-
if (completedSources.has(sourceKey)) {
|
|
640
|
-
if (
|
|
665
|
+
if (completedSources.has(sourceKey) || reusedStartupSources.has(sourceKey)) {
|
|
666
|
+
if (await hasCurrentSourceSnapshot(store, definition.name, source, verifyOwnership, options.reuseStartupSnapshots ? sources : void 0, path)) return;
|
|
641
667
|
completedSources.delete(sourceKey);
|
|
668
|
+
reusedStartupSources.delete(sourceKey);
|
|
642
669
|
}
|
|
670
|
+
const recovery = pendingBySource.get(sourceKey);
|
|
671
|
+
if (recovery && recovery !== pending) return await ensureMaterialized(sourceKey, verifyRootOwnership, path);
|
|
643
672
|
await materializeSerialized({ sources: [sourceKey] });
|
|
644
673
|
}
|
|
645
674
|
async function ensureMaterializedSources(items = sources) {
|
|
@@ -647,18 +676,23 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
647
676
|
}
|
|
648
677
|
async function listSourceAware(path = "", options = {}) {
|
|
649
678
|
const normalized = normalizeWorkspacePath(path);
|
|
679
|
+
if (!isDescriptorPath(normalized)) for (const source of await getLazySourcesForPath(normalized)) {
|
|
680
|
+
if (source.materialize !== "startup" || isExcludedWorkspacePath(source.mountPath, options.exclude)) continue;
|
|
681
|
+
await ensurePrepared(source.key);
|
|
682
|
+
if (!usesLiveProvider(source)) await ensureMaterialized(source.key);
|
|
683
|
+
}
|
|
650
684
|
const storeEntries = isDescriptorPath(normalized) ? [] : await store.list(path, options);
|
|
651
685
|
const result = new Map(storeEntries.map((entry) => [entry.path, entry]));
|
|
652
686
|
for (const entry of descriptorPathEntries(path, options)) if (!isExcludedWorkspacePath(entry.path, options.exclude)) result.set(entry.path, entry);
|
|
653
687
|
if (isDescriptorPath(normalized)) return [...result.values()].sort((left, right) => left.path.localeCompare(right.path));
|
|
654
|
-
for (const source of getLazySourcesForPath(path)) {
|
|
688
|
+
for (const source of await getLazySourcesForPath(path)) {
|
|
655
689
|
if (isExcludedWorkspacePath(source.mountPath, options.exclude)) continue;
|
|
656
690
|
await ensurePrepared(source.key);
|
|
657
691
|
if (usesLiveProvider(source)) {
|
|
658
692
|
await pruneLiveSourceStoreEntries(result, source);
|
|
659
693
|
continue;
|
|
660
694
|
}
|
|
661
|
-
if (!
|
|
695
|
+
if (!normalized && options.recursive && source.materialize !== "startup" && !await hasCurrentSourceSnapshot(store, definition.name, source)) {
|
|
662
696
|
if ([...result.keys()].some((key) => sourceMountContainsPath(source, key))) {
|
|
663
697
|
const allowed = await currentSourceTreePaths(source, getSourceContext(source));
|
|
664
698
|
for (const key of result.keys()) if (sourceMountContainsPath(source, key) && !allowed.has(key)) result.delete(key);
|
|
@@ -675,10 +709,11 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
675
709
|
});
|
|
676
710
|
continue;
|
|
677
711
|
}
|
|
678
|
-
if (
|
|
712
|
+
if (source.materialize === "startup") continue;
|
|
713
|
+
else if (sourceMountContainsPath(source, path) || !source.mountPath && normalized) {
|
|
679
714
|
await ensureMaterialized(source.key);
|
|
680
715
|
for (const entry of await store.list(path, options)) result.set(entry.path, entry);
|
|
681
|
-
} else if (!
|
|
716
|
+
} else if (!normalized && !result.has(source.mountPath)) result.set(source.mountPath, {
|
|
682
717
|
path: source.mountPath,
|
|
683
718
|
type: "directory"
|
|
684
719
|
});
|
|
@@ -701,6 +736,11 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
701
736
|
list.push(resolution.workspacePath);
|
|
702
737
|
sourcePaths.set(resolution.sourceKey, list);
|
|
703
738
|
}
|
|
739
|
+
for (const source of sources) {
|
|
740
|
+
if (source.materialize !== "startup" || !requestedPaths.some((path) => sourceMountIntersectsPath(source, normalizeWorkspacePath(path)))) continue;
|
|
741
|
+
await ensurePrepared(source.key);
|
|
742
|
+
await ensureMaterialized(source.key);
|
|
743
|
+
}
|
|
704
744
|
const results = await searchMaterializedStore(store, {
|
|
705
745
|
...query,
|
|
706
746
|
paths: storePaths.filter(Boolean).length ? storePaths.filter(Boolean) : void 0,
|
|
@@ -752,14 +792,42 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
752
792
|
async function previousStat(path) {
|
|
753
793
|
return await store.stat(path);
|
|
754
794
|
}
|
|
755
|
-
async function
|
|
795
|
+
async function materializeRootStartupSources(verifyRootOwnership = true) {
|
|
796
|
+
for (const source of sources.filter((source) => !source.mountPath && source.materialize === "startup")) {
|
|
797
|
+
await ensurePrepared(source.key);
|
|
798
|
+
await ensureMaterialized(source.key, verifyRootOwnership);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
async function readOwnedRootStartupFile(path, sourceKey) {
|
|
802
|
+
if (!sources.some((source) => !source.mountPath && source.materialize === "startup")) return;
|
|
803
|
+
const owner = await readWorkspaceFileOwner(store, path);
|
|
804
|
+
if (owner?.workspace !== definition.name || !owner.digest) return;
|
|
805
|
+
if (sourceKey && owner.source !== sourceKey) return;
|
|
806
|
+
const source = sources.find((source) => !source.mountPath && source.materialize === "startup" && source.key === owner.source);
|
|
807
|
+
if (!source) return;
|
|
808
|
+
if ((await store.stat(path))?.type !== "file") return;
|
|
809
|
+
const file = await store.readFile(path);
|
|
810
|
+
if (!file) return;
|
|
811
|
+
if (file.metadata?.source && (file.metadata.workspaceSourceOwner !== definition.name || file.metadata.source !== owner.source)) return;
|
|
812
|
+
const snapshot = await readCurrentSourceSnapshot(store, definition.name, source);
|
|
813
|
+
if (snapshot?.status !== "ready" || !Object.hasOwn(snapshot.items || {}, path)) return;
|
|
814
|
+
if (await sha256(file.content) === owner.digest) return file;
|
|
815
|
+
}
|
|
816
|
+
async function materializeRootSourceForPath(path, verifyRootOwnership = true) {
|
|
756
817
|
for (const source of sources.filter((source) => !source.mountPath)) {
|
|
757
818
|
await ensurePrepared(source.key);
|
|
758
|
-
await ensureMaterialized(source.key);
|
|
759
|
-
if (
|
|
819
|
+
await ensureMaterialized(source.key, verifyRootOwnership);
|
|
820
|
+
if (source.materialize === "startup") {
|
|
821
|
+
if (await readOwnedRootStartupFile(path, source.key)) return source;
|
|
822
|
+
} else if ((await store.stat(path))?.metadata?.source === source.key) return source;
|
|
760
823
|
}
|
|
761
824
|
}
|
|
762
825
|
async function isSourceBackedStorePath(path) {
|
|
826
|
+
if (!allSources.length) return false;
|
|
827
|
+
for (const source of allSources) {
|
|
828
|
+
const snapshot = await readCurrentSourceSnapshot(store, definition.name, source);
|
|
829
|
+
if (Object.keys(snapshot?.items || {}).some((item) => item === path || !path || item.startsWith(`${path}/`))) return true;
|
|
830
|
+
}
|
|
763
831
|
const file = await store.readFile(path);
|
|
764
832
|
if (typeof file?.metadata?.source === "string" && allSources.some((source) => source.key === file.metadata?.source)) return true;
|
|
765
833
|
if ((await store.stat(path))?.type !== "directory") return false;
|
|
@@ -774,13 +842,18 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
774
842
|
async function isSyncedStatePath(path) {
|
|
775
843
|
if (!store.getMeta) return false;
|
|
776
844
|
for (const source of syncSources) {
|
|
777
|
-
const state = readWorkspaceSourceSyncState(await store.getMeta(sourceSyncMetaKey(source.key)));
|
|
845
|
+
const state = readWorkspaceSourceSyncState(await store.getMeta(sourceSyncMetaKey(source.key, definition.name)));
|
|
778
846
|
if (!state) continue;
|
|
779
847
|
if (state.paths[path]) return true;
|
|
780
848
|
if (Object.keys(state.paths).some((item) => item.startsWith(`${path}/`))) return true;
|
|
781
849
|
}
|
|
782
850
|
return false;
|
|
783
851
|
}
|
|
852
|
+
async function assertWritableCurrentPath(path) {
|
|
853
|
+
if (isDescriptorPath(path)) throw workspaceError(`[vitehub] Source-backed workspace paths are read-only: ${path}.`);
|
|
854
|
+
const resolution = resolveWorkspacePath(definition, path);
|
|
855
|
+
if (resolution.type === "source" || isLazySourcePath(resolution.workspacePath) || isSyncSourceMountPath(resolution.workspacePath) || await isSyncedStatePath(resolution.workspacePath) || await isSourceBackedStorePath(resolution.workspacePath)) throw workspaceError(`[vitehub] Source-backed workspace paths are read-only: ${path}.`);
|
|
856
|
+
}
|
|
784
857
|
async function assertWritableResolvedStorePath(path, workspacePath, type) {
|
|
785
858
|
assertWritableStorePath(path, workspacePath, type);
|
|
786
859
|
await materializeRootSourceForPath(workspacePath);
|
|
@@ -789,61 +862,164 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
789
862
|
async function assertWritablePath(path) {
|
|
790
863
|
if (isDescriptorPath(normalizeWorkspacePath(path))) throw workspaceError(`[vitehub] Source-backed workspace paths are read-only: ${path}.`);
|
|
791
864
|
const resolution = resolveWorkspacePath(definition, path);
|
|
792
|
-
if (isDescriptorPath(resolution.workspacePath)) throw workspaceError(`[vitehub] Source-backed workspace paths are read-only: ${path}.`);
|
|
865
|
+
if (isDescriptorPath(resolution.workspacePath) || allSources.some((source) => (source.materialize === "lazy" || source.materialize === "startup") && sourceMountContainsPath(source, resolution.workspacePath))) throw workspaceError(`[vitehub] Source-backed workspace paths are read-only: ${path}.`);
|
|
793
866
|
await assertWritableResolvedStorePath(path, resolution.workspacePath, resolution.type);
|
|
794
867
|
return resolution;
|
|
795
868
|
}
|
|
869
|
+
const writeGrants = /* @__PURE__ */ new WeakMap();
|
|
870
|
+
async function grantWritablePath(path) {
|
|
871
|
+
const { workspacePath } = await assertWritablePath(path);
|
|
872
|
+
const grant = new WorkspaceSourceWriteGrant(workspacePath);
|
|
873
|
+
writeGrants.set(grant, workspacePath);
|
|
874
|
+
return grant;
|
|
875
|
+
}
|
|
876
|
+
async function grantPolicyPath(path) {
|
|
877
|
+
return await grantWritablePath(path);
|
|
878
|
+
}
|
|
879
|
+
function requireWriteGrant(write) {
|
|
880
|
+
return async (grant, path, ...args) => {
|
|
881
|
+
const workspacePath = normalizeWorkspacePath(path);
|
|
882
|
+
if (writeGrants.get(grant) !== workspacePath) throw workspaceError(`[vitehub] Workspace write to ${path} requires a Source write grant for that path.`);
|
|
883
|
+
return await withWorkspaceStoreMutation(store, async () => {
|
|
884
|
+
await assertWritableCurrentPath(workspacePath);
|
|
885
|
+
return await write(workspacePath, ...args);
|
|
886
|
+
});
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
function requireRebaseGrants(rebase) {
|
|
890
|
+
return async (grants, options) => {
|
|
891
|
+
const takeRemote = options?.takeRemote ?? [];
|
|
892
|
+
if (!Array.isArray(grants) || grants.length !== takeRemote.length) throw workspaceError("[vitehub] Workspace rebase requires one Source write grant for each takeRemote path.");
|
|
893
|
+
for (const [index, path] of takeRemote.entries()) {
|
|
894
|
+
const grant = grants[index];
|
|
895
|
+
const normalizedPath = normalizeWorkspacePath(path);
|
|
896
|
+
if (!grant || writeGrants.get(grant) !== normalizedPath) throw workspaceError(`[vitehub] Workspace rebase to take remote ${path} requires a Source write grant for that path.`);
|
|
897
|
+
if (allSources.some((source) => (source.materialize === "lazy" || source.materialize === "startup") && sourceMountIntersectsPath(source, normalizedPath))) throw workspaceError(`[vitehub] Source-backed workspace paths are read-only: ${path}.`);
|
|
898
|
+
}
|
|
899
|
+
await withWorkspaceStoreMutation(store, async () => {
|
|
900
|
+
for (const grant of grants) await assertWritableCurrentPath(grant.path);
|
|
901
|
+
await rebase(options?.takeRemote ? {
|
|
902
|
+
...options,
|
|
903
|
+
takeRemote: grants.map((grant) => grant.path)
|
|
904
|
+
} : options);
|
|
905
|
+
});
|
|
906
|
+
};
|
|
907
|
+
}
|
|
908
|
+
const grantedStore = {
|
|
909
|
+
mkdir: requireWriteGrant(async (path, options) => await store.mkdir(path, options)),
|
|
910
|
+
rm: requireWriteGrant(async (path, options) => await store.rm(path, options)),
|
|
911
|
+
writeFile: requireWriteGrant(async (path, file, ifDigest) => {
|
|
912
|
+
if (ifDigest === void 0) return await store.writeFile(path, {
|
|
913
|
+
...file,
|
|
914
|
+
path
|
|
915
|
+
});
|
|
916
|
+
if (!store.writeFileConditional) throw workspaceError("[vitehub] This Workspace Store does not support conditional writes.");
|
|
917
|
+
await store.writeFileConditional(path, {
|
|
918
|
+
...file,
|
|
919
|
+
path
|
|
920
|
+
}, ifDigest);
|
|
921
|
+
})
|
|
922
|
+
};
|
|
796
923
|
return {
|
|
924
|
+
requireHistoryGrants(history, apply = (options) => history.commit(options)) {
|
|
925
|
+
return async (grants, options) => {
|
|
926
|
+
return await withWorkspaceStoreMutation(store, async () => {
|
|
927
|
+
const ref = normalizeHistoryRef(options.ref);
|
|
928
|
+
const head = await history.head({ ref });
|
|
929
|
+
if ((head?.id ?? null) !== options.ifHead) throw historyConflict(ref, options.ifHead, head?.id ?? null);
|
|
930
|
+
const forkRef = head || options.startFrom ? void 0 : await history.forksFrom?.(ref);
|
|
931
|
+
const startId = head?.id ?? options.startFrom ?? (forkRef ? (await history.head({ ref: forkRef }))?.id : void 0);
|
|
932
|
+
const previous = startId ? await history.open(startId) : void 0;
|
|
933
|
+
const entries = /* @__PURE__ */ new Map();
|
|
934
|
+
for (const entry of previous ? await previous.list("", { recursive: true }) : []) if (entry.type === "file") entries.set(entry.path, entry);
|
|
935
|
+
const historyDigest = async (content) => history.digest ? await history.digest(contentToBytes(content)) : await sha256(content);
|
|
936
|
+
const digestOf = async (path, entry) => entry.digest ?? await historyDigest(await previous.readFile(path, { encoding: "binary" }));
|
|
937
|
+
const sameFile = async (file, digest, entry, compute = historyDigest) => digest === await compute(file.content) && (file.mediaType === void 0 || entry.mediaType === file.mediaType) && (file.metadata === void 0 || JSON.stringify(entry.metadata) === JSON.stringify(file.metadata));
|
|
938
|
+
const next = (path) => {
|
|
939
|
+
if (options.files) return options.files[path];
|
|
940
|
+
if (options.changes.put && Object.hasOwn(options.changes.put, path)) return options.changes.put[path];
|
|
941
|
+
return options.changes.delete?.includes(path) ? void 0 : entries.get(path);
|
|
942
|
+
};
|
|
943
|
+
const candidates = options.files ? /* @__PURE__ */ new Set([...Object.keys(options.files), ...entries.keys()]) : /* @__PURE__ */ new Set([...Object.keys(options.changes.put ?? {}), ...options.changes.delete ?? []]);
|
|
944
|
+
const paths = [];
|
|
945
|
+
for (const path of candidates) {
|
|
946
|
+
const file = next(path);
|
|
947
|
+
const before = entries.get(path);
|
|
948
|
+
if (!file || !before || !("content" in file) || !await sameFile(file, await digestOf(path, before), before)) paths.push(path);
|
|
949
|
+
}
|
|
950
|
+
const authorized = new Set(grants.map((grant) => writeGrants.get(grant)));
|
|
951
|
+
if (authorized.has(void 0) || paths.some((path) => !authorized.has(path))) throw workspaceError("[vitehub] History publication requires a Source write grant for every affected path.");
|
|
952
|
+
for (const path of paths) await assertWritableCurrentPath(path);
|
|
953
|
+
if (history === store.history && ref === "main" && allSources.length) for (const entry of await store.list("", { recursive: true })) {
|
|
954
|
+
if (entry.type !== "file" || !allSources.some((source) => source.key === entry.metadata?.source)) continue;
|
|
955
|
+
const file = next(entry.path);
|
|
956
|
+
const digest = entry.digest ?? await sha256((await store.readFile(entry.path)).content);
|
|
957
|
+
if (!(file && ("content" in file ? await sameFile(file, digest, entry, sha256) : await digestOf(entry.path, file) === digest && file.mediaType === entry.mediaType && JSON.stringify(file.metadata) === JSON.stringify(entry.metadata)))) await assertWritableCurrentPath(entry.path);
|
|
958
|
+
}
|
|
959
|
+
return await apply({
|
|
960
|
+
...options,
|
|
961
|
+
ref,
|
|
962
|
+
startFrom: head ? options.startFrom : startId
|
|
963
|
+
});
|
|
964
|
+
});
|
|
965
|
+
};
|
|
966
|
+
},
|
|
797
967
|
async assertWritable(path) {
|
|
798
|
-
await
|
|
968
|
+
return await grantWritablePath(path);
|
|
799
969
|
},
|
|
970
|
+
assertWritableCurrentPath,
|
|
971
|
+
requireWriteGrant,
|
|
972
|
+
requireRebaseGrants,
|
|
800
973
|
async readFile(path, options) {
|
|
801
974
|
const descriptorSource = descriptorSourceForPath(normalizeWorkspacePath(path));
|
|
802
975
|
if (descriptorSource) return decodeFile(descriptorContent(descriptorSource), options);
|
|
803
976
|
const resolution = resolveWorkspacePath(definition, path);
|
|
804
977
|
if (resolution.type === "source") {
|
|
805
|
-
await ensurePrepared(resolution.sourceKey);
|
|
806
|
-
if (isLiveSource(resolution.sourceKey))
|
|
807
|
-
|
|
978
|
+
await ensurePrepared(resolution.sourceKey, resolution.workspacePath);
|
|
979
|
+
if (isLiveSource(resolution.sourceKey)) {
|
|
980
|
+
const item = await resolution.source.source.getItem(resolution.sourcePath, getSourceContext(resolution.source));
|
|
981
|
+
return decodeFile(await sourceItemContent(item), options);
|
|
982
|
+
}
|
|
983
|
+
if (resolution.source.materialize === "startup") await ensureMaterialized(resolution.sourceKey, true, resolution.workspacePath);
|
|
808
984
|
const cacheMaxAge = resolution.source.cache && resolution.source.cache.maxAge;
|
|
809
985
|
let shouldRefreshCachedLazy = false;
|
|
810
|
-
if (resolution.source.materialize === "lazy" && Number.isFinite(cacheMaxAge)) shouldRefreshCachedLazy = materializedSources.has(resolution.sourceKey) || Boolean(await readCurrentSourceSnapshot(store, resolution.source));
|
|
986
|
+
if (resolution.source.materialize === "lazy" && Number.isFinite(cacheMaxAge)) shouldRefreshCachedLazy = materializedSources.has(resolution.sourceKey) || Boolean(await readCurrentSourceSnapshot(store, definition.name, resolution.source));
|
|
811
987
|
if (shouldRefreshCachedLazy) await ensureMaterialized(resolution.sourceKey);
|
|
812
988
|
const file = await store.readFile(resolution.workspacePath);
|
|
813
989
|
if (file) return decodeFile(file.content, options);
|
|
814
|
-
await ensureMaterialized(resolution.sourceKey);
|
|
990
|
+
await ensureMaterialized(resolution.sourceKey, true, resolution.workspacePath);
|
|
815
991
|
return await readResolvedSourceFile(resolution, store, sourceContext, options);
|
|
816
992
|
}
|
|
817
|
-
await
|
|
993
|
+
await materializeRootStartupSources(false);
|
|
994
|
+
const startupFile = await readOwnedRootStartupFile(resolution.workspacePath);
|
|
995
|
+
if (startupFile) return decodeFile(startupFile.content, options);
|
|
996
|
+
if (!await materializeRootSourceForPath(resolution.workspacePath, false)) for (const source of sources.filter((source) => !source.mountPath && source.materialize === "startup")) await ensureMaterialized(source.key, true);
|
|
818
997
|
const file = await store.readFile(resolution.workspacePath);
|
|
819
998
|
if (!file) throw workspaceError(`[vitehub] Workspace file does not exist: ${path}.`);
|
|
820
999
|
return decodeFile(file.content, options);
|
|
821
1000
|
},
|
|
822
1001
|
async writeFile(path, content, options) {
|
|
823
|
-
const
|
|
1002
|
+
const metadata = assertPublicFileMetadata(path, options?.metadata);
|
|
1003
|
+
const requested = await grantWritablePath(path);
|
|
824
1004
|
const input = await writePolicy.before({
|
|
825
1005
|
content,
|
|
826
1006
|
mediaType: options?.mediaType,
|
|
827
|
-
metadata
|
|
1007
|
+
metadata,
|
|
828
1008
|
operation: "writeFile",
|
|
829
|
-
path:
|
|
830
|
-
previous: await previousStat(
|
|
1009
|
+
path: requested.path,
|
|
1010
|
+
previous: await previousStat(requested.path),
|
|
831
1011
|
workspace: definition.name
|
|
832
1012
|
});
|
|
833
1013
|
try {
|
|
834
|
-
if (options?.preservePath && input.path !==
|
|
835
|
-
const
|
|
836
|
-
|
|
1014
|
+
if (options?.preservePath && input.path !== requested.path) throw workspaceError(`[vitehub] Workspace validator cannot rewrite preserved path: ${requested.path} -> ${input.path}.`);
|
|
1015
|
+
const grant = await grantPolicyPath(input.path);
|
|
1016
|
+
await grantedStore.writeFile(grant, input.path, {
|
|
837
1017
|
content: input.content ?? content,
|
|
838
1018
|
mediaType: input.mediaType,
|
|
839
|
-
metadata: input.metadata
|
|
840
|
-
};
|
|
841
|
-
if (options?.ifDigest !== void 0) {
|
|
842
|
-
if (!store.writeFileConditional) throw workspaceError("[vitehub] This Workspace Store does not support conditional writes.");
|
|
843
|
-
await store.writeFileConditional(input.path, file, options.ifDigest);
|
|
844
|
-
} else await store.writeFile(input.path, file);
|
|
1019
|
+
metadata: assertPublicFileMetadata(input.path, input.metadata)
|
|
1020
|
+
}, options?.ifDigest);
|
|
845
1021
|
await writePolicy.after(input);
|
|
846
|
-
return
|
|
1022
|
+
return grant.path;
|
|
847
1023
|
} catch (error) {
|
|
848
1024
|
await writePolicy.error(input, error);
|
|
849
1025
|
throw error;
|
|
@@ -854,14 +1030,17 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
854
1030
|
},
|
|
855
1031
|
async glob(pattern, options) {
|
|
856
1032
|
const patterns = Array.isArray(pattern) ? pattern : [pattern];
|
|
1033
|
+
const { cwd, matches } = createWorkspaceGlobMatcher(patterns, options);
|
|
857
1034
|
await ensurePreparedSources();
|
|
858
1035
|
await ensureMaterializedSources(sources.filter((source) => !usesLiveProvider(source)));
|
|
859
1036
|
const result = /* @__PURE__ */ new Map();
|
|
860
|
-
|
|
861
|
-
|
|
1037
|
+
if (cwd !== ".vitehub/sources") {
|
|
1038
|
+
for (const entry of await store.glob(patterns, options)) if (matches(entry.path)) result.set(entry.path, entry);
|
|
1039
|
+
}
|
|
1040
|
+
for (const entry of descriptorPathEntries(cwd, { recursive: true })) if (entry.type === "file" && matches(entry.path)) result.set(entry.path, entry);
|
|
862
1041
|
for (const source of sources.filter(usesLiveProvider)) {
|
|
863
1042
|
await pruneLiveSourceStoreEntries(result, source);
|
|
864
|
-
for (const entry of liveSourceEntries(source)) if (entry.type === "file" &&
|
|
1043
|
+
for (const entry of liveSourceEntries(source)) if (entry.type === "file" && matches(entry.path)) result.set(entry.path, entry);
|
|
865
1044
|
}
|
|
866
1045
|
return [...result.values()].sort((left, right) => left.path.localeCompare(right.path));
|
|
867
1046
|
},
|
|
@@ -886,12 +1065,13 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
886
1065
|
if (resolution.source.materialize === "startup") await ensureMaterialized(resolution.sourceKey);
|
|
887
1066
|
const stored = await store.stat(resolution.workspacePath);
|
|
888
1067
|
if (stored) return stored;
|
|
889
|
-
if (resolution.source.materialize === "startup" && completedSources.has(resolution.sourceKey)) throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
|
|
1068
|
+
if (resolution.source.materialize === "startup" && (completedSources.has(resolution.sourceKey) || reusedStartupSources.has(resolution.sourceKey))) throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
|
|
890
1069
|
await ensureMaterialized(resolution.sourceKey);
|
|
891
1070
|
const result = await statVirtualSourcePath(resolution.source, resolution.workspacePath, store, getSourceContext(resolution.source));
|
|
892
1071
|
if (!result) throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
|
|
893
1072
|
return result;
|
|
894
1073
|
}
|
|
1074
|
+
await materializeRootStartupSources();
|
|
895
1075
|
let result = await store.stat(resolution.workspacePath);
|
|
896
1076
|
if (!result) {
|
|
897
1077
|
if (!resolution.workspacePath && sources.some((source) => !source.mountPath && usesLiveProvider(source))) return {
|
|
@@ -918,25 +1098,26 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
918
1098
|
}
|
|
919
1099
|
if (resolution.source.materialize === "startup") await ensureMaterialized(resolution.sourceKey);
|
|
920
1100
|
if (await store.stat(resolution.workspacePath)) return true;
|
|
921
|
-
if (resolution.source.materialize === "startup" && completedSources.has(resolution.sourceKey)) return false;
|
|
1101
|
+
if (resolution.source.materialize === "startup" && (completedSources.has(resolution.sourceKey) || reusedStartupSources.has(resolution.sourceKey))) return false;
|
|
922
1102
|
await ensureMaterialized(resolution.sourceKey);
|
|
923
1103
|
return Boolean(await statVirtualSourcePath(resolution.source, resolution.workspacePath, store, getSourceContext(resolution.source)));
|
|
924
1104
|
}
|
|
1105
|
+
await materializeRootStartupSources();
|
|
925
1106
|
if (await store.stat(resolution.workspacePath)) return true;
|
|
926
1107
|
if (!resolution.workspacePath && sources.some((source) => !source.mountPath && usesLiveProvider(source))) return true;
|
|
927
1108
|
await materializeRootSourceForPath(resolution.workspacePath);
|
|
928
1109
|
return Boolean(await store.stat(resolution.workspacePath));
|
|
929
1110
|
},
|
|
930
1111
|
async mkdir(path, options) {
|
|
931
|
-
const
|
|
1112
|
+
const requested = await grantWritablePath(path);
|
|
932
1113
|
const input = await writePolicy.before({
|
|
933
1114
|
operation: "mkdir",
|
|
934
|
-
path:
|
|
935
|
-
previous: await previousStat(
|
|
1115
|
+
path: requested.path,
|
|
1116
|
+
previous: await previousStat(requested.path),
|
|
936
1117
|
workspace: definition.name
|
|
937
1118
|
});
|
|
938
1119
|
try {
|
|
939
|
-
await
|
|
1120
|
+
await grantedStore.mkdir(await grantPolicyPath(input.path), input.path, options);
|
|
940
1121
|
await writePolicy.after(input);
|
|
941
1122
|
} catch (error) {
|
|
942
1123
|
await writePolicy.error(input, error);
|
|
@@ -944,15 +1125,15 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
944
1125
|
}
|
|
945
1126
|
},
|
|
946
1127
|
async rm(path, options) {
|
|
947
|
-
const
|
|
1128
|
+
const requested = await grantWritablePath(path);
|
|
948
1129
|
const input = await writePolicy.before({
|
|
949
1130
|
operation: "rm",
|
|
950
|
-
path:
|
|
951
|
-
previous: await previousStat(
|
|
1131
|
+
path: requested.path,
|
|
1132
|
+
previous: await previousStat(requested.path),
|
|
952
1133
|
workspace: definition.name
|
|
953
1134
|
});
|
|
954
1135
|
try {
|
|
955
|
-
await
|
|
1136
|
+
await grantedStore.rm(await grantPolicyPath(input.path), input.path, options);
|
|
956
1137
|
await writePolicy.after(input);
|
|
957
1138
|
} catch (error) {
|
|
958
1139
|
await writePolicy.error(input, error);
|
|
@@ -1021,10 +1202,19 @@ function isListedLiveEntry(entry, path, options) {
|
|
|
1021
1202
|
return !entry.path.slice(path.length + 1).includes("/");
|
|
1022
1203
|
}
|
|
1023
1204
|
function liveSourceStat(source, workspacePath) {
|
|
1024
|
-
|
|
1205
|
+
const paths = source.livePaths;
|
|
1206
|
+
if (!paths) return;
|
|
1207
|
+
if (Object.hasOwn(paths, workspacePath)) return {
|
|
1208
|
+
path: workspacePath,
|
|
1209
|
+
type: "file"
|
|
1210
|
+
};
|
|
1211
|
+
if (Object.keys(paths).some((path) => path.startsWith(`${workspacePath}/`))) return {
|
|
1212
|
+
path: workspacePath,
|
|
1213
|
+
type: "directory"
|
|
1214
|
+
};
|
|
1025
1215
|
}
|
|
1026
1216
|
async function currentSourceTreePaths(source, sourceContext) {
|
|
1027
|
-
const allowed = new Set([source.mountPath]);
|
|
1217
|
+
const allowed = /* @__PURE__ */ new Set([source.mountPath]);
|
|
1028
1218
|
const keys = await source.source.getKeys(sourceContext);
|
|
1029
1219
|
for (const key of keys) {
|
|
1030
1220
|
const parts = `${source.mountPath}/${key}`.replace(/\/+/g, "/").split("/");
|
|
@@ -1042,38 +1232,67 @@ function dedupeHits(hits) {
|
|
|
1042
1232
|
});
|
|
1043
1233
|
}
|
|
1044
1234
|
//#endregion
|
|
1235
|
+
//#region src/storage/metadata-keys.ts
|
|
1236
|
+
const internalMetaKeyPrefixes = [
|
|
1237
|
+
"source:",
|
|
1238
|
+
"workspace:",
|
|
1239
|
+
"workspace-file-",
|
|
1240
|
+
"loader:"
|
|
1241
|
+
];
|
|
1242
|
+
function isInternalWorkspaceMetaKey(key) {
|
|
1243
|
+
const forms = [key.toLowerCase(), normalizeWorkspacePath(key).toLowerCase()];
|
|
1244
|
+
return internalMetaKeyPrefixes.some((prefix) => forms.some((form) => form.startsWith(prefix)));
|
|
1245
|
+
}
|
|
1246
|
+
/** Rejects keys that Workspace internals own. Public `setMeta` calls this before it writes. */
|
|
1247
|
+
function assertPublicWorkspaceMetaKey(key) {
|
|
1248
|
+
if (typeof key !== "string") throw workspaceError("[vitehub] Workspace metadata keys must be strings.");
|
|
1249
|
+
if (isInternalWorkspaceMetaKey(key)) throw workspaceError(`[vitehub] Workspace metadata key ${JSON.stringify(key)} is reserved for Workspace internals.`);
|
|
1250
|
+
return key;
|
|
1251
|
+
}
|
|
1252
|
+
//#endregion
|
|
1045
1253
|
//#region src/core/workspace-cache.ts
|
|
1046
|
-
|
|
1254
|
+
const workspaceStoreCacheKey = Symbol.for("vitehub.workspace.storeCache");
|
|
1255
|
+
function storeByDefinition() {
|
|
1256
|
+
const scope = globalThis;
|
|
1257
|
+
return scope[workspaceStoreCacheKey] ??= /* @__PURE__ */ new WeakMap();
|
|
1258
|
+
}
|
|
1047
1259
|
function getCachedWorkspaceStore(definition, create) {
|
|
1048
|
-
|
|
1260
|
+
const cache = storeByDefinition();
|
|
1261
|
+
let store = cache.get(definition);
|
|
1049
1262
|
if (!store) {
|
|
1050
1263
|
store = create();
|
|
1051
|
-
|
|
1264
|
+
cache.set(definition, store);
|
|
1052
1265
|
}
|
|
1053
1266
|
return store;
|
|
1054
1267
|
}
|
|
1055
1268
|
function invalidateCachedWorkspaceStore(definition) {
|
|
1056
|
-
storeByDefinition.delete(definition);
|
|
1269
|
+
storeByDefinition().delete(definition);
|
|
1057
1270
|
}
|
|
1058
1271
|
function resetWorkspaceStoreCache() {
|
|
1059
|
-
|
|
1272
|
+
const scope = globalThis;
|
|
1273
|
+
scope[workspaceStoreCacheKey] = /* @__PURE__ */ new WeakMap();
|
|
1060
1274
|
}
|
|
1061
1275
|
//#endregion
|
|
1062
1276
|
//#region src/core/workspace.ts
|
|
1063
1277
|
function getStore(definition) {
|
|
1064
|
-
return getCachedWorkspaceStore(definition, () => createWorkspaceStoreFromProvider(definition));
|
|
1278
|
+
return getCachedWorkspaceStore(definition, () => trackStagedWrites(createWorkspaceStoreFromProvider(definition)));
|
|
1065
1279
|
}
|
|
1066
|
-
function createWorkspace(definition) {
|
|
1280
|
+
function createWorkspace(definition, options = {}) {
|
|
1067
1281
|
const store = getStore(definition);
|
|
1068
|
-
const files = createWorkspaceSourceView(definition, store);
|
|
1282
|
+
const files = createWorkspaceSourceView(definition, store, options);
|
|
1283
|
+
const metadata = createWorkspaceMetadataTarget(store, definition.name);
|
|
1284
|
+
const rebaseStore = files.requireRebaseGrants(async (options) => await store.rebase?.(options));
|
|
1069
1285
|
const workspace = {
|
|
1070
|
-
[workspaceMetadataTarget]: () => store,
|
|
1071
1286
|
name: definition.name,
|
|
1287
|
+
history: createWorkspaceHistory(definition, store, files),
|
|
1072
1288
|
async capabilities() {
|
|
1073
|
-
return {
|
|
1289
|
+
return {
|
|
1290
|
+
conditionalWrites: typeof store.writeFileConditional === "function",
|
|
1291
|
+
retainedHistory: Boolean(store.history)
|
|
1292
|
+
};
|
|
1074
1293
|
},
|
|
1075
1294
|
async sync(options) {
|
|
1076
|
-
const { syncWorkspaceSources } = await import("./sync-
|
|
1295
|
+
const { syncWorkspaceSources } = await import("./sync-CCD_VYC8.js");
|
|
1077
1296
|
return await syncWorkspaceSources(definition, store, options);
|
|
1078
1297
|
},
|
|
1079
1298
|
async materializeSources(options) {
|
|
@@ -1082,8 +1301,9 @@ function createWorkspace(definition) {
|
|
|
1082
1301
|
async getMeta(key) {
|
|
1083
1302
|
return await store.getMeta?.(key);
|
|
1084
1303
|
},
|
|
1085
|
-
async setMeta(key, value) {
|
|
1086
|
-
|
|
1304
|
+
async setMeta(key, value, capability) {
|
|
1305
|
+
const metadataKey = capability === workspaceInternalMetadataCapability ? key : assertPublicWorkspaceMetaKey(key);
|
|
1306
|
+
await store.setMeta?.(metadataKey, value);
|
|
1087
1307
|
},
|
|
1088
1308
|
async readFile(path, options) {
|
|
1089
1309
|
return await files.readFile(path, options);
|
|
@@ -1112,19 +1332,14 @@ function createWorkspace(definition) {
|
|
|
1112
1332
|
async rm(path, options) {
|
|
1113
1333
|
await files.rm(path, options);
|
|
1114
1334
|
},
|
|
1115
|
-
async publish(options) {
|
|
1116
|
-
const { publishWorkspace } = await import("./lifecycle-LrL3sA4n.js").then((n) => n.t);
|
|
1117
|
-
await publishWorkspace(definition, store, options);
|
|
1118
|
-
},
|
|
1119
1335
|
async snapshot(options) {
|
|
1120
|
-
|
|
1121
|
-
const { publishWorkspaceSnapshot } = await import("./lifecycle-LrL3sA4n.js").then((n) => n.t);
|
|
1122
|
-
await publishWorkspaceSnapshot(definition, store, snapshot);
|
|
1123
|
-
return snapshot;
|
|
1336
|
+
return await store.snapshot(options);
|
|
1124
1337
|
},
|
|
1125
1338
|
async rebase(options) {
|
|
1126
|
-
if (!store.rebase) throw
|
|
1127
|
-
|
|
1339
|
+
if (!store.rebase) throw workspaceErrorDiagnostics.WORKSPACE_R0026({ message: "[vitehub] Workspace Store does not support rebasing." });
|
|
1340
|
+
const grants = [];
|
|
1341
|
+
for (const path of options?.takeRemote ?? []) grants.push(await files.assertWritable(path));
|
|
1342
|
+
await rebaseStore(grants, options);
|
|
1128
1343
|
},
|
|
1129
1344
|
async diff(options) {
|
|
1130
1345
|
return await store.diff(options);
|
|
@@ -1132,7 +1347,7 @@ function createWorkspace(definition) {
|
|
|
1132
1347
|
async startSession(options) {
|
|
1133
1348
|
const host = options?.host;
|
|
1134
1349
|
if (host) {
|
|
1135
|
-
const { createHostedWorkspaceSession } = await import("./host-
|
|
1350
|
+
const { createHostedWorkspaceSession } = await import("./host-BFBpXn0N.js").then((n) => n.n);
|
|
1136
1351
|
return await createHostedWorkspaceSession(workspace, {
|
|
1137
1352
|
...options,
|
|
1138
1353
|
host
|
|
@@ -1141,15 +1356,16 @@ function createWorkspace(definition) {
|
|
|
1141
1356
|
return await createBasicWorkspaceSession(workspace, options);
|
|
1142
1357
|
}
|
|
1143
1358
|
};
|
|
1359
|
+
attachWorkspaceMetadataTarget(workspace, () => metadata);
|
|
1144
1360
|
forwardWorkspaceStoreTarget(store, workspace);
|
|
1145
1361
|
if (!normalizeWorkspaceSources(definition.sources).some((source) => source.requestDescriptor || source.livePaths)) forwardWorkspaceRevisionMaterializer(store, workspace);
|
|
1146
1362
|
const synchronizedWorkspace = workspace;
|
|
1147
1363
|
synchronizedWorkspace.__workspaceDefinitionSyncKey = definition;
|
|
1148
1364
|
synchronizedWorkspace.__syncWorkspaceDefinition = async (abortSignal) => {
|
|
1149
|
-
const { syncWorkspaceDefinition } = await import("./lifecycle-
|
|
1365
|
+
const { syncWorkspaceDefinition } = await import("./lifecycle-B-enk_4A.js").then((n) => n.t);
|
|
1150
1366
|
await syncWorkspaceDefinition(definition, store, abortSignal);
|
|
1151
1367
|
};
|
|
1152
1368
|
return attachWorkspaceSourceRequestExecution(workspace, createWorkspaceSourceRequestExecution(definition));
|
|
1153
1369
|
}
|
|
1154
1370
|
//#endregion
|
|
1155
|
-
export { isMissingWorkspacePathError as _,
|
|
1371
|
+
export { isMissingWorkspacePathError as C, filterSessionEntries as S, workspaceSourceRequestMatches as _, isInternalWorkspaceMetaKey as a, assertPathInSessionScope as b, isWorkspaceSourceSyncMetaKey as c, sourceSyncPathClaims as d, workspaceSourceSyncStateEquals as f, getWorkspaceSourceRequestExecution as g, createWorkspaceSourceRequestExecution as h, assertPublicWorkspaceMetaKey as i, readWorkspaceSourceSyncState as l, attachWorkspaceSourceRequestExecution as m, invalidateCachedWorkspaceStore as n, createWorkspaceSourceView as o, resolveWorkspacePath as p, resetWorkspaceStoreCache as r, invalidateWorkspaceSourceMaterialization as s, createWorkspace as t, sourceSyncMetaKey as u, createBasicWorkspaceSession as v, scopedSearchQuery as w, filterSessionDiff as x, assertDiffInsideSessionPaths as y };
|