@nanocollective/roster 0.1.0-beta.2 → 0.1.0-beta.3
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/cli.js +94 -26
- package/dist/worker/assets/assets/css/base.css +13 -0
- package/dist/worker/assets/assets/js/api.js +30 -0
- package/dist/worker/assets/assets/js/app.js +37 -2
- package/dist/worker/index.js +69 -24
- package/package.json +1 -1
- package/templates/portal/css/base.css +13 -0
- package/templates/portal/js/api.js +30 -0
- package/templates/portal/js/app.js +37 -2
package/dist/cli.js
CHANGED
|
@@ -2913,7 +2913,20 @@ function workerBundle() {
|
|
|
2913
2913
|
}
|
|
2914
2914
|
return null;
|
|
2915
2915
|
}
|
|
2916
|
-
function wrangler(args) {
|
|
2916
|
+
async function wrangler(args) {
|
|
2917
|
+
let code = 1;
|
|
2918
|
+
for (let attempt = 1; attempt <= 3; attempt++) {
|
|
2919
|
+
code = await wranglerOnce(args);
|
|
2920
|
+
if (code === 0) return 0;
|
|
2921
|
+
if (attempt < 3) {
|
|
2922
|
+
process.stdout.write(` wrangler failed; trying again (${attempt + 1} of 3)\u2026
|
|
2923
|
+
`);
|
|
2924
|
+
await new Promise((r) => setTimeout(r, 15e3 * attempt));
|
|
2925
|
+
}
|
|
2926
|
+
}
|
|
2927
|
+
return code;
|
|
2928
|
+
}
|
|
2929
|
+
function wranglerOnce(args) {
|
|
2917
2930
|
return new Promise((resolve8) => {
|
|
2918
2931
|
const child = spawn("npx", ["--yes", WRANGLER, ...args], { stdio: "inherit" });
|
|
2919
2932
|
child.on("close", (code) => resolve8(code ?? 1));
|
|
@@ -6922,7 +6935,7 @@ var TIMELINE_PR = `
|
|
|
6922
6935
|
... on ReadyForReviewEvent { actor { login } createdAt }
|
|
6923
6936
|
... on ReviewRequestedEvent {
|
|
6924
6937
|
actor { login } createdAt
|
|
6925
|
-
requestedReviewer { ... on User { login } ... on
|
|
6938
|
+
requestedReviewer { __typename ... on User { login } ... on Bot { login } }
|
|
6926
6939
|
}
|
|
6927
6940
|
`;
|
|
6928
6941
|
var CLOSED_FIRST = 30;
|
|
@@ -7167,7 +7180,9 @@ function event(e) {
|
|
|
7167
7180
|
type: "review-requested",
|
|
7168
7181
|
actor: who,
|
|
7169
7182
|
createdAt: at,
|
|
7170
|
-
|
|
7183
|
+
/* A team's name needs the read:org scope, which a portal signed in with `repo` alone does
|
|
7184
|
+
not have, and asking for it fails the whole thread. Its type needs nothing. */
|
|
7185
|
+
assignee: e.requestedReviewer?.login ?? (e.requestedReviewer?.__typename === "Team" ? "a team" : "")
|
|
7171
7186
|
};
|
|
7172
7187
|
case "LabeledEvent":
|
|
7173
7188
|
return { type: "labeled", actor: who, createdAt: at, label: e.label?.name ?? "" };
|
|
@@ -7542,6 +7557,8 @@ var Snapshots = class {
|
|
|
7542
7557
|
repos = /* @__PURE__ */ new Map();
|
|
7543
7558
|
inflight = /* @__PURE__ */ new Map();
|
|
7544
7559
|
checked = /* @__PURE__ */ new Map();
|
|
7560
|
+
/** Who wants to hear how a refresh in flight is going. Every caller that joined it. */
|
|
7561
|
+
listeners = /* @__PURE__ */ new Map();
|
|
7545
7562
|
get(repo) {
|
|
7546
7563
|
return this.repos.get(repo);
|
|
7547
7564
|
}
|
|
@@ -7556,11 +7573,16 @@ var Snapshots = class {
|
|
|
7556
7573
|
if (!opts.force && this.repos.has(repo) && Date.now() - last < this.freshMs) {
|
|
7557
7574
|
return Promise.resolve({ ok: true, changed: false });
|
|
7558
7575
|
}
|
|
7576
|
+
if (opts.report) {
|
|
7577
|
+
if (!this.listeners.has(repo)) this.listeners.set(repo, /* @__PURE__ */ new Set());
|
|
7578
|
+
this.listeners.get(repo).add(opts.report);
|
|
7579
|
+
}
|
|
7559
7580
|
const running = this.inflight.get(repo);
|
|
7560
7581
|
if (running) return running;
|
|
7561
|
-
const work = this.load(gh, repo, opts.pathsOnly === true).finally(
|
|
7562
|
-
|
|
7563
|
-
|
|
7582
|
+
const work = this.load(gh, repo, opts.pathsOnly === true).finally(() => {
|
|
7583
|
+
this.inflight.delete(repo);
|
|
7584
|
+
this.listeners.delete(repo);
|
|
7585
|
+
});
|
|
7564
7586
|
this.inflight.set(repo, work);
|
|
7565
7587
|
return work;
|
|
7566
7588
|
}
|
|
@@ -7581,7 +7603,11 @@ var Snapshots = class {
|
|
|
7581
7603
|
if (commit2) snap.sha = commit2;
|
|
7582
7604
|
void this.kv.put(`blob:${sha}`, text2);
|
|
7583
7605
|
}
|
|
7606
|
+
say(repo, step) {
|
|
7607
|
+
for (const report3 of this.listeners.get(repo) ?? []) report3(repo, step);
|
|
7608
|
+
}
|
|
7584
7609
|
async load(gh, repo, pathsOnly) {
|
|
7610
|
+
this.say(repo, "checking for changes");
|
|
7585
7611
|
const head2 = await gh.request("GET", `repos/${repo}/commits/HEAD`, {
|
|
7586
7612
|
accept: "application/vnd.github.sha",
|
|
7587
7613
|
as: "text"
|
|
@@ -7593,8 +7619,10 @@ var Snapshots = class {
|
|
|
7593
7619
|
const sha = head2.data.trim();
|
|
7594
7620
|
const before = this.repos.get(repo);
|
|
7595
7621
|
if (before && before.sha === sha && before.pathsOnly === pathsOnly) {
|
|
7622
|
+
this.say(repo, "up to date");
|
|
7596
7623
|
return { ok: true, changed: false };
|
|
7597
7624
|
}
|
|
7625
|
+
this.say(repo, "reading the file list");
|
|
7598
7626
|
const next = await this.build(gh, repo, sha, pathsOnly, before);
|
|
7599
7627
|
if (!next.ok) return { ok: false, changed: false, error: next.error, status: next.status };
|
|
7600
7628
|
this.repos.set(repo, next.snap);
|
|
@@ -7643,6 +7671,7 @@ var Snapshots = class {
|
|
|
7643
7671
|
})
|
|
7644
7672
|
);
|
|
7645
7673
|
if (missing2.length > TARBALL_OVER) {
|
|
7674
|
+
this.say(repo, "downloading the repository");
|
|
7646
7675
|
const tgz = await gh.request("GET", `repos/${repo}/tarball/${sha}`, {
|
|
7647
7676
|
as: "bytes"
|
|
7648
7677
|
});
|
|
@@ -7657,6 +7686,9 @@ var Snapshots = class {
|
|
|
7657
7686
|
void this.kv.put(`blob:${e.sha}`, text2);
|
|
7658
7687
|
}
|
|
7659
7688
|
} else {
|
|
7689
|
+
if (missing2.length) {
|
|
7690
|
+
this.say(repo, `fetching ${missing2.length} changed file${missing2.length === 1 ? "" : "s"}`);
|
|
7691
|
+
}
|
|
7660
7692
|
await pool2(missing2, 8, async ([, e]) => {
|
|
7661
7693
|
const res = await gh.request("GET", `repos/${repo}/git/blobs/${e.sha}`, {
|
|
7662
7694
|
accept: "application/vnd.github.raw",
|
|
@@ -7694,6 +7726,7 @@ var Snapshots = class {
|
|
|
7694
7726
|
else ask.push(path);
|
|
7695
7727
|
}
|
|
7696
7728
|
const [owner, name] = repo.split("/");
|
|
7729
|
+
if (ask.length) this.say(repo, "reading file dates");
|
|
7697
7730
|
for (let i = 0; i < ask.length; i += DATES_PER_QUERY) {
|
|
7698
7731
|
const batch = ask.slice(i, i + DATES_PER_QUERY);
|
|
7699
7732
|
const fields = batch.map(
|
|
@@ -7824,19 +7857,24 @@ async function handlePortal(req, portal, actor) {
|
|
|
7824
7857
|
}
|
|
7825
7858
|
async function ready(c, opts = {}) {
|
|
7826
7859
|
const { portal, actor } = c;
|
|
7827
|
-
const
|
|
7860
|
+
const report3 = opts.report;
|
|
7861
|
+
const ops = await portal.snapshots.refresh(actor.gh, `${portal.org}/${portal.opsName}`, {
|
|
7862
|
+
force: opts.force,
|
|
7863
|
+
report: report3
|
|
7864
|
+
});
|
|
7828
7865
|
if (!ops.ok) {
|
|
7829
7866
|
throw new HttpError(
|
|
7830
7867
|
ops.status === 404 || ops.status === 401 ? ops.status : 502,
|
|
7831
7868
|
`could not read ${portal.org}/${portal.opsName}: ${ops.error}`
|
|
7832
7869
|
);
|
|
7833
7870
|
}
|
|
7871
|
+
report3?.(`${portal.org}/${portal.opsName}`, "ready");
|
|
7834
7872
|
const org = readOrg(portal.ws.opsDir, parseYaml2);
|
|
7835
7873
|
const brains = (org.staff ?? []).map((s) => String(s.dir ?? s.handle));
|
|
7836
7874
|
const products = opts.products ? (org.repos ?? []).map((r) => String(r.name)).filter((n) => n !== portal.opsName && !brains.includes(n)) : [];
|
|
7837
7875
|
const results = await Promise.all([
|
|
7838
7876
|
...brains.map(
|
|
7839
|
-
(d) => portal.snapshots.refresh(actor.gh, `${portal.org}/${d}`, { force: opts.force }).then((r) => ({ dir: d, ...r }))
|
|
7877
|
+
(d) => portal.snapshots.refresh(actor.gh, `${portal.org}/${d}`, { force: opts.force, report: report3 }).then((r) => ({ dir: d, ...r }))
|
|
7840
7878
|
),
|
|
7841
7879
|
...products.map(
|
|
7842
7880
|
(d) => portal.snapshots.refresh(actor.gh, `${portal.org}/${d}`, { force: opts.force, pathsOnly: true }).then((r) => ({ dir: d, ...r }))
|
|
@@ -7864,24 +7902,26 @@ var ROUTES = {
|
|
|
7864
7902
|
headers: { "content-type": asset.type, "cache-control": "public, max-age=86400" }
|
|
7865
7903
|
});
|
|
7866
7904
|
},
|
|
7905
|
+
/* The whole org. With ?progress=1 it is a stream instead: a line per step as it is read from
|
|
7906
|
+
GitHub, then the org, so a first load can say what it is doing rather than "Loading…". */
|
|
7867
7907
|
"/api/org": async (c) => {
|
|
7868
|
-
|
|
7869
|
-
const {
|
|
7870
|
-
const
|
|
7871
|
-
|
|
7872
|
-
|
|
7873
|
-
|
|
7874
|
-
|
|
7875
|
-
|
|
7876
|
-
|
|
7877
|
-
|
|
7878
|
-
|
|
7879
|
-
|
|
7880
|
-
|
|
7881
|
-
|
|
7882
|
-
|
|
7883
|
-
|
|
7884
|
-
|
|
7908
|
+
if (c.url.searchParams.get("progress") !== "1") return json(await orgExport(c));
|
|
7909
|
+
const { readable, writable } = new TransformStream();
|
|
7910
|
+
const out = writable.getWriter();
|
|
7911
|
+
const line = (o) => out.write(new TextEncoder().encode(`${JSON.stringify(o)}
|
|
7912
|
+
`));
|
|
7913
|
+
const report3 = (repo, step) => {
|
|
7914
|
+
void line({ repo: repo.slice(repo.indexOf("/") + 1), step });
|
|
7915
|
+
};
|
|
7916
|
+
void orgExport(c, report3).then((org) => line({ org })).catch(
|
|
7917
|
+
(err) => line({ error: String(err?.message ?? err), status: err.status })
|
|
7918
|
+
).finally(() => out.close());
|
|
7919
|
+
return new Response(readable, {
|
|
7920
|
+
headers: {
|
|
7921
|
+
"content-type": "application/x-ndjson; charset=utf-8",
|
|
7922
|
+
"cache-control": "no-store"
|
|
7923
|
+
}
|
|
7924
|
+
});
|
|
7885
7925
|
},
|
|
7886
7926
|
/* Every file in the org layer the portal may write: isWritable's allowlist, nothing more. */
|
|
7887
7927
|
"/api/orglayer": async (c) => {
|
|
@@ -8443,6 +8483,24 @@ ${diff}`,
|
|
|
8443
8483
|
return new Response(bytes2, { headers: { "content-type": type, "cache-control": "no-store" } });
|
|
8444
8484
|
}
|
|
8445
8485
|
};
|
|
8486
|
+
async function orgExport(c, report3) {
|
|
8487
|
+
const { portal, actor } = c;
|
|
8488
|
+
const { org, brains } = await ready(c, { report: report3 });
|
|
8489
|
+
const byRoot = /* @__PURE__ */ new Map();
|
|
8490
|
+
await Promise.all(
|
|
8491
|
+
brains.map(async (dir) => {
|
|
8492
|
+
const repo = `${portal.org}/${dir}`;
|
|
8493
|
+
const snap = portal.snapshots.get(repo);
|
|
8494
|
+
if (!snap) return;
|
|
8495
|
+
report3?.(repo, "reading recent history");
|
|
8496
|
+
byRoot.set(join29(portal.ws.root, dir), await loadHistory(actor.gh, portal.kv, repo, snap.sha));
|
|
8497
|
+
report3?.(repo, "ready");
|
|
8498
|
+
})
|
|
8499
|
+
);
|
|
8500
|
+
const data = buildExport(portal.ws, org, parseYaml2, { history: loadedHistory(byRoot) });
|
|
8501
|
+
const left = unfinished(portal.ws.opsDir, (org.staff ?? []).length);
|
|
8502
|
+
return { ...data, unfinished: left };
|
|
8503
|
+
}
|
|
8446
8504
|
function knownRepos(portal) {
|
|
8447
8505
|
const org = readOrg(portal.ws.opsDir, parseYaml2);
|
|
8448
8506
|
return (org.repos ?? []).map((r) => ({
|
|
@@ -9010,7 +9068,17 @@ async function portalCommand(argv) {
|
|
|
9010
9068
|
return;
|
|
9011
9069
|
}
|
|
9012
9070
|
res.writeHead(answer.status, Object.fromEntries(answer.headers));
|
|
9013
|
-
|
|
9071
|
+
if (!answer.body) {
|
|
9072
|
+
res.end();
|
|
9073
|
+
return;
|
|
9074
|
+
}
|
|
9075
|
+
const reader = answer.body.getReader();
|
|
9076
|
+
for (; ; ) {
|
|
9077
|
+
const { done, value } = await reader.read();
|
|
9078
|
+
if (done) break;
|
|
9079
|
+
res.write(value);
|
|
9080
|
+
}
|
|
9081
|
+
res.end();
|
|
9014
9082
|
};
|
|
9015
9083
|
const writeAllowed = (req) => {
|
|
9016
9084
|
if (req.method !== "POST") return false;
|
|
@@ -310,3 +310,16 @@ dialog.sheet.side .sidebar-x .iconbtn{margin-top:-4px}
|
|
|
310
310
|
.spinner{width:22px;height:22px;border-radius:50%;border:2px solid var(--line);border-top-color:var(--accent);
|
|
311
311
|
animation:spin .7s linear infinite}
|
|
312
312
|
@keyframes spin{to{transform:rotate(360deg)}}
|
|
313
|
+
|
|
314
|
+
/* The first load, while the org is read from GitHub: a row per repository. */
|
|
315
|
+
.loadlist{display:flex;flex-direction:column;gap:2px;max-width:520px}
|
|
316
|
+
.loadrow{display:grid;grid-template-columns:18px 140px 1fr;align-items:center;gap:10px;padding:7px 0;
|
|
317
|
+
font-size:13.5px;border-bottom:1px solid var(--line)}
|
|
318
|
+
.loadrow b{font-weight:500}
|
|
319
|
+
.loadrow .meta{color:var(--ink-dim)}
|
|
320
|
+
.loadmark{width:10px;height:10px;border-radius:50%;border:2px solid var(--accent-dim);
|
|
321
|
+
border-top-color:var(--accent);animation:loadspin .8s linear infinite}
|
|
322
|
+
.loadrow.done .loadmark{animation:none;border-color:var(--accent);background:var(--accent)}
|
|
323
|
+
.loadrow.done .meta{color:var(--ink-faint)}
|
|
324
|
+
@keyframes loadspin{to{transform:rotate(360deg)}}
|
|
325
|
+
@media (prefers-reduced-motion:reduce){.loadmark{animation:none}}
|
|
@@ -14,6 +14,36 @@ export const getSession = () =>
|
|
|
14
14
|
.catch(() => null);
|
|
15
15
|
|
|
16
16
|
export const getOrg = () => json("/api/org");
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The org, for the first load, saying what it is doing as it goes: `onStep(repo, step)` for each
|
|
20
|
+
* line the server streams, then the org itself. Anything that is not a stream (the setup answer,
|
|
21
|
+
* an older server) is read as plain JSON, so this is never worse than getOrg.
|
|
22
|
+
*/
|
|
23
|
+
export async function getOrgWithProgress(onStep) {
|
|
24
|
+
const res = await fetch("/api/org?progress=1", { cache: "no-store" });
|
|
25
|
+
if (res.status === 401) location.reload();
|
|
26
|
+
const type = String(res.headers?.get?.("content-type") ?? "");
|
|
27
|
+
if (!type.includes("ndjson") || !res.body?.pipeThrough) return res.json();
|
|
28
|
+
const reader = res.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
29
|
+
let buf = "";
|
|
30
|
+
for (;;) {
|
|
31
|
+
const { done, value } = await reader.read();
|
|
32
|
+
if (done) break;
|
|
33
|
+
buf += value;
|
|
34
|
+
let nl;
|
|
35
|
+
while ((nl = buf.indexOf("\n")) >= 0) {
|
|
36
|
+
const line = buf.slice(0, nl).trim();
|
|
37
|
+
buf = buf.slice(nl + 1);
|
|
38
|
+
if (!line) continue;
|
|
39
|
+
const msg = JSON.parse(line);
|
|
40
|
+
if (msg.org) return msg.org;
|
|
41
|
+
if (msg.error) throw new Error(msg.error);
|
|
42
|
+
onStep(msg.repo, msg.step);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
throw new Error("The org did not arrive. Reload to try again.");
|
|
46
|
+
}
|
|
17
47
|
export const getDocs = () => json("/api/docs");
|
|
18
48
|
export const getInbox = (force) => json("/api/inbox" + (force ? "?refresh=1" : ""));
|
|
19
49
|
export const getSync = () => json("/api/sync").catch(() => null);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* The shell: boot, the sidebar, and dispatching a view into <main>. */
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { getOrgWithProgress, getSession } from "./api.js";
|
|
4
4
|
import { $, el, store } from "./dom.js";
|
|
5
5
|
import { icon, iconHTML, staffIcon } from "./icons.js";
|
|
6
6
|
import { installLightbox } from "./lightbox.js";
|
|
@@ -96,7 +96,7 @@ export async function boot() {
|
|
|
96
96
|
/* Before there is a tenant the server answers every data route with `mode: setup`. That is
|
|
97
97
|
not an error state: it is the first thing a new user ever sees, and the whole page becomes
|
|
98
98
|
the thing that fixes it. */
|
|
99
|
-
const [first, session] = await Promise.all([
|
|
99
|
+
const [first, session] = await Promise.all([loadWithProgress(), getSession()]);
|
|
100
100
|
S.hosted = session?.hosted ? session : null;
|
|
101
101
|
if (S.hosted) showSignedIn(S.hosted.login);
|
|
102
102
|
if (first && first.mode === "setup") {
|
|
@@ -409,6 +409,41 @@ function render() {
|
|
|
409
409
|
(SCREEN[S.view] ?? viewBrain)(m);
|
|
410
410
|
}
|
|
411
411
|
|
|
412
|
+
/* ------------------------------- first load -------------------------------- */
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* The first read of the org, with what it is doing on screen. A cold start reads every
|
|
416
|
+
* repository from GitHub, which can take a while, and "Loading…" for fifteen seconds reads as
|
|
417
|
+
* broken. One row per repository, saying which step it is on, and a tick when it is ready.
|
|
418
|
+
*/
|
|
419
|
+
async function loadWithProgress() {
|
|
420
|
+
const main = $("#main");
|
|
421
|
+
const rows = new Map();
|
|
422
|
+
const list = el("div", { className: "loadlist" });
|
|
423
|
+
const head = el("p", { className: "sub", textContent: "Reading the org from GitHub…" });
|
|
424
|
+
// Only once something is actually slow: a warm load is over before this would be read.
|
|
425
|
+
const show = setTimeout(() => main.replaceChildren(head, list), 400);
|
|
426
|
+
try {
|
|
427
|
+
return await getOrgWithProgress((repo, step) => {
|
|
428
|
+
let row = rows.get(repo);
|
|
429
|
+
if (!row) {
|
|
430
|
+
row = el("div", { className: "loadrow" }, [
|
|
431
|
+
el("span", { className: "loadmark" }),
|
|
432
|
+
el("b", { textContent: repo }),
|
|
433
|
+
el("span", { className: "meta" }),
|
|
434
|
+
]);
|
|
435
|
+
rows.set(repo, row);
|
|
436
|
+
list.append(row);
|
|
437
|
+
}
|
|
438
|
+
const ready = step === "ready" || step === "up to date";
|
|
439
|
+
row.classList.toggle("done", ready);
|
|
440
|
+
row.lastChild.textContent = ready ? "ready" : step;
|
|
441
|
+
});
|
|
442
|
+
} finally {
|
|
443
|
+
clearTimeout(show);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
412
447
|
/* -------------------------------- signed in -------------------------------- */
|
|
413
448
|
|
|
414
449
|
/**
|
package/dist/worker/index.js
CHANGED
|
@@ -2218,7 +2218,7 @@ var TIMELINE_PR = `
|
|
|
2218
2218
|
... on ReadyForReviewEvent { actor { login } createdAt }
|
|
2219
2219
|
... on ReviewRequestedEvent {
|
|
2220
2220
|
actor { login } createdAt
|
|
2221
|
-
requestedReviewer { ... on User { login } ... on
|
|
2221
|
+
requestedReviewer { __typename ... on User { login } ... on Bot { login } }
|
|
2222
2222
|
}
|
|
2223
2223
|
`;
|
|
2224
2224
|
var CLOSED_FIRST = 30;
|
|
@@ -2463,7 +2463,9 @@ function event(e) {
|
|
|
2463
2463
|
type: "review-requested",
|
|
2464
2464
|
actor: who,
|
|
2465
2465
|
createdAt: at,
|
|
2466
|
-
|
|
2466
|
+
/* A team's name needs the read:org scope, which a portal signed in with `repo` alone does
|
|
2467
|
+
not have, and asking for it fails the whole thread. Its type needs nothing. */
|
|
2468
|
+
assignee: e.requestedReviewer?.login ?? (e.requestedReviewer?.__typename === "Team" ? "a team" : "")
|
|
2467
2469
|
};
|
|
2468
2470
|
case "LabeledEvent":
|
|
2469
2471
|
return { type: "labeled", actor: who, createdAt: at, label: e.label?.name ?? "" };
|
|
@@ -3001,6 +3003,8 @@ var Snapshots = class {
|
|
|
3001
3003
|
repos = /* @__PURE__ */ new Map();
|
|
3002
3004
|
inflight = /* @__PURE__ */ new Map();
|
|
3003
3005
|
checked = /* @__PURE__ */ new Map();
|
|
3006
|
+
/** Who wants to hear how a refresh in flight is going. Every caller that joined it. */
|
|
3007
|
+
listeners = /* @__PURE__ */ new Map();
|
|
3004
3008
|
get(repo) {
|
|
3005
3009
|
return this.repos.get(repo);
|
|
3006
3010
|
}
|
|
@@ -3015,11 +3019,16 @@ var Snapshots = class {
|
|
|
3015
3019
|
if (!opts.force && this.repos.has(repo) && Date.now() - last < this.freshMs) {
|
|
3016
3020
|
return Promise.resolve({ ok: true, changed: false });
|
|
3017
3021
|
}
|
|
3022
|
+
if (opts.report) {
|
|
3023
|
+
if (!this.listeners.has(repo)) this.listeners.set(repo, /* @__PURE__ */ new Set());
|
|
3024
|
+
this.listeners.get(repo).add(opts.report);
|
|
3025
|
+
}
|
|
3018
3026
|
const running = this.inflight.get(repo);
|
|
3019
3027
|
if (running) return running;
|
|
3020
|
-
const work = this.load(gh, repo, opts.pathsOnly === true).finally(
|
|
3021
|
-
|
|
3022
|
-
|
|
3028
|
+
const work = this.load(gh, repo, opts.pathsOnly === true).finally(() => {
|
|
3029
|
+
this.inflight.delete(repo);
|
|
3030
|
+
this.listeners.delete(repo);
|
|
3031
|
+
});
|
|
3023
3032
|
this.inflight.set(repo, work);
|
|
3024
3033
|
return work;
|
|
3025
3034
|
}
|
|
@@ -3040,7 +3049,11 @@ var Snapshots = class {
|
|
|
3040
3049
|
if (commit2) snap.sha = commit2;
|
|
3041
3050
|
void this.kv.put(`blob:${sha}`, text2);
|
|
3042
3051
|
}
|
|
3052
|
+
say(repo, step) {
|
|
3053
|
+
for (const report of this.listeners.get(repo) ?? []) report(repo, step);
|
|
3054
|
+
}
|
|
3043
3055
|
async load(gh, repo, pathsOnly) {
|
|
3056
|
+
this.say(repo, "checking for changes");
|
|
3044
3057
|
const head2 = await gh.request("GET", `repos/${repo}/commits/HEAD`, {
|
|
3045
3058
|
accept: "application/vnd.github.sha",
|
|
3046
3059
|
as: "text"
|
|
@@ -3052,8 +3065,10 @@ var Snapshots = class {
|
|
|
3052
3065
|
const sha = head2.data.trim();
|
|
3053
3066
|
const before = this.repos.get(repo);
|
|
3054
3067
|
if (before && before.sha === sha && before.pathsOnly === pathsOnly) {
|
|
3068
|
+
this.say(repo, "up to date");
|
|
3055
3069
|
return { ok: true, changed: false };
|
|
3056
3070
|
}
|
|
3071
|
+
this.say(repo, "reading the file list");
|
|
3057
3072
|
const next = await this.build(gh, repo, sha, pathsOnly, before);
|
|
3058
3073
|
if (!next.ok) return { ok: false, changed: false, error: next.error, status: next.status };
|
|
3059
3074
|
this.repos.set(repo, next.snap);
|
|
@@ -3102,6 +3117,7 @@ var Snapshots = class {
|
|
|
3102
3117
|
})
|
|
3103
3118
|
);
|
|
3104
3119
|
if (missing2.length > TARBALL_OVER) {
|
|
3120
|
+
this.say(repo, "downloading the repository");
|
|
3105
3121
|
const tgz = await gh.request("GET", `repos/${repo}/tarball/${sha}`, {
|
|
3106
3122
|
as: "bytes"
|
|
3107
3123
|
});
|
|
@@ -3116,6 +3132,9 @@ var Snapshots = class {
|
|
|
3116
3132
|
void this.kv.put(`blob:${e.sha}`, text2);
|
|
3117
3133
|
}
|
|
3118
3134
|
} else {
|
|
3135
|
+
if (missing2.length) {
|
|
3136
|
+
this.say(repo, `fetching ${missing2.length} changed file${missing2.length === 1 ? "" : "s"}`);
|
|
3137
|
+
}
|
|
3119
3138
|
await pool2(missing2, 8, async ([, e]) => {
|
|
3120
3139
|
const res = await gh.request("GET", `repos/${repo}/git/blobs/${e.sha}`, {
|
|
3121
3140
|
accept: "application/vnd.github.raw",
|
|
@@ -3153,6 +3172,7 @@ var Snapshots = class {
|
|
|
3153
3172
|
else ask.push(path);
|
|
3154
3173
|
}
|
|
3155
3174
|
const [owner, name] = repo.split("/");
|
|
3175
|
+
if (ask.length) this.say(repo, "reading file dates");
|
|
3156
3176
|
for (let i = 0; i < ask.length; i += DATES_PER_QUERY) {
|
|
3157
3177
|
const batch = ask.slice(i, i + DATES_PER_QUERY);
|
|
3158
3178
|
const fields = batch.map(
|
|
@@ -3283,19 +3303,24 @@ async function handlePortal(req, portal2, actor) {
|
|
|
3283
3303
|
}
|
|
3284
3304
|
async function ready(c, opts = {}) {
|
|
3285
3305
|
const { portal: portal2, actor } = c;
|
|
3286
|
-
const
|
|
3306
|
+
const report = opts.report;
|
|
3307
|
+
const ops = await portal2.snapshots.refresh(actor.gh, `${portal2.org}/${portal2.opsName}`, {
|
|
3308
|
+
force: opts.force,
|
|
3309
|
+
report
|
|
3310
|
+
});
|
|
3287
3311
|
if (!ops.ok) {
|
|
3288
3312
|
throw new HttpError(
|
|
3289
3313
|
ops.status === 404 || ops.status === 401 ? ops.status : 502,
|
|
3290
3314
|
`could not read ${portal2.org}/${portal2.opsName}: ${ops.error}`
|
|
3291
3315
|
);
|
|
3292
3316
|
}
|
|
3317
|
+
report?.(`${portal2.org}/${portal2.opsName}`, "ready");
|
|
3293
3318
|
const org = readOrg(portal2.ws.opsDir, parseYaml2);
|
|
3294
3319
|
const brains = (org.staff ?? []).map((s) => String(s.dir ?? s.handle));
|
|
3295
3320
|
const products = opts.products ? (org.repos ?? []).map((r) => String(r.name)).filter((n) => n !== portal2.opsName && !brains.includes(n)) : [];
|
|
3296
3321
|
const results = await Promise.all([
|
|
3297
3322
|
...brains.map(
|
|
3298
|
-
(d) => portal2.snapshots.refresh(actor.gh, `${portal2.org}/${d}`, { force: opts.force }).then((r) => ({ dir: d, ...r }))
|
|
3323
|
+
(d) => portal2.snapshots.refresh(actor.gh, `${portal2.org}/${d}`, { force: opts.force, report }).then((r) => ({ dir: d, ...r }))
|
|
3299
3324
|
),
|
|
3300
3325
|
...products.map(
|
|
3301
3326
|
(d) => portal2.snapshots.refresh(actor.gh, `${portal2.org}/${d}`, { force: opts.force, pathsOnly: true }).then((r) => ({ dir: d, ...r }))
|
|
@@ -3327,24 +3352,26 @@ var ROUTES = {
|
|
|
3327
3352
|
headers: { "content-type": asset.type, "cache-control": "public, max-age=86400" }
|
|
3328
3353
|
});
|
|
3329
3354
|
},
|
|
3355
|
+
/* The whole org. With ?progress=1 it is a stream instead: a line per step as it is read from
|
|
3356
|
+
GitHub, then the org, so a first load can say what it is doing rather than "Loading…". */
|
|
3330
3357
|
"/api/org": async (c) => {
|
|
3331
|
-
|
|
3332
|
-
const {
|
|
3333
|
-
const
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3358
|
+
if (c.url.searchParams.get("progress") !== "1") return json(await orgExport(c));
|
|
3359
|
+
const { readable, writable } = new TransformStream();
|
|
3360
|
+
const out = writable.getWriter();
|
|
3361
|
+
const line = (o) => out.write(new TextEncoder().encode(`${JSON.stringify(o)}
|
|
3362
|
+
`));
|
|
3363
|
+
const report = (repo, step) => {
|
|
3364
|
+
void line({ repo: repo.slice(repo.indexOf("/") + 1), step });
|
|
3365
|
+
};
|
|
3366
|
+
void orgExport(c, report).then((org) => line({ org })).catch(
|
|
3367
|
+
(err) => line({ error: String(err?.message ?? err), status: err.status })
|
|
3368
|
+
).finally(() => out.close());
|
|
3369
|
+
return new Response(readable, {
|
|
3370
|
+
headers: {
|
|
3371
|
+
"content-type": "application/x-ndjson; charset=utf-8",
|
|
3372
|
+
"cache-control": "no-store"
|
|
3373
|
+
}
|
|
3374
|
+
});
|
|
3348
3375
|
},
|
|
3349
3376
|
/* Every file in the org layer the portal may write: isWritable's allowlist, nothing more. */
|
|
3350
3377
|
"/api/orglayer": async (c) => {
|
|
@@ -3906,6 +3933,24 @@ ${diff}`,
|
|
|
3906
3933
|
return new Response(bytes, { headers: { "content-type": type, "cache-control": "no-store" } });
|
|
3907
3934
|
}
|
|
3908
3935
|
};
|
|
3936
|
+
async function orgExport(c, report) {
|
|
3937
|
+
const { portal: portal2, actor } = c;
|
|
3938
|
+
const { org, brains } = await ready(c, { report });
|
|
3939
|
+
const byRoot = /* @__PURE__ */ new Map();
|
|
3940
|
+
await Promise.all(
|
|
3941
|
+
brains.map(async (dir) => {
|
|
3942
|
+
const repo = `${portal2.org}/${dir}`;
|
|
3943
|
+
const snap = portal2.snapshots.get(repo);
|
|
3944
|
+
if (!snap) return;
|
|
3945
|
+
report?.(repo, "reading recent history");
|
|
3946
|
+
byRoot.set(join17(portal2.ws.root, dir), await loadHistory(actor.gh, portal2.kv, repo, snap.sha));
|
|
3947
|
+
report?.(repo, "ready");
|
|
3948
|
+
})
|
|
3949
|
+
);
|
|
3950
|
+
const data = buildExport(portal2.ws, org, parseYaml2, { history: loadedHistory(byRoot) });
|
|
3951
|
+
const left = unfinished(portal2.ws.opsDir, (org.staff ?? []).length);
|
|
3952
|
+
return { ...data, unfinished: left };
|
|
3953
|
+
}
|
|
3909
3954
|
function knownRepos(portal2) {
|
|
3910
3955
|
const org = readOrg(portal2.ws.opsDir, parseYaml2);
|
|
3911
3956
|
return (org.repos ?? []).map((r) => ({
|
package/package.json
CHANGED
|
@@ -310,3 +310,16 @@ dialog.sheet.side .sidebar-x .iconbtn{margin-top:-4px}
|
|
|
310
310
|
.spinner{width:22px;height:22px;border-radius:50%;border:2px solid var(--line);border-top-color:var(--accent);
|
|
311
311
|
animation:spin .7s linear infinite}
|
|
312
312
|
@keyframes spin{to{transform:rotate(360deg)}}
|
|
313
|
+
|
|
314
|
+
/* The first load, while the org is read from GitHub: a row per repository. */
|
|
315
|
+
.loadlist{display:flex;flex-direction:column;gap:2px;max-width:520px}
|
|
316
|
+
.loadrow{display:grid;grid-template-columns:18px 140px 1fr;align-items:center;gap:10px;padding:7px 0;
|
|
317
|
+
font-size:13.5px;border-bottom:1px solid var(--line)}
|
|
318
|
+
.loadrow b{font-weight:500}
|
|
319
|
+
.loadrow .meta{color:var(--ink-dim)}
|
|
320
|
+
.loadmark{width:10px;height:10px;border-radius:50%;border:2px solid var(--accent-dim);
|
|
321
|
+
border-top-color:var(--accent);animation:loadspin .8s linear infinite}
|
|
322
|
+
.loadrow.done .loadmark{animation:none;border-color:var(--accent);background:var(--accent)}
|
|
323
|
+
.loadrow.done .meta{color:var(--ink-faint)}
|
|
324
|
+
@keyframes loadspin{to{transform:rotate(360deg)}}
|
|
325
|
+
@media (prefers-reduced-motion:reduce){.loadmark{animation:none}}
|
|
@@ -14,6 +14,36 @@ export const getSession = () =>
|
|
|
14
14
|
.catch(() => null);
|
|
15
15
|
|
|
16
16
|
export const getOrg = () => json("/api/org");
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The org, for the first load, saying what it is doing as it goes: `onStep(repo, step)` for each
|
|
20
|
+
* line the server streams, then the org itself. Anything that is not a stream (the setup answer,
|
|
21
|
+
* an older server) is read as plain JSON, so this is never worse than getOrg.
|
|
22
|
+
*/
|
|
23
|
+
export async function getOrgWithProgress(onStep) {
|
|
24
|
+
const res = await fetch("/api/org?progress=1", { cache: "no-store" });
|
|
25
|
+
if (res.status === 401) location.reload();
|
|
26
|
+
const type = String(res.headers?.get?.("content-type") ?? "");
|
|
27
|
+
if (!type.includes("ndjson") || !res.body?.pipeThrough) return res.json();
|
|
28
|
+
const reader = res.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
29
|
+
let buf = "";
|
|
30
|
+
for (;;) {
|
|
31
|
+
const { done, value } = await reader.read();
|
|
32
|
+
if (done) break;
|
|
33
|
+
buf += value;
|
|
34
|
+
let nl;
|
|
35
|
+
while ((nl = buf.indexOf("\n")) >= 0) {
|
|
36
|
+
const line = buf.slice(0, nl).trim();
|
|
37
|
+
buf = buf.slice(nl + 1);
|
|
38
|
+
if (!line) continue;
|
|
39
|
+
const msg = JSON.parse(line);
|
|
40
|
+
if (msg.org) return msg.org;
|
|
41
|
+
if (msg.error) throw new Error(msg.error);
|
|
42
|
+
onStep(msg.repo, msg.step);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
throw new Error("The org did not arrive. Reload to try again.");
|
|
46
|
+
}
|
|
17
47
|
export const getDocs = () => json("/api/docs");
|
|
18
48
|
export const getInbox = (force) => json("/api/inbox" + (force ? "?refresh=1" : ""));
|
|
19
49
|
export const getSync = () => json("/api/sync").catch(() => null);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* The shell: boot, the sidebar, and dispatching a view into <main>. */
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { getOrgWithProgress, getSession } from "./api.js";
|
|
4
4
|
import { $, el, store } from "./dom.js";
|
|
5
5
|
import { icon, iconHTML, staffIcon } from "./icons.js";
|
|
6
6
|
import { installLightbox } from "./lightbox.js";
|
|
@@ -96,7 +96,7 @@ export async function boot() {
|
|
|
96
96
|
/* Before there is a tenant the server answers every data route with `mode: setup`. That is
|
|
97
97
|
not an error state: it is the first thing a new user ever sees, and the whole page becomes
|
|
98
98
|
the thing that fixes it. */
|
|
99
|
-
const [first, session] = await Promise.all([
|
|
99
|
+
const [first, session] = await Promise.all([loadWithProgress(), getSession()]);
|
|
100
100
|
S.hosted = session?.hosted ? session : null;
|
|
101
101
|
if (S.hosted) showSignedIn(S.hosted.login);
|
|
102
102
|
if (first && first.mode === "setup") {
|
|
@@ -409,6 +409,41 @@ function render() {
|
|
|
409
409
|
(SCREEN[S.view] ?? viewBrain)(m);
|
|
410
410
|
}
|
|
411
411
|
|
|
412
|
+
/* ------------------------------- first load -------------------------------- */
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* The first read of the org, with what it is doing on screen. A cold start reads every
|
|
416
|
+
* repository from GitHub, which can take a while, and "Loading…" for fifteen seconds reads as
|
|
417
|
+
* broken. One row per repository, saying which step it is on, and a tick when it is ready.
|
|
418
|
+
*/
|
|
419
|
+
async function loadWithProgress() {
|
|
420
|
+
const main = $("#main");
|
|
421
|
+
const rows = new Map();
|
|
422
|
+
const list = el("div", { className: "loadlist" });
|
|
423
|
+
const head = el("p", { className: "sub", textContent: "Reading the org from GitHub…" });
|
|
424
|
+
// Only once something is actually slow: a warm load is over before this would be read.
|
|
425
|
+
const show = setTimeout(() => main.replaceChildren(head, list), 400);
|
|
426
|
+
try {
|
|
427
|
+
return await getOrgWithProgress((repo, step) => {
|
|
428
|
+
let row = rows.get(repo);
|
|
429
|
+
if (!row) {
|
|
430
|
+
row = el("div", { className: "loadrow" }, [
|
|
431
|
+
el("span", { className: "loadmark" }),
|
|
432
|
+
el("b", { textContent: repo }),
|
|
433
|
+
el("span", { className: "meta" }),
|
|
434
|
+
]);
|
|
435
|
+
rows.set(repo, row);
|
|
436
|
+
list.append(row);
|
|
437
|
+
}
|
|
438
|
+
const ready = step === "ready" || step === "up to date";
|
|
439
|
+
row.classList.toggle("done", ready);
|
|
440
|
+
row.lastChild.textContent = ready ? "ready" : step;
|
|
441
|
+
});
|
|
442
|
+
} finally {
|
|
443
|
+
clearTimeout(show);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
412
447
|
/* -------------------------------- signed in -------------------------------- */
|
|
413
448
|
|
|
414
449
|
/**
|