@protobase/cli 0.28.1 → 0.28.3

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.28.1";
2
+ var version = "0.28.3";
3
3
  //#endregion
4
4
  export { version };
@@ -106,6 +106,20 @@ const galleryShapes = (item, owner, models) => {
106
106
  }
107
107
  }];
108
108
  };
109
+ const recordChartShapes = (item, owner, models) => {
110
+ const target = models[item.resource];
111
+ const field = target?.fields[item.field];
112
+ if (!target || !field || !target.fields[item.at]) return [];
113
+ return [{
114
+ resource: target.name,
115
+ request: `GET /${target.name}:aggregate?group_by=${item.at}&filter=${field.name} = …`,
116
+ from: `chart "${item.title}" on the ${owner} record page`,
117
+ query: {
118
+ filter: compare(field),
119
+ groupBy: item.at
120
+ }
121
+ }];
122
+ };
109
123
  const displayShapes = (model, view, models) => (view.list?.displays ?? []).flatMap((display) => {
110
124
  if (display.kind === "map") {
111
125
  const latitude = model.fields[display.latitude];
@@ -240,7 +254,7 @@ const listShapes = (model, view, list, models) => [
240
254
  ];
241
255
  /**
242
256
  * The reads a view's pages make: its list in its order, the filter widgets and their counts, its chart per value, its displays' maps,
243
- * board columns and photos, the records of its related sections and the photos of its galleries, the recent records in the sidebar, a saved search's new records and the records sorted by hand.
257
+ * board columns and photos, the records of its related sections and charts and the photos of its galleries, the recent records in the sidebar, a saved search's new records and the records sorted by hand.
244
258
  */
245
259
  const viewShapes = (view, models) => {
246
260
  const model = models[view.resource];
@@ -249,7 +263,7 @@ const viewShapes = (view, models) => {
249
263
  return [
250
264
  ...listShapes(model, view, list, models),
251
265
  ...(view.lists ?? []).flatMap((named) => listShapes(model, viewOfList(view, named.name), `${list} "${named.name}"`, models)),
252
- ...layoutItems(view.layout).flatMap((item) => item.kind === "related" ? relatedShapes(item, model.name, models) : item.kind === "gallery" ? galleryShapes(item, model.name, models) : []),
266
+ ...layoutItems(view.layout).flatMap((item) => item.kind === "related" ? relatedShapes(item, model.name, models) : item.kind === "gallery" ? galleryShapes(item, model.name, models) : item.kind === "chart" ? recordChartShapes(item, model.name, models) : []),
253
267
  ...recentShapes(model, view),
254
268
  ...searchesShapes(view, models),
255
269
  ...handOrderShapes(model, view, list, models)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.28.1",
3
+ "version": "0.28.3",
4
4
  "description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -35,11 +35,11 @@
35
35
  "dependencies": {
36
36
  "@hono/node-server": "^2.1.3",
37
37
  "@hono/vite-dev-server": "^0.26.1",
38
- "@protobase/layout": "0.28.1",
39
- "@protobase/query": "0.28.1",
40
- "@protobase/schema": "0.28.1",
41
- "@protobase/server": "0.28.1",
42
- "@protobase/ui": "0.28.1",
38
+ "@protobase/layout": "0.28.3",
39
+ "@protobase/query": "0.28.3",
40
+ "@protobase/schema": "0.28.3",
41
+ "@protobase/server": "0.28.3",
42
+ "@protobase/ui": "0.28.3",
43
43
  "@react-email/render": "^2.1.0",
44
44
  "@scalar/hono-api-reference": "^0.12.10",
45
45
  "@tailwindcss/vite": "^4.3.3",
@@ -47,8 +47,8 @@ Under `/api/v1`:
47
47
  | `POST /{resource}/{key}:undelete` | restores a soft-deleted record ([AIP-164](https://google.aip.dev/164)); `If-Match` optional; `409` when not deleted, `400` on hard-delete resources |
48
48
  | `POST /api/v1:batchWrite` | many writes in one transaction, see [Batch writes](#batch-writes) |
49
49
  | `GET /{resource}:facets?field=&filter=&limit=&label=` | `{ field, facets: [{ value, count }] }`, the `limit` most frequent values (100 by default, at most 1,000), never all of them; with `label`, a relation's facets carry the related record's name as `label`, as in [Related names](#related-names) |
50
- | `GET /{resource}:aggregate?group_by=&sum=&average=&filter=` | `{ group_by, groups: [{ value, count, sum }] }`: the records the whole filter finds, per value of `group_by`, each with its count and, with `sum` or `average` (one of the two), that of a numeric field, `null` when no record of the group has one. Values come largest first, the first `limit` (100 by default, at most 1,000), with `label` as in `:facets`. A date or timestamp `group_by` is bucketed like `:series` instead (`granularity` `hour` to `year`, `range` or `from` and `to`, `time_zone`), empty buckets included, and each `value` is the bucket's start; the response adds `granularity` and `time_zone`. With `split_by` (a filterable field of values), a date `group_by` also splits each bucket: the response adds `split_by` and `splits` (the `split_limit` largest values over the range, 8 by default and at most 100, ranked by the sum, else by count; `split_label` names a relation's values), and each group lists its `splits` with their count and sum or average. Unlike `:facets`, the filter's terms on `group_by` apply too, so the groups add up to what the filter finds |
51
- | `GET /{resource}:series?field=&range=&granularity=&time_zone=&filter=` | `range` is `7d`, `30d`, `90d`, `1y`, `all`, or `from` and `to` (ISO) |
50
+ | `GET /{resource}:aggregate?group_by=&sum=&average=&maximum=&filter=` | `{ group_by, groups: [{ value, count, sum }] }`: the records the whole filter finds, per value of `group_by`, each with its count and, with `sum`, `average` or `maximum` (one of them), that of a numeric field, `null` when no record of the group has one. Values come largest first, the first `limit` (100 by default, at most 1,000), with `label` as in `:facets`. A date or timestamp `group_by` is bucketed like `:series` instead (`granularity` `minute`, `5_minutes`, `15_minutes` or `hour` to `year`, `range` or `from` and `to`, `time_zone`), empty buckets included, and each `value` is the bucket's start; the response adds `granularity` and `time_zone`. With `split_by` (a filterable field of values), a date `group_by` also splits each bucket: the response adds `split_by` and `splits` (the `split_limit` largest values over the range, 8 by default and at most 100, ranked by the sum, else by count; `split_label` names a relation's values), and each group lists its `splits` with their count and sum, average or maximum. Unlike `:facets`, the filter's terms on `group_by` apply too, so the groups add up to what the filter finds |
51
+ | `GET /{resource}:series?field=&range=&granularity=&time_zone=&filter=` | `range` is `1h`, `24h`, `7d`, `30d`, `90d`, `1y`, `all`, or `from` and `to` (ISO); `granularity` `minute`, `5_minutes`, `15_minutes`, `hour`, `day` (the default), `week` or `month`. Buckets of minutes start on the clock's multiples of them |
52
52
  | `GET /{resource}:histogram?field=&buckets=&filter=` | equal-width buckets of a numeric field |
53
53
  | `GET /{resource}:map?latitude=&longitude=&zoom=&filter=&order_by=&fields=&labels=&photos=&photos_order_by=` | the records in a map's view, the bounding box being in `filter` (`lat >= 51.9 AND lat <= 52.1 AND lng >= 4.2 AND lng <= 4.5`), as `{ items, buckets, total_size }`; see [Maps](#maps) |
54
54
  | `GET /{resource}:seek?position=&order_by=&filter=&page_size=&fields=&labels=&photos=&photos_order_by=` | the page at a row position (scrollbar jumps), with `next_page_token` and `prev_page_token`; same items as a list |
@@ -85,7 +85,7 @@ Filters use the language of [access rules](access.md)) and views, on any field,
85
85
  - **`changes.capture()`**, the trigger function. It runs as its owner, with a fixed search path, so a role that writes the table needs no rights on `changes`: another service writing as its own role keeps working once a resource has events.
86
86
  - **Two triggers per resource with events or history**, on its table: `<table>_changes` for inserts and deletes, and `<table>_changes_update` for updates that change the row.
87
87
 
88
- The first row a transaction captures also enqueues a `changes.dispatch` job with `jobs.enqueue()`, in the same transaction, so a resource with events needs the [`jobs` schema](jobs.md#the-jobs-schema)) too. Dispatch jobs run one at a time, in the app's workers. After a write through the API commits, the server has its own worker look for that job at once, so its events usually go out within milliseconds; a write from elsewhere waits for the next poll, two seconds at most.
88
+ The first row a transaction captures also enqueues a `changes.dispatch` job with `jobs.enqueue()`, in the same transaction, so a resource with events needs the [`jobs` schema](jobs.md#the-jobs-schema)) too. Dispatch jobs run one at a time, in the app's workers. After a write through the API commits, or an API function returns, the server has its own worker look for that job at once, so its events usually go out within milliseconds; a write from elsewhere waits for the next poll, two seconds at most.
89
89
 
90
90
  A trigger keeps the columns of the resource's fields, minus sensitive ones, whose names it lists in `changed` when they change. Columns that are not fields, such as a password hash, are never captured. One table can have events for one resource.
91
91
 
@@ -603,6 +603,7 @@ export const repairsView = filtered
603
603
  | `l.related(title, { ... })` | A table or cards of the records of another resource that point at this one, in the main column. See [Related records](#related-records). |
604
604
  | `l.custom(Component, { title?, props?, sidebar?, when? })` | 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. |
605
605
  | `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). |
606
+ | `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). |
606
607
  | `l.gallery(title, { image?, photos?, when? })` | The record's photos as tiles, opening a lightbox. See [Galleries](#galleries). |
607
608
  | `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)). |
608
609
  | `l.comments(title?, { when? })` | The record's comments, oldest first, with a box to write one that @mentions people; needs `.comments()` on the resource, and a view without a layout shows it last by itself. See [Record comments](comments.md#on-the-record-page)). |
@@ -637,7 +638,7 @@ The open groups are in the address, as `?open=<title>` once per group, so a link
637
638
 
638
639
  ### Tabs
639
640
 
640
- `l.tab(title, items)` splits the record page into tabs. A tab holds any main-column item: sections, groups, related tables, custom components, maps, 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.
641
+ `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, 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.
641
642
 
642
643
  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.
643
644
 
@@ -877,6 +878,29 @@ l.related('Waiting on you', {
877
878
 
878
879
  An action that `actions` names must be a named action of `resource`'s view. The cards have no display switch or **Reorder**; View all opens the list as a table section would.
879
880
 
881
+ ### Charts of related records
882
+
883
+ `l.chart(title, options)` draws line graphs of numeric fields of the records that point at the record on the page, over a timestamp of theirs, as a virtual machine's page graphs its CPU and network from the samples an app keeps of it, about one a minute. The section has a switch between the last **Hour**, per minute, the last **Day**, per 5 minutes, and the last **Week**, per hour, and one between the **Average** and the **Maximum** of each bucket. A bucket without a sample is a gap in the line, never 0. Each series is a line of its own colour, with a legend when there are several, and the tooltip shows each value with its field's prefix, suffix and decimals; the axis has one scale, so a chart holds series of one unit, such as bytes in and out.
884
+
885
+ | Option | |
886
+ | --- | --- |
887
+ | `resource` | The records charted, such as `host_samples`. Required. |
888
+ | `field` | The filterable relation on `resource` that holds this record's key. Required. |
889
+ | `at` | The filterable timestamp field of `resource` the records are placed by. Required. |
890
+ | `series` | The numeric fields of `resource` it draws, one line each, labelled as `resource`'s view labels them. At least one. |
891
+ | `range` | The range it opens on: `1h` (the default), `24h` or `7d`. |
892
+ | `help`, `when` | A line under the title, and whether it shows on the form, the read view or both. |
893
+
894
+ ```ts
895
+ view<typeof hosts>('hosts').layout((r) => [
896
+ l.section('Host', [r.name, r.address]),
897
+ l.chart('CPU', { resource: 'host_samples', field: 'host_id', at: 'sampled_at', series: ['cpu_percent'] }),
898
+ l.chart('Network', { resource: 'host_samples', field: 'host_id', at: 'sampled_at', series: ['net_in', 'net_out'], help: 'Bytes per second.' }),
899
+ ])
900
+ ```
901
+
902
+ Each series is read through [`:aggregate`](api.md)), grouped by `at` with `field = <this record's key>` as its filter, so the user's access applies as on the list, and a user who cannot read `field`, `at` or any series gets no chart (one who cannot read some series gets the others). That filter and grouping need an index on `(field, at)`, such as `create index on host_samples (host_id, sampled_at)`, which [`protobase doctor`](cli.md#doctor)) checks. A `field` that is no relation to this resource, an `at` that is no timestamp or not filterable, or a series that is no number or is sensitive stops the server at startup. Keeping the samples, and removing old ones, is the app's own work.
903
+
880
904
  ## Actions and views per role
881
905
 
882
906
  ```ts title="docs-examples/bike-shop/step-5.ts"