@protobase/cli 0.101.1 → 0.102.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.
@@ -18,6 +18,17 @@ const recordChildBlocks = /* @__PURE__ */ new Set([
18
18
  "ReferenceField",
19
19
  "RecordsIterator"
20
20
  ]);
21
+ const conditionProps = /* @__PURE__ */ new Set([
22
+ "filter",
23
+ "edgeFilter",
24
+ "animated",
25
+ "dashed",
26
+ "dotted"
27
+ ]);
28
+ const isArrowProp = (attribute) => {
29
+ const name = attribute.name.getText();
30
+ return conditionProps.has(name) || name === "node" && elementName(attribute).replace(/<.*$/, "") === "Graph";
31
+ };
21
32
  const unwrapped = (expression) => ts.isParenthesizedExpression(expression) ? expression.expression : expression;
22
33
  const isExpressionArrow = (expression) => {
23
34
  const inner = unwrapped(expression);
@@ -34,8 +45,8 @@ const layoutProblems = (code, file) => {
34
45
  };
35
46
  const visit = (node) => {
36
47
  if (ts.isJsxAttribute(node) && node.initializer && ts.isJsxExpression(node.initializer) && node.initializer.expression) {
37
- const kind = node.name.getText() === "filter" && isExpressionArrow(node.initializer.expression) ? void 0 : what(node.initializer.expression);
38
- if (kind) problems.push(`${at(node)}: <${elementName(node)} ${node.name.getText()}> is ${kind}; layout props must be static data, a filter may be one arrow of the builder. Use <Action name="..."> for behaviour, or a custom component for React code.`);
48
+ const kind = isArrowProp(node) && isExpressionArrow(node.initializer.expression) ? void 0 : what(node.initializer.expression);
49
+ if (kind) problems.push(`${at(node)}: <${elementName(node)} ${node.name.getText()}> is ${kind}; layout props must be static data, a filter or condition may be one arrow of the builder, the node of a Graph one arrow of its record. Use <Action name="..."> for behaviour, or a custom component for React code.`);
39
50
  }
40
51
  if (ts.isJsxExpression(node) && node.expression && (ts.isJsxElement(node.parent) || ts.isJsxFragment(node.parent))) {
41
52
  const kind = ts.isJsxElement(node.parent) && recordChildBlocks.has(node.parent.openingElement.tagName.getText().replace(/<.*$/, "")) && isExpressionArrow(node.expression) ? void 0 : what(node.expression);
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.101.1";
2
+ var version = "0.102.0";
3
3
  //#endregion
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.101.1",
3
+ "version": "0.102.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.101.1",
47
- "@protobase/layout": "0.101.1",
48
- "@protobase/query": "0.101.1",
49
- "@protobase/schema": "0.101.1",
50
- "@protobase/server": "0.101.1",
51
- "@protobase/ui": "0.101.1",
52
- "@protobase/workflows": "0.101.1",
46
+ "@protobase/config": "0.102.0",
47
+ "@protobase/layout": "0.102.0",
48
+ "@protobase/query": "0.102.0",
49
+ "@protobase/schema": "0.102.0",
50
+ "@protobase/server": "0.102.0",
51
+ "@protobase/ui": "0.102.0",
52
+ "@protobase/workflows": "0.102.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",
@@ -31,7 +31,7 @@ Pages of your own, built from blocks in a JSX layout.
31
31
  - [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.
32
32
  - [Chart block](../reference/blocks.md#chart): Counts, sums or averages by value or by date, as bars, lines or a donut, and over time split by a second field.
33
33
  - [Timeline block](../reference/blocks.md#timeline) (beta): A `Timeline` block draws records as bars in lanes over time, each bar's parts coloured by a status field and its waits striped, with the chosen bar's details under it.
34
- - [Graph plugin](../reference/plugins.md#graph) (beta): The graph plugin draws records as nodes and the records that link them as edges, grouped by a field and coloured by status, with the chosen node's details beside it.
34
+ - [Graph block](../reference/blocks.md#graph) (beta): A `Graph` block draws records as nodes and the records that link them as edges, laid out in layers or by force or at stored positions, each node in the region of its group, coloured by its status and drawing contents of the layout's own, each edge with a label, a status colour and a moving, dashed or dotted line, with the chosen node's details beside it.
35
35
  - [Conversations](../reference/blocks.md#conversation): A chat declared in the layout: a thread of a resource's messages under each sender's name and time, following new ones as they arrive, and a box that sends one as the signed-in user.
36
36
  - [Tool calls in threads](../reference/blocks.md#tool-calls): Conversation threads show tool calls in time order, with a status and an expandable input and result.
37
37
  - [Buttons and forms](../reference/blocks.md#behaviour): Buttons for named actions, and create or edit forms in a dialog.
@@ -583,6 +583,63 @@ view<typeof phases>('phases').fields((r) => ({
583
583
 
584
584
  Its [text form](layouts.md#text-form) is a Markdown table with a row per segment: its lane, bar, value, start and end under the fields' labels. A timeline whose fields the user cannot read is left out of their page, and a field it cannot draw, such as a `start` that is no date, stops the server at startup.
585
585
 
586
+ ### Graph
587
+
588
+ :::caution[Beta]
589
+ A graph is read-only: you cannot move, add or connect nodes in it, and it reads at most 500 nodes and 500 edges.
590
+ :::
591
+
592
+ The records of `nodes` as boxes and the records of `edges` as arrows between them, from the node an edge's `source` holds the key of to the one its `target` holds, such as services and the links between them, or tasks and what blocks them. Each node sits in the region of its `group`, coloured by its `status`, and draws its label and status, or contents of the layout's own; each edge can carry a label, a status colour and a moving, dashed or dotted line. With `select`, the chosen node's details draw beside the graph. Its drawing code loads only on a page with a graph, and it is laid out in a worker of its own, so a large graph never holds up the page.
593
+
594
+ | Prop | |
595
+ | --- | --- |
596
+ | `nodes`, `edges` | The resources whose records are the nodes and the edges. A node is found by its key, which must be one field: a resource with a key of several fields stops the server at startup. An edge whose `source` or `target` is not among the nodes is left out. Required. |
597
+ | `source`, `target` | The fields of an edge that hold the keys of the nodes it runs from and to. Required. |
598
+ | `label` | The field of a node that names it: its text where it draws no `node`, the name of its link and its line in the text form. Required. |
599
+ | `group` | The field of a node whose value puts it in a region with the nodes that hold the same, the value at the region's top; a node without one stands outside every region. |
600
+ | `status` | An enum field of a node, shown under its label and colouring its left edge, as the view's [`valueColors`](ui-config.md#value-tones-and-currencies) give each value. |
601
+ | `node` | What each node draws, inside its record: [placeholders](layouts.md#data), `Field`s, `Show`s and the other blocks that show a record, but no block that reads records of its own, which would read once per node. In a [typed layout](layouts.md#typed-layouts) it is a function of the node's record, `(service) => <Text>{service.owner}</Text>`. A node that draws one is 224 pixels wide and as tall as it draws. |
602
+ | `filter`, `edgeFilter` | Which nodes and which edges it shows, AIP-160 or the [builder's arrow](layouts.md#the-condition-builder). |
603
+ | `edgeLabel` | A field of an edge shown on its middle, by its value label if the edges' view gives one. |
604
+ | `edgeStatus` | An enum field of an edge that colours its line and arrow, as the edges' view's `valueColors` give each value. |
605
+ | `animated`, `dashed`, `dotted` | Conditions on an edge, AIP-160 or the builder's arrow of the edge's fields, `(link) => link.state.eq('busy')`, under which its line moves, as for work running along it, is dashed or is dotted; dotted wins over dashed. Each is evaluated for each edge as the graph draws, `now()` included. |
606
+ | `layout` | `layered` (the default), the nodes in layers along their edges, or `force`, linked nodes pulled near each other and the others pushed apart, for a graph that has no direction. |
607
+ | `direction` | Which way a layered graph's edges run: `down` (the default), which keeps it narrow on a phone, or `right`. |
608
+ | `x`, `y` | Two number fields of a node that place its top left corner, in pixels at the graph's normal size. A node with both stands there, and the nodes without are laid out under the placed ones; when every node has them, nothing is laid out. |
609
+ | `select` | The [page parameter](layouts.md#page-parameters) that holds the chosen node's key: each node links to the page with it chosen, a node that draws its own `node` as a whole, and the `Graph`'s children draw beside the graph, inside that node's record, or under it on a narrow screen. |
610
+ | `empty` | What it shows without nodes. |
611
+ | `fallback` | What draws in its place where it cannot draw, as when its records cannot be read, such as the [picture](#image) one of the app's API functions draws of the same graph. Without one, it shows the error. |
612
+
613
+ ```tsx
614
+ export const serviceMap = page('service-map', layout(() => (
615
+ <Page title="Services" width="full">
616
+ <Card title="Service map">
617
+ <Graph
618
+ nodes="services" edges="links" source="from_id" target="to_id"
619
+ label="name" group="area" status="health" select="service"
620
+ node={(service) => (
621
+ <>
622
+ <Text as="strong">{service.name}</Text>
623
+ <Text>{`Owned by ${service.owner}`}</Text>
624
+ </>
625
+ )}
626
+ edgeLabel="protocol" edgeStatus="state"
627
+ animated={(link) => link.state.eq('busy')}
628
+ dashed={(link) => link.optional.eq(true)}
629
+ fallback={<Image function="service_map" alt="The services and the links between them" />}
630
+ >
631
+ <Field source="owner" />
632
+ <Field source="health" />
633
+ </Graph>
634
+ </Card>
635
+ </Page>
636
+ )))
637
+ ```
638
+
639
+ The page's [read plan](layouts.md#how-a-page-reads-its-data) reads the nodes, with the fields they and their `node` draw, and the edges, with the fields their label, colour and conditions read, with the rest of the page as it opens. The same records always make the same picture: groups, nodes and edges are laid out in the order of their keys, and a force layout from a fixed seed. The graph is as wide as its place and as tall as its shape asks, up to most of the screen; it fits in that box unless that would make it too small to read, as on a phone, where you drag to pan. Pinch or the zoom buttons zoom it, the fit button shows all of it, and the mouse wheel scrolls the page past it. <gap>A group cannot show the title of the record its field points at, because reading related records' titles in the graph is not implemented, so a relation groups by its key.</gap> <gap>Nodes cannot be dragged to store their positions, because writing `x` and `y` from the graph is not implemented; store them from elsewhere, such as an action.</gap>
640
+
641
+ Its [text form](layouts.md#text-form) lists each group with its nodes and their status, the nodes in no group, then each edge as `a → b` with its label, from the records of the page's plan, or its fallback without them. A graph whose resources, label or ends the user cannot read is left out of their page, and its other props that name fields they cannot read are dropped.
642
+
586
643
  ## Related records
587
644
 
588
645
  The blocks that repeat over a record's related records, as [related records](layouts.md#related-records) explains, with the names, props and defaults of react-admin's components. `ReferenceManyField`, `ReferenceArrayField` and `ArrayField` hold a list and draw nothing of their own; a `RecordsIterator` or a `Table` without `resource` inside one draws it. Each sits inside a record, whose field it reads.
@@ -79,7 +79,7 @@ renderText(<Page title="Order"><Field source="status" /></Page>, {
79
79
  | `locale` | The reader's locale, such as `nl-NL`, in which [field components](#field-values) without `locales` format numbers and dates; the runtime's default when omitted. |
80
80
  | `basePath` | What links start with, such as `https://example.com/admin`. |
81
81
  | `forms` | Text forms by block type, over the built-in ones. |
82
- | `models`, `labels` | The app's resources by name, and per resource its fields' labels and value labels, which a custom component's text form reads its records with, such as the graph plugin's [`graphText`](plugins.md#graph). |
82
+ | `models`, `labels` | The app's resources by name, and per resource its fields' labels and value labels, which a [`Graph`](blocks.md#graph)'s text form and a custom component's read its records with. |
83
83
  | `planned` | Per read of the page's plan, by its block's place in the tree with `#<part>` for a block's other reads (`/children/0#edges`), and the record around it, the records it holds; `pageText` gives it, so a custom component's text form reads its own reads' records. |
84
84
 
85
85
  A heading reads at its level: a `Page` title as `#`, a `Tab` label as `##`, and the title of a `Card` and of a data block as `###`, the data block's linked to its records' list as it filters them. A field's value reads as its enum label, a list as its items, and JSON as a code block. A table's records read as a Markdown table: a header row of labels, a separator row and a row per record, its columns most important first by the same rule a [phone](blocks.md#columns-on-a-phone) uses, each cell on one line with its pipes escaped. `tableMarkdown` gives the same table for records you hold yourself.
@@ -119,7 +119,7 @@ It takes the options of `renderText` but `records`, `tables` and `planned`, and
119
119
 
120
120
  A prop is a string, a finite number, a boolean, `null`, or an array or plain object of those (elements included). It is JSON in the end, so the rules are checked twice:
121
121
 
122
- - **At build time.** `protobase build` and `protobase dev` read every file with the `@jsxImportSource @protobase/layout` comment and refuse a function, class or `new` value in a prop or child, and any call to a hook (`useState`, ...), with the file, line and column. Two arrows are data and pass: a [filter's arrow](#the-condition-builder) and a record block's child arrow in a [typed layout](#typed-layouts), each one expression, never a body of statements. No project code runs for this.
122
+ - **At build time.** `protobase build` and `protobase dev` read every file with the `@jsxImportSource @protobase/layout` comment and refuse a function, class or `new` value in a prop or child, and any call to a hook (`useState`, ...), with the file, line and column. Two kinds of arrow are data and pass: a [filter's arrow](#the-condition-builder), and a [`Graph`](blocks.md#graph)'s `edgeFilter`, `animated`, `dashed` and `dotted`, and a record block's child arrow or a `Graph`'s `node` in a [typed layout](#typed-layouts), each one expression, never a body of statements. No project code runs for this.
123
123
  - **When the config loads.** The JSX runtime refuses anything else that is not plain data (a function in a variable, a `Date`, a `Map`, `NaN`), `page()` checks every element's props against its block (unknown, missing and mistyped props, children where none are allowed, elements that need a record outside one), and `createAdmin` checks every resource, field, filter, sort, action and condition against the models. Each problem names its place, such as `Page "overview": <Page> › <Table resource="invoices">: unknown column "amount" on invoices`.
124
124
 
125
125
  Behaviour comes from [named actions](#named-actions); React code from [custom components](custom-components.md).
@@ -188,7 +188,7 @@ export const tasksView = view<typeof tasks>('tasks').layout(() => [
188
188
  | --- | --- |
189
189
  | `data` | The record page's record, in `recordLayout` only: `data.title` is the placeholder `{{title}}`, so `` `Runs of ${data.title}` `` is `Runs of {{title}}`. |
190
190
  | `resources` | `resources.invoices.count` is how many `invoices` the user can see, for a [condition](#conditions). |
191
- | A record block's child | A `RecordCard`, a `CardRow`, a `ReferenceField` or a `RecordsIterator` takes a function of its record as its children, `(run) => ...`. Inside it `run.outcome` is `{{outcome}}`, the page's record is `{{@root.title}}`, and a record further out is `{{../outcome}}`. |
191
+ | A record block's child | A `RecordCard`, a `CardRow`, a `ReferenceField` or a `RecordsIterator` takes a function of its record as its children, `(run) => ...`, and a [`Graph`](blocks.md#graph) one of its node's record as its `node`. Inside it `run.outcome` is `{{outcome}}`, the page's record is `{{@root.title}}`, and a record further out is `{{../outcome}}`. |
192
192
 
193
193
  With `.protobase/register.d.ts`, which `protobase types`, `dev` and `build` write from `config/index.ts` (see [`types`](cli.md#types)), TypeScript checks the names against the app: `resource` against its resources, `columns`, `fields`, `sort` and the filter's fields against the resource's fields, `data` against the record's fields, and a [`<Trans>`](#texts-in-the-readers-language)'s key against its texts. Without the file, any name type-checks and the server checks them as it starts. Export a typed layout inside `page()` or a view, as above: a tree exported bare, `export const tree = layout(...)`, refers to its own type through the register, and TypeScript gives up on it.
194
194
 
@@ -209,70 +209,6 @@ export default definePlugin({ fileViewers: { 'application/vnd.example.report+jso
209
209
 
210
210
  `useFileText(file)` reads the file's text once, as a TanStack Query result kept while the file stays the same. It reads through the API that serves the record, whatever store holds the file and wherever its link points, up to 10 MB. The viewer draws on the page below the file's bar, which scrolls as the page does. The file's link is a download link served with a sandboxing CSP, so a viewer reads the file and draws it itself rather than framing it; a page of HTML it draws in an [`HtmlFrame`](files.md#html-files).
211
211
 
212
- ## Graph
213
-
214
- :::caution[Beta]
215
- A graph is read-only, and its positions are laid out automatically: you cannot move, add or connect nodes in it.
216
- :::
217
-
218
- `@protobase/graph` is a plugin with a `Graph` layout block: it draws the records of one resource as nodes and the records of another as edges between them, each node in the box of its group and coloured by its status, and with `select` the chosen node's details beside the graph. It draws with the `@xyflow/react` package and lays the graph out with the `@dagrejs/dagre` package, so an app that does not attach it carries neither. An app installs it and extends its `protobase.ui.tsx` with it:
219
-
220
- ```sh
221
- npm install @protobase/graph
222
- ```
223
-
224
- ```tsx
225
- // protobase.ui.tsx
226
- import { defineUi } from '@protobase/ui'
227
- import graph from '@protobase/graph'
228
-
229
- export default defineUi({ extends: [graph] })
230
- ```
231
-
232
- Its layout uses the block from `@protobase/graph/layout`, which carries no drawing code:
233
-
234
- ```tsx
235
- /** @jsxImportSource @protobase/layout */
236
- import { Card, Field, page, Page } from '@protobase/layout'
237
- import { Graph } from '@protobase/graph/layout'
238
-
239
- export const serviceMap = page(
240
- 'service-map',
241
- <Page title="Services" width="full">
242
- <Card title="Service map">
243
- <Graph nodes="services" edges="links" label="name" group="area" status="health" source="from_id" target="to_id" select="service">
244
- <Field source="name" />
245
- <Field source="health" />
246
- </Graph>
247
- </Card>
248
- </Page>,
249
- )
250
- ```
251
-
252
- | Prop | |
253
- | --- | --- |
254
- | `nodes` | The resource whose records are the nodes, each by its key, which is one field: a resource with a key of several fields draws the fallback. |
255
- | `edges` | The resource whose records are the edges. An edge whose `source` or `target` is not among the nodes is left out. |
256
- | `label` | The field of a node that labels it. |
257
- | `group` | The field of a node whose value puts it in a box with the nodes that hold the same; a node without one stands outside every box. |
258
- | `status` | The enum field of a node shown under its label, and colouring its left edge, as the view's `valueColors` give each value. |
259
- | `source`, `target` | The fields of an edge that hold the keys of the nodes it runs from and to. |
260
- | `select` | The [page parameter](layouts.md#page-parameters) that holds the chosen node's key: each node's label links to the page with it chosen, and the `Graph`'s children draw beside the graph, inside that node's record, or under it on a narrow screen. |
261
- | `empty` | What it shows without nodes. |
262
-
263
- The block declares its [reads](custom-components.md#reads): the page's [read plan](layouts.md#how-a-page-reads-its-data) reads the nodes and the edges, up to 500 of each, with the rest of the page as it opens, and the plugin only draws them. The same records always make the same picture: edges run top to bottom, and groups, nodes and edges are laid out in the order of their keys. The graph is as wide as its place and as tall as its shape asks, up to most of the screen; it fits in that box unless that would make it too small to read, as on a phone, where you drag to pan. Pinch or the zoom buttons zoom it, the fit button shows all of it, and the mouse wheel scrolls the page past it. <gap>A group cannot show the title of the record its field points at because reading related records' titles in the graph is not implemented, so a relation groups by its key.</gap>
264
-
265
- Where it cannot be drawn, a client draws its fallback. `graph({ fallback })` declares the block with one, such as the [picture](blocks.md#image) one of the app's API functions draws of the same graph:
266
-
267
- ```tsx
268
- import { Image } from '@protobase/layout'
269
- import { graph } from '@protobase/graph/layout'
270
-
271
- export const Graph = graph({ fallback: <Image function="service_map" alt="The services and the links between them" /> })
272
- ```
273
-
274
- Its [text form](layouts.md#text-form), `graphText` from `@protobase/graph/layout`, lists each group with its nodes and their status, then each edge as `a → b`, from the records of the page's plan: pass it as `forms: { Graph: graphText }` to `pageText`, with the app's `models` and `labels`.
275
-
276
212
  ## Building
277
213
 
278
214
  ```sh