@protobase/cli 0.73.4 → 0.74.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.
- package/dist/cli/package.js +1 -1
- package/dist/doctor/field-shapes.js +16 -1
- package/package.json +8 -8
- package/skills/protobase/references/features/rest-api.md +1 -0
- package/skills/protobase/references/features/workflows.md +1 -1
- package/skills/protobase/references/reference/access.md +2 -0
- package/skills/protobase/references/reference/api.md +15 -1
- package/skills/protobase/references/reference/data-config.md +1 -0
- package/skills/protobase/references/reference/mcp.md +8 -2
- package/skills/protobase/references/reference/workflows.md +4 -4
package/dist/cli/package.js
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "0.74.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.
|
|
47
|
-
"@protobase/layout": "0.
|
|
48
|
-
"@protobase/query": "0.
|
|
49
|
-
"@protobase/schema": "0.
|
|
50
|
-
"@protobase/server": "0.
|
|
51
|
-
"@protobase/ui": "0.
|
|
52
|
-
"@protobase/workflows": "0.
|
|
46
|
+
"@protobase/config": "0.74.0",
|
|
47
|
+
"@protobase/layout": "0.74.0",
|
|
48
|
+
"@protobase/query": "0.74.0",
|
|
49
|
+
"@protobase/schema": "0.74.0",
|
|
50
|
+
"@protobase/server": "0.74.0",
|
|
51
|
+
"@protobase/ui": "0.74.0",
|
|
52
|
+
"@protobase/workflows": "0.74.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",
|
|
@@ -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.
|
|
@@ -21,7 +21,7 @@ Graphs of steps the server runs along their edges, written in a language a model
|
|
|
21
21
|
- [Who may run workflows](../reference/workflows.md#who-may-do-what) (beta): Making, changing and running workflows and reading their runs are each granted by name, within the tenant.
|
|
22
22
|
- [Workflows over MCP](../reference/mcp.md#workflows) (beta): AI clients find, write, validate, change by a small edit and test-run workflows as the signed-in person, and read each step of a run to fix the one that failed and re-run it from there.
|
|
23
23
|
- [Record triggers](../reference/workflows.md#apprecord) (beta): A workflow starts once for each record that becomes ready, at once or when a time in it comes, read as the user who saved the enabled version.
|
|
24
|
-
- [Triggers turned on while the app runs](../reference/workflows.md#turning-a-trigger-on) (beta):
|
|
24
|
+
- [Triggers turned on while the app runs](../reference/workflows.md#turning-a-trigger-on) (beta): Publishing a saved version registers its trigger on every server process, and turning the workflow off stops it, with no restart; a save goes live only once it is published.
|
|
25
25
|
- [Workflow plugins](../reference/workflow-plugins.md) (beta): A file of the app or a package adds trigger and step types through the same public interface the built-in types use.
|
|
26
26
|
- [Step cache](../reference/workflow-plugins.md#caching-results) (beta): A plugin's step reuses the result of an identical earlier call from any run or workflow, as its plugin decides, while secrets always come in with their current value; a workflow can force it on, and the graph marks a step forced on against its plugin's advice.
|
|
27
27
|
- [Guarded requests for plugins](../reference/workflow-plugins.md#sending-requests) (beta): A plugin's requests reach only public addresses, follow no redirect and read at most 10 MiB.
|
|
@@ -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 |
|
|
@@ -98,7 +99,7 @@ Access is resolved once per request and resource ([`resolveAccess`](https://docs
|
|
|
98
99
|
- **Record-level rules** (a rule that needs the record, such as `status != 'locked'`) run in the write transaction with the stored record; a filter they return is checked in the database against the row as written, and a miss rolls the write back with `403`.
|
|
99
100
|
- **`.own` on create**: when the create rule is limited to rows, the owner field is set to the caller unless given, and a row owned by someone else is refused with `403`.
|
|
100
101
|
- **Seeking**: `:seek` resolves a row position to a page on the server, inside the caller's tenant, row filter and filter. No anchor value, column statistic or boundary token is ever returned (table-wide statistics include rows the caller may not see), only the page and the tokens of its own rows.
|
|
101
|
-
- **ETags**: with a read-only `version` or `updated_at` column the ETag is a hash of that column's exact text, so it never shows a hidden value yet moves on every change. Without one it is a hash of the fields the caller may read, sensitive ones excluded: a change to a field they cannot read, or to a sensitive field, does not change their ETag.
|
|
102
|
+
- **ETags**: with a read-only `version` or `updated_at` column the ETag is a hash of that column's exact text, so it never shows a hidden value yet moves on every change; `.etagFrom((r) => r.updated_at)` on a resource names the column, for a `version` that counts something else. Without one it is a hash of the fields the caller may read, sensitive ones excluded: a change to a field they cannot read, or to a sensitive field, does not change their ETag.
|
|
102
103
|
- **Errors** never contain values of fields the caller cannot read; database errors leave out constraint and column names.
|
|
103
104
|
|
|
104
105
|
The roles (the `roles` export of `config/roles.ts`, from `defineRoles`) make an operation without an explicit rule need the matching capability (`orders.update`), and limits each role to the [fields and rows](access.md#capabilities) its capabilities list; `defaultAccess: 'allow' | 'deny'` in the config overrides the capability check. Without either, operations without a rule are allowed (single-admin projects).
|
|
@@ -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
|
|
@@ -106,8 +112,8 @@ In an app with [workflows](workflows.md), the endpoint also offers tools to find
|
|
|
106
112
|
| `list_connections` | The person's own [connected accounts](workflows.md#connecting-an-account), by each connection the app's plugins declare: its key and label, and each account's `id`, scopes and `needs_sign_in`. A definition's `connections` binds an account by its `id`. It returns no token, and no one else's accounts. |
|
|
107
113
|
| `create_workflow` | Creates a workflow from its `name`, `description` and `definition`, and returns its `id`, `version` and ETag. |
|
|
108
114
|
| `update_workflow` | Changes a workflow's definition by an `edit` or whole, as `definition`, and its `name` or `description`, and returns its `id`, new `version` and ETag. With the `etag` that `get_workflow` gave, it fails when someone changed the workflow since; an edit without one is saved against the version it was applied to. |
|
|
109
|
-
| `run_workflow` | Starts a run of a workflow's
|
|
110
|
-
| `enable_workflow` |
|
|
115
|
+
| `run_workflow` | Starts a run of a workflow's version saved last, or of the `version` it names, with an `input`, and returns its `run_id` and `status`. With `rerun_of`, a failed run's id, it [re-runs](workflows.md#re-running-a-failed-run) that run from its failed step instead, on its input; with `replay: true` too, it [replays](workflows.md#replaying-a-run) any ended run of the workflow on its current version, with that run's input, sending none of its outside writes. |
|
|
116
|
+
| `enable_workflow` | Publishes the saved `version` it names (`enabled: true`), which puts the workflow's trigger on it, or turns the workflow off, and returns its `enabled_version`. A save never goes live by itself. One that uses a [connected account](workflows.md#connecting-an-account) is turned on only by the account's owner in the admin app: the tool answers `own-sign-in-only` and says so. |
|
|
111
117
|
| `new_webhook_url` | Issues a new URL and secret for a workflow that starts from a [webhook trigger](workflows.md#appwebhook), keeping a `secret` the sender makes when given one, and returns `{ url, secret }`, shown this once; the old URL stops. |
|
|
112
118
|
|
|
113
119
|
An `edit` is a [JSON Merge Patch](https://www.rfc-editor.org/rfc/rfc7396) of the saved definition: only what changes, at its place in the document. An object merges into the object there, `null` removes a member, and any other value, a list included, replaces it. Changing one argument of one state:
|
|
@@ -24,7 +24,7 @@ It adds five resources, over a `workflows` schema that [`protobase migration`](c
|
|
|
24
24
|
| --- | --- |
|
|
25
25
|
| `workflows` | A name, a description and the definition. Each save that changes the definition is checked, and kept as the workflow's next version, saved by the caller. |
|
|
26
26
|
| `workflow_versions` | Every version of every definition as it was saved, with who saved it and when. Read-only. |
|
|
27
|
-
| `workflow_runs` | A run, started by creating it with `workflow_id` and an `input`, or with `rerun_of` to [re-run a failed run](#re-running-a-failed-run), and `replay: true` too to [replay a run](#replaying-a-run); it runs the version its workflow had then, and a re-run or a replay the input of the run it names. Its status, output, error and timing are written by the runner. |
|
|
27
|
+
| `workflow_runs` | A run, started by creating it with `workflow_id` and an `input`, and a saved `version` to run another than the published one, or on a workflow that is off the one saved last, or with `rerun_of` to [re-run a failed run](#re-running-a-failed-run), and `replay: true` too to [replay a run](#replaying-a-run); it runs the version its workflow had then, and a re-run or a replay the input of the run it names. Its status, output, error and timing are written by the runner. |
|
|
28
28
|
| `workflow_steps` | Every step of every run. Read-only. |
|
|
29
29
|
| `workflow_triggers` | The trigger of each enabled workflow that has one besides `manual`: its type, status and last error. Read-only. |
|
|
30
30
|
|
|
@@ -35,7 +35,7 @@ It adds five resources, over a `workflows` schema that [`protobase migration`](c
|
|
|
35
35
|
| `allowPrivateAddresses` | Lets the `app:http` step, and every plugin's `fetch`, reach private, loopback and link-local addresses, for development and tests. Default false. |
|
|
36
36
|
| `plugins` | Packages of [workflow plugins](workflow-plugins.md) to run, by name, beside the app's own in `workflows/plugins/<name>.ts`. |
|
|
37
37
|
|
|
38
|
-
Records steps act as
|
|
38
|
+
Records steps act as the user who saved the run's version, with the roles the project's sign-in gives them now. A project that signs people in otherwise exports its own, `async ({ id, tenant }) => [...]`, as the default of `workflows/saved-by-roles.ts` (`createAdmin` takes it as `workflows.savedByRoles`); without either, startup stops.
|
|
39
39
|
|
|
40
40
|
## The document
|
|
41
41
|
|
|
@@ -98,7 +98,7 @@ A save checks a trigger's input against its type, and refuses a type the app doe
|
|
|
98
98
|
|
|
99
99
|
### Turning a trigger on
|
|
100
100
|
|
|
101
|
-
A trigger starts runs only while its workflow is
|
|
101
|
+
A trigger starts runs only while its workflow is published: set `enabled_version` to any saved version through the API, in the admin app or with `enable_workflow` over MCP, and clear it to turn the workflow off. The trigger is registered at once on every server process, with no restart, and its status, `active` or `failing` with its last error, is the workflow's `workflow_triggers` record. A save makes a new version and changes nothing that is live, so a change can be run and tested first; publishing it moves `enabled_version`, and publishing an older version goes back to it. A published version whose trigger has the same type and input as the one before keeps the running trigger as it is, and any other change stops it and starts the new one. Runs in progress stay on their version. A trigger's runs run the enabled version and act as the user who saved it, as any run acts as its version's saver.
|
|
102
102
|
|
|
103
103
|
### app:record
|
|
104
104
|
|
|
@@ -353,7 +353,7 @@ A replay given an `input` of its own is refused with `rerun-input`, and one with
|
|
|
353
353
|
|
|
354
354
|
### Test runs
|
|
355
355
|
|
|
356
|
-
A workflow's page offers *Test run*: the form for a new run of the workflow, whose `input` takes a sample input as JSON, which every state reads as `$states.context.Execution.Input`. Creating it opens the workflow's page with the run on the graph, followed as it runs. A test run is a run like any other: its steps do what they do, as
|
|
356
|
+
A workflow's page offers *Test run*: the form for a new run of the workflow, whose `input` takes a sample input as JSON, which every state reads as `$states.context.Execution.Input`. Creating it opens the workflow's page with the run on the graph, followed as it runs. A test run is a run like any other, of the version saved last, which need not be published: its steps do what they do, acting as that version's saver.
|
|
357
357
|
|
|
358
358
|
## Over MCP
|
|
359
359
|
|