@protobase/cli 0.94.18 → 0.94.20
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/package.js +1 -1
- package/dist/migration/parts.js +2 -2
- package/dist/worker/start-worker.js +1 -1
- package/package.json +8 -8
- package/skills/protobase/references/features/history-comments-and-live-updates.md +1 -0
- package/skills/protobase/references/features/lists.md +1 -0
- package/skills/protobase/references/reference/live.md +30 -1
- package/skills/protobase/references/reference/plugins.md +1 -1
- package/skills/protobase/references/reference/ui-config.md +22 -1
package/dist/cli/package.js
CHANGED
package/dist/migration/parts.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { authMigrationTitle } from "../auth/migration-file.js";
|
|
2
|
-
import { authSchemaMigration, callsMigration, changesMigration, channelSendsMigration, commentsMigration, computedMigration, derivedMigration,
|
|
2
|
+
import { authSchemaMigration, callsMigration, capturedBy, changesMigration, channelSendsMigration, commentsMigration, computedMigration, derivedMigration, jobsSchemaMigration, notificationsMigration, ownedDefinitionsMigration, queryRunnerMigration, realtimeRelayMigration, relayed, sqlSends, statusMigration, userTablesMigration, webhooksMigration, workflowsMigration } from "@protobase/server";
|
|
3
3
|
//#region src/migration/parts.ts
|
|
4
4
|
/** Every feature the project's config enables, in the order their files are written. */
|
|
5
5
|
const migrationParts = (project) => {
|
|
@@ -11,7 +11,7 @@ const migrationParts = (project) => {
|
|
|
11
11
|
title: authMigrationTitle,
|
|
12
12
|
sql: () => authSchemaMigration(project.auth)
|
|
13
13
|
}] : [],
|
|
14
|
-
...project.jobs.length > 0 || project.models.some(
|
|
14
|
+
...project.jobs.length > 0 || project.models.some(capturedBy(project.models)) || comments || aiFields || project.webhooks || project.workflows || project.notifications ? [{
|
|
15
15
|
name: "jobs",
|
|
16
16
|
title: "The jobs schema this version of Protobase needs",
|
|
17
17
|
sql: () => jobsSchemaMigration(project.db)
|
|
@@ -26,7 +26,7 @@ const startWorker = async ({ config, databaseUrl, openDb = (url) => openAppDatab
|
|
|
26
26
|
const project = await buildProject(config, database);
|
|
27
27
|
const builtIn = configExports(project.config).resources.some((resource) => {
|
|
28
28
|
const model = resource.toModel();
|
|
29
|
-
return isCaptured(model) || model.comments || Object.values(model.fields).some((field) => field.ai);
|
|
29
|
+
return isCaptured(model) || model.live || model.comments || Object.values(model.fields).some((field) => field.ai);
|
|
30
30
|
});
|
|
31
31
|
if (project.jobs.length === 0 && !builtIn) throw new Error("The bundle has no jobs: name their module in protobase.config.ts as `jobs`, or give a resource events, history, comments or an AI field");
|
|
32
32
|
const { admin, jobs: definitions } = projectAdmin(project, db);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.94.
|
|
3
|
+
"version": "0.94.20",
|
|
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.94.
|
|
47
|
-
"@protobase/layout": "0.94.
|
|
48
|
-
"@protobase/query": "0.94.
|
|
49
|
-
"@protobase/schema": "0.94.
|
|
50
|
-
"@protobase/server": "0.94.
|
|
51
|
-
"@protobase/ui": "0.94.
|
|
52
|
-
"@protobase/workflows": "0.94.
|
|
46
|
+
"@protobase/config": "0.94.20",
|
|
47
|
+
"@protobase/layout": "0.94.20",
|
|
48
|
+
"@protobase/query": "0.94.20",
|
|
49
|
+
"@protobase/schema": "0.94.20",
|
|
50
|
+
"@protobase/server": "0.94.20",
|
|
51
|
+
"@protobase/ui": "0.94.20",
|
|
52
|
+
"@protobase/workflows": "0.94.20",
|
|
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",
|
|
@@ -11,6 +11,7 @@ The changes of each record, comments on it, and pages that refresh as records ch
|
|
|
11
11
|
- [Mentions](../reference/comments.md#mentions): Mentioning a colleague in a comment sends them an email with a link to the record.
|
|
12
12
|
- [Comment moderation](../reference/comments.md#moderation): Admins find and delete comments across the app.
|
|
13
13
|
- [Live updates](../reference/live.md#what-a-page-hears): Open lists and record pages refresh within seconds when a record changes, including changes made outside the API.
|
|
14
|
+
- [Live views](../reference/live.md#resources-backed-by-a-view) (experimental): A resource backed by a view updates live when the tables it reads change.
|
|
14
15
|
- [Change stream](../reference/live.md#the-stream): Apps follow record changes over a stream that catches up after a reconnect.
|
|
15
16
|
- [Polling, then a socket](../reference/live.md#polling-then-a-socket): Apps and Node scripts poll for changes first and switch to a WebSocket after 30 seconds, or at once, falling back to polling while the socket is down.
|
|
16
17
|
- [Presence](../reference/channels.md#presence) (beta): Apps see who else has a record open and what each of them tracks, such as online or away, for whoever may read the record.
|
|
@@ -7,6 +7,7 @@ The list page of each resource, with its columns, filters, charts, search, expor
|
|
|
7
7
|
- [Names and columns](../reference/ui-config.md#names-and-columns): Each resource gets singular and plural names and a title field, and a list shows the columns you choose, with a starting sort and search.
|
|
8
8
|
- [Field display hints](../reference/ui-config.md#names-and-columns): Labels, help lines, badges, codes, percentages, currencies, units, decimals and relative times such as "5 minutes ago".
|
|
9
9
|
- [Email, phone and web links](../reference/ui-config.md#names-and-columns): Fields marked as email, phone or URL show as links and are edited with the matching phone keyboard and browser autofill.
|
|
10
|
+
- [JSON fields and link text](../reference/ui-config.md#json-fields-and-link-text) (experimental): Tables show JSON fields readably, and links can carry their own text.
|
|
10
11
|
- [Markdown and long text](../reference/ui-config.md#names-and-columns): Long text is edited in a box that grows with it. Markdown fields have Write and Preview and show rendered on the record page.
|
|
11
12
|
- [Enum labels and colours](../reference/ui-config.md#names-and-columns): Enum values get readable labels and badge colours that show everywhere the value appears, and badges can be drawn as arrows, as on a rating scale.
|
|
12
13
|
- [Value tones and currencies](../reference/ui-config.md#value-tones-and-currencies): An enum value's badge takes the tone or colour its view gives it, and a money field shows in the ISO 4217 currency its view names.
|
|
@@ -43,6 +43,35 @@ It is live data, not multiplayer editing: two people editing the same record sti
|
|
|
43
43
|
|
|
44
44
|
Connecting again with `?after=<cursor>` catches up on what was missed while disconnected. [`client.live({ onChanges, onResync })`](client.md) of `@protobase/client` follows the stream and connects again by itself, as the app does. However many callers of one client follow it, they share one stream, so a page with many live views holds one connection, which matters under HTTP/1.1, where a browser opens at most six to a host.
|
|
45
45
|
|
|
46
|
+
## Resources backed by a view
|
|
47
|
+
|
|
48
|
+
:::caution[Experimental]
|
|
49
|
+
A view's change names no record, so the [Realtime socket](supabase-realtime.md) does not send it.
|
|
50
|
+
:::
|
|
51
|
+
|
|
52
|
+
A resource backed by a database view, such as a chat thread that merges messages and replies, updates live when the tables it reads change. A view takes no trigger, so name the resources it reads with `.live({ reads })`: a change in any of them refreshes the view's open lists, record pages and related lists, and a change in another table does not.
|
|
53
|
+
|
|
54
|
+
```ts title="config/thread.ts"
|
|
55
|
+
import { f, resource } from '@protobase/schema'
|
|
56
|
+
|
|
57
|
+
// A chat thread over a view merging messages and replies: an open thread shows a new message or reply within a second or two.
|
|
58
|
+
|
|
59
|
+
/** thread */
|
|
60
|
+
export const thread = resource('thread')
|
|
61
|
+
.table('thread')
|
|
62
|
+
.fields({
|
|
63
|
+
id: f.text().filterable(),
|
|
64
|
+
body: f.text(),
|
|
65
|
+
sent_at: f.timestamp().sortable(),
|
|
66
|
+
})
|
|
67
|
+
.primaryKey((r) => r.id)
|
|
68
|
+
.live({ reads: ['messages', 'replies'] })
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Each resource it names is captured like a live one, needs no `.live()` of its own and still needs a resource of its own; `protobase dev` and `protobase serve` do not start when a name is not a resource, or is another resource backed by a view: name the tables that view reads instead. The stream sends the view a change with an empty key, `{ resource, key: '', operation: 'update' }`, once for writes that come close together: any of its records may have changed, so the page reads what it shows of the view again. A reader hears of it in the tenant of the record that changed, or in every tenant when that resource has no tenant.
|
|
72
|
+
|
|
73
|
+
<gap>A view cannot update live from a table without a resource because the capture of plain tables is not implemented.</gap>
|
|
74
|
+
|
|
46
75
|
## Polling, then a socket
|
|
47
76
|
|
|
48
77
|
`pollThenSocket({ poll, onError, socket, onMessage, pollMs?, switchAfterMs?, socketFirst? })` of `@protobase/client`, in the browser and on Node, keeps up with anything that changes, until the function it returns is called. It calls `poll` at once and again `pollMs` (5 seconds) after each call ends, also after one that rejected, whose error goes to `onError`, and after `switchAfterMs` (30 seconds) opens the WebSocket `socket()` returns, such as `() => new WebSocket(url)`. Once the socket is open, polling stops: `poll` runs once more, for what changed before the socket opened, and `onMessage` gets each message's data. When the socket closes, or never opens, it polls again at once and opens a new socket `switchAfterMs` later. Polling goes on while a socket connects, so nothing waits on it. A short visit thus never opens a socket; `socketFirst: true` opens one at once instead, for a process that stays, and polls only while it is down.
|
|
@@ -51,6 +80,6 @@ Who is on a record's page and what they send each other, which no change of a re
|
|
|
51
80
|
|
|
52
81
|
## The table
|
|
53
82
|
|
|
54
|
-
[`protobase migration`](cli.md#migration) adds the table `changes.notices` to the `changes` schema of the event capture (renamed with `events: { schema }`), and the capture triggers of each live resource; apply it with the project's other migrations. `protobase dev` and `protobase serve` do not start while the table or a trigger is missing.
|
|
83
|
+
[`protobase migration`](cli.md#migration) adds the table `changes.notices` to the `changes` schema of the event capture (renamed with `events: { schema }`), and the capture triggers of each live resource and of each resource a live view reads; apply it with the project's other migrations. `protobase dev` and `protobase serve` do not start while the table or a trigger is missing.
|
|
55
84
|
|
|
56
85
|
A notice is a resource, a record key, the record's tenant and the operation, written by the `changes.dispatch` job in the transaction that removes the change from the outbox; a live resource therefore needs the [`jobs` schema](jobs.md#the-jobs-schema) and the app's workers. Notices are kept for 10 minutes. Each serving process with at least one page open reads the table once a second, however many pages it serves, so live updates work with several serving processes, with `PROTOBASE_JOBS=false` and through a pooler in transaction mode.
|
|
@@ -151,7 +151,7 @@ Each part gets:
|
|
|
151
151
|
|
|
152
152
|
### JSON
|
|
153
153
|
|
|
154
|
-
`json` is a field type Protobase brings for any JSON field a form should edit, such as a workflow run's `input`: `r.input.widget('json')`. The form edits the value as JSON text, the record page shows it written out on several lines, and a list's table
|
|
154
|
+
`json` is a field type Protobase brings for any JSON field a form should edit, such as a workflow run's `input`: `r.input.widget('json')`. The form edits the value as JSON text, the record page shows it written out on several lines, and a list's table as a [short summary](ui-config.md#json-fields-and-link-text). Text that does not parse yet says so under the box and leaves the value as it last parsed; an emptied box is null. It takes the form's whole width. A plugin that registers a field type named `json` replaces it.
|
|
155
155
|
|
|
156
156
|
### Members
|
|
157
157
|
|
|
@@ -103,7 +103,7 @@ Field hints:
|
|
|
103
103
|
| `.help(text, { when? })` | A line under the field on the record page and in forms. `when: 'editing'` shows it only while the record is edited; see [Help while editing](#help-while-editing). |
|
|
104
104
|
| `.notOnCreate()` | Leaves the field off the create form, for one that makes sense only once the record exists, such as a choice among records added after it: the create leaves it empty or to its default, and the record page shows it as usual. The server stops at startup on a field a create needs, one that is not optional and has no default, a boolean too. |
|
|
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
|
-
| `.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> |
|
|
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), and `.format('url', { text })` gives the link [its own text](#json-fields-and-link-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
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. |
|
|
@@ -135,6 +135,27 @@ view<typeof orders>('orders').fields((r) => ({
|
|
|
135
135
|
|
|
136
136
|
The table's columns take their width from the first rows it shows, and keep it while it scrolls, filters and sorts: the `.title` column gets the largest share, other text a share as long as its values, and short values such as enums, booleans, numbers, amounts and dates their own width whole. A value cut short shows whole when hovered. On a desktop the title column is pinned to the left by default, with the column before it when it is the second, so it stays in view when the table scrolls sideways; the column menu unpins it, and pins any other column to the left edge, and the choice is kept in the browser for that list. A column of the table is made wider or narrower by dragging its header's right edge, or with the left and right arrow keys on that edge, down to 64 pixels; the other columns keep their width, a drag never sorts, and the widths last until the page is left or reloaded. The row menu stays at the table's right edge as it scrolls sideways. Embedded lists and a page's `Table` blocks size their columns the same way.
|
|
137
137
|
|
|
138
|
+
### JSON fields and link text
|
|
139
|
+
|
|
140
|
+
:::caution[Experimental]
|
|
141
|
+
JSON summaries and link text are new and may change in any release.
|
|
142
|
+
:::
|
|
143
|
+
|
|
144
|
+
Tables show JSON fields readably, and links can carry their own text. A JSON field, such as a tool call's input, shows in a list's table, a related table, a page's `Table` block and on cards and a phone's rows as a short summary on one line: an object as its keys and values, plain values before nested ones, `command: ls -la, cwd: /tmp, env: {…}`, a list of plain values as those values, and a list of objects as how many it holds, `3 items`. An object or list inside another shows as `{…}` or `[…]`, an empty text as `""`, each value is cut at 40 characters so one long value leaves room for the rest, and the summary at 160. The keys keep the order the database returns, which for a `jsonb` column is shortest first. The record page shows the whole value, written out on several lines across the width of its section.
|
|
145
|
+
|
|
146
|
+
A `url` field's link shows its address unless you give it a text. `.format('url', { text })` takes a fixed text, or one with `{field}` placeholders the record fills in, each as the record page shows it, such as an enum value by its label:
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
view<typeof errors>('errors').fields((r) => ({
|
|
150
|
+
report: r.report.format('url', { text: 'Error report' }),
|
|
151
|
+
trace: r.trace.format('url', { text: '{title}' }),
|
|
152
|
+
}))
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
The link still opens the address in a new tab, in the list's cells, related tables, the record page and its sidebar; cards and a phone's rows show the text too. When a field it names is empty, the link shows its address rather than a text with a gap, and so does it for a reader who cannot read a field it names. The list loads the fields a link's text names along with its columns. A text on another format, or one naming a field the resource does not have, stops the server at startup.
|
|
156
|
+
|
|
157
|
+
<gap>Cards, boards and a list's phone rows cannot open a url field's address because links on a card's one-line parts are not implemented; they show its text or address as plain text.</gap>
|
|
158
|
+
|
|
138
159
|
### Related records in a list
|
|
139
160
|
|
|
140
161
|
A list column can show the records of another resource that point at each row, as a dot per record: the tasks that serve an objective, say, each in its status's colour, so an objective's dots turn green as its tasks get done. `c`, the list's third argument, makes the column, and its name goes among the `columns`:
|