@vite-hub/workspace 0.6.1 → 0.7.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 +5 -5
- package/dist/{asset-registry-0CdRAjIV.js → asset-registry-DJyE42kr.js} +1 -1
- package/dist/blob-database.d.ts +1 -1
- package/dist/blob-database.js +6 -6
- package/dist/checkout.js +2 -2
- package/dist/cloudflare.d.ts +1 -1
- package/dist/cloudflare.js +1 -1
- package/dist/{config-jo5QgE1w.js → config--ZzAvhMp.js} +14 -9
- package/dist/{config-DeA287c0.d.ts → config-DF6sqKXB.d.ts} +1 -1
- package/dist/durability.d.ts +1 -1
- package/dist/durability.js +2 -2
- package/dist/{error-diagnostics-B4me-ouV.js → error-diagnostics-CHgE8TQM.js} +16 -0
- package/dist/{error-diagnostics-kKXseq8d.js → error-diagnostics-CsiNo_oI.js} +3 -3
- package/dist/{file-BrNAXQgY.js → file-DQ5-TBTD.js} +1 -1
- package/dist/{file-metadata-Bpsvjw_X.js → file-metadata-Dqpldj0h.js} +7 -2
- package/dist/{files--z2dLC5z.js → files-D1UkSjzX.js} +2 -2
- package/dist/files.d.ts +5 -5
- package/dist/files.js +5 -5
- package/dist/{github-k--_LCrX.js → github-BECfOMaw.js} +4 -4
- package/dist/{glob-BreFjNAV.js → glob-BIg9O4yY.js} +2 -2
- package/dist/{glob-BEutagp1.js → glob-BIsxLusH.js} +1 -1
- package/dist/{host-C8yZizfk.js → host-BYBRcSnh.js} +7 -7
- package/dist/hosted-vercel-blob.d.ts +1 -1
- package/dist/hosted-vercel-blob.js +464 -1
- package/dist/hosted.d.ts +1 -1
- package/dist/hosted.js +917 -1
- package/dist/index.d.ts +6 -7
- package/dist/index.js +13 -13
- package/dist/internal/path.js +108 -1
- package/dist/internal/workspace.d.ts +2 -3
- package/dist/internal/workspace.js +2 -2
- package/dist/{lifecycle-IReZfi0b.js → lifecycle-BK7WNfcP.js} +8 -8
- package/dist/loader.d.ts +1 -1
- package/dist/loader.js +2 -2
- package/dist/{mcp-resources-DeJnbOaw.js → mcp-resources-F4SJF4_P.js} +2 -2
- package/dist/{memory-BlSRrBH1.js → memory-BCZl_ZsJ.js} +26 -4
- package/dist/{metadata-target-CaGLY4ay.js → metadata-target-DPGF6L68.js} +59 -24
- package/dist/{operation-definition-CqZkx1Rm.d.ts → operations-BALFFdKj.d.ts} +1 -0
- package/dist/{operations-BIaK_uYG.js → operations-DJ_7W0gs.js} +8 -7
- package/dist/operations.d.ts +2 -2
- package/dist/operations.js +1327 -2
- package/dist/{path-Bb9OIc_F.js → path-DYHw5KNk.js} +11 -3
- package/dist/plugins-BYxsPDBH.d.ts +12 -0
- package/dist/{provider-CN14ewvx.js → provider-fcI7kJ5k.js} +256 -70
- package/dist/providers/github/store.d.ts +1 -1
- package/dist/providers/github/store.js +1994 -1
- package/dist/{registry-BbUg9vJB.js → registry-CFeUQsja.js} +3 -3
- package/dist/{registry-B0g19sdy.d.ts → registry-h1-cT-cE.d.ts} +1 -1
- package/dist/{registry-s2Ob9PeX.d.ts → registry-hnARUKNF.d.ts} +2 -2
- package/dist/replacement-CVZVsflC.js +76 -0
- package/dist/{request-scope-CXCI_wCb.js → request-scope-jH4H0Sbm.js} +3 -1
- package/dist/{rule-keys-BLEbi1h5.js → rule-keys-xMpiTLq1.js} +1 -1
- package/dist/{rules-BPDXypZV.js → rules-DYQCKYdt.js} +4 -4
- package/dist/runtime/assets.d.ts +1 -1
- package/dist/runtime/assets.js +4 -4
- package/dist/runtime/empty-assets-registry.d.ts +1 -1
- package/dist/runtime/empty-registry.d.ts +2 -2
- package/dist/runtime/registry.d.ts +1 -1
- package/dist/runtime/request.js +1 -1
- package/dist/runtime/state.d.ts +17 -6
- package/dist/runtime/state.js +7 -7
- package/dist/runtime/workspace.d.ts +1 -1
- package/dist/runtime/workspace.js +1 -1
- package/dist/runtime.d.ts +8 -8
- package/dist/runtime.js +38 -23
- package/dist/{search-C_nVorq7.js → search-CG6UNOtn.js} +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.js +301 -1
- package/dist/{shared-C20Wh1mp.js → shared-PFnkYidS.js} +59 -21
- package/dist/source-metadata.d.ts +2 -2
- package/dist/source-metadata.js +3 -3
- package/dist/{sync-BBfR4g5y.js → sync-CUkCuP_g.js} +5 -5
- package/dist/test.d.ts +1 -1
- package/dist/test.js +1 -1
- package/dist/{types-Bel5IDmF.d.ts → types-BnSUug2v.d.ts} +13 -1
- package/dist/{use-D0DyTMxM.js → use-BCMkT-kC.js} +15 -51
- package/dist/{use-CpphIBof.d.ts → use-CJ5rdIrW.d.ts} +1 -1
- package/dist/{use-tools-CHduR5k6.js → use-tools-CcXs2hFA.js} +4 -4
- package/dist/{use-tools-CAK10LTc.d.ts → use-tools-DFVqZwgc.d.ts} +2 -2
- package/dist/{utils-DXP9xfXo.js → utils-Bv1NBg8r.js} +5 -5
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +368 -62
- package/dist/{workspace-BOuxrZrP.d.ts → workspace-B6QreLJd.d.ts} +1 -1
- package/dist/{workspace-CLuPkyZR.js → workspace-D1m00MCM.js} +340 -104
- package/dist/workspace-inspection-scanner-BlJ8bCAB.js +140 -0
- package/package.json +12 -12
- package/dist/errors-CnFDXxeJ.d.ts +0 -4
- package/dist/hosted-8BTKAtMX.js +0 -883
- package/dist/hosted-vercel-blob-B6kygYqn.js +0 -408
- package/dist/operations-DS1C4uXd.js +0 -1308
- package/dist/path-CuYE8-X6.js +0 -57
- package/dist/plugins-CLc32jvL.d.ts +0 -8
- package/dist/server-aa1a4rkV.js +0 -301
- package/dist/state-BdDfBtOR.d.ts +0 -17
- package/dist/store-cx3OqNTi.js +0 -1971
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as isExcludedWorkspacePath,
|
|
3
|
-
import { t as searchText } from "./search-
|
|
4
|
-
import { t as createMemoryWorkspaceStore } from "./memory-
|
|
5
|
-
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
|
|
6
|
-
import { t as workspaceErrorDiagnostics } from "./error-diagnostics-
|
|
7
|
-
import { f as normalizeHistoryRef, i as createWorkspaceHistory, m as rejectHistoryHead, u as historyConflict } from "./utils-
|
|
8
|
-
import { t as
|
|
9
|
-
import { t as createWorkspaceGlobMatcher } from "./glob-
|
|
10
|
-
import { t as createWorkspaceWritePolicy } from "./rules-
|
|
11
|
-
import {
|
|
12
|
-
import { t as
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
1
|
+
import { l as workspaceSourceReadOnlyError, n as isWorkspaceConflict, normalizeSafeWorkspacePath, o as workspaceError } from "./internal/path.js";
|
|
2
|
+
import { a as isExcludedWorkspacePath, f as sha256, i as decodeFile, l as normalizeWorkspacePath, n as contentStreamToBytes, r as contentToBytes, s as matchesAny, u as readStoredFile } from "./path-DYHw5KNk.js";
|
|
3
|
+
import { t as searchText } from "./search-CG6UNOtn.js";
|
|
4
|
+
import { t as createMemoryWorkspaceStore } from "./memory-BCZl_ZsJ.js";
|
|
5
|
+
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--ZzAvhMp.js";
|
|
6
|
+
import { t as workspaceErrorDiagnostics } from "./error-diagnostics-CHgE8TQM.js";
|
|
7
|
+
import { f as normalizeHistoryRef, i as createWorkspaceHistory, m as rejectHistoryHead, u as historyConflict } from "./utils-Bv1NBg8r.js";
|
|
8
|
+
import { t as assertPublicFileMetadata } from "./file-metadata-Dqpldj0h.js";
|
|
9
|
+
import { t as createWorkspaceGlobMatcher } from "./glob-BIg9O4yY.js";
|
|
10
|
+
import { t as createWorkspaceWritePolicy } from "./rules-DYQCKYdt.js";
|
|
11
|
+
import { i as forwardWorkspaceStoreTarget, o as resolveWorkspaceStoreTarget, t as forwardWorkspaceRevisionMaterializer } from "./vitehub-grants-Co713QTg.js";
|
|
12
|
+
import { i as replaceStorePath, n as getWorkspaceReplacement, o as requireWorkspaceReplacement, r as prepareWorkspaceReplacement, t as attachWorkspaceReplacement } from "./replacement-CVZVsflC.js";
|
|
13
|
+
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-DPGF6L68.js";
|
|
14
|
+
import { t as createWorkspaceStoreFromProvider } from "./provider-fcI7kJ5k.js";
|
|
15
|
+
import { n as trackStagedWrites } from "./request-scope-jH4H0Sbm.js";
|
|
15
16
|
import { noExecutionAuthority } from "@vite-hub/runtime";
|
|
17
|
+
import { posix } from "node:path";
|
|
18
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
19
|
+
import { Buffer } from "node:buffer";
|
|
16
20
|
// src/session/scope.ts
|
|
17
21
|
function isMissingWorkspacePathError(error) {
|
|
18
22
|
return error instanceof Error && error.message.includes("Workspace path does not exist:");
|
|
@@ -89,7 +93,7 @@ async function createBasicWorkspaceSession(workspace, options) {
|
|
|
89
93
|
const initialEntries = filterSessionEntries(await workspace.list("", { recursive: true }), sessionPaths);
|
|
90
94
|
for (const entry of initialEntries.filter((entry) => entry.type === "directory")) await overlay.mkdir(entry.path, { recursive: true });
|
|
91
95
|
for (const entry of initialEntries.filter((entry) => entry.type === "file")) await overlay.writeFile(entry.path, {
|
|
92
|
-
content: await workspace
|
|
96
|
+
content: await readStoredFile(workspace, entry.path),
|
|
93
97
|
mediaType: entry.mediaType,
|
|
94
98
|
metadata: entry.metadata,
|
|
95
99
|
path: entry.path
|
|
@@ -267,6 +271,108 @@ function serializedQuery(query) {
|
|
|
267
271
|
}
|
|
268
272
|
return queryFromUrl(new URL(`https://vitehub.local/?${params}`));
|
|
269
273
|
}
|
|
274
|
+
// src/fs-ops.ts
|
|
275
|
+
async function readTree(workspace, from, to, type, mediaType) {
|
|
276
|
+
if (type === "file") return {
|
|
277
|
+
directories: [],
|
|
278
|
+
files: [{
|
|
279
|
+
content: await readStoredFile(workspace, from),
|
|
280
|
+
mediaType,
|
|
281
|
+
path: to
|
|
282
|
+
}]
|
|
283
|
+
};
|
|
284
|
+
const entries = await workspace.list(from, { recursive: true });
|
|
285
|
+
const target = (path) => posix.join(to, posix.relative(from, path));
|
|
286
|
+
return {
|
|
287
|
+
directories: [to, ...entries.filter((entry) => entry.type === "directory").map((entry) => target(entry.path))].sort((left, right) => left.length - right.length),
|
|
288
|
+
files: await Promise.all(entries.filter((entry) => entry.type === "file").map(async (entry) => ({
|
|
289
|
+
content: await readStoredFile(workspace, entry.path),
|
|
290
|
+
mediaType: entry.mediaType,
|
|
291
|
+
path: target(entry.path)
|
|
292
|
+
})))
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
async function writeTree(workspace, tree) {
|
|
296
|
+
for (const directory of tree.directories) await workspace.mkdir(directory, { recursive: true });
|
|
297
|
+
for (const file of tree.files) await workspace.writeFile(file.path, file.content, { mediaType: file.mediaType });
|
|
298
|
+
}
|
|
299
|
+
async function copyWorkspacePath(workspace, from, to, overwrite = false) {
|
|
300
|
+
from = normalizeSafeWorkspacePath(from, { allowReserved: true });
|
|
301
|
+
to = normalizeSafeWorkspacePath(to, { allowReserved: true });
|
|
302
|
+
if (from === to) throw workspaceError("[vitehub] Source and destination must be different.");
|
|
303
|
+
const source = await workspace.stat(from);
|
|
304
|
+
if (source.type === "directory" && to.startsWith(`${from}/`)) throw workspaceError("[vitehub] Destination cannot be nested inside the source directory.");
|
|
305
|
+
if (from.startsWith(`${to}/`)) throw workspaceError("[vitehub] Destination cannot contain the source.");
|
|
306
|
+
const storeTarget = overwrite ? await resolveWorkspaceStoreTarget(workspace) : void 0;
|
|
307
|
+
if (await storeTarget?.containsPath?.(to, from)) throw workspaceError("[vitehub] Destination cannot contain the source.");
|
|
308
|
+
const destination = await workspace.exists(to) ? await workspace.stat(to) : void 0;
|
|
309
|
+
if (destination && !overwrite) throw workspaceError(`[vitehub] Workspace path already exists: ${to}.`);
|
|
310
|
+
const copied = await readTree(workspace, from, to, source.type, source.mediaType);
|
|
311
|
+
if (!destination) return await writeTree(workspace, copied);
|
|
312
|
+
const removeTree = source.type === "directory" || destination.type === "directory" || Boolean(await storeTarget?.hasFileDescendants?.(to));
|
|
313
|
+
const replace = getWorkspaceReplacement(workspace);
|
|
314
|
+
if (!removeTree && !replace) return await writeTree(workspace, copied);
|
|
315
|
+
await (replace ?? requireWorkspaceReplacement(workspace))({
|
|
316
|
+
...copied,
|
|
317
|
+
path: to,
|
|
318
|
+
removeTree
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
const appendQueues = /* @__PURE__ */ new WeakMap();
|
|
322
|
+
const activeAppends = new AsyncLocalStorage();
|
|
323
|
+
const appendCondition = Symbol.for("vitehub.workspace.appendCondition");
|
|
324
|
+
async function inAppendQueue(workspace, path, append) {
|
|
325
|
+
const parents = activeAppends.getStore() ?? [];
|
|
326
|
+
if (parents.some((parent) => parent.active && parent.name === workspace.name && parent.path === path)) throw workspaceError(`[vitehub] Workspace write hooks cannot reenter appendFile for ${path}.`);
|
|
327
|
+
const queues = appendQueues.get(workspace) ?? /* @__PURE__ */ new Map();
|
|
328
|
+
appendQueues.set(workspace, queues);
|
|
329
|
+
const previous = queues.get(path) ?? Promise.resolve();
|
|
330
|
+
const entry = {
|
|
331
|
+
name: workspace.name,
|
|
332
|
+
path,
|
|
333
|
+
active: true
|
|
334
|
+
};
|
|
335
|
+
const current = previous.then(async () => await activeAppends.run([...parents, entry], append));
|
|
336
|
+
const settled = current.then(() => void 0, () => void 0);
|
|
337
|
+
queues.set(path, settled);
|
|
338
|
+
try {
|
|
339
|
+
await current;
|
|
340
|
+
} finally {
|
|
341
|
+
entry.active = false;
|
|
342
|
+
if (queues.get(path) === settled) queues.delete(path);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
function appendContent(base, suffix) {
|
|
346
|
+
if (base === void 0 || typeof base === "string") return `${base ?? ""}${suffix}`;
|
|
347
|
+
const bytes = Buffer.from(base);
|
|
348
|
+
const text = bytes.toString("utf8");
|
|
349
|
+
return bytes.equals(Buffer.from(text)) ? `${text}${suffix}` : Buffer.concat([bytes, contentToBytes(suffix)]);
|
|
350
|
+
}
|
|
351
|
+
const appendAttempts = 20;
|
|
352
|
+
async function appendWorkspaceFile(workspace, path, content) {
|
|
353
|
+
path = normalizeSafeWorkspacePath(path, { allowReserved: true });
|
|
354
|
+
await inAppendQueue(workspace, path, async () => {
|
|
355
|
+
for (let attempt = 1;; attempt++) {
|
|
356
|
+
const base = await workspace.exists(path) ? await readStoredFile(workspace, path) : void 0;
|
|
357
|
+
let conflict;
|
|
358
|
+
const options = {
|
|
359
|
+
preservePath: true,
|
|
360
|
+
[appendCondition]: {
|
|
361
|
+
base,
|
|
362
|
+
onConflict: (error) => {
|
|
363
|
+
conflict = { error };
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
try {
|
|
368
|
+
await workspace.writeFile(path, appendContent(base, content), options);
|
|
369
|
+
return;
|
|
370
|
+
} catch (error) {
|
|
371
|
+
if (!conflict || conflict.error !== error || attempt === appendAttempts) throw error;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
}
|
|
270
376
|
// src/sources/resolver.ts
|
|
271
377
|
function resolveWorkspacePath(definition, path) {
|
|
272
378
|
const workspacePath = normalizeSafeWorkspacePath(path, { allowEmpty: true });
|
|
@@ -353,11 +459,6 @@ function canonicalSourceSyncState(state) {
|
|
|
353
459
|
};
|
|
354
460
|
}
|
|
355
461
|
// src/sources/view.ts
|
|
356
|
-
function assertPublicFileMetadata(path, metadata) {
|
|
357
|
-
metadata = copyJsonFileMetadata(path, metadata);
|
|
358
|
-
if (metadata && Object.hasOwn(metadata, "source")) throw workspaceError(`[vitehub] Invalid Workspace metadata for ${path}. metadata.source is reserved for Source materialization.`);
|
|
359
|
-
return metadata;
|
|
360
|
-
}
|
|
361
462
|
/**
|
|
362
463
|
* Proof that one Source view checked one normalized Workspace path for writes.
|
|
363
464
|
* Only `assertWritable` creates a grant. A grant is request-scoped. Do not persist it.
|
|
@@ -372,7 +473,55 @@ var WorkspaceSourceWriteGrant = class {
|
|
|
372
473
|
return this.#path;
|
|
373
474
|
}
|
|
374
475
|
};
|
|
476
|
+
function createMaterializationPreview(base) {
|
|
477
|
+
const memory = createMemoryWorkspaceStore();
|
|
478
|
+
const removed = /* @__PURE__ */ new Set();
|
|
479
|
+
const metadataKeys = /* @__PURE__ */ new Set();
|
|
480
|
+
const isRemoved = (path) => [...removed].some((parent) => path === parent || path.startsWith(`${parent}/`));
|
|
481
|
+
function merge(baseEntries, previewEntries) {
|
|
482
|
+
const entries = new Map(baseEntries.filter((entry) => !isRemoved(entry.path)).map((entry) => [entry.path, entry]));
|
|
483
|
+
for (const entry of previewEntries) entries.set(entry.path, entry);
|
|
484
|
+
return [...entries.values()].sort((left, right) => left.path.localeCompare(right.path));
|
|
485
|
+
}
|
|
486
|
+
return {
|
|
487
|
+
async readFile(path) {
|
|
488
|
+
return await memory.readFile(path) ?? (isRemoved(path) ? void 0 : await base.readFile(path));
|
|
489
|
+
},
|
|
490
|
+
writeFile: memory.writeFile.bind(memory),
|
|
491
|
+
async list(path, options) {
|
|
492
|
+
return merge(await base.list(path, options), await memory.list(path, options));
|
|
493
|
+
},
|
|
494
|
+
async glob(pattern, options) {
|
|
495
|
+
return merge(await base.glob(pattern, options), await memory.glob(pattern, options));
|
|
496
|
+
},
|
|
497
|
+
async stat(path) {
|
|
498
|
+
return await memory.stat(path) ?? (isRemoved(path) ? void 0 : await base.stat(path));
|
|
499
|
+
},
|
|
500
|
+
mkdir: memory.mkdir.bind(memory),
|
|
501
|
+
async rm(path, options) {
|
|
502
|
+
await memory.rm(path, options);
|
|
503
|
+
removed.add(path);
|
|
504
|
+
},
|
|
505
|
+
snapshot: memory.snapshot.bind(memory),
|
|
506
|
+
diff: memory.diff.bind(memory),
|
|
507
|
+
async getMeta(key) {
|
|
508
|
+
return await (metadataKeys.has(key) ? memory.getMeta?.(key) : base.getMeta?.(key));
|
|
509
|
+
},
|
|
510
|
+
async setMeta(key, value, capability) {
|
|
511
|
+
await memory.setMeta?.(key, value, capability);
|
|
512
|
+
metadataKeys.add(key);
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
}
|
|
375
516
|
const materializationByStore = /* @__PURE__ */ new WeakMap();
|
|
517
|
+
let materializationProgressScopes;
|
|
518
|
+
function materializationProgressStorage() {
|
|
519
|
+
if (materializationProgressScopes) return materializationProgressScopes;
|
|
520
|
+
const Storage = globalThis.process?.getBuiltinModule?.("node:async_hooks")?.AsyncLocalStorage;
|
|
521
|
+
if (!Storage) return;
|
|
522
|
+
materializationProgressScopes = new Storage();
|
|
523
|
+
return materializationProgressScopes;
|
|
524
|
+
}
|
|
376
525
|
async function invalidateWorkspaceSourceMaterialization(definition, store, sourceKeys) {
|
|
377
526
|
const state = materializationByStore.get(store)?.get(definition);
|
|
378
527
|
if (!state) return;
|
|
@@ -388,7 +537,10 @@ async function invalidateWorkspaceSourceMaterialization(definition, store, sourc
|
|
|
388
537
|
}
|
|
389
538
|
async function waitForMaterialization(pending, signal) {
|
|
390
539
|
if (!signal) return await pending;
|
|
391
|
-
signal.
|
|
540
|
+
if (signal.aborted) {
|
|
541
|
+
pending.catch(() => {});
|
|
542
|
+
throw signal.reason;
|
|
543
|
+
}
|
|
392
544
|
let removeAbortListener = () => {};
|
|
393
545
|
const aborted = new Promise((_resolve, reject) => {
|
|
394
546
|
const onAbort = () => reject(signal.reason);
|
|
@@ -405,7 +557,8 @@ async function waitForMaterialization(pending, signal) {
|
|
|
405
557
|
function createWorkspaceSourceView(definition, store, options = {}) {
|
|
406
558
|
const sourceContext = createSourceContext(definition, void 0, store);
|
|
407
559
|
const allSources = normalizeWorkspaceSources(definition.sources);
|
|
408
|
-
const
|
|
560
|
+
const mountSources = allSources.filter((source) => source.materialize === "lazy" || source.materialize === "startup");
|
|
561
|
+
const sources = mountSources.filter((source) => !source.requestOnly);
|
|
409
562
|
const syncSources = allSources.filter((source) => source.sync);
|
|
410
563
|
const descriptorSources = allSources.filter((source) => source.requestDescriptor);
|
|
411
564
|
const writePolicy = createWorkspaceWritePolicy(definition);
|
|
@@ -428,6 +581,13 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
428
581
|
const { completedSources, generationBySource, materializedSources, pendingBySource } = materializationState;
|
|
429
582
|
const reusedStartupSources = /* @__PURE__ */ new Set();
|
|
430
583
|
const uncachedMaterializedSources = /* @__PURE__ */ new Set();
|
|
584
|
+
function activeProgressScope() {
|
|
585
|
+
const scope = materializationProgressStorage()?.getStore();
|
|
586
|
+
if (scope?.active && scope.state === materializationState) return scope;
|
|
587
|
+
}
|
|
588
|
+
function readStore() {
|
|
589
|
+
return activeProgressScope()?.preview ?? store;
|
|
590
|
+
}
|
|
431
591
|
function getSourceContext(source) {
|
|
432
592
|
let context = sourceContexts.get(source.key);
|
|
433
593
|
if (!context) {
|
|
@@ -436,12 +596,6 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
436
596
|
}
|
|
437
597
|
return context;
|
|
438
598
|
}
|
|
439
|
-
function isLazySourcePath(path) {
|
|
440
|
-
return sources.some((source) => sourceMountContainsPath(source, path));
|
|
441
|
-
}
|
|
442
|
-
function isSyncSourceMountPath(path) {
|
|
443
|
-
return syncSources.some((source) => source.mountPath && sourceMountContainsPath(source, path));
|
|
444
|
-
}
|
|
445
599
|
function descriptorSourceForPath(path) {
|
|
446
600
|
return descriptorSources.find((source) => workspaceSourceRequestDescriptorPath(source.key) === path);
|
|
447
601
|
}
|
|
@@ -555,7 +709,10 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
555
709
|
}
|
|
556
710
|
let pending = prepareBySource.get(sourceKey);
|
|
557
711
|
if (!pending) {
|
|
558
|
-
pending = prepareWorkspaceSource(source.source, getSourceContext(source)).then(() => void 0)
|
|
712
|
+
pending = prepareWorkspaceSource(source.source, getSourceContext(source)).then(() => void 0, (error) => {
|
|
713
|
+
prepareBySource.delete(sourceKey);
|
|
714
|
+
throw error;
|
|
715
|
+
});
|
|
559
716
|
prepareBySource.set(sourceKey, pending);
|
|
560
717
|
}
|
|
561
718
|
await pending;
|
|
@@ -598,18 +755,58 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
598
755
|
reusedStartupSources.delete(source.key);
|
|
599
756
|
}
|
|
600
757
|
}
|
|
758
|
+
const control = {
|
|
759
|
+
isCurrent,
|
|
760
|
+
async mutate(mutation) {
|
|
761
|
+
options.abortSignal?.throwIfAborted();
|
|
762
|
+
return await trackMutation(mutation);
|
|
763
|
+
},
|
|
764
|
+
async checkpoint(mutation) {
|
|
765
|
+
return await trackMutation(mutation);
|
|
766
|
+
}
|
|
767
|
+
};
|
|
768
|
+
const onProgress = options.onProgress;
|
|
769
|
+
const progressStorage = onProgress ? materializationProgressStorage() : void 0;
|
|
770
|
+
const startedSources = /* @__PURE__ */ new Set();
|
|
771
|
+
const selectedKeys = new Set(selectedSources.map((source) => source.key));
|
|
772
|
+
const operationOptions = onProgress && progressStorage ? {
|
|
773
|
+
...options,
|
|
774
|
+
async onProgress(event) {
|
|
775
|
+
startedSources.add(event.source);
|
|
776
|
+
const nestedBySource = /* @__PURE__ */ new Map();
|
|
777
|
+
const progressScope = {
|
|
778
|
+
active: true,
|
|
779
|
+
state: materializationState,
|
|
780
|
+
selected: selectedKeys,
|
|
781
|
+
started: startedSources,
|
|
782
|
+
async materialize(sourceKey) {
|
|
783
|
+
const preview = progressScope.preview ??= createMaterializationPreview(store);
|
|
784
|
+
let nested = nestedBySource.get(sourceKey);
|
|
785
|
+
if (!nested) {
|
|
786
|
+
nested = materializeWorkspaceSources(definition, preview, {
|
|
787
|
+
abortSignal: options.abortSignal,
|
|
788
|
+
sources: [sourceKey]
|
|
789
|
+
});
|
|
790
|
+
nestedBySource.set(sourceKey, nested);
|
|
791
|
+
}
|
|
792
|
+
try {
|
|
793
|
+
if ((await nested).sources.some((source) => source.status !== "ready")) nestedBySource.delete(sourceKey);
|
|
794
|
+
} catch (error) {
|
|
795
|
+
nestedBySource.delete(sourceKey);
|
|
796
|
+
throw error;
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
try {
|
|
801
|
+
await progressStorage.run(progressScope, async () => await onProgress(event));
|
|
802
|
+
} finally {
|
|
803
|
+
progressScope.active = false;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
} : options;
|
|
601
807
|
let result;
|
|
602
808
|
try {
|
|
603
|
-
result = await waitForMaterialization(materializeWorkspaceSources(definition, store,
|
|
604
|
-
isCurrent,
|
|
605
|
-
async mutate(operation) {
|
|
606
|
-
options.abortSignal?.throwIfAborted();
|
|
607
|
-
return await trackMutation(operation);
|
|
608
|
-
},
|
|
609
|
-
async checkpoint(operation) {
|
|
610
|
-
return await trackMutation(operation);
|
|
611
|
-
}
|
|
612
|
-
}), options.abortSignal);
|
|
809
|
+
result = await waitForMaterialization(materializeWorkspaceSources(definition, store, operationOptions, control), options.abortSignal);
|
|
613
810
|
} catch (error) {
|
|
614
811
|
if (options.abortSignal?.aborted && mutations.size) await Promise.allSettled(mutations);
|
|
615
812
|
throw error;
|
|
@@ -644,6 +841,11 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
644
841
|
const verifyOwnership = options.reuseStartupSnapshots ? true : verifyRootOwnership || source.mountPath || !sources.some((item) => !item.mountPath && item.materialize === "lazy") ? "workspace" : false;
|
|
645
842
|
const isUncachedLazySource = source.materialize === "lazy" && source.cache === false;
|
|
646
843
|
const pending = pendingBySource.get(sourceKey);
|
|
844
|
+
const progress = activeProgressScope();
|
|
845
|
+
if (progress && (progress.selected.has(sourceKey) || pending)) {
|
|
846
|
+
if (!progress.started.has(sourceKey)) await progress.materialize(sourceKey);
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
647
849
|
if (pending?.fullSource) {
|
|
648
850
|
try {
|
|
649
851
|
await pending.promise;
|
|
@@ -677,7 +879,7 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
677
879
|
await ensurePrepared(source.key, { directory: normalized });
|
|
678
880
|
if (!usesLiveProvider(source)) await ensureMaterialized(source.key, true, { directory: normalized });
|
|
679
881
|
}
|
|
680
|
-
const storeEntries = isDescriptorPath(normalized) ? [] : await
|
|
882
|
+
const storeEntries = isDescriptorPath(normalized) ? [] : await readStore().list(path, options);
|
|
681
883
|
const result = new Map(storeEntries.map((entry) => [entry.path, entry]));
|
|
682
884
|
for (const entry of descriptorPathEntries(path, options)) if (!isExcludedWorkspacePath(entry.path, options.exclude)) result.set(entry.path, entry);
|
|
683
885
|
if (isDescriptorPath(normalized)) return [...result.values()].sort((left, right) => left.path.localeCompare(right.path));
|
|
@@ -708,7 +910,7 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
708
910
|
if (source.materialize === "startup") continue;
|
|
709
911
|
else if (sourceMountContainsPath(source, path) || !source.mountPath && normalized) {
|
|
710
912
|
await ensureMaterialized(source.key);
|
|
711
|
-
for (const entry of await
|
|
913
|
+
for (const entry of await readStore().list(path, options)) result.set(entry.path, entry);
|
|
712
914
|
} else if (!normalized && !result.has(source.mountPath)) result.set(source.mountPath, {
|
|
713
915
|
path: source.mountPath,
|
|
714
916
|
type: "directory"
|
|
@@ -737,7 +939,7 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
737
939
|
await ensurePrepared(source.key);
|
|
738
940
|
await ensureMaterialized(source.key);
|
|
739
941
|
}
|
|
740
|
-
const results = await searchMaterializedStore(
|
|
942
|
+
const results = await searchMaterializedStore(readStore(), {
|
|
741
943
|
...query,
|
|
742
944
|
paths: storePaths.filter(Boolean).length ? storePaths.filter(Boolean) : void 0,
|
|
743
945
|
limit
|
|
@@ -773,7 +975,7 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
773
975
|
continue;
|
|
774
976
|
}
|
|
775
977
|
await ensureMaterialized(source.key);
|
|
776
|
-
results.push(...await searchMaterializedStore(
|
|
978
|
+
results.push(...await searchMaterializedStore(readStore(), {
|
|
777
979
|
...query,
|
|
778
980
|
paths,
|
|
779
981
|
limit: limit - results.length
|
|
@@ -782,9 +984,6 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
782
984
|
}
|
|
783
985
|
return dedupeHits(results).slice(0, limit);
|
|
784
986
|
}
|
|
785
|
-
function assertWritableStorePath(path, workspacePath, type) {
|
|
786
|
-
if (type === "source" || isLazySourcePath(workspacePath)) throw workspaceError(`[vitehub] Source-backed workspace paths are read-only: ${path}.`);
|
|
787
|
-
}
|
|
788
987
|
async function previousStat(path) {
|
|
789
988
|
return await store.stat(path);
|
|
790
989
|
}
|
|
@@ -796,16 +995,17 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
796
995
|
}
|
|
797
996
|
async function readOwnedRootStartupFile(path, sourceKey) {
|
|
798
997
|
if (!sources.some((source) => !source.mountPath && source.materialize === "startup")) return;
|
|
799
|
-
const
|
|
998
|
+
const sourceStore = readStore();
|
|
999
|
+
const owner = await readWorkspaceFileOwner(sourceStore, path);
|
|
800
1000
|
if (owner?.workspace !== definition.name || !owner.digest) return;
|
|
801
|
-
if (sourceKey && owner.source !== sourceKey) return;
|
|
1001
|
+
if (sourceKey !== void 0 && owner.source !== sourceKey) return;
|
|
802
1002
|
const source = sources.find((source) => !source.mountPath && source.materialize === "startup" && source.key === owner.source);
|
|
803
1003
|
if (!source) return;
|
|
804
|
-
if ((await
|
|
805
|
-
const file = await
|
|
1004
|
+
if ((await sourceStore.stat(path))?.type !== "file") return;
|
|
1005
|
+
const file = await sourceStore.readFile(path);
|
|
806
1006
|
if (!file) return;
|
|
807
|
-
if (file.metadata?.source && (file.metadata.workspaceSourceOwner !== definition.name || file.metadata.source !== owner.source)) return;
|
|
808
|
-
const snapshot = await readCurrentSourceSnapshot(
|
|
1007
|
+
if (typeof file.metadata?.source === "string" && (file.metadata.workspaceSourceOwner !== definition.name || file.metadata.source !== owner.source)) return;
|
|
1008
|
+
const snapshot = await readCurrentSourceSnapshot(sourceStore, definition.name, source);
|
|
809
1009
|
if (snapshot?.status !== "ready" || !Object.hasOwn(snapshot.items || {}, path)) return;
|
|
810
1010
|
if (await sha256(file.content) === owner.digest) return file;
|
|
811
1011
|
}
|
|
@@ -815,51 +1015,55 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
815
1015
|
await ensureMaterialized(source.key, verifyRootOwnership);
|
|
816
1016
|
if (source.materialize === "startup") {
|
|
817
1017
|
if (await readOwnedRootStartupFile(path, source.key)) return source;
|
|
818
|
-
} else if ((await
|
|
1018
|
+
} else if ((await readStore().stat(path))?.metadata?.source === source.key) return source;
|
|
819
1019
|
}
|
|
820
1020
|
}
|
|
821
|
-
async function
|
|
822
|
-
if (!allSources.length) return
|
|
1021
|
+
async function assertNoSourceClaims(path, workspacePath, claims) {
|
|
1022
|
+
if (!allSources.length) return;
|
|
1023
|
+
const fileOwner = (file) => allSources.find((source) => source.key === file?.metadata?.source);
|
|
1024
|
+
const current = await store.stat(workspacePath);
|
|
1025
|
+
const owner = current?.type === "file" ? fileOwner(await store.readFile(workspacePath)) : void 0;
|
|
1026
|
+
if (owner) throw workspaceSourceReadOnlyError(path, owner.key);
|
|
1027
|
+
if (claims.size > 1) throw workspaceSourceReadOnlyError(path);
|
|
1028
|
+
const matches = (item) => !workspacePath || item === workspacePath || item.startsWith(`${workspacePath}/`);
|
|
823
1029
|
for (const source of allSources) {
|
|
1030
|
+
if (claims.has(source.key)) continue;
|
|
824
1031
|
const snapshot = await readCurrentSourceSnapshot(store, definition.name, source);
|
|
825
|
-
if (Object.keys(snapshot?.items
|
|
1032
|
+
if (Object.keys(snapshot?.items ?? {}).some(matches)) claims.add(source.key);
|
|
1033
|
+
else if (source.sync && store.getMeta) {
|
|
1034
|
+
const state = readWorkspaceSourceSyncState(await store.getMeta(sourceSyncMetaKey(source.key, definition.name)));
|
|
1035
|
+
if (Object.keys(state?.paths ?? {}).some(matches)) claims.add(source.key);
|
|
1036
|
+
}
|
|
1037
|
+
if (claims.size > 1) throw workspaceSourceReadOnlyError(path);
|
|
826
1038
|
}
|
|
827
|
-
const
|
|
828
|
-
if (typeof file?.metadata?.source === "string" && allSources.some((source) => source.key === file.metadata?.source)) return true;
|
|
829
|
-
if ((await store.stat(path))?.type !== "directory") return false;
|
|
830
|
-
const entries = await store.list(path, { recursive: true });
|
|
831
|
-
for (const entry of entries) {
|
|
1039
|
+
if (current?.type === "directory") for (const entry of await store.list(workspacePath, { recursive: true })) {
|
|
832
1040
|
if (entry.type !== "file") continue;
|
|
833
|
-
const
|
|
834
|
-
if (
|
|
1041
|
+
const childOwner = fileOwner(await store.readFile(entry.path));
|
|
1042
|
+
if (childOwner) claims.add(childOwner.key);
|
|
1043
|
+
if (claims.size > 1) break;
|
|
835
1044
|
}
|
|
836
|
-
|
|
1045
|
+
if (claims.size) throw workspaceSourceReadOnlyError(path, claims.size === 1 ? [...claims][0] : void 0);
|
|
837
1046
|
}
|
|
838
|
-
|
|
839
|
-
if (
|
|
840
|
-
for (const source of syncSources) {
|
|
841
|
-
const state = readWorkspaceSourceSyncState(await store.getMeta(sourceSyncMetaKey(source.key, definition.name)));
|
|
842
|
-
if (!state) continue;
|
|
843
|
-
if (state.paths[path]) return true;
|
|
844
|
-
if (Object.keys(state.paths).some((item) => item.startsWith(`${path}/`))) return true;
|
|
845
|
-
}
|
|
846
|
-
return false;
|
|
1047
|
+
function assertWritableDescriptorPath(path, workspacePath) {
|
|
1048
|
+
if (isDescriptorPath(workspacePath)) throw workspaceSourceReadOnlyError(path, descriptorSourceForPath(workspacePath)?.key);
|
|
847
1049
|
}
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
const
|
|
851
|
-
|
|
1050
|
+
function sourceMountClaims(workspacePath, includeRequestOnly) {
|
|
1051
|
+
const claims = new Set((includeRequestOnly ? mountSources : sources).filter((source) => sourceMountContainsPath(source, workspacePath) || !source.requestOnly && typeof source.livePaths?.[workspacePath] === "string").map((source) => source.key));
|
|
1052
|
+
for (const source of syncSources) if (source.mountPath && sourceMountContainsPath(source, workspacePath)) claims.add(source.key);
|
|
1053
|
+
return claims;
|
|
852
1054
|
}
|
|
853
|
-
async function
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
1055
|
+
async function assertWritableCurrentPath(path) {
|
|
1056
|
+
assertWritableDescriptorPath(path, path);
|
|
1057
|
+
const { workspacePath } = resolveWorkspacePath(definition, path);
|
|
1058
|
+
await assertNoSourceClaims(path, workspacePath, sourceMountClaims(workspacePath, false));
|
|
857
1059
|
}
|
|
858
1060
|
async function assertWritablePath(path) {
|
|
859
|
-
|
|
1061
|
+
assertWritableDescriptorPath(path, normalizeWorkspacePath(path));
|
|
860
1062
|
const resolution = resolveWorkspacePath(definition, path);
|
|
861
|
-
|
|
862
|
-
|
|
1063
|
+
assertWritableDescriptorPath(path, resolution.workspacePath);
|
|
1064
|
+
const claims = sourceMountClaims(resolution.workspacePath, true);
|
|
1065
|
+
if (!claims.size) await materializeRootSourceForPath(resolution.workspacePath);
|
|
1066
|
+
await assertNoSourceClaims(path, resolution.workspacePath, claims);
|
|
863
1067
|
return resolution;
|
|
864
1068
|
}
|
|
865
1069
|
const writeGrants = /* @__PURE__ */ new WeakMap();
|
|
@@ -890,7 +1094,8 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
890
1094
|
const grant = grants[index];
|
|
891
1095
|
const normalizedPath = normalizeWorkspacePath(path);
|
|
892
1096
|
if (!grant || writeGrants.get(grant) !== normalizedPath) throw workspaceError(`[vitehub] Workspace rebase to take remote ${path} requires a Source write grant for that path.`);
|
|
893
|
-
|
|
1097
|
+
const claims = new Set(mountSources.filter((source) => sourceMountIntersectsPath(source, normalizedPath)).map((source) => source.key));
|
|
1098
|
+
if (claims.size) await assertNoSourceClaims(path, normalizedPath, claims);
|
|
894
1099
|
}
|
|
895
1100
|
await withWorkspaceStoreMutation(store, async () => {
|
|
896
1101
|
for (const grant of grants) await assertWritableCurrentPath(grant.path);
|
|
@@ -904,7 +1109,22 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
904
1109
|
const grantedStore = {
|
|
905
1110
|
mkdir: requireWriteGrant(async (path, options) => await store.mkdir(path, options)),
|
|
906
1111
|
rm: requireWriteGrant(async (path, options) => await store.rm(path, options)),
|
|
907
|
-
writeFile: requireWriteGrant(async (path, file,
|
|
1112
|
+
writeFile: requireWriteGrant(async (path, file, options) => {
|
|
1113
|
+
const append = options?.[appendCondition];
|
|
1114
|
+
if (append && store.writeFileConditional) {
|
|
1115
|
+
const base = append.base;
|
|
1116
|
+
const digest = base === void 0 ? null : await (store.history?.digest?.(contentToBytes(base)) ?? sha256(base));
|
|
1117
|
+
try {
|
|
1118
|
+
return await store.writeFileConditional(path, {
|
|
1119
|
+
...file,
|
|
1120
|
+
path
|
|
1121
|
+
}, digest);
|
|
1122
|
+
} catch (error) {
|
|
1123
|
+
if (isWorkspaceConflict(error)) append.onConflict(error);
|
|
1124
|
+
throw error;
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
const ifDigest = options?.ifDigest;
|
|
908
1128
|
if (ifDigest === void 0) return await store.writeFile(path, {
|
|
909
1129
|
...file,
|
|
910
1130
|
path
|
|
@@ -917,6 +1137,21 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
917
1137
|
})
|
|
918
1138
|
};
|
|
919
1139
|
return {
|
|
1140
|
+
replacePath: prepareWorkspaceReplacement({
|
|
1141
|
+
name: definition.name,
|
|
1142
|
+
policy: writePolicy,
|
|
1143
|
+
stat: previousStat,
|
|
1144
|
+
grant: grantWritablePath,
|
|
1145
|
+
check: assertWritableCurrentPath
|
|
1146
|
+
}, async (replacement, check) => {
|
|
1147
|
+
const replace = store[replaceStorePath];
|
|
1148
|
+
if (!replace && replacement.removeTree) throw workspaceError("[vitehub] This Workspace Store does not support safe tree replacement.");
|
|
1149
|
+
await withWorkspaceStoreMutation(store, async () => {
|
|
1150
|
+
await check?.();
|
|
1151
|
+
if (replace) await replace.call(store, replacement);
|
|
1152
|
+
else await store.writeFile(replacement.path, replacement.files[0]);
|
|
1153
|
+
});
|
|
1154
|
+
}),
|
|
920
1155
|
requireHistoryGrants(history, apply = (options) => history.commit(options)) {
|
|
921
1156
|
return async (grants, options) => {
|
|
922
1157
|
return await withWorkspaceStoreMutation(store, async () => {
|
|
@@ -981,16 +1216,16 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
981
1216
|
let shouldRefreshCachedLazy = false;
|
|
982
1217
|
if (resolution.source.materialize === "lazy" && Number.isFinite(cacheMaxAge)) shouldRefreshCachedLazy = materializedSources.has(resolution.sourceKey) || Boolean(await readCurrentSourceSnapshot(store, definition.name, resolution.source));
|
|
983
1218
|
if (shouldRefreshCachedLazy) await ensureMaterialized(resolution.sourceKey);
|
|
984
|
-
const file = await
|
|
1219
|
+
const file = await readStore().readFile(resolution.workspacePath);
|
|
985
1220
|
if (file) return decodeFile(file.content, options);
|
|
986
1221
|
await ensureMaterialized(resolution.sourceKey, true, resolution.workspacePath);
|
|
987
|
-
return await readResolvedSourceFile(resolution,
|
|
1222
|
+
return await readResolvedSourceFile(resolution, readStore(), sourceContext, options);
|
|
988
1223
|
}
|
|
989
1224
|
await materializeRootStartupSources(false);
|
|
990
1225
|
const startupFile = await readOwnedRootStartupFile(resolution.workspacePath);
|
|
991
1226
|
if (startupFile) return decodeFile(startupFile.content, options);
|
|
992
1227
|
if (!await materializeRootSourceForPath(resolution.workspacePath, false)) for (const source of sources.filter((source) => !source.mountPath && source.materialize === "startup")) await ensureMaterialized(source.key, true);
|
|
993
|
-
const file = await
|
|
1228
|
+
const file = await readStore().readFile(resolution.workspacePath);
|
|
994
1229
|
if (!file) throw workspaceError(`[vitehub] Workspace file does not exist: ${path}.`);
|
|
995
1230
|
return decodeFile(file.content, options);
|
|
996
1231
|
},
|
|
@@ -1013,7 +1248,7 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
1013
1248
|
content: input.content ?? content,
|
|
1014
1249
|
mediaType: input.mediaType,
|
|
1015
1250
|
metadata: assertPublicFileMetadata(input.path, input.metadata)
|
|
1016
|
-
}, options
|
|
1251
|
+
}, options);
|
|
1017
1252
|
await writePolicy.after(input);
|
|
1018
1253
|
return grant.path;
|
|
1019
1254
|
} catch (error) {
|
|
@@ -1031,7 +1266,7 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
1031
1266
|
await ensureMaterializedSources(sources.filter((source) => !usesLiveProvider(source)));
|
|
1032
1267
|
const result = /* @__PURE__ */ new Map();
|
|
1033
1268
|
if (cwd !== ".vitehub/sources") {
|
|
1034
|
-
for (const entry of await
|
|
1269
|
+
for (const entry of await readStore().glob(patterns, options)) if (matches(entry.path)) result.set(entry.path, entry);
|
|
1035
1270
|
}
|
|
1036
1271
|
for (const entry of descriptorPathEntries(cwd, { recursive: true })) if (entry.type === "file" && matches(entry.path)) result.set(entry.path, entry);
|
|
1037
1272
|
for (const source of sources.filter(usesLiveProvider)) {
|
|
@@ -1059,23 +1294,23 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
1059
1294
|
return result;
|
|
1060
1295
|
}
|
|
1061
1296
|
if (resolution.source.materialize === "startup") await ensureMaterialized(resolution.sourceKey);
|
|
1062
|
-
const stored = await
|
|
1297
|
+
const stored = await readStore().stat(resolution.workspacePath);
|
|
1063
1298
|
if (stored) return stored;
|
|
1064
1299
|
if (resolution.source.materialize === "startup" && (completedSources.has(resolution.sourceKey) || reusedStartupSources.has(resolution.sourceKey))) throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
|
|
1065
1300
|
await ensureMaterialized(resolution.sourceKey);
|
|
1066
|
-
const result = await statVirtualSourcePath(resolution.source, resolution.workspacePath,
|
|
1301
|
+
const result = await statVirtualSourcePath(resolution.source, resolution.workspacePath, readStore(), getSourceContext(resolution.source));
|
|
1067
1302
|
if (!result) throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
|
|
1068
1303
|
return result;
|
|
1069
1304
|
}
|
|
1070
1305
|
await materializeRootStartupSources();
|
|
1071
|
-
let result = await
|
|
1306
|
+
let result = await readStore().stat(resolution.workspacePath);
|
|
1072
1307
|
if (!result) {
|
|
1073
1308
|
if (!resolution.workspacePath && sources.some((source) => !source.mountPath && usesLiveProvider(source))) return {
|
|
1074
1309
|
path: "",
|
|
1075
1310
|
type: "directory"
|
|
1076
1311
|
};
|
|
1077
1312
|
await materializeRootSourceForPath(resolution.workspacePath);
|
|
1078
|
-
result = await
|
|
1313
|
+
result = await readStore().stat(resolution.workspacePath);
|
|
1079
1314
|
}
|
|
1080
1315
|
if (!result) throw workspaceError(`[vitehub] Workspace path does not exist: ${path}.`);
|
|
1081
1316
|
return result;
|
|
@@ -1093,16 +1328,16 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
1093
1328
|
return Boolean(liveSourceStat(resolution.source, resolution.workspacePath));
|
|
1094
1329
|
}
|
|
1095
1330
|
if (resolution.source.materialize === "startup") await ensureMaterialized(resolution.sourceKey);
|
|
1096
|
-
if (await
|
|
1331
|
+
if (await readStore().stat(resolution.workspacePath)) return true;
|
|
1097
1332
|
if (resolution.source.materialize === "startup" && (completedSources.has(resolution.sourceKey) || reusedStartupSources.has(resolution.sourceKey))) return false;
|
|
1098
1333
|
await ensureMaterialized(resolution.sourceKey);
|
|
1099
|
-
return Boolean(await statVirtualSourcePath(resolution.source, resolution.workspacePath,
|
|
1334
|
+
return Boolean(await statVirtualSourcePath(resolution.source, resolution.workspacePath, readStore(), getSourceContext(resolution.source)));
|
|
1100
1335
|
}
|
|
1101
1336
|
await materializeRootStartupSources();
|
|
1102
|
-
if (await
|
|
1337
|
+
if (await readStore().stat(resolution.workspacePath)) return true;
|
|
1103
1338
|
if (!resolution.workspacePath && sources.some((source) => !source.mountPath && usesLiveProvider(source))) return true;
|
|
1104
1339
|
await materializeRootSourceForPath(resolution.workspacePath);
|
|
1105
|
-
return Boolean(await
|
|
1340
|
+
return Boolean(await readStore().stat(resolution.workspacePath));
|
|
1106
1341
|
},
|
|
1107
1342
|
async mkdir(path, options) {
|
|
1108
1343
|
const requested = await grantWritablePath(path);
|
|
@@ -1142,7 +1377,7 @@ function createWorkspaceSourceView(definition, store, options = {}) {
|
|
|
1142
1377
|
for (const [path, entry] of result) {
|
|
1143
1378
|
if (!isWithinLiveSourceMount(source, path) || allowed.has(path)) continue;
|
|
1144
1379
|
if (entry.type === "file") {
|
|
1145
|
-
if ((await
|
|
1380
|
+
if ((await readStore().readFile(path))?.metadata?.source === source.key) result.delete(path);
|
|
1146
1381
|
continue;
|
|
1147
1382
|
}
|
|
1148
1383
|
if (!source.mountPath) continue;
|
|
@@ -1285,7 +1520,7 @@ function createWorkspace(definition, options = {}) {
|
|
|
1285
1520
|
};
|
|
1286
1521
|
},
|
|
1287
1522
|
async sync(options) {
|
|
1288
|
-
const { syncWorkspaceSources } = await import("./sync-
|
|
1523
|
+
const { syncWorkspaceSources } = await import("./sync-CUkCuP_g.js");
|
|
1289
1524
|
return await syncWorkspaceSources(definition, store, options);
|
|
1290
1525
|
},
|
|
1291
1526
|
async materializeSources(options) {
|
|
@@ -1340,7 +1575,7 @@ function createWorkspace(definition, options = {}) {
|
|
|
1340
1575
|
async startSession(options) {
|
|
1341
1576
|
const host = options?.host;
|
|
1342
1577
|
if (host) {
|
|
1343
|
-
const { createHostedWorkspaceSession } = await import("./host-
|
|
1578
|
+
const { createHostedWorkspaceSession } = await import("./host-BYBRcSnh.js").then((n) => n.n);
|
|
1344
1579
|
return await createHostedWorkspaceSession(workspace, {
|
|
1345
1580
|
...options,
|
|
1346
1581
|
host
|
|
@@ -1350,14 +1585,15 @@ function createWorkspace(definition, options = {}) {
|
|
|
1350
1585
|
}
|
|
1351
1586
|
};
|
|
1352
1587
|
attachWorkspaceMetadataTarget(workspace, () => metadata);
|
|
1588
|
+
attachWorkspaceReplacement(workspace, files.replacePath);
|
|
1353
1589
|
forwardWorkspaceStoreTarget(store, workspace);
|
|
1354
1590
|
if (!normalizeWorkspaceSources(definition.sources).some((source) => source.requestDescriptor || source.livePaths)) forwardWorkspaceRevisionMaterializer(store, workspace);
|
|
1355
1591
|
const synchronizedWorkspace = workspace;
|
|
1356
1592
|
synchronizedWorkspace.__workspaceDefinitionSyncKey = definition;
|
|
1357
1593
|
synchronizedWorkspace.__syncWorkspaceDefinition = async (abortSignal) => {
|
|
1358
|
-
const { syncWorkspaceDefinition } = await import("./lifecycle-
|
|
1594
|
+
const { syncWorkspaceDefinition } = await import("./lifecycle-BK7WNfcP.js").then((n) => n.t);
|
|
1359
1595
|
await syncWorkspaceDefinition(definition, store, abortSignal);
|
|
1360
1596
|
};
|
|
1361
1597
|
return attachWorkspaceSourceRequestExecution(workspace, createWorkspaceSourceRequestExecution(definition));
|
|
1362
1598
|
}
|
|
1363
|
-
export {
|
|
1599
|
+
export { assertPathInSessionScope as C, scopedSearchQuery as D, isMissingWorkspacePathError as E, assertDiffInsideSessionPaths as S, filterSessionEntries as T, attachWorkspaceSourceRequestExecution as _, isInternalWorkspaceMetaKey as a, workspaceSourceRequestMatches as b, isWorkspaceSourceSyncMetaKey as c, sourceSyncPathClaims as d, workspaceSourceSyncStateEquals as f, copyWorkspacePath as g, appendWorkspaceFile as h, assertPublicWorkspaceMetaKey as i, readWorkspaceSourceSyncState as l, appendCondition as m, invalidateCachedWorkspaceStore as n, createWorkspaceSourceView as o, resolveWorkspacePath as p, resetWorkspaceStoreCache as r, invalidateWorkspaceSourceMaterialization as s, createWorkspace as t, sourceSyncMetaKey as u, createWorkspaceSourceRequestExecution as v, filterSessionDiff as w, createBasicWorkspaceSession as x, getWorkspaceSourceRequestExecution as y };
|