@abraca/junis 2.80.0 → 2.82.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 (50) hide show
  1. package/README.md +20 -9
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +47 -18
  4. package/dist/runtime/assets/css/jun.css +1 -1
  5. package/dist/runtime/components/JunSettings.client.d.vue.ts +3 -0
  6. package/dist/runtime/components/JunSettings.client.vue +195 -0
  7. package/dist/runtime/components/JunSettings.client.vue.d.ts +3 -0
  8. package/dist/runtime/components/JunStudioBar.client.vue +11 -23
  9. package/dist/runtime/components/renderers/JunConfigRenderer.d.vue.ts +13 -0
  10. package/dist/runtime/components/renderers/JunConfigRenderer.vue +54 -21
  11. package/dist/runtime/components/renderers/JunConfigRenderer.vue.d.ts +13 -0
  12. package/dist/runtime/components/renderers/JunStatsRenderer.vue +280 -74
  13. package/dist/runtime/composables/useJunCommands.js +15 -12
  14. package/dist/runtime/composables/useJunDocPage.d.ts +8 -1
  15. package/dist/runtime/composables/useJunDocPage.js +6 -4
  16. package/dist/runtime/composables/useJunRename.js +6 -5
  17. package/dist/runtime/composables/useJunSettings.d.ts +24 -0
  18. package/dist/runtime/composables/useJunSettings.js +48 -0
  19. package/dist/runtime/composables/useJunSiteConfig.d.ts +69 -27
  20. package/dist/runtime/composables/useJunSiteConfig.js +62 -53
  21. package/dist/runtime/composables/useJunViewingAccent.d.ts +0 -1
  22. package/dist/runtime/composables/useJunViewingAccent.js +1 -1
  23. package/dist/runtime/layouts/jun.vue +18 -2
  24. package/dist/runtime/pages/index.vue +18 -8
  25. package/dist/runtime/plugins/jun-site-config.d.ts +17 -0
  26. package/dist/runtime/plugins/jun-site-config.js +26 -0
  27. package/dist/runtime/server/api/resolve/[...slug].get.d.ts +15 -1
  28. package/dist/runtime/server/api/resolve/[...slug].get.js +24 -2
  29. package/dist/runtime/server/api/stats.get.d.ts +27 -0
  30. package/dist/runtime/server/api/stats.get.js +35 -8
  31. package/dist/runtime/server/plugins/jun-bootstrap.js +40 -12
  32. package/dist/runtime/server/plugins/jun-doc-cache.js +44 -3
  33. package/dist/runtime/server/tasks/jun-register-tree.d.ts +16 -0
  34. package/dist/runtime/server/tasks/jun-register-tree.js +22 -0
  35. package/dist/runtime/server/utils/junActivity.d.ts +15 -0
  36. package/dist/runtime/server/utils/junActivity.js +71 -0
  37. package/dist/runtime/server/utils/junActivityMath.d.ts +61 -0
  38. package/dist/runtime/server/utils/junActivityMath.js +31 -0
  39. package/dist/runtime/server/utils/junCache.d.ts +30 -12
  40. package/dist/runtime/server/utils/junCache.js +13 -2
  41. package/dist/runtime/server/utils/junRegisterTree.d.ts +59 -0
  42. package/dist/runtime/server/utils/junRegisterTree.js +76 -0
  43. package/dist/runtime/server/utils/junServiceFetch.js +1 -1
  44. package/dist/runtime/server/utils/junSlugAlias.d.ts +42 -0
  45. package/dist/runtime/server/utils/junSlugAlias.js +14 -0
  46. package/dist/runtime/types.d.ts +1 -1
  47. package/package.json +2 -1
  48. package/dist/runtime/components/renderers/JunWindowRenderer.d.vue.ts +0 -10
  49. package/dist/runtime/components/renderers/JunWindowRenderer.vue +0 -516
  50. package/dist/runtime/components/renderers/JunWindowRenderer.vue.d.ts +0 -10
@@ -0,0 +1,59 @@
1
+ /**
2
+ * The tree-registration walk, and the handle the doc-cache runner publishes so
3
+ * a Nitro task can reach it.
4
+ *
5
+ * A Nitro task is invoked from outside any runner, but the work here needs two
6
+ * things only the runner has: a **service-role client** and an **already-synced
7
+ * root document**. Rather than opening a second identity and a second socket —
8
+ * which is what the standalone script this replaces had to do — the runner
9
+ * parks a handle in module scope and the task picks it up.
10
+ *
11
+ * Module scope is the right lifetime for it: one Nitro process, one runner, and
12
+ * the handle dies with the process. It is cleared on the runner's teardown so a
13
+ * task firing after a hot reload gets a clear "the runner has not started"
14
+ * rather than a client pointing at a dead socket.
15
+ */
16
+ /**
17
+ * What a run did — and the names matter, because the obvious ones lie.
18
+ *
19
+ * `accepted` is **calls the server took**, not documents newly created. The
20
+ * server's `register_subdoc` treats a re-registration as a no-op, so running
21
+ * the task twice reports the SAME figures rather than converging on zero. That
22
+ * looks like a bug and is not one: the task is idempotent, and there is no
23
+ * endpoint that distinguishes "created a row" from "there was already one".
24
+ * Calling this field `registered` invited exactly that misreading.
25
+ */
26
+ export interface JunRegisterReport {
27
+ total: number;
28
+ accepted: number;
29
+ /** Answered 409 — a row already exists and the server declined to touch it. */
30
+ alreadyPresent: number;
31
+ failed: number;
32
+ }
33
+ export interface JunTreeRegistrar {
34
+ registerAll(opts?: {
35
+ dryRun?: boolean;
36
+ }): Promise<JunRegisterReport>;
37
+ }
38
+ export declare function junSetRegisterTreeState(state: JunTreeRegistrar | null): void;
39
+ export declare function junRegisterTreeState(): JunTreeRegistrar | null;
40
+ interface RegistrarDeps {
41
+ rootId: string;
42
+ /** The root document's `doc-tree` map, read through `forEach`. */
43
+ eachEntry: (fn: (entry: Record<string, unknown>, id: string) => void) => void;
44
+ createChild: (parent: string, body: Record<string, unknown>) => Promise<unknown>;
45
+ }
46
+ /**
47
+ * Walk the live tree and register every document under its real parent.
48
+ *
49
+ * **Breadth-first from the root**, so a parent's row always exists before a
50
+ * child names it — the cascade follows `documents.parent_id`, and a child
51
+ * registered against a parent that has no row yet lands wrong or fails.
52
+ *
53
+ * Orphans — an entry whose parent is missing from the tree, or a cycle — are
54
+ * registered directly under the root. That is not their true place, but it does
55
+ * reach the space, and a document nobody can read is a worse outcome than one
56
+ * whose ancestry is approximate.
57
+ */
58
+ export declare function junCreateRegistrar(deps: RegistrarDeps): JunTreeRegistrar;
59
+ export {};
@@ -0,0 +1,76 @@
1
+ let current = null;
2
+ export function junSetRegisterTreeState(state) {
3
+ current = state;
4
+ }
5
+ export function junRegisterTreeState() {
6
+ return current;
7
+ }
8
+ export function junCreateRegistrar(deps) {
9
+ return {
10
+ async registerAll({ dryRun = false } = {}) {
11
+ const { rootId } = deps;
12
+ const entries = /* @__PURE__ */ new Map();
13
+ deps.eachEntry((raw, id) => {
14
+ const e = typeof raw?.toJSON === "function" ? raw.toJSON() : raw;
15
+ if (!e || e.trashed === true) return;
16
+ if (id === rootId) return;
17
+ entries.set(id, {
18
+ label: e.label || "Untitled",
19
+ // A legacy top-level entry uses `parentId: null`; both mean the root.
20
+ parentId: e.parentId ?? rootId,
21
+ type: e.type
22
+ });
23
+ });
24
+ const byParent = /* @__PURE__ */ new Map();
25
+ for (const [id, e] of entries) {
26
+ const list = byParent.get(e.parentId) ?? [];
27
+ list.push(id);
28
+ byParent.set(e.parentId, list);
29
+ }
30
+ const order = [];
31
+ const seen = /* @__PURE__ */ new Set([rootId]);
32
+ const queue = [rootId];
33
+ while (queue.length) {
34
+ const pid = queue.shift();
35
+ for (const id of byParent.get(pid) ?? []) {
36
+ if (seen.has(id)) continue;
37
+ seen.add(id);
38
+ order.push(id);
39
+ queue.push(id);
40
+ }
41
+ }
42
+ for (const id of entries.keys()) {
43
+ if (seen.has(id)) continue;
44
+ entries.get(id).parentId = rootId;
45
+ order.push(id);
46
+ }
47
+ const report = {
48
+ total: order.length,
49
+ accepted: 0,
50
+ alreadyPresent: 0,
51
+ failed: 0
52
+ };
53
+ if (dryRun) return report;
54
+ for (const id of order) {
55
+ const e = entries.get(id);
56
+ try {
57
+ await deps.createChild(e.parentId, {
58
+ child_id: id,
59
+ label: e.label,
60
+ doc_type: e.type
61
+ });
62
+ report.accepted++;
63
+ } catch (err) {
64
+ const msg = err?.message ?? String(err);
65
+ if (/409|already exists|conflict/i.test(msg)) {
66
+ report.alreadyPresent++;
67
+ continue;
68
+ }
69
+ report.failed++;
70
+ console.warn(`[jun:register-tree] ${id} ("${e.label}"): ${msg}`);
71
+ }
72
+ }
73
+ return report;
74
+ }
75
+ };
76
+ }
@@ -251,7 +251,7 @@ const RSS = async (ref) => {
251
251
  const HTTP = async (ref) => {
252
252
  const started = Date.now();
253
253
  let status = 0;
254
- let ms = 0;
254
+ let ms;
255
255
  try {
256
256
  const res = await safeFetch(ref, { accept: "text/html,*/*" });
257
257
  status = res.status;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Resolving a slug a document used to live at.
3
+ *
4
+ * Slugs are DERIVED from labels, so renaming a page moves it. `useJunRename`
5
+ * records the vacated slug on the entry's `meta.slugAliases`; this is the
6
+ * server's half of reading that list back, and it is what lets the resolve
7
+ * endpoint answer a cold load of an old URL with a real 301 instead of a 404.
8
+ *
9
+ * Its own file, with NO Nitro imports, so it is reachable from `pnpm test` —
10
+ * the endpoint that uses it cannot be, since importing it pulls in
11
+ * `nitropack/runtime` and a storage layer that only exists inside a running
12
+ * server. The alias rule is the part with a decision in it; the handler around
13
+ * it is plumbing.
14
+ *
15
+ * > **`useJunRename().docIdForAlias` applies the SAME rule** and must keep
16
+ * > doing so. Nitro server utils and the app's auto-imports are separate
17
+ * > bundles — the same split that already forces `isJunOwnerOnlyDoc` to exist
18
+ * > twice — and the two operate on different shapes (a record here, the tree's
19
+ * > entry array there), so this is duplicated deliberately rather than shared.
20
+ * > **Keep them in step.**
21
+ */
22
+ export interface JunAliasEntry {
23
+ trashed?: boolean;
24
+ createdAt?: number;
25
+ meta?: Record<string, unknown>;
26
+ }
27
+ /**
28
+ * The document that used to live at `slug`, or `null` when nothing claims it.
29
+ *
30
+ * Deterministic on purpose. Two documents claiming one alias is not a healthy
31
+ * state, but "unhealthy" must not mean "answers differently per request" — an
32
+ * unstable pick is how the client and the server end up on different documents,
33
+ * which is the shape of the campfire bug, where half the visitors ended up in a
34
+ * room the other half could not see. Oldest `createdAt`, ties broken on the id:
35
+ * the same tie-break every other canonical pick in this codebase uses.
36
+ *
37
+ * The CALLER must consult the canonical slug map first. `renameDoc` cannot
38
+ * compute a document's new slug at the moment it records the old one, so an
39
+ * alias may well name a slug some other document now holds — checking the live
40
+ * map first is what makes a stale alias inert rather than a shadow.
41
+ */
42
+ export declare function junDocIdForAlias(entries: Record<string, JunAliasEntry | undefined>, slug: string): string | null;
@@ -0,0 +1,14 @@
1
+ export function junDocIdForAlias(entries, slug) {
2
+ if (!slug) return null;
3
+ const claimants = [];
4
+ for (const [id, entry] of Object.entries(entries)) {
5
+ if (!entry || entry.trashed) continue;
6
+ const aliases = entry.meta?.slugAliases;
7
+ if (Array.isArray(aliases) && aliases.includes(slug)) {
8
+ claimants.push({ id, createdAt: entry.createdAt ?? 0 });
9
+ }
10
+ }
11
+ if (!claimants.length) return null;
12
+ claimants.sort((a, b) => a.createdAt - b.createdAt || (a.id < b.id ? -1 : 1));
13
+ return claimants[0].id;
14
+ }
@@ -16,7 +16,7 @@
16
16
  * - DETAIL pages are the children of a list page and render one document.
17
17
  * - SYSTEM pages are singletons that configure or describe the site itself.
18
18
  */
19
- export type JunPageTypeKey = 'apps' | 'journal' | 'live' | 'links' | 'cv' | 'wall' | 'uses' | 'library' | 'guestbook' | 'cinema' | 'festival' | 'services' | 'app' | 'entry' | 'now' | 'movie' | 'track' | 'globe' | 'mosaic' | 'config' | 'redirect' | 'stats' | 'window' | 'home';
19
+ export type JunPageTypeKey = 'apps' | 'journal' | 'live' | 'links' | 'cv' | 'wall' | 'uses' | 'library' | 'guestbook' | 'cinema' | 'festival' | 'services' | 'app' | 'entry' | 'now' | 'movie' | 'track' | 'globe' | 'mosaic' | 'config' | 'redirect' | 'stats' | 'home';
20
20
  /** Per-page-type overrides. `true` keeps every default; `false` never registers it. */
21
21
  export interface JunPageTypeOverride {
22
22
  /** Display name in pickers, breadcrumbs and the type switcher. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abraca/junis",
3
- "version": "2.80.0",
3
+ "version": "2.82.0",
4
4
  "description": "Website-builder Nuxt module for the Abracadabra CRDT platform — page-type renderers, presence chrome, studio editing and SSR, all driven by documents",
5
5
  "repository": "abracadabra/jun-is",
6
6
  "license": "MIT",
@@ -84,6 +84,7 @@
84
84
  "eslint": "^10.4.0",
85
85
  "mapbox-gl": "^3.24.0",
86
86
  "nuxt": "^4.4.6",
87
+ "puppeteer-core": "^25.5.0",
87
88
  "tailwindcss": "^4.3.0",
88
89
  "typescript": "^6.0.3",
89
90
  "vue-tsc": "^3.3.1",
@@ -1,10 +0,0 @@
1
- type __VLS_Props = {
2
- docId: string;
3
- docLabel?: string;
4
- docMeta?: Record<string, unknown>;
5
- childProvider?: unknown;
6
- editable?: boolean;
7
- };
8
- declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
9
- declare const _default: typeof __VLS_export;
10
- export default _default;