@bakers-build/addon-bakers-ui 0.3.0 → 0.3.1-next.308

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.
@@ -442,16 +442,18 @@ export declare const fetchConductorLastSeen: (client: DropshClient, id: string)
442
442
  */
443
443
  export declare const countConductors: (client: DropshClient, query: ConductorQuery) => Promise<number | null>;
444
444
  /**
445
- * Project uuid → name, for the Conductors screen's project column.
445
+ * Project uuid → name, for the Conductors screen's project column and the
446
+ * Projects tab (`loadProjectRows`).
446
447
  *
447
- * A conductor references its project by uuid; the screen shows the name. This
448
- * is a separate small read rather than a widened `ProjectRow`, because
449
- * `loadProjectRows` builds the PROJECTS screen (one row per project, derived
450
- * from conductors) and adding an id to it would change a shape four screens
451
- * depend on to serve one column.
448
+ * A conductor references its project by uuid; the screens show the name.
449
+ *
450
+ * Without `ids` this is one `bb_project` read, so only the first page of
451
+ * visible projects is named. With `ids` only those projects are read, in
452
+ * chunks below the server's page cap, so every referenced project is named
453
+ * however many projects the user can see.
452
454
  *
453
455
  * A failed read yields an empty map: an unnamed project renders blank, which is
454
456
  * better than a screen that refuses to list conductors because their projects
455
457
  * could not be resolved.
456
458
  */
457
- export declare const listProjectNames: (client: DropshClient) => Promise<Map<string, string>>;
459
+ export declare const listProjectNames: (client: DropshClient, ids?: string[]) => Promise<Map<string, string>>;
@@ -503,22 +503,43 @@ export const countConductors = async (client, query) => {
503
503
  }
504
504
  };
505
505
  /**
506
- * Project uuid → name, for the Conductors screen's project column.
506
+ * Project uuid → name, for the Conductors screen's project column and the
507
+ * Projects tab (`loadProjectRows`).
507
508
  *
508
- * A conductor references its project by uuid; the screen shows the name. This
509
- * is a separate small read rather than a widened `ProjectRow`, because
510
- * `loadProjectRows` builds the PROJECTS screen (one row per project, derived
511
- * from conductors) and adding an id to it would change a shape four screens
512
- * depend on to serve one column.
509
+ * A conductor references its project by uuid; the screens show the name.
510
+ *
511
+ * Without `ids` this is one `bb_project` read, so only the first page of
512
+ * visible projects is named. With `ids` only those projects are read, in
513
+ * chunks below the server's page cap, so every referenced project is named
514
+ * however many projects the user can see.
513
515
  *
514
516
  * A failed read yields an empty map: an unnamed project renders blank, which is
515
517
  * better than a screen that refuses to list conductors because their projects
516
518
  * could not be resolved.
517
519
  */
518
- export const listProjectNames = async (client) => {
519
- const outcome = await listOutcome(client, 'bb_project', (r) => ({
520
- id: r.id,
521
- name: str(r.attr('name')) ?? str(r.attr('label')) ?? '',
522
- }));
523
- return new Map(outcome.rows.map((p) => [p.id, p.name]));
520
+ export const listProjectNames = async (client, ids) => {
521
+ const nameOf = (r) => str(r.attr('name')) ?? str(r.attr('label')) ?? '';
522
+ if (!ids) {
523
+ const outcome = await listOutcome(client, 'bb_project', (r) => ({
524
+ id: r.id,
525
+ name: nameOf(r),
526
+ }));
527
+ return new Map(outcome.rows.map((p) => [p.id, p.name]));
528
+ }
529
+ const names = new Map();
530
+ try {
531
+ for (let i = 0; i < ids.length; i += LIST_PAGE_SIZE) {
532
+ const chunk = ids.slice(i, i + LIST_PAGE_SIZE);
533
+ const rows = await client
534
+ .collection('bb_project')
535
+ .whereIn('id', chunk)
536
+ .list();
537
+ for (const r of rows)
538
+ names.set(r.id, nameOf(r));
539
+ }
540
+ }
541
+ catch {
542
+ return new Map();
543
+ }
544
+ return names;
524
545
  };
@@ -1,5 +1,5 @@
1
1
  import type { DropshClient } from '../../../types.js';
2
- import { type ConductorStatus } from '../../conductor/Data/liveness.js';
2
+ import type { ConductorStatus } from '../../conductor/Data/liveness.js';
3
3
  /** A derived project row: one distinct project + its liveliest conductor. */
4
4
  export interface ProjectRow {
5
5
  project: string;
@@ -131,12 +131,13 @@ export declare const PROJECT_TABLE: {
131
131
  }];
132
132
  };
133
133
  /**
134
- * Resolve the projects screen's rows straight from the control plane: list the
135
- * `bb_conductor` entities (read is owner-gated, so this is already scoped to
136
- * the current user's conductors — no local registry needed), sideload their
137
- * `project_id`, group by project name, and report each project's liveliest
138
- * conductor (online > stale > offline). Everything is a Drupal entity read
139
- * through `services.client` (AC-5); the screen itself stays a screen/route.
134
+ * Resolve the projects screen's rows straight from the control plane: page the
135
+ * `bb_conductor` collection through the Conductors screen's own read (read is
136
+ * owner-gated, so this is already scoped to the current user's conductors — no
137
+ * local registry needed), name each conductor's project through
138
+ * `listProjectNames`, group by project name, and report each project's
139
+ * liveliest conductor (online > stale > offline). Everything is a Drupal entity
140
+ * read through `services.client` (AC-5); the screen itself stays a screen/route.
140
141
  */
141
142
  export declare function loadProjectRows({ client, nowSeconds, }: {
142
143
  client: DropshClient;
@@ -1,24 +1,5 @@
1
- import { DrupalJsonApiParams } from 'drupal-jsonapi-params';
2
1
  import { humanizeAge } from '../../../lib/format.js';
3
- import { deriveConductorStatus, } from '../../conductor/Data/liveness.js';
4
- /** JSON:API timestamps arrive as ISO-8601 strings; liveness works in seconds. */
5
- function toEpochSeconds(value) {
6
- if (value == null)
7
- return null;
8
- if (typeof value === 'number')
9
- return value;
10
- if (typeof value !== 'string')
11
- return null;
12
- const ms = Date.parse(value);
13
- return Number.isNaN(ms) ? null : Math.floor(ms / 1000);
14
- }
15
- /** Id of a single-valued relationship linkage (`data` object), or null. */
16
- function singleRelId(rel) {
17
- const data = rel?.data;
18
- if (!data || Array.isArray(data))
19
- return null;
20
- return data.id ?? null;
21
- }
2
+ import { listConductorRowPage, listProjectNames, } from '../../conductor/Data/conductors.js';
22
3
  // Most-alive-first ranking so a project with several conductors reports its
23
4
  // liveliest one, not whichever the collection happened to return first.
24
5
  const STATUS_RANK = {
@@ -142,53 +123,59 @@ export const PROJECT_TABLE = {
142
123
  ],
143
124
  };
144
125
  /**
145
- * Resolve the projects screen's rows straight from the control plane: list the
146
- * `bb_conductor` entities (read is owner-gated, so this is already scoped to
147
- * the current user's conductors — no local registry needed), sideload their
148
- * `project_id`, group by project name, and report each project's liveliest
149
- * conductor (online > stale > offline). Everything is a Drupal entity read
150
- * through `services.client` (AC-5); the screen itself stays a screen/route.
126
+ * Resolve the projects screen's rows straight from the control plane: page the
127
+ * `bb_conductor` collection through the Conductors screen's own read (read is
128
+ * owner-gated, so this is already scoped to the current user's conductors — no
129
+ * local registry needed), name each conductor's project through
130
+ * `listProjectNames`, group by project name, and report each project's
131
+ * liveliest conductor (online > stale > offline). Everything is a Drupal entity
132
+ * read through `services.client` (AC-5); the screen itself stays a screen/route.
151
133
  */
152
134
  export async function loadProjectRows({ client, nowSeconds, }) {
153
- const params = new DrupalJsonApiParams().addInclude(['project_id']);
154
- let doc;
135
+ const now = nowSeconds();
136
+ // Only liveness is read off these rows; locality and host identity are the
137
+ // Conductors screen's concern, so they are given values that claim neither.
138
+ const ctx = {
139
+ now,
140
+ exists: () => false,
141
+ thisHostKey: '',
142
+ };
143
+ // Every page, or no list: a failed page never yields a truncated one.
144
+ const conductors = [];
155
145
  try {
156
- doc = (await client.get('bb_conductor/bb_conductor', params));
146
+ for (let page = 0;; page++) {
147
+ const result = await listConductorRowPage(client, ctx, {}, page);
148
+ conductors.push(...result.rows);
149
+ if (!result.hasNext)
150
+ break;
151
+ }
157
152
  }
158
153
  catch {
159
154
  return [];
160
155
  }
161
- // Resolve each conductor's project name from the sideloaded bb_project.
162
- const projectNameById = new Map();
163
- for (const inc of doc.included ?? []) {
164
- if (inc.id && typeof inc.attributes?.name === 'string') {
165
- projectNameById.set(inc.id, inc.attributes.name);
166
- }
167
- }
168
- const now = nowSeconds();
156
+ const projectNameById = await listProjectNames(client, [
157
+ ...new Set(conductors.flatMap((c) => (c.projectId ? [c.projectId] : []))),
158
+ ]);
169
159
  const best = new Map();
170
- for (const c of doc.data ?? []) {
171
- const a = c.attributes ?? {};
172
- const projectId = singleRelId(c.relationships?.project_id);
173
- const project = projectId ? projectNameById.get(projectId) : undefined;
160
+ for (const c of conductors) {
161
+ const project = c.projectId ? projectNameById.get(c.projectId) : undefined;
174
162
  // A conductor whose project cannot be resolved is not a project row.
175
- if (!project)
163
+ if (!c.projectId || !project)
176
164
  continue;
177
- const lastSeen = toEpochSeconds(a.last_seen ?? null);
178
- const derivedStatus = deriveConductorStatus({
179
- present: true,
180
- status: typeof a.status === 'string' ? a.status : null,
181
- lastSeen,
182
- leaseExpiresAt: toEpochSeconds(a.lease_expires_at ?? null),
183
- }, now);
184
165
  const prev = best.get(project);
185
- if (!prev || STATUS_RANK[derivedStatus] < STATUS_RANK[prev.derivedStatus]) {
186
- best.set(project, { derivedStatus, lastSeen });
166
+ if (!prev ||
167
+ STATUS_RANK[c.derivedStatus] < STATUS_RANK[prev.derivedStatus]) {
168
+ best.set(project, {
169
+ id: c.projectId,
170
+ derivedStatus: c.derivedStatus,
171
+ // ConductorRow spells "never reported" as 0.
172
+ lastSeen: c.lastSeen || null,
173
+ });
187
174
  }
188
175
  }
189
176
  return [...best.entries()].map(([project, b]) => ({
190
177
  project,
191
- id: [...projectNameById.entries()].find(([, name]) => name === project)?.[0] ?? project,
178
+ id: b.id,
192
179
  projectName: project,
193
180
  projectSlug: project,
194
181
  derivedStatus: b.derivedStatus,
@@ -9,8 +9,8 @@ import { type ProjectRow } from '../Data/projects.js';
9
9
  *
10
10
  * MOUNTED WHOLE, so the bound on its nodes is the data's own length against
11
11
  * `@opentui/core@0.5.1`'s ceiling of 16 382 renderables. A project row is one
12
- * box of 3 cells, and the rows are the user's own projects read from a single
13
- * bounded `bb_conductor` collection, grouped by project — three orders of
12
+ * box of 3 cells, and the rows are the user's own projects read from the
13
+ * `bb_conductor` collection page by page, grouped by project — three orders of
14
14
  * magnitude of headroom on any control plane a person works with. This screen
15
15
  * therefore windows nothing of its own, deliberately rather than by omission.
16
16
  */
@@ -10,8 +10,8 @@ import { ProjectOverviewScreen } from './project-overview.js';
10
10
  *
11
11
  * MOUNTED WHOLE, so the bound on its nodes is the data's own length against
12
12
  * `@opentui/core@0.5.1`'s ceiling of 16 382 renderables. A project row is one
13
- * box of 3 cells, and the rows are the user's own projects read from a single
14
- * bounded `bb_conductor` collection, grouped by project — three orders of
13
+ * box of 3 cells, and the rows are the user's own projects read from the
14
+ * `bb_conductor` collection page by page, grouped by project — three orders of
15
15
  * magnitude of headroom on any control plane a person works with. This screen
16
16
  * therefore windows nothing of its own, deliberately rather than by omission.
17
17
  */
@@ -10,6 +10,7 @@ export interface Resource {
10
10
  /** A dropsh collection query builder (fluent). */
11
11
  export interface Collection {
12
12
  where(path: string, op: string, value: unknown): Collection;
13
+ whereIn(path: string, values: unknown[]): Collection;
13
14
  sort(field: string, direction: string): Collection;
14
15
  page(size: number): Collection;
15
16
  first(): Promise<Resource | null>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/addon-bakers-ui",
3
- "version": "0.3.0",
3
+ "version": "0.3.1-next.308",
4
4
  "description": "bakers.build TUI: interactive terminal UI (dashboard, projects, tickets) as a dropsh `tui` renderer plugin.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -29,7 +29,7 @@
29
29
  "zustand": "^5.0.15"
30
30
  },
31
31
  "peerDependencies": {
32
- "@bakers-build/core": "^0.3.0",
33
- "@bakers-build/message": "^0.3.0"
32
+ "@bakers-build/core": "^0.3.1-next.308",
33
+ "@bakers-build/message": "^0.3.1-next.308"
34
34
  }
35
35
  }