@protobase/cli 0.28.0 → 0.28.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
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.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": {
|
|
@@ -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.
|
|
39
|
-
"@protobase/query": "0.28.
|
|
40
|
-
"@protobase/schema": "0.28.
|
|
41
|
-
"@protobase/server": "0.28.
|
|
42
|
-
"@protobase/ui": "0.28.
|
|
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",
|
|
43
43
|
"@react-email/render": "^2.1.0",
|
|
44
44
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
45
45
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -108,6 +108,51 @@ Each item has `id`, `name`, `slug`, `price` and `image`, of published products o
|
|
|
108
108
|
|
|
109
109
|
A field rule goes from the field to the roles: `cost_price` above is hidden from every role that reads products but those holding `costs.read`. Use it for the few sensitive columns of a resource that many roles read, such as a screening result (`f.text().access({ read: roles.can('screening.read') })`). A field list goes from the role to the fields: use it for a role that should see only some columns, such as an integration or anonymous visitors, so a new column stays hidden from it. When both apply, a field needs both.
|
|
110
110
|
|
|
111
|
+
## Records that belong to another
|
|
112
|
+
|
|
113
|
+
A record often belongs to another one through a relation, such as an operation to the VM it runs on, and who may write it follows from who may change that VM. `.parent((r) => r.vm_id, 'update')` says so: writing an operation needs `update` on the record `vm_id` points at, `'read'` needing only to see it, as for a comment on a ticket. A member below may run operations on their own VMs only, with no rule of your own:
|
|
114
|
+
|
|
115
|
+
```ts title="docs-examples/reference/child-records.ts"
|
|
116
|
+
import { defineRoles, f, resource } from '@protobase/schema'
|
|
117
|
+
|
|
118
|
+
// Virtual machines and the operations run on them: a member creates an operation only on a VM they may update.
|
|
119
|
+
|
|
120
|
+
export const roles = defineRoles<'vms' | 'operations'>({
|
|
121
|
+
admin: ['*'],
|
|
122
|
+
member: ['vms.read', 'vms.update.own', 'operations.read', 'operations.create'],
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
/** virt.vms, each owned by the user who made it. */
|
|
126
|
+
export const vms = resource('vms')
|
|
127
|
+
.table('virt.vms')
|
|
128
|
+
.fields({
|
|
129
|
+
id: f.integer().readOnly().filterable().dbDefault(),
|
|
130
|
+
name: f.text().filterable(),
|
|
131
|
+
owner_id: f.text().readOnly().filterable(),
|
|
132
|
+
})
|
|
133
|
+
.primaryKey((r) => r.id)
|
|
134
|
+
.owner((r) => r.owner_id)
|
|
135
|
+
|
|
136
|
+
/** virt.operations: writing one needs `update` on the VM its `vm_id` points at. */
|
|
137
|
+
export const operations = resource('operations')
|
|
138
|
+
.table('virt.operations')
|
|
139
|
+
.fields({
|
|
140
|
+
id: f.integer().readOnly().filterable().dbDefault(),
|
|
141
|
+
vm_id: f.relation('vms').filterable(),
|
|
142
|
+
kind: f.enum(['start', 'stop', 'reboot']),
|
|
143
|
+
})
|
|
144
|
+
.primaryKey((r) => r.id)
|
|
145
|
+
.parent((r) => r.vm_id, 'update')
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
- **Every write is checked.** Creating a record checks the parent it names; changing it, the parent it points at and the one it moves to; deleting and undeleting it, the parent it points at. So a record cannot be created under an allowed parent and then moved under another. It holds for `/api/v1` and its batches, and for everything that writes through them: forms, [API functions](../guides/api-functions.md)) and the assistant.
|
|
149
|
+
- **The caller's own rules decide.** The parent is read as the caller would read it, with its tenant, row filters, soft delete and record-level rules; for `update`, also its update row filter and record-level update rule, given an empty input. A parent the caller cannot see, may not update, that is soft deleted or does not exist gets the same `403` as a refused create (`You may not create this operations record`), and nothing is written: the answer does not tell which VM ids exist.
|
|
150
|
+
- **A null relation checks nothing.** A relation set by a column default or a trigger is checked from the record as written.
|
|
151
|
+
- **`update` follows the parent's own parents**, so with VMs under `.parent((r) => r.folder_id, 'update')` an operation needs update on the VM's folder too. A write that would put a record under itself, or under a cycle already in the data, is refused. A `read` parent is not followed further.
|
|
152
|
+
- **Several parents** are each checked with their own access, also two of one resource, such as a transfer that reads its `source_vm_id` and updates its `target_vm_id`.
|
|
153
|
+
- **The parent is locked until the write commits** (`FOR NO KEY UPDATE`), so a VM handed to someone else or deleted at the same moment is waited for and checked again. That is the cost: writes of records under one parent, and through an `update` parent under one ancestor, run one after another. The server's database role needs `UPDATE` on the parent's table to take the lock. Two writes that lock the same records in opposite orders, such as two batches writing under VM A then B and B then A, can deadlock: Postgres rolls one back, which answers `409` and writes nothing, and the client sends it again.
|
|
154
|
+
- The record page and `/api/meta` count the check, so the admin app offers no Edit or Delete the server would refuse. `/rest/v1` does not use Protobase's access rules at all, so this check is not part of it.
|
|
155
|
+
|
|
111
156
|
## Restricted model and row filters
|
|
112
157
|
|
|
113
158
|
[`resolveAccess`](https://docs.protobase.net/api/schema/functions/resolveaccess/)) returns everything a request may do. Use [`restrictModel(model, access)`](https://docs.protobase.net/api/schema/functions/restrictmodel/)) for everything user-facing (checking filters and sorts, queries, OpenAPI, `/meta`): hidden fields are gone, so they cannot be referenced, searched, sorted or leaked. Key columns always stay, because records are addressed by them.
|
|
@@ -63,6 +63,7 @@ export const repairs = resource('repairs')
|
|
|
63
63
|
| `.owner((r) => r.owner_id)` | The field holding the owning user's id, which `.own` capabilities filter on (see [Access](#access)). |
|
|
64
64
|
| `.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. |
|
|
65
65
|
| `.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)). |
|
|
66
|
+
| `.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. 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)). |
|
|
66
67
|
| `.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. |
|
|
67
68
|
| `.access({ ... })` | Rules per operation. See [Access](#access). |
|
|
68
69
|
| `.events((e, r) => [...])` | What changes of its records mean, such as `orders.created`, captured in the database for every write. See [Events](events.md)). |
|