@protobase/cli 0.94.17 → 0.94.19

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.94.17";
2
+ var version = "0.94.19";
3
3
  //#endregion
4
4
  export { version };
@@ -1,5 +1,5 @@
1
1
  import { authMigrationTitle } from "../auth/migration-file.js";
2
- import { authSchemaMigration, callsMigration, changesMigration, channelSendsMigration, commentsMigration, computedMigration, derivedMigration, isCaptured, jobsSchemaMigration, notificationsMigration, ownedDefinitionsMigration, queryRunnerMigration, realtimeRelayMigration, relayed, sqlSends, statusMigration, userTablesMigration, webhooksMigration, workflowsMigration } from "@protobase/server";
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(isCaptured) || comments || aiFields || project.webhooks || project.workflows || project.notifications ? [{
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.17",
3
+ "version": "0.94.19",
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.17",
47
- "@protobase/layout": "0.94.17",
48
- "@protobase/query": "0.94.17",
49
- "@protobase/schema": "0.94.17",
50
- "@protobase/server": "0.94.17",
51
- "@protobase/ui": "0.94.17",
52
- "@protobase/workflows": "0.94.17",
46
+ "@protobase/config": "0.94.19",
47
+ "@protobase/layout": "0.94.19",
48
+ "@protobase/query": "0.94.19",
49
+ "@protobase/schema": "0.94.19",
50
+ "@protobase/server": "0.94.19",
51
+ "@protobase/ui": "0.94.19",
52
+ "@protobase/workflows": "0.94.19",
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",
@@ -14,7 +14,7 @@ Pages of your own, built from blocks in a JSX layout.
14
14
  - [Tailwind classes](../reference/layouts.md#tailwind-classes) (experimental): Layouts can carry Tailwind classes, on plain elements and on blocks, for pages too custom for blocks.
15
15
  - [Full-width pages](../reference/blocks.md#page): A page fills the whole area beside the sidebar instead of a centred column, for a dashboard with many blocks.
16
16
  - [Data blocks](../reference/blocks.md#data): Counts, tables, single records, rows of cards, field values and progress bars.
17
- - [Row buttons](../reference/blocks.md#row-buttons): A table's rows carry a button to an address their fields name, such as a task's tab, labelled by a field of the row, such as its next step.
17
+ - [Row buttons](../reference/blocks.md#row-buttons) (experimental): A table's rows carry a button labelled by a field of the row, such as its next step; the row decides where it goes: a record tab a field names, a list with a filter built from its fields, or an outside https link a field holds.
18
18
  - [Record rows](../reference/blocks.md#recordrow): A sideways row of cards for a filter, favorites or saved searches, with a count and new-record marks.
19
19
  - [Record cards](../reference/blocks.md#recordcards): Full-width cards with fields and buttons, stacked or in a carousel.
20
20
  - [Image block](../reference/blocks.md#image): A picture one of the app's API functions draws for the reader, such as a system map, at the size and theme the client asks, refreshed on a timer; a client that draws no images shows its alt text, or nothing.
@@ -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.
@@ -226,7 +226,7 @@ The first records of a list, drawn the way the resource's list page draws them:
226
226
  | --- | --- |
227
227
  | `resource`, `filter`, `sort` | Which records, in which order. `resource` is required; `sort` defaults to the list's. |
228
228
  | `columns` | Field names for the table; default the view's list columns. |
229
- | `button` | A [button on each row](#row-buttons) to an address the row's fields name. |
229
+ | `button` | A [button on each row](#row-buttons) to an address the row's fields name, or to the outside page a field holds; a list of these gives each row the first whose fields it holds. |
230
230
  | `limit` | How many records it shows; default 10. It has no pages: the rest are in the list. Before 0.13 this was `pageSize`, rows per page; rename it. |
231
231
  | `display` | The display it opens in, such as `cards`; default the list's. |
232
232
  | `title`, `description`, `actions` | The heading. |
@@ -251,8 +251,30 @@ The first records of a list, drawn the way the resource's list page draws them:
251
251
  />
252
252
  ```
253
253
 
254
+ Each row can decide where its button goes:
255
+
256
+ - **A record's tab from a field**: `tab: '{tab}'` opens the tab the row's `tab` field names; a name the record page has no tab for opens its first tab.
257
+ - **A filtered list**: `{ kind: 'list', resource: 'holds', filter: 'task_id = {task_id} AND state = "{state}"' }` opens the list with a filter built from the row. A text value goes in quotes, escaped so a title with quotes in it stays one value; a value outside quotes must be a number or `true`/`false`, and a row with any other value there shows no button. The filter's fields must be filterable, as in any address.
258
+ - **An outside page**: `{ label: 'Error report', href: '{report_url}' }` opens the page the row's `report_url` field holds, in a new tab without the referrer, and the button carries the outside-link mark, which screen readers hear as "opens in a new tab". The `href` is one field, never a URL put together from parts, and a row whose field holds no `https:` URL shows no button.
259
+ - **A different kind per row**: `button` takes a list of these, and each row shows the first whose fields it holds, so one list can hold items that each need a different act. A row whose first such choice leads nowhere, such as an `href` field without an `https:` URL, shows no button rather than the next choice. A caller who cannot read a choice's fields or follow its address gets the list without it.
260
+
261
+ ```tsx
262
+ <Table
263
+ title="Needs attention"
264
+ resource="alerts"
265
+ columns={['summary']}
266
+ button={[
267
+ { label: 'Open the error report', href: '{report_url}' },
268
+ { label: '{verb}', to: { kind: 'record', resource: 'tasks', key: '{task_id}', tab: '{tab}' } },
269
+ { label: 'See its failed jobs', to: { kind: 'list', resource: 'failed_jobs', filter: 'alert_id = {id}' } },
270
+ ]}
271
+ />
272
+ ```
273
+
254
274
  <gap>A row button cannot show when the table switches to a list display such as cards because drawing it on a display is not implemented.</gap>
255
275
 
276
+ <gap>A row button cannot show beside its row's first cell on a phone, where the table scrolls sideways to reach it, because a phone layout for table rows is not implemented.</gap>
277
+
256
278
  ### RecordCard
257
279
 
258
280
  One record and what is inside it: the one `recordKey` names (the key as the record's URL has it), else the first that matches `filter` in `sort` order. Its children and its heading `actions` work on that record.
@@ -89,7 +89,7 @@ Record pages take the same conditions in the `when` of `l.section`, `l.related`
89
89
  | --- | --- |
90
90
  | `a.update(name, { label, set, confirm?, icon?, bulk?, inputs? })` | Updates the record with `set`, with its ETag; not offered on a record that holds those values already, unless it asks for `inputs`, whose answers it writes where `set` says `'{name}'`. |
91
91
  | `a.remove(name, { label, confirm?, icon? })` | Deletes the record (soft delete when the resource has one). |
92
- | `a.link(name, { label, to, icon? })` | Goes `to` an [address](#addresses) in the app, with `{field}` in its key, filter, order or create values replaced by the record's value, and its resource too when that is only `{field}`: see [links to a resource the record names](#links-to-a-resource-the-record-names). |
92
+ | `a.link(name, { label, to, icon? })` | Goes `to` an [address](#addresses) in the app, with `{field}` in its key, tab, filter, order or create values replaced by the record's value (one in quotes in a filter, `title = "{title}"`, with its quotes escaped, so any text stays one value), and its resource too when that is only `{field}`: see [links to a resource the record names](#links-to-a-resource-the-record-names). |
93
93
  | `a.link(name, { label, href, icon? })` | Opens an `href` that leaves the app (`https:`, `mailto:`), with `{field}` replaced by the record's value (percent-encoded); an `https:` or `http:` link opens in a new tab without the referrer. An `href` that is only a field, `'{website}'`, opens the URL the record holds, as it is: see [links to a record's URL](#links-to-a-records-url). A path in the app is refused when the config loads: give it as `to`. |
94
94
  | `a.ai(name, { label, prompt, writes, confirm?, icon? })` | Has the model write the field `writes` of the record from `prompt`, `{field}` replaced by the record's values, as the user, on the server; see [AI fields and actions](ai.md#ai-actions). |
95
95
  | `a.action(name, { label, confirm?, icon?, bulk?, inputs? })` | Runs the handler the app registers under `name` in [`protobase.ui.tsx`](custom-components.md#action-handlers), after asking for its [`inputs`](ui-config.md#actions-that-ask-for-input) in a dialog when it has some. |
@@ -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.
@@ -975,7 +975,7 @@ Without any configuration, the record page's rail has a **Related records** card
975
975
  | `actions` | Named actions of `resource`'s view, by name, as buttons on each card; only with `presentation: 'cards'` or `'compact'`. |
976
976
  | `time` | A date or timestamp field of `resource` each compact card shows beside its title, as its view formats it; only with `presentation: 'compact'`. |
977
977
  | `tone` | An enum field of `resource` whose value colours each card's left edge, by its view's [`valueColors`](#value-tones-and-currencies); only with `presentation: 'cards'` or `'compact'`. |
978
- | `button` | `{ label, to }`: a [button on each row](blocks.md#row-buttons), or each card, to an address the row's fields name, such as `{ label: '{verb}', to: { kind: 'record', resource: 'tasks', key: '{task_id}', tab: 'Review' } }`; a row without a value for a field it names shows none. Not with `lines`. |
978
+ | `button` | `{ label, to }` or `{ label, href }`, or a list of them of which each row shows the first whose fields it holds: a [button on each row](blocks.md#row-buttons), or each card, to an address the row's fields name, its tab or list filter too, or to the outside page a field holds, such as `{ label: '{verb}', to: { kind: 'record', resource: 'tasks', key: '{task_id}', tab: 'Review' } }`; a row without a value for a field it names shows none. Not with `lines`. |
979
979
  | `open` | The relation of `resource` whose record a row opens, for rows that link this record to another. By default the one relation in `resource`'s primary key besides `field`, when there is exactly one (a join resource such as `task_dependencies` keyed on `[task_id, type, depends_on_id]`); otherwise rows open their own records. The row's menu then has **Open** for the other record and **Edit** for the link itself. |
980
980
  | `limit` | How many records it shows, 1 to 100; default 10. Not with `presentation: 'record'`. When there are more, the section says so beside View all, such as "The first 10 of 37.". Before 0.13 this was `pageSize`, rows per page; rename it. |
981
981
  | `display` | The display of `resource`'s list it opens in, and View all opens, such as `cards`; default the list's. Not with `presentation: 'record'`. |