@protobase/cli 0.63.3 → 0.63.4
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/doctor/run.js +2 -0
- package/dist/doctor/sort-issues.js +26 -0
- package/dist/doctor/view-shapes.js +9 -6
- package/package.json +7 -7
- package/skills/protobase/references/features/record-pages.md +1 -1
- package/skills/protobase/references/reference/cli.md +7 -0
- package/skills/protobase/references/reference/ui-config.md +12 -2
package/dist/cli/package.js
CHANGED
package/dist/doctor/run.js
CHANGED
|
@@ -6,6 +6,7 @@ import { checkResource } from "./check.js";
|
|
|
6
6
|
import { indexIssues } from "./index-issues.js";
|
|
7
7
|
import { readShapes } from "./read-shapes.js";
|
|
8
8
|
import { relationIssues } from "./relation-issues.js";
|
|
9
|
+
import { sortIssues } from "./sort-issues.js";
|
|
9
10
|
import { existsSync } from "node:fs";
|
|
10
11
|
import path from "node:path";
|
|
11
12
|
import { tableIndexes } from "@protobase/query";
|
|
@@ -24,6 +25,7 @@ const runDoctor = async (options, out) => {
|
|
|
24
25
|
const issues = models.flatMap((model, i) => [
|
|
25
26
|
...checkResource(model, tables),
|
|
26
27
|
...relationIssues(model, models),
|
|
28
|
+
...sortIssues(model, shapes),
|
|
27
29
|
...indexes[i]
|
|
28
30
|
]);
|
|
29
31
|
for (const issue of issues) out(format(issue));
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/doctor/sort-issues.ts
|
|
2
|
+
/**
|
|
3
|
+
* The reads of `model` that sort by a field it does not mark `.sortable()`, which the API refuses: one error per field,
|
|
4
|
+
* naming each read that sorts by it and where it comes from, the order a list opens in included.
|
|
5
|
+
*/
|
|
6
|
+
const sortIssues = (model, shapes) => {
|
|
7
|
+
const refused = /* @__PURE__ */ new Map();
|
|
8
|
+
for (const shape of shapes) {
|
|
9
|
+
if (shape.resource !== model.name) continue;
|
|
10
|
+
for (const [name] of shape.query.sort ?? []) {
|
|
11
|
+
if ((Object.hasOwn(model.fields, name) ? model.fields[name] : void 0)?.sortable !== false) continue;
|
|
12
|
+
const requests = refused.get(name) ?? /* @__PURE__ */ new Map();
|
|
13
|
+
const from = requests.get(shape.request) ?? [];
|
|
14
|
+
if (!from.includes(shape.from)) requests.set(shape.request, [...from, shape.from]);
|
|
15
|
+
refused.set(name, requests);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return [...refused].map(([name, requests]) => ({
|
|
19
|
+
severity: "error",
|
|
20
|
+
resource: model.name,
|
|
21
|
+
message: `${name}: not sortable, so the API refuses:${[...requests].map(([request, from]) => `\n ${request} (${from.join("; ")})`).join("")}`,
|
|
22
|
+
suggestion: `mark "${name}" .sortable() in data.ts, or sort the list by a sortable field`
|
|
23
|
+
}));
|
|
24
|
+
};
|
|
25
|
+
//#endregion
|
|
26
|
+
export { sortIssues };
|
|
@@ -10,9 +10,12 @@ const request = (resource, filter, sort) => {
|
|
|
10
10
|
const params = [...filter ? [`filter=${filter}`] : [], ...sort ? [`order_by=${sortText(sort)}`] : []];
|
|
11
11
|
return `GET /${resource}${params.length > 0 ? `?${params.join("&")}` : ""}`;
|
|
12
12
|
};
|
|
13
|
-
/** The order a list opens in, as the app asks for it: the view's sort, or the primary key's. */
|
|
13
|
+
/** The order a list opens in, as the app asks for it: the view's sort, or the primary key's when it is sortable, else none. */
|
|
14
14
|
const listSort = (model, view) => {
|
|
15
|
-
|
|
15
|
+
const first = view?.list?.sort?.[0];
|
|
16
|
+
if (first) return [first];
|
|
17
|
+
const key = model.primaryKey[0];
|
|
18
|
+
return model.fields[key]?.sortable ? [[key, "asc"]] : void 0;
|
|
16
19
|
};
|
|
17
20
|
const widgetShapes = (model, widget, from) => {
|
|
18
21
|
const shape = (request, query) => ({
|
|
@@ -149,7 +152,7 @@ const displayShapes = (model, view, models) => (view.list?.displays ?? []).flatM
|
|
|
149
152
|
from: `the board display "${display.name}"`,
|
|
150
153
|
query: {
|
|
151
154
|
filter: compare(by),
|
|
152
|
-
sort
|
|
155
|
+
...sort && { sort }
|
|
153
156
|
}
|
|
154
157
|
}];
|
|
155
158
|
}
|
|
@@ -223,7 +226,7 @@ const recentShapes = (model, view) => {
|
|
|
223
226
|
from: "the recent records in the sidebar",
|
|
224
227
|
query: {
|
|
225
228
|
...filter && { filter },
|
|
226
|
-
sort
|
|
229
|
+
...sort && { sort }
|
|
227
230
|
}
|
|
228
231
|
}];
|
|
229
232
|
};
|
|
@@ -233,7 +236,7 @@ const openingShape = (model, view, list, sort) => {
|
|
|
233
236
|
resource: model.name,
|
|
234
237
|
request: request(model.name, void 0, sort),
|
|
235
238
|
from: `${list}'s order`,
|
|
236
|
-
query: { sort }
|
|
239
|
+
query: { ...sort && { sort } }
|
|
237
240
|
};
|
|
238
241
|
const filter = configFilter(model, source);
|
|
239
242
|
return {
|
|
@@ -242,7 +245,7 @@ const openingShape = (model, view, list, sort) => {
|
|
|
242
245
|
from: `${list} as it opens`,
|
|
243
246
|
query: {
|
|
244
247
|
...filter && { filter },
|
|
245
|
-
sort
|
|
248
|
+
...sort && { sort }
|
|
246
249
|
}
|
|
247
250
|
};
|
|
248
251
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.63.
|
|
3
|
+
"version": "0.63.4",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@better-auth/core": "^1.7.12",
|
|
44
44
|
"@hono/node-server": "^2.1.3",
|
|
45
|
-
"@protobase/config": "0.63.
|
|
46
|
-
"@protobase/layout": "0.63.
|
|
47
|
-
"@protobase/query": "0.63.
|
|
48
|
-
"@protobase/schema": "0.63.
|
|
49
|
-
"@protobase/server": "0.63.
|
|
50
|
-
"@protobase/ui": "0.63.
|
|
45
|
+
"@protobase/config": "0.63.4",
|
|
46
|
+
"@protobase/layout": "0.63.4",
|
|
47
|
+
"@protobase/query": "0.63.4",
|
|
48
|
+
"@protobase/schema": "0.63.4",
|
|
49
|
+
"@protobase/server": "0.63.4",
|
|
50
|
+
"@protobase/ui": "0.63.4",
|
|
51
51
|
"@react-email/render": "^2.1.0",
|
|
52
52
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
53
53
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -20,7 +20,7 @@ The page of one record, with its sections, related records, galleries, charts an
|
|
|
20
20
|
- [Conditional sections](../reference/ui-config.md#form-and-read-view): Sections and fields show only while editing, only while reading, or only when a condition on the record holds.
|
|
21
21
|
- [Galleries](../reference/ui-config.md#galleries): A record's photos show as tiles that open a full-screen lightbox, with keyboard and swipe navigation.
|
|
22
22
|
- [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.
|
|
23
|
-
- Record lines:
|
|
23
|
+
- [Record lines](../reference/ui-config.md#record-lines): All the lines of a record, such as those of an invoice, show as a table on its page, where you edit, add, remove and reorder them, and Save writes the record and its lines together.
|
|
24
24
|
- [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.
|
|
25
25
|
- [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.
|
|
26
26
|
- [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.
|
|
@@ -119,6 +119,13 @@ Imports `config/index.ts` and the views of `config/*/ui.ts`, as the config modul
|
|
|
119
119
|
```
|
|
120
120
|
|
|
121
121
|
Reads are judged as the scan guard's default `reject` mode judges them, for a role that reads every row, such as admin; other access rules are code doctor does not run. A resource on a plain view or a foreign table is not judged, as the scan guard does not judge it.
|
|
122
|
+
- error: a read of those that sorts by a field that is not `.sortable()`, which the API refuses with a `400` whatever the indexes: a list's order, from its view's `sort` or the order the app picks itself, such as a calendar's or timeline's start, a recent-records `orderBy`, a related section's, gallery's or page block's `sort`. One error per field, with every request that sorts by it:
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
error seller: name: not sortable, so the API refuses:
|
|
126
|
+
GET /seller?order_by=name asc (the seller list's order)
|
|
127
|
+
fix: mark "name" .sortable() in data.ts, or sort the list by a sortable field
|
|
128
|
+
```
|
|
122
129
|
- warning: enum values differ
|
|
123
130
|
|
|
124
131
|
Exit code is 1 when there are errors. Run it after the project's migrations and before a new version serves, as a platform's deploy does: a read it fails is one the API would refuse once the version runs. `protobase build` needs no database, so the indexes are doctor's to check.
|
|
@@ -51,7 +51,7 @@ export const repairsView = view<typeof repairs>('repairs')
|
|
|
51
51
|
| `.title((r) => r.number)` | The field that names a record: in breadcrumbs, browser tabs, the record page's heading, relation links and search results. |
|
|
52
52
|
| `.titleFrom(rule, (r) => [r.member_ids])` | A title derived in the browser for the person reading it, in place of `.title`, by the function `rule` names in the UI config's `titles`, from the fields picked. See [Titles per reader](#titles-per-reader). |
|
|
53
53
|
| `.searchResult((r) => ({ title?, subtitle? }))` | A record in the [global search](client.md#global-search): `title` is one field or several joined by spaces (`[r.first_name, r.last_name]`, default: `.title`), `subtitle` the line under it (default: the first search field not in the title), replaced by the search field the text matched when neither line shows it. |
|
|
54
|
-
| `.list((r, d, c) => ({ columns, sort?, search?, filter?, editable?, displays?, default? }))` | The list's columns in order, fields or [related records](#related-records-in-a-list) (`c.related`); the `filter` it [opens with](#a-filter-the-list-opens-with); its starting `sort` as `[[field, 'asc' \| 'desc'], ...]`, on `.sortable()` fields; the fields the search box suggests, among the resource's `.search` fields, which decide what search matches on the server; the columns [edited in their cell](#editing-in-the-list); other ways to show it, see [List displays](#list-displays). `protobase build` fails on a sort or search field outside those. |
|
|
54
|
+
| `.list((r, d, c) => ({ columns, sort?, search?, filter?, editable?, displays?, default? }))` | The list's columns in order, fields or [related records](#related-records-in-a-list) (`c.related`); the `filter` it [opens with](#a-filter-the-list-opens-with); its starting `sort` as `[[field, 'asc' \| 'desc'], ...]`, on `.sortable()` fields, else the primary key's order when it is `.sortable()`, else none, which the API orders by the key; the fields the search box suggests, among the resource's `.search` fields, which decide what search matches on the server; the columns [edited in their cell](#editing-in-the-list); other ways to show it, see [List displays](#list-displays). `protobase build` fails on a sort or search field outside those. |
|
|
55
55
|
| `.fields((r) => ({ name: r.name.label(...) }))` | Hints per field, below. Calls add up. |
|
|
56
56
|
| `.help(text)` | A line under the list's title. |
|
|
57
57
|
| `.nav({ group, order, hidden, recent, tenant })` | Where the resource sits in the sidebar, its [recent-record group](sidebar.md#recent-records), and with `tenant: 'current'` that it opens on [the current organization](sidebar.md#the-current-organization). |
|
|
@@ -226,7 +226,7 @@ The list of a resource ordered as one, such as the products, has a **Reorder** b
|
|
|
226
226
|
|
|
227
227
|
Each drop shows at once and is saved straight away: one [batch `reorder`](api.md#batch-writes) sends only the stretch of records whose place changed, with the ETags they were listed with, and numbers them on from the record before them; it reaches further only where a gap or a tie left by an earlier write needs it, so a list of thousands saves a short move as a few records. Drops made while one saves are saved after it. A saved drop says so in a toast with **Undo**, which puts back the positions it changed; see [Dragging in the list](#dragging-in-the-list). A refusal, such as a record someone else changed since, puts the rows back as the server has them, with the reason. Every list of the resource reloads afterwards.
|
|
228
228
|
|
|
229
|
-
A user who may not update the resource or write the field gets no **Reorder**, and `/api/meta` leaves out `position` for one who cannot read its field or its `within`. A related section offers it only when it lists all of the parent's records: its `field` is the `within` relation, without a `filter` or `through`. The list page does not offer it for a resource ordered within a parent, since its list mixes the parents. The field must be `.sortable()` and `within` a `.filterable()` relation, checked when the config loads, and [`protobase doctor`](cli.md#doctor) checks that an index serves each read in the field's order, such as `(invoice_id, position)`. Records created later are not numbered for you: give them a position, or the next drop numbers them, after the others when the field is empty.
|
|
229
|
+
A user who may not update the resource or write the field gets no **Reorder**, and `/api/meta` leaves out `position` for one who cannot read its field or its `within`. A related section offers it only when it lists all of the parent's records: its `field` is the `within` relation, without a `filter` or `through`. The list page does not offer it for a resource ordered within a parent, since its list mixes the parents. The field must be `.sortable()` and `within` a `.filterable()` relation, checked when the config loads, and [`protobase doctor`](cli.md#doctor) checks that an index serves each read in the field's order, such as `(invoice_id, position)`. Records created later are not numbered for you: give them a position, or the next drop numbers them, after the others when the field is empty; the [record lines](#record-lines) table numbers the lines it adds.
|
|
230
230
|
|
|
231
231
|
### Dragging in the list
|
|
232
232
|
|
|
@@ -773,6 +773,16 @@ The record's form and the create form edit each field as its type asks, under it
|
|
|
773
773
|
- **Save conflicts.** When someone else saved the record after it was opened, Save writes nothing over their change: the form takes in the record as it is now, keeps your changes, and each field you both changed shows the value saved in the meantime, with **Keep mine** and **Use theirs**. The next Save writes what you kept.
|
|
774
774
|
- **Leaving.** Leaving a page with changes not yet saved, by a link, a reload or closing the tab, asks first. The record's form keeps its changes in the browser, so they come back when the record opens again; the create page, a [`ModalForm`](blocks.md#modalform) and a comment being written lose theirs, and the question says so.
|
|
775
775
|
|
|
776
|
+
### Record lines
|
|
777
|
+
|
|
778
|
+
A record with numbered lines, such as an invoice, shows all of them on its page as one table, without paging. The lines are the records of the first resource with a relation to the record's resource, an integer `position` field and a `quantity` field, and the table's columns are their list columns (`.list({ columns })` of their view, or their first fields), without the line's key, its tenant, the relation to the record and `position`, which is the order of the rows.
|
|
779
|
+
|
|
780
|
+
On the record's form the lines are edited in place, each field with the form's own editor and a relation with its picker. **Add line** adds an empty line at the end, which gets the record's key and the place after the last line when saved, and the database's defaults fill what is left empty. **Remove line**, in a line's menu, removes it, and the drag handle or **Move up** and **Move down** change the order, as in [Reordering by hand](#reordering-by-hand).
|
|
781
|
+
|
|
782
|
+
Nothing is written until **Save**, which writes the record and its lines in one [batch](api.md#batch-writes), all or nothing: the removed lines are deleted, the changed fields of a line updated with the ETag it was read with, the new lines created and the order written with `reorder`. A line the server turns down says why, under the field it names or under the line, and the changes stay to put right. When someone else changed the lines in the meantime, nothing is written and the lines load again.
|
|
783
|
+
|
|
784
|
+
**Add line** is there for a user who may create lines, a line's fields and the order change for one who may update them, and **Remove line** for one who may delete them, as each line's own permissions allow. On the read view, and on a record the user may not update, such as a sent invoice whose [rule](access.md#rules-that-read-the-record) allows updates to drafts only, the lines only show. The table loads up to 1,000 lines; a record with more shows them, the first 1,000, read-only.
|
|
785
|
+
|
|
776
786
|
### Deleting a record
|
|
777
787
|
|
|
778
788
|
**Delete**, in the action rail of a user who may delete the record, asks first. A resource with a [soft delete](data-config.md#resource) deletes at once instead, and the toast offers **Undo**, which brings the record back. When someone saved the record after it was opened, the delete stops and says so, with **Review changes**, which shows the record as it is now, and **Delete anyway**. When other records still point at it, the delete is refused and the toast names them, such as "Orders still point at this company.", with a link to their list filtered on this record when the user may read it. Deleting a list's selected rows asks once, deletes only the rows that did not change since the list loaded, and lists each record it kept and why.
|