@protobase/cli 0.73.4 → 0.73.5

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.73.4";
2
+ var version = "0.73.5";
3
3
  //#endregion
4
4
  export { version };
@@ -29,9 +29,24 @@ const fieldShapes = (model) => {
29
29
  query: { filter: searchFor }
30
30
  }] : [],
31
31
  ...ownerShapes(model),
32
- ...parentShapes(model)
32
+ ...parentShapes(model),
33
+ ...linkShapes(model)
33
34
  ];
34
35
  };
36
+ const linkShapes = (model) => {
37
+ if (!model.links) return [];
38
+ const [first, second] = model.links.map((name) => model.fields[name]);
39
+ const side = (near, far) => ({
40
+ resource: model.name,
41
+ request: `GET /${model.name}?filter=${near.name} = …`,
42
+ from: `it links ${near.name} to ${far.name}`,
43
+ query: {
44
+ filter: compare(near),
45
+ selects: far
46
+ }
47
+ });
48
+ return [side(first, second), side(second, first)];
49
+ };
35
50
  const parentShapes = (model) => (model.parents ?? []).filter((parent) => parent.access === "read").map(({ field }) => ({
36
51
  resource: model.name,
37
52
  request: `GET /${model.name}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.73.4",
3
+ "version": "0.73.5",
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.73.4",
47
- "@protobase/layout": "0.73.4",
48
- "@protobase/query": "0.73.4",
49
- "@protobase/schema": "0.73.4",
50
- "@protobase/server": "0.73.4",
51
- "@protobase/ui": "0.73.4",
52
- "@protobase/workflows": "0.73.4",
46
+ "@protobase/config": "0.73.5",
47
+ "@protobase/layout": "0.73.5",
48
+ "@protobase/query": "0.73.5",
49
+ "@protobase/schema": "0.73.5",
50
+ "@protobase/server": "0.73.5",
51
+ "@protobase/ui": "0.73.5",
52
+ "@protobase/workflows": "0.73.5",
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",
@@ -7,6 +7,7 @@ The API every resource gets, with filters, writes, errors and the typed client.
7
7
  - [Generated REST API](../reference/api.md#routes): List, get, create, update and delete endpoints for every resource, following the AIP API design guidelines.
8
8
  - [OpenAPI and reference](../reference/api.md#meta-and-openapi-per-caller): An OpenAPI 3.1 document and an API reference page, each showing only what the caller may see and do.
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
+ - [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.
10
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.
11
12
  - [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.
12
13
  - [Map queries](../reference/api.md#maps): The records inside a map's view, or counts per area when there are many.
@@ -194,6 +194,8 @@ A list's filter can reach through other records with [`related(field, resource.k
194
194
 
195
195
  A link record the caller reads can narrow a list by a record they cannot read: with `related(project_id, memberships.project_id)`, a ticket matches through a membership of a project hidden from them, because they could read that membership and that ticket anyway. Going through `projects` instead, `related(project_id, projects.id)`, keeps to the projects they read. `total_size_estimate` comes from the planner's statistics of the whole table, as on any list.
196
196
 
197
+ A [list under a record](api.md#lists-under-a-record), `/objectives/40/tasks`, is stricter, since its address names one record: the parent is read first as the caller would read it, and a parent they cannot read answers the same `404` as one that does not exist.
198
+
197
199
  Only a read of the API resolves `related()`: access rules, role filters and the other places a filter is stored refuse it. <gap>An access rule cannot filter through related records because `related()` in rules is not implemented.</gap>
198
200
 
199
201
  ## Lists across organizations
@@ -35,6 +35,7 @@ Under `/api/v1`:
35
35
  | --- | --- |
36
36
  | `GET /{resource}` | list: `filter`, `order_by`, `page_size` (50, max 500), `page_token`, `fields`, `labels`, `photos`, `photos_order_by`, `count=exact` |
37
37
  | `POST /{resource}:search` | same parameters as a JSON body (`fields` and `labels` arrays), for long filters |
38
+ | `GET /{parent}/{key}/{resource}` | the list of `resource` that belongs to one record, see [Lists under a record](#lists-under-a-record) |
38
39
  | `GET /{resource}/{key}` | one record, with `ETag`; composite keys are `part,part`, each part percent-encoded |
39
40
  | `POST /{resource}` | create, `201` with `Location` and `ETag` |
40
41
  | `PATCH /{resource}/{key}` | partial update, `If-Match` required |
@@ -164,6 +165,19 @@ It works in the `filter` of a list, `:search`, `:seek`, `:facets`, `:aggregate`,
164
165
  - The [scan guard](#safety) judges both tables. Besides `field` and the subfilter's columns, `key` needs a btree index under what the subfilter pins.
165
166
  - A [list across organizations](access.md#lists-across-organizations) with a term reads the session's own organization alone, and so does the term.
166
167
 
168
+ ### Lists under a record
169
+
170
+ `GET /{parent}/{key}/{resource}` is the list of `resource` that belongs to one record, with the same parameters as its own list: `/objectives/40/tasks?filter=state != "done"`. The other list methods work too: `/objectives/40/tasks:facets`, `POST /objectives/40/tasks:search` and the rest. It is a filter the path spells out, and a record keeps its one address, `/tasks/7`.
171
+
172
+ - A relation of `resource` to `parent` leads there without a declaration: `/tasks/7/task_claims` keeps to `task_id = 7`, also in a `:facets` on `task_id`.
173
+ - A link resource that declares its two relations with [`.links()`](data-config.md#resource) joins them: `/objectives/40/tasks` reads as `related(id, objective_tasks.task_id, (objective_id = 40))`, the other side `/tasks/7/objectives`, and a resource a further step away, `/objectives/40/task_claims`, as `related(task_id, objective_tasks.task_id, (objective_id = 40))`.
174
+ - The caller's own `filter` stands beside it, with its own [limits](#filtering-through-related-records); a `:facets` on the relation stays inside the record.
175
+ - Where nothing leads there the answer is a `404`. Where several ways do, such as `task_dependencies` with its two relations to `tasks`, it is a `400` `ambiguous-parent` that names them, and a [`related()`](#filtering-through-related-records) filter says which. Links count only when the caller can list them.
176
+ - The parent is read as the caller would read it first: one in another tenant, soft-deleted, outside their row filter or refused by a rule that reads the record answers the same `404` as one that does not exist. A resource they do nothing with answers as one that does not exist. A list of a resource they may not list answers as that list does.
177
+ - A composite key has no list under it.
178
+
179
+ MCP's `list_records` and `count_records` take the same as `belongs_to: { "resource": "objectives", "key": 40 }`, beside `filter`.
180
+
167
181
  ## Writes
168
182
 
169
183
  Create, update and delete share one pipeline (`write-pipeline.ts`):
@@ -65,6 +65,7 @@ export const repairs = resource('repairs')
65
65
  | `.search((r) => [r.number, r.name])` | The fields that `search("...")` and bare words in a filter match, and what the admin's [global search](client.md#global-search) looks in. Every word of the text must appear in one of them, ignoring case, and part of a word is enough: `port` finds "Portfolio". `r.phone.digitsEnd()` matches only the end of a field's digits instead, ignoring spaces, `+` and dashes, and only words written like phone numbers: `9623`, `47069623` and `+31 6 47069623` find "+31 6 47069623", `4706` and `+316` do not. Each field needs a pg_trgm index (`using gin (name gin_trgm_ops)`), a `digitsEnd` one on `regexp_replace(phone, '[^0-9]', '', 'g')`, or the API refuses the search. |
66
66
  | `.position((r) => r.position, { within?, after? })` | The integer field holding the records' order by hand, 1 the first, which a list's **Reorder** button changes by dragging; with `within: (r) => r.invoice_id`, a filterable relation, each parent's records have an order of their own, sorted in its related section; with `after`, a record never ranks above the records it depends on. The field must be sortable. See [Reordering by hand](ui-config.md#reordering-by-hand) and [Ranked after what they depend on](ui-config.md#ranked-after-what-they-depend-on). |
67
67
  | `.parent((r) => r.vm_id, 'update')` | The relation whose record each record belongs to, and the access on it (`'read'` or `'update'`) that creating, changing, deleting and undeleting a record needs, checked with the caller's own rules on that resource. With `'read'`, every read of its records also keeps to those whose parent the caller reads. The relation is one column, to a resource with a key of one field. See [Records that belong to another](access.md#records-that-belong-to-another). |
68
+ | `.links((r) => [r.objective_id, r.task_id])` | Its records link records of two resources, so each side lists the other, and what points at it, at [`/{parent}/{key}/{resource}`](api.md#lists-under-a-record). Two different filterable relations of one column. [`protobase doctor`](cli.md#doctor) asks for the indexes reading either side needs. |
68
69
  | `.openExisting((r) => [r.organization_id, r.member_key])` | A unique key of the table whose conflict on create opens the record already holding those values, such as a direct message with the same members. See [Opening an existing record](#opening-an-existing-record). |
69
70
  | `.validate((record) => issues)` | A rule over the whole record, run after the field checks on every create and update. It returns `[{ field, message }]` or `undefined`; issues answer `400` with the field named. |
70
71
  | `.access({ ... })` | Rules per operation. See [Access](#access). |
@@ -79,6 +79,12 @@ To find records through related ones, a client filters with [`related()`](api.md
79
79
  { "resource": "task_claims", "filter": "related(task_id, objective_tasks.task_id, (objective_id = 40))" }
80
80
  ```
81
81
 
82
+ For the records of one record it passes `belongs_to`, as the [list under a record](api.md#lists-under-a-record) does, with `filter` beside it:
83
+
84
+ ```json
85
+ { "resource": "tasks", "belongs_to": { "resource": "objectives", "key": 40 }, "filter": "state != \"done\"" }
86
+ ```
87
+
82
88
  A refusal, such as a resource the person may not read, a bad filter or a field the person may not read, comes back to the client as text it can act on, `{ "error": ..., "message": ... }`.
83
89
 
84
90
  ### Comments