@protobase/cli 0.99.0 → 0.99.1
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/package.json +8 -8
- package/skills/protobase/references/features/compatibility.md +1 -1
- package/skills/protobase/references/features/rest-api.md +1 -0
- package/skills/protobase/references/reference/api.md +22 -3
- package/skills/protobase/references/reference/layouts.md +1 -1
package/dist/cli/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.99.
|
|
3
|
+
"version": "0.99.1",
|
|
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.99.
|
|
47
|
-
"@protobase/layout": "0.99.
|
|
48
|
-
"@protobase/query": "0.99.
|
|
49
|
-
"@protobase/schema": "0.99.
|
|
50
|
-
"@protobase/server": "0.99.
|
|
51
|
-
"@protobase/ui": "0.99.
|
|
52
|
-
"@protobase/workflows": "0.99.
|
|
46
|
+
"@protobase/config": "0.99.1",
|
|
47
|
+
"@protobase/layout": "0.99.1",
|
|
48
|
+
"@protobase/query": "0.99.1",
|
|
49
|
+
"@protobase/schema": "0.99.1",
|
|
50
|
+
"@protobase/server": "0.99.1",
|
|
51
|
+
"@protobase/ui": "0.99.1",
|
|
52
|
+
"@protobase/workflows": "0.99.1",
|
|
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",
|
|
@@ -20,7 +20,7 @@ Apps written for other systems that keep working on Protobase, and moving their
|
|
|
20
20
|
|
|
21
21
|
## react-admin
|
|
22
22
|
|
|
23
|
-
- [Related records](../reference/layouts.md#related-records) (beta): Layouts take react-admin's `ReferenceManyField`, `ReferenceArrayField`, `ArrayField`, `RecordsIterator` and `ReferenceField` with their names, props and defaults: `
|
|
23
|
+
- [Related records](../reference/layouts.md#related-records) (beta): Layouts take react-admin's `ReferenceManyField`, `ReferenceArrayField`, `ArrayField`, `RecordsIterator` and `ReferenceField` with their names, props and defaults: `sort` is the key descending, and a `ReferenceManyField`'s `source` is `id` and its `perPage` 25.
|
|
24
24
|
- [Text filters on related records](../reference/layouts.md#related-records) (beta): `filter` and `sort` also take AIP-160 and AIP-132 text, since an object cannot say `OR`.
|
|
25
25
|
- [Page size of related records](../reference/layouts.md#related-records) (beta): A list reads at most 500 records, the API's largest page, which is also a `ReferenceArrayField`'s `perPage` where react-admin's is 1000.
|
|
26
26
|
- [Items of an ArrayField](../reference/layouts.md#related-records) (beta): A text item of an `ArrayField` is read as `this`. An `ArrayField` takes no `filter`, `sort` or `perPage` yet.
|
|
@@ -9,6 +9,7 @@ The API every resource gets, with filters, writes, errors and the typed client.
|
|
|
9
9
|
- [Filters](../reference/api.md#filters): AIP-160 filters and ordering, with word search across a resource's search fields, lists of values and relative dates.
|
|
10
10
|
- [Lists under a record](../reference/api.md#lists-under-a-record): `/objectives/40/tasks` lists what belongs to one record, by a relation or a declared link, after reading that record as the caller would.
|
|
11
11
|
- [Filtering through related records](../reference/api.md#filtering-through-related-records): A list asks for the records that belong to another with a subfilter, such as an objective's tasks, in one read under the caller's access, instead of sending a list of keys. The filter can keep to one page of those records, with their sort, limit and page token, and follow a JSON list of keys they hold.
|
|
12
|
+
- [First rows per value](../reference/api.md#first-rows-per-value) (beta): A list can return the first n records per value of a field, such as the latest three comments of each task, in one read.
|
|
12
13
|
- [Counts, facets and charts](../reference/api.md#routes): Endpoints for value counts, grouped sums and averages, records over time, histograms and paging to any row.
|
|
13
14
|
- [Map queries](../reference/api.md#maps): The records inside a map's view, or counts per area when there are many.
|
|
14
15
|
- [Related names and photos](../reference/api.md#related-names): A list response can carry the names of related records and each record's first photos.
|
|
@@ -33,7 +33,7 @@ Under `/api/v1`:
|
|
|
33
33
|
|
|
34
34
|
| Route | |
|
|
35
35
|
| --- | --- |
|
|
36
|
-
| `GET /{resource}` | list: `filter`, `order_by`, `page_size` (50, max 500), `page_token`, `fields`, `labels`, `photos`, `photos_order_by`, `count=exact` |
|
|
36
|
+
| `GET /{resource}` | list: `filter`, `order_by`, `page_size` (50, max 500), `page_token`, `fields`, `labels`, `photos`, `photos_order_by`, `count=exact`, [`limit_per`](#first-rows-per-value) |
|
|
37
37
|
| `POST /{resource}:search` | same parameters as a JSON body (`fields` and `labels` arrays), for long filters |
|
|
38
38
|
| `GET /{parent}/{key}/{resource}` | the list of `resource` that belongs to one record, see [Lists under a record](#lists-under-a-record) |
|
|
39
39
|
| `GET /{resource}/{key}` | one record, with `ETag`; composite keys are `part,part`, each part percent-encoded |
|
|
@@ -48,7 +48,7 @@ Under `/api/v1`:
|
|
|
48
48
|
| `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 |
|
|
49
49
|
| `POST /api/v1:batchWrite` | many writes in one transaction, see [Batch writes](#batch-writes) |
|
|
50
50
|
| `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) |
|
|
51
|
-
| `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}: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. A values `group_by` takes [`limit_per=<field>:<n>`](#first-rows-per-value): the first `n` groups per value of `field`, each with that value as `per`, by `per`, with `limit` capping all groups together; a date `group_by` refuses it |
|
|
52
52
|
| `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 |
|
|
53
53
|
| `GET /{resource}:histogram?field=&buckets=&filter=` | equal-width buckets of a numeric field |
|
|
54
54
|
| `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) |
|
|
@@ -64,6 +64,24 @@ Every response carries `X-Meta-Version`, the hash of the models, the Protobase v
|
|
|
64
64
|
|
|
65
65
|
A list returns `{ items, next_page_token, total_size_estimate }`, the estimate being the planner's, which reads no rows. `count=exact` adds `total_size`, counted through the indexes but no further than 10,000 matches: above that `total_size` is left out and the estimate stands. `next_page_token` is `""` on the last page, and a token only continues the `filter` and `order_by` it came from: with others the request fails with `400 invalid-cursor`. Items use field names, dates as ISO 8601 text, 64-bit integers and decimals as strings.
|
|
66
66
|
|
|
67
|
+
### First rows per value
|
|
68
|
+
|
|
69
|
+
:::caution[Beta]
|
|
70
|
+
<gap>A list with `limit_per` cannot continue on a next page because paging per value is not implemented.</gap> It takes no `page_token`.
|
|
71
|
+
:::
|
|
72
|
+
|
|
73
|
+
`limit_per=<field>:<n>` keeps, for each value of `field` among the records the filter finds, the first `n` records in the list's `order_by`, such as the latest three comments of each task on a page in one read:
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
GET /api/v1/comments?filter=related(task_id, tasks.id, (state = "open"), "created_at desc", 20)&order_by=created_at desc&limit_per=task_id:3
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
- `field` is a filterable field that is not JSON, `n` a whole number from 1 to 500. The items come per value of `field`, in its order, and in `order_by` within each value; records whose `field` is null are left out. `page_size` caps the items over all values together.
|
|
80
|
+
- The records are read as any list reads them, under the caller's tenant, access and filter, a [`related()`](#filtering-through-related-records) term included, so only the values that filter keeps appear. `total_size_estimate` and `total_size` count what the filter finds, not what `limit_per` keeps.
|
|
81
|
+
- `next_page_token` is always `""`. `limit_per` with a `page_token` or on `:seek` is a `400` `invalid-parameter` that names the conflict.
|
|
82
|
+
- The [scan guard](#safety) needs a btree index on `field` with the first field of `order_by` under it, such as `create index on comments (task_id, created_at)`.
|
|
83
|
+
- On [`:aggregate`](#routes), `limit_per` groups by `field` as well as `group_by` and keeps, for each value of `field`, the first `n` groups in the aggregate's order; each group carries that value as `per`.
|
|
84
|
+
|
|
67
85
|
### Record history
|
|
68
86
|
|
|
69
87
|
`GET /{resource}/{key}:history` answers `{ items, next_page_token }` for a resource with `.history()`, and `404` for one without. It needs what a get needs, a soft-deleted record included. Each item is `{ id, at, operation, changed, before?, after?, actor, database_role }`: `before` and `after` hold only the fields the caller may read, never a sensitive or file field, `changed` names the changed fields the caller may read, and an update of only other fields is left out. `actor` is `{ id, name? }` for a write through the API, the name when the project's Better Auth knows the user, and `null` otherwise; `database_role` is the role that wrote. See [Record history](history.md).
|
|
@@ -249,8 +267,9 @@ The API sends no CORS headers until it has something to allow: other websites in
|
|
|
249
267
|
|
|
250
268
|
- Every request runs in a transaction with `SET LOCAL statement_timeout` (`statementTimeoutMs`, default 1 s), so a slow query fails where it runs instead of holding a connection that other requests wait for. List, search, get, histogram, series, map and seek transactions are read-only. A query that runs longer is stopped: a `504` `statement-timeout` that names the request, its limit and the ways out, such as `GET /api/v1/orders ran a query longer than 1 s, so the database stopped it. Make the query faster, such as with an index or a narrower filter, or move the work into a function or job with longQueries: true, whose queries may run up to 30 s.` It goes to the app's error hook (`hooks/error.ts`, `createAdmin`'s `options.onUnhandledError`) and the [error tracker](#error-reporting) like a `500`. A read that needs longer has no way to opt out: give it an index, or move it into a [function](../guides/api-functions.md#long-queries) or [job](jobs.md) with `longQueries`.
|
|
251
269
|
- Under `protobase dev` and `serve`, a request waits at most 2 seconds for a free database connection. When every connection stays busy that long, it is a `503` `connections-busy` with `Retry-After: 1` that names the request, reported the same way, rather than a request that hangs behind slow ones. A request that finds room for a new connection waits up to 30 seconds for it to open, such as while a database that scaled to zero wakes.
|
|
252
|
-
- **Scan guard**: a list, `:search`, `:seek`, `:map` page, card photos, `:facets` and `:aggregate` read only columns an index serves, so they stay cheap however many rows match. The server reads each table's valid indexes from the catalog once, then checks every column the caller's filter, the role's row filter, the sort's first field, a facet's or an aggregate's grouped field a [`read` parent](access.md#records-that-belong-to-another)'s relation read and a [`related()`](#filtering-through-related-records) term's `field`, the columns of the parent's own row filter against the parent's table, and the subfilter's columns and `key` of a term against its resource's table:
|
|
270
|
+
- **Scan guard**: a list, `:search`, `:seek`, `:map` page, card photos, `:facets` and `:aggregate` read only columns an index serves, so they stay cheap however many rows match. The server reads each table's valid indexes from the catalog once, then checks every column the caller's filter, the role's row filter, the sort's first field, a facet's or an aggregate's grouped field, the field of [`limit_per`](#first-rows-per-value), a [`read` parent](access.md#records-that-belong-to-another)'s relation read and a [`related()`](#filtering-through-related-records) term's `field`, the columns of the parent's own row filter against the parent's table, and the subfilter's columns and `key` of a term against its resource's table:
|
|
253
271
|
- Comparisons, `in`, null checks, sorts and facets need a btree index with the column as a key, every key before it pinned by the query: by `=` or `in` in the filter (outside `OR` and `NOT`), by the tenant or by soft delete. `(for_sale, status, published_at desc)` serves `for_sale = true AND status = "available"` sorted by `published_at desc`, but not `status` alone. `=` on text may use a pg_trgm index instead.
|
|
272
|
+
- `limit_per` reads each value's records in the sort's order, so it needs one btree index with its field as a key and the sort's first field under it, `(task_id, created_at)` for `limit_per=task_id:3&order_by=created_at desc`; without an `order_by`, an index on its field alone.
|
|
254
273
|
- Patterns (`name = "*port*"`), `regex()`, `similar()` and `search()` need a pg_trgm (GIN or GiST) index on each column they read, a `digitsEnd` search field one on its digits; JSON `field:value` needs a GIN index.
|
|
255
274
|
- A partial index counts for nothing, and a resource on a plain view or a foreign table, which has no indexes of its own, is not checked.
|
|
256
275
|
|
|
@@ -137,7 +137,7 @@ A record's related records repeat under it as a list: a `ReferenceManyField` hol
|
|
|
137
137
|
</RecordCard>
|
|
138
138
|
```
|
|
139
139
|
|
|
140
|
-
Each entry is a record of the stack while its children draw, so `Field`, `Show`, `{{path}}` placeholders and nested lists inside it read it, and `@index`, `@first` and `@last` count its place in the list. A text item of an `ArrayField`, such as a label, is read as `this`; an object item by its keys, which no model describes, so the build does not check them, and it warns when an item's key could shadow a field of a record further out. A list ties itself to the record around it by a field of that record
|
|
140
|
+
Each entry is a record of the stack while its children draw, so `Field`, `Show`, `{{path}}` placeholders and nested lists inside it read it, and `@index`, `@first` and `@last` count its place in the list. A text item of an `ArrayField`, such as a label, is read as `this`; an object item by its keys, which no model describes, so the build does not check them, and it warns when an item's key could shadow a field of a record further out. A list ties itself to the record around it by a field of that record, its `source`; a `ReferenceManyField`'s is `id` of the nearest record by default. `filter` and `sort` take AIP-160 and AIP-132 text, or the objects react-admin writes: `{ status: 'open' }` is `status = "open"`, its fields ANDed, and `{ field: 'claimed_at', order: 'DESC' }` is `claimed_at desc`. Without `sort`, a list is in its key's order, descending, as react-admin's is. `pagination="more"` adds a button that reads the next `perPage` records into the same list. The [blocks reference](blocks.md#related-records) lists every prop.
|
|
141
141
|
|
|
142
142
|
<gap>A list block cannot read its records at page load, beside the records around it, because planning a page's reads is not implemented; each reads once the record around it has drawn.</gap>
|
|
143
143
|
|