@protobase/cli 0.100.13 → 0.100.15

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.
@@ -13,7 +13,7 @@ import { shellForBuild, shellManifestFile } from "./shell.js";
13
13
  import { checkUi } from "./ui-check.js";
14
14
  import { checkPageScopes } from "./page-scope-check.js";
15
15
  import { checkViews } from "./view-check.js";
16
- import { pagesCarryClasses } from "./page-classes.js";
16
+ import { pagesCarryClasses, viewsCarryClasses } from "./page-classes.js";
17
17
  import { existsSync } from "node:fs";
18
18
  import path from "node:path";
19
19
  import { cp, readFile, rm, writeFile } from "node:fs/promises";
@@ -61,10 +61,11 @@ const buildDeployBundle = async ({ projectDir, outDir, bun, extensions = [], sou
61
61
  components
62
62
  });
63
63
  const mobileSection = bundleMobile(mobile, notifications);
64
- const { pages, models } = await checkViews(projectDir);
64
+ const { pages, views, models } = await checkViews(projectDir);
65
65
  checkPageScopes(pages, models, {
66
66
  strict,
67
- onWarning
67
+ onWarning,
68
+ views
68
69
  });
69
70
  await checkUi(projectDir, extensions, components);
70
71
  const packages = native.length > 0 ? await copyPackages(native, path.join(outDir, bundleNodeModules)) : [];
@@ -78,7 +79,7 @@ const buildDeployBundle = async ({ projectDir, outDir, bun, extensions = [], sou
78
79
  projectDir,
79
80
  publicDir,
80
81
  extensions,
81
- styles: pagesCarryClasses(pages),
82
+ styles: pagesCarryClasses(pages) || viewsCarryClasses(views),
82
83
  ignore: [outDir, path.join(projectDir, protobaseFolder)],
83
84
  sourceMaps
84
85
  });
@@ -1,12 +1,16 @@
1
1
  import { walkTree } from "@protobase/layout";
2
+ import { layoutItems } from "@protobase/schema/internal";
2
3
  //#region src/build/page-classes.ts
3
- /** Whether any element of the pages carries Tailwind classes, which then need a stylesheet of the project's. */
4
- const pagesCarryClasses = (pages) => pages.some((page) => {
4
+ const treeCarriesClasses = (tree) => {
5
5
  let found = false;
6
- walkTree(page.tree, (node) => {
6
+ walkTree(tree, (node) => {
7
7
  if (typeof node.props.className === "string" && node.props.className.trim() !== "") found = true;
8
8
  });
9
9
  return found;
10
- });
10
+ };
11
+ /** Whether any element of the pages carries Tailwind classes, which then need a stylesheet of the project's. */
12
+ const pagesCarryClasses = (pages) => pages.some((page) => treeCarriesClasses(page.tree));
13
+ /** Whether any element of the views' record page block trees (`l.blocks`), in tabs and fallbacks too, carries Tailwind classes. */
14
+ const viewsCarryClasses = (views) => views.some((view) => layoutItems(view.layout).some((item) => item.kind === "blocks" && treeCarriesClasses(item.tree)));
11
15
  //#endregion
12
- export { pagesCarryClasses };
16
+ export { pagesCarryClasses, viewsCarryClasses };
@@ -1,16 +1,18 @@
1
+ import { recordBlocksOf } from "@protobase/server";
1
2
  import { pageFindings } from "@protobase/layout";
2
3
  //#region src/build/page-scope-check.ts
3
4
  /**
4
- * Hears of each bare name in the pages that a nearer record shadows, which reads the nearest one as Mustache does;
5
- * with `strict` (`protobase build --strict`) they fail the build instead. The models are the config folder's own, so
6
- * every other problem of a page is left to the server's check of them all.
5
+ * Hears of each bare name in the pages, and in the block trees of the views' record pages, that a nearer record
6
+ * shadows, which reads the nearest one as Mustache does; with `strict` (`protobase build --strict`) they fail the build
7
+ * instead. The models are the config folder's own, so every other problem of a page is left to the server's check of
8
+ * them all.
7
9
  */
8
- const checkPageScopes = (pages, models, { strict = false, onWarning }) => {
9
- const byName = Object.fromEntries(models.map((model) => [model.name, model]));
10
- const warnings = pages.flatMap((page) => pageFindings(page, {
11
- models: byName,
10
+ const checkPageScopes = (pages, models, { strict = false, onWarning, views = [] }) => {
11
+ const input = {
12
+ models: Object.fromEntries(models.map((model) => [model.name, model])),
12
13
  actions: () => /* @__PURE__ */ new Set()
13
- }).warnings.map((warning) => `Page "${page.name}": ${warning}`));
14
+ };
15
+ const warnings = [...pages.flatMap((page) => pageFindings(page, input).warnings.map((warning) => `Page "${page.name}": ${warning}`)), ...recordBlocksOf(views, input).warnings];
14
16
  if (strict && warnings.length > 0) throw new Error(`The pages read shadowed names, which --strict refuses:\n${warnings.map((warning) => ` - ${warning}`).join("\n")}`);
15
17
  for (const warning of warnings) onWarning?.(warning);
16
18
  };
@@ -7,18 +7,20 @@ import { checkViewQueries } from "@protobase/server";
7
7
  * Fails the build, instead of a page once it asks, when a view filters, counts, sorts or searches by a field that its
8
8
  * resource does not mark for it. It loads the config folder once in Node, config/index.ts and config/<dir>/ui.ts with
9
9
  * what they import; protobase.config.ts does not run, so the build still needs no secrets and no database. Returns the
10
- * folder's pages and resources, which the build reads too.
10
+ * folder's pages, views and resources, which the build reads too.
11
11
  */
12
12
  const checkViews = async (projectDir) => {
13
13
  const configDir = path.join(projectDir, "config");
14
14
  if (!existsSync(path.join(configDir, "index.ts"))) return {
15
15
  pages: [],
16
+ views: [],
16
17
  models: []
17
18
  };
18
19
  const { models, views, pages } = await loadDataConfig(configDir, projectDir);
19
20
  checkViewQueries(models, views);
20
21
  return {
21
22
  pages,
23
+ views,
22
24
  models
23
25
  };
24
26
  };
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.100.13";
2
+ var version = "0.100.15";
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.100.13",
3
+ "version": "0.100.15",
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.100.13",
47
- "@protobase/layout": "0.100.13",
48
- "@protobase/query": "0.100.13",
49
- "@protobase/schema": "0.100.13",
50
- "@protobase/server": "0.100.13",
51
- "@protobase/ui": "0.100.13",
52
- "@protobase/workflows": "0.100.13",
46
+ "@protobase/config": "0.100.15",
47
+ "@protobase/layout": "0.100.15",
48
+ "@protobase/query": "0.100.15",
49
+ "@protobase/schema": "0.100.15",
50
+ "@protobase/server": "0.100.15",
51
+ "@protobase/ui": "0.100.15",
52
+ "@protobase/workflows": "0.100.15",
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",
@@ -34,6 +34,7 @@ The page of one record, with its sections, related records, galleries, charts an
34
34
  - [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.
35
35
  - [Custom section fallbacks](../reference/custom-components.md#record-section-fallbacks) (experimental): Where your own component on a record page cannot be drawn, such as on a watch, what you declare shows in its place: any main-column item in the main column, conversations included, and sidebar maps and sidebar custom components in the sidebar.
36
36
  - [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.
37
+ - [Block trees on record pages](../reference/layouts.md#record-pages) (beta): A record page tab holds a tree of layout blocks that reads the page's record as `@root`, and the page keeps its address, breadcrumbs and actions. A thread there, as anywhere, can be one author's, such as a log, with no sender line.
37
38
  - [Message status and a working indicator](../reference/ui-config.md#message-status-and-a-working-indicator) (experimental): Threads can show each message's status and when a reply is being written.
38
39
  - [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.
39
40
  - [Trends of related records](../reference/ui-config.md#trends-of-related-records) (experimental): Record pages can chart their related records over time.
@@ -659,7 +659,7 @@ The latest messages that match `filter`, oldest first, each under its sender's n
659
659
  | Prop | |
660
660
  | --- | --- |
661
661
  | `resource`, `filter` | Which messages. `resource` is required. |
662
- | `sender` | Who wrote each message: a relation, named as the record it points at, or a text field. Required. |
662
+ | `sender` | Who wrote each message: a relation, named as the record it points at, or a text field. Without it, the thread is one author's, such as a log: each message shows under the time it was sent, with no name or avatar. |
663
663
  | `time` | When each was sent: a date or timestamp field the API can sort by, which orders them. Required. |
664
664
  | `text` | The message; shown rendered when the message resource's view marks it [`.markdown()`](ui-config.md#names-and-columns). Required. |
665
665
  | `status` | A short line under each message, such as whether it was delivered: a text or enum field, shown with its view's value labels, in red for a value it colours `red`; a message without a value shows none. Left out for a user who cannot read it. Experimental, see [Message status and a working indicator](ui-config.md#message-status-and-a-working-indicator). |
@@ -696,7 +696,7 @@ A thread with an assistant in it can show what the assistant did between its mes
696
696
 
697
697
  Each call is a line under the messages before it, closed at first; a call with an input, result or error opens and closes with a click on its line. The thread reads the latest calls as it reads the latest messages, `limit` at a time, newest first by `time`, so that read needs an index on the filter's field and `time`, which [`protobase doctor`](cli.md#doctor) checks, and **Load earlier messages** loads the earlier calls with the earlier messages, keeping them in time order. A user who cannot read the calls' `name`, `time` or `status` gets the thread without its calls, and one who cannot read `input`, `result` or `error` gets the calls without that part.
698
698
 
699
- Clients that cannot draw the calls get their simpler forms from `@protobase/layout`: `threadLines(items)` gives one short line per item, a message as its sender and first line and a call as its name and status, and `threadMarkdown(items, words)` gives the thread as Markdown, for clients that read text, such as an MCP client or a language model: each message under its sender in bold, each call as its name and status with its input and result as JSON and its error in fenced code blocks. A message's text is escaped so it reads as written, unless its item sets `markdown: true`. The Markdown comes from [`renderText`](layouts.md#text-form), the text form every block renders through: `threadItemNodes(items, words)` gives the items as elements, and a `Thread` element holding them as its children reads as its heading with its items under it, so a page's text can include its thread. <gap>A watch cannot show a thread's tool calls as lines because drawing a thread on a watch is not implemented.</gap> <gap>An MCP client cannot read a thread as Markdown because serving a page's blocks as text is not implemented.</gap>
699
+ Clients that cannot draw the calls get their simpler forms from `@protobase/layout`: `threadLines(items)` gives one short line per item, a message as its sender, when it has one, and first line and a call as its name and status, and `threadMarkdown(items, words)` gives the thread as Markdown, for clients that read text, such as an MCP client or a language model: each message under its sender in bold, or one author's under its time alone, each call as its name and status with its input and result as JSON and its error in fenced code blocks. A message's text is escaped so it reads as written, unless its item sets `markdown: true`. The Markdown comes from [`renderText`](layouts.md#text-form), the text form every block renders through: `threadItemNodes(items, words)` gives the items as elements, and a `Thread` element holding them as its children reads as its heading with its items under it, so a page's text can include its thread. <gap>A watch cannot show a thread's tool calls as lines because drawing a thread on a watch is not implemented.</gap> <gap>An MCP client cannot read a thread as Markdown because serving a page's blocks as text is not implemented.</gap>
700
700
 
701
701
  ### Composer
702
702
 
@@ -179,7 +179,7 @@ Each read in the plan (`page.reads.reads`) names its block by a JSON Pointer int
179
179
 
180
180
  A [custom component](custom-components.md#reads) is planned when it declares its reads: the page starts them with the others, each of several a part of its own named by its resource prop (`/children/0#edges`), and the component draws from them. One that declares none is outside the plan (`page.reads.outside`): whatever it reads, it reads by itself once it draws, and `protobase doctor` lists it.
181
181
 
182
- <gap>A `RecordRow` of a view with `listOf` or `searchesOf` cannot start its read when the page opens because starting the user's saved records or searches ahead of it is not implemented, so it reads once it draws, under a `Show` or `Match` once its condition holds.</gap> <gap>A `RecordRow` inside the records of another block cannot start its read when the page opens because a planned first page per record is not implemented, so it reads once it draws.</gap> <gap>A `Chart` cannot sit inside a repeated record because grouping a chart per record is not implemented.</gap> <gap>A `Table` or `RecordCards` tied by a JSON list of keys cannot show every record its total when the lists around it hold more than 500 keys in all because paging a total's groups is not implemented.</gap>
182
+ <gap>A `RecordRow` of a view with `listOf` or `searchesOf` cannot start its read when the page opens because starting the user's saved records or searches ahead of it is not implemented, so it reads once it draws, under a `Show` or `Match` once its condition holds.</gap> <gap>A `RecordRow` inside the records of another block cannot start its read when the page opens because a planned first page per record is not implemented, so it reads once it draws.</gap> <gap>A `Chart` cannot sit inside a repeated record because grouping a chart per record is not implemented.</gap> <gap>A `Table` or `RecordCards` tied by a JSON list of keys cannot show every record all its rows and its total when the lists around it hold more than 500 keys or rows in all because paging such a read is not implemented.</gap>
183
183
 
184
184
  ## Field values
185
185
 
@@ -224,10 +224,6 @@ In the [text form](#text-form) each one reads as its formatted value, a `UrlFiel
224
224
 
225
225
  ## Paths and scopes
226
226
 
227
- :::caution[Beta]
228
- A path cannot read `@root` yet, as the marked limit below says.
229
- :::
230
-
231
227
  A `RecordCard`, a `ReferenceField`, each card of a `CardRow` and each entry of a [`RecordsIterator`](#related-records) put their record on a stack of records: an element inside both a task's `RecordCard` and a `CardRow` of its claims sits in a claim, inside the task. A bare name is looked up in the innermost record, then in each record further out, then in the page's own record; the [compatibility page](../features/compatibility.md#template-paths) says which template syntax this follows:
232
228
 
233
229
  | Path | Reads |
@@ -237,7 +233,7 @@ A `RecordCard`, a `ReferenceField`, each card of a `CardRow` and each entry of a
237
233
  | `../id`, `../../id` | The record one, or two, out from the nearest. |
238
234
  | `this.id`, `./id` | The nearest record only. |
239
235
  | `@index`, `@first`, `@last` | The card's place among a `CardRow`'s cards, or the entry's among a `RecordsIterator`'s, from 0, and whether it is the first or the last. |
240
- | `@root.id` | The page's own record. <gap>A path cannot read `@root` because pages with a record of their own are not implemented.</gap> |
236
+ | `@root.id` | The page's own record, in a [block tree on a record page](#record-pages). |
241
237
  | `@params.window` | The [page parameter](#page-parameters) `window`, which a `SelectInput source="window"` on the page sets. |
242
238
 
243
239
  `Field source`, a field component's `source`, `Diff source`, `Stat field`, `Progress`, and the names in a [condition](#conditions) take a path. A string prop takes `{{path}}` placeholders in double braces, filled with the path's value where the element draws, and empty when it has none:
@@ -256,6 +252,36 @@ The build checks every path where it sits:
256
252
  - **Reads that would wait.** A per-row value in a filter in any other place than a top-level `AND` equality (with `>=`, inside `OR` or `NOT`, a second one), `@index`, `@first`, `@last` or `this` in a filter, key or values, and any placeholder in `resource`, `sort`, `columns` or `limit` fail with "this would wait for the parent's rows": each block's records are one read of their own, and none may wait for another's rows.
257
253
  - **Shadowing.** A bare name that more than one record around it has reads the nearest, and the build warns which it read and how to write the others: `"id" resolves to task_claims; write ../id for the one of tasks`. `protobase build --strict` fails on it instead. `this.`, `./`, `../` and `@` paths never warn.
258
254
 
255
+ ## Record pages
256
+
257
+ :::caution[Beta]
258
+ A block tree on a record page sets no page parameters, chosen rows or tabs of its own, and may still change.
259
+ :::
260
+
261
+ A record page holds a tree of blocks among its items with `l.blocks(tree)`, in a [tab](ui-config.md#tabs) or in the main column, beside its sections and related tables. The tree is written in JSX like a composed page's, and checked and read like one, inside the page's own record: `@root` is the record, and it is the last record a bare name reaches, so `{{title}}` and `{{@root.title}}` both read the record's title where no record nearer has one. The page keeps its address, `/<resource>/<key>`, its breadcrumbs, its place among the recent records and its actions.
262
+
263
+ ```tsx
264
+ /** @jsxImportSource @protobase/layout */
265
+ import { Thread } from '@protobase/layout'
266
+ import { l, view } from '@protobase/schema'
267
+
268
+ export const tasksView = view<typeof tasks>('tasks').layout((r) => [
269
+ l.tab('Task', [l.section('Task', [r.title, r.status])]),
270
+ l.tab('Log', [l.blocks(<Thread title="Log of {{@root.title}}" resource="task_notes" filter="task_id = {{@root.id}}" time="noted_at" text="body" />)]),
271
+ ])
272
+ ```
273
+
274
+ The view's file is then `.tsx` and starts with the JSX import source, as a [layout file](#setup) does, or it imports the tree from a layout file of its own.
275
+
276
+ | | |
277
+ | --- | --- |
278
+ | `tree` | One element: any block or custom component but a `<Page>`. |
279
+ | `when` | `'editing'` or `'reading'` to show it only on the form or only on the read view, as other items take. |
280
+
281
+ Every block reads as it does on a composed page, all its reads started at once as the record page opens. The record's key comes from the address, so a filter that takes `{{@root.id}}` reads at once. A filter that takes another field of the record, such as `id = {{@root.owner_id}}`, reads with a [`related()`](api.md#filtering-through-related-records) filter on the record by its key, so it does not wait for the record either. Blocks that work on a record, such as a `Field`, an `Action` or a custom component's `useLayoutRecord()`, work on the page's record where no record nearer is around them.
282
+
283
+ The server checks each tree against the resources when it starts, as it checks pages: a name the record does not have fails, naming the record's resource, `"titel" is no field of tasks (@root); did you mean title?`, and a name a nearer record shadows warns as [above](#paths-and-scopes). A `<Page>`, a `SelectInput`, `Tabs` or a block that chooses a row with `select` in the tree fails too, since the record page's address is the record's. <gap>A block tree on a record page cannot hold a `SelectInput`, `Tabs` or a `select` because page parameters, block tabs and chosen rows in a record page's address are not implemented.</gap> Each reader gets the tree without what they cannot read, and no tree when nothing of it is left.
284
+
259
285
  ## Page parameters
260
286
 
261
287
  :::caution[Beta]
@@ -686,7 +686,8 @@ export const repairsView = filtered
686
686
  | `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`](custom-components.md#record-section-fallbacks) shows in its place where it cannot be drawn. |
687
687
  | `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). |
688
688
  | `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). |
689
- | `l.thread(title, { resource, field, sender, time, text, status?, working?, 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). |
689
+ | `l.thread(title, { resource, field, sender?, time, text, status?, working?, 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). |
690
+ | `l.blocks(tree, { when? })` | A tree of [layout blocks](layouts.md#record-pages), written in JSX as a composed page's, that reads the record as `@root`. |
690
691
  | `l.composer({ resource, field, text, placeholder?, when? })` | A box that sends a message about the record, which the thread then shows. See [Conversations](#conversations). |
691
692
  | `l.gallery(title, { image?, photos?, when? })` | The record's photos as tiles, opening a lightbox. See [Galleries](#galleries). |
692
693
  | `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). |
@@ -796,7 +797,7 @@ The open groups are in the address, as `?open=<title>` once per group, so a link
796
797
 
797
798
  ### Tabs
798
799
 
799
- `l.tab(title, items)` splits the record page into tabs. A tab holds any main-column item: sections, groups, related tables, custom components, maps, charts, trends, galleries, history and comments. It refuses a sidebar item, another tab, and a custom component or map with `sidebar: true`, since the sidebar stays beside the tabs on every tab.
800
+ `l.tab(title, items)` splits the record page into tabs. A tab holds any main-column item: sections, groups, related tables, custom components, maps, charts, trends, galleries, history, comments, conversations and [block trees](layouts.md#record-pages). It refuses a sidebar item, another tab, and a custom component or map with `sidebar: true`, since the sidebar stays beside the tabs on every tab.
800
801
 
801
802
  A view's tabs stand together in the layout and show as one strip; items before them show above the strip and items after them below it, on every tab. Tab titles are unique among a view's tabs, and group titles are unique across the whole layout, groups inside tabs too. The read view and the form show the same tabs.
802
803
 
@@ -1200,7 +1201,7 @@ The thread shows the latest messages oldest first, each under its sender's name
1200
1201
  | --- | --- |
1201
1202
  | `resource` | The message resource, such as `task_messages`. Required. |
1202
1203
  | `field` | The filterable relation of `resource` that holds this record's key. Required. |
1203
- | `sender` | Who wrote each message: a relation, named as the record it points at, or a text field. Required. |
1204
+ | `sender` | Who wrote each message: a relation, named as the record it points at, or a text field. Without it, the thread is one author's, such as a log: each message shows under the time it was sent, with no name or avatar. |
1204
1205
  | `time` | When each was sent: a date or timestamp field the API can sort by, which orders them. Required. |
1205
1206
  | `text` | The message, a text field. Required. |
1206
1207
  | `status` | A short line under each message, such as whether it was delivered: a text or enum field. See [Message status and a working indicator](#message-status-and-a-working-indicator). |