@dev.fast/whiteboard 0.4.1-preview.20261027.141 → 0.4.1-preview.20261028.142
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/dist/{account-alias-AJ6miBT5.js → account-alias-D1iIc7j5.js} +4 -5
- package/dist/{agent-cli-DIC2tBpL.js → agent-cli-B_gSzrhA.js} +8 -9
- package/dist/agent-cli-DtjnkDSL.js +2 -0
- package/dist/{agent-client-DyNmSHfO.js → agent-client-DudPjH3I.js} +3 -3
- package/dist/{authoring-tools-B9MhiKw4.js → authoring-tools-B-OyXmtR.js} +5 -5
- package/dist/{background-server-CZaB8zFH.js → background-server-CORnMQmu.js} +1 -1
- package/dist/{background-server-DlgbnDVt.js → background-server-CesuMV6N.js} +7 -6
- package/dist/build-info.json +1 -1
- package/dist/{cli-D7Lpc4ws.js → cli-CIP_-Fvm.js} +1 -1
- package/dist/{cli-runner-JPkbHD7I.js → cli-runner-dHnKnyNw.js} +22 -23
- package/dist/cli.js +2 -2
- package/dist/{fuzzy-match-rWIeloqo.js → fuzzy-match-CTvayutE.js} +3 -3
- package/dist/{headless-host-Cn6WDmaL.js → headless-host-CWuFw-CO.js} +118 -218
- package/dist/{headless-host-DmuAjcgt.js → headless-host-Cnu-o0xk.js} +1 -1
- package/dist/{import-CUNdl3NP.js → import-FOpJL22V.js} +198 -505
- package/dist/{lens-selection-BQxqiuWY.js → lens-selection-B_LTVyTB.js} +1 -1
- package/dist/{local-data-DxkQXCNG.js → local-data-BhNZ1Yep.js} +72 -91
- package/dist/{mcp-B154Vpj0.js → mcp-2bWqlJNW.js} +3 -3
- package/dist/{package-paths-LcO6HNp_.js → package-paths-Cg6fnaGp.js} +1 -1
- package/dist/profile-BmtFpq8d.js +2 -0
- package/dist/{profile-hC1iAoRB.js → profile-DnwIJvlh.js} +2 -2
- package/dist/{remote-attach-DhvNHMe1.js → remote-attach-C79X5M2Z.js} +4 -4
- package/dist/{remote-extensions-VLpt_4Tn.js → remote-extensions-Bw029iIS.js} +1 -1
- package/dist/{remote-extensions-DMKyDjAs.js → remote-extensions-MUUgbLJn.js} +2 -2
- package/dist/{remote-language-server-zgvAe8wb.js → remote-language-server-Dw1o27aF.js} +4 -4
- package/dist/{remote-uninstall-BR-rIuvK.js → remote-uninstall-Aza0u1_3.js} +5 -5
- package/dist/{request-origin-BnA7Nnca.js → request-origin-DEQd09Db.js} +3 -3
- package/dist/{review-app-launcher-B0Z4B8By.js → review-app-launcher-L7xKjTLQ.js} +2 -2
- package/dist/{src-KTjWplV9.js → review-home-paths-LdGS4SpR.js} +48 -8
- package/dist/{review-telemetry-yuCLNpDu.js → review-telemetry-lmK8HPLI.js} +4 -5
- package/dist/{runtime-5WG8rRgg.js → runtime-Bhk5L_SN.js} +1 -1
- package/dist/runtime.js +1 -1
- package/dist/server/desktop-host.js +34 -48
- package/dist/{server-discovery-Dj_xSDSa.js → server-discovery-D-2vz5gG.js} +2 -3
- package/dist/sharing/index.d.ts +51 -144
- package/dist/sharing/index.js +2 -2
- package/dist/{src-BJ_MeEmN.js → src-Bew3mW9I.js} +1 -1
- package/dist/{src-BTCRHmRM.js → src-Y30gweiK.js} +7 -1
- package/dist/{stored-document-migration-fQWLDqDx.js → stored-document-migration-CZe65mkx.js} +20 -6
- package/dist/{thread-state-BburMvgn.js → thread-state-XgVKaQ3-.js} +1 -1
- package/dist/{tool-failure-BuvwfVeF.js → tool-failure-Bi_-Zck-.js} +2 -2
- package/instructions/animation.md +18 -68
- package/instructions/authoring.md +1 -1
- package/package.json +5 -5
- package/src/review-api/README.md +5 -5
- package/src/review-api/ask-history.ts +3 -13
- package/src/review-api/authoring-tools.ts +2 -2
- package/src/review-api/blocks/animation.ts +50 -0
- package/src/review-api/http.ts +213 -383
- package/src/review-api/local-data.ts +24 -53
- package/src/review-api/review-progress.ts +1 -5
- package/src/review-api/store.ts +95 -16
- package/src/review-api/workspaces.ts +17 -48
- package/src/review-checkout-paths.ts +2 -5
- package/src/review-head-checkout.ts +3 -14
- package/src/server/background-server.ts +4 -2
- package/src/server/desktop-host.ts +17 -9
- package/src/server/desktop-server.ts +4 -6
- package/src/server/json-review-reporting.ts +4 -23
- package/src/server/review-gateway-pushes.ts +1 -10
- package/src/server/review-server-core.ts +8 -13
- package/src/sharing/client.ts +86 -2
- package/src/sharing/host.ts +111 -88
- package/src/sharing/import.ts +173 -710
- package/src/sharing/index.ts +1 -7
- package/src/sharing/repository.ts +18 -49
- package/dist/agent-cli-BDcF54b3.js +0 -2
- package/dist/profile-BLToeYh6.js +0 -2
- package/dist/review-home-paths-CjHB5c8m.js +0 -39
- package/src/sharing/routes.ts +0 -35
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { f as gitAt } from "./src-
|
|
1
|
+
import { f as gitAt } from "./src-Y30gweiK.js";
|
|
2
2
|
import { u as parseJsonText } from "./src-X9phtB2j.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { s as safeStorageSegment } from "./review-home-paths-LdGS4SpR.js";
|
|
4
|
+
import { _ as scopedCoverage, b as unionIntervals, f as sourceAnchors, h as emptyCoverage, i as anchorSelection, l as resolveDiffSelection, m as coverageSources, n as SelectionUnavailableError, o as comparisonKey, u as selectionKey, v as sourcesForFile, y as subtractIntervals } from "./lens-selection-B_LTVyTB.js";
|
|
5
|
+
import { A as documentSchema, B as resourceReference, K as selectionReferences, L as pinsSchema, M as elements, O as boardRepositoryId, Q as UNCATEGORIZED_LENS_ID, V as resourceReferences, Y as checkReferences, at as fileLineRangeSchema, b as textIncludesQuote, c as traceSchema, ct as markdownNodes, n as migrateStoredDocument, nt as lensSelections, q as sourceReferences, r as migrateStoredLenses, s as softwareModelDataSchema, t as liftFileLenses, tt as lensSchema, u as pullRequestUrl, ut as parseMarkdown, w as anchorPins, x as textualRows, z as readsAtBoardPins } from "./stored-document-migration-CZe65mkx.js";
|
|
5
6
|
import { t as ReviewInputError } from "./input-error-OLgB_h31.js";
|
|
7
|
+
import { N as devReviewHome } from "./s3-config-CjcLyFV5.js";
|
|
6
8
|
import { createHash, randomUUID } from "node:crypto";
|
|
7
9
|
import { z } from "zod";
|
|
10
|
+
import { Agent } from "undici";
|
|
8
11
|
import { Minimatch } from "minimatch";
|
|
9
12
|
import { existsSync } from "node:fs";
|
|
10
|
-
import { mkdir,
|
|
13
|
+
import { mkdir, realpath, rm } from "node:fs/promises";
|
|
11
14
|
import path from "node:path";
|
|
12
|
-
import { tmpdir } from "node:os";
|
|
13
15
|
//#region ../review-share-protocol/src/index.ts
|
|
14
16
|
const SHARE_FORMAT = "review-share/2";
|
|
15
17
|
/** UTF-8 bytes of a bundle's JSON, as uploaded and as stored. */
|
|
@@ -186,7 +188,7 @@ const progressUpdateSchema = z.strictObject({
|
|
|
186
188
|
});
|
|
187
189
|
/** Coverage survives new pins only when both complete file contents are unchanged. */
|
|
188
190
|
async function reviewProgress(store, data, snapshot, signal = new AbortController().signal, partial) {
|
|
189
|
-
const marks =
|
|
191
|
+
const marks = store.viewedCoverage(snapshot.reviewId);
|
|
190
192
|
const pins = snapshot.pins ? (await data.resolveSource(snapshot)).pins : void 0;
|
|
191
193
|
const comparison = pins ? partial ?? await data.coverage(snapshot.reviewId, pins) : {
|
|
192
194
|
counted: true,
|
|
@@ -491,6 +493,20 @@ async function exportShare(input) {
|
|
|
491
493
|
//#endregion
|
|
492
494
|
//#region src/sharing/client.ts
|
|
493
495
|
const MAX_RESPONSE_BYTES = MAX_SHARE_BYTES;
|
|
496
|
+
const pool = new Agent({
|
|
497
|
+
keepAliveTimeout: 3e5,
|
|
498
|
+
keepAliveMaxTimeout: 3e5
|
|
499
|
+
});
|
|
500
|
+
const pooledFetch = (input, init) => {
|
|
501
|
+
const pooled = {
|
|
502
|
+
...init,
|
|
503
|
+
dispatcher: pool
|
|
504
|
+
};
|
|
505
|
+
return fetch(input, pooled);
|
|
506
|
+
};
|
|
507
|
+
const jwtSchema = z.object({ token: z.string().min(1) });
|
|
508
|
+
const jwtPayloadSchema = z.object({ exp: z.number() });
|
|
509
|
+
const bearers = /* @__PURE__ */ new Map();
|
|
494
510
|
const linkSchema = z.strictObject({
|
|
495
511
|
shareId: z.uuid(),
|
|
496
512
|
url: z.url()
|
|
@@ -527,7 +543,7 @@ var ShareClient = class {
|
|
|
527
543
|
token;
|
|
528
544
|
send;
|
|
529
545
|
origin;
|
|
530
|
-
constructor(origin, token, send =
|
|
546
|
+
constructor(origin, token, send = pooledFetch) {
|
|
531
547
|
this.token = token;
|
|
532
548
|
this.send = send;
|
|
533
549
|
const url = new URL(origin);
|
|
@@ -539,7 +555,7 @@ var ShareClient = class {
|
|
|
539
555
|
}
|
|
540
556
|
async request(route, method, body, anonymous, maxBytes) {
|
|
541
557
|
const headers = new Headers({ "content-type": "application/json" });
|
|
542
|
-
if (this.token && !anonymous) headers.set("authorization", `Bearer ${this.token}`);
|
|
558
|
+
if (this.token && !anonymous) headers.set("authorization", `Bearer ${await this.bearer(this.token)}`);
|
|
543
559
|
const init = {
|
|
544
560
|
method,
|
|
545
561
|
redirect: "error",
|
|
@@ -555,6 +571,47 @@ var ShareClient = class {
|
|
|
555
571
|
}
|
|
556
572
|
return readBoundedBytes(response, maxBytes);
|
|
557
573
|
}
|
|
574
|
+
async bearer(token) {
|
|
575
|
+
const key = `${this.origin} ${token}`;
|
|
576
|
+
const pending = bearers.get(key);
|
|
577
|
+
if (pending) {
|
|
578
|
+
const cached = await pending.catch(() => void 0);
|
|
579
|
+
if (cached && cached.until > Date.now()) return cached.bearer;
|
|
580
|
+
if (bearers.get(key) !== pending) return this.bearer(token);
|
|
581
|
+
}
|
|
582
|
+
const next = this.exchange(token);
|
|
583
|
+
bearers.set(key, next);
|
|
584
|
+
return (await next).bearer;
|
|
585
|
+
}
|
|
586
|
+
async exchange(token) {
|
|
587
|
+
const response = await this.send(`${this.origin}/api/auth/token`, {
|
|
588
|
+
redirect: "error",
|
|
589
|
+
signal: AbortSignal.timeout(3e4),
|
|
590
|
+
headers: { authorization: `Bearer ${token}` }
|
|
591
|
+
});
|
|
592
|
+
if (!response.ok) {
|
|
593
|
+
await response.body?.cancel();
|
|
594
|
+
if (response.status === 404 || response.status === 405) return {
|
|
595
|
+
bearer: token,
|
|
596
|
+
until: Date.now() + 6e5
|
|
597
|
+
};
|
|
598
|
+
if (response.status === 401) throw new ShareAuthError();
|
|
599
|
+
throw new Error(`Share request failed (${response.status}).`);
|
|
600
|
+
}
|
|
601
|
+
const { token: jwt } = jwtSchema.parse(parseJsonText(Buffer.from(await readBoundedBytes(response, 65536)).toString()));
|
|
602
|
+
const { exp } = jwtPayloadSchema.parse(parseJsonText(Buffer.from(jwt.split(".")[1] ?? "", "base64url").toString()));
|
|
603
|
+
return {
|
|
604
|
+
bearer: jwt,
|
|
605
|
+
until: exp * 1e3 - 6e4
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
async warm() {
|
|
609
|
+
if (this.token) await this.bearer(this.token);
|
|
610
|
+
await (await this.send(`${this.origin}/api/v2/shares`, {
|
|
611
|
+
redirect: "error",
|
|
612
|
+
signal: AbortSignal.timeout(1e4)
|
|
613
|
+
})).body?.cancel();
|
|
614
|
+
}
|
|
558
615
|
async create(bundle, requestId = randomUUID()) {
|
|
559
616
|
return linkSchema.parse(await this.api("/api/v2/shares", "POST", shareRequestBody(bundle, requestId)));
|
|
560
617
|
}
|
|
@@ -606,20 +663,16 @@ function sharedGit(cwd, args) {
|
|
|
606
663
|
"-c",
|
|
607
664
|
"core.fsmonitor=false",
|
|
608
665
|
...args
|
|
609
|
-
], {
|
|
610
|
-
env,
|
|
611
|
-
timeout: 3e5
|
|
612
|
-
});
|
|
666
|
+
], { env });
|
|
613
667
|
}
|
|
614
|
-
function fetchError(stderr
|
|
615
|
-
if (/not our ref|couldn't find remote ref|unadvertised object/i.test(stderr)) return new ReviewInputError(
|
|
668
|
+
function fetchError(stderr) {
|
|
669
|
+
if (/not our ref|couldn't find remote ref|unadvertised object/i.test(stderr)) return new ReviewInputError("The shared commits are no longer available on GitHub. Ask the sender to restore them, then retry.", 409);
|
|
616
670
|
if (/could not read (?:username|password)|authentication failed|permission denied \(publickey|repository not found|returned error: 40[13]|\bSAML\b/i.test(stderr)) return new ReviewInputError("Git couldn't access this GitHub repository. Your Whiteboard sign-in doesn't grant repository access, so set up Git credentials for it, then retry.", 409);
|
|
617
671
|
return new ReviewInputError("Could not fetch the GitHub repository. Check your connection and Git credentials for this repository, then retry.", 409);
|
|
618
672
|
}
|
|
619
|
-
/**
|
|
620
|
-
* `commits` are other commits the board's references read at; a plan has
|
|
673
|
+
/** `commits` are other commits the board's references read at; a plan has
|
|
621
674
|
* only those. */
|
|
622
|
-
async function fetchPinnedRepository(root, url, pins,
|
|
675
|
+
async function fetchPinnedRepository(root, url, pins, commits = []) {
|
|
623
676
|
const named = [...pins ? [{
|
|
624
677
|
commit: pins.base,
|
|
625
678
|
ref: "base"
|
|
@@ -636,41 +689,42 @@ async function fetchPinnedRepository(root, url, pins, publishing = false, commit
|
|
|
636
689
|
mode: 448
|
|
637
690
|
});
|
|
638
691
|
await sharedGit(root, ["init", "--quiet"]);
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
692
|
+
await sharedGit(root, [
|
|
693
|
+
"config",
|
|
694
|
+
"core.hooksPath",
|
|
695
|
+
"/dev/null"
|
|
696
|
+
]);
|
|
697
|
+
await sharedGit(root, [
|
|
698
|
+
"config",
|
|
699
|
+
"core.fsmonitor",
|
|
700
|
+
"false"
|
|
701
|
+
]);
|
|
702
|
+
if (process.platform === "win32") await sharedGit(root, [
|
|
703
|
+
"config",
|
|
704
|
+
"core.longpaths",
|
|
705
|
+
"true"
|
|
706
|
+
]);
|
|
707
|
+
await sharedGit(root, [
|
|
708
|
+
"remote",
|
|
709
|
+
"add",
|
|
710
|
+
"origin",
|
|
711
|
+
{ remote: url }
|
|
712
|
+
]);
|
|
658
713
|
try {
|
|
659
714
|
await sharedGit(root, [
|
|
660
715
|
"fetch",
|
|
661
716
|
"--no-tags",
|
|
662
717
|
"--force",
|
|
663
|
-
|
|
664
|
-
{ remote: publishing ? url : "origin" },
|
|
718
|
+
"origin",
|
|
665
719
|
...named.map(({ commit, ref }) => ({ refspec: {
|
|
666
720
|
from: commit,
|
|
667
|
-
to:
|
|
721
|
+
to: `refs/review/${ref}`
|
|
668
722
|
} }))
|
|
669
723
|
]);
|
|
670
724
|
} catch (error) {
|
|
671
|
-
throw fetchError(error instanceof Error && "stderr" in error ? String(error.stderr) : ""
|
|
725
|
+
throw fetchError(error instanceof Error && "stderr" in error ? String(error.stderr) : "");
|
|
672
726
|
}
|
|
673
|
-
|
|
727
|
+
for (const { commit } of named) await sharedGit(root, [
|
|
674
728
|
"cat-file",
|
|
675
729
|
"-e",
|
|
676
730
|
{ rev: `${commit}^{commit}` }
|
|
@@ -711,7 +765,7 @@ async function fetchSharedCommits(root, commits, share) {
|
|
|
711
765
|
} }))
|
|
712
766
|
]);
|
|
713
767
|
} catch (error) {
|
|
714
|
-
throw fetchError(error instanceof Error && "stderr" in error ? String(error.stderr) : ""
|
|
768
|
+
throw fetchError(error instanceof Error && "stderr" in error ? String(error.stderr) : "");
|
|
715
769
|
}
|
|
716
770
|
}
|
|
717
771
|
/** Drops the refs `fetchSharedCommits` kept for a share, once the share is
|
|
@@ -746,6 +800,11 @@ async function cloneSharedRepository(root, url) {
|
|
|
746
800
|
"core.fsmonitor",
|
|
747
801
|
"false"
|
|
748
802
|
]);
|
|
803
|
+
if (process.platform === "win32") await sharedGit(root, [
|
|
804
|
+
"config",
|
|
805
|
+
"core.longpaths",
|
|
806
|
+
"true"
|
|
807
|
+
]);
|
|
749
808
|
await sharedGit(root, [
|
|
750
809
|
"remote",
|
|
751
810
|
"add",
|
|
@@ -760,7 +819,7 @@ async function cloneSharedRepository(root, url) {
|
|
|
760
819
|
"HEAD"
|
|
761
820
|
]);
|
|
762
821
|
} catch (error) {
|
|
763
|
-
throw fetchError(error instanceof Error && "stderr" in error ? String(error.stderr) : ""
|
|
822
|
+
throw fetchError(error instanceof Error && "stderr" in error ? String(error.stderr) : "");
|
|
764
823
|
}
|
|
765
824
|
await sharedGit(root, [
|
|
766
825
|
"checkout",
|
|
@@ -768,28 +827,6 @@ async function cloneSharedRepository(root, url) {
|
|
|
768
827
|
"FETCH_HEAD"
|
|
769
828
|
]);
|
|
770
829
|
}
|
|
771
|
-
async function repositoryReady(root, pins, commits = []) {
|
|
772
|
-
if (![
|
|
773
|
-
pins.base,
|
|
774
|
-
pins.head,
|
|
775
|
-
...commits
|
|
776
|
-
].every((commit) => COMMIT_ID.test(commit))) return false;
|
|
777
|
-
try {
|
|
778
|
-
if ((await sharedGit(root, ["rev-parse", "HEAD"])).stdout.trim() !== pins.head) return false;
|
|
779
|
-
for (const commit of [
|
|
780
|
-
pins.base,
|
|
781
|
-
pins.head,
|
|
782
|
-
...commits
|
|
783
|
-
]) await sharedGit(root, [
|
|
784
|
-
"cat-file",
|
|
785
|
-
"-e",
|
|
786
|
-
{ rev: `${commit}^{commit}` }
|
|
787
|
-
]);
|
|
788
|
-
return true;
|
|
789
|
-
} catch {
|
|
790
|
-
return false;
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
830
|
async function readShareRepository(root) {
|
|
794
831
|
let cloneUrl;
|
|
795
832
|
try {
|
|
@@ -803,23 +840,6 @@ async function readShareRepository(root) {
|
|
|
803
840
|
}
|
|
804
841
|
return { cloneUrl };
|
|
805
842
|
}
|
|
806
|
-
/** Fetches through origin itself, so its transport and credentials apply. */
|
|
807
|
-
async function verifyShareRepository(root, pins, commits = []) {
|
|
808
|
-
const origin = (await sharedGit(root, [
|
|
809
|
-
"remote",
|
|
810
|
-
"get-url",
|
|
811
|
-
"origin"
|
|
812
|
-
])).stdout.trim();
|
|
813
|
-
const temporary = await mkdtemp(path.join(tmpdir(), "review-share-check-"));
|
|
814
|
-
try {
|
|
815
|
-
await fetchPinnedRepository(temporary, origin, pins, true, commits);
|
|
816
|
-
} finally {
|
|
817
|
-
await rm(temporary, {
|
|
818
|
-
recursive: true,
|
|
819
|
-
force: true
|
|
820
|
-
});
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
843
|
//#endregion
|
|
824
844
|
//#region src/sharing/import.ts
|
|
825
845
|
const sharedSnapshotSchema = z.strictObject({
|
|
@@ -868,6 +888,10 @@ const mapSchema = softwareModelDataSchema.extend({
|
|
|
868
888
|
})) }))
|
|
869
889
|
});
|
|
870
890
|
z.strictObject({ maps: z.record(z.string(), mapSchema) });
|
|
891
|
+
/** Commits and traces live in a checkout; a document alone needs none. */
|
|
892
|
+
function needsRepository(bundle, snapshot) {
|
|
893
|
+
return Boolean(snapshot.pins || referenceCommits(snapshot).length || Object.keys(bundle.traces).length);
|
|
894
|
+
}
|
|
871
895
|
function validateShareBundle(input) {
|
|
872
896
|
const bundle = shareBundleSchema.parse(input);
|
|
873
897
|
const stored = bundle.snapshot;
|
|
@@ -876,7 +900,7 @@ function validateShareBundle(input) {
|
|
|
876
900
|
checkReferences(snapshot.document);
|
|
877
901
|
validateShareSources(snapshot);
|
|
878
902
|
assertCommitIds(referenceCommits(snapshot));
|
|
879
|
-
if ((
|
|
903
|
+
if (needsRepository(bundle, snapshot) && !bundle.repository) throw new ReviewInputError("This share can only be viewed in the browser.", 409);
|
|
880
904
|
const maps = z.record(z.string(), mapSchema).parse(bundle.maps);
|
|
881
905
|
if (!snapshot.pins && Object.keys(maps).length) throw new Error("Shared maps require source pins.");
|
|
882
906
|
const traces = /* @__PURE__ */ new Map();
|
|
@@ -913,443 +937,112 @@ function liftSharedLenses(stored, migrated) {
|
|
|
913
937
|
...(kept.length || lenses.length) && { lenses: [...kept, ...lenses] }
|
|
914
938
|
};
|
|
915
939
|
}
|
|
916
|
-
|
|
940
|
+
/** Names a share link: reopening it finds the copy it made. */
|
|
941
|
+
function shareKey(origin, capability) {
|
|
917
942
|
const url = new URL(origin);
|
|
918
943
|
capabilitySchema.parse(capability);
|
|
919
|
-
return
|
|
944
|
+
return createHash("sha256").update(JSON.stringify([url.origin, capability])).digest("hex");
|
|
920
945
|
}
|
|
921
|
-
/**
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
downloads = /* @__PURE__ */ new Set();
|
|
934
|
-
trackImport(job) {
|
|
935
|
-
this.downloads.add(job);
|
|
936
|
-
job.finally(() => this.downloads.delete(job));
|
|
946
|
+
/** Imports a share as an ordinary board, once per link: the link's copy
|
|
947
|
+
* comes back while it exists, even from Trash. */
|
|
948
|
+
async function importShare(input, key, received, attribution) {
|
|
949
|
+
const { store, data } = input;
|
|
950
|
+
const existing = store.copyOf(key);
|
|
951
|
+
if (existing) return existing;
|
|
952
|
+
const { bundle, snapshot, maps } = validateShareBundle(received);
|
|
953
|
+
const cloneUrl = bundle.repository?.cloneUrl;
|
|
954
|
+
let repositoryId;
|
|
955
|
+
if (cloneUrl && (needsRepository(bundle, snapshot) || store.checkoutsOf(cloneUrl).length)) {
|
|
956
|
+
input.onStage?.("fetching");
|
|
957
|
+
repositoryId = await shareRepository(input, cloneUrl, snapshot.pins, referenceCommits(snapshot), key);
|
|
937
958
|
}
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
}
|
|
956
|
-
purgeExpired() {
|
|
957
|
-
if (this.purgePending) return this.purgePending;
|
|
958
|
-
const expired = [...this.attention].filter(([, state]) => state.trashedAt && Date.parse(state.trashedAt) <= Date.now() - 2592e6);
|
|
959
|
-
const pending = (async () => {
|
|
960
|
-
for (const [id] of expired) await this.removeLocal(id);
|
|
961
|
-
})();
|
|
962
|
-
this.purgePending = pending.finally(() => {
|
|
963
|
-
this.purgePending = void 0;
|
|
964
|
-
});
|
|
965
|
-
return this.purgePending;
|
|
966
|
-
}
|
|
967
|
-
connect(store, data) {
|
|
968
|
-
this.local = {
|
|
969
|
-
store,
|
|
970
|
-
data
|
|
971
|
-
};
|
|
972
|
-
store.askHistory.setExternalWriteGuard((id) => this.assertWritable(id));
|
|
973
|
-
data.workspaces.attachExternalReviews({
|
|
974
|
-
has: (id) => this.has(id) || !this.catalogLoaded && id.startsWith("shared-"),
|
|
975
|
-
subscribe: (listener) => this.subscribe(listener)
|
|
959
|
+
const pins = snapshot.pins && repositoryId ? {
|
|
960
|
+
...snapshot.pins,
|
|
961
|
+
repositoryId
|
|
962
|
+
} : void 0;
|
|
963
|
+
input.onStage?.("validating");
|
|
964
|
+
const ranges = Object.values(maps).flatMap((map) => map.elements.flatMap((element) => (element.sourceRanges ?? []).map((range) => ({
|
|
965
|
+
...range,
|
|
966
|
+
side: map.side
|
|
967
|
+
}))));
|
|
968
|
+
if (pins && ranges.length) await data.validateSources(pins, ranges);
|
|
969
|
+
const ids = new Map([...Object.keys(bundle.traces), ...Object.keys(maps)].map((id) => [id, randomUUID()]));
|
|
970
|
+
if (repositoryId) {
|
|
971
|
+
for (const [id, trace] of Object.entries(bundle.traces)) await data.upload({
|
|
972
|
+
kind: "trace",
|
|
973
|
+
id: ids.get(id),
|
|
974
|
+
repositoryId,
|
|
975
|
+
trace
|
|
976
976
|
});
|
|
977
|
+
for (const [id, { commit, side, elements, relationships }] of Object.entries(maps)) store.putResource(ids.get(id), repositoryId, "map", "application/json", Buffer.from(JSON.stringify({
|
|
978
|
+
commit,
|
|
979
|
+
side,
|
|
980
|
+
elements,
|
|
981
|
+
relationships
|
|
982
|
+
})));
|
|
977
983
|
}
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
984
|
+
let document = JSON.stringify(snapshot.document);
|
|
985
|
+
for (const [id, copy] of ids) document = document.replaceAll(id, copy);
|
|
986
|
+
const { reviewId } = await store.execute({ operation: {
|
|
987
|
+
type: "create",
|
|
988
|
+
...snapshot.title && { title: snapshot.title },
|
|
989
|
+
...pins ? { target: {
|
|
990
|
+
kind: "commits",
|
|
991
|
+
...pins
|
|
992
|
+
} } : repositoryId && { target: {
|
|
993
|
+
kind: "project",
|
|
994
|
+
repositoryId
|
|
995
|
+
} }
|
|
996
|
+
} }, {
|
|
997
|
+
document: JSON.parse(document),
|
|
998
|
+
lenses: snapshot.lenses,
|
|
999
|
+
origin: snapshot.origin,
|
|
1000
|
+
shared: {
|
|
1001
|
+
...attribution,
|
|
1002
|
+
cloneUrl,
|
|
1003
|
+
key
|
|
1004
|
+
},
|
|
1005
|
+
copiedFrom: snapshot.reviewId
|
|
1006
|
+
}, { kind: "person" });
|
|
1007
|
+
return reviewId;
|
|
1008
|
+
}
|
|
1009
|
+
/** A checkout of the share's repository with every commit it reads at: the
|
|
1010
|
+
* receiver's own when they have one, else one Desktop clones. */
|
|
1011
|
+
async function shareRepository({ store, data, ...git }, cloneUrl, pins, commits, key) {
|
|
1012
|
+
const root = path.join(devReviewHome(), "shared-repositories");
|
|
1013
|
+
await mkdir(root, {
|
|
1014
|
+
recursive: true,
|
|
1015
|
+
mode: 448
|
|
1016
|
+
});
|
|
1017
|
+
const name = cloneUrl.replace(/\/+$/, "").replace(/\.git$/, "").split("/").at(-1);
|
|
1018
|
+
const managed = path.join(await realpath(root), `${safeStorageSegment(name || "repository")}-${createHash("sha256").update(cloneUrl).digest("hex").slice(0, 8)}`);
|
|
1019
|
+
const own = store.checkoutsOf(cloneUrl).find((id) => store.repositoryPath(id) !== managed);
|
|
1020
|
+
const cloned = store.repositories().some((repository) => repository.path === managed);
|
|
1021
|
+
if (!own && !(cloned && existsSync(path.join(managed, ".git")))) {
|
|
1022
|
+
await rm(managed, {
|
|
1023
|
+
recursive: true,
|
|
1024
|
+
force: true
|
|
991
1025
|
});
|
|
992
|
-
for (const listener of this.listeners) listener();
|
|
993
|
-
}
|
|
994
|
-
repositoryRoot(id) {
|
|
995
|
-
if (!/^shared-[a-f0-9]{64}$/.test(id)) throw new ReviewInputError("Invalid shared review ID.");
|
|
996
|
-
return path.join(this.root, ".repositories", id);
|
|
997
|
-
}
|
|
998
|
-
async prepare(id) {
|
|
999
|
-
const active = this.jobs.get(id);
|
|
1000
|
-
if (active) return active;
|
|
1001
|
-
const job = this.prepareRepository(id).finally(() => this.jobs.delete(id));
|
|
1002
|
-
this.jobs.set(id, job);
|
|
1003
|
-
return job;
|
|
1004
|
-
}
|
|
1005
|
-
async prepareRepository(id) {
|
|
1006
|
-
const local = this.local;
|
|
1007
|
-
const saved = this.validated.get(id);
|
|
1008
|
-
if (!saved) throw new ReviewInputError("Shared review is not available.", 404);
|
|
1009
|
-
if (!saved.snapshot.pins) {
|
|
1010
|
-
await this.prepareUnpinned(id, saved.bundle.repository?.cloneUrl);
|
|
1011
|
-
return;
|
|
1012
|
-
}
|
|
1013
|
-
if (!local) throw new ReviewInputError("Repository service is unavailable.", 409);
|
|
1014
|
-
const root = this.repositoryRoot(id);
|
|
1015
|
-
const commits = referenceCommits(saved.snapshot);
|
|
1016
1026
|
try {
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
await local.data.workspaces.remove(id);
|
|
1021
|
-
if (prior) await local.data.forgetRepository(prior);
|
|
1022
|
-
await rm(root, {
|
|
1023
|
-
recursive: true,
|
|
1024
|
-
force: true
|
|
1025
|
-
});
|
|
1026
|
-
await this.fetchRepository(root, saved.bundle.repository.cloneUrl, saved.snapshot.pins, false, commits);
|
|
1027
|
-
await sharedGit(root, [
|
|
1027
|
+
if (pins) {
|
|
1028
|
+
await (git.fetchRepository ?? fetchPinnedRepository)(managed, cloneUrl, pins, commits);
|
|
1029
|
+
await sharedGit(managed, [
|
|
1028
1030
|
"checkout",
|
|
1029
1031
|
"--detach",
|
|
1030
|
-
{ commit:
|
|
1032
|
+
{ commit: pins.head }
|
|
1031
1033
|
]);
|
|
1032
|
-
}
|
|
1033
|
-
const repository = await local.data.register(root);
|
|
1034
|
-
this.repositories.set(id, repository.id);
|
|
1035
|
-
await writeFile(path.join(this.root, id, "repository.json"), JSON.stringify({
|
|
1036
|
-
repositoryId: repository.id,
|
|
1037
|
-
ready: false
|
|
1038
|
-
}), { mode: 384 });
|
|
1039
|
-
const pins = {
|
|
1040
|
-
...saved.snapshot.pins,
|
|
1041
|
-
repositoryId: repository.id
|
|
1042
|
-
};
|
|
1043
|
-
this.setStatus(id, "validating");
|
|
1044
|
-
await local.data.validatePins(pins);
|
|
1045
|
-
await this.validateReferences(saved, repository.id, pins);
|
|
1046
|
-
await local.data.workspaces.open(id, pins);
|
|
1047
|
-
if (local.data.workspaces.list(id).some((workspace) => !workspace.rootPath)) throw new ReviewInputError("Could not prepare the pinned checkout. Retry opening the share.", 409);
|
|
1048
|
-
await writeFile(path.join(this.root, id, "repository.json"), JSON.stringify({
|
|
1049
|
-
repositoryId: repository.id,
|
|
1050
|
-
ready: true
|
|
1051
|
-
}), { mode: 384 });
|
|
1052
|
-
this.setStatus(id, "ready");
|
|
1034
|
+
} else await (git.cloneRepository ?? cloneSharedRepository)(managed, cloneUrl);
|
|
1053
1035
|
} catch (error) {
|
|
1054
|
-
|
|
1055
|
-
this.setStatus(id, "error", message);
|
|
1056
|
-
throw new ReviewInputError(message, 409);
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
/** Reads each of a shared board's references at its own commits, in the
|
|
1060
|
-
* checkout of its repository. */
|
|
1061
|
-
async validateReferences(saved, repositoryId, pins) {
|
|
1062
|
-
const references = /* @__PURE__ */ new Map();
|
|
1063
|
-
const add = (at, range) => {
|
|
1064
|
-
const key = JSON.stringify([at.base, at.head]);
|
|
1065
|
-
const group = references.get(key) ?? {
|
|
1066
|
-
pins: at,
|
|
1067
|
-
ranges: []
|
|
1068
|
-
};
|
|
1069
|
-
group.ranges.push(range);
|
|
1070
|
-
references.set(key, group);
|
|
1071
|
-
};
|
|
1072
|
-
for (const { source } of sourceReferences(saved.snapshot.document, { repositoryId })) add({
|
|
1073
|
-
...anchorPins(source, pins),
|
|
1074
|
-
repositoryId
|
|
1075
|
-
}, source);
|
|
1076
|
-
if (pins) for (const map of Object.values(saved.maps)) for (const element of map.elements) for (const range of element.sourceRanges ?? []) add(pins, {
|
|
1077
|
-
...range,
|
|
1078
|
-
side: map.side
|
|
1079
|
-
});
|
|
1080
|
-
for (const group of references.values()) await this.local.data.validateSources(group.pins, group.ranges);
|
|
1081
|
-
}
|
|
1082
|
-
/** Files an unpinned board under a local checkout of its repository,
|
|
1083
|
-
* else a managed clone. */
|
|
1084
|
-
async prepareUnpinned(id, cloneUrl) {
|
|
1085
|
-
const local = this.local;
|
|
1086
|
-
const saved = this.validated.get(id);
|
|
1087
|
-
if (!cloneUrl || !local) {
|
|
1088
|
-
this.setStatus(id, "ready");
|
|
1089
|
-
return;
|
|
1090
|
-
}
|
|
1091
|
-
const root = this.repositoryRoot(id);
|
|
1092
|
-
try {
|
|
1093
|
-
this.setStatus(id, "fetching");
|
|
1094
|
-
const managed = path.join(await realpath(this.root), ".repositories");
|
|
1095
|
-
let repositoryId = local.store.checkoutsOf(cloneUrl).find((checkout) => !local.store.repositoryPath(checkout).startsWith(managed));
|
|
1096
|
-
if (!repositoryId) {
|
|
1097
|
-
if (!existsSync(path.join(root, ".git"))) {
|
|
1098
|
-
await rm(root, {
|
|
1099
|
-
recursive: true,
|
|
1100
|
-
force: true
|
|
1101
|
-
});
|
|
1102
|
-
await this.cloneRepository(root, cloneUrl);
|
|
1103
|
-
}
|
|
1104
|
-
repositoryId = (await local.data.register(root)).id;
|
|
1105
|
-
}
|
|
1106
|
-
await fetchSharedCommits(local.store.repositoryPath(repositoryId), referenceCommits(saved.snapshot, repositoryId), id);
|
|
1107
|
-
this.setStatus(id, "validating");
|
|
1108
|
-
await this.validateReferences(saved, repositoryId);
|
|
1109
|
-
this.repositories.set(id, repositoryId);
|
|
1110
|
-
await writeFile(path.join(this.root, id, "repository.json"), JSON.stringify({
|
|
1111
|
-
repositoryId,
|
|
1112
|
-
ready: true
|
|
1113
|
-
}), { mode: 384 });
|
|
1114
|
-
this.setStatus(id, "ready");
|
|
1115
|
-
} catch (error) {
|
|
1116
|
-
const message = error instanceof ReviewInputError ? error.message : "Could not prepare the shared repository. Check Git credentials and retry.";
|
|
1117
|
-
this.setStatus(id, "error", message);
|
|
1118
|
-
throw new ReviewInputError(message, 409);
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1121
|
-
async assertReady(id) {
|
|
1122
|
-
const saved = this.validated.get(id);
|
|
1123
|
-
if (!saved || saved.snapshot.pins && !await repositoryReady(this.repositoryRoot(id), saved.snapshot.pins, referenceCommits(saved.snapshot))) {
|
|
1124
|
-
this.setStatus(id, "error", "The managed checkout is missing. Reopen the share link to fetch it again.");
|
|
1125
|
-
throw new ReviewInputError(this.status(id).error, 409);
|
|
1126
|
-
}
|
|
1127
|
-
this.get(id);
|
|
1128
|
-
}
|
|
1129
|
-
subscribe(listener) {
|
|
1130
|
-
this.listeners.add(listener);
|
|
1131
|
-
return () => {
|
|
1132
|
-
this.listeners.delete(listener);
|
|
1133
|
-
};
|
|
1134
|
-
}
|
|
1135
|
-
async load() {
|
|
1136
|
-
await mkdir(this.root, {
|
|
1137
|
-
recursive: true,
|
|
1138
|
-
mode: 448
|
|
1139
|
-
});
|
|
1140
|
-
for (const id of await readdir(this.root)) {
|
|
1141
|
-
if (!/^shared-[a-f0-9]{64}$/.test(id)) continue;
|
|
1142
|
-
if (!existsSync(path.join(this.root, id, "bundle.json"))) {
|
|
1143
|
-
await rm(path.join(this.root, id), {
|
|
1144
|
-
recursive: true,
|
|
1145
|
-
force: true
|
|
1146
|
-
});
|
|
1147
|
-
continue;
|
|
1148
|
-
}
|
|
1149
|
-
let saved;
|
|
1150
|
-
try {
|
|
1151
|
-
saved = await this.readValidated(id);
|
|
1152
|
-
} catch {
|
|
1153
|
-
await rename(path.join(this.root, id), path.join(this.root, `.invalid-${id}-${Date.now()}`));
|
|
1154
|
-
console.warn("A cached shared review was corrupt. Reopen its share link to download it again.");
|
|
1155
|
-
continue;
|
|
1156
|
-
}
|
|
1157
|
-
const { attribution, validated } = saved;
|
|
1158
|
-
this.loaded.set(id, { attribution });
|
|
1159
|
-
this.validated.set(id, validated);
|
|
1160
|
-
let prepared = false;
|
|
1161
|
-
try {
|
|
1162
|
-
const metadata = z.strictObject({
|
|
1163
|
-
repositoryId: z.string(),
|
|
1164
|
-
ready: z.boolean()
|
|
1165
|
-
}).parse(JSON.parse(await readFile(path.join(this.root, id, "repository.json"), "utf8")));
|
|
1166
|
-
if (this.local?.store.repositoryPath(metadata.repositoryId) === path.join(await realpath(this.root), ".repositories", id) || !validated.snapshot.pins && this.local?.store.repositories().some((repository) => repository.id === metadata.repositoryId)) {
|
|
1167
|
-
this.repositories.set(id, metadata.repositoryId);
|
|
1168
|
-
prepared = metadata.ready;
|
|
1169
|
-
}
|
|
1170
|
-
} catch {}
|
|
1171
|
-
if (!validated.snapshot.pins) {
|
|
1172
|
-
if (this.repositories.has(id) || !validated.bundle.repository) this.setStatus(id, "ready");
|
|
1173
|
-
else this.prepare(id).catch(() => {});
|
|
1174
|
-
} else if (prepared && this.local && await repositoryReady(this.repositoryRoot(id), validated.snapshot.pins, referenceCommits(validated.snapshot))) {
|
|
1175
|
-
const repository = await this.local.data.register(this.repositoryRoot(id));
|
|
1176
|
-
this.repositories.set(id, repository.id);
|
|
1177
|
-
this.setStatus(id, "ready");
|
|
1178
|
-
} else this.setStatus(id, "error", "Reopen the share link to fetch its repository.");
|
|
1179
|
-
const attentionPath = path.join(this.root, id, "attention.json");
|
|
1180
|
-
if (existsSync(attentionPath)) {
|
|
1181
|
-
const raw = JSON.parse(await readFile(attentionPath, "utf8"));
|
|
1182
|
-
const migrated = Object.hasOwn(raw, "dismissedAt") || Object.hasOwn(raw, "deletedAt");
|
|
1183
|
-
const state = z.strictObject({
|
|
1184
|
-
viewedAt: z.string().nullable(),
|
|
1185
|
-
trashedAt: z.string().nullable()
|
|
1186
|
-
}).parse(migrated ? {
|
|
1187
|
-
viewedAt: raw.viewedAt,
|
|
1188
|
-
trashedAt: Object.hasOwn(raw, "deletedAt") ? raw.deletedAt : raw.dismissedAt ? (/* @__PURE__ */ new Date()).toISOString() : null
|
|
1189
|
-
} : raw);
|
|
1190
|
-
this.attention.set(id, state);
|
|
1191
|
-
if (migrated) await writeFile(attentionPath, JSON.stringify(state), { mode: 384 });
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
await this.purgeExpired();
|
|
1195
|
-
this.catalogLoaded = true;
|
|
1196
|
-
for (const listener of this.listeners) listener();
|
|
1197
|
-
}
|
|
1198
|
-
assertWritable(id) {
|
|
1199
|
-
const trashedAt = this.attention.get(id)?.trashedAt;
|
|
1200
|
-
if (trashedAt) throw new ReviewInputError(`This whiteboard was moved to Trash on ${new Date(trashedAt).toLocaleDateString("en-US", {
|
|
1201
|
-
month: "short",
|
|
1202
|
-
day: "numeric"
|
|
1203
|
-
})}. Restore it with session_lifecycle({"sessionId":"${id}","state":"active"}) to continue.`, 409);
|
|
1204
|
-
}
|
|
1205
|
-
get(id) {
|
|
1206
|
-
const loaded = this.loaded.get(id);
|
|
1207
|
-
if (!loaded) throw new ReviewInputError("Shared review is not available.", 404);
|
|
1208
|
-
const validated = this.validated.get(id);
|
|
1209
|
-
const repositoryId = this.repositories.get(id);
|
|
1210
|
-
if (this.status(id).stage !== "ready" || validated.snapshot.pins && (!repositoryId || !existsSync(path.join(this.repositoryRoot(id), ".git")))) throw new ReviewInputError(this.status(id).error ?? "Fetch the shared repository before opening this review.", 409);
|
|
1211
|
-
return {
|
|
1212
|
-
...validated,
|
|
1213
|
-
snapshot: {
|
|
1214
|
-
...validated.snapshot,
|
|
1215
|
-
reviewId: id,
|
|
1216
|
-
trashedAt: this.attention.get(id)?.trashedAt ?? null,
|
|
1217
|
-
pins: validated.snapshot.pins ? {
|
|
1218
|
-
...validated.snapshot.pins,
|
|
1219
|
-
repositoryId
|
|
1220
|
-
} : void 0,
|
|
1221
|
-
target: validated.snapshot.pins ? {
|
|
1222
|
-
kind: "commits",
|
|
1223
|
-
...validated.snapshot.pins,
|
|
1224
|
-
repositoryId
|
|
1225
|
-
} : repositoryId ? {
|
|
1226
|
-
kind: "project",
|
|
1227
|
-
repositoryId
|
|
1228
|
-
} : void 0,
|
|
1229
|
-
shared: {
|
|
1230
|
-
...loaded.attribution,
|
|
1231
|
-
cloneUrl: validated.bundle.repository?.cloneUrl
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
};
|
|
1235
|
-
}
|
|
1236
|
-
list() {
|
|
1237
|
-
const reviews = this.loaded.keys().filter((id) => this.status(id).stage === "ready" && (!this.validated.get(id)?.snapshot.pins || existsSync(path.join(this.repositoryRoot(id), ".git")))).map((id) => {
|
|
1238
|
-
const { document: _document, ...snapshot } = this.get(id).snapshot;
|
|
1239
|
-
const project = snapshot.target ? this.local?.store.checkoutProject(snapshot.target.repositoryId) : void 0;
|
|
1240
|
-
return {
|
|
1241
|
-
...snapshot,
|
|
1242
|
-
firstCreatedAt: snapshot.version === 0 ? snapshot.createdAt : void 0,
|
|
1243
|
-
repositoryName: "Shared review",
|
|
1244
|
-
...project && { project },
|
|
1245
|
-
viewedAt: this.attention.get(id)?.viewedAt ?? null,
|
|
1246
|
-
trashedAt: this.attention.get(id)?.trashedAt ?? null
|
|
1247
|
-
};
|
|
1248
|
-
}).toArray();
|
|
1249
|
-
return this.local?.store.withDiffStats(reviews) ?? reviews;
|
|
1250
|
-
}
|
|
1251
|
-
async removeLocal(id) {
|
|
1252
|
-
await this.jobs.get(id)?.catch(() => {});
|
|
1253
|
-
if (!this.loaded.has(id)) throw new ReviewInputError("Shared review is not available.", 404);
|
|
1254
|
-
await this.local?.data.workspaces.remove(id);
|
|
1255
|
-
const repositoryId = this.repositories.get(id);
|
|
1256
|
-
if (repositoryId) {
|
|
1257
|
-
const checkout = this.local?.store.repositoryPath(repositoryId);
|
|
1258
|
-
if (checkout) await forgetSharedCommits(checkout, id).catch((error) => console.error(`Could not drop the refs kept for share ${id}:`, error));
|
|
1259
|
-
await this.local?.data.forgetRepository(repositoryId);
|
|
1260
|
-
await this.local?.store.unregisterRepository(repositoryId);
|
|
1261
|
-
}
|
|
1262
|
-
await rm(this.repositoryRoot(id), {
|
|
1263
|
-
recursive: true,
|
|
1264
|
-
force: true
|
|
1265
|
-
});
|
|
1266
|
-
this.repositories.delete(id);
|
|
1267
|
-
this.states.delete(id);
|
|
1268
|
-
await rm(path.join(this.root, id), {
|
|
1269
|
-
recursive: true,
|
|
1270
|
-
force: true
|
|
1271
|
-
});
|
|
1272
|
-
this.local?.store.askHistory.removeReview(id);
|
|
1273
|
-
this.loaded.delete(id);
|
|
1274
|
-
this.validated.delete(id);
|
|
1275
|
-
this.attention.delete(id);
|
|
1276
|
-
for (const listener of this.listeners) listener();
|
|
1277
|
-
}
|
|
1278
|
-
async setAttention(id) {
|
|
1279
|
-
await this.updateAttention(id, "view");
|
|
1280
|
-
}
|
|
1281
|
-
async setLifecycle(id, state) {
|
|
1282
|
-
await this.updateAttention(id, state);
|
|
1283
|
-
}
|
|
1284
|
-
async updateAttention(id, action) {
|
|
1285
|
-
this.get(id);
|
|
1286
|
-
const trashedAt = this.attention.get(id)?.trashedAt;
|
|
1287
|
-
if (trashedAt && Date.parse(trashedAt) <= Date.now() - 2592e6) {
|
|
1288
|
-
await this.removeLocal(id);
|
|
1289
|
-
throw new ReviewInputError("The 30-day recovery period has ended. This whiteboard was permanently deleted.", 404);
|
|
1290
|
-
}
|
|
1291
|
-
if (action === "view") this.assertWritable(id);
|
|
1292
|
-
const state = this.attention.get(id) ?? {
|
|
1293
|
-
viewedAt: null,
|
|
1294
|
-
trashedAt: null
|
|
1295
|
-
};
|
|
1296
|
-
if (action === "view") state.viewedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1297
|
-
else state.trashedAt = action === "trash" ? state.trashedAt ?? (/* @__PURE__ */ new Date()).toISOString() : null;
|
|
1298
|
-
await writeFile(path.join(this.root, id, "attention.json"), JSON.stringify(state), { mode: 384 });
|
|
1299
|
-
this.attention.set(id, state);
|
|
1300
|
-
for (const listener of this.listeners) listener();
|
|
1301
|
-
}
|
|
1302
|
-
async import(origin, capability, bundle, attribution) {
|
|
1303
|
-
const validated = validateShareBundle(bundle);
|
|
1304
|
-
const id = sharedReviewId(origin, capability);
|
|
1305
|
-
this.assertWritable(id);
|
|
1306
|
-
await mkdir(this.root, {
|
|
1307
|
-
recursive: true,
|
|
1308
|
-
mode: 448
|
|
1309
|
-
});
|
|
1310
|
-
const staging = await mkdtemp(path.join(this.root, ".import-"));
|
|
1311
|
-
try {
|
|
1312
|
-
await writeFile(path.join(staging, "bundle.json"), JSON.stringify(validated.bundle), { mode: 384 });
|
|
1313
|
-
if (attribution) await writeFile(path.join(staging, "attribution.json"), JSON.stringify(attribution), { mode: 384 });
|
|
1314
|
-
try {
|
|
1315
|
-
await rename(staging, path.join(this.root, id));
|
|
1316
|
-
} catch (error) {
|
|
1317
|
-
if (!(error instanceof Error && "code" in error && ["ENOTEMPTY", "EEXIST"].includes(String(error.code)))) throw error;
|
|
1318
|
-
const existing = await this.read(id);
|
|
1319
|
-
if (JSON.stringify(existing) !== JSON.stringify(validated.bundle)) throw new Error("An immutable share changed its bundle.");
|
|
1320
|
-
}
|
|
1321
|
-
} finally {
|
|
1322
|
-
await rm(staging, {
|
|
1036
|
+
await rm(managed, {
|
|
1323
1037
|
recursive: true,
|
|
1324
1038
|
force: true
|
|
1325
1039
|
});
|
|
1040
|
+
throw error;
|
|
1326
1041
|
}
|
|
1327
|
-
this.loaded.set(id, { attribution });
|
|
1328
|
-
this.validated.set(id, validated);
|
|
1329
|
-
for (const listener of this.listeners) listener();
|
|
1330
|
-
await this.prepare(id);
|
|
1331
|
-
return id;
|
|
1332
|
-
}
|
|
1333
|
-
async read(id) {
|
|
1334
|
-
return (await this.readValidated(id)).validated.bundle;
|
|
1335
1042
|
}
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
if ((await stat(file)).size > 16777216) throw new Error("Shared bundle is too large.");
|
|
1341
|
-
let attribution;
|
|
1342
|
-
try {
|
|
1343
|
-
attribution = z.strictObject({
|
|
1344
|
-
login: z.string(),
|
|
1345
|
-
sharedAt: z.number()
|
|
1346
|
-
}).parse(JSON.parse(await readFile(path.join(dir, "attribution.json"), "utf8")));
|
|
1347
|
-
} catch {}
|
|
1348
|
-
return {
|
|
1349
|
-
attribution,
|
|
1350
|
-
validated: validateShareBundle(JSON.parse(await readFile(file, "utf8")))
|
|
1351
|
-
};
|
|
1352
|
-
}
|
|
1353
|
-
};
|
|
1043
|
+
const repositoryId = own ?? (await data.register(managed)).id;
|
|
1044
|
+
await fetchSharedCommits(store.repositoryPath(repositoryId), [...pins ? [pins.base, pins.head] : [], ...commits], key);
|
|
1045
|
+
return repositoryId;
|
|
1046
|
+
}
|
|
1354
1047
|
//#endregion
|
|
1355
|
-
export {
|
|
1048
|
+
export { parseShareLink as _, readShareRepository as a, exportShare as c, lensReport as d, progressUpdateSchema as f, readBoundedStream as g, StreamLimitError as h, forgetSharedCommits as i, validateShareSources as l, uncategorizedReport as m, shareKey as n, ShareAuthError as o, reviewProgress as p, validateShareBundle as r, ShareClient as s, importShare as t, legacyModeSchema as u, shareIdSchema as v };
|