@abraca/junis 2.85.0 → 2.87.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/dist/module.d.mts +17 -2
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +253 -21
  4. package/dist/runtime/assets/css/jun.css +1 -1
  5. package/dist/runtime/components/JunCampfirePresence.client.vue +75 -10
  6. package/dist/runtime/components/JunCollectionIntro.d.vue.ts +11 -0
  7. package/dist/runtime/components/JunCollectionIntro.vue +45 -0
  8. package/dist/runtime/components/JunCollectionIntro.vue.d.ts +11 -0
  9. package/dist/runtime/components/JunConfigRow.d.vue.ts +43 -0
  10. package/dist/runtime/components/JunConfigRow.vue +34 -0
  11. package/dist/runtime/components/JunConfigRow.vue.d.ts +43 -0
  12. package/dist/runtime/components/JunDocSurface.vue +3 -0
  13. package/dist/runtime/components/JunFooter.vue +1 -1
  14. package/dist/runtime/components/JunHorizontalTimeline.d.vue.ts +30 -0
  15. package/dist/runtime/components/JunHorizontalTimeline.vue.d.ts +30 -0
  16. package/dist/runtime/components/JunLinksRow.d.vue.ts +16 -1
  17. package/dist/runtime/components/JunLinksRow.vue +17 -7
  18. package/dist/runtime/components/JunLinksRow.vue.d.ts +16 -1
  19. package/dist/runtime/components/JunMedia.client.d.vue.ts +1 -1
  20. package/dist/runtime/components/JunMedia.client.vue.d.ts +1 -1
  21. package/dist/runtime/components/JunNavigation.vue +21 -4
  22. package/dist/runtime/components/JunNoteLinks.d.vue.ts +6 -0
  23. package/dist/runtime/components/JunNoteLinks.vue +57 -0
  24. package/dist/runtime/components/JunNoteLinks.vue.d.ts +6 -0
  25. package/dist/runtime/components/JunPageHero.d.vue.ts +8 -2
  26. package/dist/runtime/components/JunPageHero.vue +15 -3
  27. package/dist/runtime/components/JunPageHero.vue.d.ts +8 -2
  28. package/dist/runtime/components/JunReaders.d.vue.ts +11 -0
  29. package/dist/runtime/components/JunReaders.vue +99 -0
  30. package/dist/runtime/components/JunReaders.vue.d.ts +11 -0
  31. package/dist/runtime/components/JunSearch.client.vue +2 -2
  32. package/dist/runtime/components/JunSectionPresence.d.vue.ts +17 -0
  33. package/dist/runtime/components/JunSectionPresence.vue +99 -0
  34. package/dist/runtime/components/JunSectionPresence.vue.d.ts +17 -0
  35. package/dist/runtime/components/JunThreadComposer.d.vue.ts +37 -0
  36. package/dist/runtime/components/JunThreadComposer.vue +54 -0
  37. package/dist/runtime/components/JunThreadComposer.vue.d.ts +37 -0
  38. package/dist/runtime/components/JunTravellersChip.vue +35 -5
  39. package/dist/runtime/components/JunVideoEmbed.client.d.vue.ts +1 -1
  40. package/dist/runtime/components/JunVideoEmbed.client.vue.d.ts +1 -1
  41. package/dist/runtime/components/JunViewControl.d.vue.ts +29 -0
  42. package/dist/runtime/components/JunViewControl.vue +340 -0
  43. package/dist/runtime/components/JunViewControl.vue.d.ts +29 -0
  44. package/dist/runtime/components/JunViewControls.d.vue.ts +27 -0
  45. package/dist/runtime/components/JunViewControls.vue +94 -0
  46. package/dist/runtime/components/JunViewControls.vue.d.ts +27 -0
  47. package/dist/runtime/components/renderers/JunAppsRenderer.vue +45 -4
  48. package/dist/runtime/components/renderers/JunCinemaRenderer.vue +42 -4
  49. package/dist/runtime/components/renderers/JunConfigRenderer.vue +348 -225
  50. package/dist/runtime/components/renderers/JunCourseRenderer.d.vue.ts +10 -0
  51. package/dist/runtime/components/renderers/JunCourseRenderer.vue +229 -0
  52. package/dist/runtime/components/renderers/JunCourseRenderer.vue.d.ts +10 -0
  53. package/dist/runtime/components/renderers/JunCvRenderer.vue +44 -6
  54. package/dist/runtime/components/renderers/JunDeckRenderer.d.vue.ts +9 -0
  55. package/dist/runtime/components/renderers/JunDeckRenderer.vue +370 -0
  56. package/dist/runtime/components/renderers/JunDeckRenderer.vue.d.ts +9 -0
  57. package/dist/runtime/components/renderers/JunEntryRenderer.vue +151 -23
  58. package/dist/runtime/components/renderers/JunFestivalRenderer.vue +41 -4
  59. package/dist/runtime/components/renderers/JunGardenRenderer.d.vue.ts +10 -0
  60. package/dist/runtime/components/renderers/JunGardenRenderer.vue +280 -0
  61. package/dist/runtime/components/renderers/JunGardenRenderer.vue.d.ts +10 -0
  62. package/dist/runtime/components/renderers/JunGlobeRenderer.vue +43 -26
  63. package/dist/runtime/components/renderers/JunGuestbookRenderer.vue +96 -14
  64. package/dist/runtime/components/renderers/JunHomeRenderer.vue +28 -129
  65. package/dist/runtime/components/renderers/JunItemRenderer.d.vue.ts +10 -0
  66. package/dist/runtime/components/renderers/JunItemRenderer.vue +398 -0
  67. package/dist/runtime/components/renderers/JunItemRenderer.vue.d.ts +10 -0
  68. package/dist/runtime/components/renderers/JunJournalRenderer.vue +141 -11
  69. package/dist/runtime/components/renderers/JunLibraryRenderer.vue +295 -12
  70. package/dist/runtime/components/renderers/JunLinksRenderer.vue +33 -1
  71. package/dist/runtime/components/renderers/JunLiveRenderer.vue +37 -1
  72. package/dist/runtime/components/renderers/JunMosaicRenderer.vue +3 -2
  73. package/dist/runtime/components/renderers/JunMovieRenderer.vue +32 -5
  74. package/dist/runtime/components/renderers/JunNowRenderer.vue +38 -5
  75. package/dist/runtime/components/renderers/JunPollRenderer.d.vue.ts +9 -0
  76. package/dist/runtime/components/renderers/JunPollRenderer.vue +231 -0
  77. package/dist/runtime/components/renderers/JunPollRenderer.vue.d.ts +9 -0
  78. package/dist/runtime/components/renderers/JunProjectRenderer.vue +74 -18
  79. package/dist/runtime/components/renderers/JunServicesRenderer.vue +40 -2
  80. package/dist/runtime/components/renderers/JunStatsRenderer.vue +37 -50
  81. package/dist/runtime/components/renderers/JunThreadRenderer.d.vue.ts +9 -0
  82. package/dist/runtime/components/renderers/JunThreadRenderer.vue +304 -0
  83. package/dist/runtime/components/renderers/JunThreadRenderer.vue.d.ts +9 -0
  84. package/dist/runtime/components/renderers/JunTrackRenderer.vue +32 -4
  85. package/dist/runtime/components/renderers/JunUsesRenderer.vue +51 -5
  86. package/dist/runtime/components/renderers/JunWallRenderer.vue +60 -5
  87. package/dist/runtime/composables/useJunDeck.d.ts +66 -0
  88. package/dist/runtime/composables/useJunDeck.js +61 -0
  89. package/dist/runtime/composables/useJunDocPage.d.ts +14 -11
  90. package/dist/runtime/composables/useJunDocPage.js +67 -3
  91. package/dist/runtime/composables/useJunFollow.d.ts +65 -9
  92. package/dist/runtime/composables/useJunFollow.js +237 -20
  93. package/dist/runtime/composables/useJunGarden.d.ts +67 -0
  94. package/dist/runtime/composables/useJunGarden.js +92 -0
  95. package/dist/runtime/composables/useJunPresence.d.ts +26 -0
  96. package/dist/runtime/composables/useJunPresence.js +9 -2
  97. package/dist/runtime/composables/useJunSections.d.ts +73 -0
  98. package/dist/runtime/composables/useJunSections.js +117 -0
  99. package/dist/runtime/composables/useJunSettings.d.ts +1 -1
  100. package/dist/runtime/composables/useJunSettings.js +5 -1
  101. package/dist/runtime/composables/useJunSiteConfig.d.ts +37 -0
  102. package/dist/runtime/composables/useJunTheme.js +40 -2
  103. package/dist/runtime/composables/useJunViewOptions.d.ts +85 -0
  104. package/dist/runtime/composables/useJunViewOptions.js +63 -0
  105. package/dist/runtime/pages/doc.vue +52 -42
  106. package/dist/runtime/pages/index.vue +61 -35
  107. package/dist/runtime/plugins/jun-doc-tree.d.ts +2 -0
  108. package/dist/runtime/plugins/jun-doc-tree.js +26 -0
  109. package/dist/runtime/server/api/health.get.d.ts +19 -0
  110. package/dist/runtime/server/api/health.get.js +40 -0
  111. package/dist/runtime/server/api/links.get.d.ts +19 -0
  112. package/dist/runtime/server/api/links.get.js +37 -0
  113. package/dist/runtime/server/api/resolve/[...slug].get.d.ts +9 -0
  114. package/dist/runtime/server/api/resolve/[...slug].get.js +7 -2
  115. package/dist/runtime/server/api/stats.get.js +2 -1
  116. package/dist/runtime/server/api/tree.get.d.ts +9 -0
  117. package/dist/runtime/server/api/tree.get.js +23 -0
  118. package/dist/runtime/server/janitor/junJanitorActor.d.ts +13 -0
  119. package/dist/runtime/server/janitor/junJanitorActor.js +36 -5
  120. package/dist/runtime/server/janitor/junJanitorChores.js +8 -0
  121. package/dist/runtime/server/plugins/jun-bootstrap.js +103 -15
  122. package/dist/runtime/server/plugins/jun-doc-cache.js +42 -4
  123. package/dist/runtime/server/plugins/jun-janitor.js +7 -0
  124. package/dist/runtime/server/plugins/jun-rpc.js +293 -0
  125. package/dist/runtime/server/plugins/jun-watchdog.d.ts +2 -0
  126. package/dist/runtime/server/plugins/jun-watchdog.js +54 -0
  127. package/dist/runtime/server/routes/sitemap.xml.get.js +2 -0
  128. package/dist/runtime/server/utils/junBoot.d.ts +1 -0
  129. package/dist/runtime/server/utils/junBoot.js +4 -0
  130. package/dist/runtime/server/utils/junCache.d.ts +17 -0
  131. package/dist/runtime/server/utils/junCache.js +5 -0
  132. package/dist/runtime/server/utils/junSeedGate.d.ts +68 -0
  133. package/dist/runtime/server/utils/junSeedGate.js +41 -0
  134. package/dist/runtime/types.d.ts +57 -1
  135. package/dist/runtime/utils/junCourse.d.ts +106 -0
  136. package/dist/runtime/utils/junCourse.js +65 -0
  137. package/dist/runtime/utils/junGarden.d.ts +193 -0
  138. package/dist/runtime/utils/junGarden.js +233 -0
  139. package/dist/runtime/utils/junMetaSchemas.js +8 -1
  140. package/dist/runtime/utils/junModeration.d.ts +67 -0
  141. package/dist/runtime/utils/junModeration.js +20 -0
  142. package/dist/runtime/utils/junMotion.d.ts +26 -0
  143. package/dist/runtime/utils/junMotion.js +31 -0
  144. package/dist/runtime/utils/junPeople.d.ts +43 -0
  145. package/dist/runtime/utils/junPeople.js +9 -0
  146. package/dist/runtime/utils/junPoll.d.ts +79 -0
  147. package/dist/runtime/utils/junPoll.js +82 -0
  148. package/dist/runtime/utils/junReadiness.d.ts +131 -0
  149. package/dist/runtime/utils/junReadiness.js +69 -0
  150. package/dist/runtime/utils/junSections.d.ts +115 -0
  151. package/dist/runtime/utils/junSections.js +45 -0
  152. package/dist/runtime/utils/junSlides.d.ts +66 -0
  153. package/dist/runtime/utils/junSlides.js +47 -0
  154. package/dist/runtime/utils/junThread.d.ts +81 -0
  155. package/dist/runtime/utils/junThread.js +75 -0
  156. package/dist/runtime/utils/junViewSpecs.d.ts +671 -0
  157. package/dist/runtime/utils/junViewSpecs.js +534 -0
  158. package/dist/runtime/utils/junViewValues.d.ts +125 -0
  159. package/dist/runtime/utils/junViewValues.js +104 -0
  160. package/dist/types.d.mts +1 -1
  161. package/package.json +5 -1
@@ -0,0 +1,19 @@
1
+ import { type JunReadinessState } from '../../utils/junReadiness.js';
2
+ export interface JunHealthReport {
3
+ state: JunReadinessState;
4
+ healthy: boolean;
5
+ reason: string;
6
+ hint?: string;
7
+ /** The numbers the verdict was made from — so a reader need not guess. */
8
+ cache: {
9
+ tree: number;
10
+ slugs: number;
11
+ bodies: number;
12
+ };
13
+ /** Milliseconds since the doc-cache runner last swept IN THIS PROCESS. */
14
+ sweptMsAgo: number | null;
15
+ rootDocId: string;
16
+ ageMs: number;
17
+ }
18
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<JunHealthReport>>;
19
+ export default _default;
@@ -0,0 +1,40 @@
1
+ import { defineEventHandler, setResponseStatus } from "h3";
2
+ import { useRuntimeConfig, useStorage } from "nitropack/runtime";
3
+ import { junDocTree, junHeartbeat, junRootDocId, junSlugMap } from "../utils/junCache.js";
4
+ import { junBootedAt } from "../utils/junBoot.js";
5
+ import { junReadiness } from "../../utils/junReadiness.js";
6
+ export default defineEventHandler(async (event) => {
7
+ const storage = useStorage();
8
+ const [tree, slugs, bodyKeys, beat] = await Promise.all([
9
+ junDocTree(),
10
+ junSlugMap(),
11
+ storage.getKeys("doc-cache:html"),
12
+ junHeartbeat()
13
+ ]);
14
+ const ageMs = Date.now() - junBootedAt();
15
+ const sweptMsAgo = beat && beat.at >= junBootedAt() ? Date.now() - beat.at : null;
16
+ const features = (useRuntimeConfig().public.jun ?? {}).features ?? {};
17
+ const verdict = junReadiness({
18
+ treeSize: Object.keys(tree).length,
19
+ slugCount: Object.keys(slugs).length,
20
+ bodyCount: bodyKeys.length,
21
+ ageMs,
22
+ heartbeatAgeMs: sweptMsAgo,
23
+ expectHeartbeat: features.docCache !== false
24
+ });
25
+ if (!verdict.healthy) setResponseStatus(event, 503);
26
+ return {
27
+ state: verdict.state,
28
+ healthy: verdict.healthy,
29
+ reason: verdict.reason,
30
+ ...verdict.hint ? { hint: verdict.hint } : {},
31
+ cache: {
32
+ tree: Object.keys(tree).length,
33
+ slugs: Object.keys(slugs).length,
34
+ bodies: bodyKeys.length
35
+ },
36
+ sweptMsAgo,
37
+ rootDocId: junRootDocId(),
38
+ ageMs
39
+ };
40
+ });
@@ -0,0 +1,19 @@
1
+ import { type JunGardenEdge } from '../../utils/junGarden.js';
2
+ export interface JunLinkNode {
3
+ id: string;
4
+ label: string;
5
+ href: string;
6
+ type: string;
7
+ parentId?: string | null;
8
+ updatedAt: number;
9
+ maturity: string | null;
10
+ }
11
+ export interface JunLinkGraph {
12
+ nodes: JunLinkNode[];
13
+ edges: JunGardenEdge[];
14
+ /** How many bodies the cache had. Zero means "not warm yet", not "no links". */
15
+ scanned: number;
16
+ generatedAt: number;
17
+ }
18
+ declare const _default: import("h3").EventHandler<Omit<import("h3").EventHandlerRequest, "body">, Promise<JunLinkGraph>>;
19
+ export default _default;
@@ -0,0 +1,37 @@
1
+ import { defineCachedEventHandler } from "nitropack/runtime";
2
+ import { junDocHtml, junDocTree, junRootDocId, junSlugMap } from "../utils/junCache.js";
3
+ import { isJunOwnerOnlyDoc } from "../utils/junVisibility.js";
4
+ import { junGardenEdges, junMaturityOf } from "../../utils/junGarden.js";
5
+ export default defineCachedEventHandler(async () => {
6
+ const rootDocId = junRootDocId();
7
+ const [tree, idToSlug] = await Promise.all([junDocTree(), junSlugMap()]);
8
+ const nodes = [];
9
+ const slugToId = {};
10
+ const knownIds = /* @__PURE__ */ new Set();
11
+ for (const [id, entry] of Object.entries(tree)) {
12
+ if (!entry || entry.trashed) continue;
13
+ if (id === rootDocId || isJunOwnerOnlyDoc(entry)) continue;
14
+ const slug = idToSlug[id];
15
+ knownIds.add(id);
16
+ if (slug) slugToId[slug.toLowerCase()] = id;
17
+ nodes.push({
18
+ id,
19
+ label: entry.label ?? "",
20
+ href: `/${slug ?? id}`,
21
+ type: entry.type ?? "doc",
22
+ parentId: entry.parentId ?? null,
23
+ updatedAt: typeof entry.updatedAt === "number" ? entry.updatedAt : entry.createdAt ?? 0,
24
+ maturity: junMaturityOf(entry.meta)
25
+ });
26
+ }
27
+ const bodies = await Promise.all(
28
+ nodes.map(async (node) => ({ id: node.id, html: await junDocHtml(node.id) }))
29
+ );
30
+ const scanned = bodies.filter((b) => b.html).length;
31
+ return {
32
+ nodes,
33
+ edges: junGardenEdges(bodies, slugToId, knownIds),
34
+ scanned,
35
+ generatedAt: Date.now()
36
+ };
37
+ }, { maxAge: 60, swr: true, name: "jun-links", getKey: () => "graph" });
@@ -8,6 +8,9 @@ declare const _default: import("h3").EventHandler<import("h3").EventHandlerReque
8
8
  title?: undefined;
9
9
  meta?: undefined;
10
10
  html?: undefined;
11
+ parentId?: undefined;
12
+ parentType?: undefined;
13
+ parentTitle?: undefined;
11
14
  } | {
12
15
  found: true;
13
16
  cacheReady: boolean;
@@ -18,6 +21,9 @@ declare const _default: import("h3").EventHandler<import("h3").EventHandlerReque
18
21
  title: null;
19
22
  meta: {};
20
23
  html: null;
24
+ parentId?: undefined;
25
+ parentType?: undefined;
26
+ parentTitle?: undefined;
21
27
  } | {
22
28
  found: true;
23
29
  cacheReady: boolean;
@@ -26,6 +32,9 @@ declare const _default: import("h3").EventHandler<import("h3").EventHandlerReque
26
32
  title: string | null;
27
33
  type: string;
28
34
  meta: Record<string, unknown>;
35
+ parentId: string | null;
36
+ parentType: string | null;
37
+ parentTitle: string | null;
29
38
  html: string | null;
30
39
  ownerOnly?: undefined;
31
40
  }>>;
@@ -1,5 +1,5 @@
1
1
  import { defineEventHandler, getRouterParam } from "h3";
2
- import { junDocHtml, junDocTree, junSlugMap } from "../../utils/junCache.js";
2
+ import { junDocHtml, junDocTree, junRootDocId, junSlugMap } from "../../utils/junCache.js";
3
3
  import { junDocIdForAlias } from "../../utils/junSlugAlias.js";
4
4
  import { isJunOwnerOnlyDoc } from "../../utils/junVisibility.js";
5
5
  export default defineEventHandler(async (event) => {
@@ -7,7 +7,7 @@ export default defineEventHandler(async (event) => {
7
7
  const slug = raw.replace(/^\/+|\/+$/g, "");
8
8
  const [tree, idToSlug] = await Promise.all([junDocTree(), junSlugMap()]);
9
9
  const cacheReady = Object.keys(tree).length > 0;
10
- let docId = Object.entries(idToSlug).find(([, s]) => s === slug)?.[0];
10
+ let docId = slug ? Object.entries(idToSlug).find(([, s]) => s === slug)?.[0] : junRootDocId();
11
11
  let canonical = null;
12
12
  if (!docId) {
13
13
  const aliasId = junDocIdForAlias(tree, slug);
@@ -29,6 +29,8 @@ export default defineEventHandler(async (event) => {
29
29
  html: null
30
30
  };
31
31
  }
32
+ const parentId = entry?.parentId ?? null;
33
+ const parent = parentId ? tree[parentId] : void 0;
32
34
  return {
33
35
  found: true,
34
36
  cacheReady,
@@ -37,6 +39,9 @@ export default defineEventHandler(async (event) => {
37
39
  title: entry?.label ?? null,
38
40
  type: entry?.type ?? "doc",
39
41
  meta: entry?.meta ?? {},
42
+ parentId,
43
+ parentType: parent?.type ?? null,
44
+ parentTitle: parent?.label ?? null,
40
45
  html: await junDocHtml(docId)
41
46
  };
42
47
  });
@@ -2,6 +2,7 @@ import { defineCachedEventHandler, useRuntimeConfig, useStorage } from "nitropac
2
2
  import { junCountedDocIds, junDocTree, junRootDocId } from "../utils/junCache.js";
3
3
  import { junReadActivity } from "../utils/junActivity.js";
4
4
  import { junActivitySeries, junCountWords } from "../utils/junActivityMath.js";
5
+ import { junIsVisibleMessage } from "../../utils/junModeration.js";
5
6
  export default defineCachedEventHandler(async () => {
6
7
  const jun = useRuntimeConfig().public.jun;
7
8
  const types = jun?.typeIds ?? {};
@@ -26,7 +27,7 @@ export default defineCachedEventHandler(async () => {
26
27
  if (entry.type) byType[entry.type] = (byType[entry.type] ?? 0) + 1;
27
28
  const parent = entry.parentId ? counted[entry.parentId] ?? tree[entry.parentId] : void 0;
28
29
  if (types.wall && parent?.type === types.wall && entry.meta?.coverUploadId) photos++;
29
- if (types.guestbook && parent?.type === types.guestbook && typeof entry.meta?.message === "string") {
30
+ if (types.guestbook && parent?.type === types.guestbook && junIsVisibleMessage(entry.meta)) {
30
31
  signatures++;
31
32
  }
32
33
  if (Array.isArray(entry.meta?.appreciatedBy)) appreciations += entry.meta.appreciatedBy.length;
@@ -0,0 +1,9 @@
1
+ export interface JunTreeSnapshot {
2
+ /** The space document's id — what `topLevelDocs` measures "top level" against. */
3
+ rootId: string;
4
+ /** Whether the cache holds anything at all; `false` means "not synced yet". */
5
+ ready: boolean;
6
+ entries: Record<string, unknown>;
7
+ }
8
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<JunTreeSnapshot>>;
9
+ export default _default;
@@ -0,0 +1,23 @@
1
+ import { defineEventHandler } from "h3";
2
+ import { junDocTree, junRootDocId } from "../utils/junCache.js";
3
+ import { isJunOwnerOnlyDoc } from "../utils/junVisibility.js";
4
+ const META_OMIT = /* @__PURE__ */ new Set(["routeGeo", "junSite"]);
5
+ export default defineEventHandler(async () => {
6
+ const rootId = junRootDocId();
7
+ const tree = await junDocTree();
8
+ const entries = {};
9
+ for (const [id, entry] of Object.entries(tree)) {
10
+ if (!entry) continue;
11
+ if (isJunOwnerOnlyDoc(entry)) continue;
12
+ let meta = entry.meta;
13
+ if (meta) {
14
+ const kept = {};
15
+ for (const [k, v] of Object.entries(meta)) {
16
+ if (!META_OMIT.has(k)) kept[k] = v;
17
+ }
18
+ meta = kept;
19
+ }
20
+ entries[id] = meta ? { ...entry, meta } : entry;
21
+ }
22
+ return { rootId, ready: Object.keys(tree).length > 0, entries };
23
+ });
@@ -83,6 +83,19 @@ export declare class JunJanitorActor {
83
83
  /** The root doc-tree, live. Read-only as far as the janitor is concerned. */
84
84
  get tree(): Y.Map<unknown> | null;
85
85
  get openDocId(): string | null;
86
+ /**
87
+ * `loginOrRegisterWithKey`, with the service runner's retry policy around it.
88
+ *
89
+ * Registration stays INSIDE the retried call rather than beside it: the
90
+ * "not registered" branch lives in `loginOrRegisterWithKey`, and a first boot
91
+ * that hits a 410 on its post-registration login has to be able to register
92
+ * (a no-op the second time — the server answers an already-registered key
93
+ * without creating anything) and try again.
94
+ *
95
+ * The last failure is rethrown unchanged, so a genuine credential error still
96
+ * surfaces with its own message rather than as "gave up after N attempts".
97
+ */
98
+ private loginRetrying;
86
99
  connect(): Promise<void>;
87
100
  /**
88
101
  * Where the janitor is. `docId` + `page` are the wire contract every presence
@@ -41,6 +41,41 @@ export class JunJanitorActor {
41
41
  return this.open?.docId ?? null;
42
42
  }
43
43
  // ── Connecting ─────────────────────────────────────────────────────────────
44
+ /**
45
+ * `loginOrRegisterWithKey`, with the service runner's retry policy around it.
46
+ *
47
+ * Registration stays INSIDE the retried call rather than beside it: the
48
+ * "not registered" branch lives in `loginOrRegisterWithKey`, and a first boot
49
+ * that hits a 410 on its post-registration login has to be able to register
50
+ * (a no-op the second time — the server answers an already-registered key
51
+ * without creating anything) and try again.
52
+ *
53
+ * The last failure is rethrown unchanged, so a genuine credential error still
54
+ * surfaces with its own message rather than as "gave up after N attempts".
55
+ */
56
+ async loginRetrying(client, keypair) {
57
+ const attempts = 5;
58
+ for (let attempt = 1; ; attempt++) {
59
+ try {
60
+ await loginOrRegisterWithKey(client, keypair, {
61
+ displayName: this.options.name,
62
+ deviceName: "jun janitor",
63
+ onRegister: () => this.log(`registering a new account for "${this.options.name}"`)
64
+ });
65
+ return;
66
+ } catch (err) {
67
+ const e = err;
68
+ const status = e?.status ?? e?.response?.status;
69
+ const retryable = isRetryableAuthStatus(status);
70
+ if (!retryable || attempt >= attempts) throw err;
71
+ const delay = authRetryDelayMs(attempt);
72
+ this.log(
73
+ `login attempt ${attempt}/${attempts} failed (${status ?? "no status"}) \u2014 retrying in ${delay}ms` + (status === 410 ? ". A 410 means the backend process answering /auth/verify never issued the challenge; a backend before 3.2.0 keeps that store per-process." : "")
74
+ );
75
+ await new Promise((r) => setTimeout(r, delay));
76
+ }
77
+ }
78
+ }
44
79
  async connect() {
45
80
  if (this.rootProvider) return;
46
81
  const httpUrl = this.options.url.replace(/^wss:\/\//, "https://").replace(/^ws:\/\//, "http://");
@@ -52,11 +87,7 @@ export class JunJanitorActor {
52
87
  const client = new AbracadabraClient({ url: httpUrl });
53
88
  const keypair = this.options.identity.keyFile ? await loadOrCreateKeyFile(this.options.identity.keyFile) : deterministicKeypair(this.options.identity.seed ?? this.options.name);
54
89
  this.publicKey = keypair.publicKeyB64;
55
- await loginOrRegisterWithKey(client, keypair, {
56
- displayName: this.options.name,
57
- deviceName: "jun janitor",
58
- onRegister: () => this.log(`registering a new account for "${this.options.name}"`)
59
- });
90
+ await this.loginRetrying(client, keypair);
60
91
  this.client = client;
61
92
  this.log(`authenticated as "${this.options.name}" (${keypair.publicKeyB64})`);
62
93
  this.log(
@@ -20,6 +20,14 @@ export const JUN_CHORE_POLICY_DEFAULT = {
20
20
  // hides it, or out of one.
21
21
  metaIgnore: [
22
22
  "appreciatedBy",
23
+ // Visitor-contributed, exactly like `appreciatedBy` above, and the same
24
+ // reasoning applies: reverting these to a baseline would DELETE real votes and
25
+ // real progress — people who took part, silently un-taken-part. They also
26
+ // predate this list by a round each, which is how a demo's janitor quietly
27
+ // erased its own poll. Anything the RPC runner writes on a visitor's behalf
28
+ // belongs here the moment it is invented.
29
+ "pollVotes",
30
+ "courseProgress",
23
31
  "slugAliases",
24
32
  "createdAt",
25
33
  "updatedAt",
@@ -2,10 +2,11 @@ import * as Y from "yjs";
2
2
  import { AbracadabraProvider } from "@abraca/dabra";
3
3
  import { markdownToFragmentNodes } from "@abraca/convert";
4
4
  import { defineNitroPlugin, useRuntimeConfig } from "nitropack/runtime";
5
+ import { junSeedFinished, junSeedStarted } from "../utils/junSeedGate.js";
5
6
  const BOOT_DELAY_MS = 4e3;
6
7
  const SYNC_TIMEOUT_MS = 1e4;
7
8
  const ECHO_TIMEOUT_MS = 8e3;
8
- const BODY_CONCURRENCY = 4;
9
+ const BODY_CONCURRENCY = 8;
9
10
  const BODY_FLUSH_MS = 400;
10
11
  function plain(e) {
11
12
  if (!e) return void 0;
@@ -128,7 +129,8 @@ function defaultTree(typeIds) {
128
129
  {
129
130
  label: "Something in progress",
130
131
  type: typeIds.app ?? "doc",
131
- meta: { status: "building", description: "Tiles reorder by dragging \u2014 their order is stored." }
132
+ meta: { status: "building", description: "Tiles reorder by dragging \u2014 their order is stored." },
133
+ body: "Tiles reorder by dragging, and the order is stored on the documents \u2014 so everyone sees the same arrangement rather than a per-browser one."
132
134
  }
133
135
  ]
134
136
  });
@@ -148,7 +150,8 @@ function defaultTree(typeIds) {
148
150
  place: "Everywhere",
149
151
  description: 'An open end reads as "now" \u2014 leave it blank while something is ongoing.',
150
152
  icon: "sprout"
151
- }
153
+ },
154
+ body: "A station is a document, so it holds as much as you want to write about it. This one has no end date, which is how the timeline draws it as ongoing."
152
155
  },
153
156
  {
154
157
  label: "Something earlier",
@@ -158,7 +161,8 @@ function defaultTree(typeIds) {
158
161
  end: "2021",
159
162
  place: "Elsewhere",
160
163
  description: "A bare year is fine. Stations sort newest first by their start."
161
- }
164
+ },
165
+ body: "Stations sort by their start date, newest first. A bare year is enough \u2014 and a station with no dates at all sorts last rather than being dropped, which is the rule every collection here follows."
162
166
  }
163
167
  ]
164
168
  });
@@ -177,7 +181,8 @@ function defaultTree(typeIds) {
177
181
  url: "https://github.com/abracadabra",
178
182
  icon: "github",
179
183
  description: "The platform this site is built on."
180
- }
184
+ },
185
+ body: "A links row is a document too, so it can carry a note about why the link is here. Rows with a destination open outward; the page behind them is still indexed and still yours to write."
181
186
  },
182
187
  {
183
188
  // No url on purpose: a row without one links to its own page, which
@@ -187,7 +192,8 @@ function defaultTree(typeIds) {
187
192
  meta: {
188
193
  icon: "file-text",
189
194
  description: "No URL, so this row opens its own page instead."
190
- }
195
+ },
196
+ body: "No `url`, so this row opens its own page rather than pointing outward. Add one from the editor and it starts leaving the site \u2014 which is how a note grows into a link, or the other way round."
191
197
  }
192
198
  ]
193
199
  });
@@ -202,19 +208,22 @@ function defaultTree(typeIds) {
202
208
  {
203
209
  label: "A laptop",
204
210
  type: "doc",
205
- meta: { category: "Hardware", icon: "laptop", description: "Sections come from the page's own meta.categories." }
211
+ meta: { category: "Hardware", icon: "laptop", description: "Sections come from the page's own meta.categories." },
212
+ body: "Sections on the Uses page come from that page's own `categories` metadata, not from code \u2014 so the headings are yours to name."
206
213
  },
207
214
  {
208
215
  label: "An editor",
209
216
  type: "doc",
210
- meta: { category: "Software", icon: "code", description: "Change an item's category and it moves section." }
217
+ meta: { category: "Software", icon: "code", description: "Change an item's category and it moves section." },
218
+ body: "Change this item's category and it moves section, live, for everyone reading the page. The move is one write; nothing is duplicated and nothing is deleted."
211
219
  },
212
220
  {
213
221
  // No category on purpose: it must surface under "Other" rather than
214
222
  // vanish, which is the rule that makes page types convertible.
215
223
  label: "Something uncategorised",
216
224
  type: "doc",
217
- meta: { icon: "box", description: 'No category \u2014 shows under "Other".' }
225
+ meta: { icon: "box", description: 'No category \u2014 shows under "Other".' },
226
+ body: "No category at all, so it shows under **Other** rather than vanishing. Every collection here tolerates a child it did not expect \u2014 that is what makes changing a page's type safe."
218
227
  }
219
228
  ]
220
229
  });
@@ -229,14 +238,21 @@ function defaultTree(typeIds) {
229
238
  {
230
239
  label: "Something being read",
231
240
  type: "doc",
232
- meta: { status: "reading", author: "An author", rating: 4 }
241
+ meta: { status: "reading", author: "An author", rating: 4 },
242
+ body: "Books are child documents shelved by one metadata field. Open one and you get a page of its own \u2014 the place for a note about what it changed."
233
243
  },
234
244
  {
235
245
  label: "Something finished",
236
246
  type: "doc",
237
- meta: { status: "read", author: "Another author", rating: 5 }
247
+ meta: { status: "read", author: "Another author", rating: 5 },
248
+ body: "Drag a book between shelves to change its status. That is a single write, and it is live for everyone reading the page."
238
249
  },
239
- { label: "Something next", type: "doc", meta: { status: "want" } }
250
+ {
251
+ label: "Something next",
252
+ type: "doc",
253
+ meta: { status: "want" },
254
+ body: 'Nothing has been read here yet. A book with no status at all shelves under "Up next" \u2014 the state a book starts in \u2014 rather than needing one set before it can appear.'
255
+ }
240
256
  ]
241
257
  });
242
258
  }
@@ -436,12 +452,16 @@ export default defineNitroPlugin((nitroApp) => {
436
452
  {
437
453
  name: "jun:bootstrap",
438
454
  start(ctx) {
455
+ junSeedStarted();
439
456
  const timer = setTimeout(() => {
440
457
  void bootstrap(ctx, seed).catch((err) => {
441
458
  console.warn("[jun:bootstrap] failed:", err?.message ?? err);
442
- });
459
+ }).finally(() => junSeedFinished());
443
460
  }, BOOT_DELAY_MS);
444
- return () => clearTimeout(timer);
461
+ return () => {
462
+ clearTimeout(timer);
463
+ junSeedFinished();
464
+ };
445
465
  }
446
466
  }
447
467
  ]
@@ -488,6 +508,7 @@ async function bootstrap(ctx, seed) {
488
508
  if (hasContent) {
489
509
  console.log("[jun:bootstrap] root already has content \u2014 skipping seed");
490
510
  repairIconFormat(ydoc, tree);
511
+ if (backfillRequested()) await backfillBodies(ctx, tree, rootId, nodes);
491
512
  return;
492
513
  }
493
514
  console.log("[jun:bootstrap] empty root \u2014 seeding starter content");
@@ -677,6 +698,72 @@ function attachJsonNodes(target, nodes) {
677
698
  }
678
699
  }
679
700
  }
701
+ const SCHEMA_NODE_NAMES = /* @__PURE__ */ new Set(["documentHeader", "documentMeta"]);
702
+ function fragmentHasProse(fragment) {
703
+ for (const child of fragment.toArray()) {
704
+ const name = child.nodeName;
705
+ if (name && SCHEMA_NODE_NAMES.has(name)) continue;
706
+ if (name === "paragraph") {
707
+ const text = child.toString?.().replace(/<[^>]*>/g, "").trim();
708
+ if (!text) continue;
709
+ }
710
+ return true;
711
+ }
712
+ return false;
713
+ }
714
+ function backfillRequested() {
715
+ const v = process.env.JUN_SEED_BACKFILL;
716
+ return v === "1" || v === "true";
717
+ }
718
+ async function backfillBodies(ctx, tree, rootId, nodes) {
719
+ const childrenByLabel = (parentId) => {
720
+ const out = /* @__PURE__ */ new Map();
721
+ tree.forEach((raw, id) => {
722
+ const e = plain(raw);
723
+ if (!e || e.trashed || e.parentId !== parentId || id === parentId) return;
724
+ const label = e.label;
725
+ if (!label) return;
726
+ out.set(label, out.has(label) ? null : id);
727
+ });
728
+ return out;
729
+ };
730
+ const matched = [];
731
+ const ambiguous = [];
732
+ const missing = [];
733
+ const walk = (seedNodes, parentId) => {
734
+ const live = childrenByLabel(parentId);
735
+ for (const node of seedNodes) {
736
+ const id = live.get(node.label);
737
+ if (id === null) {
738
+ ambiguous.push(node.label);
739
+ continue;
740
+ }
741
+ if (!id) {
742
+ missing.push(node.label);
743
+ continue;
744
+ }
745
+ const planned = toPlan(node);
746
+ if (typeof planned.meta.body === "string" && planned.meta.body) {
747
+ matched.push({ ...planned, id, children: [] });
748
+ }
749
+ if (node.children?.length) walk(node.children, id);
750
+ }
751
+ };
752
+ walk(nodes, rootId);
753
+ if (ambiguous.length) {
754
+ console.warn(
755
+ `[jun:bootstrap] backfill skipped ${ambiguous.length} ambiguous label(s): ` + ambiguous.slice(0, 8).join(", ")
756
+ );
757
+ }
758
+ if (!matched.length) {
759
+ console.log(
760
+ `[jun:bootstrap] backfill: nothing to fill` + (missing.length ? ` (${missing.length} seed page(s) not found in this tree)` : "")
761
+ );
762
+ return;
763
+ }
764
+ console.log(`[jun:bootstrap] backfill: ${matched.length} candidate document(s)`);
765
+ await writeBodies(ctx, matched);
766
+ }
680
767
  async function writeBodies(ctx, flat) {
681
768
  const withBody = flat.filter((n) => typeof n.meta.body === "string" && n.meta.body);
682
769
  if (!withBody.length) return;
@@ -703,12 +790,13 @@ async function writeBodies(ctx, flat) {
703
790
  });
704
791
  }
705
792
  const fragment = ydoc.getXmlFragment("default");
706
- if (fragment.length > 0) return;
793
+ if (fragmentHasProse(fragment)) return;
707
794
  const { header, meta, body } = markdownToFragmentNodes(
708
795
  String(node.meta.body),
709
796
  node.label
710
797
  );
711
798
  ydoc.transact(() => {
799
+ if (fragment.length > 0) fragment.delete(0, fragment.length);
712
800
  attachJsonNodes(fragment, [
713
801
  ...header ? [header] : [],
714
802
  ...meta ? [meta] : [],
@@ -1,8 +1,8 @@
1
1
  import * as Y from "yjs";
2
2
  import { AbracadabraProvider } from "@abraca/dabra";
3
3
  import { Node } from "@tiptap/core";
4
- import { defineNitroPlugin, useRuntimeConfig } from "nitropack/runtime";
5
- import { junCountedDocIds } from "../utils/junCache.js";
4
+ import { defineNitroPlugin, useRuntimeConfig, useStorage } from "nitropack/runtime";
5
+ import { JUN_HEARTBEAT_KEY, junCountedDocIds } from "../utils/junCache.js";
6
6
  import { junReadActivity, junSweepActivity } from "../utils/junActivity.js";
7
7
  import { junDayKey } from "../utils/junActivityMath.js";
8
8
  import { junCreateRegistrar, junSetRegisterTreeState } from "../utils/junRegisterTree.js";
@@ -29,6 +29,27 @@ const CalloutStub = Node.create({
29
29
  content: "block+",
30
30
  renderHTML: () => ["div", { class: "callout" }, 0]
31
31
  });
32
+ const DocLinkStub = Node.create({
33
+ name: "docLink",
34
+ group: "inline",
35
+ inline: true,
36
+ atom: true,
37
+ addAttributes: () => ({ docId: { default: null } }),
38
+ renderHTML: ({ HTMLAttributes }) => ["a", {
39
+ "href": `/doc/${HTMLAttributes.docId}`,
40
+ "data-doc-link": ""
41
+ }]
42
+ });
43
+ const DocEmbedStub = Node.create({
44
+ name: "docEmbed",
45
+ group: "block",
46
+ atom: true,
47
+ addAttributes: () => ({ docId: { default: null } }),
48
+ renderHTML: ({ HTMLAttributes }) => ["div", { "data-doc-embed": "" }, [
49
+ "a",
50
+ { href: `/doc/${HTMLAttributes.docId}` }
51
+ ]]
52
+ });
32
53
  function createLimiter(concurrency) {
33
54
  let active = 0;
34
55
  const queue = [];
@@ -55,7 +76,13 @@ export default defineNitroPlugin((nitroApp) => {
55
76
  nitroApp.hooks.hook("abracadabra:before-runners", () => {
56
77
  registerServerPlugin({
57
78
  name: "jun:doc-cache",
58
- serverExtensions: () => [DocumentHeaderStub, DocumentMetaStub, CalloutStub],
79
+ serverExtensions: () => [
80
+ DocumentHeaderStub,
81
+ DocumentMetaStub,
82
+ CalloutStub,
83
+ DocLinkStub,
84
+ DocEmbedStub
85
+ ],
59
86
  serverRunners: [
60
87
  {
61
88
  name: "jun:doc-cache",
@@ -153,12 +180,23 @@ export default defineNitroPlugin((nitroApp) => {
153
180
  console.warn("[jun:doc-cache] activity sweep failed:", e);
154
181
  }
155
182
  }
183
+ const beat = async () => {
184
+ try {
185
+ await useStorage().setItem(JUN_HEARTBEAT_KEY, {
186
+ at: Date.now(),
187
+ docs: docs.size
188
+ });
189
+ } catch (e) {
190
+ console.warn("[jun:doc-cache] heartbeat write failed:", e);
191
+ }
192
+ };
193
+ void beat();
156
194
  const sweep = setInterval(() => {
157
195
  const renders = [...docs].map(
158
196
  ([docId, ydoc]) => limit(() => renderDoc(docId, ydoc)).catch(() => {
159
197
  })
160
198
  );
161
- void Promise.all(renders).then(bookActivity);
199
+ void Promise.all(renders).then(bookActivity).then(beat);
162
200
  }, REFRESH_INTERVAL_MS);
163
201
  const observer = (event) => {
164
202
  event.keysChanged.forEach((docId) => {
@@ -8,7 +8,9 @@ import {
8
8
  plain
9
9
  } from "../janitor/junJanitorStore.js";
10
10
  import { junSiteConfigMeta, junSlugMap } from "../utils/junCache.js";
11
+ import { junSeedExpected, junSeedSettled, junWaitForSeed } from "../utils/junSeedGate.js";
11
12
  const BOOT_DELAY_MS = 2e4;
13
+ const SEED_WAIT_MS = 18e4;
12
14
  export default defineNitroPlugin((nitroApp) => {
13
15
  const runtime = useRuntimeConfig();
14
16
  const jun = runtime.public.jun;
@@ -27,6 +29,11 @@ export default defineNitroPlugin((nitroApp) => {
27
29
  const boot = setTimeout(() => {
28
30
  void (async () => {
29
31
  try {
32
+ if (junSeedExpected() && !junSeedSettled()) {
33
+ log('waiting for the seeder to finish before deciding what "clean" means');
34
+ const settled = await junWaitForSeed(SEED_WAIT_MS);
35
+ log(settled ? "seed finished \u2014 reading the site" : `seed still running after ${Math.round(SEED_WAIT_MS / 1e3)}s \u2014 starting anyway`);
36
+ }
30
37
  shutdown = await hire(ctx, options, log);
31
38
  } catch (error) {
32
39
  log(`could not start: ${error?.message ?? error}`);