@protobase/cli 0.89.1 → 0.90.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.
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.89.1";
2
+ var version = "0.90.0";
3
3
  //#endregion
4
4
  export { version };
@@ -1,4 +1,5 @@
1
1
  import { all, any, anyOf, compare, configFilter, configSort, isTrue, sortText } from "./shape-filters.js";
2
+ import { threadSort } from "@protobase/layout";
2
3
  import { isGroupChart, layoutItems, viewOfList } from "@protobase/schema/internal";
3
4
  //#region src/doctor/view-shapes.ts
4
5
  const numberTypes = [
@@ -127,6 +128,21 @@ const recordChartShapes = (item, owner, models) => {
127
128
  }
128
129
  }];
129
130
  };
131
+ const threadShapes = (item, owner, models) => {
132
+ const target = models[item.resource];
133
+ const field = target?.fields[item.field];
134
+ if (!target || !field || !target.fields[item.time]) return [];
135
+ const sort = configSort(target, threadSort(item.time));
136
+ return [{
137
+ resource: target.name,
138
+ request: request(target.name, `${field.name} = …`, sort),
139
+ from: `thread "${item.title}" on the ${owner} record page`,
140
+ query: {
141
+ filter: compare(field),
142
+ ...sort && { sort }
143
+ }
144
+ }];
145
+ };
130
146
  const displayShapes = (model, view, models) => (view.list?.displays ?? []).flatMap((display) => {
131
147
  if (display.kind === "map") {
132
148
  const latitude = model.fields[display.latitude];
@@ -261,7 +277,7 @@ const listShapes = (model, view, list, models) => [
261
277
  ];
262
278
  /**
263
279
  * The reads a view's pages make: its list in its order, the filter widgets and their counts, its chart per value, its displays' maps,
264
- * board columns and photos, the records of its related sections and charts and the photos of its galleries, the recent records in the sidebar, a saved search's new records and the records sorted by hand.
280
+ * board columns and photos, the records of its related sections, charts and conversations and the photos of its galleries, the recent records in the sidebar, a saved search's new records and the records sorted by hand.
265
281
  */
266
282
  const viewShapes = (view, models) => {
267
283
  const model = models[view.resource];
@@ -270,7 +286,7 @@ const viewShapes = (view, models) => {
270
286
  return [
271
287
  ...listShapes(model, view, list, models),
272
288
  ...(view.lists ?? []).flatMap((named) => listShapes(model, viewOfList(view, named.name), `${list} "${named.name}"`, models)),
273
- ...layoutItems(view.layout).flatMap((item) => item.kind === "related" ? relatedShapes(item, model.name, models) : item.kind === "gallery" ? galleryShapes(item, model.name, models) : item.kind === "chart" ? recordChartShapes(item, model.name, models) : []),
289
+ ...layoutItems(view.layout).flatMap((item) => item.kind === "related" ? relatedShapes(item, model.name, models) : item.kind === "gallery" ? galleryShapes(item, model.name, models) : item.kind === "chart" ? recordChartShapes(item, model.name, models) : item.kind === "thread" ? threadShapes(item, model.name, models) : []),
274
290
  ...recentShapes(model, view),
275
291
  ...searchesShapes(view, models),
276
292
  ...handOrderShapes(model, view, list, models)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.89.1",
3
+ "version": "0.90.0",
4
4
  "description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -43,13 +43,13 @@
43
43
  "dependencies": {
44
44
  "@better-auth/core": "^1.7.12",
45
45
  "@hono/node-server": "^2.1.3",
46
- "@protobase/config": "0.89.1",
47
- "@protobase/layout": "0.89.1",
48
- "@protobase/query": "0.89.1",
49
- "@protobase/schema": "0.89.1",
50
- "@protobase/server": "0.89.1",
51
- "@protobase/ui": "0.89.1",
52
- "@protobase/workflows": "0.89.1",
46
+ "@protobase/config": "0.90.0",
47
+ "@protobase/layout": "0.90.0",
48
+ "@protobase/query": "0.90.0",
49
+ "@protobase/schema": "0.90.0",
50
+ "@protobase/server": "0.90.0",
51
+ "@protobase/ui": "0.90.0",
52
+ "@protobase/workflows": "0.90.0",
53
53
  "@react-email/render": "^2.1.0",
54
54
  "@scalar/hono-api-reference": "^0.12.10",
55
55
  "@sentry/vite-plugin": "^11.10.0",
@@ -4,7 +4,7 @@
4
4
 
5
5
  The page of one record, with its sections, related records, galleries, charts and editing.
6
6
 
7
- - [Record page layout](../reference/ui-config.md#the-record-page): Sections, a summary sidebar, related tables, maps, charts, galleries, history, comments and your own components.
7
+ - [Record page layout](../reference/ui-config.md#the-record-page): Sections, a summary sidebar, related tables, maps, charts, galleries, history, comments, conversations and your own components.
8
8
  - [Full-width record pages](../reference/ui-config.md#page-width): A view's record pages and create form fill the whole area beside the sidebar instead of a centred column, with the sidebar cards still beside the sections.
9
9
  - [Focus pages](../reference/ui-config.md#focus-pages) (beta): A record whose page is one big surface, such as a graph or a board, fills the page under a thin bar with its Save, actions and panels, its form a link away.
10
10
  - [A create address that opens a page](../reference/ui-config.md#focus-pages) (beta): `.createOpens(to)` sends a resource's create address to a page in place of its form, such as a record's focus page with a panel open, filled from the address's values.
@@ -27,6 +27,7 @@ The page of one record, with its sections, related records, galleries, charts an
27
27
  - [Galleries](../reference/ui-config.md#galleries): A record's photos show as tiles that open a full-screen lightbox, with keyboard and swipe navigation.
28
28
  - [Related records](../reference/ui-config.md#related-records): Every record page shows how many records point at it, and can list related records, also through a join resource, as a table, another display or cards with buttons, each row or card with a button to an address its fields name.
29
29
  - [Record lines](../reference/ui-config.md#record-lines): The related table a record's view marks as its lines, such as an invoice's, shows all of them on its page, where you edit, add, remove and reorder them, and Save writes the record and its lines together.
30
+ - [Conversations](../reference/ui-config.md#conversations): A record page holds a chat about the record, such as a task's, with its messages in markdown and a box that sends one, declared in its layout with no component of the app's own.
30
31
  - [Charts of samples](../reference/ui-config.md#charts-of-related-records): A record page graphs numeric samples over the last hour, day or week, such as a server's CPU use.
31
32
  - [Fresh data on return](../reference/ui-config.md#the-record-page): Records and lists reload when the browser tab is focused again, keeping unsaved edits.
32
33
  - [Safe deletes](../reference/ui-config.md#deleting-a-record): Deleting asks first, or offers Undo for a soft delete, offers a review when the record changed since it was opened, and names the records that still point at it.
@@ -358,7 +358,7 @@ Each value takes its colour from the view's `valueColors`, else an enum value's
358
358
 
359
359
  ## Conversation
360
360
 
361
- A chat declared in the layout like any other block: a `Thread` lists the messages of a resource and a `Composer` beneath it sends one, so [`/meta`](api.md#meta-and-openapi-per-caller) describes the conversation and every client can draw it, with no component of the app's own.
361
+ A chat declared in the layout like any other block: a `Thread` lists the messages of a resource and a `Composer` beneath it sends one, so [`/meta`](api.md#meta-and-openapi-per-caller) describes the conversation and every client can draw it, with no component of the app's own. On a record page, [`l.thread` and `l.composer`](ui-config.md#conversations) hold the conversation of that record.
362
362
 
363
363
  ```tsx
364
364
  <Card title="General">
@@ -378,8 +378,8 @@ The latest messages that match `filter`, oldest first, each under its sender's n
378
378
  | `resource`, `filter` | Which messages. `resource` is required. |
379
379
  | `sender` | Who wrote each message: a relation, named as the record it points at, or a text field. Required. |
380
380
  | `time` | When each was sent: a date or timestamp field the API can sort by, which orders them. Required. |
381
- | `text` | The message. Required. |
382
- | `limit` | How many of the latest it shows at first, and how many each **Load earlier messages** adds; default 50. |
381
+ | `text` | The message; shown rendered when the message resource's view marks it [`.markdown()`](ui-config.md#names-and-columns). Required. |
382
+ | `limit` | How many of the latest it shows at first, and how many each **Load earlier messages** adds: 1 to 500, the API's largest page; default 50. |
383
383
  | `title`, `description`, `actions` | The heading; no card is drawn around the thread, so it can sit in a `Card` with its composer. |
384
384
  | `empty` | Text while there are no messages. |
385
385
  | `span` | Width in a grid. |
@@ -105,7 +105,7 @@ Field hints:
105
105
  | `.confirm(question)` | Asks `question` before a person changes the value in a form or a list cell, and Cancel keeps it. See [Confirming a change](#confirming-a-change). |
106
106
  | `.format(format)` | `badge` shows statuses as coloured badges, `code` sets identifiers in monospace, as the list's identifier column too, `percent` adds a % sign, and `signed` shows a whole number in a list with its sign, green above zero and red below, such as a stock change of `+12` or `−3`; it needs an integer field. On a text field, `email`, `phone` and `url` show the value as a link that writes to it (`mailto:`), calls it (`tel:`, its digits and a leading +) or opens it in a new tab (only an `http` or `https` address; anything else stays text), on the record page, in its sidebar and in the list's cells but the title's, which links to the record; forms edit it in an email, phone or web address input, which brings up the keyboard for it on a mobile screen and offers the browser's autofill. Another field type with one of them stops the server at startup. `relative` on a timestamp shows it as "5 minutes ago" or "in 2 hours" in lists and on the record page, with the exact time on hover; `absolute` and `compact` are accepted and carried in `/meta` for apps that render their own lists. <gap>The admin does not use the `absolute` and `compact` formats yet.</gap> |
107
107
  | `.multiline()` | A text of several lines, such as a description: forms edit it in a box that grows with the text, so the page scrolls rather than the box, and the record page's sections, a page's field blocks and a card's subtitle keep its line breaks (a card shows the first three lines); the record's sidebar shows it on one line. On the record page and the create form it takes the whole width of its section. Only a text field takes it; the list's table shows the text on one line. |
108
- | `.markdown()` | Markdown, such as a task's notes: forms edit its source in a box that grows with it, with a Write and Preview switch above it, and store it exactly as typed. The record page's sections and a page's field blocks show it rendered as GitHub does, line breaks kept; raw HTML shows as text, links and images keep only http(s), mailto, tel and relative addresses, and links open in a new tab. A card's subtitle shows its first three lines rendered, its links as text; the list's table, the record's sidebar and a card's other lines show its text on one line without the marks. On the record page and the create form it takes the whole width of its section. Only a text field takes it, and the renderer loads with the first markdown shown. |
108
+ | `.markdown()` | Markdown, such as a task's notes: forms edit its source in a box that grows with it, with a Write and Preview switch above it, and store it exactly as typed. The record page's sections, a page's field blocks and a conversation's messages show it rendered as GitHub does, line breaks kept; raw HTML shows as text, links and images keep only http(s), mailto, tel and relative addresses, and links open in a new tab. A card's subtitle shows its first three lines rendered, its links as text; the list's table, the record's sidebar and a card's other lines show its text on one line without the marks. On the record page and the create form it takes the whole width of its section. Only a text field takes it, and the renderer loads with the first markdown shown. |
109
109
  | `.prefix(text)`, `.suffix(text)`, `.decimals(n)` | Text around a number and its decimals: `€` and `2` show `€1,234.50`, `.suffix(' m²')` shows `120 m²`. They show wherever the number does: records, cards, table cells, forms and the range filter. A prefix is plain text, so a list does not show `€` as money; `.currency()` does. |
110
110
  | `.currency(code)` | The currency a decimal is an amount of, as an ISO 4217 code such as `EUR`: the list shows it as money in that currency, in its table and its range filter. See [Value tones and currencies](#value-tones-and-currencies). |
111
111
  | `.icon(name)` | An icon before the value on a card's meta row: one of the names [actions](layouts.md#named-actions) take, such as `bed`, `calendar` or `cpu`, and above the value in a section of [key facts](#key-facts). Nowhere else shows it. |
@@ -662,6 +662,8 @@ export const repairsView = filtered
662
662
  | `l.custom(Component, { title?, props?, sidebar?, when?, fallback? })` | A [custom component](custom-components.md#record-sections) where it is listed: in the main column under `title`, or with `sidebar: true` as a sidebar card. `fallback` shows in its place where it cannot be drawn. |
663
663
  | `l.map(title, { latitude, longitude, zoom?, sidebar?, when? })` | A map with a pin at the record's position, in the main column or with `sidebar: true` as a sidebar card. See [Maps](#maps). |
664
664
  | `l.chart(title, { resource, field, at, series, range?, help?, when? })` | Line graphs of numbers of the records that point at this one, such as a machine's samples, over the last hour, day or week. See [Charts of related records](#charts-of-related-records). |
665
+ | `l.thread(title, { resource, field, sender, time, text, limit?, empty?, help?, when? })` | The record's conversation: the latest messages that point at it, oldest first, under each sender's name and time. See [Conversations](#conversations). |
666
+ | `l.composer({ resource, field, text, placeholder?, when? })` | A box that sends a message about the record, which the thread then shows. See [Conversations](#conversations). |
665
667
  | `l.gallery(title, { image?, photos?, when? })` | The record's photos as tiles, opening a lightbox. See [Galleries](#galleries). |
666
668
  | `l.history(title?, { limit?, when? })` | The record's changes, newest first, with who made each and the fields before and after; needs `.history()` on the resource, and a view without a layout shows it last by itself. See [Record history](history.md#on-the-record-page). |
667
669
  | `l.comments(title?, { when? })` | The record's comments, oldest first, with a box to write one that @mentions people; needs `.comments()` on the resource, and a view without a layout shows it last by itself. See [Record comments](comments.md#on-the-record-page). |
@@ -1052,6 +1054,43 @@ view<typeof hosts>('hosts').layout((r) => [
1052
1054
 
1053
1055
  Each series is read through [`:aggregate`](api.md), grouped by `at` with `field = <this record's key>` as its filter, so the user's access applies as on the list, and a user who cannot read `field`, `at` or any series gets no chart (one who cannot read some series gets the others). That filter and grouping need an index on `(field, at)`, such as `create index on host_samples (host_id, sampled_at)`, which [`protobase doctor`](cli.md#doctor) checks. A `field` that is no relation to this resource, an `at` that is no timestamp or not filterable, or a series that is no number or is sensitive stops the server at startup. Keeping the samples, and removing old ones, is the app's own work.
1054
1056
 
1057
+ ### Conversations
1058
+
1059
+ `l.thread(title, options)` shows the messages that point at the record on the page, as a task's chat between the people working on it, and `l.composer(options)` below it writes one. They are the record page's form of the [Thread and Composer blocks](blocks.md#conversation) of composed pages, scoped to the record by a relation of the messages: the thread reads only the messages whose `field` holds this record's key, and each message the composer sends gets that key in `field`. [`/meta`](api.md#meta-and-openapi-per-caller) describes both as data, so every client can draw the conversation with no component of the app's own.
1060
+
1061
+ The thread shows the latest messages oldest first, each under its sender's name and the time it was sent, with a line between days, and **Load earlier messages** reads the ones before; it scrolls in a box of its own, opening at the newest and following what arrives, as the [Thread block](blocks.md#thread) does; others' new messages arrive without a reload when the message resource is [live](live.md) (`.live()`), and otherwise once the page is read again. A message whose text field the message resource's view marks [`.markdown()`](#names-and-columns) shows rendered, its raw HTML as text. The composer sends with Enter, starts a new line with Shift+Enter, and keeps a refused message in the box under the reason. A message carries its sender only when the message resource marks its author with [`.author()`](data-config.md#resource), which every create sets to the signed-in user, so the thread's `sender` names that field, such as `author_id`. It sends only `field` and `text`, so every other required field of the message, such as its time, needs a default, such as `sent_at timestamptz not null default now()`.
1062
+
1063
+ | `l.thread` option | |
1064
+ | --- | --- |
1065
+ | `resource` | The message resource, such as `task_messages`. Required. |
1066
+ | `field` | The filterable relation of `resource` that holds this record's key. Required. |
1067
+ | `sender` | Who wrote each message: a relation, named as the record it points at, or a text field. Required. |
1068
+ | `time` | When each was sent: a date or timestamp field the API can sort by, which orders them. Required. |
1069
+ | `text` | The message, a text field. Required. |
1070
+ | `limit` | How many of the latest it shows at first, and how many each **Load earlier messages** adds: 1 to 500, the API's largest page; default 50. |
1071
+ | `empty` | Text while there are no messages. |
1072
+ | `help`, `when` | A line under the title, and whether it shows on the form, the read view or both. |
1073
+
1074
+ | `l.composer` option | |
1075
+ | --- | --- |
1076
+ | `resource` | The message resource. Required. |
1077
+ | `field` | The relation of `resource` each message gets this record's key in. Required. |
1078
+ | `text` | The text field the message goes in. Required. |
1079
+ | `placeholder` | The box's text while empty. |
1080
+ | `when` | Whether it shows on the form, the read view or both. |
1081
+
1082
+ ```ts
1083
+ view<typeof task_messages>('task_messages').fields((r) => ({ body: r.body.markdown() }))
1084
+
1085
+ view<typeof tasks>('tasks').layout((r) => [
1086
+ l.section('Task', [r.title]),
1087
+ l.thread('Conversation', { resource: 'task_messages', field: 'task_id', sender: 'author_id', time: 'sent_at', text: 'body' }),
1088
+ l.composer({ resource: 'task_messages', field: 'task_id', text: 'body', placeholder: 'Message about this task' }),
1089
+ ])
1090
+ ```
1091
+
1092
+ The messages are read with `field = <this record's key>` as the filter, newest first by `time`, so the user's access applies as on the list. That read needs an index on `(field, time)`, such as `create index on task_messages (task_id, sent_at)`, which [`protobase doctor`](cli.md#doctor) checks. A user who cannot read `field`, `sender`, `time` or `text` gets no thread, and one who may not create a message with `field` and `text` gets no composer. A `field` that is no relation to this resource, a `time` that is no date or timestamp the API can sort by, a `sender` that is no relation or text field, a thread `text` that is no text field, a sensitive field in the thread, or a composer `text` that is no writable text field stops the server at startup. As with a related section, the record page's count of the records that point at it leaves out the messages its thread shows.
1093
+
1055
1094
  ## Actions and views per role
1056
1095
 
1057
1096
  ```ts title="docs-examples/bike-shop/step-5.ts"